@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | protected $theme; |
20 | 20 | protected $utility; |
21 | 21 | |
22 | - public function __construct( Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility ) |
|
22 | + public function __construct(Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
23 | 23 | { |
24 | 24 | $this->image = $image; |
25 | 25 | $this->oembed = $oembed; |
@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | $this->utility = $utility; |
29 | 29 | } |
30 | 30 | |
31 | - public function get( $args = [] ) |
|
31 | + public function get($args = []) |
|
32 | 32 | { |
33 | - $args = $this->normalize( $args ); |
|
34 | - $this->video = $this->oembed->request( $args['url'], $args['player'] ); |
|
33 | + $args = $this->normalize($args); |
|
34 | + $this->video = $this->oembed->request($args['url'], $args['player']); |
|
35 | 35 | return $this; |
36 | 36 | } |
37 | 37 | |
38 | 38 | public function render() |
39 | 39 | { |
40 | - if( !isset( $this->video->html ))return; |
|
40 | + if (!isset($this->video->html))return; |
|
41 | 41 | return sprintf( |
42 | 42 | '<div class="video embed">%s%s</div>', |
43 | 43 | $this->renderScreenshot(), |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | '<a href="%s" class="video-play-btn">%s</a>' . |
56 | 56 | '</div>', |
57 | 57 | $this->args['url'], |
58 | - $this->theme->svg( 'play.svg' ) |
|
58 | + $this->theme->svg('play.svg') |
|
59 | 59 | ); |
60 | 60 | } |
61 | 61 | |
62 | 62 | public function renderScreenshot() |
63 | 63 | { |
64 | - if( !$this->args['image'] )return; |
|
65 | - return sprintf( '%s<div class="video-poster" style="background-image: url(%s)">%s</div>', |
|
64 | + if (!$this->args['image'])return; |
|
65 | + return sprintf('%s<div class="video-poster" style="background-image: url(%s)">%s</div>', |
|
66 | 66 | $this->renderSpinner(), |
67 | 67 | $this->args['image'], |
68 | 68 | $this->renderPlayButton() |
@@ -75,28 +75,28 @@ discard block |
||
75 | 75 | '<div class="video-spinner">' . |
76 | 76 | '<div class="spinner"><div class="spinner-dots">%s</div></div>' . |
77 | 77 | '</div>', |
78 | - implode( '', array_fill( 0, 8, '<div class="spinner-dot"></div>' )) |
|
78 | + implode('', array_fill(0, 8, '<div class="spinner-dot"></div>')) |
|
79 | 79 | ); |
80 | 80 | } |
81 | 81 | |
82 | - protected function setImage( $image ) |
|
82 | + protected function setImage($image) |
|
83 | 83 | { |
84 | - $image = $this->image->get( $image )->image; |
|
85 | - $this->args['image'] = isset( $image->large ) |
|
84 | + $image = $this->image->get($image)->image; |
|
85 | + $this->args['image'] = isset($image->large) |
|
86 | 86 | ? $image->large['url'] |
87 | 87 | : null; |
88 | 88 | } |
89 | 89 | |
90 | - protected function setUrl( $url ) |
|
90 | + protected function setUrl($url) |
|
91 | 91 | { |
92 | - $this->args['url'] = !filter_var( $url, FILTER_VALIDATE_URL ) |
|
93 | - ? $this->postmeta->get( $url ) |
|
92 | + $this->args['url'] = !filter_var($url, FILTER_VALIDATE_URL) |
|
93 | + ? $this->postmeta->get($url) |
|
94 | 94 | : $url; |
95 | 95 | } |
96 | 96 | |
97 | - protected function normalize( $args ) |
|
97 | + protected function normalize($args) |
|
98 | 98 | { |
99 | - if( is_string( $args )) { |
|
99 | + if (is_string($args)) { |
|
100 | 100 | $args = ['url' => $args]; |
101 | 101 | } |
102 | 102 | |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | 'image' => '', // string || int |
105 | 105 | 'player' => '', // string || array |
106 | 106 | 'url' => '', // string |
107 | - ], $args ); |
|
107 | + ], $args); |
|
108 | 108 | |
109 | - foreach( $this->args as $key => $value ) { |
|
110 | - $method = $this->utility->buildMethodName( $key, 'set' ); |
|
111 | - if( !method_exists( $this, $method ))continue; |
|
112 | - call_user_func([ $this, $method ], $value ); |
|
109 | + foreach ($this->args as $key => $value) { |
|
110 | + $method = $this->utility->buildMethodName($key, 'set'); |
|
111 | + if (!method_exists($this, $method))continue; |
|
112 | + call_user_func([$this, $method], $value); |
|
113 | 113 | } |
114 | 114 | return $this->args; |
115 | 115 | } |
@@ -37,7 +37,9 @@ discard block |
||
37 | 37 | |
38 | 38 | public function render() |
39 | 39 | { |
40 | - if( !isset( $this->video->html ))return; |
|
40 | + if( !isset( $this->video->html )) { |
|
41 | + return; |
|
42 | + } |
|
41 | 43 | return sprintf( |
42 | 44 | '<div class="video embed">%s%s</div>', |
43 | 45 | $this->renderScreenshot(), |
@@ -61,7 +63,9 @@ discard block |
||
61 | 63 | |
62 | 64 | public function renderScreenshot() |
63 | 65 | { |
64 | - if( !$this->args['image'] )return; |
|
66 | + if( !$this->args['image'] ) { |
|
67 | + return; |
|
68 | + } |
|
65 | 69 | return sprintf( '%s<div class="video-poster" style="background-image: url(%s)">%s</div>', |
66 | 70 | $this->renderSpinner(), |
67 | 71 | $this->args['image'], |
@@ -108,7 +112,9 @@ discard block |
||
108 | 112 | |
109 | 113 | foreach( $this->args as $key => $value ) { |
110 | 114 | $method = $this->utility->buildMethodName( $key, 'set' ); |
111 | - if( !method_exists( $this, $method ))continue; |
|
115 | + if( !method_exists( $this, $method )) { |
|
116 | + continue; |
|
117 | + } |
|
112 | 118 | call_user_func([ $this, $method ], $value ); |
113 | 119 | } |
114 | 120 | return $this->args; |
@@ -22,66 +22,66 @@ |
||
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 | - $request = $this->oembed->fetch( $this->oembed->get_provider( $url ), $url, [ |
|
33 | + $request = $this->oembed->fetch($this->oembed->get_provider($url), $url, [ |
|
34 | 34 | 'width' => 1280, |
35 | 35 | 'height' => 1280, |
36 | 36 | ]); |
37 | - if( $request ) { |
|
38 | - return $this->modifyRequest( $request, $args ); |
|
37 | + if ($request) { |
|
38 | + return $this->modifyRequest($request, $args); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | - protected function domLoad( $html ) |
|
42 | + protected function domLoad($html) |
|
43 | 43 | { |
44 | 44 | $dom = new DomDocument; |
45 | - $dom->loadHTML( $html ); |
|
45 | + $dom->loadHTML($html); |
|
46 | 46 | return $dom; |
47 | 47 | } |
48 | 48 | |
49 | - protected function modifyRequest( $request, $args ) |
|
49 | + protected function modifyRequest($request, $args) |
|
50 | 50 | { |
51 | - $providerName = strtolower( $request->provider_name ); |
|
52 | - $provider = property_exists( $this, $providerName ) |
|
51 | + $providerName = strtolower($request->provider_name); |
|
52 | + $provider = property_exists($this, $providerName) |
|
53 | 53 | ? $this->$providerName |
54 | 54 | : []; |
55 | 55 | |
56 | - $method = $this->utility->buildMethodName( $providerName . '_request', 'modify' ); |
|
56 | + $method = $this->utility->buildMethodName($providerName . '_request', 'modify'); |
|
57 | 57 | |
58 | - if( method_exists( $this, $method )) { |
|
59 | - return call_user_func( [$this, $method], $request, array_intersect_key( |
|
60 | - wp_parse_args( $args ), |
|
61 | - array_flip( $provider ) |
|
58 | + if (method_exists($this, $method)) { |
|
59 | + return call_user_func([$this, $method], $request, array_intersect_key( |
|
60 | + wp_parse_args($args), |
|
61 | + array_flip($provider) |
|
62 | 62 | )); |
63 | 63 | } |
64 | 64 | return $request; |
65 | 65 | } |
66 | 66 | |
67 | - protected function modifyYoutubeRequest( $request, array $args ) |
|
67 | + protected function modifyYoutubeRequest($request, array $args) |
|
68 | 68 | { |
69 | - $html = $this->domLoad( $request->html ); |
|
70 | - $node = $html->getElementsByTagName( 'iframe' )->item(0); |
|
71 | - $url = $node->getAttribute( 'src' ); |
|
69 | + $html = $this->domLoad($request->html); |
|
70 | + $node = $html->getElementsByTagName('iframe')->item(0); |
|
71 | + $url = $node->getAttribute('src'); |
|
72 | 72 | |
73 | - if( isset( $args['fs'] ) && $args['fs'] == 0 ) { |
|
74 | - $node->removeAttribute( 'allowfullscreen' ); |
|
73 | + if (isset($args['fs']) && $args['fs'] == 0) { |
|
74 | + $node->removeAttribute('allowfullscreen'); |
|
75 | 75 | } |
76 | 76 | |
77 | - $args['origin'] = urlencode( get_bloginfo( 'url' )); |
|
77 | + $args['origin'] = urlencode(get_bloginfo('url')); |
|
78 | 78 | |
79 | - $node->setAttribute( 'class', 'video-embed' ); |
|
80 | - $node->setAttribute( 'src', |
|
81 | - add_query_arg( $args, remove_query_arg( 'feature', $url )) |
|
79 | + $node->setAttribute('class', 'video-embed'); |
|
80 | + $node->setAttribute('src', |
|
81 | + add_query_arg($args, remove_query_arg('feature', $url)) |
|
82 | 82 | ); |
83 | 83 | |
84 | - $request->html = $html->saveHTML( $node ); |
|
84 | + $request->html = $html->saveHTML($node); |
|
85 | 85 | |
86 | 86 | return $request; |
87 | 87 | } |