Completed
Pull Request — master (#801)
by Jared
13:18
created
lib/timber-query-iterator.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -1,156 +1,156 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3 3
 if ( !defined( 'ABSPATH' ) )
4
-    exit;
4
+	exit;
5 5
 
6 6
 class TimberQueryIterator implements Iterator {
7 7
 
8
-    /**
9
-     *
10
-     *
11
-     * @var WP_Query
12
-     */
13
-    private $_query = null;
14
-    private $_posts_class = 'TimberPost';
15
-
16
-    public function __construct( $query = false, $posts_class = 'TimberPost' ) {
17
-        add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' ));
18
-        if ( $posts_class )
19
-            $this->_posts_class = $posts_class;
20
-
21
-        if ( is_a( $query, 'WP_Query' ) ) {
22
-            // We got a full-fledged WP Query, look no further!
23
-            $the_query = $query;
24
-
25
-        } elseif ( false === $query ) {
26
-            // If query is explicitly set to false, use the main loop
27
-            global $wp_query;
28
-            $the_query =& $wp_query;
29
-            //if we're on a custom posts page?
30
-            $the_query = self::handle_maybe_custom_posts_page($the_query);
31
-        } elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) {
32
-            // We have a regularly formed WP query string or array to use
33
-            $the_query = new WP_Query( $query );
34
-
35
-        } elseif ( is_numeric( $query ) || is_string( $query ) ) {
36
-            // We have what could be a post name or post ID to pull out
37
-            $the_query = self::get_query_from_string( $query );
38
-
39
-        } elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) {
40
-            // We have a list of pids (post IDs) to extract from
41
-            $the_query = self::get_query_from_array_of_ids( $query );
42
-        } elseif ( is_array($query) && empty($query)) {
43
-            // it's an empty array
44
-            $the_query = array();
45
-        } else {
46
-            TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ );
47
-            TimberHelper::error_log( $query );
48
-
49
-            // We have failed hard, at least let get something.
50
-            $the_query = new WP_Query();
51
-        }
52
-
53
-        $this->_query = $the_query;
54
-
55
-    }
56
-
57
-    public function get_posts( $return_collection = false ) {
58
-        if (isset($this->_query->posts)){
59
-            $posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class );
60
-            return ( $return_collection ) ? $posts : $posts->get_posts();
61
-        }
62
-    }
63
-
64
-    //
65
-    // GET POSTS
66
-    //
67
-    public static function get_query_from_array_of_ids( $query = array() ) {
68
-        if ( !is_array( $query ) || !count( $query ) )
69
-            return null;
70
-
71
-        return new WP_Query( array(
72
-                'post_type'=> 'any',
73
-                'ignore_sticky_posts' => true,
74
-                'post__in' => $query,
75
-                'orderby'  => 'post__in',
76
-                'nopaging' => true
77
-            ) );
78
-    }
79
-
80
-    public static function get_query_from_string( $string = '' ) {
81
-        $post_type = false;
82
-
83
-        if ( is_string( $string ) && strstr( $string, '#' ) ) {
84
-            //we have a post_type directive here
85
-            list( $post_type, $string ) = explode( '#', $string );
86
-        }
87
-
88
-        $query = array(
89
-            'post_type' => ( $post_type ) ? $post_type : 'any'
90
-        );
91
-
92
-        if ( is_numeric( $string ) ) {
93
-            $query['p'] = $string;
94
-
95
-        } else {
96
-            $query['name'] = $string;
97
-        }
98
-
99
-        return new WP_Query( $query );
100
-    }
101
-
102
-    //
103
-    // Iterator Interface
104
-    //
105
-
106
-    public function valid() {
107
-        return $this->_query->have_posts();
108
-    }
109
-
110
-    public function current() {
111
-        global $post;
112
-
113
-        $this->_query->the_post();
114
-
115
-        // Sets up the global post, but also return the post, for use in Twig template
116
-        $posts_class = $this->_posts_class;
117
-        return new $posts_class( $post );
118
-    }
119
-
120
-    /**
121
-     * Don't implement next, because current already advances the loop
122
-     */
123
-    final public function next() {}
124
-
125
-    public function rewind() {
126
-        $this->_query->rewind_posts();
127
-    }
128
-
129
-    public function key() {
130
-        $this->_query->current_post;
131
-    }
132
-
133
-    //get_posts users numberposts
134
-    static function fix_number_posts_wp_quirk( $query ) {
135
-        if (isset($query->query) && isset($query->query['numberposts'])
136
-                && !isset($query->query['posts_per_page'])) {
137
-            $query->set( 'posts_per_page', $query->query['numberposts'] );
138
-        }
139
-        return $query;
140
-    }
141
-
142
-    /**
143
-     * this will test for whether a custom page to display posts is active, and if so, set the query to the default
144
-     * @param  WP_Query $query the original query recived from WordPress
145
-     * @return WP_Query
146
-     */
147
-    static function handle_maybe_custom_posts_page( $query ) {
148
-    	if ($custom_posts_page = get_option('page_for_posts')) {
149
-        	if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) {
150
-        		return new WP_Query(array('post_type' => 'post'));
151
-        	}
152
-        }
153
-        return $query;
154
-    }
8
+	/**
9
+	 *
10
+	 *
11
+	 * @var WP_Query
12
+	 */
13
+	private $_query = null;
14
+	private $_posts_class = 'TimberPost';
15
+
16
+	public function __construct( $query = false, $posts_class = 'TimberPost' ) {
17
+		add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' ));
18
+		if ( $posts_class )
19
+			$this->_posts_class = $posts_class;
20
+
21
+		if ( is_a( $query, 'WP_Query' ) ) {
22
+			// We got a full-fledged WP Query, look no further!
23
+			$the_query = $query;
24
+
25
+		} elseif ( false === $query ) {
26
+			// If query is explicitly set to false, use the main loop
27
+			global $wp_query;
28
+			$the_query =& $wp_query;
29
+			//if we're on a custom posts page?
30
+			$the_query = self::handle_maybe_custom_posts_page($the_query);
31
+		} elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) {
32
+			// We have a regularly formed WP query string or array to use
33
+			$the_query = new WP_Query( $query );
34
+
35
+		} elseif ( is_numeric( $query ) || is_string( $query ) ) {
36
+			// We have what could be a post name or post ID to pull out
37
+			$the_query = self::get_query_from_string( $query );
38
+
39
+		} elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) {
40
+			// We have a list of pids (post IDs) to extract from
41
+			$the_query = self::get_query_from_array_of_ids( $query );
42
+		} elseif ( is_array($query) && empty($query)) {
43
+			// it's an empty array
44
+			$the_query = array();
45
+		} else {
46
+			TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ );
47
+			TimberHelper::error_log( $query );
48
+
49
+			// We have failed hard, at least let get something.
50
+			$the_query = new WP_Query();
51
+		}
52
+
53
+		$this->_query = $the_query;
54
+
55
+	}
56
+
57
+	public function get_posts( $return_collection = false ) {
58
+		if (isset($this->_query->posts)){
59
+			$posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class );
60
+			return ( $return_collection ) ? $posts : $posts->get_posts();
61
+		}
62
+	}
63
+
64
+	//
65
+	// GET POSTS
66
+	//
67
+	public static function get_query_from_array_of_ids( $query = array() ) {
68
+		if ( !is_array( $query ) || !count( $query ) )
69
+			return null;
70
+
71
+		return new WP_Query( array(
72
+				'post_type'=> 'any',
73
+				'ignore_sticky_posts' => true,
74
+				'post__in' => $query,
75
+				'orderby'  => 'post__in',
76
+				'nopaging' => true
77
+			) );
78
+	}
79
+
80
+	public static function get_query_from_string( $string = '' ) {
81
+		$post_type = false;
82
+
83
+		if ( is_string( $string ) && strstr( $string, '#' ) ) {
84
+			//we have a post_type directive here
85
+			list( $post_type, $string ) = explode( '#', $string );
86
+		}
87
+
88
+		$query = array(
89
+			'post_type' => ( $post_type ) ? $post_type : 'any'
90
+		);
91
+
92
+		if ( is_numeric( $string ) ) {
93
+			$query['p'] = $string;
94
+
95
+		} else {
96
+			$query['name'] = $string;
97
+		}
98
+
99
+		return new WP_Query( $query );
100
+	}
101
+
102
+	//
103
+	// Iterator Interface
104
+	//
105
+
106
+	public function valid() {
107
+		return $this->_query->have_posts();
108
+	}
109
+
110
+	public function current() {
111
+		global $post;
112
+
113
+		$this->_query->the_post();
114
+
115
+		// Sets up the global post, but also return the post, for use in Twig template
116
+		$posts_class = $this->_posts_class;
117
+		return new $posts_class( $post );
118
+	}
119
+
120
+	/**
121
+	 * Don't implement next, because current already advances the loop
122
+	 */
123
+	final public function next() {}
124
+
125
+	public function rewind() {
126
+		$this->_query->rewind_posts();
127
+	}
128
+
129
+	public function key() {
130
+		$this->_query->current_post;
131
+	}
132
+
133
+	//get_posts users numberposts
134
+	static function fix_number_posts_wp_quirk( $query ) {
135
+		if (isset($query->query) && isset($query->query['numberposts'])
136
+				&& !isset($query->query['posts_per_page'])) {
137
+			$query->set( 'posts_per_page', $query->query['numberposts'] );
138
+		}
139
+		return $query;
140
+	}
141
+
142
+	/**
143
+	 * this will test for whether a custom page to display posts is active, and if so, set the query to the default
144
+	 * @param  WP_Query $query the original query recived from WordPress
145
+	 * @return WP_Query
146
+	 */
147
+	static function handle_maybe_custom_posts_page( $query ) {
148
+		if ($custom_posts_page = get_option('page_for_posts')) {
149
+			if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) {
150
+				return new WP_Query(array('post_type' => 'post'));
151
+			}
152
+		}
153
+		return $query;
154
+	}
155 155
 
