@@ -7,48 +7,48 @@ |
||
7 | 7 | |
8 | 8 | class ReviewHtml extends ArrayObject |
9 | 9 | { |
10 | - /** |
|
11 | - * @var Review |
|
12 | - */ |
|
13 | - public $review; |
|
10 | + /** |
|
11 | + * @var Review |
|
12 | + */ |
|
13 | + public $review; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $values; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $values; |
|
19 | 19 | |
20 | - public function __construct(Review $review, array $values = []) |
|
21 | - { |
|
22 | - $this->review = $review; |
|
23 | - $this->values = $values; |
|
24 | - parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
25 | - } |
|
20 | + public function __construct(Review $review, array $values = []) |
|
21 | + { |
|
22 | + $this->review = $review; |
|
23 | + $this->values = $values; |
|
24 | + parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @return string|void |
|
29 | - */ |
|
30 | - public function __toString() |
|
31 | - { |
|
32 | - if (empty($this->values)) { |
|
33 | - return; |
|
34 | - } |
|
35 | - return glsr(Template::class)->build('templates/review', [ |
|
36 | - 'context' => $this->values, |
|
37 | - 'review' => $this->review, |
|
38 | - ]); |
|
39 | - } |
|
27 | + /** |
|
28 | + * @return string|void |
|
29 | + */ |
|
30 | + public function __toString() |
|
31 | + { |
|
32 | + if (empty($this->values)) { |
|
33 | + return; |
|
34 | + } |
|
35 | + return glsr(Template::class)->build('templates/review', [ |
|
36 | + 'context' => $this->values, |
|
37 | + 'review' => $this->review, |
|
38 | + ]); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param mixed $key |
|
43 | - * @return mixed |
|
44 | - */ |
|
45 | - public function offsetGet($key) |
|
46 | - { |
|
47 | - if (property_exists($this, $key)) { |
|
48 | - return $this->$key; |
|
49 | - } |
|
50 | - return array_key_exists($key, $this->values) |
|
51 | - ? $this->values[$key] |
|
52 | - : null; |
|
53 | - } |
|
41 | + /** |
|
42 | + * @param mixed $key |
|
43 | + * @return mixed |
|
44 | + */ |
|
45 | + public function offsetGet($key) |
|
46 | + { |
|
47 | + if (property_exists($this, $key)) { |
|
48 | + return $this->$key; |
|
49 | + } |
|
50 | + return array_key_exists($key, $this->values) |
|
51 | + ? $this->values[$key] |
|
52 | + : null; |
|
53 | + } |
|
54 | 54 | } |
@@ -7,135 +7,135 @@ |
||
7 | 7 | |
8 | 8 | class ReviewsHtml extends ArrayObject |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - public $args; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + public $args; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var int |
|
17 | - */ |
|
18 | - public $max_num_pages; |
|
15 | + /** |
|
16 | + * @var int |
|
17 | + */ |
|
18 | + public $max_num_pages; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $pagination; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $pagination; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - public $reviews; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + public $reviews; |
|
29 | 29 | |
30 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
31 | - { |
|
32 | - $this->args = $args; |
|
33 | - $this->max_num_pages = $maxPageCount; |
|
34 | - $this->reviews = $reviews; |
|
35 | - $this->pagination = $this->buildPagination(); |
|
36 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | - } |
|
30 | + public function __construct(array $reviews, $maxPageCount, array $args) |
|
31 | + { |
|
32 | + $this->args = $args; |
|
33 | + $this->max_num_pages = $maxPageCount; |
|
34 | + $this->reviews = $reviews; |
|
35 | + $this->pagination = $this->buildPagination(); |
|
36 | + parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function __toString() |
|
43 | - { |
|
44 | - return glsr(Template::class)->build('templates/reviews', [ |
|
45 | - 'args' => $this->args, |
|
46 | - 'context' => [ |
|
47 | - 'assigned_to' => $this->args['assigned_to'], |
|
48 | - 'category' => $this->args['category'], |
|
49 | - 'class' => $this->getClass(), |
|
50 | - 'id' => $this->args['id'], |
|
51 | - 'pagination' => $this->getPagination(), |
|
52 | - 'reviews' => $this->getReviews(), |
|
53 | - ], |
|
54 | - ]); |
|
55 | - } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function __toString() |
|
43 | + { |
|
44 | + return glsr(Template::class)->build('templates/reviews', [ |
|
45 | + 'args' => $this->args, |
|
46 | + 'context' => [ |
|
47 | + 'assigned_to' => $this->args['assigned_to'], |
|
48 | + 'category' => $this->args['category'], |
|
49 | + 'class' => $this->getClass(), |
|
50 | + 'id' => $this->args['id'], |
|
51 | + 'pagination' => $this->getPagination(), |
|
52 | + 'reviews' => $this->getReviews(), |
|
53 | + ], |
|
54 | + ]); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getPagination() |
|
61 | - { |
|
62 | - return wp_validate_boolean($this->args['pagination']) |
|
63 | - ? $this->pagination |
|
64 | - : ''; |
|
65 | - } |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getPagination() |
|
61 | + { |
|
62 | + return wp_validate_boolean($this->args['pagination']) |
|
63 | + ? $this->pagination |
|
64 | + : ''; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getReviews() |
|
71 | - { |
|
72 | - $html = empty($this->reviews) |
|
73 | - ? $this->getReviewsFallback() |
|
74 | - : implode(PHP_EOL, $this->reviews); |
|
75 | - $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
76 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
77 | - return sprintf($wrapper, $html); |
|
78 | - } |
|
67 | + /** |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getReviews() |
|
71 | + { |
|
72 | + $html = empty($this->reviews) |
|
73 | + ? $this->getReviewsFallback() |
|
74 | + : implode(PHP_EOL, $this->reviews); |
|
75 | + $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
76 | + $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
77 | + return sprintf($wrapper, $html); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param mixed $key |
|
82 | - * @return mixed |
|
83 | - */ |
|
84 | - public function offsetGet($key) |
|
85 | - { |
|
86 | - if ('navigation' == $key) { |
|
87 | - glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
88 | - return $this->pagination; |
|
89 | - } |
|
90 | - if (property_exists($this, $key)) { |
|
91 | - return $this->$key; |
|
92 | - } |
|
93 | - return array_key_exists($key, $this->reviews) |
|
94 | - ? $this->reviews[$key] |
|
95 | - : null; |
|
96 | - } |
|
80 | + /** |
|
81 | + * @param mixed $key |
|
82 | + * @return mixed |
|
83 | + */ |
|
84 | + public function offsetGet($key) |
|
85 | + { |
|
86 | + if ('navigation' == $key) { |
|
87 | + glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
88 | + return $this->pagination; |
|
89 | + } |
|
90 | + if (property_exists($this, $key)) { |
|
91 | + return $this->$key; |
|
92 | + } |
|
93 | + return array_key_exists($key, $this->reviews) |
|
94 | + ? $this->reviews[$key] |
|
95 | + : null; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - protected function buildPagination() |
|
102 | - { |
|
103 | - $html = glsr(Partial::class)->build('pagination', [ |
|
104 | - 'baseUrl' => glsr_get($this->args, 'pagedUrl'), |
|
105 | - 'current' => glsr_get($this->args, 'paged'), |
|
106 | - 'total' => $this->max_num_pages, |
|
107 | - ]); |
|
108 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
109 | - $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
110 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
111 | - return sprintf($wrapper, $html); |
|
112 | - } |
|
98 | + /** |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + protected function buildPagination() |
|
102 | + { |
|
103 | + $html = glsr(Partial::class)->build('pagination', [ |
|
104 | + 'baseUrl' => glsr_get($this->args, 'pagedUrl'), |
|
105 | + 'current' => glsr_get($this->args, 'paged'), |
|
106 | + 'total' => $this->max_num_pages, |
|
107 | + ]); |
|
108 | + $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
109 | + $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
110 | + $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
111 | + return sprintf($wrapper, $html); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - protected function getClass() |
|
118 | - { |
|
119 | - $defaults = [ |
|
120 | - 'glsr-default', |
|
121 | - ]; |
|
122 | - if ('ajax' == $this->args['pagination']) { |
|
123 | - $defaults[] = 'glsr-ajax-pagination'; |
|
124 | - } |
|
125 | - $classes = explode(' ', $this->args['class']); |
|
126 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
127 | - return implode(' ', $classes); |
|
128 | - } |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + protected function getClass() |
|
118 | + { |
|
119 | + $defaults = [ |
|
120 | + 'glsr-default', |
|
121 | + ]; |
|
122 | + if ('ajax' == $this->args['pagination']) { |
|
123 | + $defaults[] = 'glsr-ajax-pagination'; |
|
124 | + } |
|
125 | + $classes = explode(' ', $this->args['class']); |
|
126 | + $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
127 | + return implode(' ', $classes); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - protected function getReviewsFallback() |
|
134 | - { |
|
135 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
136 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
137 | - } |
|
138 | - $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
139 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | - } |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + protected function getReviewsFallback() |
|
134 | + { |
|
135 | + if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
136 | + $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
137 | + } |
|
138 | + $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
139 | + return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | + } |
|
141 | 141 | } |
@@ -10,371 +10,371 @@ |
||
10 | 10 | |
11 | 11 | class System |
12 | 12 | { |
13 | - const PAD = 40; |
|
13 | + const PAD = 40; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function __toString() |
|
19 | - { |
|
20 | - return $this->get(); |
|
21 | - } |
|
15 | + /** |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function __toString() |
|
19 | + { |
|
20 | + return $this->get(); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function get() |
|
27 | - { |
|
28 | - $details = [ |
|
29 | - 'plugin' => 'Plugin Details', |
|
30 | - 'addon' => 'Addon Details', |
|
31 | - 'browser' => 'Browser Details', |
|
32 | - 'server' => 'Server Details', |
|
33 | - 'php' => 'PHP Configuration', |
|
34 | - 'wordpress' => 'WordPress Configuration', |
|
35 | - 'mu-plugin' => 'Must-Use Plugins', |
|
36 | - 'multisite-plugin' => 'Network Active Plugins', |
|
37 | - 'active-plugin' => 'Active Plugins', |
|
38 | - 'inactive-plugin' => 'Inactive Plugins', |
|
39 | - 'setting' => 'Plugin Settings', |
|
40 | - 'reviews' => 'Review Counts', |
|
41 | - ]; |
|
42 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
43 | - $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details'); |
|
44 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
45 | - return $carry.$this->implode( |
|
46 | - strtoupper($details[$key]), |
|
47 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | - ); |
|
49 | - } |
|
50 | - return $carry; |
|
51 | - }); |
|
52 | - return trim($systemInfo); |
|
53 | - } |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function get() |
|
27 | + { |
|
28 | + $details = [ |
|
29 | + 'plugin' => 'Plugin Details', |
|
30 | + 'addon' => 'Addon Details', |
|
31 | + 'browser' => 'Browser Details', |
|
32 | + 'server' => 'Server Details', |
|
33 | + 'php' => 'PHP Configuration', |
|
34 | + 'wordpress' => 'WordPress Configuration', |
|
35 | + 'mu-plugin' => 'Must-Use Plugins', |
|
36 | + 'multisite-plugin' => 'Network Active Plugins', |
|
37 | + 'active-plugin' => 'Active Plugins', |
|
38 | + 'inactive-plugin' => 'Inactive Plugins', |
|
39 | + 'setting' => 'Plugin Settings', |
|
40 | + 'reviews' => 'Review Counts', |
|
41 | + ]; |
|
42 | + $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
43 | + $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details'); |
|
44 | + if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
45 | + return $carry.$this->implode( |
|
46 | + strtoupper($details[$key]), |
|
47 | + apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | + ); |
|
49 | + } |
|
50 | + return $carry; |
|
51 | + }); |
|
52 | + return trim($systemInfo); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getActivePluginDetails() |
|
59 | - { |
|
60 | - $plugins = get_plugins(); |
|
61 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
62 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
63 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
64 | - } |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getActivePluginDetails() |
|
59 | + { |
|
60 | + $plugins = get_plugins(); |
|
61 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
62 | + $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
63 | + return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function getAddonDetails() |
|
70 | - { |
|
71 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
72 | - ksort($details); |
|
73 | - return $details; |
|
74 | - } |
|
66 | + /** |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function getAddonDetails() |
|
70 | + { |
|
71 | + $details = apply_filters('site-reviews/addon/system-info', []); |
|
72 | + ksort($details); |
|
73 | + return $details; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public function getBrowserDetails() |
|
80 | - { |
|
81 | - $browser = new Browser(); |
|
82 | - $name = esc_attr($browser->getName()); |
|
83 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
84 | - $version = esc_attr($browser->getVersion()); |
|
85 | - return [ |
|
86 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
87 | - 'Browser UA' => $userAgent, |
|
88 | - ]; |
|
89 | - } |
|
76 | + /** |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public function getBrowserDetails() |
|
80 | + { |
|
81 | + $browser = new Browser(); |
|
82 | + $name = esc_attr($browser->getName()); |
|
83 | + $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
84 | + $version = esc_attr($browser->getVersion()); |
|
85 | + return [ |
|
86 | + 'Browser Name' => sprintf('%s %s', $name, $version), |
|
87 | + 'Browser UA' => $userAgent, |
|
88 | + ]; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function getInactivePluginDetails() |
|
95 | - { |
|
96 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
97 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | - $multisitePlugins = $this->getMultisitePluginDetails(); |
|
99 | - return empty($multisitePlugins) |
|
100 | - ? $inactivePlugins |
|
101 | - : array_diff($inactivePlugins, $multisitePlugins); |
|
102 | - } |
|
91 | + /** |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function getInactivePluginDetails() |
|
95 | + { |
|
96 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
97 | + $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | + $multisitePlugins = $this->getMultisitePluginDetails(); |
|
99 | + return empty($multisitePlugins) |
|
100 | + ? $inactivePlugins |
|
101 | + : array_diff($inactivePlugins, $multisitePlugins); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - public function getMuPluginDetails() |
|
108 | - { |
|
109 | - if (empty($plugins = get_mu_plugins())) { |
|
110 | - return []; |
|
111 | - } |
|
112 | - return $this->normalizePluginList($plugins); |
|
113 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + public function getMuPluginDetails() |
|
108 | + { |
|
109 | + if (empty($plugins = get_mu_plugins())) { |
|
110 | + return []; |
|
111 | + } |
|
112 | + return $this->normalizePluginList($plugins); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - public function getMultisitePluginDetails() |
|
119 | - { |
|
120 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
121 | - if (!is_multisite() || empty($activePlugins)) { |
|
122 | - return []; |
|
123 | - } |
|
124 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
125 | - } |
|
115 | + /** |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + public function getMultisitePluginDetails() |
|
119 | + { |
|
120 | + $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
121 | + if (!is_multisite() || empty($activePlugins)) { |
|
122 | + return []; |
|
123 | + } |
|
124 | + return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function getPhpDetails() |
|
131 | - { |
|
132 | - $displayErrors = ini_get('display_errors') |
|
133 | - ? 'On ('.ini_get('display_errors').')' |
|
134 | - : 'N/A'; |
|
135 | - $intlSupport = extension_loaded('intl') |
|
136 | - ? phpversion('intl') |
|
137 | - : 'false'; |
|
138 | - return [ |
|
139 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
140 | - 'Default Charset' => ini_get('default_charset'), |
|
141 | - 'Display Errors' => $displayErrors, |
|
142 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
143 | - 'Intl' => $intlSupport, |
|
144 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
145 | - 'Max Execution Time' => ini_get('max_execution_time'), |
|
146 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
147 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
148 | - 'Memory Limit' => ini_get('memory_limit'), |
|
149 | - 'Post Max Size' => ini_get('post_max_size'), |
|
150 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
151 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
152 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
153 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
154 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
155 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
156 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
157 | - ]; |
|
158 | - } |
|
127 | + /** |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function getPhpDetails() |
|
131 | + { |
|
132 | + $displayErrors = ini_get('display_errors') |
|
133 | + ? 'On ('.ini_get('display_errors').')' |
|
134 | + : 'N/A'; |
|
135 | + $intlSupport = extension_loaded('intl') |
|
136 | + ? phpversion('intl') |
|
137 | + : 'false'; |
|
138 | + return [ |
|
139 | + 'cURL' => var_export(function_exists('curl_init'), true), |
|
140 | + 'Default Charset' => ini_get('default_charset'), |
|
141 | + 'Display Errors' => $displayErrors, |
|
142 | + 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
143 | + 'Intl' => $intlSupport, |
|
144 | + 'IPv6' => var_export(defined('AF_INET6'), true), |
|
145 | + 'Max Execution Time' => ini_get('max_execution_time'), |
|
146 | + 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
147 | + 'Max Input Vars' => ini_get('max_input_vars'), |
|
148 | + 'Memory Limit' => ini_get('memory_limit'), |
|
149 | + 'Post Max Size' => ini_get('post_max_size'), |
|
150 | + 'Sendmail Path' => ini_get('sendmail_path'), |
|
151 | + 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
152 | + 'Session Name' => esc_html(ini_get('session.name')), |
|
153 | + 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
154 | + 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
155 | + 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
156 | + 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
157 | + ]; |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function getReviewsDetails() |
|
164 | - { |
|
165 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
166 | - $counts = glsr(Helper::class)->flattenArray($counts); |
|
167 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
168 | - if (!is_array($ratings)) { |
|
169 | - glsr_log() |
|
170 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
171 | - ->debug($ratings) |
|
172 | - ->debug($counts); |
|
173 | - return; |
|
174 | - } |
|
175 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
176 | - }); |
|
177 | - ksort($counts); |
|
178 | - return $counts; |
|
179 | - } |
|
160 | + /** |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function getReviewsDetails() |
|
164 | + { |
|
165 | + $counts = glsr(CountsManager::class)->getCounts(); |
|
166 | + $counts = glsr(Helper::class)->flattenArray($counts); |
|
167 | + array_walk($counts, function (&$ratings) use ($counts) { |
|
168 | + if (!is_array($ratings)) { |
|
169 | + glsr_log() |
|
170 | + ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
171 | + ->debug($ratings) |
|
172 | + ->debug($counts); |
|
173 | + return; |
|
174 | + } |
|
175 | + $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
176 | + }); |
|
177 | + ksort($counts); |
|
178 | + return $counts; |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - public function getServerDetails() |
|
185 | - { |
|
186 | - global $wpdb; |
|
187 | - return [ |
|
188 | - 'Host Name' => $this->getHostName(), |
|
189 | - 'MySQL Version' => $wpdb->db_version(), |
|
190 | - 'PHP Version' => PHP_VERSION, |
|
191 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
192 | - ]; |
|
193 | - } |
|
181 | + /** |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + public function getServerDetails() |
|
185 | + { |
|
186 | + global $wpdb; |
|
187 | + return [ |
|
188 | + 'Host Name' => $this->getHostName(), |
|
189 | + 'MySQL Version' => $wpdb->db_version(), |
|
190 | + 'PHP Version' => PHP_VERSION, |
|
191 | + 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
192 | + ]; |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - public function getSettingDetails() |
|
199 | - { |
|
200 | - $helper = glsr(Helper::class); |
|
201 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
202 | - $settings = $helper->flattenArray($settings, true); |
|
203 | - $settings = $this->purgeSensitiveData($settings); |
|
204 | - ksort($settings); |
|
205 | - $details = []; |
|
206 | - foreach ($settings as $key => $value) { |
|
207 | - if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) { |
|
208 | - continue; |
|
209 | - } |
|
210 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | - $details[$key] = $value; |
|
212 | - } |
|
213 | - return $details; |
|
214 | - } |
|
195 | + /** |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + public function getSettingDetails() |
|
199 | + { |
|
200 | + $helper = glsr(Helper::class); |
|
201 | + $settings = glsr(OptionManager::class)->get('settings', []); |
|
202 | + $settings = $helper->flattenArray($settings, true); |
|
203 | + $settings = $this->purgeSensitiveData($settings); |
|
204 | + ksort($settings); |
|
205 | + $details = []; |
|
206 | + foreach ($settings as $key => $value) { |
|
207 | + if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) { |
|
208 | + continue; |
|
209 | + } |
|
210 | + $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | + $details[$key] = $value; |
|
212 | + } |
|
213 | + return $details; |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * @return array |
|
218 | - */ |
|
219 | - public function getPluginDetails() |
|
220 | - { |
|
221 | - return [ |
|
222 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
223 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
224 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
225 | - 'Version (current)' => glsr()->version, |
|
226 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | - ]; |
|
228 | - } |
|
216 | + /** |
|
217 | + * @return array |
|
218 | + */ |
|
219 | + public function getPluginDetails() |
|
220 | + { |
|
221 | + return [ |
|
222 | + 'Console level' => glsr(Console::class)->humanLevel(), |
|
223 | + 'Console size' => glsr(Console::class)->humanSize('0'), |
|
224 | + 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
225 | + 'Version (current)' => glsr()->version, |
|
226 | + 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | + ]; |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - public function getWordpressDetails() |
|
234 | - { |
|
235 | - global $wpdb; |
|
236 | - $theme = wp_get_theme(); |
|
237 | - return [ |
|
238 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
239 | - 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
240 | - 'Home URL' => home_url(), |
|
241 | - 'Language' => get_locale(), |
|
242 | - 'Memory Limit' => WP_MEMORY_LIMIT, |
|
243 | - 'Multisite' => var_export(is_multisite(), true), |
|
244 | - 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
245 | - 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
246 | - 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
247 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
248 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
249 | - 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
250 | - 'Site URL' => site_url(), |
|
251 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
252 | - 'Version' => get_bloginfo('version'), |
|
253 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
254 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
255 | - 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
256 | - ]; |
|
257 | - } |
|
230 | + /** |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + public function getWordpressDetails() |
|
234 | + { |
|
235 | + global $wpdb; |
|
236 | + $theme = wp_get_theme(); |
|
237 | + return [ |
|
238 | + 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
239 | + 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
240 | + 'Home URL' => home_url(), |
|
241 | + 'Language' => get_locale(), |
|
242 | + 'Memory Limit' => WP_MEMORY_LIMIT, |
|
243 | + 'Multisite' => var_export(is_multisite(), true), |
|
244 | + 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
245 | + 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
246 | + 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
247 | + 'Post Stati' => implode(', ', get_post_stati()), |
|
248 | + 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
249 | + 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
250 | + 'Site URL' => site_url(), |
|
251 | + 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
252 | + 'Version' => get_bloginfo('version'), |
|
253 | + 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
254 | + 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
255 | + 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
256 | + ]; |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - protected function detectWebhostProvider() |
|
263 | - { |
|
264 | - $checks = [ |
|
265 | - '.accountservergroup.com' => 'Site5', |
|
266 | - '.gridserver.com' => 'MediaTemple Grid', |
|
267 | - '.inmotionhosting.com' => 'InMotion Hosting', |
|
268 | - '.ovh.net' => 'OVH', |
|
269 | - '.pair.com' => 'pair Networks', |
|
270 | - '.stabletransit.com' => 'Rackspace Cloud', |
|
271 | - '.stratoserver.net' => 'STRATO', |
|
272 | - '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
273 | - 'bluehost.com' => 'Bluehost', |
|
274 | - 'DH_USER' => 'DreamHost', |
|
275 | - 'Flywheel' => 'Flywheel', |
|
276 | - 'ipagemysql.com' => 'iPage', |
|
277 | - 'ipowermysql.com' => 'IPower', |
|
278 | - 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
279 | - 'mysqlv5' => 'NetworkSolutions', |
|
280 | - 'PAGELYBIN' => 'Pagely', |
|
281 | - 'secureserver.net' => 'GoDaddy', |
|
282 | - 'WPE_APIKEY' => 'WP Engine', |
|
283 | - ]; |
|
284 | - foreach ($checks as $key => $value) { |
|
285 | - if (!$this->isWebhostCheckValid($key)) { |
|
286 | - continue; |
|
287 | - } |
|
288 | - return $value; |
|
289 | - } |
|
290 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | - } |
|
259 | + /** |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + protected function detectWebhostProvider() |
|
263 | + { |
|
264 | + $checks = [ |
|
265 | + '.accountservergroup.com' => 'Site5', |
|
266 | + '.gridserver.com' => 'MediaTemple Grid', |
|
267 | + '.inmotionhosting.com' => 'InMotion Hosting', |
|
268 | + '.ovh.net' => 'OVH', |
|
269 | + '.pair.com' => 'pair Networks', |
|
270 | + '.stabletransit.com' => 'Rackspace Cloud', |
|
271 | + '.stratoserver.net' => 'STRATO', |
|
272 | + '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
273 | + 'bluehost.com' => 'Bluehost', |
|
274 | + 'DH_USER' => 'DreamHost', |
|
275 | + 'Flywheel' => 'Flywheel', |
|
276 | + 'ipagemysql.com' => 'iPage', |
|
277 | + 'ipowermysql.com' => 'IPower', |
|
278 | + 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
279 | + 'mysqlv5' => 'NetworkSolutions', |
|
280 | + 'PAGELYBIN' => 'Pagely', |
|
281 | + 'secureserver.net' => 'GoDaddy', |
|
282 | + 'WPE_APIKEY' => 'WP Engine', |
|
283 | + ]; |
|
284 | + foreach ($checks as $key => $value) { |
|
285 | + if (!$this->isWebhostCheckValid($key)) { |
|
286 | + continue; |
|
287 | + } |
|
288 | + return $value; |
|
289 | + } |
|
290 | + return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - protected function getHostName() |
|
297 | - { |
|
298 | - return sprintf('%s (%s)', |
|
299 | - $this->detectWebhostProvider(), |
|
300 | - glsr(Helper::class)->getIpAddress() |
|
301 | - ); |
|
302 | - } |
|
293 | + /** |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + protected function getHostName() |
|
297 | + { |
|
298 | + return sprintf('%s (%s)', |
|
299 | + $this->detectWebhostProvider(), |
|
300 | + glsr(Helper::class)->getIpAddress() |
|
301 | + ); |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * @return array |
|
306 | - */ |
|
307 | - protected function getWordpressPlugins() |
|
308 | - { |
|
309 | - $plugins = get_plugins(); |
|
310 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
311 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
312 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
313 | - return $active + $inactive; |
|
314 | - } |
|
304 | + /** |
|
305 | + * @return array |
|
306 | + */ |
|
307 | + protected function getWordpressPlugins() |
|
308 | + { |
|
309 | + $plugins = get_plugins(); |
|
310 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
311 | + $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
312 | + $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
313 | + return $active + $inactive; |
|
314 | + } |
|
315 | 315 | |
316 | - /** |
|
317 | - * @param string $title |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - protected function implode($title, array $details) |
|
321 | - { |
|
322 | - $strings = ['['.$title.']']; |
|
323 | - $padding = max(array_map('strlen', array_keys($details))); |
|
324 | - $padding = max([$padding, static::PAD]); |
|
325 | - foreach ($details as $key => $value) { |
|
326 | - $strings[] = is_string($key) |
|
327 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
328 | - : ' - '.$value; |
|
329 | - } |
|
330 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
331 | - } |
|
316 | + /** |
|
317 | + * @param string $title |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + protected function implode($title, array $details) |
|
321 | + { |
|
322 | + $strings = ['['.$title.']']; |
|
323 | + $padding = max(array_map('strlen', array_keys($details))); |
|
324 | + $padding = max([$padding, static::PAD]); |
|
325 | + foreach ($details as $key => $value) { |
|
326 | + $strings[] = is_string($key) |
|
327 | + ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
328 | + : ' - '.$value; |
|
329 | + } |
|
330 | + return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
331 | + } |
|
332 | 332 | |
333 | - /** |
|
334 | - * @param string $key |
|
335 | - * @return bool |
|
336 | - */ |
|
337 | - protected function isWebhostCheckValid($key) |
|
338 | - { |
|
339 | - return defined($key) |
|
340 | - || filter_input(INPUT_SERVER, $key) |
|
341 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
342 | - || false !== strpos(DB_HOST, $key) |
|
343 | - || false !== strpos(php_uname(), $key); |
|
344 | - } |
|
333 | + /** |
|
334 | + * @param string $key |
|
335 | + * @return bool |
|
336 | + */ |
|
337 | + protected function isWebhostCheckValid($key) |
|
338 | + { |
|
339 | + return defined($key) |
|
340 | + || filter_input(INPUT_SERVER, $key) |
|
341 | + || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
342 | + || false !== strpos(DB_HOST, $key) |
|
343 | + || false !== strpos(php_uname(), $key); |
|
344 | + } |
|
345 | 345 | |
346 | - /** |
|
347 | - * @return array |
|
348 | - */ |
|
349 | - protected function normalizePluginList(array $plugins) |
|
350 | - { |
|
351 | - $plugins = array_map(function ($plugin) { |
|
352 | - return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version')); |
|
353 | - }, $plugins); |
|
354 | - natcasesort($plugins); |
|
355 | - return array_flip($plugins); |
|
356 | - } |
|
346 | + /** |
|
347 | + * @return array |
|
348 | + */ |
|
349 | + protected function normalizePluginList(array $plugins) |
|
350 | + { |
|
351 | + $plugins = array_map(function ($plugin) { |
|
352 | + return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version')); |
|
353 | + }, $plugins); |
|
354 | + natcasesort($plugins); |
|
355 | + return array_flip($plugins); |
|
356 | + } |
|
357 | 357 | |
358 | - /** |
|
359 | - * @return array |
|
360 | - */ |
|
361 | - protected function purgeSensitiveData(array $settings) |
|
362 | - { |
|
363 | - $keys = [ |
|
364 | - 'general.rebusify_serial', |
|
365 | - 'licenses.', |
|
366 | - 'submissions.recaptcha.key', |
|
367 | - 'submissions.recaptcha.secret', |
|
368 | - ]; |
|
369 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
370 | - foreach ($keys as $key) { |
|
371 | - if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) { |
|
372 | - continue; |
|
373 | - } |
|
374 | - $value = str_repeat('•', 13); |
|
375 | - return; |
|
376 | - } |
|
377 | - }); |
|
378 | - return $settings; |
|
379 | - } |
|
358 | + /** |
|
359 | + * @return array |
|
360 | + */ |
|
361 | + protected function purgeSensitiveData(array $settings) |
|
362 | + { |
|
363 | + $keys = [ |
|
364 | + 'general.rebusify_serial', |
|
365 | + 'licenses.', |
|
366 | + 'submissions.recaptcha.key', |
|
367 | + 'submissions.recaptcha.secret', |
|
368 | + ]; |
|
369 | + array_walk($settings, function (&$value, $setting) use ($keys) { |
|
370 | + foreach ($keys as $key) { |
|
371 | + if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) { |
|
372 | + continue; |
|
373 | + } |
|
374 | + $value = str_repeat('•', 13); |
|
375 | + return; |
|
376 | + } |
|
377 | + }); |
|
378 | + return $settings; |
|
379 | + } |
|
380 | 380 | } |
@@ -9,143 +9,143 @@ |
||
9 | 9 | |
10 | 10 | class Rebusify |
11 | 11 | { |
12 | - const API_URL = 'https://www.rebusify.com/api/rbs/'; |
|
13 | - const WEB_URL = 'https://rebusify.com/plans?ref=105'; |
|
12 | + const API_URL = 'https://www.rebusify.com/api/rbs/'; |
|
13 | + const WEB_URL = 'https://rebusify.com/plans?ref=105'; |
|
14 | 14 | |
15 | - public $message; |
|
16 | - public $response; |
|
17 | - public $success; |
|
15 | + public $message; |
|
16 | + public $response; |
|
17 | + public $success; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @return mixed |
|
21 | - */ |
|
22 | - public function __get($key) |
|
23 | - { |
|
24 | - return property_exists($this, $key) |
|
25 | - ? $this->$key |
|
26 | - : glsr_get($this->response, $key, null); |
|
27 | - } |
|
19 | + /** |
|
20 | + * @return mixed |
|
21 | + */ |
|
22 | + public function __get($key) |
|
23 | + { |
|
24 | + return property_exists($this, $key) |
|
25 | + ? $this->$key |
|
26 | + : glsr_get($this->response, $key, null); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return self |
|
31 | - */ |
|
32 | - public function activateKey($apiKey = '', $email = '') |
|
33 | - { |
|
34 | - $this->send('api_key_activation.php', [ |
|
35 | - 'body' => [ |
|
36 | - 'apikey' => $apiKey ?: 0, |
|
37 | - 'domain' => get_home_url(), |
|
38 | - 'email' => $email ?: 0, |
|
39 | - ], |
|
40 | - ]); |
|
41 | - return $this; |
|
42 | - } |
|
29 | + /** |
|
30 | + * @return self |
|
31 | + */ |
|
32 | + public function activateKey($apiKey = '', $email = '') |
|
33 | + { |
|
34 | + $this->send('api_key_activation.php', [ |
|
35 | + 'body' => [ |
|
36 | + 'apikey' => $apiKey ?: 0, |
|
37 | + 'domain' => get_home_url(), |
|
38 | + 'email' => $email ?: 0, |
|
39 | + ], |
|
40 | + ]); |
|
41 | + return $this; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return self |
|
46 | - */ |
|
47 | - public function reset() |
|
48 | - { |
|
49 | - $this->message = ''; |
|
50 | - $this->response = []; |
|
51 | - $this->success = false; |
|
52 | - return $this; |
|
53 | - } |
|
44 | + /** |
|
45 | + * @return self |
|
46 | + */ |
|
47 | + public function reset() |
|
48 | + { |
|
49 | + $this->message = ''; |
|
50 | + $this->response = []; |
|
51 | + $this->success = false; |
|
52 | + return $this; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public function sendReview(Review $review) |
|
59 | - { |
|
60 | - $this->send('index.php', [ |
|
61 | - 'body' => $this->getBodyForReview($review), |
|
62 | - 'timeout' => 120, |
|
63 | - ]); |
|
64 | - return $this; |
|
65 | - } |
|
55 | + /** |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public function sendReview(Review $review) |
|
59 | + { |
|
60 | + $this->send('index.php', [ |
|
61 | + 'body' => $this->getBodyForReview($review), |
|
62 | + 'timeout' => 120, |
|
63 | + ]); |
|
64 | + return $this; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return self |
|
69 | - */ |
|
70 | - public function sendReviewResponse(Review $review) |
|
71 | - { |
|
72 | - $this->send('fetch_customer_reply.php', [ |
|
73 | - 'body' => $this->getBodyForResponse($review), |
|
74 | - ]); |
|
75 | - return $this; |
|
76 | - } |
|
67 | + /** |
|
68 | + * @return self |
|
69 | + */ |
|
70 | + public function sendReviewResponse(Review $review) |
|
71 | + { |
|
72 | + $this->send('fetch_customer_reply.php', [ |
|
73 | + 'body' => $this->getBodyForResponse($review), |
|
74 | + ]); |
|
75 | + return $this; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function getBodyForResponse(Review $review) |
|
82 | - { |
|
83 | - $rebusifyResponse = [ |
|
84 | - 'reply' => glsr(Helper::class)->truncate($review->response, 300), |
|
85 | - 'review_id' => glsr(Database::class)->get($review->ID, 'rebusify'), // this is the rebusify review ID |
|
86 | - 'review_transaction_id' => $review->review_id, |
|
87 | - 'type' => 'M', |
|
88 | - ]; |
|
89 | - return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review); |
|
90 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function getBodyForResponse(Review $review) |
|
82 | + { |
|
83 | + $rebusifyResponse = [ |
|
84 | + 'reply' => glsr(Helper::class)->truncate($review->response, 300), |
|
85 | + 'review_id' => glsr(Database::class)->get($review->ID, 'rebusify'), // this is the rebusify review ID |
|
86 | + 'review_transaction_id' => $review->review_id, |
|
87 | + 'type' => 'M', |
|
88 | + ]; |
|
89 | + return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getBodyForReview(Review $review) |
|
96 | - { |
|
97 | - $rebusifyReview = [ |
|
98 | - 'domain' => get_home_url(), |
|
99 | - 'firstname' => glsr(Helper::class)->truncate(glsr(Helper::class)->convertName($review->author, 'first'), 25), |
|
100 | - 'rate' => $review->rating, |
|
101 | - 'review_transaction_id' => $review->review_id, |
|
102 | - 'reviews' => glsr(Helper::class)->truncate($review->content, 280), |
|
103 | - 'title' => glsr(Helper::class)->truncate($review->title, 35), |
|
104 | - 'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews |
|
105 | - ]; |
|
106 | - return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review); |
|
107 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getBodyForReview(Review $review) |
|
96 | + { |
|
97 | + $rebusifyReview = [ |
|
98 | + 'domain' => get_home_url(), |
|
99 | + 'firstname' => glsr(Helper::class)->truncate(glsr(Helper::class)->convertName($review->author, 'first'), 25), |
|
100 | + 'rate' => $review->rating, |
|
101 | + 'review_transaction_id' => $review->review_id, |
|
102 | + 'reviews' => glsr(Helper::class)->truncate($review->content, 280), |
|
103 | + 'title' => glsr(Helper::class)->truncate($review->title, 35), |
|
104 | + 'transaction' => Application::ID, // woocommerce field, not needed for Site Reviews |
|
105 | + ]; |
|
106 | + return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param \WP_Error|array $response |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - protected function handleResponse($response) |
|
114 | - { |
|
115 | - if (is_wp_error($response)) { |
|
116 | - $this->message = $response->get_error_message(); |
|
117 | - } else { |
|
118 | - $responseBody = wp_remote_retrieve_body($response); |
|
119 | - $responseCode = wp_remote_retrieve_response_code($response); |
|
120 | - $responseData = (array) json_decode($responseBody, true); |
|
121 | - $this->response = array_shift($responseData); |
|
122 | - $this->message = glsr_get($this->response, 'msg'); |
|
123 | - $this->success = 'success' === glsr_get($this->response, 'result') || 'yes' === glsr_get($this->response, 'success'); // @todo remove this ugly hack! |
|
124 | - if (200 !== $responseCode) { |
|
125 | - glsr_log()->error('Bad response code ['.$responseCode.']'); |
|
126 | - } |
|
127 | - if (!$this->success) { |
|
128 | - glsr_log()->error($this->message); |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
109 | + /** |
|
110 | + * @param \WP_Error|array $response |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + protected function handleResponse($response) |
|
114 | + { |
|
115 | + if (is_wp_error($response)) { |
|
116 | + $this->message = $response->get_error_message(); |
|
117 | + } else { |
|
118 | + $responseBody = wp_remote_retrieve_body($response); |
|
119 | + $responseCode = wp_remote_retrieve_response_code($response); |
|
120 | + $responseData = (array) json_decode($responseBody, true); |
|
121 | + $this->response = array_shift($responseData); |
|
122 | + $this->message = glsr_get($this->response, 'msg'); |
|
123 | + $this->success = 'success' === glsr_get($this->response, 'result') || 'yes' === glsr_get($this->response, 'success'); // @todo remove this ugly hack! |
|
124 | + if (200 !== $responseCode) { |
|
125 | + glsr_log()->error('Bad response code ['.$responseCode.']'); |
|
126 | + } |
|
127 | + if (!$this->success) { |
|
128 | + glsr_log()->error($this->message); |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * @param string $endpoint |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - protected function send($endpoint, array $args = []) |
|
138 | - { |
|
139 | - $args = wp_parse_args($args, [ |
|
140 | - 'body' => null, |
|
141 | - 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
|
142 | - 'redirection' => 5, |
|
143 | - 'sslverify' => false, |
|
144 | - 'timeout' => 5, |
|
145 | - ]); |
|
146 | - $this->reset(); |
|
147 | - $this->handleResponse( |
|
148 | - wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args) |
|
149 | - ); |
|
150 | - } |
|
133 | + /** |
|
134 | + * @param string $endpoint |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + protected function send($endpoint, array $args = []) |
|
138 | + { |
|
139 | + $args = wp_parse_args($args, [ |
|
140 | + 'body' => null, |
|
141 | + 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
|
142 | + 'redirection' => 5, |
|
143 | + 'sslverify' => false, |
|
144 | + 'timeout' => 5, |
|
145 | + ]); |
|
146 | + $this->reset(); |
|
147 | + $this->handleResponse( |
|
148 | + wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args) |
|
149 | + ); |
|
150 | + } |
|
151 | 151 | } |
@@ -11,385 +11,385 @@ |
||
11 | 11 | |
12 | 12 | class CountsManager |
13 | 13 | { |
14 | - const LIMIT = 500; |
|
15 | - const META_AVERAGE = '_glsr_average'; |
|
16 | - const META_COUNT = '_glsr_count'; |
|
17 | - const META_RANKING = '_glsr_ranking'; |
|
14 | + const LIMIT = 500; |
|
15 | + const META_AVERAGE = '_glsr_average'; |
|
16 | + const META_COUNT = '_glsr_count'; |
|
17 | + const META_RANKING = '_glsr_ranking'; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @return array |
|
21 | - * @todo verify the additional type checks are needed |
|
22 | - */ |
|
23 | - public function buildCounts(array $args = []) |
|
24 | - { |
|
25 | - $counts = []; |
|
26 | - $query = $this->queryReviews($args); |
|
27 | - while ($query) { |
|
28 | - $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type'))); |
|
29 | - $types = array_unique(array_merge(['local'], $types)); |
|
30 | - foreach ($types as $type) { |
|
31 | - $type = $this->normalizeType($type); |
|
32 | - if (isset($counts[$type])) { |
|
33 | - continue; |
|
34 | - } |
|
35 | - $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
36 | - } |
|
37 | - foreach ($query->reviews as $review) { |
|
38 | - $type = $this->normalizeType($review->type); |
|
39 | - ++$counts[$type][$review->rating]; |
|
40 | - } |
|
41 | - $query = $query->has_more |
|
42 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
43 | - : false; |
|
44 | - } |
|
45 | - return $counts; |
|
46 | - } |
|
19 | + /** |
|
20 | + * @return array |
|
21 | + * @todo verify the additional type checks are needed |
|
22 | + */ |
|
23 | + public function buildCounts(array $args = []) |
|
24 | + { |
|
25 | + $counts = []; |
|
26 | + $query = $this->queryReviews($args); |
|
27 | + while ($query) { |
|
28 | + $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type'))); |
|
29 | + $types = array_unique(array_merge(['local'], $types)); |
|
30 | + foreach ($types as $type) { |
|
31 | + $type = $this->normalizeType($type); |
|
32 | + if (isset($counts[$type])) { |
|
33 | + continue; |
|
34 | + } |
|
35 | + $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
36 | + } |
|
37 | + foreach ($query->reviews as $review) { |
|
38 | + $type = $this->normalizeType($review->type); |
|
39 | + ++$counts[$type][$review->rating]; |
|
40 | + } |
|
41 | + $query = $query->has_more |
|
42 | + ? $this->queryReviews($args, end($query->reviews)->ID) |
|
43 | + : false; |
|
44 | + } |
|
45 | + return $counts; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param int $postId |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - public function buildPostCounts($postId) |
|
53 | - { |
|
54 | - return $this->buildCounts(['post_ids' => [$postId]]); |
|
55 | - } |
|
48 | + /** |
|
49 | + * @param int $postId |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + public function buildPostCounts($postId) |
|
53 | + { |
|
54 | + return $this->buildCounts(['post_ids' => [$postId]]); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param int $termTaxonomyId |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public function buildTermCounts($termTaxonomyId) |
|
62 | - { |
|
63 | - return $this->buildCounts(['term_ids' => [$termTaxonomyId]]); |
|
64 | - } |
|
57 | + /** |
|
58 | + * @param int $termTaxonomyId |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public function buildTermCounts($termTaxonomyId) |
|
62 | + { |
|
63 | + return $this->buildCounts(['term_ids' => [$termTaxonomyId]]); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function countAll() |
|
70 | - { |
|
71 | - $terms = glsr(Database::class)->getTerms(['fields' => 'all']); |
|
72 | - foreach ($terms as $term) { |
|
73 | - $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id)); |
|
74 | - } |
|
75 | - $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
76 | - foreach ($postIds as $postId) { |
|
77 | - $this->setPostCounts($postId, $this->buildPostCounts($postId)); |
|
78 | - } |
|
79 | - $this->setCounts($this->buildCounts()); |
|
80 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function countAll() |
|
70 | + { |
|
71 | + $terms = glsr(Database::class)->getTerms(['fields' => 'all']); |
|
72 | + foreach ($terms as $term) { |
|
73 | + $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id)); |
|
74 | + } |
|
75 | + $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
76 | + foreach ($postIds as $postId) { |
|
77 | + $this->setPostCounts($postId, $this->buildPostCounts($postId)); |
|
78 | + } |
|
79 | + $this->setCounts($this->buildCounts()); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return void |
|
84 | - */ |
|
85 | - public function decrease(Review $review) |
|
86 | - { |
|
87 | - $this->decreaseCounts($review); |
|
88 | - $this->decreasePostCounts($review); |
|
89 | - $this->decreaseTermCounts($review); |
|
90 | - } |
|
82 | + /** |
|
83 | + * @return void |
|
84 | + */ |
|
85 | + public function decrease(Review $review) |
|
86 | + { |
|
87 | + $this->decreaseCounts($review); |
|
88 | + $this->decreasePostCounts($review); |
|
89 | + $this->decreaseTermCounts($review); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function decreaseCounts(Review $review) |
|
96 | - { |
|
97 | - $this->setCounts($this->decreaseRating( |
|
98 | - $this->getCounts(), |
|
99 | - $review->review_type, |
|
100 | - $review->rating |
|
101 | - )); |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function decreaseCounts(Review $review) |
|
96 | + { |
|
97 | + $this->setCounts($this->decreaseRating( |
|
98 | + $this->getCounts(), |
|
99 | + $review->review_type, |
|
100 | + $review->rating |
|
101 | + )); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function decreasePostCounts(Review $review) |
|
108 | - { |
|
109 | - if (empty($counts = $this->getPostCounts($review->assigned_to))) { |
|
110 | - return; |
|
111 | - } |
|
112 | - $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
113 | - $this->setPostCounts($review->assigned_to, $counts); |
|
114 | - } |
|
104 | + /** |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function decreasePostCounts(Review $review) |
|
108 | + { |
|
109 | + if (empty($counts = $this->getPostCounts($review->assigned_to))) { |
|
110 | + return; |
|
111 | + } |
|
112 | + $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
113 | + $this->setPostCounts($review->assigned_to, $counts); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public function decreaseTermCounts(Review $review) |
|
120 | - { |
|
121 | - foreach ($review->term_ids as $termId) { |
|
122 | - if (empty($counts = $this->getTermCounts($termId))) { |
|
123 | - continue; |
|
124 | - } |
|
125 | - $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
126 | - $this->setTermCounts($termId, $counts); |
|
127 | - } |
|
128 | - } |
|
116 | + /** |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public function decreaseTermCounts(Review $review) |
|
120 | + { |
|
121 | + foreach ($review->term_ids as $termId) { |
|
122 | + if (empty($counts = $this->getTermCounts($termId))) { |
|
123 | + continue; |
|
124 | + } |
|
125 | + $counts = $this->decreaseRating($counts, $review->review_type, $review->rating); |
|
126 | + $this->setTermCounts($termId, $counts); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @return array |
|
132 | - */ |
|
133 | - public function flatten(array $reviewCounts, array $args = []) |
|
134 | - { |
|
135 | - $counts = []; |
|
136 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
137 | - $counts[$index] = $num + intval(glsr_get($counts, $index, 0)); |
|
138 | - }); |
|
139 | - $args = wp_parse_args($args, [ |
|
140 | - 'max' => glsr()->constant('MAX_RATING', Rating::class), |
|
141 | - 'min' => glsr()->constant('MIN_RATING', Rating::class), |
|
142 | - ]); |
|
143 | - foreach ($counts as $index => &$num) { |
|
144 | - if ($index >= intval($args['min']) && $index <= intval($args['max'])) { |
|
145 | - continue; |
|
146 | - } |
|
147 | - $num = 0; |
|
148 | - } |
|
149 | - return $counts; |
|
150 | - } |
|
130 | + /** |
|
131 | + * @return array |
|
132 | + */ |
|
133 | + public function flatten(array $reviewCounts, array $args = []) |
|
134 | + { |
|
135 | + $counts = []; |
|
136 | + array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
137 | + $counts[$index] = $num + intval(glsr_get($counts, $index, 0)); |
|
138 | + }); |
|
139 | + $args = wp_parse_args($args, [ |
|
140 | + 'max' => glsr()->constant('MAX_RATING', Rating::class), |
|
141 | + 'min' => glsr()->constant('MIN_RATING', Rating::class), |
|
142 | + ]); |
|
143 | + foreach ($counts as $index => &$num) { |
|
144 | + if ($index >= intval($args['min']) && $index <= intval($args['max'])) { |
|
145 | + continue; |
|
146 | + } |
|
147 | + $num = 0; |
|
148 | + } |
|
149 | + return $counts; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - public function get(array $args = []) |
|
156 | - { |
|
157 | - $args = $this->normalizeArgs($args); |
|
158 | - $counts = []; |
|
159 | - if ($this->isMixedCount($args)) { |
|
160 | - $counts = [$this->buildCounts($args)]; // force query the database |
|
161 | - } else { |
|
162 | - foreach ($args['post_ids'] as $postId) { |
|
163 | - $counts[] = $this->getPostCounts($postId); |
|
164 | - } |
|
165 | - foreach ($args['term_ids'] as $termId) { |
|
166 | - $counts[] = $this->getTermCounts($termId); |
|
167 | - } |
|
168 | - if (empty($counts)) { |
|
169 | - $counts[] = $this->getCounts(); |
|
170 | - } |
|
171 | - } |
|
172 | - return in_array($args['type'], ['', 'all']) |
|
173 | - ? $this->normalize([$this->flatten($counts)]) |
|
174 | - : $this->normalize(glsr_array_column($counts, $args['type'])); |
|
175 | - } |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + public function get(array $args = []) |
|
156 | + { |
|
157 | + $args = $this->normalizeArgs($args); |
|
158 | + $counts = []; |
|
159 | + if ($this->isMixedCount($args)) { |
|
160 | + $counts = [$this->buildCounts($args)]; // force query the database |
|
161 | + } else { |
|
162 | + foreach ($args['post_ids'] as $postId) { |
|
163 | + $counts[] = $this->getPostCounts($postId); |
|
164 | + } |
|
165 | + foreach ($args['term_ids'] as $termId) { |
|
166 | + $counts[] = $this->getTermCounts($termId); |
|
167 | + } |
|
168 | + if (empty($counts)) { |
|
169 | + $counts[] = $this->getCounts(); |
|
170 | + } |
|
171 | + } |
|
172 | + return in_array($args['type'], ['', 'all']) |
|
173 | + ? $this->normalize([$this->flatten($counts)]) |
|
174 | + : $this->normalize(glsr_array_column($counts, $args['type'])); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @return array |
|
179 | - */ |
|
180 | - public function getCounts() |
|
181 | - { |
|
182 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
183 | - if (!is_array($counts)) { |
|
184 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
185 | - return []; |
|
186 | - } |
|
187 | - return $counts; |
|
188 | - } |
|
177 | + /** |
|
178 | + * @return array |
|
179 | + */ |
|
180 | + public function getCounts() |
|
181 | + { |
|
182 | + $counts = glsr(OptionManager::class)->get('counts', []); |
|
183 | + if (!is_array($counts)) { |
|
184 | + glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
185 | + return []; |
|
186 | + } |
|
187 | + return $counts; |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * @param int $postId |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - public function getPostCounts($postId) |
|
195 | - { |
|
196 | - return array_filter((array) get_post_meta($postId, static::META_COUNT, true)); |
|
197 | - } |
|
190 | + /** |
|
191 | + * @param int $postId |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + public function getPostCounts($postId) |
|
195 | + { |
|
196 | + return array_filter((array) get_post_meta($postId, static::META_COUNT, true)); |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * @param int $termId |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - public function getTermCounts($termId) |
|
204 | - { |
|
205 | - return array_filter((array) get_term_meta($termId, static::META_COUNT, true)); |
|
206 | - } |
|
199 | + /** |
|
200 | + * @param int $termId |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + public function getTermCounts($termId) |
|
204 | + { |
|
205 | + return array_filter((array) get_term_meta($termId, static::META_COUNT, true)); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function increase(Review $review) |
|
212 | - { |
|
213 | - $this->increaseCounts($review); |
|
214 | - $this->increasePostCounts($review); |
|
215 | - $this->increaseTermCounts($review); |
|
216 | - } |
|
208 | + /** |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function increase(Review $review) |
|
212 | + { |
|
213 | + $this->increaseCounts($review); |
|
214 | + $this->increasePostCounts($review); |
|
215 | + $this->increaseTermCounts($review); |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - public function increaseCounts(Review $review) |
|
222 | - { |
|
223 | - if (empty($counts = $this->getCounts())) { |
|
224 | - $counts = $this->buildCounts(); |
|
225 | - } |
|
226 | - $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating)); |
|
227 | - } |
|
218 | + /** |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + public function increaseCounts(Review $review) |
|
222 | + { |
|
223 | + if (empty($counts = $this->getCounts())) { |
|
224 | + $counts = $this->buildCounts(); |
|
225 | + } |
|
226 | + $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating)); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - public function increasePostCounts(Review $review) |
|
233 | - { |
|
234 | - if (!(get_post($review->assigned_to) instanceof WP_Post)) { |
|
235 | - return; |
|
236 | - } |
|
237 | - $counts = $this->getPostCounts($review->assigned_to); |
|
238 | - $counts = empty($counts) |
|
239 | - ? $this->buildPostCounts($review->assigned_to) |
|
240 | - : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
241 | - $this->setPostCounts($review->assigned_to, $counts); |
|
242 | - } |
|
229 | + /** |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + public function increasePostCounts(Review $review) |
|
233 | + { |
|
234 | + if (!(get_post($review->assigned_to) instanceof WP_Post)) { |
|
235 | + return; |
|
236 | + } |
|
237 | + $counts = $this->getPostCounts($review->assigned_to); |
|
238 | + $counts = empty($counts) |
|
239 | + ? $this->buildPostCounts($review->assigned_to) |
|
240 | + : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
241 | + $this->setPostCounts($review->assigned_to, $counts); |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * @return void |
|
246 | - */ |
|
247 | - public function increaseTermCounts(Review $review) |
|
248 | - { |
|
249 | - $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
250 | - foreach ($terms as $term) { |
|
251 | - $counts = $this->getTermCounts($term['term_id']); |
|
252 | - $counts = empty($counts) |
|
253 | - ? $this->buildTermCounts($term['term_taxonomy_id']) |
|
254 | - : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
255 | - $this->setTermCounts($term['term_id'], $counts); |
|
256 | - } |
|
257 | - } |
|
244 | + /** |
|
245 | + * @return void |
|
246 | + */ |
|
247 | + public function increaseTermCounts(Review $review) |
|
248 | + { |
|
249 | + $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
250 | + foreach ($terms as $term) { |
|
251 | + $counts = $this->getTermCounts($term['term_id']); |
|
252 | + $counts = empty($counts) |
|
253 | + ? $this->buildTermCounts($term['term_taxonomy_id']) |
|
254 | + : $this->increaseRating($counts, $review->review_type, $review->rating); |
|
255 | + $this->setTermCounts($term['term_id'], $counts); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * @return void |
|
261 | - */ |
|
262 | - public function setCounts(array $reviewCounts) |
|
263 | - { |
|
264 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
265 | - } |
|
259 | + /** |
|
260 | + * @return void |
|
261 | + */ |
|
262 | + public function setCounts(array $reviewCounts) |
|
263 | + { |
|
264 | + glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
265 | + } |
|
266 | 266 | |
267 | - /** |
|
268 | - * @param int $postId |
|
269 | - * @return void |
|
270 | - */ |
|
271 | - public function setPostCounts($postId, array $reviewCounts) |
|
272 | - { |
|
273 | - $ratingCounts = $this->flatten($reviewCounts); |
|
274 | - update_post_meta($postId, static::META_COUNT, $reviewCounts); |
|
275 | - update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
276 | - update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
277 | - } |
|
267 | + /** |
|
268 | + * @param int $postId |
|
269 | + * @return void |
|
270 | + */ |
|
271 | + public function setPostCounts($postId, array $reviewCounts) |
|
272 | + { |
|
273 | + $ratingCounts = $this->flatten($reviewCounts); |
|
274 | + update_post_meta($postId, static::META_COUNT, $reviewCounts); |
|
275 | + update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
276 | + update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * @param int $termId |
|
281 | - * @return void |
|
282 | - */ |
|
283 | - public function setTermCounts($termId, array $reviewCounts) |
|
284 | - { |
|
285 | - $term = get_term($termId, Application::TAXONOMY); |
|
286 | - if (!isset($term->term_id)) { |
|
287 | - return; |
|
288 | - } |
|
289 | - $ratingCounts = $this->flatten($reviewCounts); |
|
290 | - update_term_meta($termId, static::META_COUNT, $reviewCounts); |
|
291 | - update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
292 | - update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
293 | - } |
|
279 | + /** |
|
280 | + * @param int $termId |
|
281 | + * @return void |
|
282 | + */ |
|
283 | + public function setTermCounts($termId, array $reviewCounts) |
|
284 | + { |
|
285 | + $term = get_term($termId, Application::TAXONOMY); |
|
286 | + if (!isset($term->term_id)) { |
|
287 | + return; |
|
288 | + } |
|
289 | + $ratingCounts = $this->flatten($reviewCounts); |
|
290 | + update_term_meta($termId, static::META_COUNT, $reviewCounts); |
|
291 | + update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
292 | + update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * @param string $type |
|
297 | - * @param int $rating |
|
298 | - * @return array |
|
299 | - */ |
|
300 | - protected function decreaseRating(array $reviewCounts, $type, $rating) |
|
301 | - { |
|
302 | - if (isset($reviewCounts[$type][$rating])) { |
|
303 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
304 | - } |
|
305 | - return $reviewCounts; |
|
306 | - } |
|
295 | + /** |
|
296 | + * @param string $type |
|
297 | + * @param int $rating |
|
298 | + * @return array |
|
299 | + */ |
|
300 | + protected function decreaseRating(array $reviewCounts, $type, $rating) |
|
301 | + { |
|
302 | + if (isset($reviewCounts[$type][$rating])) { |
|
303 | + $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
304 | + } |
|
305 | + return $reviewCounts; |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * @param string $type |
|
310 | - * @param int $rating |
|
311 | - * @return array |
|
312 | - */ |
|
313 | - protected function increaseRating(array $reviewCounts, $type, $rating) |
|
314 | - { |
|
315 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
316 | - return $reviewCounts; |
|
317 | - } |
|
318 | - if (!array_key_exists($type, $reviewCounts)) { |
|
319 | - $reviewCounts[$type] = []; |
|
320 | - } |
|
321 | - $reviewCounts = $this->normalize($reviewCounts); |
|
322 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
323 | - return $reviewCounts; |
|
324 | - } |
|
308 | + /** |
|
309 | + * @param string $type |
|
310 | + * @param int $rating |
|
311 | + * @return array |
|
312 | + */ |
|
313 | + protected function increaseRating(array $reviewCounts, $type, $rating) |
|
314 | + { |
|
315 | + if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
316 | + return $reviewCounts; |
|
317 | + } |
|
318 | + if (!array_key_exists($type, $reviewCounts)) { |
|
319 | + $reviewCounts[$type] = []; |
|
320 | + } |
|
321 | + $reviewCounts = $this->normalize($reviewCounts); |
|
322 | + $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
323 | + return $reviewCounts; |
|
324 | + } |
|
325 | 325 | |
326 | - /** |
|
327 | - * @return bool |
|
328 | - */ |
|
329 | - protected function isMixedCount(array $args) |
|
330 | - { |
|
331 | - return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
332 | - } |
|
326 | + /** |
|
327 | + * @return bool |
|
328 | + */ |
|
329 | + protected function isMixedCount(array $args) |
|
330 | + { |
|
331 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
332 | + } |
|
333 | 333 | |
334 | - /** |
|
335 | - * @return array |
|
336 | - */ |
|
337 | - protected function normalize(array $reviewCounts) |
|
338 | - { |
|
339 | - if (empty($reviewCounts)) { |
|
340 | - $reviewCounts = [[]]; |
|
341 | - } |
|
342 | - foreach ($reviewCounts as &$counts) { |
|
343 | - foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) { |
|
344 | - if (isset($counts[$index])) { |
|
345 | - continue; |
|
346 | - } |
|
347 | - $counts[$index] = 0; |
|
348 | - } |
|
349 | - ksort($counts); |
|
350 | - } |
|
351 | - return $reviewCounts; |
|
352 | - } |
|
334 | + /** |
|
335 | + * @return array |
|
336 | + */ |
|
337 | + protected function normalize(array $reviewCounts) |
|
338 | + { |
|
339 | + if (empty($reviewCounts)) { |
|
340 | + $reviewCounts = [[]]; |
|
341 | + } |
|
342 | + foreach ($reviewCounts as &$counts) { |
|
343 | + foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) { |
|
344 | + if (isset($counts[$index])) { |
|
345 | + continue; |
|
346 | + } |
|
347 | + $counts[$index] = 0; |
|
348 | + } |
|
349 | + ksort($counts); |
|
350 | + } |
|
351 | + return $reviewCounts; |
|
352 | + } |
|
353 | 353 | |
354 | - /** |
|
355 | - * @return array |
|
356 | - */ |
|
357 | - protected function normalizeArgs(array $args) |
|
358 | - { |
|
359 | - $args = wp_parse_args(array_filter($args), [ |
|
360 | - 'post_ids' => [], |
|
361 | - 'term_ids' => [], |
|
362 | - 'type' => 'local', |
|
363 | - ]); |
|
364 | - $args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']); |
|
365 | - $args['type'] = $this->normalizeType($args['type']); |
|
366 | - return $args; |
|
367 | - } |
|
354 | + /** |
|
355 | + * @return array |
|
356 | + */ |
|
357 | + protected function normalizeArgs(array $args) |
|
358 | + { |
|
359 | + $args = wp_parse_args(array_filter($args), [ |
|
360 | + 'post_ids' => [], |
|
361 | + 'term_ids' => [], |
|
362 | + 'type' => 'local', |
|
363 | + ]); |
|
364 | + $args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']); |
|
365 | + $args['type'] = $this->normalizeType($args['type']); |
|
366 | + return $args; |
|
367 | + } |
|
368 | 368 | |
369 | - /** |
|
370 | - * @param string $type |
|
371 | - * @return string |
|
372 | - */ |
|
373 | - protected function normalizeType($type) |
|
374 | - { |
|
375 | - return empty($type) || !is_string($type) |
|
376 | - ? 'local' |
|
377 | - : $type; |
|
378 | - } |
|
369 | + /** |
|
370 | + * @param string $type |
|
371 | + * @return string |
|
372 | + */ |
|
373 | + protected function normalizeType($type) |
|
374 | + { |
|
375 | + return empty($type) || !is_string($type) |
|
376 | + ? 'local' |
|
377 | + : $type; |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * @param int $lastPostId |
|
382 | - * @return object |
|
383 | - */ |
|
384 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
385 | - { |
|
386 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
387 | - $hasMore = is_array($reviews) |
|
388 | - ? count($reviews) == static::LIMIT |
|
389 | - : false; |
|
390 | - return (object) [ |
|
391 | - 'has_more' => $hasMore, |
|
392 | - 'reviews' => $reviews, |
|
393 | - ]; |
|
394 | - } |
|
380 | + /** |
|
381 | + * @param int $lastPostId |
|
382 | + * @return object |
|
383 | + */ |
|
384 | + protected function queryReviews(array $args = [], $lastPostId = 0) |
|
385 | + { |
|
386 | + $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
387 | + $hasMore = is_array($reviews) |
|
388 | + ? count($reviews) == static::LIMIT |
|
389 | + : false; |
|
390 | + return (object) [ |
|
391 | + 'has_more' => $hasMore, |
|
392 | + 'reviews' => $reviews, |
|
393 | + ]; |
|
394 | + } |
|
395 | 395 | } |
@@ -11,173 +11,173 @@ |
||
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 | - return property_exists($this, $key) |
|
96 | - ? $this->$key |
|
97 | - : glsr_get($this->custom, $key, null); |
|
98 | - } |
|
89 | + /** |
|
90 | + * @param mixed $key |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + public function offsetGet($key) |
|
94 | + { |
|
95 | + return property_exists($this, $key) |
|
96 | + ? $this->$key |
|
97 | + : glsr_get($this->custom, $key, null); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param mixed $key |
|
102 | - * @param mixed $value |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public function offsetSet($key, $value) |
|
106 | - { |
|
107 | - if (property_exists($this, $key)) { |
|
108 | - $this->$key = $value; |
|
109 | - return; |
|
110 | - } |
|
111 | - if (!is_array($this->custom)) { |
|
112 | - $this->custom = array_filter((array) $this->custom); |
|
113 | - } |
|
114 | - $this->custom[$key] = $value; |
|
115 | - } |
|
100 | + /** |
|
101 | + * @param mixed $key |
|
102 | + * @param mixed $value |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public function offsetSet($key, $value) |
|
106 | + { |
|
107 | + if (property_exists($this, $key)) { |
|
108 | + $this->$key = $value; |
|
109 | + return; |
|
110 | + } |
|
111 | + if (!is_array($this->custom)) { |
|
112 | + $this->custom = array_filter((array) $this->custom); |
|
113 | + } |
|
114 | + $this->custom[$key] = $value; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @param mixed $key |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - public function offsetUnset($key) |
|
122 | - { |
|
123 | - $this->offsetSet($key, null); |
|
124 | - } |
|
117 | + /** |
|
118 | + * @param mixed $key |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + public function offsetUnset($key) |
|
122 | + { |
|
123 | + $this->offsetSet($key, null); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public function render() |
|
130 | - { |
|
131 | - echo $this->build(); |
|
132 | - } |
|
126 | + /** |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public function render() |
|
130 | + { |
|
131 | + echo $this->build(); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @return bool |
|
136 | - */ |
|
137 | - protected function isModified(array $properties) |
|
138 | - { |
|
139 | - return $this->date != $properties['date'] |
|
140 | - || $this->content != $properties['content'] |
|
141 | - || $this->title != $properties['title']; |
|
142 | - } |
|
134 | + /** |
|
135 | + * @return bool |
|
136 | + */ |
|
137 | + protected function isModified(array $properties) |
|
138 | + { |
|
139 | + return $this->date != $properties['date'] |
|
140 | + || $this->content != $properties['content'] |
|
141 | + || $this->title != $properties['title']; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - protected function setProperties(WP_Post $post) |
|
148 | - { |
|
149 | - $defaults = [ |
|
150 | - 'author' => __('Anonymous', 'site-reviews'), |
|
151 | - 'date' => '', |
|
152 | - 'review_id' => '', |
|
153 | - 'review_type' => 'local', |
|
154 | - ]; |
|
155 | - $meta = array_filter( |
|
156 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
157 | - 'strlen' |
|
158 | - ); |
|
159 | - $meta = array_merge($defaults, glsr(Helper::class)->unprefixArrayKeys($meta)); |
|
160 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
161 | - $this->modified = $this->isModified($properties); |
|
162 | - array_walk($properties, function ($value, $key) { |
|
163 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
164 | - return; |
|
165 | - } |
|
166 | - $this->$key = maybe_unserialize($value); |
|
167 | - }); |
|
168 | - } |
|
144 | + /** |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + protected function setProperties(WP_Post $post) |
|
148 | + { |
|
149 | + $defaults = [ |
|
150 | + 'author' => __('Anonymous', 'site-reviews'), |
|
151 | + 'date' => '', |
|
152 | + 'review_id' => '', |
|
153 | + 'review_type' => 'local', |
|
154 | + ]; |
|
155 | + $meta = array_filter( |
|
156 | + array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
157 | + 'strlen' |
|
158 | + ); |
|
159 | + $meta = array_merge($defaults, glsr(Helper::class)->unprefixArrayKeys($meta)); |
|
160 | + $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
161 | + $this->modified = $this->isModified($properties); |
|
162 | + array_walk($properties, function ($value, $key) { |
|
163 | + if (!property_exists($this, $key) || isset($this->$key)) { |
|
164 | + return; |
|
165 | + } |
|
166 | + $this->$key = maybe_unserialize($value); |
|
167 | + }); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * @return void |
|
172 | - */ |
|
173 | - protected function setTermIds(WP_Post $post) |
|
174 | - { |
|
175 | - $this->term_ids = []; |
|
176 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
177 | - return; |
|
178 | - } |
|
179 | - foreach ($terms as $term) { |
|
180 | - $this->term_ids[] = $term->term_id; |
|
181 | - } |
|
182 | - } |
|
170 | + /** |
|
171 | + * @return void |
|
172 | + */ |
|
173 | + protected function setTermIds(WP_Post $post) |
|
174 | + { |
|
175 | + $this->term_ids = []; |
|
176 | + if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
177 | + return; |
|
178 | + } |
|
179 | + foreach ($terms as $term) { |
|
180 | + $this->term_ids[] = $term->term_id; |
|
181 | + } |
|
182 | + } |
|
183 | 183 | } |
@@ -11,139 +11,139 @@ |
||
11 | 11 | |
12 | 12 | class ReviewController extends Controller |
13 | 13 | { |
14 | - /** |
|
15 | - * @param int $postId |
|
16 | - * @param array $terms |
|
17 | - * @param array $newTTIds |
|
18 | - * @param string $taxonomy |
|
19 | - * @param bool $append |
|
20 | - * @param array $oldTTIds |
|
21 | - * @return void |
|
22 | - * @action set_object_terms |
|
23 | - */ |
|
24 | - public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
25 | - { |
|
26 | - sort($newTTIds); |
|
27 | - sort($oldTTIds); |
|
28 | - if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
29 | - return; |
|
30 | - } |
|
31 | - $review = glsr_get_review($postId); |
|
32 | - $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
33 | - $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
34 | - $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
35 | - if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
36 | - glsr(CountsManager::class)->decreaseTermCounts($review); |
|
37 | - } |
|
38 | - if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
39 | - glsr(CountsManager::class)->increaseTermCounts($review); |
|
40 | - } |
|
41 | - } |
|
14 | + /** |
|
15 | + * @param int $postId |
|
16 | + * @param array $terms |
|
17 | + * @param array $newTTIds |
|
18 | + * @param string $taxonomy |
|
19 | + * @param bool $append |
|
20 | + * @param array $oldTTIds |
|
21 | + * @return void |
|
22 | + * @action set_object_terms |
|
23 | + */ |
|
24 | + public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
25 | + { |
|
26 | + sort($newTTIds); |
|
27 | + sort($oldTTIds); |
|
28 | + if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
29 | + return; |
|
30 | + } |
|
31 | + $review = glsr_get_review($postId); |
|
32 | + $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
33 | + $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
34 | + $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
35 | + if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
36 | + glsr(CountsManager::class)->decreaseTermCounts($review); |
|
37 | + } |
|
38 | + if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
39 | + glsr(CountsManager::class)->increaseTermCounts($review); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $oldStatus |
|
45 | - * @param string $newStatus |
|
46 | - * @param WP_Post $post |
|
47 | - * @return void |
|
48 | - * @action transition_post_status |
|
49 | - */ |
|
50 | - public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
51 | - { |
|
52 | - if (Application::POST_TYPE != glsr_get($post, 'post_type') || in_array($oldStatus, ['new', $newStatus])) { |
|
53 | - return; |
|
54 | - } |
|
55 | - $review = glsr_get_review($post); |
|
56 | - if ('publish' == $post->post_status) { |
|
57 | - glsr(CountsManager::class)->increase($review); |
|
58 | - } else { |
|
59 | - glsr(CountsManager::class)->decrease($review); |
|
60 | - } |
|
61 | - } |
|
43 | + /** |
|
44 | + * @param string $oldStatus |
|
45 | + * @param string $newStatus |
|
46 | + * @param WP_Post $post |
|
47 | + * @return void |
|
48 | + * @action transition_post_status |
|
49 | + */ |
|
50 | + public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
51 | + { |
|
52 | + if (Application::POST_TYPE != glsr_get($post, 'post_type') || in_array($oldStatus, ['new', $newStatus])) { |
|
53 | + return; |
|
54 | + } |
|
55 | + $review = glsr_get_review($post); |
|
56 | + if ('publish' == $post->post_status) { |
|
57 | + glsr(CountsManager::class)->increase($review); |
|
58 | + } else { |
|
59 | + glsr(CountsManager::class)->decrease($review); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return void |
|
65 | - * @action site-reviews/review/created |
|
66 | - */ |
|
67 | - public function onAfterCreate(Review $review) |
|
68 | - { |
|
69 | - if ('publish' !== $review->status) { |
|
70 | - return; |
|
71 | - } |
|
72 | - glsr(CountsManager::class)->increaseCounts($review); |
|
73 | - glsr(CountsManager::class)->increasePostCounts($review); |
|
74 | - } |
|
63 | + /** |
|
64 | + * @return void |
|
65 | + * @action site-reviews/review/created |
|
66 | + */ |
|
67 | + public function onAfterCreate(Review $review) |
|
68 | + { |
|
69 | + if ('publish' !== $review->status) { |
|
70 | + return; |
|
71 | + } |
|
72 | + glsr(CountsManager::class)->increaseCounts($review); |
|
73 | + glsr(CountsManager::class)->increasePostCounts($review); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param int $postId |
|
78 | - * @return void |
|
79 | - * @action before_delete_post |
|
80 | - */ |
|
81 | - public function onBeforeDelete($postId) |
|
82 | - { |
|
83 | - if (!$this->isReviewPostId($postId)) { |
|
84 | - return; |
|
85 | - } |
|
86 | - $review = glsr_get_review($postId); |
|
87 | - if ('trash' !== $review->status) { // do not run for trashed posts |
|
88 | - glsr(CountsManager::class)->decrease($review); |
|
89 | - } |
|
90 | - } |
|
76 | + /** |
|
77 | + * @param int $postId |
|
78 | + * @return void |
|
79 | + * @action before_delete_post |
|
80 | + */ |
|
81 | + public function onBeforeDelete($postId) |
|
82 | + { |
|
83 | + if (!$this->isReviewPostId($postId)) { |
|
84 | + return; |
|
85 | + } |
|
86 | + $review = glsr_get_review($postId); |
|
87 | + if ('trash' !== $review->status) { // do not run for trashed posts |
|
88 | + glsr(CountsManager::class)->decrease($review); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param int $metaId |
|
94 | - * @param int $postId |
|
95 | - * @param string $metaKey |
|
96 | - * @param mixed $metaValue |
|
97 | - * @return void |
|
98 | - * @action update_postmeta |
|
99 | - */ |
|
100 | - public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
101 | - { |
|
102 | - if (!$this->isReviewPostId($postId)) { |
|
103 | - return; |
|
104 | - } |
|
105 | - $metaKey = glsr(Helper::class)->removePrefix('_', $metaKey); |
|
106 | - if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
107 | - return; |
|
108 | - } |
|
109 | - $review = glsr_get_review($postId); |
|
110 | - if ($review->$metaKey == $metaValue) { |
|
111 | - return; |
|
112 | - } |
|
113 | - $method = glsr(Helper::class)->buildMethodName($metaKey, 'onBeforeChange'); |
|
114 | - call_user_func([$this, $method], $review, $metaValue); |
|
115 | - } |
|
92 | + /** |
|
93 | + * @param int $metaId |
|
94 | + * @param int $postId |
|
95 | + * @param string $metaKey |
|
96 | + * @param mixed $metaValue |
|
97 | + * @return void |
|
98 | + * @action update_postmeta |
|
99 | + */ |
|
100 | + public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
101 | + { |
|
102 | + if (!$this->isReviewPostId($postId)) { |
|
103 | + return; |
|
104 | + } |
|
105 | + $metaKey = glsr(Helper::class)->removePrefix('_', $metaKey); |
|
106 | + if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
107 | + return; |
|
108 | + } |
|
109 | + $review = glsr_get_review($postId); |
|
110 | + if ($review->$metaKey == $metaValue) { |
|
111 | + return; |
|
112 | + } |
|
113 | + $method = glsr(Helper::class)->buildMethodName($metaKey, 'onBeforeChange'); |
|
114 | + call_user_func([$this, $method], $review, $metaValue); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @param string|int $assignedTo |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - public function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
122 | - { |
|
123 | - glsr(CountsManager::class)->decreasePostCounts($review); |
|
124 | - $review->assigned_to = $assignedTo; |
|
125 | - glsr(CountsManager::class)->increasePostCounts($review); |
|
126 | - } |
|
117 | + /** |
|
118 | + * @param string|int $assignedTo |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + public function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
122 | + { |
|
123 | + glsr(CountsManager::class)->decreasePostCounts($review); |
|
124 | + $review->assigned_to = $assignedTo; |
|
125 | + glsr(CountsManager::class)->increasePostCounts($review); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @param string|int $rating |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - public function onBeforeChangeRating(Review $review, $rating) |
|
133 | - { |
|
134 | - glsr(CountsManager::class)->decrease($review); |
|
135 | - $review->rating = $rating; |
|
136 | - glsr(CountsManager::class)->increase($review); |
|
137 | - } |
|
128 | + /** |
|
129 | + * @param string|int $rating |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + public function onBeforeChangeRating(Review $review, $rating) |
|
133 | + { |
|
134 | + glsr(CountsManager::class)->decrease($review); |
|
135 | + $review->rating = $rating; |
|
136 | + glsr(CountsManager::class)->increase($review); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param string $reviewType |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - public function onBeforeChangeReviewType(Review $review, $reviewType) |
|
144 | - { |
|
145 | - glsr(CountsManager::class)->decrease($review); |
|
146 | - $review->review_type = $reviewType; |
|
147 | - glsr(CountsManager::class)->increase($review); |
|
148 | - } |
|
139 | + /** |
|
140 | + * @param string $reviewType |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + public function onBeforeChangeReviewType(Review $review, $reviewType) |
|
144 | + { |
|
145 | + glsr(CountsManager::class)->decrease($review); |
|
146 | + $review->review_type = $reviewType; |
|
147 | + glsr(CountsManager::class)->increase($review); |
|
148 | + } |
|
149 | 149 | } |
@@ -6,140 +6,140 @@ |
||
6 | 6 | |
7 | 7 | class CreateReview |
8 | 8 | { |
9 | - public $ajax_request; |
|
10 | - public $assigned_to; |
|
11 | - public $author; |
|
12 | - public $avatar; |
|
13 | - public $blacklisted; |
|
14 | - public $category; |
|
15 | - public $content; |
|
16 | - public $custom; |
|
17 | - public $date; |
|
18 | - public $email; |
|
19 | - public $form_id; |
|
20 | - public $ip_address; |
|
21 | - public $post_id; |
|
22 | - public $rating; |
|
23 | - public $referer; |
|
24 | - public $request; |
|
25 | - public $response; |
|
26 | - public $terms; |
|
27 | - public $title; |
|
28 | - public $url; |
|
9 | + public $ajax_request; |
|
10 | + public $assigned_to; |
|
11 | + public $author; |
|
12 | + public $avatar; |
|
13 | + public $blacklisted; |
|
14 | + public $category; |
|
15 | + public $content; |
|
16 | + public $custom; |
|
17 | + public $date; |
|
18 | + public $email; |
|
19 | + public $form_id; |
|
20 | + public $ip_address; |
|
21 | + public $post_id; |
|
22 | + public $rating; |
|
23 | + public $referer; |
|
24 | + public $request; |
|
25 | + public $response; |
|
26 | + public $terms; |
|
27 | + public $title; |
|
28 | + public $url; |
|
29 | 29 | |
30 | - public function __construct($input) |
|
31 | - { |
|
32 | - $this->request = $input; |
|
33 | - $this->ajax_request = isset($input['_ajax_request']); |
|
34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | - $this->avatar = $this->getAvatar(); |
|
37 | - $this->blacklisted = isset($input['blacklisted']); |
|
38 | - $this->category = $this->getCategory(); |
|
39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | - $this->custom = $this->getCustom(); |
|
41 | - $this->date = $this->getDate('date'); |
|
42 | - $this->email = sanitize_email($this->getUser('email')); |
|
43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | - $this->ip_address = $this->get('ip_address'); |
|
45 | - $this->post_id = intval($this->get('_post_id')); |
|
46 | - $this->rating = intval($this->get('rating')); |
|
47 | - $this->referer = $this->get('_referer'); |
|
48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | - $this->terms = !empty($input['terms']); |
|
50 | - $this->title = sanitize_text_field($this->get('title')); |
|
51 | - $this->url = esc_url_raw($this->get('url')); |
|
52 | - } |
|
30 | + public function __construct($input) |
|
31 | + { |
|
32 | + $this->request = $input; |
|
33 | + $this->ajax_request = isset($input['_ajax_request']); |
|
34 | + $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | + $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | + $this->avatar = $this->getAvatar(); |
|
37 | + $this->blacklisted = isset($input['blacklisted']); |
|
38 | + $this->category = $this->getCategory(); |
|
39 | + $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | + $this->custom = $this->getCustom(); |
|
41 | + $this->date = $this->getDate('date'); |
|
42 | + $this->email = sanitize_email($this->getUser('email')); |
|
43 | + $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | + $this->ip_address = $this->get('ip_address'); |
|
45 | + $this->post_id = intval($this->get('_post_id')); |
|
46 | + $this->rating = intval($this->get('rating')); |
|
47 | + $this->referer = $this->get('_referer'); |
|
48 | + $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | + $this->terms = !empty($input['terms']); |
|
50 | + $this->title = sanitize_text_field($this->get('title')); |
|
51 | + $this->url = esc_url_raw($this->get('url')); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $key |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected function get($key) |
|
59 | - { |
|
60 | - return (string) glsr_get($this->request, $key); |
|
61 | - } |
|
54 | + /** |
|
55 | + * @param string $key |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected function get($key) |
|
59 | + { |
|
60 | + return (string) glsr_get($this->request, $key); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - protected function getAvatar() |
|
67 | - { |
|
68 | - $avatar = $this->get('avatar'); |
|
69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | - ? (string) get_avatar_url($this->get('email')) |
|
71 | - : $avatar; |
|
72 | - } |
|
63 | + /** |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + protected function getAvatar() |
|
67 | + { |
|
68 | + $avatar = $this->get('avatar'); |
|
69 | + return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | + ? (string) get_avatar_url($this->get('email')) |
|
71 | + : $avatar; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - protected function getCategory() |
|
78 | - { |
|
79 | - $categories = glsr(Helper::class)->convertStringToArray($this->get('category')); |
|
80 | - return sanitize_key(glsr_get($categories, 0)); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + protected function getCategory() |
|
78 | + { |
|
79 | + $categories = glsr(Helper::class)->convertStringToArray($this->get('category')); |
|
80 | + return sanitize_key(glsr_get($categories, 0)); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function getCustom() |
|
87 | - { |
|
88 | - $unset = [ |
|
89 | - '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | - '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | - 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | - ]; |
|
93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | - $custom = $this->request; |
|
95 | - foreach ($unset as $value) { |
|
96 | - unset($custom[$value]); |
|
97 | - } |
|
98 | - return $custom; |
|
99 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function getCustom() |
|
87 | + { |
|
88 | + $unset = [ |
|
89 | + '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | + '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | + 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | + ]; |
|
93 | + $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | + $custom = $this->request; |
|
95 | + foreach ($unset as $value) { |
|
96 | + unset($custom[$value]); |
|
97 | + } |
|
98 | + return $custom; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param string $key |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - protected function getDate($key) |
|
106 | - { |
|
107 | - $date = strtotime($this->get($key)); |
|
108 | - if (false === $date) { |
|
109 | - $date = time(); |
|
110 | - } |
|
111 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
112 | - } |
|
101 | + /** |
|
102 | + * @param string $key |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + protected function getDate($key) |
|
106 | + { |
|
107 | + $date = strtotime($this->get($key)); |
|
108 | + if (false === $date) { |
|
109 | + $date = time(); |
|
110 | + } |
|
111 | + return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @param string $key |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function getUser($key) |
|
119 | - { |
|
120 | - $value = $this->get($key); |
|
121 | - if (empty($value)) { |
|
122 | - $user = wp_get_current_user(); |
|
123 | - $userValues = [ |
|
124 | - 'email' => 'user_email', |
|
125 | - 'name' => 'display_name', |
|
126 | - ]; |
|
127 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
128 | - return $user->{$userValues[$key]}; |
|
129 | - } |
|
130 | - } |
|
131 | - return $value; |
|
132 | - } |
|
114 | + /** |
|
115 | + * @param string $key |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function getUser($key) |
|
119 | + { |
|
120 | + $value = $this->get($key); |
|
121 | + if (empty($value)) { |
|
122 | + $user = wp_get_current_user(); |
|
123 | + $userValues = [ |
|
124 | + 'email' => 'user_email', |
|
125 | + 'name' => 'display_name', |
|
126 | + ]; |
|
127 | + if ($user->exists() && array_key_exists($key, $userValues)) { |
|
128 | + return $user->{$userValues[$key]}; |
|
129 | + } |
|
130 | + } |
|
131 | + return $value; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @param string $key |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - protected function getNumeric($key) |
|
139 | - { |
|
140 | - $value = $this->get($key); |
|
141 | - return is_numeric($value) |
|
142 | - ? $value |
|
143 | - : ''; |
|
144 | - } |
|
134 | + /** |
|
135 | + * @param string $key |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + protected function getNumeric($key) |
|
139 | + { |
|
140 | + $value = $this->get($key); |
|
141 | + return is_numeric($value) |
|
142 | + ? $value |
|
143 | + : ''; |
|
144 | + } |
|
145 | 145 | } |