PluginProbe
Vision – Interactive Image Map with Hotspots Builder / 1.6.2
Vision – Interactive Image Map with Hotspots Builder v1.6.2
1.12.2 1.12.1 1.12.0 1.11.0 1.6.0 1.6.1 1.6.2 1.7.1 1.7.2 1.7.3 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 All 33 releases
vision / includes / plugin.php

plugin.php in Vision – Interactive Image Map with Hotspots Builder 1.6.2, at includes/plugin.php

1,195 lines 44.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || exit;
3
4 class Vision_Builder {
5 private $pluginBasename = NULL;
6
7 private $ajax_action_item_update = NULL;
8 private $ajax_action_item_update_status = NULL;
9 private $ajax_action_settings_update = NULL;
10 private $ajax_action_settings_get = NULL;
11 private $ajax_action_delete_data = NULL;
12 private $ajax_action_modal = NULL;
13
14 private $vision_map_id = null;
15 private $vision_map_version = null;
16 private $shortcodes = [];
17
18 function __construct($pluginBasename) {
19 $this->pluginBasename = $pluginBasename;
20 }
21
22 function run() {
23 $upload_dir = wp_upload_dir();
24 $plugin_url = plugin_dir_url(dirname(__FILE__));
25
26 define('VISION_PLUGIN_UPLOAD_DIR', wp_normalize_path($upload_dir['basedir'] . '/vision'));
27 define('VISION_PLUGIN_UPLOAD_URL', set_url_scheme($upload_dir['baseurl'] . '/vision/'));
28
29 define('VISION_PLUGIN_PLAN', 'lite');
30
31 $user = wp_get_current_user(); //is_super_admin()
32 $allowed_roles = $this->getAllowedRoles();
33 if((array_intersect($allowed_roles, $user->roles) || current_user_can('manage_options')) && is_admin()) {
34 $this->ajax_action_item_update = 'vision_ajax_item_update';
35 $this->ajax_action_item_update_status = 'vision_ajax_item_update_status';
36 $this->ajax_action_settings_update = 'vision_ajax_settings_update';
37 $this->ajax_action_settings_get = 'vision_ajax_settings_get';
38 $this->ajax_action_delete_data = 'vision_ajax_delete_data';
39 $this->ajax_action_modal = 'vision_ajax_modal';
40
41 load_plugin_textdomain('vision', false, dirname(dirname(plugin_basename(__FILE__))) . '/languages/');
42
43 add_action('admin_menu', [$this, 'admin_menu']);
44 add_action('admin_footer', [$this, 'admin_footer']);
45 add_action('admin_notices', [$this, 'admin_notices']);
46 add_action('in_admin_header', [$this, 'in_admin_header']);
47 add_action('wp_loaded', [$this, 'page_redirects']);
48
49 // important, because ajax has another url
50 add_action('wp_ajax_' . $this->ajax_action_item_update, [$this, 'ajax_item_update']);
51 add_action('wp_ajax_' . $this->ajax_action_item_update_status, [$this, 'ajax_item_update_status']);
52 add_action('wp_ajax_' . $this->ajax_action_settings_update, [$this, 'ajax_settings_update']);
53 add_action('wp_ajax_' . $this->ajax_action_settings_get, [$this, 'ajax_settings_get']);
54 add_action('wp_ajax_' . $this->ajax_action_delete_data, [$this, 'ajax_delete_data']);
55 add_action('wp_ajax_' . $this->ajax_action_modal, [$this, 'ajax_modal']);
56 } else {
57 add_shortcode(VISION_SHORTCODE_NAME, [$this, 'shortcode']);
58 }
59
60 // only logged users with right roles can preview a vision map
61 if(array_intersect($allowed_roles, $user->roles) || current_user_can('manage_options')) {
62 add_filter('do_parse_request', [$this, 'do_parse_request'], 10, 3);
63 }
64 }
65
66 function joinPaths() {
67 $paths = [];
68
69 foreach(func_get_args() as $arg) {
70 if($arg !== '') {
71 $paths[] = $arg;
72 }
73 }
74
75 return preg_replace('#/+#','/',join('/', $paths));
76 }
77
78 function joinUrls() {
79 $urls = [];
80
81 foreach(func_get_args() as $arg) {
82 if($arg !== '') {
83 $urls[] = $arg;
84 }
85 }
86
87 return preg_replace('/([^:])(\/{2,})/','$1/',join('/', $urls));
88 }
89
90 function IsNullOrEmptyString($str) {
91 return(!isset($str) || trim($str)==='');
92 }
93
94 function getAllowedRoles() {
95 $allowed_roles = ['administrator'];
96
97 $settings_key = 'vision_settings';
98 $settings_value = get_option($settings_key);
99 if($settings_value) {
100 $settings = unserialize($settings_value);
101 if(is_array($settings->roles)) $allowed_roles = array_merge($allowed_roles, $settings->roles);
102 }
103
104 return $allowed_roles;
105 }
106
107 function getLoaderGlobals($timestamp) {
108 $plugin_url = plugin_dir_url(dirname(__FILE__));
109
110 $globals = [
111 'plan' => VISION_PLUGIN_PLAN,
112 'version' => $timestamp,
113 'effects_url' => $plugin_url . 'assets/css/vision-effects.min.css',
114 'theme_base_url' => $plugin_url . 'assets/themes/',
115 'plugin_base_url' => $plugin_url . 'assets/js/lib/vision/',
116 'plugin_upload_base_url' => VISION_PLUGIN_UPLOAD_URL,
117 'plugin_version' => VISION_PLUGIN_VERSION,
118 'ssl' => is_ssl()
119 ];
120
121 return $globals;
122 }
123
124 function embedLoader($in_footer, $timestamp) {
125 $plugin_url = plugin_dir_url(dirname(__FILE__));
126 wp_enqueue_script('vision_loader_js', $plugin_url . 'assets/js/loader.min.js', ['jquery'], VISION_PLUGIN_VERSION, $in_footer);
127 wp_localize_script('vision_loader_js', 'vision_globals', $this->getLoaderGlobals($timestamp));
128 }
129
130 /**
131 * generate main css text
132 */
133 function getMainCss($itemData, $itemId) {
134 $upload_dir = wp_upload_dir();
135
136 // create main css
137 $main_css = '';
138 $main_css .= '.vision-map-' . $itemId . ' {' . PHP_EOL;
139
140 $main_css .= (!$this->IsNullOrEmptyString($itemData->background->color) ? 'background-color:' . $itemData->background->color . ';' . PHP_EOL : '');
141 if(!$this->IsNullOrEmptyString($itemData->background->image->url)) {
142 $imageUrl = ($itemData->background->image->relative ? $upload_dir['baseurl'] : '') . $itemData->background->image->url;
143 $main_css .= 'background-image:url(' . $imageUrl . ');' . PHP_EOL;
144 }
145 $main_css .= ($itemData->background->size ? 'background-size:' . $itemData->background->size . ';' . PHP_EOL : '');
146 $main_css .= ($itemData->background->repeat ? 'background-repeat:' . $itemData->background->repeat . ';' . PHP_EOL : '');
147 $main_css .= ($itemData->background->position ? 'background-position:' . $itemData->background->position . ';' . PHP_EOL : '');
148
149 $main_css .= '}' . PHP_EOL;
150
151 $layerId = 0;
152 foreach($itemData->layers as $layerKey => $layer) {
153 if(!$layer->visible) {
154 continue;
155 }
156
157 $layerId++;
158 $layerSelector = '.vision-map-' . $itemId . ' .vision-layers [data-layer-id="' . $layer->id . '"] .vision-body';
159
160 // main
161 $main_css .= $layerSelector . ' {' . PHP_EOL;
162 switch($layer->type) {
163 case 'link': {
164 $main_css .= ($layer->link->normalColor ? 'background-color:' . $layer->link->normalColor . ';' . PHP_EOL : '');
165 $main_css .= ($layer->link->radius != NULL ? 'border-radius:' . $layer->link->radius . ';' . PHP_EOL : '');
166 } break;
167 case 'image': {
168 $main_css .= (!$this->IsNullOrEmptyString($layer->image->background->color) ? 'background-color:' . $layer->image->background->color . ';' . PHP_EOL : '');
169 if(!$this->IsNullOrEmptyString($layer->image->background->file->url)) {
170 $imageUrl = ($layer->image->background->file->relative ? $upload_dir['baseurl'] : '') . $layer->image->background->file->url;
171 $main_css .= 'background-image:url(' . $imageUrl . ');' . PHP_EOL;
172 }
173 $main_css .= ($layer->image->background->size ? 'background-size:' . $layer->image->background->size . ';' . PHP_EOL : '');
174 $main_css .= ($layer->image->background->repeat ? 'background-repeat:' . $layer->image->background->repeat . ';' . PHP_EOL : '');
175 $main_css .= ($layer->image->background->position ? 'background-position:' . $layer->image->background->position . ';' . PHP_EOL : '');
176 } break;
177 case 'text': {
178 $main_css .= (!$this->IsNullOrEmptyString($layer->text->background->color) ? 'background-color:' . $layer->text->background->color . ';' . PHP_EOL : '');
179 if(!$this->IsNullOrEmptyString($layer->text->background->file->url)) {
180 $imageUrl = ($layer->text->background->file->relative ? $upload_dir['baseurl'] : '') . $layer->text->background->file->url;
181 $main_css .= 'background-image:url(' . $imageUrl . ');' . PHP_EOL;
182 }
183 $main_css .= ($layer->text->background->size ? 'background-size:' . $layer->text->background->size . ';' . PHP_EOL : '');
184 $main_css .= ($layer->text->background->repeat ? 'background-repeat:' . $layer->text->background->repeat . ';' . PHP_EOL : '');
185 $main_css .= ($layer->text->background->position ? 'background-position:' . $layer->text->background->position . ';' . PHP_EOL : '');
186
187 $main_css .= ($layer->text->font ? 'font-family:"' . str_replace('+', ' ', $layer->text->font) . '",sans-serif;' . PHP_EOL : '');
188 $main_css .= ($layer->text->color ? 'color:' . $layer->text->color . ';' . PHP_EOL : '');
189 $main_css .= ($layer->text->size != NULL ? 'font-size:' . $layer->text->size . 'px;' . PHP_EOL : '');
190 $main_css .= ($layer->text->lineHeight != NULL ? 'line-height:' . $layer->text->lineHeight . 'px;' . PHP_EOL : '');
191 $main_css .= ($layer->text->align ? 'text-align:' . $layer->text->align . ';' . PHP_EOL : '');
192 $main_css .= ($layer->text->letterSpacing != NULL ? 'letter-spacing:' . $layer->text->letterSpacing . 'px;' . PHP_EOL : '');
193 } break;
194 }
195 $main_css .= '}' . PHP_EOL;
196
197 if($layer->type == 'link') {
198 $main_css .= $layerSelector . ':hover {' . PHP_EOL;
199 $main_css .= ($layer->link->hoverColor ? 'background-color:' . $layer->link->hoverColor . ';' . PHP_EOL : '');
200 $main_css .= '}' . PHP_EOL;
201 }
202 }
203
204 return $main_css;
205 }
206
207 /**
208 * Shortcode output for the plugin
209 */
210 function shortcode($atts) {
211 $keys_valid = ['id', 'slug', 'class'];
212 $atts_valid = array_filter($atts, function($key) use ($keys_valid) {
213 return in_array($key, $keys_valid);
214 }, ARRAY_FILTER_USE_KEY);
215 $opt_valid = [
216 'id' => FILTER_SANITIZE_NUMBER_INT,
217 'slug' => FILTER_SANITIZE_STRING,
218 'class' => FILTER_SANITIZE_STRING
219 ];
220 $atts_valid = filter_var_array($atts_valid, $opt_valid);
221
222 extract(shortcode_atts(['id'=>0, 'slug'=>NULL, 'class'=>NULL], $atts_valid));
223
224 if(!$id && !$slug) {
225 return '<p>' . esc_html__('Error: invalid vision identifier attribute', 'vision') . '</p>';
226 }
227
228 global $wpdb;
229 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
230 $upload_dir = wp_upload_dir();
231
232 $sql = ($id ? $wpdb->prepare("SELECT * FROM {$table} WHERE id=%d AND NOT deleted", $id) : $wpdb->prepare("SELECT * FROM {$table} WHERE slug=%s AND NOT deleted LIMIT 0, 1", $slug));
233 $item = $wpdb->get_row($sql, OBJECT);
234 $preview = filter_input(INPUT_GET, 'preview', FILTER_SANITIZE_NUMBER_INT);
235
236 if($item && ($item->active || (!$item->active && $preview == 1))) {
237 $version = strtotime(mysql2date('d M Y H:i:s', $item->modified));
238 $itemData = unserialize($item->data);
239 $id = $item->id;
240 $id_postfix = strtolower(wp_generate_password(5, false)); // generate unique postfix for $id to avoid clashes with multiple same shortcode use
241 $id_element = 'vision-' . $id . '-' . $id_postfix;
242
243 array_push($this->shortcodes, ['id' => $item->id, 'version' => $version]);
244
245 if(sizeof($this->shortcodes) == 1) {
246 $this->embedLoader(true, $version);
247 }
248
249 ob_start(); // turn on buffering
250
251 echo '<!-- vision begin -->' . PHP_EOL;
252 echo '<div ';
253 echo (property_exists($itemData, 'containerId') && $itemData->containerId ? 'id="' . esc_attr($itemData->containerId) . '" ':'');
254 echo 'class="vision-map vision-map-' . esc_attr($id . ($class ? ' ' . $class : '')) . '"';
255 echo 'data-json-src="'. VISION_PLUGIN_UPLOAD_URL . $item->id . '/config.json' . ($version ? '?ver=' . $version : '') . '" ';
256 echo 'data-item-id="' . esc_attr($item->id) . '" ';
257 echo 'tabindex="1" ';
258 echo 'style="display:none;" ';
259 echo '>' . PHP_EOL;
260
261 //=============================================
262 // STORE BEGIN
263 echo '<div class="vision-store">' . PHP_EOL;
264 echo '<div class="vision-layers-data">' . PHP_EOL;
265 foreach($itemData->layers as $layerKey => $layer) {
266 if(!$layer->visible) {
267 continue;
268 }
269
270 //=============================================
271 // LAYER BEGIN
272 echo '<div class="vision-layer" data-layer-id="' . esc_attr($layer->id) . '">';
273
274 if($layer->contentData) {
275 echo do_shortcode($layer->contentData);
276 }
277
278 if($layer->type == 'text') {
279 echo wp_kses_post($layer->text->data);
280 }
281
282 if($layer->type == 'svg') {
283 if(!$this->IsNullOrEmptyString($layer->svg->file->url)) {
284 $svgUrl = ($layer->svg->file->url ? ($layer->svg->file->relative ? $upload_dir['baseurl'] : '') . $layer->svg->file->url : '');
285 echo file_get_contents($svgUrl, FILE_USE_INCLUDE_PATH);
286 }
287 }
288
289 echo '</div>' . PHP_EOL;
290 // LAYER END
291 //=============================================
292 }
293 echo '</div>' . PHP_EOL;
294
295 echo '<div class="vision-tooltips-data">' . PHP_EOL;
296 foreach($itemData->layers as $layerKey => $layer) {
297 if(!$layer->visible) {
298 continue;
299 }
300
301 //=============================================
302 // TOOLTIP BEGIN
303 echo '<div class="vision-data" data-layer-id="' . esc_attr($layer->id) . '">';
304 echo do_shortcode($layer->tooltip->data);
305 echo '</div>' . PHP_EOL;
306 // TOOLTIP END
307 //=============================================
308 }
309 echo '</div>' . PHP_EOL;
310
311 echo '<div class="vision-popovers-data">' . PHP_EOL;
312 foreach($itemData->layers as $layerKey => $layer) {
313 if(!$layer->visible) {
314 continue;
315 }
316
317 //=============================================
318 // POPOVER BEGIN
319 echo '<div class="vision-data" data-layer-id="' . esc_attr($layer->id) . '">';
320 echo do_shortcode($layer->popover->data);
321 echo '</div>' . PHP_EOL;
322 // POPOVER END
323 //=============================================
324 }
325 echo '</div>' . PHP_EOL;
326
327 echo '</div>' . PHP_EOL;
328 // STORE END
329 //=============================================
330
331 echo '</div>' . PHP_EOL;
332 echo '<!-- vision end -->' . PHP_EOL;
333
334 $output = ob_get_contents(); // get the buffered content into a var
335 ob_end_clean(); // clean buffer
336
337 return $output;
338 }
339
340 return '<p>' . esc_html__('Error: the vision item can’t be found', 'vision') . '</p>';
341 }
342
343 /**
344 * Run a filter to obtain some custom url settings, compare them to the current url
345 * and if a match is found the custom callback is fired, the custom view is loaded
346 * and request is stopped.
347 */
348 function do_parse_request($result) {
349 if(current_filter() !== 'do_parse_request') {
350 return $result;
351 }
352
353 if(preg_match('/vision\/map\/([a-z0-9_-]+)/', $_SERVER['REQUEST_URI'], $matches)) {
354 $preview = filter_input(INPUT_GET, 'preview', FILTER_SANITIZE_NUMBER_INT);
355
356 global $wpdb;
357 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
358 $shortcode = false;
359
360 if(is_numeric($matches[1])) {
361 $vision_map_id = $matches[1];
362
363 if($vision_map_id != null) {
364 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE id=%d AND NOT deleted", $vision_map_id);
365 $item = $wpdb->get_row($sql, OBJECT);
366
367 if($item && ($item->active || (!$item->active && $preview == 1))) {
368 $this->vision_map_id = $item->id;
369 $this->vision_map_version = strtotime(mysql2date('Y-m-d H:i:s', $item->modified));
370 $shortcode = true;
371 }
372 }
373 } else {
374 $vision_map_slug = $matches[1];
375
376 if($vision_map_slug != null) {
377 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE slug=%s AND NOT deleted", $vision_map_slug);
378 $item = $wpdb->get_row($sql, OBJECT);
379
380 if($item && ($item->active || (!$item->active && $preview == 1))) {
381 $this->vision_map_id = $item->id;
382 $this->vision_map_version = strtotime(mysql2date('Y-m-d H:i:s', $item->modified));
383
384 $shortcode = true;
385 }
386 }
387 }
388
389 if($shortcode) {
390 require_once(plugin_dir_path(dirname(__FILE__)) . 'includes/page-preview.php');
391 exit();
392 }
393 }
394
395 return $result;
396 }
397
398 /**
399 * Prepare upload directory
400 */
401 function admin_notices() {
402 $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
403
404 if(!($page==='vision' || $page==='vision_item')) {
405 return;
406 }
407
408 if(!file_exists(VISION_PLUGIN_UPLOAD_DIR)) {
409 wp_mkdir_p(VISION_PLUGIN_UPLOAD_DIR);
410 }
411
412 if(!file_exists(VISION_PLUGIN_UPLOAD_DIR)) {
413 echo '<div class="notice notice-error is-dismissible">';
414 echo '<p>' . sprintf(esc_html__('The "%s" directory could not be created', 'vision'), '<b>vision</b>') . '</p>';
415 echo '<p>' . esc_html__('Please run the following commands in order to make the directory', 'vision') . '<br>';
416 echo '<b>mkdir ' . VISION_PLUGIN_UPLOAD_DIR . '</b><br>';
417 echo '<b>chmod 777 ' . VISION_PLUGIN_UPLOAD_DIR . '</b></p>';
418 echo '</div>';
419 return;
420 }
421
422 if(!wp_is_writable(VISION_PLUGIN_UPLOAD_DIR)) {
423 echo '<div class="notice notice-error is-dismissible">';
424 echo '<p>' . sprintf(esc_html__('The "%s" directory is not writable, therefore the css and js files cannot be saved.', 'vision'), '<b>vision</b>') . '</p>';
425 echo '<p>' . esc_html__('Please run the following commands in order to make the directory', 'vision') . '<br>';
426 echo '<b>chmod 777 ' . VISION_PLUGIN_UPLOAD_DIR . '</b></p>';
427 echo '</div>';
428 return;
429 }
430
431 if(!file_exists(VISION_PLUGIN_UPLOAD_DIR . '/' . 'index.php')) {
432 $data = '<?php' . PHP_EOL . '// silence is golden' . PHP_EOL . '?>';
433 @file_put_contents(VISION_PLUGIN_UPLOAD_DIR . '/' . 'index.php', $data);
434 }
435 }
436
437 /**
438 * Fires at the beginning of the content section in an admin page
439 */
440 function in_admin_header() {
441 $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
442
443 if(!(($page==='vision') || ($page==='vision_item') || ($page==='vision_settings'))) {
444 return;
445 }
446
447 remove_all_actions('admin_notices');
448 remove_all_actions('all_admin_notices');
449 add_action('admin_notices', [$this, 'admin_notices']);
450 }
451
452 /**
453 * Register the administration menu for this plugin into the WordPress Dashboard menu.
454 */
455 function admin_menu() {
456 // add "edit_posts" if we want to give access to author, editor and contributor roles
457 add_menu_page(esc_html__('Vision', 'vision'), esc_html__('Vision', 'vision'), 'read', 'vision', [$this, 'admin_menu_page_items'], 'dashicons-format-image');
458 add_submenu_page('vision', esc_html__('Vision', 'vision'), esc_html__('All Items', 'vision'), 'read', 'vision', [$this, 'admin_menu_page_items']);
459 add_submenu_page('vision', esc_html__('Vision', 'vision'), esc_html__('Add New', 'vision'), 'read', 'vision_item', [$this, 'admin_menu_page_item']);
460 add_submenu_page('vision', esc_html__('Vision', 'vision'), esc_html__('Settings', 'vision'), 'manage_options', 'vision_settings', [$this, 'admin_menu_page_settings']);
461 }
462
463 function admin_footer() {
464 if(get_current_screen() && get_current_screen()->base !== 'plugins') {
465 return;
466 }
467
468 $globals = [
469 'token' => $this->get_token(),
470 'ajax' => [
471 'url' => VISION_FEEDBACK_URL
472 ]
473 ];
474
475 wp_enqueue_style('vision-feedback-css', VISION_PLUGIN_URL . 'assets/css/feedback.min.css', [], VISION_PLUGIN_VERSION);
476 wp_enqueue_script('vision-feedback-js', VISION_PLUGIN_URL . 'assets/js/feedback.min.js', ['jquery'], VISION_PLUGIN_VERSION, false);
477 wp_localize_script('vision-feedback-js', 'vision_feedback_globals', $globals);
478
479 require_once(plugin_dir_path(dirname(__FILE__)) . 'templates/feedback.php');
480 }
481
482 function get_token() {
483 global $wp_version;
484 $current_user = wp_get_current_user();
485
486 $data = [
487 'plugin_name' => VISION_PLUGIN_NAME,
488 'plugin_version' => VISION_PLUGIN_VERSION,
489 'wordpress' => $wp_version,
490 'php' => PHP_VERSION,
491 'email' => $current_user->user_email,
492 'site' => trim(str_replace(['http://', 'https://'], '', get_site_url()), '/')
493 ];
494 return base64_encode(json_encode($data));
495 }
496
497 /**
498 * Custom redirects
499 */
500 function page_redirects() {
501 $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
502
503 if($page==='vision') {
504 $action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
505 if($action) {
506 $url = remove_query_arg(['action', 'id', '_wpnonce'], $_SERVER['REQUEST_URI']);
507 header('Refresh:0; url="' . $url . '"', true, 303);
508 //wp_redirect($url); // does not work delete and dublicate operations on XAMPP
509 }
510 }
511 }
512
513 /**
514 * Show admin menu items page
515 */
516 function admin_menu_page_items() {
517 $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
518
519 if($page==='vision') {
520 $plugin_url = plugin_dir_url( dirname(__FILE__) );
521 $upload_dir = wp_upload_dir();
522
523 wp_enqueue_style('vision_admin_css', $plugin_url . 'assets/css/admin.min.css', [], VISION_PLUGIN_VERSION, 'all' );
524 wp_enqueue_style('vision_fontawesome_css', $plugin_url . 'assets/css/font-awesome.min.css', [], VISION_PLUGIN_VERSION, 'all' );
525 wp_enqueue_script('vision_admin_js', $plugin_url . 'assets/js/admin.min.js', ['jquery'], VISION_PLUGIN_VERSION, false );
526
527 // global settings to help ajax work
528 $globals = [
529 'plan' => VISION_PLUGIN_PLAN,
530 'msg_pro_title' => esc_html__('Available only in Pro version', 'vision'),
531 'upload_url' => $upload_dir['baseurl'],
532 'ajax_url' => admin_url('admin-ajax.php'),
533 'ajax_nonce' => wp_create_nonce('vision_ajax' ),
534 'ajax_msg_error' => esc_html__('Uncaught Error', 'vision') //Look at the console (F12 or Ctrl+Shift+I, Console tab) for more information
535 ];
536 $globals['ajax_action_update'] = $this->ajax_action_item_update_status;
537
538 require_once(plugin_dir_path( dirname(__FILE__) ) . 'includes/list-table-items.php');
539 require_once(plugin_dir_path( dirname(__FILE__) ) . 'includes/page-items.php');
540
541 wp_localize_script('vision_admin_js', 'vision_globals', $globals);
542 }
543 }
544
545 /**
546 * Show admin menu item page
547 */
548 function admin_menu_page_item() {
549 $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
550
551 if($page==='vision_item') {
552 $plugin_url = plugin_dir_url(dirname(__FILE__));
553 $upload_dir = wp_upload_dir();
554
555 wp_enqueue_style('vision_admin_css', $plugin_url . 'assets/css/admin.min.css', [], VISION_PLUGIN_VERSION, 'all' );
556 wp_enqueue_style('vision_fontawesome_css', $plugin_url . 'assets/css/font-awesome.min.css', [], VISION_PLUGIN_VERSION, 'all' );
557 wp_enqueue_style('vision_vision_effects_css', $plugin_url . 'assets/css/vision-effects.min.css', [], VISION_PLUGIN_VERSION, 'all' );
558 wp_enqueue_script('vision_ace_js', $plugin_url . 'assets/js/lib/ace/ace.js', [], VISION_PLUGIN_VERSION, false );
559 wp_enqueue_script('vision_url_js', $plugin_url . 'assets/js/lib/url/url.min.js', [], VISION_PLUGIN_VERSION, false );
560 wp_enqueue_script('vision_admin_js', $plugin_url . 'assets/js/admin.min.js', ['jquery'], VISION_PLUGIN_VERSION, false );
561 wp_enqueue_media();
562
563 // global settings to help ajax work
564 $globals = [
565 'plan' => VISION_PLUGIN_PLAN,
566 'msg_pro_title' => esc_html__('Available only in Pro version', 'vision'),
567 'msg_edit_text' => esc_html__('Edit your text here', 'vision'),
568 'msg_custom_js_error' => esc_html__('Custom js code error', 'vision'),
569 'msg_layer_id_error' => esc_html__('The layer ID should be unique', 'vision'),
570 'wp_base_url' => get_site_url(),
571 'upload_base_url' => $upload_dir['baseurl'],
572 'plugin_base_url' => $plugin_url,
573 'ajax_url' => admin_url('admin-ajax.php'),
574 'ajax_nonce' => wp_create_nonce('vision_ajax'),
575 'ajax_msg_error' => esc_html__('Uncaught Error', 'vision') //Look at the console (F12 or Ctrl+Shift+I, Console tab) for more information
576 ];
577
578 $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
579
580 $globals['ajax_action_get'] = $this->ajax_action_settings_get;
581 $globals['ajax_action_update'] = $this->ajax_action_item_update;
582 $globals['ajax_action_modal'] = $this->ajax_action_modal;
583 $globals['ajax_item_id'] = $id;
584 $globals['settings'] = NULL;
585 $globals['config'] = NULL;
586
587 $settings_key = 'vision_settings';
588 $settings_value = get_option($settings_key);
589 if($settings_value) {
590 $globals['settings'] = unserialize($settings_value); // json_encode(unserialize($settings_value)) problem with double quotes
591 }
592
593 // get item data from DB
594 if($id) {
595 global $wpdb;
596 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
597
598 $query = $wpdb->prepare("SELECT * FROM {$table} WHERE id=%s", $id);
599 $item = $wpdb->get_row($query, OBJECT);
600 if($item) {
601 $globals['config'] = unserialize($item->data); // json_encode(unserialize($item->data)) problem with double quotes
602 }
603 } else {
604 // new item
605 $item = (object) [
606 'author' => get_current_user_id(),
607 'editor' => get_current_user_id(),
608 'created' => current_time('mysql', 1),
609 'modified' => current_time('mysql', 1)
610 ];
611 }
612
613 require_once( plugin_dir_path( dirname(__FILE__) ) . 'includes/page-item.php' );
614
615 // set global settings
616 wp_localize_script('vision_admin_js', 'vision_globals', $globals);
617 }
618 }
619
620 /**
621 * Show admin menu settings page
622 */
623 function admin_menu_page_settings() {
624 $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
625
626 if($page==='vision_settings') {
627 $plugin_url = plugin_dir_url(dirname(__FILE__));
628
629 wp_enqueue_style('vision_admin_css', $plugin_url . 'assets/css/admin.min.css', [], VISION_PLUGIN_VERSION, 'all' );
630 wp_enqueue_style('vision_fontawesome_css', $plugin_url . 'assets/css/font-awesome.min.css', [], VISION_PLUGIN_VERSION, 'all' );
631 wp_enqueue_script('vision_admin_js', $plugin_url . 'assets/js/admin.min.js', ['jquery'], VISION_PLUGIN_VERSION, false );
632
633 // global settings to help ajax work
634 $globals = [
635 'plan' => VISION_PLUGIN_PLAN,
636 'msg_pro_title' => esc_html__('Available only in Pro version', 'vision'),
637 'ajax_url' => admin_url('admin-ajax.php'),
638 'ajax_nonce' => wp_create_nonce('vision_ajax' ),
639 'ajax_msg_error' => esc_html__('Uncaught Error', 'vision') //Look at the console (F12 or Ctrl+Shift+I, Console tab) for more information
640 ];
641
642 $globals['ajax_action_update'] = $this->ajax_action_settings_update;
643 $globals['ajax_action_get'] = $this->ajax_action_settings_get;
644 $globals['ajax_action_modal'] = $this->ajax_action_modal;
645 $globals['ajax_action_delete_data'] = $this->ajax_action_delete_data;
646 $globals['config'] = NULL;
647
648 // read settings
649 $settings_key = 'vision_settings';
650 $settings_value = get_option($settings_key);
651 if($settings_value) {
652 $globals['config'] = json_encode(unserialize($settings_value));
653 }
654
655 require_once(plugin_dir_path( dirname(__FILE__) ) . 'includes/page-settings.php' );
656
657 wp_localize_script('vision_admin_js', 'vision_globals', $globals);
658 }
659 }
660
661 /**
662 * Ajax update item state
663 */
664 function ajax_item_update_status() {
665 $error = false;
666 $data = [];
667 $config = filter_input(INPUT_POST, 'config', FILTER_UNSAFE_RAW);
668
669 if(check_ajax_referer('vision_ajax', 'nonce', false)) {
670 global $wpdb;
671 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
672
673 $config = json_decode($config);
674 $result = false;
675
676 if(isset($config->id) && isset($config->active)) {
677 $query = $wpdb->prepare("SELECT * FROM {$table} WHERE id=%s", $config->id);
678 $item = $wpdb->get_row($query, OBJECT );
679
680 if($item && (current_user_can('manage_options') || get_current_user_id()==$item->author) ) {
681 $itemData = unserialize($item->data);
682 $itemData->active = $config->active;
683
684 $result = $wpdb->update(
685 $table,
686 ['active' => $itemData->active, 'data' => serialize($itemData)],
687 ['id' => $config->id]
688 );
689 }
690 }
691
692 if($result) {
693 $data['id'] = $config->id;
694 $data['msg'] = esc_html__('The item was successfully updated', 'vision');
695 } else {
696 $error = true;
697 $data['msg'] = esc_html__('The operation failed, can\'t update item', 'vision');
698 }
699 } else {
700 $error = true;
701 $data['msg'] = esc_html__('The operation failed', 'vision');
702 }
703
704 if($error) {
705 wp_send_json_error($data);
706 } else {
707 wp_send_json_success($data);
708 }
709
710 wp_die(); // this is required to terminate immediately and return a proper response
711 }
712
713 /**
714 * Ajax update item data
715 */
716 function ajax_item_update() {
717 $error = false;
718 $data = [];
719
720 if(check_ajax_referer('vision_ajax', 'nonce', false)) {
721 global $wpdb;
722 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
723
724 $inputId = filter_input(INPUT_POST, 'id', FILTER_UNSAFE_RAW);
725 $inputData = filter_input(INPUT_POST, 'data', FILTER_UNSAFE_RAW);
726 $inputConfig = filter_input(INPUT_POST, 'config', FILTER_UNSAFE_RAW);
727 $itemData = json_decode($inputData);
728 $itemConfig = json_decode($inputConfig);
729 $flag = true;
730
731 if(VISION_PLUGIN_PLAN == 'lite') {
732 $rowcount = $wpdb->get_var("SELECT COUNT(*) FROM {$table}");
733
734 if(!($rowcount == 0 || ($rowcount == 1 && $inputId))) {
735 $flag = false;
736 $error = true;
737 $data['msg'] = esc_html__('The operation failed, you can work only with one item. To create more, buy the pro version.', 'vision');
738 }
739 }
740
741 if($flag) {
742 $itemConfig->modified = current_time('mysql', 1);
743
744 if($inputId) {
745 $result = false;
746
747 $query = $wpdb->prepare("SELECT * FROM {$table} WHERE id=%s", $inputId);
748 $item = $wpdb->get_row($query, OBJECT);
749 if($item && (current_user_can('manage_options') || get_current_user_id()==$item->author) ) {
750 $itemData->slug = sanitize_title(($itemData->slug ? $itemData->slug : $itemData->title));
751
752 $result = $wpdb->update(
753 $table,
754 [
755 'title' => $itemData->title,
756 'slug' => $itemData->slug,
757 'active' => $itemData->active,
758 'data' => serialize($itemData),
759 'config' => serialize($itemConfig),
760 //'author' => get_current_user_id(),
761 'editor' => get_current_user_id(),
762 //'date' => NULL,
763 'modified' => current_time('mysql', 1)
764 ],
765 ['id' => $inputId]
766 );
767 }
768
769 if($result) {
770 $data['id'] = $inputId;
771 $data['msg'] = esc_html__('The item was successfully updated', 'vision');
772 } else {
773 $error = true;
774 $data['msg'] = esc_html__('The operation failed, can\'t update item', 'vision');
775 }
776 } else {
777 $itemData->slug = sanitize_title(($itemData->slug ? $itemData->slug : $itemData->title));
778
779 $result = $wpdb->insert(
780 $table,
781 [
782 'title' => $itemData->title,
783 'slug' => $itemData->slug,
784 'active' => $itemData->active,
785 'data' => serialize($itemData),
786 'config' => serialize($itemConfig),
787 'author' => get_current_user_id(),
788 'editor' => get_current_user_id(),
789 'created' => current_time('mysql', 1),
790 'modified' => current_time('mysql', 1)
791 ]);
792
793 if($result) {
794 $data['id'] = $inputId = $wpdb->insert_id;
795 $data['msg'] = esc_html__('The item was successfully created', 'vision');
796 } else {
797 $error = true;
798 $data['msg'] = esc_html__('The operation failed, can\'t create item', 'vision');
799 }
800 }
801 }
802
803 // [filemanager] create an external file
804 if(!$error && wp_is_writable(VISION_PLUGIN_UPLOAD_DIR)) {
805 $file_json = 'config.json';
806 $file_main_css = 'main.css';
807 $file_custom_css = 'custom.css';
808 $file_root_path = VISION_PLUGIN_UPLOAD_DIR . '/' . $inputId . '/';
809
810 if(!is_dir($file_root_path)) {
811 mkdir($file_root_path);
812 }
813
814 @file_put_contents($file_root_path . $file_json, json_encode($itemConfig));
815 @file_put_contents($file_root_path . $file_main_css, $this->getMainCss($itemData, $inputId));
816 @file_put_contents($file_root_path . $file_custom_css, $itemData->customCSS->data);
817 }
818 } else {
819 $error = true;
820 $data['msg'] = esc_html__('The operation failed', 'vision');
821 }
822
823 if($error) {
824 wp_send_json_error($data);
825 } else {
826 wp_send_json_success($data);
827 }
828
829 wp_die(); // this is required to terminate immediately and return a proper response
830 }
831
832 /**
833 * Ajax update settings data
834 */
835 function ajax_settings_update() {
836 $error = false;
837 $data = [];
838 $config = filter_input(INPUT_POST, 'config', FILTER_UNSAFE_RAW);
839
840 if(check_ajax_referer('vision_ajax', 'nonce', false)) {
841 $settings_key = 'vision_settings';
842 $settings_value = serialize(json_decode($config));
843 $result = false;
844
845 if(get_option($settings_key) == false) {
846 $deprecated = null;
847 $autoload = 'no';
848 $result = add_option($settings_key, $settings_value, $deprecated, $autoload);
849 } else {
850 $old_settings_value = get_option($settings_key);
851 if($old_settings_value === $settings_value) {
852 $result = true;
853 } else {
854 $result = update_option($settings_key, $settings_value);
855 }
856 }
857
858 if($result) {
859 $data['msg'] = esc_html__('The settings were successfully updated', 'vision');
860 } else {
861 $error = true;
862 $data['msg'] = esc_html__('The operation failed, can\'t update settings', 'vision');
863 }
864 }
865
866 if($error) {
867 wp_send_json_error($data);
868 } else {
869 wp_send_json_success($data);
870 }
871
872 wp_die(); // this is required to terminate immediately and return a proper response
873 }
874
875 /**
876 * Ajax settings get data
877 */
878 function ajax_settings_get() {
879 $error = false;
880 $data = [];
881 $type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING);
882
883 if(check_ajax_referer('vision_ajax', 'nonce', false)) {
884 switch($type) {
885 case 'roles': {
886 $data['list'] = [];
887
888 $roles = wp_roles()->roles;
889 foreach($roles as $key => $role) {
890 if(array_key_exists('read', $role['capabilities'])) {
891 array_push($data['list'], ['id' => $key, 'name' => translate_user_role($role['name'])]);
892 }
893 }
894 }
895 break;
896 case 'themes': {
897 $data['list'] = [];
898
899 $files = glob(plugin_dir_path( dirname(__FILE__) ) . 'assets/themes/*.min.css');
900 foreach($files as $file) {
901 $filename = basename($file, '.min.css');
902 array_push($data['list'], ['id' => $filename, 'title' => str_replace('-', ' ', $filename)]);
903 }
904 }
905 break;
906 case 'editor-themes': {
907 $data['list'] = [];
908
909 $files = glob(plugin_dir_path( dirname(__FILE__) ) . 'assets/js/lib/ace/theme-*.js');
910 foreach($files as $file) {
911 $filename = str_replace('theme-','',basename($file, '.js'));
912 array_push($data['list'], ['id' => $filename, 'title' => str_replace('_', ' ', $filename)]);
913 }
914 }
915 break;
916 case 'fonts': {
917 $data['list'] = array(
918 array('fontname' => 'none'),
919 array('fontname' => 'Aclonica'),
920 array('fontname' => 'Allan'),
921 array('fontname' => 'Annie+Use+Your+Telescope'),
922 array('fontname' => 'Anonymous+Pro'),
923 array('fontname' => 'Allerta+Stencil'),
924 array('fontname' => 'Allerta'),
925 array('fontname' => 'Amaranth'),
926 array('fontname' => 'Anton'),
927 array('fontname' => 'Architects+Daughter'),
928 array('fontname' => 'Arimo'),
929 array('fontname' => 'Artifika'),
930 array('fontname' => 'Arvo'),
931 array('fontname' => 'Asset'),
932 array('fontname' => 'Astloch'),
933 array('fontname' => 'Bangers'),
934 array('fontname' => 'Bentham'),
935 array('fontname' => 'Bevan'),
936 array('fontname' => 'Bigshot+One'),
937 array('fontname' => 'Bowlby+One'),
938 array('fontname' => 'Bowlby+One+SC'),
939 array('fontname' => 'Brawler'),
940 array('fontname' => 'Cabin'),
941 array('fontname' => 'Calligraffitti'),
942 array('fontname' => 'Candal'),
943 array('fontname' => 'Cantarell'),
944 array('fontname' => 'Cardo'),
945 array('fontname' => 'Carter One'),
946 array('fontname' => 'Caudex'),
947 array('fontname' => 'Cedarville+Cursive'),
948 array('fontname' => 'Cherry+Cream+Soda'),
949 array('fontname' => 'Chewy'),
950 array('fontname' => 'Coda'),
951 array('fontname' => 'Coming+Soon'),
952 array('fontname' => 'Copse'),
953 array('fontname' => 'Cousine'),
954 array('fontname' => 'Covered+By+Your+Grace'),
955 array('fontname' => 'Crafty+Girls'),
956 array('fontname' => 'Crimson+Text'),
957 array('fontname' => 'Crushed'),
958 array('fontname' => 'Cuprum'),
959 array('fontname' => 'Damion'),
960 array('fontname' => 'Dancing+Script'),
961 array('fontname' => 'Dawning+of+a+New+Day'),
962 array('fontname' => 'Didact+Gothic'),
963 array('fontname' => 'Droid+Sans'),
964 array('fontname' => 'Droid+Sans+Mono'),
965 array('fontname' => 'Droid+Serif'),
966 array('fontname' => 'EB+Garamond'),
967 array('fontname' => 'Expletus+Sans'),
968 array('fontname' => 'Fontdiner+Swanky'),
969 array('fontname' => 'Forum'),
970 array('fontname' => 'Francois+One'),
971 array('fontname' => 'Geo'),
972 array('fontname' => 'Give+You+Glory'),
973 array('fontname' => 'Goblin+One'),
974 array('fontname' => 'Goudy+Bookletter+1911'),
975 array('fontname' => 'Gravitas+One'),
976 array('fontname' => 'Gruppo'),
977 array('fontname' => 'Hammersmith+One'),
978 array('fontname' => 'Holtwood+One+SC'),
979 array('fontname' => 'Homemade+Apple'),
980 array('fontname' => 'Inconsolata'),
981 array('fontname' => 'Indie+Flower'),
982 array('fontname' => 'IM+Fell+DW+Pica'),
983 array('fontname' => 'IM+Fell+DW+Pica+SC'),
984 array('fontname' => 'IM+Fell+Double+Pica'),
985 array('fontname' => 'IM+Fell+Double+Pica+SC'),
986 array('fontname' => 'IM+Fell+English'),
987 array('fontname' => 'IM+Fell+English+SC'),
988 array('fontname' => 'IM+Fell+French+Canon'),
989 array('fontname' => 'IM+Fell+French+Canon+SC'),
990 array('fontname' => 'IM+Fell+Great+Primer'),
991 array('fontname' => 'IM+Fell+Great+Primer+SC'),
992 array('fontname' => 'Irish+Grover'),
993 array('fontname' => 'Irish+Growler'),
994 array('fontname' => 'Istok+Web'),
995 array('fontname' => 'Josefin+Sans'),
996 array('fontname' => 'Josefin+Slab'),
997 array('fontname' => 'Judson'),
998 array('fontname' => 'Jura'),
999 array('fontname' => 'Just+Another+Hand'),
1000 array('fontname' => 'Just+Me+Again+Down+Here'),
1001 array('fontname' => 'Kameron'),
1002 array('fontname' => 'Kenia'),
1003 array('fontname' => 'Kranky'),
1004 array('fontname' => 'Kreon'),
1005 array('fontname' => 'Kristi'),
1006 array('fontname' => 'La+Belle+Aurore'),
1007 array('fontname' => 'Lato'),
1008 array('fontname' => 'League+Script'),
1009 array('fontname' => 'Lekton'),
1010 array('fontname' => 'Limelight'),
1011 array('fontname' => 'Lobster'),
1012 array('fontname' => 'Lobster Two'),
1013 array('fontname' => 'Lora'),
1014 array('fontname' => 'Love+Ya+Like+A+Sister'),
1015 array('fontname' => 'Loved+by+the+King'),
1016 array('fontname' => 'Luckiest+Guy'),
1017 array('fontname' => 'Maiden+Orange'),
1018 array('fontname' => 'Mako'),
1019 array('fontname' => 'Maven+Pro'),
1020 array('fontname' => 'Meddon'),
1021 array('fontname' => 'MedievalSharp'),
1022 array('fontname' => 'Megrim'),
1023 array('fontname' => 'Merriweather'),
1024 array('fontname' => 'Metrophobic'),
1025 array('fontname' => 'Michroma'),
1026 array('fontname' => 'Miltonian+Tattoo'),
1027 array('fontname' => 'Miltonian'),
1028 array('fontname' => 'Modern Antiqua'),
1029 array('fontname' => 'Monofett'),
1030 array('fontname' => 'Molengo'),
1031 array('fontname' => 'Mountains of Christmas'),
1032 array('fontname' => 'Muli'),
1033 array('fontname' => 'Neucha'),
1034 array('fontname' => 'Neuton'),
1035 array('fontname' => 'News+Cycle'),
1036 array('fontname' => 'Nixie+One'),
1037 array('fontname' => 'Nobile'),
1038 array('fontname' => 'Nova+Cut'),
1039 array('fontname' => 'Nova+Flat'),
1040 array('fontname' => 'Nova+Mono'),
1041 array('fontname' => 'Nova+Oval'),
1042 array('fontname' => 'Nova+Round'),
1043 array('fontname' => 'Nova+Script'),
1044 array('fontname' => 'Nova+Slim'),
1045 array('fontname' => 'Nova+Square'),
1046 array('fontname' => 'Nunito'),
1047 array('fontname' => 'OFL+Sorts+Mill+Goudy+TT'),
1048 array('fontname' => 'Old+Standard+TT'),
1049 array('fontname' => 'Open+Sans'),
1050 array('fontname' => 'Orbitron'),
1051 array('fontname' => 'Oswald'),
1052 array('fontname' => 'Over+the+Rainbow'),
1053 array('fontname' => 'Reenie+Beanie'),
1054 array('fontname' => 'Pacifico'),
1055 array('fontname' => 'Patrick+Hand'),
1056 array('fontname' => 'Paytone+One'),
1057 array('fontname' => 'Permanent+Marker'),
1058 array('fontname' => 'Philosopher'),
1059 array('fontname' => 'Play'),
1060 array('fontname' => 'Playfair+Display'),
1061 array('fontname' => 'Podkova'),
1062 array('fontname' => 'PT+Sans'),
1063 array('fontname' => 'PT+Sans+Narrow'),
1064 array('fontname' => 'PT+Serif'),
1065 array('fontname' => 'PT+Serif Caption'),
1066 array('fontname' => 'Puritan'),
1067 array('fontname' => 'Quattrocento'),
1068 array('fontname' => 'Quattrocento+Sans'),
1069 array('fontname' => 'Radley'),
1070 array('fontname' => 'Redressed'),
1071 array('fontname' => 'Rock+Salt'),
1072 array('fontname' => 'Rokkitt'),
1073 array('fontname' => 'Ruslan+Display'),
1074 array('fontname' => 'Schoolbell'),
1075 array('fontname' => 'Shadows+Into+Light'),
1076 array('fontname' => 'Shanti'),
1077 array('fontname' => 'Sigmar+One'),
1078 array('fontname' => 'Six+Caps'),
1079 array('fontname' => 'Slackey'),
1080 array('fontname' => 'Smythe'),
1081 array('fontname' => 'Special+Elite'),
1082 array('fontname' => 'Stardos+Stencil'),
1083 array('fontname' => 'Sue+Ellen+Francisco'),
1084 array('fontname' => 'Sunshiney'),
1085 array('fontname' => 'Swanky+and+Moo+Moo'),
1086 array('fontname' => 'Syncopate'),
1087 array('fontname' => 'Tangerine'),
1088 array('fontname' => 'Tenor+Sans'),
1089 array('fontname' => 'Terminal+Dosis+Light'),
1090 array('fontname' => 'The+Girl+Next+Door'),
1091 array('fontname' => 'Tinos'),
1092 array('fontname' => 'Ubuntu'),
1093 array('fontname' => 'Ultra'),
1094 array('fontname' => 'Unkempt'),
1095 array('fontname' => 'UnifrakturMaguntia'),
1096 array('fontname' => 'Varela'),
1097 array('fontname' => 'Varela Round'),
1098 array('fontname' => 'Vibur'),
1099 array('fontname' => 'Vollkorn'),
1100 array('fontname' => 'VT323'),
1101 array('fontname' => 'Waiting+for+the+Sunrise'),
1102 array('fontname' => 'Wallpoet'),
1103 array('fontname' => 'Walter+Turncoat'),
1104 array('fontname' => 'Wire+One'),
1105 array('fontname' => 'Yanone+Kaffeesatz'),
1106 array('fontname' => 'Yeseva+One'),
1107 array('fontname' => 'Zeyada')
1108 );
1109 }
1110 break;
1111 default: {
1112 $error = true;
1113 $data['msg'] = esc_html__('The operation failed', 'vision');
1114 }
1115 break;
1116 }
1117 } else {
1118 $error = true;
1119 $data['msg'] = esc_html__('The operation failed', 'vision');
1120 }
1121
1122 if($error) {
1123 wp_send_json_error($data);
1124 } else {
1125 wp_send_json_success($data);
1126 }
1127
1128 wp_die(); // this is required to terminate immediately and return a proper response
1129 }
1130
1131 /**
1132 * Ajax delete all data from tables
1133 */
1134 function ajax_delete_data() {
1135 $error = true;
1136 $data = [];
1137 $data['msg'] = esc_html__('The operation failed, can\'t delete data', 'vision');
1138
1139 if(check_ajax_referer('vision_ajax', 'nonce', false)) {
1140 global $wpdb;
1141 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
1142
1143 foreach($wpdb->get_results("SELECT id FROM {$table}") as $key => $item) {
1144 // [filemanager] delete file
1145 if(wp_is_writable(VISION_PLUGIN_UPLOAD_DIR)) {
1146 $file_json = 'config.json';
1147 $file_main_css = 'main.css';
1148 $file_custom_css = 'custom.css';
1149 $file_root_path = VISION_PLUGIN_UPLOAD_DIR . '/' . $item->id . '/';
1150
1151 wp_delete_file($file_root_path . $file_json);
1152 wp_delete_file($file_root_path . $file_main_css);
1153 wp_delete_file($file_root_path . $file_custom_css);
1154
1155 if(is_dir($file_root_path)) {
1156 rmdir($file_root_path);
1157 }
1158 }
1159 }
1160
1161 $query = "TRUNCATE TABLE {$table}";
1162 $result = $wpdb->query($query);
1163
1164 if($result) {
1165 $error = false;
1166 $data['msg'] = esc_html__('All data deleted', 'vision');
1167 }
1168 }
1169
1170 if($error) {
1171 wp_send_json_error($data);
1172 } else {
1173 wp_send_json_success($data);
1174 }
1175
1176 wp_die(); // this is required to terminate immediately and return a proper response
1177 }
1178
1179 /**
1180 * Ajax settings get data
1181 */
1182 function ajax_modal() {
1183 if(check_ajax_referer('vision_ajax', 'nonce', false)) {
1184 $modalName = filter_input(INPUT_GET, 'name', FILTER_SANITIZE_STRING);
1185 $modalPath = plugin_dir_path( dirname(__FILE__) ) . 'includes/modal-' . $modalName . '.php';
1186
1187 if(file_exists($modalPath)) {
1188 require_once( $modalPath );
1189 }
1190 }
1191
1192 wp_die(); // this is required to terminate immediately and return a proper response
1193 }
1194 }
1195 ?>