156 156
 }
Please login to merge, or discard this patch.
lib/timber-site.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
 
65 65
 	/** @api
66 66
 	 * @var string for people who like trackback spam
67
-	*/
67
+	 */
68 68
 	public $pingback_url;
69 69
 	public $siteurl;
70 70
 	/**
Please login to merge, or discard this patch.
lib/image/timber-image-operation-retina.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Contains the class for running image retina-izing operations
4
- */
3
+	 * Contains the class for running image retina-izing operations
4
+	 */
5 5
 
6 6
 /**
7 7
  * Increases image size by a given factor
@@ -11,64 +11,64 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class TimberImageOperationRetina extends TimberImageOperation {
13 13
 
14
-    private $factor;
14
+	private $factor;
15 15
 
16
-    /**
17
-     * Construct our operation
18
-     * @param float   $factor to multiply original dimensions by
19
-     */
20
-    function __construct($factor) {
21
-        $this->factor = $factor;
22
-    }
16
+	/**
17
+	 * Construct our operation
18
+	 * @param float   $factor to multiply original dimensions by
19
+	 */
20
+	function __construct($factor) {
21
+		$this->factor = $factor;
22
+	}
23 23
 
24
-    /**
25
-     * Generates the final filename based on the source's name and extension
26
-     *
27
-     * @param   string    $src_filename     the basename of the file (ex: my-awesome-pic)
28
-     * @param   string    $src_extension    the extension (ex: .jpg)
29
-     * @return  string    the final filename to be used (ex: [email protected])
30
-     */
31
-    function filename($src_filename, $src_extension) {
32
-        $newbase = $src_filename . '@' . $this->factor . 'x'; // add @2x, @3x, @1.5x, etc.
33
-        $new_name = $newbase . '.' . $src_extension;
34
-        return $new_name;
35
-    }
24
+	/**
25
+	 * Generates the final filename based on the source's name and extension
26
+	 *
27
+	 * @param   string    $src_filename     the basename of the file (ex: my-awesome-pic)
28
+	 * @param   string    $src_extension    the extension (ex: .jpg)
29
+	 * @return  string    the final filename to be used (ex: [email protected])
30
+	 */
31
+	function filename($src_filename, $src_extension) {
32
+		$newbase = $src_filename . '@' . $this->factor . 'x'; // add @2x, @3x, @1.5x, etc.
33
+		$new_name = $newbase . '.' . $src_extension;
34
+		return $new_name;
35
+	}
36 36
 
