Completed
Push — develop ( 410ed6...c337fc )
by Paul
02:03
created
src/Video.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	protected $theme;
21 21
 	protected $utility;
22 22
 
23
-	public function __construct( Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility )
23
+	public function __construct(Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility)
24 24
 	{
25 25
 		$this->image    = $image;
26 26
 		$this->oembed   = $oembed;
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
 		$this->utility  = $utility;
30 30
 	}
31 31
 
32
-	public function get( $args = [] )
32
+	public function get($args = [])
33 33
 	{
34
-		$args = $this->normalize( $args );
35
-		$embed = $this->oembed->request( $args['url'], $args['player'] );
36
-		if( isset( $embed->type ) && $embed->type == 'video' ) {
34
+		$args = $this->normalize($args);
35
+		$embed = $this->oembed->request($args['url'], $args['player']);
36
+		if (isset($embed->type) && $embed->type == 'video') {
37 37
 			$this->video = $embed;
38 38
 		}
39 39
 		return $this;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
 	public function render()
43 43
 	{
44
-		if( !isset( $this->video->html ))return;
44
+		if (!isset($this->video->html))return;
45 45
 		return sprintf(
46 46
 			'<div class="video embed">%s%s</div>',
47 47
 			$this->renderScreenshot(),
@@ -59,15 +59,15 @@  discard block
 block discarded – undo
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,28 +81,28 @@  discard block
 block discarded – undo
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
 
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
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 ))continue;
118
-			call_user_func([ $this, $method ], $value );
115
+		foreach ($this->args as $key => $value) {
116
+			$method = $this->utility->buildMethodName($key, 'set');
117
+			if (!method_exists($this, $method))continue;
118
+			call_user_func([$this, $method], $value);
119 119
 		}
120 120
 		return $this->args;
121 121
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,9 @@  discard block
 block discarded – undo
41 41
 
42 42
 	public function render()
43 43
 	{
44
-		if( !isset( $this->video->html ))return;
44
+		if( !isset( $this->video->html )) {
45
+			return;
46
+		}
45 47
 		return sprintf(
46 48
 			'<div class="video embed">%s%s</div>',
47 49
 			$this->renderScreenshot(),
@@ -114,7 +116,9 @@  discard block
 block discarded – undo
114 116
 
115 117
 		foreach( $this->args as $key => $value ) {
116 118
 			$method = $this->utility->buildMethodName( $key, 'set' );
117
-			if( !method_exists( $this, $method ))continue;
119
+			if( !method_exists( $this, $method )) {
120
+				continue;
121
+			}
118 122
 			call_user_func([ $this, $method ], $value );
119 123
 		}
120 124
 		return $this->args;
Please login to merge, or discard this patch.
src/Helpers/Template.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 {
9 9
 	public $util;
10 10
 
11
-	public function __construct( Utility $util )
11
+	public function __construct(Utility $util)
12 12
 	{
13 13
 		$this->util = $util;
14 14
 	}
@@ -24,24 +24,24 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @return string
26 26
 	 */
27
-	public function get( $slug, $name = '' )
27
+	public function get($slug, $name = '')
28 28
 	{
29
-		$template  = $this->util->startWith( 'templates/', $slug );
29
+		$template  = $this->util->startWith('templates/', $slug);
30 30
 		$templates = ["{$template}.php"];
31 31
 
32
-		if( 'index' != basename( $this->template, '.php' )) {
33
-			$filepath = dirname( $template ) != '.'
34
-				? sprintf( '%s/', dirname( $template ))
32
+		if ('index' != basename($this->template, '.php')) {
33
+			$filepath = dirname($template) != '.'
34
+				? sprintf('%s/', dirname($template))
35 35
 				: '';
36 36
 			array_unshift(
37 37
 				$templates,
38
-				sprintf( '%s%s-%s.php', $filepath, $name, basename( $template ))
38
+				sprintf('%s%s-%s.php', $filepath, $name, basename($template))
39 39
 			);
40 40
 		}
41 41
 
42
-		$templates = apply_filters( "castor/templates/{$slug}", $templates, $name );
42
+		$templates = apply_filters("castor/templates/{$slug}", $templates, $name);
43 43
 
44
-		return locate_template( $templates );
44
+		return locate_template($templates);
45 45
 	}
46 46
 
47 47
 	/**
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @return void
52 52
 	 */
53
-	public function load( $slug, $name = '' )
53
+	public function load($slug, $name = '')
54 54
 	{
55
-		$template = $this->get( $slug, $name );
56
-		if( !empty( $template )) {
57
-			load_template( $template, false );
55
+		$template = $this->get($slug, $name);
56
+		if (!empty($template)) {
57
+			load_template($template, false);
58 58
 		}
59 59
 	}
60 60
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	public function main()
65 65
 	{
66
-		$this->load( $this->template );
66
+		$this->load($this->template);
67 67
 	}
68 68
 
69 69
 	/**
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @return string|void
73 73
 	 */
74
-	public function setLayout( $template )
74
+	public function setLayout($template)
75 75
 	{
76
-		$this->template = $this->util->trimRight( strstr( $template, 'templates/' ), '.php' );
77
-		return $this->get( apply_filters( 'castor/templates/layout', 'layouts/default' ));
76
+		$this->template = $this->util->trimRight(strstr($template, 'templates/'), '.php');
77
+		return $this->get(apply_filters('castor/templates/layout', 'layouts/default'));
78 78
 	}
79 79
 }
Please login to merge, or discard this patch.
src/Helpers/Render.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 	public $theme;
15 15
 	public $utility;
16 16
 
17
-	public function __construct( Media $media, PostMeta $postmeta, Theme $theme, Utility $utility )
17
+	public function __construct(Media $media, PostMeta $postmeta, Theme $theme, Utility $utility)
18 18
 	{
19 19
 		$this->media    = $media;
20 20
 		$this->postmeta = $postmeta;
@@ -22,80 +22,80 @@  discard block
 block discarded – undo
22 22
 		$this->utility  = $utility;
23 23
 	}
24 24
 
25
-	public function blockquote( $metaKey = false, array $attributes = [] )
25
+	public function blockquote($metaKey = false, array $attributes = [])
26 26
 	{
27
-		if( $value = $this->postmeta->get( $metaKey )) {
28
-			$this->utility->printTag( 'blockquote', wp_strip_all_tags( $value ), $attributes );
27
+		if ($value = $this->postmeta->get($metaKey)) {
28
+			$this->utility->printTag('blockquote', wp_strip_all_tags($value), $attributes);
29 29
 		}
30 30
 	}
31 31
 
32
-	public function button( $postId = 0, $title = false )
32
+	public function button($postId = 0, $title = false)
33 33
 	{
34
-		$post = get_post( $postId );
34
+		$post = get_post($postId);
35 35
 
36
-		if( !$postId || !$post )return;
37
-		if( !$title ) {
36
+		if (!$postId || !$post)return;
37
+		if (!$title) {
38 38
 			$title = $post->post_title;
39 39
 		}
40
-		printf( '<a href="%s" class="button"><span>%s</span></a>',
41
-			get_permalink( $post->ID ),
40
+		printf('<a href="%s" class="button"><span>%s</span></a>',
41
+			get_permalink($post->ID),
42 42
 			$title
43 43
 		);
44 44
 	}
45 45
 
46
-	public function buttons( $postIds = [] )
46
+	public function buttons($postIds = [])
47 47
 	{
48
-		foreach( (array) $postIds as $postId ) {
49
-			$this->button( $postId );
48
+		foreach ((array) $postIds as $postId) {
49
+			$this->button($postId);
50 50
 		}
51 51
 	}
52 52
 
53
-	public function content( $metaKey = false )
53
+	public function content($metaKey = false)
54 54
 	{
55 55
 		$content = $metaKey
56
-			? $this->postmeta->get( $metaKey )
56
+			? $this->postmeta->get($metaKey)
57 57
 			: get_the_content();
58 58
 
59
-		echo str_replace( ']]>', ']]&gt;', apply_filters( 'the_content', $content ));
59
+		echo str_replace(']]>', ']]&gt;', apply_filters('the_content', $content));
60 60
 	}
61 61
 
62
-	public function featured( $args = [] )
62
+	public function featured($args = [])
63 63
 	{
64
-		$args = wp_parse_args( $args, [
64
+		$args = wp_parse_args($args, [
65 65
 			'class' => 'featured',
66 66
 			'image' => get_post_thumbnail_id(),
67 67
 			'video' => 'featured_video',
68 68
 		]);
69
-		$featuredHtml = $this->media->video( wp_parse_args( $args, [
69
+		$featuredHtml = $this->media->video(wp_parse_args($args, [
70 70
 			'url' => $args['video'],
71 71
 		]));
72
-		if( empty( $featuredHtml ) && $featuredImage = $this->media->getImage( $args['image'] )) {
73
-			$featuredHtml = sprintf( '<div class="featured-image"><img src="%s" alt="%s"></div><figcaption>%s</figcaption>',
72
+		if (empty($featuredHtml) && $featuredImage = $this->media->getImage($args['image'])) {
73
+			$featuredHtml = sprintf('<div class="featured-image"><img src="%s" alt="%s"></div><figcaption>%s</figcaption>',
74 74
 				$featuredImage->large['url'],
75 75
 				$featuredImage->alt,
76 76
 				$featuredImage->caption
77 77
 			);
78 78
 		}
79
-		if( !empty( $featuredHtml )) {
80
-			printf( '<figure class="%s">%s</figure>', $args['class'], $featuredHtml );
79
+		if (!empty($featuredHtml)) {
80
+			printf('<figure class="%s">%s</figure>', $args['class'], $featuredHtml);
81 81
 		}
82 82
 	}
83 83
 
84
-	public function gallery( array $args = [] )
84
+	public function gallery(array $args = [])
85 85
 	{
86
-		echo $this->media->gallery( $args );
86
+		echo $this->media->gallery($args);
87 87
 	}
88 88
 
89
-	public function title( $metaKey = false, array $attributes = [] )
89
+	public function title($metaKey = false, array $attributes = [])
90 90
 	{
91
-		$tag = apply_filters( 'castor/render/title/tag', 'h2' );
91
+		$tag = apply_filters('castor/render/title/tag', 'h2');
92 92
 		$value = $metaKey
93
-			? $this->postmeta->get( $metaKey )
93
+			? $this->postmeta->get($metaKey)
94 94
 			: $this->theme->pageTitle();
95 95
 
96
-		if( !$value )return;
96
+		if (!$value)return;
97 97
 
98
-		$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes );
98
+		$this->utility->printTag($tag, wp_strip_all_tags($value), $attributes);
99 99
 	}
100 100
 
101 101
 	/**
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @return string|null
105 105
 	 */
106
-	public function video( $args )
106
+	public function video($args)
107 107
 	{
108
-		echo $this->media->video( $args );
108
+		echo $this->media->video($args);
109 109
 	}
110 110
 }
Please login to merge, or discard this patch.
src/Oembed.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -22,69 +22,69 @@
 block discarded – undo
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 35
 		]);
36
-		$request = $this->oembed->fetch( $this->oembed->get_provider( $url ), $url, [
36
+		$request = $this->oembed->fetch($this->oembed->get_provider($url), $url, [
37 37
 			'width'  => 1280,
38 38
 			'height' => 1280,
39 39
 		]);
40
-		if( $request === false )return;
41
-		if( !empty( $args['embed_type'] ) && $args['embed_type'] != $request->type )return;
42
-		return $this->modifyRequest( $request, $args );
40
+		if ($request === false)return;
41
+		if (!empty($args['embed_type']) && $args['embed_type'] != $request->type)return;
42
+		return $this->modifyRequest($request, $args);
43 43
 	}
44 44
 
45
-	protected function domLoad( $html )
45
+	protected function domLoad($html)
46 46
 	{
47 47
 		$dom = new DomDocument;
48
-		$dom->loadHTML( $html );
48
+		$dom->loadHTML($html);
49 49
 		return $dom;
50 50
 	}
51 51
 
52
-	protected function modifyRequest( $request, $args )
52
+	protected function modifyRequest($request, $args)
53 53
 	{
54
-		$providerName = strtolower( $request->provider_name );
55
-		$provider = property_exists( $this, $providerName )
54
+		$providerName = strtolower($request->provider_name);
55
+		$provider = property_exists($this, $providerName)
56 56
 			? $this->$providerName
57 57
 			: [];
58 58
 
59
-		$method = $this->utility->buildMethodName( $providerName . '_request', 'modify' );
59
+		$method = $this->utility->buildMethodName($providerName . '_request', 'modify');
60 60
 
61
-		if( method_exists( $this, $method )) {
62
-			return call_user_func( [$this, $method], $request, array_intersect_key(
61
+		if (method_exists($this, $method)) {
62
+			return call_user_func([$this, $method], $request, array_intersect_key(
63 63
 				$args,
64
-				array_flip( $provider )
64
+				array_flip($provider)
65 65
 			));
66 66
 		}
67 67
 		return $request;
68 68
 	}
69 69
 
70
-	protected function modifyYoutubeRequest( $request, array $args )
70
+	protected function modifyYoutubeRequest($request, array $args)
71 71
 	{
72
-		$html = $this->domLoad( $request->html );
73
-		$node = $html->getElementsByTagName( 'iframe' )->item(0);
74
-		$url  = $node->getAttribute( 'src' );
72
+		$html = $this->domLoad($request->html);
73
+		$node = $html->getElementsByTagName('iframe')->item(0);
74
+		$url  = $node->getAttribute('src');
75 75
 
76
-		if( isset( $args['fs'] ) && $args['fs'] == 0 ) {
77
-			$node->removeAttribute( 'allowfullscreen' );
76
+		if (isset($args['fs']) && $args['fs'] == 0) {
77
+			$node->removeAttribute('allowfullscreen');
78 78
 		}
79 79
 
80
-		$args['origin'] = urlencode( get_bloginfo( 'url' ));
80
+		$args['origin'] = urlencode(get_bloginfo('url'));
81 81
 
82
-		$node->setAttribute( 'class', 'video-embed' );
83
-		$node->setAttribute( 'src',
84
-			add_query_arg( $args, remove_query_arg( 'feature', $url ))
82
+		$node->setAttribute('class', 'video-embed');
83
+		$node->setAttribute('src',
84
+			add_query_arg($args, remove_query_arg('feature', $url))
85 85
 		);
86 86
 
87
-		$request->html = $html->saveHTML( $node );
87
+		$request->html = $html->saveHTML($node);
88 88
 
89 89
 		return $request;
90 90
 	}
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,8 +37,12 @@
 block discarded – undo
37 37
 			'width'  => 1280,
38 38
 			'height' => 1280,
39 39
 		]);
40
-		if( $request === false )return;
41
-		if( !empty( $args['embed_type'] ) && $args['embed_type'] != $request->type )return;
40
+		if( $request === false ) {
41
+			return;
42
+		}
43
+		if( !empty( $args['embed_type'] ) && $args['embed_type'] != $request->type ) {
44
+			return;
45
+		}
42 46
 		return $this->modifyRequest( $request, $args );
43 47
 	}
44 48
 
Please login to merge, or discard this patch.