@@ -11,8 +11,7 @@ |
||
11 | 11 | * |
12 | 12 | * @property object all |
13 | 13 | */ |
14 | -class SiteMeta |
|
15 | -{ |
|
14 | +class SiteMeta { |
|
16 | 15 | protected $options; |
17 | 16 | |
18 | 17 | public function __construct() |
@@ -13,90 +13,90 @@ |
||
13 | 13 | */ |
14 | 14 | class SiteMeta |
15 | 15 | { |
16 | - protected $options; |
|
16 | + protected $options; |
|
17 | 17 | |
18 | - public function __construct() |
|
19 | - { |
|
20 | - $this->options = get_option(apply_filters('pollux/settings/id', 'pollux_settings'), []); |
|
21 | - } |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | + $this->options = get_option(apply_filters('pollux/settings/id', 'pollux_settings'), []); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string $group |
|
25 | - * @return object|array|null |
|
26 | - */ |
|
27 | - public function __call($group, $args) |
|
28 | - { |
|
29 | - $args = array_pad($args, 2, null); |
|
30 | - $group = $this->$group; |
|
31 | - if (is_object($group)) { |
|
32 | - return $group; |
|
33 | - } |
|
34 | - return $this->get($group, $args[0], $args[1]); |
|
35 | - } |
|
23 | + /** |
|
24 | + * @param string $group |
|
25 | + * @return object|array|null |
|
26 | + */ |
|
27 | + public function __call($group, $args) |
|
28 | + { |
|
29 | + $args = array_pad($args, 2, null); |
|
30 | + $group = $this->$group; |
|
31 | + if (is_object($group)) { |
|
32 | + return $group; |
|
33 | + } |
|
34 | + return $this->get($group, $args[0], $args[1]); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $group |
|
39 | - * @return object|array|null |
|
40 | - */ |
|
41 | - public function __get($group) |
|
42 | - { |
|
43 | - if ('all' == $group) { |
|
44 | - return (object) $this->options; |
|
45 | - } |
|
46 | - if (empty($group)) { |
|
47 | - $group = $this->getDefaultGroup(); |
|
48 | - } |
|
49 | - if (is_array($group)) { |
|
50 | - $group = reset($group); |
|
51 | - } |
|
52 | - return isset($this->options[$group]) |
|
53 | - ? $this->options[$group] |
|
54 | - : null; |
|
55 | - } |
|
37 | + /** |
|
38 | + * @param string $group |
|
39 | + * @return object|array|null |
|
40 | + */ |
|
41 | + public function __get($group) |
|
42 | + { |
|
43 | + if ('all' == $group) { |
|
44 | + return (object) $this->options; |
|
45 | + } |
|
46 | + if (empty($group)) { |
|
47 | + $group = $this->getDefaultGroup(); |
|
48 | + } |
|
49 | + if (is_array($group)) { |
|
50 | + $group = reset($group); |
|
51 | + } |
|
52 | + return isset($this->options[$group]) |
|
53 | + ? $this->options[$group] |
|
54 | + : null; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param string $group |
|
59 | - * @param string|null $key |
|
60 | - * @param mixed $fallback |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - public function get($group = '', $key = '', $fallback = null) |
|
64 | - { |
|
65 | - if (func_num_args() < 1) { |
|
66 | - return $this->all; |
|
67 | - } |
|
68 | - if (is_string($group)) { |
|
69 | - $group = $this->$group; |
|
70 | - } |
|
71 | - if (!is_array($group)) { |
|
72 | - return $fallback; |
|
73 | - } |
|
74 | - if (is_null($key)) { |
|
75 | - return $group; |
|
76 | - } |
|
77 | - return $this->getValue($group, $key, $fallback); |
|
78 | - } |
|
57 | + /** |
|
58 | + * @param string $group |
|
59 | + * @param string|null $key |
|
60 | + * @param mixed $fallback |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + public function get($group = '', $key = '', $fallback = null) |
|
64 | + { |
|
65 | + if (func_num_args() < 1) { |
|
66 | + return $this->all; |
|
67 | + } |
|
68 | + if (is_string($group)) { |
|
69 | + $group = $this->$group; |
|
70 | + } |
|
71 | + if (!is_array($group)) { |
|
72 | + return $fallback; |
|
73 | + } |
|
74 | + if (is_null($key)) { |
|
75 | + return $group; |
|
76 | + } |
|
77 | + return $this->getValue($group, $key, $fallback); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - protected function getDefaultGroup() |
|
84 | - { |
|
85 | - return ''; |
|
86 | - } |
|
80 | + /** |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + protected function getDefaultGroup() |
|
84 | + { |
|
85 | + return ''; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param string $key |
|
90 | - * @param mixed $fallback |
|
91 | - * @return mixed |
|
92 | - */ |
|
93 | - protected function getValue(array $group, $key = '', $fallback = null) |
|
94 | - { |
|
95 | - if (empty($key) || !array_key_exists($key, $group)) { |
|
96 | - return $fallback; |
|
97 | - } |
|
98 | - return empty($group[$key]) && !is_null($fallback) |
|
99 | - ? $fallback |
|
100 | - : $group[$key]; |
|
101 | - } |
|
88 | + /** |
|
89 | + * @param string $key |
|
90 | + * @param mixed $fallback |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + protected function getValue(array $group, $key = '', $fallback = null) |
|
94 | + { |
|
95 | + if (empty($key) || !array_key_exists($key, $group)) { |
|
96 | + return $fallback; |
|
97 | + } |
|
98 | + return empty($group[$key]) && !is_null($fallback) |
|
99 | + ? $fallback |
|
100 | + : $group[$key]; |
|
101 | + } |
|
102 | 102 | } |
@@ -17,39 +17,39 @@ discard block |
||
17 | 17 | |
18 | 18 | public function __construct() |
19 | 19 | { |
20 | - $this->options = get_option(apply_filters('pollux/settings/id', 'pollux_settings'), []); |
|
20 | + $this->options = get_option( apply_filters( 'pollux/settings/id', 'pollux_settings' ), [] ); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @param string $group |
25 | 25 | * @return object|array|null |
26 | 26 | */ |
27 | - public function __call($group, $args) |
|
27 | + public function __call( $group, $args ) |
|
28 | 28 | { |
29 | - $args = array_pad($args, 2, null); |
|
29 | + $args = array_pad( $args, 2, null ); |
|
30 | 30 | $group = $this->$group; |
31 | - if (is_object($group)) { |
|
31 | + if( is_object( $group ) ) { |
|
32 | 32 | return $group; |
33 | 33 | } |
34 | - return $this->get($group, $args[0], $args[1]); |
|
34 | + return $this->get( $group, $args[0], $args[1] ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @param string $group |
39 | 39 | * @return object|array|null |
40 | 40 | */ |
41 | - public function __get($group) |
|
41 | + public function __get( $group ) |
|
42 | 42 | { |
43 | - if ('all' == $group) { |
|
43 | + if( 'all' == $group ) { |
|
44 | 44 | return (object) $this->options; |
45 | 45 | } |
46 | - if (empty($group)) { |
|
46 | + if( empty( $group ) ) { |
|
47 | 47 | $group = $this->getDefaultGroup(); |
48 | 48 | } |
49 | - if (is_array($group)) { |
|
50 | - $group = reset($group); |
|
49 | + if( is_array( $group ) ) { |
|
50 | + $group = reset( $group ); |
|
51 | 51 | } |
52 | - return isset($this->options[$group]) |
|
52 | + return isset( $this->options[$group] ) |
|
53 | 53 | ? $this->options[$group] |
54 | 54 | : null; |
55 | 55 | } |
@@ -60,21 +60,21 @@ discard block |
||
60 | 60 | * @param mixed $fallback |
61 | 61 | * @return mixed |
62 | 62 | */ |
63 | - public function get($group = '', $key = '', $fallback = null) |
|
63 | + public function get( $group = '', $key = '', $fallback = null ) |
|
64 | 64 | { |
65 | - if (func_num_args() < 1) { |
|
65 | + if( func_num_args() < 1 ) { |
|
66 | 66 | return $this->all; |
67 | 67 | } |
68 | - if (is_string($group)) { |
|
68 | + if( is_string( $group ) ) { |
|
69 | 69 | $group = $this->$group; |
70 | 70 | } |
71 | - if (!is_array($group)) { |
|
71 | + if( !is_array( $group ) ) { |
|
72 | 72 | return $fallback; |
73 | 73 | } |
74 | - if (is_null($key)) { |
|
74 | + if( is_null( $key ) ) { |
|
75 | 75 | return $group; |
76 | 76 | } |
77 | - return $this->getValue($group, $key, $fallback); |
|
77 | + return $this->getValue( $group, $key, $fallback ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * @param mixed $fallback |
91 | 91 | * @return mixed |
92 | 92 | */ |
93 | - protected function getValue(array $group, $key = '', $fallback = null) |
|
93 | + protected function getValue( array $group, $key = '', $fallback = null ) |
|
94 | 94 | { |
95 | - if (empty($key) || !array_key_exists($key, $group)) { |
|
95 | + if( empty( $key ) || !array_key_exists( $key, $group ) ) { |
|
96 | 96 | return $fallback; |
97 | 97 | } |
98 | - return empty($group[$key]) && !is_null($fallback) |
|
98 | + return empty( $group[$key] ) && !is_null( $fallback ) |
|
99 | 99 | ? $fallback |
100 | 100 | : $group[$key]; |
101 | 101 | } |
@@ -8,68 +8,68 @@ |
||
8 | 8 | |
9 | 9 | class Template |
10 | 10 | { |
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - public $template; |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + public $template; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @param string $slug |
|
18 | - * @param string $name |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function get($slug, $name = '') |
|
23 | - { |
|
24 | - $template = UtilityFacade::startWith('templates/', $slug); |
|
25 | - $templates = ["$template.php"]; |
|
26 | - if (!empty($name)) { |
|
27 | - $fileName = basename($template); |
|
28 | - $filePath = UtilityFacade::trimRight($template, $fileName); |
|
29 | - array_unshift($templates, sprintf('%s/%s.php', $filePath.$name, $fileName)); |
|
30 | - } |
|
31 | - $templates = array_unique(apply_filters("castor/templates/$slug", $templates, $name)); |
|
32 | - $template = locate_template($templates); |
|
33 | - if (empty($template)) { |
|
34 | - if (file_exists("$slug.php")) { |
|
35 | - return "$slug.php"; |
|
36 | - } |
|
37 | - LogFacade::debug("$slug not found."); |
|
38 | - } |
|
39 | - return $template; |
|
40 | - } |
|
16 | + /** |
|
17 | + * @param string $slug |
|
18 | + * @param string $name |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function get($slug, $name = '') |
|
23 | + { |
|
24 | + $template = UtilityFacade::startWith('templates/', $slug); |
|
25 | + $templates = ["$template.php"]; |
|
26 | + if (!empty($name)) { |
|
27 | + $fileName = basename($template); |
|
28 | + $filePath = UtilityFacade::trimRight($template, $fileName); |
|
29 | + array_unshift($templates, sprintf('%s/%s.php', $filePath.$name, $fileName)); |
|
30 | + } |
|
31 | + $templates = array_unique(apply_filters("castor/templates/$slug", $templates, $name)); |
|
32 | + $template = locate_template($templates); |
|
33 | + if (empty($template)) { |
|
34 | + if (file_exists("$slug.php")) { |
|
35 | + return "$slug.php"; |
|
36 | + } |
|
37 | + LogFacade::debug("$slug not found."); |
|
38 | + } |
|
39 | + return $template; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param string $slug |
|
44 | - * @param string $name |
|
45 | - * |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function load($slug, $name = '') |
|
49 | - { |
|
50 | - if (!empty(($template = $this->get($slug, $name)))) { |
|
51 | - DevelopmentFacade::storeTemplatePath($template); |
|
52 | - load_template($template, false); |
|
53 | - } |
|
54 | - } |
|
42 | + /** |
|
43 | + * @param string $slug |
|
44 | + * @param string $name |
|
45 | + * |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function load($slug, $name = '') |
|
49 | + { |
|
50 | + if (!empty(($template = $this->get($slug, $name)))) { |
|
51 | + DevelopmentFacade::storeTemplatePath($template); |
|
52 | + load_template($template, false); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public function main() |
|
60 | - { |
|
61 | - $this->load($this->template); |
|
62 | - } |
|
56 | + /** |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public function main() |
|
60 | + { |
|
61 | + $this->load($this->template); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $template |
|
66 | - * |
|
67 | - * @return string|void |
|
68 | - */ |
|
69 | - public function setLayout($template) |
|
70 | - { |
|
71 | - $template = str_replace(get_stylesheet_directory().'/templates/', '', $template); |
|
72 | - $this->template = UtilityFacade::trimRight($template, '.php'); |
|
73 | - return $this->get(apply_filters('castor/templates/layout', 'layouts/default')); |
|
74 | - } |
|
64 | + /** |
|
65 | + * @param string $template |
|
66 | + * |
|
67 | + * @return string|void |
|
68 | + */ |
|
69 | + public function setLayout($template) |
|
70 | + { |
|
71 | + $template = str_replace(get_stylesheet_directory().'/templates/', '', $template); |
|
72 | + $this->template = UtilityFacade::trimRight($template, '.php'); |
|
73 | + return $this->get(apply_filters('castor/templates/layout', 'layouts/default')); |
|
74 | + } |
|
75 | 75 | } |
@@ -19,22 +19,22 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return string |
21 | 21 | */ |
22 | - public function get($slug, $name = '') |
|
22 | + public function get( $slug, $name = '' ) |
|
23 | 23 | { |
24 | - $template = UtilityFacade::startWith('templates/', $slug); |
|
24 | + $template = UtilityFacade::startWith( 'templates/', $slug ); |
|
25 | 25 | $templates = ["$template.php"]; |
26 | - if (!empty($name)) { |
|
27 | - $fileName = basename($template); |
|
28 | - $filePath = UtilityFacade::trimRight($template, $fileName); |
|
29 | - array_unshift($templates, sprintf('%s/%s.php', $filePath.$name, $fileName)); |
|
26 | + if( !empty( $name ) ) { |
|
27 | + $fileName = basename( $template ); |
|
28 | + $filePath = UtilityFacade::trimRight( $template, $fileName ); |
|
29 | + array_unshift( $templates, sprintf( '%s/%s.php', $filePath.$name, $fileName ) ); |
|
30 | 30 | } |
31 | - $templates = array_unique(apply_filters("castor/templates/$slug", $templates, $name)); |
|
32 | - $template = locate_template($templates); |
|
33 | - if (empty($template)) { |
|
34 | - if (file_exists("$slug.php")) { |
|
31 | + $templates = array_unique( apply_filters( "castor/templates/$slug", $templates, $name ) ); |
|
32 | + $template = locate_template( $templates ); |
|
33 | + if( empty( $template ) ) { |
|
34 | + if( file_exists( "$slug.php" ) ) { |
|
35 | 35 | return "$slug.php"; |
36 | 36 | } |
37 | - LogFacade::debug("$slug not found."); |
|
37 | + LogFacade::debug( "$slug not found." ); |
|
38 | 38 | } |
39 | 39 | return $template; |
40 | 40 | } |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return void |
47 | 47 | */ |
48 | - public function load($slug, $name = '') |
|
48 | + public function load( $slug, $name = '' ) |
|
49 | 49 | { |
50 | - if (!empty(($template = $this->get($slug, $name)))) { |
|
51 | - DevelopmentFacade::storeTemplatePath($template); |
|
52 | - load_template($template, false); |
|
50 | + if( !empty( ( $template = $this->get( $slug, $name ) ) ) ) { |
|
51 | + DevelopmentFacade::storeTemplatePath( $template ); |
|
52 | + load_template( $template, false ); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function main() |
60 | 60 | { |
61 | - $this->load($this->template); |
|
61 | + $this->load( $this->template ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return string|void |
68 | 68 | */ |
69 | - public function setLayout($template) |
|
69 | + public function setLayout( $template ) |
|
70 | 70 | { |
71 | - $template = str_replace(get_stylesheet_directory().'/templates/', '', $template); |
|
72 | - $this->template = UtilityFacade::trimRight($template, '.php'); |
|
73 | - return $this->get(apply_filters('castor/templates/layout', 'layouts/default')); |
|
71 | + $template = str_replace( get_stylesheet_directory().'/templates/', '', $template ); |
|
72 | + $this->template = UtilityFacade::trimRight( $template, '.php' ); |
|
73 | + return $this->get( apply_filters( 'castor/templates/layout', 'layouts/default' ) ); |
|
74 | 74 | } |
75 | 75 | } |
@@ -6,8 +6,7 @@ |
||
6 | 6 | use GeminiLabs\Castor\Facades\Log as LogFacade; |
7 | 7 | use GeminiLabs\Castor\Facades\Utility as UtilityFacade; |
8 | 8 | |
9 | -class Template |
|
10 | -{ |
|
9 | +class Template { |
|
11 | 10 | /** |
12 | 11 | * @var string |
13 | 12 | */ |
@@ -17,75 +17,75 @@ |
||
17 | 17 | */ |
18 | 18 | class Media |
19 | 19 | { |
20 | - protected $gallery; |
|
21 | - protected $image; |
|
22 | - protected $video; |
|
20 | + protected $gallery; |
|
21 | + protected $image; |
|
22 | + protected $video; |
|
23 | 23 | |
24 | - public function __construct(Gallery $gallery, Image $image, Video $video) |
|
25 | - { |
|
26 | - $this->gallery = $gallery; |
|
27 | - $this->image = $image; |
|
28 | - $this->video = $video; |
|
29 | - } |
|
24 | + public function __construct(Gallery $gallery, Image $image, Video $video) |
|
25 | + { |
|
26 | + $this->gallery = $gallery; |
|
27 | + $this->image = $image; |
|
28 | + $this->video = $video; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param string $name |
|
33 | - * @return string|void |
|
34 | - * @throws BadMethodCallException |
|
35 | - */ |
|
36 | - public function __call($name, array $args) |
|
37 | - { |
|
38 | - $mediaType = $this->validateMethod($name); |
|
39 | - $args = $this->validateArgs($args, $mediaType); |
|
31 | + /** |
|
32 | + * @param string $name |
|
33 | + * @return string|void |
|
34 | + * @throws BadMethodCallException |
|
35 | + */ |
|
36 | + public function __call($name, array $args) |
|
37 | + { |
|
38 | + $mediaType = $this->validateMethod($name); |
|
39 | + $args = $this->validateArgs($args, $mediaType); |
|
40 | 40 | |
41 | - if (str_replace($mediaType, '', strtolower($name))) { |
|
42 | - return $this->$mediaType->get($args[0])->$mediaType; |
|
43 | - } |
|
44 | - return !empty($args[1]) |
|
45 | - ? $this->$mediaType->get($args[0])->render($args[1]) |
|
46 | - : $this->$mediaType->get($args[0])->render(); |
|
47 | - } |
|
41 | + if (str_replace($mediaType, '', strtolower($name))) { |
|
42 | + return $this->$mediaType->get($args[0])->$mediaType; |
|
43 | + } |
|
44 | + return !empty($args[1]) |
|
45 | + ? $this->$mediaType->get($args[0])->render($args[1]) |
|
46 | + : $this->$mediaType->get($args[0])->render(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string $name |
|
51 | - * @param mixed $args |
|
52 | - * @return mixed |
|
53 | - * @throws BadMethodCallException |
|
54 | - */ |
|
55 | - public function get($name, $args = []) |
|
56 | - { |
|
57 | - $mediaType = $this->validateMethod($name); |
|
58 | - return $this->$mediaType->get($args)->$mediaType; |
|
59 | - } |
|
49 | + /** |
|
50 | + * @param string $name |
|
51 | + * @param mixed $args |
|
52 | + * @return mixed |
|
53 | + * @throws BadMethodCallException |
|
54 | + */ |
|
55 | + public function get($name, $args = []) |
|
56 | + { |
|
57 | + $mediaType = $this->validateMethod($name); |
|
58 | + return $this->$mediaType->get($args)->$mediaType; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param string $name |
|
63 | - * @return array |
|
64 | - * @throws BadMethodCallException |
|
65 | - */ |
|
66 | - protected function validateArgs(array $args, $name) |
|
67 | - { |
|
68 | - if (!count($args) && 'image' == $name) { |
|
69 | - $args[] = get_post_thumbnail_id(); |
|
70 | - } |
|
71 | - if (count($args)) { |
|
72 | - return $args; |
|
73 | - } |
|
74 | - throw new BadMethodCallException(sprintf('Missing arguments for: %s', $name)); |
|
75 | - } |
|
61 | + /** |
|
62 | + * @param string $name |
|
63 | + * @return array |
|
64 | + * @throws BadMethodCallException |
|
65 | + */ |
|
66 | + protected function validateArgs(array $args, $name) |
|
67 | + { |
|
68 | + if (!count($args) && 'image' == $name) { |
|
69 | + $args[] = get_post_thumbnail_id(); |
|
70 | + } |
|
71 | + if (count($args)) { |
|
72 | + return $args; |
|
73 | + } |
|
74 | + throw new BadMethodCallException(sprintf('Missing arguments for: %s', $name)); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param string $name |
|
79 | - * @return string|false |
|
80 | - * @throws BadMethodCallException |
|
81 | - */ |
|
82 | - protected function validateMethod($name) |
|
83 | - { |
|
84 | - foreach ([$name, strtolower(substr($name, 3))] as $method) { |
|
85 | - if (property_exists($this, $method) && is_object($this->$method)) { |
|
86 | - return $method; |
|
87 | - } |
|
88 | - } |
|
89 | - throw new BadMethodCallException(sprintf('Not a valid method: %s', $name)); |
|
90 | - } |
|
77 | + /** |
|
78 | + * @param string $name |
|
79 | + * @return string|false |
|
80 | + * @throws BadMethodCallException |
|
81 | + */ |
|
82 | + protected function validateMethod($name) |
|
83 | + { |
|
84 | + foreach ([$name, strtolower(substr($name, 3))] as $method) { |
|
85 | + if (property_exists($this, $method) && is_object($this->$method)) { |
|
86 | + return $method; |
|
87 | + } |
|
88 | + } |
|
89 | + throw new BadMethodCallException(sprintf('Not a valid method: %s', $name)); |
|
90 | + } |
|
91 | 91 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | protected $image; |
22 | 22 | protected $video; |
23 | 23 | |
24 | - public function __construct(Gallery $gallery, Image $image, Video $video) |
|
24 | + public function __construct( Gallery $gallery, Image $image, Video $video ) |
|
25 | 25 | { |
26 | 26 | $this->gallery = $gallery; |
27 | 27 | $this->image = $image; |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | * @return string|void |
34 | 34 | * @throws BadMethodCallException |
35 | 35 | */ |
36 | - public function __call($name, array $args) |
|
36 | + public function __call( $name, array $args ) |
|
37 | 37 | { |
38 | - $mediaType = $this->validateMethod($name); |
|
39 | - $args = $this->validateArgs($args, $mediaType); |
|
38 | + $mediaType = $this->validateMethod( $name ); |
|
39 | + $args = $this->validateArgs( $args, $mediaType ); |
|
40 | 40 | |
41 | - if (str_replace($mediaType, '', strtolower($name))) { |
|
42 | - return $this->$mediaType->get($args[0])->$mediaType; |
|
41 | + if( str_replace( $mediaType, '', strtolower( $name ) ) ) { |
|
42 | + return $this->$mediaType->get( $args[0] )->$mediaType; |
|
43 | 43 | } |
44 | - return !empty($args[1]) |
|
45 | - ? $this->$mediaType->get($args[0])->render($args[1]) |
|
46 | - : $this->$mediaType->get($args[0])->render(); |
|
44 | + return !empty( $args[1] ) |
|
45 | + ? $this->$mediaType->get( $args[0] )->render( $args[1] ) |
|
46 | + : $this->$mediaType->get( $args[0] )->render(); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * @return mixed |
53 | 53 | * @throws BadMethodCallException |
54 | 54 | */ |
55 | - public function get($name, $args = []) |
|
55 | + public function get( $name, $args = [] ) |
|
56 | 56 | { |
57 | - $mediaType = $this->validateMethod($name); |
|
58 | - return $this->$mediaType->get($args)->$mediaType; |
|
57 | + $mediaType = $this->validateMethod( $name ); |
|
58 | + return $this->$mediaType->get( $args )->$mediaType; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | * @return array |
64 | 64 | * @throws BadMethodCallException |
65 | 65 | */ |
66 | - protected function validateArgs(array $args, $name) |
|
66 | + protected function validateArgs( array $args, $name ) |
|
67 | 67 | { |
68 | - if (!count($args) && 'image' == $name) { |
|
68 | + if( !count( $args ) && 'image' == $name ) { |
|
69 | 69 | $args[] = get_post_thumbnail_id(); |
70 | 70 | } |
71 | - if (count($args)) { |
|
71 | + if( count( $args ) ) { |
|
72 | 72 | return $args; |
73 | 73 | } |
74 | - throw new BadMethodCallException(sprintf('Missing arguments for: %s', $name)); |
|
74 | + throw new BadMethodCallException( sprintf( 'Missing arguments for: %s', $name ) ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | * @return string|false |
80 | 80 | * @throws BadMethodCallException |
81 | 81 | */ |
82 | - protected function validateMethod($name) |
|
82 | + protected function validateMethod( $name ) |
|
83 | 83 | { |
84 | - foreach ([$name, strtolower(substr($name, 3))] as $method) { |
|
85 | - if (property_exists($this, $method) && is_object($this->$method)) { |
|
84 | + foreach( [$name, strtolower( substr( $name, 3 ) )] as $method ) { |
|
85 | + if( property_exists( $this, $method ) && is_object( $this->$method ) ) { |
|
86 | 86 | return $method; |
87 | 87 | } |
88 | 88 | } |
89 | - throw new BadMethodCallException(sprintf('Not a valid method: %s', $name)); |
|
89 | + throw new BadMethodCallException( sprintf( 'Not a valid method: %s', $name ) ); |
|
90 | 90 | } |
91 | 91 | } |
@@ -15,8 +15,7 @@ |
||
15 | 15 | * @method object|void getImage( int|string $attachment ) |
16 | 16 | * @method object|void getVideo( string|array $args ) |
17 | 17 | */ |
18 | -class Media |
|
19 | -{ |
|
18 | +class Media { |
|
20 | 19 | protected $gallery; |
21 | 20 | protected $image; |
22 | 21 | protected $video; |
@@ -4,178 +4,178 @@ |
||
4 | 4 | |
5 | 5 | class Utility |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function buildAttributes(array $atts = []) |
|
11 | - { |
|
12 | - $attributes = []; |
|
13 | - foreach ($atts as $key => $value) { |
|
14 | - $attributes[] = sprintf('%s="%s"', $key, $value); |
|
15 | - } |
|
16 | - return implode(' ', $attributes); |
|
17 | - } |
|
18 | - |
|
19 | - /** |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public function buildAttributesFor($tag, array $atts = []) |
|
23 | - { |
|
24 | - return $this->buildAttributes( |
|
25 | - wp_parse_args($atts, apply_filters("castor/render/$tag/attributes", [])) |
|
26 | - ); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @param string $name |
|
31 | - * @param string $path |
|
32 | - * |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function buildClassName($name, $path = '') |
|
36 | - { |
|
37 | - $className = array_map('ucfirst', array_map('strtolower', (array) preg_split('/[-_]/', $name))); |
|
38 | - $className = implode('', $className); |
|
39 | - |
|
40 | - return !empty($path) |
|
41 | - ? str_replace('\\\\', '\\', sprintf('%s\%s', $path, $className)) |
|
42 | - : $className; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param string $name |
|
47 | - * @param string $prefix |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function buildMethodName($name, $prefix = 'get') |
|
52 | - { |
|
53 | - return lcfirst($this->buildClassName($prefix.'-'.$name)); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $needle |
|
58 | - * @param string $haystack |
|
59 | - * |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function contains($needle, $haystack) |
|
63 | - { |
|
64 | - false !== strpos($haystack, $needle); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @param string $suffix |
|
69 | - * @param string $string |
|
70 | - * @param bool $unique |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function endWith($suffix, $string, $unique = true) |
|
75 | - { |
|
76 | - return $unique && $this->endsWith($suffix, $string) |
|
77 | - ? $string |
|
78 | - : $string.$suffix; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $needle |
|
83 | - * @param string $haystack |
|
84 | - * |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function endsWith($needle, $haystack) |
|
88 | - { |
|
89 | - $length = strlen($needle); |
|
90 | - return 0 != $length |
|
91 | - ? substr($haystack, -$length) === $needle |
|
92 | - : true; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @param string $tag |
|
97 | - * @param string $value |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public function printTag($tag, $value, array $attributes = []) |
|
102 | - { |
|
103 | - $attributes = $this->buildAttributesFor($tag, $attributes); |
|
104 | - |
|
105 | - printf('<%s>%s</%s>', |
|
106 | - rtrim(sprintf('%s %s', $tag, $attributes)), |
|
107 | - $value, |
|
108 | - $tag |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @param string $prefix |
|
114 | - * @param string $string |
|
115 | - * @param bool $unique |
|
116 | - * |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public function startWith($prefix, $string, $unique = true) |
|
120 | - { |
|
121 | - return $unique && $this->startsWith($prefix, $string) |
|
122 | - ? $string |
|
123 | - : $prefix.$string; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $needle |
|
128 | - * @param string $haystack |
|
129 | - * |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - public function startsWith($needle, $haystack) |
|
133 | - { |
|
134 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @param mixed $value |
|
139 | - * |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - public function toArray($value) |
|
143 | - { |
|
144 | - if (is_string($value)) { |
|
145 | - $value = trim($value); |
|
146 | - } |
|
147 | - return array_filter((array) $value); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $string |
|
152 | - * @param string $needle |
|
153 | - * @param bool $caseSensitive |
|
154 | - * |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function trimLeft($string, $needle, $caseSensitive = true) |
|
158 | - { |
|
159 | - $strPos = $caseSensitive ? 'strpos' : 'stripos'; |
|
160 | - if (0 === $strPos($string, $needle)) { |
|
161 | - $string = substr($string, strlen($needle)); |
|
162 | - } |
|
163 | - return $string; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $string |
|
168 | - * @param string $needle |
|
169 | - * @param bool $caseSensitive |
|
170 | - * |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public function trimRight($string, $needle, $caseSensitive = true) |
|
174 | - { |
|
175 | - $strPos = $caseSensitive ? 'strpos' : 'stripos'; |
|
176 | - if (false !== $strPos($string, $needle, strlen($string) - strlen($needle))) { |
|
177 | - $string = substr($string, 0, -strlen($needle)); |
|
178 | - } |
|
179 | - return $string; |
|
180 | - } |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function buildAttributes(array $atts = []) |
|
11 | + { |
|
12 | + $attributes = []; |
|
13 | + foreach ($atts as $key => $value) { |
|
14 | + $attributes[] = sprintf('%s="%s"', $key, $value); |
|
15 | + } |
|
16 | + return implode(' ', $attributes); |
|
17 | + } |
|
18 | + |
|
19 | + /** |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public function buildAttributesFor($tag, array $atts = []) |
|
23 | + { |
|
24 | + return $this->buildAttributes( |
|
25 | + wp_parse_args($atts, apply_filters("castor/render/$tag/attributes", [])) |
|
26 | + ); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @param string $name |
|
31 | + * @param string $path |
|
32 | + * |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function buildClassName($name, $path = '') |
|
36 | + { |
|
37 | + $className = array_map('ucfirst', array_map('strtolower', (array) preg_split('/[-_]/', $name))); |
|
38 | + $className = implode('', $className); |
|
39 | + |
|
40 | + return !empty($path) |
|
41 | + ? str_replace('\\\\', '\\', sprintf('%s\%s', $path, $className)) |
|
42 | + : $className; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param string $name |
|
47 | + * @param string $prefix |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function buildMethodName($name, $prefix = 'get') |
|
52 | + { |
|
53 | + return lcfirst($this->buildClassName($prefix.'-'.$name)); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $needle |
|
58 | + * @param string $haystack |
|
59 | + * |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function contains($needle, $haystack) |
|
63 | + { |
|
64 | + false !== strpos($haystack, $needle); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @param string $suffix |
|
69 | + * @param string $string |
|
70 | + * @param bool $unique |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function endWith($suffix, $string, $unique = true) |
|
75 | + { |
|
76 | + return $unique && $this->endsWith($suffix, $string) |
|
77 | + ? $string |
|
78 | + : $string.$suffix; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $needle |
|
83 | + * @param string $haystack |
|
84 | + * |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function endsWith($needle, $haystack) |
|
88 | + { |
|
89 | + $length = strlen($needle); |
|
90 | + return 0 != $length |
|
91 | + ? substr($haystack, -$length) === $needle |
|
92 | + : true; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @param string $tag |
|
97 | + * @param string $value |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public function printTag($tag, $value, array $attributes = []) |
|
102 | + { |
|
103 | + $attributes = $this->buildAttributesFor($tag, $attributes); |
|
104 | + |
|
105 | + printf('<%s>%s</%s>', |
|
106 | + rtrim(sprintf('%s %s', $tag, $attributes)), |
|
107 | + $value, |
|
108 | + $tag |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @param string $prefix |
|
114 | + * @param string $string |
|
115 | + * @param bool $unique |
|
116 | + * |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public function startWith($prefix, $string, $unique = true) |
|
120 | + { |
|
121 | + return $unique && $this->startsWith($prefix, $string) |
|
122 | + ? $string |
|
123 | + : $prefix.$string; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $needle |
|
128 | + * @param string $haystack |
|
129 | + * |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + public function startsWith($needle, $haystack) |
|
133 | + { |
|
134 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @param mixed $value |
|
139 | + * |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + public function toArray($value) |
|
143 | + { |
|
144 | + if (is_string($value)) { |
|
145 | + $value = trim($value); |
|
146 | + } |
|
147 | + return array_filter((array) $value); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $string |
|
152 | + * @param string $needle |
|
153 | + * @param bool $caseSensitive |
|
154 | + * |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function trimLeft($string, $needle, $caseSensitive = true) |
|
158 | + { |
|
159 | + $strPos = $caseSensitive ? 'strpos' : 'stripos'; |
|
160 | + if (0 === $strPos($string, $needle)) { |
|
161 | + $string = substr($string, strlen($needle)); |
|
162 | + } |
|
163 | + return $string; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $string |
|
168 | + * @param string $needle |
|
169 | + * @param bool $caseSensitive |
|
170 | + * |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public function trimRight($string, $needle, $caseSensitive = true) |
|
174 | + { |
|
175 | + $strPos = $caseSensitive ? 'strpos' : 'stripos'; |
|
176 | + if (false !== $strPos($string, $needle, strlen($string) - strlen($needle))) { |
|
177 | + $string = substr($string, 0, -strlen($needle)); |
|
178 | + } |
|
179 | + return $string; |
|
180 | + } |
|
181 | 181 | } |
@@ -7,22 +7,22 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * @return string |
9 | 9 | */ |
10 | - public function buildAttributes(array $atts = []) |
|
10 | + public function buildAttributes( array $atts = [] ) |
|
11 | 11 | { |
12 | 12 | $attributes = []; |
13 | - foreach ($atts as $key => $value) { |
|
14 | - $attributes[] = sprintf('%s="%s"', $key, $value); |
|
13 | + foreach( $atts as $key => $value ) { |
|
14 | + $attributes[] = sprintf( '%s="%s"', $key, $value ); |
|
15 | 15 | } |
16 | - return implode(' ', $attributes); |
|
16 | + return implode( ' ', $attributes ); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @return string |
21 | 21 | */ |
22 | - public function buildAttributesFor($tag, array $atts = []) |
|
22 | + public function buildAttributesFor( $tag, array $atts = [] ) |
|
23 | 23 | { |
24 | 24 | return $this->buildAttributes( |
25 | - wp_parse_args($atts, apply_filters("castor/render/$tag/attributes", [])) |
|
25 | + wp_parse_args( $atts, apply_filters( "castor/render/$tag/attributes", [] ) ) |
|
26 | 26 | ); |
27 | 27 | } |
28 | 28 | |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return string |
34 | 34 | */ |
35 | - public function buildClassName($name, $path = '') |
|
35 | + public function buildClassName( $name, $path = '' ) |
|
36 | 36 | { |
37 | - $className = array_map('ucfirst', array_map('strtolower', (array) preg_split('/[-_]/', $name))); |
|
38 | - $className = implode('', $className); |
|
37 | + $className = array_map( 'ucfirst', array_map( 'strtolower', (array) preg_split( '/[-_]/', $name ) ) ); |
|
38 | + $className = implode( '', $className ); |
|
39 | 39 | |
40 | - return !empty($path) |
|
41 | - ? str_replace('\\\\', '\\', sprintf('%s\%s', $path, $className)) |
|
40 | + return !empty( $path ) |
|
41 | + ? str_replace( '\\\\', '\\', sprintf( '%s\%s', $path, $className ) ) |
|
42 | 42 | : $className; |
43 | 43 | } |
44 | 44 | |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - public function buildMethodName($name, $prefix = 'get') |
|
51 | + public function buildMethodName( $name, $prefix = 'get' ) |
|
52 | 52 | { |
53 | - return lcfirst($this->buildClassName($prefix.'-'.$name)); |
|
53 | + return lcfirst( $this->buildClassName( $prefix.'-'.$name ) ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function contains($needle, $haystack) |
|
62 | + public function contains( $needle, $haystack ) |
|
63 | 63 | { |
64 | - false !== strpos($haystack, $needle); |
|
64 | + false !== strpos( $haystack, $needle ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string |
73 | 73 | */ |
74 | - public function endWith($suffix, $string, $unique = true) |
|
74 | + public function endWith( $suffix, $string, $unique = true ) |
|
75 | 75 | { |
76 | - return $unique && $this->endsWith($suffix, $string) |
|
76 | + return $unique && $this->endsWith( $suffix, $string ) |
|
77 | 77 | ? $string |
78 | 78 | : $string.$suffix; |
79 | 79 | } |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return bool |
86 | 86 | */ |
87 | - public function endsWith($needle, $haystack) |
|
87 | + public function endsWith( $needle, $haystack ) |
|
88 | 88 | { |
89 | - $length = strlen($needle); |
|
89 | + $length = strlen( $needle ); |
|
90 | 90 | return 0 != $length |
91 | - ? substr($haystack, -$length) === $needle |
|
91 | + ? substr( $haystack, -$length ) === $needle |
|
92 | 92 | : true; |
93 | 93 | } |
94 | 94 | |
@@ -98,12 +98,12 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @return void |
100 | 100 | */ |
101 | - public function printTag($tag, $value, array $attributes = []) |
|
101 | + public function printTag( $tag, $value, array $attributes = [] ) |
|
102 | 102 | { |
103 | - $attributes = $this->buildAttributesFor($tag, $attributes); |
|
103 | + $attributes = $this->buildAttributesFor( $tag, $attributes ); |
|
104 | 104 | |
105 | - printf('<%s>%s</%s>', |
|
106 | - rtrim(sprintf('%s %s', $tag, $attributes)), |
|
105 | + printf( '<%s>%s</%s>', |
|
106 | + rtrim( sprintf( '%s %s', $tag, $attributes ) ), |
|
107 | 107 | $value, |
108 | 108 | $tag |
109 | 109 | ); |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return string |
118 | 118 | */ |
119 | - public function startWith($prefix, $string, $unique = true) |
|
119 | + public function startWith( $prefix, $string, $unique = true ) |
|
120 | 120 | { |
121 | - return $unique && $this->startsWith($prefix, $string) |
|
121 | + return $unique && $this->startsWith( $prefix, $string ) |
|
122 | 122 | ? $string |
123 | 123 | : $prefix.$string; |
124 | 124 | } |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return bool |
131 | 131 | */ |
132 | - public function startsWith($needle, $haystack) |
|
132 | + public function startsWith( $needle, $haystack ) |
|
133 | 133 | { |
134 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
134 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,12 +139,12 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - public function toArray($value) |
|
142 | + public function toArray( $value ) |
|
143 | 143 | { |
144 | - if (is_string($value)) { |
|
145 | - $value = trim($value); |
|
144 | + if( is_string( $value ) ) { |
|
145 | + $value = trim( $value ); |
|
146 | 146 | } |
147 | - return array_filter((array) $value); |
|
147 | + return array_filter( (array) $value ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return string |
156 | 156 | */ |
157 | - public function trimLeft($string, $needle, $caseSensitive = true) |
|
157 | + public function trimLeft( $string, $needle, $caseSensitive = true ) |
|
158 | 158 | { |
159 | 159 | $strPos = $caseSensitive ? 'strpos' : 'stripos'; |
160 | - if (0 === $strPos($string, $needle)) { |
|
161 | - $string = substr($string, strlen($needle)); |
|
160 | + if( 0 === $strPos( $string, $needle ) ) { |
|
161 | + $string = substr( $string, strlen( $needle ) ); |
|
162 | 162 | } |
163 | 163 | return $string; |
164 | 164 | } |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return string |
172 | 172 | */ |
173 | - public function trimRight($string, $needle, $caseSensitive = true) |
|
173 | + public function trimRight( $string, $needle, $caseSensitive = true ) |
|
174 | 174 | { |
175 | 175 | $strPos = $caseSensitive ? 'strpos' : 'stripos'; |
176 | - if (false !== $strPos($string, $needle, strlen($string) - strlen($needle))) { |
|
177 | - $string = substr($string, 0, -strlen($needle)); |
|
176 | + if( false !== $strPos( $string, $needle, strlen( $string ) - strlen( $needle ) ) ) { |
|
177 | + $string = substr( $string, 0, -strlen( $needle ) ); |
|
178 | 178 | } |
179 | 179 | return $string; |
180 | 180 | } |
@@ -2,8 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace GeminiLabs\Castor\Helpers; |
4 | 4 | |
5 | -class Utility |
|
6 | -{ |
|
5 | +class Utility { |
|
7 | 6 | /** |
8 | 7 | * @return string |
9 | 8 | */ |
@@ -7,184 +7,184 @@ |
||
7 | 7 | |
8 | 8 | class Log |
9 | 9 | { |
10 | - const EMERGENCY = 'emergency'; |
|
11 | - const ALERT = 'alert'; |
|
12 | - const CRITICAL = 'critical'; |
|
13 | - const ERROR = 'error'; |
|
14 | - const WARNING = 'warning'; |
|
15 | - const NOTICE = 'notice'; |
|
16 | - const INFO = 'info'; |
|
17 | - const DEBUG = 'debug'; |
|
18 | - |
|
19 | - protected $file; |
|
20 | - protected $log; |
|
21 | - |
|
22 | - public function __construct($filename) |
|
23 | - { |
|
24 | - $this->file = $filename; |
|
25 | - $this->log = file_exists($filename) |
|
26 | - ? file_get_contents($filename) |
|
27 | - : ''; |
|
28 | - } |
|
29 | - |
|
30 | - public function __toString() |
|
31 | - { |
|
32 | - return $this->log; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Action must be taken immediately. |
|
37 | - * Example: Entire website down, database unavailable, etc. This should |
|
38 | - * trigger the SMS alerts and wake you up. |
|
39 | - * |
|
40 | - * @param string $message |
|
41 | - * @param array $context |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function alert($message, array $context = []) |
|
45 | - { |
|
46 | - $this->log(static::ALERT, $message, $context); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function clear() |
|
53 | - { |
|
54 | - $this->log = ''; |
|
55 | - file_put_contents($this->file, $this->log); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Critical conditions. |
|
60 | - * Example: Application component unavailable, unexpected exception. |
|
61 | - * |
|
62 | - * @param string $message |
|
63 | - * @param array $context |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function critical($message, array $context = []) |
|
67 | - { |
|
68 | - $this->log(static::CRITICAL, $message, $context); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Detailed debug information. |
|
73 | - * |
|
74 | - * @param string $message |
|
75 | - * @param array $context |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public function debug($message, array $context = []) |
|
79 | - { |
|
80 | - $this->log(static::DEBUG, $message, $context); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * System is unusable. |
|
85 | - * |
|
86 | - * @param string $message |
|
87 | - * @param array $context |
|
88 | - * @return void |
|
89 | - */ |
|
90 | - public function emergency($message, array $context = []) |
|
91 | - { |
|
92 | - $this->log(static::EMERGENCY, $message, $context); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Runtime errors that do not require immediate action but should typically |
|
97 | - * be logged and monitored. |
|
98 | - * |
|
99 | - * @param string $message |
|
100 | - * @param array $context |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - public function error($message, array $context = []) |
|
104 | - { |
|
105 | - $this->log(static::ERROR, $message, $context); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Interesting events. |
|
110 | - * Example: User logs in, SQL logs. |
|
111 | - * |
|
112 | - * @param string $message |
|
113 | - * @param array $context |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public function info($message, array $context = []) |
|
117 | - { |
|
118 | - $this->log(static::INFO, $message, $context); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Normal but significant events. |
|
123 | - * |
|
124 | - * @param string $message |
|
125 | - * @param array $context |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - public function notice($message, array $context = []) |
|
129 | - { |
|
130 | - $this->log(static::NOTICE, $message, $context); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Exceptional occurrences that are not errors. |
|
135 | - * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
136 | - * that are not necessarily wrong. |
|
137 | - * |
|
138 | - * @param string $message |
|
139 | - * @param array $context |
|
140 | - * @return void |
|
141 | - */ |
|
142 | - public function warning($message, array $context = []) |
|
143 | - { |
|
144 | - $this->log(static::WARNING, $message, $context); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param string $message |
|
149 | - * @param array $context |
|
150 | - * @return array|string |
|
151 | - */ |
|
152 | - protected function interpolate($message, array $context = []) |
|
153 | - { |
|
154 | - if (is_array($message)) { |
|
155 | - return htmlspecialchars(print_r($message, true), ENT_QUOTES, 'UTF-8'); |
|
156 | - } |
|
157 | - $replace = []; |
|
158 | - foreach ($context as $key => $val) { |
|
159 | - if (is_object($val) && 'DateTime' === get_class($val)) { |
|
160 | - $val = $val->format('Y-m-d H:i:s'); |
|
161 | - } elseif (is_object($val) || is_array($val)) { |
|
162 | - $val = json_encode($val); |
|
163 | - } elseif (is_resource($val)) { |
|
164 | - $val = (string) $val; |
|
165 | - } |
|
166 | - $replace['{'.$key.'}'] = $val; |
|
167 | - } |
|
168 | - return strtr($message, $replace); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param mixed $level |
|
173 | - * @param string $message |
|
174 | - * @param array $context |
|
175 | - * @return void |
|
176 | - */ |
|
177 | - protected function log($level, $message, array $context = []) |
|
178 | - { |
|
179 | - if (!in_array($level, (new ReflectionClass(__NAMESPACE__.'\Log'))->getConstants(), true) |
|
180 | - || !DevelopmentFacade::isDev() |
|
181 | - ) { |
|
182 | - return; |
|
183 | - } |
|
184 | - $date = get_date_from_gmt(gmdate('Y-m-d H:i:s')); |
|
185 | - $level = strtoupper($level); |
|
186 | - $message = $this->interpolate($message, $context); |
|
187 | - $entry = "[$date] $level: $message".PHP_EOL; |
|
188 | - file_put_contents($this->file, $entry, FILE_APPEND | LOCK_EX); |
|
189 | - } |
|
10 | + const EMERGENCY = 'emergency'; |
|
11 | + const ALERT = 'alert'; |
|
12 | + const CRITICAL = 'critical'; |
|
13 | + const ERROR = 'error'; |
|
14 | + const WARNING = 'warning'; |
|
15 | + const NOTICE = 'notice'; |
|
16 | + const INFO = 'info'; |
|
17 | + const DEBUG = 'debug'; |
|
18 | + |
|
19 | + protected $file; |
|
20 | + protected $log; |
|
21 | + |
|
22 | + public function __construct($filename) |
|
23 | + { |
|
24 | + $this->file = $filename; |
|
25 | + $this->log = file_exists($filename) |
|
26 | + ? file_get_contents($filename) |
|
27 | + : ''; |
|
28 | + } |
|
29 | + |
|
30 | + public function __toString() |
|
31 | + { |
|
32 | + return $this->log; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Action must be taken immediately. |
|
37 | + * Example: Entire website down, database unavailable, etc. This should |
|
38 | + * trigger the SMS alerts and wake you up. |
|
39 | + * |
|
40 | + * @param string $message |
|
41 | + * @param array $context |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function alert($message, array $context = []) |
|
45 | + { |
|
46 | + $this->log(static::ALERT, $message, $context); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function clear() |
|
53 | + { |
|
54 | + $this->log = ''; |
|
55 | + file_put_contents($this->file, $this->log); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Critical conditions. |
|
60 | + * Example: Application component unavailable, unexpected exception. |
|
61 | + * |
|
62 | + * @param string $message |
|
63 | + * @param array $context |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function critical($message, array $context = []) |
|
67 | + { |
|
68 | + $this->log(static::CRITICAL, $message, $context); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Detailed debug information. |
|
73 | + * |
|
74 | + * @param string $message |
|
75 | + * @param array $context |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public function debug($message, array $context = []) |
|
79 | + { |
|
80 | + $this->log(static::DEBUG, $message, $context); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * System is unusable. |
|
85 | + * |
|
86 | + * @param string $message |
|
87 | + * @param array $context |
|
88 | + * @return void |
|
89 | + */ |
|
90 | + public function emergency($message, array $context = []) |
|
91 | + { |
|
92 | + $this->log(static::EMERGENCY, $message, $context); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Runtime errors that do not require immediate action but should typically |
|
97 | + * be logged and monitored. |
|
98 | + * |
|
99 | + * @param string $message |
|
100 | + * @param array $context |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + public function error($message, array $context = []) |
|
104 | + { |
|
105 | + $this->log(static::ERROR, $message, $context); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Interesting events. |
|
110 | + * Example: User logs in, SQL logs. |
|
111 | + * |
|
112 | + * @param string $message |
|
113 | + * @param array $context |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public function info($message, array $context = []) |
|
117 | + { |
|
118 | + $this->log(static::INFO, $message, $context); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Normal but significant events. |
|
123 | + * |
|
124 | + * @param string $message |
|
125 | + * @param array $context |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + public function notice($message, array $context = []) |
|
129 | + { |
|
130 | + $this->log(static::NOTICE, $message, $context); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Exceptional occurrences that are not errors. |
|
135 | + * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
136 | + * that are not necessarily wrong. |
|
137 | + * |
|
138 | + * @param string $message |
|
139 | + * @param array $context |
|
140 | + * @return void |
|
141 | + */ |
|
142 | + public function warning($message, array $context = []) |
|
143 | + { |
|
144 | + $this->log(static::WARNING, $message, $context); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param string $message |
|
149 | + * @param array $context |
|
150 | + * @return array|string |
|
151 | + */ |
|
152 | + protected function interpolate($message, array $context = []) |
|
153 | + { |
|
154 | + if (is_array($message)) { |
|
155 | + return htmlspecialchars(print_r($message, true), ENT_QUOTES, 'UTF-8'); |
|
156 | + } |
|
157 | + $replace = []; |
|
158 | + foreach ($context as $key => $val) { |
|
159 | + if (is_object($val) && 'DateTime' === get_class($val)) { |
|
160 | + $val = $val->format('Y-m-d H:i:s'); |
|
161 | + } elseif (is_object($val) || is_array($val)) { |
|
162 | + $val = json_encode($val); |
|
163 | + } elseif (is_resource($val)) { |
|
164 | + $val = (string) $val; |
|
165 | + } |
|
166 | + $replace['{'.$key.'}'] = $val; |
|
167 | + } |
|
168 | + return strtr($message, $replace); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param mixed $level |
|
173 | + * @param string $message |
|
174 | + * @param array $context |
|
175 | + * @return void |
|
176 | + */ |
|
177 | + protected function log($level, $message, array $context = []) |
|
178 | + { |
|
179 | + if (!in_array($level, (new ReflectionClass(__NAMESPACE__.'\Log'))->getConstants(), true) |
|
180 | + || !DevelopmentFacade::isDev() |
|
181 | + ) { |
|
182 | + return; |
|
183 | + } |
|
184 | + $date = get_date_from_gmt(gmdate('Y-m-d H:i:s')); |
|
185 | + $level = strtoupper($level); |
|
186 | + $message = $this->interpolate($message, $context); |
|
187 | + $entry = "[$date] $level: $message".PHP_EOL; |
|
188 | + file_put_contents($this->file, $entry, FILE_APPEND | LOCK_EX); |
|
189 | + } |
|
190 | 190 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | protected $file; |
20 | 20 | protected $log; |
21 | 21 | |
22 | - public function __construct($filename) |
|
22 | + public function __construct( $filename ) |
|
23 | 23 | { |
24 | 24 | $this->file = $filename; |
25 | - $this->log = file_exists($filename) |
|
26 | - ? file_get_contents($filename) |
|
25 | + $this->log = file_exists( $filename ) |
|
26 | + ? file_get_contents( $filename ) |
|
27 | 27 | : ''; |
28 | 28 | } |
29 | 29 | |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | * @param array $context |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - public function alert($message, array $context = []) |
|
44 | + public function alert( $message, array $context = [] ) |
|
45 | 45 | { |
46 | - $this->log(static::ALERT, $message, $context); |
|
46 | + $this->log( static::ALERT, $message, $context ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public function clear() |
53 | 53 | { |
54 | 54 | $this->log = ''; |
55 | - file_put_contents($this->file, $this->log); |
|
55 | + file_put_contents( $this->file, $this->log ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | * @param array $context |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - public function critical($message, array $context = []) |
|
66 | + public function critical( $message, array $context = [] ) |
|
67 | 67 | { |
68 | - $this->log(static::CRITICAL, $message, $context); |
|
68 | + $this->log( static::CRITICAL, $message, $context ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * @param array $context |
76 | 76 | * @return void |
77 | 77 | */ |
78 | - public function debug($message, array $context = []) |
|
78 | + public function debug( $message, array $context = [] ) |
|
79 | 79 | { |
80 | - $this->log(static::DEBUG, $message, $context); |
|
80 | + $this->log( static::DEBUG, $message, $context ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param array $context |
88 | 88 | * @return void |
89 | 89 | */ |
90 | - public function emergency($message, array $context = []) |
|
90 | + public function emergency( $message, array $context = [] ) |
|
91 | 91 | { |
92 | - $this->log(static::EMERGENCY, $message, $context); |
|
92 | + $this->log( static::EMERGENCY, $message, $context ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param array $context |
101 | 101 | * @return void |
102 | 102 | */ |
103 | - public function error($message, array $context = []) |
|
103 | + public function error( $message, array $context = [] ) |
|
104 | 104 | { |
105 | - $this->log(static::ERROR, $message, $context); |
|
105 | + $this->log( static::ERROR, $message, $context ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * @param array $context |
114 | 114 | * @return void |
115 | 115 | */ |
116 | - public function info($message, array $context = []) |
|
116 | + public function info( $message, array $context = [] ) |
|
117 | 117 | { |
118 | - $this->log(static::INFO, $message, $context); |
|
118 | + $this->log( static::INFO, $message, $context ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @param array $context |
126 | 126 | * @return void |
127 | 127 | */ |
128 | - public function notice($message, array $context = []) |
|
128 | + public function notice( $message, array $context = [] ) |
|
129 | 129 | { |
130 | - $this->log(static::NOTICE, $message, $context); |
|
130 | + $this->log( static::NOTICE, $message, $context ); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * @param array $context |
140 | 140 | * @return void |
141 | 141 | */ |
142 | - public function warning($message, array $context = []) |
|
142 | + public function warning( $message, array $context = [] ) |
|
143 | 143 | { |
144 | - $this->log(static::WARNING, $message, $context); |
|
144 | + $this->log( static::WARNING, $message, $context ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -149,23 +149,23 @@ discard block |
||
149 | 149 | * @param array $context |
150 | 150 | * @return array|string |
151 | 151 | */ |
152 | - protected function interpolate($message, array $context = []) |
|
152 | + protected function interpolate( $message, array $context = [] ) |
|
153 | 153 | { |
154 | - if (is_array($message)) { |
|
155 | - return htmlspecialchars(print_r($message, true), ENT_QUOTES, 'UTF-8'); |
|
154 | + if( is_array( $message ) ) { |
|
155 | + return htmlspecialchars( print_r( $message, true ), ENT_QUOTES, 'UTF-8' ); |
|
156 | 156 | } |
157 | 157 | $replace = []; |
158 | - foreach ($context as $key => $val) { |
|
159 | - if (is_object($val) && 'DateTime' === get_class($val)) { |
|
160 | - $val = $val->format('Y-m-d H:i:s'); |
|
161 | - } elseif (is_object($val) || is_array($val)) { |
|
162 | - $val = json_encode($val); |
|
163 | - } elseif (is_resource($val)) { |
|
158 | + foreach( $context as $key => $val ) { |
|
159 | + if( is_object( $val ) && 'DateTime' === get_class( $val ) ) { |
|
160 | + $val = $val->format( 'Y-m-d H:i:s' ); |
|
161 | + } elseif( is_object( $val ) || is_array( $val ) ) { |
|
162 | + $val = json_encode( $val ); |
|
163 | + } elseif( is_resource( $val ) ) { |
|
164 | 164 | $val = (string) $val; |
165 | 165 | } |
166 | 166 | $replace['{'.$key.'}'] = $val; |
167 | 167 | } |
168 | - return strtr($message, $replace); |
|
168 | + return strtr( $message, $replace ); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -174,17 +174,17 @@ discard block |
||
174 | 174 | * @param array $context |
175 | 175 | * @return void |
176 | 176 | */ |
177 | - protected function log($level, $message, array $context = []) |
|
177 | + protected function log( $level, $message, array $context = [] ) |
|
178 | 178 | { |
179 | - if (!in_array($level, (new ReflectionClass(__NAMESPACE__.'\Log'))->getConstants(), true) |
|
179 | + if( !in_array( $level, ( new ReflectionClass( __NAMESPACE__.'\Log' ) )->getConstants(), true ) |
|
180 | 180 | || !DevelopmentFacade::isDev() |
181 | 181 | ) { |
182 | 182 | return; |
183 | 183 | } |
184 | - $date = get_date_from_gmt(gmdate('Y-m-d H:i:s')); |
|
185 | - $level = strtoupper($level); |
|
186 | - $message = $this->interpolate($message, $context); |
|
184 | + $date = get_date_from_gmt( gmdate( 'Y-m-d H:i:s' ) ); |
|
185 | + $level = strtoupper( $level ); |
|
186 | + $message = $this->interpolate( $message, $context ); |
|
187 | 187 | $entry = "[$date] $level: $message".PHP_EOL; |
188 | - file_put_contents($this->file, $entry, FILE_APPEND | LOCK_EX); |
|
188 | + file_put_contents( $this->file, $entry, FILE_APPEND | LOCK_EX ); |
|
189 | 189 | } |
190 | 190 | } |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | use GeminiLabs\Castor\Facades\Development as DevelopmentFacade; |
6 | 6 | use ReflectionClass; |
7 | 7 | |
8 | -class Log |
|
9 | -{ |
|
8 | +class Log { |
|
10 | 9 | const EMERGENCY = 'emergency'; |
11 | 10 | const ALERT = 'alert'; |
12 | 11 | const CRITICAL = 'critical'; |
@@ -158,9 +157,11 @@ discard block |
||
158 | 157 | foreach ($context as $key => $val) { |
159 | 158 | if (is_object($val) && 'DateTime' === get_class($val)) { |
160 | 159 | $val = $val->format('Y-m-d H:i:s'); |
161 | - } elseif (is_object($val) || is_array($val)) { |
|
160 | + } |
|
161 | + elseif (is_object($val) || is_array($val)) { |
|
162 | 162 | $val = json_encode($val); |
163 | - } elseif (is_resource($val)) { |
|
163 | + } |
|
164 | + elseif (is_resource($val)) { |
|
164 | 165 | $val = (string) $val; |
165 | 166 | } |
166 | 167 | $replace['{'.$key.'}'] = $val; |
@@ -4,161 +4,161 @@ |
||
4 | 4 | |
5 | 5 | class Theme |
6 | 6 | { |
7 | - public $archiveMeta; |
|
8 | - public $postMeta; |
|
9 | - |
|
10 | - public function __construct(ArchiveMeta $archiveMeta, PostMeta $postMeta) |
|
11 | - { |
|
12 | - $this->archiveMeta = $archiveMeta; |
|
13 | - $this->postMeta = $postMeta; |
|
14 | - } |
|
15 | - |
|
16 | - /** |
|
17 | - * @param string $asset |
|
18 | - * |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public function assetPath($asset) |
|
22 | - { |
|
23 | - return $this->paths('dir.stylesheet').'assets/'.$asset; |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * @param string $asset |
|
28 | - * |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function assetUri($asset) |
|
32 | - { |
|
33 | - return $this->paths('uri.stylesheet').'assets/'.$asset; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function copyright() |
|
40 | - { |
|
41 | - return __('Copyright', 'castor').' © '.date('Y').', '.get_bloginfo('name'); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @return bool |
|
46 | - */ |
|
47 | - public function displaySidebar() |
|
48 | - { |
|
49 | - $conditions = [ |
|
50 | - is_archive(), |
|
51 | - is_home(), |
|
52 | - is_single(), |
|
53 | - ]; |
|
54 | - |
|
55 | - $display = in_array(true, $conditions); |
|
56 | - |
|
57 | - return apply_filters('castor/display/sidebar', $display); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param string $asset |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function imagePath($asset) |
|
66 | - { |
|
67 | - return $this->assetPath(castor_app()->imgDir.$asset); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param string $asset |
|
72 | - * |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function imageUri($asset) |
|
76 | - { |
|
77 | - return $this->assetUri(castor_app()->imgDir.$asset); |
|
78 | - } |
|
79 | - |
|
80 | - public function pageTitle() |
|
81 | - { |
|
82 | - foreach (['is_404', 'is_archive', 'is_home', 'is_page', 'is_search'] as $bool) { |
|
83 | - if (!$bool()) { |
|
84 | - continue; |
|
85 | - } |
|
86 | - $method = sprintf('get%sTitle', ucfirst(str_replace('is_', '', $bool))); |
|
87 | - return $this->$method(); |
|
88 | - } |
|
89 | - |
|
90 | - return get_the_title(); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string|null $path |
|
95 | - * |
|
96 | - * @return array|string |
|
97 | - */ |
|
98 | - public function paths($path = null) |
|
99 | - { |
|
100 | - $paths = [ |
|
101 | - 'dir.stylesheet' => get_stylesheet_directory(), |
|
102 | - 'dir.template' => get_template_directory(), |
|
103 | - 'dir.upload' => wp_upload_dir()['basedir'], |
|
104 | - 'uri.stylesheet' => get_stylesheet_directory_uri(), |
|
105 | - 'uri.template' => get_template_directory_uri(), |
|
106 | - ]; |
|
107 | - |
|
108 | - if (is_null($path)) { |
|
109 | - return $paths; |
|
110 | - } |
|
111 | - |
|
112 | - return array_key_exists($path, $paths) |
|
113 | - ? trailingslashit($paths[$path]) |
|
114 | - : ''; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string|null $path |
|
119 | - * @param string $class |
|
120 | - * @return string|null |
|
121 | - */ |
|
122 | - public function svg($path = null, $class = '') |
|
123 | - { |
|
124 | - if (!file_exists($this->imagePath($path))) { |
|
125 | - return; |
|
126 | - } |
|
127 | - $svg = file_get_contents($this->imagePath($path)); |
|
128 | - $pattern = '/(<svg.+)( class=[\'\"](|[^\'\"]+)[\'\"])(>.+)/i'; |
|
129 | - if (1 === preg_match($pattern, $svg, $matches)) { |
|
130 | - $class .= ' '.$matches[3]; |
|
131 | - $svg = preg_filter($pattern, '$1$4', $svg); |
|
132 | - } |
|
133 | - return str_replace('<svg', '<svg class="'.trim($class).'"', $svg); |
|
134 | - } |
|
135 | - |
|
136 | - protected function get404Title() |
|
137 | - { |
|
138 | - return __('Not Found', 'castor'); |
|
139 | - } |
|
140 | - |
|
141 | - protected function getArchiveTitle() |
|
142 | - { |
|
143 | - return $this->archiveMeta->get('title', get_the_archive_title(), get_query_var('post_type')); |
|
144 | - } |
|
145 | - |
|
146 | - protected function getHomeTitle() |
|
147 | - { |
|
148 | - return ($home = (string) get_option('page_for_posts')) |
|
149 | - ? get_the_title($home) |
|
150 | - : get_the_archive_title(); |
|
151 | - } |
|
152 | - |
|
153 | - protected function getPageTitle() |
|
154 | - { |
|
155 | - return $this->postMeta->get('title', [ |
|
156 | - 'fallback' => get_the_title(), |
|
157 | - ]); |
|
158 | - } |
|
159 | - |
|
160 | - protected function getSearchTitle() |
|
161 | - { |
|
162 | - return sprintf(__('Search Results for %s', 'castor'), get_search_query()); |
|
163 | - } |
|
7 | + public $archiveMeta; |
|
8 | + public $postMeta; |
|
9 | + |
|
10 | + public function __construct(ArchiveMeta $archiveMeta, PostMeta $postMeta) |
|
11 | + { |
|
12 | + $this->archiveMeta = $archiveMeta; |
|
13 | + $this->postMeta = $postMeta; |
|
14 | + } |
|
15 | + |
|
16 | + /** |
|
17 | + * @param string $asset |
|
18 | + * |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public function assetPath($asset) |
|
22 | + { |
|
23 | + return $this->paths('dir.stylesheet').'assets/'.$asset; |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * @param string $asset |
|
28 | + * |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function assetUri($asset) |
|
32 | + { |
|
33 | + return $this->paths('uri.stylesheet').'assets/'.$asset; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function copyright() |
|
40 | + { |
|
41 | + return __('Copyright', 'castor').' © '.date('Y').', '.get_bloginfo('name'); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @return bool |
|
46 | + */ |
|
47 | + public function displaySidebar() |
|
48 | + { |
|
49 | + $conditions = [ |
|
50 | + is_archive(), |
|
51 | + is_home(), |
|
52 | + is_single(), |
|
53 | + ]; |
|
54 | + |
|
55 | + $display = in_array(true, $conditions); |
|
56 | + |
|
57 | + return apply_filters('castor/display/sidebar', $display); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param string $asset |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function imagePath($asset) |
|
66 | + { |
|
67 | + return $this->assetPath(castor_app()->imgDir.$asset); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param string $asset |
|
72 | + * |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function imageUri($asset) |
|
76 | + { |
|
77 | + return $this->assetUri(castor_app()->imgDir.$asset); |
|
78 | + } |
|
79 | + |
|
80 | + public function pageTitle() |
|
81 | + { |
|
82 | + foreach (['is_404', 'is_archive', 'is_home', 'is_page', 'is_search'] as $bool) { |
|
83 | + if (!$bool()) { |
|
84 | + continue; |
|
85 | + } |
|
86 | + $method = sprintf('get%sTitle', ucfirst(str_replace('is_', '', $bool))); |
|
87 | + return $this->$method(); |
|
88 | + } |
|
89 | + |
|
90 | + return get_the_title(); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string|null $path |
|
95 | + * |
|
96 | + * @return array|string |
|
97 | + */ |
|
98 | + public function paths($path = null) |
|
99 | + { |
|
100 | + $paths = [ |
|
101 | + 'dir.stylesheet' => get_stylesheet_directory(), |
|
102 | + 'dir.template' => get_template_directory(), |
|
103 | + 'dir.upload' => wp_upload_dir()['basedir'], |
|
104 | + 'uri.stylesheet' => get_stylesheet_directory_uri(), |
|
105 | + 'uri.template' => get_template_directory_uri(), |
|
106 | + ]; |
|
107 | + |
|
108 | + if (is_null($path)) { |
|
109 | + return $paths; |
|
110 | + } |
|
111 | + |
|
112 | + return array_key_exists($path, $paths) |
|
113 | + ? trailingslashit($paths[$path]) |
|
114 | + : ''; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string|null $path |
|
119 | + * @param string $class |
|
120 | + * @return string|null |
|
121 | + */ |
|
122 | + public function svg($path = null, $class = '') |
|
123 | + { |
|
124 | + if (!file_exists($this->imagePath($path))) { |
|
125 | + return; |
|
126 | + } |
|
127 | + $svg = file_get_contents($this->imagePath($path)); |
|
128 | + $pattern = '/(<svg.+)( class=[\'\"](|[^\'\"]+)[\'\"])(>.+)/i'; |
|
129 | + if (1 === preg_match($pattern, $svg, $matches)) { |
|
130 | + $class .= ' '.$matches[3]; |
|
131 | + $svg = preg_filter($pattern, '$1$4', $svg); |
|
132 | + } |
|
133 | + return str_replace('<svg', '<svg class="'.trim($class).'"', $svg); |
|
134 | + } |
|
135 | + |
|
136 | + protected function get404Title() |
|
137 | + { |
|
138 | + return __('Not Found', 'castor'); |
|
139 | + } |
|
140 | + |
|
141 | + protected function getArchiveTitle() |
|
142 | + { |
|
143 | + return $this->archiveMeta->get('title', get_the_archive_title(), get_query_var('post_type')); |
|
144 | + } |
|
145 | + |
|
146 | + protected function getHomeTitle() |
|
147 | + { |
|
148 | + return ($home = (string) get_option('page_for_posts')) |
|
149 | + ? get_the_title($home) |
|
150 | + : get_the_archive_title(); |
|
151 | + } |
|
152 | + |
|
153 | + protected function getPageTitle() |
|
154 | + { |
|
155 | + return $this->postMeta->get('title', [ |
|
156 | + 'fallback' => get_the_title(), |
|
157 | + ]); |
|
158 | + } |
|
159 | + |
|
160 | + protected function getSearchTitle() |
|
161 | + { |
|
162 | + return sprintf(__('Search Results for %s', 'castor'), get_search_query()); |
|
163 | + } |
|
164 | 164 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | public $archiveMeta; |
8 | 8 | public $postMeta; |
9 | 9 | |
10 | - public function __construct(ArchiveMeta $archiveMeta, PostMeta $postMeta) |
|
10 | + public function __construct( ArchiveMeta $archiveMeta, PostMeta $postMeta ) |
|
11 | 11 | { |
12 | 12 | $this->archiveMeta = $archiveMeta; |
13 | 13 | $this->postMeta = $postMeta; |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public function assetPath($asset) |
|
21 | + public function assetPath( $asset ) |
|
22 | 22 | { |
23 | - return $this->paths('dir.stylesheet').'assets/'.$asset; |
|
23 | + return $this->paths( 'dir.stylesheet' ).'assets/'.$asset; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function assetUri($asset) |
|
31 | + public function assetUri( $asset ) |
|
32 | 32 | { |
33 | - return $this->paths('uri.stylesheet').'assets/'.$asset; |
|
33 | + return $this->paths( 'uri.stylesheet' ).'assets/'.$asset; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function copyright() |
40 | 40 | { |
41 | - return __('Copyright', 'castor').' © '.date('Y').', '.get_bloginfo('name'); |
|
41 | + return __( 'Copyright', 'castor' ).' © '.date( 'Y' ).', '.get_bloginfo( 'name' ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | is_single(), |
53 | 53 | ]; |
54 | 54 | |
55 | - $display = in_array(true, $conditions); |
|
55 | + $display = in_array( true, $conditions ); |
|
56 | 56 | |
57 | - return apply_filters('castor/display/sidebar', $display); |
|
57 | + return apply_filters( 'castor/display/sidebar', $display ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return string |
64 | 64 | */ |
65 | - public function imagePath($asset) |
|
65 | + public function imagePath( $asset ) |
|
66 | 66 | { |
67 | - return $this->assetPath(castor_app()->imgDir.$asset); |
|
67 | + return $this->assetPath( castor_app()->imgDir.$asset ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,18 +72,18 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return string |
74 | 74 | */ |
75 | - public function imageUri($asset) |
|
75 | + public function imageUri( $asset ) |
|
76 | 76 | { |
77 | - return $this->assetUri(castor_app()->imgDir.$asset); |
|
77 | + return $this->assetUri( castor_app()->imgDir.$asset ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public function pageTitle() |
81 | 81 | { |
82 | - foreach (['is_404', 'is_archive', 'is_home', 'is_page', 'is_search'] as $bool) { |
|
83 | - if (!$bool()) { |
|
82 | + foreach( ['is_404', 'is_archive', 'is_home', 'is_page', 'is_search'] as $bool ) { |
|
83 | + if( !$bool() ) { |
|
84 | 84 | continue; |
85 | 85 | } |
86 | - $method = sprintf('get%sTitle', ucfirst(str_replace('is_', '', $bool))); |
|
86 | + $method = sprintf( 'get%sTitle', ucfirst( str_replace( 'is_', '', $bool ) ) ); |
|
87 | 87 | return $this->$method(); |
88 | 88 | } |
89 | 89 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return array|string |
97 | 97 | */ |
98 | - public function paths($path = null) |
|
98 | + public function paths( $path = null ) |
|
99 | 99 | { |
100 | 100 | $paths = [ |
101 | 101 | 'dir.stylesheet' => get_stylesheet_directory(), |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | 'uri.template' => get_template_directory_uri(), |
106 | 106 | ]; |
107 | 107 | |
108 | - if (is_null($path)) { |
|
108 | + if( is_null( $path ) ) { |
|
109 | 109 | return $paths; |
110 | 110 | } |
111 | 111 | |
112 | - return array_key_exists($path, $paths) |
|
113 | - ? trailingslashit($paths[$path]) |
|
112 | + return array_key_exists( $path, $paths ) |
|
113 | + ? trailingslashit( $paths[$path] ) |
|
114 | 114 | : ''; |
115 | 115 | } |
116 | 116 | |
@@ -119,46 +119,46 @@ discard block |
||
119 | 119 | * @param string $class |
120 | 120 | * @return string|null |
121 | 121 | */ |
122 | - public function svg($path = null, $class = '') |
|
122 | + public function svg( $path = null, $class = '' ) |
|
123 | 123 | { |
124 | - if (!file_exists($this->imagePath($path))) { |
|
124 | + if( !file_exists( $this->imagePath( $path ) ) ) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | - $svg = file_get_contents($this->imagePath($path)); |
|
127 | + $svg = file_get_contents( $this->imagePath( $path ) ); |
|
128 | 128 | $pattern = '/(<svg.+)( class=[\'\"](|[^\'\"]+)[\'\"])(>.+)/i'; |
129 | - if (1 === preg_match($pattern, $svg, $matches)) { |
|
129 | + if( 1 === preg_match( $pattern, $svg, $matches ) ) { |
|
130 | 130 | $class .= ' '.$matches[3]; |
131 | - $svg = preg_filter($pattern, '$1$4', $svg); |
|
131 | + $svg = preg_filter( $pattern, '$1$4', $svg ); |
|
132 | 132 | } |
133 | - return str_replace('<svg', '<svg class="'.trim($class).'"', $svg); |
|
133 | + return str_replace( '<svg', '<svg class="'.trim( $class ).'"', $svg ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | protected function get404Title() |
137 | 137 | { |
138 | - return __('Not Found', 'castor'); |
|
138 | + return __( 'Not Found', 'castor' ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | protected function getArchiveTitle() |
142 | 142 | { |
143 | - return $this->archiveMeta->get('title', get_the_archive_title(), get_query_var('post_type')); |
|
143 | + return $this->archiveMeta->get( 'title', get_the_archive_title(), get_query_var( 'post_type' ) ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | protected function getHomeTitle() |
147 | 147 | { |
148 | - return ($home = (string) get_option('page_for_posts')) |
|
149 | - ? get_the_title($home) |
|
148 | + return ( $home = (string) get_option( 'page_for_posts' ) ) |
|
149 | + ? get_the_title( $home ) |
|
150 | 150 | : get_the_archive_title(); |
151 | 151 | } |
152 | 152 | |
153 | 153 | protected function getPageTitle() |
154 | 154 | { |
155 | - return $this->postMeta->get('title', [ |
|
155 | + return $this->postMeta->get( 'title', [ |
|
156 | 156 | 'fallback' => get_the_title(), |
157 | - ]); |
|
157 | + ] ); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | protected function getSearchTitle() |
161 | 161 | { |
162 | - return sprintf(__('Search Results for %s', 'castor'), get_search_query()); |
|
162 | + return sprintf( __( 'Search Results for %s', 'castor' ), get_search_query() ); |
|
163 | 163 | } |
164 | 164 | } |
@@ -2,8 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace GeminiLabs\Castor\Helpers; |
4 | 4 | |
5 | -class Theme |
|
6 | -{ |
|
5 | +class Theme { |
|
7 | 6 | public $archiveMeta; |
8 | 7 | public $postMeta; |
9 | 8 |
@@ -4,181 +4,181 @@ |
||
4 | 4 | |
5 | 5 | class Render |
6 | 6 | { |
7 | - public $media; |
|
8 | - public $postmeta; |
|
9 | - public $theme; |
|
10 | - public $utility; |
|
11 | - |
|
12 | - public function __construct(Media $media, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
13 | - { |
|
14 | - $this->media = $media; |
|
15 | - $this->postmeta = $postmeta; |
|
16 | - $this->theme = $theme; |
|
17 | - $this->utility = $utility; |
|
18 | - } |
|
19 | - |
|
20 | - public function blockquote($metaKey = false, array $attributes = []) |
|
21 | - { |
|
22 | - if ($value = $this->postmeta->get($metaKey)) { |
|
23 | - $this->utility->printTag('blockquote', wp_strip_all_tags($value), $attributes); |
|
24 | - } |
|
25 | - } |
|
26 | - |
|
27 | - public function button($postId = 0, $title = false, $passthrough = false) |
|
28 | - { |
|
29 | - if ($passthrough) { |
|
30 | - $url = $postId; |
|
31 | - } |
|
32 | - if (!isset($url)) { |
|
33 | - $url = get_permalink($postId); |
|
34 | - if (!$title) { |
|
35 | - $title = get_the_title($postId); |
|
36 | - } |
|
37 | - } |
|
38 | - if (!$title || !$url) { |
|
39 | - return; |
|
40 | - } |
|
41 | - printf('<a href="%s" class="button"><span>%s</span></a>', $url, $title); |
|
42 | - } |
|
43 | - |
|
44 | - public function buttons($postIds = []) |
|
45 | - { |
|
46 | - foreach ((array) $postIds as $postId) { |
|
47 | - $this->button($postId); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public function content($metaKey = false, $passthrough = false) |
|
52 | - { |
|
53 | - if ($passthrough) { |
|
54 | - $content = $metaKey; |
|
55 | - } |
|
56 | - if (!isset($content)) { |
|
57 | - $content = $metaKey |
|
58 | - ? $this->postmeta->get($metaKey) |
|
59 | - : get_the_content(); |
|
60 | - } |
|
61 | - echo str_replace(']]>', ']]>', apply_filters('the_content', $content)); |
|
62 | - } |
|
63 | - |
|
64 | - public function copyright(array $args = []) |
|
65 | - { |
|
66 | - $args = shortcode_atts([ |
|
67 | - 'copyright' => sprintf('<span>%s </span>©', __('Copyright', 'castor')), |
|
68 | - 'date' => date('Y'), |
|
69 | - 'name' => get_bloginfo('name'), |
|
70 | - 'separator' => '—', |
|
71 | - ], $args); |
|
72 | - extract($args); |
|
73 | - if ($separator) { |
|
74 | - $separator .= ' '; |
|
75 | - } |
|
76 | - printf('%s %s %s%s', $copyright, $date, $separator, $name); |
|
77 | - } |
|
78 | - |
|
79 | - public function featured($args = []) |
|
80 | - { |
|
81 | - $args = wp_parse_args($args, [ |
|
82 | - 'class' => 'featured', |
|
83 | - 'image' => get_post_thumbnail_id(), |
|
84 | - 'player' => '', |
|
85 | - 'video' => 'featured_video', |
|
86 | - ]); |
|
87 | - $featuredHtml = $this->media->video(wp_parse_args($args, [ |
|
88 | - 'url' => $args['video'], |
|
89 | - ])); |
|
90 | - if (empty($featuredHtml) && $featuredImage = $this->media->getImage($args['image'])) { |
|
91 | - $featuredCaption = $featuredImage->caption |
|
92 | - ? sprintf('<figcaption>%s</figcaption>', $featuredImage->caption) |
|
93 | - : ''; |
|
94 | - $featuredHtml = sprintf('<div class="featured-image"><img src="%s" alt="%s"></div>%s', |
|
95 | - $featuredImage->large['url'], |
|
96 | - $featuredImage->alt, |
|
97 | - $featuredCaption |
|
98 | - ); |
|
99 | - } |
|
100 | - if (!empty($featuredHtml)) { |
|
101 | - printf('<figure class="%s">%s</figure>', $args['class'], $featuredHtml); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - public function field($name, array $args = []) |
|
106 | - { |
|
107 | - } |
|
108 | - |
|
109 | - public function form($name, array $args = []) |
|
110 | - { |
|
111 | - } |
|
112 | - |
|
113 | - public function gallery(array $args = []) |
|
114 | - { |
|
115 | - echo $this->media->gallery($args); |
|
116 | - } |
|
117 | - |
|
118 | - public function h1($string, array $attributes = []) |
|
119 | - { |
|
120 | - $this->utility->printTag('h1', wp_strip_all_tags($string), $attributes); |
|
121 | - } |
|
122 | - |
|
123 | - public function h2($string, array $attributes = []) |
|
124 | - { |
|
125 | - $this->utility->printTag('h2', wp_strip_all_tags($string), $attributes); |
|
126 | - } |
|
127 | - |
|
128 | - public function h3($string, array $attributes = []) |
|
129 | - { |
|
130 | - $this->utility->printTag('h3', wp_strip_all_tags($string), $attributes); |
|
131 | - } |
|
132 | - |
|
133 | - public function h4($string, array $attributes = []) |
|
134 | - { |
|
135 | - $this->utility->printTag('h4', wp_strip_all_tags($string), $attributes); |
|
136 | - } |
|
137 | - |
|
138 | - public function h5($string, array $attributes = []) |
|
139 | - { |
|
140 | - $this->utility->printTag('h5', wp_strip_all_tags($string), $attributes); |
|
141 | - } |
|
142 | - |
|
143 | - public function h6($string, array $attributes = []) |
|
144 | - { |
|
145 | - $this->utility->printTag('h6', wp_strip_all_tags($string), $attributes); |
|
146 | - } |
|
147 | - |
|
148 | - public function madeWithLove($name) |
|
149 | - { |
|
150 | - printf(__('Made with %s by %s', 'castor'), |
|
151 | - file_get_contents(sprintf('%simg/heart.svg', \GeminiLabs\Castor\Application::getInstance()->assets)), |
|
152 | - $name |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - public function p($string, array $attributes = []) |
|
157 | - { |
|
158 | - $this->utility->printTag('p', wp_strip_all_tags($string), $attributes); |
|
159 | - } |
|
160 | - |
|
161 | - public function title($metaKey = false, array $attributes = []) |
|
162 | - { |
|
163 | - $tag = apply_filters('castor/render/title/tag', 'h2'); |
|
164 | - $value = $metaKey |
|
165 | - ? $this->postmeta->get($metaKey) |
|
166 | - : $this->theme->pageTitle(); |
|
167 | - |
|
168 | - if (!$value) { |
|
169 | - return; |
|
170 | - } |
|
171 | - |
|
172 | - $this->utility->printTag($tag, wp_strip_all_tags($value), $attributes); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @param array|string $args |
|
177 | - * |
|
178 | - * @return string|null |
|
179 | - */ |
|
180 | - public function video($args) |
|
181 | - { |
|
182 | - echo $this->media->video($args); |
|
183 | - } |
|
7 | + public $media; |
|
8 | + public $postmeta; |
|
9 | + public $theme; |
|
10 | + public $utility; |
|
11 | + |
|
12 | + public function __construct(Media $media, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
13 | + { |
|
14 | + $this->media = $media; |
|
15 | + $this->postmeta = $postmeta; |
|
16 | + $this->theme = $theme; |
|
17 | + $this->utility = $utility; |
|
18 | + } |
|
19 | + |
|
20 | + public function blockquote($metaKey = false, array $attributes = []) |
|
21 | + { |
|
22 | + if ($value = $this->postmeta->get($metaKey)) { |
|
23 | + $this->utility->printTag('blockquote', wp_strip_all_tags($value), $attributes); |
|
24 | + } |
|
25 | + } |
|
26 | + |
|
27 | + public function button($postId = 0, $title = false, $passthrough = false) |
|
28 | + { |
|
29 | + if ($passthrough) { |
|
30 | + $url = $postId; |
|
31 | + } |
|
32 | + if (!isset($url)) { |
|
33 | + $url = get_permalink($postId); |
|
34 | + if (!$title) { |
|
35 | + $title = get_the_title($postId); |
|
36 | + } |
|
37 | + } |
|
38 | + if (!$title || !$url) { |
|
39 | + return; |
|
40 | + } |
|
41 | + printf('<a href="%s" class="button"><span>%s</span></a>', $url, $title); |
|
42 | + } |
|
43 | + |
|
44 | + public function buttons($postIds = []) |
|
45 | + { |
|
46 | + foreach ((array) $postIds as $postId) { |
|
47 | + $this->button($postId); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public function content($metaKey = false, $passthrough = false) |
|
52 | + { |
|
53 | + if ($passthrough) { |
|
54 | + $content = $metaKey; |
|
55 | + } |
|
56 | + if (!isset($content)) { |
|
57 | + $content = $metaKey |
|
58 | + ? $this->postmeta->get($metaKey) |
|
59 | + : get_the_content(); |
|
60 | + } |
|
61 | + echo str_replace(']]>', ']]>', apply_filters('the_content', $content)); |
|
62 | + } |
|
63 | + |
|
64 | + public function copyright(array $args = []) |
|
65 | + { |
|
66 | + $args = shortcode_atts([ |
|
67 | + 'copyright' => sprintf('<span>%s </span>©', __('Copyright', 'castor')), |
|
68 | + 'date' => date('Y'), |
|
69 | + 'name' => get_bloginfo('name'), |
|
70 | + 'separator' => '—', |
|
71 | + ], $args); |
|
72 | + extract($args); |
|
73 | + if ($separator) { |
|
74 | + $separator .= ' '; |
|
75 | + } |
|
76 | + printf('%s %s %s%s', $copyright, $date, $separator, $name); |
|
77 | + } |
|
78 | + |
|
79 | + public function featured($args = []) |
|
80 | + { |
|
81 | + $args = wp_parse_args($args, [ |
|
82 | + 'class' => 'featured', |
|
83 | + 'image' => get_post_thumbnail_id(), |
|
84 | + 'player' => '', |
|
85 | + 'video' => 'featured_video', |
|
86 | + ]); |
|
87 | + $featuredHtml = $this->media->video(wp_parse_args($args, [ |
|
88 | + 'url' => $args['video'], |
|
89 | + ])); |
|
90 | + if (empty($featuredHtml) && $featuredImage = $this->media->getImage($args['image'])) { |
|
91 | + $featuredCaption = $featuredImage->caption |
|
92 | + ? sprintf('<figcaption>%s</figcaption>', $featuredImage->caption) |
|
93 | + : ''; |
|
94 | + $featuredHtml = sprintf('<div class="featured-image"><img src="%s" alt="%s"></div>%s', |
|
95 | + $featuredImage->large['url'], |
|
96 | + $featuredImage->alt, |
|
97 | + $featuredCaption |
|
98 | + ); |
|
99 | + } |
|
100 | + if (!empty($featuredHtml)) { |
|
101 | + printf('<figure class="%s">%s</figure>', $args['class'], $featuredHtml); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + public function field($name, array $args = []) |
|
106 | + { |
|
107 | + } |
|
108 | + |
|
109 | + public function form($name, array $args = []) |
|
110 | + { |
|
111 | + } |
|
112 | + |
|
113 | + public function gallery(array $args = []) |
|
114 | + { |
|
115 | + echo $this->media->gallery($args); |
|
116 | + } |
|
117 | + |
|
118 | + public function h1($string, array $attributes = []) |
|
119 | + { |
|
120 | + $this->utility->printTag('h1', wp_strip_all_tags($string), $attributes); |
|
121 | + } |
|
122 | + |
|
123 | + public function h2($string, array $attributes = []) |
|
124 | + { |
|
125 | + $this->utility->printTag('h2', wp_strip_all_tags($string), $attributes); |
|
126 | + } |
|
127 | + |
|
128 | + public function h3($string, array $attributes = []) |
|
129 | + { |
|
130 | + $this->utility->printTag('h3', wp_strip_all_tags($string), $attributes); |
|
131 | + } |
|
132 | + |
|
133 | + public function h4($string, array $attributes = []) |
|
134 | + { |
|
135 | + $this->utility->printTag('h4', wp_strip_all_tags($string), $attributes); |
|
136 | + } |
|
137 | + |
|
138 | + public function h5($string, array $attributes = []) |
|
139 | + { |
|
140 | + $this->utility->printTag('h5', wp_strip_all_tags($string), $attributes); |
|
141 | + } |
|
142 | + |
|
143 | + public function h6($string, array $attributes = []) |
|
144 | + { |
|
145 | + $this->utility->printTag('h6', wp_strip_all_tags($string), $attributes); |
|
146 | + } |
|
147 | + |
|
148 | + public function madeWithLove($name) |
|
149 | + { |
|
150 | + printf(__('Made with %s by %s', 'castor'), |
|
151 | + file_get_contents(sprintf('%simg/heart.svg', \GeminiLabs\Castor\Application::getInstance()->assets)), |
|
152 | + $name |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + public function p($string, array $attributes = []) |
|
157 | + { |
|
158 | + $this->utility->printTag('p', wp_strip_all_tags($string), $attributes); |
|
159 | + } |
|
160 | + |
|
161 | + public function title($metaKey = false, array $attributes = []) |
|
162 | + { |
|
163 | + $tag = apply_filters('castor/render/title/tag', 'h2'); |
|
164 | + $value = $metaKey |
|
165 | + ? $this->postmeta->get($metaKey) |
|
166 | + : $this->theme->pageTitle(); |
|
167 | + |
|
168 | + if (!$value) { |
|
169 | + return; |
|
170 | + } |
|
171 | + |
|
172 | + $this->utility->printTag($tag, wp_strip_all_tags($value), $attributes); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @param array|string $args |
|
177 | + * |
|
178 | + * @return string|null |
|
179 | + */ |
|
180 | + public function video($args) |
|
181 | + { |
|
182 | + echo $this->media->video($args); |
|
183 | + } |
|
184 | 184 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | public $theme; |
10 | 10 | public $utility; |
11 | 11 | |
12 | - public function __construct(Media $media, PostMeta $postmeta, Theme $theme, Utility $utility) |
|
12 | + public function __construct( Media $media, PostMeta $postmeta, Theme $theme, Utility $utility ) |
|
13 | 13 | { |
14 | 14 | $this->media = $media; |
15 | 15 | $this->postmeta = $postmeta; |
@@ -17,159 +17,159 @@ discard block |
||
17 | 17 | $this->utility = $utility; |
18 | 18 | } |
19 | 19 | |
20 | - public function blockquote($metaKey = false, array $attributes = []) |
|
20 | + public function blockquote( $metaKey = false, array $attributes = [] ) |
|
21 | 21 | { |
22 | - if ($value = $this->postmeta->get($metaKey)) { |
|
23 | - $this->utility->printTag('blockquote', wp_strip_all_tags($value), $attributes); |
|
22 | + if( $value = $this->postmeta->get( $metaKey ) ) { |
|
23 | + $this->utility->printTag( 'blockquote', wp_strip_all_tags( $value ), $attributes ); |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | - public function button($postId = 0, $title = false, $passthrough = false) |
|
27 | + public function button( $postId = 0, $title = false, $passthrough = false ) |
|
28 | 28 | { |
29 | - if ($passthrough) { |
|
29 | + if( $passthrough ) { |
|
30 | 30 | $url = $postId; |
31 | 31 | } |
32 | - if (!isset($url)) { |
|
33 | - $url = get_permalink($postId); |
|
34 | - if (!$title) { |
|
35 | - $title = get_the_title($postId); |
|
32 | + if( !isset( $url ) ) { |
|
33 | + $url = get_permalink( $postId ); |
|
34 | + if( !$title ) { |
|
35 | + $title = get_the_title( $postId ); |
|
36 | 36 | } |
37 | 37 | } |
38 | - if (!$title || !$url) { |
|
38 | + if( !$title || !$url ) { |
|
39 | 39 | return; |
40 | 40 | } |
41 | - printf('<a href="%s" class="button"><span>%s</span></a>', $url, $title); |
|
41 | + printf( '<a href="%s" class="button"><span>%s</span></a>', $url, $title ); |
|
42 | 42 | } |
43 | 43 | |
44 | - public function buttons($postIds = []) |
|
44 | + public function buttons( $postIds = [] ) |
|
45 | 45 | { |
46 | - foreach ((array) $postIds as $postId) { |
|
47 | - $this->button($postId); |
|
46 | + foreach( (array) $postIds as $postId ) { |
|
47 | + $this->button( $postId ); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | - public function content($metaKey = false, $passthrough = false) |
|
51 | + public function content( $metaKey = false, $passthrough = false ) |
|
52 | 52 | { |
53 | - if ($passthrough) { |
|
53 | + if( $passthrough ) { |
|
54 | 54 | $content = $metaKey; |
55 | 55 | } |
56 | - if (!isset($content)) { |
|
56 | + if( !isset( $content ) ) { |
|
57 | 57 | $content = $metaKey |
58 | - ? $this->postmeta->get($metaKey) |
|
58 | + ? $this->postmeta->get( $metaKey ) |
|
59 | 59 | : get_the_content(); |
60 | 60 | } |
61 | - echo str_replace(']]>', ']]>', apply_filters('the_content', $content)); |
|
61 | + echo str_replace( ']]>', ']]>', apply_filters( 'the_content', $content ) ); |
|
62 | 62 | } |
63 | 63 | |
64 | - public function copyright(array $args = []) |
|
64 | + public function copyright( array $args = [] ) |
|
65 | 65 | { |
66 | - $args = shortcode_atts([ |
|
67 | - 'copyright' => sprintf('<span>%s </span>©', __('Copyright', 'castor')), |
|
68 | - 'date' => date('Y'), |
|
69 | - 'name' => get_bloginfo('name'), |
|
66 | + $args = shortcode_atts( [ |
|
67 | + 'copyright' => sprintf( '<span>%s </span>©', __( 'Copyright', 'castor' ) ), |
|
68 | + 'date' => date( 'Y' ), |
|
69 | + 'name' => get_bloginfo( 'name' ), |
|
70 | 70 | 'separator' => '—', |
71 | - ], $args); |
|
72 | - extract($args); |
|
73 | - if ($separator) { |
|
71 | + ], $args ); |
|
72 | + extract( $args ); |
|
73 | + if( $separator ) { |
|
74 | 74 | $separator .= ' '; |
75 | 75 | } |
76 | - printf('%s %s %s%s', $copyright, $date, $separator, $name); |
|
76 | + printf( '%s %s %s%s', $copyright, $date, $separator, $name ); |
|
77 | 77 | } |
78 | 78 | |
79 | - public function featured($args = []) |
|
79 | + public function featured( $args = [] ) |
|
80 | 80 | { |
81 | - $args = wp_parse_args($args, [ |
|
81 | + $args = wp_parse_args( $args, [ |
|
82 | 82 | 'class' => 'featured', |
83 | 83 | 'image' => get_post_thumbnail_id(), |
84 | 84 | 'player' => '', |
85 | 85 | 'video' => 'featured_video', |
86 | - ]); |
|
87 | - $featuredHtml = $this->media->video(wp_parse_args($args, [ |
|
86 | + ] ); |
|
87 | + $featuredHtml = $this->media->video( wp_parse_args( $args, [ |
|
88 | 88 | 'url' => $args['video'], |
89 | - ])); |
|
90 | - if (empty($featuredHtml) && $featuredImage = $this->media->getImage($args['image'])) { |
|
89 | + ] ) ); |
|
90 | + if( empty( $featuredHtml ) && $featuredImage = $this->media->getImage( $args['image'] ) ) { |
|
91 | 91 | $featuredCaption = $featuredImage->caption |
92 | - ? sprintf('<figcaption>%s</figcaption>', $featuredImage->caption) |
|
92 | + ? sprintf( '<figcaption>%s</figcaption>', $featuredImage->caption ) |
|
93 | 93 | : ''; |
94 | - $featuredHtml = sprintf('<div class="featured-image"><img src="%s" alt="%s"></div>%s', |
|
94 | + $featuredHtml = sprintf( '<div class="featured-image"><img src="%s" alt="%s"></div>%s', |
|
95 | 95 | $featuredImage->large['url'], |
96 | 96 | $featuredImage->alt, |
97 | 97 | $featuredCaption |
98 | 98 | ); |
99 | 99 | } |
100 | - if (!empty($featuredHtml)) { |
|
101 | - printf('<figure class="%s">%s</figure>', $args['class'], $featuredHtml); |
|
100 | + if( !empty( $featuredHtml ) ) { |
|
101 | + printf( '<figure class="%s">%s</figure>', $args['class'], $featuredHtml ); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | - public function field($name, array $args = []) |
|
105 | + public function field( $name, array $args = [] ) |
|
106 | 106 | { |
107 | 107 | } |
108 | 108 | |
109 | - public function form($name, array $args = []) |
|
109 | + public function form( $name, array $args = [] ) |
|
110 | 110 | { |
111 | 111 | } |
112 | 112 | |
113 | - public function gallery(array $args = []) |
|
113 | + public function gallery( array $args = [] ) |
|
114 | 114 | { |
115 | - echo $this->media->gallery($args); |
|
115 | + echo $this->media->gallery( $args ); |
|
116 | 116 | } |
117 | 117 | |
118 | - public function h1($string, array $attributes = []) |
|
118 | + public function h1( $string, array $attributes = [] ) |
|
119 | 119 | { |
120 | - $this->utility->printTag('h1', wp_strip_all_tags($string), $attributes); |
|
120 | + $this->utility->printTag( 'h1', wp_strip_all_tags( $string ), $attributes ); |
|
121 | 121 | } |
122 | 122 | |
123 | - public function h2($string, array $attributes = []) |
|
123 | + public function h2( $string, array $attributes = [] ) |
|
124 | 124 | { |
125 | - $this->utility->printTag('h2', wp_strip_all_tags($string), $attributes); |
|
125 | + $this->utility->printTag( 'h2', wp_strip_all_tags( $string ), $attributes ); |
|
126 | 126 | } |
127 | 127 | |
128 | - public function h3($string, array $attributes = []) |
|
128 | + public function h3( $string, array $attributes = [] ) |
|
129 | 129 | { |
130 | - $this->utility->printTag('h3', wp_strip_all_tags($string), $attributes); |
|
130 | + $this->utility->printTag( 'h3', wp_strip_all_tags( $string ), $attributes ); |
|
131 | 131 | } |
132 | 132 | |
133 | - public function h4($string, array $attributes = []) |
|
133 | + public function h4( $string, array $attributes = [] ) |
|
134 | 134 | { |
135 | - $this->utility->printTag('h4', wp_strip_all_tags($string), $attributes); |
|
135 | + $this->utility->printTag( 'h4', wp_strip_all_tags( $string ), $attributes ); |
|
136 | 136 | } |
137 | 137 | |
138 | - public function h5($string, array $attributes = []) |
|
138 | + public function h5( $string, array $attributes = [] ) |
|
139 | 139 | { |
140 | - $this->utility->printTag('h5', wp_strip_all_tags($string), $attributes); |
|
140 | + $this->utility->printTag( 'h5', wp_strip_all_tags( $string ), $attributes ); |
|
141 | 141 | } |
142 | 142 | |
143 | - public function h6($string, array $attributes = []) |
|
143 | + public function h6( $string, array $attributes = [] ) |
|
144 | 144 | { |
145 | - $this->utility->printTag('h6', wp_strip_all_tags($string), $attributes); |
|
145 | + $this->utility->printTag( 'h6', wp_strip_all_tags( $string ), $attributes ); |
|
146 | 146 | } |
147 | 147 | |
148 | - public function madeWithLove($name) |
|
148 | + public function madeWithLove( $name ) |
|
149 | 149 | { |
150 | - printf(__('Made with %s by %s', 'castor'), |
|
151 | - file_get_contents(sprintf('%simg/heart.svg', \GeminiLabs\Castor\Application::getInstance()->assets)), |
|
150 | + printf( __( 'Made with %s by %s', 'castor' ), |
|
151 | + file_get_contents( sprintf( '%simg/heart.svg', \GeminiLabs\Castor\Application::getInstance()->assets ) ), |
|
152 | 152 | $name |
153 | 153 | ); |
154 | 154 | } |
155 | 155 | |
156 | - public function p($string, array $attributes = []) |
|
156 | + public function p( $string, array $attributes = [] ) |
|
157 | 157 | { |
158 | - $this->utility->printTag('p', wp_strip_all_tags($string), $attributes); |
|
158 | + $this->utility->printTag( 'p', wp_strip_all_tags( $string ), $attributes ); |
|
159 | 159 | } |
160 | 160 | |
161 | - public function title($metaKey = false, array $attributes = []) |
|
161 | + public function title( $metaKey = false, array $attributes = [] ) |
|
162 | 162 | { |
163 | - $tag = apply_filters('castor/render/title/tag', 'h2'); |
|
163 | + $tag = apply_filters( 'castor/render/title/tag', 'h2' ); |
|
164 | 164 | $value = $metaKey |
165 | - ? $this->postmeta->get($metaKey) |
|
165 | + ? $this->postmeta->get( $metaKey ) |
|
166 | 166 | : $this->theme->pageTitle(); |
167 | 167 | |
168 | - if (!$value) { |
|
168 | + if( !$value ) { |
|
169 | 169 | return; |
170 | 170 | } |
171 | 171 | |
172 | - $this->utility->printTag($tag, wp_strip_all_tags($value), $attributes); |
|
172 | + $this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes ); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return string|null |
179 | 179 | */ |
180 | - public function video($args) |
|
180 | + public function video( $args ) |
|
181 | 181 | { |
182 | - echo $this->media->video($args); |
|
182 | + echo $this->media->video( $args ); |
|
183 | 183 | } |
184 | 184 | } |
@@ -2,8 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace GeminiLabs\Castor\Helpers; |
4 | 4 | |
5 | -class Render |
|
6 | -{ |
|
5 | +class Render { |
|
7 | 6 | public $media; |
8 | 7 | public $postmeta; |
9 | 8 | public $theme; |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace GeminiLabs\Castor\Helpers; |
4 | 4 | |
5 | -class Development |
|
6 | -{ |
|
5 | +class Development { |
|
7 | 6 | public $templatePaths = []; |
8 | 7 | |
9 | 8 | protected $utility; |
@@ -72,7 +71,8 @@ discard block |
||
72 | 71 | printf('<div class="print__r"><pre>%s</pre></div>', |
73 | 72 | htmlspecialchars(print_r(func_get_arg(0), true), ENT_QUOTES, 'UTF-8') |
74 | 73 | ); |
75 | - } elseif ($args > 1) { |
|
74 | + } |
|
75 | + elseif ($args > 1) { |
|
76 | 76 | echo '<div class="print__r_group">'; |
77 | 77 | foreach (func_get_args() as $value) { |
78 | 78 | $this->printF($value); |
@@ -4,82 +4,82 @@ |
||
4 | 4 | |
5 | 5 | class Development |
6 | 6 | { |
7 | - public $templatePaths = []; |
|
7 | + public $templatePaths = []; |
|
8 | 8 | |
9 | - protected $utility; |
|
9 | + protected $utility; |
|
10 | 10 | |
11 | - public function __construct(Utility $utility) |
|
12 | - { |
|
13 | - $this->utility = $utility; |
|
14 | - } |
|
11 | + public function __construct(Utility $utility) |
|
12 | + { |
|
13 | + $this->utility = $utility; |
|
14 | + } |
|
15 | 15 | |
16 | - public function capture() |
|
17 | - { |
|
18 | - ob_start(); |
|
19 | - call_user_func_array([$this, 'printF'], func_get_args()); |
|
20 | - return ob_get_clean(); |
|
21 | - } |
|
16 | + public function capture() |
|
17 | + { |
|
18 | + ob_start(); |
|
19 | + call_user_func_array([$this, 'printF'], func_get_args()); |
|
20 | + return ob_get_clean(); |
|
21 | + } |
|
22 | 22 | |
23 | - public function className($override = 'dev') |
|
24 | - { |
|
25 | - return $this->isDev() ? $override : ''; |
|
26 | - } |
|
23 | + public function className($override = 'dev') |
|
24 | + { |
|
25 | + return $this->isDev() ? $override : ''; |
|
26 | + } |
|
27 | 27 | |
28 | - public function debug() |
|
29 | - { |
|
30 | - call_user_func_array([$this, 'printF'], func_get_args()); |
|
31 | - } |
|
28 | + public function debug() |
|
29 | + { |
|
30 | + call_user_func_array([$this, 'printF'], func_get_args()); |
|
31 | + } |
|
32 | 32 | |
33 | - public function isDev() |
|
34 | - { |
|
35 | - return defined('DEV') && (bool) DEV && WP_ENV == 'development'; |
|
36 | - } |
|
33 | + public function isDev() |
|
34 | + { |
|
35 | + return defined('DEV') && (bool) DEV && WP_ENV == 'development'; |
|
36 | + } |
|
37 | 37 | |
38 | - public function isProduction() |
|
39 | - { |
|
40 | - return WP_ENV == 'production'; |
|
41 | - } |
|
38 | + public function isProduction() |
|
39 | + { |
|
40 | + return WP_ENV == 'production'; |
|
41 | + } |
|
42 | 42 | |
43 | - public function printFiltersFor($hook = '') |
|
44 | - { |
|
45 | - global $wp_filter; |
|
46 | - if (empty($hook) || !isset($wp_filter[$hook])) { |
|
47 | - return; |
|
48 | - } |
|
49 | - $this->printF($wp_filter[$hook]); |
|
50 | - } |
|
43 | + public function printFiltersFor($hook = '') |
|
44 | + { |
|
45 | + global $wp_filter; |
|
46 | + if (empty($hook) || !isset($wp_filter[$hook])) { |
|
47 | + return; |
|
48 | + } |
|
49 | + $this->printF($wp_filter[$hook]); |
|
50 | + } |
|
51 | 51 | |
52 | - public function printTemplatePaths() |
|
53 | - { |
|
54 | - $this->printF(implode("\n", $this->templatePaths())); |
|
55 | - } |
|
52 | + public function printTemplatePaths() |
|
53 | + { |
|
54 | + $this->printF(implode("\n", $this->templatePaths())); |
|
55 | + } |
|
56 | 56 | |
57 | - public function storeTemplatePath($template) |
|
58 | - { |
|
59 | - if (is_string($template)) { |
|
60 | - $this->templatePaths[] = $this->utility->trimLeft($template, trailingslashit(WP_CONTENT_DIR)); |
|
61 | - } |
|
62 | - } |
|
57 | + public function storeTemplatePath($template) |
|
58 | + { |
|
59 | + if (is_string($template)) { |
|
60 | + $this->templatePaths[] = $this->utility->trimLeft($template, trailingslashit(WP_CONTENT_DIR)); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - protected function printF() |
|
65 | - { |
|
66 | - $args = func_num_args(); |
|
64 | + protected function printF() |
|
65 | + { |
|
66 | + $args = func_num_args(); |
|
67 | 67 | |
68 | - if (1 == $args) { |
|
69 | - printf('<div class="print__r"><pre>%s</pre></div>', |
|
70 | - htmlspecialchars(print_r(func_get_arg(0), true), ENT_QUOTES, 'UTF-8') |
|
71 | - ); |
|
72 | - } elseif ($args > 1) { |
|
73 | - echo '<div class="print__r_group">'; |
|
74 | - foreach (func_get_args() as $value) { |
|
75 | - $this->printF($value); |
|
76 | - } |
|
77 | - echo '</div>'; |
|
78 | - } |
|
79 | - } |
|
68 | + if (1 == $args) { |
|
69 | + printf('<div class="print__r"><pre>%s</pre></div>', |
|
70 | + htmlspecialchars(print_r(func_get_arg(0), true), ENT_QUOTES, 'UTF-8') |
|
71 | + ); |
|
72 | + } elseif ($args > 1) { |
|
73 | + echo '<div class="print__r_group">'; |
|
74 | + foreach (func_get_args() as $value) { |
|
75 | + $this->printF($value); |
|
76 | + } |
|
77 | + echo '</div>'; |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - public function templatePaths() |
|
82 | - { |
|
83 | - return $this->templatePaths; |
|
84 | - } |
|
81 | + public function templatePaths() |
|
82 | + { |
|
83 | + return $this->templatePaths; |
|
84 | + } |
|
85 | 85 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | protected $utility; |
10 | 10 | |
11 | - public function __construct(Utility $utility) |
|
11 | + public function __construct( Utility $utility ) |
|
12 | 12 | { |
13 | 13 | $this->utility = $utility; |
14 | 14 | } |
@@ -16,23 +16,23 @@ discard block |
||
16 | 16 | public function capture() |
17 | 17 | { |
18 | 18 | ob_start(); |
19 | - call_user_func_array([$this, 'printF'], func_get_args()); |
|
19 | + call_user_func_array( [$this, 'printF'], func_get_args() ); |
|
20 | 20 | return ob_get_clean(); |
21 | 21 | } |
22 | 22 | |
23 | - public function className($override = 'dev') |
|
23 | + public function className( $override = 'dev' ) |
|
24 | 24 | { |
25 | 25 | return $this->isDev() ? $override : ''; |
26 | 26 | } |
27 | 27 | |
28 | 28 | public function debug() |
29 | 29 | { |
30 | - call_user_func_array([$this, 'printF'], func_get_args()); |
|
30 | + call_user_func_array( [$this, 'printF'], func_get_args() ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function isDev() |
34 | 34 | { |
35 | - return defined('DEV') && (bool) DEV && WP_ENV == 'development'; |
|
35 | + return defined( 'DEV' ) && (bool) DEV && WP_ENV == 'development'; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function isProduction() |
@@ -40,24 +40,24 @@ discard block |
||
40 | 40 | return WP_ENV == 'production'; |
41 | 41 | } |
42 | 42 | |
43 | - public function printFiltersFor($hook = '') |
|
43 | + public function printFiltersFor( $hook = '' ) |
|
44 | 44 | { |
45 | 45 | global $wp_filter; |
46 | - if (empty($hook) || !isset($wp_filter[$hook])) { |
|
46 | + if( empty( $hook ) || !isset( $wp_filter[$hook] ) ) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | - $this->printF($wp_filter[$hook]); |
|
49 | + $this->printF( $wp_filter[$hook] ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public function printTemplatePaths() |
53 | 53 | { |
54 | - $this->printF(implode("\n", $this->templatePaths())); |
|
54 | + $this->printF( implode( "\n", $this->templatePaths() ) ); |
|
55 | 55 | } |
56 | 56 | |
57 | - public function storeTemplatePath($template) |
|
57 | + public function storeTemplatePath( $template ) |
|
58 | 58 | { |
59 | - if (is_string($template)) { |
|
60 | - $this->templatePaths[] = $this->utility->trimLeft($template, trailingslashit(WP_CONTENT_DIR)); |
|
59 | + if( is_string( $template ) ) { |
|
60 | + $this->templatePaths[] = $this->utility->trimLeft( $template, trailingslashit( WP_CONTENT_DIR ) ); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | { |
66 | 66 | $args = func_num_args(); |
67 | 67 | |
68 | - if (1 == $args) { |
|
69 | - printf('<div class="print__r"><pre>%s</pre></div>', |
|
70 | - htmlspecialchars(print_r(func_get_arg(0), true), ENT_QUOTES, 'UTF-8') |
|
68 | + if( 1 == $args ) { |
|
69 | + printf( '<div class="print__r"><pre>%s</pre></div>', |
|
70 | + htmlspecialchars( print_r( func_get_arg( 0 ), true ), ENT_QUOTES, 'UTF-8' ) |
|
71 | 71 | ); |
72 | - } elseif ($args > 1) { |
|
72 | + } elseif( $args > 1 ) { |
|
73 | 73 | echo '<div class="print__r_group">'; |
74 | - foreach (func_get_args() as $value) { |
|
75 | - $this->printF($value); |
|
74 | + foreach( func_get_args() as $value ) { |
|
75 | + $this->printF( $value ); |
|
76 | 76 | } |
77 | 77 | echo '</div>'; |
78 | 78 | } |
@@ -4,14 +4,14 @@ |
||
4 | 4 | |
5 | 5 | class Email extends Text |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function render() |
|
11 | - { |
|
12 | - return parent::render([ |
|
13 | - 'class' => 'regular-text ltr', |
|
14 | - 'type' => 'email', |
|
15 | - ]); |
|
16 | - } |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function render() |
|
11 | + { |
|
12 | + return parent::render([ |
|
13 | + 'class' => 'regular-text ltr', |
|
14 | + 'type' => 'email', |
|
15 | + ]); |
|
16 | + } |
|
17 | 17 | } |
@@ -9,9 +9,9 @@ |
||
9 | 9 | */ |
10 | 10 | public function render() |
11 | 11 | { |
12 | - return parent::render([ |
|
12 | + return parent::render( [ |
|
13 | 13 | 'class' => 'regular-text ltr', |
14 | 14 | 'type' => 'email', |
15 | - ]); |
|
15 | + ] ); |
|
16 | 16 | } |
17 | 17 | } |
@@ -2,8 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace GeminiLabs\Castor\Forms\Fields; |
4 | 4 | |
5 | -class Email extends Text |
|
6 | -{ |
|
5 | +class Email extends Text { |
|
7 | 6 | /** |
8 | 7 | * @return string |
9 | 8 | */ |