37
-    /**
38
-     * Performs the actual image manipulation,
39
-     * including saving the target file.
40
-     *
41
-     * @param  string $load_filename filepath (not URL) to source file
42
-     *                               (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
43
-     * @param  string $save_filename filepath (not URL) where result file should be saved
44
-     *                               (ex: /src/var/www/wp-content/uploads/[email protected])
45
-     * @return bool                  true if everything went fine, false otherwise
46
-     */
47
-    function run($load_filename, $save_filename){
48
-        $image = wp_get_image_editor( $load_filename );
49
-        if ( !is_wp_error( $image ) ) {
50
-            $current_size = $image->get_size();
51
-            $src_w = $current_size['width'];
52
-            $src_h = $current_size['height'];
53
-            // Get ratios
54
-            $w = $src_w * $this->factor;
55
-            $h = $src_h * $this->factor;
56
-            $image->crop( 0, 0, $src_w, $src_h, $w, $h );
57
-            $result = $image->save( $save_filename );
58
-            if ( is_wp_error( $result ) ) {
59
-            	// @codeCoverageIgnoreStart
37
+	/**
38
+	 * Performs the actual image manipulation,
39
+	 * including saving the target file.
40
+	 *
41
+	 * @param  string $load_filename filepath (not URL) to source file
42
+	 *                               (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
43
+	 * @param  string $save_filename filepath (not URL) where result file should be saved
44
+	 *                               (ex: /src/var/www/wp-content/uploads/[email protected])
45
+	 * @return bool                  true if everything went fine, false otherwise
46
+	 */
47
+	function run($load_filename, $save_filename){
48
+		$image = wp_get_image_editor( $load_filename );
49
+		if ( !is_wp_error( $image ) ) {
50
+			$current_size = $image->get_size();
51
+			$src_w = $current_size['width'];
52
+			$src_h = $current_size['height'];
53
+			// Get ratios
54
+			$w = $src_w * $this->factor;
55
+			$h = $src_h * $this->factor;
56
+			$image->crop( 0, 0, $src_w, $src_h, $w, $h );
57
+			$result = $image->save( $save_filename );
58
+			if ( is_wp_error( $result ) ) {
59
+				// @codeCoverageIgnoreStart
60 60
 				TimberHelper::error_log( 'Error resizing image' );
61 61
 				TimberHelper::error_log( $result );
62 62
 				return false;
63 63
 				// @codeCoverageIgnoreEnd
64
-            } else {
65
-                return true;
66
-            }
67
-        } else if ( isset( $image->error_data['error_loading_image'] ) ) {
68
-            TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] );
69
-        } else {
70
-            TimberHelper::error_log( $image );
71
-        }
72
-        return false;
73
-    }
64
+			} else {
65
+				return true;
66
+			}
67
+		} else if ( isset( $image->error_data['error_loading_image'] ) ) {
68
+			TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] );
69
+		} else {
70
+			TimberHelper::error_log( $image );
71
+		}
72
+		return false;
73
+	}
74 74
 }
