@@ -21,360 +21,360 @@ |
||
21 | 21 | */ |
22 | 22 | class TimberComment extends TimberCore implements TimberCoreInterface { |
23 | 23 | |
24 | - public $PostClass = 'TimberPost'; |
|
25 | - public $object_type = 'comment'; |
|
24 | + public $PostClass = 'TimberPost'; |
|
25 | + public $object_type = 'comment'; |
|
26 | 26 | |
27 | - public static $representation = 'comment'; |
|
27 | + public static $representation = 'comment'; |
|
28 | 28 | |
29 | - public $ID; |
|
30 | - public $id; |
|
31 | - public $comment_author_email; |
|
32 | - public $comment_content; |
|
33 | - public $comment_date; |
|
34 | - public $comment_ID; |
|
35 | - public $user_id; |
|
36 | - public $comment_author; |
|
29 | + public $ID; |
|
30 | + public $id; |
|
31 | + public $comment_author_email; |
|
32 | + public $comment_content; |
|
33 | + public $comment_date; |
|
34 | + public $comment_ID; |
|
35 | + public $user_id; |
|
36 | + public $comment_author; |
|
37 | 37 | |
38 | - public $children = array(); |
|
38 | + public $children = array(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param int $cid |
|
42 | - */ |
|
43 | - function __construct($cid) { |
|
44 | - $this->init($cid); |
|
45 | - } |
|
40 | + /** |
|
41 | + * @param int $cid |
|
42 | + */ |
|
43 | + function __construct($cid) { |
|
44 | + $this->init($cid); |
|
45 | + } |
|
46 | 46 | |
47 | - function __toString() { |
|
48 | - return $this->content(); |
|
49 | - } |
|
47 | + function __toString() { |
|
48 | + return $this->content(); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @internal |
|
53 | - * @param integer $cid |
|
54 | - */ |
|
55 | - function init($cid) { |
|
56 | - $comment_data = $cid; |
|
57 | - if (is_integer($cid)) { |
|
58 | - $comment_data = get_comment($cid); |
|
59 | - } |
|
60 | - $this->import($comment_data); |
|
61 | - $this->ID = $this->comment_ID; |
|
62 | - $this->id = $this->comment_ID; |
|
63 | - $comment_meta_data = $this->get_meta_fields($this->ID); |
|
64 | - $this->import($comment_meta_data); |
|
65 | - } |
|
51 | + /** |
|
52 | + * @internal |
|
53 | + * @param integer $cid |
|
54 | + */ |
|
55 | + function init($cid) { |
|
56 | + $comment_data = $cid; |
|
57 | + if (is_integer($cid)) { |
|
58 | + $comment_data = get_comment($cid); |
|
59 | + } |
|
60 | + $this->import($comment_data); |
|
61 | + $this->ID = $this->comment_ID; |
|
62 | + $this->id = $this->comment_ID; |
|
63 | + $comment_meta_data = $this->get_meta_fields($this->ID); |
|
64 | + $this->import($comment_meta_data); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @api |
|
69 | - * @example |
|
70 | - * ```twig |
|
71 | - * <h3>Comments by...</h3> |
|
72 | - * <ol> |
|
73 | - * {% for comment in post.comments %} |
|
74 | - * <li>{{comment.author.name}}, who is a {{comment.author.role}}</li> |
|
75 | - * {% endfor %} |
|
76 | - * </ol> |
|
77 | - * ``` |
|
78 | - * ```html |
|
79 | - * <h3>Comments by...</h3> |
|
80 | - * <ol> |
|
81 | - * <li>Jared Novack, who is a contributor</li> |
|
82 | - * <li>Katie Ricci, who is a subscriber</li> |
|
83 | - * <li>Rebecca Pearl, who is a author</li> |
|
84 | - * </ol> |
|
85 | - * ``` |
|
86 | - * @return TimberUser |
|
87 | - */ |
|
88 | - public function author() { |
|
89 | - if ($this->user_id) { |
|
90 | - return new TimberUser($this->user_id); |
|
91 | - } else { |
|
92 | - $author = new TimberUser(0); |
|
93 | - if (isset($this->comment_author) && $this->comment_author) { |
|
94 | - $author->name = $this->comment_author; |
|
95 | - } else { |
|
96 | - $author->name = 'Anonymous'; |
|
97 | - } |
|
98 | - } |
|
99 | - return $author; |
|
100 | - } |
|
67 | + /** |
|
68 | + * @api |
|
69 | + * @example |
|
70 | + * ```twig |
|
71 | + * <h3>Comments by...</h3> |
|
72 | + * <ol> |
|
73 | + * {% for comment in post.comments %} |
|
74 | + * <li>{{comment.author.name}}, who is a {{comment.author.role}}</li> |
|
75 | + * {% endfor %} |
|
76 | + * </ol> |
|
77 | + * ``` |
|
78 | + * ```html |
|
79 | + * <h3>Comments by...</h3> |
|
80 | + * <ol> |
|
81 | + * <li>Jared Novack, who is a contributor</li> |
|
82 | + * <li>Katie Ricci, who is a subscriber</li> |
|
83 | + * <li>Rebecca Pearl, who is a author</li> |
|
84 | + * </ol> |
|
85 | + * ``` |
|
86 | + * @return TimberUser |
|
87 | + */ |
|
88 | + public function author() { |
|
89 | + if ($this->user_id) { |
|
90 | + return new TimberUser($this->user_id); |
|
91 | + } else { |
|
92 | + $author = new TimberUser(0); |
|
93 | + if (isset($this->comment_author) && $this->comment_author) { |
|
94 | + $author->name = $this->comment_author; |
|
95 | + } else { |
|
96 | + $author->name = 'Anonymous'; |
|
97 | + } |
|
98 | + } |
|
99 | + return $author; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Fetches the Gravatar |
|
104 | - * @api |
|
105 | - * @example |
|
106 | - * ```twig |
|
107 | - * <img src="{{comment.avatar(36,template_uri~"/img/dude.jpg")}}" alt="Image of {{comment.author.name}}" /> |
|
108 | - * ``` |
|
109 | - * ```html |
|
110 | - * <img src="http://gravatar.com/i/sfsfsdfasdfsfa.jpg" alt="Image of Katherine Rich" /> |
|
111 | - * ``` |
|
112 | - * @param int $size |
|
113 | - * @param string $default |
|
114 | - * @return bool|mixed|string |
|
115 | - */ |
|
116 | - public function avatar($size = 92, $default = '') { |
|
117 | - if (!get_option('show_avatars')) { |
|
118 | - return false; |
|
119 | - } |
|
120 | - if (!is_numeric($size)) { |
|
121 | - $size = '92'; |
|
122 | - } |
|
102 | + /** |
|
103 | + * Fetches the Gravatar |
|
104 | + * @api |
|
105 | + * @example |
|
106 | + * ```twig |
|
107 | + * <img src="{{comment.avatar(36,template_uri~"/img/dude.jpg")}}" alt="Image of {{comment.author.name}}" /> |
|
108 | + * ``` |
|
109 | + * ```html |
|
110 | + * <img src="http://gravatar.com/i/sfsfsdfasdfsfa.jpg" alt="Image of Katherine Rich" /> |
|
111 | + * ``` |
|
112 | + * @param int $size |
|
113 | + * @param string $default |
|
114 | + * @return bool|mixed|string |
|
115 | + */ |
|
116 | + public function avatar($size = 92, $default = '') { |
|
117 | + if (!get_option('show_avatars')) { |
|
118 | + return false; |
|
119 | + } |
|
120 | + if (!is_numeric($size)) { |
|
121 | + $size = '92'; |
|
122 | + } |
|
123 | 123 | |
124 | - $email = $this->avatar_email(); |
|
125 | - $email_hash = ''; |
|
126 | - if (!empty($email)) { |
|
127 | - $email_hash = md5(strtolower(trim($email))); |
|
128 | - } |
|
129 | - $host = $this->avatar_host($email_hash); |
|
130 | - $default = $this->avatar_default($default, $email, $size, $host); |
|
131 | - if (!empty($email)) { |
|
132 | - $avatar = $this->avatar_out($default, $host, $email_hash, $size); |
|
133 | - } else { |
|
134 | - $avatar = $default; |
|
135 | - } |
|
136 | - return $avatar; |
|
137 | - } |
|
124 | + $email = $this->avatar_email(); |
|
125 | + $email_hash = ''; |
|
126 | + if (!empty($email)) { |
|
127 | + $email_hash = md5(strtolower(trim($email))); |
|
128 | + } |
|
129 | + $host = $this->avatar_host($email_hash); |
|
130 | + $default = $this->avatar_default($default, $email, $size, $host); |
|
131 | + if (!empty($email)) { |
|
132 | + $avatar = $this->avatar_out($default, $host, $email_hash, $size); |
|
133 | + } else { |
|
134 | + $avatar = $default; |
|
135 | + } |
|
136 | + return $avatar; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @api |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function content() { |
|
144 | - return apply_filters('get_comment_text ', $this->comment_content); |
|
145 | - } |
|
139 | + /** |
|
140 | + * @api |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function content() { |
|
144 | + return apply_filters('get_comment_text ', $this->comment_content); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @api |
|
149 | - * @example |
|
150 | - * ```twig |
|
151 | - * {% if comment.approved %} |
|
152 | - * Your comment is good |
|
153 | - * {% else %} |
|
154 | - * Do you kiss your mother with that mouth? |
|
155 | - * {% endif %} |
|
156 | - * ``` |
|
157 | - * @return boolean |
|
158 | - */ |
|
159 | - public function approved() { |
|
160 | - return $this->comment_approved; |
|
161 | - } |
|
147 | + /** |
|
148 | + * @api |
|
149 | + * @example |
|
150 | + * ```twig |
|
151 | + * {% if comment.approved %} |
|
152 | + * Your comment is good |
|
153 | + * {% else %} |
|
154 | + * Do you kiss your mother with that mouth? |
|
155 | + * {% endif %} |
|
156 | + * ``` |
|
157 | + * @return boolean |
|
158 | + */ |
|
159 | + public function approved() { |
|
160 | + return $this->comment_approved; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @api |
|
165 | - * @example |
|
166 | - * ```twig |
|
167 | - * {% for comment in post.comments %} |
|
168 | - * <article class="comment"> |
|
169 | - * <p class="date">Posted on {{ comment.date }}:</p> |
|
170 | - * <p class="comment">{{ comment.content }}</p> |
|
171 | - * </article> |
|
172 | - * {% endfor %} |
|
173 | - * ``` |
|
174 | - * ```html |
|
175 | - * <article class="comment"> |
|
176 | - * <p class="date">Posted on September 28, 2015:</p> |
|
177 | - * <p class="comment">Happy Birthday!</p> |
|
178 | - * </article> |
|
179 | - * ``` |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function date( $date_format = '' ) { |
|
183 | - $df = $date_format ? $date_format : get_option('date_format'); |
|
184 | - $the_date = (string)mysql2date($df, $this->comment_date); |
|
185 | - return apply_filters('get_comment_date ', $the_date, $df); |
|
186 | - } |
|
163 | + /** |
|
164 | + * @api |
|
165 | + * @example |
|
166 | + * ```twig |
|
167 | + * {% for comment in post.comments %} |
|
168 | + * <article class="comment"> |
|
169 | + * <p class="date">Posted on {{ comment.date }}:</p> |
|
170 | + * <p class="comment">{{ comment.content }}</p> |
|
171 | + * </article> |
|
172 | + * {% endfor %} |
|
173 | + * ``` |
|
174 | + * ```html |
|
175 | + * <article class="comment"> |
|
176 | + * <p class="date">Posted on September 28, 2015:</p> |
|
177 | + * <p class="comment">Happy Birthday!</p> |
|
178 | + * </article> |
|
179 | + * ``` |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function date( $date_format = '' ) { |
|
183 | + $df = $date_format ? $date_format : get_option('date_format'); |
|
184 | + $the_date = (string)mysql2date($df, $this->comment_date); |
|
185 | + return apply_filters('get_comment_date ', $the_date, $df); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @api |
|
190 | - * @example |
|
191 | - * ```twig |
|
192 | - * {% for comment in post.comments %} |
|
193 | - * <article class="comment"> |
|
194 | - * <p class="date">Posted on {{ comment.date }} at {{comment.time}}:</p> |
|
195 | - * <p class="comment">{{ comment.content }}</p> |
|
196 | - * </article> |
|
197 | - * {% endfor %} |
|
198 | - * ``` |
|
199 | - * ```html |
|
200 | - * <article class="comment"> |
|
201 | - * <p class="date">Posted on September 28, 2015 at 12:45 am:</p> |
|
202 | - * <p class="comment">Happy Birthday!</p> |
|
203 | - * </article> |
|
204 | - * ``` |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function time( $time_format = '' ) { |
|
208 | - $tf = $time_format ? $time_format : get_option('time_format'); |
|
209 | - $the_time = (string)mysql2date($tf, $this->comment_date); |
|
210 | - return apply_filters('get_comment_time', $the_time, $tf); |
|
211 | - } |
|
188 | + /** |
|
189 | + * @api |
|
190 | + * @example |
|
191 | + * ```twig |
|
192 | + * {% for comment in post.comments %} |
|
193 | + * <article class="comment"> |
|
194 | + * <p class="date">Posted on {{ comment.date }} at {{comment.time}}:</p> |
|
195 | + * <p class="comment">{{ comment.content }}</p> |
|
196 | + * </article> |
|
197 | + * {% endfor %} |
|
198 | + * ``` |
|
199 | + * ```html |
|
200 | + * <article class="comment"> |
|
201 | + * <p class="date">Posted on September 28, 2015 at 12:45 am:</p> |
|
202 | + * <p class="comment">Happy Birthday!</p> |
|
203 | + * </article> |
|
204 | + * ``` |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public function time( $time_format = '' ) { |
|
208 | + $tf = $time_format ? $time_format : get_option('time_format'); |
|
209 | + $the_time = (string)mysql2date($tf, $this->comment_date); |
|
210 | + return apply_filters('get_comment_time', $the_time, $tf); |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * @param string $field_name |
|
215 | - * @return mixed |
|
216 | - */ |
|
217 | - public function meta($field_name) { |
|
218 | - return $this->get_meta_field($field_name); |
|
219 | - } |
|
213 | + /** |
|
214 | + * @param string $field_name |
|
215 | + * @return mixed |
|
216 | + */ |
|
217 | + public function meta($field_name) { |
|
218 | + return $this->get_meta_field($field_name); |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * @api |
|
223 | - * @return bool |
|
224 | - */ |
|
225 | - public function is_child() { |
|
226 | - return $this->comment_parent > 0; |
|
227 | - } |
|
221 | + /** |
|
222 | + * @api |
|
223 | + * @return bool |
|
224 | + */ |
|
225 | + public function is_child() { |
|
226 | + return $this->comment_parent > 0; |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * @internal |
|
231 | - * @param int $comment_id |
|
232 | - * @return mixed |
|
233 | - */ |
|
234 | - protected function get_meta_fields($comment_id = null) { |
|
235 | - if ($comment_id === null) { |
|
236 | - $comment_id = $this->ID; |
|
237 | - } |
|
238 | - //Could not find a WP function to fetch all comment meta data, so I made one. |
|
239 | - apply_filters('timber_comment_get_meta_pre', array(), $comment_id); |
|
240 | - $comment_metas = get_comment_meta($comment_id); |
|
241 | - foreach ($comment_metas as &$cm) { |
|
242 | - if (is_array($cm) && count($cm) == 1) { |
|
243 | - $cm = $cm[0]; |
|
244 | - } |
|
245 | - } |
|
246 | - $comment_metas = apply_filters('timber_comment_get_meta', $comment_metas, $comment_id); |
|
247 | - return $comment_metas; |
|
248 | - } |
|
229 | + /** |
|
230 | + * @internal |
|
231 | + * @param int $comment_id |
|
232 | + * @return mixed |
|
233 | + */ |
|
234 | + protected function get_meta_fields($comment_id = null) { |
|
235 | + if ($comment_id === null) { |
|
236 | + $comment_id = $this->ID; |
|
237 | + } |
|
238 | + //Could not find a WP function to fetch all comment meta data, so I made one. |
|
239 | + apply_filters('timber_comment_get_meta_pre', array(), $comment_id); |
|
240 | + $comment_metas = get_comment_meta($comment_id); |
|
241 | + foreach ($comment_metas as &$cm) { |
|
242 | + if (is_array($cm) && count($cm) == 1) { |
|
243 | + $cm = $cm[0]; |
|
244 | + } |
|
245 | + } |
|
246 | + $comment_metas = apply_filters('timber_comment_get_meta', $comment_metas, $comment_id); |
|
247 | + return $comment_metas; |
|
248 | + } |
|
249 | 249 | |
250 | - /** |
|
251 | - * @internal |
|
252 | - * @param string $field_name |
|
253 | - * @return mixed |
|
254 | - */ |
|
255 | - protected function get_meta_field($field_name) { |
|
256 | - $value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this); |
|
257 | - if ($value === null) { |
|
258 | - $value = get_comment_meta($this->ID, $field_name, true); |
|
259 | - } |
|
260 | - $value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this); |
|
261 | - return $value; |
|
262 | - } |
|
250 | + /** |
|
251 | + * @internal |
|
252 | + * @param string $field_name |
|
253 | + * @return mixed |
|
254 | + */ |
|
255 | + protected function get_meta_field($field_name) { |
|
256 | + $value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this); |
|
257 | + if ($value === null) { |
|
258 | + $value = get_comment_meta($this->ID, $field_name, true); |
|
259 | + } |
|
260 | + $value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this); |
|
261 | + return $value; |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * Enqueue the WP threaded comments javascript, |
|
266 | - * and fetch the reply link for various comments. |
|
267 | - * @api |
|
268 | - * @return string |
|
269 | - */ |
|
270 | - public function reply_link( $reply_text = 'Reply' ) { |
|
271 | - if ( is_singular() && comments_open() && get_option('thread_comments') ) { |
|
272 | - wp_enqueue_script( 'comment-reply' ); |
|
273 | - } |
|
264 | + /** |
|
265 | + * Enqueue the WP threaded comments javascript, |
|
266 | + * and fetch the reply link for various comments. |
|
267 | + * @api |
|
268 | + * @return string |
|
269 | + */ |
|
270 | + public function reply_link( $reply_text = 'Reply' ) { |
|
271 | + if ( is_singular() && comments_open() && get_option('thread_comments') ) { |
|
272 | + wp_enqueue_script( 'comment-reply' ); |
|
273 | + } |
|
274 | 274 | |
275 | - // Get the comments depth option from the admin panel |
|
276 | - $max_depth = get_option('thread_comments_depth'); |
|
275 | + // Get the comments depth option from the admin panel |
|
276 | + $max_depth = get_option('thread_comments_depth'); |
|
277 | 277 | |
278 | - // Default args |
|
279 | - $args = array( |
|
280 | - 'add_below' => 'comment', |
|
281 | - 'respond_id' => 'respond', |
|
282 | - 'reply_text' => $reply_text, |
|
283 | - 'depth' => 1, |
|
284 | - 'max_depth' => $max_depth, |
|
285 | - ); |
|
278 | + // Default args |
|
279 | + $args = array( |
|
280 | + 'add_below' => 'comment', |
|
281 | + 'respond_id' => 'respond', |
|
282 | + 'reply_text' => $reply_text, |
|
283 | + 'depth' => 1, |
|
284 | + 'max_depth' => $max_depth, |
|
285 | + ); |
|
286 | 286 | |
287 | - return get_comment_reply_link( $args, $this->ID, $this->post_id ); |
|
288 | - } |
|
287 | + return get_comment_reply_link( $args, $this->ID, $this->post_id ); |
|
288 | + } |
|
289 | 289 | |
290 | - /* AVATAR Stuff |
|
290 | + /* AVATAR Stuff |
|
291 | 291 | ======================= */ |
292 | 292 | |
293 | - /** |
|
294 | - * @internal |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - protected function avatar_email() { |
|
298 | - $id = (int)$this->user_id; |
|
299 | - $user = get_userdata($id); |
|
300 | - if ($user) { |
|
301 | - $email = $user->user_email; |
|
302 | - } else { |
|
303 | - $email = $this->comment_author_email; |
|
304 | - } |
|
305 | - return $email; |
|
306 | - } |
|
293 | + /** |
|
294 | + * @internal |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + protected function avatar_email() { |
|
298 | + $id = (int)$this->user_id; |
|
299 | + $user = get_userdata($id); |
|
300 | + if ($user) { |
|
301 | + $email = $user->user_email; |
|
302 | + } else { |
|
303 | + $email = $this->comment_author_email; |
|
304 | + } |
|
305 | + return $email; |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * @internal |
|
310 | - * @param string $email_hash |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - protected function avatar_host($email_hash) { |
|
314 | - if (is_ssl()) { |
|
315 | - $host = 'https://secure.gravatar.com'; |
|
316 | - } else { |
|
317 | - if (!empty($email_hash)) { |
|
318 | - $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2)); |
|
319 | - } else { |
|
320 | - $host = 'http://0.gravatar.com'; |
|
321 | - } |
|
322 | - } |
|
323 | - return $host; |
|
324 | - } |
|
308 | + /** |
|
309 | + * @internal |
|
310 | + * @param string $email_hash |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + protected function avatar_host($email_hash) { |
|
314 | + if (is_ssl()) { |
|
315 | + $host = 'https://secure.gravatar.com'; |
|
316 | + } else { |
|
317 | + if (!empty($email_hash)) { |
|
318 | + $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2)); |
|
319 | + } else { |
|
320 | + $host = 'http://0.gravatar.com'; |
|
321 | + } |
|
322 | + } |
|
323 | + return $host; |
|
324 | + } |
|
325 | 325 | |
326 | - /** |
|
327 | - * @internal |
|
328 | - * @todo what if it's relative? |
|
329 | - * @param string $default |
|
330 | - * @param string $email |
|
331 | - * @param string $size |
|
332 | - * @param string $host |
|
333 | - * @return string |
|
334 | - */ |
|
335 | - protected function avatar_default($default, $email, $size, $host) { |
|
336 | - if (substr($default, 0, 1) == '/') { |
|
337 | - $default = home_url() . $default; |
|
338 | - } |
|
326 | + /** |
|
327 | + * @internal |
|
328 | + * @todo what if it's relative? |
|
329 | + * @param string $default |
|
330 | + * @param string $email |
|
331 | + * @param string $size |
|
332 | + * @param string $host |
|
333 | + * @return string |
|
334 | + */ |
|
335 | + protected function avatar_default($default, $email, $size, $host) { |
|
336 | + if (substr($default, 0, 1) == '/') { |
|
337 | + $default = home_url() . $default; |
|
338 | + } |
|
339 | 339 | |
340 | - if (empty($default)) { |
|
341 | - $avatar_default = get_option('avatar_default'); |
|
342 | - if (empty($avatar_default)) { |
|
343 | - $default = 'mystery'; |
|
344 | - } else { |
|
345 | - $default = $avatar_default; |
|
346 | - } |
|
347 | - } |
|
348 | - if ('mystery' == $default) { |
|
349 | - $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size; |
|
350 | - // ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]') |
|
351 | - } else if ('blank' == $default) { |
|
352 | - $default = $email ? 'blank' : includes_url('images/blank.gif'); |
|
353 | - } else if (!empty($email) && 'gravatar_default' == $default) { |
|
354 | - $default = ''; |
|
355 | - } else if ('gravatar_default' == $default) { |
|
356 | - $default = $host . '/avatar/?s=' . $size; |
|
357 | - } else if (empty($email) && !strstr($default, 'http://')) { |
|
358 | - $default = $host . '/avatar/?d=' . $default . '&s=' . $size; |
|
359 | - } |
|
360 | - return $default; |
|
361 | - } |
|
340 | + if (empty($default)) { |
|
341 | + $avatar_default = get_option('avatar_default'); |
|
342 | + if (empty($avatar_default)) { |
|
343 | + $default = 'mystery'; |
|
344 | + } else { |
|
345 | + $default = $avatar_default; |
|
346 | + } |
|
347 | + } |
|
348 | + if ('mystery' == $default) { |
|
349 | + $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size; |
|
350 | + // ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]') |
|
351 | + } else if ('blank' == $default) { |
|
352 | + $default = $email ? 'blank' : includes_url('images/blank.gif'); |
|
353 | + } else if (!empty($email) && 'gravatar_default' == $default) { |
|
354 | + $default = ''; |
|
355 | + } else if ('gravatar_default' == $default) { |
|
356 | + $default = $host . '/avatar/?s=' . $size; |
|
357 | + } else if (empty($email) && !strstr($default, 'http://')) { |
|
358 | + $default = $host . '/avatar/?d=' . $default . '&s=' . $size; |
|
359 | + } |
|
360 | + return $default; |
|
361 | + } |
|
362 | 362 | |
363 | - /** |
|
364 | - * @internal |
|
365 | - * @param string $default |
|
366 | - * @param string $host |
|
367 | - * @param string $email_hash |
|
368 | - * @param string $size |
|
369 | - * @return mixed |
|
370 | - */ |
|
371 | - protected function avatar_out($default, $host, $email_hash, $size) { |
|
372 | - $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&d=' . urlencode($default); |
|
373 | - $rating = get_option('avatar_rating'); |
|
374 | - if (!empty($rating)) { |
|
375 | - $out .= '&r=' . $rating; |
|
376 | - } |
|
377 | - return str_replace('&', '&', esc_url($out)); |
|
378 | - } |
|
363 | + /** |
|
364 | + * @internal |
|
365 | + * @param string $default |
|
366 | + * @param string $host |
|
367 | + * @param string $email_hash |
|
368 | + * @param string $size |
|
369 | + * @return mixed |
|
370 | + */ |
|
371 | + protected function avatar_out($default, $host, $email_hash, $size) { |
|
372 | + $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&d=' . urlencode($default); |
|
373 | + $rating = get_option('avatar_rating'); |
|
374 | + if (!empty($rating)) { |
|
375 | + $out .= '&r=' . $rating; |
|
376 | + } |
|
377 | + return str_replace('&', '&', esc_url($out)); |
|
378 | + } |
|
379 | 379 | |
380 | 380 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @param int $cid |
42 | 42 | */ |
43 | - function __construct($cid) { |
|
43 | + function __construct( $cid ) { |
|
44 | 44 | $this->init($cid); |
45 | 45 | } |
46 | 46 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * @internal |
53 | 53 | * @param integer $cid |
54 | 54 | */ |
55 | - function init($cid) { |
|
55 | + function init( $cid ) { |
|
56 | 56 | $comment_data = $cid; |
57 | - if (is_integer($cid)) { |
|
57 | + if ( is_integer($cid) ) { |
|
58 | 58 | $comment_data = get_comment($cid); |
59 | 59 | } |
60 | 60 | $this->import($comment_data); |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | * @return TimberUser |
87 | 87 | */ |
88 | 88 | public function author() { |
89 | - if ($this->user_id) { |
|
89 | + if ( $this->user_id ) { |
|
90 | 90 | return new TimberUser($this->user_id); |
91 | 91 | } else { |
92 | 92 | $author = new TimberUser(0); |
93 | - if (isset($this->comment_author) && $this->comment_author) { |
|
93 | + if ( isset($this->comment_author) && $this->comment_author ) { |
|
94 | 94 | $author->name = $this->comment_author; |
95 | 95 | } else { |
96 | 96 | $author->name = 'Anonymous'; |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | * @param string $default |
114 | 114 | * @return bool|mixed|string |
115 | 115 | */ |
116 | - public function avatar($size = 92, $default = '') { |
|
117 | - if (!get_option('show_avatars')) { |
|
116 | + public function avatar( $size = 92, $default = '' ) { |
|
117 | + if ( !get_option('show_avatars') ) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | - if (!is_numeric($size)) { |
|
120 | + if ( !is_numeric($size) ) { |
|
121 | 121 | $size = '92'; |
122 | 122 | } |
123 | 123 | |
124 | 124 | $email = $this->avatar_email(); |
125 | 125 | $email_hash = ''; |
126 | - if (!empty($email)) { |
|
126 | + if ( !empty($email) ) { |
|
127 | 127 | $email_hash = md5(strtolower(trim($email))); |
128 | 128 | } |
129 | 129 | $host = $this->avatar_host($email_hash); |
130 | 130 | $default = $this->avatar_default($default, $email, $size, $host); |
131 | - if (!empty($email)) { |
|
131 | + if ( !empty($email) ) { |
|
132 | 132 | $avatar = $this->avatar_out($default, $host, $email_hash, $size); |
133 | 133 | } else { |
134 | 134 | $avatar = $default; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function date( $date_format = '' ) { |
183 | 183 | $df = $date_format ? $date_format : get_option('date_format'); |
184 | - $the_date = (string)mysql2date($df, $this->comment_date); |
|
184 | + $the_date = (string) mysql2date($df, $this->comment_date); |
|
185 | 185 | return apply_filters('get_comment_date ', $the_date, $df); |
186 | 186 | } |
187 | 187 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function time( $time_format = '' ) { |
208 | 208 | $tf = $time_format ? $time_format : get_option('time_format'); |
209 | - $the_time = (string)mysql2date($tf, $this->comment_date); |
|
209 | + $the_time = (string) mysql2date($tf, $this->comment_date); |
|
210 | 210 | return apply_filters('get_comment_time', $the_time, $tf); |
211 | 211 | } |
212 | 212 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param string $field_name |
215 | 215 | * @return mixed |
216 | 216 | */ |
217 | - public function meta($field_name) { |
|
217 | + public function meta( $field_name ) { |
|
218 | 218 | return $this->get_meta_field($field_name); |
219 | 219 | } |
220 | 220 | |
@@ -231,15 +231,15 @@ discard block |
||
231 | 231 | * @param int $comment_id |
232 | 232 | * @return mixed |
233 | 233 | */ |
234 | - protected function get_meta_fields($comment_id = null) { |
|
235 | - if ($comment_id === null) { |
|
234 | + protected function get_meta_fields( $comment_id = null ) { |
|
235 | + if ( $comment_id === null ) { |
|
236 | 236 | $comment_id = $this->ID; |
237 | 237 | } |
238 | 238 | //Could not find a WP function to fetch all comment meta data, so I made one. |
239 | 239 | apply_filters('timber_comment_get_meta_pre', array(), $comment_id); |
240 | 240 | $comment_metas = get_comment_meta($comment_id); |
241 | - foreach ($comment_metas as &$cm) { |
|
242 | - if (is_array($cm) && count($cm) == 1) { |
|
241 | + foreach ( $comment_metas as &$cm ) { |
|
242 | + if ( is_array($cm) && count($cm) == 1 ) { |
|
243 | 243 | $cm = $cm[0]; |
244 | 244 | } |
245 | 245 | } |
@@ -252,9 +252,9 @@ discard block |
||
252 | 252 | * @param string $field_name |
253 | 253 | * @return mixed |
254 | 254 | */ |
255 | - protected function get_meta_field($field_name) { |
|
255 | + protected function get_meta_field( $field_name ) { |
|
256 | 256 | $value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this); |
257 | - if ($value === null) { |
|
257 | + if ( $value === null ) { |
|
258 | 258 | $value = get_comment_meta($this->ID, $field_name, true); |
259 | 259 | } |
260 | 260 | $value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this); |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function reply_link( $reply_text = 'Reply' ) { |
271 | 271 | if ( is_singular() && comments_open() && get_option('thread_comments') ) { |
272 | - wp_enqueue_script( 'comment-reply' ); |
|
272 | + wp_enqueue_script('comment-reply'); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | // Get the comments depth option from the admin panel |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | 'max_depth' => $max_depth, |
285 | 285 | ); |
286 | 286 | |
287 | - return get_comment_reply_link( $args, $this->ID, $this->post_id ); |
|
287 | + return get_comment_reply_link($args, $this->ID, $this->post_id); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /* AVATAR Stuff |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | * @return string |
296 | 296 | */ |
297 | 297 | protected function avatar_email() { |
298 | - $id = (int)$this->user_id; |
|
298 | + $id = (int) $this->user_id; |
|
299 | 299 | $user = get_userdata($id); |
300 | - if ($user) { |
|
300 | + if ( $user ) { |
|
301 | 301 | $email = $user->user_email; |
302 | 302 | } else { |
303 | 303 | $email = $this->comment_author_email; |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | * @param string $email_hash |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - protected function avatar_host($email_hash) { |
|
314 | - if (is_ssl()) { |
|
313 | + protected function avatar_host( $email_hash ) { |
|
314 | + if ( is_ssl() ) { |
|
315 | 315 | $host = 'https://secure.gravatar.com'; |
316 | 316 | } else { |
317 | - if (!empty($email_hash)) { |
|
317 | + if ( !empty($email_hash) ) { |
|
318 | 318 | $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2)); |
319 | 319 | } else { |
320 | 320 | $host = 'http://0.gravatar.com'; |
@@ -332,29 +332,29 @@ discard block |
||
332 | 332 | * @param string $host |
333 | 333 | * @return string |
334 | 334 | */ |
335 | - protected function avatar_default($default, $email, $size, $host) { |
|
336 | - if (substr($default, 0, 1) == '/') { |
|
335 | + protected function avatar_default( $default, $email, $size, $host ) { |
|
336 | + if ( substr($default, 0, 1) == '/' ) { |
|
337 | 337 | $default = home_url() . $default; |
338 | 338 | } |
339 | 339 | |
340 | - if (empty($default)) { |
|
340 | + if ( empty($default) ) { |
|
341 | 341 | $avatar_default = get_option('avatar_default'); |
342 | - if (empty($avatar_default)) { |
|
342 | + if ( empty($avatar_default) ) { |
|
343 | 343 | $default = 'mystery'; |
344 | 344 | } else { |
345 | 345 | $default = $avatar_default; |
346 | 346 | } |
347 | 347 | } |
348 | - if ('mystery' == $default) { |
|
348 | + if ( 'mystery' == $default ) { |
|
349 | 349 | $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size; |
350 | 350 | // ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]') |
351 | - } else if ('blank' == $default) { |
|
351 | + } else if ( 'blank' == $default ) { |
|
352 | 352 | $default = $email ? 'blank' : includes_url('images/blank.gif'); |
353 | - } else if (!empty($email) && 'gravatar_default' == $default) { |
|
353 | + } else if ( !empty($email) && 'gravatar_default' == $default ) { |
|
354 | 354 | $default = ''; |
355 | - } else if ('gravatar_default' == $default) { |
|
355 | + } else if ( 'gravatar_default' == $default ) { |
|
356 | 356 | $default = $host . '/avatar/?s=' . $size; |
357 | - } else if (empty($email) && !strstr($default, 'http://')) { |
|
357 | + } else if ( empty($email) && !strstr($default, 'http://') ) { |
|
358 | 358 | $default = $host . '/avatar/?d=' . $default . '&s=' . $size; |
359 | 359 | } |
360 | 360 | return $default; |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | * @param string $size |
369 | 369 | * @return mixed |
370 | 370 | */ |
371 | - protected function avatar_out($default, $host, $email_hash, $size) { |
|
371 | + protected function avatar_out( $default, $host, $email_hash, $size ) { |
|
372 | 372 | $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&d=' . urlencode($default); |
373 | 373 | $rating = get_option('avatar_rating'); |
374 | - if (!empty($rating)) { |
|
374 | + if ( !empty($rating) ) { |
|
375 | 375 | $out .= '&r=' . $rating; |
376 | 376 | } |
377 | 377 | return str_replace('&', '&', esc_url($out)); |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | interface TimberCoreInterface { |
4 | 4 | |
5 | - public function __call( $field, $args ); |
|
5 | + public function __call( $field, $args ); |
|
6 | 6 | |
7 | - public function __get( $field ); |
|
7 | + public function __get( $field ); |
|
8 | 8 | |
9 | - /** |
|
10 | - * @return boolean |
|
11 | - */ |
|
12 | - public function __isset( $field ); |
|
9 | + /** |
|
10 | + * @return boolean |
|
11 | + */ |
|
12 | + public function __isset( $field ); |
|
13 | 13 | |
14 | - public function meta( $key ); |
|
14 | + public function meta( $key ); |
|
15 | 15 | |
16 | 16 | } |
@@ -2,91 +2,91 @@ |
||
2 | 2 | |
3 | 3 | class TimberFunctionWrapper { |
4 | 4 | |
5 | - private $_class; |
|
6 | - private $_function; |
|
7 | - private $_args; |
|
8 | - private $_use_ob; |
|
5 | + private $_class; |
|
6 | + private $_function; |
|
7 | + private $_args; |
|
8 | + private $_use_ob; |
|
9 | 9 | |
10 | - public function __toString() { |
|
11 | - try { |
|
12 | - return (string)$this->call(); |
|
13 | - } catch (Exception $e) { |
|
14 | - return 'Caught exception: ' . $e->getMessage() . "\n"; |
|
15 | - } |
|
16 | - } |
|
10 | + public function __toString() { |
|
11 | + try { |
|
12 | + return (string)$this->call(); |
|
13 | + } catch (Exception $e) { |
|
14 | + return 'Caught exception: ' . $e->getMessage() . "\n"; |
|
15 | + } |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * |
|
20 | - * |
|
21 | - * @param callable $function |
|
22 | - * @param array $args |
|
23 | - * @param bool $return_output_buffer |
|
24 | - */ |
|
25 | - public function __construct( $function, $args = array(), $return_output_buffer = false ) { |
|
26 | - if( is_array( $function ) ) { |
|
27 | - if( (is_string( $function[0] ) && class_exists( $function[0] ) ) || gettype( $function[0] ) === 'object' ) { |
|
28 | - $this->_class = $function[0]; |
|
29 | - } |
|
18 | + /** |
|
19 | + * |
|
20 | + * |
|
21 | + * @param callable $function |
|
22 | + * @param array $args |
|
23 | + * @param bool $return_output_buffer |
|
24 | + */ |
|
25 | + public function __construct( $function, $args = array(), $return_output_buffer = false ) { |
|
26 | + if( is_array( $function ) ) { |
|
27 | + if( (is_string( $function[0] ) && class_exists( $function[0] ) ) || gettype( $function[0] ) === 'object' ) { |
|
28 | + $this->_class = $function[0]; |
|
29 | + } |
|
30 | 30 | |
31 | - if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
32 | - } else { |
|
33 | - $this->_function = $function; |
|
34 | - } |
|
31 | + if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
32 | + } else { |
|
33 | + $this->_function = $function; |
|
34 | + } |
|
35 | 35 | |
36 | - $this->_args = $args; |
|
37 | - $this->_use_ob = $return_output_buffer; |
|
36 | + $this->_args = $args; |
|
37 | + $this->_use_ob = $return_output_buffer; |
|
38 | 38 | |
39 | - add_filter( 'get_twig', array( &$this, 'add_to_twig' ) ); |
|
40 | - } |
|
39 | + add_filter( 'get_twig', array( &$this, 'add_to_twig' ) ); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * |
|
44 | - * |
|
45 | - * @param Twig_Environment $twig |
|
46 | - * @return Twig_Environment |
|
47 | - */ |
|
48 | - public function add_to_twig( $twig ) { |
|
49 | - $wrapper = $this; |
|
42 | + /** |
|
43 | + * |
|
44 | + * |
|
45 | + * @param Twig_Environment $twig |
|
46 | + * @return Twig_Environment |
|
47 | + */ |
|
48 | + public function add_to_twig( $twig ) { |
|
49 | + $wrapper = $this; |
|
50 | 50 | |
51 | - $twig->addFunction( new Twig_SimpleFunction( $this->_function, function () use ( $wrapper ) { |
|
52 | - return call_user_func_array( array( $wrapper, 'call' ), func_get_args() ); |
|
53 | - } ) ); |
|
51 | + $twig->addFunction( new Twig_SimpleFunction( $this->_function, function () use ( $wrapper ) { |
|
52 | + return call_user_func_array( array( $wrapper, 'call' ), func_get_args() ); |
|
53 | + } ) ); |
|
54 | 54 | |
55 | - return $twig; |
|
56 | - } |
|
55 | + return $twig; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function call() { |
|
64 | - $args = $this->_parse_args( func_get_args(), $this->_args ); |
|
65 | - $callable = ( isset( $this->_class ) ) ? array( $this->_class, $this->_function ) : $this->_function; |
|
58 | + /** |
|
59 | + * |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function call() { |
|
64 | + $args = $this->_parse_args( func_get_args(), $this->_args ); |
|
65 | + $callable = ( isset( $this->_class ) ) ? array( $this->_class, $this->_function ) : $this->_function; |
|
66 | 66 | |
67 | - if ( $this->_use_ob ) { |
|
68 | - return TimberHelper::ob_function( $callable, $args ); |
|
69 | - } else { |
|
70 | - return call_user_func_array( $callable, $args ); |
|
71 | - } |
|
72 | - } |
|
67 | + if ( $this->_use_ob ) { |
|
68 | + return TimberHelper::ob_function( $callable, $args ); |
|
69 | + } else { |
|
70 | + return call_user_func_array( $callable, $args ); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * |
|
76 | - * |
|
77 | - * @param array $args |
|
78 | - * @param array $defaults |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - private function _parse_args( $args, $defaults ) { |
|
82 | - $_arg = reset( $defaults ); |
|
74 | + /** |
|
75 | + * |
|
76 | + * |
|
77 | + * @param array $args |
|
78 | + * @param array $defaults |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + private function _parse_args( $args, $defaults ) { |
|
82 | + $_arg = reset( $defaults ); |
|
83 | 83 | |
84 | - foreach ( $args as $index => $arg ) { |
|
85 | - $defaults[$index] = is_null( $arg ) ? $_arg : $arg; |
|
86 | - $_arg = next( $defaults ); |
|
87 | - } |
|
84 | + foreach ( $args as $index => $arg ) { |
|
85 | + $defaults[$index] = is_null( $arg ) ? $_arg : $arg; |
|
86 | + $_arg = next( $defaults ); |
|
87 | + } |
|
88 | 88 | |
89 | - return $defaults; |
|
90 | - } |
|
89 | + return $defaults; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | } |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | |
10 | 10 | public function __toString() { |
11 | 11 | try { |
12 | - return (string)$this->call(); |
|
13 | - } catch (Exception $e) { |
|
12 | + return (string) $this->call(); |
|
13 | + } catch ( Exception $e ) { |
|
14 | 14 | return 'Caught exception: ' . $e->getMessage() . "\n"; |
15 | 15 | } |
16 | 16 | } |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | * @param bool $return_output_buffer |
24 | 24 | */ |
25 | 25 | public function __construct( $function, $args = array(), $return_output_buffer = false ) { |
26 | - if( is_array( $function ) ) { |
|
27 | - if( (is_string( $function[0] ) && class_exists( $function[0] ) ) || gettype( $function[0] ) === 'object' ) { |
|
26 | + if ( is_array($function) ) { |
|
27 | + if ( (is_string($function[0]) && class_exists($function[0])) || gettype($function[0]) === 'object' ) { |
|
28 | 28 | $this->_class = $function[0]; |
29 | 29 | } |
30 | 30 | |
31 | - if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
31 | + if ( is_string($function[1]) ) $this->_function = $function[1]; |
|
32 | 32 | } else { |
33 | 33 | $this->_function = $function; |
34 | 34 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $this->_args = $args; |
37 | 37 | $this->_use_ob = $return_output_buffer; |
38 | 38 | |
39 | - add_filter( 'get_twig', array( &$this, 'add_to_twig' ) ); |
|
39 | + add_filter('get_twig', array(&$this, 'add_to_twig')); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | public function add_to_twig( $twig ) { |
49 | 49 | $wrapper = $this; |
50 | 50 | |
51 | - $twig->addFunction( new Twig_SimpleFunction( $this->_function, function () use ( $wrapper ) { |
|
52 | - return call_user_func_array( array( $wrapper, 'call' ), func_get_args() ); |
|
53 | - } ) ); |
|
51 | + $twig->addFunction(new Twig_SimpleFunction($this->_function, function() use ($wrapper) { |
|
52 | + return call_user_func_array(array($wrapper, 'call'), func_get_args()); |
|
53 | + } )); |
|
54 | 54 | |
55 | 55 | return $twig; |
56 | 56 | } |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | public function call() { |
64 | - $args = $this->_parse_args( func_get_args(), $this->_args ); |
|
65 | - $callable = ( isset( $this->_class ) ) ? array( $this->_class, $this->_function ) : $this->_function; |
|
64 | + $args = $this->_parse_args(func_get_args(), $this->_args); |
|
65 | + $callable = (isset($this->_class)) ? array($this->_class, $this->_function) : $this->_function; |
|
66 | 66 | |
67 | 67 | if ( $this->_use_ob ) { |
68 | - return TimberHelper::ob_function( $callable, $args ); |
|
68 | + return TimberHelper::ob_function($callable, $args); |
|
69 | 69 | } else { |
70 | - return call_user_func_array( $callable, $args ); |
|
70 | + return call_user_func_array($callable, $args); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | * @return array |
80 | 80 | */ |
81 | 81 | private function _parse_args( $args, $defaults ) { |
82 | - $_arg = reset( $defaults ); |
|
82 | + $_arg = reset($defaults); |
|
83 | 83 | |
84 | 84 | foreach ( $args as $index => $arg ) { |
85 | - $defaults[$index] = is_null( $arg ) ? $_arg : $arg; |
|
86 | - $_arg = next( $defaults ); |
|
85 | + $defaults[$index] = is_null($arg) ? $_arg : $arg; |
|
86 | + $_arg = next($defaults); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | return $defaults; |
@@ -28,7 +28,9 @@ |
||
28 | 28 | $this->_class = $function[0]; |
29 | 29 | } |
30 | 30 | |
31 | - if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
31 | + if( is_string( $function[1] ) ) { |
|
32 | + $this->_function = $function[1]; |
|
33 | + } |
|
32 | 34 | } else { |
33 | 35 | $this->_function = $function; |
34 | 36 | } |
@@ -2,180 +2,180 @@ |
||
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 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @param string $TermClass |
9 | 9 | * @return mixed |
10 | 10 | */ |
11 | - public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
11 | + public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) { |
|
12 | 12 | if ( is_string($maybe_args) && !strstr($maybe_args, '=') ) { |
13 | 13 | //the user is sending the $TermClass in the second argument |
14 | 14 | $TermClass = $maybe_args; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param string $TermClass |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public static function handle_term_query($taxonomies, $args, $TermClass) { |
|
56 | + public static function handle_term_query( $taxonomies, $args, $TermClass ) { |
|
57 | 57 | if ( !isset($args['hide_empty']) ) { |
58 | 58 | $args['hide_empty'] = false; |
59 | 59 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $args['include'] = $args['term_id']; |
65 | 65 | } |
66 | 66 | $terms = get_terms($taxonomies, $args); |
67 | - foreach ($terms as &$term) { |
|
67 | + foreach ( $terms as &$term ) { |
|
68 | 68 | $term = new $TermClass($term->term_id, $term->taxonomy); |
69 | 69 | } |
70 | 70 | return $terms; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param string $query_string |
75 | 75 | * @return stdClass |
76 | 76 | */ |
77 | - protected static function get_term_query_from_query_string($query_string) { |
|
77 | + protected static function get_term_query_from_query_string( $query_string ) { |
|
78 | 78 | $args = array(); |
79 | 79 | parse_str($query_string, $args); |
80 | 80 | $ret = self::get_term_query_from_assoc_array($args); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param string $taxs |
86 | 86 | * @return stdClass |
87 | 87 | */ |
88 | - protected static function get_term_query_from_string($taxs) { |
|
88 | + protected static function get_term_query_from_string( $taxs ) { |
|
89 | 89 | $ret = new stdClass(); |
90 | 90 | $ret->args = array(); |
91 | 91 | if ( is_string($taxs) ) { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param array $args |
100 | 100 | * @return stdClass |
101 | 101 | */ |
102 | - public static function get_term_query_from_assoc_array($args) { |
|
102 | + public static function get_term_query_from_assoc_array( $args ) { |
|
103 | 103 | $ret = new stdClass(); |
104 | 104 | $ret->args = $args; |
105 | 105 | if ( isset($ret->args['tax']) ) { |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param array $args |
127 | 127 | * @return stdClass |
128 | 128 | */ |
129 | - public static function get_term_query_from_array($args) { |
|
129 | + public static function get_term_query_from_array( $args ) { |
|
130 | 130 | if ( is_array($args) && !empty($args) ) { |
131 | 131 | //okay its an array with content |
132 | 132 | if ( is_int($args[0]) ) { |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param integer[] $args |
143 | 143 | * @return stdClass |
144 | 144 | */ |
145 | - public static function get_term_query_from_array_of_ids($args) { |
|
145 | + public static function get_term_query_from_array_of_ids( $args ) { |
|
146 | 146 | $ret = new stdClass(); |
147 | 147 | $ret->taxonomies = get_taxonomies(); |
148 | 148 | $ret->args['include'] = $args; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param string[] $args |
154 | 154 | * @return stdClass |
155 | 155 | */ |
156 | - public static function get_term_query_from_array_of_strings($args) { |
|
156 | + public static function get_term_query_from_array_of_strings( $args ) { |
|
157 | 157 | $ret = new stdClass(); |
158 | 158 | $ret->taxonomies = self::correct_taxonomy_names($args); |
159 | 159 | $ret->args = array(); |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | * @param string|array $taxs |
165 | 165 | * @return array |
166 | 166 | */ |
167 | - private static function correct_taxonomy_names($taxs) { |
|
167 | + private static function correct_taxonomy_names( $taxs ) { |
|
168 | 168 | if ( is_string($taxs) ) { |
169 | 169 | $taxs = array($taxs); |
170 | 170 | } |
171 | - foreach ($taxs as &$tax) { |
|
171 | + foreach ( $taxs as &$tax ) { |
|
172 | 172 | if ( $tax == 'tags' || $tax == 'tag' ) { |
173 | 173 | $tax = 'post_tag'; |
174 | 174 | } else if ( $tax == 'categories' ) { |
@@ -19,230 +19,230 @@ |
||
19 | 19 | */ |
20 | 20 | class TimberUser extends TimberCore implements TimberCoreInterface { |
21 | 21 | |
22 | - public $object_type = 'user'; |
|
23 | - public static $representation = 'user'; |
|
24 | - |
|
25 | - public $_link; |
|
26 | - |
|
27 | - /** |
|
28 | - * @api |
|
29 | - * @var string The description from WordPress |
|
30 | - */ |
|
31 | - public $description; |
|
32 | - public $display_name; |
|
33 | - |
|
34 | - /** |
|
35 | - * @api |
|
36 | - * @var string The first name of the user |
|
37 | - */ |
|
38 | - public $first_name; |
|
39 | - |
|
40 | - /** |
|
41 | - * @api |
|
42 | - * @var string The last name of the user |
|
43 | - */ |
|
44 | - public $last_name; |
|
45 | - |
|
46 | - /** |
|
47 | - * @api |
|
48 | - * @var int The ID from WordPress |
|
49 | - */ |
|
50 | - public $id; |
|
51 | - public $user_nicename; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param int|bool $uid |
|
55 | - */ |
|
56 | - function __construct($uid = false) { |
|
57 | - $this->init($uid); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @example |
|
62 | - * ```twig |
|
63 | - * This post is by {{ post.author }} |
|
64 | - * ``` |
|
65 | - * ```html |
|
66 | - * This post is by Jared Novack |
|
67 | - * ``` |
|
68 | - * |
|
69 | - * @return string a fallback for TimberUser::name() |
|
70 | - */ |
|
71 | - function __toString() { |
|
72 | - $name = $this->name(); |
|
73 | - if ( strlen($name) ) { |
|
74 | - return $name; |
|
75 | - } |
|
76 | - if ( strlen($this->name) ) { |
|
77 | - return $this->name; |
|
78 | - } |
|
79 | - return ''; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @internal |
|
84 | - * @param string $field_name |
|
85 | - * @return null |
|
86 | - */ |
|
87 | - function get_meta($field_name) { |
|
88 | - return $this->get_meta_field($field_name); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @internal |
|
93 | - * @param string $field |
|
94 | - * @param mixed $value |
|
95 | - */ |
|
96 | - function __set($field, $value) { |
|
97 | - if ( $field == 'name' ) { |
|
98 | - $this->display_name = $value; |
|
99 | - } |
|
100 | - $this->$field = $value; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @internal |
|
105 | - * @param int|bool $uid The user ID to use |
|
106 | - */ |
|
107 | - protected function init($uid = false) { |
|
108 | - if ( $uid === false ) { |
|
109 | - $uid = get_current_user_id(); |
|
110 | - } |
|
111 | - if ( is_object($uid) || is_array($uid) ) { |
|
112 | - $data = $uid; |
|
113 | - if ( is_array($uid) ) { |
|
114 | - $data = (object) $uid; |
|
115 | - } |
|
116 | - $uid = $data->ID; |
|
117 | - } |
|
118 | - if ( is_numeric($uid) ) { |
|
119 | - $data = get_userdata($uid); |
|
120 | - } else if ( is_string($uid) ) { |
|
121 | - $data = get_user_by('login', $uid); |
|
122 | - } |
|
123 | - if ( isset($data) && is_object($data) ) { |
|
124 | - if ( isset($data->data) ) { |
|
125 | - $this->import($data->data); |
|
126 | - } else { |
|
127 | - $this->import($data); |
|
128 | - } |
|
129 | - } |
|
130 | - $this->id = $this->ID; |
|
131 | - $this->name = $this->name(); |
|
132 | - $custom = $this->get_custom(); |
|
133 | - $this->import($custom); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $field_name |
|
138 | - * @return mixed |
|
139 | - */ |
|
140 | - function get_meta_field($field_name) { |
|
141 | - $value = null; |
|
142 | - $value = apply_filters('timber_user_get_meta_field_pre', $value, $this->ID, $field_name, $this); |
|
143 | - if ( $value === null ) { |
|
144 | - $value = get_user_meta($this->ID, $field_name, true); |
|
145 | - } |
|
146 | - $value = apply_filters('timber_user_get_meta_field', $value, $this->ID, $field_name, $this); |
|
147 | - return $value; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array|null |
|
152 | - */ |
|
153 | - function get_custom() { |
|
154 | - if ( $this->ID ) { |
|
155 | - $um = array(); |
|
156 | - $um = apply_filters('timber_user_get_meta_pre', $um, $this->ID, $this); |
|
157 | - if ( empty($um) ) { |
|
158 | - $um = get_user_meta($this->ID); |
|
159 | - } |
|
160 | - $custom = array(); |
|
161 | - foreach ($um as $key => $value) { |
|
162 | - if ( is_array($value) && count($value) == 1 ) { |
|
163 | - $value = $value[0]; |
|
164 | - } |
|
165 | - $custom[$key] = maybe_unserialize($value); |
|
166 | - } |
|
167 | - $custom = apply_filters('timber_user_get_meta', $custom, $this->ID, $this); |
|
168 | - return $custom; |
|
169 | - } |
|
170 | - return null; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @api |
|
175 | - * @return string http://example.org/author/lincoln |
|
176 | - */ |
|
177 | - public function link() { |
|
178 | - if ( !$this->_link ) { |
|
179 | - $this->_link = untrailingslashit(get_author_posts_url($this->ID)); |
|
180 | - } |
|
181 | - return $this->_link; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @api |
|
186 | - * @return string the human-friendly name of the user (ex: "Buster Bluth") |
|
187 | - */ |
|
188 | - function name() { |
|
189 | - return $this->display_name; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @param string $field_name |
|
194 | - * @return mixed |
|
195 | - */ |
|
196 | - function meta($field_name) { |
|
197 | - return $this->get_meta_field($field_name); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @api |
|
202 | - * @return string ex: /author/lincoln |
|
203 | - */ |
|
204 | - public function path() { |
|
205 | - return TimberURLHelper::get_rel_url($this->get_link()); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @api |
|
210 | - * @return string ex baberaham-lincoln |
|
211 | - */ |
|
212 | - public function slug() { |
|
213 | - return $this->user_nicename; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @deprecated 0.21.9 |
|
218 | - * @return string The link to a user's profile page |
|
219 | - */ |
|
220 | - function get_link() { |
|
221 | - return $this->link(); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @deprecated 0.21.8 |
|
226 | - * @return string ex: /author/lincoln |
|
227 | - */ |
|
228 | - function get_path() { |
|
229 | - return $this->path(); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @deprecated 0.21.8 |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - function get_permalink() { |
|
237 | - return $this->get_link(); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @deprecated 0.21.8 |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - function permalink() { |
|
245 | - return $this->get_permalink(); |
|
246 | - } |
|
22 | + public $object_type = 'user'; |
|
23 | + public static $representation = 'user'; |
|
24 | + |
|
25 | + public $_link; |
|
26 | + |
|
27 | + /** |
|
28 | + * @api |
|
29 | + * @var string The description from WordPress |
|
30 | + */ |
|
31 | + public $description; |
|
32 | + public $display_name; |
|
33 | + |
|
34 | + /** |
|
35 | + * @api |
|
36 | + * @var string The first name of the user |
|
37 | + */ |
|
38 | + public $first_name; |
|
39 | + |
|
40 | + /** |
|
41 | + * @api |
|
42 | + * @var string The last name of the user |
|
43 | + */ |
|
44 | + public $last_name; |
|
45 | + |
|
46 | + /** |
|
47 | + * @api |
|
48 | + * @var int The ID from WordPress |
|
49 | + */ |
|
50 | + public $id; |
|
51 | + public $user_nicename; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param int|bool $uid |
|
55 | + */ |
|
56 | + function __construct($uid = false) { |
|
57 | + $this->init($uid); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @example |
|
62 | + * ```twig |
|
63 | + * This post is by {{ post.author }} |
|
64 | + * ``` |
|
65 | + * ```html |
|
66 | + * This post is by Jared Novack |
|
67 | + * ``` |
|
68 | + * |
|
69 | + * @return string a fallback for TimberUser::name() |
|
70 | + */ |
|
71 | + function __toString() { |
|
72 | + $name = $this->name(); |
|
73 | + if ( strlen($name) ) { |
|
74 | + return $name; |
|
75 | + } |
|
76 | + if ( strlen($this->name) ) { |
|
77 | + return $this->name; |
|
78 | + } |
|
79 | + return ''; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @internal |
|
84 | + * @param string $field_name |
|
85 | + * @return null |
|
86 | + */ |
|
87 | + function get_meta($field_name) { |
|
88 | + return $this->get_meta_field($field_name); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @internal |
|
93 | + * @param string $field |
|
94 | + * @param mixed $value |
|
95 | + */ |
|
96 | + function __set($field, $value) { |
|
97 | + if ( $field == 'name' ) { |
|
98 | + $this->display_name = $value; |
|
99 | + } |
|
100 | + $this->$field = $value; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @internal |
|
105 | + * @param int|bool $uid The user ID to use |
|
106 | + */ |
|
107 | + protected function init($uid = false) { |
|
108 | + if ( $uid === false ) { |
|
109 | + $uid = get_current_user_id(); |
|
110 | + } |
|
111 | + if ( is_object($uid) || is_array($uid) ) { |
|
112 | + $data = $uid; |
|
113 | + if ( is_array($uid) ) { |
|
114 | + $data = (object) $uid; |
|
115 | + } |
|
116 | + $uid = $data->ID; |
|
117 | + } |
|
118 | + if ( is_numeric($uid) ) { |
|
119 | + $data = get_userdata($uid); |
|
120 | + } else if ( is_string($uid) ) { |
|
121 | + $data = get_user_by('login', $uid); |
|
122 | + } |
|
123 | + if ( isset($data) && is_object($data) ) { |
|
124 | + if ( isset($data->data) ) { |
|
125 | + $this->import($data->data); |
|
126 | + } else { |
|
127 | + $this->import($data); |
|
128 | + } |
|
129 | + } |
|
130 | + $this->id = $this->ID; |
|
131 | + $this->name = $this->name(); |
|
132 | + $custom = $this->get_custom(); |
|
133 | + $this->import($custom); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $field_name |
|
138 | + * @return mixed |
|
139 | + */ |
|
140 | + function get_meta_field($field_name) { |
|
141 | + $value = null; |
|
142 | + $value = apply_filters('timber_user_get_meta_field_pre', $value, $this->ID, $field_name, $this); |
|
143 | + if ( $value === null ) { |
|
144 | + $value = get_user_meta($this->ID, $field_name, true); |
|
145 | + } |
|
146 | + $value = apply_filters('timber_user_get_meta_field', $value, $this->ID, $field_name, $this); |
|
147 | + return $value; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array|null |
|
152 | + */ |
|
153 | + function get_custom() { |
|
154 | + if ( $this->ID ) { |
|
155 | + $um = array(); |
|
156 | + $um = apply_filters('timber_user_get_meta_pre', $um, $this->ID, $this); |
|
157 | + if ( empty($um) ) { |
|
158 | + $um = get_user_meta($this->ID); |
|
159 | + } |
|
160 | + $custom = array(); |
|
161 | + foreach ($um as $key => $value) { |
|
162 | + if ( is_array($value) && count($value) == 1 ) { |
|
163 | + $value = $value[0]; |
|
164 | + } |
|
165 | + $custom[$key] = maybe_unserialize($value); |
|
166 | + } |
|
167 | + $custom = apply_filters('timber_user_get_meta', $custom, $this->ID, $this); |
|
168 | + return $custom; |
|
169 | + } |
|
170 | + return null; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @api |
|
175 | + * @return string http://example.org/author/lincoln |
|
176 | + */ |
|
177 | + public function link() { |
|
178 | + if ( !$this->_link ) { |
|
179 | + $this->_link = untrailingslashit(get_author_posts_url($this->ID)); |
|
180 | + } |
|
181 | + return $this->_link; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @api |
|
186 | + * @return string the human-friendly name of the user (ex: "Buster Bluth") |
|
187 | + */ |
|
188 | + function name() { |
|
189 | + return $this->display_name; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @param string $field_name |
|
194 | + * @return mixed |
|
195 | + */ |
|
196 | + function meta($field_name) { |
|
197 | + return $this->get_meta_field($field_name); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @api |
|
202 | + * @return string ex: /author/lincoln |
|
203 | + */ |
|
204 | + public function path() { |
|
205 | + return TimberURLHelper::get_rel_url($this->get_link()); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @api |
|
210 | + * @return string ex baberaham-lincoln |
|
211 | + */ |
|
212 | + public function slug() { |
|
213 | + return $this->user_nicename; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @deprecated 0.21.9 |
|
218 | + * @return string The link to a user's profile page |
|
219 | + */ |
|
220 | + function get_link() { |
|
221 | + return $this->link(); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @deprecated 0.21.8 |
|
226 | + * @return string ex: /author/lincoln |
|
227 | + */ |
|
228 | + function get_path() { |
|
229 | + return $this->path(); |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @deprecated 0.21.8 |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + function get_permalink() { |
|
237 | + return $this->get_link(); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @deprecated 0.21.8 |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + function permalink() { |
|
245 | + return $this->get_permalink(); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @param int|bool $uid |
55 | 55 | */ |
56 | - function __construct($uid = false) { |
|
56 | + function __construct( $uid = false ) { |
|
57 | 57 | $this->init($uid); |
58 | 58 | } |
59 | 59 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param string $field_name |
85 | 85 | * @return null |
86 | 86 | */ |
87 | - function get_meta($field_name) { |
|
87 | + function get_meta( $field_name ) { |
|
88 | 88 | return $this->get_meta_field($field_name); |
89 | 89 | } |
90 | 90 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param string $field |
94 | 94 | * @param mixed $value |
95 | 95 | */ |
96 | - function __set($field, $value) { |
|
96 | + function __set( $field, $value ) { |
|
97 | 97 | if ( $field == 'name' ) { |
98 | 98 | $this->display_name = $value; |
99 | 99 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @internal |
105 | 105 | * @param int|bool $uid The user ID to use |
106 | 106 | */ |
107 | - protected function init($uid = false) { |
|
107 | + protected function init( $uid = false ) { |
|
108 | 108 | if ( $uid === false ) { |
109 | 109 | $uid = get_current_user_id(); |
110 | 110 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param string $field_name |
138 | 138 | * @return mixed |
139 | 139 | */ |
140 | - function get_meta_field($field_name) { |
|
140 | + function get_meta_field( $field_name ) { |
|
141 | 141 | $value = null; |
142 | 142 | $value = apply_filters('timber_user_get_meta_field_pre', $value, $this->ID, $field_name, $this); |
143 | 143 | if ( $value === null ) { |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $um = get_user_meta($this->ID); |
159 | 159 | } |
160 | 160 | $custom = array(); |
161 | - foreach ($um as $key => $value) { |
|
161 | + foreach ( $um as $key => $value ) { |
|
162 | 162 | if ( is_array($value) && count($value) == 1 ) { |
163 | 163 | $value = $value[0]; |
164 | 164 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @param string $field_name |
194 | 194 | * @return mixed |
195 | 195 | */ |
196 | - function meta($field_name) { |
|
196 | + function meta( $field_name ) { |
|
197 | 197 | return $this->get_meta_field($field_name); |
198 | 198 | } |
199 | 199 |
@@ -5,24 +5,24 @@ |
||
5 | 5 | |
6 | 6 | class WPObjectCacheAdapter implements CacheProviderInterface { |
7 | 7 | |
8 | - private $cache_group; |
|
8 | + private $cache_group; |
|
9 | 9 | |
10 | - /** |
|
11 | - * @var TimberLoader |
|
12 | - */ |
|
13 | - private $timberloader; |
|
10 | + /** |
|
11 | + * @var TimberLoader |
|
12 | + */ |
|
13 | + private $timberloader; |
|
14 | 14 | |
15 | - public function __construct(TimberLoader $timberloader, $cache_group = 'timber') { |
|
16 | - $this->cache_group = $cache_group; |
|
17 | - $this->timberloader = $timberloader; |
|
18 | - } |
|
15 | + public function __construct(TimberLoader $timberloader, $cache_group = 'timber') { |
|
16 | + $this->cache_group = $cache_group; |
|
17 | + $this->timberloader = $timberloader; |
|
18 | + } |
|
19 | 19 | |
20 | - public function fetch($key) { |
|
21 | - return $this->timberloader->get_cache($key, $this->cache_group, TimberLoader::CACHE_USE_DEFAULT); |
|
22 | - } |
|
20 | + public function fetch($key) { |
|
21 | + return $this->timberloader->get_cache($key, $this->cache_group, TimberLoader::CACHE_USE_DEFAULT); |
|
22 | + } |
|
23 | 23 | |
24 | - public function save($key, $value, $expire = 0) { |
|
25 | - return $this->timberloader->set_cache($key, $value, $this->cache_group, $expire, TimberLoader::CACHE_USE_DEFAULT); |
|
26 | - } |
|
24 | + public function save($key, $value, $expire = 0) { |
|
25 | + return $this->timberloader->set_cache($key, $value, $this->cache_group, $expire, TimberLoader::CACHE_USE_DEFAULT); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | } |
@@ -12,16 +12,16 @@ |
||
12 | 12 | */ |
13 | 13 | private $timberloader; |
14 | 14 | |
15 | - public function __construct(TimberLoader $timberloader, $cache_group = 'timber') { |
|
15 | + public function __construct( TimberLoader $timberloader, $cache_group = 'timber' ) { |
|
16 | 16 | $this->cache_group = $cache_group; |
17 | 17 | $this->timberloader = $timberloader; |
18 | 18 | } |
19 | 19 | |
20 | - public function fetch($key) { |
|
20 | + public function fetch( $key ) { |
|
21 | 21 | return $this->timberloader->get_cache($key, $this->cache_group, TimberLoader::CACHE_USE_DEFAULT); |
22 | 22 | } |
23 | 23 | |
24 | - public function save($key, $value, $expire = 0) { |
|
24 | + public function save( $key, $value, $expire = 0 ) { |
|
25 | 25 | return $this->timberloader->set_cache($key, $value, $this->cache_group, $expire, TimberLoader::CACHE_USE_DEFAULT); |
26 | 26 | } |
27 | 27 |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | interface TimberKeyGeneratorInterface { |
6 | 6 | |
7 | - public function _get_cache_key(); |
|
7 | + public function _get_cache_key(); |
|
8 | 8 | |
9 | 9 | } |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class KeyGenerator implements KeyGeneratorInterface { |
8 | 8 | |
9 | - /** |
|
10 | - * @param mixed $value |
|
11 | - * @return string |
|
12 | - */ |
|
13 | - public function generateKey($value) { |
|
14 | - if (is_a($value, 'TimberKeyGeneratorInterface')) { |
|
15 | - return $value->_get_cache_key(); |
|
16 | - } |
|
17 | - |
|
18 | - if (is_array($value) && isset($value['_cache_key'])) { |
|
19 | - return $value['_cache_key']; |
|
20 | - } |
|
21 | - |
|
22 | - $key = md5(json_encode($value)); |
|
23 | - if (is_object($value)) { |
|
24 | - $key = get_class($value) . '|' . $key; |
|
25 | - } |
|
26 | - |
|
27 | - return $key; |
|
28 | - } |
|
9 | + /** |
|
10 | + * @param mixed $value |
|
11 | + * @return string |
|
12 | + */ |
|
13 | + public function generateKey($value) { |
|
14 | + if (is_a($value, 'TimberKeyGeneratorInterface')) { |
|
15 | + return $value->_get_cache_key(); |
|
16 | + } |
|
17 | + |
|
18 | + if (is_array($value) && isset($value['_cache_key'])) { |
|
19 | + return $value['_cache_key']; |
|
20 | + } |
|
21 | + |
|
22 | + $key = md5(json_encode($value)); |
|
23 | + if (is_object($value)) { |
|
24 | + $key = get_class($value) . '|' . $key; |
|
25 | + } |
|
26 | + |
|
27 | + return $key; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | } |
@@ -10,17 +10,17 @@ |
||
10 | 10 | * @param mixed $value |
11 | 11 | * @return string |
12 | 12 | */ |
13 | - public function generateKey($value) { |
|
14 | - if (is_a($value, 'TimberKeyGeneratorInterface')) { |
|
13 | + public function generateKey( $value ) { |
|
14 | + if ( is_a($value, 'TimberKeyGeneratorInterface') ) { |
|
15 | 15 | return $value->_get_cache_key(); |
16 | 16 | } |
17 | 17 | |
18 | - if (is_array($value) && isset($value['_cache_key'])) { |
|
18 | + if ( is_array($value) && isset($value['_cache_key']) ) { |
|
19 | 19 | return $value['_cache_key']; |
20 | 20 | } |
21 | 21 | |
22 | 22 | $key = md5(json_encode($value)); |
23 | - if (is_object($value)) { |
|
23 | + if ( is_object($value) ) { |
|
24 | 24 | $key = get_class($value) . '|' . $key; |
25 | 25 | } |
26 | 26 |
@@ -19,107 +19,107 @@ |
||
19 | 19 | */ |
20 | 20 | class TimberTheme extends TimberCore { |
21 | 21 | |
22 | - /** |
|
23 | - * @api |
|
24 | - * @var string the human-friendly name of the theme (ex: `My Timber Starter Theme`) |
|
25 | - */ |
|
26 | - public $name; |
|
22 | + /** |
|
23 | + * @api |
|
24 | + * @var string the human-friendly name of the theme (ex: `My Timber Starter Theme`) |
|
25 | + */ |
|
26 | + public $name; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @api |
|
30 | - * @var TimberTheme|bool the TimberTheme object for the parent theme (if it exists), false otherwise |
|
31 | - */ |
|
32 | - public $parent = false; |
|
28 | + /** |
|
29 | + * @api |
|
30 | + * @var TimberTheme|bool the TimberTheme object for the parent theme (if it exists), false otherwise |
|
31 | + */ |
|
32 | + public $parent = false; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @api |
|
36 | - * @var string the slug of the parent theme (ex: `_s`) |
|
37 | - */ |
|
38 | - public $parent_slug; |
|
34 | + /** |
|
35 | + * @api |
|
36 | + * @var string the slug of the parent theme (ex: `_s`) |
|
37 | + */ |
|
38 | + public $parent_slug; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @api |
|
42 | - * @var string the slug of the theme (ex: `my-super-theme`) |
|
43 | - */ |
|
44 | - public $slug; |
|
45 | - public $uri; |
|
40 | + /** |
|
41 | + * @api |
|
42 | + * @var string the slug of the theme (ex: `my-super-theme`) |
|
43 | + */ |
|
44 | + public $slug; |
|
45 | + public $uri; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Constructs a new TimberTheme object. NOTE the TimberTheme object of the current theme comes in the default `Timber::get_context()` call. You can access this in your twig template via `{{site.theme}}. |
|
49 | - * @param string $slug |
|
50 | - * @example |
|
51 | - * ```php |
|
52 | - * <?php |
|
53 | - * $theme = new TimberTheme("my-theme"); |
|
54 | - * $context['theme_stuff'] = $theme; |
|
55 | - * Timber::render('single.') |
|
56 | - * ?> |
|
57 | - * ``` |
|
58 | - * ```twig |
|
59 | - * We are currently using the {{ theme_stuff.name }} theme. |
|
60 | - * ``` |
|
61 | - * ```html |
|
62 | - * We are currently using the My Theme theme. |
|
63 | - * ``` |
|
64 | - */ |
|
65 | - function __construct($slug = null) { |
|
66 | - $this->init($slug); |
|
67 | - } |
|
47 | + /** |
|
48 | + * Constructs a new TimberTheme object. NOTE the TimberTheme object of the current theme comes in the default `Timber::get_context()` call. You can access this in your twig template via `{{site.theme}}. |
|
49 | + * @param string $slug |
|
50 | + * @example |
|
51 | + * ```php |
|
52 | + * <?php |
|
53 | + * $theme = new TimberTheme("my-theme"); |
|
54 | + * $context['theme_stuff'] = $theme; |
|
55 | + * Timber::render('single.') |
|
56 | + * ?> |
|
57 | + * ``` |
|
58 | + * ```twig |
|
59 | + * We are currently using the {{ theme_stuff.name }} theme. |
|
60 | + * ``` |
|
61 | + * ```html |
|
62 | + * We are currently using the My Theme theme. |
|
63 | + * ``` |
|
64 | + */ |
|
65 | + function __construct($slug = null) { |
|
66 | + $this->init($slug); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @internal |
|
71 | - * @param string $slug |
|
72 | - */ |
|
73 | - protected function init($slug = null) { |
|
74 | - $data = wp_get_theme($slug); |
|
75 | - $this->name = $data->get('Name'); |
|
76 | - $ss = $data->get_stylesheet(); |
|
77 | - $this->slug = $ss; |
|
69 | + /** |
|
70 | + * @internal |
|
71 | + * @param string $slug |
|
72 | + */ |
|
73 | + protected function init($slug = null) { |
|
74 | + $data = wp_get_theme($slug); |
|
75 | + $this->name = $data->get('Name'); |
|
76 | + $ss = $data->get_stylesheet(); |
|
77 | + $this->slug = $ss; |
|
78 | 78 | |
79 | - if ( ! function_exists( 'get_home_path' ) ) { |
|
80 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
81 | - } |
|
79 | + if ( ! function_exists( 'get_home_path' ) ) { |
|
80 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
81 | + } |
|
82 | 82 | |
83 | - $this->uri = get_stylesheet_directory_uri(); |
|
84 | - $this->parent_slug = $data->get('Template'); |
|
85 | - if ( !$this->parent_slug ) { |
|
86 | - $this->uri = get_template_directory_uri(); |
|
87 | - } |
|
88 | - if ( $this->parent_slug && $this->parent_slug != $this->slug ) { |
|
89 | - $this->parent = new TimberTheme($this->parent_slug); |
|
90 | - } |
|
91 | - } |
|
83 | + $this->uri = get_stylesheet_directory_uri(); |
|
84 | + $this->parent_slug = $data->get('Template'); |
|
85 | + if ( !$this->parent_slug ) { |
|
86 | + $this->uri = get_template_directory_uri(); |
|
87 | + } |
|
88 | + if ( $this->parent_slug && $this->parent_slug != $this->slug ) { |
|
89 | + $this->parent = new TimberTheme($this->parent_slug); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @api |
|
95 | - * @return string the absolute path to the theme (ex: `http://example.org/wp-content/themes/my-timber-theme`) |
|
96 | - */ |
|
97 | - public function link() { |
|
98 | - return $this->uri; |
|
99 | - } |
|
93 | + /** |
|
94 | + * @api |
|
95 | + * @return string the absolute path to the theme (ex: `http://example.org/wp-content/themes/my-timber-theme`) |
|
96 | + */ |
|
97 | + public function link() { |
|
98 | + return $this->uri; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @api |
|
103 | - * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`) |
|
104 | - */ |
|
105 | - public function path() { |
|
106 | - return TimberURLHelper::get_rel_url( $this->link() ); |
|
107 | - } |
|
101 | + /** |
|
102 | + * @api |
|
103 | + * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`) |
|
104 | + */ |
|
105 | + public function path() { |
|
106 | + return TimberURLHelper::get_rel_url( $this->link() ); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param string $name |
|
111 | - * @param bool $default |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function theme_mod($name, $default = false) { |
|
115 | - return get_theme_mod($name, $default); |
|
116 | - } |
|
109 | + /** |
|
110 | + * @param string $name |
|
111 | + * @param bool $default |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function theme_mod($name, $default = false) { |
|
115 | + return get_theme_mod($name, $default); |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public function theme_mods() { |
|
122 | - return get_theme_mods(); |
|
123 | - } |
|
118 | + /** |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public function theme_mods() { |
|
122 | + return get_theme_mods(); |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * We are currently using the My Theme theme. |
63 | 63 | * ``` |
64 | 64 | */ |
65 | - function __construct($slug = null) { |
|
65 | + function __construct( $slug = null ) { |
|
66 | 66 | $this->init($slug); |
67 | 67 | } |
68 | 68 | |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | * @internal |
71 | 71 | * @param string $slug |
72 | 72 | */ |
73 | - protected function init($slug = null) { |
|
73 | + protected function init( $slug = null ) { |
|
74 | 74 | $data = wp_get_theme($slug); |
75 | 75 | $this->name = $data->get('Name'); |
76 | 76 | $ss = $data->get_stylesheet(); |
77 | 77 | $this->slug = $ss; |
78 | 78 | |
79 | - if ( ! function_exists( 'get_home_path' ) ) { |
|
79 | + if ( !function_exists('get_home_path') ) { |
|
80 | 80 | require_once(ABSPATH . 'wp-admin/includes/file.php'); |
81 | 81 | } |
82 | 82 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`) |
104 | 104 | */ |
105 | 105 | public function path() { |
106 | - return TimberURLHelper::get_rel_url( $this->link() ); |
|
106 | + return TimberURLHelper::get_rel_url($this->link()); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param bool $default |
112 | 112 | * @return string |
113 | 113 | */ |
114 | - public function theme_mod($name, $default = false) { |
|
114 | + public function theme_mod( $name, $default = false ) { |
|
115 | 115 | return get_theme_mod($name, $default); |
116 | 116 | } |
117 | 117 |