@@ -14,169 +14,169 @@ |
||
14 | 14 | |
15 | 15 | class AjaxController extends Controller |
16 | 16 | { |
17 | - /** |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function routerChangeStatus(array $request) |
|
21 | - { |
|
22 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
23 | - } |
|
17 | + /** |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function routerChangeStatus(array $request) |
|
21 | + { |
|
22 | + wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function routerClearConsole() |
|
29 | - { |
|
30 | - glsr(AdminController::class)->routerClearConsole(); |
|
31 | - wp_send_json_success([ |
|
32 | - 'console' => glsr(Console::class)->get(), |
|
33 | - 'notices' => glsr(Notice::class)->get(), |
|
34 | - ]); |
|
35 | - } |
|
25 | + /** |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function routerClearConsole() |
|
29 | + { |
|
30 | + glsr(AdminController::class)->routerClearConsole(); |
|
31 | + wp_send_json_success([ |
|
32 | + 'console' => glsr(Console::class)->get(), |
|
33 | + 'notices' => glsr(Notice::class)->get(), |
|
34 | + ]); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function routerCountReviews() |
|
41 | - { |
|
42 | - glsr(AdminController::class)->routerCountReviews(); |
|
43 | - wp_send_json_success([ |
|
44 | - 'notices' => glsr(Notice::class)->get(), |
|
45 | - ]); |
|
46 | - } |
|
37 | + /** |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function routerCountReviews() |
|
41 | + { |
|
42 | + glsr(AdminController::class)->routerCountReviews(); |
|
43 | + wp_send_json_success([ |
|
44 | + 'notices' => glsr(Notice::class)->get(), |
|
45 | + ]); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function routerDismissNotice(array $request) |
|
52 | - { |
|
53 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
54 | - wp_send_json_success(); |
|
55 | - } |
|
48 | + /** |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function routerDismissNotice(array $request) |
|
52 | + { |
|
53 | + glsr(NoticeController::class)->routerDismissNotice($request); |
|
54 | + wp_send_json_success(); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function routerMceShortcode(array $request) |
|
61 | - { |
|
62 | - $shortcode = $request['shortcode']; |
|
63 | - $response = false; |
|
64 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
65 | - $data = glsr()->mceShortcodes[$shortcode]; |
|
66 | - if (!empty($data['errors'])) { |
|
67 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
68 | - } |
|
69 | - $response = [ |
|
70 | - 'body' => $data['fields'], |
|
71 | - 'close' => $data['btn_close'], |
|
72 | - 'ok' => $data['btn_okay'], |
|
73 | - 'shortcode' => $shortcode, |
|
74 | - 'title' => $data['title'], |
|
75 | - ]; |
|
76 | - } |
|
77 | - wp_send_json_success($response); |
|
78 | - } |
|
57 | + /** |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function routerMceShortcode(array $request) |
|
61 | + { |
|
62 | + $shortcode = $request['shortcode']; |
|
63 | + $response = false; |
|
64 | + if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
65 | + $data = glsr()->mceShortcodes[$shortcode]; |
|
66 | + if (!empty($data['errors'])) { |
|
67 | + $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
68 | + } |
|
69 | + $response = [ |
|
70 | + 'body' => $data['fields'], |
|
71 | + 'close' => $data['btn_close'], |
|
72 | + 'ok' => $data['btn_okay'], |
|
73 | + 'shortcode' => $shortcode, |
|
74 | + 'title' => $data['title'], |
|
75 | + ]; |
|
76 | + } |
|
77 | + wp_send_json_success($response); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function routerFetchConsole() |
|
84 | - { |
|
85 | - glsr(AdminController::class)->routerFetchConsole(); |
|
86 | - wp_send_json_success([ |
|
87 | - 'console' => glsr(Console::class)->get(), |
|
88 | - 'notices' => glsr(Notice::class)->get(), |
|
89 | - ]); |
|
90 | - } |
|
80 | + /** |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function routerFetchConsole() |
|
84 | + { |
|
85 | + glsr(AdminController::class)->routerFetchConsole(); |
|
86 | + wp_send_json_success([ |
|
87 | + 'console' => glsr(Console::class)->get(), |
|
88 | + 'notices' => glsr(Notice::class)->get(), |
|
89 | + ]); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function routerSearchPosts(array $request) |
|
96 | - { |
|
97 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
98 | - wp_send_json_success([ |
|
99 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
100 | - 'items' => $results, |
|
101 | - ]); |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function routerSearchPosts(array $request) |
|
96 | + { |
|
97 | + $results = glsr(Database::class)->searchPosts($request['search']); |
|
98 | + wp_send_json_success([ |
|
99 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
100 | + 'items' => $results, |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public function routerSearchTranslations(array $request) |
|
108 | - { |
|
109 | - if (empty($request['exclude'])) { |
|
110 | - $request['exclude'] = []; |
|
111 | - } |
|
112 | - $results = glsr(Translation::class) |
|
113 | - ->search($request['search']) |
|
114 | - ->exclude() |
|
115 | - ->exclude($request['exclude']) |
|
116 | - ->renderResults(); |
|
117 | - wp_send_json_success([ |
|
118 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
119 | - 'items' => $results, |
|
120 | - ]); |
|
121 | - } |
|
104 | + /** |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public function routerSearchTranslations(array $request) |
|
108 | + { |
|
109 | + if (empty($request['exclude'])) { |
|
110 | + $request['exclude'] = []; |
|
111 | + } |
|
112 | + $results = glsr(Translation::class) |
|
113 | + ->search($request['search']) |
|
114 | + ->exclude() |
|
115 | + ->exclude($request['exclude']) |
|
116 | + ->renderResults(); |
|
117 | + wp_send_json_success([ |
|
118 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
119 | + 'items' => $results, |
|
120 | + ]); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * @return void |
|
125 | - */ |
|
126 | - public function routerSubmitReview(array $request) |
|
127 | - { |
|
128 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
129 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
130 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
131 | - $data = [ |
|
132 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
133 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
134 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
135 | - 'redirect' => $redirect, |
|
136 | - ]; |
|
137 | - if (false === $data['errors']) { |
|
138 | - glsr()->sessionClear(); |
|
139 | - wp_send_json_success($data); |
|
140 | - } |
|
141 | - wp_send_json_error($data); |
|
142 | - } |
|
123 | + /** |
|
124 | + * @return void |
|
125 | + */ |
|
126 | + public function routerSubmitReview(array $request) |
|
127 | + { |
|
128 | + $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
129 | + $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
130 | + $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
131 | + $data = [ |
|
132 | + 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
133 | + 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
134 | + 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
135 | + 'redirect' => $redirect, |
|
136 | + ]; |
|
137 | + if (false === $data['errors']) { |
|
138 | + glsr()->sessionClear(); |
|
139 | + wp_send_json_success($data); |
|
140 | + } |
|
141 | + wp_send_json_error($data); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - public function routerFetchPagedReviews(array $request) |
|
148 | - { |
|
149 | - $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
150 | - $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)); |
|
151 | - $urlQuery = []; |
|
152 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
153 | - $pagedUrl = $homePath === $urlPath |
|
154 | - ? home_url() |
|
155 | - : home_url($urlPath); |
|
156 | - $args = [ |
|
157 | - 'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
158 | - 'pagedUrl' => trailingslashit($pagedUrl), |
|
159 | - 'pagination' => 'ajax', |
|
160 | - 'schema' => false, |
|
161 | - ]; |
|
162 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
163 | - $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
164 | - $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
165 | - return wp_send_json_success([ |
|
166 | - 'pagination' => $html->getPagination(), |
|
167 | - 'reviews' => $html->getReviews(), |
|
168 | - ]); |
|
169 | - } |
|
144 | + /** |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + public function routerFetchPagedReviews(array $request) |
|
148 | + { |
|
149 | + $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
150 | + $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)); |
|
151 | + $urlQuery = []; |
|
152 | + parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
153 | + $pagedUrl = $homePath === $urlPath |
|
154 | + ? home_url() |
|
155 | + : home_url($urlPath); |
|
156 | + $args = [ |
|
157 | + 'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
158 | + 'pagedUrl' => trailingslashit($pagedUrl), |
|
159 | + 'pagination' => 'ajax', |
|
160 | + 'schema' => false, |
|
161 | + ]; |
|
162 | + $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
163 | + $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
164 | + $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
165 | + return wp_send_json_success([ |
|
166 | + 'pagination' => $html->getPagination(), |
|
167 | + 'reviews' => $html->getReviews(), |
|
168 | + ]); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - public function routerTogglePinned(array $request) |
|
175 | - { |
|
176 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
177 | - wp_send_json_success([ |
|
178 | - 'notices' => glsr(Notice::class)->get(), |
|
179 | - 'pinned' => $isPinned, |
|
180 | - ]); |
|
181 | - } |
|
171 | + /** |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + public function routerTogglePinned(array $request) |
|
175 | + { |
|
176 | + $isPinned = $this->execute(new TogglePinned($request)); |
|
177 | + wp_send_json_success([ |
|
178 | + 'notices' => glsr(Notice::class)->get(), |
|
179 | + 'pinned' => $isPinned, |
|
180 | + ]); |
|
181 | + } |
|
182 | 182 | } |