Please login to merge, or discard this patch.
lib/timber-term.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,35 +1,35 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Terms: WordPress has got 'em, you want 'em. Categories. Tags. Custom Taxonomies. You don't care, you're a fiend. Well let's get this under control
4
- * @example
5
- * ```php
6
- * //Get a term by its ID
7
- * $context['term'] = new TimberTerm(6);
8
- * //Get a term when on a term archive page
9
- * $context['term_page'] = new TimberTerm();
10
- * //Get a term with a slug
11
- * $context['team'] = new TimberTerm('patriots');
12
- * //Get a team with a slug from a specific taxonomy
13
- * $context['st_louis'] = new TimberTerm('cardinals', 'baseball');
14
- * Timber::render('index.twig', $context);
15
- * ```
16
- * ```twig
17
- * <h2>{{term_page.name}} Archives</h2>
18
- * <h3>Teams</h3>
19
- * <ul>
20
- *     <li>{{st_louis.name}} - {{st_louis.description}}</li>
21
- *     <li>{{team.name}} - {{team.description}}</li>
22
- * </ul>
23
- * ```
24
- * ```html
25
- * <h2>Team Archives</h2>
26
- * <h3>Teams</h3>
27
- * <ul>
28
- *     <li>St. Louis Cardinals - Winner of 11 World Series</li>
29
- *     <li>New England Patriots - Winner of 4 Super Bowls</li>
30
- * </ul>
31
- * ```
32
- */
3
+	 * Terms: WordPress has got 'em, you want 'em. Categories. Tags. Custom Taxonomies. You don't care, you're a fiend. Well let's get this under control
4
+	 * @example
5
+	 * ```php
6
+	 * //Get a term by its ID
7
+	 * $context['term'] = new TimberTerm(6);
8
+	 * //Get a term when on a term archive page
9
+	 * $context['term_page'] = new TimberTerm();
10
+	 * //Get a term with a slug
11
+	 * $context['team'] = new TimberTerm('patriots');
12
+	 * //Get a team with a slug from a specific taxonomy
13
+	 * $context['st_louis'] = new TimberTerm('cardinals', 'baseball');
14
+	 * Timber::render('index.twig', $context);
15
+	 * ```
16
+	 * ```twig
17
+	 * <h2>{{term_page.name}} Archives</h2>
18
+	 * <h3>Teams</h3>
19
+	 * <ul>
20
+	 *     <li>{{st_louis.name}} - {{st_louis.description}}</li>
21
+	 *     <li>{{team.name}} - {{team.description}}</li>
22
+	 * </ul>
23
+	 * ```
24
+	 * ```html
25
+	 * <h2>Team Archives</h2>
26
+	 * <h3>Teams</h3>
27
+	 * <ul>
28
+	 *     <li>St. Louis Cardinals - Winner of 11 World Series</li>
29
+	 *     <li>New England Patriots - Winner of 4 Super Bowls</li>
30
+	 * </ul>
31
+	 * ```
32
+	 */
33 33
 class TimberTerm extends TimberCore implements TimberCoreInterface {
34 34
 
35 35
 	public $PostClass = 'TimberPost';
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		$suffix = '</p>';
334 334
 		$desc = term_description( $this->ID, $this->taxonomy );
335 335
 		if (substr($desc, 0, strlen($prefix)) == $prefix) {
336
-    		$desc = substr($desc, strlen($prefix));
336
+			$desc = substr($desc, strlen($prefix));
337 337
 		}
338 338
 		$desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc);
