@@ -7,115 +7,115 @@ |
||
7 | 7 | |
8 | 8 | class SiteReviewsFormBlock extends BlockGenerator |
9 | 9 | { |
10 | - /** |
|
11 | - * @return array |
|
12 | - */ |
|
13 | - public function attributes() |
|
14 | - { |
|
15 | - return [ |
|
16 | - 'assign_to' => [ |
|
17 | - 'default' => '', |
|
18 | - 'type' => 'string', |
|
19 | - ], |
|
20 | - 'category' => [ |
|
21 | - 'default' => '', |
|
22 | - 'type' => 'string', |
|
23 | - ], |
|
24 | - 'className' => [ |
|
25 | - 'default' => '', |
|
26 | - 'type' => 'string', |
|
27 | - ], |
|
28 | - 'hide' => [ |
|
29 | - 'default' => '', |
|
30 | - 'type' => 'string', |
|
31 | - ], |
|
32 | - 'id' => [ |
|
33 | - 'default' => '', |
|
34 | - 'type' => 'string', |
|
35 | - ], |
|
36 | - ]; |
|
37 | - } |
|
10 | + /** |
|
11 | + * @return array |
|
12 | + */ |
|
13 | + public function attributes() |
|
14 | + { |
|
15 | + return [ |
|
16 | + 'assign_to' => [ |
|
17 | + 'default' => '', |
|
18 | + 'type' => 'string', |
|
19 | + ], |
|
20 | + 'category' => [ |
|
21 | + 'default' => '', |
|
22 | + 'type' => 'string', |
|
23 | + ], |
|
24 | + 'className' => [ |
|
25 | + 'default' => '', |
|
26 | + 'type' => 'string', |
|
27 | + ], |
|
28 | + 'hide' => [ |
|
29 | + 'default' => '', |
|
30 | + 'type' => 'string', |
|
31 | + ], |
|
32 | + 'id' => [ |
|
33 | + 'default' => '', |
|
34 | + 'type' => 'string', |
|
35 | + ], |
|
36 | + ]; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function render(array $attributes) |
|
43 | - { |
|
44 | - $attributes['class'] = $attributes['className']; |
|
45 | - $shortcode = glsr(Shortcode::class); |
|
46 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
47 | - $this->filterFormFields(); |
|
48 | - $this->filterRatingField(); |
|
49 | - $this->filterShortcodeClass(); |
|
50 | - $this->filterSubmitButton(); |
|
51 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
52 | - $this->filterInterpolation(); |
|
53 | - } |
|
54 | - } |
|
55 | - return $shortcode->buildShortcode($attributes); |
|
56 | - } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function render(array $attributes) |
|
43 | + { |
|
44 | + $attributes['class'] = $attributes['className']; |
|
45 | + $shortcode = glsr(Shortcode::class); |
|
46 | + if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
47 | + $this->filterFormFields(); |
|
48 | + $this->filterRatingField(); |
|
49 | + $this->filterShortcodeClass(); |
|
50 | + $this->filterSubmitButton(); |
|
51 | + if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
52 | + $this->filterInterpolation(); |
|
53 | + } |
|
54 | + } |
|
55 | + return $shortcode->buildShortcode($attributes); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - protected function filterFormFields() |
|
62 | - { |
|
63 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | - array_walk($config, function (&$field) { |
|
65 | - $field['disabled'] = true; |
|
66 | - $field['tabindex'] = '-1'; |
|
67 | - }); |
|
68 | - return $config; |
|
69 | - }); |
|
70 | - } |
|
58 | + /** |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + protected function filterFormFields() |
|
62 | + { |
|
63 | + add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | + array_walk($config, function (&$field) { |
|
65 | + $field['disabled'] = true; |
|
66 | + $field['tabindex'] = '-1'; |
|
67 | + }); |
|
68 | + return $config; |
|
69 | + }); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - protected function filterInterpolation() |
|
76 | - { |
|
77 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
78 | - $context['class'] = 'glsr-default glsr-block-disabled'; |
|
79 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
80 | - $context['response'] = ''; |
|
81 | - $context['submit_button'] = ''; |
|
82 | - return $context; |
|
83 | - }); |
|
84 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + protected function filterInterpolation() |
|
76 | + { |
|
77 | + add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
78 | + $context['class'] = 'glsr-default glsr-block-disabled'; |
|
79 | + $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
80 | + $context['response'] = ''; |
|
81 | + $context['submit_button'] = ''; |
|
82 | + return $context; |
|
83 | + }); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - protected function filterRatingField() |
|
90 | - { |
|
91 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | - if ('rating' == $args['path']) { |
|
93 | - $stars = '<span class="glsr-stars">'; |
|
94 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | - $stars.= '</span>'; |
|
96 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
97 | - } |
|
98 | - return $html; |
|
99 | - }, 10, 3); |
|
100 | - } |
|
86 | + /** |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + protected function filterRatingField() |
|
90 | + { |
|
91 | + add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | + if ('rating' == $args['path']) { |
|
93 | + $stars = '<span class="glsr-stars">'; |
|
94 | + $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | + $stars.= '</span>'; |
|
96 | + $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
97 | + } |
|
98 | + return $html; |
|
99 | + }, 10, 3); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - protected function filterShortcodeClass() |
|
106 | - { |
|
107 | - add_filter('site-reviews/style', function () { |
|
108 | - return 'default'; |
|
109 | - }); |
|
110 | - } |
|
102 | + /** |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + protected function filterShortcodeClass() |
|
106 | + { |
|
107 | + add_filter('site-reviews/style', function () { |
|
108 | + return 'default'; |
|
109 | + }); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - protected function filterSubmitButton() |
|
116 | - { |
|
117 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
119 | - }); |
|
120 | - } |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + protected function filterSubmitButton() |
|
116 | + { |
|
117 | + add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | + return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
119 | + }); |
|
120 | + } |
|
121 | 121 | } |
@@ -39,20 +39,20 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @return string |
41 | 41 | */ |
42 | - public function render(array $attributes) |
|
42 | + public function render( array $attributes ) |
|
43 | 43 | { |
44 | 44 | $attributes['class'] = $attributes['className']; |
45 | - $shortcode = glsr(Shortcode::class); |
|
46 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
45 | + $shortcode = glsr( Shortcode::class ); |
|
46 | + if( 'edit' == filter_input( INPUT_GET, 'context' ) ) { |
|
47 | 47 | $this->filterFormFields(); |
48 | 48 | $this->filterRatingField(); |
49 | 49 | $this->filterShortcodeClass(); |
50 | 50 | $this->filterSubmitButton(); |
51 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
51 | + if( !$this->hasVisibleFields( $shortcode, $attributes ) ) { |
|
52 | 52 | $this->filterInterpolation(); |
53 | 53 | } |
54 | 54 | } |
55 | - return $shortcode->buildShortcode($attributes); |
|
55 | + return $shortcode->buildShortcode( $attributes ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | */ |
61 | 61 | protected function filterFormFields() |
62 | 62 | { |
63 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | - array_walk($config, function (&$field) { |
|
63 | + add_filter( 'site-reviews/config/forms/submission-form', function( array $config ) { |
|
64 | + array_walk( $config, function( &$field ) { |
|
65 | 65 | $field['disabled'] = true; |
66 | 66 | $field['tabindex'] = '-1'; |
67 | 67 | }); |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function filterInterpolation() |
76 | 76 | { |
77 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
77 | + add_filter( 'site-reviews/interpolate/reviews-form', function( $context ) { |
|
78 | 78 | $context['class'] = 'glsr-default glsr-block-disabled'; |
79 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
79 | + $context['fields'] = __( 'You have hidden all of the fields for this block.', 'site-reviews' ); |
|
80 | 80 | $context['response'] = ''; |
81 | 81 | $context['submit_button'] = ''; |
82 | 82 | return $context; |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function filterRatingField() |
90 | 90 | { |
91 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | - if ('rating' == $args['path']) { |
|
91 | + add_filter( 'site-reviews/rendered/field', function( $html, $type, $args ) { |
|
92 | + if( 'rating' == $args['path'] ) { |
|
93 | 93 | $stars = '<span class="glsr-stars">'; |
94 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | - $stars.= '</span>'; |
|
96 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html); |
|
94 | + $stars .= str_repeat( '<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int)glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
95 | + $stars .= '</span>'; |
|
96 | + $html = preg_replace( '/(.*)(<select.*)(<\/select>)(.*)/', '$1'.$stars.'$4', $html ); |
|
97 | 97 | } |
98 | 98 | return $html; |
99 | - }, 10, 3); |
|
99 | + }, 10, 3 ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function filterShortcodeClass() |
106 | 106 | { |
107 | - add_filter('site-reviews/style', function () { |
|
107 | + add_filter( 'site-reviews/style', function() { |
|
108 | 108 | return 'default'; |
109 | 109 | }); |
110 | 110 | } |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function filterSubmitButton() |
116 | 116 | { |
117 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
117 | + add_filter( 'site-reviews/rendered/template/form/submit-button', function( $template ) { |
|
118 | + return str_replace( 'type="submit"', 'tabindex="-1"', $template ); |
|
119 | 119 | }); |
120 | 120 | } |
121 | 121 | } |
@@ -16,204 +16,204 @@ |
||
16 | 16 | |
17 | 17 | class ReviewManager |
18 | 18 | { |
19 | - /** |
|
20 | - * @return false|Review |
|
21 | - */ |
|
22 | - public function create(CreateReview $command) |
|
23 | - { |
|
24 | - $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | - $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | - $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
27 | - unset($reviewValues['json']); // @todo remove the need for this |
|
28 | - $postValues = [ |
|
29 | - 'comment_status' => 'closed', |
|
30 | - 'meta_input' => $reviewValues, |
|
31 | - 'ping_status' => 'closed', |
|
32 | - 'post_content' => $reviewValues['_content'], |
|
33 | - 'post_date' => $reviewValues['_date'], |
|
34 | - 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
35 | - 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
|
36 | - 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
37 | - 'post_title' => $reviewValues['_title'], |
|
38 | - 'post_type' => Application::POST_TYPE, |
|
39 | - ]; |
|
40 | - $postId = wp_insert_post($postValues, true); |
|
41 | - if (is_wp_error($postId)) { |
|
42 | - glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
43 | - return false; |
|
44 | - } |
|
45 | - $this->setTerms($postId, $command->category); |
|
46 | - $review = $this->single(get_post($postId)); |
|
47 | - do_action('site-reviews/review/created', $review, $command); |
|
48 | - return $review; |
|
49 | - } |
|
19 | + /** |
|
20 | + * @return false|Review |
|
21 | + */ |
|
22 | + public function create(CreateReview $command) |
|
23 | + { |
|
24 | + $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | + $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | + $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
27 | + unset($reviewValues['json']); // @todo remove the need for this |
|
28 | + $postValues = [ |
|
29 | + 'comment_status' => 'closed', |
|
30 | + 'meta_input' => $reviewValues, |
|
31 | + 'ping_status' => 'closed', |
|
32 | + 'post_content' => $reviewValues['_content'], |
|
33 | + 'post_date' => $reviewValues['_date'], |
|
34 | + 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
35 | + 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
|
36 | + 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
37 | + 'post_title' => $reviewValues['_title'], |
|
38 | + 'post_type' => Application::POST_TYPE, |
|
39 | + ]; |
|
40 | + $postId = wp_insert_post($postValues, true); |
|
41 | + if (is_wp_error($postId)) { |
|
42 | + glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
43 | + return false; |
|
44 | + } |
|
45 | + $this->setTerms($postId, $command->category); |
|
46 | + $review = $this->single(get_post($postId)); |
|
47 | + do_action('site-reviews/review/created', $review, $command); |
|
48 | + return $review; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $metaReviewId |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function delete($metaReviewId) |
|
56 | - { |
|
57 | - if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | - wp_delete_post($postId, true); |
|
59 | - } |
|
60 | - } |
|
51 | + /** |
|
52 | + * @param string $metaReviewId |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function delete($metaReviewId) |
|
56 | + { |
|
57 | + if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | + wp_delete_post($postId, true); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return object |
|
64 | - */ |
|
65 | - public function get(array $args = []) |
|
66 | - { |
|
67 | - $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | - $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
69 | - ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
|
70 | - $args |
|
71 | - ); |
|
72 | - $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
73 | - ['category'], |
|
74 | - ['category' => $this->normalizeTermIds($args['category'])] |
|
75 | - ); |
|
76 | - $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | - wp_validate_boolean($args['pagination']) |
|
78 | - ); |
|
79 | - $parameters = [ |
|
80 | - 'meta_key' => '_pinned', |
|
81 | - 'meta_query' => $metaQuery, |
|
82 | - 'offset' => $args['offset'], |
|
83 | - 'order' => $args['order'], |
|
84 | - 'orderby' => 'meta_value '.$args['orderby'], |
|
85 | - 'paged' => Arr::get($args, 'paged', $paged), |
|
86 | - 'post__in' => $args['post__in'], |
|
87 | - 'post__not_in' => $args['post__not_in'], |
|
88 | - 'post_status' => 'publish', |
|
89 | - 'post_type' => Application::POST_TYPE, |
|
90 | - 'posts_per_page' => $args['per_page'], |
|
91 | - 'tax_query' => $taxQuery, |
|
92 | - ]; |
|
93 | - $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | - $query = new WP_Query($parameters); |
|
95 | - $results = array_map([$this, 'single'], $query->posts); |
|
96 | - $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | - return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
98 | - } |
|
62 | + /** |
|
63 | + * @return object |
|
64 | + */ |
|
65 | + public function get(array $args = []) |
|
66 | + { |
|
67 | + $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | + $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
69 | + ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
|
70 | + $args |
|
71 | + ); |
|
72 | + $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
73 | + ['category'], |
|
74 | + ['category' => $this->normalizeTermIds($args['category'])] |
|
75 | + ); |
|
76 | + $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | + wp_validate_boolean($args['pagination']) |
|
78 | + ); |
|
79 | + $parameters = [ |
|
80 | + 'meta_key' => '_pinned', |
|
81 | + 'meta_query' => $metaQuery, |
|
82 | + 'offset' => $args['offset'], |
|
83 | + 'order' => $args['order'], |
|
84 | + 'orderby' => 'meta_value '.$args['orderby'], |
|
85 | + 'paged' => Arr::get($args, 'paged', $paged), |
|
86 | + 'post__in' => $args['post__in'], |
|
87 | + 'post__not_in' => $args['post__not_in'], |
|
88 | + 'post_status' => 'publish', |
|
89 | + 'post_type' => Application::POST_TYPE, |
|
90 | + 'posts_per_page' => $args['per_page'], |
|
91 | + 'tax_query' => $taxQuery, |
|
92 | + ]; |
|
93 | + $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | + $query = new WP_Query($parameters); |
|
95 | + $results = array_map([$this, 'single'], $query->posts); |
|
96 | + $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | + return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param string $metaReviewId |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - public function getPostId($metaReviewId) |
|
105 | - { |
|
106 | - return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
107 | - } |
|
100 | + /** |
|
101 | + * @param string $metaReviewId |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + public function getPostId($metaReviewId) |
|
105 | + { |
|
106 | + return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getRatingCounts(array $args = []) |
|
113 | - { |
|
114 | - $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | - $counts = glsr(CountsManager::class)->getCounts([ |
|
116 | - 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | - 'term_ids' => $this->normalizeTermIds($args['category']), |
|
118 | - 'type' => $args['type'], |
|
119 | - ]); |
|
120 | - return glsr(CountsManager::class)->flatten($counts, [ |
|
121 | - 'min' => $args['rating'], |
|
122 | - ]); |
|
123 | - } |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getRatingCounts(array $args = []) |
|
113 | + { |
|
114 | + $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | + $counts = glsr(CountsManager::class)->getCounts([ |
|
116 | + 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | + 'term_ids' => $this->normalizeTermIds($args['category']), |
|
118 | + 'type' => $args['type'], |
|
119 | + ]); |
|
120 | + return glsr(CountsManager::class)->flatten($counts, [ |
|
121 | + 'min' => $args['rating'], |
|
122 | + ]); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $commaSeparatedTermIds |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function normalizeTermIds($commaSeparatedTermIds) |
|
130 | - { |
|
131 | - $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | - return array_unique(array_map('intval', $termIds)); |
|
133 | - } |
|
125 | + /** |
|
126 | + * @param string $commaSeparatedTermIds |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function normalizeTermIds($commaSeparatedTermIds) |
|
130 | + { |
|
131 | + $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | + return array_unique(array_map('intval', $termIds)); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param string $commaSeparatedTermIds |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function normalizeTerms($commaSeparatedTermIds) |
|
140 | - { |
|
141 | - $terms = []; |
|
142 | - $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | - foreach ($termIds as $termId) { |
|
144 | - if (is_numeric($termId)) { |
|
145 | - $termId = intval($termId); |
|
146 | - } |
|
147 | - $term = term_exists($termId, Application::TAXONOMY); |
|
148 | - if (!isset($term['term_id'])) { |
|
149 | - continue; |
|
150 | - } |
|
151 | - $terms[] = $term; |
|
152 | - } |
|
153 | - return $terms; |
|
154 | - } |
|
135 | + /** |
|
136 | + * @param string $commaSeparatedTermIds |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function normalizeTerms($commaSeparatedTermIds) |
|
140 | + { |
|
141 | + $terms = []; |
|
142 | + $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | + foreach ($termIds as $termId) { |
|
144 | + if (is_numeric($termId)) { |
|
145 | + $termId = intval($termId); |
|
146 | + } |
|
147 | + $term = term_exists($termId, Application::TAXONOMY); |
|
148 | + if (!isset($term['term_id'])) { |
|
149 | + continue; |
|
150 | + } |
|
151 | + $terms[] = $term; |
|
152 | + } |
|
153 | + return $terms; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @param int $postId |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function revert($postId) |
|
161 | - { |
|
162 | - if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
163 | - return; |
|
164 | - } |
|
165 | - delete_post_meta($postId, '_edit_last'); |
|
166 | - $result = wp_update_post([ |
|
167 | - 'ID' => $postId, |
|
168 | - 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | - 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | - 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | - ]); |
|
172 | - if (is_wp_error($result)) { |
|
173 | - glsr_log()->error($result->get_error_message()); |
|
174 | - return; |
|
175 | - } |
|
176 | - do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
177 | - } |
|
156 | + /** |
|
157 | + * @param int $postId |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function revert($postId) |
|
161 | + { |
|
162 | + if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
163 | + return; |
|
164 | + } |
|
165 | + delete_post_meta($postId, '_edit_last'); |
|
166 | + $result = wp_update_post([ |
|
167 | + 'ID' => $postId, |
|
168 | + 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | + 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | + 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | + ]); |
|
172 | + if (is_wp_error($result)) { |
|
173 | + glsr_log()->error($result->get_error_message()); |
|
174 | + return; |
|
175 | + } |
|
176 | + do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * @return Review |
|
181 | - */ |
|
182 | - public function single(WP_Post $post) |
|
183 | - { |
|
184 | - if (Application::POST_TYPE != $post->post_type) { |
|
185 | - $post = new WP_Post((object) []); |
|
186 | - } |
|
187 | - $review = new Review($post); |
|
188 | - return apply_filters('site-reviews/get/review', $review, $post); |
|
189 | - } |
|
179 | + /** |
|
180 | + * @return Review |
|
181 | + */ |
|
182 | + public function single(WP_Post $post) |
|
183 | + { |
|
184 | + if (Application::POST_TYPE != $post->post_type) { |
|
185 | + $post = new WP_Post((object) []); |
|
186 | + } |
|
187 | + $review = new Review($post); |
|
188 | + return apply_filters('site-reviews/get/review', $review, $post); |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * @param bool $isBlacklisted |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
196 | - { |
|
197 | - $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
198 | - return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
|
199 | - ? 'pending' |
|
200 | - : 'publish'; |
|
201 | - } |
|
191 | + /** |
|
192 | + * @param bool $isBlacklisted |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
196 | + { |
|
197 | + $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
198 | + return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
|
199 | + ? 'pending' |
|
200 | + : 'publish'; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @param int $postId |
|
205 | - * @param string $termIds |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - protected function setTerms($postId, $termIds) |
|
209 | - { |
|
210 | - $termIds = $this->normalizeTermIds($termIds); |
|
211 | - if (empty($termIds)) { |
|
212 | - return; |
|
213 | - } |
|
214 | - $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | - if (is_wp_error($termTaxonomyIds)) { |
|
216 | - glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
217 | - } |
|
218 | - } |
|
203 | + /** |
|
204 | + * @param int $postId |
|
205 | + * @param string $termIds |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + protected function setTerms($postId, $termIds) |
|
209 | + { |
|
210 | + $termIds = $this->normalizeTermIds($termIds); |
|
211 | + if (empty($termIds)) { |
|
212 | + return; |
|
213 | + } |
|
214 | + $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | + if (is_wp_error($termTaxonomyIds)) { |
|
216 | + glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
217 | + } |
|
218 | + } |
|
219 | 219 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @return false|Review |
21 | 21 | */ |
22 | - public function create(CreateReview $command) |
|
22 | + public function create( CreateReview $command ) |
|
23 | 23 | { |
24 | - $reviewValues = glsr(CreateReviewDefaults::class)->restrict((array) $command); |
|
25 | - $reviewValues = apply_filters('site-reviews/create/review-values', $reviewValues, $command); |
|
26 | - $reviewValues = Arr::prefixArrayKeys($reviewValues); |
|
24 | + $reviewValues = glsr( CreateReviewDefaults::class )->restrict( (array)$command ); |
|
25 | + $reviewValues = apply_filters( 'site-reviews/create/review-values', $reviewValues, $command ); |
|
26 | + $reviewValues = Arr::prefixArrayKeys( $reviewValues ); |
|
27 | 27 | unset($reviewValues['json']); // @todo remove the need for this |
28 | 28 | $postValues = [ |
29 | 29 | 'comment_status' => 'closed', |
@@ -31,20 +31,20 @@ discard block |
||
31 | 31 | 'ping_status' => 'closed', |
32 | 32 | 'post_content' => $reviewValues['_content'], |
33 | 33 | 'post_date' => $reviewValues['_date'], |
34 | - 'post_date_gmt' => get_gmt_from_date($reviewValues['_date']), |
|
34 | + 'post_date_gmt' => get_gmt_from_date( $reviewValues['_date'] ), |
|
35 | 35 | 'post_name' => $reviewValues['_review_type'].'-'.$reviewValues['_review_id'], |
36 | - 'post_status' => $this->getNewPostStatus($reviewValues, $command->blacklisted), |
|
36 | + 'post_status' => $this->getNewPostStatus( $reviewValues, $command->blacklisted ), |
|
37 | 37 | 'post_title' => $reviewValues['_title'], |
38 | 38 | 'post_type' => Application::POST_TYPE, |
39 | 39 | ]; |
40 | - $postId = wp_insert_post($postValues, true); |
|
41 | - if (is_wp_error($postId)) { |
|
42 | - glsr_log()->error($postId->get_error_message())->debug($postValues); |
|
40 | + $postId = wp_insert_post( $postValues, true ); |
|
41 | + if( is_wp_error( $postId ) ) { |
|
42 | + glsr_log()->error( $postId->get_error_message() )->debug( $postValues ); |
|
43 | 43 | return false; |
44 | 44 | } |
45 | - $this->setTerms($postId, $command->category); |
|
46 | - $review = $this->single(get_post($postId)); |
|
47 | - do_action('site-reviews/review/created', $review, $command); |
|
45 | + $this->setTerms( $postId, $command->category ); |
|
46 | + $review = $this->single( get_post( $postId ) ); |
|
47 | + do_action( 'site-reviews/review/created', $review, $command ); |
|
48 | 48 | return $review; |
49 | 49 | } |
50 | 50 | |
@@ -52,29 +52,29 @@ discard block |
||
52 | 52 | * @param string $metaReviewId |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - public function delete($metaReviewId) |
|
55 | + public function delete( $metaReviewId ) |
|
56 | 56 | { |
57 | - if ($postId = $this->getPostId($metaReviewId)) { |
|
58 | - wp_delete_post($postId, true); |
|
57 | + if( $postId = $this->getPostId( $metaReviewId ) ) { |
|
58 | + wp_delete_post( $postId, true ); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @return object |
64 | 64 | */ |
65 | - public function get(array $args = []) |
|
65 | + public function get( array $args = [] ) |
|
66 | 66 | { |
67 | - $args = glsr(ReviewsDefaults::class)->merge($args); |
|
68 | - $metaQuery = glsr(QueryBuilder::class)->buildQuery( |
|
67 | + $args = glsr( ReviewsDefaults::class )->merge( $args ); |
|
68 | + $metaQuery = glsr( QueryBuilder::class )->buildQuery( |
|
69 | 69 | ['assigned_to', 'email', 'ip_address', 'type', 'rating'], |
70 | 70 | $args |
71 | 71 | ); |
72 | - $taxQuery = glsr(QueryBuilder::class)->buildQuery( |
|
72 | + $taxQuery = glsr( QueryBuilder::class )->buildQuery( |
|
73 | 73 | ['category'], |
74 | - ['category' => $this->normalizeTermIds($args['category'])] |
|
74 | + ['category' => $this->normalizeTermIds( $args['category'] )] |
|
75 | 75 | ); |
76 | - $paged = glsr(QueryBuilder::class)->getPaged( |
|
77 | - wp_validate_boolean($args['pagination']) |
|
76 | + $paged = glsr( QueryBuilder::class )->getPaged( |
|
77 | + wp_validate_boolean( $args['pagination'] ) |
|
78 | 78 | ); |
79 | 79 | $parameters = [ |
80 | 80 | 'meta_key' => '_pinned', |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | 'offset' => $args['offset'], |
83 | 83 | 'order' => $args['order'], |
84 | 84 | 'orderby' => 'meta_value '.$args['orderby'], |
85 | - 'paged' => Arr::get($args, 'paged', $paged), |
|
85 | + 'paged' => Arr::get( $args, 'paged', $paged ), |
|
86 | 86 | 'post__in' => $args['post__in'], |
87 | 87 | 'post__not_in' => $args['post__not_in'], |
88 | 88 | 'post_status' => 'publish', |
@@ -90,62 +90,62 @@ discard block |
||
90 | 90 | 'posts_per_page' => $args['per_page'], |
91 | 91 | 'tax_query' => $taxQuery, |
92 | 92 | ]; |
93 | - $parameters = apply_filters('site-reviews/get/reviews/query', $parameters, $args); |
|
94 | - $query = new WP_Query($parameters); |
|
95 | - $results = array_map([$this, 'single'], $query->posts); |
|
96 | - $reviews = new Reviews($results, $query->max_num_pages, $args); |
|
97 | - return apply_filters('site-reviews/get/reviews', $reviews, $query); |
|
93 | + $parameters = apply_filters( 'site-reviews/get/reviews/query', $parameters, $args ); |
|
94 | + $query = new WP_Query( $parameters ); |
|
95 | + $results = array_map( [$this, 'single'], $query->posts ); |
|
96 | + $reviews = new Reviews( $results, $query->max_num_pages, $args ); |
|
97 | + return apply_filters( 'site-reviews/get/reviews', $reviews, $query ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @param string $metaReviewId |
102 | 102 | * @return int |
103 | 103 | */ |
104 | - public function getPostId($metaReviewId) |
|
104 | + public function getPostId( $metaReviewId ) |
|
105 | 105 | { |
106 | - return glsr(SqlQueries::class)->getPostIdFromReviewId($metaReviewId); |
|
106 | + return glsr( SqlQueries::class )->getPostIdFromReviewId( $metaReviewId ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * @return array |
111 | 111 | */ |
112 | - public function getRatingCounts(array $args = []) |
|
112 | + public function getRatingCounts( array $args = [] ) |
|
113 | 113 | { |
114 | - $args = glsr(SiteReviewsSummaryDefaults::class)->filter($args); |
|
115 | - $counts = glsr(CountsManager::class)->getCounts([ |
|
116 | - 'post_ids' => Arr::convertStringToArray($args['assigned_to']), |
|
117 | - 'term_ids' => $this->normalizeTermIds($args['category']), |
|
114 | + $args = glsr( SiteReviewsSummaryDefaults::class )->filter( $args ); |
|
115 | + $counts = glsr( CountsManager::class )->getCounts( [ |
|
116 | + 'post_ids' => Arr::convertStringToArray( $args['assigned_to'] ), |
|
117 | + 'term_ids' => $this->normalizeTermIds( $args['category'] ), |
|
118 | 118 | 'type' => $args['type'], |
119 | - ]); |
|
120 | - return glsr(CountsManager::class)->flatten($counts, [ |
|
119 | + ] ); |
|
120 | + return glsr( CountsManager::class )->flatten( $counts, [ |
|
121 | 121 | 'min' => $args['rating'], |
122 | - ]); |
|
122 | + ] ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @param string $commaSeparatedTermIds |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public function normalizeTermIds($commaSeparatedTermIds) |
|
129 | + public function normalizeTermIds( $commaSeparatedTermIds ) |
|
130 | 130 | { |
131 | - $termIds = glsr_array_column($this->normalizeTerms($commaSeparatedTermIds), 'term_id'); |
|
132 | - return array_unique(array_map('intval', $termIds)); |
|
131 | + $termIds = glsr_array_column( $this->normalizeTerms( $commaSeparatedTermIds ), 'term_id' ); |
|
132 | + return array_unique( array_map( 'intval', $termIds ) ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | 136 | * @param string $commaSeparatedTermIds |
137 | 137 | * @return array |
138 | 138 | */ |
139 | - public function normalizeTerms($commaSeparatedTermIds) |
|
139 | + public function normalizeTerms( $commaSeparatedTermIds ) |
|
140 | 140 | { |
141 | 141 | $terms = []; |
142 | - $termIds = Arr::convertStringToArray($commaSeparatedTermIds); |
|
143 | - foreach ($termIds as $termId) { |
|
144 | - if (is_numeric($termId)) { |
|
145 | - $termId = intval($termId); |
|
142 | + $termIds = Arr::convertStringToArray( $commaSeparatedTermIds ); |
|
143 | + foreach( $termIds as $termId ) { |
|
144 | + if( is_numeric( $termId ) ) { |
|
145 | + $termId = intval( $termId ); |
|
146 | 146 | } |
147 | - $term = term_exists($termId, Application::TAXONOMY); |
|
148 | - if (!isset($term['term_id'])) { |
|
147 | + $term = term_exists( $termId, Application::TAXONOMY ); |
|
148 | + if( !isset($term['term_id']) ) { |
|
149 | 149 | continue; |
150 | 150 | } |
151 | 151 | $terms[] = $term; |
@@ -157,44 +157,44 @@ discard block |
||
157 | 157 | * @param int $postId |
158 | 158 | * @return void |
159 | 159 | */ |
160 | - public function revert($postId) |
|
160 | + public function revert( $postId ) |
|
161 | 161 | { |
162 | - if (Application::POST_TYPE != get_post_field('post_type', $postId)) { |
|
162 | + if( Application::POST_TYPE != get_post_field( 'post_type', $postId ) ) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | - delete_post_meta($postId, '_edit_last'); |
|
166 | - $result = wp_update_post([ |
|
165 | + delete_post_meta( $postId, '_edit_last' ); |
|
166 | + $result = wp_update_post( [ |
|
167 | 167 | 'ID' => $postId, |
168 | - 'post_content' => glsr(Database::class)->get($postId, 'content'), |
|
169 | - 'post_date' => glsr(Database::class)->get($postId, 'date'), |
|
170 | - 'post_title' => glsr(Database::class)->get($postId, 'title'), |
|
171 | - ]); |
|
172 | - if (is_wp_error($result)) { |
|
173 | - glsr_log()->error($result->get_error_message()); |
|
168 | + 'post_content' => glsr( Database::class )->get( $postId, 'content' ), |
|
169 | + 'post_date' => glsr( Database::class )->get( $postId, 'date' ), |
|
170 | + 'post_title' => glsr( Database::class )->get( $postId, 'title' ), |
|
171 | + ] ); |
|
172 | + if( is_wp_error( $result ) ) { |
|
173 | + glsr_log()->error( $result->get_error_message() ); |
|
174 | 174 | return; |
175 | 175 | } |
176 | - do_action('site-reviews/review/reverted', glsr_get_review($postId)); |
|
176 | + do_action( 'site-reviews/review/reverted', glsr_get_review( $postId ) ); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @return Review |
181 | 181 | */ |
182 | - public function single(WP_Post $post) |
|
182 | + public function single( WP_Post $post ) |
|
183 | 183 | { |
184 | - if (Application::POST_TYPE != $post->post_type) { |
|
185 | - $post = new WP_Post((object) []); |
|
184 | + if( Application::POST_TYPE != $post->post_type ) { |
|
185 | + $post = new WP_Post( (object)[] ); |
|
186 | 186 | } |
187 | - $review = new Review($post); |
|
188 | - return apply_filters('site-reviews/get/review', $review, $post); |
|
187 | + $review = new Review( $post ); |
|
188 | + return apply_filters( 'site-reviews/get/review', $review, $post ); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * @param bool $isBlacklisted |
193 | 193 | * @return string |
194 | 194 | */ |
195 | - protected function getNewPostStatus(array $reviewValues, $isBlacklisted) |
|
195 | + protected function getNewPostStatus( array $reviewValues, $isBlacklisted ) |
|
196 | 196 | { |
197 | - $requireApproval = glsr(OptionManager::class)->getBool('settings.general.require.approval'); |
|
197 | + $requireApproval = glsr( OptionManager::class )->getBool( 'settings.general.require.approval' ); |
|
198 | 198 | return 'local' == $reviewValues['_review_type'] && ($requireApproval || $isBlacklisted) |
199 | 199 | ? 'pending' |
200 | 200 | : 'publish'; |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | * @param string $termIds |
206 | 206 | * @return void |
207 | 207 | */ |
208 | - protected function setTerms($postId, $termIds) |
|
208 | + protected function setTerms( $postId, $termIds ) |
|
209 | 209 | { |
210 | - $termIds = $this->normalizeTermIds($termIds); |
|
211 | - if (empty($termIds)) { |
|
210 | + $termIds = $this->normalizeTermIds( $termIds ); |
|
211 | + if( empty($termIds) ) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | - $termTaxonomyIds = wp_set_object_terms($postId, $termIds, Application::TAXONOMY); |
|
215 | - if (is_wp_error($termTaxonomyIds)) { |
|
216 | - glsr_log()->error($termTaxonomyIds->get_error_message()); |
|
214 | + $termTaxonomyIds = wp_set_object_terms( $postId, $termIds, Application::TAXONOMY ); |
|
215 | + if( is_wp_error( $termTaxonomyIds ) ) { |
|
216 | + glsr_log()->error( $termTaxonomyIds->get_error_message() ); |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | } |
@@ -4,186 +4,186 @@ |
||
4 | 4 | |
5 | 5 | class Str |
6 | 6 | { |
7 | - /** |
|
8 | - * @param string $subject |
|
9 | - * @param string $search |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - public static function afterLast($subject, $search) |
|
13 | - { |
|
14 | - return '' === $search |
|
15 | - ? $subject |
|
16 | - : array_reverse(explode($search, $subject))[0]; |
|
17 | - } |
|
7 | + /** |
|
8 | + * @param string $subject |
|
9 | + * @param string $search |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + public static function afterLast($subject, $search) |
|
13 | + { |
|
14 | + return '' === $search |
|
15 | + ? $subject |
|
16 | + : array_reverse(explode($search, $subject))[0]; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $string |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public static function camelCase($string) |
|
24 | - { |
|
25 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | - return str_replace(' ', '', $string); |
|
27 | - } |
|
19 | + /** |
|
20 | + * @param string $string |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public static function camelCase($string) |
|
24 | + { |
|
25 | + $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | + return str_replace(' ', '', $string); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param string $haystack |
|
31 | - * @param string $needle |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public static function contains($haystack, $needle) |
|
35 | - { |
|
36 | - return false !== strpos($haystack, $needle); |
|
37 | - } |
|
29 | + /** |
|
30 | + * @param string $haystack |
|
31 | + * @param string $needle |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public static function contains($haystack, $needle) |
|
35 | + { |
|
36 | + return false !== strpos($haystack, $needle); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $name |
|
41 | - * @param string $nameType first|first_initial|initials|last|last_initial |
|
42 | - * @param string $initialType period|period_space|space |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
46 | - { |
|
47 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | - $firstName = array_shift($names); |
|
49 | - $lastName = array_pop($names); |
|
50 | - $initialTypes = [ |
|
51 | - 'period' => '.', |
|
52 | - 'period_space' => '. ', |
|
53 | - 'space' => ' ', |
|
54 | - ]; |
|
55 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | - if ('initials' == $nameType) { |
|
57 | - return static::convertToInitials($name, $initialPunctuation); |
|
58 | - } |
|
59 | - $nameTypes = [ |
|
60 | - 'first' => $firstName, |
|
61 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
62 | - 'last' => $lastName, |
|
63 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
64 | - ]; |
|
65 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
66 | - } |
|
39 | + /** |
|
40 | + * @param string $name |
|
41 | + * @param string $nameType first|first_initial|initials|last|last_initial |
|
42 | + * @param string $initialType period|period_space|space |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public static function convertName($name, $nameType = '', $initialType = '') |
|
46 | + { |
|
47 | + $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | + $firstName = array_shift($names); |
|
49 | + $lastName = array_pop($names); |
|
50 | + $initialTypes = [ |
|
51 | + 'period' => '.', |
|
52 | + 'period_space' => '. ', |
|
53 | + 'space' => ' ', |
|
54 | + ]; |
|
55 | + $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | + if ('initials' == $nameType) { |
|
57 | + return static::convertToInitials($name, $initialPunctuation); |
|
58 | + } |
|
59 | + $nameTypes = [ |
|
60 | + 'first' => $firstName, |
|
61 | + 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
62 | + 'last' => $lastName, |
|
63 | + 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
64 | + ]; |
|
65 | + return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $path |
|
70 | - * @param string $prefix |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function convertPathToId($path, $prefix = '') |
|
74 | - { |
|
75 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
76 | - } |
|
68 | + /** |
|
69 | + * @param string $path |
|
70 | + * @param string $prefix |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function convertPathToId($path, $prefix = '') |
|
74 | + { |
|
75 | + return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $path |
|
80 | - * @param string $prefix |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public static function convertPathToName($path, $prefix = '') |
|
84 | - { |
|
85 | - $levels = explode('.', $path); |
|
86 | - return array_reduce($levels, function ($result, $value) { |
|
87 | - return $result .= '['.$value.']'; |
|
88 | - }, $prefix); |
|
89 | - } |
|
78 | + /** |
|
79 | + * @param string $path |
|
80 | + * @param string $prefix |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public static function convertPathToName($path, $prefix = '') |
|
84 | + { |
|
85 | + $levels = explode('.', $path); |
|
86 | + return array_reduce($levels, function ($result, $value) { |
|
87 | + return $result .= '['.$value.']'; |
|
88 | + }, $prefix); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $name |
|
93 | - * @param string $initialPunctuation |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
97 | - { |
|
98 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
101 | - }); |
|
102 | - } |
|
91 | + /** |
|
92 | + * @param string $name |
|
93 | + * @param string $initialPunctuation |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public static function convertToInitials($name, $initialPunctuation = '') |
|
97 | + { |
|
98 | + preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | + return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | + return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
101 | + }); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param string $string |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public static function dashCase($string) |
|
109 | - { |
|
110 | - return str_replace('_', '-', static::snakeCase($string)); |
|
111 | - } |
|
104 | + /** |
|
105 | + * @param string $string |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public static function dashCase($string) |
|
109 | + { |
|
110 | + return str_replace('_', '-', static::snakeCase($string)); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $needle |
|
115 | - * @param string $haystack |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - public static function endsWith($needle, $haystack) |
|
119 | - { |
|
120 | - $length = strlen($needle); |
|
121 | - return 0 != $length |
|
122 | - ? substr($haystack, -$length) === $needle |
|
123 | - : true; |
|
124 | - } |
|
113 | + /** |
|
114 | + * @param string $needle |
|
115 | + * @param string $haystack |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + public static function endsWith($needle, $haystack) |
|
119 | + { |
|
120 | + $length = strlen($needle); |
|
121 | + return 0 != $length |
|
122 | + ? substr($haystack, -$length) === $needle |
|
123 | + : true; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param string $prefix |
|
128 | - * @param string $string |
|
129 | - * @param string|null $trim |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public static function prefix($prefix, $string, $trim = null) |
|
133 | - { |
|
134 | - if (null === $trim) { |
|
135 | - $trim = $prefix; |
|
136 | - } |
|
137 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
138 | - } |
|
126 | + /** |
|
127 | + * @param string $prefix |
|
128 | + * @param string $string |
|
129 | + * @param string|null $trim |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public static function prefix($prefix, $string, $trim = null) |
|
133 | + { |
|
134 | + if (null === $trim) { |
|
135 | + $trim = $prefix; |
|
136 | + } |
|
137 | + return $prefix.trim(static::removePrefix($trim, $string)); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @param string $prefix |
|
142 | - * @param string $string |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public static function removePrefix($prefix, $string) |
|
146 | - { |
|
147 | - return static::startsWith($prefix, $string) |
|
148 | - ? substr($string, strlen($prefix)) |
|
149 | - : $string; |
|
150 | - } |
|
140 | + /** |
|
141 | + * @param string $prefix |
|
142 | + * @param string $string |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public static function removePrefix($prefix, $string) |
|
146 | + { |
|
147 | + return static::startsWith($prefix, $string) |
|
148 | + ? substr($string, strlen($prefix)) |
|
149 | + : $string; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @param string $string |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - public static function snakeCase($string) |
|
157 | - { |
|
158 | - if (!ctype_lower($string)) { |
|
159 | - $string = preg_replace('/\s+/u', '', $string); |
|
160 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | - $string = function_exists('mb_strtolower') |
|
162 | - ? mb_strtolower($string, 'UTF-8') |
|
163 | - : strtolower($string); |
|
164 | - } |
|
165 | - return str_replace('-', '_', $string); |
|
166 | - } |
|
152 | + /** |
|
153 | + * @param string $string |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + public static function snakeCase($string) |
|
157 | + { |
|
158 | + if (!ctype_lower($string)) { |
|
159 | + $string = preg_replace('/\s+/u', '', $string); |
|
160 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | + $string = function_exists('mb_strtolower') |
|
162 | + ? mb_strtolower($string, 'UTF-8') |
|
163 | + : strtolower($string); |
|
164 | + } |
|
165 | + return str_replace('-', '_', $string); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @param string $needle |
|
170 | - * @param string $haystack |
|
171 | - * @return bool |
|
172 | - */ |
|
173 | - public static function startsWith($needle, $haystack) |
|
174 | - { |
|
175 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
176 | - } |
|
168 | + /** |
|
169 | + * @param string $needle |
|
170 | + * @param string $haystack |
|
171 | + * @return bool |
|
172 | + */ |
|
173 | + public static function startsWith($needle, $haystack) |
|
174 | + { |
|
175 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @param string $string |
|
180 | - * @param int $length |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public static function truncate($string, $length) |
|
184 | - { |
|
185 | - return strlen($string) > $length |
|
186 | - ? substr($string, 0, $length) |
|
187 | - : $string; |
|
188 | - } |
|
178 | + /** |
|
179 | + * @param string $string |
|
180 | + * @param int $length |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public static function truncate($string, $length) |
|
184 | + { |
|
185 | + return strlen($string) > $length |
|
186 | + ? substr($string, 0, $length) |
|
187 | + : $string; |
|
188 | + } |
|
189 | 189 | } |
@@ -9,21 +9,21 @@ discard block |
||
9 | 9 | * @param string $search |
10 | 10 | * @return string |
11 | 11 | */ |
12 | - public static function afterLast($subject, $search) |
|
12 | + public static function afterLast( $subject, $search ) |
|
13 | 13 | { |
14 | 14 | return '' === $search |
15 | 15 | ? $subject |
16 | - : array_reverse(explode($search, $subject))[0]; |
|
16 | + : array_reverse( explode( $search, $subject ) )[0]; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @param string $string |
21 | 21 | * @return string |
22 | 22 | */ |
23 | - public static function camelCase($string) |
|
23 | + public static function camelCase( $string ) |
|
24 | 24 | { |
25 | - $string = ucwords(str_replace(['-', '_'], ' ', trim($string))); |
|
26 | - return str_replace(' ', '', $string); |
|
25 | + $string = ucwords( str_replace( ['-', '_'], ' ', trim( $string ) ) ); |
|
26 | + return str_replace( ' ', '', $string ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | * @param string $needle |
32 | 32 | * @return bool |
33 | 33 | */ |
34 | - public static function contains($haystack, $needle) |
|
34 | + public static function contains( $haystack, $needle ) |
|
35 | 35 | { |
36 | - return false !== strpos($haystack, $needle); |
|
36 | + return false !== strpos( $haystack, $needle ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -42,27 +42,27 @@ discard block |
||
42 | 42 | * @param string $initialType period|period_space|space |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public static function convertName($name, $nameType = '', $initialType = '') |
|
45 | + public static function convertName( $name, $nameType = '', $initialType = '' ) |
|
46 | 46 | { |
47 | - $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY); |
|
48 | - $firstName = array_shift($names); |
|
49 | - $lastName = array_pop($names); |
|
47 | + $names = preg_split( '/\W/', $name, 0, PREG_SPLIT_NO_EMPTY ); |
|
48 | + $firstName = array_shift( $names ); |
|
49 | + $lastName = array_pop( $names ); |
|
50 | 50 | $initialTypes = [ |
51 | 51 | 'period' => '.', |
52 | 52 | 'period_space' => '. ', |
53 | 53 | 'space' => ' ', |
54 | 54 | ]; |
55 | - $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' '); |
|
56 | - if ('initials' == $nameType) { |
|
57 | - return static::convertToInitials($name, $initialPunctuation); |
|
55 | + $initialPunctuation = (string)Arr::get( $initialTypes, $initialType, ' ' ); |
|
56 | + if( 'initials' == $nameType ) { |
|
57 | + return static::convertToInitials( $name, $initialPunctuation ); |
|
58 | 58 | } |
59 | 59 | $nameTypes = [ |
60 | 60 | 'first' => $firstName, |
61 | - 'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName, |
|
61 | + 'first_initial' => substr( $firstName, 0, 1 ).$initialPunctuation.$lastName, |
|
62 | 62 | 'last' => $lastName, |
63 | - 'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation, |
|
63 | + 'last_initial' => $firstName.' '.substr( $lastName, 0, 1 ).$initialPunctuation, |
|
64 | 64 | ]; |
65 | - return trim((string) Arr::get($nameTypes, $nameType, $name)); |
|
65 | + return trim( (string)Arr::get( $nameTypes, $nameType, $name ) ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * @param string $prefix |
71 | 71 | * @return string |
72 | 72 | */ |
73 | - public static function convertPathToId($path, $prefix = '') |
|
73 | + public static function convertPathToId( $path, $prefix = '' ) |
|
74 | 74 | { |
75 | - return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix)); |
|
75 | + return str_replace( ['[', ']'], ['-', ''], static::convertPathToName( $path, $prefix ) ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | * @param string $prefix |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public static function convertPathToName($path, $prefix = '') |
|
83 | + public static function convertPathToName( $path, $prefix = '' ) |
|
84 | 84 | { |
85 | - $levels = explode('.', $path); |
|
86 | - return array_reduce($levels, function ($result, $value) { |
|
85 | + $levels = explode( '.', $path ); |
|
86 | + return array_reduce( $levels, function( $result, $value ) { |
|
87 | 87 | return $result .= '['.$value.']'; |
88 | - }, $prefix); |
|
88 | + }, $prefix ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | * @param string $initialPunctuation |
94 | 94 | * @return string |
95 | 95 | */ |
96 | - public static function convertToInitials($name, $initialPunctuation = '') |
|
96 | + public static function convertToInitials( $name, $initialPunctuation = '' ) |
|
97 | 97 | { |
98 | - preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches); |
|
99 | - return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) { |
|
100 | - return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation; |
|
98 | + preg_match_all( '/(?<=\s|\b)\pL/u', $name, $matches ); |
|
99 | + return array_reduce( $matches[0], function( $carry, $word ) use ($initialPunctuation) { |
|
100 | + return $carry.strtoupper( substr( $word, 0, 1 ) ).$initialPunctuation; |
|
101 | 101 | }); |
102 | 102 | } |
103 | 103 | |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param string $string |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public static function dashCase($string) |
|
108 | + public static function dashCase( $string ) |
|
109 | 109 | { |
110 | - return str_replace('_', '-', static::snakeCase($string)); |
|
110 | + return str_replace( '_', '-', static::snakeCase( $string ) ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | * @param string $haystack |
116 | 116 | * @return bool |
117 | 117 | */ |
118 | - public static function endsWith($needle, $haystack) |
|
118 | + public static function endsWith( $needle, $haystack ) |
|
119 | 119 | { |
120 | - $length = strlen($needle); |
|
120 | + $length = strlen( $needle ); |
|
121 | 121 | return 0 != $length |
122 | - ? substr($haystack, -$length) === $needle |
|
122 | + ? substr( $haystack, -$length ) === $needle |
|
123 | 123 | : true; |
124 | 124 | } |
125 | 125 | |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | * @param string|null $trim |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function prefix($prefix, $string, $trim = null) |
|
132 | + public static function prefix( $prefix, $string, $trim = null ) |
|
133 | 133 | { |
134 | - if (null === $trim) { |
|
134 | + if( null === $trim ) { |
|
135 | 135 | $trim = $prefix; |
136 | 136 | } |
137 | - return $prefix.trim(static::removePrefix($trim, $string)); |
|
137 | + return $prefix.trim( static::removePrefix( $trim, $string ) ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | * @param string $string |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public static function removePrefix($prefix, $string) |
|
145 | + public static function removePrefix( $prefix, $string ) |
|
146 | 146 | { |
147 | - return static::startsWith($prefix, $string) |
|
148 | - ? substr($string, strlen($prefix)) |
|
147 | + return static::startsWith( $prefix, $string ) |
|
148 | + ? substr( $string, strlen( $prefix ) ) |
|
149 | 149 | : $string; |
150 | 150 | } |
151 | 151 | |
@@ -153,16 +153,16 @@ discard block |
||
153 | 153 | * @param string $string |
154 | 154 | * @return string |
155 | 155 | */ |
156 | - public static function snakeCase($string) |
|
156 | + public static function snakeCase( $string ) |
|
157 | 157 | { |
158 | - if (!ctype_lower($string)) { |
|
159 | - $string = preg_replace('/\s+/u', '', $string); |
|
160 | - $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
161 | - $string = function_exists('mb_strtolower') |
|
162 | - ? mb_strtolower($string, 'UTF-8') |
|
163 | - : strtolower($string); |
|
158 | + if( !ctype_lower( $string ) ) { |
|
159 | + $string = preg_replace( '/\s+/u', '', $string ); |
|
160 | + $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
161 | + $string = function_exists( 'mb_strtolower' ) |
|
162 | + ? mb_strtolower( $string, 'UTF-8' ) |
|
163 | + : strtolower( $string ); |
|
164 | 164 | } |
165 | - return str_replace('-', '_', $string); |
|
165 | + return str_replace( '-', '_', $string ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * @param string $haystack |
171 | 171 | * @return bool |
172 | 172 | */ |
173 | - public static function startsWith($needle, $haystack) |
|
173 | + public static function startsWith( $needle, $haystack ) |
|
174 | 174 | { |
175 | - return substr($haystack, 0, strlen($needle)) === $needle; |
|
175 | + return substr( $haystack, 0, strlen( $needle ) ) === $needle; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | * @param int $length |
181 | 181 | * @return string |
182 | 182 | */ |
183 | - public static function truncate($string, $length) |
|
183 | + public static function truncate( $string, $length ) |
|
184 | 184 | { |
185 | - return strlen($string) > $length |
|
186 | - ? substr($string, 0, $length) |
|
185 | + return strlen( $string ) > $length |
|
186 | + ? substr( $string, 0, $length ) |
|
187 | 187 | : $string; |
188 | 188 | } |
189 | 189 | } |
@@ -8,266 +8,266 @@ |
||
8 | 8 | |
9 | 9 | class Updater |
10 | 10 | { |
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - protected $apiUrl; |
|
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $data; |
|
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $plugin; |
|
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $transientName; |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + protected $apiUrl; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $data; |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $plugin; |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $transientName; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param string $apiUrl |
|
30 | - * @param string $file |
|
31 | - */ |
|
32 | - public function __construct($apiUrl, $file, array $data = []) |
|
33 | - { |
|
34 | - if (!function_exists('get_plugin_data')) { |
|
35 | - require_once ABSPATH.WPINC.'/plugin.php'; |
|
36 | - } |
|
37 | - $this->apiUrl = trailingslashit(apply_filters('site-reviews/addon/api-url', $apiUrl)); |
|
38 | - $this->data = wp_parse_args($data, get_plugin_data($file)); |
|
39 | - $this->plugin = plugin_basename($file); |
|
40 | - $this->transientName = Application::PREFIX.md5(Arr::get($data, 'TextDomain')); |
|
41 | - } |
|
28 | + /** |
|
29 | + * @param string $apiUrl |
|
30 | + * @param string $file |
|
31 | + */ |
|
32 | + public function __construct($apiUrl, $file, array $data = []) |
|
33 | + { |
|
34 | + if (!function_exists('get_plugin_data')) { |
|
35 | + require_once ABSPATH.WPINC.'/plugin.php'; |
|
36 | + } |
|
37 | + $this->apiUrl = trailingslashit(apply_filters('site-reviews/addon/api-url', $apiUrl)); |
|
38 | + $this->data = wp_parse_args($data, get_plugin_data($file)); |
|
39 | + $this->plugin = plugin_basename($file); |
|
40 | + $this->transientName = Application::PREFIX.md5(Arr::get($data, 'TextDomain')); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return object |
|
45 | - */ |
|
46 | - public function activateLicense(array $data = []) |
|
47 | - { |
|
48 | - return $this->request('activate_license', $data); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @return object |
|
45 | + */ |
|
46 | + public function activateLicense(array $data = []) |
|
47 | + { |
|
48 | + return $this->request('activate_license', $data); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return object |
|
53 | - */ |
|
54 | - public function checkLicense(array $data = []) |
|
55 | - { |
|
56 | - $response = $this->request('check_license', $data); |
|
57 | - if ('valid' === Arr::get($response, 'license')) { |
|
58 | - $this->getPluginUpdate(true); |
|
59 | - } |
|
60 | - return $response; |
|
61 | - } |
|
51 | + /** |
|
52 | + * @return object |
|
53 | + */ |
|
54 | + public function checkLicense(array $data = []) |
|
55 | + { |
|
56 | + $response = $this->request('check_license', $data); |
|
57 | + if ('valid' === Arr::get($response, 'license')) { |
|
58 | + $this->getPluginUpdate(true); |
|
59 | + } |
|
60 | + return $response; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return object |
|
65 | - */ |
|
66 | - public function deactivateLicense(array $data = []) |
|
67 | - { |
|
68 | - return $this->request('deactivate_license', $data); |
|
69 | - } |
|
63 | + /** |
|
64 | + * @return object |
|
65 | + */ |
|
66 | + public function deactivateLicense(array $data = []) |
|
67 | + { |
|
68 | + return $this->request('deactivate_license', $data); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param false|object|array $result |
|
73 | - * @param string $action |
|
74 | - * @param object $args |
|
75 | - * @return mixed |
|
76 | - */ |
|
77 | - public function filterPluginUpdateDetails($result, $action, $args) |
|
78 | - { |
|
79 | - if ('plugin_information' != $action |
|
80 | - || Arr::get($this->data, 'TextDomain') != Arr::get($args, 'slug')) { |
|
81 | - return $result; |
|
82 | - } |
|
83 | - if ($updateInfo = $this->getPluginUpdate()) { |
|
84 | - return $this->modifyUpdateDetails($updateInfo); |
|
85 | - } |
|
86 | - return $result; |
|
87 | - } |
|
71 | + /** |
|
72 | + * @param false|object|array $result |
|
73 | + * @param string $action |
|
74 | + * @param object $args |
|
75 | + * @return mixed |
|
76 | + */ |
|
77 | + public function filterPluginUpdateDetails($result, $action, $args) |
|
78 | + { |
|
79 | + if ('plugin_information' != $action |
|
80 | + || Arr::get($this->data, 'TextDomain') != Arr::get($args, 'slug')) { |
|
81 | + return $result; |
|
82 | + } |
|
83 | + if ($updateInfo = $this->getPluginUpdate()) { |
|
84 | + return $this->modifyUpdateDetails($updateInfo); |
|
85 | + } |
|
86 | + return $result; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @param object $transient |
|
91 | - * @return object |
|
92 | - */ |
|
93 | - public function filterPluginUpdates($transient) |
|
94 | - { |
|
95 | - if ($updateInfo = $this->getPluginUpdate()) { |
|
96 | - return $this->modifyPluginUpdates($transient, $updateInfo); |
|
97 | - } |
|
98 | - return $transient; |
|
99 | - } |
|
89 | + /** |
|
90 | + * @param object $transient |
|
91 | + * @return object |
|
92 | + */ |
|
93 | + public function filterPluginUpdates($transient) |
|
94 | + { |
|
95 | + if ($updateInfo = $this->getPluginUpdate()) { |
|
96 | + return $this->modifyPluginUpdates($transient, $updateInfo); |
|
97 | + } |
|
98 | + return $transient; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return object |
|
103 | - */ |
|
104 | - public function getVersion(array $data = []) |
|
105 | - { |
|
106 | - return $this->request('get_version', $data); |
|
107 | - } |
|
101 | + /** |
|
102 | + * @return object |
|
103 | + */ |
|
104 | + public function getVersion(array $data = []) |
|
105 | + { |
|
106 | + return $this->request('get_version', $data); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - public function init() |
|
113 | - { |
|
114 | - if ($this->apiUrl === trailingslashit(home_url())) { |
|
115 | - return; |
|
116 | - } |
|
117 | - add_filter('plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3); |
|
118 | - add_filter('pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999); |
|
119 | - add_action('load-update-core.php', [$this, 'onForceUpdateCheck'], 9); |
|
120 | - add_action('in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink']); |
|
121 | - } |
|
109 | + /** |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + public function init() |
|
113 | + { |
|
114 | + if ($this->apiUrl === trailingslashit(home_url())) { |
|
115 | + return; |
|
116 | + } |
|
117 | + add_filter('plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3); |
|
118 | + add_filter('pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999); |
|
119 | + add_action('load-update-core.php', [$this, 'onForceUpdateCheck'], 9); |
|
120 | + add_action('in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink']); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - public function isLicenseValid() |
|
127 | - { |
|
128 | - $result = $this->checkLicense(); |
|
129 | - return 'valid' === Arr::get($result, 'license'); |
|
130 | - } |
|
123 | + /** |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + public function isLicenseValid() |
|
127 | + { |
|
128 | + $result = $this->checkLicense(); |
|
129 | + return 'valid' === Arr::get($result, 'license'); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return void |
|
134 | - */ |
|
135 | - public function onForceUpdateCheck() |
|
136 | - { |
|
137 | - if (!filter_input(INPUT_GET, 'force-check')) { |
|
138 | - return; |
|
139 | - } |
|
140 | - foreach (glsr()->addons as $addon) { |
|
141 | - try { |
|
142 | - glsr($addon)->updater->getPluginUpdate(true); |
|
143 | - } catch (\Exception $e) { |
|
144 | - glsr_log()->error($e->getMessage()); |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + */ |
|
135 | + public function onForceUpdateCheck() |
|
136 | + { |
|
137 | + if (!filter_input(INPUT_GET, 'force-check')) { |
|
138 | + return; |
|
139 | + } |
|
140 | + foreach (glsr()->addons as $addon) { |
|
141 | + try { |
|
142 | + glsr($addon)->updater->getPluginUpdate(true); |
|
143 | + } catch (\Exception $e) { |
|
144 | + glsr_log()->error($e->getMessage()); |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - public function renderLicenseMissingLink() |
|
153 | - { |
|
154 | - if (!$this->isLicenseValid()) { |
|
155 | - glsr()->render('partials/addons/license-missing'); |
|
156 | - } |
|
157 | - } |
|
149 | + /** |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + public function renderLicenseMissingLink() |
|
153 | + { |
|
154 | + if (!$this->isLicenseValid()) { |
|
155 | + glsr()->render('partials/addons/license-missing'); |
|
156 | + } |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * @return false|object |
|
161 | - */ |
|
162 | - protected function getCachedVersion() |
|
163 | - { |
|
164 | - return get_transient($this->transientName); |
|
165 | - } |
|
159 | + /** |
|
160 | + * @return false|object |
|
161 | + */ |
|
162 | + protected function getCachedVersion() |
|
163 | + { |
|
164 | + return get_transient($this->transientName); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param bool $force |
|
169 | - * @return false|object |
|
170 | - */ |
|
171 | - protected function getPluginUpdate($force = false) |
|
172 | - { |
|
173 | - $version = $this->getCachedVersion(); |
|
174 | - if (false === $version || $force) { |
|
175 | - $version = $this->getVersion(); |
|
176 | - $this->setCachedVersion($version); |
|
177 | - } |
|
178 | - if (isset($version->error)) { |
|
179 | - glsr_log()->error($version->error); |
|
180 | - return false; |
|
181 | - } |
|
182 | - return $version; |
|
183 | - } |
|
167 | + /** |
|
168 | + * @param bool $force |
|
169 | + * @return false|object |
|
170 | + */ |
|
171 | + protected function getPluginUpdate($force = false) |
|
172 | + { |
|
173 | + $version = $this->getCachedVersion(); |
|
174 | + if (false === $version || $force) { |
|
175 | + $version = $this->getVersion(); |
|
176 | + $this->setCachedVersion($version); |
|
177 | + } |
|
178 | + if (isset($version->error)) { |
|
179 | + glsr_log()->error($version->error); |
|
180 | + return false; |
|
181 | + } |
|
182 | + return $version; |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @param object $transient |
|
187 | - * @param object $updateInfo |
|
188 | - * @return object |
|
189 | - */ |
|
190 | - protected function modifyPluginUpdates($transient, $updateInfo) |
|
191 | - { |
|
192 | - $updateInfo->id = Application::ID.'/'.Arr::get($this->data, 'TextDomain'); |
|
193 | - $updateInfo->plugin = $this->plugin; |
|
194 | - $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
195 | - $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
196 | - $transient->checked[$this->plugin] = Arr::get($this->data, 'Version'); |
|
197 | - $transient->last_checked = time(); |
|
198 | - if (Helper::isGreaterThan($updateInfo->new_version, Arr::get($this->data, 'Version'))) { |
|
199 | - unset($transient->no_update[$this->plugin]); |
|
200 | - $updateInfo->update = true; |
|
201 | - $transient->response[$this->plugin] = $updateInfo; |
|
202 | - } else { |
|
203 | - unset($transient->response[$this->plugin]); |
|
204 | - $transient->no_update[$this->plugin] = $updateInfo; |
|
205 | - } |
|
206 | - return $transient; |
|
207 | - } |
|
185 | + /** |
|
186 | + * @param object $transient |
|
187 | + * @param object $updateInfo |
|
188 | + * @return object |
|
189 | + */ |
|
190 | + protected function modifyPluginUpdates($transient, $updateInfo) |
|
191 | + { |
|
192 | + $updateInfo->id = Application::ID.'/'.Arr::get($this->data, 'TextDomain'); |
|
193 | + $updateInfo->plugin = $this->plugin; |
|
194 | + $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
195 | + $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
196 | + $transient->checked[$this->plugin] = Arr::get($this->data, 'Version'); |
|
197 | + $transient->last_checked = time(); |
|
198 | + if (Helper::isGreaterThan($updateInfo->new_version, Arr::get($this->data, 'Version'))) { |
|
199 | + unset($transient->no_update[$this->plugin]); |
|
200 | + $updateInfo->update = true; |
|
201 | + $transient->response[$this->plugin] = $updateInfo; |
|
202 | + } else { |
|
203 | + unset($transient->response[$this->plugin]); |
|
204 | + $transient->no_update[$this->plugin] = $updateInfo; |
|
205 | + } |
|
206 | + return $transient; |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * @param object $updateInfo |
|
211 | - * @return object |
|
212 | - */ |
|
213 | - protected function modifyUpdateDetails($updateInfo) |
|
214 | - { |
|
215 | - $updateInfo->author = Arr::get($this->data, 'Author'); |
|
216 | - $updateInfo->author_profile = Arr::get($this->data, 'AuthorURI'); |
|
217 | - $updateInfo->requires = Arr::get($this->data, 'RequiresWP'); |
|
218 | - $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
219 | - $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
220 | - $updateInfo->version = $updateInfo->new_version; |
|
221 | - return $updateInfo; |
|
222 | - } |
|
209 | + /** |
|
210 | + * @param object $updateInfo |
|
211 | + * @return object |
|
212 | + */ |
|
213 | + protected function modifyUpdateDetails($updateInfo) |
|
214 | + { |
|
215 | + $updateInfo->author = Arr::get($this->data, 'Author'); |
|
216 | + $updateInfo->author_profile = Arr::get($this->data, 'AuthorURI'); |
|
217 | + $updateInfo->requires = Arr::get($this->data, 'RequiresWP'); |
|
218 | + $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
219 | + $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
220 | + $updateInfo->version = $updateInfo->new_version; |
|
221 | + return $updateInfo; |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * @param \WP_Error|array $response |
|
226 | - * @return object |
|
227 | - */ |
|
228 | - protected function normalizeResponse($response) |
|
229 | - { |
|
230 | - $body = wp_remote_retrieve_body($response); |
|
231 | - if ($data = json_decode($body)) { |
|
232 | - $data = array_map('maybe_unserialize', (array) $data); |
|
233 | - return (object) $data; |
|
234 | - } |
|
235 | - $error = is_wp_error($response) |
|
236 | - ? $response->get_error_message() |
|
237 | - : 'Update server not responding ('.Arr::get($this->data, 'TextDomain').')'; |
|
238 | - return (object) ['error' => $error]; |
|
239 | - } |
|
224 | + /** |
|
225 | + * @param \WP_Error|array $response |
|
226 | + * @return object |
|
227 | + */ |
|
228 | + protected function normalizeResponse($response) |
|
229 | + { |
|
230 | + $body = wp_remote_retrieve_body($response); |
|
231 | + if ($data = json_decode($body)) { |
|
232 | + $data = array_map('maybe_unserialize', (array) $data); |
|
233 | + return (object) $data; |
|
234 | + } |
|
235 | + $error = is_wp_error($response) |
|
236 | + ? $response->get_error_message() |
|
237 | + : 'Update server not responding ('.Arr::get($this->data, 'TextDomain').')'; |
|
238 | + return (object) ['error' => $error]; |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * @param string $action activate_license|check_license|deactivate_license|get_version |
|
243 | - * @return object |
|
244 | - */ |
|
245 | - protected function request($action, array $data = []) |
|
246 | - { |
|
247 | - $data = wp_parse_args($data, $this->data); |
|
248 | - $response = wp_remote_post($this->apiUrl, [ |
|
249 | - 'body' => [ |
|
250 | - 'edd_action' => $action, |
|
251 | - 'item_id' => Arr::get($data, 'item_id'), |
|
252 | - 'item_name' => Arr::get($data, 'Name'), |
|
253 | - 'license' => Arr::get($data, 'license'), |
|
254 | - 'slug' => Arr::get($data, 'TextDomain'), |
|
255 | - 'url' => home_url(), |
|
256 | - ], |
|
257 | - 'sslverify' => apply_filters('site-reviews/sslverify/post', false), |
|
258 | - 'timeout' => 15, |
|
259 | - ]); |
|
260 | - return $this->normalizeResponse($response); |
|
261 | - } |
|
241 | + /** |
|
242 | + * @param string $action activate_license|check_license|deactivate_license|get_version |
|
243 | + * @return object |
|
244 | + */ |
|
245 | + protected function request($action, array $data = []) |
|
246 | + { |
|
247 | + $data = wp_parse_args($data, $this->data); |
|
248 | + $response = wp_remote_post($this->apiUrl, [ |
|
249 | + 'body' => [ |
|
250 | + 'edd_action' => $action, |
|
251 | + 'item_id' => Arr::get($data, 'item_id'), |
|
252 | + 'item_name' => Arr::get($data, 'Name'), |
|
253 | + 'license' => Arr::get($data, 'license'), |
|
254 | + 'slug' => Arr::get($data, 'TextDomain'), |
|
255 | + 'url' => home_url(), |
|
256 | + ], |
|
257 | + 'sslverify' => apply_filters('site-reviews/sslverify/post', false), |
|
258 | + 'timeout' => 15, |
|
259 | + ]); |
|
260 | + return $this->normalizeResponse($response); |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * @param object $version |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - protected function setCachedVersion($version) |
|
268 | - { |
|
269 | - if (!isset($version->error)) { |
|
270 | - set_transient($this->transientName, $version, 3 * HOUR_IN_SECONDS); |
|
271 | - } |
|
272 | - } |
|
263 | + /** |
|
264 | + * @param object $version |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + protected function setCachedVersion($version) |
|
268 | + { |
|
269 | + if (!isset($version->error)) { |
|
270 | + set_transient($this->transientName, $version, 3 * HOUR_IN_SECONDS); |
|
271 | + } |
|
272 | + } |
|
273 | 273 | } |
@@ -29,33 +29,33 @@ discard block |
||
29 | 29 | * @param string $apiUrl |
30 | 30 | * @param string $file |
31 | 31 | */ |
32 | - public function __construct($apiUrl, $file, array $data = []) |
|
32 | + public function __construct( $apiUrl, $file, array $data = [] ) |
|
33 | 33 | { |
34 | - if (!function_exists('get_plugin_data')) { |
|
34 | + if( !function_exists( 'get_plugin_data' ) ) { |
|
35 | 35 | require_once ABSPATH.WPINC.'/plugin.php'; |
36 | 36 | } |
37 | - $this->apiUrl = trailingslashit(apply_filters('site-reviews/addon/api-url', $apiUrl)); |
|
38 | - $this->data = wp_parse_args($data, get_plugin_data($file)); |
|
39 | - $this->plugin = plugin_basename($file); |
|
40 | - $this->transientName = Application::PREFIX.md5(Arr::get($data, 'TextDomain')); |
|
37 | + $this->apiUrl = trailingslashit( apply_filters( 'site-reviews/addon/api-url', $apiUrl ) ); |
|
38 | + $this->data = wp_parse_args( $data, get_plugin_data( $file ) ); |
|
39 | + $this->plugin = plugin_basename( $file ); |
|
40 | + $this->transientName = Application::PREFIX.md5( Arr::get( $data, 'TextDomain' ) ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @return object |
45 | 45 | */ |
46 | - public function activateLicense(array $data = []) |
|
46 | + public function activateLicense( array $data = [] ) |
|
47 | 47 | { |
48 | - return $this->request('activate_license', $data); |
|
48 | + return $this->request( 'activate_license', $data ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return object |
53 | 53 | */ |
54 | - public function checkLicense(array $data = []) |
|
54 | + public function checkLicense( array $data = [] ) |
|
55 | 55 | { |
56 | - $response = $this->request('check_license', $data); |
|
57 | - if ('valid' === Arr::get($response, 'license')) { |
|
58 | - $this->getPluginUpdate(true); |
|
56 | + $response = $this->request( 'check_license', $data ); |
|
57 | + if( 'valid' === Arr::get( $response, 'license' ) ) { |
|
58 | + $this->getPluginUpdate( true ); |
|
59 | 59 | } |
60 | 60 | return $response; |
61 | 61 | } |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * @return object |
65 | 65 | */ |
66 | - public function deactivateLicense(array $data = []) |
|
66 | + public function deactivateLicense( array $data = [] ) |
|
67 | 67 | { |
68 | - return $this->request('deactivate_license', $data); |
|
68 | + return $this->request( 'deactivate_license', $data ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * @param object $args |
75 | 75 | * @return mixed |
76 | 76 | */ |
77 | - public function filterPluginUpdateDetails($result, $action, $args) |
|
77 | + public function filterPluginUpdateDetails( $result, $action, $args ) |
|
78 | 78 | { |
79 | - if ('plugin_information' != $action |
|
80 | - || Arr::get($this->data, 'TextDomain') != Arr::get($args, 'slug')) { |
|
79 | + if( 'plugin_information' != $action |
|
80 | + || Arr::get( $this->data, 'TextDomain' ) != Arr::get( $args, 'slug' ) ) { |
|
81 | 81 | return $result; |
82 | 82 | } |
83 | - if ($updateInfo = $this->getPluginUpdate()) { |
|
84 | - return $this->modifyUpdateDetails($updateInfo); |
|
83 | + if( $updateInfo = $this->getPluginUpdate() ) { |
|
84 | + return $this->modifyUpdateDetails( $updateInfo ); |
|
85 | 85 | } |
86 | 86 | return $result; |
87 | 87 | } |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | * @param object $transient |
91 | 91 | * @return object |
92 | 92 | */ |
93 | - public function filterPluginUpdates($transient) |
|
93 | + public function filterPluginUpdates( $transient ) |
|
94 | 94 | { |
95 | - if ($updateInfo = $this->getPluginUpdate()) { |
|
96 | - return $this->modifyPluginUpdates($transient, $updateInfo); |
|
95 | + if( $updateInfo = $this->getPluginUpdate() ) { |
|
96 | + return $this->modifyPluginUpdates( $transient, $updateInfo ); |
|
97 | 97 | } |
98 | 98 | return $transient; |
99 | 99 | } |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * @return object |
103 | 103 | */ |
104 | - public function getVersion(array $data = []) |
|
104 | + public function getVersion( array $data = [] ) |
|
105 | 105 | { |
106 | - return $this->request('get_version', $data); |
|
106 | + return $this->request( 'get_version', $data ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function init() |
113 | 113 | { |
114 | - if ($this->apiUrl === trailingslashit(home_url())) { |
|
114 | + if( $this->apiUrl === trailingslashit( home_url() ) ) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | - add_filter('plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3); |
|
118 | - add_filter('pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999); |
|
119 | - add_action('load-update-core.php', [$this, 'onForceUpdateCheck'], 9); |
|
120 | - add_action('in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink']); |
|
117 | + add_filter( 'plugins_api', [$this, 'filterPluginUpdateDetails'], 10, 3 ); |
|
118 | + add_filter( 'pre_set_site_transient_update_plugins', [$this, 'filterPluginUpdates'], 999 ); |
|
119 | + add_action( 'load-update-core.php', [$this, 'onForceUpdateCheck'], 9 ); |
|
120 | + add_action( 'in_plugin_update_message-'.$this->plugin, [$this, 'renderLicenseMissingLink'] ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public function isLicenseValid() |
127 | 127 | { |
128 | 128 | $result = $this->checkLicense(); |
129 | - return 'valid' === Arr::get($result, 'license'); |
|
129 | + return 'valid' === Arr::get( $result, 'license' ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function onForceUpdateCheck() |
136 | 136 | { |
137 | - if (!filter_input(INPUT_GET, 'force-check')) { |
|
137 | + if( !filter_input( INPUT_GET, 'force-check' ) ) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | - foreach (glsr()->addons as $addon) { |
|
140 | + foreach( glsr()->addons as $addon ) { |
|
141 | 141 | try { |
142 | - glsr($addon)->updater->getPluginUpdate(true); |
|
143 | - } catch (\Exception $e) { |
|
144 | - glsr_log()->error($e->getMessage()); |
|
142 | + glsr( $addon )->updater->getPluginUpdate( true ); |
|
143 | + } catch( \Exception $e ) { |
|
144 | + glsr_log()->error( $e->getMessage() ); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function renderLicenseMissingLink() |
153 | 153 | { |
154 | - if (!$this->isLicenseValid()) { |
|
155 | - glsr()->render('partials/addons/license-missing'); |
|
154 | + if( !$this->isLicenseValid() ) { |
|
155 | + glsr()->render( 'partials/addons/license-missing' ); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -161,22 +161,22 @@ discard block |
||
161 | 161 | */ |
162 | 162 | protected function getCachedVersion() |
163 | 163 | { |
164 | - return get_transient($this->transientName); |
|
164 | + return get_transient( $this->transientName ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | 168 | * @param bool $force |
169 | 169 | * @return false|object |
170 | 170 | */ |
171 | - protected function getPluginUpdate($force = false) |
|
171 | + protected function getPluginUpdate( $force = false ) |
|
172 | 172 | { |
173 | 173 | $version = $this->getCachedVersion(); |
174 | - if (false === $version || $force) { |
|
174 | + if( false === $version || $force ) { |
|
175 | 175 | $version = $this->getVersion(); |
176 | - $this->setCachedVersion($version); |
|
176 | + $this->setCachedVersion( $version ); |
|
177 | 177 | } |
178 | - if (isset($version->error)) { |
|
179 | - glsr_log()->error($version->error); |
|
178 | + if( isset($version->error) ) { |
|
179 | + glsr_log()->error( $version->error ); |
|
180 | 180 | return false; |
181 | 181 | } |
182 | 182 | return $version; |
@@ -187,15 +187,15 @@ discard block |
||
187 | 187 | * @param object $updateInfo |
188 | 188 | * @return object |
189 | 189 | */ |
190 | - protected function modifyPluginUpdates($transient, $updateInfo) |
|
190 | + protected function modifyPluginUpdates( $transient, $updateInfo ) |
|
191 | 191 | { |
192 | - $updateInfo->id = Application::ID.'/'.Arr::get($this->data, 'TextDomain'); |
|
192 | + $updateInfo->id = Application::ID.'/'.Arr::get( $this->data, 'TextDomain' ); |
|
193 | 193 | $updateInfo->plugin = $this->plugin; |
194 | - $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
195 | - $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
196 | - $transient->checked[$this->plugin] = Arr::get($this->data, 'Version'); |
|
194 | + $updateInfo->requires_php = Arr::get( $this->data, 'RequiresPHP' ); |
|
195 | + $updateInfo->tested = Arr::get( $this->data, 'testedTo' ); |
|
196 | + $transient->checked[$this->plugin] = Arr::get( $this->data, 'Version' ); |
|
197 | 197 | $transient->last_checked = time(); |
198 | - if (Helper::isGreaterThan($updateInfo->new_version, Arr::get($this->data, 'Version'))) { |
|
198 | + if( Helper::isGreaterThan( $updateInfo->new_version, Arr::get( $this->data, 'Version' ) ) ) { |
|
199 | 199 | unset($transient->no_update[$this->plugin]); |
200 | 200 | $updateInfo->update = true; |
201 | 201 | $transient->response[$this->plugin] = $updateInfo; |
@@ -210,13 +210,13 @@ discard block |
||
210 | 210 | * @param object $updateInfo |
211 | 211 | * @return object |
212 | 212 | */ |
213 | - protected function modifyUpdateDetails($updateInfo) |
|
213 | + protected function modifyUpdateDetails( $updateInfo ) |
|
214 | 214 | { |
215 | - $updateInfo->author = Arr::get($this->data, 'Author'); |
|
216 | - $updateInfo->author_profile = Arr::get($this->data, 'AuthorURI'); |
|
217 | - $updateInfo->requires = Arr::get($this->data, 'RequiresWP'); |
|
218 | - $updateInfo->requires_php = Arr::get($this->data, 'RequiresPHP'); |
|
219 | - $updateInfo->tested = Arr::get($this->data, 'testedTo'); |
|
215 | + $updateInfo->author = Arr::get( $this->data, 'Author' ); |
|
216 | + $updateInfo->author_profile = Arr::get( $this->data, 'AuthorURI' ); |
|
217 | + $updateInfo->requires = Arr::get( $this->data, 'RequiresWP' ); |
|
218 | + $updateInfo->requires_php = Arr::get( $this->data, 'RequiresPHP' ); |
|
219 | + $updateInfo->tested = Arr::get( $this->data, 'testedTo' ); |
|
220 | 220 | $updateInfo->version = $updateInfo->new_version; |
221 | 221 | return $updateInfo; |
222 | 222 | } |
@@ -225,49 +225,49 @@ discard block |
||
225 | 225 | * @param \WP_Error|array $response |
226 | 226 | * @return object |
227 | 227 | */ |
228 | - protected function normalizeResponse($response) |
|
228 | + protected function normalizeResponse( $response ) |
|
229 | 229 | { |
230 | - $body = wp_remote_retrieve_body($response); |
|
231 | - if ($data = json_decode($body)) { |
|
232 | - $data = array_map('maybe_unserialize', (array) $data); |
|
233 | - return (object) $data; |
|
230 | + $body = wp_remote_retrieve_body( $response ); |
|
231 | + if( $data = json_decode( $body ) ) { |
|
232 | + $data = array_map( 'maybe_unserialize', (array)$data ); |
|
233 | + return (object)$data; |
|
234 | 234 | } |
235 | - $error = is_wp_error($response) |
|
235 | + $error = is_wp_error( $response ) |
|
236 | 236 | ? $response->get_error_message() |
237 | - : 'Update server not responding ('.Arr::get($this->data, 'TextDomain').')'; |
|
238 | - return (object) ['error' => $error]; |
|
237 | + : 'Update server not responding ('.Arr::get( $this->data, 'TextDomain' ).')'; |
|
238 | + return (object)['error' => $error]; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * @param string $action activate_license|check_license|deactivate_license|get_version |
243 | 243 | * @return object |
244 | 244 | */ |
245 | - protected function request($action, array $data = []) |
|
245 | + protected function request( $action, array $data = [] ) |
|
246 | 246 | { |
247 | - $data = wp_parse_args($data, $this->data); |
|
248 | - $response = wp_remote_post($this->apiUrl, [ |
|
247 | + $data = wp_parse_args( $data, $this->data ); |
|
248 | + $response = wp_remote_post( $this->apiUrl, [ |
|
249 | 249 | 'body' => [ |
250 | 250 | 'edd_action' => $action, |
251 | - 'item_id' => Arr::get($data, 'item_id'), |
|
252 | - 'item_name' => Arr::get($data, 'Name'), |
|
253 | - 'license' => Arr::get($data, 'license'), |
|
254 | - 'slug' => Arr::get($data, 'TextDomain'), |
|
251 | + 'item_id' => Arr::get( $data, 'item_id' ), |
|
252 | + 'item_name' => Arr::get( $data, 'Name' ), |
|
253 | + 'license' => Arr::get( $data, 'license' ), |
|
254 | + 'slug' => Arr::get( $data, 'TextDomain' ), |
|
255 | 255 | 'url' => home_url(), |
256 | 256 | ], |
257 | - 'sslverify' => apply_filters('site-reviews/sslverify/post', false), |
|
257 | + 'sslverify' => apply_filters( 'site-reviews/sslverify/post', false ), |
|
258 | 258 | 'timeout' => 15, |
259 | - ]); |
|
260 | - return $this->normalizeResponse($response); |
|
259 | + ] ); |
|
260 | + return $this->normalizeResponse( $response ); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
264 | 264 | * @param object $version |
265 | 265 | * @return void |
266 | 266 | */ |
267 | - protected function setCachedVersion($version) |
|
267 | + protected function setCachedVersion( $version ) |
|
268 | 268 | { |
269 | - if (!isset($version->error)) { |
|
270 | - set_transient($this->transientName, $version, 3 * HOUR_IN_SECONDS); |
|
269 | + if( !isset($version->error) ) { |
|
270 | + set_transient( $this->transientName, $version, 3 * HOUR_IN_SECONDS ); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | } |
@@ -7,160 +7,160 @@ |
||
7 | 7 | |
8 | 8 | class Migrate_3_0_0 |
9 | 9 | { |
10 | - const MAPPED_SETTINGS = [ |
|
11 | - 'settings.general.notification' => 'settings.general.notifications', // array |
|
12 | - 'settings.general.notification_email' => 'settings.general.notification_email', |
|
13 | - 'settings.general.notification_message' => 'settings.general.notification_message', |
|
14 | - 'settings.general.require.approval' => 'settings.general.require.approval', |
|
15 | - 'settings.general.require.login' => 'settings.general.require.login', |
|
16 | - 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
17 | - 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
18 | - 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
19 | - 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
20 | - 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
21 | - 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
22 | - 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
23 | - 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
24 | - 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
25 | - 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
26 | - 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
27 | - 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
28 | - 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
29 | - 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
30 | - 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
31 | - 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
32 | - 'settings.reviews.schema.address' => 'settings.schema.address', |
|
33 | - 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
34 | - 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
35 | - 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
36 | - 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
37 | - 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
38 | - 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
39 | - 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
40 | - 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
41 | - 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
42 | - 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
43 | - 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
44 | - 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
45 | - 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
46 | - 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
47 | - 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
48 | - 'version' => 'version_upgraded_from', |
|
49 | - ]; |
|
10 | + const MAPPED_SETTINGS = [ |
|
11 | + 'settings.general.notification' => 'settings.general.notifications', // array |
|
12 | + 'settings.general.notification_email' => 'settings.general.notification_email', |
|
13 | + 'settings.general.notification_message' => 'settings.general.notification_message', |
|
14 | + 'settings.general.require.approval' => 'settings.general.require.approval', |
|
15 | + 'settings.general.require.login' => 'settings.general.require.login', |
|
16 | + 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
17 | + 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
18 | + 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
19 | + 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
20 | + 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
21 | + 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
22 | + 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
23 | + 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
24 | + 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
25 | + 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
26 | + 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
27 | + 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
28 | + 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
29 | + 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
30 | + 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
31 | + 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
32 | + 'settings.reviews.schema.address' => 'settings.schema.address', |
|
33 | + 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
34 | + 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
35 | + 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
36 | + 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
37 | + 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
38 | + 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
39 | + 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
40 | + 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
41 | + 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
42 | + 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
43 | + 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
44 | + 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
45 | + 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
46 | + 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
47 | + 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
48 | + 'version' => 'version_upgraded_from', |
|
49 | + ]; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - protected $newSettings; |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + protected $newSettings; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $oldSettings; |
|
56 | + /** |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $oldSettings; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public function migrateSettings() |
|
65 | - { |
|
66 | - $this->newSettings = $this->getNewSettings(); |
|
67 | - $this->oldSettings = $this->getOldSettings(); |
|
68 | - if (empty($this->oldSettings) || empty($this->newSettings)) { |
|
69 | - return; |
|
70 | - } |
|
71 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
72 | - if (empty($this->oldSettings[$old])) { |
|
73 | - continue; |
|
74 | - } |
|
75 | - $this->newSettings[$new] = $this->oldSettings[$old]; |
|
76 | - } |
|
77 | - $this->migrateNotificationSettings(); |
|
78 | - $this->migrateRecaptchaSettings(); |
|
79 | - $this->migrateRequiredSettings(); |
|
80 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
81 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
82 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
83 | - $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
84 | - } |
|
85 | - update_option(OptionManager::databaseKey(3), $newSettings); |
|
86 | - } |
|
61 | + /** |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public function migrateSettings() |
|
65 | + { |
|
66 | + $this->newSettings = $this->getNewSettings(); |
|
67 | + $this->oldSettings = $this->getOldSettings(); |
|
68 | + if (empty($this->oldSettings) || empty($this->newSettings)) { |
|
69 | + return; |
|
70 | + } |
|
71 | + foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
72 | + if (empty($this->oldSettings[$old])) { |
|
73 | + continue; |
|
74 | + } |
|
75 | + $this->newSettings[$new] = $this->oldSettings[$old]; |
|
76 | + } |
|
77 | + $this->migrateNotificationSettings(); |
|
78 | + $this->migrateRecaptchaSettings(); |
|
79 | + $this->migrateRequiredSettings(); |
|
80 | + $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
81 | + $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
82 | + if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
83 | + $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
84 | + } |
|
85 | + update_option(OptionManager::databaseKey(3), $newSettings); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function run() |
|
92 | - { |
|
93 | - $this->migrateSettings(); |
|
94 | - } |
|
88 | + /** |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function run() |
|
92 | + { |
|
93 | + $this->migrateSettings(); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - protected function getNewSettings() |
|
100 | - { |
|
101 | - return Arr::flattenArray(Arr::consolidateArray(OptionManager::databaseKey(3))); |
|
102 | - } |
|
96 | + /** |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + protected function getNewSettings() |
|
100 | + { |
|
101 | + return Arr::flattenArray(Arr::consolidateArray(OptionManager::databaseKey(3))); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - protected function getOldSettings() |
|
108 | - { |
|
109 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
110 | - $settings = Arr::consolidateArray(get_option(OptionManager::databaseKey(2))); |
|
111 | - $settings = Arr::flattenArray($settings); |
|
112 | - return !empty($settings) |
|
113 | - ? wp_parse_args($settings, $defaults) |
|
114 | - : []; |
|
115 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + protected function getOldSettings() |
|
108 | + { |
|
109 | + $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
110 | + $settings = Arr::consolidateArray(get_option(OptionManager::databaseKey(2))); |
|
111 | + $settings = Arr::flattenArray($settings); |
|
112 | + return !empty($settings) |
|
113 | + ? wp_parse_args($settings, $defaults) |
|
114 | + : []; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - protected function migrateNotificationSettings() |
|
121 | - { |
|
122 | - $notifications = [ |
|
123 | - 'custom' => 'custom', |
|
124 | - 'default' => 'admin', |
|
125 | - 'webhook' => 'slack', |
|
126 | - ]; |
|
127 | - $this->newSettings['settings.general.notifications'] = []; |
|
128 | - foreach ($notifications as $old => $new) { |
|
129 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
130 | - continue; |
|
131 | - } |
|
132 | - $this->newSettings['settings.general.notifications'][] = $new; |
|
133 | - } |
|
134 | - } |
|
117 | + /** |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + protected function migrateNotificationSettings() |
|
121 | + { |
|
122 | + $notifications = [ |
|
123 | + 'custom' => 'custom', |
|
124 | + 'default' => 'admin', |
|
125 | + 'webhook' => 'slack', |
|
126 | + ]; |
|
127 | + $this->newSettings['settings.general.notifications'] = []; |
|
128 | + foreach ($notifications as $old => $new) { |
|
129 | + if ($this->oldSettings['settings.general.notification'] != $old) { |
|
130 | + continue; |
|
131 | + } |
|
132 | + $this->newSettings['settings.general.notifications'][] = $new; |
|
133 | + } |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * @return void |
|
138 | - */ |
|
139 | - protected function migrateRecaptchaSettings() |
|
140 | - { |
|
141 | - $recaptcha = [ |
|
142 | - 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
143 | - 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
144 | - 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
145 | - ]; |
|
146 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
147 | - $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
148 | - } |
|
149 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
150 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
151 | - } |
|
152 | - $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
153 | - $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
154 | - $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
155 | - } |
|
136 | + /** |
|
137 | + * @return void |
|
138 | + */ |
|
139 | + protected function migrateRecaptchaSettings() |
|
140 | + { |
|
141 | + $recaptcha = [ |
|
142 | + 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
143 | + 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
144 | + 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
145 | + ]; |
|
146 | + if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
147 | + $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
148 | + } |
|
149 | + if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
150 | + $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
151 | + } |
|
152 | + $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
153 | + $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
154 | + $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - protected function migrateRequiredSettings() |
|
161 | - { |
|
162 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
163 | - $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
164 | - $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
165 | - } |
|
157 | + /** |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + protected function migrateRequiredSettings() |
|
161 | + { |
|
162 | + $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
163 | + $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
164 | + $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
165 | + } |
|
166 | 166 | } |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | { |
66 | 66 | $this->newSettings = $this->getNewSettings(); |
67 | 67 | $this->oldSettings = $this->getOldSettings(); |
68 | - if (empty($this->oldSettings) || empty($this->newSettings)) { |
|
68 | + if( empty($this->oldSettings) || empty($this->newSettings) ) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
72 | - if (empty($this->oldSettings[$old])) { |
|
71 | + foreach( static::MAPPED_SETTINGS as $old => $new ) { |
|
72 | + if( empty($this->oldSettings[$old]) ) { |
|
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | $this->newSettings[$new] = $this->oldSettings[$old]; |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | $this->migrateNotificationSettings(); |
78 | 78 | $this->migrateRecaptchaSettings(); |
79 | 79 | $this->migrateRequiredSettings(); |
80 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
81 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
82 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
80 | + $oldSettings = Arr::convertDotNotationArray( $this->oldSettings ); |
|
81 | + $newSettings = Arr::convertDotNotationArray( $this->newSettings ); |
|
82 | + if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) { |
|
83 | 83 | $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
84 | 84 | } |
85 | - update_option(OptionManager::databaseKey(3), $newSettings); |
|
85 | + update_option( OptionManager::databaseKey( 3 ), $newSettings ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function getNewSettings() |
100 | 100 | { |
101 | - return Arr::flattenArray(Arr::consolidateArray(OptionManager::databaseKey(3))); |
|
101 | + return Arr::flattenArray( Arr::consolidateArray( OptionManager::databaseKey( 3 ) ) ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function getOldSettings() |
108 | 108 | { |
109 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
110 | - $settings = Arr::consolidateArray(get_option(OptionManager::databaseKey(2))); |
|
111 | - $settings = Arr::flattenArray($settings); |
|
109 | + $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' ); |
|
110 | + $settings = Arr::consolidateArray( get_option( OptionManager::databaseKey( 2 ) ) ); |
|
111 | + $settings = Arr::flattenArray( $settings ); |
|
112 | 112 | return !empty($settings) |
113 | - ? wp_parse_args($settings, $defaults) |
|
113 | + ? wp_parse_args( $settings, $defaults ) |
|
114 | 114 | : []; |
115 | 115 | } |
116 | 116 | |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | 'webhook' => 'slack', |
126 | 126 | ]; |
127 | 127 | $this->newSettings['settings.general.notifications'] = []; |
128 | - foreach ($notifications as $old => $new) { |
|
129 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
128 | + foreach( $notifications as $old => $new ) { |
|
129 | + if( $this->oldSettings['settings.general.notification'] != $old ) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | 132 | $this->newSettings['settings.general.notifications'][] = $new; |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
144 | 144 | 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
145 | 145 | ]; |
146 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
146 | + if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) { |
|
147 | 147 | $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
148 | 148 | } |
149 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
150 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
149 | + if( 'invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration'] ) { |
|
150 | + $recaptcha = wp_parse_args( (array)get_site_option( 'ic-settings', [], false ), $recaptcha ); |
|
151 | 151 | } |
152 | 152 | $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
153 | 153 | $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | protected function migrateRequiredSettings() |
161 | 161 | { |
162 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
162 | + $this->newSettings['settings.submissions.required'] = array_filter( (array)$this->oldSettings['settings.reviews-form.required'] ); |
|
163 | 163 | $this->newSettings['settings.submissions.required'][] = 'rating'; |
164 | 164 | $this->newSettings['settings.submissions.required'][] = 'terms'; |
165 | 165 | } |
@@ -9,75 +9,75 @@ |
||
9 | 9 | |
10 | 10 | class Wpml implements Contract |
11 | 11 | { |
12 | - public $pluginName = 'WPML'; |
|
13 | - public $supportedVersion = '3.3.5'; |
|
12 | + public $pluginName = 'WPML'; |
|
13 | + public $supportedVersion = '3.3.5'; |
|
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - public function getPostId($postId) |
|
19 | - { |
|
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
22 | - return 0; |
|
23 | - } |
|
24 | - if ($this->isEnabled()) { |
|
25 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
26 | - } |
|
27 | - return intval($postId); |
|
28 | - } |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + public function getPostId($postId) |
|
19 | + { |
|
20 | + $postId = trim($postId); |
|
21 | + if (!is_numeric($postId)) { |
|
22 | + return 0; |
|
23 | + } |
|
24 | + if ($this->isEnabled()) { |
|
25 | + $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
26 | + } |
|
27 | + return intval($postId); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public function getPostIds(array $postIds) |
|
34 | - { |
|
35 | - if (!$this->isEnabled()) { |
|
36 | - return $postIds; |
|
37 | - } |
|
38 | - $newPostIds = []; |
|
39 | - foreach (Arr::unique($postIds) as $postId) { |
|
40 | - $postType = get_post_type($postId); |
|
41 | - if (!$postType) { |
|
42 | - continue; |
|
43 | - } |
|
44 | - $elementType = 'post_'.$postType; |
|
45 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
46 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
47 | - if (!is_array($translations)) { |
|
48 | - $translations = []; |
|
49 | - } |
|
50 | - $newPostIds = array_merge( |
|
51 | - $newPostIds, |
|
52 | - array_column($translations, 'element_id') |
|
53 | - ); |
|
54 | - } |
|
55 | - return Arr::unique($newPostIds); |
|
56 | - } |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public function getPostIds(array $postIds) |
|
34 | + { |
|
35 | + if (!$this->isEnabled()) { |
|
36 | + return $postIds; |
|
37 | + } |
|
38 | + $newPostIds = []; |
|
39 | + foreach (Arr::unique($postIds) as $postId) { |
|
40 | + $postType = get_post_type($postId); |
|
41 | + if (!$postType) { |
|
42 | + continue; |
|
43 | + } |
|
44 | + $elementType = 'post_'.$postType; |
|
45 | + $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
46 | + $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
47 | + if (!is_array($translations)) { |
|
48 | + $translations = []; |
|
49 | + } |
|
50 | + $newPostIds = array_merge( |
|
51 | + $newPostIds, |
|
52 | + array_column($translations, 'element_id') |
|
53 | + ); |
|
54 | + } |
|
55 | + return Arr::unique($newPostIds); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritdoc} |
|
60 | - */ |
|
61 | - public function isActive() |
|
62 | - { |
|
63 | - return defined('ICL_SITEPRESS_VERSION'); |
|
64 | - } |
|
58 | + /** |
|
59 | + * {@inheritdoc} |
|
60 | + */ |
|
61 | + public function isActive() |
|
62 | + { |
|
63 | + return defined('ICL_SITEPRESS_VERSION'); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * {@inheritdoc} |
|
68 | - */ |
|
69 | - public function isEnabled() |
|
70 | - { |
|
71 | - return $this->isActive() |
|
72 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
73 | - } |
|
66 | + /** |
|
67 | + * {@inheritdoc} |
|
68 | + */ |
|
69 | + public function isEnabled() |
|
70 | + { |
|
71 | + return $this->isActive() |
|
72 | + && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * {@inheritdoc} |
|
77 | - */ |
|
78 | - public function isSupported() |
|
79 | - { |
|
80 | - return $this->isActive() |
|
81 | - && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
82 | - } |
|
75 | + /** |
|
76 | + * {@inheritdoc} |
|
77 | + */ |
|
78 | + public function isSupported() |
|
79 | + { |
|
80 | + return $this->isActive() |
|
81 | + && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
82 | + } |
|
83 | 83 | } |
@@ -15,44 +15,44 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * {@inheritdoc} |
17 | 17 | */ |
18 | - public function getPostId($postId) |
|
18 | + public function getPostId( $postId ) |
|
19 | 19 | { |
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
20 | + $postId = trim( $postId ); |
|
21 | + if( !is_numeric( $postId ) ) { |
|
22 | 22 | return 0; |
23 | 23 | } |
24 | - if ($this->isEnabled()) { |
|
25 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | + if( $this->isEnabled() ) { |
|
25 | + $postId = apply_filters( 'wpml_object_id', $postId, 'any', true ); |
|
26 | 26 | } |
27 | - return intval($postId); |
|
27 | + return intval( $postId ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * {@inheritdoc} |
32 | 32 | */ |
33 | - public function getPostIds(array $postIds) |
|
33 | + public function getPostIds( array $postIds ) |
|
34 | 34 | { |
35 | - if (!$this->isEnabled()) { |
|
35 | + if( !$this->isEnabled() ) { |
|
36 | 36 | return $postIds; |
37 | 37 | } |
38 | 38 | $newPostIds = []; |
39 | - foreach (Arr::unique($postIds) as $postId) { |
|
40 | - $postType = get_post_type($postId); |
|
41 | - if (!$postType) { |
|
39 | + foreach( Arr::unique( $postIds ) as $postId ) { |
|
40 | + $postType = get_post_type( $postId ); |
|
41 | + if( !$postType ) { |
|
42 | 42 | continue; |
43 | 43 | } |
44 | 44 | $elementType = 'post_'.$postType; |
45 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
46 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
47 | - if (!is_array($translations)) { |
|
45 | + $trid = apply_filters( 'wpml_element_trid', null, $postId, $elementType ); |
|
46 | + $translations = apply_filters( 'wpml_get_element_translations', null, $trid, $elementType ); |
|
47 | + if( !is_array( $translations ) ) { |
|
48 | 48 | $translations = []; |
49 | 49 | } |
50 | 50 | $newPostIds = array_merge( |
51 | 51 | $newPostIds, |
52 | - array_column($translations, 'element_id') |
|
52 | + array_column( $translations, 'element_id' ) |
|
53 | 53 | ); |
54 | 54 | } |
55 | - return Arr::unique($newPostIds); |
|
55 | + return Arr::unique( $newPostIds ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function isActive() |
62 | 62 | { |
63 | - return defined('ICL_SITEPRESS_VERSION'); |
|
63 | + return defined( 'ICL_SITEPRESS_VERSION' ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function isEnabled() |
70 | 70 | { |
71 | 71 | return $this->isActive() |
72 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
72 | + && 'wpml' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -78,6 +78,6 @@ discard block |
||
78 | 78 | public function isSupported() |
79 | 79 | { |
80 | 80 | return $this->isActive() |
81 | - && Helper::isGreaterThanOrEqual(ICL_SITEPRESS_VERSION, $this->supportedVersion); |
|
81 | + && Helper::isGreaterThanOrEqual( ICL_SITEPRESS_VERSION, $this->supportedVersion ); |
|
82 | 82 | } |
83 | 83 | } |
@@ -9,71 +9,71 @@ |
||
9 | 9 | |
10 | 10 | class Polylang implements Contract |
11 | 11 | { |
12 | - public $pluginName = 'Polylang'; |
|
13 | - public $supportedVersion = '2.3'; |
|
12 | + public $pluginName = 'Polylang'; |
|
13 | + public $supportedVersion = '2.3'; |
|
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - public function getPostId($postId) |
|
19 | - { |
|
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
22 | - return 0; |
|
23 | - } |
|
24 | - if ($this->isEnabled()) { |
|
25 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
26 | - } |
|
27 | - if (!empty($polylangPostId)) { |
|
28 | - $postId = $polylangPostId; |
|
29 | - } |
|
30 | - return intval($postId); |
|
31 | - } |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + public function getPostId($postId) |
|
19 | + { |
|
20 | + $postId = trim($postId); |
|
21 | + if (!is_numeric($postId)) { |
|
22 | + return 0; |
|
23 | + } |
|
24 | + if ($this->isEnabled()) { |
|
25 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
26 | + } |
|
27 | + if (!empty($polylangPostId)) { |
|
28 | + $postId = $polylangPostId; |
|
29 | + } |
|
30 | + return intval($postId); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritdoc} |
|
35 | - */ |
|
36 | - public function getPostIds(array $postIds) |
|
37 | - { |
|
38 | - if (!$this->isEnabled()) { |
|
39 | - return $postIds; |
|
40 | - } |
|
41 | - $newPostIds = []; |
|
42 | - foreach (Arr::unique($postIds) as $postId) { |
|
43 | - $newPostIds = array_merge( |
|
44 | - $newPostIds, |
|
45 | - array_values(pll_get_post_translations($postId)) |
|
46 | - ); |
|
47 | - } |
|
48 | - return Arr::unique($newPostIds); |
|
49 | - } |
|
33 | + /** |
|
34 | + * {@inheritdoc} |
|
35 | + */ |
|
36 | + public function getPostIds(array $postIds) |
|
37 | + { |
|
38 | + if (!$this->isEnabled()) { |
|
39 | + return $postIds; |
|
40 | + } |
|
41 | + $newPostIds = []; |
|
42 | + foreach (Arr::unique($postIds) as $postId) { |
|
43 | + $newPostIds = array_merge( |
|
44 | + $newPostIds, |
|
45 | + array_values(pll_get_post_translations($postId)) |
|
46 | + ); |
|
47 | + } |
|
48 | + return Arr::unique($newPostIds); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * {@inheritdoc} |
|
53 | - */ |
|
54 | - public function isActive() |
|
55 | - { |
|
56 | - return function_exists('PLL') |
|
57 | - && function_exists('pll_get_post') |
|
58 | - && function_exists('pll_get_post_language') |
|
59 | - && function_exists('pll_get_post_translations'); |
|
60 | - } |
|
51 | + /** |
|
52 | + * {@inheritdoc} |
|
53 | + */ |
|
54 | + public function isActive() |
|
55 | + { |
|
56 | + return function_exists('PLL') |
|
57 | + && function_exists('pll_get_post') |
|
58 | + && function_exists('pll_get_post_language') |
|
59 | + && function_exists('pll_get_post_translations'); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritdoc} |
|
64 | - */ |
|
65 | - public function isEnabled() |
|
66 | - { |
|
67 | - return $this->isActive() |
|
68 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
69 | - } |
|
62 | + /** |
|
63 | + * {@inheritdoc} |
|
64 | + */ |
|
65 | + public function isEnabled() |
|
66 | + { |
|
67 | + return $this->isActive() |
|
68 | + && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * {@inheritdoc} |
|
73 | - */ |
|
74 | - public function isSupported() |
|
75 | - { |
|
76 | - return defined('POLYLANG_VERSION') |
|
77 | - && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion); |
|
78 | - } |
|
71 | + /** |
|
72 | + * {@inheritdoc} |
|
73 | + */ |
|
74 | + public function isSupported() |
|
75 | + { |
|
76 | + return defined('POLYLANG_VERSION') |
|
77 | + && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion); |
|
78 | + } |
|
79 | 79 | } |
@@ -15,37 +15,37 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * {@inheritdoc} |
17 | 17 | */ |
18 | - public function getPostId($postId) |
|
18 | + public function getPostId( $postId ) |
|
19 | 19 | { |
20 | - $postId = trim($postId); |
|
21 | - if (!is_numeric($postId)) { |
|
20 | + $postId = trim( $postId ); |
|
21 | + if( !is_numeric( $postId ) ) { |
|
22 | 22 | return 0; |
23 | 23 | } |
24 | - if ($this->isEnabled()) { |
|
25 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | + if( $this->isEnabled() ) { |
|
25 | + $polylangPostId = pll_get_post( $postId, pll_get_post_language( get_the_ID() ) ); |
|
26 | 26 | } |
27 | - if (!empty($polylangPostId)) { |
|
27 | + if( !empty($polylangPostId) ) { |
|
28 | 28 | $postId = $polylangPostId; |
29 | 29 | } |
30 | - return intval($postId); |
|
30 | + return intval( $postId ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * {@inheritdoc} |
35 | 35 | */ |
36 | - public function getPostIds(array $postIds) |
|
36 | + public function getPostIds( array $postIds ) |
|
37 | 37 | { |
38 | - if (!$this->isEnabled()) { |
|
38 | + if( !$this->isEnabled() ) { |
|
39 | 39 | return $postIds; |
40 | 40 | } |
41 | 41 | $newPostIds = []; |
42 | - foreach (Arr::unique($postIds) as $postId) { |
|
42 | + foreach( Arr::unique( $postIds ) as $postId ) { |
|
43 | 43 | $newPostIds = array_merge( |
44 | 44 | $newPostIds, |
45 | - array_values(pll_get_post_translations($postId)) |
|
45 | + array_values( pll_get_post_translations( $postId ) ) |
|
46 | 46 | ); |
47 | 47 | } |
48 | - return Arr::unique($newPostIds); |
|
48 | + return Arr::unique( $newPostIds ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function isActive() |
55 | 55 | { |
56 | - return function_exists('PLL') |
|
57 | - && function_exists('pll_get_post') |
|
58 | - && function_exists('pll_get_post_language') |
|
59 | - && function_exists('pll_get_post_translations'); |
|
56 | + return function_exists( 'PLL' ) |
|
57 | + && function_exists( 'pll_get_post' ) |
|
58 | + && function_exists( 'pll_get_post_language' ) |
|
59 | + && function_exists( 'pll_get_post_translations' ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | public function isEnabled() |
66 | 66 | { |
67 | 67 | return $this->isActive() |
68 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.multilingual'); |
|
68 | + && 'polylang' == glsr( OptionManager::class )->get( 'settings.general.multilingual' ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function isSupported() |
75 | 75 | { |
76 | - return defined('POLYLANG_VERSION') |
|
77 | - && Helper::isGreaterThanOrEqual(POLYLANG_VERSION, $this->supportedVersion); |
|
76 | + return defined( 'POLYLANG_VERSION' ) |
|
77 | + && Helper::isGreaterThanOrEqual( POLYLANG_VERSION, $this->supportedVersion ); |
|
78 | 78 | } |
79 | 79 | } |
@@ -8,218 +8,218 @@ |
||
8 | 8 | |
9 | 9 | class Helper |
10 | 10 | { |
11 | - /** |
|
12 | - * @param string $name |
|
13 | - * @param string $path |
|
14 | - * @return string |
|
15 | - */ |
|
16 | - public static function buildClassName($name, $path = '') |
|
17 | - { |
|
18 | - $className = Str::camelCase($name); |
|
19 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
20 | - return !empty($path) |
|
21 | - ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
22 | - : $className; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @param string $name |
|
27 | - * @param string $prefix |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public static function buildMethodName($name, $prefix = '') |
|
31 | - { |
|
32 | - return lcfirst($prefix.static::buildClassName($name)); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @param string $name |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public static function buildPropertyName($name) |
|
40 | - { |
|
41 | - return static::buildMethodName($name); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param string $cast |
|
46 | - * @param mixed $value |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public static function castTo($cast = '', $value) |
|
50 | - { |
|
51 | - $method = static::buildMethodName($cast, 'castTo'); |
|
52 | - return !empty($cast) && method_exists(__CLASS__, $method) |
|
53 | - ? static::$method($value) |
|
54 | - : $value; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param mixed $value |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public static function castToArray($value) |
|
62 | - { |
|
63 | - return (array) $value; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @param mixed $value |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public static function castToBool($value) |
|
71 | - { |
|
72 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param mixed $value |
|
77 | - * @return float |
|
78 | - */ |
|
79 | - public static function castToFloat($value) |
|
80 | - { |
|
81 | - return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param mixed $value |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public static function castToInt($value) |
|
89 | - { |
|
90 | - return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param mixed $value |
|
95 | - * @return object |
|
96 | - */ |
|
97 | - public static function castToObject($value) |
|
98 | - { |
|
99 | - return (object) (array) $value; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param mixed $value |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public static function castToString($value) |
|
107 | - { |
|
108 | - if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
109 | - return (string) $value->__toString(); |
|
110 | - } |
|
111 | - if (is_array($value) || is_object($value)) { |
|
112 | - return serialize($value); |
|
113 | - } |
|
114 | - return (string) $value; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $key |
|
119 | - * @return mixed |
|
120 | - */ |
|
121 | - public static function filterInput($key, array $request = []) |
|
122 | - { |
|
123 | - if (isset($request[$key])) { |
|
124 | - return $request[$key]; |
|
125 | - } |
|
126 | - $variable = filter_input(INPUT_POST, $key); |
|
127 | - if (is_null($variable) && isset($_POST[$key])) { |
|
128 | - $variable = $_POST[$key]; |
|
129 | - } |
|
130 | - return $variable; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $key |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public static function filterInputArray($key) |
|
138 | - { |
|
139 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
140 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
141 | - $variable = $_POST[$key]; |
|
142 | - } |
|
143 | - return (array) $variable; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public static function getIpAddress() |
|
150 | - { |
|
151 | - $whitelist = []; |
|
152 | - $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
153 | - if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
154 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
155 | - $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
|
156 | - if (defined('AF_INET6')) { |
|
157 | - $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
|
158 | - } |
|
159 | - } |
|
160 | - $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
161 | - $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
162 | - $whip = new Whip($methods, $whitelist); |
|
163 | - do_action_ref_array('site-reviews/whip', [$whip]); |
|
164 | - if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
165 | - return (string) $clientAddress; |
|
166 | - } |
|
167 | - glsr_log()->error('Unable to detect IP address.'); |
|
168 | - return 'unknown'; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param mixed $value |
|
173 | - * @param string|int $min |
|
174 | - * @param string|int $max |
|
175 | - * @return bool |
|
176 | - */ |
|
177 | - public static function inRange($value, $min, $max) |
|
178 | - { |
|
179 | - $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | - 'min_range' => intval($min), |
|
181 | - 'max_range' => intval($max), |
|
182 | - ]]); |
|
183 | - return false !== $inRange; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @param int|string $value |
|
188 | - * @param int|string $compareWithValue |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public static function isGreaterThan($value, $compareWithValue) |
|
192 | - { |
|
193 | - return version_compare($value, $compareWithValue, '>'); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param int|string $value |
|
198 | - * @param int|string $compareWithValue |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public static function isGreaterThanOrEqual($value, $compareWithValue) |
|
202 | - { |
|
203 | - return version_compare($value, $compareWithValue, '>='); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param int|string $value |
|
208 | - * @param int|string $compareWithValue |
|
209 | - * @return bool |
|
210 | - */ |
|
211 | - public static function isLessThan($value, $compareWithValue) |
|
212 | - { |
|
213 | - return version_compare($value, $compareWithValue, '<'); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @param int|string $value |
|
218 | - * @param int|string $compareWithValue |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public static function isLessThanOrEqual($value, $compareWithValue) |
|
222 | - { |
|
223 | - return version_compare($value, $compareWithValue, '<='); |
|
224 | - } |
|
11 | + /** |
|
12 | + * @param string $name |
|
13 | + * @param string $path |
|
14 | + * @return string |
|
15 | + */ |
|
16 | + public static function buildClassName($name, $path = '') |
|
17 | + { |
|
18 | + $className = Str::camelCase($name); |
|
19 | + $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
20 | + return !empty($path) |
|
21 | + ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
22 | + : $className; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @param string $name |
|
27 | + * @param string $prefix |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public static function buildMethodName($name, $prefix = '') |
|
31 | + { |
|
32 | + return lcfirst($prefix.static::buildClassName($name)); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @param string $name |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public static function buildPropertyName($name) |
|
40 | + { |
|
41 | + return static::buildMethodName($name); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param string $cast |
|
46 | + * @param mixed $value |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public static function castTo($cast = '', $value) |
|
50 | + { |
|
51 | + $method = static::buildMethodName($cast, 'castTo'); |
|
52 | + return !empty($cast) && method_exists(__CLASS__, $method) |
|
53 | + ? static::$method($value) |
|
54 | + : $value; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param mixed $value |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public static function castToArray($value) |
|
62 | + { |
|
63 | + return (array) $value; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @param mixed $value |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public static function castToBool($value) |
|
71 | + { |
|
72 | + return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param mixed $value |
|
77 | + * @return float |
|
78 | + */ |
|
79 | + public static function castToFloat($value) |
|
80 | + { |
|
81 | + return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param mixed $value |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public static function castToInt($value) |
|
89 | + { |
|
90 | + return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param mixed $value |
|
95 | + * @return object |
|
96 | + */ |
|
97 | + public static function castToObject($value) |
|
98 | + { |
|
99 | + return (object) (array) $value; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param mixed $value |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public static function castToString($value) |
|
107 | + { |
|
108 | + if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
109 | + return (string) $value->__toString(); |
|
110 | + } |
|
111 | + if (is_array($value) || is_object($value)) { |
|
112 | + return serialize($value); |
|
113 | + } |
|
114 | + return (string) $value; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $key |
|
119 | + * @return mixed |
|
120 | + */ |
|
121 | + public static function filterInput($key, array $request = []) |
|
122 | + { |
|
123 | + if (isset($request[$key])) { |
|
124 | + return $request[$key]; |
|
125 | + } |
|
126 | + $variable = filter_input(INPUT_POST, $key); |
|
127 | + if (is_null($variable) && isset($_POST[$key])) { |
|
128 | + $variable = $_POST[$key]; |
|
129 | + } |
|
130 | + return $variable; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $key |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public static function filterInputArray($key) |
|
138 | + { |
|
139 | + $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
140 | + if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
141 | + $variable = $_POST[$key]; |
|
142 | + } |
|
143 | + return (array) $variable; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public static function getIpAddress() |
|
150 | + { |
|
151 | + $whitelist = []; |
|
152 | + $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
153 | + if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
154 | + $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
155 | + $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
|
156 | + if (defined('AF_INET6')) { |
|
157 | + $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
|
158 | + } |
|
159 | + } |
|
160 | + $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
161 | + $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
162 | + $whip = new Whip($methods, $whitelist); |
|
163 | + do_action_ref_array('site-reviews/whip', [$whip]); |
|
164 | + if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
165 | + return (string) $clientAddress; |
|
166 | + } |
|
167 | + glsr_log()->error('Unable to detect IP address.'); |
|
168 | + return 'unknown'; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param mixed $value |
|
173 | + * @param string|int $min |
|
174 | + * @param string|int $max |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | + public static function inRange($value, $min, $max) |
|
178 | + { |
|
179 | + $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | + 'min_range' => intval($min), |
|
181 | + 'max_range' => intval($max), |
|
182 | + ]]); |
|
183 | + return false !== $inRange; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @param int|string $value |
|
188 | + * @param int|string $compareWithValue |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public static function isGreaterThan($value, $compareWithValue) |
|
192 | + { |
|
193 | + return version_compare($value, $compareWithValue, '>'); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param int|string $value |
|
198 | + * @param int|string $compareWithValue |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public static function isGreaterThanOrEqual($value, $compareWithValue) |
|
202 | + { |
|
203 | + return version_compare($value, $compareWithValue, '>='); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param int|string $value |
|
208 | + * @param int|string $compareWithValue |
|
209 | + * @return bool |
|
210 | + */ |
|
211 | + public static function isLessThan($value, $compareWithValue) |
|
212 | + { |
|
213 | + return version_compare($value, $compareWithValue, '<'); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @param int|string $value |
|
218 | + * @param int|string $compareWithValue |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public static function isLessThanOrEqual($value, $compareWithValue) |
|
222 | + { |
|
223 | + return version_compare($value, $compareWithValue, '<='); |
|
224 | + } |
|
225 | 225 | } |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | * @param string $path |
14 | 14 | * @return string |
15 | 15 | */ |
16 | - public static function buildClassName($name, $path = '') |
|
16 | + public static function buildClassName( $name, $path = '' ) |
|
17 | 17 | { |
18 | - $className = Str::camelCase($name); |
|
19 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
18 | + $className = Str::camelCase( $name ); |
|
19 | + $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' ); |
|
20 | 20 | return !empty($path) |
21 | 21 | ? __NAMESPACE__.'\\'.$path.'\\'.$className |
22 | 22 | : $className; |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | * @param string $prefix |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - public static function buildMethodName($name, $prefix = '') |
|
30 | + public static function buildMethodName( $name, $prefix = '' ) |
|
31 | 31 | { |
32 | - return lcfirst($prefix.static::buildClassName($name)); |
|
32 | + return lcfirst( $prefix.static::buildClassName( $name ) ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @param string $name |
37 | 37 | * @return string |
38 | 38 | */ |
39 | - public static function buildPropertyName($name) |
|
39 | + public static function buildPropertyName( $name ) |
|
40 | 40 | { |
41 | - return static::buildMethodName($name); |
|
41 | + return static::buildMethodName( $name ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | * @param mixed $value |
47 | 47 | * @return mixed |
48 | 48 | */ |
49 | - public static function castTo($cast = '', $value) |
|
49 | + public static function castTo( $cast = '', $value ) |
|
50 | 50 | { |
51 | - $method = static::buildMethodName($cast, 'castTo'); |
|
52 | - return !empty($cast) && method_exists(__CLASS__, $method) |
|
53 | - ? static::$method($value) |
|
51 | + $method = static::buildMethodName( $cast, 'castTo' ); |
|
52 | + return !empty($cast) && method_exists( __CLASS__, $method ) |
|
53 | + ? static::$method( $value ) |
|
54 | 54 | : $value; |
55 | 55 | } |
56 | 56 | |
@@ -58,73 +58,73 @@ discard block |
||
58 | 58 | * @param mixed $value |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - public static function castToArray($value) |
|
61 | + public static function castToArray( $value ) |
|
62 | 62 | { |
63 | - return (array) $value; |
|
63 | + return (array)$value; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @param mixed $value |
68 | 68 | * @return bool |
69 | 69 | */ |
70 | - public static function castToBool($value) |
|
70 | + public static function castToBool( $value ) |
|
71 | 71 | { |
72 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
72 | + return filter_var( $value, FILTER_VALIDATE_BOOLEAN ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @param mixed $value |
77 | 77 | * @return float |
78 | 78 | */ |
79 | - public static function castToFloat($value) |
|
79 | + public static function castToFloat( $value ) |
|
80 | 80 | { |
81 | - return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
81 | + return (float)filter_var( $value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @param mixed $value |
86 | 86 | * @return int |
87 | 87 | */ |
88 | - public static function castToInt($value) |
|
88 | + public static function castToInt( $value ) |
|
89 | 89 | { |
90 | - return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
90 | + return (int)filter_var( $value, FILTER_VALIDATE_INT ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @param mixed $value |
95 | 95 | * @return object |
96 | 96 | */ |
97 | - public static function castToObject($value) |
|
97 | + public static function castToObject( $value ) |
|
98 | 98 | { |
99 | - return (object) (array) $value; |
|
99 | + return (object)(array)$value; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @param mixed $value |
104 | 104 | * @return string |
105 | 105 | */ |
106 | - public static function castToString($value) |
|
106 | + public static function castToString( $value ) |
|
107 | 107 | { |
108 | - if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
109 | - return (string) $value->__toString(); |
|
108 | + if( is_object( $value ) && in_array( '__toString', get_class_methods( $value ) ) ) { |
|
109 | + return (string)$value->__toString(); |
|
110 | 110 | } |
111 | - if (is_array($value) || is_object($value)) { |
|
112 | - return serialize($value); |
|
111 | + if( is_array( $value ) || is_object( $value ) ) { |
|
112 | + return serialize( $value ); |
|
113 | 113 | } |
114 | - return (string) $value; |
|
114 | + return (string)$value; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | 118 | * @param string $key |
119 | 119 | * @return mixed |
120 | 120 | */ |
121 | - public static function filterInput($key, array $request = []) |
|
121 | + public static function filterInput( $key, array $request = [] ) |
|
122 | 122 | { |
123 | - if (isset($request[$key])) { |
|
123 | + if( isset($request[$key]) ) { |
|
124 | 124 | return $request[$key]; |
125 | 125 | } |
126 | - $variable = filter_input(INPUT_POST, $key); |
|
127 | - if (is_null($variable) && isset($_POST[$key])) { |
|
126 | + $variable = filter_input( INPUT_POST, $key ); |
|
127 | + if( is_null( $variable ) && isset($_POST[$key]) ) { |
|
128 | 128 | $variable = $_POST[$key]; |
129 | 129 | } |
130 | 130 | return $variable; |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | * @param string $key |
135 | 135 | * @return array |
136 | 136 | */ |
137 | - public static function filterInputArray($key) |
|
137 | + public static function filterInputArray( $key ) |
|
138 | 138 | { |
139 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
140 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
139 | + $variable = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
140 | + if( empty($variable) && !empty($_POST[$key]) && is_array( $_POST[$key] ) ) { |
|
141 | 141 | $variable = $_POST[$key]; |
142 | 142 | } |
143 | - return (array) $variable; |
|
143 | + return (array)$variable; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,22 +149,22 @@ discard block |
||
149 | 149 | public static function getIpAddress() |
150 | 150 | { |
151 | 151 | $whitelist = []; |
152 | - $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
153 | - if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
154 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
152 | + $isUsingCloudflare = !empty(filter_input( INPUT_SERVER, 'CF-Connecting-IP' )); |
|
153 | + if( apply_filters( 'site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare ) ) { |
|
154 | + $cloudflareIps = glsr( Cache::class )->getCloudflareIps(); |
|
155 | 155 | $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
156 | - if (defined('AF_INET6')) { |
|
156 | + if( defined( 'AF_INET6' ) ) { |
|
157 | 157 | $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
158 | 158 | } |
159 | 159 | } |
160 | - $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
161 | - $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
162 | - $whip = new Whip($methods, $whitelist); |
|
163 | - do_action_ref_array('site-reviews/whip', [$whip]); |
|
164 | - if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
165 | - return (string) $clientAddress; |
|
160 | + $whitelist = apply_filters( 'site-reviews/whip/whitelist', $whitelist ); |
|
161 | + $methods = apply_filters( 'site-reviews/whip/methods', Whip::ALL_METHODS ); |
|
162 | + $whip = new Whip( $methods, $whitelist ); |
|
163 | + do_action_ref_array( 'site-reviews/whip', [$whip] ); |
|
164 | + if( false !== ($clientAddress = $whip->getValidIpAddress()) ) { |
|
165 | + return (string)$clientAddress; |
|
166 | 166 | } |
167 | - glsr_log()->error('Unable to detect IP address.'); |
|
167 | + glsr_log()->error( 'Unable to detect IP address.' ); |
|
168 | 168 | return 'unknown'; |
169 | 169 | } |
170 | 170 | |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * @param string|int $max |
175 | 175 | * @return bool |
176 | 176 | */ |
177 | - public static function inRange($value, $min, $max) |
|
177 | + public static function inRange( $value, $min, $max ) |
|
178 | 178 | { |
179 | - $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | - 'min_range' => intval($min), |
|
181 | - 'max_range' => intval($max), |
|
182 | - ]]); |
|
179 | + $inRange = filter_var( $value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | + 'min_range' => intval( $min ), |
|
181 | + 'max_range' => intval( $max ), |
|
182 | + ]] ); |
|
183 | 183 | return false !== $inRange; |
184 | 184 | } |
185 | 185 | |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * @param int|string $compareWithValue |
189 | 189 | * @return bool |
190 | 190 | */ |
191 | - public static function isGreaterThan($value, $compareWithValue) |
|
191 | + public static function isGreaterThan( $value, $compareWithValue ) |
|
192 | 192 | { |
193 | - return version_compare($value, $compareWithValue, '>'); |
|
193 | + return version_compare( $value, $compareWithValue, '>' ); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | * @param int|string $compareWithValue |
199 | 199 | * @return bool |
200 | 200 | */ |
201 | - public static function isGreaterThanOrEqual($value, $compareWithValue) |
|
201 | + public static function isGreaterThanOrEqual( $value, $compareWithValue ) |
|
202 | 202 | { |
203 | - return version_compare($value, $compareWithValue, '>='); |
|
203 | + return version_compare( $value, $compareWithValue, '>=' ); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | * @param int|string $compareWithValue |
209 | 209 | * @return bool |
210 | 210 | */ |
211 | - public static function isLessThan($value, $compareWithValue) |
|
211 | + public static function isLessThan( $value, $compareWithValue ) |
|
212 | 212 | { |
213 | - return version_compare($value, $compareWithValue, '<'); |
|
213 | + return version_compare( $value, $compareWithValue, '<' ); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | * @param int|string $compareWithValue |
219 | 219 | * @return bool |
220 | 220 | */ |
221 | - public static function isLessThanOrEqual($value, $compareWithValue) |
|
221 | + public static function isLessThanOrEqual( $value, $compareWithValue ) |
|
222 | 222 | { |
223 | - return version_compare($value, $compareWithValue, '<='); |
|
223 | + return version_compare( $value, $compareWithValue, '<=' ); |
|
224 | 224 | } |
225 | 225 | } |
@@ -9,157 +9,157 @@ |
||
9 | 9 | |
10 | 10 | class OptionManager |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - protected $options; |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + protected $options; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public static function databaseKey($version = null) |
|
21 | - { |
|
22 | - if (1 == $version) { |
|
23 | - return 'geminilabs_site_reviews_settings'; |
|
24 | - } |
|
25 | - if (2 == $version) { |
|
26 | - return 'geminilabs_site_reviews-v2'; |
|
27 | - } |
|
28 | - if (null === $version) { |
|
29 | - $version = explode('.', glsr()->version); |
|
30 | - $version = array_shift($version); |
|
31 | - } |
|
32 | - return Str::snakeCase(Application::ID.'-v'.intval($version)); |
|
33 | - } |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public static function databaseKey($version = null) |
|
21 | + { |
|
22 | + if (1 == $version) { |
|
23 | + return 'geminilabs_site_reviews_settings'; |
|
24 | + } |
|
25 | + if (2 == $version) { |
|
26 | + return 'geminilabs_site_reviews-v2'; |
|
27 | + } |
|
28 | + if (null === $version) { |
|
29 | + $version = explode('.', glsr()->version); |
|
30 | + $version = array_shift($version); |
|
31 | + } |
|
32 | + return Str::snakeCase(Application::ID.'-v'.intval($version)); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return array |
|
37 | - */ |
|
38 | - public function all() |
|
39 | - { |
|
40 | - if (empty($this->options)) { |
|
41 | - $this->reset(); |
|
42 | - } |
|
43 | - return $this->options; |
|
44 | - } |
|
35 | + /** |
|
36 | + * @return array |
|
37 | + */ |
|
38 | + public function all() |
|
39 | + { |
|
40 | + if (empty($this->options)) { |
|
41 | + $this->reset(); |
|
42 | + } |
|
43 | + return $this->options; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param string $path |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function delete($path) |
|
51 | - { |
|
52 | - $keys = explode('.', $path); |
|
53 | - $last = array_pop($keys); |
|
54 | - $options = $this->all(); |
|
55 | - $pointer = &$options; |
|
56 | - foreach ($keys as $key) { |
|
57 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
58 | - continue; |
|
59 | - } |
|
60 | - $pointer = &$pointer[$key]; |
|
61 | - } |
|
62 | - unset($pointer[$last]); |
|
63 | - return $this->set($options); |
|
64 | - } |
|
46 | + /** |
|
47 | + * @param string $path |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function delete($path) |
|
51 | + { |
|
52 | + $keys = explode('.', $path); |
|
53 | + $last = array_pop($keys); |
|
54 | + $options = $this->all(); |
|
55 | + $pointer = &$options; |
|
56 | + foreach ($keys as $key) { |
|
57 | + if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
58 | + continue; |
|
59 | + } |
|
60 | + $pointer = &$pointer[$key]; |
|
61 | + } |
|
62 | + unset($pointer[$last]); |
|
63 | + return $this->set($options); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $path |
|
68 | - * @param mixed $fallback |
|
69 | - * @param string $cast |
|
70 | - * @return mixed |
|
71 | - */ |
|
72 | - public function get($path = '', $fallback = '', $cast = '') |
|
73 | - { |
|
74 | - $result = Arr::get($this->all(), $path, $fallback); |
|
75 | - return Helper::castTo($cast, $result); |
|
76 | - } |
|
66 | + /** |
|
67 | + * @param string $path |
|
68 | + * @param mixed $fallback |
|
69 | + * @param string $cast |
|
70 | + * @return mixed |
|
71 | + */ |
|
72 | + public function get($path = '', $fallback = '', $cast = '') |
|
73 | + { |
|
74 | + $result = Arr::get($this->all(), $path, $fallback); |
|
75 | + return Helper::castTo($cast, $result); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $path |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function getBool($path) |
|
83 | - { |
|
84 | - return Helper::castToBool($this->get($path)); |
|
85 | - } |
|
78 | + /** |
|
79 | + * @param string $path |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function getBool($path) |
|
83 | + { |
|
84 | + return Helper::castToBool($this->get($path)); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param string $path |
|
89 | - * @param mixed $fallback |
|
90 | - * @param string $cast |
|
91 | - * @return mixed |
|
92 | - */ |
|
93 | - public function getWP($path, $fallback = '', $cast = '') |
|
94 | - { |
|
95 | - $option = get_option($path, $fallback); |
|
96 | - if (empty($option)) { |
|
97 | - $option = $fallback; |
|
98 | - } |
|
99 | - return Helper::castTo($cast, $option); |
|
100 | - } |
|
87 | + /** |
|
88 | + * @param string $path |
|
89 | + * @param mixed $fallback |
|
90 | + * @param string $cast |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + public function getWP($path, $fallback = '', $cast = '') |
|
94 | + { |
|
95 | + $option = get_option($path, $fallback); |
|
96 | + if (empty($option)) { |
|
97 | + $option = $fallback; |
|
98 | + } |
|
99 | + return Helper::castTo($cast, $option); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function json() |
|
106 | - { |
|
107 | - return json_encode($this->all()); |
|
108 | - } |
|
102 | + /** |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function json() |
|
106 | + { |
|
107 | + return json_encode($this->all()); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public function normalize(array $options = []) |
|
114 | - { |
|
115 | - $options = wp_parse_args( |
|
116 | - Arr::flattenArray($options), |
|
117 | - glsr(DefaultsManager::class)->defaults() |
|
118 | - ); |
|
119 | - array_walk($options, function (&$value) { |
|
120 | - if (!is_string($value)) { |
|
121 | - return; |
|
122 | - } |
|
123 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
124 | - }); |
|
125 | - return Arr::convertDotNotationArray($options); |
|
126 | - } |
|
110 | + /** |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public function normalize(array $options = []) |
|
114 | + { |
|
115 | + $options = wp_parse_args( |
|
116 | + Arr::flattenArray($options), |
|
117 | + glsr(DefaultsManager::class)->defaults() |
|
118 | + ); |
|
119 | + array_walk($options, function (&$value) { |
|
120 | + if (!is_string($value)) { |
|
121 | + return; |
|
122 | + } |
|
123 | + $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
124 | + }); |
|
125 | + return Arr::convertDotNotationArray($options); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @return bool |
|
130 | - */ |
|
131 | - public function isRecaptchaEnabled() |
|
132 | - { |
|
133 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
134 | - return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
135 | - } |
|
128 | + /** |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + public function isRecaptchaEnabled() |
|
132 | + { |
|
133 | + $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
134 | + return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - public function reset() |
|
141 | - { |
|
142 | - $options = $this->getWP(static::databaseKey(), []); |
|
143 | - if (!is_array($options) || empty($options)) { |
|
144 | - delete_option(static::databaseKey()); |
|
145 | - $options = glsr()->defaults ?: []; |
|
146 | - } |
|
147 | - $this->options = $options; |
|
148 | - } |
|
137 | + /** |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + public function reset() |
|
141 | + { |
|
142 | + $options = $this->getWP(static::databaseKey(), []); |
|
143 | + if (!is_array($options) || empty($options)) { |
|
144 | + delete_option(static::databaseKey()); |
|
145 | + $options = glsr()->defaults ?: []; |
|
146 | + } |
|
147 | + $this->options = $options; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @param string|array $pathOrOptions |
|
152 | - * @param mixed $value |
|
153 | - * @return bool |
|
154 | - */ |
|
155 | - public function set($pathOrOptions, $value = '') |
|
156 | - { |
|
157 | - if (is_string($pathOrOptions)) { |
|
158 | - $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
159 | - } |
|
160 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
161 | - $this->reset(); |
|
162 | - } |
|
163 | - return $result; |
|
164 | - } |
|
150 | + /** |
|
151 | + * @param string|array $pathOrOptions |
|
152 | + * @param mixed $value |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | + public function set($pathOrOptions, $value = '') |
|
156 | + { |
|
157 | + if (is_string($pathOrOptions)) { |
|
158 | + $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
159 | + } |
|
160 | + if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
161 | + $this->reset(); |
|
162 | + } |
|
163 | + return $result; |
|
164 | + } |
|
165 | 165 | } |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @return string |
19 | 19 | */ |
20 | - public static function databaseKey($version = null) |
|
20 | + public static function databaseKey( $version = null ) |
|
21 | 21 | { |
22 | - if (1 == $version) { |
|
22 | + if( 1 == $version ) { |
|
23 | 23 | return 'geminilabs_site_reviews_settings'; |
24 | 24 | } |
25 | - if (2 == $version) { |
|
25 | + if( 2 == $version ) { |
|
26 | 26 | return 'geminilabs_site_reviews-v2'; |
27 | 27 | } |
28 | - if (null === $version) { |
|
29 | - $version = explode('.', glsr()->version); |
|
30 | - $version = array_shift($version); |
|
28 | + if( null === $version ) { |
|
29 | + $version = explode( '.', glsr()->version ); |
|
30 | + $version = array_shift( $version ); |
|
31 | 31 | } |
32 | - return Str::snakeCase(Application::ID.'-v'.intval($version)); |
|
32 | + return Str::snakeCase( Application::ID.'-v'.intval( $version ) ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function all() |
39 | 39 | { |
40 | - if (empty($this->options)) { |
|
40 | + if( empty($this->options) ) { |
|
41 | 41 | $this->reset(); |
42 | 42 | } |
43 | 43 | return $this->options; |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | * @param string $path |
48 | 48 | * @return bool |
49 | 49 | */ |
50 | - public function delete($path) |
|
50 | + public function delete( $path ) |
|
51 | 51 | { |
52 | - $keys = explode('.', $path); |
|
53 | - $last = array_pop($keys); |
|
52 | + $keys = explode( '.', $path ); |
|
53 | + $last = array_pop( $keys ); |
|
54 | 54 | $options = $this->all(); |
55 | 55 | $pointer = &$options; |
56 | - foreach ($keys as $key) { |
|
57 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
56 | + foreach( $keys as $key ) { |
|
57 | + if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) ) { |
|
58 | 58 | continue; |
59 | 59 | } |
60 | 60 | $pointer = &$pointer[$key]; |
61 | 61 | } |
62 | 62 | unset($pointer[$last]); |
63 | - return $this->set($options); |
|
63 | + return $this->set( $options ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -69,19 +69,19 @@ discard block |
||
69 | 69 | * @param string $cast |
70 | 70 | * @return mixed |
71 | 71 | */ |
72 | - public function get($path = '', $fallback = '', $cast = '') |
|
72 | + public function get( $path = '', $fallback = '', $cast = '' ) |
|
73 | 73 | { |
74 | - $result = Arr::get($this->all(), $path, $fallback); |
|
75 | - return Helper::castTo($cast, $result); |
|
74 | + $result = Arr::get( $this->all(), $path, $fallback ); |
|
75 | + return Helper::castTo( $cast, $result ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param string $path |
80 | 80 | * @return bool |
81 | 81 | */ |
82 | - public function getBool($path) |
|
82 | + public function getBool( $path ) |
|
83 | 83 | { |
84 | - return Helper::castToBool($this->get($path)); |
|
84 | + return Helper::castToBool( $this->get( $path ) ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * @param string $cast |
91 | 91 | * @return mixed |
92 | 92 | */ |
93 | - public function getWP($path, $fallback = '', $cast = '') |
|
93 | + public function getWP( $path, $fallback = '', $cast = '' ) |
|
94 | 94 | { |
95 | - $option = get_option($path, $fallback); |
|
96 | - if (empty($option)) { |
|
95 | + $option = get_option( $path, $fallback ); |
|
96 | + if( empty($option) ) { |
|
97 | 97 | $option = $fallback; |
98 | 98 | } |
99 | - return Helper::castTo($cast, $option); |
|
99 | + return Helper::castTo( $cast, $option ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,25 +104,25 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function json() |
106 | 106 | { |
107 | - return json_encode($this->all()); |
|
107 | + return json_encode( $this->all() ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * @return array |
112 | 112 | */ |
113 | - public function normalize(array $options = []) |
|
113 | + public function normalize( array $options = [] ) |
|
114 | 114 | { |
115 | 115 | $options = wp_parse_args( |
116 | - Arr::flattenArray($options), |
|
117 | - glsr(DefaultsManager::class)->defaults() |
|
116 | + Arr::flattenArray( $options ), |
|
117 | + glsr( DefaultsManager::class )->defaults() |
|
118 | 118 | ); |
119 | - array_walk($options, function (&$value) { |
|
120 | - if (!is_string($value)) { |
|
119 | + array_walk( $options, function( &$value ) { |
|
120 | + if( !is_string( $value ) ) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
123 | + $value = wp_kses( $value, wp_kses_allowed_html( 'post' ) ); |
|
124 | 124 | }); |
125 | - return Arr::convertDotNotationArray($options); |
|
125 | + return Arr::convertDotNotationArray( $options ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function isRecaptchaEnabled() |
132 | 132 | { |
133 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
133 | + $integration = $this->get( 'settings.submissions.recaptcha.integration' ); |
|
134 | 134 | return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
135 | 135 | } |
136 | 136 | |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function reset() |
141 | 141 | { |
142 | - $options = $this->getWP(static::databaseKey(), []); |
|
143 | - if (!is_array($options) || empty($options)) { |
|
144 | - delete_option(static::databaseKey()); |
|
142 | + $options = $this->getWP( static::databaseKey(), [] ); |
|
143 | + if( !is_array( $options ) || empty($options) ) { |
|
144 | + delete_option( static::databaseKey() ); |
|
145 | 145 | $options = glsr()->defaults ?: []; |
146 | 146 | } |
147 | 147 | $this->options = $options; |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | * @param mixed $value |
153 | 153 | * @return bool |
154 | 154 | */ |
155 | - public function set($pathOrOptions, $value = '') |
|
155 | + public function set( $pathOrOptions, $value = '' ) |
|
156 | 156 | { |
157 | - if (is_string($pathOrOptions)) { |
|
158 | - $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
157 | + if( is_string( $pathOrOptions ) ) { |
|
158 | + $pathOrOptions = Arr::set( $this->all(), $pathOrOptions, $value ); |
|
159 | 159 | } |
160 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
160 | + if( $result = update_option( static::databaseKey(), (array)$pathOrOptions ) ) { |
|
161 | 161 | $this->reset(); |
162 | 162 | } |
163 | 163 | return $result; |