@@ -10,126 +10,126 @@ |
||
10 | 10 | */ |
11 | 11 | trait ValidationRules |
12 | 12 | { |
13 | - /** |
|
14 | - * Get the size of an attribute. |
|
15 | - * @param string $attribute |
|
16 | - * @param mixed $value |
|
17 | - * @return mixed |
|
18 | - */ |
|
19 | - abstract protected function getSize($attribute, $value); |
|
13 | + /** |
|
14 | + * Get the size of an attribute. |
|
15 | + * @param string $attribute |
|
16 | + * @param mixed $value |
|
17 | + * @return mixed |
|
18 | + */ |
|
19 | + abstract protected function getSize($attribute, $value); |
|
20 | 20 | |
21 | - /** |
|
22 | - * Replace all placeholders. |
|
23 | - * @param string $message |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - protected function replace($message, array $parameters) |
|
27 | - { |
|
28 | - if (!Str::contains($message, '%s')) { |
|
29 | - return $message; |
|
30 | - } |
|
31 | - return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | - foreach ($parameters as $key => $value) { |
|
33 | - return array_shift($parameters); |
|
34 | - } |
|
35 | - }, $message); |
|
36 | - } |
|
21 | + /** |
|
22 | + * Replace all placeholders. |
|
23 | + * @param string $message |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + protected function replace($message, array $parameters) |
|
27 | + { |
|
28 | + if (!Str::contains($message, '%s')) { |
|
29 | + return $message; |
|
30 | + } |
|
31 | + return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | + foreach ($parameters as $key => $value) { |
|
33 | + return array_shift($parameters); |
|
34 | + } |
|
35 | + }, $message); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Validate that an attribute was "accepted". |
|
40 | - * This validation rule implies the attribute is "required". |
|
41 | - * @param string $attribute |
|
42 | - * @param mixed $value |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function validateAccepted($value) |
|
46 | - { |
|
47 | - $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
|
48 | - return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
49 | - } |
|
38 | + /** |
|
39 | + * Validate that an attribute was "accepted". |
|
40 | + * This validation rule implies the attribute is "required". |
|
41 | + * @param string $attribute |
|
42 | + * @param mixed $value |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function validateAccepted($value) |
|
46 | + { |
|
47 | + $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
|
48 | + return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Validate the size of an attribute is between a set of values. |
|
53 | - * @param string $attribute |
|
54 | - * @param mixed $value |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public function validateBetween($value, $attribute, array $parameters) |
|
58 | - { |
|
59 | - $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | - $size = $this->getSize($attribute, $value); |
|
61 | - return $size >= $parameters[0] && $size <= $parameters[1]; |
|
62 | - } |
|
51 | + /** |
|
52 | + * Validate the size of an attribute is between a set of values. |
|
53 | + * @param string $attribute |
|
54 | + * @param mixed $value |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public function validateBetween($value, $attribute, array $parameters) |
|
58 | + { |
|
59 | + $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | + $size = $this->getSize($attribute, $value); |
|
61 | + return $size >= $parameters[0] && $size <= $parameters[1]; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Validate that an attribute is a valid e-mail address. |
|
66 | - * @param mixed $value |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function validateEmail($value) |
|
70 | - { |
|
71 | - return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Validate that an attribute is a valid e-mail address. |
|
66 | + * @param mixed $value |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function validateEmail($value) |
|
70 | + { |
|
71 | + return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Validate the size of an attribute is less than a maximum value. |
|
76 | - * @param string $attribute |
|
77 | - * @param mixed $value |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function validateMax($value, $attribute, array $parameters) |
|
81 | - { |
|
82 | - $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | - return $this->getSize($attribute, $value) <= $parameters[0]; |
|
84 | - } |
|
74 | + /** |
|
75 | + * Validate the size of an attribute is less than a maximum value. |
|
76 | + * @param string $attribute |
|
77 | + * @param mixed $value |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function validateMax($value, $attribute, array $parameters) |
|
81 | + { |
|
82 | + $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | + return $this->getSize($attribute, $value) <= $parameters[0]; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Validate the size of an attribute is greater than a minimum value. |
|
88 | - * @param string $attribute |
|
89 | - * @param mixed $value |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function validateMin($value, $attribute, array $parameters) |
|
93 | - { |
|
94 | - $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | - return $this->getSize($attribute, $value) >= $parameters[0]; |
|
96 | - } |
|
86 | + /** |
|
87 | + * Validate the size of an attribute is greater than a minimum value. |
|
88 | + * @param string $attribute |
|
89 | + * @param mixed $value |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function validateMin($value, $attribute, array $parameters) |
|
93 | + { |
|
94 | + $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | + return $this->getSize($attribute, $value) >= $parameters[0]; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Validate that an attribute is numeric. |
|
100 | - * @param mixed $value |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function validateNumber($value) |
|
104 | - { |
|
105 | - return is_numeric($value); |
|
106 | - } |
|
98 | + /** |
|
99 | + * Validate that an attribute is numeric. |
|
100 | + * @param mixed $value |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function validateNumber($value) |
|
104 | + { |
|
105 | + return is_numeric($value); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Validate that a required attribute exists. |
|
110 | - * @param mixed $value |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function validateRequired($value) |
|
114 | - { |
|
115 | - return is_null($value) |
|
116 | - || (is_string($value) && '' === trim($value)) |
|
117 | - || (is_array($value) && count($value) < 1) |
|
118 | - ? false |
|
119 | - : true; |
|
120 | - } |
|
108 | + /** |
|
109 | + * Validate that a required attribute exists. |
|
110 | + * @param mixed $value |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function validateRequired($value) |
|
114 | + { |
|
115 | + return is_null($value) |
|
116 | + || (is_string($value) && '' === trim($value)) |
|
117 | + || (is_array($value) && count($value) < 1) |
|
118 | + ? false |
|
119 | + : true; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Require a certain number of parameters to be present. |
|
124 | - * @param int $count |
|
125 | - * @param string $rule |
|
126 | - * @return void |
|
127 | - * @throws InvalidArgumentException |
|
128 | - */ |
|
129 | - protected function requireParameterCount($count, array $parameters, $rule) |
|
130 | - { |
|
131 | - if (count($parameters) < $count) { |
|
132 | - throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
133 | - } |
|
134 | - } |
|
122 | + /** |
|
123 | + * Require a certain number of parameters to be present. |
|
124 | + * @param int $count |
|
125 | + * @param string $rule |
|
126 | + * @return void |
|
127 | + * @throws InvalidArgumentException |
|
128 | + */ |
|
129 | + protected function requireParameterCount($count, array $parameters, $rule) |
|
130 | + { |
|
131 | + if (count($parameters) < $count) { |
|
132 | + throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
@@ -16,23 +16,23 @@ discard block |
||
16 | 16 | * @param mixed $value |
17 | 17 | * @return mixed |
18 | 18 | */ |
19 | - abstract protected function getSize($attribute, $value); |
|
19 | + abstract protected function getSize( $attribute, $value ); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Replace all placeholders. |
23 | 23 | * @param string $message |
24 | 24 | * @return string |
25 | 25 | */ |
26 | - protected function replace($message, array $parameters) |
|
26 | + protected function replace( $message, array $parameters ) |
|
27 | 27 | { |
28 | - if (!Str::contains($message, '%s')) { |
|
28 | + if( !Str::contains( $message, '%s' ) ) { |
|
29 | 29 | return $message; |
30 | 30 | } |
31 | - return preg_replace_callback('/(%s)/', function () use (&$parameters) { |
|
32 | - foreach ($parameters as $key => $value) { |
|
33 | - return array_shift($parameters); |
|
31 | + return preg_replace_callback( '/(%s)/', function() use (&$parameters) { |
|
32 | + foreach( $parameters as $key => $value ) { |
|
33 | + return array_shift( $parameters ); |
|
34 | 34 | } |
35 | - }, $message); |
|
35 | + }, $message ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * @param mixed $value |
43 | 43 | * @return bool |
44 | 44 | */ |
45 | - public function validateAccepted($value) |
|
45 | + public function validateAccepted( $value ) |
|
46 | 46 | { |
47 | 47 | $acceptable = ['yes', 'on', '1', 1, true, 'true']; |
48 | - return $this->validateRequired($value) && in_array($value, $acceptable, true); |
|
48 | + return $this->validateRequired( $value ) && in_array( $value, $acceptable, true ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | * @param mixed $value |
55 | 55 | * @return bool |
56 | 56 | */ |
57 | - public function validateBetween($value, $attribute, array $parameters) |
|
57 | + public function validateBetween( $value, $attribute, array $parameters ) |
|
58 | 58 | { |
59 | - $this->requireParameterCount(2, $parameters, 'between'); |
|
60 | - $size = $this->getSize($attribute, $value); |
|
59 | + $this->requireParameterCount( 2, $parameters, 'between' ); |
|
60 | + $size = $this->getSize( $attribute, $value ); |
|
61 | 61 | return $size >= $parameters[0] && $size <= $parameters[1]; |
62 | 62 | } |
63 | 63 | |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @param mixed $value |
67 | 67 | * @return bool |
68 | 68 | */ |
69 | - public function validateEmail($value) |
|
69 | + public function validateEmail( $value ) |
|
70 | 70 | { |
71 | - return false !== filter_var($value, FILTER_VALIDATE_EMAIL); |
|
71 | + return false !== filter_var( $value, FILTER_VALIDATE_EMAIL ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | * @param mixed $value |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | - public function validateMax($value, $attribute, array $parameters) |
|
80 | + public function validateMax( $value, $attribute, array $parameters ) |
|
81 | 81 | { |
82 | - $this->requireParameterCount(1, $parameters, 'max'); |
|
83 | - return $this->getSize($attribute, $value) <= $parameters[0]; |
|
82 | + $this->requireParameterCount( 1, $parameters, 'max' ); |
|
83 | + return $this->getSize( $attribute, $value ) <= $parameters[0]; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * @param mixed $value |
90 | 90 | * @return bool |
91 | 91 | */ |
92 | - public function validateMin($value, $attribute, array $parameters) |
|
92 | + public function validateMin( $value, $attribute, array $parameters ) |
|
93 | 93 | { |
94 | - $this->requireParameterCount(1, $parameters, 'min'); |
|
95 | - return $this->getSize($attribute, $value) >= $parameters[0]; |
|
94 | + $this->requireParameterCount( 1, $parameters, 'min' ); |
|
95 | + return $this->getSize( $attribute, $value ) >= $parameters[0]; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param mixed $value |
101 | 101 | * @return bool |
102 | 102 | */ |
103 | - public function validateNumber($value) |
|
103 | + public function validateNumber( $value ) |
|
104 | 104 | { |
105 | - return is_numeric($value); |
|
105 | + return is_numeric( $value ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | * @param mixed $value |
111 | 111 | * @return bool |
112 | 112 | */ |
113 | - public function validateRequired($value) |
|
113 | + public function validateRequired( $value ) |
|
114 | 114 | { |
115 | - return is_null($value) |
|
116 | - || (is_string($value) && '' === trim($value)) |
|
117 | - || (is_array($value) && count($value) < 1) |
|
115 | + return is_null( $value ) |
|
116 | + || (is_string( $value ) && '' === trim( $value )) |
|
117 | + || (is_array( $value ) && count( $value ) < 1) |
|
118 | 118 | ? false |
119 | 119 | : true; |
120 | 120 | } |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @return void |
127 | 127 | * @throws InvalidArgumentException |
128 | 128 | */ |
129 | - protected function requireParameterCount($count, array $parameters, $rule) |
|
129 | + protected function requireParameterCount( $count, array $parameters, $rule ) |
|
130 | 130 | { |
131 | - if (count($parameters) < $count) { |
|
132 | - throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters."); |
|
131 | + if( count( $parameters ) < $count ) { |
|
132 | + throw new InvalidArgumentException( "Validation rule $rule requires at least $count parameters." ); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
@@ -6,97 +6,97 @@ |
||
6 | 6 | |
7 | 7 | class Translator |
8 | 8 | { |
9 | - /** |
|
10 | - * @param string $original |
|
11 | - * @param string $domain |
|
12 | - * @return string |
|
13 | - */ |
|
14 | - public function translate($original, $domain, array $args) |
|
15 | - { |
|
16 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
17 | - if (!in_array($domain, $domains)) { |
|
18 | - return $original; |
|
19 | - } |
|
20 | - $args = $this->normalizeTranslationArgs($args); |
|
21 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
22 | - if (empty($strings)) { |
|
23 | - return $original; |
|
24 | - } |
|
25 | - $string = current($strings); |
|
26 | - return 'plural' == $string['type'] |
|
27 | - ? $this->translatePlural($domain, $string, $args) |
|
28 | - : $this->translateSingle($domain, $string, $args); |
|
29 | - } |
|
9 | + /** |
|
10 | + * @param string $original |
|
11 | + * @param string $domain |
|
12 | + * @return string |
|
13 | + */ |
|
14 | + public function translate($original, $domain, array $args) |
|
15 | + { |
|
16 | + $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
17 | + if (!in_array($domain, $domains)) { |
|
18 | + return $original; |
|
19 | + } |
|
20 | + $args = $this->normalizeTranslationArgs($args); |
|
21 | + $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
22 | + if (empty($strings)) { |
|
23 | + return $original; |
|
24 | + } |
|
25 | + $string = current($strings); |
|
26 | + return 'plural' == $string['type'] |
|
27 | + ? $this->translatePlural($domain, $string, $args) |
|
28 | + : $this->translateSingle($domain, $string, $args); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Used when search/replacing a default text-domain translation |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function getTranslation(array $args) |
|
36 | - { |
|
37 | - $args = $this->normalizeTranslationArgs($args); |
|
38 | - return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
39 | - } |
|
31 | + /** |
|
32 | + * Used when search/replacing a default text-domain translation |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function getTranslation(array $args) |
|
36 | + { |
|
37 | + $args = $this->normalizeTranslationArgs($args); |
|
38 | + return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $single |
|
43 | - * @param string $plural |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - protected function getTranslationStrings($single, $plural) |
|
47 | - { |
|
48 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
49 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
50 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
51 | - }); |
|
52 | - } |
|
41 | + /** |
|
42 | + * @param string $single |
|
43 | + * @param string $plural |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + protected function getTranslationStrings($single, $plural) |
|
47 | + { |
|
48 | + return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
49 | + return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
50 | + && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
51 | + }); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - protected function normalizeTranslationArgs(array $args) |
|
58 | - { |
|
59 | - $defaults = [ |
|
60 | - 'context' => '', |
|
61 | - 'number' => 1, |
|
62 | - 'plural' => '', |
|
63 | - 'single' => '', |
|
64 | - ]; |
|
65 | - return shortcode_atts($defaults, $args); |
|
66 | - } |
|
54 | + /** |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + protected function normalizeTranslationArgs(array $args) |
|
58 | + { |
|
59 | + $defaults = [ |
|
60 | + 'context' => '', |
|
61 | + 'number' => 1, |
|
62 | + 'plural' => '', |
|
63 | + 'single' => '', |
|
64 | + ]; |
|
65 | + return shortcode_atts($defaults, $args); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $domain |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - protected function translatePlural($domain, array $string, array $args) |
|
73 | - { |
|
74 | - if (!empty($string['s2'])) { |
|
75 | - $args['single'] = $string['s2']; |
|
76 | - } |
|
77 | - if (!empty($string['p2'])) { |
|
78 | - $args['plural'] = $string['p2']; |
|
79 | - } |
|
80 | - return get_translations_for_domain($domain)->translate_plural( |
|
81 | - $args['single'], |
|
82 | - $args['plural'], |
|
83 | - $args['number'], |
|
84 | - $args['context'] |
|
85 | - ); |
|
86 | - } |
|
68 | + /** |
|
69 | + * @param string $domain |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + protected function translatePlural($domain, array $string, array $args) |
|
73 | + { |
|
74 | + if (!empty($string['s2'])) { |
|
75 | + $args['single'] = $string['s2']; |
|
76 | + } |
|
77 | + if (!empty($string['p2'])) { |
|
78 | + $args['plural'] = $string['p2']; |
|
79 | + } |
|
80 | + return get_translations_for_domain($domain)->translate_plural( |
|
81 | + $args['single'], |
|
82 | + $args['plural'], |
|
83 | + $args['number'], |
|
84 | + $args['context'] |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param string $domain |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - protected function translateSingle($domain, array $string, array $args) |
|
93 | - { |
|
94 | - if (!empty($string['s2'])) { |
|
95 | - $args['single'] = $string['s2']; |
|
96 | - } |
|
97 | - return get_translations_for_domain($domain)->translate( |
|
98 | - $args['single'], |
|
99 | - $args['context'] |
|
100 | - ); |
|
101 | - } |
|
88 | + /** |
|
89 | + * @param string $domain |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + protected function translateSingle($domain, array $string, array $args) |
|
93 | + { |
|
94 | + if (!empty($string['s2'])) { |
|
95 | + $args['single'] = $string['s2']; |
|
96 | + } |
|
97 | + return get_translations_for_domain($domain)->translate( |
|
98 | + $args['single'], |
|
99 | + $args['context'] |
|
100 | + ); |
|
101 | + } |
|
102 | 102 | } |
@@ -11,31 +11,31 @@ discard block |
||
11 | 11 | * @param string $domain |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function translate($original, $domain, array $args) |
|
14 | + public function translate( $original, $domain, array $args ) |
|
15 | 15 | { |
16 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
17 | - if (!in_array($domain, $domains)) { |
|
16 | + $domains = apply_filters( 'site-reviews/translator/domains', [Application::ID] ); |
|
17 | + if( !in_array( $domain, $domains ) ) { |
|
18 | 18 | return $original; |
19 | 19 | } |
20 | - $args = $this->normalizeTranslationArgs($args); |
|
21 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
22 | - if (empty($strings)) { |
|
20 | + $args = $this->normalizeTranslationArgs( $args ); |
|
21 | + $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
|
22 | + if( empty($strings) ) { |
|
23 | 23 | return $original; |
24 | 24 | } |
25 | - $string = current($strings); |
|
25 | + $string = current( $strings ); |
|
26 | 26 | return 'plural' == $string['type'] |
27 | - ? $this->translatePlural($domain, $string, $args) |
|
28 | - : $this->translateSingle($domain, $string, $args); |
|
27 | + ? $this->translatePlural( $domain, $string, $args ) |
|
28 | + : $this->translateSingle( $domain, $string, $args ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Used when search/replacing a default text-domain translation |
33 | 33 | * @return string |
34 | 34 | */ |
35 | - public function getTranslation(array $args) |
|
35 | + public function getTranslation( array $args ) |
|
36 | 36 | { |
37 | - $args = $this->normalizeTranslationArgs($args); |
|
38 | - return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
37 | + $args = $this->normalizeTranslationArgs( $args ); |
|
38 | + return get_translations_for_domain( Application::ID )->translate_plural( $args['single'], $args['plural'], $args['number'] ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | * @param string $plural |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - protected function getTranslationStrings($single, $plural) |
|
46 | + protected function getTranslationStrings( $single, $plural ) |
|
47 | 47 | { |
48 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
49 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
50 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
48 | + return array_filter( glsr( Translation::class )->translations(), function( $string ) use ($single, $plural) { |
|
49 | + return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
|
50 | + && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
|
51 | 51 | }); |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - protected function normalizeTranslationArgs(array $args) |
|
57 | + protected function normalizeTranslationArgs( array $args ) |
|
58 | 58 | { |
59 | 59 | $defaults = [ |
60 | 60 | 'context' => '', |
@@ -62,22 +62,22 @@ discard block |
||
62 | 62 | 'plural' => '', |
63 | 63 | 'single' => '', |
64 | 64 | ]; |
65 | - return shortcode_atts($defaults, $args); |
|
65 | + return shortcode_atts( $defaults, $args ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param string $domain |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - protected function translatePlural($domain, array $string, array $args) |
|
72 | + protected function translatePlural( $domain, array $string, array $args ) |
|
73 | 73 | { |
74 | - if (!empty($string['s2'])) { |
|
74 | + if( !empty($string['s2']) ) { |
|
75 | 75 | $args['single'] = $string['s2']; |
76 | 76 | } |
77 | - if (!empty($string['p2'])) { |
|
77 | + if( !empty($string['p2']) ) { |
|
78 | 78 | $args['plural'] = $string['p2']; |
79 | 79 | } |
80 | - return get_translations_for_domain($domain)->translate_plural( |
|
80 | + return get_translations_for_domain( $domain )->translate_plural( |
|
81 | 81 | $args['single'], |
82 | 82 | $args['plural'], |
83 | 83 | $args['number'], |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | * @param string $domain |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - protected function translateSingle($domain, array $string, array $args) |
|
92 | + protected function translateSingle( $domain, array $string, array $args ) |
|
93 | 93 | { |
94 | - if (!empty($string['s2'])) { |
|
94 | + if( !empty($string['s2']) ) { |
|
95 | 95 | $args['single'] = $string['s2']; |
96 | 96 | } |
97 | - return get_translations_for_domain($domain)->translate( |
|
97 | + return get_translations_for_domain( $domain )->translate( |
|
98 | 98 | $args['single'], |
99 | 99 | $args['context'] |
100 | 100 | ); |
@@ -6,174 +6,174 @@ |
||
6 | 6 | |
7 | 7 | class Str |
8 | 8 | { |
9 | - /** |
|
10 | - * @param string $string |
|
11 | - * @return string |
|
12 | - */ |
|
13 | - public static function camelCase($string) |
|
14 | - { |
|
15 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
16 | - return str_replace(' ', '', $string); |
|
17 | - } |
|
9 | + /** |
|
10 | + * @param string $string |
|
11 | + * @return string |
|
12 | + */ |
|
13 | + public static function camelCase($string) |
|
14 | + { |
|
15 | + $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
16 | + return str_replace(' ', '', $string); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $haystack |
|
21 | - * @param string $needle |
|
22 | - * @return bool |
|
23 | - */ |
|
24 | - public static function contains($haystack, $needle) |
|
25 | - { |
|
26 | - return false !== strpos($haystack, $needle); |
|
27 | - } |
|
19 | + /** |
|
20 | + * @param string $haystack |
|
21 | + * @param string $needle |
|
22 | + * @return bool |
|
23 | + */ |
|
24 | + public static function contains($haystack, $needle) |
|
25 | + { |
|
26 | + return false !== strpos($haystack, $needle); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param string $name |
|
31 | - * @param string $nameType first|first_initial|initials|last|last_initial |
|
32 | - * @param string $initialType period|period_space|space |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
36 | - { |
|
37 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
38 | - $firstName = array_shift($names); |
|
39 | - $lastName = array_pop($names); |
|
40 | - $initialTypes = [ |
|
41 | - 'period' => '.', |
|
42 | - 'period_space' => '. ', |
|
43 | - 'space' => ' ', |
|
44 | - ]; |
|
45 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
46 | - if ('initials' == $nameType) { |
|
47 | - return static::convertToInitials($name, $initialPunctuation); |
|
48 | - } |
|
49 | - $nameTypes = [ |
|
50 | - 'first' => $firstName, |
|
51 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
52 | - 'last' => $lastName, |
|
53 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
54 | - ]; |
|
55 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
56 | - } |
|
29 | + /** |
|
30 | + * @param string $name |
|
31 | + * @param string $nameType first|first_initial|initials|last|last_initial |
|
32 | + * @param string $initialType period|period_space|space |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public static function convertName($name, $nameType = '', $initialType = '') |
|
36 | + { |
|
37 | + $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
38 | + $firstName = array_shift($names); |
|
39 | + $lastName = array_pop($names); |
|
40 | + $initialTypes = [ |
|
41 | + 'period' => '.', |
|
42 | + 'period_space' => '. ', |
|
43 | + 'space' => ' ', |
|
44 | + ]; |
|
45 | + $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
46 | + if ('initials' == $nameType) { |
|
47 | + return static::convertToInitials($name, $initialPunctuation); |
|
48 | + } |
|
49 | + $nameTypes = [ |
|
50 | + 'first' => $firstName, |
|
51 | + 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
52 | + 'last' => $lastName, |
|
53 | + 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
54 | + ]; |
|
55 | + return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $path |
|
60 | - * @param string $prefix |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public static function convertPathToId($path, $prefix = '') |
|
64 | - { |
|
65 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
66 | - } |
|
58 | + /** |
|
59 | + * @param string $path |
|
60 | + * @param string $prefix |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public static function convertPathToId($path, $prefix = '') |
|
64 | + { |
|
65 | + return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $path |
|
70 | - * @param string $prefix |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function convertPathToName($path, $prefix = '') |
|
74 | - { |
|
75 | - $levels = explode('.', $path); |
|
76 | - return array_reduce($levels, function ($result, $value) { |
|
77 | - return $result .= '['.$value.']'; |
|
78 | - }, $prefix); |
|
79 | - } |
|
68 | + /** |
|
69 | + * @param string $path |
|
70 | + * @param string $prefix |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function convertPathToName($path, $prefix = '') |
|
74 | + { |
|
75 | + $levels = explode('.', $path); |
|
76 | + return array_reduce($levels, function ($result, $value) { |
|
77 | + return $result .= '['.$value.']'; |
|
78 | + }, $prefix); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param string $name |
|
83 | - * @param string $initialPunctuation |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
87 | - { |
|
88 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
89 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
90 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
91 | - }); |
|
92 | - } |
|
81 | + /** |
|
82 | + * @param string $name |
|
83 | + * @param string $initialPunctuation |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public static function convertToInitials($name, $initialPunctuation = '') |
|
87 | + { |
|
88 | + preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
89 | + return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
90 | + return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
91 | + }); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @param string $string |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public static function dashCase($string) |
|
99 | - { |
|
100 | - return str_replace('_', '-', static::snakeCase($string)); |
|
101 | - } |
|
94 | + /** |
|
95 | + * @param string $string |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public static function dashCase($string) |
|
99 | + { |
|
100 | + return str_replace('_', '-', static::snakeCase($string)); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param string $needle |
|
105 | - * @param string $haystack |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public static function endsWith($needle, $haystack) |
|
109 | - { |
|
110 | - $length = strlen($needle); |
|
111 | - return 0 != $length |
|
112 | - ? substr($haystack, -$length) === $needle |
|
113 | - : true; |
|
114 | - } |
|
103 | + /** |
|
104 | + * @param string $needle |
|
105 | + * @param string $haystack |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public static function endsWith($needle, $haystack) |
|
109 | + { |
|
110 | + $length = strlen($needle); |
|
111 | + return 0 != $length |
|
112 | + ? substr($haystack, -$length) === $needle |
|
113 | + : true; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @param string $prefix |
|
118 | - * @param string $string |
|
119 | - * @param string|null $trim |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public static function prefix($prefix, $string, $trim = null) |
|
123 | - { |
|
124 | - if (null === $trim) { |
|
125 | - $trim = $prefix; |
|
126 | - } |
|
127 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
128 | - } |
|
116 | + /** |
|
117 | + * @param string $prefix |
|
118 | + * @param string $string |
|
119 | + * @param string|null $trim |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public static function prefix($prefix, $string, $trim = null) |
|
123 | + { |
|
124 | + if (null === $trim) { |
|
125 | + $trim = $prefix; |
|
126 | + } |
|
127 | + return $prefix.trim(static::removePrefix($trim, $string)); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @param string $prefix |
|
132 | - * @param string $string |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public static function removePrefix($prefix, $string) |
|
136 | - { |
|
137 | - return static::startsWith($prefix, $string) |
|
138 | - ? substr($string, strlen($prefix)) |
|
139 | - : $string; |
|
140 | - } |
|
130 | + /** |
|
131 | + * @param string $prefix |
|
132 | + * @param string $string |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public static function removePrefix($prefix, $string) |
|
136 | + { |
|
137 | + return static::startsWith($prefix, $string) |
|
138 | + ? substr($string, strlen($prefix)) |
|
139 | + : $string; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @param string $string |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public static function snakeCase($string) |
|
147 | - { |
|
148 | - if (!ctype_lower($string)) { |
|
149 | - $string = preg_replace('/\s+/u', '', $string); |
|
150 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
151 | - $string = function_exists('mb_strtolower') |
|
152 | - ? mb_strtolower($string, 'UTF-8') |
|
153 | - : strtolower($string); |
|
154 | - } |
|
155 | - return str_replace('-', '_', $string); |
|
156 | - } |
|
142 | + /** |
|
143 | + * @param string $string |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public static function snakeCase($string) |
|
147 | + { |
|
148 | + if (!ctype_lower($string)) { |
|
149 | + $string = preg_replace('/\s+/u', '', $string); |
|
150 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
151 | + $string = function_exists('mb_strtolower') |
|
152 | + ? mb_strtolower($string, 'UTF-8') |
|
153 | + : strtolower($string); |
|
154 | + } |
|
155 | + return str_replace('-', '_', $string); |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @param string $needle |
|
160 | - * @param string $haystack |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public static function startsWith($needle, $haystack) |
|
164 | - { |
|
165 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
166 | - } |
|
158 | + /** |
|
159 | + * @param string $needle |
|
160 | + * @param string $haystack |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public static function startsWith($needle, $haystack) |
|
164 | + { |
|
165 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @param string $string |
|
170 | - * @param int $length |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public static function truncate($string, $length) |
|
174 | - { |
|
175 | - return strlen($string) > $length |
|
176 | - ? substr($string, 0, $length) |
|
177 | - : $string; |
|
178 | - } |
|
168 | + /** |
|
169 | + * @param string $string |
|
170 | + * @param int $length |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public static function truncate($string, $length) |
|
174 | + { |
|
175 | + return strlen($string) > $length |
|
176 | + ? substr($string, 0, $length) |
|
177 | + : $string; |
|
178 | + } |
|
179 | 179 | } |
@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | * @param string $string |
11 | 11 | * @return string |
12 | 12 | */ |
13 | - public static function camelCase($string) |
|
13 | + public static function camelCase( $string ) |
|
14 | 14 | { |
15 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
16 | - return str_replace(' ', '', $string); |
|
15 | + $string = ucwords( str_replace( ['-', '_'], ' ', trim( $string ) ) ); |
|
16 | + return str_replace( ' ', '', $string ); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | * @param string $needle |
22 | 22 | * @return bool |
23 | 23 | */ |
24 | - public static function contains($haystack, $needle) |
|
24 | + public static function contains( $haystack, $needle ) |
|
25 | 25 | { |
26 | - return false !== strpos($haystack, $needle); |
|
26 | + return false !== strpos( $haystack, $needle ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -32,27 +32,27 @@ discard block |
||
32 | 32 | * @param string $initialType period|period_space|space |
33 | 33 | * @return string |
34 | 34 | */ |
35 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
35 | + public static function convertName( $name, $nameType = '', $initialType = '' ) |
|
36 | 36 | { |
37 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
38 | - $firstName = array_shift($names); |
|
39 | - $lastName = array_pop($names); |
|
37 | + $names = preg_split( '/\W/', $name, 0, PREG_SPLIT_NO_EMPTY ); |
|
38 | + $firstName = array_shift( $names ); |
|
39 | + $lastName = array_pop( $names ); |
|
40 | 40 | $initialTypes = [ |
41 | 41 | 'period' => '.', |
42 | 42 | 'period_space' => '. ', |
43 | 43 | 'space' => ' ', |
44 | 44 | ]; |
45 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
46 | - if ('initials' == $nameType) { |
|
47 | - return static::convertToInitials($name, $initialPunctuation); |
|
45 | + $initialPunctuation = (string)Arr::get( $initialTypes, $initialType, ' ' ); |
|
46 | + if( 'initials' == $nameType ) { |
|
47 | + return static::convertToInitials( $name, $initialPunctuation ); |
|
48 | 48 | } |
49 | 49 | $nameTypes = [ |
50 | 50 | 'first' => $firstName, |
51 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
51 | + 'first_initial' => substr( $firstName, 0, 1 ).$initialPunctuation.$lastName, |
|
52 | 52 | 'last' => $lastName, |
53 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
53 | + 'last_initial' => $firstName.' '.substr( $lastName, 0, 1 ).$initialPunctuation, |
|
54 | 54 | ]; |
55 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
55 | + return trim( (string)Arr::get( $nameTypes, $nameType, $name ) ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | * @param string $prefix |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public static function convertPathToId($path, $prefix = '') |
|
63 | + public static function convertPathToId( $path, $prefix = '' ) |
|
64 | 64 | { |
65 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
65 | + return str_replace( ['[', ']'], ['-', ''], static::convertPathToName( $path, $prefix ) ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | * @param string $prefix |
71 | 71 | * @return string |
72 | 72 | */ |
73 | - public static function convertPathToName($path, $prefix = '') |
|
73 | + public static function convertPathToName( $path, $prefix = '' ) |
|
74 | 74 | { |
75 | - $levels = explode('.', $path); |
|
76 | - return array_reduce($levels, function ($result, $value) { |
|
75 | + $levels = explode( '.', $path ); |
|
76 | + return array_reduce( $levels, function( $result, $value ) { |
|
77 | 77 | return $result .= '['.$value.']'; |
78 | - }, $prefix); |
|
78 | + }, $prefix ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | * @param string $initialPunctuation |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
86 | + public static function convertToInitials( $name, $initialPunctuation = '' ) |
|
87 | 87 | { |
88 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
89 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
90 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
88 | + preg_match_all( '/(?<=\s|\b)\pL/u', $name, $matches ); |
|
89 | + return array_reduce( $matches[0], function( $carry, $word ) use ($initialPunctuation) { |
|
90 | + return $carry.strtoupper( substr( $word, 0, 1 ) ).$initialPunctuation; |
|
91 | 91 | }); |
92 | 92 | } |
93 | 93 | |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * @param string $string |
96 | 96 | * @return string |
97 | 97 | */ |
98 | - public static function dashCase($string) |
|
98 | + public static function dashCase( $string ) |
|
99 | 99 | { |
100 | - return str_replace('_', '-', static::snakeCase($string)); |
|
100 | + return str_replace( '_', '-', static::snakeCase( $string ) ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | * @param string $haystack |
106 | 106 | * @return bool |
107 | 107 | */ |
108 | - public static function endsWith($needle, $haystack) |
|
108 | + public static function endsWith( $needle, $haystack ) |
|
109 | 109 | { |
110 | - $length = strlen($needle); |
|
110 | + $length = strlen( $needle ); |
|
111 | 111 | return 0 != $length |
112 | - ? substr($haystack, -$length) === $needle |
|
112 | + ? substr( $haystack, -$length ) === $needle |
|
113 | 113 | : true; |
114 | 114 | } |
115 | 115 | |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | * @param string|null $trim |
120 | 120 | * @return string |
121 | 121 | */ |
122 | - public static function prefix($prefix, $string, $trim = null) |
|
122 | + public static function prefix( $prefix, $string, $trim = null ) |
|
123 | 123 | { |
124 | - if (null === $trim) { |
|
124 | + if( null === $trim ) { |
|
125 | 125 | $trim = $prefix; |
126 | 126 | } |
127 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
127 | + return $prefix.trim( static::removePrefix( $trim, $string ) ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | * @param string $string |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public static function removePrefix($prefix, $string) |
|
135 | + public static function removePrefix( $prefix, $string ) |
|
136 | 136 | { |
137 | - return static::startsWith($prefix, $string) |
|
138 | - ? substr($string, strlen($prefix)) |
|
137 | + return static::startsWith( $prefix, $string ) |
|
138 | + ? substr( $string, strlen( $prefix ) ) |
|
139 | 139 | : $string; |
140 | 140 | } |
141 | 141 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | * @param string $string |
144 | 144 | * @return string |
145 | 145 | */ |
146 | - public static function snakeCase($string) |
|
146 | + public static function snakeCase( $string ) |
|
147 | 147 | { |
148 | - if (!ctype_lower($string)) { |
|
149 | - $string = preg_replace('/\s+/u', '', $string); |
|
150 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
151 | - $string = function_exists('mb_strtolower') |
|
152 | - ? mb_strtolower($string, 'UTF-8') |
|
153 | - : strtolower($string); |
|
148 | + if( !ctype_lower( $string ) ) { |
|
149 | + $string = preg_replace( '/\s+/u', '', $string ); |
|
150 | + $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
151 | + $string = function_exists( 'mb_strtolower' ) |
|
152 | + ? mb_strtolower( $string, 'UTF-8' ) |
|
153 | + : strtolower( $string ); |
|
154 | 154 | } |
155 | - return str_replace('-', '_', $string); |
|
155 | + return str_replace( '-', '_', $string ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | * @param string $haystack |
161 | 161 | * @return bool |
162 | 162 | */ |
163 | - public static function startsWith($needle, $haystack) |
|
163 | + public static function startsWith( $needle, $haystack ) |
|
164 | 164 | { |
165 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
165 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | * @param int $length |
171 | 171 | * @return string |
172 | 172 | */ |
173 | - public static function truncate($string, $length) |
|
173 | + public static function truncate( $string, $length ) |
|
174 | 174 | { |
175 | - return strlen($string) > $length |
|
176 | - ? substr($string, 0, $length) |
|
175 | + return strlen( $string ) > $length |
|
176 | + ? substr( $string, 0, $length ) |
|
177 | 177 | : $string; |
178 | 178 | } |
179 | 179 | } |
@@ -10,228 +10,228 @@ |
||
10 | 10 | |
11 | 11 | class TranslationController |
12 | 12 | { |
13 | - /** |
|
14 | - * @var Translator |
|
15 | - */ |
|
16 | - public $translator; |
|
17 | - |
|
18 | - public function __construct(Translator $translator) |
|
19 | - { |
|
20 | - $this->translator = $translator; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * @param array $messages |
|
25 | - * @return array |
|
26 | - * @filter bulk_post_updated_messages |
|
27 | - */ |
|
28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
29 | - { |
|
30 | - $messages = Arr::consolidateArray($messages); |
|
31 | - $messages[Application::POST_TYPE] = [ |
|
32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
37 | - ]; |
|
38 | - return $messages; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param string $translation |
|
43 | - * @param string $text |
|
44 | - * @param string $domain |
|
45 | - * @return string |
|
46 | - * @filter gettext |
|
47 | - */ |
|
48 | - public function filterGettext($translation, $text, $domain) |
|
49 | - { |
|
50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $translation |
|
55 | - * @param string $text |
|
56 | - * @return string |
|
57 | - * @filter site-reviews/gettext/site-reviews |
|
58 | - */ |
|
59 | - public function filterGettextSiteReviews($translation, $text) |
|
60 | - { |
|
61 | - return $this->translator->translate($translation, Application::ID, [ |
|
62 | - 'single' => $text, |
|
63 | - ]); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @param string $translation |
|
68 | - * @param string $text |
|
69 | - * @param string $context |
|
70 | - * @param string $domain |
|
71 | - * @return string |
|
72 | - * @filter gettext_with_context |
|
73 | - */ |
|
74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
75 | - { |
|
76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $translation |
|
81 | - * @param string $text |
|
82 | - * @param string $context |
|
83 | - * @return string |
|
84 | - * @filter site-reviews/gettext_with_context/site-reviews |
|
85 | - */ |
|
86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
87 | - { |
|
88 | - return $this->translator->translate($translation, Application::ID, [ |
|
89 | - 'context' => $context, |
|
90 | - 'single' => $text, |
|
91 | - ]); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param string $translation |
|
96 | - * @param string $single |
|
97 | - * @param string $plural |
|
98 | - * @param int $number |
|
99 | - * @param string $domain |
|
100 | - * @return string |
|
101 | - * @filter ngettext |
|
102 | - */ |
|
103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
104 | - { |
|
105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $translation |
|
110 | - * @param string $single |
|
111 | - * @param string $plural |
|
112 | - * @param int $number |
|
113 | - * @return string |
|
114 | - * @filter site-reviews/ngettext/site-reviews |
|
115 | - */ |
|
116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
117 | - { |
|
118 | - return $this->translator->translate($translation, Application::ID, [ |
|
119 | - 'number' => $number, |
|
120 | - 'plural' => $plural, |
|
121 | - 'single' => $single, |
|
122 | - ]); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $translation |
|
127 | - * @param string $single |
|
128 | - * @param string $plural |
|
129 | - * @param int $number |
|
130 | - * @param string $context |
|
131 | - * @param string $domain |
|
132 | - * @return string |
|
133 | - * @filter ngettext_with_context |
|
134 | - */ |
|
135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
136 | - { |
|
137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param string $translation |
|
142 | - * @param string $single |
|
143 | - * @param string $plural |
|
144 | - * @param int $number |
|
145 | - * @param string $context |
|
146 | - * @return string |
|
147 | - * @filter site-reviews/ngettext_with_context/site-reviews |
|
148 | - */ |
|
149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
150 | - { |
|
151 | - return $this->translator->translate($translation, Application::ID, [ |
|
152 | - 'context' => $context, |
|
153 | - 'number' => $number, |
|
154 | - 'plural' => $plural, |
|
155 | - 'single' => $single, |
|
156 | - ]); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @param array $postStates |
|
161 | - * @param \WP_Post $post |
|
162 | - * @return array |
|
163 | - * @filter display_post_states |
|
164 | - */ |
|
165 | - public function filterPostStates($postStates, $post) |
|
166 | - { |
|
167 | - $postStates = Arr::consolidateArray($postStates); |
|
168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
170 | - } |
|
171 | - return $postStates; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param string $translation |
|
176 | - * @param string $text |
|
177 | - * @return string |
|
178 | - * @filter site-reviews/gettext/default |
|
179 | - * @filter site-reviews/gettext_with_context/default |
|
180 | - */ |
|
181 | - public function filterPostStatusLabels($translation, $text) |
|
182 | - { |
|
183 | - return $this->canModifyTranslation() |
|
184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
185 | - : $translation; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @param string $translation |
|
190 | - * @param string $single |
|
191 | - * @param string $plural |
|
192 | - * @param int $number |
|
193 | - * @return string |
|
194 | - * @filter site-reviews/ngettext/default |
|
195 | - */ |
|
196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
197 | - { |
|
198 | - if ($this->canModifyTranslation()) { |
|
199 | - $strings = [ |
|
200 | - 'Published' => __('Approved', 'site-reviews'), |
|
201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
202 | - ]; |
|
203 | - foreach ($strings as $search => $replace) { |
|
204 | - if (!Str::contains($single, $search)) { |
|
205 | - continue; |
|
206 | - } |
|
207 | - return $this->translator->getTranslation([ |
|
208 | - 'number' => $number, |
|
209 | - 'plural' => str_replace($search, $replace, $plural), |
|
210 | - 'single' => str_replace($search, $replace, $single), |
|
211 | - ]); |
|
212 | - } |
|
213 | - } |
|
214 | - return $translation; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @return void |
|
219 | - * @action admin_enqueue_scripts |
|
220 | - */ |
|
221 | - public function translatePostStatusLabels() |
|
222 | - { |
|
223 | - if ($this->canModifyTranslation()) { |
|
224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @return bool |
|
230 | - */ |
|
231 | - protected function canModifyTranslation() |
|
232 | - { |
|
233 | - $screen = glsr_current_screen(); |
|
234 | - return Application::POST_TYPE == $screen->post_type |
|
235 | - && in_array($screen->base, ['edit', 'post']); |
|
236 | - } |
|
13 | + /** |
|
14 | + * @var Translator |
|
15 | + */ |
|
16 | + public $translator; |
|
17 | + |
|
18 | + public function __construct(Translator $translator) |
|
19 | + { |
|
20 | + $this->translator = $translator; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * @param array $messages |
|
25 | + * @return array |
|
26 | + * @filter bulk_post_updated_messages |
|
27 | + */ |
|
28 | + public function filterBulkUpdateMessages($messages, array $counts) |
|
29 | + { |
|
30 | + $messages = Arr::consolidateArray($messages); |
|
31 | + $messages[Application::POST_TYPE] = [ |
|
32 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
33 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
34 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
35 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
36 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
37 | + ]; |
|
38 | + return $messages; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param string $translation |
|
43 | + * @param string $text |
|
44 | + * @param string $domain |
|
45 | + * @return string |
|
46 | + * @filter gettext |
|
47 | + */ |
|
48 | + public function filterGettext($translation, $text, $domain) |
|
49 | + { |
|
50 | + return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $translation |
|
55 | + * @param string $text |
|
56 | + * @return string |
|
57 | + * @filter site-reviews/gettext/site-reviews |
|
58 | + */ |
|
59 | + public function filterGettextSiteReviews($translation, $text) |
|
60 | + { |
|
61 | + return $this->translator->translate($translation, Application::ID, [ |
|
62 | + 'single' => $text, |
|
63 | + ]); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @param string $translation |
|
68 | + * @param string $text |
|
69 | + * @param string $context |
|
70 | + * @param string $domain |
|
71 | + * @return string |
|
72 | + * @filter gettext_with_context |
|
73 | + */ |
|
74 | + public function filterGettextWithContext($translation, $text, $context, $domain) |
|
75 | + { |
|
76 | + return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $translation |
|
81 | + * @param string $text |
|
82 | + * @param string $context |
|
83 | + * @return string |
|
84 | + * @filter site-reviews/gettext_with_context/site-reviews |
|
85 | + */ |
|
86 | + public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
87 | + { |
|
88 | + return $this->translator->translate($translation, Application::ID, [ |
|
89 | + 'context' => $context, |
|
90 | + 'single' => $text, |
|
91 | + ]); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param string $translation |
|
96 | + * @param string $single |
|
97 | + * @param string $plural |
|
98 | + * @param int $number |
|
99 | + * @param string $domain |
|
100 | + * @return string |
|
101 | + * @filter ngettext |
|
102 | + */ |
|
103 | + public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
104 | + { |
|
105 | + return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $translation |
|
110 | + * @param string $single |
|
111 | + * @param string $plural |
|
112 | + * @param int $number |
|
113 | + * @return string |
|
114 | + * @filter site-reviews/ngettext/site-reviews |
|
115 | + */ |
|
116 | + public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
117 | + { |
|
118 | + return $this->translator->translate($translation, Application::ID, [ |
|
119 | + 'number' => $number, |
|
120 | + 'plural' => $plural, |
|
121 | + 'single' => $single, |
|
122 | + ]); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $translation |
|
127 | + * @param string $single |
|
128 | + * @param string $plural |
|
129 | + * @param int $number |
|
130 | + * @param string $context |
|
131 | + * @param string $domain |
|
132 | + * @return string |
|
133 | + * @filter ngettext_with_context |
|
134 | + */ |
|
135 | + public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
136 | + { |
|
137 | + return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param string $translation |
|
142 | + * @param string $single |
|
143 | + * @param string $plural |
|
144 | + * @param int $number |
|
145 | + * @param string $context |
|
146 | + * @return string |
|
147 | + * @filter site-reviews/ngettext_with_context/site-reviews |
|
148 | + */ |
|
149 | + public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
150 | + { |
|
151 | + return $this->translator->translate($translation, Application::ID, [ |
|
152 | + 'context' => $context, |
|
153 | + 'number' => $number, |
|
154 | + 'plural' => $plural, |
|
155 | + 'single' => $single, |
|
156 | + ]); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @param array $postStates |
|
161 | + * @param \WP_Post $post |
|
162 | + * @return array |
|
163 | + * @filter display_post_states |
|
164 | + */ |
|
165 | + public function filterPostStates($postStates, $post) |
|
166 | + { |
|
167 | + $postStates = Arr::consolidateArray($postStates); |
|
168 | + if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
169 | + $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
170 | + } |
|
171 | + return $postStates; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param string $translation |
|
176 | + * @param string $text |
|
177 | + * @return string |
|
178 | + * @filter site-reviews/gettext/default |
|
179 | + * @filter site-reviews/gettext_with_context/default |
|
180 | + */ |
|
181 | + public function filterPostStatusLabels($translation, $text) |
|
182 | + { |
|
183 | + return $this->canModifyTranslation() |
|
184 | + ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
185 | + : $translation; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @param string $translation |
|
190 | + * @param string $single |
|
191 | + * @param string $plural |
|
192 | + * @param int $number |
|
193 | + * @return string |
|
194 | + * @filter site-reviews/ngettext/default |
|
195 | + */ |
|
196 | + public function filterPostStatusText($translation, $single, $plural, $number) |
|
197 | + { |
|
198 | + if ($this->canModifyTranslation()) { |
|
199 | + $strings = [ |
|
200 | + 'Published' => __('Approved', 'site-reviews'), |
|
201 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
202 | + ]; |
|
203 | + foreach ($strings as $search => $replace) { |
|
204 | + if (!Str::contains($single, $search)) { |
|
205 | + continue; |
|
206 | + } |
|
207 | + return $this->translator->getTranslation([ |
|
208 | + 'number' => $number, |
|
209 | + 'plural' => str_replace($search, $replace, $plural), |
|
210 | + 'single' => str_replace($search, $replace, $single), |
|
211 | + ]); |
|
212 | + } |
|
213 | + } |
|
214 | + return $translation; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + * @action admin_enqueue_scripts |
|
220 | + */ |
|
221 | + public function translatePostStatusLabels() |
|
222 | + { |
|
223 | + if ($this->canModifyTranslation()) { |
|
224 | + glsr(Labels::class)->translatePostStatusLabels(); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @return bool |
|
230 | + */ |
|
231 | + protected function canModifyTranslation() |
|
232 | + { |
|
233 | + $screen = glsr_current_screen(); |
|
234 | + return Application::POST_TYPE == $screen->post_type |
|
235 | + && in_array($screen->base, ['edit', 'post']); |
|
236 | + } |
|
237 | 237 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | public $translator; |
17 | 17 | |
18 | - public function __construct(Translator $translator) |
|
18 | + public function __construct( Translator $translator ) |
|
19 | 19 | { |
20 | 20 | $this->translator = $translator; |
21 | 21 | } |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | * @return array |
26 | 26 | * @filter bulk_post_updated_messages |
27 | 27 | */ |
28 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
28 | + public function filterBulkUpdateMessages( $messages, array $counts ) |
|
29 | 29 | { |
30 | - $messages = Arr::consolidateArray($messages); |
|
30 | + $messages = Arr::consolidateArray( $messages ); |
|
31 | 31 | $messages[Application::POST_TYPE] = [ |
32 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
33 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
34 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
35 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
36 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
32 | + 'updated' => _n( '%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews' ), |
|
33 | + 'locked' => _n( '%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews' ), |
|
34 | + 'deleted' => _n( '%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews' ), |
|
35 | + 'trashed' => _n( '%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews' ), |
|
36 | + 'untrashed' => _n( '%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews' ), |
|
37 | 37 | ]; |
38 | 38 | return $messages; |
39 | 39 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @return string |
46 | 46 | * @filter gettext |
47 | 47 | */ |
48 | - public function filterGettext($translation, $text, $domain) |
|
48 | + public function filterGettext( $translation, $text, $domain ) |
|
49 | 49 | { |
50 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
50 | + return apply_filters( 'site-reviews/gettext/'.$domain, $translation, $text ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | * @return string |
57 | 57 | * @filter site-reviews/gettext/site-reviews |
58 | 58 | */ |
59 | - public function filterGettextSiteReviews($translation, $text) |
|
59 | + public function filterGettextSiteReviews( $translation, $text ) |
|
60 | 60 | { |
61 | - return $this->translator->translate($translation, Application::ID, [ |
|
61 | + return $this->translator->translate( $translation, Application::ID, [ |
|
62 | 62 | 'single' => $text, |
63 | - ]); |
|
63 | + ] ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @return string |
72 | 72 | * @filter gettext_with_context |
73 | 73 | */ |
74 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
74 | + public function filterGettextWithContext( $translation, $text, $context, $domain ) |
|
75 | 75 | { |
76 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
76 | + return apply_filters( 'site-reviews/gettext_with_context/'.$domain, $translation, $text, $context ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | * @return string |
84 | 84 | * @filter site-reviews/gettext_with_context/site-reviews |
85 | 85 | */ |
86 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
86 | + public function filterGettextWithContextSiteReviews( $translation, $text, $context ) |
|
87 | 87 | { |
88 | - return $this->translator->translate($translation, Application::ID, [ |
|
88 | + return $this->translator->translate( $translation, Application::ID, [ |
|
89 | 89 | 'context' => $context, |
90 | 90 | 'single' => $text, |
91 | - ]); |
|
91 | + ] ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @return string |
101 | 101 | * @filter ngettext |
102 | 102 | */ |
103 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
103 | + public function filterNgettext( $translation, $single, $plural, $number, $domain ) |
|
104 | 104 | { |
105 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
105 | + return apply_filters( 'site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | * @return string |
114 | 114 | * @filter site-reviews/ngettext/site-reviews |
115 | 115 | */ |
116 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
116 | + public function filterNgettextSiteReviews( $translation, $single, $plural, $number ) |
|
117 | 117 | { |
118 | - return $this->translator->translate($translation, Application::ID, [ |
|
118 | + return $this->translator->translate( $translation, Application::ID, [ |
|
119 | 119 | 'number' => $number, |
120 | 120 | 'plural' => $plural, |
121 | 121 | 'single' => $single, |
122 | - ]); |
|
122 | + ] ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @return string |
133 | 133 | * @filter ngettext_with_context |
134 | 134 | */ |
135 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
135 | + public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain ) |
|
136 | 136 | { |
137 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
137 | + return apply_filters( 'site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | * @return string |
147 | 147 | * @filter site-reviews/ngettext_with_context/site-reviews |
148 | 148 | */ |
149 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
149 | + public function filterNgettextWithContextSiteReviews( $translation, $single, $plural, $number, $context ) |
|
150 | 150 | { |
151 | - return $this->translator->translate($translation, Application::ID, [ |
|
151 | + return $this->translator->translate( $translation, Application::ID, [ |
|
152 | 152 | 'context' => $context, |
153 | 153 | 'number' => $number, |
154 | 154 | 'plural' => $plural, |
155 | 155 | 'single' => $single, |
156 | - ]); |
|
156 | + ] ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | * @return array |
163 | 163 | * @filter display_post_states |
164 | 164 | */ |
165 | - public function filterPostStates($postStates, $post) |
|
165 | + public function filterPostStates( $postStates, $post ) |
|
166 | 166 | { |
167 | - $postStates = Arr::consolidateArray($postStates); |
|
168 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
169 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
167 | + $postStates = Arr::consolidateArray( $postStates ); |
|
168 | + if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) && array_key_exists( 'pending', $postStates ) ) { |
|
169 | + $postStates['pending'] = __( 'Unapproved', 'site-reviews' ); |
|
170 | 170 | } |
171 | 171 | return $postStates; |
172 | 172 | } |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * @filter site-reviews/gettext/default |
179 | 179 | * @filter site-reviews/gettext_with_context/default |
180 | 180 | */ |
181 | - public function filterPostStatusLabels($translation, $text) |
|
181 | + public function filterPostStatusLabels( $translation, $text ) |
|
182 | 182 | { |
183 | 183 | return $this->canModifyTranslation() |
184 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
184 | + ? glsr( Labels::class )->filterPostStatusLabels( $translation, $text ) |
|
185 | 185 | : $translation; |
186 | 186 | } |
187 | 187 | |
@@ -193,22 +193,22 @@ discard block |
||
193 | 193 | * @return string |
194 | 194 | * @filter site-reviews/ngettext/default |
195 | 195 | */ |
196 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
196 | + public function filterPostStatusText( $translation, $single, $plural, $number ) |
|
197 | 197 | { |
198 | - if ($this->canModifyTranslation()) { |
|
198 | + if( $this->canModifyTranslation() ) { |
|
199 | 199 | $strings = [ |
200 | - 'Published' => __('Approved', 'site-reviews'), |
|
201 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
200 | + 'Published' => __( 'Approved', 'site-reviews' ), |
|
201 | + 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
202 | 202 | ]; |
203 | - foreach ($strings as $search => $replace) { |
|
204 | - if (!Str::contains($single, $search)) { |
|
203 | + foreach( $strings as $search => $replace ) { |
|
204 | + if( !Str::contains( $single, $search ) ) { |
|
205 | 205 | continue; |
206 | 206 | } |
207 | - return $this->translator->getTranslation([ |
|
207 | + return $this->translator->getTranslation( [ |
|
208 | 208 | 'number' => $number, |
209 | - 'plural' => str_replace($search, $replace, $plural), |
|
210 | - 'single' => str_replace($search, $replace, $single), |
|
211 | - ]); |
|
209 | + 'plural' => str_replace( $search, $replace, $plural ), |
|
210 | + 'single' => str_replace( $search, $replace, $single ), |
|
211 | + ] ); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | return $translation; |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function translatePostStatusLabels() |
222 | 222 | { |
223 | - if ($this->canModifyTranslation()) { |
|
224 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
223 | + if( $this->canModifyTranslation() ) { |
|
224 | + glsr( Labels::class )->translatePostStatusLabels(); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -232,6 +232,6 @@ discard block |
||
232 | 232 | { |
233 | 233 | $screen = glsr_current_screen(); |
234 | 234 | return Application::POST_TYPE == $screen->post_type |
235 | - && in_array($screen->base, ['edit', 'post']); |
|
235 | + && in_array( $screen->base, ['edit', 'post'] ); |
|
236 | 236 | } |
237 | 237 | } |
@@ -10,52 +10,52 @@ |
||
10 | 10 | |
11 | 11 | class Pagination implements PartialContract |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $args; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $args; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return void|string |
|
20 | - */ |
|
21 | - public function build(array $args = []) |
|
22 | - { |
|
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
25 | - return; |
|
26 | - } |
|
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
28 | - 'context' => [ |
|
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
30 | - 'loader' => '<div class="glsr-loader"></div>', |
|
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
32 | - ], |
|
33 | - ]); |
|
34 | - } |
|
18 | + /** |
|
19 | + * @return void|string |
|
20 | + */ |
|
21 | + public function build(array $args = []) |
|
22 | + { |
|
23 | + $this->args = $this->normalize($args); |
|
24 | + if ($this->args['total'] < 2) { |
|
25 | + return; |
|
26 | + } |
|
27 | + return glsr(Template::class)->build('templates/pagination', [ |
|
28 | + 'context' => [ |
|
29 | + 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
30 | + 'loader' => '<div class="glsr-loader"></div>', |
|
31 | + 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
32 | + ], |
|
33 | + ]); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected function buildLinks() |
|
40 | - { |
|
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if ('array' == $args['type']) { |
|
43 | - $args['type'] = 'plain'; |
|
44 | - } |
|
45 | - return paginate_links($args); |
|
46 | - } |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected function buildLinks() |
|
40 | + { |
|
41 | + $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | + if ('array' == $args['type']) { |
|
43 | + $args['type'] = 'plain'; |
|
44 | + } |
|
45 | + return paginate_links($args); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - protected function normalize(array $args) |
|
52 | - { |
|
53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
54 | - $args['base'] = $baseUrl.'%_%'; |
|
55 | - } |
|
56 | - return wp_parse_args(array_filter($args), [ |
|
57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
58 | - 'total' => 1, |
|
59 | - ]); |
|
60 | - } |
|
48 | + /** |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + protected function normalize(array $args) |
|
52 | + { |
|
53 | + if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
54 | + $args['base'] = $baseUrl.'%_%'; |
|
55 | + } |
|
56 | + return wp_parse_args(array_filter($args), [ |
|
57 | + 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
58 | + 'total' => 1, |
|
59 | + ]); |
|
60 | + } |
|
61 | 61 | } |
@@ -18,19 +18,19 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return void|string |
20 | 20 | */ |
21 | - public function build(array $args = []) |
|
21 | + public function build( array $args = [] ) |
|
22 | 22 | { |
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
23 | + $this->args = $this->normalize( $args ); |
|
24 | + if( $this->args['total'] < 2 ) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
27 | + return glsr( Template::class )->build( 'templates/pagination', [ |
|
28 | 28 | 'context' => [ |
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
29 | + 'links' => apply_filters( 'site-reviews/paginate_links', $this->buildLinks(), $this->args ), |
|
30 | 30 | 'loader' => '<div class="glsr-loader"></div>', |
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
31 | + 'screen_reader_text' => __( 'Site Reviews navigation', 'site-reviews' ), |
|
32 | 32 | ], |
33 | - ]); |
|
33 | + ] ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,24 +38,24 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function buildLinks() |
40 | 40 | { |
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if ('array' == $args['type']) { |
|
41 | + $args = glsr( Style::class )->paginationArgs( $this->args ); |
|
42 | + if( 'array' == $args['type'] ) { |
|
43 | 43 | $args['type'] = 'plain'; |
44 | 44 | } |
45 | - return paginate_links($args); |
|
45 | + return paginate_links( $args ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @return array |
50 | 50 | */ |
51 | - protected function normalize(array $args) |
|
51 | + protected function normalize( array $args ) |
|
52 | 52 | { |
53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
53 | + if( $baseUrl = Arr::get( $args, 'baseUrl' ) ) { |
|
54 | 54 | $args['base'] = $baseUrl.'%_%'; |
55 | 55 | } |
56 | - return wp_parse_args(array_filter($args), [ |
|
57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
56 | + return wp_parse_args( array_filter( $args ), [ |
|
57 | + 'current' => glsr( QueryBuilder::class )->getPaged(), |
|
58 | 58 | 'total' => 1, |
59 | - ]); |
|
59 | + ] ); |
|
60 | 60 | } |
61 | 61 | } |
@@ -8,135 +8,135 @@ |
||
8 | 8 | |
9 | 9 | class ReviewsHtml extends ArrayObject |
10 | 10 | { |
11 | - /** |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - public $args; |
|
11 | + /** |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + public $args; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - public $max_num_pages; |
|
16 | + /** |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + public $max_num_pages; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $pagination; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $pagination; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - public $reviews; |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + public $reviews; |
|
30 | 30 | |
31 | - public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
32 | - { |
|
33 | - $this->args = $args; |
|
34 | - $this->max_num_pages = $maxPageCount; |
|
35 | - $this->reviews = $renderedReviews; |
|
36 | - $this->pagination = $this->buildPagination(); |
|
37 | - parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | - } |
|
31 | + public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
32 | + { |
|
33 | + $this->args = $args; |
|
34 | + $this->max_num_pages = $maxPageCount; |
|
35 | + $this->reviews = $renderedReviews; |
|
36 | + $this->pagination = $this->buildPagination(); |
|
37 | + parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function __toString() |
|
44 | - { |
|
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
46 | - 'args' => $this->args, |
|
47 | - 'context' => [ |
|
48 | - 'assigned_to' => $this->args['assigned_to'], |
|
49 | - 'category' => $this->args['category'], |
|
50 | - 'class' => $this->getClass(), |
|
51 | - 'id' => $this->args['id'], |
|
52 | - 'pagination' => $this->getPagination(), |
|
53 | - 'reviews' => $this->getReviews(), |
|
54 | - ], |
|
55 | - ]); |
|
56 | - } |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function __toString() |
|
44 | + { |
|
45 | + return glsr(Template::class)->build('templates/reviews', [ |
|
46 | + 'args' => $this->args, |
|
47 | + 'context' => [ |
|
48 | + 'assigned_to' => $this->args['assigned_to'], |
|
49 | + 'category' => $this->args['category'], |
|
50 | + 'class' => $this->getClass(), |
|
51 | + 'id' => $this->args['id'], |
|
52 | + 'pagination' => $this->getPagination(), |
|
53 | + 'reviews' => $this->getReviews(), |
|
54 | + ], |
|
55 | + ]); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getPagination() |
|
62 | - { |
|
63 | - return wp_validate_boolean($this->args['pagination']) |
|
64 | - ? $this->pagination |
|
65 | - : ''; |
|
66 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getPagination() |
|
62 | + { |
|
63 | + return wp_validate_boolean($this->args['pagination']) |
|
64 | + ? $this->pagination |
|
65 | + : ''; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getReviews() |
|
72 | - { |
|
73 | - $html = empty($this->reviews) |
|
74 | - ? $this->getReviewsFallback() |
|
75 | - : implode(PHP_EOL, $this->reviews); |
|
76 | - $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
79 | - } |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getReviews() |
|
72 | + { |
|
73 | + $html = empty($this->reviews) |
|
74 | + ? $this->getReviewsFallback() |
|
75 | + : implode(PHP_EOL, $this->reviews); |
|
76 | + $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
77 | + $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | + return sprintf($wrapper, $html); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param mixed $key |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public function offsetGet($key) |
|
86 | - { |
|
87 | - if ('navigation' == $key) { |
|
88 | - glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
89 | - return $this->pagination; |
|
90 | - } |
|
91 | - if (property_exists($this, $key)) { |
|
92 | - return $this->$key; |
|
93 | - } |
|
94 | - return array_key_exists($key, $this->reviews) |
|
95 | - ? $this->reviews[$key] |
|
96 | - : null; |
|
97 | - } |
|
81 | + /** |
|
82 | + * @param mixed $key |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public function offsetGet($key) |
|
86 | + { |
|
87 | + if ('navigation' == $key) { |
|
88 | + glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
89 | + return $this->pagination; |
|
90 | + } |
|
91 | + if (property_exists($this, $key)) { |
|
92 | + return $this->$key; |
|
93 | + } |
|
94 | + return array_key_exists($key, $this->reviews) |
|
95 | + ? $this->reviews[$key] |
|
96 | + : null; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - protected function buildPagination() |
|
103 | - { |
|
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
107 | - 'total' => $this->max_num_pages, |
|
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
110 | - $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
113 | - } |
|
99 | + /** |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + protected function buildPagination() |
|
103 | + { |
|
104 | + $html = glsr(Partial::class)->build('pagination', [ |
|
105 | + 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | + 'current' => Arr::get($this->args, 'paged'), |
|
107 | + 'total' => $this->max_num_pages, |
|
108 | + ]); |
|
109 | + $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
110 | + $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
111 | + $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | + return sprintf($wrapper, $html); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function getClass() |
|
119 | - { |
|
120 | - $defaults = [ |
|
121 | - 'glsr-default', |
|
122 | - ]; |
|
123 | - if ('ajax' == $this->args['pagination']) { |
|
124 | - $defaults[] = 'glsr-ajax-pagination'; |
|
125 | - } |
|
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
129 | - } |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function getClass() |
|
119 | + { |
|
120 | + $defaults = [ |
|
121 | + 'glsr-default', |
|
122 | + ]; |
|
123 | + if ('ajax' == $this->args['pagination']) { |
|
124 | + $defaults[] = 'glsr-ajax-pagination'; |
|
125 | + } |
|
126 | + $classes = explode(' ', $this->args['class']); |
|
127 | + $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | + return implode(' ', $classes); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - protected function getReviewsFallback() |
|
135 | - { |
|
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
138 | - } |
|
139 | - $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
141 | - } |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + protected function getReviewsFallback() |
|
135 | + { |
|
136 | + if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | + $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
138 | + } |
|
139 | + $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
140 | + return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
141 | + } |
|
142 | 142 | } |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public $reviews; |
30 | 30 | |
31 | - public function __construct(array $renderedReviews, $maxPageCount, array $args) |
|
31 | + public function __construct( array $renderedReviews, $maxPageCount, array $args ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | 34 | $this->max_num_pages = $maxPageCount; |
35 | 35 | $this->reviews = $renderedReviews; |
36 | 36 | $this->pagination = $this->buildPagination(); |
37 | - parent::__construct($renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | + parent::__construct( $renderedReviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function __toString() |
44 | 44 | { |
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
45 | + return glsr( Template::class )->build( 'templates/reviews', [ |
|
46 | 46 | 'args' => $this->args, |
47 | 47 | 'context' => [ |
48 | 48 | 'assigned_to' => $this->args['assigned_to'], |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'pagination' => $this->getPagination(), |
53 | 53 | 'reviews' => $this->getReviews(), |
54 | 54 | ], |
55 | - ]); |
|
55 | + ] ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getPagination() |
62 | 62 | { |
63 | - return wp_validate_boolean($this->args['pagination']) |
|
63 | + return wp_validate_boolean( $this->args['pagination'] ) |
|
64 | 64 | ? $this->pagination |
65 | 65 | : ''; |
66 | 66 | } |
@@ -72,26 +72,26 @@ discard block |
||
72 | 72 | { |
73 | 73 | $html = empty($this->reviews) |
74 | 74 | ? $this->getReviewsFallback() |
75 | - : implode(PHP_EOL, $this->reviews); |
|
75 | + : implode( PHP_EOL, $this->reviews ); |
|
76 | 76 | $wrapper = '<div class="glsr-reviews">%s</div>'; |
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
77 | + $wrapper = apply_filters( 'site-reviews/reviews/reviews-wrapper', $wrapper ); |
|
78 | + return sprintf( $wrapper, $html ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param mixed $key |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - public function offsetGet($key) |
|
85 | + public function offsetGet( $key ) |
|
86 | 86 | { |
87 | - if ('navigation' == $key) { |
|
87 | + if( 'navigation' == $key ) { |
|
88 | 88 | glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
89 | 89 | return $this->pagination; |
90 | 90 | } |
91 | - if (property_exists($this, $key)) { |
|
91 | + if( property_exists( $this, $key ) ) { |
|
92 | 92 | return $this->$key; |
93 | 93 | } |
94 | - return array_key_exists($key, $this->reviews) |
|
94 | + return array_key_exists( $key, $this->reviews ) |
|
95 | 95 | ? $this->reviews[$key] |
96 | 96 | : null; |
97 | 97 | } |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | */ |
102 | 102 | protected function buildPagination() |
103 | 103 | { |
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
104 | + $html = glsr( Partial::class )->build( 'pagination', [ |
|
105 | + 'baseUrl' => Arr::get( $this->args, 'pagedUrl' ), |
|
106 | + 'current' => Arr::get( $this->args, 'paged' ), |
|
107 | 107 | 'total' => $this->max_num_pages, |
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
108 | + ] ); |
|
109 | + $html .= sprintf( '<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json'] ); |
|
110 | 110 | $wrapper = '<div class="glsr-pagination">%s</div>'; |
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
111 | + $wrapper = apply_filters( 'site-reviews/reviews/pagination-wrapper', $wrapper ); |
|
112 | + return sprintf( $wrapper, $html ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | $defaults = [ |
121 | 121 | 'glsr-default', |
122 | 122 | ]; |
123 | - if ('ajax' == $this->args['pagination']) { |
|
123 | + if( 'ajax' == $this->args['pagination'] ) { |
|
124 | 124 | $defaults[] = 'glsr-ajax-pagination'; |
125 | 125 | } |
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
126 | + $classes = explode( ' ', $this->args['class'] ); |
|
127 | + $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) ); |
|
128 | + return implode( ' ', $classes ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function getReviewsFallback() |
135 | 135 | { |
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
136 | + if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) { |
|
137 | + $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' ); |
|
138 | 138 | } |
139 | 139 | $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | + return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args ); |
|
141 | 141 | } |
142 | 142 | } |
@@ -15,72 +15,72 @@ |
||
15 | 15 | |
16 | 16 | class Filters implements HooksContract |
17 | 17 | { |
18 | - protected $admin; |
|
19 | - protected $app; |
|
20 | - protected $basename; |
|
21 | - protected $blocks; |
|
22 | - protected $editor; |
|
23 | - protected $listtable; |
|
24 | - protected $public; |
|
25 | - protected $rebusify; |
|
26 | - protected $translator; |
|
27 | - protected $welcome; |
|
18 | + protected $admin; |
|
19 | + protected $app; |
|
20 | + protected $basename; |
|
21 | + protected $blocks; |
|
22 | + protected $editor; |
|
23 | + protected $listtable; |
|
24 | + protected $public; |
|
25 | + protected $rebusify; |
|
26 | + protected $translator; |
|
27 | + protected $welcome; |
|
28 | 28 | |
29 | - public function __construct(Application $app) |
|
30 | - { |
|
31 | - $this->app = $app; |
|
32 | - $this->admin = $app->make(AdminController::class); |
|
33 | - $this->basename = plugin_basename($app->file); |
|
34 | - $this->blocks = $app->make(BlocksController::class); |
|
35 | - $this->editor = $app->make(EditorController::class); |
|
36 | - $this->listtable = $app->make(ListTableController::class); |
|
37 | - $this->public = $app->make(PublicController::class); |
|
38 | - $this->rebusify = $app->make(RebusifyController::class); |
|
39 | - $this->translator = $app->make(TranslationController::class); |
|
40 | - $this->welcome = $app->make(WelcomeController::class); |
|
41 | - } |
|
29 | + public function __construct(Application $app) |
|
30 | + { |
|
31 | + $this->app = $app; |
|
32 | + $this->admin = $app->make(AdminController::class); |
|
33 | + $this->basename = plugin_basename($app->file); |
|
34 | + $this->blocks = $app->make(BlocksController::class); |
|
35 | + $this->editor = $app->make(EditorController::class); |
|
36 | + $this->listtable = $app->make(ListTableController::class); |
|
37 | + $this->public = $app->make(PublicController::class); |
|
38 | + $this->rebusify = $app->make(RebusifyController::class); |
|
39 | + $this->translator = $app->make(TranslationController::class); |
|
40 | + $this->welcome = $app->make(WelcomeController::class); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function run() |
|
47 | - { |
|
48 | - add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
49 | - add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
50 | - add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
51 | - add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
52 | - add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
53 | - add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
54 | - add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
55 | - add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
56 | - add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
57 | - add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
58 | - add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
59 | - add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
60 | - add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
61 | - add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
62 | - add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
63 | - add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
64 | - add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
65 | - add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
66 | - add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
67 | - add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
68 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
69 | - add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
70 | - add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
71 | - add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
72 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
73 | - add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
74 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
75 | - add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
76 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
77 | - add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
78 | - add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
79 | - add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
80 | - add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
81 | - add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
82 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
83 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
84 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
85 | - } |
|
43 | + /** |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function run() |
|
47 | + { |
|
48 | + add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
49 | + add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
50 | + add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
51 | + add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
52 | + add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
53 | + add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
54 | + add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
55 | + add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
56 | + add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
57 | + add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
58 | + add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
59 | + add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
60 | + add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
61 | + add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
62 | + add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
63 | + add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
64 | + add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
65 | + add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
66 | + add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
67 | + add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
68 | + add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
69 | + add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
70 | + add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
71 | + add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
72 | + add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
73 | + add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
74 | + add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
75 | + add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
76 | + add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
77 | + add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
78 | + add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
79 | + add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
80 | + add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
81 | + add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
82 | + add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
83 | + add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
84 | + add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
85 | + } |
|
86 | 86 | } |
@@ -26,18 +26,18 @@ discard block |
||
26 | 26 | protected $translator; |
27 | 27 | protected $welcome; |
28 | 28 | |
29 | - public function __construct(Application $app) |
|
29 | + public function __construct( Application $app ) |
|
30 | 30 | { |
31 | 31 | $this->app = $app; |
32 | - $this->admin = $app->make(AdminController::class); |
|
33 | - $this->basename = plugin_basename($app->file); |
|
34 | - $this->blocks = $app->make(BlocksController::class); |
|
35 | - $this->editor = $app->make(EditorController::class); |
|
36 | - $this->listtable = $app->make(ListTableController::class); |
|
37 | - $this->public = $app->make(PublicController::class); |
|
38 | - $this->rebusify = $app->make(RebusifyController::class); |
|
39 | - $this->translator = $app->make(TranslationController::class); |
|
40 | - $this->welcome = $app->make(WelcomeController::class); |
|
32 | + $this->admin = $app->make( AdminController::class ); |
|
33 | + $this->basename = plugin_basename( $app->file ); |
|
34 | + $this->blocks = $app->make( BlocksController::class ); |
|
35 | + $this->editor = $app->make( EditorController::class ); |
|
36 | + $this->listtable = $app->make( ListTableController::class ); |
|
37 | + $this->public = $app->make( PublicController::class ); |
|
38 | + $this->rebusify = $app->make( RebusifyController::class ); |
|
39 | + $this->translator = $app->make( TranslationController::class ); |
|
40 | + $this->welcome = $app->make( WelcomeController::class ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -45,42 +45,42 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function run() |
47 | 47 | { |
48 | - add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
49 | - add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
50 | - add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
51 | - add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
52 | - add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
53 | - add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
54 | - add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
55 | - add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
56 | - add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
57 | - add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
58 | - add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
59 | - add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
60 | - add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
61 | - add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
62 | - add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
63 | - add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
64 | - add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
65 | - add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
66 | - add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
67 | - add_filter('site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback']); |
|
68 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3); |
|
69 | - add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
70 | - add_filter('gettext', [$this->translator, 'filterGettext'], 9, 3); |
|
71 | - add_filter('site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2); |
|
72 | - add_filter('gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4); |
|
73 | - add_filter('site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
74 | - add_filter('ngettext', [$this->translator, 'filterNgettext'], 9, 5); |
|
75 | - add_filter('site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4); |
|
76 | - add_filter('ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6); |
|
77 | - add_filter('site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
78 | - add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
79 | - add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
80 | - add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
81 | - add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
82 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
83 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
84 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
48 | + add_filter( 'map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2 ); |
|
49 | + add_filter( 'mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15 ); |
|
50 | + add_filter( 'plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks'] ); |
|
51 | + add_filter( 'dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems'] ); |
|
52 | + add_filter( 'block_categories', [$this->blocks, 'filterBlockCategories'] ); |
|
53 | + add_filter( 'classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2 ); |
|
54 | + add_filter( 'use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2 ); |
|
55 | + add_filter( 'wp_editor_settings', [$this->editor, 'filterEditorSettings'] ); |
|
56 | + add_filter( 'the_editor', [$this->editor, 'filterEditorTextarea'] ); |
|
57 | + add_filter( 'is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3 ); |
|
58 | + add_filter( 'post_updated_messages', [$this->editor, 'filterUpdateMessages'] ); |
|
59 | + add_filter( 'manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType'] ); |
|
60 | + add_filter( 'post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2 ); |
|
61 | + add_filter( 'default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2 ); |
|
62 | + add_filter( 'post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2 ); |
|
63 | + add_filter( 'manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns'] ); |
|
64 | + add_filter( 'script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2 ); |
|
65 | + add_filter( 'site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11 ); |
|
66 | + add_filter( 'site-reviews/render/view', [$this->public, 'filterRenderView'] ); |
|
67 | + add_filter( 'site-reviews/settings/callback', [$this->rebusify, 'filterSettingsCallback'] ); |
|
68 | + add_filter( 'site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3 ); |
|
69 | + add_filter( 'bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2 ); |
|
70 | + add_filter( 'gettext', [$this->translator, 'filterGettext'], 9, 3 ); |
|
71 | + add_filter( 'site-reviews/gettext/site-reviews', [$this->translator, 'filterGettextSiteReviews'], 10, 2 ); |
|
72 | + add_filter( 'gettext_with_context', [$this->translator, 'filterGettextWithContext'], 9, 4 ); |
|
73 | + add_filter( 'site-reviews/gettext_with_context/site-reviews', [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3 ); |
|
74 | + add_filter( 'ngettext', [$this->translator, 'filterNgettext'], 9, 5 ); |
|
75 | + add_filter( 'site-reviews/ngettext/site-reviews', [$this->translator, 'filterNgettextSiteReviews'], 10, 4 ); |
|
76 | + add_filter( 'ngettext_with_context', [$this->translator, 'filterNgettextWithContext'], 9, 6 ); |
|
77 | + add_filter( 'site-reviews/ngettext_with_context/site-reviews', [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5 ); |
|
78 | + add_filter( 'display_post_states', [$this->translator, 'filterPostStates'], 10, 2 ); |
|
79 | + add_filter( 'site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2 ); |
|
80 | + add_filter( 'site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2 ); |
|
81 | + add_filter( 'site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4 ); |
|
82 | + add_filter( 'plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9 ); |
|
83 | + add_filter( 'admin_title', [$this->welcome, 'filterAdminTitle'] ); |
|
84 | + add_filter( 'admin_footer_text', [$this->welcome, 'filterFooterText'] ); |
|
85 | 85 | } |
86 | 86 | } |
@@ -13,81 +13,81 @@ |
||
13 | 13 | |
14 | 14 | class PublicController extends Controller |
15 | 15 | { |
16 | - /** |
|
17 | - * @return void |
|
18 | - * @action wp_enqueue_scripts |
|
19 | - */ |
|
20 | - public function enqueueAssets() |
|
21 | - { |
|
22 | - (new EnqueuePublicAssets())->handle(); |
|
23 | - } |
|
16 | + /** |
|
17 | + * @return void |
|
18 | + * @action wp_enqueue_scripts |
|
19 | + */ |
|
20 | + public function enqueueAssets() |
|
21 | + { |
|
22 | + (new EnqueuePublicAssets())->handle(); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $tag |
|
27 | - * @param string $handle |
|
28 | - * @return string |
|
29 | - * @filter script_loader_tag |
|
30 | - */ |
|
31 | - public function filterEnqueuedScripts($tag, $handle) |
|
32 | - { |
|
33 | - $scripts = [Application::ID.'/google-recaptcha']; |
|
34 | - if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
35 | - $tag = str_replace(' src=', ' async src=', $tag); |
|
36 | - } |
|
37 | - if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
38 | - $tag = str_replace(' src=', ' defer src=', $tag); |
|
39 | - } |
|
40 | - return $tag; |
|
41 | - } |
|
25 | + /** |
|
26 | + * @param string $tag |
|
27 | + * @param string $handle |
|
28 | + * @return string |
|
29 | + * @filter script_loader_tag |
|
30 | + */ |
|
31 | + public function filterEnqueuedScripts($tag, $handle) |
|
32 | + { |
|
33 | + $scripts = [Application::ID.'/google-recaptcha']; |
|
34 | + if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
35 | + $tag = str_replace(' src=', ' async src=', $tag); |
|
36 | + } |
|
37 | + if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
38 | + $tag = str_replace(' src=', ' defer src=', $tag); |
|
39 | + } |
|
40 | + return $tag; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return array |
|
45 | - * @filter site-reviews/config/forms/submission-form |
|
46 | - */ |
|
47 | - public function filterFieldOrder(array $config) |
|
48 | - { |
|
49 | - $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
50 | - return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
51 | - } |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + * @filter site-reviews/config/forms/submission-form |
|
46 | + */ |
|
47 | + public function filterFieldOrder(array $config) |
|
48 | + { |
|
49 | + $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
50 | + return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param string $view |
|
55 | - * @return string |
|
56 | - * @filter site-reviews/render/view |
|
57 | - */ |
|
58 | - public function filterRenderView($view) |
|
59 | - { |
|
60 | - return glsr(Style::class)->filterView($view); |
|
61 | - } |
|
53 | + /** |
|
54 | + * @param string $view |
|
55 | + * @return string |
|
56 | + * @filter site-reviews/render/view |
|
57 | + */ |
|
58 | + public function filterRenderView($view) |
|
59 | + { |
|
60 | + return glsr(Style::class)->filterView($view); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return void |
|
65 | - * @action site-reviews/builder |
|
66 | - */ |
|
67 | - public function modifyBuilder(Builder $instance) |
|
68 | - { |
|
69 | - call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
70 | - } |
|
63 | + /** |
|
64 | + * @return void |
|
65 | + * @action site-reviews/builder |
|
66 | + */ |
|
67 | + public function modifyBuilder(Builder $instance) |
|
68 | + { |
|
69 | + call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - * @action wp_footer |
|
75 | - */ |
|
76 | - public function renderSchema() |
|
77 | - { |
|
78 | - glsr(Schema::class)->render(); |
|
79 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + * @action wp_footer |
|
75 | + */ |
|
76 | + public function renderSchema() |
|
77 | + { |
|
78 | + glsr(Schema::class)->render(); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return CreateReview |
|
83 | - */ |
|
84 | - public function routerSubmitReview(array $request) |
|
85 | - { |
|
86 | - $validated = glsr(ValidateReview::class)->validate($request); |
|
87 | - $command = new CreateReview($validated->request); |
|
88 | - if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
89 | - $this->execute($command); |
|
90 | - } |
|
91 | - return $command; |
|
92 | - } |
|
81 | + /** |
|
82 | + * @return CreateReview |
|
83 | + */ |
|
84 | + public function routerSubmitReview(array $request) |
|
85 | + { |
|
86 | + $validated = glsr(ValidateReview::class)->validate($request); |
|
87 | + $command = new CreateReview($validated->request); |
|
88 | + if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
89 | + $this->execute($command); |
|
90 | + } |
|
91 | + return $command; |
|
92 | + } |
|
93 | 93 | } |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | * @return string |
29 | 29 | * @filter script_loader_tag |
30 | 30 | */ |
31 | - public function filterEnqueuedScripts($tag, $handle) |
|
31 | + public function filterEnqueuedScripts( $tag, $handle ) |
|
32 | 32 | { |
33 | 33 | $scripts = [Application::ID.'/google-recaptcha']; |
34 | - if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
35 | - $tag = str_replace(' src=', ' async src=', $tag); |
|
34 | + if( in_array( $handle, apply_filters( 'site-reviews/async-scripts', $scripts ) ) ) { |
|
35 | + $tag = str_replace( ' src=', ' async src=', $tag ); |
|
36 | 36 | } |
37 | - if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
38 | - $tag = str_replace(' src=', ' defer src=', $tag); |
|
37 | + if( in_array( $handle, apply_filters( 'site-reviews/defer-scripts', $scripts ) ) ) { |
|
38 | + $tag = str_replace( ' src=', ' defer src=', $tag ); |
|
39 | 39 | } |
40 | 40 | return $tag; |
41 | 41 | } |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | * @return array |
45 | 45 | * @filter site-reviews/config/forms/submission-form |
46 | 46 | */ |
47 | - public function filterFieldOrder(array $config) |
|
47 | + public function filterFieldOrder( array $config ) |
|
48 | 48 | { |
49 | - $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
50 | - return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
49 | + $order = (array)apply_filters( 'site-reviews/submission-form/order', array_keys( $config ) ); |
|
50 | + return array_intersect_key( array_merge( array_flip( $order ), $config ), $config ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | * @return string |
56 | 56 | * @filter site-reviews/render/view |
57 | 57 | */ |
58 | - public function filterRenderView($view) |
|
58 | + public function filterRenderView( $view ) |
|
59 | 59 | { |
60 | - return glsr(Style::class)->filterView($view); |
|
60 | + return glsr( Style::class )->filterView( $view ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @return void |
65 | 65 | * @action site-reviews/builder |
66 | 66 | */ |
67 | - public function modifyBuilder(Builder $instance) |
|
67 | + public function modifyBuilder( Builder $instance ) |
|
68 | 68 | { |
69 | - call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
69 | + call_user_func_array( [glsr( Style::class ), 'modifyField'], [$instance] ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -75,18 +75,18 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function renderSchema() |
77 | 77 | { |
78 | - glsr(Schema::class)->render(); |
|
78 | + glsr( Schema::class )->render(); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @return CreateReview |
83 | 83 | */ |
84 | - public function routerSubmitReview(array $request) |
|
84 | + public function routerSubmitReview( array $request ) |
|
85 | 85 | { |
86 | - $validated = glsr(ValidateReview::class)->validate($request); |
|
87 | - $command = new CreateReview($validated->request); |
|
88 | - if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
89 | - $this->execute($command); |
|
86 | + $validated = glsr( ValidateReview::class )->validate( $request ); |
|
87 | + $command = new CreateReview( $validated->request ); |
|
88 | + if( empty($validated->error) && !$validated->recaptchaIsUnset ) { |
|
89 | + $this->execute( $command ); |
|
90 | 90 | } |
91 | 91 | return $command; |
92 | 92 | } |
@@ -12,162 +12,162 @@ |
||
12 | 12 | |
13 | 13 | class QueryBuilder |
14 | 14 | { |
15 | - /** |
|
16 | - * Build a WP_Query meta_query/tax_query. |
|
17 | - * @return array |
|
18 | - */ |
|
19 | - public function buildQuery(array $keys = [], array $values = []) |
|
20 | - { |
|
21 | - $queries = []; |
|
22 | - foreach ($keys as $key) { |
|
23 | - if (!array_key_exists($key, $values)) { |
|
24 | - continue; |
|
25 | - } |
|
26 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
27 | - if (!method_exists($this, $methodName)) { |
|
28 | - continue; |
|
29 | - } |
|
30 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
31 | - if (is_array($query)) { |
|
32 | - $queries[] = $query; |
|
33 | - } |
|
34 | - } |
|
35 | - return $queries; |
|
36 | - } |
|
15 | + /** |
|
16 | + * Build a WP_Query meta_query/tax_query. |
|
17 | + * @return array |
|
18 | + */ |
|
19 | + public function buildQuery(array $keys = [], array $values = []) |
|
20 | + { |
|
21 | + $queries = []; |
|
22 | + foreach ($keys as $key) { |
|
23 | + if (!array_key_exists($key, $values)) { |
|
24 | + continue; |
|
25 | + } |
|
26 | + $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
27 | + if (!method_exists($this, $methodName)) { |
|
28 | + continue; |
|
29 | + } |
|
30 | + $query = call_user_func([$this, $methodName], $values[$key]); |
|
31 | + if (is_array($query)) { |
|
32 | + $queries[] = $query; |
|
33 | + } |
|
34 | + } |
|
35 | + return $queries; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - public function buildSqlLines(array $values, array $conditions) |
|
42 | - { |
|
43 | - $string = ''; |
|
44 | - $values = array_filter($values); |
|
45 | - foreach ($conditions as $key => $value) { |
|
46 | - if (!isset($values[$key])) { |
|
47 | - continue; |
|
48 | - } |
|
49 | - $values[$key] = implode(',', (array) $values[$key]); |
|
50 | - $string.= Str::contains($value, '%s') |
|
51 | - ? sprintf($value, strval($values[$key])) |
|
52 | - : $value; |
|
53 | - } |
|
54 | - return $string; |
|
55 | - } |
|
38 | + /** |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + public function buildSqlLines(array $values, array $conditions) |
|
42 | + { |
|
43 | + $string = ''; |
|
44 | + $values = array_filter($values); |
|
45 | + foreach ($conditions as $key => $value) { |
|
46 | + if (!isset($values[$key])) { |
|
47 | + continue; |
|
48 | + } |
|
49 | + $values[$key] = implode(',', (array) $values[$key]); |
|
50 | + $string.= Str::contains($value, '%s') |
|
51 | + ? sprintf($value, strval($values[$key])) |
|
52 | + : $value; |
|
53 | + } |
|
54 | + return $string; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Build a SQL 'OR' string from an array. |
|
59 | - * @param string|array $values |
|
60 | - * @param string $sprintfFormat |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function buildSqlOr($values, $sprintfFormat) |
|
64 | - { |
|
65 | - if (!is_array($values)) { |
|
66 | - $values = explode(',', $values); |
|
67 | - } |
|
68 | - $values = array_filter(array_map('trim', (array) $values)); |
|
69 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
70 | - return sprintf($sprintfFormat, $value); |
|
71 | - }, $values); |
|
72 | - return implode(' OR ', $values); |
|
73 | - } |
|
57 | + /** |
|
58 | + * Build a SQL 'OR' string from an array. |
|
59 | + * @param string|array $values |
|
60 | + * @param string $sprintfFormat |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function buildSqlOr($values, $sprintfFormat) |
|
64 | + { |
|
65 | + if (!is_array($values)) { |
|
66 | + $values = explode(',', $values); |
|
67 | + } |
|
68 | + $values = array_filter(array_map('trim', (array) $values)); |
|
69 | + $values = array_map(function ($value) use ($sprintfFormat) { |
|
70 | + return sprintf($sprintfFormat, $value); |
|
71 | + }, $values); |
|
72 | + return implode(' OR ', $values); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Search SQL filter for matching against post title only. |
|
77 | - * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
78 | - * @param string $search |
|
79 | - * @return string |
|
80 | - * @filter posts_search |
|
81 | - */ |
|
82 | - public function filterSearchByTitle($search, WP_Query $query) |
|
83 | - { |
|
84 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
85 | - return $search; |
|
86 | - } |
|
87 | - global $wpdb; |
|
88 | - $n = empty($query->get('exact')) |
|
89 | - ? '%' |
|
90 | - : ''; |
|
91 | - $search = []; |
|
92 | - foreach ((array) $query->get('search_terms') as $term) { |
|
93 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
94 | - } |
|
95 | - if (!is_user_logged_in()) { |
|
96 | - $search[] = "{$wpdb->posts}.post_password = ''"; |
|
97 | - } |
|
98 | - return ' AND '.implode(' AND ', $search); |
|
99 | - } |
|
75 | + /** |
|
76 | + * Search SQL filter for matching against post title only. |
|
77 | + * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
78 | + * @param string $search |
|
79 | + * @return string |
|
80 | + * @filter posts_search |
|
81 | + */ |
|
82 | + public function filterSearchByTitle($search, WP_Query $query) |
|
83 | + { |
|
84 | + if (empty($search) || empty($query->get('search_terms'))) { |
|
85 | + return $search; |
|
86 | + } |
|
87 | + global $wpdb; |
|
88 | + $n = empty($query->get('exact')) |
|
89 | + ? '%' |
|
90 | + : ''; |
|
91 | + $search = []; |
|
92 | + foreach ((array) $query->get('search_terms') as $term) { |
|
93 | + $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
94 | + } |
|
95 | + if (!is_user_logged_in()) { |
|
96 | + $search[] = "{$wpdb->posts}.post_password = ''"; |
|
97 | + } |
|
98 | + return ' AND '.implode(' AND ', $search); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the current page number from the global query. |
|
103 | - * @param bool $isEnabled |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public function getPaged($isEnabled = true) |
|
107 | - { |
|
108 | - return $isEnabled |
|
109 | - ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
110 | - : 1; |
|
111 | - } |
|
101 | + /** |
|
102 | + * Get the current page number from the global query. |
|
103 | + * @param bool $isEnabled |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public function getPaged($isEnabled = true) |
|
107 | + { |
|
108 | + return $isEnabled |
|
109 | + ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
110 | + : 1; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $value |
|
115 | - * @return void|array |
|
116 | - */ |
|
117 | - protected function buildQueryAssignedTo($value) |
|
118 | - { |
|
119 | - if (!empty($value)) { |
|
120 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
121 | - return [ |
|
122 | - 'compare' => 'IN', |
|
123 | - 'key' => '_assigned_to', |
|
124 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
125 | - ]; |
|
126 | - } |
|
127 | - } |
|
113 | + /** |
|
114 | + * @param string $value |
|
115 | + * @return void|array |
|
116 | + */ |
|
117 | + protected function buildQueryAssignedTo($value) |
|
118 | + { |
|
119 | + if (!empty($value)) { |
|
120 | + $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
121 | + return [ |
|
122 | + 'compare' => 'IN', |
|
123 | + 'key' => '_assigned_to', |
|
124 | + 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
125 | + ]; |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @param array $value |
|
131 | - * @return void|array |
|
132 | - */ |
|
133 | - protected function buildQueryCategory($value) |
|
134 | - { |
|
135 | - if (!empty($value)) { |
|
136 | - return [ |
|
137 | - 'field' => 'term_id', |
|
138 | - 'taxonomy' => Application::TAXONOMY, |
|
139 | - 'terms' => $value, |
|
140 | - ]; |
|
141 | - } |
|
142 | - } |
|
129 | + /** |
|
130 | + * @param array $value |
|
131 | + * @return void|array |
|
132 | + */ |
|
133 | + protected function buildQueryCategory($value) |
|
134 | + { |
|
135 | + if (!empty($value)) { |
|
136 | + return [ |
|
137 | + 'field' => 'term_id', |
|
138 | + 'taxonomy' => Application::TAXONOMY, |
|
139 | + 'terms' => $value, |
|
140 | + ]; |
|
141 | + } |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param string $value |
|
146 | - * @return void|array |
|
147 | - */ |
|
148 | - protected function buildQueryRating($value) |
|
149 | - { |
|
150 | - if (is_numeric($value) |
|
151 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
152 | - return [ |
|
153 | - 'compare' => '>=', |
|
154 | - 'key' => '_rating', |
|
155 | - 'value' => $value, |
|
156 | - ]; |
|
157 | - } |
|
158 | - } |
|
144 | + /** |
|
145 | + * @param string $value |
|
146 | + * @return void|array |
|
147 | + */ |
|
148 | + protected function buildQueryRating($value) |
|
149 | + { |
|
150 | + if (is_numeric($value) |
|
151 | + && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
152 | + return [ |
|
153 | + 'compare' => '>=', |
|
154 | + 'key' => '_rating', |
|
155 | + 'value' => $value, |
|
156 | + ]; |
|
157 | + } |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @param string $value |
|
162 | - * @return void|array |
|
163 | - */ |
|
164 | - protected function buildQueryType($value) |
|
165 | - { |
|
166 | - if (!in_array($value, ['', 'all'])) { |
|
167 | - return [ |
|
168 | - 'key' => '_review_type', |
|
169 | - 'value' => $value, |
|
170 | - ]; |
|
171 | - } |
|
172 | - } |
|
160 | + /** |
|
161 | + * @param string $value |
|
162 | + * @return void|array |
|
163 | + */ |
|
164 | + protected function buildQueryType($value) |
|
165 | + { |
|
166 | + if (!in_array($value, ['', 'all'])) { |
|
167 | + return [ |
|
168 | + 'key' => '_review_type', |
|
169 | + 'value' => $value, |
|
170 | + ]; |
|
171 | + } |
|
172 | + } |
|
173 | 173 | } |
@@ -16,19 +16,19 @@ discard block |
||
16 | 16 | * Build a WP_Query meta_query/tax_query. |
17 | 17 | * @return array |
18 | 18 | */ |
19 | - public function buildQuery(array $keys = [], array $values = []) |
|
19 | + public function buildQuery( array $keys = [], array $values = [] ) |
|
20 | 20 | { |
21 | 21 | $queries = []; |
22 | - foreach ($keys as $key) { |
|
23 | - if (!array_key_exists($key, $values)) { |
|
22 | + foreach( $keys as $key ) { |
|
23 | + if( !array_key_exists( $key, $values ) ) { |
|
24 | 24 | continue; |
25 | 25 | } |
26 | - $methodName = Helper::buildMethodName($key, __FUNCTION__); |
|
27 | - if (!method_exists($this, $methodName)) { |
|
26 | + $methodName = Helper::buildMethodName( $key, __FUNCTION__ ); |
|
27 | + if( !method_exists( $this, $methodName ) ) { |
|
28 | 28 | continue; |
29 | 29 | } |
30 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
31 | - if (is_array($query)) { |
|
30 | + $query = call_user_func( [$this, $methodName], $values[$key] ); |
|
31 | + if( is_array( $query ) ) { |
|
32 | 32 | $queries[] = $query; |
33 | 33 | } |
34 | 34 | } |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @return string |
40 | 40 | */ |
41 | - public function buildSqlLines(array $values, array $conditions) |
|
41 | + public function buildSqlLines( array $values, array $conditions ) |
|
42 | 42 | { |
43 | 43 | $string = ''; |
44 | - $values = array_filter($values); |
|
45 | - foreach ($conditions as $key => $value) { |
|
46 | - if (!isset($values[$key])) { |
|
44 | + $values = array_filter( $values ); |
|
45 | + foreach( $conditions as $key => $value ) { |
|
46 | + if( !isset($values[$key]) ) { |
|
47 | 47 | continue; |
48 | 48 | } |
49 | - $values[$key] = implode(',', (array) $values[$key]); |
|
50 | - $string.= Str::contains($value, '%s') |
|
51 | - ? sprintf($value, strval($values[$key])) |
|
49 | + $values[$key] = implode( ',', (array)$values[$key] ); |
|
50 | + $string .= Str::contains( $value, '%s' ) |
|
51 | + ? sprintf( $value, strval( $values[$key] ) ) |
|
52 | 52 | : $value; |
53 | 53 | } |
54 | 54 | return $string; |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | * @param string $sprintfFormat |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public function buildSqlOr($values, $sprintfFormat) |
|
63 | + public function buildSqlOr( $values, $sprintfFormat ) |
|
64 | 64 | { |
65 | - if (!is_array($values)) { |
|
66 | - $values = explode(',', $values); |
|
65 | + if( !is_array( $values ) ) { |
|
66 | + $values = explode( ',', $values ); |
|
67 | 67 | } |
68 | - $values = array_filter(array_map('trim', (array) $values)); |
|
69 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
70 | - return sprintf($sprintfFormat, $value); |
|
71 | - }, $values); |
|
72 | - return implode(' OR ', $values); |
|
68 | + $values = array_filter( array_map( 'trim', (array)$values ) ); |
|
69 | + $values = array_map( function( $value ) use ($sprintfFormat) { |
|
70 | + return sprintf( $sprintfFormat, $value ); |
|
71 | + }, $values ); |
|
72 | + return implode( ' OR ', $values ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -79,23 +79,23 @@ discard block |
||
79 | 79 | * @return string |
80 | 80 | * @filter posts_search |
81 | 81 | */ |
82 | - public function filterSearchByTitle($search, WP_Query $query) |
|
82 | + public function filterSearchByTitle( $search, WP_Query $query ) |
|
83 | 83 | { |
84 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
84 | + if( empty($search) || empty($query->get( 'search_terms' )) ) { |
|
85 | 85 | return $search; |
86 | 86 | } |
87 | 87 | global $wpdb; |
88 | - $n = empty($query->get('exact')) |
|
88 | + $n = empty($query->get( 'exact' )) |
|
89 | 89 | ? '%' |
90 | 90 | : ''; |
91 | 91 | $search = []; |
92 | - foreach ((array) $query->get('search_terms') as $term) { |
|
93 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
92 | + foreach( (array)$query->get( 'search_terms' ) as $term ) { |
|
93 | + $search[] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like( $term ).$n ); |
|
94 | 94 | } |
95 | - if (!is_user_logged_in()) { |
|
95 | + if( !is_user_logged_in() ) { |
|
96 | 96 | $search[] = "{$wpdb->posts}.post_password = ''"; |
97 | 97 | } |
98 | - return ' AND '.implode(' AND ', $search); |
|
98 | + return ' AND '.implode( ' AND ', $search ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,10 +103,10 @@ discard block |
||
103 | 103 | * @param bool $isEnabled |
104 | 104 | * @return int |
105 | 105 | */ |
106 | - public function getPaged($isEnabled = true) |
|
106 | + public function getPaged( $isEnabled = true ) |
|
107 | 107 | { |
108 | 108 | return $isEnabled |
109 | - ? max(1, intval(filter_input(INPUT_GET, glsr()->constant('PAGED_QUERY_VAR')))) |
|
109 | + ? max( 1, intval( filter_input( INPUT_GET, glsr()->constant( 'PAGED_QUERY_VAR' ) ) ) ) |
|
110 | 110 | : 1; |
111 | 111 | } |
112 | 112 | |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * @param string $value |
115 | 115 | * @return void|array |
116 | 116 | */ |
117 | - protected function buildQueryAssignedTo($value) |
|
117 | + protected function buildQueryAssignedTo( $value ) |
|
118 | 118 | { |
119 | - if (!empty($value)) { |
|
120 | - $postIds = Arr::convertStringToArray($value, 'is_numeric'); |
|
119 | + if( !empty($value) ) { |
|
120 | + $postIds = Arr::convertStringToArray( $value, 'is_numeric' ); |
|
121 | 121 | return [ |
122 | 122 | 'compare' => 'IN', |
123 | 123 | 'key' => '_assigned_to', |
124 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
124 | + 'value' => glsr( Polylang::class )->getPostIds( $postIds ), |
|
125 | 125 | ]; |
126 | 126 | } |
127 | 127 | } |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | * @param array $value |
131 | 131 | * @return void|array |
132 | 132 | */ |
133 | - protected function buildQueryCategory($value) |
|
133 | + protected function buildQueryCategory( $value ) |
|
134 | 134 | { |
135 | - if (!empty($value)) { |
|
135 | + if( !empty($value) ) { |
|
136 | 136 | return [ |
137 | 137 | 'field' => 'term_id', |
138 | 138 | 'taxonomy' => Application::TAXONOMY, |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | * @param string $value |
146 | 146 | * @return void|array |
147 | 147 | */ |
148 | - protected function buildQueryRating($value) |
|
148 | + protected function buildQueryRating( $value ) |
|
149 | 149 | { |
150 | - if (is_numeric($value) |
|
151 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
150 | + if( is_numeric( $value ) |
|
151 | + && in_array( intval( $value ), range( 1, glsr()->constant( 'MAX_RATING', Rating::class ) ) ) ) { |
|
152 | 152 | return [ |
153 | 153 | 'compare' => '>=', |
154 | 154 | 'key' => '_rating', |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | * @param string $value |
162 | 162 | * @return void|array |
163 | 163 | */ |
164 | - protected function buildQueryType($value) |
|
164 | + protected function buildQueryType( $value ) |
|
165 | 165 | { |
166 | - if (!in_array($value, ['', 'all'])) { |
|
166 | + if( !in_array( $value, ['', 'all'] ) ) { |
|
167 | 167 | return [ |
168 | 168 | 'key' => '_review_type', |
169 | 169 | 'value' => $value, |