339 339
 		return trim($desc);
Please login to merge, or discard this patch.
lib/timber-term-getter.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -2,180 +2,180 @@
 block discarded – undo
2 2
 
3 3
 class TimberTermGetter {
4 4
 
5
-    /**
6
-     * @param string|array $args
7
-     * @param array $maybe_args
8
-     * @param string $TermClass
9
-     * @return mixed
10
-     */
11
-    public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){
12
-        if (is_string($maybe_args) && !strstr($maybe_args, '=')){
13
-            //the user is sending the $TermClass in the second argument
14
-            $TermClass = $maybe_args;
15
-        }
16
-        if (is_string($maybe_args) && strstr($maybe_args, '=')){
17
-            parse_str($maybe_args, $maybe_args);
18
-        }
19
-        if (is_string($args) && strstr($args, '=')){
20
-            //a string and a query string!
21
-            $parsed = self::get_term_query_from_query_string($args);
22
-            if (is_array($maybe_args)){
23
-                $parsed->args = array_merge($parsed->args, $maybe_args);
24
-            }
25
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
26
-        } else if (is_string($args)){
27
-            //its just a string with a single taxonomy
28
-            $parsed = self::get_term_query_from_string($args);
29
-            if (is_array($maybe_args)){
30
-                $parsed->args = array_merge($parsed->args, $maybe_args);
31
-            }
32
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
33
-        } else if (is_array($args) && TimberHelper::is_array_assoc($args)){
34
-            //its an associative array, like a good ole query
35
-            $parsed = self::get_term_query_from_assoc_array($args);
36
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
37
-        } else if (is_array($args)){
38
-            //its just an array of strings or IDs (hopefully)
39
-            $parsed = self::get_term_query_from_array($args);
40
-            if (is_array($maybe_args)){
41
-                $parsed->args = array_merge($parsed->args, $maybe_args);
42
-            }
43
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
44
-        } else if (is_null($args)) {
45
-            return self::handle_term_query(get_taxonomies(), array(), $TermClass);
46
-        }
47
-        return null;
48
-    }
5
+	/**
6
+	 * @param string|array $args
7
+	 * @param array $maybe_args
8
+	 * @param string $TermClass
9
+	 * @return mixed
10
+	 */
11
+	public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){
12
+		if (is_string($maybe_args) && !strstr($maybe_args, '=')){
13
+			//the user is sending the $TermClass in the second argument
14
+			$TermClass = $maybe_args;
15
+		}
16
+		if (is_string($maybe_args) && strstr($maybe_args, '=')){
17
+			parse_str($maybe_args, $maybe_args);
18
+		}
19
+		if (is_string($args) && strstr($args, '=')){
20
+			//a string and a query string!
21
+			$parsed = self::get_term_query_from_query_string($args);
22
+			if (is_array($maybe_args)){
23
+				$parsed->args = array_merge($parsed->args, $maybe_args);
24
+			}
25
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
26
+		} else if (is_string($args)){
27
+			//its just a string with a single taxonomy
28
+			$parsed = self::get_term_query_from_string($args);
29
+			if (is_array($maybe_args)){
30
+				$parsed->args = array_merge($parsed->args, $maybe_args);
31
+			}
32
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
33
+		} else if (is_array($args) && TimberHelper::is_array_assoc($args)){
34
+			//its an associative array, like a good ole query
35
+			$parsed = self::get_term_query_from_assoc_array($args);
36
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
37
+		} else if (is_array($args)){
38
+			//its just an array of strings or IDs (hopefully)
39
+			$parsed = self::get_term_query_from_array($args);
40
+			if (is_array($maybe_args)){
41
+				$parsed->args = array_merge($parsed->args, $maybe_args);
42
+			}
43
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
44
+		} else if (is_null($args)) {
45
+			return self::handle_term_query(get_taxonomies(), array(), $TermClass);
46
+		}
47
+		return null;
48
+	}
49 49
 
