@@ -10,94 +10,94 @@ |
||
10 | 10 | |
11 | 11 | class MainController extends Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * @return void |
|
15 | - * @action init |
|
16 | - */ |
|
17 | - public function registerPostType() |
|
18 | - { |
|
19 | - if (!glsr()->hasPermission()) { |
|
20 | - return; |
|
21 | - } |
|
22 | - $command = new RegisterPostType([ |
|
23 | - 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
|
24 | - 'columns' => [ |
|
25 | - 'title' => '', |
|
26 | - 'category' => '', |
|
27 | - 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
28 | - 'reviewer' => __('Author', 'site-reviews'), |
|
29 | - 'review_type' => __('Type', 'site-reviews'), |
|
30 | - 'rating' => __('Rating', 'site-reviews'), |
|
31 | - 'pinned' => __('Pinned', 'site-reviews'), |
|
32 | - 'date' => '', |
|
33 | - ], |
|
34 | - 'menu_icon' => 'dashicons-star-half', |
|
35 | - 'menu_name' => glsr()->name, |
|
36 | - 'map_meta_cap' => true, |
|
37 | - 'plural' => __('Reviews', 'site-reviews'), |
|
38 | - 'post_type' => Application::POST_TYPE, |
|
39 | - 'rest_controller_class' => RestReviewController::class, |
|
40 | - 'show_in_rest' => true, |
|
41 | - 'single' => __('Review', 'site-reviews'), |
|
42 | - ]); |
|
43 | - $this->execute($command); |
|
44 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + * @action init |
|
16 | + */ |
|
17 | + public function registerPostType() |
|
18 | + { |
|
19 | + if (!glsr()->hasPermission()) { |
|
20 | + return; |
|
21 | + } |
|
22 | + $command = new RegisterPostType([ |
|
23 | + 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
|
24 | + 'columns' => [ |
|
25 | + 'title' => '', |
|
26 | + 'category' => '', |
|
27 | + 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
28 | + 'reviewer' => __('Author', 'site-reviews'), |
|
29 | + 'review_type' => __('Type', 'site-reviews'), |
|
30 | + 'rating' => __('Rating', 'site-reviews'), |
|
31 | + 'pinned' => __('Pinned', 'site-reviews'), |
|
32 | + 'date' => '', |
|
33 | + ], |
|
34 | + 'menu_icon' => 'dashicons-star-half', |
|
35 | + 'menu_name' => glsr()->name, |
|
36 | + 'map_meta_cap' => true, |
|
37 | + 'plural' => __('Reviews', 'site-reviews'), |
|
38 | + 'post_type' => Application::POST_TYPE, |
|
39 | + 'rest_controller_class' => RestReviewController::class, |
|
40 | + 'show_in_rest' => true, |
|
41 | + 'single' => __('Review', 'site-reviews'), |
|
42 | + ]); |
|
43 | + $this->execute($command); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return void |
|
48 | - * @action init |
|
49 | - */ |
|
50 | - public function registerShortcodes() |
|
51 | - { |
|
52 | - $command = new RegisterShortcodes([ |
|
53 | - 'site_reviews', |
|
54 | - 'site_reviews_form', |
|
55 | - 'site_reviews_summary', |
|
56 | - ]); |
|
57 | - $this->execute($command); |
|
58 | - } |
|
46 | + /** |
|
47 | + * @return void |
|
48 | + * @action init |
|
49 | + */ |
|
50 | + public function registerShortcodes() |
|
51 | + { |
|
52 | + $command = new RegisterShortcodes([ |
|
53 | + 'site_reviews', |
|
54 | + 'site_reviews_form', |
|
55 | + 'site_reviews_summary', |
|
56 | + ]); |
|
57 | + $this->execute($command); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return void |
|
62 | - * @action init |
|
63 | - */ |
|
64 | - public function registerTaxonomy() |
|
65 | - { |
|
66 | - $command = new RegisterTaxonomy([ |
|
67 | - 'hierarchical' => true, |
|
68 | - 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
69 | - 'public' => false, |
|
70 | - 'rest_controller_class' => RestCategoryController::class, |
|
71 | - 'show_admin_column' => true, |
|
72 | - 'show_in_rest' => true, |
|
73 | - 'show_ui' => true, |
|
74 | - ]); |
|
75 | - $this->execute($command); |
|
76 | - } |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + * @action init |
|
63 | + */ |
|
64 | + public function registerTaxonomy() |
|
65 | + { |
|
66 | + $command = new RegisterTaxonomy([ |
|
67 | + 'hierarchical' => true, |
|
68 | + 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
69 | + 'public' => false, |
|
70 | + 'rest_controller_class' => RestCategoryController::class, |
|
71 | + 'show_admin_column' => true, |
|
72 | + 'show_in_rest' => true, |
|
73 | + 'show_ui' => true, |
|
74 | + ]); |
|
75 | + $this->execute($command); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - * @action widgets_init |
|
81 | - */ |
|
82 | - public function registerWidgets() |
|
83 | - { |
|
84 | - $command = new RegisterWidgets([ |
|
85 | - 'site-reviews' => [ |
|
86 | - 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
87 | - 'description' => __('Your site’s most recent Reviews.', 'site-reviews'), |
|
88 | - 'title' => __('Recent Reviews', 'site-reviews'), |
|
89 | - ], |
|
90 | - 'site-reviews-form' => [ |
|
91 | - 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
|
92 | - 'description' => __('Displays a form to submit reviews.', 'site-reviews'), |
|
93 | - 'title' => __('Submit a Review', 'site-reviews'), |
|
94 | - ], |
|
95 | - 'site-reviews-summary' => [ |
|
96 | - 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
97 | - 'description' => __('A summary of your site’s reviews.', 'site-reviews'), |
|
98 | - 'title' => __('Summary of Reviews', 'site-reviews'), |
|
99 | - ], |
|
100 | - ]); |
|
101 | - $this->execute($command); |
|
102 | - } |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @action widgets_init |
|
81 | + */ |
|
82 | + public function registerWidgets() |
|
83 | + { |
|
84 | + $command = new RegisterWidgets([ |
|
85 | + 'site-reviews' => [ |
|
86 | + 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
87 | + 'description' => __('Your site’s most recent Reviews.', 'site-reviews'), |
|
88 | + 'title' => __('Recent Reviews', 'site-reviews'), |
|
89 | + ], |
|
90 | + 'site-reviews-form' => [ |
|
91 | + 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
|
92 | + 'description' => __('Displays a form to submit reviews.', 'site-reviews'), |
|
93 | + 'title' => __('Submit a Review', 'site-reviews'), |
|
94 | + ], |
|
95 | + 'site-reviews-summary' => [ |
|
96 | + 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
97 | + 'description' => __('A summary of your site’s reviews.', 'site-reviews'), |
|
98 | + 'title' => __('Summary of Reviews', 'site-reviews'), |
|
99 | + ], |
|
100 | + ]); |
|
101 | + $this->execute($command); |
|
102 | + } |
|
103 | 103 | } |
@@ -7,117 +7,117 @@ |
||
7 | 7 | |
8 | 8 | abstract class DefaultsAbstract |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - protected $callable = [ |
|
14 | - 'defaults', 'filter', 'merge', 'restrict', 'unguarded', |
|
15 | - ]; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + protected $callable = [ |
|
14 | + 'defaults', 'filter', 'merge', 'restrict', 'unguarded', |
|
15 | + ]; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected $guarded = []; |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected $guarded = []; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param string $name |
|
24 | - * @return void|array |
|
25 | - */ |
|
26 | - public function __call($name, array $args = []) |
|
27 | - { |
|
28 | - if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
29 | - return; |
|
30 | - } |
|
31 | - $defaults = call_user_func_array([$this, $name], $args); |
|
32 | - $hookName = (new ReflectionClass($this))->getShortName(); |
|
33 | - $hookName = str_replace('Defaults', '', $hookName); |
|
34 | - $hookName = glsr(Helper::class)->dashCase($hookName); |
|
35 | - return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
36 | - } |
|
22 | + /** |
|
23 | + * @param string $name |
|
24 | + * @return void|array |
|
25 | + */ |
|
26 | + public function __call($name, array $args = []) |
|
27 | + { |
|
28 | + if (!method_exists($this, $name) || !in_array($name, $this->callable)) { |
|
29 | + return; |
|
30 | + } |
|
31 | + $defaults = call_user_func_array([$this, $name], $args); |
|
32 | + $hookName = (new ReflectionClass($this))->getShortName(); |
|
33 | + $hookName = str_replace('Defaults', '', $hookName); |
|
34 | + $hookName = glsr(Helper::class)->dashCase($hookName); |
|
35 | + return apply_filters('site-reviews/defaults/'.$hookName, $defaults, $name); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - abstract protected function defaults(); |
|
38 | + /** |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + abstract protected function defaults(); |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - protected function filter(array $values = []) |
|
47 | - { |
|
48 | - return $this->normalize($this->merge(array_filter($values)), $values); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + protected function filter(array $values = []) |
|
47 | + { |
|
48 | + return $this->normalize($this->merge(array_filter($values)), $values); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - protected function filteredJson(array $values = []) |
|
55 | - { |
|
56 | - $defaults = $this->flattenArray( |
|
57 | - array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
58 | - ); |
|
59 | - $values = $this->flattenArray( |
|
60 | - shortcode_atts($defaults, $values) |
|
61 | - ); |
|
62 | - $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
63 | - return !$this->isEmpty($value); |
|
64 | - }); |
|
65 | - return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
66 | - } |
|
51 | + /** |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + protected function filteredJson(array $values = []) |
|
55 | + { |
|
56 | + $defaults = $this->flattenArray( |
|
57 | + array_diff_key($this->defaults(), array_flip($this->guarded)) |
|
58 | + ); |
|
59 | + $values = $this->flattenArray( |
|
60 | + shortcode_atts($defaults, $values) |
|
61 | + ); |
|
62 | + $filtered = array_filter(array_diff_assoc($values, $defaults), function ($value) { |
|
63 | + return !$this->isEmpty($value); |
|
64 | + }); |
|
65 | + return json_encode($filtered, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - protected function flattenArray(array $values) |
|
72 | - { |
|
73 | - array_walk($values, function (&$value) { |
|
74 | - if (!is_array($value)) { |
|
75 | - return; |
|
76 | - } |
|
77 | - $value = implode(',', $value); |
|
78 | - }); |
|
79 | - return $values; |
|
80 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + protected function flattenArray(array $values) |
|
72 | + { |
|
73 | + array_walk($values, function (&$value) { |
|
74 | + if (!is_array($value)) { |
|
75 | + return; |
|
76 | + } |
|
77 | + $value = implode(',', $value); |
|
78 | + }); |
|
79 | + return $values; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @param mixed $var |
|
84 | - * @return bool |
|
85 | - */ |
|
86 | - protected function isEmpty($var) |
|
87 | - { |
|
88 | - return !is_numeric($var) && !is_bool($var) && empty($var); |
|
89 | - } |
|
82 | + /** |
|
83 | + * @param mixed $var |
|
84 | + * @return bool |
|
85 | + */ |
|
86 | + protected function isEmpty($var) |
|
87 | + { |
|
88 | + return !is_numeric($var) && !is_bool($var) && empty($var); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - protected function merge(array $values = []) |
|
95 | - { |
|
96 | - return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
97 | - } |
|
91 | + /** |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + protected function merge(array $values = []) |
|
95 | + { |
|
96 | + return $this->normalize(wp_parse_args($values, $this->defaults()), $values); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - protected function normalize(array $values, array $originalValues) |
|
103 | - { |
|
104 | - $values['json'] = $this->filteredJson($originalValues); |
|
105 | - return $values; |
|
106 | - } |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + protected function normalize(array $values, array $originalValues) |
|
103 | + { |
|
104 | + $values['json'] = $this->filteredJson($originalValues); |
|
105 | + return $values; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - protected function restrict(array $values = []) |
|
112 | - { |
|
113 | - return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
114 | - } |
|
108 | + /** |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + protected function restrict(array $values = []) |
|
112 | + { |
|
113 | + return $this->normalize(shortcode_atts($this->defaults(), $values), $values); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - protected function unguarded() |
|
120 | - { |
|
121 | - return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
122 | - } |
|
116 | + /** |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + protected function unguarded() |
|
120 | + { |
|
121 | + return array_diff_key($this->defaults(), array_flip($this->guarded)); |
|
122 | + } |
|
123 | 123 | } |
@@ -7,41 +7,41 @@ |
||
7 | 7 | |
8 | 8 | class CreateReviewDefaults extends Defaults |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - protected $guarded = [ |
|
14 | - 'assigned_to', |
|
15 | - 'content', |
|
16 | - 'date', |
|
17 | - 'pinned', |
|
18 | - 'response', |
|
19 | - 'review_id', |
|
20 | - 'review_type', |
|
21 | - 'title', |
|
22 | - ]; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + protected $guarded = [ |
|
14 | + 'assigned_to', |
|
15 | + 'content', |
|
16 | + 'date', |
|
17 | + 'pinned', |
|
18 | + 'response', |
|
19 | + 'review_id', |
|
20 | + 'review_type', |
|
21 | + 'title', |
|
22 | + ]; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return array |
|
26 | - */ |
|
27 | - protected function defaults() |
|
28 | - { |
|
29 | - return [ |
|
30 | - 'assigned_to' => '', |
|
31 | - 'author' => '', |
|
32 | - 'avatar' => '', |
|
33 | - 'content' => '', |
|
34 | - 'custom' => '', |
|
35 | - 'date' => current_time('mysql'), |
|
36 | - 'email' => '', |
|
37 | - 'ip_address' => glsr(Helper::class)->getIpAddress(), |
|
38 | - 'pinned' => false, |
|
39 | - 'rating' => '', |
|
40 | - 'response' => '', |
|
41 | - 'review_id' => md5(time().mt_rand()), |
|
42 | - 'review_type' => 'local', |
|
43 | - 'title' => '', |
|
44 | - 'url' => '', |
|
45 | - ]; |
|
46 | - } |
|
24 | + /** |
|
25 | + * @return array |
|
26 | + */ |
|
27 | + protected function defaults() |
|
28 | + { |
|
29 | + return [ |
|
30 | + 'assigned_to' => '', |
|
31 | + 'author' => '', |
|
32 | + 'avatar' => '', |
|
33 | + 'content' => '', |
|
34 | + 'custom' => '', |
|
35 | + 'date' => current_time('mysql'), |
|
36 | + 'email' => '', |
|
37 | + 'ip_address' => glsr(Helper::class)->getIpAddress(), |
|
38 | + 'pinned' => false, |
|
39 | + 'rating' => '', |
|
40 | + 'response' => '', |
|
41 | + 'review_id' => md5(time().mt_rand()), |
|
42 | + 'review_type' => 'local', |
|
43 | + 'title' => '', |
|
44 | + 'url' => '', |
|
45 | + ]; |
|
46 | + } |
|
47 | 47 | } |
@@ -10,165 +10,165 @@ |
||
10 | 10 | |
11 | 11 | class QueryBuilder |
12 | 12 | { |
13 | - /** |
|
14 | - * Build a WP_Query meta_query/tax_query. |
|
15 | - * @return array |
|
16 | - */ |
|
17 | - public function buildQuery(array $keys = [], array $values = []) |
|
18 | - { |
|
19 | - $queries = []; |
|
20 | - foreach ($keys as $key) { |
|
21 | - if (!array_key_exists($key, $values)) { |
|
22 | - continue; |
|
23 | - } |
|
24 | - $methodName = glsr(Helper::class)->buildMethodName($key, __FUNCTION__); |
|
25 | - if (!method_exists($this, $methodName)) { |
|
26 | - continue; |
|
27 | - } |
|
28 | - $query = call_user_func([$this, $methodName], $values[$key]); |
|
29 | - if (is_array($query)) { |
|
30 | - $queries[] = $query; |
|
31 | - } |
|
32 | - } |
|
33 | - return $queries; |
|
34 | - } |
|
13 | + /** |
|
14 | + * Build a WP_Query meta_query/tax_query. |
|
15 | + * @return array |
|
16 | + */ |
|
17 | + public function buildQuery(array $keys = [], array $values = []) |
|
18 | + { |
|
19 | + $queries = []; |
|
20 | + foreach ($keys as $key) { |
|
21 | + if (!array_key_exists($key, $values)) { |
|
22 | + continue; |
|
23 | + } |
|
24 | + $methodName = glsr(Helper::class)->buildMethodName($key, __FUNCTION__); |
|
25 | + if (!method_exists($this, $methodName)) { |
|
26 | + continue; |
|
27 | + } |
|
28 | + $query = call_user_func([$this, $methodName], $values[$key]); |
|
29 | + if (is_array($query)) { |
|
30 | + $queries[] = $query; |
|
31 | + } |
|
32 | + } |
|
33 | + return $queries; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function buildSqlLines(array $values, array $conditions) |
|
40 | - { |
|
41 | - $string = ''; |
|
42 | - $values = array_filter($values); |
|
43 | - foreach ($conditions as $key => $value) { |
|
44 | - if (!isset($values[$key])) { |
|
45 | - continue; |
|
46 | - } |
|
47 | - $values[$key] = implode(',', (array) $values[$key]); |
|
48 | - $string.= false !== strpos($value, '%s') |
|
49 | - ? sprintf($value, strval($values[$key])) |
|
50 | - : $value; |
|
51 | - } |
|
52 | - return $string; |
|
53 | - } |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function buildSqlLines(array $values, array $conditions) |
|
40 | + { |
|
41 | + $string = ''; |
|
42 | + $values = array_filter($values); |
|
43 | + foreach ($conditions as $key => $value) { |
|
44 | + if (!isset($values[$key])) { |
|
45 | + continue; |
|
46 | + } |
|
47 | + $values[$key] = implode(',', (array) $values[$key]); |
|
48 | + $string.= false !== strpos($value, '%s') |
|
49 | + ? sprintf($value, strval($values[$key])) |
|
50 | + : $value; |
|
51 | + } |
|
52 | + return $string; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Build a SQL 'OR' string from an array. |
|
57 | - * @param string|array $values |
|
58 | - * @param string $sprintfFormat |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function buildSqlOr($values, $sprintfFormat) |
|
62 | - { |
|
63 | - if (!is_array($values)) { |
|
64 | - $values = explode(',', $values); |
|
65 | - } |
|
66 | - $values = array_filter(array_map('trim', (array) $values)); |
|
67 | - $values = array_map(function ($value) use ($sprintfFormat) { |
|
68 | - return sprintf($sprintfFormat, $value); |
|
69 | - }, $values); |
|
70 | - return implode(' OR ', $values); |
|
71 | - } |
|
55 | + /** |
|
56 | + * Build a SQL 'OR' string from an array. |
|
57 | + * @param string|array $values |
|
58 | + * @param string $sprintfFormat |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function buildSqlOr($values, $sprintfFormat) |
|
62 | + { |
|
63 | + if (!is_array($values)) { |
|
64 | + $values = explode(',', $values); |
|
65 | + } |
|
66 | + $values = array_filter(array_map('trim', (array) $values)); |
|
67 | + $values = array_map(function ($value) use ($sprintfFormat) { |
|
68 | + return sprintf($sprintfFormat, $value); |
|
69 | + }, $values); |
|
70 | + return implode(' OR ', $values); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Search SQL filter for matching against post title only. |
|
75 | - * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
76 | - * @param string $search |
|
77 | - * @return string |
|
78 | - * @filter posts_search |
|
79 | - */ |
|
80 | - public function filterSearchByTitle($search, WP_Query $query) |
|
81 | - { |
|
82 | - if (empty($search) || empty($query->get('search_terms'))) { |
|
83 | - return $search; |
|
84 | - } |
|
85 | - global $wpdb; |
|
86 | - $n = empty($query->get('exact')) |
|
87 | - ? '%' |
|
88 | - : ''; |
|
89 | - $search = []; |
|
90 | - foreach ((array) $query->get('search_terms') as $term) { |
|
91 | - $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
92 | - } |
|
93 | - if (!is_user_logged_in()) { |
|
94 | - $search[] = "{$wpdb->posts}.post_password = ''"; |
|
95 | - } |
|
96 | - return ' AND '.implode(' AND ', $search); |
|
97 | - } |
|
73 | + /** |
|
74 | + * Search SQL filter for matching against post title only. |
|
75 | + * @see http://wordpress.stackexchange.com/a/11826/1685 |
|
76 | + * @param string $search |
|
77 | + * @return string |
|
78 | + * @filter posts_search |
|
79 | + */ |
|
80 | + public function filterSearchByTitle($search, WP_Query $query) |
|
81 | + { |
|
82 | + if (empty($search) || empty($query->get('search_terms'))) { |
|
83 | + return $search; |
|
84 | + } |
|
85 | + global $wpdb; |
|
86 | + $n = empty($query->get('exact')) |
|
87 | + ? '%' |
|
88 | + : ''; |
|
89 | + $search = []; |
|
90 | + foreach ((array) $query->get('search_terms') as $term) { |
|
91 | + $search[] = $wpdb->prepare("{$wpdb->posts}.post_title LIKE %s", $n.$wpdb->esc_like($term).$n); |
|
92 | + } |
|
93 | + if (!is_user_logged_in()) { |
|
94 | + $search[] = "{$wpdb->posts}.post_password = ''"; |
|
95 | + } |
|
96 | + return ' AND '.implode(' AND ', $search); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get the current page number from the global query. |
|
101 | - * @param bool $isEnabled |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - public function getPaged($isEnabled = true) |
|
105 | - { |
|
106 | - $pagedQuery = !is_front_page() |
|
107 | - ? glsr()->constant('PAGED_QUERY_VAR') |
|
108 | - : 'page'; |
|
109 | - return $isEnabled |
|
110 | - ? max(1, intval(get_query_var($pagedQuery))) |
|
111 | - : 1; |
|
112 | - } |
|
99 | + /** |
|
100 | + * Get the current page number from the global query. |
|
101 | + * @param bool $isEnabled |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + public function getPaged($isEnabled = true) |
|
105 | + { |
|
106 | + $pagedQuery = !is_front_page() |
|
107 | + ? glsr()->constant('PAGED_QUERY_VAR') |
|
108 | + : 'page'; |
|
109 | + return $isEnabled |
|
110 | + ? max(1, intval(get_query_var($pagedQuery))) |
|
111 | + : 1; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @param string $value |
|
116 | - * @return void|array |
|
117 | - */ |
|
118 | - protected function buildQueryAssignedTo($value) |
|
119 | - { |
|
120 | - if (!empty($value)) { |
|
121 | - $postIds = glsr(Helper::class)->convertStringToArray($value, 'is_numeric'); |
|
122 | - return [ |
|
123 | - 'compare' => 'IN', |
|
124 | - 'key' => '_assigned_to', |
|
125 | - 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
126 | - ]; |
|
127 | - } |
|
128 | - } |
|
114 | + /** |
|
115 | + * @param string $value |
|
116 | + * @return void|array |
|
117 | + */ |
|
118 | + protected function buildQueryAssignedTo($value) |
|
119 | + { |
|
120 | + if (!empty($value)) { |
|
121 | + $postIds = glsr(Helper::class)->convertStringToArray($value, 'is_numeric'); |
|
122 | + return [ |
|
123 | + 'compare' => 'IN', |
|
124 | + 'key' => '_assigned_to', |
|
125 | + 'value' => glsr(Polylang::class)->getPostIds($postIds), |
|
126 | + ]; |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @param array $value |
|
132 | - * @return void|array |
|
133 | - */ |
|
134 | - protected function buildQueryCategory($value) |
|
135 | - { |
|
136 | - if (!empty($value)) { |
|
137 | - return [ |
|
138 | - 'field' => 'term_id', |
|
139 | - 'taxonomy' => Application::TAXONOMY, |
|
140 | - 'terms' => $value, |
|
141 | - ]; |
|
142 | - } |
|
143 | - } |
|
130 | + /** |
|
131 | + * @param array $value |
|
132 | + * @return void|array |
|
133 | + */ |
|
134 | + protected function buildQueryCategory($value) |
|
135 | + { |
|
136 | + if (!empty($value)) { |
|
137 | + return [ |
|
138 | + 'field' => 'term_id', |
|
139 | + 'taxonomy' => Application::TAXONOMY, |
|
140 | + 'terms' => $value, |
|
141 | + ]; |
|
142 | + } |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @param string $value |
|
147 | - * @return void|array |
|
148 | - */ |
|
149 | - protected function buildQueryRating($value) |
|
150 | - { |
|
151 | - if (is_numeric($value) |
|
152 | - && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
153 | - return [ |
|
154 | - 'compare' => '>=', |
|
155 | - 'key' => '_rating', |
|
156 | - 'value' => $value, |
|
157 | - ]; |
|
158 | - } |
|
159 | - } |
|
145 | + /** |
|
146 | + * @param string $value |
|
147 | + * @return void|array |
|
148 | + */ |
|
149 | + protected function buildQueryRating($value) |
|
150 | + { |
|
151 | + if (is_numeric($value) |
|
152 | + && in_array(intval($value), range(1, glsr()->constant('MAX_RATING', Rating::class)))) { |
|
153 | + return [ |
|
154 | + 'compare' => '>=', |
|
155 | + 'key' => '_rating', |
|
156 | + 'value' => $value, |
|
157 | + ]; |
|
158 | + } |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * @param string $value |
|
163 | - * @return void|array |
|
164 | - */ |
|
165 | - protected function buildQueryType($value) |
|
166 | - { |
|
167 | - if (!in_array($value, ['', 'all'])) { |
|
168 | - return [ |
|
169 | - 'key' => '_review_type', |
|
170 | - 'value' => $value, |
|
171 | - ]; |
|
172 | - } |
|
173 | - } |
|
161 | + /** |
|
162 | + * @param string $value |
|
163 | + * @return void|array |
|
164 | + */ |
|
165 | + protected function buildQueryType($value) |
|
166 | + { |
|
167 | + if (!in_array($value, ['', 'all'])) { |
|
168 | + return [ |
|
169 | + 'key' => '_review_type', |
|
170 | + 'value' => $value, |
|
171 | + ]; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | } |
@@ -5,7 +5,7 @@ |
||
5 | 5 | require_once __DIR__.'/site-reviews.php'; |
6 | 6 | |
7 | 7 | if (!(new GL_Plugin_Check_v3(__FILE__))->isValid()) { |
8 | - return; |
|
8 | + return; |
|
9 | 9 | } |
10 | 10 | delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(3)); |
11 | 11 | delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(4)); |
@@ -8,24 +8,24 @@ |
||
8 | 8 | |
9 | 9 | class TogglePinned |
10 | 10 | { |
11 | - /** |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public function handle(Command $command) |
|
15 | - { |
|
16 | - if (!get_post($command->id)) { |
|
17 | - return false; |
|
18 | - } |
|
19 | - if (is_null($command->pinned)) { |
|
20 | - $meta = glsr(Database::class)->get($command->id, 'pinned'); |
|
21 | - $command->pinned = !wp_validate_boolean($meta); |
|
22 | - } else { |
|
23 | - $notice = $command->pinned |
|
24 | - ? __('Review pinned.', 'site-reviews') |
|
25 | - : __('Review unpinned.', 'site-reviews'); |
|
26 | - glsr(Notice::class)->addSuccess($notice); |
|
27 | - } |
|
28 | - glsr(Database::class)->update($command->id, 'pinned', $command->pinned); |
|
29 | - return $command->pinned; |
|
30 | - } |
|
11 | + /** |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public function handle(Command $command) |
|
15 | + { |
|
16 | + if (!get_post($command->id)) { |
|
17 | + return false; |
|
18 | + } |
|
19 | + if (is_null($command->pinned)) { |
|
20 | + $meta = glsr(Database::class)->get($command->id, 'pinned'); |
|
21 | + $command->pinned = !wp_validate_boolean($meta); |
|
22 | + } else { |
|
23 | + $notice = $command->pinned |
|
24 | + ? __('Review pinned.', 'site-reviews') |
|
25 | + : __('Review unpinned.', 'site-reviews'); |
|
26 | + glsr(Notice::class)->addSuccess($notice); |
|
27 | + } |
|
28 | + glsr(Database::class)->update($command->id, 'pinned', $command->pinned); |
|
29 | + return $command->pinned; |
|
30 | + } |
|
31 | 31 | } |
@@ -11,176 +11,176 @@ |
||
11 | 11 | |
12 | 12 | class Review implements \ArrayAccess |
13 | 13 | { |
14 | - public $assigned_to; |
|
15 | - public $author; |
|
16 | - public $avatar; |
|
17 | - public $content; |
|
18 | - public $custom; |
|
19 | - public $date; |
|
20 | - public $email; |
|
21 | - public $ID; |
|
22 | - public $ip_address; |
|
23 | - public $modified; |
|
24 | - public $pinned; |
|
25 | - public $rating; |
|
26 | - public $response; |
|
27 | - public $review_id; |
|
28 | - public $review_type; |
|
29 | - public $status; |
|
30 | - public $term_ids; |
|
31 | - public $title; |
|
32 | - public $url; |
|
33 | - public $user_id; |
|
14 | + public $assigned_to; |
|
15 | + public $author; |
|
16 | + public $avatar; |
|
17 | + public $content; |
|
18 | + public $custom; |
|
19 | + public $date; |
|
20 | + public $email; |
|
21 | + public $ID; |
|
22 | + public $ip_address; |
|
23 | + public $modified; |
|
24 | + public $pinned; |
|
25 | + public $rating; |
|
26 | + public $response; |
|
27 | + public $review_id; |
|
28 | + public $review_type; |
|
29 | + public $status; |
|
30 | + public $term_ids; |
|
31 | + public $title; |
|
32 | + public $url; |
|
33 | + public $user_id; |
|
34 | 34 | |
35 | - public function __construct(WP_Post $post) |
|
36 | - { |
|
37 | - if (Application::POST_TYPE != $post->post_type) { |
|
38 | - return; |
|
39 | - } |
|
40 | - $this->content = $post->post_content; |
|
41 | - $this->date = $post->post_date; |
|
42 | - $this->ID = intval($post->ID); |
|
43 | - $this->status = $post->post_status; |
|
44 | - $this->title = $post->post_title; |
|
45 | - $this->user_id = intval($post->post_author); |
|
46 | - $this->setProperties($post); |
|
47 | - $this->setTermIds($post); |
|
48 | - } |
|
35 | + public function __construct(WP_Post $post) |
|
36 | + { |
|
37 | + if (Application::POST_TYPE != $post->post_type) { |
|
38 | + return; |
|
39 | + } |
|
40 | + $this->content = $post->post_content; |
|
41 | + $this->date = $post->post_date; |
|
42 | + $this->ID = intval($post->ID); |
|
43 | + $this->status = $post->post_status; |
|
44 | + $this->title = $post->post_title; |
|
45 | + $this->user_id = intval($post->post_author); |
|
46 | + $this->setProperties($post); |
|
47 | + $this->setTermIds($post); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return mixed |
|
52 | - */ |
|
53 | - public function __get($key) |
|
54 | - { |
|
55 | - return $this->offsetGet($key); |
|
56 | - } |
|
50 | + /** |
|
51 | + * @return mixed |
|
52 | + */ |
|
53 | + public function __get($key) |
|
54 | + { |
|
55 | + return $this->offsetGet($key); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function __toString() |
|
62 | - { |
|
63 | - return (string) $this->build(); |
|
64 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function __toString() |
|
62 | + { |
|
63 | + return (string) $this->build(); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return ReviewHtml |
|
68 | - */ |
|
69 | - public function build(array $args = []) |
|
70 | - { |
|
71 | - if (empty($this->ID)) { |
|
72 | - return new ReviewHtml($this); |
|
73 | - } |
|
74 | - $partial = glsr(SiteReviewsPartial::class); |
|
75 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
76 | - $partial->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()); |
|
77 | - return $partial->buildReview($this); |
|
78 | - } |
|
66 | + /** |
|
67 | + * @return ReviewHtml |
|
68 | + */ |
|
69 | + public function build(array $args = []) |
|
70 | + { |
|
71 | + if (empty($this->ID)) { |
|
72 | + return new ReviewHtml($this); |
|
73 | + } |
|
74 | + $partial = glsr(SiteReviewsPartial::class); |
|
75 | + $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
76 | + $partial->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()); |
|
77 | + return $partial->buildReview($this); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param mixed $key |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - public function offsetExists($key) |
|
85 | - { |
|
86 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
87 | - } |
|
80 | + /** |
|
81 | + * @param mixed $key |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + public function offsetExists($key) |
|
85 | + { |
|
86 | + return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @param mixed $key |
|
91 | - * @return mixed |
|
92 | - */ |
|
93 | - public function offsetGet($key) |
|
94 | - { |
|
95 | - if (property_exists($this, $key)) { |
|
96 | - return $this->{$key}; |
|
97 | - } |
|
98 | - return array_key_exists($key, (array) $this->custom) |
|
99 | - ? $this->custom[$key] |
|
100 | - : null; |
|
101 | - } |
|
89 | + /** |
|
90 | + * @param mixed $key |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + public function offsetGet($key) |
|
94 | + { |
|
95 | + if (property_exists($this, $key)) { |
|
96 | + return $this->{$key}; |
|
97 | + } |
|
98 | + return array_key_exists($key, (array) $this->custom) |
|
99 | + ? $this->custom[$key] |
|
100 | + : null; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param mixed $key |
|
105 | - * @param mixed $value |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function offsetSet($key, $value) |
|
109 | - { |
|
110 | - if (property_exists($this, $key)) { |
|
111 | - $this->{$key} = $value; |
|
112 | - return; |
|
113 | - } |
|
114 | - if (!is_array($this->custom)) { |
|
115 | - $this->custom = array_filter((array) $this->custom); |
|
116 | - } |
|
117 | - $this->custom[$key] = $value; |
|
118 | - } |
|
103 | + /** |
|
104 | + * @param mixed $key |
|
105 | + * @param mixed $value |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function offsetSet($key, $value) |
|
109 | + { |
|
110 | + if (property_exists($this, $key)) { |
|
111 | + $this->{$key} = $value; |
|
112 | + return; |
|
113 | + } |
|
114 | + if (!is_array($this->custom)) { |
|
115 | + $this->custom = array_filter((array) $this->custom); |
|
116 | + } |
|
117 | + $this->custom[$key] = $value; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @param mixed $key |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function offsetUnset($key) |
|
125 | - { |
|
126 | - $this->offsetSet($key, null); |
|
127 | - } |
|
120 | + /** |
|
121 | + * @param mixed $key |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function offsetUnset($key) |
|
125 | + { |
|
126 | + $this->offsetSet($key, null); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - public function render() |
|
133 | - { |
|
134 | - echo $this->build(); |
|
135 | - } |
|
129 | + /** |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + public function render() |
|
133 | + { |
|
134 | + echo $this->build(); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - protected function isModified(array $properties) |
|
141 | - { |
|
142 | - return $this->date != $properties['date'] |
|
143 | - || $this->content != $properties['content'] |
|
144 | - || $this->title != $properties['title']; |
|
145 | - } |
|
137 | + /** |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + protected function isModified(array $properties) |
|
141 | + { |
|
142 | + return $this->date != $properties['date'] |
|
143 | + || $this->content != $properties['content'] |
|
144 | + || $this->title != $properties['title']; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - protected function setProperties(WP_Post $post) |
|
151 | - { |
|
152 | - $defaults = [ |
|
153 | - 'author' => __('Anonymous', 'site-reviews'), |
|
154 | - 'date' => '', |
|
155 | - 'review_id' => '', |
|
156 | - 'review_type' => 'local', |
|
157 | - ]; |
|
158 | - $meta = array_filter( |
|
159 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
160 | - 'strlen' |
|
161 | - ); |
|
162 | - $meta = array_merge($defaults, glsr(Helper::class)->unprefixArrayKeys($meta)); |
|
163 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
164 | - $this->modified = $this->isModified($properties); |
|
165 | - array_walk($properties, function ($value, $key) { |
|
166 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
167 | - return; |
|
168 | - } |
|
169 | - $this->$key = maybe_unserialize($value); |
|
170 | - }); |
|
171 | - } |
|
147 | + /** |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + protected function setProperties(WP_Post $post) |
|
151 | + { |
|
152 | + $defaults = [ |
|
153 | + 'author' => __('Anonymous', 'site-reviews'), |
|
154 | + 'date' => '', |
|
155 | + 'review_id' => '', |
|
156 | + 'review_type' => 'local', |
|
157 | + ]; |
|
158 | + $meta = array_filter( |
|
159 | + array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
160 | + 'strlen' |
|
161 | + ); |
|
162 | + $meta = array_merge($defaults, glsr(Helper::class)->unprefixArrayKeys($meta)); |
|
163 | + $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
164 | + $this->modified = $this->isModified($properties); |
|
165 | + array_walk($properties, function ($value, $key) { |
|
166 | + if (!property_exists($this, $key) || isset($this->$key)) { |
|
167 | + return; |
|
168 | + } |
|
169 | + $this->$key = maybe_unserialize($value); |
|
170 | + }); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * @return void |
|
175 | - */ |
|
176 | - protected function setTermIds(WP_Post $post) |
|
177 | - { |
|
178 | - $this->term_ids = []; |
|
179 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
180 | - return; |
|
181 | - } |
|
182 | - foreach ($terms as $term) { |
|
183 | - $this->term_ids[] = $term->term_id; |
|
184 | - } |
|
185 | - } |
|
173 | + /** |
|
174 | + * @return void |
|
175 | + */ |
|
176 | + protected function setTermIds(WP_Post $post) |
|
177 | + { |
|
178 | + $this->term_ids = []; |
|
179 | + if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
180 | + return; |
|
181 | + } |
|
182 | + foreach ($terms as $term) { |
|
183 | + $this->term_ids[] = $term->term_id; |
|
184 | + } |
|
185 | + } |
|
186 | 186 | } |
@@ -7,82 +7,82 @@ |
||
7 | 7 | |
8 | 8 | class Akismet |
9 | 9 | { |
10 | - /** |
|
11 | - * @return bool |
|
12 | - */ |
|
13 | - public function isSpam(array $review) |
|
14 | - { |
|
15 | - if (!$this->isActive()) { |
|
16 | - return false; |
|
17 | - } |
|
18 | - $submission = [ |
|
19 | - 'blog' => glsr(OptionManager::class)->getWP('home'), |
|
20 | - 'blog_charset' => glsr(OptionManager::class)->getWP('blog_charset', 'UTF-8'), |
|
21 | - 'blog_lang' => get_locale(), |
|
22 | - 'comment_author' => $review['name'], |
|
23 | - 'comment_author_email' => $review['email'], |
|
24 | - 'comment_content' => $review['title']."\n\n".$review['content'], |
|
25 | - 'comment_type' => 'review', |
|
26 | - 'referrer' => filter_input(INPUT_SERVER, 'HTTP_REFERER'), |
|
27 | - 'user_agent' => filter_input(INPUT_SERVER, 'HTTP_USER_AGENT'), |
|
28 | - 'user_ip' => $review['ip_address'], |
|
29 | - // 'user_role' => 'administrator', |
|
30 | - // 'is_test' => 1, |
|
31 | - ]; |
|
32 | - foreach ($_SERVER as $key => $value) { |
|
33 | - if (is_array($value) || in_array($key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'])) { |
|
34 | - continue; |
|
35 | - } |
|
36 | - $submission[$key] = $value; |
|
37 | - } |
|
38 | - return $this->check(apply_filters('site-reviews/akismet/submission', $submission, $review)); |
|
39 | - } |
|
10 | + /** |
|
11 | + * @return bool |
|
12 | + */ |
|
13 | + public function isSpam(array $review) |
|
14 | + { |
|
15 | + if (!$this->isActive()) { |
|
16 | + return false; |
|
17 | + } |
|
18 | + $submission = [ |
|
19 | + 'blog' => glsr(OptionManager::class)->getWP('home'), |
|
20 | + 'blog_charset' => glsr(OptionManager::class)->getWP('blog_charset', 'UTF-8'), |
|
21 | + 'blog_lang' => get_locale(), |
|
22 | + 'comment_author' => $review['name'], |
|
23 | + 'comment_author_email' => $review['email'], |
|
24 | + 'comment_content' => $review['title']."\n\n".$review['content'], |
|
25 | + 'comment_type' => 'review', |
|
26 | + 'referrer' => filter_input(INPUT_SERVER, 'HTTP_REFERER'), |
|
27 | + 'user_agent' => filter_input(INPUT_SERVER, 'HTTP_USER_AGENT'), |
|
28 | + 'user_ip' => $review['ip_address'], |
|
29 | + // 'user_role' => 'administrator', |
|
30 | + // 'is_test' => 1, |
|
31 | + ]; |
|
32 | + foreach ($_SERVER as $key => $value) { |
|
33 | + if (is_array($value) || in_array($key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'])) { |
|
34 | + continue; |
|
35 | + } |
|
36 | + $submission[$key] = $value; |
|
37 | + } |
|
38 | + return $this->check(apply_filters('site-reviews/akismet/submission', $submission, $review)); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - protected function check(array $submission) |
|
45 | - { |
|
46 | - $response = AkismetPlugin::http_post($this->buildQuery($submission), 'comment-check'); |
|
47 | - return apply_filters('site-reviews/akismet/is-spam', |
|
48 | - 'true' == $response[1], |
|
49 | - $submission, |
|
50 | - $response |
|
51 | - ); |
|
52 | - } |
|
41 | + /** |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + protected function check(array $submission) |
|
45 | + { |
|
46 | + $response = AkismetPlugin::http_post($this->buildQuery($submission), 'comment-check'); |
|
47 | + return apply_filters('site-reviews/akismet/is-spam', |
|
48 | + 'true' == $response[1], |
|
49 | + $submission, |
|
50 | + $response |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - protected function buildQuery(array $data) |
|
58 | - { |
|
59 | - $query = []; |
|
60 | - foreach ($data as $key => $value) { |
|
61 | - if (is_array($value) || is_object($value)) { |
|
62 | - continue; |
|
63 | - } |
|
64 | - if (false === $value) { |
|
65 | - $value = '0'; |
|
66 | - } |
|
67 | - $value = trim($value); |
|
68 | - if (!strlen($value)) { |
|
69 | - continue; |
|
70 | - } |
|
71 | - $query[] = urlencode($key).'='.urlencode($value); |
|
72 | - } |
|
73 | - return implode('&', $query); |
|
74 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + protected function buildQuery(array $data) |
|
58 | + { |
|
59 | + $query = []; |
|
60 | + foreach ($data as $key => $value) { |
|
61 | + if (is_array($value) || is_object($value)) { |
|
62 | + continue; |
|
63 | + } |
|
64 | + if (false === $value) { |
|
65 | + $value = '0'; |
|
66 | + } |
|
67 | + $value = trim($value); |
|
68 | + if (!strlen($value)) { |
|
69 | + continue; |
|
70 | + } |
|
71 | + $query[] = urlencode($key).'='.urlencode($value); |
|
72 | + } |
|
73 | + return implode('&', $query); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - protected function isActive() |
|
80 | - { |
|
81 | - $check = !glsr(OptionManager::class)->getBool('settings.submissions.akismet') |
|
82 | - || !is_callable(['Akismet', 'get_api_key']) |
|
83 | - || !is_callable(['Akismet', 'http_post']) |
|
84 | - ? false |
|
85 | - : (bool) AkismetPlugin::get_api_key(); |
|
86 | - return apply_filters('site-reviews/akismet/is-active', $check); |
|
87 | - } |
|
76 | + /** |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + protected function isActive() |
|
80 | + { |
|
81 | + $check = !glsr(OptionManager::class)->getBool('settings.submissions.akismet') |
|
82 | + || !is_callable(['Akismet', 'get_api_key']) |
|
83 | + || !is_callable(['Akismet', 'http_post']) |
|
84 | + ? false |
|
85 | + : (bool) AkismetPlugin::get_api_key(); |
|
86 | + return apply_filters('site-reviews/akismet/is-active', $check); |
|
87 | + } |
|
88 | 88 | } |
@@ -19,376 +19,376 @@ |
||
19 | 19 | |
20 | 20 | class SiteReviews |
21 | 21 | { |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $args; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $args; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var Review |
|
29 | - */ |
|
30 | - public $current; |
|
27 | + /** |
|
28 | + * @var Review |
|
29 | + */ |
|
30 | + public $current; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - public $options; |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + public $options; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var Reviews |
|
39 | - */ |
|
40 | - protected $reviews; |
|
37 | + /** |
|
38 | + * @var Reviews |
|
39 | + */ |
|
40 | + protected $reviews; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param Reviews|null $reviews |
|
44 | - * @return ReviewsHtml |
|
45 | - */ |
|
46 | - public function build(array $args = [], $reviews = null) |
|
47 | - { |
|
48 | - $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
49 | - $this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()); |
|
50 | - $this->reviews = $reviews instanceof Reviews |
|
51 | - ? $reviews |
|
52 | - : glsr(ReviewManager::class)->get($args); |
|
53 | - $this->generateSchema(); |
|
54 | - return $this->buildReviews(); |
|
55 | - } |
|
42 | + /** |
|
43 | + * @param Reviews|null $reviews |
|
44 | + * @return ReviewsHtml |
|
45 | + */ |
|
46 | + public function build(array $args = [], $reviews = null) |
|
47 | + { |
|
48 | + $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
49 | + $this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()); |
|
50 | + $this->reviews = $reviews instanceof Reviews |
|
51 | + ? $reviews |
|
52 | + : glsr(ReviewManager::class)->get($args); |
|
53 | + $this->generateSchema(); |
|
54 | + return $this->buildReviews(); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return ReviewHtml |
|
59 | - */ |
|
60 | - public function buildReview(Review $review) |
|
61 | - { |
|
62 | - $review = apply_filters('site-reviews/review/build/before', $review); |
|
63 | - $this->current = $review; |
|
64 | - $renderedFields = []; |
|
65 | - foreach ($review as $key => $value) { |
|
66 | - $method = glsr(Helper::class)->buildMethodName($key, 'buildOption'); |
|
67 | - $field = method_exists($this, $method) |
|
68 | - ? $this->$method($key, $value) |
|
69 | - : apply_filters('site-reviews/review/build/'.$key, false, $value, $this, $review); |
|
70 | - if (false === $field) { |
|
71 | - continue; |
|
72 | - } |
|
73 | - $renderedFields[$key] = $field; |
|
74 | - } |
|
75 | - $this->wrap($renderedFields, $review); |
|
76 | - $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review); |
|
77 | - $this->current = null; |
|
78 | - return new ReviewHtml($review, (array) $renderedFields); |
|
79 | - } |
|
57 | + /** |
|
58 | + * @return ReviewHtml |
|
59 | + */ |
|
60 | + public function buildReview(Review $review) |
|
61 | + { |
|
62 | + $review = apply_filters('site-reviews/review/build/before', $review); |
|
63 | + $this->current = $review; |
|
64 | + $renderedFields = []; |
|
65 | + foreach ($review as $key => $value) { |
|
66 | + $method = glsr(Helper::class)->buildMethodName($key, 'buildOption'); |
|
67 | + $field = method_exists($this, $method) |
|
68 | + ? $this->$method($key, $value) |
|
69 | + : apply_filters('site-reviews/review/build/'.$key, false, $value, $this, $review); |
|
70 | + if (false === $field) { |
|
71 | + continue; |
|
72 | + } |
|
73 | + $renderedFields[$key] = $field; |
|
74 | + } |
|
75 | + $this->wrap($renderedFields, $review); |
|
76 | + $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review); |
|
77 | + $this->current = null; |
|
78 | + return new ReviewHtml($review, (array) $renderedFields); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return ReviewsHtml |
|
83 | - */ |
|
84 | - public function buildReviews() |
|
85 | - { |
|
86 | - $renderedReviews = []; |
|
87 | - foreach ($this->reviews as $index => $review) { |
|
88 | - $renderedReviews[] = $this->buildReview($review); |
|
89 | - } |
|
90 | - return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @return ReviewsHtml |
|
83 | + */ |
|
84 | + public function buildReviews() |
|
85 | + { |
|
86 | + $renderedReviews = []; |
|
87 | + foreach ($this->reviews as $index => $review) { |
|
88 | + $renderedReviews[] = $this->buildReview($review); |
|
89 | + } |
|
90 | + return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function generateSchema() |
|
97 | - { |
|
98 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
99 | - return; |
|
100 | - } |
|
101 | - glsr(Schema::class)->store( |
|
102 | - glsr(Schema::class)->build($this->args) |
|
103 | - ); |
|
104 | - } |
|
93 | + /** |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function generateSchema() |
|
97 | + { |
|
98 | + if (!wp_validate_boolean($this->args['schema'])) { |
|
99 | + return; |
|
100 | + } |
|
101 | + glsr(Schema::class)->store( |
|
102 | + glsr(Schema::class)->build($this->args) |
|
103 | + ); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @param string $key |
|
108 | - * @param string $path |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public function isHidden($key, $path = '') |
|
112 | - { |
|
113 | - $isOptionEnabled = !empty($path) |
|
114 | - ? $this->isOptionEnabled($path) |
|
115 | - : true; |
|
116 | - return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
117 | - } |
|
106 | + /** |
|
107 | + * @param string $key |
|
108 | + * @param string $path |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public function isHidden($key, $path = '') |
|
112 | + { |
|
113 | + $isOptionEnabled = !empty($path) |
|
114 | + ? $this->isOptionEnabled($path) |
|
115 | + : true; |
|
116 | + return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * @param string $key |
|
121 | - * @param string $value |
|
122 | - * @return void|string |
|
123 | - */ |
|
124 | - protected function buildOptionAssignedTo($key, $value) |
|
125 | - { |
|
126 | - if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
127 | - return; |
|
128 | - } |
|
129 | - $post = glsr(Polylang::class)->getPost($value); |
|
130 | - if (!($post instanceof WP_Post)) { |
|
131 | - return; |
|
132 | - } |
|
133 | - $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
134 | - 'href' => get_the_permalink($post->ID), |
|
135 | - ]); |
|
136 | - $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
137 | - return '<span>'.$assignedTo.'</span>'; |
|
138 | - } |
|
119 | + /** |
|
120 | + * @param string $key |
|
121 | + * @param string $value |
|
122 | + * @return void|string |
|
123 | + */ |
|
124 | + protected function buildOptionAssignedTo($key, $value) |
|
125 | + { |
|
126 | + if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
127 | + return; |
|
128 | + } |
|
129 | + $post = glsr(Polylang::class)->getPost($value); |
|
130 | + if (!($post instanceof WP_Post)) { |
|
131 | + return; |
|
132 | + } |
|
133 | + $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
134 | + 'href' => get_the_permalink($post->ID), |
|
135 | + ]); |
|
136 | + $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
137 | + return '<span>'.$assignedTo.'</span>'; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @param string $key |
|
142 | - * @param string $value |
|
143 | - * @return void|string |
|
144 | - */ |
|
145 | - protected function buildOptionAuthor($key, $value) |
|
146 | - { |
|
147 | - if (!$this->isHidden($key)) { |
|
148 | - return '<span>'.$value.'</span>'; |
|
149 | - } |
|
150 | - } |
|
140 | + /** |
|
141 | + * @param string $key |
|
142 | + * @param string $value |
|
143 | + * @return void|string |
|
144 | + */ |
|
145 | + protected function buildOptionAuthor($key, $value) |
|
146 | + { |
|
147 | + if (!$this->isHidden($key)) { |
|
148 | + return '<span>'.$value.'</span>'; |
|
149 | + } |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @param string $key |
|
154 | - * @param string $value |
|
155 | - * @return void|string |
|
156 | - */ |
|
157 | - protected function buildOptionAvatar($key, $value) |
|
158 | - { |
|
159 | - if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
160 | - return; |
|
161 | - } |
|
162 | - $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
163 | - return glsr(Builder::class)->img([ |
|
164 | - 'height' => $size, |
|
165 | - 'src' => $this->generateAvatar($value), |
|
166 | - 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
167 | - 'width' => $size, |
|
168 | - ]); |
|
169 | - } |
|
152 | + /** |
|
153 | + * @param string $key |
|
154 | + * @param string $value |
|
155 | + * @return void|string |
|
156 | + */ |
|
157 | + protected function buildOptionAvatar($key, $value) |
|
158 | + { |
|
159 | + if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
160 | + return; |
|
161 | + } |
|
162 | + $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
163 | + return glsr(Builder::class)->img([ |
|
164 | + 'height' => $size, |
|
165 | + 'src' => $this->generateAvatar($value), |
|
166 | + 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
167 | + 'width' => $size, |
|
168 | + ]); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @param string $key |
|
173 | - * @param string $value |
|
174 | - * @return void|string |
|
175 | - */ |
|
176 | - protected function buildOptionContent($key, $value) |
|
177 | - { |
|
178 | - $text = $this->normalizeText($value); |
|
179 | - if (!$this->isHiddenOrEmpty($key, $text)) { |
|
180 | - return '<p>'.$text.'</p>'; |
|
181 | - } |
|
182 | - } |
|
171 | + /** |
|
172 | + * @param string $key |
|
173 | + * @param string $value |
|
174 | + * @return void|string |
|
175 | + */ |
|
176 | + protected function buildOptionContent($key, $value) |
|
177 | + { |
|
178 | + $text = $this->normalizeText($value); |
|
179 | + if (!$this->isHiddenOrEmpty($key, $text)) { |
|
180 | + return '<p>'.$text.'</p>'; |
|
181 | + } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * @param string $key |
|
186 | - * @param string $value |
|
187 | - * @return void|string |
|
188 | - */ |
|
189 | - protected function buildOptionDate($key, $value) |
|
190 | - { |
|
191 | - if ($this->isHidden($key)) { |
|
192 | - return; |
|
193 | - } |
|
194 | - $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
195 | - if ('relative' == $dateFormat) { |
|
196 | - $date = glsr(Date::class)->relative($value); |
|
197 | - } else { |
|
198 | - $format = 'custom' == $dateFormat |
|
199 | - ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
200 | - : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
201 | - $date = date_i18n($format, strtotime($value)); |
|
202 | - } |
|
203 | - return '<span>'.$date.'</span>'; |
|
204 | - } |
|
184 | + /** |
|
185 | + * @param string $key |
|
186 | + * @param string $value |
|
187 | + * @return void|string |
|
188 | + */ |
|
189 | + protected function buildOptionDate($key, $value) |
|
190 | + { |
|
191 | + if ($this->isHidden($key)) { |
|
192 | + return; |
|
193 | + } |
|
194 | + $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
195 | + if ('relative' == $dateFormat) { |
|
196 | + $date = glsr(Date::class)->relative($value); |
|
197 | + } else { |
|
198 | + $format = 'custom' == $dateFormat |
|
199 | + ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
200 | + : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
201 | + $date = date_i18n($format, strtotime($value)); |
|
202 | + } |
|
203 | + return '<span>'.$date.'</span>'; |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * @param string $key |
|
208 | - * @param string $value |
|
209 | - * @return void|string |
|
210 | - */ |
|
211 | - protected function buildOptionRating($key, $value) |
|
212 | - { |
|
213 | - if (!$this->isHiddenOrEmpty($key, $value)) { |
|
214 | - return glsr_star_rating($value); |
|
215 | - } |
|
216 | - } |
|
206 | + /** |
|
207 | + * @param string $key |
|
208 | + * @param string $value |
|
209 | + * @return void|string |
|
210 | + */ |
|
211 | + protected function buildOptionRating($key, $value) |
|
212 | + { |
|
213 | + if (!$this->isHiddenOrEmpty($key, $value)) { |
|
214 | + return glsr_star_rating($value); |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * @param string $key |
|
220 | - * @param string $value |
|
221 | - * @return void|string |
|
222 | - */ |
|
223 | - protected function buildOptionResponse($key, $value) |
|
224 | - { |
|
225 | - if ($this->isHiddenOrEmpty($key, $value)) { |
|
226 | - return; |
|
227 | - } |
|
228 | - $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
229 | - $text = $this->normalizeText($value); |
|
230 | - $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
|
231 | - $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
232 | - $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
233 | - return $response.$background; |
|
234 | - } |
|
218 | + /** |
|
219 | + * @param string $key |
|
220 | + * @param string $value |
|
221 | + * @return void|string |
|
222 | + */ |
|
223 | + protected function buildOptionResponse($key, $value) |
|
224 | + { |
|
225 | + if ($this->isHiddenOrEmpty($key, $value)) { |
|
226 | + return; |
|
227 | + } |
|
228 | + $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
229 | + $text = $this->normalizeText($value); |
|
230 | + $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
|
231 | + $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
232 | + $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
233 | + return $response.$background; |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * @param string $key |
|
238 | - * @param string $value |
|
239 | - * @return void|string |
|
240 | - */ |
|
241 | - protected function buildOptionTitle($key, $value) |
|
242 | - { |
|
243 | - if ($this->isHidden($key)) { |
|
244 | - return; |
|
245 | - } |
|
246 | - if (empty($value)) { |
|
247 | - $value = __('No Title', 'site-reviews'); |
|
248 | - } |
|
249 | - return '<h3>'.$value.'</h3>'; |
|
250 | - } |
|
236 | + /** |
|
237 | + * @param string $key |
|
238 | + * @param string $value |
|
239 | + * @return void|string |
|
240 | + */ |
|
241 | + protected function buildOptionTitle($key, $value) |
|
242 | + { |
|
243 | + if ($this->isHidden($key)) { |
|
244 | + return; |
|
245 | + } |
|
246 | + if (empty($value)) { |
|
247 | + $value = __('No Title', 'site-reviews'); |
|
248 | + } |
|
249 | + return '<h3>'.$value.'</h3>'; |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * @param string $avatarUrl |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - protected function generateAvatar($avatarUrl) |
|
257 | - { |
|
258 | - if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
259 | - return $avatarUrl; |
|
260 | - } |
|
261 | - $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
262 | - if (empty($authorIdOrEmail)) { |
|
263 | - $authorIdOrEmail = $this->current->email; |
|
264 | - } |
|
265 | - if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
266 | - return $newAvatar; |
|
267 | - } |
|
268 | - return $avatarUrl; |
|
269 | - } |
|
252 | + /** |
|
253 | + * @param string $avatarUrl |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + protected function generateAvatar($avatarUrl) |
|
257 | + { |
|
258 | + if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
259 | + return $avatarUrl; |
|
260 | + } |
|
261 | + $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
262 | + if (empty($authorIdOrEmail)) { |
|
263 | + $authorIdOrEmail = $this->current->email; |
|
264 | + } |
|
265 | + if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
266 | + return $newAvatar; |
|
267 | + } |
|
268 | + return $avatarUrl; |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * @param string $text |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - protected function getExcerpt($text) |
|
276 | - { |
|
277 | - $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
278 | - $split = extension_loaded('intl') |
|
279 | - ? $this->getExcerptIntlSplit($text, $limit) |
|
280 | - : $this->getExcerptSplit($text, $limit); |
|
281 | - $hiddenText = substr($text, $split); |
|
282 | - if (!empty($hiddenText)) { |
|
283 | - $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
284 | - 'class' => 'glsr-hidden glsr-hidden-text', |
|
285 | - 'data-show-less' => __('Show less', 'site-reviews'), |
|
286 | - 'data-show-more' => __('Show more', 'site-reviews'), |
|
287 | - ]); |
|
288 | - $text = ltrim(substr($text, 0, $split)).$showMore; |
|
289 | - } |
|
290 | - return $text; |
|
291 | - } |
|
271 | + /** |
|
272 | + * @param string $text |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + protected function getExcerpt($text) |
|
276 | + { |
|
277 | + $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
278 | + $split = extension_loaded('intl') |
|
279 | + ? $this->getExcerptIntlSplit($text, $limit) |
|
280 | + : $this->getExcerptSplit($text, $limit); |
|
281 | + $hiddenText = substr($text, $split); |
|
282 | + if (!empty($hiddenText)) { |
|
283 | + $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
284 | + 'class' => 'glsr-hidden glsr-hidden-text', |
|
285 | + 'data-show-less' => __('Show less', 'site-reviews'), |
|
286 | + 'data-show-more' => __('Show more', 'site-reviews'), |
|
287 | + ]); |
|
288 | + $text = ltrim(substr($text, 0, $split)).$showMore; |
|
289 | + } |
|
290 | + return $text; |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * @param string $text |
|
295 | - * @param int $limit |
|
296 | - * @return int |
|
297 | - */ |
|
298 | - protected function getExcerptIntlSplit($text, $limit) |
|
299 | - { |
|
300 | - $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
301 | - $words->setText($text); |
|
302 | - $count = 0; |
|
303 | - foreach ($words as $offset) { |
|
304 | - if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
305 | - continue; |
|
306 | - } |
|
307 | - ++$count; |
|
308 | - if ($count != $limit) { |
|
309 | - continue; |
|
310 | - } |
|
311 | - return $offset; |
|
312 | - } |
|
313 | - return strlen($text); |
|
314 | - } |
|
293 | + /** |
|
294 | + * @param string $text |
|
295 | + * @param int $limit |
|
296 | + * @return int |
|
297 | + */ |
|
298 | + protected function getExcerptIntlSplit($text, $limit) |
|
299 | + { |
|
300 | + $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
301 | + $words->setText($text); |
|
302 | + $count = 0; |
|
303 | + foreach ($words as $offset) { |
|
304 | + if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
305 | + continue; |
|
306 | + } |
|
307 | + ++$count; |
|
308 | + if ($count != $limit) { |
|
309 | + continue; |
|
310 | + } |
|
311 | + return $offset; |
|
312 | + } |
|
313 | + return strlen($text); |
|
314 | + } |
|
315 | 315 | |
316 | - /** |
|
317 | - * @param string $text |
|
318 | - * @param int $limit |
|
319 | - * @return int |
|
320 | - */ |
|
321 | - protected function getExcerptSplit($text, $limit) |
|
322 | - { |
|
323 | - if (str_word_count($text, 0) > $limit) { |
|
324 | - $words = array_keys(str_word_count($text, 2)); |
|
325 | - return $words[$limit]; |
|
326 | - } |
|
327 | - return strlen($text); |
|
328 | - } |
|
316 | + /** |
|
317 | + * @param string $text |
|
318 | + * @param int $limit |
|
319 | + * @return int |
|
320 | + */ |
|
321 | + protected function getExcerptSplit($text, $limit) |
|
322 | + { |
|
323 | + if (str_word_count($text, 0) > $limit) { |
|
324 | + $words = array_keys(str_word_count($text, 2)); |
|
325 | + return $words[$limit]; |
|
326 | + } |
|
327 | + return strlen($text); |
|
328 | + } |
|
329 | 329 | |
330 | - /** |
|
331 | - * @param string $path |
|
332 | - * @param mixed $fallback |
|
333 | - * @return mixed |
|
334 | - */ |
|
335 | - protected function getOption($path, $fallback = '') |
|
336 | - { |
|
337 | - if (array_key_exists($path, $this->options)) { |
|
338 | - return $this->options[$path]; |
|
339 | - } |
|
340 | - return $fallback; |
|
341 | - } |
|
330 | + /** |
|
331 | + * @param string $path |
|
332 | + * @param mixed $fallback |
|
333 | + * @return mixed |
|
334 | + */ |
|
335 | + protected function getOption($path, $fallback = '') |
|
336 | + { |
|
337 | + if (array_key_exists($path, $this->options)) { |
|
338 | + return $this->options[$path]; |
|
339 | + } |
|
340 | + return $fallback; |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * @param string $key |
|
345 | - * @param string $value |
|
346 | - * @return bool |
|
347 | - */ |
|
348 | - protected function isHiddenOrEmpty($key, $value) |
|
349 | - { |
|
350 | - return $this->isHidden($key) || empty($value); |
|
351 | - } |
|
343 | + /** |
|
344 | + * @param string $key |
|
345 | + * @param string $value |
|
346 | + * @return bool |
|
347 | + */ |
|
348 | + protected function isHiddenOrEmpty($key, $value) |
|
349 | + { |
|
350 | + return $this->isHidden($key) || empty($value); |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * @param string $path |
|
355 | - * @return bool |
|
356 | - */ |
|
357 | - protected function isOptionEnabled($path) |
|
358 | - { |
|
359 | - return 'yes' == $this->getOption($path); |
|
360 | - } |
|
353 | + /** |
|
354 | + * @param string $path |
|
355 | + * @return bool |
|
356 | + */ |
|
357 | + protected function isOptionEnabled($path) |
|
358 | + { |
|
359 | + return 'yes' == $this->getOption($path); |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
363 | - * @param string $text |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - protected function normalizeText($text) |
|
367 | - { |
|
368 | - $text = wp_kses($text, wp_kses_allowed_html()); |
|
369 | - $text = convert_smilies(strip_shortcodes($text)); |
|
370 | - $text = str_replace(']]>', ']]>', $text); |
|
371 | - $text = preg_replace('/(\R){2,}/', '$1', $text); |
|
372 | - if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
373 | - $text = $this->getExcerpt($text); |
|
374 | - } |
|
375 | - return wptexturize(nl2br($text)); |
|
376 | - } |
|
362 | + /** |
|
363 | + * @param string $text |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + protected function normalizeText($text) |
|
367 | + { |
|
368 | + $text = wp_kses($text, wp_kses_allowed_html()); |
|
369 | + $text = convert_smilies(strip_shortcodes($text)); |
|
370 | + $text = str_replace(']]>', ']]>', $text); |
|
371 | + $text = preg_replace('/(\R){2,}/', '$1', $text); |
|
372 | + if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
373 | + $text = $this->getExcerpt($text); |
|
374 | + } |
|
375 | + return wptexturize(nl2br($text)); |
|
376 | + } |
|
377 | 377 | |
378 | - /** |
|
379 | - * @return void |
|
380 | - */ |
|
381 | - protected function wrap(array &$renderedFields, Review $review) |
|
382 | - { |
|
383 | - $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review); |
|
384 | - array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
385 | - $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
386 | - if (empty($value)) { |
|
387 | - return; |
|
388 | - } |
|
389 | - $value = glsr(Builder::class)->div($value, [ |
|
390 | - 'class' => 'glsr-review-'.$key, |
|
391 | - ]); |
|
392 | - }); |
|
393 | - } |
|
378 | + /** |
|
379 | + * @return void |
|
380 | + */ |
|
381 | + protected function wrap(array &$renderedFields, Review $review) |
|
382 | + { |
|
383 | + $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review); |
|
384 | + array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
385 | + $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
386 | + if (empty($value)) { |
|
387 | + return; |
|
388 | + } |
|
389 | + $value = glsr(Builder::class)->div($value, [ |
|
390 | + 'class' => 'glsr-review-'.$key, |
|
391 | + ]); |
|
392 | + }); |
|
393 | + } |
|
394 | 394 | } |