| @@ -11,16 +11,16 @@ | ||
| 11 | 11 | * @return string | 
| 12 | 12 | */ | 
| 13 | 13 |  	public function generateKey($value) { | 
| 14 | -		if (is_a($value, 'TimberKeyGeneratorInterface')) { | |
| 14 | +		if ( is_a($value, 'TimberKeyGeneratorInterface') ) { | |
| 15 | 15 | return $value->_get_cache_key(); | 
| 16 | 16 | } | 
| 17 | 17 | |
| 18 | -		if (is_array($value) && isset($value['_cache_key'])) { | |
| 18 | +		if ( is_array($value) && isset($value['_cache_key']) ) { | |
| 19 | 19 | return $value['_cache_key']; | 
| 20 | 20 | } | 
| 21 | 21 | |
| 22 | 22 | $key = md5(json_encode($value)); | 
| 23 | -		if (is_object($value)) { | |
| 23 | +		if ( is_object($value) ) { | |
| 24 | 24 | $key = get_class($value) . '|' . $key; | 
| 25 | 25 | } | 
| 26 | 26 | |
| @@ -30,7 +30,7 @@ discard block | ||
| 30 | 30 | * (ex: my-awesome-pic-lbox-300x200-FF3366.jpg) | 
| 31 | 31 | */ | 
| 32 | 32 |  	public function filename($src_filename, $src_extension) { | 
| 33 | - $color = str_replace( '#', '', $this->color ); | |
| 33 | +		$color = str_replace('#', '', $this->color); | |
| 34 | 34 | $newbase = $src_filename . '-lbox-' . $this->w . 'x' . $this->h . '-' . $color; | 
| 35 | 35 | $new_name = $newbase . '.' . $src_extension; | 
| 36 | 36 | return $new_name; | 
| @@ -50,12 +50,12 @@ discard block | ||
| 50 | 50 | $w = $this->w; | 
| 51 | 51 | $h = $this->h; | 
| 52 | 52 | |
| 53 | - $bg = imagecreatetruecolor( $w, $h ); | |
| 54 | - $c = self::hexrgb( $this->color ); | |
| 55 | - $bgColor = imagecolorallocate( $bg, $c['red'], $c['green'], $c['blue'] ); | |
| 56 | - imagefill( $bg, 0, 0, $bgColor ); | |
| 57 | - $image = wp_get_image_editor( $load_filename ); | |
| 58 | -		if ( !is_wp_error( $image ) ) { | |
| 53 | + $bg = imagecreatetruecolor($w, $h); | |
| 54 | + $c = self::hexrgb($this->color); | |
| 55 | + $bgColor = imagecolorallocate($bg, $c['red'], $c['green'], $c['blue']); | |
| 56 | + imagefill($bg, 0, 0, $bgColor); | |
| 57 | + $image = wp_get_image_editor($load_filename); | |
| 58 | +		if ( !is_wp_error($image) ) { | |
| 59 | 59 | $current_size = $image->get_size(); | 
| 60 | 60 | $quality = $image->get_quality(); | 
| 61 | 61 | $ow = $current_size['width']; | 
| @@ -69,29 +69,29 @@ discard block | ||
| 69 | 69 | $y = 0; | 
| 70 | 70 | $x = $w / 2 - $owt / 2; | 
| 71 | 71 | $oht = $h; | 
| 72 | - $image->crop( 0, 0, $ow, $oh, $owt, $oht ); | |
| 72 | + $image->crop(0, 0, $ow, $oh, $owt, $oht); | |
| 73 | 73 |  			} else { | 
| 74 | 74 | $w_scale = $w / $ow; | 
| 75 | 75 | $oht = $oh * $w_scale; | 
| 76 | 76 | $x = 0; | 
| 77 | 77 | $y = $h / 2 - $oht / 2; | 
| 78 | 78 | $owt = $w; | 
| 79 | - $image->crop( 0, 0, $ow, $oh, $owt, $oht ); | |
| 79 | + $image->crop(0, 0, $ow, $oh, $owt, $oht); | |
| 80 | 80 | } | 
| 81 | - $image->save( $save_filename ); | |
| 81 | + $image->save($save_filename); | |
| 82 | 82 | $func = 'imagecreatefromjpeg'; | 
| 83 | - $ext = pathinfo( $save_filename, PATHINFO_EXTENSION ); | |
| 83 | + $ext = pathinfo($save_filename, PATHINFO_EXTENSION); | |
| 84 | 84 |  			if ( $ext == 'gif' ) { | 
| 85 | 85 | $func = 'imagecreatefromgif'; | 
| 86 | 86 |  			} else if ( $ext == 'png' ) { | 
| 87 | 87 | $func = 'imagecreatefrompng'; | 
| 88 | 88 | } | 
| 89 | - $image = $func( $save_filename ); | |
| 90 | - imagecopy( $bg, $image, $x, $y, 0, 0, $owt, $oht ); | |
| 91 | - imagejpeg( $bg, $save_filename, $quality ); | |
| 89 | + $image = $func($save_filename); | |
| 90 | + imagecopy($bg, $image, $x, $y, 0, 0, $owt, $oht); | |
| 91 | + imagejpeg($bg, $save_filename, $quality); | |
| 92 | 92 | return true; | 
| 93 | 93 |  		} else { | 
| 94 | - TimberHelper::error_log( $image ); | |
| 94 | + TimberHelper::error_log($image); | |
| 95 | 95 | } | 
| 96 | 96 | return false; | 
| 97 | 97 | } | 
| @@ -36,14 +36,14 @@ | ||
| 36 | 36 |  	 * @return array          array('red', 'green', 'blue') to int | 
| 37 | 37 |  	 *                        ex: array('red' => 255, 'green' => 20, 'blue' => 85); | 
| 38 | 38 | */ | 
| 39 | -	public static function hexrgb( $hexstr ) { | |
| 40 | -		if ( !strstr( $hexstr, '#' ) ) { | |
| 39 | +	public static function hexrgb($hexstr) { | |
| 40 | +		if ( !strstr($hexstr, '#') ) { | |
| 41 | 41 | $hexstr = '#' . $hexstr; | 
| 42 | 42 | } | 
| 43 | -		if ( strlen( $hexstr ) == 4 ) { | |
| 43 | +		if ( strlen($hexstr) == 4 ) { | |
| 44 | 44 | $hexstr = '#' . $hexstr[1] . $hexstr[1] . $hexstr[2] . $hexstr[2] . $hexstr[3] . $hexstr[3]; | 
| 45 | 45 | } | 
| 46 | - $int = hexdec( $hexstr ); | |
| 47 | - return array( "red" => 0xFF & ( $int >> 0x10 ), "green" => 0xFF & ( $int >> 0x8 ), "blue" => 0xFF & $int ); | |
| 46 | + $int = hexdec($hexstr); | |
| 47 | +		return array("red" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int); | |
| 48 | 48 | } | 
| 49 | 49 | } | 
| 50 | 50 | \ No newline at end of file | 
| @@ -3,55 +3,55 @@ | ||
| 3 | 3 |  class ACFTimber { | 
| 4 | 4 | |
| 5 | 5 |      function __construct() { | 
| 6 | - add_filter( 'timber_post_get_meta', array( $this, 'post_get_meta' ), 10, 2 ); | |
| 7 | - add_filter( 'timber_post_get_meta_field', array( $this, 'post_get_meta_field' ), 10, 3 ); | |
| 8 | - add_filter( 'timber_term_get_meta', array( $this, 'term_get_meta' ), 10, 3 ); | |
| 9 | - add_filter( 'timber_term_get_meta_field', array( $this, 'term_get_meta_field' ), 10, 4 ); | |
| 10 | - add_filter( 'timber_user_get_meta_field_pre', array( $this, 'user_get_meta_field' ), 10, 3 ); | |
| 11 | - add_filter( 'timber_term_set_meta', array( $this, 'term_set_meta'), 10, 4 ); | |
| 6 | +        add_filter('timber_post_get_meta', array($this, 'post_get_meta'), 10, 2); | |
| 7 | +        add_filter('timber_post_get_meta_field', array($this, 'post_get_meta_field'), 10, 3); | |
| 8 | +        add_filter('timber_term_get_meta', array($this, 'term_get_meta'), 10, 3); | |
| 9 | +        add_filter('timber_term_get_meta_field', array($this, 'term_get_meta_field'), 10, 4); | |
| 10 | +        add_filter('timber_user_get_meta_field_pre', array($this, 'user_get_meta_field'), 10, 3); | |
| 11 | +        add_filter('timber_term_set_meta', array($this, 'term_set_meta'), 10, 4); | |
| 12 | 12 | } | 
| 13 | 13 | |
| 14 | -    function post_get_meta( $customs, $post_id ) { | |
| 14 | +    function post_get_meta($customs, $post_id) { | |
| 15 | 15 | return $customs; | 
| 16 | 16 | } | 
| 17 | 17 | |
| 18 | -    function post_get_meta_field( $value, $post_id, $field_name ) { | |
| 19 | - return get_field( $field_name, $post_id ); | |
| 18 | +    function post_get_meta_field($value, $post_id, $field_name) { | |
| 19 | + return get_field($field_name, $post_id); | |
| 20 | 20 | } | 
| 21 | 21 | |
| 22 | -    function term_get_meta_field( $value, $term_id, $field_name, $term ) { | |
| 22 | +    function term_get_meta_field($value, $term_id, $field_name, $term) { | |
| 23 | 23 | $searcher = $term->taxonomy . "_" . $term->ID; | 
| 24 | - return get_field( $field_name, $searcher ); | |
| 24 | + return get_field($field_name, $searcher); | |
| 25 | 25 | } | 
| 26 | 26 | |
| 27 | -    function term_set_meta( $value, $field, $term_id, $term ) { | |
| 27 | +    function term_set_meta($value, $field, $term_id, $term) { | |
| 28 | 28 | $searcher = $term->taxonomy . "_" . $term->ID; | 
| 29 | - update_field( $field, $value, $searcher ); | |
| 29 | + update_field($field, $value, $searcher); | |
| 30 | 30 | return $value; | 
| 31 | 31 | } | 
| 32 | 32 | |
| 33 | -    function term_get_meta( $fields, $term_id, $term ) { | |
| 33 | +    function term_get_meta($fields, $term_id, $term) { | |
| 34 | 34 | $searcher = $term->taxonomy . "_" . $term->ID; // save to a specific category | 
| 35 | - $fds = get_fields( $searcher ); | |
| 36 | -        if ( is_array( $fds ) ) { | |
| 37 | -            foreach ( $fds as $key => $value ) { | |
| 38 | - $key = preg_replace( '/_/', '', $key, 1 ); | |
| 39 | - $key = str_replace( $searcher, '', $key ); | |
| 40 | - $key = preg_replace( '/_/', '', $key, 1 ); | |
| 41 | - $field = get_field( $key, $searcher ); | |
| 35 | + $fds = get_fields($searcher); | |
| 36 | +        if ( is_array($fds) ) { | |
| 37 | +            foreach ($fds as $key => $value) { | |
| 38 | +                $key = preg_replace('/_/', '', $key, 1); | |
| 39 | + $key = str_replace($searcher, '', $key); | |
| 40 | +                $key = preg_replace('/_/', '', $key, 1); | |
| 41 | + $field = get_field($key, $searcher); | |
| 42 | 42 | $fields[$key] = $field; | 
| 43 | 43 | } | 
| 44 | - $fields = array_merge( $fields, $fds ); | |
| 44 | + $fields = array_merge($fields, $fds); | |
| 45 | 45 | } | 
| 46 | 46 | return $fields; | 
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | -    function user_get_meta( $fields, $user_id ) { | |
| 49 | +    function user_get_meta($fields, $user_id) { | |
| 50 | 50 | return $fields; | 
| 51 | 51 | } | 
| 52 | 52 | |
| 53 | -    function user_get_meta_field( $value, $uid, $field ) { | |
| 54 | - return get_field( $field, 'user_' . $uid ); | |
| 53 | +    function user_get_meta_field($value, $uid, $field) { | |
| 54 | + return get_field($field, 'user_' . $uid); | |
| 55 | 55 | } | 
| 56 | 56 | } | 
| 57 | 57 | |
| @@ -6,29 +6,29 @@ | ||
| 6 | 6 | */ | 
| 7 | 7 |  class TimberCommand { | 
| 8 | 8 | |
| 9 | -    public static function clear_cache($mode = 'all'){ | |
| 10 | -        if (is_array($mode)){ | |
| 9 | +    public static function clear_cache($mode = 'all') { | |
| 10 | +        if ( is_array($mode) ) { | |
| 11 | 11 | $mode = reset($mode); | 
| 12 | 12 | } | 
| 13 | -        if ($mode == 'all') { | |
| 13 | +        if ( $mode == 'all' ) { | |
| 14 | 14 | $twig_cache = self::clear_cache_twig(); | 
| 15 | 15 | $timber_cache = self::clear_cache_timber(); | 
| 16 | -            if ($twig_cache && $timber_cache){ | |
| 16 | +            if ( $twig_cache && $timber_cache ) { | |
| 17 | 17 | return true; | 
| 18 | 18 | } | 
| 19 | -        } else if ($mode == 'twig') { | |
| 19 | +        } else if ( $mode == 'twig' ) { | |
| 20 | 20 | return self::clear_cache_twig(); | 
| 21 | -        } else if ($mode == 'timber') { | |
| 21 | +        } else if ( $mode == 'timber' ) { | |
| 22 | 22 | return self::clear_cache_timber(); | 
| 23 | 23 | } | 
| 24 | 24 | } | 
| 25 | 25 | |
| 26 | -    static function clear_cache_timber(){ | |
| 26 | +    static function clear_cache_timber() { | |
| 27 | 27 | $loader = new TimberLoader(); | 
| 28 | 28 | return $loader->clear_cache_timber(); | 
| 29 | 29 | } | 
| 30 | 30 | |
| 31 | -    static function clear_cache_twig(){ | |
| 31 | +    static function clear_cache_twig() { | |
| 32 | 32 | $loader = new TimberLoader(); | 
| 33 | 33 | return $loader->clear_cache_twig(); | 
| 34 | 34 | } | 
| @@ -1,5 +1,5 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | -if (!class_exists('WP_CLI_Command')) { | |
| 2 | +if ( !class_exists('WP_CLI_Command') ) { | |
| 3 | 3 | return; | 
| 4 | 4 | } | 
| 5 | 5 | |
| @@ -25,9 +25,9 @@ discard block | ||
| 25 | 25 | * wp timber clear_cache_twig | 
| 26 | 26 | * | 
| 27 | 27 | */ | 
| 28 | -    function clear_cache_twig(){ | |
| 28 | +    function clear_cache_twig() { | |
| 29 | 29 | $clear = TimberCommand::clear_cache_twig(); | 
| 30 | -        if ($clear){ | |
| 30 | +        if ( $clear ) { | |
| 31 | 31 |              WP_CLI::success('Cleared contents of twig cache'); | 
| 32 | 32 |          } else { | 
| 33 | 33 |              WP_CLI::warning('Failed to clear twig cache'); | 
| @@ -45,7 +45,7 @@ discard block | ||
| 45 | 45 |      function clear_cache_timber() { | 
| 46 | 46 | $clear = TimberCommand::clear_cache_timber(); | 
| 47 | 47 | $message = 'Failed to clear timber cache'; | 
| 48 | -        if ($clear){ | |
| 48 | +        if ( $clear ) { | |
| 49 | 49 | $message = "Cleared contents of Timber's Cache"; | 
| 50 | 50 | WP_CLI::success($message); | 
| 51 | 51 |          } else { | 
| @@ -3,7 +3,7 @@ discard block | ||
| 3 | 3 |  class TimberAdmin { | 
| 4 | 4 | |
| 5 | 5 |      public static function init() { | 
| 6 | - return add_filter( 'plugin_row_meta', array( __CLASS__, 'meta_links' ), 10, 2 ); | |
| 6 | +        return add_filter('plugin_row_meta', array(__CLASS__, 'meta_links'), 10, 2); | |
| 7 | 7 | } | 
| 8 | 8 | |
| 9 | 9 | /** | 
| @@ -11,8 +11,8 @@ discard block | ||
| 11 | 11 | * @param string $file | 
| 12 | 12 | * @return array | 
| 13 | 13 | */ | 
| 14 | -	public static function meta_links( $links, $file ) { | |
| 15 | -		if ( strstr( $file, '/timber.php' ) ) { | |
| 14 | +	public static function meta_links($links, $file) { | |
| 15 | +		if ( strstr($file, '/timber.php') ) { | |
| 16 | 16 | unset($links[2]); | 
| 17 | 17 | $links[] = '<a href="/wp-admin/plugin-install.php?tab=plugin-information&plugin=timber-library&TB_iframe=true&width=600&height=550" class="thickbox" aria-label="More information about Timber" data-title="Timber">View details</a>'; | 
| 18 | 18 | $links[] = '<a href="http://upstatement.com/timber" target="_blank">Homepage</a>'; | 
| @@ -2,15 +2,15 @@ | ||
| 2 | 2 | |
| 3 | 3 |  interface TimberCoreInterface { | 
| 4 | 4 | |
| 5 | - public function __call( $field, $args ); | |
| 5 | + public function __call($field, $args); | |
| 6 | 6 | |
| 7 | - public function __get( $field ); | |
| 7 | + public function __get($field); | |
| 8 | 8 | |
| 9 | 9 | /** | 
| 10 | 10 | * @return boolean | 
| 11 | 11 | */ | 
| 12 | - public function __isset( $field ); | |
| 12 | + public function __isset($field); | |
| 13 | 13 | |
| 14 | - public function meta( $key ); | |
| 14 | + public function meta($key); | |
| 15 | 15 | |
| 16 | 16 | } | 
| @@ -11,8 +11,8 @@ discard block | ||
| 11 | 11 | * | 
| 12 | 12 | * @return boolean | 
| 13 | 13 | */ | 
| 14 | -    function __isset( $field ) { | |
| 15 | -        if ( isset( $this->$field ) ) { | |
| 14 | +    function __isset($field) { | |
| 15 | +        if ( isset($this->$field) ) { | |
| 16 | 16 | return $this->$field; | 
| 17 | 17 | } | 
| 18 | 18 | return false; | 
| @@ -22,8 +22,8 @@ discard block | ||
| 22 | 22 | * This is helpful for twig to return properties and methods see: https://github.com/fabpot/Twig/issues/2 | 
| 23 | 23 | * @return mixed | 
| 24 | 24 | */ | 
| 25 | -    function __call( $field, $args ) { | |
| 26 | - return $this->__get( $field ); | |
| 25 | +    function __call($field, $args) { | |
| 26 | + return $this->__get($field); | |
| 27 | 27 | } | 
| 28 | 28 | |
| 29 | 29 | /** | 
| @@ -31,11 +31,11 @@ discard block | ||
| 31 | 31 | * | 
| 32 | 32 | * @return mixed | 
| 33 | 33 | */ | 
| 34 | -    function __get( $field ) { | |
| 34 | +    function __get($field) { | |
| 35 | 35 |      	if ( property_exists($this, $field) ) { | 
| 36 | 36 | return $this->$field; | 
| 37 | 37 | } | 
| 38 | -        if ( method_exists($this, 'meta') && $meta_value = $this->meta( $field ) ) { | |
| 38 | +        if ( method_exists($this, 'meta') && $meta_value = $this->meta($field) ) { | |
| 39 | 39 | return $this->$field = $meta_value; | 
| 40 | 40 | } | 
| 41 | 41 |          if ( method_exists($this, $field) ) { | 
| @@ -55,15 +55,15 @@ discard block | ||
| 55 | 55 | * ``` | 
| 56 | 56 | * @param array|object $info an object or array you want to grab data from to attach to the Timber object | 
| 57 | 57 | */ | 
| 58 | -    function import( $info, $force = false ) { | |
| 59 | -        if ( is_object( $info ) ) { | |
| 60 | - $info = get_object_vars( $info ); | |
| 58 | +    function import($info, $force = false) { | |
| 59 | +        if ( is_object($info) ) { | |
| 60 | + $info = get_object_vars($info); | |
| 61 | 61 | } | 
| 62 | -        if ( is_array( $info ) ) { | |
| 63 | -            foreach ( $info as $key => $value ) { | |
| 64 | -                if ( !empty( $key ) && $force ) { | |
| 62 | +        if ( is_array($info) ) { | |
| 63 | +            foreach ($info as $key => $value) { | |
| 64 | +                if ( !empty($key) && $force ) { | |
| 65 | 65 | $this->$key = $value; | 
| 66 | -                } else if ( !empty( $key ) && !method_exists($this, $key) ){ | |
| 66 | +                } else if ( !empty($key) && !method_exists($this, $key) ) { | |
| 67 | 67 | $this->$key = $value; | 
| 68 | 68 | } | 
| 69 | 69 | } | 
| @@ -76,8 +76,8 @@ discard block | ||
| 76 | 76 | * @param string $key | 
| 77 | 77 | * @param mixed $value | 
| 78 | 78 | */ | 
| 79 | -    function update( $key, $value ) { | |
| 80 | - update_metadata( $this->object_type, $this->ID, $key, $value ); | |
| 79 | +    function update($key, $value) { | |
| 80 | + update_metadata($this->object_type, $this->ID, $key, $value); | |
| 81 | 81 | } | 
| 82 | 82 | |
| 83 | 83 | /** | 
| @@ -94,10 +94,10 @@ discard block | ||
| 94 | 94 | * @return bool | 
| 95 | 95 | */ | 
| 96 | 96 |      function can_edit() { | 
| 97 | -        if ( !function_exists( 'current_user_can' ) ) { | |
| 97 | +        if ( !function_exists('current_user_can') ) { | |
| 98 | 98 | return false; | 
| 99 | 99 | } | 
| 100 | -        if ( current_user_can( 'edit_post', $this->ID ) ) { | |
| 100 | +        if ( current_user_can('edit_post', $this->ID) ) { | |
| 101 | 101 | return true; | 
| 102 | 102 | } | 
| 103 | 103 | return false; |