1 |
commit: c8b6d8429150837cdf56e483cfdb846a61f772bf |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Nov 30 21:18:49 2016 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Nov 30 21:18:49 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/blogs-gentoo.git/commit/?id=c8b6d842 |
7 |
|
8 |
Update plugin wordpress-mobile-pack to 2.2.6 |
9 |
|
10 |
.../admin/class-admin-ajax.php | 2362 ++++++++++---------- |
11 |
.../admin/class-admin-init.php | 657 +++--- |
12 |
.../wordpress-mobile-pack/admin/class-admin.php | 922 ++++---- |
13 |
.../wordpress-mobile-pack/admin/css/general.css | 2 +- |
14 |
.../admin/images/app2/1-preview-cover.png | Bin 240586 -> 0 bytes |
15 |
.../admin/images/app2/2-preview-categories.png | Bin 105914 -> 0 bytes |
16 |
.../admin/images/app2/3-preview-menu.png | Bin 86627 -> 0 bytes |
17 |
.../admin/images/app2/4-preview-article.png | Bin 131571 -> 0 bytes |
18 |
.../admin/images/app3/1-preview-cover.png | Bin 167097 -> 0 bytes |
19 |
.../admin/images/app3/2-preview-categories.png | Bin 113501 -> 0 bytes |
20 |
.../admin/images/app3/3-preview-menu.png | Bin 181059 -> 0 bytes |
21 |
.../admin/images/app3/4-preview-article.png | Bin 129744 -> 0 bytes |
22 |
.../admin/images/app4/1-homepage.png | Bin 120477 -> 0 bytes |
23 |
.../admin/images/app4/2-menu-opened.png | Bin 109023 -> 0 bytes |
24 |
.../admin/images/app4/3-categories-opened.png | Bin 131445 -> 0 bytes |
25 |
.../admin/images/app4/4-others-opened.png | Bin 101199 -> 0 bytes |
26 |
.../admin/images/app4/5-article-details.png | Bin 172225 -> 0 bytes |
27 |
.../admin/images/app5/1-preview-homepage.png | Bin 164839 -> 0 bytes |
28 |
.../admin/images/app5/2-preview-articles.png | Bin 146002 -> 0 bytes |
29 |
.../admin/images/app5/3-preview-menu.png | Bin 49171 -> 0 bytes |
30 |
.../images/app5/4-preview-menu-categories.png | Bin 103374 -> 0 bytes |
31 |
.../images/app5/5-preview-article-details.png | Bin 141803 -> 0 bytes |
32 |
.../images/app5/6-preview-article-details-menu.png | Bin 130862 -> 0 bytes |
33 |
.../images/{themes/theme-1.jpg => theme-obliq.jpg} | Bin |
34 |
.../admin/images/themes/theme-2.jpg | Bin 18073 -> 0 bytes |
35 |
.../admin/images/themes/theme-3.jpg | Bin 22592 -> 0 bytes |
36 |
.../admin/images/themes/theme-4.jpg | Bin 19340 -> 0 bytes |
37 |
.../admin/images/themes/theme-5.jpg | Bin 25664 -> 0 bytes |
38 |
.../js/UI.Modules/Settings/WMP_SOCIAL_MEDIA.js | 215 ++ |
39 |
.../js/UI.Modules/Settings/WMP_SOCIAL_MEDIA.min.js | 10 + |
40 |
.../js/UI.Modules/Theming/WMP_THEMES_GALLERY.js | 242 +- |
41 |
.../UI.Modules/Theming/WMP_THEMES_GALLERY.min.js | 2 +- |
42 |
.../wordpress-mobile-pack/admin/pages/premium.php | 306 +-- |
43 |
.../wordpress-mobile-pack/admin/pages/settings.php | 503 +++-- |
44 |
.../admin/pages/{theme.php => theme-settings.php} | 974 ++++---- |
45 |
.../wordpress-mobile-pack/admin/pages/themes.php | 130 ++ |
46 |
.../wordpress-mobile-pack/admin/pages/upgrade.php | 145 -- |
47 |
.../admin/sass/core/_buttons.scss | 210 +- |
48 |
.../admin/sass/core/_core.scss | 911 ++++---- |
49 |
.../admin/sass/core/_variables.scss | 203 +- |
50 |
.../admin/sass/fonts/wp-font.eot | Bin 6428 -> 7112 bytes |
51 |
.../admin/sass/fonts/wp-font.svg | 4 +- |
52 |
.../admin/sass/fonts/wp-font.ttf | Bin 6264 -> 6920 bytes |
53 |
.../admin/sass/fonts/wp-font.woff | Bin 6340 -> 6996 bytes |
54 |
.../wordpress-mobile-pack/admin/sass/general.scss | 66 +- |
55 |
.../admin/sass/mixins/_icon.scss | 114 +- |
56 |
.../admin/sass/modules/_look-and-feel.scss | 880 +++----- |
57 |
.../admin/sass/modules/_more.scss | 169 -- |
58 |
.../admin/sass/modules/_themes.scss | 265 +++ |
59 |
.../admin/sections/admin-menu.php | 92 +- |
60 |
.../admin/sections/theme-box.php | 57 + |
61 |
plugins/wordpress-mobile-pack/core/config.php | 78 +- |
62 |
.../wordpress-mobile-pack/export/class-export.php | 62 +- |
63 |
.../frontend/class-application.php | 5 +- |
64 |
.../wordpress-mobile-pack/frontend/locales/ja.json | 53 + |
65 |
.../frontend/themes/app1/template.php | 352 +-- |
66 |
.../inc/class-wmp-options.php | 599 ++--- |
67 |
plugins/wordpress-mobile-pack/readme.txt | 858 +++---- |
68 |
.../wordpress-mobile-pack.php | 150 +- |
69 |
59 files changed, 5834 insertions(+), 5764 deletions(-) |
70 |
|
71 |
diff --git a/plugins/wordpress-mobile-pack/admin/class-admin-ajax.php b/plugins/wordpress-mobile-pack/admin/class-admin-ajax.php |
72 |
index f3a3e96..dea9e2b 100755 |
73 |
--- a/plugins/wordpress-mobile-pack/admin/class-admin-ajax.php |
74 |
+++ b/plugins/wordpress-mobile-pack/admin/class-admin-ajax.php |
75 |
@@ -1,1181 +1,1181 @@ |
76 |
-<?php |
77 |
- |
78 |
-if ( ! class_exists( 'WMobilePack_Themes_Config' )) { |
79 |
- require_once(WMP_PLUGIN_PATH.'inc/class-wmp-themes-config.php'); |
80 |
-} |
81 |
- |
82 |
-if ( ! class_exists( 'WMobilePack_Admin_Ajax' ) ) { |
83 |
- |
84 |
- /** |
85 |
- * |
86 |
- * WMobilePack_Admin_Ajax class for managing Ajax requests from the admin area of the Wordpress Mobile Pack plugin |
87 |
- * |
88 |
- * @todo Test separately the methods of this class |
89 |
- */ |
90 |
- class WMobilePack_Admin_Ajax |
91 |
- { |
92 |
- |
93 |
- /** |
94 |
- * |
95 |
- * Create a theme management object and return it |
96 |
- * |
97 |
- * @return object |
98 |
- * |
99 |
- */ |
100 |
- protected function get_theme_manager() |
101 |
- { |
102 |
- if ( ! class_exists( 'WMobilePack_Themes_Compiler' ) && version_compare(PHP_VERSION, '5.3') >= 0 ) { |
103 |
- require_once(WMP_PLUGIN_PATH.'inc/class-wmp-themes-compiler.php'); |
104 |
- } |
105 |
- |
106 |
- if (class_exists('WMobilePack_Themes_Compiler')) { |
107 |
- return new WMobilePack_Themes_Compiler(); |
108 |
- } |
109 |
- |
110 |
- return false; |
111 |
- } |
112 |
- |
113 |
- |
114 |
- /** |
115 |
- * |
116 |
- * Create an uploads management object and return it |
117 |
- * |
118 |
- * @return object |
119 |
- * |
120 |
- */ |
121 |
- protected function get_uploads_manager() |
122 |
- { |
123 |
- return new WMobilePack_Uploads(); |
124 |
- } |
125 |
- |
126 |
- |
127 |
- /** |
128 |
- * |
129 |
- * Create a premium management object and return it |
130 |
- * |
131 |
- * @return object |
132 |
- * |
133 |
- */ |
134 |
- protected function get_premium_manager() |
135 |
- { |
136 |
- // attempt to load the settings json |
137 |
- if (!class_exists('WMobilePack_Premium')) { |
138 |
- require_once(WMP_PLUGIN_PATH . 'inc/class-wmp-premium.php'); |
139 |
- } |
140 |
- |
141 |
- return new WMobilePack_Premium(); |
142 |
- } |
143 |
- |
144 |
- |
145 |
- /** |
146 |
- * Save new font settings into the database. Returns true if we need to compile the css file. |
147 |
- * |
148 |
- * @param $data = array with POST data |
149 |
- * |
150 |
- * @return array with the following properties: |
151 |
- * - scss - If we need to compile the theme |
152 |
- * - updated - If any of the font settings have changed |
153 |
- * |
154 |
- */ |
155 |
- protected function update_theme_fonts($data) |
156 |
- { |
157 |
- |
158 |
- // check if we have to compile the scss file |
159 |
- $response = array( |
160 |
- 'scss' => false, |
161 |
- 'updated' => false |
162 |
- ); |
163 |
- |
164 |
- $font_families = array(); |
165 |
- |
166 |
- foreach (array('headlines', 'subtitles', 'paragraphs') as $font_type) { |
167 |
- |
168 |
- // check if the font settings have changed |
169 |
- if (isset($data['wmp_edittheme_font'.$font_type])) { |
170 |
- |
171 |
- if ($data['wmp_edittheme_font'.$font_type] != WMobilePack_Options::get_setting('font_'.$font_type)) { |
172 |
- |
173 |
- WMobilePack_Options::update_settings('font_' . $font_type, $data['wmp_edittheme_font' . $font_type]); |
174 |
- $response['updated'] = true; |
175 |
- } |
176 |
- |
177 |
- // if a font different from the default ones was selected, we need to compile the css file |
178 |
- if ($data['wmp_edittheme_font' . $font_type] > 3) { |
179 |
- $response['scss'] = true; |
180 |
- } |
181 |
- |
182 |
- $font_families[] = $data['wmp_edittheme_font'.$font_type]; |
183 |
- } |
184 |
- } |
185 |
- |
186 |
- // if the font settings are different for headlines, subtitles or paragraphs, we need to compile the css file |
187 |
- if (count(array_unique($font_families)) > 1){ |
188 |
- $response['scss'] = true; |
189 |
- } |
190 |
- |
191 |
- return $response; |
192 |
- } |
193 |
- |
194 |
- |
195 |
- /** |
196 |
- * |
197 |
- * Save new color scheme setting into the database. Returns true if we need to compile the css file. |
198 |
- * |
199 |
- * @param $data = array with POST data |
200 |
- * |
201 |
- * @return array with the following properties: |
202 |
- * - scss - If we need to compile the theme |
203 |
- * - updated - If the color scheme setting has changed |
204 |
- * |
205 |
- */ |
206 |
- protected function update_theme_color_scheme($data) |
207 |
- { |
208 |
- |
209 |
- // check if we have to compile the scss file |
210 |
- $response = array( |
211 |
- 'scss' => false, |
212 |
- 'updated' => false |
213 |
- ); |
214 |
- |
215 |
- if (isset($data['wmp_edittheme_colorscheme'])) { |
216 |
- |
217 |
- if (WMobilePack_Options::get_setting('color_scheme') != $data['wmp_edittheme_colorscheme']) { |
218 |
- |
219 |
- WMobilePack_Options::update_settings('color_scheme', $data['wmp_edittheme_colorscheme']); |
220 |
- $response['updated'] = true; |
221 |
- } |
222 |
- |
223 |
- // enable compiling for custom color schemes |
224 |
- if ($data['wmp_edittheme_colorscheme'] == 0) { |
225 |
- $response['scss'] = true; |
226 |
- } |
227 |
- } |
228 |
- |
229 |
- return $response; |
230 |
- } |
231 |
- |
232 |
- |
233 |
- /** |
234 |
- * Save new colors settings into the database. Returns true if we need to compile the css file. |
235 |
- * |
236 |
- * @param $data = array with POST data |
237 |
- * |
238 |
- * @return array with the following properties: |
239 |
- * - scss - If we need to compile the theme |
240 |
- * - error = If set to true if we have invalid color codes or the number of colors is not the same |
241 |
- * with the one from the theme. |
242 |
- * |
243 |
- * |
244 |
- */ |
245 |
- protected function update_theme_colors($data) |
246 |
- { |
247 |
- |
248 |
- $response = array( |
249 |
- 'scss' => false, |
250 |
- 'error' => false |
251 |
- ); |
252 |
- |
253 |
- $arr_custom_colors = array(); |
254 |
- |
255 |
- // read theme and custom colors options |
256 |
- $selected_theme = WMobilePack_Options::get_setting('theme'); |
257 |
- $selected_custom_colors = WMobilePack_Options::get_setting('custom_colors'); |
258 |
- |
259 |
- // how many colors does the theme have |
260 |
- $no_theme_colors = count(WMobilePack_Themes_Config::$color_schemes[$selected_theme]['vars']); |
261 |
- |
262 |
- for ($i = 0; $i < $no_theme_colors; $i++) { |
263 |
- |
264 |
- // validate color code format |
265 |
- if (isset($data['wmp_edittheme_customcolor' . $i]) && |
266 |
- trim($data['wmp_edittheme_customcolor' . $i]) != '' && |
267 |
- preg_match('/^#[a-f0-9]{6}$/i', trim($data['wmp_edittheme_customcolor' . $i]))) { |
268 |
- |
269 |
- $arr_custom_colors[] = strtolower($data['wmp_edittheme_customcolor' . $i]); |
270 |
- |
271 |
- // if the color settings have changed, we need to recompile the css file |
272 |
- if (empty($selected_custom_colors) || |
273 |
- (isset($selected_custom_colors[$i]) && strtolower($data['wmp_edittheme_customcolor' . $i]) != $selected_custom_colors[$i])){ |
274 |
- |
275 |
- $response['scss'] = true; |
276 |
- } |
277 |
- |
278 |
- } else { |
279 |
- $response['error'] = true; |
280 |
- break; |
281 |
- } |
282 |
- } |
283 |
- |
284 |
- // save colors only if all the colors from the theme have been set |
285 |
- if (count($arr_custom_colors) == $no_theme_colors){ |
286 |
- |
287 |
- WMobilePack_Options::update_settings('custom_colors', $arr_custom_colors); |
288 |
- |
289 |
- } else { |
290 |
- |
291 |
- $response['error'] = true; |
292 |
- $response['scss'] = false; |
293 |
- } |
294 |
- |
295 |
- return $response; |
296 |
- } |
297 |
- |
298 |
- |
299 |
- /** |
300 |
- * |
301 |
- * Delete custom theme file and reset option |
302 |
- */ |
303 |
- protected function remove_custom_theme(){ |
304 |
- |
305 |
- // remove compiled css file (if it exists) |
306 |
- $theme_timestamp = WMobilePack_Options::get_setting('theme_timestamp'); |
307 |
- |
308 |
- if ($theme_timestamp != ''){ |
309 |
- |
310 |
- $wmp_themes_compiler = $this->get_theme_manager(); |
311 |
- |
312 |
- if ($wmp_themes_compiler !== false) { |
313 |
- |
314 |
- $wmp_themes_compiler->remove_css_file($theme_timestamp); |
315 |
- WMobilePack_Options::update_settings('theme_timestamp', ''); |
316 |
- } |
317 |
- } |
318 |
- } |
319 |
- |
320 |
- |
321 |
- /** |
322 |
- * |
323 |
- * Method used to save the custom settings for a theme. |
324 |
- * |
325 |
- * Displays a JSON response with the following fields: |
326 |
- * |
327 |
- * - status = 0 if an error has occurred, 1 otherwise |
328 |
- * - messages = array with error messages, possible values are: |
329 |
- * |
330 |
- * - invalid custom colors format |
331 |
- * - settings were not changed |
332 |
- * - other error messages resulted from compiling the theme |
333 |
- * |
334 |
- * @todo Revert to old fonts settings if the theme was not successfully compiled. |
335 |
- * |
336 |
- */ |
337 |
- public function theme_settings() |
338 |
- { |
339 |
- if (current_user_can('manage_options')) { |
340 |
- |
341 |
- $arr_response = array( |
342 |
- 'status' => 0, |
343 |
- 'messages' => array() |
344 |
- ); |
345 |
- |
346 |
- // handle color schemes and fonts (look & feel page) |
347 |
- if (isset($_POST['wmp_edittheme_colorscheme']) && is_numeric($_POST['wmp_edittheme_colorscheme']) && |
348 |
- isset($_POST['wmp_edittheme_fontheadlines']) && is_numeric($_POST['wmp_edittheme_fontheadlines']) && |
349 |
- isset($_POST['wmp_edittheme_fontsubtitles']) && is_numeric($_POST['wmp_edittheme_fontsubtitles']) && |
350 |
- isset($_POST['wmp_edittheme_fontparagraphs']) && is_numeric($_POST['wmp_edittheme_fontparagraphs'])){ |
351 |
- |
352 |
- if (in_array($_POST['wmp_edittheme_colorscheme'], array(0,1,2,3)) && |
353 |
- in_array($_POST['wmp_edittheme_fontheadlines']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts)) && |
354 |
- in_array($_POST['wmp_edittheme_fontsubtitles']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts)) && |
355 |
- in_array($_POST['wmp_edittheme_fontparagraphs']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts))){ |
356 |
- |
357 |
- // check if the theme compiler can be successfully loaded |
358 |
- $wmp_themes_compiler = $this->get_theme_manager(); |
359 |
- |
360 |
- if ($wmp_themes_compiler === false) { |
361 |
- |
362 |
- $arr_response['messages'][] = 'Unable to load theme compiler. Please check your PHP version, should be at least 5.3.'; |
363 |
- |
364 |
- } else { |
365 |
- |
366 |
- // save custom colors first |
367 |
- $updated_colors = array('scss' => false, 'error' => false); |
368 |
- |
369 |
- if ($_POST['wmp_edittheme_colorscheme'] == 0) { |
370 |
- |
371 |
- $updated_colors = $this->update_theme_colors($_POST); |
372 |
- |
373 |
- // if the colors were not successfully processed, display error message and exit |
374 |
- if ($updated_colors['error']) { |
375 |
- |
376 |
- $arr_response['messages'][] = 'Please select all colors before saving the custom color scheme!'; |
377 |
- echo json_encode($arr_response); |
378 |
- |
379 |
- wp_die(); |
380 |
- } |
381 |
- } |
382 |
- |
383 |
- // update fonts and check if we need to compile the scss file |
384 |
- $updated_fonts = $this->update_theme_fonts($_POST); |
385 |
- |
386 |
- // update color scheme |
387 |
- $updated_color_scheme = $this->update_theme_color_scheme($_POST); |
388 |
- |
389 |
- // the settings haven't changed, so return error status |
390 |
- if (!$updated_colors['scss'] && !$updated_fonts['updated'] && !$updated_color_scheme['updated']) { |
391 |
- |
392 |
- $arr_response['messages'][] = 'Your application\'s settings have not changed!'; |
393 |
- |
394 |
- } else { |
395 |
- |
396 |
- if ($updated_colors['scss'] || $updated_fonts['scss'] || $updated_color_scheme['scss']) { |
397 |
- |
398 |
- $theme_timestamp = time(); |
399 |
- |
400 |
- // create new css theme file |
401 |
- $theme_compiled = $wmp_themes_compiler->compile_css_file($theme_timestamp); |
402 |
- |
403 |
- if (!$theme_compiled['compiled']) { |
404 |
- $arr_response['messages'][] = $theme_compiled['error']; |
405 |
- } else { |
406 |
- |
407 |
- // delete old css file (if it exists) |
408 |
- $old_theme_timestamp = WMobilePack_Options::get_setting('theme_timestamp'); |
409 |
- |
410 |
- // update theme timestamp |
411 |
- WMobilePack_Options::update_settings('theme_timestamp', $theme_timestamp); |
412 |
- |
413 |
- if ($old_theme_timestamp != '') { |
414 |
- $wmp_themes_compiler->remove_css_file($old_theme_timestamp); |
415 |
- } |
416 |
- |
417 |
- // the theme was successfully compiled and saved |
418 |
- $arr_response['status'] = 1; |
419 |
- } |
420 |
- |
421 |
- |
422 |
- } else { |
423 |
- |
424 |
- // we have reverted to the first color scheme (which is 1), remove custom theme file |
425 |
- $this->remove_custom_theme(); |
426 |
- $arr_response['status'] = 1; |
427 |
- } |
428 |
- } |
429 |
- } |
430 |
- } |
431 |
- } |
432 |
- |
433 |
- echo json_encode($arr_response); |
434 |
- } |
435 |
- |
436 |
- wp_die(); |
437 |
- } |
438 |
- |
439 |
- |
440 |
- /** |
441 |
- * Resize & copy image using Wordpress methods |
442 |
- * |
443 |
- * @param $file_type = icon, logo, cover or category_icon |
444 |
- * @param $file_path |
445 |
- * @param $file_name |
446 |
- * @param string $error_message |
447 |
- * @return bool |
448 |
- * |
449 |
- */ |
450 |
- protected function resize_image($file_type, $file_path, $file_name, &$error_message = '') |
451 |
- { |
452 |
- |
453 |
- $copied_and_resized = false; |
454 |
- |
455 |
- if (array_key_exists($file_type, WMobilePack_Uploads::$allowed_files)) { |
456 |
- |
457 |
- $arrMaximumSize = WMobilePack_Uploads::$allowed_files[$file_type]; |
458 |
- |
459 |
- $image = wp_get_image_editor($file_path); |
460 |
- |
461 |
- if (!is_wp_error($image)) { |
462 |
- |
463 |
- $image_size = $image->get_size(); |
464 |
- |
465 |
- // if the image exceeds the size limits |
466 |
- if ($image_size['width'] > $arrMaximumSize['max_width'] || $image_size['height'] > $arrMaximumSize['max_height']) { |
467 |
- |
468 |
- // resize and copy to the plugin uploads folder |
469 |
- $image->resize($arrMaximumSize['max_width'], $arrMaximumSize['max_height']); |
470 |
- $image->save(WMP_FILES_UPLOADS_DIR . $file_name); |
471 |
- |
472 |
- $copied_and_resized = true; |
473 |
- |
474 |
- } else { |
475 |
- |
476 |
- // copy file without resizing to the plugin uploads folder |
477 |
- $copied_and_resized = copy($file_path, WMP_FILES_UPLOADS_DIR . $file_name); |
478 |
- } |
479 |
- |
480 |
- } else { |
481 |
- |
482 |
- $error_message = "We encountered a problem resizing your " . ($file_type == 'category_icon' ? 'image' : $file_type) . ". Please choose another image!"; |
483 |
- } |
484 |
- |
485 |
- } |
486 |
- |
487 |
- return $copied_and_resized; |
488 |
- } |
489 |
- |
490 |
- |
491 |
- /** |
492 |
- * |
493 |
- * Remove image using the corresponding option's value for the filename |
494 |
- * |
495 |
- * @param $file_type = icon, logo or cover |
496 |
- * @return bool |
497 |
- */ |
498 |
- protected function remove_image($file_type) |
499 |
- { |
500 |
- |
501 |
- // get previous image filename |
502 |
- $previous_file_path = WMobilePack_Options::get_setting($file_type); |
503 |
- |
504 |
- // check the file exists and remove it |
505 |
- if ($previous_file_path != ''){ |
506 |
- $WMP_Uploads = $this->get_uploads_manager(); |
507 |
- return $WMP_Uploads->remove_uploaded_file($previous_file_path); |
508 |
- } |
509 |
- |
510 |
- return false; |
511 |
- } |
512 |
- |
513 |
- |
514 |
- /** |
515 |
- * Remove a category's icon file |
516 |
- * |
517 |
- * @param $category_id |
518 |
- * @return bool |
519 |
- */ |
520 |
- protected function remove_image_category($category_id){ |
521 |
- |
522 |
- $categories_details = WMobilePack_Options::get_setting('categories_details'); |
523 |
- |
524 |
- if (is_array($categories_details)) { |
525 |
- |
526 |
- if (array_key_exists($category_id, $categories_details)) { |
527 |
- |
528 |
- if (is_array($categories_details[$category_id])) { |
529 |
- |
530 |
- if (array_key_exists('icon', $categories_details[$category_id])) { |
531 |
- |
532 |
- $previous_file_path = $categories_details[$category_id]['icon']; |
533 |
- |
534 |
- // check the file exists and remove it |
535 |
- $WMP_Uploads = $this->get_uploads_manager(); |
536 |
- return $WMP_Uploads->remove_uploaded_file($previous_file_path); |
537 |
- } |
538 |
- } |
539 |
- } |
540 |
- } |
541 |
- |
542 |
- return false; |
543 |
- } |
544 |
- |
545 |
- /** |
546 |
- * |
547 |
- * Method used to save the icon, logo, cover or category image |
548 |
- * |
549 |
- */ |
550 |
- public function theme_editimages() |
551 |
- { |
552 |
- |
553 |
- if (current_user_can( 'manage_options' )){ |
554 |
- |
555 |
- $action = null; |
556 |
- |
557 |
- if (!empty($_GET) && isset($_GET['type'])) |
558 |
- if ($_GET['type'] == 'upload' || $_GET['type'] == 'delete') |
559 |
- $action = $_GET['type']; |
560 |
- |
561 |
- $arr_response = array( |
562 |
- 'status' => 0, |
563 |
- 'messages' => array() |
564 |
- ); |
565 |
- |
566 |
- if ($action == 'upload'){ |
567 |
- |
568 |
- if (!empty($_FILES) && sizeof($_FILES) > 0){ |
569 |
- |
570 |
- require_once(ABSPATH . 'wp-admin/includes/image.php'); |
571 |
- |
572 |
- if (!function_exists( 'wp_handle_upload' )) |
573 |
- require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
574 |
- |
575 |
- $default_uploads_dir = wp_upload_dir(); |
576 |
- |
577 |
- // check if the upload folder is writable |
578 |
- if (!is_writable(WMP_FILES_UPLOADS_DIR)){ |
579 |
- |
580 |
- $arr_response['messages'][] = "Error uploading image, the upload folder ".WMP_FILES_UPLOADS_DIR." is not writable."; |
581 |
- |
582 |
- } elseif (!is_writable($default_uploads_dir['path'])) { |
583 |
- |
584 |
- $arr_response['messages'][] = "Error uploading image, the upload folder ".$default_uploads_dir['path']." is not writable."; |
585 |
- |
586 |
- } else { |
587 |
- |
588 |
- $has_uploaded_files = false; |
589 |
- |
590 |
- foreach ($_FILES as $file => $info) { |
591 |
- |
592 |
- if (!empty($info['name'])){ |
593 |
- |
594 |
- $has_uploaded_files = true; |
595 |
- |
596 |
- $file_type = null; |
597 |
- |
598 |
- if ($file == 'wmp_editimages_icon') { |
599 |
- $file_type = 'icon'; |
600 |
- } elseif ($file == 'wmp_editimages_logo'){ |
601 |
- $file_type = 'logo'; |
602 |
- } elseif ($file == 'wmp_editcover_cover'){ |
603 |
- $file_type = 'cover'; |
604 |
- } elseif ($file == 'wmp_categoryedit_icon') { |
605 |
- $file_type = 'category_icon'; |
606 |
- } |
607 |
- |
608 |
- if ($info['error'] >= 1 || $info['size'] <= 0 && array_key_exists($file_type, WMobilePack_Uploads::$allowed_files)) { |
609 |
- |
610 |
- $arr_response['status'] = 0; |
611 |
- $arr_response["messages"][] = "We encountered a problem processing your ".($file_type == 'category_icon' ? 'image' : $file_type).". Please choose another image!"; |
612 |
- |
613 |
- } elseif ($info['size'] > 1048576){ |
614 |
- |
615 |
- $arr_response['status'] = 0; |
616 |
- $arr_response["messages"][] = "Do not exceed the 1MB file size limit when uploading your custom ".($file_type == 'category_icon' ? 'image' : $file_type)."."; |
617 |
- |
618 |
- } elseif ($file_type == 'category_icon' && (!isset($_POST['wmp_categoryedit_id']) || !is_numeric($_POST['wmp_categoryedit_id']))) { |
619 |
- |
620 |
- // If the category icon file is NOT accompanied by the category ID, default to the error message |
621 |
- $arr_response['status'] = 0; |
622 |
- |
623 |
- } else { |
624 |
- |
625 |
- /****************************************/ |
626 |
- /* */ |
627 |
- /* SET FILENAME, ALLOWED FORMATS AND SIZE */ |
628 |
- /* */ |
629 |
- /****************************************/ |
630 |
- |
631 |
- // make unique file name for the image |
632 |
- $arrFilename = explode(".", $info['name']); |
633 |
- $fileExtension = end($arrFilename); |
634 |
- |
635 |
- $arrAllowedExtensions = WMobilePack_Uploads::$allowed_files[$file_type]['extensions']; |
636 |
- |
637 |
- // check file extension |
638 |
- if (!in_array(strtolower($fileExtension), $arrAllowedExtensions)) { |
639 |
- |
640 |
- $arr_response['messages'][] = "Error saving image, please add a ".implode(' or ',$arrAllowedExtensions)." image for your ".($file_type == 'category_icon' ? 'category' : $file_type)."!"; |
641 |
- |
642 |
- } else { |
643 |
- |
644 |
- /****************************************/ |
645 |
- /* */ |
646 |
- /* UPLOAD IMAGE */ |
647 |
- /* */ |
648 |
- /****************************************/ |
649 |
- |
650 |
- $uniqueFilename = $file_type.'_'.time().'.'.$fileExtension; |
651 |
- |
652 |
- // upload to the default uploads folder |
653 |
- $upload_overrides = array( 'test_form' => false ); |
654 |
- $movefile = wp_handle_upload( $info, $upload_overrides ); |
655 |
- |
656 |
- if (is_array($movefile)) { |
657 |
- |
658 |
- if (isset($movefile['error'])) { |
659 |
- |
660 |
- $arr_response['messages'][] = $movefile['error']; |
661 |
- |
662 |
- } else { |
663 |
- |
664 |
- /****************************************/ |
665 |
- /* */ |
666 |
- /* RESIZE AND COPY IMAGE */ |
667 |
- /* */ |
668 |
- /****************************************/ |
669 |
- |
670 |
- $copied_and_resized = $this->resize_image($file_type, $movefile['file'], $uniqueFilename, $error_message); |
671 |
- |
672 |
- if ($error_message != ''){ |
673 |
- $arr_response["messages"][] = $error_message; |
674 |
- } |
675 |
- |
676 |
- /****************************************/ |
677 |
- /* */ |
678 |
- /* DELETE PREVIOUS IMAGE AND SET OPTION */ |
679 |
- /* */ |
680 |
- /****************************************/ |
681 |
- |
682 |
- if ($copied_and_resized) { |
683 |
- |
684 |
- if ($file_type == 'category_icon') { |
685 |
- |
686 |
- // delete previous image |
687 |
- $this->remove_image_category($_POST['wmp_categoryedit_id']); |
688 |
- |
689 |
- // update categories settings array |
690 |
- $categories_details = WMobilePack_Options::get_setting('categories_details'); |
691 |
- $categories_details[$_POST['wmp_categoryedit_id']] = array('icon' => $uniqueFilename); |
692 |
- |
693 |
- WMobilePack_Options::update_settings('categories_details', $categories_details); |
694 |
- |
695 |
- } else { |
696 |
- |
697 |
- // delete previous image |
698 |
- $this->remove_image($file_type); |
699 |
- |
700 |
- // save option |
701 |
- WMobilePack_Options::update_settings($file_type, $uniqueFilename); |
702 |
- } |
703 |
- |
704 |
- // add path in the response |
705 |
- $arr_response['status'] = 1; |
706 |
- $arr_response['uploaded_' . $file_type] = WMP_FILES_UPLOADS_URL . $uniqueFilename; |
707 |
- } |
708 |
- |
709 |
- // remove file from the default uploads folder |
710 |
- if (file_exists($movefile['file'])) |
711 |
- unlink($movefile['file']); |
712 |
- } |
713 |
- } |
714 |
- } |
715 |
- } |
716 |
- } |
717 |
- } |
718 |
- |
719 |
- if ($has_uploaded_files == false){ |
720 |
- $arr_response['messages'][] = "Please upload an image!"; |
721 |
- } |
722 |
- } |
723 |
- } |
724 |
- |
725 |
- } elseif ($action == 'delete'){ |
726 |
- |
727 |
- /****************************************/ |
728 |
- /* */ |
729 |
- /* DELETE ICON / LOGO / COVER */ |
730 |
- /* */ |
731 |
- /****************************************/ |
732 |
- |
733 |
- // delete icon, logo or cover, depending on the 'source' param |
734 |
- if (isset($_GET['source'])) { |
735 |
- |
736 |
- if (array_key_exists($_GET['source'], WMobilePack_Uploads::$allowed_files)){ |
737 |
- |
738 |
- $file_type = $_GET['source']; |
739 |
- |
740 |
- if ($file_type == 'category_icon' && isset($_GET['category_id']) && is_numeric($_GET['category_id'])) { |
741 |
- |
742 |
- // delete previous image |
743 |
- $this->remove_image_category($_GET['category_id']); |
744 |
- |
745 |
- // update categories settings array |
746 |
- $categories_details = WMobilePack_Options::get_setting('categories_details'); |
747 |
- unset($categories_details[ $_GET['category_id'] ]); |
748 |
- |
749 |
- WMobilePack_Options::update_settings('categories_details', $categories_details); |
750 |
- |
751 |
- $arr_response['status'] = 1; |
752 |
- |
753 |
- } elseif (in_array($file_type, array('icon', 'logo', 'cover'))) { |
754 |
- |
755 |
- // get the previous file name from the options table |
756 |
- $this->remove_image($file_type); |
757 |
- |
758 |
- // save option with an empty value |
759 |
- WMobilePack_Options::update_settings($file_type, ''); |
760 |
- |
761 |
- $arr_response['status'] = 1; |
762 |
- } |
763 |
- } |
764 |
- } |
765 |
- } |
766 |
- |
767 |
- // echo json with response |
768 |
- echo json_encode($arr_response); |
769 |
- } |
770 |
- |
771 |
- exit(); |
772 |
- } |
773 |
- |
774 |
- |
775 |
- |
776 |
- /** |
777 |
- * |
778 |
- * Method used to save the categories pages status settings in the database |
779 |
- * |
780 |
- */ |
781 |
- public function content_status() |
782 |
- { |
783 |
- |
784 |
- if (current_user_can( 'manage_options' )){ |
785 |
- |
786 |
- $status = 0; |
787 |
- |
788 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
789 |
- |
790 |
- if (isset($_POST['id']) && isset($_POST['status']) && isset($_POST['type'])){ |
791 |
- |
792 |
- if (is_numeric($_POST['id']) && |
793 |
- ($_POST['status'] == 'active' || $_POST['status'] == 'inactive') && |
794 |
- ($_POST['type'] == 'category' || $_POST['type'] == 'page')){ |
795 |
- |
796 |
- $status = 1; |
797 |
- |
798 |
- $item_id = intval($_POST['id']); |
799 |
- $item_status = strval($_POST['status']); |
800 |
- |
801 |
- // get inactive items option |
802 |
- if ($_POST['type'] == 'category') |
803 |
- $inactive_items = WMobilePack_Options::get_setting('inactive_categories'); |
804 |
- else |
805 |
- $inactive_items = WMobilePack_Options::get_setting('inactive_pages'); |
806 |
- |
807 |
- // add or remove the item from the options array |
808 |
- if (in_array($item_id, $inactive_items) && $item_status == 'active') |
809 |
- $inactive_items = array_diff($inactive_items, array($item_id)); |
810 |
- |
811 |
- if (!in_array($item_id, $inactive_items) && $item_status == 'inactive') |
812 |
- $inactive_items[] = $item_id; |
813 |
- |
814 |
- // save option |
815 |
- if ($_POST['type'] == 'category') |
816 |
- WMobilePack_Options::update_settings('inactive_categories', $inactive_items); |
817 |
- else |
818 |
- WMobilePack_Options::update_settings('inactive_pages', $inactive_items); |
819 |
- } |
820 |
- } |
821 |
- } |
822 |
- |
823 |
- echo $status; |
824 |
- } |
825 |
- |
826 |
- exit(); |
827 |
- } |
828 |
- |
829 |
- |
830 |
- |
831 |
- /** |
832 |
- * |
833 |
- * Method used to save the order of categories in the database |
834 |
- * |
835 |
- */ |
836 |
- public function content_order() |
837 |
- { |
838 |
- |
839 |
- if (current_user_can( 'manage_options' )){ |
840 |
- |
841 |
- $status = 0; |
842 |
- |
843 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
844 |
- |
845 |
- if (isset($_POST['ids']) && isset($_POST['type'])){ |
846 |
- |
847 |
- if ($_POST['ids'] != '' && $_POST['type'] == 'categories'){ |
848 |
- |
849 |
- // Retrieve the ids list from the param |
850 |
- $items_ids = array_filter(explode(",", $_POST['ids'])); |
851 |
- |
852 |
- if (count($items_ids) > 0) { |
853 |
- |
854 |
- // Check if the received ids are numeric |
855 |
- $valid_ids = true; |
856 |
- |
857 |
- foreach ($items_ids as $item_id) { |
858 |
- |
859 |
- if (!is_numeric($item_id)){ |
860 |
- $valid_ids = false; |
861 |
- } |
862 |
- } |
863 |
- |
864 |
- if ($valid_ids) { |
865 |
- |
866 |
- $status = 1; |
867 |
- |
868 |
- // Save option |
869 |
- WMobilePack_Options::update_settings('ordered_categories', $items_ids); |
870 |
- } |
871 |
- } |
872 |
- } |
873 |
- } |
874 |
- } |
875 |
- |
876 |
- echo $status; |
877 |
- } |
878 |
- |
879 |
- exit(); |
880 |
- } |
881 |
- |
882 |
- |
883 |
- /** |
884 |
- * |
885 |
- * Method used to save the page details content in the database |
886 |
- * |
887 |
- */ |
888 |
- public function content_pagedetails() |
889 |
- { |
890 |
- |
891 |
- if (current_user_can( 'manage_options' )){ |
892 |
- |
893 |
- $status = 0; |
894 |
- |
895 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
896 |
- |
897 |
- if (isset($_POST['wmp_pageedit_id']) && isset($_POST['wmp_pageedit_content'])){ |
898 |
- |
899 |
- if (is_numeric($_POST['wmp_pageedit_id'])){ |
900 |
- |
901 |
- if (trim($_POST['wmp_pageedit_content']) != '') { |
902 |
- |
903 |
- // load HTML purifier / formatter |
904 |
- if (!class_exists('WMobilePack_Formatter')) { |
905 |
- require_once(WMP_PLUGIN_PATH . 'inc/class-wmp-formatter.php'); |
906 |
- } |
907 |
- |
908 |
- $purifier = WMobilePack_Formatter::init_purifier(); |
909 |
- |
910 |
- $page_id = intval($_POST['wmp_pageedit_id']); |
911 |
- $page_content = $purifier->purify(stripslashes($_POST['wmp_pageedit_content'])); |
912 |
- |
913 |
- // save option in the db |
914 |
- update_option(WMobilePack_Options::$prefix . 'page_' . $page_id, $page_content); |
915 |
- |
916 |
- $status = 1; |
917 |
- |
918 |
- } else { |
919 |
- $status = 2; |
920 |
- } |
921 |
- } |
922 |
- } |
923 |
- } |
924 |
- |
925 |
- echo $status; |
926 |
- } |
927 |
- |
928 |
- exit(); |
929 |
- } |
930 |
- |
931 |
- |
932 |
- |
933 |
- /** |
934 |
- * |
935 |
- * Method used to save the app settings (display mode, google analytics id, etc.) |
936 |
- * |
937 |
- */ |
938 |
- public function settings_app() |
939 |
- { |
940 |
- |
941 |
- if (current_user_can( 'manage_options' )) { |
942 |
- |
943 |
- $status = 0; |
944 |
- |
945 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
946 |
- |
947 |
- if (isset($_POST['wmp_editsettings_displaymode']) && $_POST['wmp_editsettings_displaymode'] != '' && |
948 |
- isset($_POST['wmp_editsettings_displaywebsitelink']) && is_numeric($_POST['wmp_editsettings_displaywebsitelink']) && |
949 |
- isset($_POST['wmp_editsettings_postsperpage']) && $_POST['wmp_editsettings_postsperpage'] != ''){ |
950 |
- |
951 |
- if (in_array($_POST['wmp_editsettings_displaymode'], array('normal', 'preview', 'disabled')) && |
952 |
- in_array($_POST['wmp_editsettings_postsperpage'], array('auto', 'single', 'double'))){ |
953 |
- |
954 |
- $status = 1; |
955 |
- |
956 |
- // save google analytics id |
957 |
- if (isset($_POST["wmp_editsettings_ganalyticsid"])) { |
958 |
- |
959 |
- // validate google analytics id |
960 |
- if (preg_match('/^ua-\d{4,9}-\d{1,4}$/i', strval($_POST["wmp_editsettings_ganalyticsid"]))) |
961 |
- WMobilePack_Options::update_settings('google_analytics_id', $_POST['wmp_editsettings_ganalyticsid']); |
962 |
- elseif ($_POST["wmp_editsettings_ganalyticsid"] == "") |
963 |
- WMobilePack_Options::update_settings('google_analytics_id', ""); |
964 |
- } |
965 |
- |
966 |
- // save other options |
967 |
- WMobilePack_Options::update_settings('display_mode', $_POST['wmp_editsettings_displaymode']); |
968 |
- WMobilePack_Options::update_settings('display_website_link', intval($_POST['wmp_editsettings_displaywebsitelink'])); |
969 |
- WMobilePack_Options::update_settings('posts_per_page', $_POST['wmp_editsettings_postsperpage']); |
970 |
- } |
971 |
- } |
972 |
- } |
973 |
- |
974 |
- echo $status; |
975 |
- } |
976 |
- |
977 |
- exit(); |
978 |
- } |
979 |
- |
980 |
- |
981 |
- /** |
982 |
- * |
983 |
- * Save social media and other opt-ins settings |
984 |
- * |
985 |
- */ |
986 |
- public function settings_save() |
987 |
- { |
988 |
- |
989 |
- if (current_user_can( 'manage_options' )) { |
990 |
- |
991 |
- $status = 0; |
992 |
- |
993 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)) { |
994 |
- |
995 |
- // handle opt-ins settings |
996 |
- foreach (array('allow_tracking', 'upgrade_notice_updated') as $option_name) { |
997 |
- |
998 |
- if (isset($_POST['wmp_option_'.$option_name]) && $_POST['wmp_option_'.$option_name] != '' && is_numeric($_POST['wmp_option_'.$option_name])) { |
999 |
- |
1000 |
- $enabled_option = intval($_POST['wmp_option_'.$option_name]); |
1001 |
- |
1002 |
- if ($enabled_option == 0 || $enabled_option == 1) { |
1003 |
- |
1004 |
- $status = 1; |
1005 |
- |
1006 |
- // save option |
1007 |
- WMobilePack_Options::update_settings($option_name, $enabled_option); |
1008 |
- |
1009 |
- if ($option_name == 'allow_tracking'){ |
1010 |
- |
1011 |
- // update cron schedule |
1012 |
- WMobilePack::schedule_tracking($enabled_option); |
1013 |
- } |
1014 |
- } |
1015 |
- } |
1016 |
- } |
1017 |
- } |
1018 |
- |
1019 |
- echo $status; |
1020 |
- } |
1021 |
- |
1022 |
- exit(); |
1023 |
- } |
1024 |
- |
1025 |
- /** |
1026 |
- * |
1027 |
- * Save waitlist settings |
1028 |
- * |
1029 |
- */ |
1030 |
- public function settings_waitlist() |
1031 |
- { |
1032 |
- |
1033 |
- if (current_user_can('manage_options')) { |
1034 |
- |
1035 |
- $status = 0; |
1036 |
- |
1037 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)) { |
1038 |
- |
1039 |
- // handle joined waitlists |
1040 |
- if (isset($_POST['joined_waitlist']) && $_POST['joined_waitlist'] != '') { |
1041 |
- |
1042 |
- if (in_array($_POST['joined_waitlist'], array('content', 'settings', 'lifestyletheme', 'businesstheme', 'themes_features'))) { |
1043 |
- |
1044 |
- $option_waitlists = WMobilePack_Options::get_setting('joined_waitlists'); |
1045 |
- |
1046 |
- if ($option_waitlists == null || !is_array($option_waitlists)) { |
1047 |
- $option_waitlists = array(); |
1048 |
- } |
1049 |
- |
1050 |
- if (!in_array($_POST['joined_waitlist'], $option_waitlists)) { |
1051 |
- |
1052 |
- $status = 1; |
1053 |
- |
1054 |
- $option_waitlists[] = $_POST['joined_waitlist']; |
1055 |
- |
1056 |
- // save option |
1057 |
- WMobilePack_Options::update_settings('joined_waitlists', $option_waitlists); |
1058 |
- } |
1059 |
- } |
1060 |
- } |
1061 |
- } |
1062 |
- |
1063 |
- echo $status; |
1064 |
- } |
1065 |
- |
1066 |
- exit(); |
1067 |
- } |
1068 |
- |
1069 |
- |
1070 |
- /** |
1071 |
- * |
1072 |
- * Method used to validate and save the api key in the options table. |
1073 |
- * |
1074 |
- */ |
1075 |
- public function premium_save(){ |
1076 |
- |
1077 |
- if (current_user_can( 'manage_options' )){ |
1078 |
- |
1079 |
- $status = 0; |
1080 |
- |
1081 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
1082 |
- |
1083 |
- if (isset($_POST['api_key'])){ |
1084 |
- |
1085 |
- if (preg_match('/^[a-zA-Z0-9]+$/', $_POST['api_key'])){ |
1086 |
- |
1087 |
- // save options |
1088 |
- $status = 1; |
1089 |
- |
1090 |
- WMobilePack_Options::update_settings('premium_api_key',$_POST['api_key']); |
1091 |
- } |
1092 |
- } |
1093 |
- } |
1094 |
- |
1095 |
- echo $status; |
1096 |
- } |
1097 |
- |
1098 |
- exit(); |
1099 |
- } |
1100 |
- |
1101 |
- /** |
1102 |
- * |
1103 |
- * Method used to save the premium settings |
1104 |
- * |
1105 |
- */ |
1106 |
- public function premium_connect(){ |
1107 |
- |
1108 |
- if (current_user_can('manage_options')){ |
1109 |
- |
1110 |
- $status = 0; |
1111 |
- |
1112 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
1113 |
- |
1114 |
- if (isset($_POST['api_key']) && isset($_POST['valid']) && isset($_POST['config_path'])){ |
1115 |
- |
1116 |
- if ( |
1117 |
- preg_match('/^[a-zA-Z0-9]+$/', $_POST['api_key']) && |
1118 |
- ($_POST['valid'] == '0' || $_POST['valid'] == '1') && |
1119 |
- $_POST['config_path'] != '' && filter_var($_POST['config_path'], FILTER_VALIDATE_URL) |
1120 |
- ){ |
1121 |
- |
1122 |
- if ($_POST['api_key'] == WMobilePack_Options::get_setting('premium_api_key')) { |
1123 |
- |
1124 |
- $arr_data = array( |
1125 |
- 'premium_api_key' => $_POST['api_key'], |
1126 |
- 'premium_active' => $_POST['valid'], |
1127 |
- 'premium_config_path' => $_POST['config_path'] |
1128 |
- ); |
1129 |
- |
1130 |
- if (WMobilePack_Options::update_settings($arr_data)) { |
1131 |
- |
1132 |
- // attempt to load the settings json |
1133 |
- $premium_manager = $this->get_premium_manager(); |
1134 |
- $json_config_premium = $premium_manager->set_premium_config(); |
1135 |
- |
1136 |
- if ($json_config_premium !== false){ |
1137 |
- $status = 1; |
1138 |
- } else { |
1139 |
- WMobilePack_Options::update_settings('premium_active', 0); |
1140 |
- } |
1141 |
- } |
1142 |
- } |
1143 |
- } |
1144 |
- } |
1145 |
- } |
1146 |
- |
1147 |
- echo $status; |
1148 |
- |
1149 |
- } |
1150 |
- |
1151 |
- exit(); |
1152 |
- } |
1153 |
- |
1154 |
- |
1155 |
- /** |
1156 |
- * |
1157 |
- * Method used to disconnect the dashboard from Appticles and revert to basic theme |
1158 |
- * |
1159 |
- */ |
1160 |
- public function premium_disconnect(){ |
1161 |
- |
1162 |
- if (current_user_can('manage_options')){ |
1163 |
- |
1164 |
- $status = 0; |
1165 |
- |
1166 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
1167 |
- |
1168 |
- if (isset($_POST['api_key']) && isset($_POST['active'])){ |
1169 |
- |
1170 |
- if (preg_match('/^[a-zA-Z0-9]+$/', $_POST['api_key']) && $_POST['active'] == 0){ |
1171 |
- |
1172 |
- $status = 1; |
1173 |
- |
1174 |
- // delete transient with the json config |
1175 |
- if (get_transient(WMobilePack_Options::$transient_prefix."premium_config_path") !== false) |
1176 |
- delete_transient(WMobilePack_Options::$transient_prefix.'premium_config_path'); |
1177 |
- |
1178 |
- $arr_data = array( |
1179 |
- 'premium_api_key' => '', |
1180 |
- 'premium_active' => 0, |
1181 |
- 'premium_config_path' => '' |
1182 |
- ); |
1183 |
- |
1184 |
- // save options |
1185 |
- WMobilePack_Options::update_settings($arr_data); |
1186 |
- } |
1187 |
- } |
1188 |
- } |
1189 |
- |
1190 |
- echo $status; |
1191 |
- } |
1192 |
- |
1193 |
- exit(); |
1194 |
- } |
1195 |
- |
1196 |
- /** |
1197 |
- * |
1198 |
- * Method used to send a feedback e-mail from the admin |
1199 |
- * |
1200 |
- * Handle request, then display 1 for success and 0 for error. |
1201 |
- * |
1202 |
- */ |
1203 |
- public function send_feedback() |
1204 |
- { |
1205 |
- |
1206 |
- if (current_user_can('manage_options')){ |
1207 |
- |
1208 |
- $status = 0; |
1209 |
- |
1210 |
- if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
1211 |
- |
1212 |
- if (isset($_POST['wmp_feedback_page']) && |
1213 |
- isset($_POST['wmp_feedback_name']) && |
1214 |
- isset($_POST['wmp_feedback_email']) && |
1215 |
- isset($_POST['wmp_feedback_message'])){ |
1216 |
- |
1217 |
- if ($_POST['wmp_feedback_page'] != '' && |
1218 |
- $_POST['wmp_feedback_name'] != '' && |
1219 |
- $_POST['wmp_feedback_email'] != '' && |
1220 |
- $_POST['wmp_feedback_message'] != ''){ |
1221 |
- |
1222 |
- $admin_email = $_POST['wmp_feedback_email']; |
1223 |
- |
1224 |
- // filter e-mail |
1225 |
- if (filter_var($admin_email, FILTER_VALIDATE_EMAIL) !== false ){ |
1226 |
- |
1227 |
- // set e-mail variables |
1228 |
- $message = "Name: ".strip_tags($_POST["wmp_feedback_name"])."\r\n \r\n"; |
1229 |
- $message .= "E-mail: ".$admin_email."\r\n \r\n"; |
1230 |
- $message .= "Message: ".strip_tags($_POST["wmp_feedback_message"])."\r\n \r\n"; |
1231 |
- $message .= "Page: ".stripslashes(strip_tags($_POST['wmp_feedback_page']))."\r\n \r\n"; |
1232 |
- |
1233 |
- if (isset($_SERVER['HTTP_HOST'])) |
1234 |
- $message .= "Host: ".$_SERVER['HTTP_HOST']."\r\n \r\n"; |
1235 |
- |
1236 |
- $subject = WMP_PLUGIN_NAME.' Feedback'; |
1237 |
- $to = WMP_FEEDBACK_EMAIL; |
1238 |
- |
1239 |
- // set headers |
1240 |
- $headers = 'From:'.$admin_email."\r\nReply-To:".$admin_email; |
1241 |
- |
1242 |
- // send e-mail |
1243 |
- if (mail($to, $subject, $message, $headers)) |
1244 |
- $status = 1; |
1245 |
- } |
1246 |
- } |
1247 |
- } |
1248 |
- } |
1249 |
- |
1250 |
- echo $status; |
1251 |
- } |
1252 |
- |
1253 |
- exit(); |
1254 |
- } |
1255 |
- } |
1256 |
-} |
1257 |
\ No newline at end of file |
1258 |
+<?php |
1259 |
+ |
1260 |
+if ( ! class_exists( 'WMobilePack_Themes_Config' )) { |
1261 |
+ require_once(WMP_PLUGIN_PATH.'inc/class-wmp-themes-config.php'); |
1262 |
+} |
1263 |
+ |
1264 |
+if ( ! class_exists( 'WMobilePack_Admin_Ajax' ) ) { |
1265 |
+ |
1266 |
+ /** |
1267 |
+ * |
1268 |
+ * WMobilePack_Admin_Ajax class for managing Ajax requests from the admin area of the Wordpress Mobile Pack plugin |
1269 |
+ * |
1270 |
+ * @todo Test separately the methods of this class |
1271 |
+ */ |
1272 |
+ class WMobilePack_Admin_Ajax |
1273 |
+ { |
1274 |
+ |
1275 |
+ /** |
1276 |
+ * |
1277 |
+ * Create a theme management object and return it |
1278 |
+ * |
1279 |
+ * @return object |
1280 |
+ * |
1281 |
+ */ |
1282 |
+ protected function get_theme_manager() |
1283 |
+ { |
1284 |
+ if ( ! class_exists( 'WMobilePack_Themes_Compiler' ) && version_compare(PHP_VERSION, '5.3') >= 0 ) { |
1285 |
+ require_once(WMP_PLUGIN_PATH.'inc/class-wmp-themes-compiler.php'); |
1286 |
+ } |
1287 |
+ |
1288 |
+ if (class_exists('WMobilePack_Themes_Compiler')) { |
1289 |
+ return new WMobilePack_Themes_Compiler(); |
1290 |
+ } |
1291 |
+ |
1292 |
+ return false; |
1293 |
+ } |
1294 |
+ |
1295 |
+ |
1296 |
+ /** |
1297 |
+ * |
1298 |
+ * Create an uploads management object and return it |
1299 |
+ * |
1300 |
+ * @return object |
1301 |
+ * |
1302 |
+ */ |
1303 |
+ protected function get_uploads_manager() |
1304 |
+ { |
1305 |
+ return new WMobilePack_Uploads(); |
1306 |
+ } |
1307 |
+ |
1308 |
+ |
1309 |
+ /** |
1310 |
+ * |
1311 |
+ * Create a premium management object and return it |
1312 |
+ * |
1313 |
+ * @return object |
1314 |
+ * |
1315 |
+ */ |
1316 |
+ protected function get_premium_manager() |
1317 |
+ { |
1318 |
+ // attempt to load the settings json |
1319 |
+ if (!class_exists('WMobilePack_Premium')) { |
1320 |
+ require_once(WMP_PLUGIN_PATH . 'inc/class-wmp-premium.php'); |
1321 |
+ } |
1322 |
+ |
1323 |
+ return new WMobilePack_Premium(); |
1324 |
+ } |
1325 |
+ |
1326 |
+ |
1327 |
+ /** |
1328 |
+ * Save new font settings into the database. Returns true if we need to compile the css file. |
1329 |
+ * |
1330 |
+ * @param $data = array with POST data |
1331 |
+ * |
1332 |
+ * @return array with the following properties: |
1333 |
+ * - scss - If we need to compile the theme |
1334 |
+ * - updated - If any of the font settings have changed |
1335 |
+ * |
1336 |
+ */ |
1337 |
+ protected function update_theme_fonts($data) |
1338 |
+ { |
1339 |
+ |
1340 |
+ // check if we have to compile the scss file |
1341 |
+ $response = array( |
1342 |
+ 'scss' => false, |
1343 |
+ 'updated' => false |
1344 |
+ ); |
1345 |
+ |
1346 |
+ $font_families = array(); |
1347 |
+ |
1348 |
+ foreach (array('headlines', 'subtitles', 'paragraphs') as $font_type) { |
1349 |
+ |
1350 |
+ // check if the font settings have changed |
1351 |
+ if (isset($data['wmp_edittheme_font'.$font_type])) { |
1352 |
+ |
1353 |
+ if ($data['wmp_edittheme_font'.$font_type] != WMobilePack_Options::get_setting('font_'.$font_type)) { |
1354 |
+ |
1355 |
+ WMobilePack_Options::update_settings('font_' . $font_type, $data['wmp_edittheme_font' . $font_type]); |
1356 |
+ $response['updated'] = true; |
1357 |
+ } |
1358 |
+ |
1359 |
+ // if a font different from the default ones was selected, we need to compile the css file |
1360 |
+ if ($data['wmp_edittheme_font' . $font_type] > 3) { |
1361 |
+ $response['scss'] = true; |
1362 |
+ } |
1363 |
+ |
1364 |
+ $font_families[] = $data['wmp_edittheme_font'.$font_type]; |
1365 |
+ } |
1366 |
+ } |
1367 |
+ |
1368 |
+ // if the font settings are different for headlines, subtitles or paragraphs, we need to compile the css file |
1369 |
+ if (count(array_unique($font_families)) > 1){ |
1370 |
+ $response['scss'] = true; |
1371 |
+ } |
1372 |
+ |
1373 |
+ return $response; |
1374 |
+ } |
1375 |
+ |
1376 |
+ |
1377 |
+ /** |
1378 |
+ * |
1379 |
+ * Save new color scheme setting into the database. Returns true if we need to compile the css file. |
1380 |
+ * |
1381 |
+ * @param $data = array with POST data |
1382 |
+ * |
1383 |
+ * @return array with the following properties: |
1384 |
+ * - scss - If we need to compile the theme |
1385 |
+ * - updated - If the color scheme setting has changed |
1386 |
+ * |
1387 |
+ */ |
1388 |
+ protected function update_theme_color_scheme($data) |
1389 |
+ { |
1390 |
+ |
1391 |
+ // check if we have to compile the scss file |
1392 |
+ $response = array( |
1393 |
+ 'scss' => false, |
1394 |
+ 'updated' => false |
1395 |
+ ); |
1396 |
+ |
1397 |
+ if (isset($data['wmp_edittheme_colorscheme'])) { |
1398 |
+ |
1399 |
+ if (WMobilePack_Options::get_setting('color_scheme') != $data['wmp_edittheme_colorscheme']) { |
1400 |
+ |
1401 |
+ WMobilePack_Options::update_settings('color_scheme', $data['wmp_edittheme_colorscheme']); |
1402 |
+ $response['updated'] = true; |
1403 |
+ } |
1404 |
+ |
1405 |
+ // enable compiling for custom color schemes |
1406 |
+ if ($data['wmp_edittheme_colorscheme'] == 0) { |
1407 |
+ $response['scss'] = true; |
1408 |
+ } |
1409 |
+ } |
1410 |
+ |
1411 |
+ return $response; |
1412 |
+ } |
1413 |
+ |
1414 |
+ |
1415 |
+ /** |
1416 |
+ * Save new colors settings into the database. Returns true if we need to compile the css file. |
1417 |
+ * |
1418 |
+ * @param $data = array with POST data |
1419 |
+ * |
1420 |
+ * @return array with the following properties: |
1421 |
+ * - scss - If we need to compile the theme |
1422 |
+ * - error = If set to true if we have invalid color codes or the number of colors is not the same |
1423 |
+ * with the one from the theme. |
1424 |
+ * |
1425 |
+ * |
1426 |
+ */ |
1427 |
+ protected function update_theme_colors($data) |
1428 |
+ { |
1429 |
+ |
1430 |
+ $response = array( |
1431 |
+ 'scss' => false, |
1432 |
+ 'error' => false |
1433 |
+ ); |
1434 |
+ |
1435 |
+ $arr_custom_colors = array(); |
1436 |
+ |
1437 |
+ // read theme and custom colors options |
1438 |
+ $selected_theme = WMobilePack_Options::get_setting('theme'); |
1439 |
+ $selected_custom_colors = WMobilePack_Options::get_setting('custom_colors'); |
1440 |
+ |
1441 |
+ // how many colors does the theme have |
1442 |
+ $no_theme_colors = count(WMobilePack_Themes_Config::$color_schemes[$selected_theme]['vars']); |
1443 |
+ |
1444 |
+ for ($i = 0; $i < $no_theme_colors; $i++) { |
1445 |
+ |
1446 |
+ // validate color code format |
1447 |
+ if (isset($data['wmp_edittheme_customcolor' . $i]) && |
1448 |
+ trim($data['wmp_edittheme_customcolor' . $i]) != '' && |
1449 |
+ preg_match('/^#[a-f0-9]{6}$/i', trim($data['wmp_edittheme_customcolor' . $i]))) { |
1450 |
+ |
1451 |
+ $arr_custom_colors[] = strtolower($data['wmp_edittheme_customcolor' . $i]); |
1452 |
+ |
1453 |
+ // if the color settings have changed, we need to recompile the css file |
1454 |
+ if (empty($selected_custom_colors) || |
1455 |
+ (isset($selected_custom_colors[$i]) && strtolower($data['wmp_edittheme_customcolor' . $i]) != $selected_custom_colors[$i])){ |
1456 |
+ |
1457 |
+ $response['scss'] = true; |
1458 |
+ } |
1459 |
+ |
1460 |
+ } else { |
1461 |
+ $response['error'] = true; |
1462 |
+ break; |
1463 |
+ } |
1464 |
+ } |
1465 |
+ |
1466 |
+ // save colors only if all the colors from the theme have been set |
1467 |
+ if (count($arr_custom_colors) == $no_theme_colors){ |
1468 |
+ |
1469 |
+ WMobilePack_Options::update_settings('custom_colors', $arr_custom_colors); |
1470 |
+ |
1471 |
+ } else { |
1472 |
+ |
1473 |
+ $response['error'] = true; |
1474 |
+ $response['scss'] = false; |
1475 |
+ } |
1476 |
+ |
1477 |
+ return $response; |
1478 |
+ } |
1479 |
+ |
1480 |
+ |
1481 |
+ /** |
1482 |
+ * |
1483 |
+ * Delete custom theme file and reset option |
1484 |
+ */ |
1485 |
+ protected function remove_custom_theme(){ |
1486 |
+ |
1487 |
+ // remove compiled css file (if it exists) |
1488 |
+ $theme_timestamp = WMobilePack_Options::get_setting('theme_timestamp'); |
1489 |
+ |
1490 |
+ if ($theme_timestamp != ''){ |
1491 |
+ |
1492 |
+ $wmp_themes_compiler = $this->get_theme_manager(); |
1493 |
+ |
1494 |
+ if ($wmp_themes_compiler !== false) { |
1495 |
+ |
1496 |
+ $wmp_themes_compiler->remove_css_file($theme_timestamp); |
1497 |
+ WMobilePack_Options::update_settings('theme_timestamp', ''); |
1498 |
+ } |
1499 |
+ } |
1500 |
+ } |
1501 |
+ |
1502 |
+ |
1503 |
+ /** |
1504 |
+ * |
1505 |
+ * Method used to save the custom settings for a theme. |
1506 |
+ * |
1507 |
+ * Displays a JSON response with the following fields: |
1508 |
+ * |
1509 |
+ * - status = 0 if an error has occurred, 1 otherwise |
1510 |
+ * - messages = array with error messages, possible values are: |
1511 |
+ * |
1512 |
+ * - invalid custom colors format |
1513 |
+ * - settings were not changed |
1514 |
+ * - other error messages resulted from compiling the theme |
1515 |
+ * |
1516 |
+ * @todo Revert to old fonts settings if the theme was not successfully compiled. |
1517 |
+ * |
1518 |
+ */ |
1519 |
+ public function theme_settings() |
1520 |
+ { |
1521 |
+ if (current_user_can('manage_options')) { |
1522 |
+ |
1523 |
+ $arr_response = array( |
1524 |
+ 'status' => 0, |
1525 |
+ 'messages' => array() |
1526 |
+ ); |
1527 |
+ |
1528 |
+ // handle color schemes and fonts (look & feel page) |
1529 |
+ if (isset($_POST['wmp_edittheme_colorscheme']) && is_numeric($_POST['wmp_edittheme_colorscheme']) && |
1530 |
+ isset($_POST['wmp_edittheme_fontheadlines']) && is_numeric($_POST['wmp_edittheme_fontheadlines']) && |
1531 |
+ isset($_POST['wmp_edittheme_fontsubtitles']) && is_numeric($_POST['wmp_edittheme_fontsubtitles']) && |
1532 |
+ isset($_POST['wmp_edittheme_fontparagraphs']) && is_numeric($_POST['wmp_edittheme_fontparagraphs'])){ |
1533 |
+ |
1534 |
+ if (in_array($_POST['wmp_edittheme_colorscheme'], array(0,1,2,3)) && |
1535 |
+ in_array($_POST['wmp_edittheme_fontheadlines']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts)) && |
1536 |
+ in_array($_POST['wmp_edittheme_fontsubtitles']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts)) && |
1537 |
+ in_array($_POST['wmp_edittheme_fontparagraphs']-1, array_keys(WMobilePack_Themes_Config::$allowed_fonts))){ |
1538 |
+ |
1539 |
+ // check if the theme compiler can be successfully loaded |
1540 |
+ $wmp_themes_compiler = $this->get_theme_manager(); |
1541 |
+ |
1542 |
+ if ($wmp_themes_compiler === false) { |
1543 |
+ |
1544 |
+ $arr_response['messages'][] = 'Unable to load theme compiler. Please check your PHP version, should be at least 5.3.'; |
1545 |
+ |
1546 |
+ } else { |
1547 |
+ |
1548 |
+ // save custom colors first |
1549 |
+ $updated_colors = array('scss' => false, 'error' => false); |
1550 |
+ |
1551 |
+ if ($_POST['wmp_edittheme_colorscheme'] == 0) { |
1552 |
+ |
1553 |
+ $updated_colors = $this->update_theme_colors($_POST); |
1554 |
+ |
1555 |
+ // if the colors were not successfully processed, display error message and exit |
1556 |
+ if ($updated_colors['error']) { |
1557 |
+ |
1558 |
+ $arr_response['messages'][] = 'Please select all colors before saving the custom color scheme!'; |
1559 |
+ echo json_encode($arr_response); |
1560 |
+ |
1561 |
+ wp_die(); |
1562 |
+ } |
1563 |
+ } |
1564 |
+ |
1565 |
+ // update fonts and check if we need to compile the scss file |
1566 |
+ $updated_fonts = $this->update_theme_fonts($_POST); |
1567 |
+ |
1568 |
+ // update color scheme |
1569 |
+ $updated_color_scheme = $this->update_theme_color_scheme($_POST); |
1570 |
+ |
1571 |
+ // the settings haven't changed, so return error status |
1572 |
+ if (!$updated_colors['scss'] && !$updated_fonts['updated'] && !$updated_color_scheme['updated']) { |
1573 |
+ |
1574 |
+ $arr_response['messages'][] = 'Your application\'s settings have not changed!'; |
1575 |
+ |
1576 |
+ } else { |
1577 |
+ |
1578 |
+ if ($updated_colors['scss'] || $updated_fonts['scss'] || $updated_color_scheme['scss']) { |
1579 |
+ |
1580 |
+ $theme_timestamp = time(); |
1581 |
+ |
1582 |
+ // create new css theme file |
1583 |
+ $theme_compiled = $wmp_themes_compiler->compile_css_file($theme_timestamp); |
1584 |
+ |
1585 |
+ if (!$theme_compiled['compiled']) { |
1586 |
+ $arr_response['messages'][] = $theme_compiled['error']; |
1587 |
+ } else { |
1588 |
+ |
1589 |
+ // delete old css file (if it exists) |
1590 |
+ $old_theme_timestamp = WMobilePack_Options::get_setting('theme_timestamp'); |
1591 |
+ |
1592 |
+ // update theme timestamp |
1593 |
+ WMobilePack_Options::update_settings('theme_timestamp', $theme_timestamp); |
1594 |
+ |
1595 |
+ if ($old_theme_timestamp != '') { |
1596 |
+ $wmp_themes_compiler->remove_css_file($old_theme_timestamp); |
1597 |
+ } |
1598 |
+ |
1599 |
+ // the theme was successfully compiled and saved |
1600 |
+ $arr_response['status'] = 1; |
1601 |
+ } |
1602 |
+ |
1603 |
+ |
1604 |
+ } else { |
1605 |
+ |
1606 |
+ // we have reverted to the first color scheme (which is 1), remove custom theme file |
1607 |
+ $this->remove_custom_theme(); |
1608 |
+ $arr_response['status'] = 1; |
1609 |
+ } |
1610 |
+ } |
1611 |
+ } |
1612 |
+ } |
1613 |
+ } |
1614 |
+ |
1615 |
+ echo json_encode($arr_response); |
1616 |
+ } |
1617 |
+ |
1618 |
+ wp_die(); |
1619 |
+ } |
1620 |
+ |
1621 |
+ |
1622 |
+ /** |
1623 |
+ * Resize & copy image using Wordpress methods |
1624 |
+ * |
1625 |
+ * @param $file_type = icon, logo, cover or category_icon |
1626 |
+ * @param $file_path |
1627 |
+ * @param $file_name |
1628 |
+ * @param string $error_message |
1629 |
+ * @return bool |
1630 |
+ * |
1631 |
+ */ |
1632 |
+ protected function resize_image($file_type, $file_path, $file_name, &$error_message = '') |
1633 |
+ { |
1634 |
+ |
1635 |
+ $copied_and_resized = false; |
1636 |
+ |
1637 |
+ if (array_key_exists($file_type, WMobilePack_Uploads::$allowed_files)) { |
1638 |
+ |
1639 |
+ $arrMaximumSize = WMobilePack_Uploads::$allowed_files[$file_type]; |
1640 |
+ |
1641 |
+ $image = wp_get_image_editor($file_path); |
1642 |
+ |
1643 |
+ if (!is_wp_error($image)) { |
1644 |
+ |
1645 |
+ $image_size = $image->get_size(); |
1646 |
+ |
1647 |
+ // if the image exceeds the size limits |
1648 |
+ if ($image_size['width'] > $arrMaximumSize['max_width'] || $image_size['height'] > $arrMaximumSize['max_height']) { |
1649 |
+ |
1650 |
+ // resize and copy to the plugin uploads folder |
1651 |
+ $image->resize($arrMaximumSize['max_width'], $arrMaximumSize['max_height']); |
1652 |
+ $image->save(WMP_FILES_UPLOADS_DIR . $file_name); |
1653 |
+ |
1654 |
+ $copied_and_resized = true; |
1655 |
+ |
1656 |
+ } else { |
1657 |
+ |
1658 |
+ // copy file without resizing to the plugin uploads folder |
1659 |
+ $copied_and_resized = copy($file_path, WMP_FILES_UPLOADS_DIR . $file_name); |
1660 |
+ } |
1661 |
+ |
1662 |
+ } else { |
1663 |
+ |
1664 |
+ $error_message = "We encountered a problem resizing your " . ($file_type == 'category_icon' ? 'image' : $file_type) . ". Please choose another image!"; |
1665 |
+ } |
1666 |
+ |
1667 |
+ } |
1668 |
+ |
1669 |
+ return $copied_and_resized; |
1670 |
+ } |
1671 |
+ |
1672 |
+ |
1673 |
+ /** |
1674 |
+ * |
1675 |
+ * Remove image using the corresponding option's value for the filename |
1676 |
+ * |
1677 |
+ * @param $file_type = icon, logo or cover |
1678 |
+ * @return bool |
1679 |
+ */ |
1680 |
+ protected function remove_image($file_type) |
1681 |
+ { |
1682 |
+ |
1683 |
+ // get previous image filename |
1684 |
+ $previous_file_path = WMobilePack_Options::get_setting($file_type); |
1685 |
+ |
1686 |
+ // check the file exists and remove it |
1687 |
+ if ($previous_file_path != ''){ |
1688 |
+ $WMP_Uploads = $this->get_uploads_manager(); |
1689 |
+ return $WMP_Uploads->remove_uploaded_file($previous_file_path); |
1690 |
+ } |
1691 |
+ |
1692 |
+ return false; |
1693 |
+ } |
1694 |
+ |
1695 |
+ |
1696 |
+ /** |
1697 |
+ * Remove a category's icon file |
1698 |
+ * |
1699 |
+ * @param $category_id |
1700 |
+ * @return bool |
1701 |
+ */ |
1702 |
+ protected function remove_image_category($category_id){ |
1703 |
+ |
1704 |
+ $categories_details = WMobilePack_Options::get_setting('categories_details'); |
1705 |
+ |
1706 |
+ if (is_array($categories_details)) { |
1707 |
+ |
1708 |
+ if (array_key_exists($category_id, $categories_details)) { |
1709 |
+ |
1710 |
+ if (is_array($categories_details[$category_id])) { |
1711 |
+ |
1712 |
+ if (array_key_exists('icon', $categories_details[$category_id])) { |
1713 |
+ |
1714 |
+ $previous_file_path = $categories_details[$category_id]['icon']; |
1715 |
+ |
1716 |
+ // check the file exists and remove it |
1717 |
+ $WMP_Uploads = $this->get_uploads_manager(); |
1718 |
+ return $WMP_Uploads->remove_uploaded_file($previous_file_path); |
1719 |
+ } |
1720 |
+ } |
1721 |
+ } |
1722 |
+ } |
1723 |
+ |
1724 |
+ return false; |
1725 |
+ } |
1726 |
+ |
1727 |
+ /** |
1728 |
+ * |
1729 |
+ * Method used to save the icon, logo, cover or category image |
1730 |
+ * |
1731 |
+ */ |
1732 |
+ public function theme_editimages() |
1733 |
+ { |
1734 |
+ |
1735 |
+ if (current_user_can( 'manage_options' )){ |
1736 |
+ |
1737 |
+ $action = null; |
1738 |
+ |
1739 |
+ if (!empty($_GET) && isset($_GET['type'])) |
1740 |
+ if ($_GET['type'] == 'upload' || $_GET['type'] == 'delete') |
1741 |
+ $action = $_GET['type']; |
1742 |
+ |
1743 |
+ $arr_response = array( |
1744 |
+ 'status' => 0, |
1745 |
+ 'messages' => array() |
1746 |
+ ); |
1747 |
+ |
1748 |
+ if ($action == 'upload'){ |
1749 |
+ |
1750 |
+ if (!empty($_FILES) && sizeof($_FILES) > 0){ |
1751 |
+ |
1752 |
+ require_once(ABSPATH . 'wp-admin/includes/image.php'); |
1753 |
+ |
1754 |
+ if (!function_exists( 'wp_handle_upload' )) |
1755 |
+ require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
1756 |
+ |
1757 |
+ $default_uploads_dir = wp_upload_dir(); |
1758 |
+ |
1759 |
+ // check if the upload folder is writable |
1760 |
+ if (!is_writable(WMP_FILES_UPLOADS_DIR)){ |
1761 |
+ |
1762 |
+ $arr_response['messages'][] = "Error uploading image, the upload folder ".WMP_FILES_UPLOADS_DIR." is not writable."; |
1763 |
+ |
1764 |
+ } elseif (!is_writable($default_uploads_dir['path'])) { |
1765 |
+ |
1766 |
+ $arr_response['messages'][] = "Error uploading image, the upload folder ".$default_uploads_dir['path']." is not writable."; |
1767 |
+ |
1768 |
+ } else { |
1769 |
+ |
1770 |
+ $has_uploaded_files = false; |
1771 |
+ |
1772 |
+ foreach ($_FILES as $file => $info) { |
1773 |
+ |
1774 |
+ if (!empty($info['name'])){ |
1775 |
+ |
1776 |
+ $has_uploaded_files = true; |
1777 |
+ |
1778 |
+ $file_type = null; |
1779 |
+ |
1780 |
+ if ($file == 'wmp_editimages_icon') { |
1781 |
+ $file_type = 'icon'; |
1782 |
+ } elseif ($file == 'wmp_editimages_logo'){ |
1783 |
+ $file_type = 'logo'; |
1784 |
+ } elseif ($file == 'wmp_editcover_cover'){ |
1785 |
+ $file_type = 'cover'; |
1786 |
+ } elseif ($file == 'wmp_categoryedit_icon') { |
1787 |
+ $file_type = 'category_icon'; |
1788 |
+ } |
1789 |
+ |
1790 |
+ if ($info['error'] >= 1 || $info['size'] <= 0 && array_key_exists($file_type, WMobilePack_Uploads::$allowed_files)) { |
1791 |
+ |
1792 |
+ $arr_response['status'] = 0; |
1793 |
+ $arr_response["messages"][] = "We encountered a problem processing your ".($file_type == 'category_icon' ? 'image' : $file_type).". Please choose another image!"; |
1794 |
+ |
1795 |
+ } elseif ($info['size'] > 1048576){ |
1796 |
+ |
1797 |
+ $arr_response['status'] = 0; |
1798 |
+ $arr_response["messages"][] = "Do not exceed the 1MB file size limit when uploading your custom ".($file_type == 'category_icon' ? 'image' : $file_type)."."; |
1799 |
+ |
1800 |
+ } elseif ($file_type == 'category_icon' && (!isset($_POST['wmp_categoryedit_id']) || !is_numeric($_POST['wmp_categoryedit_id']))) { |
1801 |
+ |
1802 |
+ // If the category icon file is NOT accompanied by the category ID, default to the error message |
1803 |
+ $arr_response['status'] = 0; |
1804 |
+ |
1805 |
+ } else { |
1806 |
+ |
1807 |
+ /****************************************/ |
1808 |
+ /* */ |
1809 |
+ /* SET FILENAME, ALLOWED FORMATS AND SIZE */ |
1810 |
+ /* */ |
1811 |
+ /****************************************/ |
1812 |
+ |
1813 |
+ // make unique file name for the image |
1814 |
+ $arrFilename = explode(".", $info['name']); |
1815 |
+ $fileExtension = end($arrFilename); |
1816 |
+ |
1817 |
+ $arrAllowedExtensions = WMobilePack_Uploads::$allowed_files[$file_type]['extensions']; |
1818 |
+ |
1819 |
+ // check file extension |
1820 |
+ if (!in_array(strtolower($fileExtension), $arrAllowedExtensions)) { |
1821 |
+ |
1822 |
+ $arr_response['messages'][] = "Error saving image, please add a ".implode(' or ',$arrAllowedExtensions)." image for your ".($file_type == 'category_icon' ? 'category' : $file_type)."!"; |
1823 |
+ |
1824 |
+ } else { |
1825 |
+ |
1826 |
+ /****************************************/ |
1827 |
+ /* */ |
1828 |
+ /* UPLOAD IMAGE */ |
1829 |
+ /* */ |
1830 |
+ /****************************************/ |
1831 |
+ |
1832 |
+ $uniqueFilename = $file_type.'_'.time().'.'.$fileExtension; |
1833 |
+ |
1834 |
+ // upload to the default uploads folder |
1835 |
+ $upload_overrides = array( 'test_form' => false ); |
1836 |
+ $movefile = wp_handle_upload( $info, $upload_overrides ); |
1837 |
+ |
1838 |
+ if (is_array($movefile)) { |
1839 |
+ |
1840 |
+ if (isset($movefile['error'])) { |
1841 |
+ |
1842 |
+ $arr_response['messages'][] = $movefile['error']; |
1843 |
+ |
1844 |
+ } else { |
1845 |
+ |
1846 |
+ /****************************************/ |
1847 |
+ /* */ |
1848 |
+ /* RESIZE AND COPY IMAGE */ |
1849 |
+ /* */ |
1850 |
+ /****************************************/ |
1851 |
+ |
1852 |
+ $copied_and_resized = $this->resize_image($file_type, $movefile['file'], $uniqueFilename, $error_message); |
1853 |
+ |
1854 |
+ if ($error_message != ''){ |
1855 |
+ $arr_response["messages"][] = $error_message; |
1856 |
+ } |
1857 |
+ |
1858 |
+ /****************************************/ |
1859 |
+ /* */ |
1860 |
+ /* DELETE PREVIOUS IMAGE AND SET OPTION */ |
1861 |
+ /* */ |
1862 |
+ /****************************************/ |
1863 |
+ |
1864 |
+ if ($copied_and_resized) { |
1865 |
+ |
1866 |
+ if ($file_type == 'category_icon') { |
1867 |
+ |
1868 |
+ // delete previous image |
1869 |
+ $this->remove_image_category($_POST['wmp_categoryedit_id']); |
1870 |
+ |
1871 |
+ // update categories settings array |
1872 |
+ $categories_details = WMobilePack_Options::get_setting('categories_details'); |
1873 |
+ $categories_details[$_POST['wmp_categoryedit_id']] = array('icon' => $uniqueFilename); |
1874 |
+ |
1875 |
+ WMobilePack_Options::update_settings('categories_details', $categories_details); |
1876 |
+ |
1877 |
+ } else { |
1878 |
+ |
1879 |
+ // delete previous image |
1880 |
+ $this->remove_image($file_type); |
1881 |
+ |
1882 |
+ // save option |
1883 |
+ WMobilePack_Options::update_settings($file_type, $uniqueFilename); |
1884 |
+ } |
1885 |
+ |
1886 |
+ // add path in the response |
1887 |
+ $arr_response['status'] = 1; |
1888 |
+ $arr_response['uploaded_' . $file_type] = WMP_FILES_UPLOADS_URL . $uniqueFilename; |
1889 |
+ } |
1890 |
+ |
1891 |
+ // remove file from the default uploads folder |
1892 |
+ if (file_exists($movefile['file'])) |
1893 |
+ unlink($movefile['file']); |
1894 |
+ } |
1895 |
+ } |
1896 |
+ } |
1897 |
+ } |
1898 |
+ } |
1899 |
+ } |
1900 |
+ |
1901 |
+ if ($has_uploaded_files == false){ |
1902 |
+ $arr_response['messages'][] = "Please upload an image!"; |
1903 |
+ } |
1904 |
+ } |
1905 |
+ } |
1906 |
+ |
1907 |
+ } elseif ($action == 'delete'){ |
1908 |
+ |
1909 |
+ /****************************************/ |
1910 |
+ /* */ |
1911 |
+ /* DELETE ICON / LOGO / COVER */ |
1912 |
+ /* */ |
1913 |
+ /****************************************/ |
1914 |
+ |
1915 |
+ // delete icon, logo or cover, depending on the 'source' param |
1916 |
+ if (isset($_GET['source'])) { |
1917 |
+ |
1918 |
+ if (array_key_exists($_GET['source'], WMobilePack_Uploads::$allowed_files)){ |
1919 |
+ |
1920 |
+ $file_type = $_GET['source']; |
1921 |
+ |
1922 |
+ if ($file_type == 'category_icon' && isset($_GET['category_id']) && is_numeric($_GET['category_id'])) { |
1923 |
+ |
1924 |
+ // delete previous image |
1925 |
+ $this->remove_image_category($_GET['category_id']); |
1926 |
+ |
1927 |
+ // update categories settings array |
1928 |
+ $categories_details = WMobilePack_Options::get_setting('categories_details'); |
1929 |
+ unset($categories_details[ $_GET['category_id'] ]); |
1930 |
+ |
1931 |
+ WMobilePack_Options::update_settings('categories_details', $categories_details); |
1932 |
+ |
1933 |
+ $arr_response['status'] = 1; |
1934 |
+ |
1935 |
+ } elseif (in_array($file_type, array('icon', 'logo', 'cover'))) { |
1936 |
+ |
1937 |
+ // get the previous file name from the options table |
1938 |
+ $this->remove_image($file_type); |
1939 |
+ |
1940 |
+ // save option with an empty value |
1941 |
+ WMobilePack_Options::update_settings($file_type, ''); |
1942 |
+ |
1943 |
+ $arr_response['status'] = 1; |
1944 |
+ } |
1945 |
+ } |
1946 |
+ } |
1947 |
+ } |
1948 |
+ |
1949 |
+ // echo json with response |
1950 |
+ echo json_encode($arr_response); |
1951 |
+ } |
1952 |
+ |
1953 |
+ exit(); |
1954 |
+ } |
1955 |
+ |
1956 |
+ |
1957 |
+ |
1958 |
+ /** |
1959 |
+ * |
1960 |
+ * Method used to save the categories pages status settings in the database |
1961 |
+ * |
1962 |
+ */ |
1963 |
+ public function content_status() |
1964 |
+ { |
1965 |
+ |
1966 |
+ if (current_user_can( 'manage_options' )){ |
1967 |
+ |
1968 |
+ $status = 0; |
1969 |
+ |
1970 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
1971 |
+ |
1972 |
+ if (isset($_POST['id']) && isset($_POST['status']) && isset($_POST['type'])){ |
1973 |
+ |
1974 |
+ if (is_numeric($_POST['id']) && |
1975 |
+ ($_POST['status'] == 'active' || $_POST['status'] == 'inactive') && |
1976 |
+ ($_POST['type'] == 'category' || $_POST['type'] == 'page')){ |
1977 |
+ |
1978 |
+ $status = 1; |
1979 |
+ |
1980 |
+ $item_id = intval($_POST['id']); |
1981 |
+ $item_status = strval($_POST['status']); |
1982 |
+ |
1983 |
+ // get inactive items option |
1984 |
+ if ($_POST['type'] == 'category') |
1985 |
+ $inactive_items = WMobilePack_Options::get_setting('inactive_categories'); |
1986 |
+ else |
1987 |
+ $inactive_items = WMobilePack_Options::get_setting('inactive_pages'); |
1988 |
+ |
1989 |
+ // add or remove the item from the options array |
1990 |
+ if (in_array($item_id, $inactive_items) && $item_status == 'active') |
1991 |
+ $inactive_items = array_diff($inactive_items, array($item_id)); |
1992 |
+ |
1993 |
+ if (!in_array($item_id, $inactive_items) && $item_status == 'inactive') |
1994 |
+ $inactive_items[] = $item_id; |
1995 |
+ |
1996 |
+ // save option |
1997 |
+ if ($_POST['type'] == 'category') |
1998 |
+ WMobilePack_Options::update_settings('inactive_categories', $inactive_items); |
1999 |
+ else |
2000 |
+ WMobilePack_Options::update_settings('inactive_pages', $inactive_items); |
2001 |
+ } |
2002 |
+ } |
2003 |
+ } |
2004 |
+ |
2005 |
+ echo $status; |
2006 |
+ } |
2007 |
+ |
2008 |
+ exit(); |
2009 |
+ } |
2010 |
+ |
2011 |
+ |
2012 |
+ |
2013 |
+ /** |
2014 |
+ * |
2015 |
+ * Method used to save the order of categories in the database |
2016 |
+ * |
2017 |
+ */ |
2018 |
+ public function content_order() |
2019 |
+ { |
2020 |
+ |
2021 |
+ if (current_user_can( 'manage_options' )){ |
2022 |
+ |
2023 |
+ $status = 0; |
2024 |
+ |
2025 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
2026 |
+ |
2027 |
+ if (isset($_POST['ids']) && isset($_POST['type'])){ |
2028 |
+ |
2029 |
+ if ($_POST['ids'] != '' && $_POST['type'] == 'categories'){ |
2030 |
+ |
2031 |
+ // Retrieve the ids list from the param |
2032 |
+ $items_ids = array_filter(explode(",", $_POST['ids'])); |
2033 |
+ |
2034 |
+ if (count($items_ids) > 0) { |
2035 |
+ |
2036 |
+ // Check if the received ids are numeric |
2037 |
+ $valid_ids = true; |
2038 |
+ |
2039 |
+ foreach ($items_ids as $item_id) { |
2040 |
+ |
2041 |
+ if (!is_numeric($item_id)){ |
2042 |
+ $valid_ids = false; |
2043 |
+ } |
2044 |
+ } |
2045 |
+ |
2046 |
+ if ($valid_ids) { |
2047 |
+ |
2048 |
+ $status = 1; |
2049 |
+ |
2050 |
+ // Save option |
2051 |
+ WMobilePack_Options::update_settings('ordered_categories', $items_ids); |
2052 |
+ } |
2053 |
+ } |
2054 |
+ } |
2055 |
+ } |
2056 |
+ } |
2057 |
+ |
2058 |
+ echo $status; |
2059 |
+ } |
2060 |
+ |
2061 |
+ exit(); |
2062 |
+ } |
2063 |
+ |
2064 |
+ |
2065 |
+ /** |
2066 |
+ * |
2067 |
+ * Method used to save the page details content in the database |
2068 |
+ * |
2069 |
+ */ |
2070 |
+ public function content_pagedetails() |
2071 |
+ { |
2072 |
+ |
2073 |
+ if (current_user_can( 'manage_options' )){ |
2074 |
+ |
2075 |
+ $status = 0; |
2076 |
+ |
2077 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
2078 |
+ |
2079 |
+ if (isset($_POST['wmp_pageedit_id']) && isset($_POST['wmp_pageedit_content'])){ |
2080 |
+ |
2081 |
+ if (is_numeric($_POST['wmp_pageedit_id'])){ |
2082 |
+ |
2083 |
+ if (trim($_POST['wmp_pageedit_content']) != '') { |
2084 |
+ |
2085 |
+ // load HTML purifier / formatter |
2086 |
+ if (!class_exists('WMobilePack_Formatter')) { |
2087 |
+ require_once(WMP_PLUGIN_PATH . 'inc/class-wmp-formatter.php'); |
2088 |
+ } |
2089 |
+ |
2090 |
+ $purifier = WMobilePack_Formatter::init_purifier(); |
2091 |
+ |
2092 |
+ $page_id = intval($_POST['wmp_pageedit_id']); |
2093 |
+ $page_content = $purifier->purify(stripslashes($_POST['wmp_pageedit_content'])); |
2094 |
+ |
2095 |
+ // save option in the db |
2096 |
+ update_option(WMobilePack_Options::$prefix . 'page_' . $page_id, $page_content); |
2097 |
+ |
2098 |
+ $status = 1; |
2099 |
+ |
2100 |
+ } else { |
2101 |
+ $status = 2; |
2102 |
+ } |
2103 |
+ } |
2104 |
+ } |
2105 |
+ } |
2106 |
+ |
2107 |
+ echo $status; |
2108 |
+ } |
2109 |
+ |
2110 |
+ exit(); |
2111 |
+ } |
2112 |
+ |
2113 |
+ |
2114 |
+ |
2115 |
+ /** |
2116 |
+ * |
2117 |
+ * Method used to save the app settings (display mode, google analytics id, etc.) |
2118 |
+ * |
2119 |
+ */ |
2120 |
+ public function settings_app() |
2121 |
+ { |
2122 |
+ |
2123 |
+ if (current_user_can( 'manage_options' )) { |
2124 |
+ |
2125 |
+ $status = 0; |
2126 |
+ |
2127 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
2128 |
+ |
2129 |
+ if (isset($_POST['wmp_editsettings_displaymode']) && $_POST['wmp_editsettings_displaymode'] != '' && |
2130 |
+ isset($_POST['wmp_editsettings_displaywebsitelink']) && is_numeric($_POST['wmp_editsettings_displaywebsitelink']) && |
2131 |
+ isset($_POST['wmp_editsettings_postsperpage']) && $_POST['wmp_editsettings_postsperpage'] != ''){ |
2132 |
+ |
2133 |
+ if (in_array($_POST['wmp_editsettings_displaymode'], array('normal', 'preview', 'disabled')) && |
2134 |
+ in_array($_POST['wmp_editsettings_postsperpage'], array('auto', 'single', 'double'))){ |
2135 |
+ |
2136 |
+ $status = 1; |
2137 |
+ |
2138 |
+ // save google analytics id |
2139 |
+ if (isset($_POST["wmp_editsettings_ganalyticsid"])) { |
2140 |
+ |
2141 |
+ // validate google analytics id |
2142 |
+ if (preg_match('/^ua-\d{4,9}-\d{1,4}$/i', strval($_POST["wmp_editsettings_ganalyticsid"]))) |
2143 |
+ WMobilePack_Options::update_settings('google_analytics_id', $_POST['wmp_editsettings_ganalyticsid']); |
2144 |
+ elseif ($_POST["wmp_editsettings_ganalyticsid"] == "") |
2145 |
+ WMobilePack_Options::update_settings('google_analytics_id', ""); |
2146 |
+ } |
2147 |
+ |
2148 |
+ // save other options |
2149 |
+ WMobilePack_Options::update_settings('display_mode', $_POST['wmp_editsettings_displaymode']); |
2150 |
+ WMobilePack_Options::update_settings('display_website_link', intval($_POST['wmp_editsettings_displaywebsitelink'])); |
2151 |
+ WMobilePack_Options::update_settings('posts_per_page', $_POST['wmp_editsettings_postsperpage']); |
2152 |
+ } |
2153 |
+ } |
2154 |
+ } |
2155 |
+ |
2156 |
+ echo $status; |
2157 |
+ } |
2158 |
+ |
2159 |
+ exit(); |
2160 |
+ } |
2161 |
+ |
2162 |
+ |
2163 |
+ /** |
2164 |
+ * |
2165 |
+ * Save social media and other opt-ins settings |
2166 |
+ * |
2167 |
+ */ |
2168 |
+ public function settings_save() |
2169 |
+ { |
2170 |
+ |
2171 |
+ if (current_user_can( 'manage_options' )) { |
2172 |
+ |
2173 |
+ $status = 0; |
2174 |
+ |
2175 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)) { |
2176 |
+ |
2177 |
+ // handle opt-ins settings |
2178 |
+ foreach (array('enable_facebook', 'enable_twitter', 'enable_google','allow_tracking', 'upgrade_notice_updated') as $option_name) { |
2179 |
+ |
2180 |
+ if (isset($_POST['wmp_option_'.$option_name]) && $_POST['wmp_option_'.$option_name] != '' && is_numeric($_POST['wmp_option_'.$option_name])) { |
2181 |
+ |
2182 |
+ $enabled_option = intval($_POST['wmp_option_'.$option_name]); |
2183 |
+ |
2184 |
+ if ($enabled_option == 0 || $enabled_option == 1) { |
2185 |
+ |
2186 |
+ $status = 1; |
2187 |
+ |
2188 |
+ // save option |
2189 |
+ WMobilePack_Options::update_settings($option_name, $enabled_option); |
2190 |
+ |
2191 |
+ if ($option_name == 'allow_tracking'){ |
2192 |
+ |
2193 |
+ // update cron schedule |
2194 |
+ WMobilePack::schedule_tracking($enabled_option); |
2195 |
+ } |
2196 |
+ } |
2197 |
+ } |
2198 |
+ } |
2199 |
+ } |
2200 |
+ |
2201 |
+ echo $status; |
2202 |
+ } |
2203 |
+ |
2204 |
+ exit(); |
2205 |
+ } |
2206 |
+ |
2207 |
+ /** |
2208 |
+ * |
2209 |
+ * Save waitlist settings |
2210 |
+ * |
2211 |
+ */ |
2212 |
+ public function settings_waitlist() |
2213 |
+ { |
2214 |
+ |
2215 |
+ if (current_user_can('manage_options')) { |
2216 |
+ |
2217 |
+ $status = 0; |
2218 |
+ |
2219 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)) { |
2220 |
+ |
2221 |
+ // handle joined waitlists |
2222 |
+ if (isset($_POST['joined_waitlist']) && $_POST['joined_waitlist'] != '') { |
2223 |
+ |
2224 |
+ if (in_array($_POST['joined_waitlist'], array('content', 'settings', 'lifestyletheme', 'businesstheme', 'themes_features'))) { |
2225 |
+ |
2226 |
+ $option_waitlists = WMobilePack_Options::get_setting('joined_waitlists'); |
2227 |
+ |
2228 |
+ if ($option_waitlists == null || !is_array($option_waitlists)) { |
2229 |
+ $option_waitlists = array(); |
2230 |
+ } |
2231 |
+ |
2232 |
+ if (!in_array($_POST['joined_waitlist'], $option_waitlists)) { |
2233 |
+ |
2234 |
+ $status = 1; |
2235 |
+ |
2236 |
+ $option_waitlists[] = $_POST['joined_waitlist']; |
2237 |
+ |
2238 |
+ // save option |
2239 |
+ WMobilePack_Options::update_settings('joined_waitlists', $option_waitlists); |
2240 |
+ } |
2241 |
+ } |
2242 |
+ } |
2243 |
+ } |
2244 |
+ |
2245 |
+ echo $status; |
2246 |
+ } |
2247 |
+ |
2248 |
+ exit(); |
2249 |
+ } |
2250 |
+ |
2251 |
+ |
2252 |
+ /** |
2253 |
+ * |
2254 |
+ * Method used to validate and save the api key in the options table. |
2255 |
+ * |
2256 |
+ */ |
2257 |
+ public function premium_save(){ |
2258 |
+ |
2259 |
+ if (current_user_can( 'manage_options' )){ |
2260 |
+ |
2261 |
+ $status = 0; |
2262 |
+ |
2263 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
2264 |
+ |
2265 |
+ if (isset($_POST['api_key'])){ |
2266 |
+ |
2267 |
+ if (preg_match('/^[a-zA-Z0-9]+$/', $_POST['api_key'])){ |
2268 |
+ |
2269 |
+ // save options |
2270 |
+ $status = 1; |
2271 |
+ |
2272 |
+ WMobilePack_Options::update_settings('premium_api_key',$_POST['api_key']); |
2273 |
+ } |
2274 |
+ } |
2275 |
+ } |
2276 |
+ |
2277 |
+ echo $status; |
2278 |
+ } |
2279 |
+ |
2280 |
+ exit(); |
2281 |
+ } |
2282 |
+ |
2283 |
+ /** |
2284 |
+ * |
2285 |
+ * Method used to save the premium settings |
2286 |
+ * |
2287 |
+ */ |
2288 |
+ public function premium_connect(){ |
2289 |
+ |
2290 |
+ if (current_user_can('manage_options')){ |
2291 |
+ |
2292 |
+ $status = 0; |
2293 |
+ |
2294 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
2295 |
+ |
2296 |
+ if (isset($_POST['api_key']) && isset($_POST['valid']) && isset($_POST['config_path'])){ |
2297 |
+ |
2298 |
+ if ( |
2299 |
+ preg_match('/^[a-zA-Z0-9]+$/', $_POST['api_key']) && |
2300 |
+ ($_POST['valid'] == '0' || $_POST['valid'] == '1') && |
2301 |
+ $_POST['config_path'] != '' && filter_var($_POST['config_path'], FILTER_VALIDATE_URL) |
2302 |
+ ){ |
2303 |
+ |
2304 |
+ if ($_POST['api_key'] == WMobilePack_Options::get_setting('premium_api_key')) { |
2305 |
+ |
2306 |
+ $arr_data = array( |
2307 |
+ 'premium_api_key' => $_POST['api_key'], |
2308 |
+ 'premium_active' => $_POST['valid'], |
2309 |
+ 'premium_config_path' => $_POST['config_path'] |
2310 |
+ ); |
2311 |
+ |
2312 |
+ if (WMobilePack_Options::update_settings($arr_data)) { |
2313 |
+ |
2314 |
+ // attempt to load the settings json |
2315 |
+ $premium_manager = $this->get_premium_manager(); |
2316 |
+ $json_config_premium = $premium_manager->set_premium_config(); |
2317 |
+ |
2318 |
+ if ($json_config_premium !== false){ |
2319 |
+ $status = 1; |
2320 |
+ } else { |
2321 |
+ WMobilePack_Options::update_settings('premium_active', 0); |
2322 |
+ } |
2323 |
+ } |
2324 |
+ } |
2325 |
+ } |
2326 |
+ } |
2327 |
+ } |
2328 |
+ |
2329 |
+ echo $status; |
2330 |
+ |
2331 |
+ } |
2332 |
+ |
2333 |
+ exit(); |
2334 |
+ } |
2335 |
+ |
2336 |
+ |
2337 |
+ /** |
2338 |
+ * |
2339 |
+ * Method used to disconnect the dashboard from Appticles and revert to basic theme |
2340 |
+ * |
2341 |
+ */ |
2342 |
+ public function premium_disconnect(){ |
2343 |
+ |
2344 |
+ if (current_user_can('manage_options')){ |
2345 |
+ |
2346 |
+ $status = 0; |
2347 |
+ |
2348 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
2349 |
+ |
2350 |
+ if (isset($_POST['api_key']) && isset($_POST['active'])){ |
2351 |
+ |
2352 |
+ if (preg_match('/^[a-zA-Z0-9]+$/', $_POST['api_key']) && $_POST['active'] == 0){ |
2353 |
+ |
2354 |
+ $status = 1; |
2355 |
+ |
2356 |
+ // delete transient with the json config |
2357 |
+ if (get_transient(WMobilePack_Options::$transient_prefix."premium_config_path") !== false) |
2358 |
+ delete_transient(WMobilePack_Options::$transient_prefix.'premium_config_path'); |
2359 |
+ |
2360 |
+ $arr_data = array( |
2361 |
+ 'premium_api_key' => '', |
2362 |
+ 'premium_active' => 0, |
2363 |
+ 'premium_config_path' => '' |
2364 |
+ ); |
2365 |
+ |
2366 |
+ // save options |
2367 |
+ WMobilePack_Options::update_settings($arr_data); |
2368 |
+ } |
2369 |
+ } |
2370 |
+ } |
2371 |
+ |
2372 |
+ echo $status; |
2373 |
+ } |
2374 |
+ |
2375 |
+ exit(); |
2376 |
+ } |
2377 |
+ |
2378 |
+ /** |
2379 |
+ * |
2380 |
+ * Method used to send a feedback e-mail from the admin |
2381 |
+ * |
2382 |
+ * Handle request, then display 1 for success and 0 for error. |
2383 |
+ * |
2384 |
+ */ |
2385 |
+ public function send_feedback() |
2386 |
+ { |
2387 |
+ |
2388 |
+ if (current_user_can('manage_options')){ |
2389 |
+ |
2390 |
+ $status = 0; |
2391 |
+ |
2392 |
+ if (isset($_POST) && is_array($_POST) && !empty($_POST)){ |
2393 |
+ |
2394 |
+ if (isset($_POST['wmp_feedback_page']) && |
2395 |
+ isset($_POST['wmp_feedback_name']) && |
2396 |
+ isset($_POST['wmp_feedback_email']) && |
2397 |
+ isset($_POST['wmp_feedback_message'])){ |
2398 |
+ |
2399 |
+ if ($_POST['wmp_feedback_page'] != '' && |
2400 |
+ $_POST['wmp_feedback_name'] != '' && |
2401 |
+ $_POST['wmp_feedback_email'] != '' && |
2402 |
+ $_POST['wmp_feedback_message'] != ''){ |
2403 |
+ |
2404 |
+ $admin_email = $_POST['wmp_feedback_email']; |
2405 |
+ |
2406 |
+ // filter e-mail |
2407 |
+ if (filter_var($admin_email, FILTER_VALIDATE_EMAIL) !== false ){ |
2408 |
+ |
2409 |
+ // set e-mail variables |
2410 |
+ $message = "Name: ".strip_tags($_POST["wmp_feedback_name"])."\r\n \r\n"; |
2411 |
+ $message .= "E-mail: ".$admin_email."\r\n \r\n"; |
2412 |
+ $message .= "Message: ".strip_tags($_POST["wmp_feedback_message"])."\r\n \r\n"; |
2413 |
+ $message .= "Page: ".stripslashes(strip_tags($_POST['wmp_feedback_page']))."\r\n \r\n"; |
2414 |
+ |
2415 |
+ if (isset($_SERVER['HTTP_HOST'])) |
2416 |
+ $message .= "Host: ".$_SERVER['HTTP_HOST']."\r\n \r\n"; |
2417 |
+ |
2418 |
+ $subject = WMP_PLUGIN_NAME.' Feedback'; |
2419 |
+ $to = WMP_FEEDBACK_EMAIL; |
2420 |
+ |
2421 |
+ // set headers |
2422 |
+ $headers = 'From:'.$admin_email."\r\nReply-To:".$admin_email; |
2423 |
+ |
2424 |
+ // send e-mail |
2425 |
+ if (mail($to, $subject, $message, $headers)) |
2426 |
+ $status = 1; |
2427 |
+ } |
2428 |
+ } |
2429 |
+ } |
2430 |
+ } |
2431 |
+ |
2432 |
+ echo $status; |
2433 |
+ } |
2434 |
+ |
2435 |
+ exit(); |
2436 |
+ } |
2437 |
+ } |
2438 |
+} |
2439 |
|
2440 |
diff --git a/plugins/wordpress-mobile-pack/admin/class-admin-init.php b/plugins/wordpress-mobile-pack/admin/class-admin-init.php |
2441 |
index e111414..e85f61b 100755 |
2442 |
--- a/plugins/wordpress-mobile-pack/admin/class-admin-init.php |
2443 |
+++ b/plugins/wordpress-mobile-pack/admin/class-admin-init.php |
2444 |
@@ -1,320 +1,337 @@ |
2445 |
-<?php |
2446 |
- |
2447 |
-if ( ! class_exists( 'WMobilePack_Admin' ) ) { |
2448 |
- require_once(WMP_PLUGIN_PATH.'admin/class-admin.php'); |
2449 |
-} |
2450 |
- |
2451 |
-if ( ! class_exists( 'WMobilePack_Themes_Config' )) { |
2452 |
- require_once(WMP_PLUGIN_PATH.'inc/class-wmp-themes-config.php'); |
2453 |
-} |
2454 |
- |
2455 |
-if ( ! class_exists( 'WMobilePack_Admin_Init' ) ) { |
2456 |
- |
2457 |
- /** |
2458 |
- * WMobilePack_Admin_Init class for initializing the admin area for the Wordpress Mobile Pack plugin |
2459 |
- * |
2460 |
- * Displays menu & loads static files for each admin page. |
2461 |
- */ |
2462 |
- class WMobilePack_Admin_Init |
2463 |
- { |
2464 |
- |
2465 |
- /** |
2466 |
- * The menu item's title |
2467 |
- * @var string |
2468 |
- */ |
2469 |
- private static $submenu_title = WMP_PLUGIN_NAME; |
2470 |
- |
2471 |
- /** |
2472 |
- * Submenu pages arrays. Each item has the following properties: |
2473 |
- * |
2474 |
- * - page_title = The page's and menu's title |
2475 |
- * - capability = GET parameter to be sent to the admin.php page |
2476 |
- * - function = The admin function that display the page (from class-admin.php) |
2477 |
- * - enqueue_hook = (optional) The method that adds the Javascript & CSS files required by each page |
2478 |
- * |
2479 |
- * @var array |
2480 |
- */ |
2481 |
- private static $submenu_pages = array( |
2482 |
- array( |
2483 |
- 'page_title' => "Quick Start", |
2484 |
- 'capability' => 'wmp-options', |
2485 |
- 'function' => 'whatsnew', |
2486 |
- ), |
2487 |
- array( |
2488 |
- 'page_title' => "Look & Feel", |
2489 |
- 'capability' => 'wmp-options-theme', |
2490 |
- 'function' => 'theme', |
2491 |
- 'enqueue_hook' => 'wmp_admin_load_theme_js' |
2492 |
- ), |
2493 |
- array( |
2494 |
- 'page_title' => "Content", |
2495 |
- 'capability' => 'wmp-options-content', |
2496 |
- 'function' => 'content', |
2497 |
- 'enqueue_hook' => 'wmp_admin_load_content_js' |
2498 |
- ), |
2499 |
- array( |
2500 |
- 'page_title' => "Settings", |
2501 |
- 'capability' => 'wmp-options-settings', |
2502 |
- 'function' => 'settings', |
2503 |
- 'enqueue_hook' => 'wmp_admin_load_settings_js' |
2504 |