Completed
Pull Request — master (#793)
by Jared
03:03
created
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/timber-term-getter.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -3,180 +3,180 @@
 block discarded – undo
3 3
 class TimberTermGetter
4 4
 {
5 5
 
6
-    /**
7
-     * @param string|array $args
8
-     * @param array $maybe_args
9
-     * @param string $TermClass
10
-     * @return mixed
11
-     */
12
-    public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){
13
-        if (is_string($maybe_args) && !strstr($maybe_args, '=')){
14
-            //the user is sending the $TermClass in the second argument
15
-            $TermClass = $maybe_args;
16
-        }
17
-        if (is_string($maybe_args) && strstr($maybe_args, '=')){
18
-            parse_str($maybe_args, $maybe_args);
19
-        }
20
-        if (is_string($args) && strstr($args, '=')){
21
-            //a string and a query string!
22
-            $parsed = TimberTermGetter::get_term_query_from_query_string($args);
23
-            if (is_array($maybe_args)){
24
-                $parsed->args = array_merge($parsed->args, $maybe_args);
25
-            }
26
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
27
-        } else if (is_string($args)){
28
-            //its just a string with a single taxonomy
29
-            $parsed = TimberTermGetter::get_term_query_from_string($args);
30
-            if (is_array($maybe_args)){
31
-                $parsed->args = array_merge($parsed->args, $maybe_args);
32
-            }
33
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
34
-        } else if (is_array($args) && TimberHelper::is_array_assoc($args)){
35
-            //its an associative array, like a good ole query
36
-            $parsed = TimberTermGetter::get_term_query_from_assoc_array($args);
37
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
38
-        } else if (is_array($args)){
39
-            //its just an array of strings or IDs (hopefully)
40
-            $parsed = TimberTermGetter::get_term_query_from_array($args);
41
-            if (is_array($maybe_args)){
42
-                $parsed->args = array_merge($parsed->args, $maybe_args);
43
-            }
44
-            return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
45
-        } else if (is_null($args)) {
46
-            return self::handle_term_query(get_taxonomies(), array(), $TermClass);
47
-        }
48
-        return null;
49
-    }
6
+	/**
7
+	 * @param string|array $args
8
+	 * @param array $maybe_args
9
+	 * @param string $TermClass
10
+	 * @return mixed
11
+	 */
12
+	public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm'){
13
+		if (is_string($maybe_args) && !strstr($maybe_args, '=')){
14
+			//the user is sending the $TermClass in the second argument
15
+			$TermClass = $maybe_args;
16
+		}
17
+		if (is_string($maybe_args) && strstr($maybe_args, '=')){
18
+			parse_str($maybe_args, $maybe_args);
19
+		}
20
+		if (is_string($args) && strstr($args, '=')){
21
+			//a string and a query string!
22
+			$parsed = TimberTermGetter::get_term_query_from_query_string($args);
23
+			if (is_array($maybe_args)){
24
+				$parsed->args = array_merge($parsed->args, $maybe_args);
25
+			}
26
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
27
+		} else if (is_string($args)){
28
+			//its just a string with a single taxonomy
29
+			$parsed = TimberTermGetter::get_term_query_from_string($args);
30
+			if (is_array($maybe_args)){
31
+				$parsed->args = array_merge($parsed->args, $maybe_args);
32
+			}
33
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
34
+		} else if (is_array($args) && TimberHelper::is_array_assoc($args)){
35
+			//its an associative array, like a good ole query
36
+			$parsed = TimberTermGetter::get_term_query_from_assoc_array($args);
37
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
38
+		} else if (is_array($args)){
39
+			//its just an array of strings or IDs (hopefully)
40
+			$parsed = TimberTermGetter::get_term_query_from_array($args);
41
+			if (is_array($maybe_args)){
42
+				$parsed->args = array_merge($parsed->args, $maybe_args);
43
+			}
44
+			return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
45
+		} else if (is_null($args)) {
46
+			return self::handle_term_query(get_taxonomies(), array(), $TermClass);
47
+		}
48
+		return null;
49
+	}
50 50
 
