@@ -26,13 +26,13 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function __construct( $data ) { |
| 28 | 28 | $data = (object) $data; |
| 29 | - $this->import( $data ); |
|
| 30 | - $this->import_classes( $data ); |
|
| 31 | - if ( isset( $this->name ) ) { |
|
| 29 | + $this->import($data); |
|
| 30 | + $this->import_classes($data); |
|
| 31 | + if ( isset($this->name) ) { |
|
| 32 | 32 | $this->_name = $this->name; |
| 33 | 33 | } |
| 34 | 34 | $this->name = $this->name(); |
| 35 | - $this->add_class( 'menu-item-' . $this->ID ); |
|
| 35 | + $this->add_class('menu-item-' . $this->ID); |
|
| 36 | 36 | $this->menu_object = $data; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | if ( $title = $this->title() ) { |
| 62 | 62 | return $title; |
| 63 | 63 | } |
| 64 | - if ( isset( $this->_name ) ) { |
|
| 64 | + if ( isset($this->_name) ) { |
|
| 65 | 65 | return $this->_name; |
| 66 | 66 | } |
| 67 | 67 | return ''; |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @return string the slug of the menu item kinda-like-this |
| 83 | 83 | */ |
| 84 | 84 | public function slug() { |
| 85 | - if ( !isset( $this->master_object ) ) { |
|
| 85 | + if ( !isset($this->master_object) ) { |
|
| 86 | 86 | $this->master_object = $this->get_master_object(); |
| 87 | 87 | } |
| 88 | - if ( isset( $this->master_object->post_name ) && $this->master_object->post_name ) { |
|
| 88 | + if ( isset($this->master_object->post_name) && $this->master_object->post_name ) { |
|
| 89 | 89 | return $this->master_object->post_name; |
| 90 | 90 | } |
| 91 | 91 | return $this->post_name; |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * @return mixed whatever object (Post, Term, etc.) the menu item represents |
| 97 | 97 | */ |
| 98 | 98 | protected function get_master_object() { |
| 99 | - if ( isset( $this->_menu_item_object_id ) ) { |
|
| 100 | - return new $this->PostClass( $this->_menu_item_object_id ); |
|
| 99 | + if ( isset($this->_menu_item_object_id) ) { |
|
| 100 | + return new $this->PostClass($this->_menu_item_object_id); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | * @return string an absolute URL http://example.org/my-page |
| 108 | 108 | */ |
| 109 | 109 | function get_link() { |
| 110 | - if ( !isset( $this->url ) || !$this->url ) { |
|
| 111 | - if ( isset( $this->_menu_item_type ) && $this->_menu_item_type == 'custom' ) { |
|
| 110 | + if ( !isset($this->url) || !$this->url ) { |
|
| 111 | + if ( isset($this->_menu_item_type) && $this->_menu_item_type == 'custom' ) { |
|
| 112 | 112 | $this->url = $this->_menu_item_url; |
| 113 | - } else if ( isset( $this->menu_object ) && method_exists( $this->menu_object, 'get_link' ) ) { |
|
| 113 | + } else if ( isset($this->menu_object) && method_exists($this->menu_object, 'get_link') ) { |
|
| 114 | 114 | $this->url = $this->menu_object->get_link(); |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @return string a relative url /my-page |
| 124 | 124 | */ |
| 125 | 125 | function get_path() { |
| 126 | - return TimberURLHelper::get_rel_url( $this->get_link() ); |
|
| 126 | + return TimberURLHelper::get_rel_url($this->get_link()); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -133,15 +133,15 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | function add_child( $item ) { |
| 135 | 135 | if ( !$this->has_child_class ) { |
| 136 | - $this->add_class( 'menu-item-has-children' ); |
|
| 136 | + $this->add_class('menu-item-has-children'); |
|
| 137 | 137 | $this->has_child_class = true; |
| 138 | 138 | } |
| 139 | - if ( !isset( $this->children ) ) { |
|
| 139 | + if ( !isset($this->children) ) { |
|
| 140 | 140 | $this->children = array(); |
| 141 | 141 | } |
| 142 | 142 | $this->children[] = $item; |
| 143 | 143 | $item->level = $this->level + 1; |
| 144 | - if ($item->children) { |
|
| 144 | + if ( $item->children ) { |
|
| 145 | 145 | $this->update_child_levels(); |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * @return bool |
| 153 | 153 | */ |
| 154 | 154 | function update_child_levels() { |
| 155 | - if (is_array($this->children)) { |
|
| 156 | - foreach( $this->children as $child ) { |
|
| 155 | + if ( is_array($this->children) ) { |
|
| 156 | + foreach ( $this->children as $child ) { |
|
| 157 | 157 | $child->level = $this->level + 1; |
| 158 | 158 | $child->update_child_levels(); |
| 159 | 159 | } |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | if ( is_array($data) ) { |
| 171 | 171 | $data = (object) $data; |
| 172 | 172 | } |
| 173 | - $this->classes = array_merge( $this->classes, $data->classes ); |
|
| 174 | - $this->classes = array_unique( $this->classes ); |
|
| 175 | - $this->classes = apply_filters( 'nav_menu_css_class', $this->classes, $this ); |
|
| 176 | - $this->class = trim( implode( ' ', $this->classes ) ); |
|
| 173 | + $this->classes = array_merge($this->classes, $data->classes); |
|
| 174 | + $this->classes = array_unique($this->classes); |
|
| 175 | + $this->classes = apply_filters('nav_menu_css_class', $this->classes, $this); |
|
| 176 | + $this->class = trim(implode(' ', $this->classes)); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @return array|bool |
| 183 | 183 | */ |
| 184 | 184 | function get_children() { |
| 185 | - if ( isset( $this->children ) ) { |
|
| 185 | + if ( isset($this->children) ) { |
|
| 186 | 186 | return $this->children; |
| 187 | 187 | } |
| 188 | 188 | return false; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | if ( $this->type != 'custom' ) { |
| 202 | 202 | return false; |
| 203 | 203 | } |
| 204 | - return TimberURLHelper::is_external( $this->url ); |
|
| 204 | + return TimberURLHelper::is_external($this->url); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -209,10 +209,10 @@ discard block |
||
| 209 | 209 | * @return mixed whatever value is storied in the database |
| 210 | 210 | */ |
| 211 | 211 | public function meta( $key ) { |
| 212 | - if ( is_object( $this->menu_object ) && method_exists( $this->menu_object, 'meta' ) ) { |
|
| 213 | - return $this->menu_object->meta( $key ); |
|
| 212 | + if ( is_object($this->menu_object) && method_exists($this->menu_object, 'meta') ) { |
|
| 213 | + return $this->menu_object->meta($key); |
|
| 214 | 214 | } |
| 215 | - if ( isset( $this->$key ) ) { |
|
| 215 | + if ( isset($this->$key) ) { |
|
| 216 | 216 | return $this->$key; |
| 217 | 217 | } |
| 218 | 218 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @return string the public label like Foo |
| 300 | 300 | */ |
| 301 | 301 | public function title() { |
| 302 | - if ( isset( $this->__title ) ) { |
|
| 302 | + if ( isset($this->__title) ) { |
|
| 303 | 303 | return $this->__title; |
| 304 | 304 | } |
| 305 | 305 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * We are currently using the My Theme theme. |
| 63 | 63 | * ``` |
| 64 | 64 | */ |
| 65 | - function __construct($slug = null) { |
|
| 65 | + function __construct( $slug = null ) { |
|
| 66 | 66 | $this->init($slug); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | * @internal |
| 71 | 71 | * @param string $slug |
| 72 | 72 | */ |
| 73 | - protected function init($slug = null) { |
|
| 73 | + protected function init( $slug = null ) { |
|
| 74 | 74 | $data = wp_get_theme($slug); |
| 75 | 75 | $this->name = $data->get('Name'); |
| 76 | 76 | $ss = $data->get_stylesheet(); |
| 77 | 77 | $this->slug = $ss; |
| 78 | 78 | |
| 79 | - if ( ! function_exists( 'get_home_path' ) ) { |
|
| 79 | + if ( !function_exists('get_home_path') ) { |
|
| 80 | 80 | require_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @return string the relative path to the theme (ex: `/wp-content/themes/my-timber-theme`) |
| 104 | 104 | */ |
| 105 | 105 | public function path() { |
| 106 | - return TimberURLHelper::get_rel_url( $this->link() ); |
|
| 106 | + return TimberURLHelper::get_rel_url($this->link()); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @param bool $default |
| 112 | 112 | * @return string |
| 113 | 113 | */ |
| 114 | - public function theme_mod($name, $default = false) { |
|
| 114 | + public function theme_mod( $name, $default = false ) { |
|
| 115 | 115 | return get_theme_mod($name, $default); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( !defined( 'ABSPATH' ) ) |
|
| 3 | +if ( !defined('ABSPATH') ) |
|
| 4 | 4 | exit; |
| 5 | 5 | |
| 6 | 6 | class TimberQueryIterator implements Iterator { |
@@ -14,37 +14,37 @@ discard block |
||
| 14 | 14 | private $_posts_class = 'TimberPost'; |
| 15 | 15 | |
| 16 | 16 | public function __construct( $query = false, $posts_class = 'TimberPost' ) { |
| 17 | - add_action( 'pre_get_posts', array($this, 'fix_number_posts_wp_quirk' )); |
|
| 17 | + add_action('pre_get_posts', array($this, 'fix_number_posts_wp_quirk')); |
|
| 18 | 18 | if ( $posts_class ) |
| 19 | 19 | $this->_posts_class = $posts_class; |
| 20 | 20 | |
| 21 | - if ( is_a( $query, 'WP_Query' ) ) { |
|
| 21 | + if ( is_a($query, 'WP_Query') ) { |
|
| 22 | 22 | // We got a full-fledged WP Query, look no further! |
| 23 | 23 | $the_query = $query; |
| 24 | 24 | |
| 25 | 25 | } elseif ( false === $query ) { |
| 26 | 26 | // If query is explicitly set to false, use the main loop |
| 27 | 27 | global $wp_query; |
| 28 | - $the_query =& $wp_query; |
|
| 28 | + $the_query = & $wp_query; |
|
| 29 | 29 | //if we're on a custom posts page? |
| 30 | 30 | $the_query = self::handle_maybe_custom_posts_page($the_query); |
| 31 | - } elseif ( TimberHelper::is_array_assoc( $query ) || ( is_string( $query ) && strstr( $query, '=' ) ) ) { |
|
| 31 | + } elseif ( TimberHelper::is_array_assoc($query) || (is_string($query) && strstr($query, '=')) ) { |
|
| 32 | 32 | // We have a regularly formed WP query string or array to use |
| 33 | - $the_query = new WP_Query( $query ); |
|
| 33 | + $the_query = new WP_Query($query); |
|
| 34 | 34 | |
| 35 | - } elseif ( is_numeric( $query ) || is_string( $query ) ) { |
|
| 35 | + } elseif ( is_numeric($query) || is_string($query) ) { |
|
| 36 | 36 | // We have what could be a post name or post ID to pull out |
| 37 | - $the_query = self::get_query_from_string( $query ); |
|
| 37 | + $the_query = self::get_query_from_string($query); |
|
| 38 | 38 | |
| 39 | - } elseif ( is_array( $query ) && count( $query ) && ( is_integer( $query[0] ) || is_string( $query[0] ) ) ) { |
|
| 39 | + } elseif ( is_array($query) && count($query) && (is_integer($query[0]) || is_string($query[0])) ) { |
|
| 40 | 40 | // We have a list of pids (post IDs) to extract from |
| 41 | - $the_query = self::get_query_from_array_of_ids( $query ); |
|
| 42 | - } elseif ( is_array($query) && empty($query)) { |
|
| 41 | + $the_query = self::get_query_from_array_of_ids($query); |
|
| 42 | + } elseif ( is_array($query) && empty($query) ) { |
|
| 43 | 43 | // it's an empty array |
| 44 | 44 | $the_query = array(); |
| 45 | 45 | } else { |
| 46 | - TimberHelper::error_log( 'I have failed you! in ' . basename( __FILE__ ) . '::' . __LINE__ ); |
|
| 47 | - TimberHelper::error_log( $query ); |
|
| 46 | + TimberHelper::error_log('I have failed you! in ' . basename(__FILE__) . '::' . __LINE__); |
|
| 47 | + TimberHelper::error_log($query); |
|
| 48 | 48 | |
| 49 | 49 | // We have failed hard, at least let get something. |
| 50 | 50 | $the_query = new WP_Query(); |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | public function get_posts( $return_collection = false ) { |
| 58 | - if (isset($this->_query->posts)){ |
|
| 59 | - $posts = new TimberPostsCollection( $this->_query->posts, $this->_posts_class ); |
|
| 60 | - return ( $return_collection ) ? $posts : $posts->get_posts(); |
|
| 58 | + if ( isset($this->_query->posts) ) { |
|
| 59 | + $posts = new TimberPostsCollection($this->_query->posts, $this->_posts_class); |
|
| 60 | + return ($return_collection) ? $posts : $posts->get_posts(); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
@@ -65,38 +65,38 @@ discard block |
||
| 65 | 65 | // GET POSTS |
| 66 | 66 | // |
| 67 | 67 | public static function get_query_from_array_of_ids( $query = array() ) { |
| 68 | - if ( !is_array( $query ) || !count( $query ) ) |
|
| 68 | + if ( !is_array($query) || !count($query) ) |
|
| 69 | 69 | return null; |
| 70 | 70 | |
| 71 | - return new WP_Query( array( |
|
| 71 | + return new WP_Query(array( |
|
| 72 | 72 | 'post_type'=> 'any', |
| 73 | 73 | 'ignore_sticky_posts' => true, |
| 74 | 74 | 'post__in' => $query, |
| 75 | 75 | 'orderby' => 'post__in', |
| 76 | 76 | 'nopaging' => true |
| 77 | - ) ); |
|
| 77 | + )); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public static function get_query_from_string( $string = '' ) { |
| 81 | 81 | $post_type = false; |
| 82 | 82 | |
| 83 | - if ( is_string( $string ) && strstr( $string, '#' ) ) { |
|
| 83 | + if ( is_string($string) && strstr($string, '#') ) { |
|
| 84 | 84 | //we have a post_type directive here |
| 85 | - list( $post_type, $string ) = explode( '#', $string ); |
|
| 85 | + list($post_type, $string) = explode('#', $string); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $query = array( |
| 89 | - 'post_type' => ( $post_type ) ? $post_type : 'any' |
|
| 89 | + 'post_type' => ($post_type) ? $post_type : 'any' |
|
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | - if ( is_numeric( $string ) ) { |
|
| 92 | + if ( is_numeric($string) ) { |
|
| 93 | 93 | $query['p'] = $string; |
| 94 | 94 | |
| 95 | 95 | } else { |
| 96 | 96 | $query['name'] = $string; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - return new WP_Query( $query ); |
|
| 99 | + return new WP_Query($query); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | // Sets up the global post, but also return the post, for use in Twig template |
| 116 | 116 | $posts_class = $this->_posts_class; |
| 117 | - return new $posts_class( $post ); |
|
| 117 | + return new $posts_class($post); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -132,9 +132,9 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | //get_posts users numberposts |
| 134 | 134 | static function fix_number_posts_wp_quirk( $query ) { |
| 135 | - if (isset($query->query) && isset($query->query['numberposts']) |
|
| 136 | - && !isset($query->query['posts_per_page'])) { |
|
| 137 | - $query->set( 'posts_per_page', $query->query['numberposts'] ); |
|
| 135 | + if ( isset($query->query) && isset($query->query['numberposts']) |
|
| 136 | + && !isset($query->query['posts_per_page']) ) { |
|
| 137 | + $query->set('posts_per_page', $query->query['numberposts']); |
|
| 138 | 138 | } |
| 139 | 139 | return $query; |
| 140 | 140 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @return WP_Query |
| 146 | 146 | */ |
| 147 | 147 | static function handle_maybe_custom_posts_page( $query ) { |
| 148 | - if ($custom_posts_page = get_option('page_for_posts')) { |
|
| 148 | + if ( $custom_posts_page = get_option('page_for_posts') ) { |
|
| 149 | 149 | if ( isset($query->query['p']) && $query->query['p'] == $custom_posts_page ) { |
| 150 | 150 | return new WP_Query(array('post_type' => 'post')); |
| 151 | 151 | } |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | $w = $_wp_additional_image_sizes[$size]['width']; |
| 73 | 73 | $h = $_wp_additional_image_sizes[$size]['height']; |
| 74 | 74 | } else if ( in_array($size, array('thumbnail', 'medium', 'large')) ) { |
| 75 | - $w = get_option($size.'_size_w'); |
|
| 76 | - $h = get_option($size.'_size_h'); |
|
| 75 | + $w = get_option($size . '_size_w'); |
|
| 76 | + $h = get_option($size . '_size_h'); |
|
| 77 | 77 | } |
| 78 | 78 | if ( isset($w) && isset($h) && ($w || $h) ) { |
| 79 | 79 | return array('w' => $w, 'h' => $h); |
@@ -106,7 +106,7 @@ discard block |
||
| 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 | } |
@@ -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 | } |
@@ -201,17 +201,17 @@ discard block |
||
| 201 | 201 | * or: http://example.org/wp-content/uploads/2015/my-pic.jpg |
| 202 | 202 | */ |
| 203 | 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 ); |
|
| 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]*.' ); |
|
| 213 | - self::process_delete_generated_files( $filename, 'jpg', $dir, '-tojpg.*' ); |
|
| 214 | - self::process_delete_generated_files( $filename, 'jpg', $dir, '-tojpg-[0-9999999]*' ); |
|
| 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 | + self::process_delete_generated_files($filename, 'jpg', $dir, '-tojpg.*'); |
|
| 214 | + self::process_delete_generated_files($filename, 'jpg', $dir, '-tojpg-[0-9999999]*'); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -230,12 +230,12 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | protected static function process_delete_generated_files( $filename, $ext, $dir, $search_pattern, $match_pattern = null ) { |
| 232 | 232 | $searcher = '/' . $filename . $search_pattern; |
| 233 | - foreach ( glob( $dir . $searcher ) as $found_file ) { |
|
| 234 | - $regexdir = str_replace( '/', '\/', $dir ); |
|
| 235 | - $pattern = '/' . ( $regexdir ) . '\/' . $filename . $match_pattern . $ext . '/'; |
|
| 236 | - $match = preg_match( $pattern, $found_file ); |
|
| 237 | - if ( ! $match_pattern || $match ) { |
|
| 238 | - unlink( $found_file ); |
|
| 233 | + foreach ( glob($dir . $searcher) as $found_file ) { |
|
| 234 | + $regexdir = str_replace('/', '\/', $dir); |
|
| 235 | + $pattern = '/' . ($regexdir) . '\/' . $filename . $match_pattern . $ext . '/'; |
|
| 236 | + $match = preg_match($pattern, $found_file); |
|
| 237 | + if ( !$match_pattern || $match ) { |
|
| 238 | + unlink($found_file); |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | public static function get_server_location( $url ) { |
| 251 | 251 | // if we're already an absolute dir, just return |
| 252 | - if ( 0 === strpos( $url, ABSPATH ) ) { |
|
| 252 | + if ( 0 === strpos($url, ABSPATH) ) { |
|
| 253 | 253 | return $url; |
| 254 | 254 | } |
| 255 | 255 | // otherwise, analyze URL then build mapping path |
@@ -268,11 +268,11 @@ discard block |
||
| 268 | 268 | $upload = wp_upload_dir(); |
| 269 | 269 | $dir = $upload['path']; |
| 270 | 270 | $filename = $file; |
| 271 | - $file = parse_url( $file ); |
|
| 272 | - $path_parts = pathinfo( $file['path'] ); |
|
| 273 | - $basename = md5( $filename ); |
|
| 271 | + $file = parse_url($file); |
|
| 272 | + $path_parts = pathinfo($file['path']); |
|
| 273 | + $basename = md5($filename); |
|
| 274 | 274 | $ext = 'jpg'; |
| 275 | - if ( isset( $path_parts['extension'] ) ) { |
|
| 275 | + if ( isset($path_parts['extension']) ) { |
|
| 276 | 276 | $ext = $path_parts['extension']; |
| 277 | 277 | } |
| 278 | 278 | return $dir . '/' . $basename . '.' . $ext; |
@@ -285,27 +285,27 @@ discard block |
||
| 285 | 285 | * @return string the URL to the downloaded file |
| 286 | 286 | */ |
| 287 | 287 | public static function sideload_image( $file ) { |
| 288 | - $loc = self::get_sideloaded_file_loc( $file ); |
|
| 289 | - if ( file_exists( $loc ) ) { |
|
| 290 | - return TimberURLHelper::preslashit( TimberURLHelper::get_rel_path( $loc ) ); |
|
| 288 | + $loc = self::get_sideloaded_file_loc($file); |
|
| 289 | + if ( file_exists($loc) ) { |
|
| 290 | + return TimberURLHelper::preslashit(TimberURLHelper::get_rel_path($loc)); |
|
| 291 | 291 | } |
| 292 | 292 | // Download file to temp location |
| 293 | - if ( !function_exists( 'download_url' ) ) { |
|
| 293 | + if ( !function_exists('download_url') ) { |
|
| 294 | 294 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 295 | 295 | } |
| 296 | - $tmp = download_url( $file ); |
|
| 297 | - preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches ); |
|
| 296 | + $tmp = download_url($file); |
|
| 297 | + preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches); |
|
| 298 | 298 | $file_array = array(); |
| 299 | - $file_array['name'] = basename( $matches[0] ); |
|
| 299 | + $file_array['name'] = basename($matches[0]); |
|
| 300 | 300 | $file_array['tmp_name'] = $tmp; |
| 301 | 301 | // If error storing temporarily, unlink |
| 302 | - if ( is_wp_error( $tmp ) ) { |
|
| 303 | - @unlink( $file_array['tmp_name'] ); |
|
| 302 | + if ( is_wp_error($tmp) ) { |
|
| 303 | + @unlink($file_array['tmp_name']); |
|
| 304 | 304 | $file_array['tmp_name'] = ''; |
| 305 | 305 | } |
| 306 | 306 | // do the validation and storage stuff |
| 307 | - $locinfo = pathinfo( $loc ); |
|
| 308 | - $file = wp_upload_bits( $locinfo['basename'], null, file_get_contents( $file_array['tmp_name'] ) ); |
|
| 307 | + $locinfo = pathinfo($loc); |
|
| 308 | + $file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name'])); |
|
| 309 | 309 | return $file['url']; |
| 310 | 310 | } |
| 311 | 311 | |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @param string $url an URL (absolute or relative) pointing to an image |
| 318 | 318 | * @return array an array (see keys in code below) |
| 319 | 319 | */ |
| 320 | - private static function analyze_url($url) { |
|
| 320 | + private static function analyze_url( $url ) { |
|
| 321 | 321 | $result = array( |
| 322 | 322 | 'url' => $url, // the initial url |
| 323 | 323 | 'absolute' => TimberURLHelper::is_absolute($url), // is the url absolute or relative (to home_url) |
@@ -332,23 +332,23 @@ discard block |
||
| 332 | 332 | if ( 0 === strpos($tmp, ABSPATH) ) { // we've been given a dir, not an url |
| 333 | 333 | $result['absolute'] = true; |
| 334 | 334 | if ( 0 === strpos($tmp, $upload_dir['basedir']) ) { |
| 335 | - $result['base']= self::BASE_UPLOADS; // upload based |
|
| 335 | + $result['base'] = self::BASE_UPLOADS; // upload based |
|
| 336 | 336 | $tmp = str_replace($upload_dir['basedir'], '', $tmp); |
| 337 | 337 | } |
| 338 | 338 | if ( 0 === strpos($tmp, WP_CONTENT_DIR) ) { |
| 339 | - $result['base']= self::BASE_CONTENT; // content based |
|
| 339 | + $result['base'] = self::BASE_CONTENT; // content based |
|
| 340 | 340 | $tmp = str_replace(WP_CONTENT_DIR, '', $tmp); |
| 341 | 341 | } |
| 342 | 342 | } else { |
| 343 | - if (!$result['absolute']) { |
|
| 344 | - $tmp = home_url().$tmp; |
|
| 343 | + if ( !$result['absolute'] ) { |
|
| 344 | + $tmp = home_url() . $tmp; |
|
| 345 | 345 | } |
| 346 | - if (0 === strpos($tmp, $upload_dir['baseurl'])) { |
|
| 347 | - $result['base']= self::BASE_UPLOADS; // upload based |
|
| 346 | + if ( 0 === strpos($tmp, $upload_dir['baseurl']) ) { |
|
| 347 | + $result['base'] = self::BASE_UPLOADS; // upload based |
|
| 348 | 348 | $tmp = str_replace($upload_dir['baseurl'], '', $tmp); |
| 349 | 349 | } |
| 350 | - if (0 === strpos($tmp, content_url())) { |
|
| 351 | - $result['base']= self::BASE_CONTENT; // content-based |
|
| 350 | + if ( 0 === strpos($tmp, content_url()) ) { |
|
| 351 | + $result['base'] = self::BASE_CONTENT; // content-based |
|
| 352 | 352 | $tmp = str_replace(content_url(), '', $tmp); |
| 353 | 353 | } |
| 354 | 354 | } |
@@ -370,20 +370,20 @@ discard block |
||
| 370 | 370 | * @param bool $absolute should the returned URL be absolute (include protocol+host), or relative |
| 371 | 371 | * @return string the URL |
| 372 | 372 | */ |
| 373 | - private static function _get_file_url($base, $subdir, $filename, $absolute) { |
|
| 373 | + private static function _get_file_url( $base, $subdir, $filename, $absolute ) { |
|
| 374 | 374 | $url = ''; |
| 375 | - if( self::BASE_UPLOADS == $base ) { |
|
| 375 | + if ( self::BASE_UPLOADS == $base ) { |
|
| 376 | 376 | $upload_dir = wp_upload_dir(); |
| 377 | 377 | $url = $upload_dir['baseurl']; |
| 378 | 378 | } |
| 379 | - if( self::BASE_CONTENT == $base ) { |
|
| 379 | + if ( self::BASE_CONTENT == $base ) { |
|
| 380 | 380 | $url = content_url(); |
| 381 | 381 | } |
| 382 | - if(!empty($subdir)) { |
|
| 382 | + if ( !empty($subdir) ) { |
|
| 383 | 383 | $url .= $subdir; |
| 384 | 384 | } |
| 385 | - $url .= '/'.$filename; |
|
| 386 | - if(!$absolute) { |
|
| 385 | + $url .= '/' . $filename; |
|
| 386 | + if ( !$absolute ) { |
|
| 387 | 387 | $url = str_replace(home_url(), '', $url); |
| 388 | 388 | } |
| 389 | 389 | // $url = TimberURLHelper::remove_double_slashes( $url); |
@@ -398,19 +398,19 @@ discard block |
||
| 398 | 398 | * @param string $filename file name, including extension (but no path) |
| 399 | 399 | * @return string the file location |
| 400 | 400 | */ |
| 401 | - private static function _get_file_path($base, $subdir, $filename) { |
|
| 401 | + private static function _get_file_path( $base, $subdir, $filename ) { |
|
| 402 | 402 | $path = ''; |
| 403 | - if(self::BASE_UPLOADS == $base) { |
|
| 403 | + if ( self::BASE_UPLOADS == $base ) { |
|
| 404 | 404 | $upload_dir = wp_upload_dir(); |
| 405 | 405 | $path = $upload_dir['basedir']; |
| 406 | 406 | } |
| 407 | - if(self::BASE_CONTENT == $base) { |
|
| 407 | + if ( self::BASE_CONTENT == $base ) { |
|
| 408 | 408 | $path = WP_CONTENT_DIR; |
| 409 | 409 | } |
| 410 | - if(!empty($subdir)) { |
|
| 410 | + if ( !empty($subdir) ) { |
|
| 411 | 411 | $path .= $subdir; |
| 412 | 412 | } |
| 413 | - $path .= '/'.$filename; |
|
| 413 | + $path .= '/' . $filename; |
|
| 414 | 414 | return $path; |
| 415 | 415 | } |
| 416 | 416 | |
@@ -429,14 +429,14 @@ discard block |
||
| 429 | 429 | * |
| 430 | 430 | */ |
| 431 | 431 | private static function _operate( $src, $op, $force = false ) { |
| 432 | - if ( empty( $src ) ) { |
|
| 432 | + if ( empty($src) ) { |
|
| 433 | 433 | return ''; |
| 434 | 434 | } |
| 435 | 435 | $external = false; |
| 436 | 436 | |
| 437 | 437 | // if external image, load it first |
| 438 | - if ( TimberURLHelper::is_external_content( $src ) ) { |
|
| 439 | - $src = self::sideload_image( $src ); |
|
| 438 | + if ( TimberURLHelper::is_external_content($src) ) { |
|
| 439 | + $src = self::sideload_image($src); |
|
| 440 | 440 | $external = true; |
| 441 | 441 | } |
| 442 | 442 | // break down URL into components |
@@ -459,19 +459,19 @@ discard block |
||
| 459 | 459 | $au['basename'] |
| 460 | 460 | ); |
| 461 | 461 | // if already exists... |
| 462 | - if ( file_exists( $new_server_path ) ) { |
|
| 462 | + if ( file_exists($new_server_path) ) { |
|
| 463 | 463 | if ( $force ) { |
| 464 | 464 | // Force operation - warning: will regenerate the image on every pageload, use for testing purposes only! |
| 465 | - unlink( $new_server_path ); |
|
| 465 | + unlink($new_server_path); |
|
| 466 | 466 | } else { |
| 467 | 467 | // return existing file (caching) |
| 468 | 468 | return $new_url; |
| 469 | 469 | } |
| 470 | 470 | } |
| 471 | 471 | // otherwise generate result file |
| 472 | - if($op->run($old_server_path, $new_server_path)) { |
|
| 473 | - if( get_class( $op ) === 'TimberImageOperationResize' && $external ) { |
|
| 474 | - $new_url = strtolower( $new_url ); |
|
| 472 | + if ( $op->run($old_server_path, $new_server_path) ) { |
|
| 473 | + if ( get_class($op) === 'TimberImageOperationResize' && $external ) { |
|
| 474 | + $new_url = strtolower($new_url); |
|
| 475 | 475 | } |
| 476 | 476 | return $new_url; |
| 477 | 477 | } else { |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | |
| 484 | 484 | // -- the below methods are just used for unit testing the URL generation code |
| 485 | 485 | // |
| 486 | - static function get_letterbox_file_url($url, $w, $h, $color) { |
|
| 486 | + static function get_letterbox_file_url( $url, $w, $h, $color ) { |
|
| 487 | 487 | $au = self::analyze_url($url); |
| 488 | 488 | $op = new TimberImageOperationLetterbox($w, $h, $color); |
| 489 | 489 | $new_url = self::_get_file_url( |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | ); |
| 495 | 495 | return $new_url; |
| 496 | 496 | } |
| 497 | - public static function get_letterbox_file_path($url, $w, $h, $color ) { |
|
| 497 | + public static function get_letterbox_file_path( $url, $w, $h, $color ) { |
|
| 498 | 498 | $au = self::analyze_url($url); |
| 499 | 499 | $op = new TimberImageOperationLetterbox($w, $h, $color); |
| 500 | 500 | $new_path = self::_get_file_path( |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | ); |
| 505 | 505 | return $new_path; |
| 506 | 506 | } |
| 507 | - static function get_resize_file_url($url, $w, $h, $crop) { |
|
| 507 | + static function get_resize_file_url( $url, $w, $h, $crop ) { |
|
| 508 | 508 | $au = self::analyze_url($url); |
| 509 | 509 | $op = new TimberImageOperationResize($w, $h, $crop); |
| 510 | 510 | $new_url = self::_get_file_url( |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | ); |
| 516 | 516 | return $new_url; |
| 517 | 517 | } |
| 518 | - static function get_resize_file_path($url, $w, $h, $crop) { |
|
| 518 | + static function get_resize_file_path( $url, $w, $h, $crop ) { |
|
| 519 | 519 | $au = self::analyze_url($url); |
| 520 | 520 | $op = new TimberImageOperationResize($w, $h, $crop); |
| 521 | 521 | $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(); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @return array|bool|null |
| 80 | 80 | */ |
| 81 | 81 | public static function get_post( $query = false, $PostClass = 'TimberPost' ) { |
| 82 | - return TimberPostGetter::get_post( $query, $PostClass ); |
|
| 82 | + return TimberPostGetter::get_post($query, $PostClass); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return array|bool|null |
| 91 | 91 | */ |
| 92 | 92 | public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) { |
| 93 | - return TimberPostGetter::get_posts( $query, $PostClass, $return_collection ); |
|
| 93 | + return TimberPostGetter::get_posts($query, $PostClass, $return_collection); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @return array|bool|null |
| 102 | 102 | */ |
| 103 | 103 | public static function query_post( $query = false, $PostClass = 'TimberPost' ) { |
| 104 | - return TimberPostGetter::query_post( $query, $PostClass ); |
|
| 104 | + return TimberPostGetter::query_post($query, $PostClass); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @return array|bool|null |
| 113 | 113 | */ |
| 114 | 114 | public static function query_posts( $query = false, $PostClass = 'TimberPost' ) { |
| 115 | - return TimberPostGetter::query_posts( $query, $PostClass ); |
|
| 115 | + return TimberPostGetter::query_posts($query, $PostClass); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @return mixed |
| 138 | 138 | */ |
| 139 | 139 | public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) { |
| 140 | - return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass ); |
|
| 140 | + return TimberTermGetter::get_terms($args, $maybe_args, $TermClass); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /* Site Retrieval |
@@ -150,13 +150,13 @@ discard block |
||
| 150 | 150 | * @return array |
| 151 | 151 | */ |
| 152 | 152 | public static function get_sites( $blog_ids = false ) { |
| 153 | - if ( !is_array( $blog_ids ) ) { |
|
| 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 | 158 | foreach ( $blog_ids as $blog_id ) { |
| 159 | - $return[] = new TimberSite( $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 | |
@@ -202,24 +202,24 @@ discard block |
||
| 202 | 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 | |
@@ -234,10 +234,10 @@ discard block |
||
| 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 | /** |
@@ -256,8 +256,8 @@ discard block |
||
| 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 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @return bool|string |
| 272 | 272 | */ |
| 273 | 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 ); |
|
| 274 | + $output = static::fetch($filenames, $data, $expires, $cache_mode); |
|
| 275 | 275 | echo $output; |
| 276 | 276 | return $output; |
| 277 | 277 | } |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * @return bool|string |
| 285 | 285 | */ |
| 286 | 286 | public static function render_string( $string, $data = array() ) { |
| 287 | - $compiled = self::compile_string( $string, $data ); |
|
| 287 | + $compiled = self::compile_string($string, $data); |
|
| 288 | 288 | echo $compiled; |
| 289 | 289 | return $compiled; |
| 290 | 290 | } |
@@ -304,10 +304,10 @@ discard block |
||
| 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 | /** |
@@ -320,18 +320,18 @@ discard block |
||
| 320 | 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 | 326 | foreach ( $uris as $uri ) { |
| 327 | - if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) { |
|
| 328 | - include trailingslashit( $uri ) . $sidebar; |
|
| 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(); |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | * @return TimberFunctionWrapper |
| 349 | 349 | */ |
| 350 | 350 | public static function get_widgets( $widget_id ) { |
| 351 | - return trim( TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ) ); |
|
| 351 | + return trim(TimberHelper::function_wrapper('dynamic_sidebar', array($widget_id), true)); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * @deprecated since 0.20.0 |
| 365 | 365 | */ |
| 366 | 366 | public static function add_route( $route, $callback, $args = array() ) { |
| 367 | - Routes::map( $route, $callback, $args ); |
|
| 367 | + Routes::map($route, $callback, $args); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @deprecated since 0.20.0 |
| 374 | 374 | */ |
| 375 | 375 | public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) { |
| 376 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
| 376 | + return Routes::load($template, $tparams, $query, $status_code); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | * @deprecated since 0.20.2 |
| 383 | 383 | */ |
| 384 | 384 | public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) { |
| 385 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
| 385 | + return Routes::load($template, $tparams, $query, $status_code); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | |
@@ -400,43 +400,43 @@ discard block |
||
| 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'] = ''; |
| 438 | 438 | } |
| 439 | - if ( $data['total'] === ( double ) 0 ) { |
|
| 439 | + if ( $data['total'] === (double) 0 ) { |
|
| 440 | 440 | $data['next'] = ''; |
| 441 | 441 | } |
| 442 | 442 | return $data; |
@@ -451,9 +451,9 @@ discard block |
||
| 451 | 451 | * @return string |
| 452 | 452 | */ |
| 453 | 453 | public static function get_calling_script_dir( $offset = 0 ) { |
| 454 | - $caller = self::get_calling_script_file( $offset ); |
|
| 455 | - if ( !is_null( $caller ) ) { |
|
| 456 | - $pathinfo = pathinfo( $caller ); |
|
| 454 | + $caller = self::get_calling_script_file($offset); |
|
| 455 | + if ( !is_null($caller) ) { |
|
| 456 | + $pathinfo = pathinfo($caller); |
|
| 457 | 457 | $dir = $pathinfo['dirname']; |
| 458 | 458 | return $dir; |
| 459 | 459 | } |