@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $this->init($cid); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - function __toString(){ |
|
| 47 | + function __toString() { |
|
| 48 | 48 | return $this->content(); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 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'; |
@@ -114,21 +114,21 @@ discard block |
||
| 114 | 114 | * @return bool|mixed|string |
| 115 | 115 | */ |
| 116 | 116 | public function avatar($size = 92, $default = '') { |
| 117 | - if (!get_option('show_avatars')) { |
|
| 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; |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | * ``` |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - public function date( $date_format = '' ) { |
|
| 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 | |
@@ -204,9 +204,9 @@ discard block |
||
| 204 | 204 | * ``` |
| 205 | 205 | * @return string |
| 206 | 206 | */ |
| 207 | - public function time( $time_format = '' ) { |
|
| 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 | |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | * @return mixed |
| 233 | 233 | */ |
| 234 | 234 | protected function get_meta_fields($comment_id = null) { |
| 235 | - if ($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 | 241 | foreach ($comment_metas as &$cm) { |
| 242 | - if (is_array($cm) && count($cm) == 1) { |
|
| 242 | + if ( is_array($cm) && count($cm) == 1 ) { |
|
| 243 | 243 | $cm = $cm[0]; |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 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,9 +269,9 @@ discard block |
||
| 269 | 269 | * @param int $post_id |
| 270 | 270 | * @return string |
| 271 | 271 | */ |
| 272 | - public function reply_link( $reply_text = 'Reply' ) { |
|
| 272 | + public function reply_link($reply_text = 'Reply') { |
|
| 273 | 273 | if ( is_singular() && comments_open() && get_option('thread_comments') ) { |
| 274 | - wp_enqueue_script( 'comment-reply' ); |
|
| 274 | + wp_enqueue_script('comment-reply'); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | // Get the comments depth option from the admin panel |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | 'max_depth' => $max_depth, |
| 287 | 287 | ); |
| 288 | 288 | |
| 289 | - return get_comment_reply_link( $args, $this->ID, $this->post_id ); |
|
| 289 | + return get_comment_reply_link($args, $this->ID, $this->post_id); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /* AVATAR Stuff |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | * @return string |
| 298 | 298 | */ |
| 299 | 299 | protected function avatar_email() { |
| 300 | - $id = (int)$this->user_id; |
|
| 300 | + $id = (int) $this->user_id; |
|
| 301 | 301 | $user = get_userdata($id); |
| 302 | - if ($user) { |
|
| 302 | + if ( $user ) { |
|
| 303 | 303 | $email = $user->user_email; |
| 304 | 304 | } else { |
| 305 | 305 | $email = $this->comment_author_email; |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * @return string |
| 314 | 314 | */ |
| 315 | 315 | protected function avatar_host($email_hash) { |
| 316 | - if (is_ssl()) { |
|
| 316 | + if ( is_ssl() ) { |
|
| 317 | 317 | $host = 'https://secure.gravatar.com'; |
| 318 | 318 | } else { |
| 319 | - if (!empty($email_hash)) { |
|
| 319 | + if ( !empty($email_hash) ) { |
|
| 320 | 320 | $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2)); |
| 321 | 321 | } else { |
| 322 | 322 | $host = 'http://0.gravatar.com'; |
@@ -335,28 +335,28 @@ discard block |
||
| 335 | 335 | * @return string |
| 336 | 336 | */ |
| 337 | 337 | protected function avatar_default($default, $email, $size, $host) { |
| 338 | - if (substr($default, 0, 1) == '/') { |
|
| 338 | + if ( substr($default, 0, 1) == '/' ) { |
|
| 339 | 339 | $default = home_url() . $default; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if (empty($default)) { |
|
| 342 | + if ( empty($default) ) { |
|
| 343 | 343 | $avatar_default = get_option('avatar_default'); |
| 344 | - if (empty($avatar_default)) { |
|
| 344 | + if ( empty($avatar_default) ) { |
|
| 345 | 345 | $default = 'mystery'; |
| 346 | 346 | } else { |
| 347 | 347 | $default = $avatar_default; |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | - if ('mystery' == $default) { |
|
| 350 | + if ( 'mystery' == $default ) { |
|
| 351 | 351 | $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size; |
| 352 | 352 | // ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]') |
| 353 | - } else if ('blank' == $default) { |
|
| 353 | + } else if ( 'blank' == $default ) { |
|
| 354 | 354 | $default = $email ? 'blank' : includes_url('images/blank.gif'); |
| 355 | - } else if (!empty($email) && 'gravatar_default' == $default) { |
|
| 355 | + } else if ( !empty($email) && 'gravatar_default' == $default ) { |
|
| 356 | 356 | $default = ''; |
| 357 | - } else if ('gravatar_default' == $default) { |
|
| 357 | + } else if ( 'gravatar_default' == $default ) { |
|
| 358 | 358 | $default = $host . '/avatar/?s=' . $size; |
| 359 | - } else if (empty($email) && !strstr($default, 'http://')) { |
|
| 359 | + } else if ( empty($email) && !strstr($default, 'http://') ) { |
|
| 360 | 360 | $default = $host . '/avatar/?d=' . $default . '&s=' . $size; |
| 361 | 361 | } |
| 362 | 362 | return $default; |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | protected function avatar_out($default, $host, $email_hash, $size) { |
| 374 | 374 | $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&d=' . urlencode($default); |
| 375 | 375 | $rating = get_option('avatar_rating'); |
| 376 | - if (!empty($rating)) { |
|
| 376 | + if ( !empty($rating) ) { |
|
| 377 | 377 | $out .= '&r=' . $rating; |
| 378 | 378 | } |
| 379 | 379 | return str_replace('&', '&', esc_url($out)); |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * ``` |
| 44 | 44 | * @return string (ex: ) |
| 45 | 45 | */ |
| 46 | - public static function resize( $src, $w, $h = 0, $crop = 'default', $force = false ) { |
|
| 47 | - if (!is_numeric($w) && is_string($w)) { |
|
| 48 | - if ($sizes = self::find_wp_dimensions($w)) { |
|
| 46 | + public static function resize($src, $w, $h = 0, $crop = 'default', $force = false) { |
|
| 47 | + if ( !is_numeric($w) && is_string($w) ) { |
|
| 48 | + if ( $sizes = self::find_wp_dimensions($w) ) { |
|
| 49 | 49 | $w = $sizes['w']; |
| 50 | 50 | $h = $sizes['h']; |
| 51 | 51 | } else { |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * @type int h |
| 67 | 67 | * } |
| 68 | 68 | */ |
| 69 | - private static function find_wp_dimensions( $size ) { |
|
| 69 | + private static function find_wp_dimensions($size) { |
|
| 70 | 70 | global $_wp_additional_image_sizes; |
| 71 | - if (isset($_wp_additional_image_sizes[$size])) { |
|
| 71 | + if ( isset($_wp_additional_image_sizes[$size]) ) { |
|
| 72 | 72 | $w = $_wp_additional_image_sizes[$size]['width']; |
| 73 | 73 | $h = $_wp_additional_image_sizes[$size]['height']; |
| 74 | - } else if (in_array($size, array('thumbnail', 'medium', 'large'))) { |
|
| 75 | - $w = get_option($size.'_size_w'); |
|
| 76 | - $h = get_option($size.'_size_h'); |
|
| 74 | + } else if ( in_array($size, array('thumbnail', 'medium', 'large')) ) { |
|
| 75 | + $w = get_option($size . '_size_w'); |
|
| 76 | + $h = get_option($size . '_size_h'); |
|
| 77 | 77 | } |
| 78 | - if (isset($w) && isset($h) && ($w || $h)) { |
|
| 78 | + if ( isset($w) && isset($h) && ($w || $h) ) { |
|
| 79 | 79 | return array('w' => $w, 'h' => $h); |
| 80 | 80 | } |
| 81 | 81 | return false; |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return string url to the new image |
| 92 | 92 | */ |
| 93 | - public static function retina_resize( $src, $multiplier = 2, $force = false ) { |
|
| 93 | + public static function retina_resize($src, $multiplier = 2, $force = false) { |
|
| 94 | 94 | $op = new TimberImageOperationRetina($multiplier); |
| 95 | 95 | return self::_operate($src, $op, $force); |
| 96 | 96 | } |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | * @param string $file local filepath to a file, not a URL |
| 101 | 101 | * @return boolean true if it's an animated gif, false if not |
| 102 | 102 | */ |
| 103 | - public static function is_animated_gif( $file ) { |
|
| 103 | + public static function is_animated_gif($file) { |
|
| 104 | 104 | if ( strpos(strtolower($file), '.gif') == -1 ) { |
| 105 | 105 | //doesn't have .gif, bail |
| 106 | 106 | return false; |
| 107 | 107 | } |
| 108 | 108 | //its a gif so test |
| 109 | - if(!($fh = @fopen($file, 'rb'))) { |
|
| 109 | + if ( !($fh = @fopen($file, 'rb')) ) { |
|
| 110 | 110 | return false; |
| 111 | 111 | } |
| 112 | 112 | $count = 0; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | // We read through the file til we reach the end of the file, or we've found |
| 120 | 120 | // at least 2 frame headers |
| 121 | - while(!feof($fh) && $count < 2) { |
|
| 121 | + while (!feof($fh) && $count < 2) { |
|
| 122 | 122 | $chunk = fread($fh, 1024 * 100); //read 100kb at a time |
| 123 | 123 | $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches); |
| 124 | 124 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param bool $force |
| 139 | 139 | * @return mixed|null|string |
| 140 | 140 | */ |
| 141 | - public static function letterbox( $src, $w, $h, $color = '#000000', $force = false ) { |
|
| 141 | + public static function letterbox($src, $w, $h, $color = '#000000', $force = false) { |
|
| 142 | 142 | $op = new TimberImageOperationLetterbox($w, $h, $color); |
| 143 | 143 | return self::_operate($src, $op, $force); |
| 144 | 144 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param string $bghex |
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | - public static function img_to_jpg( $src, $bghex = '#FFFFFF', $force = false ) { |
|
| 153 | + public static function img_to_jpg($src, $bghex = '#FFFFFF', $force = false) { |
|
| 154 | 154 | $op = new TimberImageOperationToJpg($bghex); |
| 155 | 155 | return self::_operate($src, $op, $force); |
| 156 | 156 | } |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | * Deletes all resized versions of an image when the source is deleted |
| 160 | 160 | */ |
| 161 | 161 | protected static function add_actions() { |
| 162 | - add_action( 'delete_attachment', function ( $post_id ) { |
|
| 163 | - $post = get_post( $post_id ); |
|
| 164 | - $image_types = array( 'image/jpeg', 'image/png', 'image/gif', 'image/jpg' ); |
|
| 165 | - if ( in_array( $post->post_mime_type, $image_types ) ) { |
|
| 166 | - $attachment = new TimberImage( $post_id ); |
|
| 162 | + add_action('delete_attachment', function($post_id) { |
|
| 163 | + $post = get_post($post_id); |
|
| 164 | + $image_types = array('image/jpeg', 'image/png', 'image/gif', 'image/jpg'); |
|
| 165 | + if ( in_array($post->post_mime_type, $image_types) ) { |
|
| 166 | + $attachment = new TimberImage($post_id); |
|
| 167 | 167 | if ( $attachment->file_loc ) { |
| 168 | - TimberImageHelper::delete_generated_files( $attachment->file_loc ); |
|
| 168 | + TimberImageHelper::delete_generated_files($attachment->file_loc); |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | } ); |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | * for example /wp-content or /content |
| 177 | 177 | */ |
| 178 | 178 | protected static function add_constants() { |
| 179 | - if ( !defined( 'WP_CONTENT_SUBDIR' ) ) { |
|
| 180 | - $wp_content_path = str_replace( home_url(), '', WP_CONTENT_URL ); |
|
| 181 | - define( 'WP_CONTENT_SUBDIR', $wp_content_path ); |
|
| 179 | + if ( !defined('WP_CONTENT_SUBDIR') ) { |
|
| 180 | + $wp_content_path = str_replace(home_url(), '', WP_CONTENT_URL); |
|
| 181 | + define('WP_CONTENT_SUBDIR', $wp_content_path); |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @return void |
| 189 | 189 | */ |
| 190 | 190 | static function add_filters() { |
| 191 | - add_filter( 'upload_dir', function ( $arr ) { |
|
| 192 | - $arr['relative'] = str_replace( home_url(), '', $arr['baseurl'] ); |
|
| 191 | + add_filter('upload_dir', function($arr) { |
|
| 192 | + $arr['relative'] = str_replace(home_url(), '', $arr['baseurl']); |
|
| 193 | 193 | return $arr; |
| 194 | 194 | } ); |
| 195 | 195 | } |
@@ -200,16 +200,16 @@ discard block |
||
| 200 | 200 | * @param string $local_file ex: /var/www/wp-content/uploads/2015/my-pic.jpg |
| 201 | 201 | * or: http://example.org/wp-content/uploads/2015/my-pic.jpg |
| 202 | 202 | */ |
| 203 | - static function delete_generated_files( $local_file ) { |
|
| 204 | - if (TimberURLHelper::is_absolute( $local_file ) ) { |
|
| 205 | - $local_file = TimberURLHelper::url_to_file_system( $local_file ); |
|
| 203 | + static function delete_generated_files($local_file) { |
|
| 204 | + if ( TimberURLHelper::is_absolute($local_file) ) { |
|
| 205 | + $local_file = TimberURLHelper::url_to_file_system($local_file); |
|
| 206 | 206 | } |
| 207 | - $info = pathinfo( $local_file ); |
|
| 207 | + $info = pathinfo($local_file); |
|
| 208 | 208 | $dir = $info['dirname']; |
| 209 | 209 | $ext = $info['extension']; |
| 210 | 210 | $filename = $info['filename']; |
| 211 | - self::process_delete_generated_files( $filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.' ); |
|
| 212 | - self::process_delete_generated_files( $filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.' ); |
|
| 211 | + self::process_delete_generated_files($filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.'); |
|
| 212 | + self::process_delete_generated_files($filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.'); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -226,14 +226,14 @@ discard block |
||
| 226 | 226 | * @param string $search_pattern pattern of files to pluck from |
| 227 | 227 | * @param string $match_pattern pattern of files to go forth and delete |
| 228 | 228 | */ |
| 229 | - protected static function process_delete_generated_files( $filename, $ext, $dir, $search_pattern, $match_pattern ) { |
|
| 229 | + protected static function process_delete_generated_files($filename, $ext, $dir, $search_pattern, $match_pattern) { |
|
| 230 | 230 | $searcher = '/' . $filename . $search_pattern; |
| 231 | - foreach ( glob( $dir . $searcher ) as $found_file ) { |
|
| 232 | - $regexdir = str_replace( '/', '\/', $dir ); |
|
| 233 | - $pattern = '/' . ( $regexdir ) . '\/' . $filename . $match_pattern . $ext . '/'; |
|
| 234 | - $match = preg_match( $pattern, $found_file ); |
|
| 231 | + foreach (glob($dir . $searcher) as $found_file) { |
|
| 232 | + $regexdir = str_replace('/', '\/', $dir); |
|
| 233 | + $pattern = '/' . ($regexdir) . '\/' . $filename . $match_pattern . $ext . '/'; |
|
| 234 | + $match = preg_match($pattern, $found_file); |
|
| 235 | 235 | if ( $match ) { |
| 236 | - unlink( $found_file ); |
|
| 236 | + unlink($found_file); |
|
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | } |
@@ -245,9 +245,9 @@ discard block |
||
| 245 | 245 | * @param string $url |
| 246 | 246 | * @return string |
| 247 | 247 | */ |
| 248 | - public static function get_server_location( $url ) { |
|
| 248 | + public static function get_server_location($url) { |
|
| 249 | 249 | // if we're already an absolute dir, just return |
| 250 | - if ( 0 === strpos( $url, ABSPATH ) ) { |
|
| 250 | + if ( 0 === strpos($url, ABSPATH) ) { |
|
| 251 | 251 | return $url; |
| 252 | 252 | } |
| 253 | 253 | // otherwise, analyze URL then build mapping path |
@@ -262,15 +262,15 @@ discard block |
||
| 262 | 262 | * @param string $file |
| 263 | 263 | * @return string |
| 264 | 264 | */ |
| 265 | - public static function get_sideloaded_file_loc( $file ) { |
|
| 265 | + public static function get_sideloaded_file_loc($file) { |
|
| 266 | 266 | $upload = wp_upload_dir(); |
| 267 | 267 | $dir = $upload['path']; |
| 268 | 268 | $filename = $file; |
| 269 | - $file = parse_url( $file ); |
|
| 270 | - $path_parts = pathinfo( $file['path'] ); |
|
| 271 | - $basename = md5( $filename ); |
|
| 269 | + $file = parse_url($file); |
|
| 270 | + $path_parts = pathinfo($file['path']); |
|
| 271 | + $basename = md5($filename); |
|
| 272 | 272 | $ext = 'jpg'; |
| 273 | - if ( isset( $path_parts['extension'] ) ) { |
|
| 273 | + if ( isset($path_parts['extension']) ) { |
|
| 274 | 274 | $ext = $path_parts['extension']; |
| 275 | 275 | } |
| 276 | 276 | return $dir . '/' . $basename . '.' . $ext; |
@@ -282,28 +282,28 @@ discard block |
||
| 282 | 282 | * @param string $file the URL to the original file |
| 283 | 283 | * @return string the URL to the downloaded file |
| 284 | 284 | */ |
| 285 | - public static function sideload_image( $file ) { |
|
| 286 | - $loc = self::get_sideloaded_file_loc( $file ); |
|
| 287 | - if ( file_exists( $loc ) ) { |
|
| 288 | - return TimberURLHelper::preslashit( TimberURLHelper::get_rel_path( $loc ) ); |
|
| 285 | + public static function sideload_image($file) { |
|
| 286 | + $loc = self::get_sideloaded_file_loc($file); |
|
| 287 | + if ( file_exists($loc) ) { |
|
| 288 | + return TimberURLHelper::preslashit(TimberURLHelper::get_rel_path($loc)); |
|
| 289 | 289 | } |
| 290 | 290 | // Download file to temp location |
| 291 | - if ( !function_exists( 'download_url' ) ) { |
|
| 291 | + if ( !function_exists('download_url') ) { |
|
| 292 | 292 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 293 | 293 | } |
| 294 | - $tmp = download_url( $file ); |
|
| 295 | - preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); |
|
| 294 | + $tmp = download_url($file); |
|
| 295 | + preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches); |
|
| 296 | 296 | $file_array = array(); |
| 297 | - $file_array['name'] = basename( $matches[0] ); |
|
| 297 | + $file_array['name'] = basename($matches[0]); |
|
| 298 | 298 | $file_array['tmp_name'] = $tmp; |
| 299 | 299 | // If error storing temporarily, unlink |
| 300 | - if ( is_wp_error( $tmp ) ) { |
|
| 301 | - @unlink( $file_array['tmp_name'] ); |
|
| 300 | + if ( is_wp_error($tmp) ) { |
|
| 301 | + @unlink($file_array['tmp_name']); |
|
| 302 | 302 | $file_array['tmp_name'] = ''; |
| 303 | 303 | } |
| 304 | 304 | // do the validation and storage stuff |
| 305 | - $locinfo = pathinfo( $loc ); |
|
| 306 | - $file = wp_upload_bits( $locinfo['basename'], null, file_get_contents( $file_array['tmp_name'] ) ); |
|
| 305 | + $locinfo = pathinfo($loc); |
|
| 306 | + $file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name'])); |
|
| 307 | 307 | return $file['url']; |
| 308 | 308 | } |
| 309 | 309 | |
@@ -330,23 +330,23 @@ discard block |
||
| 330 | 330 | if ( 0 === strpos($tmp, ABSPATH) ) { // we've been given a dir, not an url |
| 331 | 331 | $result['absolute'] = true; |
| 332 | 332 | if ( 0 === strpos($tmp, $upload_dir['basedir']) ) { |
| 333 | - $result['base']= self::BASE_UPLOADS; // upload based |
|
| 333 | + $result['base'] = self::BASE_UPLOADS; // upload based |
|
| 334 | 334 | $tmp = str_replace($upload_dir['basedir'], '', $tmp); |
| 335 | 335 | } |
| 336 | 336 | if ( 0 === strpos($tmp, WP_CONTENT_DIR) ) { |
| 337 | - $result['base']= self::BASE_CONTENT; // content based |
|
| 337 | + $result['base'] = self::BASE_CONTENT; // content based |
|
| 338 | 338 | $tmp = str_replace(WP_CONTENT_DIR, '', $tmp); |
| 339 | 339 | } |
| 340 | 340 | } else { |
| 341 | - if (!$result['absolute']) { |
|
| 342 | - $tmp = home_url().$tmp; |
|
| 341 | + if ( !$result['absolute'] ) { |
|
| 342 | + $tmp = home_url() . $tmp; |
|
| 343 | 343 | } |
| 344 | - if (0 === strpos($tmp, $upload_dir['baseurl'])) { |
|
| 345 | - $result['base']= self::BASE_UPLOADS; // upload based |
|
| 344 | + if ( 0 === strpos($tmp, $upload_dir['baseurl']) ) { |
|
| 345 | + $result['base'] = self::BASE_UPLOADS; // upload based |
|
| 346 | 346 | $tmp = str_replace($upload_dir['baseurl'], '', $tmp); |
| 347 | 347 | } |
| 348 | - if (0 === strpos($tmp, content_url())) { |
|
| 349 | - $result['base']= self::BASE_CONTENT; // content-based |
|
| 348 | + if ( 0 === strpos($tmp, content_url()) ) { |
|
| 349 | + $result['base'] = self::BASE_CONTENT; // content-based |
|
| 350 | 350 | $tmp = str_replace(content_url(), '', $tmp); |
| 351 | 351 | } |
| 352 | 352 | } |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | private static function _get_file_url($base, $subdir, $filename, $absolute) { |
| 372 | 372 | $url = ''; |
| 373 | - if( self::BASE_UPLOADS == $base ) { |
|
| 373 | + if ( self::BASE_UPLOADS == $base ) { |
|
| 374 | 374 | $upload_dir = wp_upload_dir(); |
| 375 | 375 | $url = $upload_dir['baseurl']; |
| 376 | 376 | } |
| 377 | - if( self::BASE_CONTENT == $base ) { |
|
| 377 | + if ( self::BASE_CONTENT == $base ) { |
|
| 378 | 378 | $url = content_url(); |
| 379 | 379 | } |
| 380 | - if(!empty($subdir)) { |
|
| 380 | + if ( !empty($subdir) ) { |
|
| 381 | 381 | $url .= $subdir; |
| 382 | 382 | } |
| 383 | - $url .= '/'.$filename; |
|
| 384 | - if(!$absolute) { |
|
| 383 | + $url .= '/' . $filename; |
|
| 384 | + if ( !$absolute ) { |
|
| 385 | 385 | $url = str_replace(home_url(), '', $url); |
| 386 | 386 | } |
| 387 | 387 | // $url = TimberURLHelper::remove_double_slashes( $url); |
@@ -398,17 +398,17 @@ discard block |
||
| 398 | 398 | */ |
| 399 | 399 | private static function _get_file_path($base, $subdir, $filename) { |
| 400 | 400 | $path = ''; |
| 401 | - if(self::BASE_UPLOADS == $base) { |
|
| 401 | + if ( self::BASE_UPLOADS == $base ) { |
|
| 402 | 402 | $upload_dir = wp_upload_dir(); |
| 403 | 403 | $path = $upload_dir['basedir']; |
| 404 | 404 | } |
| 405 | - if(self::BASE_CONTENT == $base) { |
|
| 405 | + if ( self::BASE_CONTENT == $base ) { |
|
| 406 | 406 | $path = WP_CONTENT_DIR; |
| 407 | 407 | } |
| 408 | - if(!empty($subdir)) { |
|
| 408 | + if ( !empty($subdir) ) { |
|
| 409 | 409 | $path .= $subdir; |
| 410 | 410 | } |
| 411 | - $path .= '/'.$filename; |
|
| 411 | + $path .= '/' . $filename; |
|
| 412 | 412 | return $path; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -426,13 +426,13 @@ discard block |
||
| 426 | 426 | * @return string URL to the new image - or the source one if error |
| 427 | 427 | * |
| 428 | 428 | */ |
| 429 | - private static function _operate( $src, $op, $force = false ) { |
|
| 430 | - if ( empty( $src ) ) { |
|
| 429 | + private static function _operate($src, $op, $force = false) { |
|
| 430 | + if ( empty($src) ) { |
|
| 431 | 431 | return ''; |
| 432 | 432 | } |
| 433 | 433 | // if external image, load it first |
| 434 | - if ( TimberURLHelper::is_external_content( $src ) ) { |
|
| 435 | - $src = self::sideload_image( $src ); |
|
| 434 | + if ( TimberURLHelper::is_external_content($src) ) { |
|
| 435 | + $src = self::sideload_image($src); |
|
| 436 | 436 | } |
| 437 | 437 | // break down URL into components |
| 438 | 438 | $au = self::analyze_url($src); |
@@ -454,17 +454,17 @@ discard block |
||
| 454 | 454 | $au['basename'] |
| 455 | 455 | ); |
| 456 | 456 | // if already exists... |
| 457 | - if ( file_exists( $new_server_path ) ) { |
|
| 457 | + if ( file_exists($new_server_path) ) { |
|
| 458 | 458 | if ( $force ) { |
| 459 | 459 | // Force operation - warning: will regenerate the image on every pageload, use for testing purposes only! |
| 460 | - unlink( $new_server_path ); |
|
| 460 | + unlink($new_server_path); |
|
| 461 | 461 | } else { |
| 462 | 462 | // return existing file (caching) |
| 463 | 463 | return $new_url; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | // otherwise generate result file |
| 467 | - if($op->run($old_server_path, $new_server_path)) { |
|
| 467 | + if ( $op->run($old_server_path, $new_server_path) ) { |
|
| 468 | 468 | return $new_url; |
| 469 | 469 | } else { |
| 470 | 470 | // in case of error, we return source file itself |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | ); |
| 487 | 487 | return $new_url; |
| 488 | 488 | } |
| 489 | - public static function get_letterbox_file_path($url, $w, $h, $color ) { |
|
| 489 | + public static function get_letterbox_file_path($url, $w, $h, $color) { |
|
| 490 | 490 | $au = self::analyze_url($url); |
| 491 | 491 | $op = new TimberImageOperationLetterbox($w, $h, $color); |
| 492 | 492 | $new_path = self::_get_file_path( |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function __construct() { |
| 15 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters_deprecated' ) ); |
|
| 16 | - add_action( 'timber/twig/filters', array( $this, 'add_timber_filters' ) ); |
|
| 15 | + add_action('timber/twig/filters', array($this, 'add_timber_filters_deprecated')); |
|
| 16 | + add_action('timber/twig/filters', array($this, 'add_timber_filters')); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -23,14 +23,14 @@ discard block |
||
| 23 | 23 | * @deprecated since 0.20.7 |
| 24 | 24 | * @return Twig_Environment |
| 25 | 25 | */ |
| 26 | - function add_timber_filters_deprecated( $twig ) { |
|
| 27 | - $twig->addFilter( new Twig_SimpleFilter( 'get_src_from_attachment_id', 'twig_get_src_from_attachment_id' ) ); |
|
| 28 | - $twig->addFilter( new Twig_SimpleFilter( 'wp_body_class', array( $this, 'body_class' ) ) ); |
|
| 29 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterify', array( 'TimberHelper', 'twitterify' ) ) ); |
|
| 30 | - $twig->addFilter( new Twig_SimpleFilter( 'twitterfy', array( 'TimberHelper', 'twitterify' ) ) ); |
|
| 31 | - $twig->addFilter( new Twig_SimpleFilter( 'string', function($arr, $glue = ' '){ |
|
| 26 | + function add_timber_filters_deprecated($twig) { |
|
| 27 | + $twig->addFilter(new Twig_SimpleFilter('get_src_from_attachment_id', 'twig_get_src_from_attachment_id')); |
|
| 28 | + $twig->addFilter(new Twig_SimpleFilter('wp_body_class', array($this, 'body_class'))); |
|
| 29 | + $twig->addFilter(new Twig_SimpleFilter('twitterify', array('TimberHelper', 'twitterify'))); |
|
| 30 | + $twig->addFilter(new Twig_SimpleFilter('twitterfy', array('TimberHelper', 'twitterify'))); |
|
| 31 | + $twig->addFilter(new Twig_SimpleFilter('string', function($arr, $glue = ' ') { |
|
| 32 | 32 | return twig_join_filter($arr, $glue); |
| 33 | - } ) ); |
|
| 33 | + } )); |
|
| 34 | 34 | return $twig; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -40,151 +40,151 @@ discard block |
||
| 40 | 40 | * @param Twig_Environment $twig |
| 41 | 41 | * @return Twig_Environment |
| 42 | 42 | */ |
| 43 | - function add_timber_filters( $twig ) { |
|
| 43 | + function add_timber_filters($twig) { |
|
| 44 | 44 | /* image filters */ |
| 45 | - $twig->addFilter( new Twig_SimpleFilter( 'resize', array( 'TimberImageHelper', 'resize' ) ) ); |
|
| 46 | - $twig->addFilter( new Twig_SimpleFilter( 'retina', array( 'TimberImageHelper', 'retina_resize' ) ) ); |
|
| 47 | - $twig->addFilter( new Twig_SimpleFilter( 'letterbox', array( 'TimberImageHelper', 'letterbox' ) ) ); |
|
| 48 | - $twig->addFilter( new Twig_SimpleFilter( 'tojpg', array( 'TimberImageHelper', 'img_to_jpg' ) ) ); |
|
| 45 | + $twig->addFilter(new Twig_SimpleFilter('resize', array('TimberImageHelper', 'resize'))); |
|
| 46 | + $twig->addFilter(new Twig_SimpleFilter('retina', array('TimberImageHelper', 'retina_resize'))); |
|
| 47 | + $twig->addFilter(new Twig_SimpleFilter('letterbox', array('TimberImageHelper', 'letterbox'))); |
|
| 48 | + $twig->addFilter(new Twig_SimpleFilter('tojpg', array('TimberImageHelper', 'img_to_jpg'))); |
|
| 49 | 49 | |
| 50 | 50 | /* debugging filters */ |
| 51 | - $twig->addFilter( new Twig_SimpleFilter( 'docs', 'twig_object_docs' ) ); |
|
| 52 | - $twig->addFilter( new Twig_SimpleFilter( 'get_class', 'get_class' ) ); |
|
| 53 | - $twig->addFilter( new Twig_SimpleFilter( 'get_type', 'get_type' ) ); |
|
| 54 | - $twig->addFilter( new Twig_SimpleFilter( 'print_r', function( $arr ) { |
|
| 55 | - return print_r( $arr, true ); |
|
| 56 | - } ) ); |
|
| 57 | - $twig->addFilter( new Twig_SimpleFilter( 'print_a', function( $arr ) { |
|
| 58 | - return '<pre>' . self::object_docs( $arr, true ) . '</pre>'; |
|
| 59 | - } ) ); |
|
| 51 | + $twig->addFilter(new Twig_SimpleFilter('docs', 'twig_object_docs')); |
|
| 52 | + $twig->addFilter(new Twig_SimpleFilter('get_class', 'get_class')); |
|
| 53 | + $twig->addFilter(new Twig_SimpleFilter('get_type', 'get_type')); |
|
| 54 | + $twig->addFilter(new Twig_SimpleFilter('print_r', function($arr) { |
|
| 55 | + return print_r($arr, true); |
|
| 56 | + } )); |
|
| 57 | + $twig->addFilter(new Twig_SimpleFilter('print_a', function($arr) { |
|
| 58 | + return '<pre>' . self::object_docs($arr, true) . '</pre>'; |
|
| 59 | + } )); |
|
| 60 | 60 | |
| 61 | 61 | /* other filters */ |
| 62 | - $twig->addFilter( new Twig_SimpleFilter( 'stripshortcodes', 'strip_shortcodes' ) ); |
|
| 63 | - $twig->addFilter( new Twig_SimpleFilter( 'array', array( $this, 'to_array' ) ) ); |
|
| 64 | - $twig->addFilter( new Twig_SimpleFilter( 'excerpt', 'wp_trim_words' ) ); |
|
| 65 | - $twig->addFilter( new Twig_SimpleFilter( 'function', array( $this, 'exec_function' ) ) ); |
|
| 66 | - $twig->addFilter( new Twig_SimpleFilter( 'pretags', array( $this, 'twig_pretags' ) ) ); |
|
| 67 | - $twig->addFilter( new Twig_SimpleFilter( 'sanitize', 'sanitize_title' ) ); |
|
| 68 | - $twig->addFilter( new Twig_SimpleFilter( 'shortcodes', 'do_shortcode' ) ); |
|
| 69 | - $twig->addFilter( new Twig_SimpleFilter( 'time_ago', array( $this, 'time_ago' ) ) ); |
|
| 70 | - $twig->addFilter( new Twig_SimpleFilter( 'wpautop', 'wpautop' ) ); |
|
| 71 | - $twig->addFilter( new Twig_SimpleFilter( 'list', array( $this, 'add_list_separators' ) ) ); |
|
| 72 | - |
|
| 73 | - $twig->addFilter( new Twig_SimpleFilter( 'relative', function ( $link ) { |
|
| 74 | - return TimberURLHelper::get_rel_url( $link, true ); |
|
| 75 | - } ) ); |
|
| 76 | - |
|
| 77 | - $twig->addFilter( new Twig_SimpleFilter( 'date', array( $this, 'intl_date' ) ) ); |
|
| 78 | - |
|
| 79 | - $twig->addFilter( new Twig_SimpleFilter( 'truncate', function ( $text, $len ) { |
|
| 80 | - return TimberHelper::trim_words( $text, $len ); |
|
| 81 | - } ) ); |
|
| 62 | + $twig->addFilter(new Twig_SimpleFilter('stripshortcodes', 'strip_shortcodes')); |
|
| 63 | + $twig->addFilter(new Twig_SimpleFilter('array', array($this, 'to_array'))); |
|
| 64 | + $twig->addFilter(new Twig_SimpleFilter('excerpt', 'wp_trim_words')); |
|
| 65 | + $twig->addFilter(new Twig_SimpleFilter('function', array($this, 'exec_function'))); |
|
| 66 | + $twig->addFilter(new Twig_SimpleFilter('pretags', array($this, 'twig_pretags'))); |
|
| 67 | + $twig->addFilter(new Twig_SimpleFilter('sanitize', 'sanitize_title')); |
|
| 68 | + $twig->addFilter(new Twig_SimpleFilter('shortcodes', 'do_shortcode')); |
|
| 69 | + $twig->addFilter(new Twig_SimpleFilter('time_ago', array($this, 'time_ago'))); |
|
| 70 | + $twig->addFilter(new Twig_SimpleFilter('wpautop', 'wpautop')); |
|
| 71 | + $twig->addFilter(new Twig_SimpleFilter('list', array($this, 'add_list_separators'))); |
|
| 72 | + |
|
| 73 | + $twig->addFilter(new Twig_SimpleFilter('relative', function($link) { |
|
| 74 | + return TimberURLHelper::get_rel_url($link, true); |
|
| 75 | + } )); |
|
| 76 | + |
|
| 77 | + $twig->addFilter(new Twig_SimpleFilter('date', array($this, 'intl_date'))); |
|
| 78 | + |
|
| 79 | + $twig->addFilter(new Twig_SimpleFilter('truncate', function($text, $len) { |
|
| 80 | + return TimberHelper::trim_words($text, $len); |
|
| 81 | + } )); |
|
| 82 | 82 | |
| 83 | 83 | /* actions and filters */ |
| 84 | - $twig->addFunction( new Twig_SimpleFunction( 'action', function ( $context ) { |
|
| 84 | + $twig->addFunction(new Twig_SimpleFunction('action', function($context) { |
|
| 85 | 85 | $args = func_get_args(); |
| 86 | - array_shift( $args ); |
|
| 86 | + array_shift($args); |
|
| 87 | 87 | $args[] = $context; |
| 88 | - call_user_func_array( 'do_action', $args ); |
|
| 89 | - }, array( 'needs_context' => true ) ) ); |
|
| 88 | + call_user_func_array('do_action', $args); |
|
| 89 | + }, array('needs_context' => true))); |
|
| 90 | 90 | |
| 91 | - $twig->addFilter( new Twig_SimpleFilter( 'apply_filters', function () { |
|
| 91 | + $twig->addFilter(new Twig_SimpleFilter('apply_filters', function() { |
|
| 92 | 92 | $args = func_get_args(); |
| 93 | - $tag = current( array_splice( $args, 1, 1 ) ); |
|
| 93 | + $tag = current(array_splice($args, 1, 1)); |
|
| 94 | 94 | |
| 95 | - return apply_filters_ref_array( $tag, $args ); |
|
| 96 | - } ) ); |
|
| 97 | - $twig->addFunction( new Twig_SimpleFunction( 'function', array( &$this, 'exec_function' ) ) ); |
|
| 98 | - $twig->addFunction( new Twig_SimpleFunction( 'fn', array( &$this, 'exec_function' ) ) ); |
|
| 95 | + return apply_filters_ref_array($tag, $args); |
|
| 96 | + } )); |
|
| 97 | + $twig->addFunction(new Twig_SimpleFunction('function', array(&$this, 'exec_function'))); |
|
| 98 | + $twig->addFunction(new Twig_SimpleFunction('fn', array(&$this, 'exec_function'))); |
|
| 99 | 99 | |
| 100 | - $twig->addFunction( new Twig_SimpleFunction( 'shortcode', 'do_shortcode' ) ); |
|
| 100 | + $twig->addFunction(new Twig_SimpleFunction('shortcode', 'do_shortcode')); |
|
| 101 | 101 | |
| 102 | 102 | /* TimberObjects */ |
| 103 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberPost', function ( $pid, $PostClass = 'TimberPost' ) { |
|
| 104 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 105 | - foreach ( $pid as &$p ) { |
|
| 106 | - $p = new $PostClass( $p ); |
|
| 103 | + $twig->addFunction(new Twig_SimpleFunction('TimberPost', function($pid, $PostClass = 'TimberPost') { |
|
| 104 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 105 | + foreach ($pid as &$p) { |
|
| 106 | + $p = new $PostClass($p); |
|
| 107 | 107 | } |
| 108 | 108 | return $pid; |
| 109 | 109 | } |
| 110 | - return new $PostClass( $pid ); |
|
| 111 | - } ) ); |
|
| 112 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberImage', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
| 113 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 114 | - foreach ( $pid as &$p ) { |
|
| 115 | - $p = new $ImageClass( $p ); |
|
| 110 | + return new $PostClass($pid); |
|
| 111 | + } )); |
|
| 112 | + $twig->addFunction(new Twig_SimpleFunction('TimberImage', function($pid, $ImageClass = 'TimberImage') { |
|
| 113 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 114 | + foreach ($pid as &$p) { |
|
| 115 | + $p = new $ImageClass($p); |
|
| 116 | 116 | } |
| 117 | 117 | return $pid; |
| 118 | 118 | } |
| 119 | - return new $ImageClass( $pid ); |
|
| 120 | - } ) ); |
|
| 121 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberTerm', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
| 122 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 123 | - foreach ( $pid as &$p ) { |
|
| 124 | - $p = new $TermClass( $p ); |
|
| 119 | + return new $ImageClass($pid); |
|
| 120 | + } )); |
|
| 121 | + $twig->addFunction(new Twig_SimpleFunction('TimberTerm', function($pid, $TermClass = 'TimberTerm') { |
|
| 122 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 123 | + foreach ($pid as &$p) { |
|
| 124 | + $p = new $TermClass($p); |
|
| 125 | 125 | } |
| 126 | 126 | return $pid; |
| 127 | 127 | } |
| 128 | - return new $TermClass( $pid ); |
|
| 129 | - } ) ); |
|
| 130 | - $twig->addFunction( new Twig_SimpleFunction( 'TimberUser', function ( $pid, $UserClass = 'TimberUser' ) { |
|
| 131 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 132 | - foreach ( $pid as &$p ) { |
|
| 133 | - $p = new $UserClass( $p ); |
|
| 128 | + return new $TermClass($pid); |
|
| 129 | + } )); |
|
| 130 | + $twig->addFunction(new Twig_SimpleFunction('TimberUser', function($pid, $UserClass = 'TimberUser') { |
|
| 131 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 132 | + foreach ($pid as &$p) { |
|
| 133 | + $p = new $UserClass($p); |
|
| 134 | 134 | } |
| 135 | 135 | return $pid; |
| 136 | 136 | } |
| 137 | - return new $UserClass( $pid ); |
|
| 138 | - } ) ); |
|
| 137 | + return new $UserClass($pid); |
|
| 138 | + } )); |
|
| 139 | 139 | |
| 140 | 140 | /* TimberObjects Alias */ |
| 141 | - $twig->addFunction( new Twig_SimpleFunction( 'Post', function ( $pid, $PostClass = 'TimberPost' ) { |
|
| 142 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 143 | - foreach ( $pid as &$p ) { |
|
| 144 | - $p = new $PostClass( $p ); |
|
| 141 | + $twig->addFunction(new Twig_SimpleFunction('Post', function($pid, $PostClass = 'TimberPost') { |
|
| 142 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 143 | + foreach ($pid as &$p) { |
|
| 144 | + $p = new $PostClass($p); |
|
| 145 | 145 | } |
| 146 | 146 | return $pid; |
| 147 | 147 | } |
| 148 | - return new $PostClass( $pid ); |
|
| 149 | - } ) ); |
|
| 150 | - $twig->addFunction( new Twig_SimpleFunction( 'Image', function ( $pid, $ImageClass = 'TimberImage' ) { |
|
| 151 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 152 | - foreach ( $pid as &$p ) { |
|
| 153 | - $p = new $ImageClass( $p ); |
|
| 148 | + return new $PostClass($pid); |
|
| 149 | + } )); |
|
| 150 | + $twig->addFunction(new Twig_SimpleFunction('Image', function($pid, $ImageClass = 'TimberImage') { |
|
| 151 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 152 | + foreach ($pid as &$p) { |
|
| 153 | + $p = new $ImageClass($p); |
|
| 154 | 154 | } |
| 155 | 155 | return $pid; |
| 156 | 156 | } |
| 157 | - return new $ImageClass( $pid ); |
|
| 158 | - } ) ); |
|
| 159 | - $twig->addFunction( new Twig_SimpleFunction( 'Term', function ( $pid, $TermClass = 'TimberTerm' ) { |
|
| 160 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 161 | - foreach ( $pid as &$p ) { |
|
| 162 | - $p = new $TermClass( $p ); |
|
| 157 | + return new $ImageClass($pid); |
|
| 158 | + } )); |
|
| 159 | + $twig->addFunction(new Twig_SimpleFunction('Term', function($pid, $TermClass = 'TimberTerm') { |
|
| 160 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 161 | + foreach ($pid as &$p) { |
|
| 162 | + $p = new $TermClass($p); |
|
| 163 | 163 | } |
| 164 | 164 | return $pid; |
| 165 | 165 | } |
| 166 | - return new $TermClass( $pid ); |
|
| 167 | - } ) ); |
|
| 168 | - $twig->addFunction( new Twig_SimpleFunction( 'User', function ( $pid, $UserClass = 'TimberUser' ) { |
|
| 169 | - if ( is_array( $pid ) && !TimberHelper::is_array_assoc( $pid ) ) { |
|
| 170 | - foreach ( $pid as &$p ) { |
|
| 171 | - $p = new $UserClass( $p ); |
|
| 166 | + return new $TermClass($pid); |
|
| 167 | + } )); |
|
| 168 | + $twig->addFunction(new Twig_SimpleFunction('User', function($pid, $UserClass = 'TimberUser') { |
|
| 169 | + if ( is_array($pid) && !TimberHelper::is_array_assoc($pid) ) { |
|
| 170 | + foreach ($pid as &$p) { |
|
| 171 | + $p = new $UserClass($p); |
|
| 172 | 172 | } |
| 173 | 173 | return $pid; |
| 174 | 174 | } |
| 175 | - return new $UserClass( $pid ); |
|
| 176 | - } ) ); |
|
| 175 | + return new $UserClass($pid); |
|
| 176 | + } )); |
|
| 177 | 177 | |
| 178 | 178 | /* bloginfo and translate */ |
| 179 | - $twig->addFunction( 'bloginfo', new Twig_SimpleFunction( 'bloginfo', function ( $show = '', $filter = 'raw' ) { |
|
| 180 | - return get_bloginfo( $show, $filter ); |
|
| 181 | - } ) ); |
|
| 182 | - $twig->addFunction( '__', new Twig_SimpleFunction( '__', function ( $text, $domain = 'default' ) { |
|
| 183 | - return __( $text, $domain ); |
|
| 184 | - } ) ); |
|
| 179 | + $twig->addFunction('bloginfo', new Twig_SimpleFunction('bloginfo', function($show = '', $filter = 'raw') { |
|
| 180 | + return get_bloginfo($show, $filter); |
|
| 181 | + } )); |
|
| 182 | + $twig->addFunction('__', new Twig_SimpleFunction('__', function($text, $domain = 'default') { |
|
| 183 | + return __($text, $domain); |
|
| 184 | + } )); |
|
| 185 | 185 | /* get_twig is deprecated, use timber/twig */ |
| 186 | - $twig = apply_filters( 'get_twig', $twig ); |
|
| 187 | - $twig = apply_filters( 'timber/twig', $twig ); |
|
| 186 | + $twig = apply_filters('get_twig', $twig); |
|
| 187 | + $twig = apply_filters('timber/twig', $twig); |
|
| 188 | 188 | return $twig; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | * @param mixed $arr |
| 195 | 195 | * @return array |
| 196 | 196 | */ |
| 197 | - function to_array( $arr ) { |
|
| 198 | - if ( is_array( $arr ) ) { |
|
| 197 | + function to_array($arr) { |
|
| 198 | + if ( is_array($arr) ) { |
|
| 199 | 199 | return $arr; |
| 200 | 200 | } |
| 201 | - $arr = array( $arr ); |
|
| 201 | + $arr = array($arr); |
|
| 202 | 202 | return $arr; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -208,13 +208,13 @@ discard block |
||
| 208 | 208 | * @param string $function_name |
| 209 | 209 | * @return mixed |
| 210 | 210 | */ |
| 211 | - function exec_function( $function_name ) { |
|
| 211 | + function exec_function($function_name) { |
|
| 212 | 212 | $args = func_get_args(); |
| 213 | - array_shift( $args ); |
|
| 213 | + array_shift($args); |
|
| 214 | 214 | if ( is_string($function_name) ) { |
| 215 | - $function_name = trim( $function_name ); |
|
| 215 | + $function_name = trim($function_name); |
|
| 216 | 216 | } |
| 217 | - return call_user_func_array( $function_name, ( $args ) ); |
|
| 217 | + return call_user_func_array($function_name, ($args)); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * @param string $content |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - function twig_pretags( $content ) { |
|
| 227 | - return preg_replace_callback( '|<pre.*>(.*)</pre|isU', array( &$this, 'convert_pre_entities' ), $content ); |
|
| 226 | + function twig_pretags($content) { |
|
| 227 | + return preg_replace_callback('|<pre.*>(.*)</pre|isU', array(&$this, 'convert_pre_entities'), $content); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @param array $matches |
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | - function convert_pre_entities( $matches ) { |
|
| 237 | - return str_replace( $matches[1], htmlentities( $matches[1] ), $matches[0] ); |
|
| 236 | + function convert_pre_entities($matches) { |
|
| 237 | + return str_replace($matches[1], htmlentities($matches[1]), $matches[0]); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -242,12 +242,12 @@ discard block |
||
| 242 | 242 | * @deprecated 0.20.7 |
| 243 | 243 | * @return string |
| 244 | 244 | */ |
| 245 | - function body_class( $body_classes ) { |
|
| 245 | + function body_class($body_classes) { |
|
| 246 | 246 | ob_start(); |
| 247 | - if ( is_array( $body_classes ) ) { |
|
| 248 | - $body_classes = explode( ' ', $body_classes ); |
|
| 247 | + if ( is_array($body_classes) ) { |
|
| 248 | + $body_classes = explode(' ', $body_classes); |
|
| 249 | 249 | } |
| 250 | - body_class( $body_classes ); |
|
| 250 | + body_class($body_classes); |
|
| 251 | 251 | $return = ob_get_contents(); |
| 252 | 252 | ob_end_clean(); |
| 253 | 253 | return $return; |
@@ -260,20 +260,20 @@ discard block |
||
| 260 | 260 | * @param string $format (optional) |
| 261 | 261 | * @return string |
| 262 | 262 | */ |
| 263 | - function intl_date( $date, $format = null ) { |
|
| 263 | + function intl_date($date, $format = null) { |
|
| 264 | 264 | if ( $format === null ) { |
| 265 | - $format = get_option( 'date_format' ); |
|
| 265 | + $format = get_option('date_format'); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | if ( $date instanceof DateTime ) { |
| 269 | 269 | $timestamp = $date->getTimestamp(); |
| 270 | - } else if (is_numeric( $date ) && strtotime( $date ) === false ) { |
|
| 271 | - $timestamp = intval( $date ); |
|
| 270 | + } else if ( is_numeric($date) && strtotime($date) === false ) { |
|
| 271 | + $timestamp = intval($date); |
|
| 272 | 272 | } else { |
| 273 | - $timestamp = strtotime( $date ); |
|
| 273 | + $timestamp = strtotime($date); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - return date_i18n( $format, $timestamp ); |
|
| 276 | + return date_i18n($format, $timestamp); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | //debug |
@@ -285,17 +285,17 @@ discard block |
||
| 285 | 285 | * @param bool $methods |
| 286 | 286 | * @return string |
| 287 | 287 | */ |
| 288 | - function object_docs( $obj, $methods = true ) { |
|
| 289 | - $class = get_class( $obj ); |
|
| 290 | - $properties = (array)$obj; |
|
| 288 | + function object_docs($obj, $methods = true) { |
|
| 289 | + $class = get_class($obj); |
|
| 290 | + $properties = (array) $obj; |
|
| 291 | 291 | if ( $methods ) { |
| 292 | 292 | /** @var array $methods */ |
| 293 | 293 | $methods = $obj->get_method_values(); |
| 294 | 294 | } |
| 295 | - $rets = array_merge( $properties, $methods ); |
|
| 296 | - ksort( $rets ); |
|
| 297 | - $str = print_r( $rets, true ); |
|
| 298 | - $str = str_replace( 'Array', $class . ' Object', $str ); |
|
| 295 | + $rets = array_merge($properties, $methods); |
|
| 296 | + ksort($rets); |
|
| 297 | + $str = print_r($rets, true); |
|
| 298 | + $str = str_replace('Array', $class . ' Object', $str); |
|
| 299 | 299 | return $str; |
| 300 | 300 | } |
| 301 | 301 | |
@@ -306,15 +306,15 @@ discard block |
||
| 306 | 306 | * @param string $format_future |
| 307 | 307 | * @return string |
| 308 | 308 | */ |
| 309 | - function time_ago( $from, $to = null, $format_past = '%s ago', $format_future = '%s from now' ) { |
|
| 309 | + function time_ago($from, $to = null, $format_past = '%s ago', $format_future = '%s from now') { |
|
| 310 | 310 | $to = $to === null ? time() : $to; |
| 311 | - $to = is_int( $to ) ? $to : strtotime( $to ); |
|
| 312 | - $from = is_int( $from ) ? $from : strtotime( $from ); |
|
| 311 | + $to = is_int($to) ? $to : strtotime($to); |
|
| 312 | + $from = is_int($from) ? $from : strtotime($from); |
|
| 313 | 313 | |
| 314 | 314 | if ( $from < $to ) { |
| 315 | - return sprintf( $format_past, human_time_diff( $from, $to ) ); |
|
| 315 | + return sprintf($format_past, human_time_diff($from, $to)); |
|
| 316 | 316 | } else { |
| 317 | - return sprintf( $format_future, human_time_diff( $to, $from ) ); |
|
| 317 | + return sprintf($format_future, human_time_diff($to, $from)); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
@@ -324,18 +324,18 @@ discard block |
||
| 324 | 324 | * @param string $second_delimiter |
| 325 | 325 | * @return string |
| 326 | 326 | */ |
| 327 | - function add_list_separators( $arr, $first_delimiter = ',', $second_delimiter = 'and' ) { |
|
| 328 | - $length = count( $arr ); |
|
| 327 | + function add_list_separators($arr, $first_delimiter = ',', $second_delimiter = 'and') { |
|
| 328 | + $length = count($arr); |
|
| 329 | 329 | $list = ''; |
| 330 | - foreach( $arr as $index => $item ) { |
|
| 330 | + foreach ($arr as $index => $item) { |
|
| 331 | 331 | if ( $index < $length - 2 ) { |
| 332 | - $delimiter = $first_delimiter.' '; |
|
| 332 | + $delimiter = $first_delimiter . ' '; |
|
| 333 | 333 | } elseif ( $index == $length - 2 ) { |
| 334 | - $delimiter = ' '.$second_delimiter.' '; |
|
| 334 | + $delimiter = ' ' . $second_delimiter . ' '; |
|
| 335 | 335 | } else { |
| 336 | 336 | $delimiter = ''; |
| 337 | 337 | } |
| 338 | - $list = $list.$item.$delimiter; |
|
| 338 | + $list = $list . $item . $delimiter; |
|
| 339 | 339 | } |
| 340 | 340 | return $list; |
| 341 | 341 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @param mixed $pid |
| 169 | 169 | */ |
| 170 | 170 | public function __construct($pid = null) { |
| 171 | - $pid = $this->determine_id( $pid ); |
|
| 171 | + $pid = $this->determine_id($pid); |
|
| 172 | 172 | $this->init($pid); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | && get_class($wp_query->queried_object) == 'WP_Post' |
| 189 | 189 | ) { |
| 190 | 190 | $pid = $wp_query->queried_object_id; |
| 191 | - } else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) { |
|
| 191 | + } else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) { |
|
| 192 | 192 | //hack for static page as home page |
| 193 | 193 | $pid = $wp_query->queried_object_id; |
| 194 | 194 | } else if ( $pid === null ) { |
| 195 | 195 | $gtid = false; |
| 196 | 196 | $maybe_post = get_post(); |
| 197 | - if ( isset($maybe_post->ID) ){ |
|
| 197 | + if ( isset($maybe_post->ID) ) { |
|
| 198 | 198 | $gtid = true; |
| 199 | 199 | } |
| 200 | 200 | if ( $gtid ) { |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @param string $field |
| 261 | 261 | * @param mixed $value |
| 262 | 262 | */ |
| 263 | - public function update( $field, $value ) { |
|
| 263 | + public function update($field, $value) { |
|
| 264 | 264 | if ( isset($this->ID) ) { |
| 265 | 265 | update_post_meta($this->ID, $field, $value); |
| 266 | 266 | $this->$field = $value; |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @param mixed $pid |
| 276 | 276 | * @return WP_Post on success |
| 277 | 277 | */ |
| 278 | - protected function prepare_post_info( $pid = 0 ) { |
|
| 278 | + protected function prepare_post_info($pid = 0) { |
|
| 279 | 279 | if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) { |
| 280 | 280 | $pid = self::check_post_id($pid); |
| 281 | 281 | $post = get_post($pid); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @internal |
| 298 | 298 | * @return integer ID number of a post |
| 299 | 299 | */ |
| 300 | - protected function check_post_id( $pid ) { |
|
| 300 | + protected function check_post_id($pid) { |
|
| 301 | 301 | if ( is_numeric($pid) && $pid === 0 ) { |
| 302 | 302 | $pid = get_the_ID(); |
| 303 | 303 | return $pid; |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | global $wpdb; |
| 324 | 324 | $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name); |
| 325 | 325 | $result = $wpdb->get_row($query); |
| 326 | - if (!$result) { |
|
| 326 | + if ( !$result ) { |
|
| 327 | 327 | return null; |
| 328 | 328 | } |
| 329 | 329 | return $result->ID; |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $text = TimberHelper::trim_words($text, $len, false); |
| 363 | 363 | $trimmed = true; |
| 364 | 364 | } |
| 365 | - $text = do_shortcode( $text ); |
|
| 365 | + $text = do_shortcode($text); |
|
| 366 | 366 | } |
| 367 | 367 | if ( !strlen($text) ) { |
| 368 | 368 | $text = TimberHelper::trim_words($this->get_content(), $len, false); |
@@ -391,11 +391,11 @@ discard block |
||
| 391 | 391 | } |
| 392 | 392 | $read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more"); |
| 393 | 393 | if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) { |
| 394 | - $text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore_matches[1]) . '</a>'; |
|
| 394 | + $text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore_matches[1]) . '</a>'; |
|
| 395 | 395 | } elseif ( $readmore ) { |
| 396 | - $text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore) . '</a>'; |
|
| 396 | + $text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore) . '</a>'; |
|
| 397 | 397 | } |
| 398 | - if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) { |
|
| 398 | + if ( !$strip && $last_p_tag && (strpos($text, '<p>') || strpos($text, '<p ')) ) { |
|
| 399 | 399 | $text .= '</p>'; |
| 400 | 400 | } |
| 401 | 401 | } |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | * @internal |
| 408 | 408 | * @param bool|int $pid a post ID number |
| 409 | 409 | */ |
| 410 | - function import_custom( $pid = false ) { |
|
| 410 | + function import_custom($pid = false) { |
|
| 411 | 411 | if ( !$pid ) { |
| 412 | 412 | $pid = $this->ID; |
| 413 | 413 | } |
@@ -422,13 +422,13 @@ discard block |
||
| 422 | 422 | * @param int $pid |
| 423 | 423 | * @return array |
| 424 | 424 | */ |
| 425 | - protected function get_post_custom( $pid ) { |
|
| 425 | + protected function get_post_custom($pid) { |
|
| 426 | 426 | apply_filters('timber_post_get_meta_pre', array(), $pid, $this); |
| 427 | 427 | $customs = get_post_custom($pid); |
| 428 | 428 | if ( !is_array($customs) || empty($customs) ) { |
| 429 | 429 | return array(); |
| 430 | 430 | } |
| 431 | - foreach ( $customs as $key => $value ) { |
|
| 431 | + foreach ($customs as $key => $value) { |
|
| 432 | 432 | if ( is_array($value) && count($value) == 1 && isset($value[0]) ) { |
| 433 | 433 | $value = $value[0]; |
| 434 | 434 | } |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | * @param bool $taxonomy |
| 483 | 483 | * @return TimberPost|boolean |
| 484 | 484 | */ |
| 485 | - function get_next( $taxonomy = false ) { |
|
| 485 | + function get_next($taxonomy = false) { |
|
| 486 | 486 | if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) { |
| 487 | 487 | global $post; |
| 488 | 488 | $this->_next = array(); |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | $post = $this; |
| 514 | 514 | $ret = array(); |
| 515 | 515 | if ( $multipage ) { |
| 516 | - for ( $i = 1; $i <= $numpages; $i++ ) { |
|
| 516 | + for ($i = 1; $i <= $numpages; $i++) { |
|
| 517 | 517 | $link = self::get_wp_link_page($i); |
| 518 | 518 | $data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link); |
| 519 | 519 | if ( $i == $page ) { |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | * @param bool $taxonomy |
| 566 | 566 | * @return TimberPost|boolean |
| 567 | 567 | */ |
| 568 | - function get_prev( $taxonomy = false ) { |
|
| 568 | + function get_prev($taxonomy = false) { |
|
| 569 | 569 | if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) { |
| 570 | 570 | return $this->_prev[$taxonomy]; |
| 571 | 571 | } |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | $post->slug = $post->post_name; |
| 633 | 633 | $customs = $this->get_post_custom($post->ID); |
| 634 | 634 | $post->custom = $customs; |
| 635 | - $post = (object) array_merge((array)$customs, (array)$post); |
|
| 635 | + $post = (object) array_merge((array) $customs, (array) $post); |
|
| 636 | 636 | return $post; |
| 637 | 637 | } |
| 638 | 638 | |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | * @param string $use |
| 644 | 644 | * @return string |
| 645 | 645 | */ |
| 646 | - function get_display_date( $use = 'post_date' ) { |
|
| 646 | + function get_display_date($use = 'post_date') { |
|
| 647 | 647 | return date(get_option('date_format'), strtotime($this->$use)); |
| 648 | 648 | } |
| 649 | 649 | |
@@ -653,9 +653,9 @@ discard block |
||
| 653 | 653 | * @param string $date_format |
| 654 | 654 | * @return string |
| 655 | 655 | */ |
| 656 | - function get_date( $date_format = '' ) { |
|
| 656 | + function get_date($date_format = '') { |
|
| 657 | 657 | $df = $date_format ? $date_format : get_option('date_format'); |
| 658 | - $the_date = (string)mysql2date($df, $this->post_date); |
|
| 658 | + $the_date = (string) mysql2date($df, $this->post_date); |
|
| 659 | 659 | return apply_filters('get_the_date', $the_date, $df); |
| 660 | 660 | } |
| 661 | 661 | |
@@ -664,7 +664,7 @@ discard block |
||
| 664 | 664 | * @param string $date_format |
| 665 | 665 | * @return string |
| 666 | 666 | */ |
| 667 | - function get_modified_date( $date_format = '' ) { |
|
| 667 | + function get_modified_date($date_format = '') { |
|
| 668 | 668 | $df = $date_format ? $date_format : get_option('date_format'); |
| 669 | 669 | $the_time = $this->get_modified_time($df); |
| 670 | 670 | return apply_filters('get_the_modified_date', $the_time, $date_format); |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | * @param string $time_format |
| 676 | 676 | * @return string |
| 677 | 677 | */ |
| 678 | - function get_modified_time( $time_format = '' ) { |
|
| 678 | + function get_modified_time($time_format = '') { |
|
| 679 | 679 | $tf = $time_format ? $time_format : get_option('time_format'); |
| 680 | 680 | $the_time = get_post_modified_time($tf, false, $this->ID, true); |
| 681 | 681 | return apply_filters('get_the_modified_time', $the_time, $time_format); |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | * @param bool|string $childPostClass |
| 689 | 689 | * @return array |
| 690 | 690 | */ |
| 691 | - function get_children( $post_type = 'any', $childPostClass = false ) { |
|
| 691 | + function get_children($post_type = 'any', $childPostClass = false) { |
|
| 692 | 692 | if ( $childPostClass === false ) { |
| 693 | 693 | $childPostClass = $this->PostClass; |
| 694 | 694 | } |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | $post_type = $this->post_type; |
| 697 | 697 | } |
| 698 | 698 | $children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC'); |
| 699 | - foreach ( $children as &$child ) { |
|
| 699 | + foreach ($children as &$child) { |
|
| 700 | 700 | $child = new $childPostClass($child->ID); |
| 701 | 701 | } |
| 702 | 702 | $children = array_values($children); |
@@ -732,25 +732,25 @@ discard block |
||
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | if ( $user_ID ) { |
| 735 | - $args['include_unapproved'] = array( $user_ID ); |
|
| 736 | - } elseif ( ! empty( $comment_author_email ) ) { |
|
| 737 | - $args['include_unapproved'] = array( $comment_author_email ); |
|
| 735 | + $args['include_unapproved'] = array($user_ID); |
|
| 736 | + } elseif ( !empty($comment_author_email) ) { |
|
| 737 | + $args['include_unapproved'] = array($comment_author_email); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | $comments = get_comments($args); |
| 741 | 741 | $timber_comments = array(); |
| 742 | 742 | |
| 743 | 743 | if ( '' == get_query_var('cpage') && get_option('page_comments') ) { |
| 744 | - set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); |
|
| 744 | + set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); |
|
| 745 | 745 | $overridden_cpage = true; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - foreach( $comments as $key => &$comment ) { |
|
| 748 | + foreach ($comments as $key => &$comment) { |
|
| 749 | 749 | $timber_comment = new $CommentClass($comment); |
| 750 | 750 | $timber_comments[$timber_comment->id] = $timber_comment; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - foreach( $timber_comments as $key => $comment ) { |
|
| 753 | + foreach ($timber_comments as $key => $comment) { |
|
| 754 | 754 | if ( $comment->is_child() ) { |
| 755 | 755 | unset($timber_comments[$comment->id]); |
| 756 | 756 | |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | * @param string $TermClass |
| 795 | 795 | * @return array |
| 796 | 796 | */ |
| 797 | - function get_terms( $tax = '', $merge = true, $TermClass = '' ) { |
|
| 797 | + function get_terms($tax = '', $merge = true, $TermClass = '') { |
|
| 798 | 798 | |
| 799 | 799 | $TermClass = $TermClass ?: $this->TermClass; |
| 800 | 800 | |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | $taxonomies = $tax; |
| 806 | 806 | } |
| 807 | 807 | if ( is_string($tax) ) { |
| 808 | - if ( in_array($tax, array('all','any','')) ) { |
|
| 808 | + if ( in_array($tax, array('all', 'any', '')) ) { |
|
| 809 | 809 | $taxonomies = get_object_taxonomies($this->post_type); |
| 810 | 810 | } else { |
| 811 | 811 | $taxonomies = array($tax); |
@@ -814,8 +814,8 @@ discard block |
||
| 814 | 814 | |
| 815 | 815 | $term_class_objects = array(); |
| 816 | 816 | |
| 817 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 818 | - if ( in_array($taxonomy, array('tag','tags')) ) { |
|
| 817 | + foreach ($taxonomies as $taxonomy) { |
|
| 818 | + if ( in_array($taxonomy, array('tag', 'tags')) ) { |
|
| 819 | 819 | $taxonomy = 'post_tag'; |
| 820 | 820 | } |
| 821 | 821 | if ( $taxonomy == 'categories' ) { |
@@ -853,11 +853,11 @@ discard block |
||
| 853 | 853 | * @param string $taxonomy |
| 854 | 854 | * @return bool |
| 855 | 855 | */ |
| 856 | - function has_term( $term_name_or_id, $taxonomy = 'all' ) { |
|
| 856 | + function has_term($term_name_or_id, $taxonomy = 'all') { |
|
| 857 | 857 | if ( $taxonomy == 'all' || $taxonomy == 'any' ) { |
| 858 | 858 | $taxes = get_object_taxonomies($this->post_type, 'names'); |
| 859 | 859 | $ret = false; |
| 860 | - foreach ( $taxes as $tax ) { |
|
| 860 | + foreach ($taxes as $tax) { |
|
| 861 | 861 | if ( has_term($term_name_or_id, $tax, $this->ID) ) { |
| 862 | 862 | $ret = true; |
| 863 | 863 | break; |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | * @param string $field |
| 873 | 873 | * @return TimberImage |
| 874 | 874 | */ |
| 875 | - function get_image( $field ) { |
|
| 875 | + function get_image($field) { |
|
| 876 | 876 | return new $this->ImageClass($this->$field); |
| 877 | 877 | } |
| 878 | 878 | |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | * @param int $page |
| 923 | 923 | * @return string |
| 924 | 924 | */ |
| 925 | - function get_content( $len = 0, $page = 0 ) { |
|
| 925 | + function get_content($len = 0, $page = 0) { |
|
| 926 | 926 | if ( $len == 0 && $page == 0 && $this->_content ) { |
| 927 | 927 | return $this->_content; |
| 928 | 928 | } |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | * @param string $field_name |
| 984 | 984 | * @return mixed |
| 985 | 985 | */ |
| 986 | - public function get_field( $field_name ) { |
|
| 986 | + public function get_field($field_name) { |
|
| 987 | 987 | $value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this); |
| 988 | 988 | if ( $value === null ) { |
| 989 | 989 | $value = get_post_meta($this->ID, $field_name); |
@@ -1001,7 +1001,7 @@ discard block |
||
| 1001 | 1001 | /** |
| 1002 | 1002 | * @param string $field_name |
| 1003 | 1003 | */ |
| 1004 | - function import_field( $field_name ) { |
|
| 1004 | + function import_field($field_name) { |
|
| 1005 | 1005 | $this->$field_name = $this->get_field($field_name); |
| 1006 | 1006 | } |
| 1007 | 1007 | |
@@ -1032,13 +1032,13 @@ discard block |
||
| 1032 | 1032 | * ``` |
| 1033 | 1033 | * @return string a space-seperated list of classes |
| 1034 | 1034 | */ |
| 1035 | - public function post_class( $class='' ) { |
|
| 1035 | + public function post_class($class = '') { |
|
| 1036 | 1036 | global $post; |
| 1037 | 1037 | $old_global_post = $post; |
| 1038 | 1038 | $post = $this; |
| 1039 | 1039 | $class_array = get_post_class($class, $this->ID); |
| 1040 | 1040 | $post = $old_global_post; |
| 1041 | - if ( is_array($class_array) ){ |
|
| 1041 | + if ( is_array($class_array) ) { |
|
| 1042 | 1042 | return implode(' ', $class_array); |
| 1043 | 1043 | } |
| 1044 | 1044 | return $class_array; |
@@ -1140,8 +1140,8 @@ discard block |
||
| 1140 | 1140 | * @param string|bool $childPostClass _optional_ a custom post class (ex: 'MyTimberPost') to return the objects as. By default (false) it will use TimberPost::$post_class value. |
| 1141 | 1141 | * @return array |
| 1142 | 1142 | */ |
| 1143 | - public function children( $post_type = 'any', $childPostClass = false ) { |
|
| 1144 | - return $this->get_children( $post_type, $childPostClass ); |
|
| 1143 | + public function children($post_type = 'any', $childPostClass = false) { |
|
| 1144 | + return $this->get_children($post_type, $childPostClass); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
@@ -1165,7 +1165,7 @@ discard block |
||
| 1165 | 1165 | * ``` |
| 1166 | 1166 | * @return bool|array |
| 1167 | 1167 | */ |
| 1168 | - public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) { |
|
| 1168 | + public function comments($count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') { |
|
| 1169 | 1169 | return $this->get_comments($count, $order, $type, $status, $CommentClass); |
| 1170 | 1170 | } |
| 1171 | 1171 | |
@@ -1182,7 +1182,7 @@ discard block |
||
| 1182 | 1182 | * @param int $page |
| 1183 | 1183 | * @return string |
| 1184 | 1184 | */ |
| 1185 | - public function content( $page = 0 ) { |
|
| 1185 | + public function content($page = 0) { |
|
| 1186 | 1186 | return $this->get_content(0, $page); |
| 1187 | 1187 | } |
| 1188 | 1188 | |
@@ -1211,7 +1211,7 @@ discard block |
||
| 1211 | 1211 | * @param string $date_format |
| 1212 | 1212 | * @return string |
| 1213 | 1213 | */ |
| 1214 | - public function date( $date_format = '' ) { |
|
| 1214 | + public function date($date_format = '') { |
|
| 1215 | 1215 | return $this->get_date($date_format); |
| 1216 | 1216 | } |
| 1217 | 1217 | |
@@ -1233,9 +1233,9 @@ discard block |
||
| 1233 | 1233 | * @param string $time_format |
| 1234 | 1234 | * @return string |
| 1235 | 1235 | */ |
| 1236 | - public function time( $time_format = '' ) { |
|
| 1236 | + public function time($time_format = '') { |
|
| 1237 | 1237 | $tf = $time_format ? $time_format : get_option('time_format'); |
| 1238 | - $the_time = (string)mysql2date($tf, $this->post_date); |
|
| 1238 | + $the_time = (string) mysql2date($tf, $this->post_date); |
|
| 1239 | 1239 | return apply_filters('get_the_time', $the_time, $tf); |
| 1240 | 1240 | } |
| 1241 | 1241 | |
@@ -1271,7 +1271,7 @@ discard block |
||
| 1271 | 1271 | * @param string $field_name |
| 1272 | 1272 | * @return mixed |
| 1273 | 1273 | */ |
| 1274 | - public function meta( $field_name = null ) { |
|
| 1274 | + public function meta($field_name = null) { |
|
| 1275 | 1275 | if ( $field_name === null ) { |
| 1276 | 1276 | //on the off-chance the field is actually named meta |
| 1277 | 1277 | $field_name = 'meta'; |
@@ -1282,7 +1282,7 @@ discard block |
||
| 1282 | 1282 | /** |
| 1283 | 1283 | * @return string |
| 1284 | 1284 | */ |
| 1285 | - public function name(){ |
|
| 1285 | + public function name() { |
|
| 1286 | 1286 | return $this->title(); |
| 1287 | 1287 | } |
| 1288 | 1288 | |
@@ -1290,7 +1290,7 @@ discard block |
||
| 1290 | 1290 | * @param string $date_format |
| 1291 | 1291 | * @return string |
| 1292 | 1292 | */ |
| 1293 | - public function modified_date( $date_format = '' ) { |
|
| 1293 | + public function modified_date($date_format = '') { |
|
| 1294 | 1294 | return $this->get_modified_date($date_format); |
| 1295 | 1295 | } |
| 1296 | 1296 | |
@@ -1298,7 +1298,7 @@ discard block |
||
| 1298 | 1298 | * @param string $time_format |
| 1299 | 1299 | * @return string |
| 1300 | 1300 | */ |
| 1301 | - public function modified_time( $time_format = '' ) { |
|
| 1301 | + public function modified_time($time_format = '') { |
|
| 1302 | 1302 | return $this->get_modified_time($time_format); |
| 1303 | 1303 | } |
| 1304 | 1304 | |
@@ -1307,7 +1307,7 @@ discard block |
||
| 1307 | 1307 | * @param bool $in_same_cat |
| 1308 | 1308 | * @return mixed |
| 1309 | 1309 | */ |
| 1310 | - public function next( $in_same_cat = false ) { |
|
| 1310 | + public function next($in_same_cat = false) { |
|
| 1311 | 1311 | return $this->get_next($in_same_cat); |
| 1312 | 1312 | } |
| 1313 | 1313 | |
@@ -1365,7 +1365,7 @@ discard block |
||
| 1365 | 1365 | * @param bool $in_same_cat |
| 1366 | 1366 | * @return mixed |
| 1367 | 1367 | */ |
| 1368 | - public function prev( $in_same_cat = false ) { |
|
| 1368 | + public function prev($in_same_cat = false) { |
|
| 1369 | 1369 | return $this->get_prev($in_same_cat); |
| 1370 | 1370 | } |
| 1371 | 1371 | |
@@ -1377,7 +1377,7 @@ discard block |
||
| 1377 | 1377 | * @param bool $merge Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)? |
| 1378 | 1378 | * @return array |
| 1379 | 1379 | */ |
| 1380 | - public function terms( $tax = '', $merge = true ) { |
|
| 1380 | + public function terms($tax = '', $merge = true) { |
|
| 1381 | 1381 | return $this->get_terms($tax, $merge); |
| 1382 | 1382 | } |
| 1383 | 1383 | |