@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | public function __toString() { |
| 11 | 11 | try { |
| 12 | - return (string)$this->call(); |
|
| 12 | + return (string) $this->call(); |
|
| 13 | 13 | } catch (Exception $e) { |
| 14 | 14 | return 'Caught exception: ' . $e->getMessage() . "\n"; |
| 15 | 15 | } |
@@ -22,13 +22,13 @@ discard block |
||
| 22 | 22 | * @param array $args |
| 23 | 23 | * @param bool $return_output_buffer |
| 24 | 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' ) { |
|
| 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 | 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 | /** |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | * @param Twig_Environment $twig |
| 46 | 46 | * @return Twig_Environment |
| 47 | 47 | */ |
| 48 | - public function add_to_twig( $twig ) { |
|
| 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 | |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | * @param array $defaults |
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | - private function _parse_args( $args, $defaults ) { |
|
| 82 | - $_arg = reset( $defaults ); |
|
| 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 ); |
|
| 84 | + foreach ($args as $index => $arg) { |
|
| 85 | + $defaults[$index] = is_null($arg) ? $_arg : $arg; |
|
| 86 | + $_arg = next($defaults); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | return $defaults; |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | $this->w = $w; |
| 22 | 22 | $this->h = $h; |
| 23 | 23 | // Sanitize crop position |
| 24 | - $allowed_crop_positions = array( 'default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center' ); |
|
| 25 | - if ( $crop !== false && !in_array( $crop, $allowed_crop_positions ) ) { |
|
| 24 | + $allowed_crop_positions = array('default', 'center', 'top', 'bottom', 'left', 'right', 'top-center', 'bottom-center'); |
|
| 25 | + if ( $crop !== false && !in_array($crop, $allowed_crop_positions) ) { |
|
| 26 | 26 | $crop = $allowed_crop_positions[0]; |
| 27 | 27 | } |
| 28 | 28 | $this->crop = $crop; |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | if ( $this->h ) { |
| 43 | 43 | $h = $this->h; |
| 44 | 44 | } |
| 45 | - $result = $src_filename . '-' . $w . 'x' . $h . '-c-' . ( $this->crop ? $this->crop : 'f' ); // Crop will be either user named or f (false) |
|
| 46 | - if($src_extension) { |
|
| 47 | - $result .= '.'.$src_extension; |
|
| 45 | + $result = $src_filename . '-' . $w . 'x' . $h . '-c-' . ($this->crop ? $this->crop : 'f'); // Crop will be either user named or f (false) |
|
| 46 | + if ( $src_extension ) { |
|
| 47 | + $result .= '.' . $src_extension; |
|
| 48 | 48 | } |
| 49 | 49 | return $result; |
| 50 | 50 | } |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @param string $load_filename |
| 54 | 54 | * @param string $save_filename |
| 55 | 55 | */ |
| 56 | - protected function run_animated_gif( $load_filename, $save_filename ) { |
|
| 57 | - $image = wp_get_image_editor( $load_filename ); |
|
| 56 | + protected function run_animated_gif($load_filename, $save_filename) { |
|
| 57 | + $image = wp_get_image_editor($load_filename); |
|
| 58 | 58 | $current_size = $image->get_size(); |
| 59 | 59 | $src_w = $current_size['width']; |
| 60 | 60 | $src_h = $current_size['height']; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | $image = new Imagick($load_filename); |
| 67 | 67 | $image = $image->coalesceImages(); |
| 68 | - $crop = self::get_target_sizes( $load_filename ); |
|
| 68 | + $crop = self::get_target_sizes($load_filename); |
|
| 69 | 69 | foreach ($image as $frame) { |
| 70 | 70 | $frame->cropImage($crop['src_w'], $crop['src_h'], $crop['x'], $crop['y']); |
| 71 | 71 | $frame->thumbnailImage($w, $h); |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | return $image->writeImages($save_filename, true); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - protected function get_target_sizes( $load_filename ) { |
|
| 79 | - $image = wp_get_image_editor( $load_filename ); |
|
| 78 | + protected function get_target_sizes($load_filename) { |
|
| 79 | + $image = wp_get_image_editor($load_filename); |
|
| 80 | 80 | $w = $this->w; |
| 81 | 81 | $h = $this->h; |
| 82 | 82 | $crop = $this->crop; |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | $src_h = $current_size['height']; |
| 87 | 87 | $src_ratio = $src_w / $src_h; |
| 88 | 88 | if ( !$h ) { |
| 89 | - $h = round( $w / $src_ratio ); |
|
| 89 | + $h = round($w / $src_ratio); |
|
| 90 | 90 | } |
| 91 | 91 | if ( !$w ) { |
| 92 | 92 | //the user wants to resize based on constant height |
| 93 | - $w = round( $h * $src_ratio ); |
|
| 93 | + $w = round($h * $src_ratio); |
|
| 94 | 94 | } |
| 95 | 95 | if ( !$crop ) { |
| 96 | 96 | return array( |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | $src_wt = $src_h * $dest_ratio; |
| 105 | 105 | $src_ht = $src_w / $dest_ratio; |
| 106 | 106 | $src_x = $src_w / 2 - $src_wt / 2; |
| 107 | - $src_y = ( $src_h - $src_ht ) / 6; |
|
| 107 | + $src_y = ($src_h - $src_ht) / 6; |
|
| 108 | 108 | //now specific overrides based on options: |
| 109 | - switch ( $crop ) { |
|
| 109 | + switch ($crop) { |
|
| 110 | 110 | case 'center': |
| 111 | 111 | // Get source x and y |
| 112 | - $src_x = round( ( $src_w - $src_wt ) / 2 ); |
|
| 113 | - $src_y = round( ( $src_h - $src_ht ) / 2 ); |
|
| 112 | + $src_x = round(($src_w - $src_wt) / 2); |
|
| 113 | + $src_y = round(($src_h - $src_ht) / 2); |
|
| 114 | 114 | break; |
| 115 | 115 | |
| 116 | 116 | case 'top': |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | break; |
| 123 | 123 | |
| 124 | 124 | case 'top-center': |
| 125 | - $src_y = round( ( $src_h - $src_ht ) / 4 ); |
|
| 125 | + $src_y = round(($src_h - $src_ht) / 4); |
|
| 126 | 126 | break; |
| 127 | 127 | |
| 128 | 128 | case 'bottom-center': |
| 129 | - $src_y = $src_h - $src_ht - round( ( $src_h - $src_ht ) / 4 ); |
|
| 129 | + $src_y = $src_h - $src_ht - round(($src_h - $src_ht) / 4); |
|
| 130 | 130 | break; |
| 131 | 131 | |
| 132 | 132 | case 'left': |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | break; |
| 139 | 139 | } |
| 140 | 140 | // Crop the image |
| 141 | - return ( $dest_ratio > $src_ratio ) |
|
| 141 | + return ($dest_ratio > $src_ratio) |
|
| 142 | 142 | ? array( |
| 143 | 143 | 'x' => 0, 'y' => $src_y, |
| 144 | 144 | 'src_w' => $src_w, 'src_h' => $src_ht, |
@@ -168,35 +168,35 @@ discard block |
||
| 168 | 168 | //return if successful |
| 169 | 169 | //proceed if not |
| 170 | 170 | $gif = self::run_animated_gif($load_filename, $save_filename); |
| 171 | - if ($gif) { |
|
| 171 | + if ( $gif ) { |
|
| 172 | 172 | return true; |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | - $image = wp_get_image_editor( $load_filename ); |
|
| 176 | - if ( !is_wp_error( $image ) ) { |
|
| 177 | - $crop = self::get_target_sizes( $load_filename ); |
|
| 178 | - $image->crop( $crop['x'], |
|
| 175 | + $image = wp_get_image_editor($load_filename); |
|
| 176 | + if ( !is_wp_error($image) ) { |
|
| 177 | + $crop = self::get_target_sizes($load_filename); |
|
| 178 | + $image->crop($crop['x'], |
|
| 179 | 179 | $crop['y'], |
| 180 | 180 | $crop['src_w'], |
| 181 | 181 | $crop['src_h'], |
| 182 | 182 | $crop['target_w'], |
| 183 | 183 | $crop['target_h'] |
| 184 | 184 | ); |
| 185 | - $result = $image->save( $save_filename ); |
|
| 186 | - if ( is_wp_error( $result ) ) { |
|
| 185 | + $result = $image->save($save_filename); |
|
| 186 | + if ( is_wp_error($result) ) { |
|
| 187 | 187 | // @codeCoverageIgnoreStart |
| 188 | - TimberHelper::error_log( 'Error resizing image' ); |
|
| 189 | - TimberHelper::error_log( $result ); |
|
| 188 | + TimberHelper::error_log('Error resizing image'); |
|
| 189 | + TimberHelper::error_log($result); |
|
| 190 | 190 | return false; |
| 191 | 191 | // @codeCoverageIgnoreEnd |
| 192 | 192 | } else { |
| 193 | 193 | return true; |
| 194 | 194 | } |
| 195 | - } else if ( isset( $image->error_data['error_loading_image'] ) ) { |
|
| 195 | + } else if ( isset($image->error_data['error_loading_image']) ) { |
|
| 196 | 196 | // @codeCoverageIgnoreStart |
| 197 | - TimberHelper::error_log( 'Error loading ' . $image->error_data['error_loading_image'] ); |
|
| 197 | + TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']); |
|
| 198 | 198 | } else { |
| 199 | - TimberHelper::error_log( $image ); |
|
| 199 | + TimberHelper::error_log($image); |
|
| 200 | 200 | // @codeCoverageIgnoreEnd |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -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,15 +426,15 @@ 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 | $external = false; |
| 434 | 434 | |
| 435 | 435 | // if external image, load it first |
| 436 | - if ( TimberURLHelper::is_external_content( $src ) ) { |
|
| 437 | - $src = self::sideload_image( $src ); |
|
| 436 | + if ( TimberURLHelper::is_external_content($src) ) { |
|
| 437 | + $src = self::sideload_image($src); |
|
| 438 | 438 | $external = true; |
| 439 | 439 | } |
| 440 | 440 | // break down URL into components |
@@ -457,19 +457,19 @@ discard block |
||
| 457 | 457 | $au['basename'] |
| 458 | 458 | ); |
| 459 | 459 | // if already exists... |
| 460 | - if ( file_exists( $new_server_path ) ) { |
|
| 460 | + if ( file_exists($new_server_path) ) { |
|
| 461 | 461 | if ( $force ) { |
| 462 | 462 | // Force operation - warning: will regenerate the image on every pageload, use for testing purposes only! |
| 463 | - unlink( $new_server_path ); |
|
| 463 | + unlink($new_server_path); |
|
| 464 | 464 | } else { |
| 465 | 465 | // return existing file (caching) |
| 466 | 466 | return $new_url; |
| 467 | 467 | } |
| 468 | 468 | } |
| 469 | 469 | // otherwise generate result file |
| 470 | - if($op->run($old_server_path, $new_server_path)) { |
|
| 471 | - if( get_class( $op ) === 'TimberImageOperationResize' && $external ) { |
|
| 472 | - $new_url = strtolower( $new_url ); |
|
| 470 | + if ( $op->run($old_server_path, $new_server_path) ) { |
|
| 471 | + if ( get_class($op) === 'TimberImageOperationResize' && $external ) { |
|
| 472 | + $new_url = strtolower($new_url); |
|
| 473 | 473 | } |
| 474 | 474 | return $new_url; |
| 475 | 475 | } else { |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | ); |
| 493 | 493 | return $new_url; |
| 494 | 494 | } |
| 495 | - public static function get_letterbox_file_path($url, $w, $h, $color ) { |
|
| 495 | + public static function get_letterbox_file_path($url, $w, $h, $color) { |
|
| 496 | 496 | $au = self::analyze_url($url); |
| 497 | 497 | $op = new TimberImageOperationLetterbox($w, $h, $color); |
| 498 | 498 | $new_path = self::_get_file_path( |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | if ( is_admin() || $_SERVER['PHP_SELF'] == '/wp-login.php' ) { |
| 46 | 46 | return; |
| 47 | 47 | } |
| 48 | - if ( version_compare( phpversion(), '5.3.0', '<' ) && !is_admin() ) { |
|
| 49 | - trigger_error( 'Timber requires PHP 5.3.0 or greater. You have '.phpversion(), E_USER_ERROR ); |
|
| 48 | + if ( version_compare(phpversion(), '5.3.0', '<') && !is_admin() ) { |
|
| 49 | + trigger_error('Timber requires PHP 5.3.0 or greater. You have ' . phpversion(), E_USER_ERROR); |
|
| 50 | 50 | } |
| 51 | - if ( !class_exists( 'Twig_Autoloader' ) ) { |
|
| 52 | - trigger_error( 'You have not run "composer install" to download required dependencies for Timber, you can read more on https://github.com/jarednova/timber#installation', E_USER_ERROR ); |
|
| 51 | + if ( !class_exists('Twig_Autoloader') ) { |
|
| 52 | + trigger_error('You have not run "composer install" to download required dependencies for Timber, you can read more on https://github.com/jarednova/timber#installation', E_USER_ERROR); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function init_constants() { |
| 57 | - defined( "TIMBER_LOC" ) or define( "TIMBER_LOC", realpath( dirname(__DIR__) ) ); |
|
| 57 | + defined("TIMBER_LOC") or define("TIMBER_LOC", realpath(dirname(__DIR__))); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | protected function init() { |
| 64 | 64 | TimberTwig::init(); |
| 65 | - TimberRoutes::init( $this ); |
|
| 65 | + TimberRoutes::init($this); |
|
| 66 | 66 | TimberImageHelper::init(); |
| 67 | 67 | TimberAdmin::init(); |
| 68 | 68 | TimberIntegrations::init(); |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | * @param string $PostClass |
| 79 | 79 | * @return array|bool|null |
| 80 | 80 | */ |
| 81 | - public static function get_post( $query = false, $PostClass = 'TimberPost' ) { |
|
| 82 | - return TimberPostGetter::get_post( $query, $PostClass ); |
|
| 81 | + public static function get_post($query = false, $PostClass = 'TimberPost') { |
|
| 82 | + return TimberPostGetter::get_post($query, $PostClass); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | * @param string $PostClass |
| 90 | 90 | * @return array|bool|null |
| 91 | 91 | */ |
| 92 | - public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) { |
|
| 93 | - return TimberPostGetter::get_posts( $query, $PostClass, $return_collection ); |
|
| 92 | + public static function get_posts($query = false, $PostClass = 'TimberPost', $return_collection = false) { |
|
| 93 | + return TimberPostGetter::get_posts($query, $PostClass, $return_collection); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | * @param string $PostClass |
| 101 | 101 | * @return array|bool|null |
| 102 | 102 | */ |
| 103 | - public static function query_post( $query = false, $PostClass = 'TimberPost' ) { |
|
| 104 | - return TimberPostGetter::query_post( $query, $PostClass ); |
|
| 103 | + public static function query_post($query = false, $PostClass = 'TimberPost') { |
|
| 104 | + return TimberPostGetter::query_post($query, $PostClass); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | * @param string $PostClass |
| 112 | 112 | * @return array|bool|null |
| 113 | 113 | */ |
| 114 | - public static function query_posts( $query = false, $PostClass = 'TimberPost' ) { |
|
| 115 | - return TimberPostGetter::query_posts( $query, $PostClass ); |
|
| 114 | + public static function query_posts($query = false, $PostClass = 'TimberPost') { |
|
| 115 | + return TimberPostGetter::query_posts($query, $PostClass); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | * @param string $TermClass |
| 137 | 137 | * @return mixed |
| 138 | 138 | */ |
| 139 | - public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) { |
|
| 140 | - return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass ); |
|
| 139 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
| 140 | + return TimberTermGetter::get_terms($args, $maybe_args, $TermClass); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /* Site Retrieval |
@@ -149,14 +149,14 @@ discard block |
||
| 149 | 149 | * @param array|bool $blog_ids |
| 150 | 150 | * @return array |
| 151 | 151 | */ |
| 152 | - public static function get_sites( $blog_ids = false ) { |
|
| 153 | - if ( !is_array( $blog_ids ) ) { |
|
| 152 | + public static function get_sites($blog_ids = false) { |
|
| 153 | + if ( !is_array($blog_ids) ) { |
|
| 154 | 154 | global $wpdb; |
| 155 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" ); |
|
| 155 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC"); |
|
| 156 | 156 | } |
| 157 | 157 | $return = array(); |
| 158 | - foreach ( $blog_ids as $blog_id ) { |
|
| 159 | - $return[] = new TimberSite( $blog_id ); |
|
| 158 | + foreach ($blog_ids as $blog_id) { |
|
| 159 | + $return[] = new TimberSite($blog_id); |
|
| 160 | 160 | } |
| 161 | 161 | return $return; |
| 162 | 162 | } |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | $data = array(); |
| 175 | 175 | $data['http_host'] = 'http://' . TimberURLHelper::get_host(); |
| 176 | 176 | $data['wp_title'] = TimberHelper::get_wp_title(); |
| 177 | - $data['wp_head'] = TimberHelper::function_wrapper( 'wp_head' ); |
|
| 178 | - $data['wp_footer'] = TimberHelper::function_wrapper( 'wp_footer' ); |
|
| 179 | - $data['body_class'] = implode( ' ', get_body_class() ); |
|
| 177 | + $data['wp_head'] = TimberHelper::function_wrapper('wp_head'); |
|
| 178 | + $data['wp_footer'] = TimberHelper::function_wrapper('wp_footer'); |
|
| 179 | + $data['body_class'] = implode(' ', get_body_class()); |
|
| 180 | 180 | |
| 181 | 181 | $data['site'] = new TimberSite(); |
| 182 | 182 | $data['request'] = new TimberRequest(); |
@@ -184,8 +184,8 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | $data['posts'] = Timber::query_posts(); |
| 186 | 186 | |
| 187 | - $data = apply_filters( 'timber_context', $data ); |
|
| 188 | - $data = apply_filters( 'timber/context', $data ); |
|
| 187 | + $data = apply_filters('timber_context', $data); |
|
| 188 | + $data = apply_filters('timber/context', $data); |
|
| 189 | 189 | return $data; |
| 190 | 190 | } |
| 191 | 191 | |
@@ -199,27 +199,27 @@ discard block |
||
| 199 | 199 | * @param bool $via_render |
| 200 | 200 | * @return bool|string |
| 201 | 201 | */ |
| 202 | - public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false ) { |
|
| 202 | + public static function compile($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false) { |
|
| 203 | 203 | $caller = self::get_calling_script_dir(); |
| 204 | 204 | $caller_file = self::get_calling_script_file(); |
| 205 | - $caller_file = apply_filters( 'timber_calling_php_file', $caller_file ); |
|
| 206 | - $loader = new TimberLoader( $caller ); |
|
| 207 | - $file = $loader->choose_template( $filenames ); |
|
| 205 | + $caller_file = apply_filters('timber_calling_php_file', $caller_file); |
|
| 206 | + $loader = new TimberLoader($caller); |
|
| 207 | + $file = $loader->choose_template($filenames); |
|
| 208 | 208 | $output = ''; |
| 209 | - if ( is_null( $data ) ) { |
|
| 209 | + if ( is_null($data) ) { |
|
| 210 | 210 | $data = array(); |
| 211 | 211 | } |
| 212 | - if ( strlen( $file ) ) { |
|
| 212 | + if ( strlen($file) ) { |
|
| 213 | 213 | if ( $via_render ) { |
| 214 | - $file = apply_filters( 'timber_render_file', $file ); |
|
| 215 | - $data = apply_filters( 'timber_render_data', $data ); |
|
| 214 | + $file = apply_filters('timber_render_file', $file); |
|
| 215 | + $data = apply_filters('timber_render_data', $data); |
|
| 216 | 216 | } else { |
| 217 | - $file = apply_filters( 'timber_compile_file', $file ); |
|
| 218 | - $data = apply_filters( 'timber_compile_data', $data ); |
|
| 217 | + $file = apply_filters('timber_compile_file', $file); |
|
| 218 | + $data = apply_filters('timber_compile_data', $data); |
|
| 219 | 219 | } |
| 220 | - $output = $loader->render( $file, $data, $expires, $cache_mode ); |
|
| 220 | + $output = $loader->render($file, $data, $expires, $cache_mode); |
|
| 221 | 221 | } |
| 222 | - do_action( 'timber_compile_done' ); |
|
| 222 | + do_action('timber_compile_done'); |
|
| 223 | 223 | return $output; |
| 224 | 224 | } |
| 225 | 225 | |
@@ -230,14 +230,14 @@ discard block |
||
| 230 | 230 | * @param array $data an array with data in it. |
| 231 | 231 | * @return bool|string |
| 232 | 232 | */ |
| 233 | - public static function compile_string( $string, $data = array() ) { |
|
| 233 | + public static function compile_string($string, $data = array()) { |
|
| 234 | 234 | $dummy_loader = new TimberLoader(); |
| 235 | 235 | $dummy_loader->get_twig(); |
| 236 | 236 | $loader = new Twig_Loader_String(); |
| 237 | - $twig = new Twig_Environment( $loader ); |
|
| 238 | - $twig = apply_filters( 'timber/twig/filters', $twig ); |
|
| 239 | - $twig = apply_filters( 'twig_apply_filters', $twig ); |
|
| 240 | - return $twig->render( $string, $data ); |
|
| 237 | + $twig = new Twig_Environment($loader); |
|
| 238 | + $twig = apply_filters('timber/twig/filters', $twig); |
|
| 239 | + $twig = apply_filters('twig_apply_filters', $twig); |
|
| 240 | + return $twig->render($string, $data); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -249,15 +249,15 @@ discard block |
||
| 249 | 249 | * @param string $cache_mode |
| 250 | 250 | * @return bool|string |
| 251 | 251 | */ |
| 252 | - public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) { |
|
| 252 | + public static function fetch($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) { |
|
| 253 | 253 | if ( $expires === true ) { |
| 254 | 254 | //if this is reading as true; the user probably is using the old $echo param |
| 255 | 255 | //so we should move all vars up by a spot |
| 256 | 256 | $expires = $cache_mode; |
| 257 | 257 | $cache_mode = TimberLoader::CACHE_USE_DEFAULT; |
| 258 | 258 | } |
| 259 | - $output = self::compile( $filenames, $data, $expires, $cache_mode, true ); |
|
| 260 | - $output = apply_filters( 'timber_compile_result', $output ); |
|
| 259 | + $output = self::compile($filenames, $data, $expires, $cache_mode, true); |
|
| 260 | + $output = apply_filters('timber_compile_result', $output); |
|
| 261 | 261 | return $output; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * @param string $cache_mode |
| 271 | 271 | * @return bool|string |
| 272 | 272 | */ |
| 273 | - public static function render( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) { |
|
| 274 | - $output = static::fetch( $filenames, $data, $expires, $cache_mode ); |
|
| 273 | + public static function render($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) { |
|
| 274 | + $output = static::fetch($filenames, $data, $expires, $cache_mode); |
|
| 275 | 275 | echo $output; |
| 276 | 276 | return $output; |
| 277 | 277 | } |
@@ -283,8 +283,8 @@ discard block |
||
| 283 | 283 | * @param array $data an array with data in it. |
| 284 | 284 | * @return bool|string |
| 285 | 285 | */ |
| 286 | - public static function render_string( $string, $data = array() ) { |
|
| 287 | - $compiled = self::compile_string( $string, $data ); |
|
| 286 | + public static function render_string($string, $data = array()) { |
|
| 287 | + $compiled = self::compile_string($string, $data); |
|
| 288 | 288 | echo $compiled; |
| 289 | 289 | return $compiled; |
| 290 | 290 | } |
@@ -300,14 +300,14 @@ discard block |
||
| 300 | 300 | * @param array $data |
| 301 | 301 | * @return bool|string |
| 302 | 302 | */ |
| 303 | - public static function get_sidebar( $sidebar = '', $data = array() ) { |
|
| 303 | + public static function get_sidebar($sidebar = '', $data = array()) { |
|
| 304 | 304 | if ( $sidebar == '' ) { |
| 305 | 305 | $sidebar = 'sidebar.php'; |
| 306 | 306 | } |
| 307 | - if ( strstr( strtolower( $sidebar ), '.php' ) ) { |
|
| 308 | - return self::get_sidebar_from_php( $sidebar, $data ); |
|
| 307 | + if ( strstr(strtolower($sidebar), '.php') ) { |
|
| 308 | + return self::get_sidebar_from_php($sidebar, $data); |
|
| 309 | 309 | } |
| 310 | - return self::compile( $sidebar, $data ); |
|
| 310 | + return self::compile($sidebar, $data); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
@@ -317,21 +317,21 @@ discard block |
||
| 317 | 317 | * @param array $data |
| 318 | 318 | * @return string |
| 319 | 319 | */ |
| 320 | - public static function get_sidebar_from_php( $sidebar = '', $data ) { |
|
| 320 | + public static function get_sidebar_from_php($sidebar = '', $data) { |
|
| 321 | 321 | $caller = self::get_calling_script_dir(); |
| 322 | 322 | $loader = new TimberLoader(); |
| 323 | - $uris = $loader->get_locations( $caller ); |
|
| 323 | + $uris = $loader->get_locations($caller); |
|
| 324 | 324 | ob_start(); |
| 325 | 325 | $found = false; |
| 326 | - foreach ( $uris as $uri ) { |
|
| 327 | - if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) { |
|
| 328 | - include trailingslashit( $uri ) . $sidebar; |
|
| 326 | + foreach ($uris as $uri) { |
|
| 327 | + if ( file_exists(trailingslashit($uri) . $sidebar) ) { |
|
| 328 | + include trailingslashit($uri) . $sidebar; |
|
| 329 | 329 | $found = true; |
| 330 | 330 | break; |
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | 333 | if ( !$found ) { |
| 334 | - TimberHelper::error_log( 'error loading your sidebar, check to make sure the file exists' ); |
|
| 334 | + TimberHelper::error_log('error loading your sidebar, check to make sure the file exists'); |
|
| 335 | 335 | } |
| 336 | 336 | $ret = ob_get_contents(); |
| 337 | 337 | ob_end_clean(); |
@@ -347,8 +347,8 @@ discard block |
||
| 347 | 347 | * @param int $widget_id |
| 348 | 348 | * @return TimberFunctionWrapper |
| 349 | 349 | */ |
| 350 | - public static function get_widgets( $widget_id ) { |
|
| 351 | - return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) ); |
|
| 350 | + public static function get_widgets($widget_id) { |
|
| 351 | + return trim(TimberHelper::function_wrapper('dynamic_sidebar', array($widget_id), true)); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -363,8 +363,8 @@ discard block |
||
| 363 | 363 | * @param array $args |
| 364 | 364 | * @deprecated since 0.20.0 |
| 365 | 365 | */ |
| 366 | - public static function add_route( $route, $callback, $args = array() ) { |
|
| 367 | - Routes::map( $route, $callback, $args ); |
|
| 366 | + public static function add_route($route, $callback, $args = array()) { |
|
| 367 | + Routes::map($route, $callback, $args); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | * |
| 373 | 373 | * @deprecated since 0.20.0 |
| 374 | 374 | */ |
| 375 | - public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) { |
|
| 376 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
| 375 | + public static function load_template($template, $query = false, $status_code = 200, $tparams = false) { |
|
| 376 | + return Routes::load($template, $tparams, $query, $status_code); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | * |
| 382 | 382 | * @deprecated since 0.20.2 |
| 383 | 383 | */ |
| 384 | - public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) { |
|
| 385 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
| 384 | + public static function load_view($template, $query = false, $status_code = 200, $tparams = false) { |
|
| 385 | + return Routes::load($template, $tparams, $query, $status_code); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | |
@@ -395,43 +395,43 @@ discard block |
||
| 395 | 395 | * @param array $prefs |
| 396 | 396 | * @return array mixed |
| 397 | 397 | */ |
| 398 | - public static function get_pagination( $prefs = array() ) { |
|
| 398 | + public static function get_pagination($prefs = array()) { |
|
| 399 | 399 | global $wp_query; |
| 400 | 400 | global $paged; |
| 401 | 401 | global $wp_rewrite; |
| 402 | 402 | $args = array(); |
| 403 | - $args['total'] = ceil( $wp_query->found_posts / $wp_query->query_vars['posts_per_page'] ); |
|
| 403 | + $args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']); |
|
| 404 | 404 | if ( $wp_rewrite->using_permalinks() ) { |
| 405 | - $url = explode( '?', get_pagenum_link( 0 ) ); |
|
| 406 | - if ( isset( $url[1] ) ) { |
|
| 407 | - parse_str( $url[1], $query ); |
|
| 405 | + $url = explode('?', get_pagenum_link(0)); |
|
| 406 | + if ( isset($url[1]) ) { |
|
| 407 | + parse_str($url[1], $query); |
|
| 408 | 408 | $args['add_args'] = $query; |
| 409 | 409 | } |
| 410 | 410 | $args['format'] = 'page/%#%'; |
| 411 | - $args['base'] = trailingslashit( $url[0] ).'%_%'; |
|
| 411 | + $args['base'] = trailingslashit($url[0]) . '%_%'; |
|
| 412 | 412 | } else { |
| 413 | 413 | $big = 999999999; |
| 414 | - $args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ); |
|
| 414 | + $args['base'] = str_replace($big, '%#%', esc_url(get_pagenum_link($big))); |
|
| 415 | 415 | } |
| 416 | 416 | $args['type'] = 'array'; |
| 417 | - $args['current'] = max( 1, get_query_var( 'paged' ) ); |
|
| 418 | - $args['mid_size'] = max( 9 - $args['current'], 3 ); |
|
| 419 | - if ( is_int( $prefs ) ) { |
|
| 417 | + $args['current'] = max(1, get_query_var('paged')); |
|
| 418 | + $args['mid_size'] = max(9 - $args['current'], 3); |
|
| 419 | + if ( is_int($prefs) ) { |
|
| 420 | 420 | $args['mid_size'] = $prefs - 2; |
| 421 | 421 | } else { |
| 422 | - $args = array_merge( $args, $prefs ); |
|
| 422 | + $args = array_merge($args, $prefs); |
|
| 423 | 423 | } |
| 424 | 424 | $data = array(); |
| 425 | 425 | $data['current'] = $args['current']; |
| 426 | 426 | $data['total'] = $args['total']; |
| 427 | - $data['pages'] = TimberHelper::paginate_links( $args ); |
|
| 428 | - $next = get_next_posts_page_link( $args['total'] ); |
|
| 427 | + $data['pages'] = TimberHelper::paginate_links($args); |
|
| 428 | + $next = get_next_posts_page_link($args['total']); |
|
| 429 | 429 | if ( $next ) { |
| 430 | - $data['next'] = array( 'link' => untrailingslashit( $next ), 'class' => 'page-numbers next' ); |
|
| 430 | + $data['next'] = array('link' => untrailingslashit($next), 'class' => 'page-numbers next'); |
|
| 431 | 431 | } |
| 432 | - $prev = previous_posts( false ); |
|
| 432 | + $prev = previous_posts(false); |
|
| 433 | 433 | if ( $prev ) { |
| 434 | - $data['prev'] = array( 'link' => untrailingslashit( $prev ), 'class' => 'page-numbers prev' ); |
|
| 434 | + $data['prev'] = array('link' => untrailingslashit($prev), 'class' => 'page-numbers prev'); |
|
| 435 | 435 | } |
| 436 | 436 | if ( $paged < 2 ) { |
| 437 | 437 | $data['prev'] = ''; |
@@ -447,10 +447,10 @@ discard block |
||
| 447 | 447 | * |
| 448 | 448 | * @return string |
| 449 | 449 | */ |
| 450 | - public static function get_calling_script_dir( $offset = 0 ) { |
|
| 451 | - $caller = self::get_calling_script_file( $offset ); |
|
| 452 | - if ( !is_null( $caller ) ) { |
|
| 453 | - $pathinfo = pathinfo( $caller ); |
|
| 450 | + public static function get_calling_script_dir($offset = 0) { |
|
| 451 | + $caller = self::get_calling_script_file($offset); |
|
| 452 | + if ( !is_null($caller) ) { |
|
| 453 | + $pathinfo = pathinfo($caller); |
|
| 454 | 454 | $dir = $pathinfo['dirname']; |
| 455 | 455 | return $dir; |
| 456 | 456 | } |
@@ -463,11 +463,11 @@ discard block |
||
| 463 | 463 | * @return string|null |
| 464 | 464 | * @deprecated since 0.20.0 |
| 465 | 465 | */ |
| 466 | - public static function get_calling_script_file( $offset = 0 ) { |
|
| 466 | + public static function get_calling_script_file($offset = 0) { |
|
| 467 | 467 | $caller = null; |
| 468 | 468 | $backtrace = debug_backtrace(); |
| 469 | 469 | $i = 0; |
| 470 | - foreach ( $backtrace as $trace ) { |
|
| 470 | + foreach ($backtrace as $trace) { |
|
| 471 | 471 | if ( array_key_exists('file', $trace) && $trace['file'] != __FILE__ ) { |
| 472 | 472 | $caller = $trace['file']; |
| 473 | 473 | break; |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @param mixed $pid |
| 163 | 163 | */ |
| 164 | 164 | public function __construct($pid = null) { |
| 165 | - $pid = $this->determine_id( $pid ); |
|
| 165 | + $pid = $this->determine_id($pid); |
|
| 166 | 166 | $this->init($pid); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -181,18 +181,18 @@ discard block |
||
| 181 | 181 | && is_object($wp_query->queried_object) |
| 182 | 182 | && get_class($wp_query->queried_object) == 'WP_Post' |
| 183 | 183 | ) { |
| 184 | - if( isset( $_GET['preview'] ) && isset( $_GET['preview_nonce'] ) && wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $wp_query->queried_object_id ) ) { |
|
| 185 | - $pid = $this->get_post_preview_id( $wp_query ); |
|
| 184 | + if ( isset($_GET['preview']) && isset($_GET['preview_nonce']) && wp_verify_nonce($_GET['preview_nonce'], 'post_preview_' . $wp_query->queried_object_id) ) { |
|
| 185 | + $pid = $this->get_post_preview_id($wp_query); |
|
| 186 | 186 | } else if ( !$pid ) { |
| 187 | 187 | $pid = $wp_query->queried_object_id; |
| 188 | 188 | } |
| 189 | - } else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) { |
|
| 189 | + } else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) { |
|
| 190 | 190 | //hack for static page as home page |
| 191 | 191 | $pid = $wp_query->queried_object_id; |
| 192 | 192 | } else if ( $pid === null ) { |
| 193 | 193 | $gtid = false; |
| 194 | 194 | $maybe_post = get_post(); |
| 195 | - if ( isset($maybe_post->ID) ){ |
|
| 195 | + if ( isset($maybe_post->ID) ) { |
|
| 196 | 196 | $gtid = true; |
| 197 | 197 | } |
| 198 | 198 | if ( $gtid ) { |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | return $this->title(); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - protected function get_post_preview_id( $query ) { |
|
| 222 | + protected function get_post_preview_id($query) { |
|
| 223 | 223 | $can = array( |
| 224 | 224 | 'edit_' . $query->queried_object->post_type . 's', |
| 225 | 225 | ); |
@@ -230,19 +230,19 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | $can_preview = array(); |
| 232 | 232 | |
| 233 | - foreach( $can as $type ) { |
|
| 234 | - if( current_user_can( $type ) ) { |
|
| 233 | + foreach ($can as $type) { |
|
| 234 | + if ( current_user_can($type) ) { |
|
| 235 | 235 | $can_preview[] = true; |
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - if ( count( $can_preview ) !== count( $can ) ) { |
|
| 239 | + if ( count($can_preview) !== count($can) ) { |
|
| 240 | 240 | return; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - $revisions = wp_get_post_revisions( $query->queried_object_id ); |
|
| 243 | + $revisions = wp_get_post_revisions($query->queried_object_id); |
|
| 244 | 244 | |
| 245 | - if( !empty( $revisions ) ) { |
|
| 245 | + if ( !empty($revisions) ) { |
|
| 246 | 246 | $last = end($revisions); |
| 247 | 247 | return $last->ID; |
| 248 | 248 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * @param string $field |
| 287 | 287 | * @param mixed $value |
| 288 | 288 | */ |
| 289 | - public function update( $field, $value ) { |
|
| 289 | + public function update($field, $value) { |
|
| 290 | 290 | if ( isset($this->ID) ) { |
| 291 | 291 | update_post_meta($this->ID, $field, $value); |
| 292 | 292 | $this->$field = $value; |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @param mixed $pid |
| 302 | 302 | * @return WP_Post on success |
| 303 | 303 | */ |
| 304 | - protected function prepare_post_info( $pid = 0 ) { |
|
| 304 | + protected function prepare_post_info($pid = 0) { |
|
| 305 | 305 | if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) { |
| 306 | 306 | $pid = self::check_post_id($pid); |
| 307 | 307 | $post = get_post($pid); |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @internal |
| 321 | 321 | * @return integer ID number of a post |
| 322 | 322 | */ |
| 323 | - protected function check_post_id( $pid ) { |
|
| 323 | + protected function check_post_id($pid) { |
|
| 324 | 324 | if ( is_numeric($pid) && $pid === 0 ) { |
| 325 | 325 | $pid = get_the_ID(); |
| 326 | 326 | return $pid; |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | global $wpdb; |
| 347 | 347 | $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name); |
| 348 | 348 | $result = $wpdb->get_row($query); |
| 349 | - if (!$result) { |
|
| 349 | + if ( !$result ) { |
|
| 350 | 350 | return null; |
| 351 | 351 | } |
| 352 | 352 | return $result->ID; |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | $text = TimberHelper::trim_words($text, $len, false); |
| 387 | 387 | $trimmed = true; |
| 388 | 388 | } |
| 389 | - $text = do_shortcode( $text ); |
|
| 389 | + $text = do_shortcode($text); |
|
| 390 | 390 | } |
| 391 | 391 | if ( !strlen($text) ) { |
| 392 | 392 | $text = TimberHelper::trim_words($this->get_content(), $len, false); |
@@ -416,11 +416,11 @@ discard block |
||
| 416 | 416 | } |
| 417 | 417 | $read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more"); |
| 418 | 418 | if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) { |
| 419 | - $text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore_matches[1]) . '</a>'; |
|
| 419 | + $text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore_matches[1]) . '</a>'; |
|
| 420 | 420 | } elseif ( $readmore ) { |
| 421 | - $text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore) . '</a>'; |
|
| 421 | + $text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore) . '</a>'; |
|
| 422 | 422 | } |
| 423 | - if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) { |
|
| 423 | + if ( !$strip && $last_p_tag && (strpos($text, '<p>') || strpos($text, '<p ')) ) { |
|
| 424 | 424 | $text .= '</p>'; |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | * @internal |
| 433 | 433 | * @param bool|int $pid a post ID number |
| 434 | 434 | */ |
| 435 | - function import_custom( $pid = false ) { |
|
| 435 | + function import_custom($pid = false) { |
|
| 436 | 436 | if ( !$pid ) { |
| 437 | 437 | $pid = $this->ID; |
| 438 | 438 | } |
@@ -447,13 +447,13 @@ discard block |
||
| 447 | 447 | * @param int $pid |
| 448 | 448 | * @return array |
| 449 | 449 | */ |
| 450 | - protected function get_post_custom( $pid ) { |
|
| 450 | + protected function get_post_custom($pid) { |
|
| 451 | 451 | apply_filters('timber_post_get_meta_pre', array(), $pid, $this); |
| 452 | 452 | $customs = get_post_custom($pid); |
| 453 | 453 | if ( !is_array($customs) || empty($customs) ) { |
| 454 | 454 | return array(); |
| 455 | 455 | } |
| 456 | - foreach ( $customs as $key => $value ) { |
|
| 456 | + foreach ($customs as $key => $value) { |
|
| 457 | 457 | if ( is_array($value) && count($value) == 1 && isset($value[0]) ) { |
| 458 | 458 | $value = $value[0]; |
| 459 | 459 | } |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | * @param bool $taxonomy |
| 508 | 508 | * @return TimberPost|boolean |
| 509 | 509 | */ |
| 510 | - function get_next( $taxonomy = false ) { |
|
| 510 | + function get_next($taxonomy = false) { |
|
| 511 | 511 | if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) { |
| 512 | 512 | global $post; |
| 513 | 513 | $this->_next = array(); |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | $post = $this; |
| 539 | 539 | $ret = array(); |
| 540 | 540 | if ( $multipage ) { |
| 541 | - for ( $i = 1; $i <= $numpages; $i++ ) { |
|
| 541 | + for ($i = 1; $i <= $numpages; $i++) { |
|
| 542 | 542 | $link = self::get_wp_link_page($i); |
| 543 | 543 | $data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link); |
| 544 | 544 | if ( $i == $page ) { |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * @param bool $taxonomy |
| 591 | 591 | * @return TimberPost|boolean |
| 592 | 592 | */ |
| 593 | - function get_prev( $taxonomy = false ) { |
|
| 593 | + function get_prev($taxonomy = false) { |
|
| 594 | 594 | if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) { |
| 595 | 595 | return $this->_prev[$taxonomy]; |
| 596 | 596 | } |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | $post->slug = $post->post_name; |
| 658 | 658 | $customs = $this->get_post_custom($post->ID); |
| 659 | 659 | $post->custom = $customs; |
| 660 | - $post = (object) array_merge((array)$customs, (array)$post); |
|
| 660 | + $post = (object) array_merge((array) $customs, (array) $post); |
|
| 661 | 661 | return $post; |
| 662 | 662 | } |
| 663 | 663 | |
@@ -667,9 +667,9 @@ discard block |
||
| 667 | 667 | * @param string $date_format |
| 668 | 668 | * @return string |
| 669 | 669 | */ |
| 670 | - function get_date( $date_format = '' ) { |
|
| 670 | + function get_date($date_format = '') { |
|
| 671 | 671 | $df = $date_format ? $date_format : get_option('date_format'); |
| 672 | - $the_date = (string)mysql2date($df, $this->post_date); |
|
| 672 | + $the_date = (string) mysql2date($df, $this->post_date); |
|
| 673 | 673 | return apply_filters('get_the_date', $the_date, $df); |
| 674 | 674 | } |
| 675 | 675 | |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | * @param string $date_format |
| 679 | 679 | * @return string |
| 680 | 680 | */ |
| 681 | - function get_modified_date( $date_format = '' ) { |
|
| 681 | + function get_modified_date($date_format = '') { |
|
| 682 | 682 | $df = $date_format ? $date_format : get_option('date_format'); |
| 683 | 683 | $the_time = $this->get_modified_time($df); |
| 684 | 684 | return apply_filters('get_the_modified_date', $the_time, $date_format); |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | * @param string $time_format |
| 690 | 690 | * @return string |
| 691 | 691 | */ |
| 692 | - function get_modified_time( $time_format = '' ) { |
|
| 692 | + function get_modified_time($time_format = '') { |
|
| 693 | 693 | $tf = $time_format ? $time_format : get_option('time_format'); |
| 694 | 694 | $the_time = get_post_modified_time($tf, false, $this->ID, true); |
| 695 | 695 | return apply_filters('get_the_modified_time', $the_time, $time_format); |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | * @param bool|string $childPostClass |
| 703 | 703 | * @return array |
| 704 | 704 | */ |
| 705 | - function get_children( $post_type = 'any', $childPostClass = false ) { |
|
| 705 | + function get_children($post_type = 'any', $childPostClass = false) { |
|
| 706 | 706 | if ( $childPostClass === false ) { |
| 707 | 707 | $childPostClass = $this->PostClass; |
| 708 | 708 | } |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | $post_type = $this->post_type; |
| 711 | 711 | } |
| 712 | 712 | $children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC&post_status=publish'); |
| 713 | - foreach ( $children as &$child ) { |
|
| 713 | + foreach ($children as &$child) { |
|
| 714 | 714 | $child = new $childPostClass($child->ID); |
| 715 | 715 | } |
| 716 | 716 | $children = array_values($children); |
@@ -747,42 +747,42 @@ discard block |
||
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | if ( $user_ID ) { |
| 750 | - $args['include_unapproved'] = array( $user_ID ); |
|
| 751 | - } elseif ( ! empty( $comment_author_email ) ) { |
|
| 752 | - $args['include_unapproved'] = array( $comment_author_email ); |
|
| 750 | + $args['include_unapproved'] = array($user_ID); |
|
| 751 | + } elseif ( !empty($comment_author_email) ) { |
|
| 752 | + $args['include_unapproved'] = array($comment_author_email); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | $comments = get_comments($args); |
| 756 | 756 | $timber_comments = array(); |
| 757 | 757 | |
| 758 | 758 | if ( '' == get_query_var('cpage') && get_option('page_comments') ) { |
| 759 | - set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); |
|
| 759 | + set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); |
|
| 760 | 760 | $overridden_cpage = true; |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - foreach($comments as $key => &$comment) { |
|
| 763 | + foreach ($comments as $key => &$comment) { |
|
| 764 | 764 | $timber_comment = new $CommentClass($comment); |
| 765 | 765 | $timber_comments[$timber_comment->id] = $timber_comment; |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | // Build a flattened (depth=1) comment tree |
| 769 | 769 | $comments_tree = array(); |
| 770 | - foreach( $timber_comments as $key => $comment ) { |
|
| 771 | - if ( ! $comment->is_child() ) { |
|
| 770 | + foreach ($timber_comments as $key => $comment) { |
|
| 771 | + if ( !$comment->is_child() ) { |
|
| 772 | 772 | continue; |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | $tree_element = $comment; |
| 776 | 776 | do { |
| 777 | 777 | $tree_element = $timber_comments[$tree_element->comment_parent]; |
| 778 | - } while( $tree_element->is_child() ); |
|
| 778 | + } while ($tree_element->is_child()); |
|
| 779 | 779 | |
| 780 | 780 | $comments_tree[$tree_element->id][] = $comment->id; |
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | // Add child comments to the relative "super parents" |
| 784 | - foreach($comments_tree as $comment_parent => $comment_children) { |
|
| 785 | - foreach($comment_children as $comment_child) { |
|
| 784 | + foreach ($comments_tree as $comment_parent => $comment_children) { |
|
| 785 | + foreach ($comment_children as $comment_child) { |
|
| 786 | 786 | $timber_comments[$comment_parent]->children[] = $timber_comments[$comment_child]; |
| 787 | 787 | unset($timber_comments[$comment_child]); |
| 788 | 788 | } |
@@ -822,7 +822,7 @@ discard block |
||
| 822 | 822 | * @param string $TermClass |
| 823 | 823 | * @return array |
| 824 | 824 | */ |
| 825 | - function get_terms( $tax = '', $merge = true, $TermClass = '' ) { |
|
| 825 | + function get_terms($tax = '', $merge = true, $TermClass = '') { |
|
| 826 | 826 | |
| 827 | 827 | $TermClass = $TermClass ?: $this->TermClass; |
| 828 | 828 | |
@@ -833,7 +833,7 @@ discard block |
||
| 833 | 833 | $taxonomies = $tax; |
| 834 | 834 | } |
| 835 | 835 | if ( is_string($tax) ) { |
| 836 | - if ( in_array($tax, array('all','any','')) ) { |
|
| 836 | + if ( in_array($tax, array('all', 'any', '')) ) { |
|
| 837 | 837 | $taxonomies = get_object_taxonomies($this->post_type); |
| 838 | 838 | } else { |
| 839 | 839 | $taxonomies = array($tax); |
@@ -842,8 +842,8 @@ discard block |
||
| 842 | 842 | |
| 843 | 843 | $term_class_objects = array(); |
| 844 | 844 | |
| 845 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 846 | - if ( in_array($taxonomy, array('tag','tags')) ) { |
|
| 845 | + foreach ($taxonomies as $taxonomy) { |
|
| 846 | + if ( in_array($taxonomy, array('tag', 'tags')) ) { |
|
| 847 | 847 | $taxonomy = 'post_tag'; |
| 848 | 848 | } |
| 849 | 849 | if ( $taxonomy == 'categories' ) { |
@@ -880,11 +880,11 @@ discard block |
||
| 880 | 880 | * @param string $taxonomy |
| 881 | 881 | * @return bool |
| 882 | 882 | */ |
| 883 | - function has_term( $term_name_or_id, $taxonomy = 'all' ) { |
|
| 883 | + function has_term($term_name_or_id, $taxonomy = 'all') { |
|
| 884 | 884 | if ( $taxonomy == 'all' || $taxonomy == 'any' ) { |
| 885 | 885 | $taxes = get_object_taxonomies($this->post_type, 'names'); |
| 886 | 886 | $ret = false; |
| 887 | - foreach ( $taxes as $tax ) { |
|
| 887 | + foreach ($taxes as $tax) { |
|
| 888 | 888 | if ( has_term($term_name_or_id, $tax, $this->ID) ) { |
| 889 | 889 | $ret = true; |
| 890 | 890 | break; |
@@ -899,7 +899,7 @@ discard block |
||
| 899 | 899 | * @param string $field |
| 900 | 900 | * @return TimberImage |
| 901 | 901 | */ |
| 902 | - function get_image( $field ) { |
|
| 902 | + function get_image($field) { |
|
| 903 | 903 | return new $this->ImageClass($this->$field); |
| 904 | 904 | } |
| 905 | 905 | |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | * @param int $page |
| 950 | 950 | * @return string |
| 951 | 951 | */ |
| 952 | - function get_content( $len = 0, $page = 0 ) { |
|
| 952 | + function get_content($len = 0, $page = 0) { |
|
| 953 | 953 | if ( $len == 0 && $page == 0 && $this->_content ) { |
| 954 | 954 | return $this->_content; |
| 955 | 955 | } |
@@ -1006,7 +1006,7 @@ discard block |
||
| 1006 | 1006 | * @param string $field_name |
| 1007 | 1007 | * @return mixed |
| 1008 | 1008 | */ |
| 1009 | - public function get_field( $field_name ) { |
|
| 1009 | + public function get_field($field_name) { |
|
| 1010 | 1010 | $value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this); |
| 1011 | 1011 | if ( $value === null ) { |
| 1012 | 1012 | $value = get_post_meta($this->ID, $field_name); |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | /** |
| 1025 | 1025 | * @param string $field_name |
| 1026 | 1026 | */ |
| 1027 | - function import_field( $field_name ) { |
|
| 1027 | + function import_field($field_name) { |
|
| 1028 | 1028 | $this->$field_name = $this->get_field($field_name); |
| 1029 | 1029 | } |
| 1030 | 1030 | |
@@ -1055,13 +1055,13 @@ discard block |
||
| 1055 | 1055 | * ``` |
| 1056 | 1056 | * @return string a space-seperated list of classes |
| 1057 | 1057 | */ |
| 1058 | - public function post_class( $class='' ) { |
|
| 1058 | + public function post_class($class = '') { |
|
| 1059 | 1059 | global $post; |
| 1060 | 1060 | $old_global_post = $post; |
| 1061 | 1061 | $post = $this; |
| 1062 | 1062 | $class_array = get_post_class($class, $this->ID); |
| 1063 | 1063 | $post = $old_global_post; |
| 1064 | - if ( is_array($class_array) ){ |
|
| 1064 | + if ( is_array($class_array) ) { |
|
| 1065 | 1065 | return implode(' ', $class_array); |
| 1066 | 1066 | } |
| 1067 | 1067 | return $class_array; |
@@ -1163,8 +1163,8 @@ discard block |
||
| 1163 | 1163 | * @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. |
| 1164 | 1164 | * @return array |
| 1165 | 1165 | */ |
| 1166 | - public function children( $post_type = 'any', $childPostClass = false ) { |
|
| 1167 | - return $this->get_children( $post_type, $childPostClass ); |
|
| 1166 | + public function children($post_type = 'any', $childPostClass = false) { |
|
| 1167 | + return $this->get_children($post_type, $childPostClass); |
|
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | /** |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | * ``` |
| 1189 | 1189 | * @return bool|array |
| 1190 | 1190 | */ |
| 1191 | - public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) { |
|
| 1191 | + public function comments($count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') { |
|
| 1192 | 1192 | return $this->get_comments($count, $order, $type, $status, $CommentClass); |
| 1193 | 1193 | } |
| 1194 | 1194 | |
@@ -1205,7 +1205,7 @@ discard block |
||
| 1205 | 1205 | * @param int $page |
| 1206 | 1206 | * @return string |
| 1207 | 1207 | */ |
| 1208 | - public function content( $page = 0 ) { |
|
| 1208 | + public function content($page = 0) { |
|
| 1209 | 1209 | return $this->get_content(0, $page); |
| 1210 | 1210 | } |
| 1211 | 1211 | |
@@ -1234,7 +1234,7 @@ discard block |
||
| 1234 | 1234 | * @param string $date_format |
| 1235 | 1235 | * @return string |
| 1236 | 1236 | */ |
| 1237 | - public function date( $date_format = '' ) { |
|
| 1237 | + public function date($date_format = '') { |
|
| 1238 | 1238 | return $this->get_date($date_format); |
| 1239 | 1239 | } |
| 1240 | 1240 | |
@@ -1256,9 +1256,9 @@ discard block |
||
| 1256 | 1256 | * @param string $time_format |
| 1257 | 1257 | * @return string |
| 1258 | 1258 | */ |
| 1259 | - public function time( $time_format = '' ) { |
|
| 1259 | + public function time($time_format = '') { |
|
| 1260 | 1260 | $tf = $time_format ? $time_format : get_option('time_format'); |
| 1261 | - $the_time = (string)mysql2date($tf, $this->post_date); |
|
| 1261 | + $the_time = (string) mysql2date($tf, $this->post_date); |
|
| 1262 | 1262 | return apply_filters('get_the_time', $the_time, $tf); |
| 1263 | 1263 | } |
| 1264 | 1264 | |
@@ -1294,7 +1294,7 @@ discard block |
||
| 1294 | 1294 | * @param string $field_name |
| 1295 | 1295 | * @return mixed |
| 1296 | 1296 | */ |
| 1297 | - public function meta( $field_name = null ) { |
|
| 1297 | + public function meta($field_name = null) { |
|
| 1298 | 1298 | if ( $field_name === null ) { |
| 1299 | 1299 | //on the off-chance the field is actually named meta |
| 1300 | 1300 | $field_name = 'meta'; |
@@ -1305,7 +1305,7 @@ discard block |
||
| 1305 | 1305 | /** |
| 1306 | 1306 | * @return string |
| 1307 | 1307 | */ |
| 1308 | - public function name(){ |
|
| 1308 | + public function name() { |
|
| 1309 | 1309 | return $this->title(); |
| 1310 | 1310 | } |
| 1311 | 1311 | |
@@ -1313,7 +1313,7 @@ discard block |
||
| 1313 | 1313 | * @param string $date_format |
| 1314 | 1314 | * @return string |
| 1315 | 1315 | */ |
| 1316 | - public function modified_date( $date_format = '' ) { |
|
| 1316 | + public function modified_date($date_format = '') { |
|
| 1317 | 1317 | return $this->get_modified_date($date_format); |
| 1318 | 1318 | } |
| 1319 | 1319 | |
@@ -1321,7 +1321,7 @@ discard block |
||
| 1321 | 1321 | * @param string $time_format |
| 1322 | 1322 | * @return string |
| 1323 | 1323 | */ |
| 1324 | - public function modified_time( $time_format = '' ) { |
|
| 1324 | + public function modified_time($time_format = '') { |
|
| 1325 | 1325 | return $this->get_modified_time($time_format); |
| 1326 | 1326 | } |
| 1327 | 1327 | |
@@ -1330,7 +1330,7 @@ discard block |
||
| 1330 | 1330 | * @param bool $in_same_cat |
| 1331 | 1331 | * @return mixed |
| 1332 | 1332 | */ |
| 1333 | - public function next( $in_same_cat = false ) { |
|
| 1333 | + public function next($in_same_cat = false) { |
|
| 1334 | 1334 | return $this->get_next($in_same_cat); |
| 1335 | 1335 | } |
| 1336 | 1336 | |
@@ -1388,7 +1388,7 @@ discard block |
||
| 1388 | 1388 | * @param bool $in_same_cat |
| 1389 | 1389 | * @return mixed |
| 1390 | 1390 | */ |
| 1391 | - public function prev( $in_same_cat = false ) { |
|
| 1391 | + public function prev($in_same_cat = false) { |
|
| 1392 | 1392 | return $this->get_prev($in_same_cat); |
| 1393 | 1393 | } |
| 1394 | 1394 | |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | * @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)? |
| 1401 | 1401 | * @return array |
| 1402 | 1402 | */ |
| 1403 | - public function terms( $tax = '', $merge = true ) { |
|
| 1403 | + public function terms($tax = '', $merge = true) { |
|
| 1404 | 1404 | return $this->get_terms($tax, $merge); |
| 1405 | 1405 | } |
| 1406 | 1406 | |