51
-    /**
52
-     * @param string|array $taxonomies
53
-     * @param string|array $args
54
-     * @param string $TermClass
55
-     * @return mixed
56
-     */
57
-    public static function handle_term_query($taxonomies, $args, $TermClass){
58
-        if (!isset($args['hide_empty'])){
59
-            $args['hide_empty'] = false;
60
-        }
61
-        if (isset($args['term_id']) && is_int($args['term_id'])){
62
-            $args['term_id'] = array($args['term_id']);
63
-        }
64
-        if (isset($args['term_id'])){
65
-            $args['include'] = $args['term_id'];
66
-        }
67
-        $terms = get_terms($taxonomies, $args);
68
-        foreach($terms as &$term){
69
-            $term = new $TermClass($term->term_id, $term->taxonomy);
70
-        }
71
-        return $terms;
72
-    }
51
+	/**
52
+	 * @param string|array $taxonomies
53
+	 * @param string|array $args
54
+	 * @param string $TermClass
55
+	 * @return mixed
56
+	 */
57
+	public static function handle_term_query($taxonomies, $args, $TermClass){
58
+		if (!isset($args['hide_empty'])){
59
+			$args['hide_empty'] = false;
60
+		}
61
+		if (isset($args['term_id']) && is_int($args['term_id'])){
62
+			$args['term_id'] = array($args['term_id']);
63
+		}
64
+		if (isset($args['term_id'])){
65
+			$args['include'] = $args['term_id'];
66
+		}
67
+		$terms = get_terms($taxonomies, $args);
68
+		foreach($terms as &$term){
69
+			$term = new $TermClass($term->term_id, $term->taxonomy);
70
+		}
71
+		return $terms;
72
+	}
73 73
 
74
-    /**
75
-     * @param string $query_string
76
-     * @return stdClass
77
-     */
78
-    public static function get_term_query_from_query_string($query_string) {
79
-        $args = array();
80
-        parse_str($query_string, $args);
81
-        $ret = self::get_term_query_from_assoc_array($args);
82
-        return $ret;
83
-    }
74
+	/**
75
+	 * @param string $query_string
76
+	 * @return stdClass
77
+	 */
78
+	public static function get_term_query_from_query_string($query_string) {
79
+		$args = array();
80
+		parse_str($query_string, $args);
81
+		$ret = self::get_term_query_from_assoc_array($args);
82
+		return $ret;
83
+	}
84 84
 
85
-    /**
86
-     * @param string $taxs
87
-     * @return stdClass
88
-     */
89
-    public static function get_term_query_from_string($taxs) {
90
-        $ret = new stdClass();
91
-        $ret->args = array();
92
-        if (is_string($taxs)) {
93
-            $taxs = array($taxs);
94
-        }
95
-        $ret->taxonomies = self::correct_taxonomy_names($taxs);
96
-        return $ret;
97
-    }
85
+	/**
86
+	 * @param string $taxs
87
+	 * @return stdClass
88
+	 */
89
+	public static function get_term_query_from_string($taxs) {
90
+		$ret = new stdClass();
91
+		$ret->args = array();
92
+		if (is_string($taxs)) {
93
+			$taxs = array($taxs);
94
+		}
95
+		$ret->taxonomies = self::correct_taxonomy_names($taxs);
96
+		return $ret;
97
+	}
98 98
 
99
-    /**
100
-     * @param array $args
101
-     * @return stdClass
102
-     */
103
-    public static function get_term_query_from_assoc_array($args) {
104
-        $ret = new stdClass();
105
-        $ret->args = $args;
106
-        if (isset($ret->args['tax'])) {
107
-            $ret->taxonomies = $ret->args['tax'];
108
-        } else if (isset($ret->args['taxonomies'])) {
109
-            $ret->taxonomies = $ret->args['taxonomies'];
110
-        } else if (isset($ret->args['taxs'])) {
111
-            $ret->taxonomies = $ret->args['taxs'];
112
-        } else if (isset($ret->args['taxonomy'])) {
113
-            $ret->taxonomies = $ret->args['taxonomy'];
114
-        }
115
-        if (isset($ret->taxonomies)) {
116
-            if (is_string($ret->taxonomies)) {
117
-                $ret->taxonomies = array($ret->taxonomies);
118
-            }
119
-            $ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies);
120
-        } else {
121
-            $ret->taxonomies = get_taxonomies();
122
-        }
123
-        return $ret;
124
-    }
99
+	/**
100
+	 * @param array $args
101
+	 * @return stdClass
102
+	 */
103
+	public static function get_term_query_from_assoc_array($args) {
104
+		$ret = new stdClass();
105
+		$ret->args = $args;
106
+		if (isset($ret->args['tax'])) {
107
+			$ret->taxonomies = $ret->args['tax'];
108
+		} else if (isset($ret->args['taxonomies'])) {
109
+			$ret->taxonomies = $ret->args['taxonomies'];
110
+		} else if (isset($ret->args['taxs'])) {
111
+			$ret->taxonomies = $ret->args['taxs'];
112
+		} else if (isset($ret->args['taxonomy'])) {
113
+			$ret->taxonomies = $ret->args['taxonomy'];
114
+		}
115
+		if (isset($ret->taxonomies)) {
116
+			if (is_string($ret->taxonomies)) {
117
+				$ret->taxonomies = array($ret->taxonomies);
118
+			}
119
+			$ret->taxonomies = self::correct_taxonomy_names($ret->taxonomies);
120
+		} else {
121
+			$ret->taxonomies = get_taxonomies();
122
+		}
123
+		return $ret;
124
+	}
125 125
 
