@@ -4,6 +4,5 @@ |
||
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | |
| 7 | -class BindingResolutionException extends Exception |
|
| 8 | -{ |
|
| 7 | +class BindingResolutionException extends Exception { |
|
| 9 | 8 | } |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | <html> |
| 3 | 3 | <head> |
| 4 | 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 5 | - <title><?= wp_specialchars_decode((string) get_option('blogname'), ENT_QUOTES); ?></title> |
|
| 5 | + <title><?= wp_specialchars_decode( (string) get_option( 'blogname' ), ENT_QUOTES ); ?></title> |
|
| 6 | 6 | </head> |
| 7 | 7 | <body> |
| 8 | 8 | |
@@ -7,80 +7,80 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Image |
| 9 | 9 | { |
| 10 | - public $image; |
|
| 10 | + public $image; |
|
| 11 | 11 | |
| 12 | - protected $postmeta; |
|
| 13 | - protected $utility; |
|
| 12 | + protected $postmeta; |
|
| 13 | + protected $utility; |
|
| 14 | 14 | |
| 15 | - public function __construct(PostMeta $postmeta, Utility $utility) |
|
| 16 | - { |
|
| 17 | - $this->postmeta = $postmeta; |
|
| 18 | - $this->utility = $utility; |
|
| 19 | - } |
|
| 15 | + public function __construct(PostMeta $postmeta, Utility $utility) |
|
| 16 | + { |
|
| 17 | + $this->postmeta = $postmeta; |
|
| 18 | + $this->utility = $utility; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param int|string $attachment |
|
| 23 | - * |
|
| 24 | - * @return self |
|
| 25 | - */ |
|
| 26 | - public function get($attachment) |
|
| 27 | - { |
|
| 28 | - $attachment = $this->normalize($attachment); |
|
| 29 | - if ($attachment && $thumbnail = wp_get_attachment_image_src($attachment, 'thumbnail')) { |
|
| 30 | - $medium = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'medium'), $thumbnail); |
|
| 31 | - $large = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'large'), $medium); |
|
| 21 | + /** |
|
| 22 | + * @param int|string $attachment |
|
| 23 | + * |
|
| 24 | + * @return self |
|
| 25 | + */ |
|
| 26 | + public function get($attachment) |
|
| 27 | + { |
|
| 28 | + $attachment = $this->normalize($attachment); |
|
| 29 | + if ($attachment && $thumbnail = wp_get_attachment_image_src($attachment, 'thumbnail')) { |
|
| 30 | + $medium = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'medium'), $thumbnail); |
|
| 31 | + $large = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'large'), $medium); |
|
| 32 | 32 | |
| 33 | - $this->image = (object) [ |
|
| 34 | - 'alt' => wp_strip_all_tags(get_post_meta($attachment, '_wp_attachment_image_alt', true), true), |
|
| 35 | - 'caption' => wp_get_attachment_caption($attachment), |
|
| 36 | - 'copyright' => wp_strip_all_tags(get_post_meta($attachment, '_copyright', true), true), |
|
| 37 | - 'ID' => $attachment, |
|
| 38 | - 'large' => $large, |
|
| 39 | - 'medium' => $medium, |
|
| 40 | - 'permalink' => get_attachment_link($attachment), |
|
| 41 | - 'thumbnail' => $this->normalizeSrc($thumbnail), |
|
| 42 | - ]; |
|
| 43 | - } |
|
| 44 | - return $this; |
|
| 45 | - } |
|
| 33 | + $this->image = (object) [ |
|
| 34 | + 'alt' => wp_strip_all_tags(get_post_meta($attachment, '_wp_attachment_image_alt', true), true), |
|
| 35 | + 'caption' => wp_get_attachment_caption($attachment), |
|
| 36 | + 'copyright' => wp_strip_all_tags(get_post_meta($attachment, '_copyright', true), true), |
|
| 37 | + 'ID' => $attachment, |
|
| 38 | + 'large' => $large, |
|
| 39 | + 'medium' => $medium, |
|
| 40 | + 'permalink' => get_attachment_link($attachment), |
|
| 41 | + 'thumbnail' => $this->normalizeSrc($thumbnail), |
|
| 42 | + ]; |
|
| 43 | + } |
|
| 44 | + return $this; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function render($size = 'large') |
|
| 48 | - { |
|
| 49 | - if ($this->image) { |
|
| 50 | - return wp_get_attachment_image($this->image->ID, $size); |
|
| 51 | - } |
|
| 52 | - } |
|
| 47 | + public function render($size = 'large') |
|
| 48 | + { |
|
| 49 | + if ($this->image) { |
|
| 50 | + return wp_get_attachment_image($this->image->ID, $size); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - protected function normalize($attachmentId) |
|
| 55 | - { |
|
| 56 | - if (!filter_var($attachmentId, FILTER_VALIDATE_INT)) { |
|
| 57 | - $attachmentId = $this->postmeta->get($attachmentId); |
|
| 58 | - } |
|
| 54 | + protected function normalize($attachmentId) |
|
| 55 | + { |
|
| 56 | + if (!filter_var($attachmentId, FILTER_VALIDATE_INT)) { |
|
| 57 | + $attachmentId = $this->postmeta->get($attachmentId); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $attachment = get_post($attachmentId); |
|
| 60 | + $attachment = get_post($attachmentId); |
|
| 61 | 61 | |
| 62 | - if (is_null($attachment) || 'attachment' != $attachment->post_type) { |
|
| 63 | - return; |
|
| 64 | - } |
|
| 62 | + if (is_null($attachment) || 'attachment' != $attachment->post_type) { |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return $attachment->ID; |
|
| 67 | - } |
|
| 66 | + return $attachment->ID; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param mixed $fallback |
|
| 71 | - * |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - protected function normalizeSrc(array $image, $fallback = false) |
|
| 75 | - { |
|
| 76 | - if (is_array($fallback) && count(array_diff($image, $fallback)) < 2) { |
|
| 77 | - $image = $fallback; |
|
| 78 | - } |
|
| 79 | - $image = array_pad($image, 3, ''); |
|
| 80 | - return [ |
|
| 81 | - 'url' => array_shift($image), |
|
| 82 | - 'width' => array_shift($image), |
|
| 83 | - 'height' => array_shift($image), |
|
| 84 | - ]; |
|
| 85 | - } |
|
| 69 | + /** |
|
| 70 | + * @param mixed $fallback |
|
| 71 | + * |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + protected function normalizeSrc(array $image, $fallback = false) |
|
| 75 | + { |
|
| 76 | + if (is_array($fallback) && count(array_diff($image, $fallback)) < 2) { |
|
| 77 | + $image = $fallback; |
|
| 78 | + } |
|
| 79 | + $image = array_pad($image, 3, ''); |
|
| 80 | + return [ |
|
| 81 | + 'url' => array_shift($image), |
|
| 82 | + 'width' => array_shift($image), |
|
| 83 | + 'height' => array_shift($image), |
|
| 84 | + ]; |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | protected $postmeta; |
| 13 | 13 | protected $utility; |
| 14 | 14 | |
| 15 | - public function __construct(PostMeta $postmeta, Utility $utility) |
|
| 15 | + public function __construct( PostMeta $postmeta, Utility $utility ) |
|
| 16 | 16 | { |
| 17 | 17 | $this->postmeta = $postmeta; |
| 18 | 18 | $this->utility = $utility; |
@@ -23,43 +23,43 @@ discard block |
||
| 23 | 23 | * |
| 24 | 24 | * @return self |
| 25 | 25 | */ |
| 26 | - public function get($attachment) |
|
| 26 | + public function get( $attachment ) |
|
| 27 | 27 | { |
| 28 | - $attachment = $this->normalize($attachment); |
|
| 29 | - if ($attachment && $thumbnail = wp_get_attachment_image_src($attachment, 'thumbnail')) { |
|
| 30 | - $medium = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'medium'), $thumbnail); |
|
| 31 | - $large = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'large'), $medium); |
|
| 28 | + $attachment = $this->normalize( $attachment ); |
|
| 29 | + if( $attachment && $thumbnail = wp_get_attachment_image_src( $attachment, 'thumbnail' ) ) { |
|
| 30 | + $medium = $this->normalizeSrc( wp_get_attachment_image_src( $attachment, 'medium' ), $thumbnail ); |
|
| 31 | + $large = $this->normalizeSrc( wp_get_attachment_image_src( $attachment, 'large' ), $medium ); |
|
| 32 | 32 | |
| 33 | 33 | $this->image = (object) [ |
| 34 | - 'alt' => wp_strip_all_tags(get_post_meta($attachment, '_wp_attachment_image_alt', true), true), |
|
| 35 | - 'caption' => wp_get_attachment_caption($attachment), |
|
| 36 | - 'copyright' => wp_strip_all_tags(get_post_meta($attachment, '_copyright', true), true), |
|
| 34 | + 'alt' => wp_strip_all_tags( get_post_meta( $attachment, '_wp_attachment_image_alt', true ), true ), |
|
| 35 | + 'caption' => wp_get_attachment_caption( $attachment ), |
|
| 36 | + 'copyright' => wp_strip_all_tags( get_post_meta( $attachment, '_copyright', true ), true ), |
|
| 37 | 37 | 'ID' => $attachment, |
| 38 | 38 | 'large' => $large, |
| 39 | 39 | 'medium' => $medium, |
| 40 | - 'permalink' => get_attachment_link($attachment), |
|
| 41 | - 'thumbnail' => $this->normalizeSrc($thumbnail), |
|
| 40 | + 'permalink' => get_attachment_link( $attachment ), |
|
| 41 | + 'thumbnail' => $this->normalizeSrc( $thumbnail ), |
|
| 42 | 42 | ]; |
| 43 | 43 | } |
| 44 | 44 | return $this; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function render($size = 'large') |
|
| 47 | + public function render( $size = 'large' ) |
|
| 48 | 48 | { |
| 49 | - if ($this->image) { |
|
| 50 | - return wp_get_attachment_image($this->image->ID, $size); |
|
| 49 | + if( $this->image ) { |
|
| 50 | + return wp_get_attachment_image( $this->image->ID, $size ); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - protected function normalize($attachmentId) |
|
| 54 | + protected function normalize( $attachmentId ) |
|
| 55 | 55 | { |
| 56 | - if (!filter_var($attachmentId, FILTER_VALIDATE_INT)) { |
|
| 57 | - $attachmentId = $this->postmeta->get($attachmentId); |
|
| 56 | + if( !filter_var( $attachmentId, FILTER_VALIDATE_INT ) ) { |
|
| 57 | + $attachmentId = $this->postmeta->get( $attachmentId ); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $attachment = get_post($attachmentId); |
|
| 60 | + $attachment = get_post( $attachmentId ); |
|
| 61 | 61 | |
| 62 | - if (is_null($attachment) || 'attachment' != $attachment->post_type) { |
|
| 62 | + if( is_null( $attachment ) || 'attachment' != $attachment->post_type ) { |
|
| 63 | 63 | return; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -71,16 +71,16 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return array |
| 73 | 73 | */ |
| 74 | - protected function normalizeSrc(array $image, $fallback = false) |
|
| 74 | + protected function normalizeSrc( array $image, $fallback = false ) |
|
| 75 | 75 | { |
| 76 | - if (is_array($fallback) && count(array_diff($image, $fallback)) < 2) { |
|
| 76 | + if( is_array( $fallback ) && count( array_diff( $image, $fallback ) ) < 2 ) { |
|
| 77 | 77 | $image = $fallback; |
| 78 | 78 | } |
| 79 | - $image = array_pad($image, 3, ''); |
|
| 79 | + $image = array_pad( $image, 3, '' ); |
|
| 80 | 80 | return [ |
| 81 | - 'url' => array_shift($image), |
|
| 82 | - 'width' => array_shift($image), |
|
| 83 | - 'height' => array_shift($image), |
|
| 81 | + 'url' => array_shift( $image ), |
|
| 82 | + 'width' => array_shift( $image ), |
|
| 83 | + 'height' => array_shift( $image ), |
|
| 84 | 84 | ]; |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -5,8 +5,7 @@ |
||
| 5 | 5 | use GeminiLabs\Castor\Helpers\PostMeta; |
| 6 | 6 | use GeminiLabs\Castor\Helpers\Utility; |
| 7 | 7 | |
| 8 | -class Image |
|
| 9 | -{ |
|
| 8 | +class Image { |
|
| 10 | 9 | public $image; |
| 11 | 10 | |
| 12 | 11 | protected $postmeta; |
@@ -6,109 +6,109 @@ |
||
| 6 | 6 | |
| 7 | 7 | abstract class Facade |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * The application instance being facaded. |
|
| 11 | - * |
|
| 12 | - * @var Application |
|
| 13 | - */ |
|
| 14 | - protected static $app; |
|
| 9 | + /** |
|
| 10 | + * The application instance being facaded. |
|
| 11 | + * |
|
| 12 | + * @var Application |
|
| 13 | + */ |
|
| 14 | + protected static $app; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * The resolved object instances. |
|
| 18 | - * |
|
| 19 | - * @var array |
|
| 20 | - */ |
|
| 21 | - protected static $resolvedInstance; |
|
| 16 | + /** |
|
| 17 | + * The resolved object instances. |
|
| 18 | + * |
|
| 19 | + * @var array |
|
| 20 | + */ |
|
| 21 | + protected static $resolvedInstance; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Handle dynamic, static calls to the object. |
|
| 25 | - * |
|
| 26 | - * @param string $method |
|
| 27 | - * @param array $args |
|
| 28 | - * |
|
| 29 | - * @return mixed |
|
| 30 | - * @throws \RuntimeException |
|
| 31 | - */ |
|
| 32 | - public static function __callStatic($method, $args) |
|
| 33 | - { |
|
| 34 | - $instance = static::getFacadeRoot(); |
|
| 23 | + /** |
|
| 24 | + * Handle dynamic, static calls to the object. |
|
| 25 | + * |
|
| 26 | + * @param string $method |
|
| 27 | + * @param array $args |
|
| 28 | + * |
|
| 29 | + * @return mixed |
|
| 30 | + * @throws \RuntimeException |
|
| 31 | + */ |
|
| 32 | + public static function __callStatic($method, $args) |
|
| 33 | + { |
|
| 34 | + $instance = static::getFacadeRoot(); |
|
| 35 | 35 | |
| 36 | - if (!$instance) { |
|
| 37 | - throw new RuntimeException('A facade root has not been set.'); |
|
| 38 | - } |
|
| 36 | + if (!$instance) { |
|
| 37 | + throw new RuntimeException('A facade root has not been set.'); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $instance->$method(...$args); |
|
| 41 | - } |
|
| 40 | + return $instance->$method(...$args); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Clear all of the resolved instances. |
|
| 45 | - * |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - public static function clearResolvedInstances() |
|
| 49 | - { |
|
| 50 | - static::$resolvedInstance = []; |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * Clear all of the resolved instances. |
|
| 45 | + * |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + public static function clearResolvedInstances() |
|
| 49 | + { |
|
| 50 | + static::$resolvedInstance = []; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get the application instance behind the facade. |
|
| 55 | - * |
|
| 56 | - * @return Application |
|
| 57 | - */ |
|
| 58 | - public static function getFacadeApplication() |
|
| 59 | - { |
|
| 60 | - return static::$app; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * Get the application instance behind the facade. |
|
| 55 | + * |
|
| 56 | + * @return Application |
|
| 57 | + */ |
|
| 58 | + public static function getFacadeApplication() |
|
| 59 | + { |
|
| 60 | + return static::$app; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Get the root object behind the facade. |
|
| 65 | - * |
|
| 66 | - * @return mixed |
|
| 67 | - */ |
|
| 68 | - public static function getFacadeRoot() |
|
| 69 | - { |
|
| 70 | - return static::resolveFacadeInstance(static::getFacadeAccessor()); |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * Get the root object behind the facade. |
|
| 65 | + * |
|
| 66 | + * @return mixed |
|
| 67 | + */ |
|
| 68 | + public static function getFacadeRoot() |
|
| 69 | + { |
|
| 70 | + return static::resolveFacadeInstance(static::getFacadeAccessor()); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Set the application instance. |
|
| 75 | - * |
|
| 76 | - * @return void |
|
| 77 | - */ |
|
| 78 | - public static function setFacadeApplication(Application $app) |
|
| 79 | - { |
|
| 80 | - static::$app = $app; |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * Set the application instance. |
|
| 75 | + * |
|
| 76 | + * @return void |
|
| 77 | + */ |
|
| 78 | + public static function setFacadeApplication(Application $app) |
|
| 79 | + { |
|
| 80 | + static::$app = $app; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Get the registered name of the component. |
|
| 85 | - * |
|
| 86 | - * @return string |
|
| 87 | - * |
|
| 88 | - * @throws \RuntimeException |
|
| 89 | - */ |
|
| 90 | - protected static function getFacadeAccessor() |
|
| 91 | - { |
|
| 92 | - throw new RuntimeException('Facade does not implement getFacadeAccessor method.'); |
|
| 93 | - } |
|
| 83 | + /** |
|
| 84 | + * Get the registered name of the component. |
|
| 85 | + * |
|
| 86 | + * @return string |
|
| 87 | + * |
|
| 88 | + * @throws \RuntimeException |
|
| 89 | + */ |
|
| 90 | + protected static function getFacadeAccessor() |
|
| 91 | + { |
|
| 92 | + throw new RuntimeException('Facade does not implement getFacadeAccessor method.'); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Resolve the facade root instance from the container. |
|
| 97 | - * |
|
| 98 | - * @param string|object $name |
|
| 99 | - * |
|
| 100 | - * @return mixed |
|
| 101 | - */ |
|
| 102 | - protected static function resolveFacadeInstance($name) |
|
| 103 | - { |
|
| 104 | - if (is_object($name)) { |
|
| 105 | - return $name; |
|
| 106 | - } |
|
| 95 | + /** |
|
| 96 | + * Resolve the facade root instance from the container. |
|
| 97 | + * |
|
| 98 | + * @param string|object $name |
|
| 99 | + * |
|
| 100 | + * @return mixed |
|
| 101 | + */ |
|
| 102 | + protected static function resolveFacadeInstance($name) |
|
| 103 | + { |
|
| 104 | + if (is_object($name)) { |
|
| 105 | + return $name; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - if (isset(static::$resolvedInstance[$name])) { |
|
| 109 | - return static::$resolvedInstance[$name]; |
|
| 110 | - } |
|
| 108 | + if (isset(static::$resolvedInstance[$name])) { |
|
| 109 | + return static::$resolvedInstance[$name]; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - return static::$resolvedInstance[$name] = static::$app->make($name); |
|
| 113 | - } |
|
| 112 | + return static::$resolvedInstance[$name] = static::$app->make($name); |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -29,15 +29,15 @@ discard block |
||
| 29 | 29 | * @return mixed |
| 30 | 30 | * @throws \RuntimeException |
| 31 | 31 | */ |
| 32 | - public static function __callStatic($method, $args) |
|
| 32 | + public static function __callStatic( $method, $args ) |
|
| 33 | 33 | { |
| 34 | 34 | $instance = static::getFacadeRoot(); |
| 35 | 35 | |
| 36 | - if (!$instance) { |
|
| 37 | - throw new RuntimeException('A facade root has not been set.'); |
|
| 36 | + if( !$instance ) { |
|
| 37 | + throw new RuntimeException( 'A facade root has not been set.' ); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - return $instance->$method(...$args); |
|
| 40 | + return $instance->$method( ...$args ); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | public static function getFacadeRoot() |
| 69 | 69 | { |
| 70 | - return static::resolveFacadeInstance(static::getFacadeAccessor()); |
|
| 70 | + return static::resolveFacadeInstance( static::getFacadeAccessor() ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return void |
| 77 | 77 | */ |
| 78 | - public static function setFacadeApplication(Application $app) |
|
| 78 | + public static function setFacadeApplication( Application $app ) |
|
| 79 | 79 | { |
| 80 | 80 | static::$app = $app; |
| 81 | 81 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | protected static function getFacadeAccessor() |
| 91 | 91 | { |
| 92 | - throw new RuntimeException('Facade does not implement getFacadeAccessor method.'); |
|
| 92 | + throw new RuntimeException( 'Facade does not implement getFacadeAccessor method.' ); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,16 +99,16 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return mixed |
| 101 | 101 | */ |
| 102 | - protected static function resolveFacadeInstance($name) |
|
| 102 | + protected static function resolveFacadeInstance( $name ) |
|
| 103 | 103 | { |
| 104 | - if (is_object($name)) { |
|
| 104 | + if( is_object( $name ) ) { |
|
| 105 | 105 | return $name; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if (isset(static::$resolvedInstance[$name])) { |
|
| 108 | + if( isset( static::$resolvedInstance[$name] ) ) { |
|
| 109 | 109 | return static::$resolvedInstance[$name]; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - return static::$resolvedInstance[$name] = static::$app->make($name); |
|
| 112 | + return static::$resolvedInstance[$name] = static::$app->make( $name ); |
|
| 113 | 113 | } |
| 114 | 114 | } |
@@ -4,8 +4,7 @@ |
||
| 4 | 4 | |
| 5 | 5 | use RuntimeException; |
| 6 | 6 | |
| 7 | -abstract class Facade |
|
| 8 | -{ |
|
| 7 | +abstract class Facade { |
|
| 9 | 8 | /** |
| 10 | 9 | * The application instance being facaded. |
| 11 | 10 | * |
@@ -10,294 +10,294 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Gallery |
| 12 | 12 | { |
| 13 | - public $gallery; |
|
| 14 | - |
|
| 15 | - protected $args; |
|
| 16 | - protected $image; |
|
| 17 | - protected $postmeta; |
|
| 18 | - protected $theme; |
|
| 19 | - protected $utility; |
|
| 20 | - |
|
| 21 | - public function __construct(Image $image, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
| 22 | - { |
|
| 23 | - $this->image = $image; |
|
| 24 | - $this->postmeta = $postmeta; |
|
| 25 | - $this->theme = $theme; |
|
| 26 | - $this->utility = $utility; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @return static |
|
| 31 | - */ |
|
| 32 | - public function get(array $args = []) |
|
| 33 | - { |
|
| 34 | - $this->normalizeArgs($args); |
|
| 35 | - |
|
| 36 | - $this->gallery = new WP_Query([ |
|
| 37 | - 'orderby' => 'post__in', |
|
| 38 | - 'paged' => $this->getPaged(), |
|
| 39 | - 'post__in' => $this->args['media'], |
|
| 40 | - 'post_mime_type' => 'image', |
|
| 41 | - 'post_type' => 'attachment', |
|
| 42 | - 'post_status' => 'inherit', |
|
| 43 | - 'posts_per_page' => $this->args['images_per_page'], |
|
| 44 | - ]); |
|
| 45 | - return $this; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function render() |
|
| 52 | - { |
|
| 53 | - if (empty($this->args['media'])) { |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - $images = array_reduce($this->gallery->posts, function ($images, $attachment) { |
|
| 57 | - return $images.$this->renderImage($attachment); |
|
| 58 | - }); |
|
| 59 | - return sprintf('<div class="gallery-images" itemscope itemtype="http://schema.org/ImageGallery">%s</div>%s', |
|
| 60 | - $images, |
|
| 61 | - $this->renderPagination() |
|
| 62 | - ); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return string|null |
|
| 67 | - */ |
|
| 68 | - public function renderImage(WP_Post $attachment) |
|
| 69 | - { |
|
| 70 | - $image = $this->image->get($attachment->ID)->image; |
|
| 71 | - |
|
| 72 | - if (!$image) { |
|
| 73 | - return; |
|
| 74 | - } |
|
| 75 | - return sprintf( |
|
| 76 | - '<figure class="gallery-image" data-w="%s" data-h="%s" data-ps=\'%s\' itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">'. |
|
| 77 | - '%s%s'. |
|
| 78 | - '</figure>', |
|
| 79 | - $image->thumbnail['width'], |
|
| 80 | - $image->thumbnail['height'], |
|
| 81 | - $this->getPhotoswipeData($image), |
|
| 82 | - $this->renderImageTag($image), |
|
| 83 | - $this->renderImageCaption($image) |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @return string|null |
|
| 89 | - */ |
|
| 90 | - public function renderPagination() |
|
| 91 | - { |
|
| 92 | - if (!$this->args['pagination']) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - return paginate_links([ |
|
| 96 | - 'before_page_number' => '<span class="screen-reader-text">'.__('Page', 'castor').' </span>', |
|
| 97 | - 'current' => $this->gallery->query['paged'], |
|
| 98 | - 'mid_size' => 1, |
|
| 99 | - 'next_text' => __('Next', 'castor'), |
|
| 100 | - 'prev_text' => __('Previous', 'castor'), |
|
| 101 | - 'total' => $this->gallery->max_num_pages, |
|
| 102 | - ]); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @param string $key |
|
| 107 | - * @param mixed $value |
|
| 108 | - * |
|
| 109 | - * @return bool |
|
| 110 | - */ |
|
| 111 | - protected function getBoolValue($key, $value = null) |
|
| 112 | - { |
|
| 113 | - $bool = $this->getValue($key, $value); |
|
| 114 | - |
|
| 115 | - if (is_null(filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))) { |
|
| 116 | - $bool = $this->postmeta->get($bool); |
|
| 117 | - } |
|
| 118 | - return wp_validate_boolean($bool); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param mixed $value |
|
| 123 | - * |
|
| 124 | - * @return int |
|
| 125 | - */ |
|
| 126 | - protected function getGalleryArg($value = null) |
|
| 127 | - { |
|
| 128 | - $gallery = $this->getValue('gallery', $value); |
|
| 129 | - |
|
| 130 | - if (!is_numeric($gallery) && is_string($gallery)) { |
|
| 131 | - $gallery = intval($this->postmeta->get($gallery)); |
|
| 132 | - } |
|
| 133 | - return !is_null(get_post($gallery)) |
|
| 134 | - ? intval($gallery) |
|
| 135 | - : 0; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param mixed $value |
|
| 140 | - * |
|
| 141 | - * @return int |
|
| 142 | - */ |
|
| 143 | - protected function getImagesPerPageArg($value = null) |
|
| 144 | - { |
|
| 145 | - $perPage = $this->getValue('images_per_page', $value); |
|
| 146 | - |
|
| 147 | - if (!is_numeric($perPage) && is_string($perPage)) { |
|
| 148 | - $perPage = $this->postmeta->get($perPage); |
|
| 149 | - } |
|
| 150 | - return (bool) intval($perPage) |
|
| 151 | - ? $perPage |
|
| 152 | - : -1; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param mixed $value |
|
| 157 | - * |
|
| 158 | - * @return bool |
|
| 159 | - */ |
|
| 160 | - protected function getLazyloadArg($value = null) |
|
| 161 | - { |
|
| 162 | - return $this->getBoolValue('lazyload', $value); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param mixed $value |
|
| 167 | - * |
|
| 168 | - * @return array |
|
| 169 | - */ |
|
| 170 | - protected function getMediaArg($value = null) |
|
| 171 | - { |
|
| 172 | - $media = $this->getValue('media', $value); |
|
| 173 | - |
|
| 174 | - if (is_string($media)) { |
|
| 175 | - $media = $this->postmeta->get($media, [ |
|
| 176 | - 'ID' => $this->getGalleryArg(), |
|
| 177 | - 'single' => false, |
|
| 178 | - ]); |
|
| 179 | - } |
|
| 180 | - return is_array($media) |
|
| 181 | - ? wp_parse_id_list($media) |
|
| 182 | - : []; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return int |
|
| 187 | - */ |
|
| 188 | - protected function getPaged() |
|
| 189 | - { |
|
| 190 | - return intval(get_query_var((is_front_page() ? 'page' : 'paged'))) ?: 1; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @param mixed $value |
|
| 195 | - * |
|
| 196 | - * @return bool |
|
| 197 | - */ |
|
| 198 | - protected function getPaginationArg($value = null) |
|
| 199 | - { |
|
| 200 | - return $this->getBoolValue('pagination', $value); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param mixed $value |
|
| 205 | - * |
|
| 206 | - * @return bool |
|
| 207 | - */ |
|
| 208 | - protected function getPermalinksArg($value = null) |
|
| 209 | - { |
|
| 210 | - return $this->getBoolValue('permalinks', $value); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @return string |
|
| 215 | - */ |
|
| 216 | - protected function getPhotoswipeData($image) |
|
| 217 | - { |
|
| 218 | - return sprintf('{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}', |
|
| 219 | - $image->large['url'], |
|
| 220 | - $image->large['width'], |
|
| 221 | - $image->large['height'], |
|
| 222 | - $image->medium['url'], |
|
| 223 | - $image->medium['width'], |
|
| 224 | - $image->medium['height'] |
|
| 225 | - ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @param string $key |
|
| 230 | - * @param mixed $value |
|
| 231 | - * |
|
| 232 | - * @return mixed |
|
| 233 | - */ |
|
| 234 | - protected function getValue($key, $value = null) |
|
| 235 | - { |
|
| 236 | - if (is_null($value) && isset($this->args[$key])) { |
|
| 237 | - $value = $this->args[$key]; |
|
| 238 | - } |
|
| 239 | - return $value; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return array |
|
| 244 | - */ |
|
| 245 | - protected function normalizeArgs(array $args = []) |
|
| 246 | - { |
|
| 247 | - $defaults = [ |
|
| 248 | - 'gallery', // (string) meta_key | (int) post_id |
|
| 249 | - 'lazyload', // (string) meta_key | (bool) |
|
| 250 | - 'media', // (string) meta_key | (array) post_ids |
|
| 251 | - 'pagination', // (string) meta_key | (bool) |
|
| 252 | - 'images_per_page', // (string) meta_key | (int) number |
|
| 253 | - 'permalinks', // (string) meta_key | (bool) |
|
| 254 | - ]; |
|
| 255 | - |
|
| 256 | - $this->args = shortcode_atts(array_combine($defaults, $defaults), $args); |
|
| 257 | - |
|
| 258 | - array_walk($this->args, function (&$value, $key) { |
|
| 259 | - $method = $this->utility->buildMethodName($key.'_arg'); |
|
| 260 | - if (method_exists($this, $method)) { |
|
| 261 | - $value = call_user_func([$this, $method], $value); |
|
| 262 | - } |
|
| 263 | - }); |
|
| 264 | - |
|
| 265 | - return $this->args; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @param object $image |
|
| 270 | - * @return string|null |
|
| 271 | - */ |
|
| 272 | - protected function renderImageCaption($image) |
|
| 273 | - { |
|
| 274 | - if (!empty($image->copyright)) { |
|
| 275 | - $image->caption .= sprintf(' <span itemprop="copyrightHolder">%s</span>', $image->copyright); |
|
| 276 | - } |
|
| 277 | - if (empty($image->caption)) { |
|
| 278 | - return; |
|
| 279 | - } |
|
| 280 | - return sprintf('<figcaption itemprop="caption description">%s</figcaption>', $image->caption); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @param object $image |
|
| 285 | - * @return string|null |
|
| 286 | - */ |
|
| 287 | - protected function renderImageTag($image) |
|
| 288 | - { |
|
| 289 | - $imgSrc = $this->getLazyloadArg() |
|
| 290 | - ? $this->theme->imageUri('blank.gif') |
|
| 291 | - : $image->thumbnail['url']; |
|
| 292 | - |
|
| 293 | - $imgTag = sprintf('<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>', |
|
| 294 | - $imgSrc, |
|
| 295 | - $image->thumbnail['url'], |
|
| 296 | - $image->alt |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - return $this->getPermalinksArg() |
|
| 300 | - ? sprintf('<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag) |
|
| 301 | - : $imgTag; |
|
| 302 | - } |
|
| 13 | + public $gallery; |
|
| 14 | + |
|
| 15 | + protected $args; |
|
| 16 | + protected $image; |
|
| 17 | + protected $postmeta; |
|
| 18 | + protected $theme; |
|
| 19 | + protected $utility; |
|
| 20 | + |
|
| 21 | + public function __construct(Image $image, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
| 22 | + { |
|
| 23 | + $this->image = $image; |
|
| 24 | + $this->postmeta = $postmeta; |
|
| 25 | + $this->theme = $theme; |
|
| 26 | + $this->utility = $utility; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @return static |
|
| 31 | + */ |
|
| 32 | + public function get(array $args = []) |
|
| 33 | + { |
|
| 34 | + $this->normalizeArgs($args); |
|
| 35 | + |
|
| 36 | + $this->gallery = new WP_Query([ |
|
| 37 | + 'orderby' => 'post__in', |
|
| 38 | + 'paged' => $this->getPaged(), |
|
| 39 | + 'post__in' => $this->args['media'], |
|
| 40 | + 'post_mime_type' => 'image', |
|
| 41 | + 'post_type' => 'attachment', |
|
| 42 | + 'post_status' => 'inherit', |
|
| 43 | + 'posts_per_page' => $this->args['images_per_page'], |
|
| 44 | + ]); |
|
| 45 | + return $this; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function render() |
|
| 52 | + { |
|
| 53 | + if (empty($this->args['media'])) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + $images = array_reduce($this->gallery->posts, function ($images, $attachment) { |
|
| 57 | + return $images.$this->renderImage($attachment); |
|
| 58 | + }); |
|
| 59 | + return sprintf('<div class="gallery-images" itemscope itemtype="http://schema.org/ImageGallery">%s</div>%s', |
|
| 60 | + $images, |
|
| 61 | + $this->renderPagination() |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return string|null |
|
| 67 | + */ |
|
| 68 | + public function renderImage(WP_Post $attachment) |
|
| 69 | + { |
|
| 70 | + $image = $this->image->get($attachment->ID)->image; |
|
| 71 | + |
|
| 72 | + if (!$image) { |
|
| 73 | + return; |
|
| 74 | + } |
|
| 75 | + return sprintf( |
|
| 76 | + '<figure class="gallery-image" data-w="%s" data-h="%s" data-ps=\'%s\' itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">'. |
|
| 77 | + '%s%s'. |
|
| 78 | + '</figure>', |
|
| 79 | + $image->thumbnail['width'], |
|
| 80 | + $image->thumbnail['height'], |
|
| 81 | + $this->getPhotoswipeData($image), |
|
| 82 | + $this->renderImageTag($image), |
|
| 83 | + $this->renderImageCaption($image) |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @return string|null |
|
| 89 | + */ |
|
| 90 | + public function renderPagination() |
|
| 91 | + { |
|
| 92 | + if (!$this->args['pagination']) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + return paginate_links([ |
|
| 96 | + 'before_page_number' => '<span class="screen-reader-text">'.__('Page', 'castor').' </span>', |
|
| 97 | + 'current' => $this->gallery->query['paged'], |
|
| 98 | + 'mid_size' => 1, |
|
| 99 | + 'next_text' => __('Next', 'castor'), |
|
| 100 | + 'prev_text' => __('Previous', 'castor'), |
|
| 101 | + 'total' => $this->gallery->max_num_pages, |
|
| 102 | + ]); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param string $key |
|
| 107 | + * @param mixed $value |
|
| 108 | + * |
|
| 109 | + * @return bool |
|
| 110 | + */ |
|
| 111 | + protected function getBoolValue($key, $value = null) |
|
| 112 | + { |
|
| 113 | + $bool = $this->getValue($key, $value); |
|
| 114 | + |
|
| 115 | + if (is_null(filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))) { |
|
| 116 | + $bool = $this->postmeta->get($bool); |
|
| 117 | + } |
|
| 118 | + return wp_validate_boolean($bool); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param mixed $value |
|
| 123 | + * |
|
| 124 | + * @return int |
|
| 125 | + */ |
|
| 126 | + protected function getGalleryArg($value = null) |
|
| 127 | + { |
|
| 128 | + $gallery = $this->getValue('gallery', $value); |
|
| 129 | + |
|
| 130 | + if (!is_numeric($gallery) && is_string($gallery)) { |
|
| 131 | + $gallery = intval($this->postmeta->get($gallery)); |
|
| 132 | + } |
|
| 133 | + return !is_null(get_post($gallery)) |
|
| 134 | + ? intval($gallery) |
|
| 135 | + : 0; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param mixed $value |
|
| 140 | + * |
|
| 141 | + * @return int |
|
| 142 | + */ |
|
| 143 | + protected function getImagesPerPageArg($value = null) |
|
| 144 | + { |
|
| 145 | + $perPage = $this->getValue('images_per_page', $value); |
|
| 146 | + |
|
| 147 | + if (!is_numeric($perPage) && is_string($perPage)) { |
|
| 148 | + $perPage = $this->postmeta->get($perPage); |
|
| 149 | + } |
|
| 150 | + return (bool) intval($perPage) |
|
| 151 | + ? $perPage |
|
| 152 | + : -1; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param mixed $value |
|
| 157 | + * |
|
| 158 | + * @return bool |
|
| 159 | + */ |
|
| 160 | + protected function getLazyloadArg($value = null) |
|
| 161 | + { |
|
| 162 | + return $this->getBoolValue('lazyload', $value); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param mixed $value |
|
| 167 | + * |
|
| 168 | + * @return array |
|
| 169 | + */ |
|
| 170 | + protected function getMediaArg($value = null) |
|
| 171 | + { |
|
| 172 | + $media = $this->getValue('media', $value); |
|
| 173 | + |
|
| 174 | + if (is_string($media)) { |
|
| 175 | + $media = $this->postmeta->get($media, [ |
|
| 176 | + 'ID' => $this->getGalleryArg(), |
|
| 177 | + 'single' => false, |
|
| 178 | + ]); |
|
| 179 | + } |
|
| 180 | + return is_array($media) |
|
| 181 | + ? wp_parse_id_list($media) |
|
| 182 | + : []; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @return int |
|
| 187 | + */ |
|
| 188 | + protected function getPaged() |
|
| 189 | + { |
|
| 190 | + return intval(get_query_var((is_front_page() ? 'page' : 'paged'))) ?: 1; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @param mixed $value |
|
| 195 | + * |
|
| 196 | + * @return bool |
|
| 197 | + */ |
|
| 198 | + protected function getPaginationArg($value = null) |
|
| 199 | + { |
|
| 200 | + return $this->getBoolValue('pagination', $value); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param mixed $value |
|
| 205 | + * |
|
| 206 | + * @return bool |
|
| 207 | + */ |
|
| 208 | + protected function getPermalinksArg($value = null) |
|
| 209 | + { |
|
| 210 | + return $this->getBoolValue('permalinks', $value); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @return string |
|
| 215 | + */ |
|
| 216 | + protected function getPhotoswipeData($image) |
|
| 217 | + { |
|
| 218 | + return sprintf('{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}', |
|
| 219 | + $image->large['url'], |
|
| 220 | + $image->large['width'], |
|
| 221 | + $image->large['height'], |
|
| 222 | + $image->medium['url'], |
|
| 223 | + $image->medium['width'], |
|
| 224 | + $image->medium['height'] |
|
| 225 | + ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @param string $key |
|
| 230 | + * @param mixed $value |
|
| 231 | + * |
|
| 232 | + * @return mixed |
|
| 233 | + */ |
|
| 234 | + protected function getValue($key, $value = null) |
|
| 235 | + { |
|
| 236 | + if (is_null($value) && isset($this->args[$key])) { |
|
| 237 | + $value = $this->args[$key]; |
|
| 238 | + } |
|
| 239 | + return $value; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return array |
|
| 244 | + */ |
|
| 245 | + protected function normalizeArgs(array $args = []) |
|
| 246 | + { |
|
| 247 | + $defaults = [ |
|
| 248 | + 'gallery', // (string) meta_key | (int) post_id |
|
| 249 | + 'lazyload', // (string) meta_key | (bool) |
|
| 250 | + 'media', // (string) meta_key | (array) post_ids |
|
| 251 | + 'pagination', // (string) meta_key | (bool) |
|
| 252 | + 'images_per_page', // (string) meta_key | (int) number |
|
| 253 | + 'permalinks', // (string) meta_key | (bool) |
|
| 254 | + ]; |
|
| 255 | + |
|
| 256 | + $this->args = shortcode_atts(array_combine($defaults, $defaults), $args); |
|
| 257 | + |
|
| 258 | + array_walk($this->args, function (&$value, $key) { |
|
| 259 | + $method = $this->utility->buildMethodName($key.'_arg'); |
|
| 260 | + if (method_exists($this, $method)) { |
|
| 261 | + $value = call_user_func([$this, $method], $value); |
|
| 262 | + } |
|
| 263 | + }); |
|
| 264 | + |
|
| 265 | + return $this->args; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @param object $image |
|
| 270 | + * @return string|null |
|
| 271 | + */ |
|
| 272 | + protected function renderImageCaption($image) |
|
| 273 | + { |
|
| 274 | + if (!empty($image->copyright)) { |
|
| 275 | + $image->caption .= sprintf(' <span itemprop="copyrightHolder">%s</span>', $image->copyright); |
|
| 276 | + } |
|
| 277 | + if (empty($image->caption)) { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 280 | + return sprintf('<figcaption itemprop="caption description">%s</figcaption>', $image->caption); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @param object $image |
|
| 285 | + * @return string|null |
|
| 286 | + */ |
|
| 287 | + protected function renderImageTag($image) |
|
| 288 | + { |
|
| 289 | + $imgSrc = $this->getLazyloadArg() |
|
| 290 | + ? $this->theme->imageUri('blank.gif') |
|
| 291 | + : $image->thumbnail['url']; |
|
| 292 | + |
|
| 293 | + $imgTag = sprintf('<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>', |
|
| 294 | + $imgSrc, |
|
| 295 | + $image->thumbnail['url'], |
|
| 296 | + $image->alt |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + return $this->getPermalinksArg() |
|
| 300 | + ? sprintf('<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag) |
|
| 301 | + : $imgTag; |
|
| 302 | + } |
|
| 303 | 303 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | protected $theme; |
| 19 | 19 | protected $utility; |
| 20 | 20 | |
| 21 | - public function __construct(Image $image, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
| 21 | + public function __construct( Image $image, PostMeta $postmeta, Theme $theme, Utility $utility ) |
|
| 22 | 22 | { |
| 23 | 23 | $this->image = $image; |
| 24 | 24 | $this->postmeta = $postmeta; |
@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * @return static |
| 31 | 31 | */ |
| 32 | - public function get(array $args = []) |
|
| 32 | + public function get( array $args = [] ) |
|
| 33 | 33 | { |
| 34 | - $this->normalizeArgs($args); |
|
| 34 | + $this->normalizeArgs( $args ); |
|
| 35 | 35 | |
| 36 | - $this->gallery = new WP_Query([ |
|
| 36 | + $this->gallery = new WP_Query( [ |
|
| 37 | 37 | 'orderby' => 'post__in', |
| 38 | 38 | 'paged' => $this->getPaged(), |
| 39 | 39 | 'post__in' => $this->args['media'], |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | 'post_type' => 'attachment', |
| 42 | 42 | 'post_status' => 'inherit', |
| 43 | 43 | 'posts_per_page' => $this->args['images_per_page'], |
| 44 | - ]); |
|
| 44 | + ] ); |
|
| 45 | 45 | return $this; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -50,13 +50,13 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function render() |
| 52 | 52 | { |
| 53 | - if (empty($this->args['media'])) { |
|
| 53 | + if( empty( $this->args['media'] ) ) { |
|
| 54 | 54 | return; |
| 55 | 55 | } |
| 56 | - $images = array_reduce($this->gallery->posts, function ($images, $attachment) { |
|
| 57 | - return $images.$this->renderImage($attachment); |
|
| 56 | + $images = array_reduce( $this->gallery->posts, function( $images, $attachment ) { |
|
| 57 | + return $images.$this->renderImage( $attachment ); |
|
| 58 | 58 | }); |
| 59 | - return sprintf('<div class="gallery-images" itemscope itemtype="http://schema.org/ImageGallery">%s</div>%s', |
|
| 59 | + return sprintf( '<div class="gallery-images" itemscope itemtype="http://schema.org/ImageGallery">%s</div>%s', |
|
| 60 | 60 | $images, |
| 61 | 61 | $this->renderPagination() |
| 62 | 62 | ); |
@@ -65,11 +65,11 @@ discard block |
||
| 65 | 65 | /** |
| 66 | 66 | * @return string|null |
| 67 | 67 | */ |
| 68 | - public function renderImage(WP_Post $attachment) |
|
| 68 | + public function renderImage( WP_Post $attachment ) |
|
| 69 | 69 | { |
| 70 | - $image = $this->image->get($attachment->ID)->image; |
|
| 70 | + $image = $this->image->get( $attachment->ID )->image; |
|
| 71 | 71 | |
| 72 | - if (!$image) { |
|
| 72 | + if( !$image ) { |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | return sprintf( |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | '</figure>', |
| 79 | 79 | $image->thumbnail['width'], |
| 80 | 80 | $image->thumbnail['height'], |
| 81 | - $this->getPhotoswipeData($image), |
|
| 82 | - $this->renderImageTag($image), |
|
| 83 | - $this->renderImageCaption($image) |
|
| 81 | + $this->getPhotoswipeData( $image ), |
|
| 82 | + $this->renderImageTag( $image ), |
|
| 83 | + $this->renderImageCaption( $image ) |
|
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -89,17 +89,17 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function renderPagination() |
| 91 | 91 | { |
| 92 | - if (!$this->args['pagination']) { |
|
| 92 | + if( !$this->args['pagination'] ) { |
|
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | - return paginate_links([ |
|
| 96 | - 'before_page_number' => '<span class="screen-reader-text">'.__('Page', 'castor').' </span>', |
|
| 95 | + return paginate_links( [ |
|
| 96 | + 'before_page_number' => '<span class="screen-reader-text">'.__( 'Page', 'castor' ).' </span>', |
|
| 97 | 97 | 'current' => $this->gallery->query['paged'], |
| 98 | 98 | 'mid_size' => 1, |
| 99 | - 'next_text' => __('Next', 'castor'), |
|
| 100 | - 'prev_text' => __('Previous', 'castor'), |
|
| 99 | + 'next_text' => __( 'Next', 'castor' ), |
|
| 100 | + 'prev_text' => __( 'Previous', 'castor' ), |
|
| 101 | 101 | 'total' => $this->gallery->max_num_pages, |
| 102 | - ]); |
|
| 102 | + ] ); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -108,14 +108,14 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return bool |
| 110 | 110 | */ |
| 111 | - protected function getBoolValue($key, $value = null) |
|
| 111 | + protected function getBoolValue( $key, $value = null ) |
|
| 112 | 112 | { |
| 113 | - $bool = $this->getValue($key, $value); |
|
| 113 | + $bool = $this->getValue( $key, $value ); |
|
| 114 | 114 | |
| 115 | - if (is_null(filter_var($bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))) { |
|
| 116 | - $bool = $this->postmeta->get($bool); |
|
| 115 | + if( is_null( filter_var( $bool, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) ) ) { |
|
| 116 | + $bool = $this->postmeta->get( $bool ); |
|
| 117 | 117 | } |
| 118 | - return wp_validate_boolean($bool); |
|
| 118 | + return wp_validate_boolean( $bool ); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @return int |
| 125 | 125 | */ |
| 126 | - protected function getGalleryArg($value = null) |
|
| 126 | + protected function getGalleryArg( $value = null ) |
|
| 127 | 127 | { |
| 128 | - $gallery = $this->getValue('gallery', $value); |
|
| 128 | + $gallery = $this->getValue( 'gallery', $value ); |
|
| 129 | 129 | |
| 130 | - if (!is_numeric($gallery) && is_string($gallery)) { |
|
| 131 | - $gallery = intval($this->postmeta->get($gallery)); |
|
| 130 | + if( !is_numeric( $gallery ) && is_string( $gallery ) ) { |
|
| 131 | + $gallery = intval( $this->postmeta->get( $gallery ) ); |
|
| 132 | 132 | } |
| 133 | - return !is_null(get_post($gallery)) |
|
| 134 | - ? intval($gallery) |
|
| 133 | + return !is_null( get_post( $gallery ) ) |
|
| 134 | + ? intval( $gallery ) |
|
| 135 | 135 | : 0; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -140,14 +140,14 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return int |
| 142 | 142 | */ |
| 143 | - protected function getImagesPerPageArg($value = null) |
|
| 143 | + protected function getImagesPerPageArg( $value = null ) |
|
| 144 | 144 | { |
| 145 | - $perPage = $this->getValue('images_per_page', $value); |
|
| 145 | + $perPage = $this->getValue( 'images_per_page', $value ); |
|
| 146 | 146 | |
| 147 | - if (!is_numeric($perPage) && is_string($perPage)) { |
|
| 148 | - $perPage = $this->postmeta->get($perPage); |
|
| 147 | + if( !is_numeric( $perPage ) && is_string( $perPage ) ) { |
|
| 148 | + $perPage = $this->postmeta->get( $perPage ); |
|
| 149 | 149 | } |
| 150 | - return (bool) intval($perPage) |
|
| 150 | + return (bool) intval( $perPage ) |
|
| 151 | 151 | ? $perPage |
| 152 | 152 | : -1; |
| 153 | 153 | } |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @return bool |
| 159 | 159 | */ |
| 160 | - protected function getLazyloadArg($value = null) |
|
| 160 | + protected function getLazyloadArg( $value = null ) |
|
| 161 | 161 | { |
| 162 | - return $this->getBoolValue('lazyload', $value); |
|
| 162 | + return $this->getBoolValue( 'lazyload', $value ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -167,18 +167,18 @@ discard block |
||
| 167 | 167 | * |
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | - protected function getMediaArg($value = null) |
|
| 170 | + protected function getMediaArg( $value = null ) |
|
| 171 | 171 | { |
| 172 | - $media = $this->getValue('media', $value); |
|
| 172 | + $media = $this->getValue( 'media', $value ); |
|
| 173 | 173 | |
| 174 | - if (is_string($media)) { |
|
| 175 | - $media = $this->postmeta->get($media, [ |
|
| 174 | + if( is_string( $media ) ) { |
|
| 175 | + $media = $this->postmeta->get( $media, [ |
|
| 176 | 176 | 'ID' => $this->getGalleryArg(), |
| 177 | 177 | 'single' => false, |
| 178 | - ]); |
|
| 178 | + ] ); |
|
| 179 | 179 | } |
| 180 | - return is_array($media) |
|
| 181 | - ? wp_parse_id_list($media) |
|
| 180 | + return is_array( $media ) |
|
| 181 | + ? wp_parse_id_list( $media ) |
|
| 182 | 182 | : []; |
| 183 | 183 | } |
| 184 | 184 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | protected function getPaged() |
| 189 | 189 | { |
| 190 | - return intval(get_query_var((is_front_page() ? 'page' : 'paged'))) ?: 1; |
|
| 190 | + return intval( get_query_var( ( is_front_page() ? 'page' : 'paged' ) ) ) ?: 1; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -195,9 +195,9 @@ discard block |
||
| 195 | 195 | * |
| 196 | 196 | * @return bool |
| 197 | 197 | */ |
| 198 | - protected function getPaginationArg($value = null) |
|
| 198 | + protected function getPaginationArg( $value = null ) |
|
| 199 | 199 | { |
| 200 | - return $this->getBoolValue('pagination', $value); |
|
| 200 | + return $this->getBoolValue( 'pagination', $value ); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -205,17 +205,17 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @return bool |
| 207 | 207 | */ |
| 208 | - protected function getPermalinksArg($value = null) |
|
| 208 | + protected function getPermalinksArg( $value = null ) |
|
| 209 | 209 | { |
| 210 | - return $this->getBoolValue('permalinks', $value); |
|
| 210 | + return $this->getBoolValue( 'permalinks', $value ); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * @return string |
| 215 | 215 | */ |
| 216 | - protected function getPhotoswipeData($image) |
|
| 216 | + protected function getPhotoswipeData( $image ) |
|
| 217 | 217 | { |
| 218 | - return sprintf('{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}', |
|
| 218 | + return sprintf( '{"l":{"src":"%s","w":%d,"h":%d},"m":{"src":"%s","w":%d,"h":%d}}', |
|
| 219 | 219 | $image->large['url'], |
| 220 | 220 | $image->large['width'], |
| 221 | 221 | $image->large['height'], |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @return mixed |
| 233 | 233 | */ |
| 234 | - protected function getValue($key, $value = null) |
|
| 234 | + protected function getValue( $key, $value = null ) |
|
| 235 | 235 | { |
| 236 | - if (is_null($value) && isset($this->args[$key])) { |
|
| 236 | + if( is_null( $value ) && isset( $this->args[$key] ) ) { |
|
| 237 | 237 | $value = $this->args[$key]; |
| 238 | 238 | } |
| 239 | 239 | return $value; |
@@ -242,23 +242,23 @@ discard block |
||
| 242 | 242 | /** |
| 243 | 243 | * @return array |
| 244 | 244 | */ |
| 245 | - protected function normalizeArgs(array $args = []) |
|
| 245 | + protected function normalizeArgs( array $args = [] ) |
|
| 246 | 246 | { |
| 247 | 247 | $defaults = [ |
| 248 | - 'gallery', // (string) meta_key | (int) post_id |
|
| 249 | - 'lazyload', // (string) meta_key | (bool) |
|
| 250 | - 'media', // (string) meta_key | (array) post_ids |
|
| 251 | - 'pagination', // (string) meta_key | (bool) |
|
| 248 | + 'gallery', // (string) meta_key | (int) post_id |
|
| 249 | + 'lazyload', // (string) meta_key | (bool) |
|
| 250 | + 'media', // (string) meta_key | (array) post_ids |
|
| 251 | + 'pagination', // (string) meta_key | (bool) |
|
| 252 | 252 | 'images_per_page', // (string) meta_key | (int) number |
| 253 | - 'permalinks', // (string) meta_key | (bool) |
|
| 253 | + 'permalinks', // (string) meta_key | (bool) |
|
| 254 | 254 | ]; |
| 255 | 255 | |
| 256 | - $this->args = shortcode_atts(array_combine($defaults, $defaults), $args); |
|
| 256 | + $this->args = shortcode_atts( array_combine( $defaults, $defaults ), $args ); |
|
| 257 | 257 | |
| 258 | - array_walk($this->args, function (&$value, $key) { |
|
| 259 | - $method = $this->utility->buildMethodName($key.'_arg'); |
|
| 260 | - if (method_exists($this, $method)) { |
|
| 261 | - $value = call_user_func([$this, $method], $value); |
|
| 258 | + array_walk( $this->args, function( &$value, $key ) { |
|
| 259 | + $method = $this->utility->buildMethodName( $key.'_arg' ); |
|
| 260 | + if( method_exists( $this, $method ) ) { |
|
| 261 | + $value = call_user_func( [$this, $method], $value ); |
|
| 262 | 262 | } |
| 263 | 263 | }); |
| 264 | 264 | |
@@ -269,35 +269,35 @@ discard block |
||
| 269 | 269 | * @param object $image |
| 270 | 270 | * @return string|null |
| 271 | 271 | */ |
| 272 | - protected function renderImageCaption($image) |
|
| 272 | + protected function renderImageCaption( $image ) |
|
| 273 | 273 | { |
| 274 | - if (!empty($image->copyright)) { |
|
| 275 | - $image->caption .= sprintf(' <span itemprop="copyrightHolder">%s</span>', $image->copyright); |
|
| 274 | + if( !empty( $image->copyright ) ) { |
|
| 275 | + $image->caption .= sprintf( ' <span itemprop="copyrightHolder">%s</span>', $image->copyright ); |
|
| 276 | 276 | } |
| 277 | - if (empty($image->caption)) { |
|
| 277 | + if( empty( $image->caption ) ) { |
|
| 278 | 278 | return; |
| 279 | 279 | } |
| 280 | - return sprintf('<figcaption itemprop="caption description">%s</figcaption>', $image->caption); |
|
| 280 | + return sprintf( '<figcaption itemprop="caption description">%s</figcaption>', $image->caption ); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * @param object $image |
| 285 | 285 | * @return string|null |
| 286 | 286 | */ |
| 287 | - protected function renderImageTag($image) |
|
| 287 | + protected function renderImageTag( $image ) |
|
| 288 | 288 | { |
| 289 | 289 | $imgSrc = $this->getLazyloadArg() |
| 290 | - ? $this->theme->imageUri('blank.gif') |
|
| 290 | + ? $this->theme->imageUri( 'blank.gif' ) |
|
| 291 | 291 | : $image->thumbnail['url']; |
| 292 | 292 | |
| 293 | - $imgTag = sprintf('<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>', |
|
| 293 | + $imgTag = sprintf( '<img src="%s" data-src="%s" itemprop="thumbnail" alt="%s"/>', |
|
| 294 | 294 | $imgSrc, |
| 295 | 295 | $image->thumbnail['url'], |
| 296 | 296 | $image->alt |
| 297 | 297 | ); |
| 298 | 298 | |
| 299 | 299 | return $this->getPermalinksArg() |
| 300 | - ? sprintf('<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag) |
|
| 300 | + ? sprintf( '<a href="%s" itemprop="contentUrl">%s</a>', $image->permalink, $imgTag ) |
|
| 301 | 301 | : $imgTag; |
| 302 | 302 | } |
| 303 | 303 | } |
@@ -8,8 +8,7 @@ |
||
| 8 | 8 | use WP_Post; |
| 9 | 9 | use WP_Query; |
| 10 | 10 | |
| 11 | -class Gallery |
|
| 12 | -{ |
|
| 11 | +class Gallery { |
|
| 13 | 12 | public $gallery; |
| 14 | 13 | |
| 15 | 14 | protected $args; |
@@ -7,89 +7,89 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Oembed |
| 9 | 9 | { |
| 10 | - public $oembed; |
|
| 11 | - public $utility; |
|
| 12 | - |
|
| 13 | - public $vimeo = [ |
|
| 14 | - 'api', 'autopause', 'autoplay', 'byline', 'color', 'height', 'loop', 'player_id', |
|
| 15 | - 'portrait', 'title', 'width', |
|
| 16 | - ]; |
|
| 17 | - |
|
| 18 | - public $youtube = [ |
|
| 19 | - 'autohide', 'autoplay', 'cc_load_policy', 'color', 'controls', 'disablekb', 'enablejsapi', |
|
| 20 | - 'end', 'fs', 'height', 'hl', 'iv_load_policy', 'list', 'listType', 'loop', 'modestbranding', |
|
| 21 | - 'origin', 'playerapiid', 'playlist', 'playsinline', 'rel', 'showinfo', 'start', 'theme', |
|
| 22 | - 'width', |
|
| 23 | - ]; |
|
| 24 | - |
|
| 25 | - public function __construct(Utility $utility) |
|
| 26 | - { |
|
| 27 | - $this->oembed = _wp_oembed_get_object(); |
|
| 28 | - $this->utility = $utility; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function request($url, $args = '') |
|
| 32 | - { |
|
| 33 | - $args = wp_parse_args($args, [ |
|
| 34 | - 'embed_type' => '', |
|
| 35 | - ]); |
|
| 36 | - $request = $this->oembed->fetch($this->oembed->get_provider($url), $url, [ |
|
| 37 | - 'width' => 1280, |
|
| 38 | - 'height' => 1280, |
|
| 39 | - ]); |
|
| 40 | - if (false === $request) { |
|
| 41 | - return; |
|
| 42 | - } |
|
| 43 | - if (!empty($args['embed_type']) && $args['embed_type'] != $request->type) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - return $this->modifyRequest($request, $args); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - protected function domLoad($html) |
|
| 50 | - { |
|
| 51 | - $dom = new DomDocument(); |
|
| 52 | - $dom->loadHTML($html); |
|
| 53 | - return $dom; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - protected function modifyRequest($request, $args) |
|
| 57 | - { |
|
| 58 | - $providerName = strtolower($request->provider_name); |
|
| 59 | - $provider = property_exists($this, $providerName) |
|
| 60 | - ? $this->$providerName |
|
| 61 | - : []; |
|
| 62 | - |
|
| 63 | - $method = $this->utility->buildMethodName($providerName.'_request', 'modify'); |
|
| 64 | - |
|
| 65 | - if (method_exists($this, $method)) { |
|
| 66 | - return call_user_func([$this, $method], $request, array_intersect_key( |
|
| 67 | - $args, |
|
| 68 | - array_flip($provider) |
|
| 69 | - )); |
|
| 70 | - } |
|
| 71 | - return $request; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - protected function modifyYoutubeRequest($request, array $args) |
|
| 75 | - { |
|
| 76 | - $html = $this->domLoad($request->html); |
|
| 77 | - $node = $html->getElementsByTagName('iframe')->item(0); |
|
| 78 | - $url = $node->getAttribute('src'); |
|
| 79 | - |
|
| 80 | - if (isset($args['fs']) && 0 == $args['fs']) { |
|
| 81 | - $node->removeAttribute('allowfullscreen'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $args['origin'] = urlencode(get_bloginfo('url')); |
|
| 85 | - |
|
| 86 | - $node->setAttribute('class', 'video-embed'); |
|
| 87 | - $node->setAttribute('src', |
|
| 88 | - add_query_arg($args, remove_query_arg('feature', $url)) |
|
| 89 | - ); |
|
| 90 | - |
|
| 91 | - $request->html = $html->saveHTML($node); |
|
| 92 | - |
|
| 93 | - return $request; |
|
| 94 | - } |
|
| 10 | + public $oembed; |
|
| 11 | + public $utility; |
|
| 12 | + |
|
| 13 | + public $vimeo = [ |
|
| 14 | + 'api', 'autopause', 'autoplay', 'byline', 'color', 'height', 'loop', 'player_id', |
|
| 15 | + 'portrait', 'title', 'width', |
|
| 16 | + ]; |
|
| 17 | + |
|
| 18 | + public $youtube = [ |
|
| 19 | + 'autohide', 'autoplay', 'cc_load_policy', 'color', 'controls', 'disablekb', 'enablejsapi', |
|
| 20 | + 'end', 'fs', 'height', 'hl', 'iv_load_policy', 'list', 'listType', 'loop', 'modestbranding', |
|
| 21 | + 'origin', 'playerapiid', 'playlist', 'playsinline', 'rel', 'showinfo', 'start', 'theme', |
|
| 22 | + 'width', |
|
| 23 | + ]; |
|
| 24 | + |
|
| 25 | + public function __construct(Utility $utility) |
|
| 26 | + { |
|
| 27 | + $this->oembed = _wp_oembed_get_object(); |
|
| 28 | + $this->utility = $utility; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function request($url, $args = '') |
|
| 32 | + { |
|
| 33 | + $args = wp_parse_args($args, [ |
|
| 34 | + 'embed_type' => '', |
|
| 35 | + ]); |
|
| 36 | + $request = $this->oembed->fetch($this->oembed->get_provider($url), $url, [ |
|
| 37 | + 'width' => 1280, |
|
| 38 | + 'height' => 1280, |
|
| 39 | + ]); |
|
| 40 | + if (false === $request) { |
|
| 41 | + return; |
|
| 42 | + } |
|
| 43 | + if (!empty($args['embed_type']) && $args['embed_type'] != $request->type) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + return $this->modifyRequest($request, $args); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + protected function domLoad($html) |
|
| 50 | + { |
|
| 51 | + $dom = new DomDocument(); |
|
| 52 | + $dom->loadHTML($html); |
|
| 53 | + return $dom; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + protected function modifyRequest($request, $args) |
|
| 57 | + { |
|
| 58 | + $providerName = strtolower($request->provider_name); |
|
| 59 | + $provider = property_exists($this, $providerName) |
|
| 60 | + ? $this->$providerName |
|
| 61 | + : []; |
|
| 62 | + |
|
| 63 | + $method = $this->utility->buildMethodName($providerName.'_request', 'modify'); |
|
| 64 | + |
|
| 65 | + if (method_exists($this, $method)) { |
|
| 66 | + return call_user_func([$this, $method], $request, array_intersect_key( |
|
| 67 | + $args, |
|
| 68 | + array_flip($provider) |
|
| 69 | + )); |
|
| 70 | + } |
|
| 71 | + return $request; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + protected function modifyYoutubeRequest($request, array $args) |
|
| 75 | + { |
|
| 76 | + $html = $this->domLoad($request->html); |
|
| 77 | + $node = $html->getElementsByTagName('iframe')->item(0); |
|
| 78 | + $url = $node->getAttribute('src'); |
|
| 79 | + |
|
| 80 | + if (isset($args['fs']) && 0 == $args['fs']) { |
|
| 81 | + $node->removeAttribute('allowfullscreen'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $args['origin'] = urlencode(get_bloginfo('url')); |
|
| 85 | + |
|
| 86 | + $node->setAttribute('class', 'video-embed'); |
|
| 87 | + $node->setAttribute('src', |
|
| 88 | + add_query_arg($args, remove_query_arg('feature', $url)) |
|
| 89 | + ); |
|
| 90 | + |
|
| 91 | + $request->html = $html->saveHTML($node); |
|
| 92 | + |
|
| 93 | + return $request; |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -22,73 +22,73 @@ |
||
| 22 | 22 | 'width', |
| 23 | 23 | ]; |
| 24 | 24 | |
| 25 | - public function __construct(Utility $utility) |
|
| 25 | + public function __construct( Utility $utility ) |
|
| 26 | 26 | { |
| 27 | 27 | $this->oembed = _wp_oembed_get_object(); |
| 28 | 28 | $this->utility = $utility; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - public function request($url, $args = '') |
|
| 31 | + public function request( $url, $args = '' ) |
|
| 32 | 32 | { |
| 33 | - $args = wp_parse_args($args, [ |
|
| 33 | + $args = wp_parse_args( $args, [ |
|
| 34 | 34 | 'embed_type' => '', |
| 35 | - ]); |
|
| 36 | - $request = $this->oembed->fetch($this->oembed->get_provider($url), $url, [ |
|
| 35 | + ] ); |
|
| 36 | + $request = $this->oembed->fetch( $this->oembed->get_provider( $url ), $url, [ |
|
| 37 | 37 | 'width' => 1280, |
| 38 | 38 | 'height' => 1280, |
| 39 | - ]); |
|
| 40 | - if (false === $request) { |
|
| 39 | + ] ); |
|
| 40 | + if( false === $request ) { |
|
| 41 | 41 | return; |
| 42 | 42 | } |
| 43 | - if (!empty($args['embed_type']) && $args['embed_type'] != $request->type) { |
|
| 43 | + if( !empty( $args['embed_type'] ) && $args['embed_type'] != $request->type ) { |
|
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | - return $this->modifyRequest($request, $args); |
|
| 46 | + return $this->modifyRequest( $request, $args ); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - protected function domLoad($html) |
|
| 49 | + protected function domLoad( $html ) |
|
| 50 | 50 | { |
| 51 | 51 | $dom = new DomDocument(); |
| 52 | - $dom->loadHTML($html); |
|
| 52 | + $dom->loadHTML( $html ); |
|
| 53 | 53 | return $dom; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - protected function modifyRequest($request, $args) |
|
| 56 | + protected function modifyRequest( $request, $args ) |
|
| 57 | 57 | { |
| 58 | - $providerName = strtolower($request->provider_name); |
|
| 59 | - $provider = property_exists($this, $providerName) |
|
| 58 | + $providerName = strtolower( $request->provider_name ); |
|
| 59 | + $provider = property_exists( $this, $providerName ) |
|
| 60 | 60 | ? $this->$providerName |
| 61 | 61 | : []; |
| 62 | 62 | |
| 63 | - $method = $this->utility->buildMethodName($providerName.'_request', 'modify'); |
|
| 63 | + $method = $this->utility->buildMethodName( $providerName.'_request', 'modify' ); |
|
| 64 | 64 | |
| 65 | - if (method_exists($this, $method)) { |
|
| 66 | - return call_user_func([$this, $method], $request, array_intersect_key( |
|
| 65 | + if( method_exists( $this, $method ) ) { |
|
| 66 | + return call_user_func( [$this, $method], $request, array_intersect_key( |
|
| 67 | 67 | $args, |
| 68 | - array_flip($provider) |
|
| 69 | - )); |
|
| 68 | + array_flip( $provider ) |
|
| 69 | + ) ); |
|
| 70 | 70 | } |
| 71 | 71 | return $request; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - protected function modifyYoutubeRequest($request, array $args) |
|
| 74 | + protected function modifyYoutubeRequest( $request, array $args ) |
|
| 75 | 75 | { |
| 76 | - $html = $this->domLoad($request->html); |
|
| 77 | - $node = $html->getElementsByTagName('iframe')->item(0); |
|
| 78 | - $url = $node->getAttribute('src'); |
|
| 76 | + $html = $this->domLoad( $request->html ); |
|
| 77 | + $node = $html->getElementsByTagName( 'iframe' )->item( 0 ); |
|
| 78 | + $url = $node->getAttribute( 'src' ); |
|
| 79 | 79 | |
| 80 | - if (isset($args['fs']) && 0 == $args['fs']) { |
|
| 81 | - $node->removeAttribute('allowfullscreen'); |
|
| 80 | + if( isset( $args['fs'] ) && 0 == $args['fs'] ) { |
|
| 81 | + $node->removeAttribute( 'allowfullscreen' ); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $args['origin'] = urlencode(get_bloginfo('url')); |
|
| 84 | + $args['origin'] = urlencode( get_bloginfo( 'url' ) ); |
|
| 85 | 85 | |
| 86 | - $node->setAttribute('class', 'video-embed'); |
|
| 87 | - $node->setAttribute('src', |
|
| 88 | - add_query_arg($args, remove_query_arg('feature', $url)) |
|
| 86 | + $node->setAttribute( 'class', 'video-embed' ); |
|
| 87 | + $node->setAttribute( 'src', |
|
| 88 | + add_query_arg( $args, remove_query_arg( 'feature', $url ) ) |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - $request->html = $html->saveHTML($node); |
|
| 91 | + $request->html = $html->saveHTML( $node ); |
|
| 92 | 92 | |
| 93 | 93 | return $request; |
| 94 | 94 | } |
@@ -5,8 +5,7 @@ |
||
| 5 | 5 | use GeminiLabs\Castor\Helpers\Utility; |
| 6 | 6 | use DomDocument; |
| 7 | 7 | |
| 8 | -class Oembed |
|
| 9 | -{ |
|
| 8 | +class Oembed { |
|
| 10 | 9 | public $oembed; |
| 11 | 10 | public $utility; |
| 12 | 11 | |
@@ -8,117 +8,117 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Video |
| 10 | 10 | { |
| 11 | - public $video; |
|
| 11 | + public $video; |
|
| 12 | 12 | |
| 13 | - protected $args; |
|
| 14 | - protected $image; |
|
| 15 | - protected $oembed; |
|
| 16 | - protected $postmeta; |
|
| 17 | - protected $supported = ['youtube']; |
|
| 18 | - protected $theme; |
|
| 19 | - protected $utility; |
|
| 13 | + protected $args; |
|
| 14 | + protected $image; |
|
| 15 | + protected $oembed; |
|
| 16 | + protected $postmeta; |
|
| 17 | + protected $supported = ['youtube']; |
|
| 18 | + protected $theme; |
|
| 19 | + protected $utility; |
|
| 20 | 20 | |
| 21 | - public function __construct(Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
| 22 | - { |
|
| 23 | - $this->image = $image; |
|
| 24 | - $this->oembed = $oembed; |
|
| 25 | - $this->postmeta = $postmeta; |
|
| 26 | - $this->theme = $theme; |
|
| 27 | - $this->utility = $utility; |
|
| 28 | - } |
|
| 21 | + public function __construct(Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
| 22 | + { |
|
| 23 | + $this->image = $image; |
|
| 24 | + $this->oembed = $oembed; |
|
| 25 | + $this->postmeta = $postmeta; |
|
| 26 | + $this->theme = $theme; |
|
| 27 | + $this->utility = $utility; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function get($args = []) |
|
| 31 | - { |
|
| 32 | - $args = $this->normalize($args); |
|
| 33 | - $embed = $this->oembed->request($args['url'], $args['player']); |
|
| 34 | - if (isset($embed->type) && 'video' == $embed->type) { |
|
| 35 | - $this->video = $embed; |
|
| 36 | - } |
|
| 37 | - return $this; |
|
| 38 | - } |
|
| 30 | + public function get($args = []) |
|
| 31 | + { |
|
| 32 | + $args = $this->normalize($args); |
|
| 33 | + $embed = $this->oembed->request($args['url'], $args['player']); |
|
| 34 | + if (isset($embed->type) && 'video' == $embed->type) { |
|
| 35 | + $this->video = $embed; |
|
| 36 | + } |
|
| 37 | + return $this; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function render() |
|
| 41 | - { |
|
| 42 | - if (!isset($this->video->html)) { |
|
| 43 | - return; |
|
| 44 | - } |
|
| 45 | - return sprintf( |
|
| 46 | - '<div class="video embed">%s%s</div>', |
|
| 47 | - $this->renderScreenshot(), |
|
| 48 | - $this->video->html |
|
| 49 | - ); |
|
| 50 | - } |
|
| 40 | + public function render() |
|
| 41 | + { |
|
| 42 | + if (!isset($this->video->html)) { |
|
| 43 | + return; |
|
| 44 | + } |
|
| 45 | + return sprintf( |
|
| 46 | + '<div class="video embed">%s%s</div>', |
|
| 47 | + $this->renderScreenshot(), |
|
| 48 | + $this->video->html |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function renderPlayButton() |
|
| 53 | - { |
|
| 54 | - return sprintf( |
|
| 55 | - '<div class="video-play">'. |
|
| 56 | - '<div class="video-play-pulse pulse1"></div>'. |
|
| 57 | - '<div class="video-play-pulse pulse2"></div>'. |
|
| 58 | - '<div class="video-play-pulse pulse3"></div>'. |
|
| 59 | - '<a href="%s" class="video-play-btn">%s</a>'. |
|
| 60 | - '</div>', |
|
| 61 | - $this->args['url'], |
|
| 62 | - $this->theme->svg('play.svg') |
|
| 63 | - ); |
|
| 64 | - } |
|
| 52 | + public function renderPlayButton() |
|
| 53 | + { |
|
| 54 | + return sprintf( |
|
| 55 | + '<div class="video-play">'. |
|
| 56 | + '<div class="video-play-pulse pulse1"></div>'. |
|
| 57 | + '<div class="video-play-pulse pulse2"></div>'. |
|
| 58 | + '<div class="video-play-pulse pulse3"></div>'. |
|
| 59 | + '<a href="%s" class="video-play-btn">%s</a>'. |
|
| 60 | + '</div>', |
|
| 61 | + $this->args['url'], |
|
| 62 | + $this->theme->svg('play.svg') |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function renderScreenshot() |
|
| 67 | - { |
|
| 68 | - if ($this->args['image'] |
|
| 69 | - && in_array(strtolower($this->video->provider_name), $this->supported)) { |
|
| 70 | - return sprintf('%s<div class="video-poster" style="background-image: url(%s)">%s</div>', |
|
| 71 | - $this->renderSpinner(), |
|
| 72 | - $this->args['image'], |
|
| 73 | - $this->renderPlayButton() |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 66 | + public function renderScreenshot() |
|
| 67 | + { |
|
| 68 | + if ($this->args['image'] |
|
| 69 | + && in_array(strtolower($this->video->provider_name), $this->supported)) { |
|
| 70 | + return sprintf('%s<div class="video-poster" style="background-image: url(%s)">%s</div>', |
|
| 71 | + $this->renderSpinner(), |
|
| 72 | + $this->args['image'], |
|
| 73 | + $this->renderPlayButton() |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function renderSpinner() |
|
| 79 | - { |
|
| 80 | - return sprintf( |
|
| 81 | - '<div class="video-spinner">'. |
|
| 82 | - '<div class="spinner"><div class="spinner-dots">%s</div></div>'. |
|
| 83 | - '</div>', |
|
| 84 | - implode('', array_fill(0, 8, '<div class="spinner-dot"></div>')) |
|
| 85 | - ); |
|
| 86 | - } |
|
| 78 | + public function renderSpinner() |
|
| 79 | + { |
|
| 80 | + return sprintf( |
|
| 81 | + '<div class="video-spinner">'. |
|
| 82 | + '<div class="spinner"><div class="spinner-dots">%s</div></div>'. |
|
| 83 | + '</div>', |
|
| 84 | + implode('', array_fill(0, 8, '<div class="spinner-dot"></div>')) |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - protected function setImage($image) |
|
| 89 | - { |
|
| 90 | - $image = $this->image->get($image)->image; |
|
| 91 | - $this->args['image'] = isset($image->large) |
|
| 92 | - ? $image->large['url'] |
|
| 93 | - : null; |
|
| 94 | - } |
|
| 88 | + protected function setImage($image) |
|
| 89 | + { |
|
| 90 | + $image = $this->image->get($image)->image; |
|
| 91 | + $this->args['image'] = isset($image->large) |
|
| 92 | + ? $image->large['url'] |
|
| 93 | + : null; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - protected function setUrl($url) |
|
| 97 | - { |
|
| 98 | - $this->args['url'] = !filter_var($url, FILTER_VALIDATE_URL) |
|
| 99 | - ? $this->postmeta->get($url) |
|
| 100 | - : $url; |
|
| 101 | - } |
|
| 96 | + protected function setUrl($url) |
|
| 97 | + { |
|
| 98 | + $this->args['url'] = !filter_var($url, FILTER_VALIDATE_URL) |
|
| 99 | + ? $this->postmeta->get($url) |
|
| 100 | + : $url; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - protected function normalize($args) |
|
| 104 | - { |
|
| 105 | - if (is_string($args)) { |
|
| 106 | - $args = ['url' => $args]; |
|
| 107 | - } |
|
| 103 | + protected function normalize($args) |
|
| 104 | + { |
|
| 105 | + if (is_string($args)) { |
|
| 106 | + $args = ['url' => $args]; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - $this->args = shortcode_atts([ |
|
| 110 | - 'image' => '', // string || int |
|
| 111 | - 'player' => '', // string || array |
|
| 112 | - 'url' => '', // string |
|
| 113 | - ], $args); |
|
| 109 | + $this->args = shortcode_atts([ |
|
| 110 | + 'image' => '', // string || int |
|
| 111 | + 'player' => '', // string || array |
|
| 112 | + 'url' => '', // string |
|
| 113 | + ], $args); |
|
| 114 | 114 | |
| 115 | - foreach ($this->args as $key => $value) { |
|
| 116 | - $method = $this->utility->buildMethodName($key, 'set'); |
|
| 117 | - if (!method_exists($this, $method)) { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - call_user_func([$this, $method], $value); |
|
| 121 | - } |
|
| 122 | - return $this->args; |
|
| 123 | - } |
|
| 115 | + foreach ($this->args as $key => $value) { |
|
| 116 | + $method = $this->utility->buildMethodName($key, 'set'); |
|
| 117 | + if (!method_exists($this, $method)) { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + call_user_func([$this, $method], $value); |
|
| 121 | + } |
|
| 122 | + return $this->args; |
|
| 123 | + } |
|
| 124 | 124 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | protected $theme; |
| 19 | 19 | protected $utility; |
| 20 | 20 | |
| 21 | - public function __construct(Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
| 21 | + public function __construct( Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility ) |
|
| 22 | 22 | { |
| 23 | 23 | $this->image = $image; |
| 24 | 24 | $this->oembed = $oembed; |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | $this->utility = $utility; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function get($args = []) |
|
| 30 | + public function get( $args = [] ) |
|
| 31 | 31 | { |
| 32 | - $args = $this->normalize($args); |
|
| 33 | - $embed = $this->oembed->request($args['url'], $args['player']); |
|
| 34 | - if (isset($embed->type) && 'video' == $embed->type) { |
|
| 32 | + $args = $this->normalize( $args ); |
|
| 33 | + $embed = $this->oembed->request( $args['url'], $args['player'] ); |
|
| 34 | + if( isset( $embed->type ) && 'video' == $embed->type ) { |
|
| 35 | 35 | $this->video = $embed; |
| 36 | 36 | } |
| 37 | 37 | return $this; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | public function render() |
| 41 | 41 | { |
| 42 | - if (!isset($this->video->html)) { |
|
| 42 | + if( !isset( $this->video->html ) ) { |
|
| 43 | 43 | return; |
| 44 | 44 | } |
| 45 | 45 | return sprintf( |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | '<a href="%s" class="video-play-btn">%s</a>'. |
| 60 | 60 | '</div>', |
| 61 | 61 | $this->args['url'], |
| 62 | - $this->theme->svg('play.svg') |
|
| 62 | + $this->theme->svg( 'play.svg' ) |
|
| 63 | 63 | ); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | public function renderScreenshot() |
| 67 | 67 | { |
| 68 | - if ($this->args['image'] |
|
| 69 | - && in_array(strtolower($this->video->provider_name), $this->supported)) { |
|
| 70 | - return sprintf('%s<div class="video-poster" style="background-image: url(%s)">%s</div>', |
|
| 68 | + if( $this->args['image'] |
|
| 69 | + && in_array( strtolower( $this->video->provider_name ), $this->supported ) ) { |
|
| 70 | + return sprintf( '%s<div class="video-poster" style="background-image: url(%s)">%s</div>', |
|
| 71 | 71 | $this->renderSpinner(), |
| 72 | 72 | $this->args['image'], |
| 73 | 73 | $this->renderPlayButton() |
@@ -81,43 +81,43 @@ discard block |
||
| 81 | 81 | '<div class="video-spinner">'. |
| 82 | 82 | '<div class="spinner"><div class="spinner-dots">%s</div></div>'. |
| 83 | 83 | '</div>', |
| 84 | - implode('', array_fill(0, 8, '<div class="spinner-dot"></div>')) |
|
| 84 | + implode( '', array_fill( 0, 8, '<div class="spinner-dot"></div>' ) ) |
|
| 85 | 85 | ); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - protected function setImage($image) |
|
| 88 | + protected function setImage( $image ) |
|
| 89 | 89 | { |
| 90 | - $image = $this->image->get($image)->image; |
|
| 91 | - $this->args['image'] = isset($image->large) |
|
| 90 | + $image = $this->image->get( $image )->image; |
|
| 91 | + $this->args['image'] = isset( $image->large ) |
|
| 92 | 92 | ? $image->large['url'] |
| 93 | 93 | : null; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - protected function setUrl($url) |
|
| 96 | + protected function setUrl( $url ) |
|
| 97 | 97 | { |
| 98 | - $this->args['url'] = !filter_var($url, FILTER_VALIDATE_URL) |
|
| 99 | - ? $this->postmeta->get($url) |
|
| 98 | + $this->args['url'] = !filter_var( $url, FILTER_VALIDATE_URL ) |
|
| 99 | + ? $this->postmeta->get( $url ) |
|
| 100 | 100 | : $url; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - protected function normalize($args) |
|
| 103 | + protected function normalize( $args ) |
|
| 104 | 104 | { |
| 105 | - if (is_string($args)) { |
|
| 105 | + if( is_string( $args ) ) { |
|
| 106 | 106 | $args = ['url' => $args]; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - $this->args = shortcode_atts([ |
|
| 109 | + $this->args = shortcode_atts( [ |
|
| 110 | 110 | 'image' => '', // string || int |
| 111 | 111 | 'player' => '', // string || array |
| 112 | 112 | 'url' => '', // string |
| 113 | - ], $args); |
|
| 113 | + ], $args ); |
|
| 114 | 114 | |
| 115 | - foreach ($this->args as $key => $value) { |
|
| 116 | - $method = $this->utility->buildMethodName($key, 'set'); |
|
| 117 | - if (!method_exists($this, $method)) { |
|
| 115 | + foreach( $this->args as $key => $value ) { |
|
| 116 | + $method = $this->utility->buildMethodName( $key, 'set' ); |
|
| 117 | + if( !method_exists( $this, $method ) ) { |
|
| 118 | 118 | continue; |
| 119 | 119 | } |
| 120 | - call_user_func([$this, $method], $value); |
|
| 120 | + call_user_func( [$this, $method], $value ); |
|
| 121 | 121 | } |
| 122 | 122 | return $this->args; |
| 123 | 123 | } |
@@ -6,8 +6,7 @@ |
||
| 6 | 6 | use GeminiLabs\Castor\Helpers\Theme; |
| 7 | 7 | use GeminiLabs\Castor\Helpers\Utility; |
| 8 | 8 | |
| 9 | -class Video |
|
| 10 | -{ |
|
| 9 | +class Video { |
|
| 11 | 10 | public $video; |
| 12 | 11 | |
| 13 | 12 | protected $args; |
@@ -8,8 +8,7 @@ |
||
| 8 | 8 | use GeminiLabs\Castor\Facades\Utility; |
| 9 | 9 | use WP_Customize_Manager; |
| 10 | 10 | |
| 11 | -class Controller |
|
| 12 | -{ |
|
| 11 | +class Controller { |
|
| 13 | 12 | /** |
| 14 | 13 | * @return void |
| 15 | 14 | * @action after_setup_theme |
@@ -10,211 +10,211 @@ |
||
| 10 | 10 | |
| 11 | 11 | class Controller |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @return void |
|
| 15 | - * @action after_setup_theme |
|
| 16 | - */ |
|
| 17 | - public function afterSetupTheme() |
|
| 18 | - { |
|
| 19 | - castor_app()->cssDir = trailingslashit((string) apply_filters('castor/assets/styles/dir', 'css')); |
|
| 20 | - castor_app()->imgDir = trailingslashit((string) apply_filters('castor/assets/images/dir', 'img')); |
|
| 21 | - castor_app()->jsDir = trailingslashit((string) apply_filters('castor/assets/scripts/dir', 'js')); |
|
| 22 | - |
|
| 23 | - add_editor_style(Theme::assetUri(castor_app()->cssDir.'editor.css')); |
|
| 24 | - add_theme_support('customize-selective-refresh-widgets'); |
|
| 25 | - add_theme_support('html5', ['caption', 'comment-form', 'comment-list', 'gallery', 'search-form']); |
|
| 26 | - add_theme_support('post-thumbnails'); |
|
| 27 | - add_theme_support('soil-clean-up'); |
|
| 28 | - add_theme_support('soil-jquery-cdn'); |
|
| 29 | - add_theme_support('soil-nav-walker'); |
|
| 30 | - add_theme_support('soil-nice-search'); |
|
| 31 | - add_theme_support('soil-relative-urls'); |
|
| 32 | - add_theme_support('title-tag'); |
|
| 33 | - load_theme_textdomain('castor', Theme::paths('dir.template').'/languages'); |
|
| 34 | - |
|
| 35 | - $menus = apply_filters('castor/register/nav_menus', [ |
|
| 36 | - 'main_menu' => __('Main Menu', 'castor'), |
|
| 37 | - ]); |
|
| 38 | - |
|
| 39 | - foreach ($menus as $location => $description) { |
|
| 40 | - register_nav_menu($location, $description); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @return array |
|
| 46 | - * @filter body_class |
|
| 47 | - */ |
|
| 48 | - public function filterBodyClasses(array $classes) |
|
| 49 | - { |
|
| 50 | - if (Theme::displaySidebar()) { |
|
| 51 | - $classes[] = 'has-sidebar'; |
|
| 52 | - } |
|
| 53 | - return array_keys(array_flip($classes)); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return string |
|
| 58 | - * @filter login_headertext |
|
| 59 | - */ |
|
| 60 | - public function filterLoginTitle() |
|
| 61 | - { |
|
| 62 | - return get_bloginfo('name'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return string |
|
| 67 | - * @filter login_headerurl |
|
| 68 | - */ |
|
| 69 | - public function filterLoginUrl() |
|
| 70 | - { |
|
| 71 | - return get_bloginfo('url'); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return string |
|
| 76 | - * @filter template_include |
|
| 77 | - */ |
|
| 78 | - public function filterTemplate($template) |
|
| 79 | - { |
|
| 80 | - if (is_string($template)) { |
|
| 81 | - $template = Template::setLayout($template); |
|
| 82 | - Development::storeTemplatePath($template); |
|
| 83 | - } |
|
| 84 | - return $template; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @return array |
|
| 89 | - * @filter {$type}_template_hierarchy |
|
| 90 | - */ |
|
| 91 | - public function filterTemplateHierarchy(array $templates) |
|
| 92 | - { |
|
| 93 | - return array_map(function ($template) { |
|
| 94 | - return Utility::startWith('templates/', $template); |
|
| 95 | - }, $templates); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return void |
|
| 100 | - * @action admin_head |
|
| 101 | - * @action login_head |
|
| 102 | - */ |
|
| 103 | - public function loadAdminFavicon() |
|
| 104 | - { |
|
| 105 | - if (file_exists(Theme::assetPath('favicon/favicon-admin.ico'))) { |
|
| 106 | - printf('<link rel="shortcut icon" href="%s">', Theme::assetUri('favicon/favicon-admin.ico')); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @return void |
|
| 112 | - * @action login_head |
|
| 113 | - */ |
|
| 114 | - public function login() |
|
| 115 | - { |
|
| 116 | - if (file_exists(Theme::assetPath(castor_app()->cssDir.'login.css'))) { |
|
| 117 | - printf('<link rel="stylesheet" href="%s">', Theme::assetUri(castor_app()->cssDir.'login.css')); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return void |
|
| 123 | - * @action admin_enqueue_scripts |
|
| 124 | - */ |
|
| 125 | - public function registerAdminAssets() |
|
| 126 | - { |
|
| 127 | - if (file_exists(Theme::assetPath(castor_app()->cssDir.'admin.css'))) { |
|
| 128 | - wp_enqueue_style('castor/admin.css', |
|
| 129 | - Theme::assetUri(castor_app()->cssDir.'admin.css'), |
|
| 130 | - apply_filters('castor/enqueue/admin/css/deps', []), |
|
| 131 | - CASTOR_FRAMEWORK_VERSION |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - if (file_exists(Theme::assetPath(castor_app()->jsDir.'admin.js'))) { |
|
| 135 | - wp_enqueue_script('castor/admin.js', |
|
| 136 | - Theme::assetUri(castor_app()->jsDir.'admin.js'), |
|
| 137 | - apply_filters('castor/enqueue/admin/js/deps', []), |
|
| 138 | - CASTOR_FRAMEWORK_VERSION, |
|
| 139 | - true |
|
| 140 | - ); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return void |
|
| 146 | - * @action wp_enqueue_scripts |
|
| 147 | - */ |
|
| 148 | - public function registerAssets() |
|
| 149 | - { |
|
| 150 | - wp_register_style('castor/main.css', |
|
| 151 | - Theme::assetUri(castor_app()->cssDir.'main.css'), |
|
| 152 | - apply_filters('castor/enqueue/css/deps', []), |
|
| 153 | - CASTOR_FRAMEWORK_VERSION |
|
| 154 | - ); |
|
| 155 | - wp_register_script('castor/main.js', |
|
| 156 | - Theme::assetUri(castor_app()->jsDir.'main.js'), |
|
| 157 | - apply_filters('castor/enqueue/js/deps', []), |
|
| 158 | - CASTOR_FRAMEWORK_VERSION, |
|
| 159 | - true |
|
| 160 | - ); |
|
| 161 | - wp_localize_script('castor/main.js', apply_filters('castor/enqueue/js/localize/variable', 'globals'), |
|
| 162 | - apply_filters('castor/enqueue/js/localize/variables', [ |
|
| 163 | - 'ajax' => admin_url('admin-ajax.php'), |
|
| 164 | - ]) |
|
| 165 | - ); |
|
| 166 | - do_action('castor/register/assets'); |
|
| 167 | - wp_enqueue_style('castor/main.css'); |
|
| 168 | - wp_enqueue_script('castor/main.js'); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @return void |
|
| 173 | - * @action customize_register |
|
| 174 | - */ |
|
| 175 | - public function registerCustomizer(WP_Customize_Manager $manager) |
|
| 176 | - { |
|
| 177 | - $manager->get_setting('blogname')->transport = 'postMessage'; |
|
| 178 | - $manager->selective_refresh->add_partial('blogname', [ |
|
| 179 | - 'selector' => '.brand', |
|
| 180 | - 'render_callback' => function () { |
|
| 181 | - bloginfo('name'); |
|
| 182 | - }, |
|
| 183 | - ]); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return void |
|
| 188 | - * @action customize_preview_init |
|
| 189 | - */ |
|
| 190 | - public function registerCustomizerAssets() |
|
| 191 | - { |
|
| 192 | - wp_enqueue_script('castor/customizer.js', Theme::assetUri(castor_app()->jsDir.'customizer.js'), ['customize-preview'], CASTOR_FRAMEWORK_VERSION, true); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @return void |
|
| 197 | - * @action widgets_init |
|
| 198 | - */ |
|
| 199 | - public function registerSidebars() |
|
| 200 | - { |
|
| 201 | - $defaults = apply_filters('castor/register/sidebars/defaults', [ |
|
| 202 | - 'before_widget' => '<div class="widget %1$s %2$s">', |
|
| 203 | - 'after_widget' => '</div>', |
|
| 204 | - 'before_title' => '<h4>', |
|
| 205 | - 'after_title' => '</h4>', |
|
| 206 | - ]); |
|
| 207 | - |
|
| 208 | - $sidebars = apply_filters('castor/register/sidebars', [ |
|
| 209 | - 'sidebar-primary' => __('Primary Sidebar', 'castor'), |
|
| 210 | - 'sidebar-footer' => __('Footer Widgets', 'castor'), |
|
| 211 | - ]); |
|
| 212 | - |
|
| 213 | - foreach ($sidebars as $id => $name) { |
|
| 214 | - register_sidebar([ |
|
| 215 | - 'id' => $id, |
|
| 216 | - 'name' => $name, |
|
| 217 | - ] + $defaults); |
|
| 218 | - } |
|
| 219 | - } |
|
| 13 | + /** |
|
| 14 | + * @return void |
|
| 15 | + * @action after_setup_theme |
|
| 16 | + */ |
|
| 17 | + public function afterSetupTheme() |
|
| 18 | + { |
|
| 19 | + castor_app()->cssDir = trailingslashit((string) apply_filters('castor/assets/styles/dir', 'css')); |
|
| 20 | + castor_app()->imgDir = trailingslashit((string) apply_filters('castor/assets/images/dir', 'img')); |
|
| 21 | + castor_app()->jsDir = trailingslashit((string) apply_filters('castor/assets/scripts/dir', 'js')); |
|
| 22 | + |
|
| 23 | + add_editor_style(Theme::assetUri(castor_app()->cssDir.'editor.css')); |
|
| 24 | + add_theme_support('customize-selective-refresh-widgets'); |
|
| 25 | + add_theme_support('html5', ['caption', 'comment-form', 'comment-list', 'gallery', 'search-form']); |
|
| 26 | + add_theme_support('post-thumbnails'); |
|
| 27 | + add_theme_support('soil-clean-up'); |
|
| 28 | + add_theme_support('soil-jquery-cdn'); |
|
| 29 | + add_theme_support('soil-nav-walker'); |
|
| 30 | + add_theme_support('soil-nice-search'); |
|
| 31 | + add_theme_support('soil-relative-urls'); |
|
| 32 | + add_theme_support('title-tag'); |
|
| 33 | + load_theme_textdomain('castor', Theme::paths('dir.template').'/languages'); |
|
| 34 | + |
|
| 35 | + $menus = apply_filters('castor/register/nav_menus', [ |
|
| 36 | + 'main_menu' => __('Main Menu', 'castor'), |
|
| 37 | + ]); |
|
| 38 | + |
|
| 39 | + foreach ($menus as $location => $description) { |
|
| 40 | + register_nav_menu($location, $description); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @return array |
|
| 46 | + * @filter body_class |
|
| 47 | + */ |
|
| 48 | + public function filterBodyClasses(array $classes) |
|
| 49 | + { |
|
| 50 | + if (Theme::displaySidebar()) { |
|
| 51 | + $classes[] = 'has-sidebar'; |
|
| 52 | + } |
|
| 53 | + return array_keys(array_flip($classes)); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return string |
|
| 58 | + * @filter login_headertext |
|
| 59 | + */ |
|
| 60 | + public function filterLoginTitle() |
|
| 61 | + { |
|
| 62 | + return get_bloginfo('name'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return string |
|
| 67 | + * @filter login_headerurl |
|
| 68 | + */ |
|
| 69 | + public function filterLoginUrl() |
|
| 70 | + { |
|
| 71 | + return get_bloginfo('url'); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return string |
|
| 76 | + * @filter template_include |
|
| 77 | + */ |
|
| 78 | + public function filterTemplate($template) |
|
| 79 | + { |
|
| 80 | + if (is_string($template)) { |
|
| 81 | + $template = Template::setLayout($template); |
|
| 82 | + Development::storeTemplatePath($template); |
|
| 83 | + } |
|
| 84 | + return $template; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @return array |
|
| 89 | + * @filter {$type}_template_hierarchy |
|
| 90 | + */ |
|
| 91 | + public function filterTemplateHierarchy(array $templates) |
|
| 92 | + { |
|
| 93 | + return array_map(function ($template) { |
|
| 94 | + return Utility::startWith('templates/', $template); |
|
| 95 | + }, $templates); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return void |
|
| 100 | + * @action admin_head |
|
| 101 | + * @action login_head |
|
| 102 | + */ |
|
| 103 | + public function loadAdminFavicon() |
|
| 104 | + { |
|
| 105 | + if (file_exists(Theme::assetPath('favicon/favicon-admin.ico'))) { |
|
| 106 | + printf('<link rel="shortcut icon" href="%s">', Theme::assetUri('favicon/favicon-admin.ico')); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @return void |
|
| 112 | + * @action login_head |
|
| 113 | + */ |
|
| 114 | + public function login() |
|
| 115 | + { |
|
| 116 | + if (file_exists(Theme::assetPath(castor_app()->cssDir.'login.css'))) { |
|
| 117 | + printf('<link rel="stylesheet" href="%s">', Theme::assetUri(castor_app()->cssDir.'login.css')); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return void |
|
| 123 | + * @action admin_enqueue_scripts |
|
| 124 | + */ |
|
| 125 | + public function registerAdminAssets() |
|
| 126 | + { |
|
| 127 | + if (file_exists(Theme::assetPath(castor_app()->cssDir.'admin.css'))) { |
|
| 128 | + wp_enqueue_style('castor/admin.css', |
|
| 129 | + Theme::assetUri(castor_app()->cssDir.'admin.css'), |
|
| 130 | + apply_filters('castor/enqueue/admin/css/deps', []), |
|
| 131 | + CASTOR_FRAMEWORK_VERSION |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + if (file_exists(Theme::assetPath(castor_app()->jsDir.'admin.js'))) { |
|
| 135 | + wp_enqueue_script('castor/admin.js', |
|
| 136 | + Theme::assetUri(castor_app()->jsDir.'admin.js'), |
|
| 137 | + apply_filters('castor/enqueue/admin/js/deps', []), |
|
| 138 | + CASTOR_FRAMEWORK_VERSION, |
|
| 139 | + true |
|
| 140 | + ); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return void |
|
| 146 | + * @action wp_enqueue_scripts |
|
| 147 | + */ |
|
| 148 | + public function registerAssets() |
|
| 149 | + { |
|
| 150 | + wp_register_style('castor/main.css', |
|
| 151 | + Theme::assetUri(castor_app()->cssDir.'main.css'), |
|
| 152 | + apply_filters('castor/enqueue/css/deps', []), |
|
| 153 | + CASTOR_FRAMEWORK_VERSION |
|
| 154 | + ); |
|
| 155 | + wp_register_script('castor/main.js', |
|
| 156 | + Theme::assetUri(castor_app()->jsDir.'main.js'), |
|
| 157 | + apply_filters('castor/enqueue/js/deps', []), |
|
| 158 | + CASTOR_FRAMEWORK_VERSION, |
|
| 159 | + true |
|
| 160 | + ); |
|
| 161 | + wp_localize_script('castor/main.js', apply_filters('castor/enqueue/js/localize/variable', 'globals'), |
|
| 162 | + apply_filters('castor/enqueue/js/localize/variables', [ |
|
| 163 | + 'ajax' => admin_url('admin-ajax.php'), |
|
| 164 | + ]) |
|
| 165 | + ); |
|
| 166 | + do_action('castor/register/assets'); |
|
| 167 | + wp_enqueue_style('castor/main.css'); |
|
| 168 | + wp_enqueue_script('castor/main.js'); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @return void |
|
| 173 | + * @action customize_register |
|
| 174 | + */ |
|
| 175 | + public function registerCustomizer(WP_Customize_Manager $manager) |
|
| 176 | + { |
|
| 177 | + $manager->get_setting('blogname')->transport = 'postMessage'; |
|
| 178 | + $manager->selective_refresh->add_partial('blogname', [ |
|
| 179 | + 'selector' => '.brand', |
|
| 180 | + 'render_callback' => function () { |
|
| 181 | + bloginfo('name'); |
|
| 182 | + }, |
|
| 183 | + ]); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return void |
|
| 188 | + * @action customize_preview_init |
|
| 189 | + */ |
|
| 190 | + public function registerCustomizerAssets() |
|
| 191 | + { |
|
| 192 | + wp_enqueue_script('castor/customizer.js', Theme::assetUri(castor_app()->jsDir.'customizer.js'), ['customize-preview'], CASTOR_FRAMEWORK_VERSION, true); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @return void |
|
| 197 | + * @action widgets_init |
|
| 198 | + */ |
|
| 199 | + public function registerSidebars() |
|
| 200 | + { |
|
| 201 | + $defaults = apply_filters('castor/register/sidebars/defaults', [ |
|
| 202 | + 'before_widget' => '<div class="widget %1$s %2$s">', |
|
| 203 | + 'after_widget' => '</div>', |
|
| 204 | + 'before_title' => '<h4>', |
|
| 205 | + 'after_title' => '</h4>', |
|
| 206 | + ]); |
|
| 207 | + |
|
| 208 | + $sidebars = apply_filters('castor/register/sidebars', [ |
|
| 209 | + 'sidebar-primary' => __('Primary Sidebar', 'castor'), |
|
| 210 | + 'sidebar-footer' => __('Footer Widgets', 'castor'), |
|
| 211 | + ]); |
|
| 212 | + |
|
| 213 | + foreach ($sidebars as $id => $name) { |
|
| 214 | + register_sidebar([ |
|
| 215 | + 'id' => $id, |
|
| 216 | + 'name' => $name, |
|
| 217 | + ] + $defaults); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | 220 | } |
@@ -16,28 +16,28 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | public function afterSetupTheme() |
| 18 | 18 | { |
| 19 | - castor_app()->cssDir = trailingslashit((string) apply_filters('castor/assets/styles/dir', 'css')); |
|
| 20 | - castor_app()->imgDir = trailingslashit((string) apply_filters('castor/assets/images/dir', 'img')); |
|
| 21 | - castor_app()->jsDir = trailingslashit((string) apply_filters('castor/assets/scripts/dir', 'js')); |
|
| 22 | - |
|
| 23 | - add_editor_style(Theme::assetUri(castor_app()->cssDir.'editor.css')); |
|
| 24 | - add_theme_support('customize-selective-refresh-widgets'); |
|
| 25 | - add_theme_support('html5', ['caption', 'comment-form', 'comment-list', 'gallery', 'search-form']); |
|
| 26 | - add_theme_support('post-thumbnails'); |
|
| 27 | - add_theme_support('soil-clean-up'); |
|
| 28 | - add_theme_support('soil-jquery-cdn'); |
|
| 29 | - add_theme_support('soil-nav-walker'); |
|
| 30 | - add_theme_support('soil-nice-search'); |
|
| 31 | - add_theme_support('soil-relative-urls'); |
|
| 32 | - add_theme_support('title-tag'); |
|
| 33 | - load_theme_textdomain('castor', Theme::paths('dir.template').'/languages'); |
|
| 34 | - |
|
| 35 | - $menus = apply_filters('castor/register/nav_menus', [ |
|
| 36 | - 'main_menu' => __('Main Menu', 'castor'), |
|
| 37 | - ]); |
|
| 38 | - |
|
| 39 | - foreach ($menus as $location => $description) { |
|
| 40 | - register_nav_menu($location, $description); |
|
| 19 | + castor_app()->cssDir = trailingslashit( (string) apply_filters( 'castor/assets/styles/dir', 'css' ) ); |
|
| 20 | + castor_app()->imgDir = trailingslashit( (string) apply_filters( 'castor/assets/images/dir', 'img' ) ); |
|
| 21 | + castor_app()->jsDir = trailingslashit( (string) apply_filters( 'castor/assets/scripts/dir', 'js' ) ); |
|
| 22 | + |
|
| 23 | + add_editor_style( Theme::assetUri( castor_app()->cssDir.'editor.css' ) ); |
|
| 24 | + add_theme_support( 'customize-selective-refresh-widgets' ); |
|
| 25 | + add_theme_support( 'html5', ['caption', 'comment-form', 'comment-list', 'gallery', 'search-form'] ); |
|
| 26 | + add_theme_support( 'post-thumbnails' ); |
|
| 27 | + add_theme_support( 'soil-clean-up' ); |
|
| 28 | + add_theme_support( 'soil-jquery-cdn' ); |
|
| 29 | + add_theme_support( 'soil-nav-walker' ); |
|
| 30 | + add_theme_support( 'soil-nice-search' ); |
|
| 31 | + add_theme_support( 'soil-relative-urls' ); |
|
| 32 | + add_theme_support( 'title-tag' ); |
|
| 33 | + load_theme_textdomain( 'castor', Theme::paths( 'dir.template' ).'/languages' ); |
|
| 34 | + |
|
| 35 | + $menus = apply_filters( 'castor/register/nav_menus', [ |
|
| 36 | + 'main_menu' => __( 'Main Menu', 'castor' ), |
|
| 37 | + ] ); |
|
| 38 | + |
|
| 39 | + foreach( $menus as $location => $description ) { |
|
| 40 | + register_nav_menu( $location, $description ); |
|
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | * @return array |
| 46 | 46 | * @filter body_class |
| 47 | 47 | */ |
| 48 | - public function filterBodyClasses(array $classes) |
|
| 48 | + public function filterBodyClasses( array $classes ) |
|
| 49 | 49 | { |
| 50 | - if (Theme::displaySidebar()) { |
|
| 50 | + if( Theme::displaySidebar() ) { |
|
| 51 | 51 | $classes[] = 'has-sidebar'; |
| 52 | 52 | } |
| 53 | - return array_keys(array_flip($classes)); |
|
| 53 | + return array_keys( array_flip( $classes ) ); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function filterLoginTitle() |
| 61 | 61 | { |
| 62 | - return get_bloginfo('name'); |
|
| 62 | + return get_bloginfo( 'name' ); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -68,18 +68,18 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function filterLoginUrl() |
| 70 | 70 | { |
| 71 | - return get_bloginfo('url'); |
|
| 71 | + return get_bloginfo( 'url' ); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * @return string |
| 76 | 76 | * @filter template_include |
| 77 | 77 | */ |
| 78 | - public function filterTemplate($template) |
|
| 78 | + public function filterTemplate( $template ) |
|
| 79 | 79 | { |
| 80 | - if (is_string($template)) { |
|
| 81 | - $template = Template::setLayout($template); |
|
| 82 | - Development::storeTemplatePath($template); |
|
| 80 | + if( is_string( $template ) ) { |
|
| 81 | + $template = Template::setLayout( $template ); |
|
| 82 | + Development::storeTemplatePath( $template ); |
|
| 83 | 83 | } |
| 84 | 84 | return $template; |
| 85 | 85 | } |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | * @return array |
| 89 | 89 | * @filter {$type}_template_hierarchy |
| 90 | 90 | */ |
| 91 | - public function filterTemplateHierarchy(array $templates) |
|
| 91 | + public function filterTemplateHierarchy( array $templates ) |
|
| 92 | 92 | { |
| 93 | - return array_map(function ($template) { |
|
| 94 | - return Utility::startWith('templates/', $template); |
|
| 95 | - }, $templates); |
|
| 93 | + return array_map( function( $template ) { |
|
| 94 | + return Utility::startWith( 'templates/', $template ); |
|
| 95 | + }, $templates ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function loadAdminFavicon() |
| 104 | 104 | { |
| 105 | - if (file_exists(Theme::assetPath('favicon/favicon-admin.ico'))) { |
|
| 106 | - printf('<link rel="shortcut icon" href="%s">', Theme::assetUri('favicon/favicon-admin.ico')); |
|
| 105 | + if( file_exists( Theme::assetPath( 'favicon/favicon-admin.ico' ) ) ) { |
|
| 106 | + printf( '<link rel="shortcut icon" href="%s">', Theme::assetUri( 'favicon/favicon-admin.ico' ) ); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function login() |
| 115 | 115 | { |
| 116 | - if (file_exists(Theme::assetPath(castor_app()->cssDir.'login.css'))) { |
|
| 117 | - printf('<link rel="stylesheet" href="%s">', Theme::assetUri(castor_app()->cssDir.'login.css')); |
|
| 116 | + if( file_exists( Theme::assetPath( castor_app()->cssDir.'login.css' ) ) ) { |
|
| 117 | + printf( '<link rel="stylesheet" href="%s">', Theme::assetUri( castor_app()->cssDir.'login.css' ) ); |
|
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
@@ -124,17 +124,17 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public function registerAdminAssets() |
| 126 | 126 | { |
| 127 | - if (file_exists(Theme::assetPath(castor_app()->cssDir.'admin.css'))) { |
|
| 128 | - wp_enqueue_style('castor/admin.css', |
|
| 129 | - Theme::assetUri(castor_app()->cssDir.'admin.css'), |
|
| 130 | - apply_filters('castor/enqueue/admin/css/deps', []), |
|
| 127 | + if( file_exists( Theme::assetPath( castor_app()->cssDir.'admin.css' ) ) ) { |
|
| 128 | + wp_enqueue_style( 'castor/admin.css', |
|
| 129 | + Theme::assetUri( castor_app()->cssDir.'admin.css' ), |
|
| 130 | + apply_filters( 'castor/enqueue/admin/css/deps', [] ), |
|
| 131 | 131 | CASTOR_FRAMEWORK_VERSION |
| 132 | 132 | ); |
| 133 | 133 | } |
| 134 | - if (file_exists(Theme::assetPath(castor_app()->jsDir.'admin.js'))) { |
|
| 135 | - wp_enqueue_script('castor/admin.js', |
|
| 136 | - Theme::assetUri(castor_app()->jsDir.'admin.js'), |
|
| 137 | - apply_filters('castor/enqueue/admin/js/deps', []), |
|
| 134 | + if( file_exists( Theme::assetPath( castor_app()->jsDir.'admin.js' ) ) ) { |
|
| 135 | + wp_enqueue_script( 'castor/admin.js', |
|
| 136 | + Theme::assetUri( castor_app()->jsDir.'admin.js' ), |
|
| 137 | + apply_filters( 'castor/enqueue/admin/js/deps', [] ), |
|
| 138 | 138 | CASTOR_FRAMEWORK_VERSION, |
| 139 | 139 | true |
| 140 | 140 | ); |
@@ -147,40 +147,40 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function registerAssets() |
| 149 | 149 | { |
| 150 | - wp_register_style('castor/main.css', |
|
| 151 | - Theme::assetUri(castor_app()->cssDir.'main.css'), |
|
| 152 | - apply_filters('castor/enqueue/css/deps', []), |
|
| 150 | + wp_register_style( 'castor/main.css', |
|
| 151 | + Theme::assetUri( castor_app()->cssDir.'main.css' ), |
|
| 152 | + apply_filters( 'castor/enqueue/css/deps', [] ), |
|
| 153 | 153 | CASTOR_FRAMEWORK_VERSION |
| 154 | 154 | ); |
| 155 | - wp_register_script('castor/main.js', |
|
| 156 | - Theme::assetUri(castor_app()->jsDir.'main.js'), |
|
| 157 | - apply_filters('castor/enqueue/js/deps', []), |
|
| 155 | + wp_register_script( 'castor/main.js', |
|
| 156 | + Theme::assetUri( castor_app()->jsDir.'main.js' ), |
|
| 157 | + apply_filters( 'castor/enqueue/js/deps', [] ), |
|
| 158 | 158 | CASTOR_FRAMEWORK_VERSION, |
| 159 | 159 | true |
| 160 | 160 | ); |
| 161 | - wp_localize_script('castor/main.js', apply_filters('castor/enqueue/js/localize/variable', 'globals'), |
|
| 162 | - apply_filters('castor/enqueue/js/localize/variables', [ |
|
| 163 | - 'ajax' => admin_url('admin-ajax.php'), |
|
| 164 | - ]) |
|
| 161 | + wp_localize_script( 'castor/main.js', apply_filters( 'castor/enqueue/js/localize/variable', 'globals' ), |
|
| 162 | + apply_filters( 'castor/enqueue/js/localize/variables', [ |
|
| 163 | + 'ajax' => admin_url( 'admin-ajax.php' ), |
|
| 164 | + ] ) |
|
| 165 | 165 | ); |
| 166 | - do_action('castor/register/assets'); |
|
| 167 | - wp_enqueue_style('castor/main.css'); |
|
| 168 | - wp_enqueue_script('castor/main.js'); |
|
| 166 | + do_action( 'castor/register/assets' ); |
|
| 167 | + wp_enqueue_style( 'castor/main.css' ); |
|
| 168 | + wp_enqueue_script( 'castor/main.js' ); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
| 172 | 172 | * @return void |
| 173 | 173 | * @action customize_register |
| 174 | 174 | */ |
| 175 | - public function registerCustomizer(WP_Customize_Manager $manager) |
|
| 175 | + public function registerCustomizer( WP_Customize_Manager $manager ) |
|
| 176 | 176 | { |
| 177 | - $manager->get_setting('blogname')->transport = 'postMessage'; |
|
| 178 | - $manager->selective_refresh->add_partial('blogname', [ |
|
| 177 | + $manager->get_setting( 'blogname' )->transport = 'postMessage'; |
|
| 178 | + $manager->selective_refresh->add_partial( 'blogname', [ |
|
| 179 | 179 | 'selector' => '.brand', |
| 180 | - 'render_callback' => function () { |
|
| 181 | - bloginfo('name'); |
|
| 180 | + 'render_callback' => function() { |
|
| 181 | + bloginfo( 'name' ); |
|
| 182 | 182 | }, |
| 183 | - ]); |
|
| 183 | + ] ); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | public function registerCustomizerAssets() |
| 191 | 191 | { |
| 192 | - wp_enqueue_script('castor/customizer.js', Theme::assetUri(castor_app()->jsDir.'customizer.js'), ['customize-preview'], CASTOR_FRAMEWORK_VERSION, true); |
|
| 192 | + wp_enqueue_script( 'castor/customizer.js', Theme::assetUri( castor_app()->jsDir.'customizer.js' ), ['customize-preview'], CASTOR_FRAMEWORK_VERSION, true ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -198,23 +198,23 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public function registerSidebars() |
| 200 | 200 | { |
| 201 | - $defaults = apply_filters('castor/register/sidebars/defaults', [ |
|
| 201 | + $defaults = apply_filters( 'castor/register/sidebars/defaults', [ |
|
| 202 | 202 | 'before_widget' => '<div class="widget %1$s %2$s">', |
| 203 | 203 | 'after_widget' => '</div>', |
| 204 | 204 | 'before_title' => '<h4>', |
| 205 | 205 | 'after_title' => '</h4>', |
| 206 | - ]); |
|
| 206 | + ] ); |
|
| 207 | 207 | |
| 208 | - $sidebars = apply_filters('castor/register/sidebars', [ |
|
| 209 | - 'sidebar-primary' => __('Primary Sidebar', 'castor'), |
|
| 210 | - 'sidebar-footer' => __('Footer Widgets', 'castor'), |
|
| 211 | - ]); |
|
| 208 | + $sidebars = apply_filters( 'castor/register/sidebars', [ |
|
| 209 | + 'sidebar-primary' => __( 'Primary Sidebar', 'castor' ), |
|
| 210 | + 'sidebar-footer' => __( 'Footer Widgets', 'castor' ), |
|
| 211 | + ] ); |
|
| 212 | 212 | |
| 213 | - foreach ($sidebars as $id => $name) { |
|
| 214 | - register_sidebar([ |
|
| 213 | + foreach( $sidebars as $id => $name ) { |
|
| 214 | + register_sidebar( [ |
|
| 215 | 215 | 'id' => $id, |
| 216 | 216 | 'name' => $name, |
| 217 | - ] + $defaults); |
|
| 217 | + ] + $defaults ); |
|
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | } |
@@ -8,8 +8,7 @@ |
||
| 8 | 8 | * 'fallback' => [], |
| 9 | 9 | * ]);. |
| 10 | 10 | */ |
| 11 | -class PostMeta |
|
| 12 | -{ |
|
| 11 | +class PostMeta { |
|
| 13 | 12 | /** |
| 14 | 13 | * @param string $metaKey |
| 15 | 14 | * @return mixed |
@@ -10,51 +10,51 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class PostMeta |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @param string $metaKey |
|
| 15 | - * @return mixed |
|
| 16 | - */ |
|
| 17 | - public function get($metaKey, array $args = []) |
|
| 18 | - { |
|
| 19 | - if (empty($metaKey)) { |
|
| 20 | - return; |
|
| 21 | - } |
|
| 13 | + /** |
|
| 14 | + * @param string $metaKey |
|
| 15 | + * @return mixed |
|
| 16 | + */ |
|
| 17 | + public function get($metaKey, array $args = []) |
|
| 18 | + { |
|
| 19 | + if (empty($metaKey)) { |
|
| 20 | + return; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - $args = $this->normalize($args); |
|
| 24 | - $metaKey = $this->buildMetaKey($metaKey, $args['prefix']); |
|
| 25 | - $metaValue = get_post_meta($args['id'], $metaKey, $args['single']); |
|
| 23 | + $args = $this->normalize($args); |
|
| 24 | + $metaKey = $this->buildMetaKey($metaKey, $args['prefix']); |
|
| 25 | + $metaValue = get_post_meta($args['id'], $metaKey, $args['single']); |
|
| 26 | 26 | |
| 27 | - if (is_string($metaValue)) { |
|
| 28 | - $metaValue = trim($metaValue); |
|
| 29 | - } |
|
| 30 | - return empty($metaValue) && !in_array($metaValue, [0,'0']) |
|
| 31 | - ? $args['fallback'] |
|
| 32 | - : $metaValue; |
|
| 33 | - } |
|
| 27 | + if (is_string($metaValue)) { |
|
| 28 | + $metaValue = trim($metaValue); |
|
| 29 | + } |
|
| 30 | + return empty($metaValue) && !in_array($metaValue, [0,'0']) |
|
| 31 | + ? $args['fallback'] |
|
| 32 | + : $metaValue; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param string $metaKey |
|
| 37 | - * @param string $prefix |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - protected function buildMetaKey($metaKey, $prefix) |
|
| 41 | - { |
|
| 42 | - return ('_' == substr($metaKey, 0, 1) && !empty($prefix)) |
|
| 43 | - ? sprintf('_%s%s', rtrim($prefix, '_'), $metaKey) |
|
| 44 | - : $prefix.$metaKey; |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * @param string $metaKey |
|
| 37 | + * @param string $prefix |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + protected function buildMetaKey($metaKey, $prefix) |
|
| 41 | + { |
|
| 42 | + return ('_' == substr($metaKey, 0, 1) && !empty($prefix)) |
|
| 43 | + ? sprintf('_%s%s', rtrim($prefix, '_'), $metaKey) |
|
| 44 | + : $prefix.$metaKey; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return array |
|
| 49 | - */ |
|
| 50 | - protected function normalize(array $args) |
|
| 51 | - { |
|
| 52 | - $defaults = [ |
|
| 53 | - 'id' => get_the_ID(), |
|
| 54 | - 'fallback' => '', |
|
| 55 | - 'single' => true, |
|
| 56 | - 'prefix' => apply_filters('pollux/prefix', 'pollux_'), |
|
| 57 | - ]; |
|
| 58 | - return shortcode_atts($defaults, array_change_key_case($args)); |
|
| 59 | - } |
|
| 47 | + /** |
|
| 48 | + * @return array |
|
| 49 | + */ |
|
| 50 | + protected function normalize(array $args) |
|
| 51 | + { |
|
| 52 | + $defaults = [ |
|
| 53 | + 'id' => get_the_ID(), |
|
| 54 | + 'fallback' => '', |
|
| 55 | + 'single' => true, |
|
| 56 | + 'prefix' => apply_filters('pollux/prefix', 'pollux_'), |
|
| 57 | + ]; |
|
| 58 | + return shortcode_atts($defaults, array_change_key_case($args)); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -14,20 +14,20 @@ discard block |
||
| 14 | 14 | * @param string $metaKey |
| 15 | 15 | * @return mixed |
| 16 | 16 | */ |
| 17 | - public function get($metaKey, array $args = []) |
|
| 17 | + public function get( $metaKey, array $args = [] ) |
|
| 18 | 18 | { |
| 19 | - if (empty($metaKey)) { |
|
| 19 | + if( empty( $metaKey ) ) { |
|
| 20 | 20 | return; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - $args = $this->normalize($args); |
|
| 24 | - $metaKey = $this->buildMetaKey($metaKey, $args['prefix']); |
|
| 25 | - $metaValue = get_post_meta($args['id'], $metaKey, $args['single']); |
|
| 23 | + $args = $this->normalize( $args ); |
|
| 24 | + $metaKey = $this->buildMetaKey( $metaKey, $args['prefix'] ); |
|
| 25 | + $metaValue = get_post_meta( $args['id'], $metaKey, $args['single'] ); |
|
| 26 | 26 | |
| 27 | - if (is_string($metaValue)) { |
|
| 28 | - $metaValue = trim($metaValue); |
|
| 27 | + if( is_string( $metaValue ) ) { |
|
| 28 | + $metaValue = trim( $metaValue ); |
|
| 29 | 29 | } |
| 30 | - return empty($metaValue) && !in_array($metaValue, [0,'0']) |
|
| 30 | + return empty( $metaValue ) && !in_array( $metaValue, [0, '0'] ) |
|
| 31 | 31 | ? $args['fallback'] |
| 32 | 32 | : $metaValue; |
| 33 | 33 | } |
@@ -37,24 +37,24 @@ discard block |
||
| 37 | 37 | * @param string $prefix |
| 38 | 38 | * @return string |
| 39 | 39 | */ |
| 40 | - protected function buildMetaKey($metaKey, $prefix) |
|
| 40 | + protected function buildMetaKey( $metaKey, $prefix ) |
|
| 41 | 41 | { |
| 42 | - return ('_' == substr($metaKey, 0, 1) && !empty($prefix)) |
|
| 43 | - ? sprintf('_%s%s', rtrim($prefix, '_'), $metaKey) |
|
| 42 | + return ( '_' == substr( $metaKey, 0, 1 ) && !empty( $prefix ) ) |
|
| 43 | + ? sprintf( '_%s%s', rtrim( $prefix, '_' ), $metaKey ) |
|
| 44 | 44 | : $prefix.$metaKey; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @return array |
| 49 | 49 | */ |
| 50 | - protected function normalize(array $args) |
|
| 50 | + protected function normalize( array $args ) |
|
| 51 | 51 | { |
| 52 | 52 | $defaults = [ |
| 53 | 53 | 'id' => get_the_ID(), |
| 54 | 54 | 'fallback' => '', |
| 55 | 55 | 'single' => true, |
| 56 | - 'prefix' => apply_filters('pollux/prefix', 'pollux_'), |
|
| 56 | + 'prefix' => apply_filters( 'pollux/prefix', 'pollux_' ), |
|
| 57 | 57 | ]; |
| 58 | - return shortcode_atts($defaults, array_change_key_case($args)); |
|
| 58 | + return shortcode_atts( $defaults, array_change_key_case( $args ) ); |
|
| 59 | 59 | } |
| 60 | 60 | } |