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