50
-    /**
51
-     * @param string|array $taxonomies
52
-     * @param string|array $args
53
-     * @param string $TermClass
54
-     * @return mixed
55
-     */
56
-    public static function handle_term_query($taxonomies, $args, $TermClass){
57
-        if (!isset($args['hide_empty'])){
58
-            $args['hide_empty'] = false;
59
-        }
60
-        if (isset($args['term_id']) && is_int($args['term_id'])){
61
-            $args['term_id'] = array($args['term_id']);
62
-        }
63
-        if (isset($args['term_id'])){
64
-            $args['include'] = $args['term_id'];
65
-        }
66
-        $terms = get_terms($taxonomies, $args);
67
-        foreach($terms as &$term){
68
-            $term = new $TermClass($term->term_id, $term->taxonomy);
69
-        }
70
-        return $terms;
71
-    }
50
+	/**
51
+	 * @param string|array $taxonomies
52
+	 * @param string|array $args
53
+	 * @param string $TermClass
54
+	 * @return mixed
55
+	 */
56
+	public static function handle_term_query($taxonomies, $args, $TermClass){
57
+		if (!isset($args['hide_empty'])){
58
+			$args['hide_empty'] = false;
59
+		}
60
+		if (isset($args['term_id']) && is_int($args['term_id'])){
61
+			$args['term_id'] = array($args['term_id']);
62
+		}
63
+		if (isset($args['term_id'])){
64
+			$args['include'] = $args['term_id'];
65
+		}
66
+		$terms = get_terms($taxonomies, $args);
67
+		foreach($terms as &$term){
68
+			$term = new $TermClass($term->term_id, $term->taxonomy);
69
+		}
70
+		return $terms;
71
+	}
72 72
 