126
-    /**
127
-     * @param array $args
128
-     * @return stdClass
129
-     */
130
-    public static function get_term_query_from_array($args) {
131
-        if (is_array($args) && !empty($args)) {
132
-            //okay its an array with content
133
-            if (is_int($args[0])) {
134
-                return self::get_term_query_from_array_of_ids($args);
135
-            } else if (is_string($args[0])) {
136
-                return self::get_term_query_from_array_of_strings($args);
137
-            }
138
-        }
139
-        return null;
140
-    }
126
+	/**
127
+	 * @param array $args
128
+	 * @return stdClass
129
+	 */
130
+	public static function get_term_query_from_array($args) {
131
+		if (is_array($args) && !empty($args)) {
132
+			//okay its an array with content
133
+			if (is_int($args[0])) {
134
+				return self::get_term_query_from_array_of_ids($args);
135
+			} else if (is_string($args[0])) {
136
+				return self::get_term_query_from_array_of_strings($args);
137
+			}
138
+		}
139
+		return null;
140
+	}
141 141
 
142
-    /**
143
-     * @param integer[] $args
144
-     * @return stdClass
145
-     */
146
-    public static function get_term_query_from_array_of_ids($args) {
147
-        $ret = new stdClass();
148
-        $ret->taxonomies = get_taxonomies();
149
-        $ret->args['include'] = $args;
150
-        return $ret;
151
-    }
142
+	/**
143
+	 * @param integer[] $args
144
+	 * @return stdClass
145
+	 */
146
+	public static function get_term_query_from_array_of_ids($args) {
147
+		$ret = new stdClass();
148
+		$ret->taxonomies = get_taxonomies();
149
+		$ret->args['include'] = $args;
150
+		return $ret;
151
+	}
152 152
 
153
-    /**
154
-     * @param string[] $args
155
-     * @return stdClass
156
-     */
157
-    public static function get_term_query_from_array_of_strings($args) {
158
-        $ret = new stdClass();
159
-        $ret->taxonomies = self::correct_taxonomy_names($args);
160
-        $ret->args = array();
161
-        return $ret;
162
-    }
153
+	/**
154
+	 * @param string[] $args
155
+	 * @return stdClass
156
+	 */
157
+	public static function get_term_query_from_array_of_strings($args) {
158
+		$ret = new stdClass();
159
+		$ret->taxonomies = self::correct_taxonomy_names($args);
160
+		$ret->args = array();
161
+		return $ret;
162
+	}
163 163
 
164
-    /**
165
-     * @param string|array $taxs
166
-     * @return array
167
-     */
168
-    private static function correct_taxonomy_names($taxs) {
169
-        if (is_string($taxs)) {
170
-            $taxs = array($taxs);
171
-        }
172
-        foreach ($taxs as &$tax) {
173
-            if ($tax == 'tags' || $tax == 'tag') {
174
-                $tax = 'post_tag';
175
-            } else if ($tax == 'categories') {
176
-                $tax = 'category';
177
-            }
178
-        }
179
-        return $taxs;
180
-    }
164
+	/**
165
+	 * @param string|array $taxs
166
+	 * @return array
167
+	 */
168
+	private static function correct_taxonomy_names($taxs) {
169
+		if (is_string($taxs)) {
170
+			$taxs = array($taxs);
171
+		}
172
+		foreach ($taxs as &$tax) {
173
+			if ($tax == 'tags' || $tax == 'tag') {
174
+				$tax = 'post_tag';
175
+			} else if ($tax == 'categories') {
176
+				$tax = 'category';
177
+			}
178
+		}
179
+		return $taxs;
180
+	}
181 181
 
182 182
 }
Please login to merge, or discard this patch.
lib/timber-term.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -333,7 +333,7 @@
 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/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.