73
-    /**
74
-     * @param string $query_string
75
-     * @return stdClass
76
-     */
77
-    protected static function get_term_query_from_query_string($query_string) {
78
-        $args = array();
79
-        parse_str($query_string, $args);
80
-        $ret = self::get_term_query_from_assoc_array($args);
81
-        return $ret;
82
-    }
73
+	/**
74
+	 * @param string $query_string
75
+	 * @return stdClass
76
+	 */
77
+	protected static function get_term_query_from_query_string($query_string) {
78
+		$args = array();
79
+		parse_str($query_string, $args);
80
+		$ret = self::get_term_query_from_assoc_array($args);
81
+		return $ret;
82
+	}
83 83
 
84
-    /**
85
-     * @param string $taxs
86
-     * @return stdClass
87
-     */
88
-    protected static function get_term_query_from_string($taxs) {
89
-        $ret = new stdClass();
90
-        $ret->args = array();
91
-        if (is_string($taxs)) {
92
-            $taxs = array($taxs);
93
-        }
94
-        $ret->taxonomies = self::correct_taxonomy_names($taxs);
95
-        return $ret;
96
-    }
84
+	/**
85
+	 * @param string $taxs
86
+	 * @return stdClass
87
+	 */
88
+	protected static function get_term_query_from_string($taxs) {
89
+		$ret = new stdClass();
90
+		$ret->args = array();
91
+		if (is_string($taxs)) {
92
+			$taxs = array($taxs);
93
+		}
94
+		$ret->taxonomies = self::correct_taxonomy_names($taxs);
95
+		return $ret;
96
+	}
97 97
 
98
-    /**
99
-     * @param array $args
100
-     * @return stdClass
101
-     */
102
-    public static function get_term_query_from_assoc_array($args) {
103
-        $ret = new stdClass();
104
-        $ret->args = $args;
105
-        if (isset($ret->args['tax'])) {
106
-            $ret->taxonomies = $ret->args['tax'];
107
-        } else if (isset($ret->args['taxonomies'])) {
108
-            $ret->taxonomies = $ret->args['taxonomies'];
109
-        } else if (isset($ret->args['taxs'])) {
110
-            $ret->taxonomies = $ret->args['taxs'];
111
-        } else if (isset($ret->args['taxonomy'])) {
112
-            $ret->taxonomies = $ret->args['taxonomy'];
113
-        }
114
-        if (isset($ret->taxonomies)) {
115
-            if (is_string($ret->taxonomies)) {
116
-                $ret->taxonomies = array($ret->taxonomies);
117
-            }
118
-            $ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies);
119
-        } else {
120
-            $ret->taxonomies = get_taxonomies();
121
-        }
122
-        return $ret;
123
-    }
98
+	/**
99
+	 * @param array $args
100
+	 * @return stdClass
101
+	 */
102
+	public static function get_term_query_from_assoc_array($args) {
103
+		$ret = new stdClass();
104
+		$ret->args = $args;
105
+		if (isset($ret->args['tax'])) {
106
+			$ret->taxonomies = $ret->args['tax'];
107
+		} else if (isset($ret->args['taxonomies'])) {
108
+			$ret->taxonomies = $ret->args['taxonomies'];
109
+		} else if (isset($ret->args['taxs'])) {
110
+			$ret->taxonomies = $ret->args['taxs'];
111
+		} else if (isset($ret->args['taxonomy'])) {
112
+			$ret->taxonomies = $ret->args['taxonomy'];
113
+		}
114
+		if (isset($ret->taxonomies)) {
115
+			if (is_string($ret->taxonomies)) {
116
+				$ret->taxonomies = array($ret->taxonomies);
117
+			}
118
+			$ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies);
119
+		} else {
120
+			$ret->taxonomies = get_taxonomies();
121
+		}
122
+		return $ret;
123
+	}
124 124
 
125
-    /**
126
-     * @param array $args
127
-     * @return stdClass
128
-     */
129
-    public static function get_term_query_from_array($args) {
130
-        if (is_array($args) && !empty($args)) {
131
-            //okay its an array with content
132
-            if (is_int($args[0])) {
133
-                return self::get_term_query_from_array_of_ids($args);
134
-            } else if (is_string($args[0])) {
135
-                return self::get_term_query_from_array_of_strings($args);
136
-            }
137
-        }
138
-        return null;
139
-    }
125
+	/**
126
+	 * @param array $args
127
+	 * @return stdClass
128
+	 */
129
+	public static function get_term_query_from_array($args) {
130
+		if (is_array($args) && !empty($args)) {
131
+			//okay its an array with content
132
+			if (is_int($args[0])) {
133
+				return self::get_term_query_from_array_of_ids($args);
134
+			} else if (is_string($args[0])) {
135
+				return self::get_term_query_from_array_of_strings($args);
136
+			}
137
+		}
138
+		return null;
139
+	}
140 140
 
141
-    /**
142
-     * @param integer[] $args
143
-     * @return stdClass
144
-     */
145
-    public static function get_term_query_from_array_of_ids($args) {
146
-        $ret = new stdClass();
147
-        $ret->taxonomies = get_taxonomies();
148
-        $ret->args['include'] = $args;
149
-        return $ret;
150
-    }
141
+	/**
142
+	 * @param integer[] $args
143
+	 * @return stdClass
144
+	 */
145
+	public static function get_term_query_from_array_of_ids($args) {
146
+		$ret = new stdClass();
147
+		$ret->taxonomies = get_taxonomies();
148
+		$ret->args['include'] = $args;
149
+		return $ret;
150
+	}
151 151
 
152
-    /**
153
-     * @param string[] $args
154
-     * @return stdClass
155
-     */
156
-    public static function get_term_query_from_array_of_strings($args) {
157
-        $ret = new stdClass();
158
-        $ret->taxonomies = self::correct_taxonomy_names($args);
159
-        $ret->args = array();
160
-        return $ret;
161
-    }
152
+	/**
153
+	 * @param string[] $args
154
+	 * @return stdClass
155
+	 */
156
+	public static function get_term_query_from_array_of_strings($args) {
157
+		$ret = new stdClass();
158
+		$ret->taxonomies = self::correct_taxonomy_names($args);
159
+		$ret->args = array();
160
+		return $ret;
161
+	}
162 162
 
163
-    /**
164
-     * @param string|array $taxs
165
-     * @return array
166
-     */
167
-    private static function correct_taxonomy_names($taxs) {
168
-        if (is_string($taxs)) {
169
-            $taxs = array($taxs);
170
-        }
171
-        foreach ($taxs as &$tax) {
172
-            if ($tax == 'tags' || $tax == 'tag') {
173
-                $tax = 'post_tag';
174
-            } else if ($tax == 'categories') {
175
-                $tax = 'category';
176
-            }
177
-        }
178
-        return $taxs;
179
-    }
163
+	/**
164
+	 * @param string|array $taxs
165
+	 * @return array
166
+	 */
167
+	private static function correct_taxonomy_names($taxs) {
168
+		if (is_string($taxs)) {
169
+			$taxs = array($taxs);
170
+		}
171
+		foreach ($taxs as &$tax) {
172
+			if ($tax == 'tags' || $tax == 'tag') {
173
+				$tax = 'post_tag';
174
+			} else if ($tax == 'categories') {
175
+				$tax = 'category';
176
+			}
177
+		}
178
+		return $taxs;
179
+	}
180 180
 
181 181
 }
Please login to merge, or discard this patch.