PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.9.2
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.9.2
3.1.9 3.1.8 3.1.7 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 trunk 1.3.7 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9 2.9.1 2.9.2
folders / includes / folders.class.php
folders / includes Last commit date
class-affiliate.php 3 years ago class-polylang.php 3 years ago class-review-box.php 3 years ago class-upgrade-box.php 3 years ago class-wpml.php 3 years ago folders.class.php 3 years ago form.class.php 3 years ago media.replace.php 3 years ago plugins.class.php 3 years ago tree.class.php 3 years ago
folders.class.php
6992 lines
1 <?php
2 /**
3 * Class Folders Main
4 *
5 * @author : Premio <contact@premio.io>
6 * @license : GPL2
7 * */
8
9 if (! defined('ABSPATH')) {
10 exit;
11 }
12
13 // Free/Pro Class name change
14 class WCP_Folders
15 {
16
17 /**
18 * Instance of Class
19 *
20 * @var object $instance Instance of Class
21 * @since 1.0.0
22 * @access public
23 */
24 private static $instance;
25
26 /**
27 * License key data
28 *
29 * @var array $license_key_data License key data
30 * @since 1.0.0
31 * @access public
32 */
33 private static $license_key_data = null;
34
35 /**
36 * Folders data
37 *
38 * @var object $folders Folders data
39 * @since 1.0.0
40 * @access public
41 */
42 private static $folders;
43
44 /**
45 * Total number of folders
46 *
47 * @var integer $tlfs total number of folders
48 * @since 1.0.0
49 * @access public
50 */
51 public $tlfs = 0;
52
53 /**
54 * Collection on post ids
55 *
56 * @var array $postIds collection on post ids
57 * @since 1.0.0
58 * @access public
59 */
60 private static $postIds;
61
62 /**
63 * Folders Settings
64 *
65 * @var array $folderSettings Folders Settings
66 * @since 1.0.0
67 * @access public
68 */
69 private static $folderSettings = false;
70
71
72 /**
73 * Folders Settings
74 *
75 * @var array $folders_settings Folders Settings
76 * @since 1.0.0
77 * @access public
78 */
79 var $folders_settings = false;
80
81
82 /**
83 * Define the core functionality of the import data functionality.
84 *
85 * Add/Update folders settings
86 * Add/Update/Remove/List of folders
87 * Add/Update/Remove/List posts to folders
88 * Mark/Unmark folders
89 * Make Sticky/Unsticky folders
90 * Add content to folders
91 * Update folder sidebar width
92 * Filter taxonomies for folders
93 * Show drag buttons to post/page table
94 *
95 * @since 1.0.0
96 */
97 public function __construct()
98 {
99
100 spl_autoload_register([$this, 'autoload']);
101 add_action('init', [$this, 'create_folder_terms'], 15);
102 add_action('admin_init', [$this, 'folders_register_settings']);
103 add_action('admin_menu', [$this, 'admin_menu'], 10000);
104 add_action('admin_enqueue_scripts', [$this, 'folders_admin_styles']);
105 add_action('admin_enqueue_scripts', [$this, 'folders_admin_scripts']);
106 add_filter('plugin_action_links_'.WCP_FOLDERS_PLUGIN_BASE, [$this, 'plugin_action_links']);
107 add_action('admin_footer', [$this, 'admin_footer']);
108
109 add_action('parse_tax_query', [$this, 'taxonomy_archive_exclude_children']);
110 add_action('admin_footer', [$this, 'admin_footer_for_media']);
111
112 // Save Data
113 add_action('wp_ajax_wcp_add_new_folder', [$this, 'wcp_add_new_folder']);
114 // Update Data
115 add_action('wp_ajax_wcp_update_folder', [$this, 'wcp_update_folder']);
116 // Remove Data
117 add_action('wp_ajax_wcp_remove_folder', [$this, 'wcp_remove_folder']);
118 // Remove Multple Folder
119 add_action('wp_ajax_wcp_remove_muliple_folder', [$this, 'remove_muliple_folder']);
120 // Save State Data
121 add_action('wp_ajax_save_wcp_folder_state', [$this, 'save_wcp_folder_state']);
122 // Save State Data
123 add_action('wp_ajax_wcp_save_parent_data', [$this, 'wcp_save_parent_data']);
124 // Update Parent Data
125 add_action('wp_ajax_wcp_update_parent_information', [$this, 'wcp_update_parent_information']);
126 // Update Parent Data
127 add_action('wp_ajax_wcp_save_folder_order', [$this, 'wcp_save_folder_order']);
128 // Update Parent Data
129 add_action('wp_ajax_wcp_mark_un_mark_folder', [$this, 'wcp_mark_un_mark_folder']);
130 // Update Parent Data
131 add_action('wp_ajax_wcp_make_sticky_folder', [$this, 'wcp_make_sticky_folder']);
132 // Update Parent Data
133 add_action('wp_ajax_wcp_change_post_folder', [$this, 'wcp_change_post_folder']);
134 // Update Parent Data
135 add_action('wp_ajax_wcp_change_multiple_post_folder', [$this, 'wcp_change_multiple_post_folder']);
136 // Update width Data
137 add_action('wp_ajax_wcp_change_post_width', [$this, 'wcp_change_post_width']);
138 // Update width Data
139 add_action('wp_ajax_wcp_change_folder_display_status', [$this, 'wcp_change_folder_display_status']);
140 // Update width Data
141 add_action('wp_ajax_wcp_change_all_status', [$this, 'wcp_change_all_status']);
142 // Update width Data
143 add_action('wp_ajax_save_folder_last_status', [$this, 'save_folder_last_status']);
144 // Update width Data
145 add_action('wp_ajax_wcp_folders_by_order', [$this, 'wcp_folders_by_order']);
146 // Update width Data
147 add_action('wp_ajax_wcp_remove_all_folders_data', [$this, 'remove_all_folders_data']);
148 // Update folders Status
149 add_action('wp_ajax_wcp_update_folders_uninstall_status', [$this, 'update_folders_uninstall_status']);
150 // Undo Functionality
151 add_action('wp_ajax_wcp_undo_folder_changes', [$this, 'wcp_undo_folder_changes']);
152 self::$folders = 10;
153
154 // Send message on plugin deactivate
155 add_action('wp_ajax_folder_plugin_deactivate', [ $this, 'folder_plugin_deactivate' ]);
156 // Update Parent Data
157 add_action('wp_ajax_wcp_remove_post_folder', [$this, 'wcp_remove_post_folder']);
158 // Send message on owner
159 add_action('wp_ajax_wcp_folder_send_message_to_owner', [ $this, 'wcp_folder_send_message_to_owner' ]);
160 // Get default list
161 add_action('wp_ajax_premio_check_for_other_folders', [$this, 'premio_check_for_other_folders']);
162 // Send message on owner
163 add_action('wp_ajax_wcp_get_default_list', [ $this, 'wcp_get_default_list' ]);
164 // Get default list
165 add_action('wp_ajax_get_folders_default_list', [ $this, 'get_folders_default_list' ]);
166 // Auto select folder for new page, post
167 add_action('new_to_auto-draft', [$this, 'new_to_auto_draft'], 10);
168 // for media
169 add_action('restrict_manage_posts', [$this, 'output_list_table_filters'], 10, 2);
170 add_filter('pre_get_posts', [$this, 'filter_attachments_list']);
171 add_action('wp_enqueue_media', [$this, 'output_backbone_view_filters']);
172 add_filter('ajax_query_attachments_args', [$this, 'filter_attachments_grid']);
173 add_filter('add_attachment', [$this, 'save_media_terms']);
174
175 // to filter un assigned items
176 add_filter('pre_get_posts', [$this, 'filter_record_list']);
177 add_filter('pre-upload-ui', [$this, 'show_dropdown_on_media_screen']);
178 add_action('add_attachment', [$this, 'add_attachment_category']);
179
180 $options = get_option("folders_settings");
181
182 $options = is_array($options) ? $options : [];
183
184 if (in_array("post", $options)) {
185 add_filter('manage_posts_columns', [$this, 'wcp_manage_columns_head']);
186 add_action('manage_posts_custom_column', [$this, 'wcp_manage_columns_content'], 10, 2);
187 add_filter('bulk_actions-edit-post', [$this, 'custom_bulk_action' ]);
188 }
189
190 if (in_array("page", $options)) {
191 add_filter('manage_page_posts_columns', [$this, 'wcp_manage_columns_head']);
192 add_action('manage_page_posts_custom_column', [$this, 'wcp_manage_columns_content'], 10, 2);
193 add_filter('bulk_actions-edit-page', [$this, 'custom_bulk_action' ]);
194 }
195
196 if (in_array("attachment", $options)) {
197 add_filter('manage_media_columns', [$this, 'wcp_manage_columns_head']);
198 add_action('manage_media_custom_column', [$this, 'wcp_manage_columns_content'], 10, 2);
199 // add_filter('bulk_actions-edit-media', array($this, 'custom_bulk_action' ));
200 }
201
202 foreach ($options as $option) {
203 if ($option != "post" && $option != "page" && $option != "attachment") {
204 add_filter('manage_edit-'.$option.'_columns', [$this, 'wcp_manage_columns_head'], 99999);
205 add_action('manage_'.$option.'_posts_custom_column', [$this, 'wcp_manage_columns_content'], 2, 2);
206 add_filter('bulk_actions-edit-'.$option, [$this, 'custom_bulk_action' ]);
207 }
208 }
209
210 // check for default folders
211 add_filter('pre_get_posts', [$this, 'check_for_default_folders']);
212 add_filter('folders_count_where_query', [$this, 'folders_count_where_query']);
213 add_filter('folders_count_join_query', [$this, 'folders_count_join_query']);
214
215 add_action("wp_ajax_folder_update_status", [$this, 'folder_update_status']);
216
217 // load language files
218 add_action('plugins_loaded', [ $this, 'folders_text' ]);
219
220 add_action("wp_ajax_folder_update_popup_status", [$this, 'folder_update_popup_status']);
221
222 add_action("wp_ajax_premio_hide_child_popup", [$this, 'premio_hide_child_popup']);
223
224 add_action("wp_ajax_wcp_update_folders_import_status", [$this, 'update_folders_import_status']);
225
226 add_filter('get_terms', [ $this, 'get_terms_filter_without_trash'], 10, 3);
227
228 add_filter('mla_media_modal_query_final_terms', [ $this, 'media_modal_query_final_terms'], 10, 3);
229
230 // reset count when post/page updated
231 add_action('deleted_term_relationships', [$this, 'update_folder_term_relationships'], 10, 3);
232
233 add_action('added_term_relationship', [$this, 'update_folder_new_term_relationships'], 10, 3);
234
235 add_action('set_object_terms', [$this, 'set_object_terms_for_folders'], 10, 6);
236
237 /*
238 * To Remove Attachment
239 * */
240
241 add_action('wp_trash_post', [$this, "wcp_delete_post"]);
242 add_action('before_delete_post', [$this, "wcp_delete_post"]);
243
244 /*
245 * Hide Folder CTA
246 * */
247 add_action('wp_ajax_hide_folders_cta', [$this, 'hide_folders_cta']);
248
249 add_action("manage_posts_extra_tablenav", [$this, "manage_posts_extra_fields"]);
250
251 /* Mailpoet Whitelist JS/CSS */
252 add_filter("mailpoet_conflict_resolver_whitelist_style", [$this, 'mailpoet_conflict_whitelist_style']);
253 add_filter("mailpoet_conflict_resolver_whitelist_script", [$this, 'mailpoet_conflict_whitelist_script']);
254
255 }//end __construct()
256
257 /**
258 * Add folders script to mailpoet's conflict list
259 *
260 * @since 2.8.7
261 * @access public
262 * @return $scripts
263 */
264 public function mailpoet_conflict_whitelist_script($scripts) {
265 $scripts[] = "folders";
266 $scripts[] = "folders-pro";
267 return $scripts;
268 }
269
270
271 /**
272 * Add folders styles to mailpoet's conflict list
273 *
274 * @since 2.8.7
275 * @access public
276 * @return $styles
277 */
278 public function mailpoet_conflict_whitelist_style($styles) {
279 $styles[] = "folders";
280 $styles[] = "folders-pro";
281 return $styles;
282 }
283
284 /**
285 * Update User Profile fields
286 *
287 * @since 2.8.5
288 * @access public
289 */
290 function save_extra_user_profile_fields( $user_id ) {
291 if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'update-user_' . $user_id ) ) {
292 return;
293 }
294
295 if (!current_user_can( 'edit_user', $user_id ) ) {
296 return;
297 }
298
299 if(isset($_POST['folders_access_role'])) {
300 $setting = get_user_meta($user_id, "folders_access_role", true);
301 if($setting === false) {
302 add_user_meta($user_id, "folders_access_role", sanitize_text_field($_POST['folders_access_role']));
303 } else {
304 update_user_meta($user_id, "folders_access_role", sanitize_text_field($_POST['folders_access_role']));
305 }
306 }
307 }
308
309 /**
310 * Fetch User Profile fields
311 *
312 * @since 2.8.5
313 * @access public
314 */
315 function extra_user_profile_fields($user) {
316 $userRoles = $this->get_user_roles();
317 $userRole = get_user_meta($user->ID, "folders_access_role", true);
318 if($userRole === false || empty($userRole)) {
319 $userRole = "default";
320 }
321 ?>
322 <h3><?php esc_html_e("Folders", "folders"); ?></h3>
323
324 <table class="form-table">
325 <tr>
326 <th><label for="folders_access_role"><?php esc_html_e("Folder Access"); ?></label></th>
327 <td>
328 <select class="regular-text" id="folders_access_role" name="folders_access_role">
329 <?php foreach($userRoles as $key=>$role) { ?>
330 <option <?php selected($userRole, $key) ?> value="<?php echo esc_attr($key) ?>"><?php echo esc_attr($role) ?></option>
331 <?php } ?>
332 </select>
333 </td>
334 </tr>
335 </table>
336 <?php }
337
338 /**
339 * Add extra params in search
340 *
341 * @since 1.0.0
342 * @access public
343 * @return $response
344 */
345 function manage_posts_extra_fields($which) {
346 global $typenow;
347 if($which == "top" && !empty($typenow)) {
348 if ($this->folders_settings === false) {
349 $this->folders_settings = get_option('folders_settings');
350 $this->folders_settings = $this->folders_settings;
351 $this->folders_settings = is_array($this->folders_settings) ? $this->folders_settings : [];
352 }
353 if(in_array($typenow, $this->folders_settings)) {
354 $folder_type = self::get_custom_post_type($typenow);
355 if(isset($_REQUEST[$folder_type]) && !empty($_REQUEST[$folder_type])) {
356 $folder = sanitize_text_field($_REQUEST[$folder_type]);
357 echo "<input type='hidden' name='".esc_attr($folder_type)."' value='".esc_attr($folder)."' />";
358 } else if(isset($_REQUEST['ajax_action']) && $_REQUEST['ajax_action'] == "premio_dynamic_folders" && isset($_REQUEST['dynamic_folder'])) {
359 $dynamic_folder = sanitize_text_field($_REQUEST['dynamic_folder']);
360 echo "<input type='hidden' name='ajax_action' value='premio_dynamic_folders' />";
361 echo "<input type='hidden' name='dynamic_folder' value='".esc_attr($dynamic_folder)."' />";
362 }
363 }
364 }
365 }
366
367 /**
368 * Hide CTA button text
369 *
370 * @since 1.0.0
371 * @access public
372 * @return $response
373 */
374 public function hide_folders_cta()
375 {
376 $response = [];
377 $response['status'] = 0;
378 $response['error'] = 0;
379 $response['data'] = [];
380 $response['message'] = "";
381 $postData = filter_input_array(INPUT_POST);
382 $errorCounter = 0;
383 if (!isset($postData['nonce']) || empty($postData['nonce'])) {
384 $response['message'] = esc_html__("Your request is not valid", 'folders');
385 $errorCounter++;
386 } else {
387 $nonce = self::sanitize_options($postData['nonce']);
388 if (!wp_verify_nonce($nonce, 'hide_folders_cta')) {
389 $response['message'] = esc_html__("Your request is not valid", 'folders');
390 $errorCounter++;
391 }
392 }
393
394 if ($errorCounter == 0) {
395 $response['status'] = 1;
396 add_option("hide_folders_cta", "yes");
397 }
398
399 echo json_encode($response);
400 die;
401
402 }//end hide_folders_cta()
403
404
405 /**
406 * Delete post hook, clear data on post delete
407 *
408 * @since 1.0.0
409 * @access public
410 * @return $status
411 */
412 public function wcp_delete_post($postID)
413 {
414 delete_transient("premio_folders_without_trash");
415
416 }//end wcp_delete_post()
417
418
419 /**
420 * Set folders data for post/page ids
421 *
422 * @since 1.0.0
423 * @access public
424 * @return $post
425 */
426 public function set_object_terms_for_folders($object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids)
427 {
428 if (!empty($object_id)) {
429 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
430 if (!empty($tt_ids) && is_array($tt_ids)) {
431 foreach ($tt_ids as $term_id) {
432 $term = get_term($term_id, $taxonomy);
433 if (isset($term->term_taxonomy_id) && isset($trash_folders[$term->term_taxonomy_id])) {
434 unset($trash_folders[$term->term_taxonomy_id]);
435 }
436 }
437 }
438
439 if (!empty($old_tt_ids) && is_array($old_tt_ids)) {
440 foreach ($old_tt_ids as $term_id) {
441 $term = get_term($term_id, $taxonomy);
442 if (isset($term->term_taxonomy_id) && isset($trash_folders[$term->term_taxonomy_id])) {
443 unset($trash_folders[$term->term_taxonomy_id]);
444 }
445 }
446 }
447
448 if ($initial_trash_folders != $trash_folders) {
449 delete_transient("premio_folders_without_trash");
450 set_transient("premio_folders_without_trash", $trash_folders, (3 * DAY_IN_SECONDS));
451 }
452 }//end if
453
454 }//end set_object_terms_for_folders()
455
456
457 /**
458 * Check for folders settings
459 *
460 * @since 1.0.0
461 * @access public
462 * @return $options
463 */
464 public static function check_for_setting($key, $setting, $default="")
465 {
466 if (self::$folderSettings === false) {
467 $options = get_option("premio_folder_options");
468 if ($options === false || !is_array($options)) {
469 $options = [];
470 }
471
472 self::$folderSettings = $options;
473 }
474
475 if ($setting == "folders_settings") {
476 if (isset(self::$folderSettings[$setting]) && is_array(self::$folderSettings[$setting])) {
477 return in_array($key, self::$folderSettings[$setting]);
478 }
479 } else {
480 if (isset(self::$folderSettings[$setting][$key])) {
481 return self::$folderSettings[$setting][$key];
482 }
483 }
484
485 return false;
486
487 }//end check_for_setting()
488
489
490 /**
491 * Send message to owner on Uninstall
492 *
493 * @since 1.0.0
494 * @access public
495 * @return $response
496 */
497 public function update_folders_uninstall_status()
498 {
499 $response = [];
500 $response['status'] = 0;
501 $response['error'] = 0;
502 $response['data'] = [];
503 $response['message'] = "";
504 $postData = filter_input_array(INPUT_POST);
505 $errorCounter = 0;
506
507 if (!isset($postData['nonce']) || empty($postData['nonce'])) {
508 $response['message'] = esc_html__("Your request is not valid", 'folders');
509 $errorCounter++;
510 } else {
511 $nonce = self::sanitize_options($postData['nonce']);
512 if (!wp_verify_nonce($nonce, 'wcp_folders_uninstall_status')) {
513 $response['message'] = esc_html__("Your request is not valid", 'folders');
514 $errorCounter++;
515 }
516 }
517
518 if ($errorCounter == 0) {
519 $status = isset($postData['status']) ? $postData['status'] : "";
520 $status = ($status == "on") ? "on" : "off";
521 $customize_folders = get_option('customize_folders');
522 $customize_folders['remove_folders_when_removed'] = $status;
523 update_option("customize_folders", $customize_folders);
524 $response['status'] = 1;
525 }
526
527 echo json_encode($response);
528 die;
529
530 }//end update_folders_uninstall_status()
531
532
533 /**
534 * Remove folders data
535 *
536 * @since 1.0.0
537 * @access public
538 * @return $response
539 */
540 public function remove_all_folders_data()
541 {
542 $response = [];
543 $response['status'] = 0;
544 $response['error'] = 0;
545 $response['data'] = [];
546 $response['message'] = "";
547 $postData = filter_input_array(INPUT_POST);
548 $errorCounter = 0;
549
550 if (!isset($postData['nonce']) || empty($postData['nonce'])) {
551 $response['message'] = esc_html__("Your request is not valid", 'folders');
552 $errorCounter++;
553 } else {
554 $type = self::sanitize_options($postData['type']);
555 $nonce = self::sanitize_options($postData['nonce']);
556 if (!wp_verify_nonce($nonce, 'remove_folders_data')) {
557 $response['message'] = esc_html__("Your request is not valid", 'folders');
558 $errorCounter++;
559 }
560 }
561
562 if ($errorCounter == 0) {
563 self::$folders = 0;
564 self::remove_folder_by_taxonomy("media_folder");
565 self::remove_folder_by_taxonomy("folder");
566 self::remove_folder_by_taxonomy("post_folder");
567 $post_types = get_post_types([], 'objects');
568 $post_array = [
569 "page",
570 "post",
571 "attachment",
572 ];
573 foreach ($post_types as $post_type) {
574 if (!in_array($post_type->name, $post_array)) {
575 self::remove_folder_by_taxonomy($post_type->name.'_folder');
576 }
577 }
578
579 delete_option('default_folders');
580 $response['status'] = 1;
581 $response['data'] = [
582 'items' => self::$folders,
583 ];
584 }//end if
585
586 echo json_encode($response);
587 die;
588
589 }//end remove_all_folders_data()
590
591
592 /**
593 * Remove folders from poge/post
594 *
595 * @since 1.0.0
596 * @access public
597 * @return $folders
598 */
599 public static function remove_folder_by_taxonomy($taxonomy)
600 {
601 global $wpdb;
602 $query = "SELECT * FROM ".$wpdb->term_taxonomy."
603 LEFT JOIN ".$wpdb->terms."
604 ON ".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id
605 WHERE ".$wpdb->term_taxonomy.".taxonomy = '%d'
606 ORDER BY parent ASC";
607 $query = $wpdb->prepare($query, $taxonomy);
608 $folders = $wpdb->get_results($query);
609 $folders = array_values($folders);
610 foreach ($folders as $folder) {
611 $term_id = intval($folder->term_id);
612 if ($term_id) {
613 $wpdb->delete($wpdb->prefix.'term_relationships', ['term_taxonomy_id' => $term_id]);
614 $wpdb->delete($wpdb->prefix.'term_taxonomy', ['term_id' => $term_id]);
615 $wpdb->delete($wpdb->prefix.'terms', ['term_id' => $term_id]);
616 $wpdb->delete($wpdb->prefix.'termmeta', ['term_id' => $term_id]);
617 self::$folders++;
618 }
619 }
620
621 }//end remove_folder_by_taxonomy()
622
623
624 /**
625 * Convent Hex color code to RGB code
626 *
627 * @since 1.0.0
628 * @access public
629 * @return $rgb
630 */
631 public static function hexToRgb($hex, $alpha=false)
632 {
633 $hex = str_replace('#', '', $hex);
634 $length = strlen($hex);
635 $rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
636 $rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
637 $rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
638 if ($alpha) {
639 $rgb['a'] = $alpha;
640 }
641
642 return $rgb;
643
644 }//end hexToRgb()
645
646
647 /**
648 * Get folders by folder order
649 *
650 * @since 1.0.0
651 * @access public
652 * @return $folders
653 */
654 public function wcp_folders_by_order()
655 {
656 $response = [];
657 $response['status'] = 0;
658 $response['error'] = 0;
659 $response['data'] = [];
660 $response['message'] = "";
661 $postData = filter_input_array(INPUT_POST);
662 $errorCounter = 0;
663
664 if (!isset($postData['order']) || empty($postData['order'])) {
665 $response['message'] = esc_html__("Your request is not valid", 'folders');
666 $errorCounter++;
667 } else if (!isset($postData['type']) || empty($postData['type'])) {
668 $response['message'] = esc_html__("Your request is not valid", 'folders');
669 $errorCounter++;
670 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
671 $response['message'] = esc_html__("Your request is not valid", 'folders');
672 $errorCounter++;
673 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
674 $response['message'] = esc_html__("You have not permission to update width", 'folders');
675 $errorCounter++;
676 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
677 $response['message'] = esc_html__("You have not permission to update width", 'folders');
678 $errorCounter++;
679 } else {
680 $type = self::sanitize_options($postData['type']);
681 $nonce = self::sanitize_options($postData['nonce']);
682 if (!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
683 $response['message'] = esc_html__("Your request is not valid", 'folders');
684 $errorCounter++;
685 }
686 }//end if
687
688 if ($errorCounter == 0) {
689 $response['status'] = 1;
690
691 $order_field = $postData['order'];
692
693 $order_by = "";
694 $order = "ASC";
695
696 if ($order_field == "a-z" || $order_field == "z-a") {
697 $order_by = 'title';
698 if ($order_field == "z-a") {
699 $order = "DESC";
700 }
701 } else if ($order_field == "n-o" || $order_field == "o-n") {
702 $order_by = 'ID';
703 if ($order_field == "o-n") {
704 $order = "ASC";
705 } else {
706 $order = "DESC";
707 }
708 }
709
710 if (empty($order_by)) {
711 $order = "";
712 }
713
714 $folder_type = self::get_custom_post_type($postData['type']);
715 // Do not change: Free/Pro Class name change
716 $tree_data = WCP_Tree::get_full_tree_data($folder_type, $order_by, $order);
717
718 $response['data'] = $tree_data['string'];
719 $taxonomies = [];
720 if ($postData['type'] == "attachment") {
721 $taxonomies = self::get_terms_hierarchical($folder_type);
722 }
723
724 $response['terms'] = $taxonomies;
725 }//end if
726
727 echo json_encode($response);
728 die;
729
730 }//end wcp_folders_by_order()
731
732
733 /**
734 * Save selected post for page/post/media
735 *
736 * @since 1.0.0
737 * @access public
738 * @return $folders
739 */
740 public function save_folder_last_status()
741 {
742 $postData = filter_input_array(INPUT_POST);
743 $error = 0;
744 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
745 $response['message'] = esc_html__("Your request is not valid", 'folders');
746 $error = 1;
747 } else if (!isset($postData['post_type']) || empty($postData['type'])) {
748 $response['message'] = esc_html__("Your request is not valid", 'folders');
749 $error = 1;
750 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
751 $response['message'] = esc_html__("Your request is not valid", 'folders');
752 $error = 1;
753 } else if ($postData['post_type'] == "page" && !current_user_can("edit_pages")) {
754 $response['message'] = esc_html__("You have not permission to update width", 'folders');
755 $error = 1;
756 } else if ($postData['post_type'] != "page" && !current_user_can("edit_posts")) {
757 $response['message'] = esc_html__("You have not permission to update width", 'folders');
758 $error = 1;
759 }
760
761 if ($error == 0) {
762 $post_type = filter_input(INPUT_POST, 'post_type');
763 $post_id = filter_input(INPUT_POST, 'post_id');
764 if (!empty($post_type) && !empty($post_id)) {
765 delete_option("last_folder_status_for".$post_type);
766 add_option("last_folder_status_for".$post_type, $post_id);
767 }
768 }
769
770 }//end save_folder_last_status()
771
772
773 /**
774 * Save selected post for page/post/media
775 *
776 * @since 1.0.0
777 * @access public
778 * @return $folders
779 */
780 public function media_modal_query_final_terms($request)
781 {
782 $action = $this->getRequestVar("action");
783 if ($action == "mla-query-attachments") {
784 $query = $this->getRequestVar("query");
785 if (isset($query['media_folder']) && !empty($query['media_folder'])) {
786 if ($query['media_folder'] == -1) {
787 $tax_query = [
788 'taxonomy' => 'media_folder',
789 'operator' => 'NOT EXISTS',
790 ];
791 $request['tax_query'] = [$tax_query];
792 $request = apply_filters('media_library_organizer_media_filter_attachments', $request, $_REQUEST);
793 } else {
794 $request['media_folder'] = $query['media_folder'];
795 }
796 }
797 }
798
799 return $request;
800
801 }//end media_modal_query_final_terms()
802
803
804 /**
805 * Filter folders without trash count
806 *
807 * @since 1.0.0
808 * @access public
809 */
810 public function get_terms_filter_without_trash($terms, $taxonomies, $args) {
811 $isForFolders = 0;
812 if(!empty($taxonomies) && is_array($taxonomies) && count($taxonomies)){
813 foreach ($taxonomies as $taxonomy) {
814 if (in_array($taxonomy, array("media_folder", "folder", "post_folder"))) {
815 $isForFolders = 1;
816 } else {
817 $folder = substr($taxonomy, -7);
818 if ($folder == "_folder") {
819 $isForFolders = 1;
820 }
821 }
822 }
823 }
824
825 if($isForFolders) {
826 global $wpdb;
827 if (!is_array($terms) && count($terms) < 1) {
828 return $terms;
829 }
830
831 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
832
833 if ($trash_folders === false) {
834 $trash_folders = array();
835 $initial_trash_folders = array();
836 }
837
838 $post_table = $wpdb->prefix . "posts";
839 $term_table = $wpdb->prefix . "term_relationships";
840 $options = get_option('folders_settings');
841 $option_array = array();
842 if (!empty($options)) {
843 foreach ($options as $option) {
844 $option_array[] = self::get_custom_post_type($option);
845 }
846 }
847 foreach ($terms as $key => $term) {
848 if (isset($term->term_id) && isset($term->taxonomy) && !empty($term->taxonomy) && in_array($term->taxonomy, $option_array)) {
849 $trash_count = null;
850 if (has_filter("premio_folder_item_in_taxonomy")) {
851 $post_type = "";
852 $taxonomy = $term->taxonomy;
853
854 if ($taxonomy == "post_folder") {
855 $post_type = "post";
856 } else if ($taxonomy == "folder") {
857 $post_type = "page";
858 } else if ($taxonomy == "media_folder") {
859 $post_type = "attachment";
860 } else {
861 $post_type = trim($taxonomy, "'_folder'");
862 }
863 $arg = array(
864 'post_type' => $post_type,
865 'taxonomy' => $taxonomy,
866 );
867 $trash_count = apply_filters("premio_folder_item_in_taxonomy", $term->term_id, $arg);
868 } else {
869 if ($trash_count == null && isset($trash_folders[$term->term_taxonomy_id])) {
870 $trash_count = $trash_folders[$term->term_taxonomy_id];
871 } else if ($trash_count == null) {
872
873 if ($trash_count === null) {
874 //$result = $wpdb->get_var("SELECT COUNT(*) FROM {$post_table} p JOIN {$term_table} rl ON p.ID = rl.object_id WHERE rl.term_taxonomy_id = '{$term->term_taxonomy_id}' AND p.post_status != 'trash' LIMIT 1");
875 $query = "SELECT COUNT(DISTINCT(p.ID))
876 FROM {$post_table} p
877 JOIN {$term_table} rl ON p.ID = rl.object_id
878 WHERE rl.term_taxonomy_id = '{$term->term_taxonomy_id}' AND p.post_status != 'trash' LIMIT 1";
879 $result = $wpdb->get_var($query);
880 if (intval($result) > 0) {
881 $trash_count = intval($result);
882 } else {
883 $trash_count = 0;
884 }
885 }
886 }
887 }
888 if ($trash_count === null) {
889 $trash_count = 0;
890 }
891 $terms[$key]->trash_count = $trash_count;
892 $trash_folders[$term->term_taxonomy_id] = $trash_count;
893 }
894 }
895
896 if (!empty($terms) && $initial_trash_folders != $trash_folders) {
897 delete_transient("premio_folders_without_trash");
898 set_transient("premio_folders_without_trash", $trash_folders, 3 * DAY_IN_SECONDS);
899 }
900 }
901 return $terms;
902 }//end get_terms_filter_without_trash()
903
904
905 /**
906 * Add Checkbox to page/post lists
907 *
908 * @since 1.0.0
909 * @access public
910 * @return $folders
911 */
912 public function custom_bulk_action($bulk_actions)
913 {
914 $bulk_actions['move_to_folder'] = __('Move to Folder', 'email_to_eric');
915 return $bulk_actions;
916
917 }//end custom_bulk_action()
918
919
920 /**
921 * Folders domain for language translation
922 *
923 * @since 1.0.0
924 * @access public
925 * @return $folders
926 */
927 public function folders_text()
928 {
929 load_plugin_textdomain("folders", false, dirname(dirname(plugin_basename(__FILE__))).'/languages/');
930
931 }//end folders_text()
932
933
934 /**
935 * Add custom CSS to footer for media button
936 *
937 * @since 1.0.0
938 * @access public
939 * @return $folders
940 */
941 public function admin_footer_for_media()
942 {
943 $customize_folders = get_option('customize_folders');
944 if (isset($customize_folders['dropdown_color']) && !empty($customize_folders['dropdown_color'])) {
945 ?>
946 <style>
947 #media-attachment-taxonomy-filter, .post-upload-ui .folder_for_media, select.media-select-folder {
948 border-color: <?php echo esc_attr($customize_folders['dropdown_color']) ?>;
949 color: <?php echo esc_attr($customize_folders['dropdown_color']) ?>
950 }
951 .folder_for_media option {
952 color:#000000;
953 }
954 .folder_for_media option:first-child {
955 font-weight: bold;
956 }
957 </style>
958 <?php
959 }
960
961 }//end admin_footer_for_media()
962
963
964 /**
965 * Check for default page/post/media folder on load
966 *
967 * @since 1.0.0
968 * @access public
969 * @return $folders
970 */
971 public function check_for_default_folders()
972 {
973 global $typenow, $current_screen;
974 $isAjax = (defined('DOING_AJAX') && DOING_AJAX) ? 1 : 0;
975 $options = get_option('folders_settings');
976 $options = (empty($options) || !is_array($options)) ? [] : $options;
977 $post_status = filter_input(INPUT_GET, 'post_status');
978 $last_status = get_option("last_folder_status_for".$typenow);
979 if (empty($post_status) && !$isAjax && (in_array($typenow, $options) || !empty($last_status)) && (isset($current_screen->base) && ($current_screen->base == "edit" || ($current_screen->base == "upload")))) {
980 $requests = filter_input_array(INPUT_GET);
981 $requests = empty($requests)||!is_array($requests) ? [] : $requests;
982
983 if ($typenow == "attachment") {
984 if (count($requests) > 0) {
985 return;
986 }
987 } else if ($typenow == "post") {
988 if (count($requests) > 0) {
989 return;
990 }
991 } else {
992 if (count($requests) > 1) {
993 return;
994 }
995 }
996
997 if (!empty($last_status)) {
998 $status = 1;
999 if ($last_status != "-1" && $last_status != "all") {
1000 $type = self::get_custom_post_type($typenow);
1001 $term = get_term_by('slug', $last_status, $type);
1002 if (empty($term) || !is_object($term)) {
1003 $status = 0;
1004 }
1005 }
1006
1007 delete_option("last_folder_status_for".$typenow);
1008 if ($last_status == "all") {
1009 $last_status = "";
1010 }
1011
1012 if ($status) {
1013 if ($typenow == "attachment") {
1014 if (!isset($_REQUEST['media_folder'])) {
1015 ?>
1016 <script>
1017 window.location = '<?php echo admin_url("upload.php?post_type=attachment")."&media_folder=".esc_attr($last_status) ?>';
1018 </script>
1019 <?php
1020 exit;
1021 }
1022 } else {
1023 $post_type = self::get_custom_post_type($typenow);
1024 $admin_url = admin_url("edit.php?post_type=".$typenow);
1025 if (!isset($_REQUEST[$post_type])) {
1026 ?>
1027 <script>
1028 window.location = '<?php echo admin_url("edit.php?post_type=".esc_attr($typenow))."&".esc_attr($post_type)."=".esc_attr($last_status) ?>';
1029 </script>
1030 <?php
1031 exit;
1032 }
1033 }//end if
1034 }//end if
1035 }//end if
1036
1037 $default_folders = get_option('default_folders');
1038 $default_folders = (empty($default_folders) || !is_array($default_folders)) ? [] : $default_folders;
1039
1040 $status = 1;
1041 if (isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
1042 $type = self::get_custom_post_type($typenow);
1043 if ($default_folders[$typenow] != -1) {
1044 $term = get_term_by('slug', $default_folders[$typenow], $type);
1045 if (empty($term) || !is_object($term)) {
1046 $status = 0;
1047 }
1048 }
1049 } else {
1050 $status = 0;
1051 }
1052
1053 if ($status) {
1054 if ($typenow == "attachment") {
1055 if (!isset($_REQUEST['media_folder'])) {
1056 if (isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
1057 ?>
1058 <script>
1059 window.location = '<?php echo admin_url("upload.php?post_type=attachment")."&media_folder=".esc_attr($default_folders[$typenow]) ?>';
1060 </script>
1061 <?php
1062 exit;
1063 }
1064 }
1065 } else {
1066 $search = filter_input(INPUT_GET, "s");
1067 if (!empty($search)) {
1068 $search = esc_attr($search);
1069 } else {
1070 $search = "";
1071 }
1072
1073 $post_type = self::get_custom_post_type($typenow);
1074 if (!isset($_REQUEST[$post_type])) {
1075 if (isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
1076 ?>
1077 <script>
1078 window.location = '<?php echo admin_url("edit.php?post_type=".esc_attr($typenow))."&".esc_attr($post_type)."=".esc_attr($default_folders[$typenow])."&s=".esc_attr($search) ?>';
1079 </script>
1080 <?php
1081 exit;
1082 }
1083 }
1084 }//end if
1085 }//end if
1086 }//end if
1087
1088 }//end check_for_default_folders()
1089
1090
1091 /**
1092 * Signup for folders news
1093 *
1094 * @since 1.0.0
1095 * @access public
1096 * @return $folders
1097 */
1098 public function folder_update_status()
1099 {
1100 $response = [];
1101 $response['status'] = 0;
1102 $nonce = filter_input(INPUT_POST, 'nonce');
1103 if (!empty($nonce) && wp_verify_nonce($nonce, 'folder_update_status')) {
1104 $status = filter_input(INPUT_POST, 'status');
1105 $email = filter_input(INPUT_POST, 'email');
1106 update_option("folder_update_message", 2);
1107 if ($status == 1) {
1108 $url = 'https://premioapps.com/premio/signup/email.php';
1109 $apiParams = [
1110 'plugin' => 'folders',
1111 'email' => $email,
1112 ];
1113
1114 // Signup Email for Folders
1115 $apiResponse = wp_safe_remote_post($url, ['body' => $apiParams, 'timeout' => 15, 'sslverify' => true]);
1116
1117 if (is_wp_error($apiResponse)) {
1118 wp_safe_remote_post($url, ['body' => $apiParams, 'timeout' => 15, 'sslverify' => false]);
1119 }
1120
1121 $response['status'] = 1;
1122 }
1123 }//end if
1124
1125 echo json_encode($response);
1126 die;
1127
1128 }//end folder_update_status()
1129
1130
1131 /**
1132 * Add category to media
1133 *
1134 * @since 1.0.0
1135 * @access public
1136 * @return $folders
1137 */
1138 public function add_attachment_category($post_ID)
1139 {
1140 if (self::is_for_this_post_type('attachment') || self::is_for_this_post_type('media')) {
1141 $folder_id = null;
1142 if (isset($_REQUEST["folder_for_media"])) {
1143 $folder_id = $this->getRequestVar("folder_for_media");
1144 }
1145
1146 if ($folder_id !== null) {
1147 $folder_id = (int) $folder_id;
1148 $folder_id = self::sanitize_options($folder_id, "int");
1149 if ($folder_id > 0) {
1150 $post_type = self::get_custom_post_type("attachment");
1151 $term = get_term($folder_id);
1152 if (!empty($term) && isset($term->slug)) {
1153 wp_set_object_terms($post_ID, $term->slug, $post_type);
1154
1155 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
1156 if ($trash_folders === false) {
1157 $trash_folders = [];
1158 $initial_trash_folders = [];
1159 }
1160
1161 if (isset($term->term_taxonomy_id) && isset($trash_folders[$term->term_taxonomy_id])) {
1162 unset($trash_folders[$term->term_taxonomy_id]);
1163 }
1164
1165 if ($initial_trash_folders != $trash_folders) {
1166 delete_transient("premio_folders_without_trash");
1167 set_transient("premio_folders_without_trash", $trash_folders, (3 * DAY_IN_SECONDS));
1168 }
1169 }
1170 }//end if
1171 }//end if
1172 }//end if
1173
1174 }//end add_attachment_category()
1175
1176
1177 /**
1178 * Get Dropdown data for media popup
1179 *
1180 * @since 1.0.0
1181 * @access public
1182 * @return $folders
1183 */
1184 public function show_dropdown_on_media_screen()
1185 {
1186 if (self::is_for_this_post_type('attachment')) {
1187 $post_type = self::get_custom_post_type('attachment');
1188 global $typenow, $current_screen;
1189 // Free/Pro Class name change
1190 if (!class_exists('WCP_Tree')) {
1191 $files = [
1192 'WCP_Tree' => WCP_DS."includes".WCP_DS."tree.class.php",
1193 ];
1194
1195 foreach ($files as $file) {
1196 if (file_exists(dirname(dirname(__FILE__)).$file)) {
1197 include_once dirname(dirname(__FILE__)).$file;
1198 }
1199 }
1200 }
1201
1202 // Free/Pro Class name change
1203 $options = WCP_Tree::get_folder_option_data($post_type);?>
1204 <p class="attachments-category"><?php esc_html_e("Select a folder (Optional)", 'folders'); ?></p>
1205 <p class="attachments-category"><?php esc_html_e("First select the folder, and then upload the files", 'folders'); ?><br/></p>
1206 <p>
1207 <?php
1208 $request = sanitize_text_field($_SERVER['REQUEST_URI']);
1209 $request = strpos($request, "post.php");
1210 ?>
1211 <select name="folder_for_media" class="folder_for_media">
1212 <option value="-1">- <?php esc_html_e('Unassigned', 'folders'); ?></option>
1213 <?php echo ($options) ?>
1214 <?php if (($typenow == "attachment" && isset($current_screen->base) && $current_screen->base == "upload") || ($request !== false) || self::is_for_this_post_type('attachment') || self::is_for_this_post_type('media')) {?>
1215 <option value="add-folder"><?php esc_html_e('+ Create a New Folder', 'folders'); ?></option>
1216 <?php } ?>
1217 </select>
1218 </p>
1219 <?php
1220 }//end if
1221
1222 }//end show_dropdown_on_media_screen()
1223
1224
1225 /**
1226 * Hide folders
1227 *
1228 * @since 1.0.0
1229 * @access public
1230 * @return $folders
1231 */
1232 public function wcp_hide_folders()
1233 {
1234 $response = [];
1235 $response['status'] = 0;
1236 $response['error'] = 0;
1237 $response['data'] = [];
1238 $response['message'] = "";
1239 $postData = filter_input_array(INPUT_POST);
1240 $errorCounter = 0;
1241
1242 if (!isset($postData['status']) || empty($postData['status'])) {
1243 $response['message'] = esc_html__("Your request is not valid", 'folders');
1244 $errorCounter++;
1245 } else if (!isset($postData['type']) || empty($postData['type'])) {
1246 $response['message'] = esc_html__("Your request is not valid", 'folders');
1247 $errorCounter++;
1248 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1249 $response['message'] = esc_html__("Your request is not valid", 'folders');
1250 $errorCounter++;
1251 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
1252 $response['message'] = esc_html__("You have not permission to update width", 'folders');
1253 $errorCounter++;
1254 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
1255 $response['message'] = esc_html__("You have not permission to update width", 'folders');
1256 $errorCounter++;
1257 } else {
1258 $type = self::sanitize_options($postData['type']);
1259 $nonce = self::sanitize_options($postData['nonce']);
1260 if (!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
1261 $response['message'] = esc_html__("Your request is not valid", 'folders');
1262 $errorCounter++;
1263 }
1264 }//end if
1265
1266 if ($errorCounter == 0) {
1267 $type = self::sanitize_options($postData['type']);
1268 $status = self::sanitize_options($postData['status']);
1269 $optionName = "wcp_folder_display_status_".$type;
1270 update_option($optionName, $status);
1271 $response['status'] = 1;
1272 }
1273
1274 echo json_encode($response);
1275 wp_die();
1276
1277 }//end wcp_hide_folders()
1278
1279
1280 /**
1281 * Change status for folders
1282 *
1283 * @since 1.0.0
1284 * @access public
1285 * @return $folders
1286 */
1287 public function wcp_change_folder_display_status()
1288 {
1289 $response = [];
1290 $response['status'] = 0;
1291 $response['error'] = 0;
1292 $response['data'] = [];
1293 $response['message'] = "";
1294 $postData = filter_input_array(INPUT_POST);
1295 $errorCounter = 0;
1296 if (!isset($postData['status']) || empty($postData['status'])) {
1297 $response['message'] = esc_html__("Your request is not valid", 'folders');
1298 $errorCounter++;
1299 } else if (!isset($postData['type']) || empty($postData['type'])) {
1300 $response['message'] = esc_html__("Your request is not valid", 'folders');
1301 $errorCounter++;
1302 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1303 $response['message'] = esc_html__("Your request is not valid", 'folders');
1304 $errorCounter++;
1305 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
1306 $response['message'] = esc_html__("You have not permission to update width", 'folders');
1307 $errorCounter++;
1308 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
1309 $response['message'] = esc_html__("You have not permission to update width", 'folders');
1310 $errorCounter++;
1311 } else {
1312 $type = self::sanitize_options($postData['type']);
1313 $nonce = self::sanitize_options($postData['nonce']);
1314 if (!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
1315 $response['message'] = esc_html__("Your request is not valid", 'folders');
1316 $errorCounter++;
1317 }
1318 }//end if
1319
1320 if ($errorCounter == 0) {
1321 $type = self::sanitize_options($postData['type']);
1322 $width = self::sanitize_options($postData['status']);
1323 $optionName = "wcp_dynamic_display_status_".$type;
1324 update_option($optionName, $width);
1325 $response['status'] = 1;
1326 }
1327
1328 echo json_encode($response);
1329 wp_die();
1330
1331 }//end wcp_change_folder_display_status()
1332
1333
1334 /**
1335 * Check for folders for page/post/media id
1336 *
1337 * @since 1.0.0
1338 * @access public
1339 * @return $folders
1340 */
1341 public function premio_check_for_other_folders()
1342 {
1343 $response = [];
1344 $response['status'] = 0;
1345 $response['error'] = 0;
1346 $response['data'] = [];
1347 $response['message'] = "";
1348 $postData = filter_input_array(INPUT_POST);
1349 $errorCounter = 0;
1350 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
1351 $response['message'] = esc_html__("Your request is not valid", 'folders');
1352 $errorCounter++;
1353 } else if (!isset($postData['type']) || empty($postData['type'])) {
1354 $response['message'] = esc_html__("Your request is not valid", 'folders');
1355 $errorCounter++;
1356 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1357 $response['message'] = esc_html__("Your request is not valid", 'folders');
1358 $errorCounter++;
1359 } else if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$postData['type'])) {
1360 $response['message'] = esc_html__("Your request is not valid", 'folders');
1361 $errorCounter++;
1362 } else if (!current_user_can("manage_categories")) {
1363 $response['message'] = esc_html__("Your request is not valid", 'folders');
1364 $errorCounter++;
1365 }
1366
1367 if ($errorCounter == 0) {
1368 $folderUndoSettings = [];
1369 $type = self::sanitize_options($postData['type']);
1370 $post_id = self::sanitize_options($postData['post_id']);
1371
1372 $post_id = explode(",", $post_id);
1373
1374 $taxonomy = self::get_custom_post_type($type);
1375
1376 foreach ($post_id as $id) {
1377 $terms = get_the_terms($id, $taxonomy);
1378 if (!empty($terms) && is_array($terms)) {
1379 foreach ($terms as $term) {
1380 if ($term->term_id != $postData['taxonomy']) {
1381 $response['status'] = -1;
1382 $response['data']['post_id'] = $postData['post_id'];
1383 echo json_encode($response);
1384 wp_die();
1385 }
1386 }
1387 }
1388 }
1389
1390 $this->wcp_remove_post_folder();
1391 }//end if
1392
1393 echo json_encode($response);
1394 wp_die();
1395
1396 }//end premio_check_for_other_folders()
1397
1398
1399 /**
1400 * Remove Folder
1401 *
1402 * @since 1.0.0
1403 * @access public
1404 * @return $folders
1405 */
1406 public function wcp_remove_post_folder()
1407 {
1408 $response = [];
1409 $response['status'] = 0;
1410 $response['error'] = 0;
1411 $response['data'] = [];
1412 $response['message'] = "";
1413 $postData = filter_input_array(INPUT_POST);
1414 $errorCounter = 0;
1415 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
1416 $response['message'] = esc_html__("Your request is not valid", 'folders');
1417 $errorCounter++;
1418 } else if (!isset($postData['type']) || empty($postData['type'])) {
1419 $response['message'] = esc_html__("Your request is not valid", 'folders');
1420 $errorCounter++;
1421 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1422 $response['message'] = esc_html__("Your request is not valid", 'folders');
1423 $errorCounter++;
1424 } else if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$postData['type'])) {
1425 $response['message'] = esc_html__("Your request is not valid", 'folders');
1426 $errorCounter++;
1427 } else if (!current_user_can("manage_categories")) {
1428 $response['message'] = esc_html__("Your request is not valid", 'folders');
1429 $errorCounter++;
1430 }
1431
1432 if ($errorCounter == 0) {
1433 $folderUndoSettings = [];
1434 $type = self::sanitize_options($postData['type']);
1435 $post_id = self::sanitize_options($postData['post_id']);
1436
1437 $post_id = explode(",", $post_id);
1438
1439 $taxonomy = self::get_custom_post_type($type);
1440
1441 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
1442 if ($trash_folders === false) {
1443 $trash_folders = [];
1444 $initial_trash_folders = [];
1445 }
1446
1447 foreach ($post_id as $id) {
1448 if (!empty($id) && is_numeric($id) && $id > 0) {
1449 $terms = get_the_terms($id, $taxonomy);
1450 $post_terms = [
1451 'post_id' => $id,
1452 'terms' => $terms,
1453 ];
1454 if (!empty($terms) && count($terms) > 0) {
1455 foreach ($terms as $term) {
1456 if (isset($term->term_taxonomy_id) && isset($trash_folders[$term->term_taxonomy_id])) {
1457 unset($trash_folders[$term->term_taxonomy_id]);
1458 }
1459 }
1460 }
1461
1462 $folderUndoSettings[] = $post_terms;
1463 if (isset($postData['remove_from']) && $postData['remove_from'] == "current" && isset($postData['remove_from']) && $postData['remove_from'] == "current" && isset($postData['active_folder']) && is_numeric($postData['active_folder'])) {
1464 wp_remove_object_terms($id, intval($postData['active_folder']), $taxonomy);
1465 } else {
1466 wp_delete_object_term_relationships($id, $taxonomy);
1467 }
1468 }//end if
1469 }//end foreach
1470
1471 delete_transient("folder_undo_settings");
1472 set_transient("folder_undo_settings", $folderUndoSettings, DAY_IN_SECONDS);
1473
1474 if ($initial_trash_folders != $trash_folders) {
1475 delete_transient("premio_folders_without_trash");
1476 set_transient("premio_folders_without_trash", $trash_folders, (3 * DAY_IN_SECONDS));
1477 }
1478
1479 $response['status'] = 1;
1480 }//end if
1481
1482 echo json_encode($response);
1483 wp_die();
1484
1485 }//end wcp_remove_post_folder()
1486
1487
1488 /**
1489 * Filter records by selected categories
1490 *
1491 * @since 1.0.0
1492 * @access public
1493 * @return $folders
1494 */
1495 public function filter_record_list($query)
1496 {
1497 global $typenow;
1498
1499 if ($typenow == "attachment") {
1500 return;
1501 }
1502
1503 if (!self::is_for_this_post_type($typenow)) {
1504 return $query;
1505 }
1506
1507 $taxonomy = self::get_custom_post_type($typenow);
1508
1509 if (! isset($query->query['post_type'])) {
1510 return $query;
1511 }
1512
1513 if (! isset($_REQUEST[$taxonomy])) {
1514 return $query;
1515 }
1516
1517 $term = sanitize_text_field($_REQUEST[$taxonomy]);
1518 if ($term != "-1") {
1519 return $query;
1520 }
1521
1522 unset($query->query_vars[$taxonomy]);
1523
1524 $tax_query = [
1525 'taxonomy' => $taxonomy,
1526 'operator' => 'NOT EXISTS',
1527 ];
1528
1529 $query->set('tax_query', [ $tax_query ]);
1530 $query->tax_query = new WP_Tax_Query([ $tax_query ]);
1531
1532 return $query;
1533
1534 }//end filter_record_list()
1535
1536
1537 /**
1538 * Get folders list
1539 *
1540 * @since 1.0.0
1541 * @access public
1542 * @return $folders
1543 */
1544 public function wcp_get_default_list()
1545 {
1546
1547 $postData = filter_input_array(INPUT_POST);
1548
1549 $post_type = $postData['type'];
1550
1551 $ttpsts = $this->get_ttlpst($post_type);
1552
1553 $empty_items = self::get_tempt_posts($post_type);
1554
1555 $post_type = self::get_custom_post_type($post_type);
1556
1557 $taxonomies = self::get_terms_hierarchical($post_type);
1558
1559 $response = [
1560 'status' => 1,
1561 'total_items' => $ttpsts,
1562 'taxonomies' => $taxonomies,
1563 'empty_items' => $empty_items,
1564 ];
1565 echo json_encode($response);
1566 wp_die();
1567
1568 }//end wcp_get_default_list()
1569
1570
1571 /**
1572 * Get folders list
1573 *
1574 * @since 1.0.0
1575 * @access public
1576 * @return $folders
1577 */
1578 function get_folders_default_list()
1579 {
1580 $postData = filter_input_array(INPUT_POST);
1581
1582 $post_type = $postData['type'];
1583
1584 $ttpsts = $this->get_ttlpst($post_type);
1585
1586 $empty_items = self::get_tempt_posts($post_type);
1587
1588 $post_type = self::get_custom_post_type($post_type);
1589
1590 $taxonomies = self::get_terms_hierarchical($post_type);
1591
1592 $response = [
1593 'status' => 1,
1594 'total_items' => $ttpsts,
1595 'empty_items' => $empty_items,
1596 'taxonomies' => $taxonomies,
1597 ];
1598 echo json_encode($response);
1599 die;
1600
1601 }//end get_folders_default_list()
1602
1603
1604 /**
1605 * Save folders data for page/post id
1606 *
1607 * @since 1.0.0
1608 * @access public
1609 * @return $folders
1610 */
1611 function save_media_terms($post_id)
1612 {
1613 if (wp_is_post_revision($post_id)) {
1614 return;
1615 }
1616
1617 $post = get_post($post_id);
1618 if ($post->post_type !== 'attachment') {
1619 return;
1620 }
1621
1622 $post_type = self::get_custom_post_type('attachment');
1623 $selected_folder = get_option("selected_".esc_attr($post_type)."_folder");
1624 if ($selected_folder != null && !empty($selected_folder)) {
1625 $terms = get_term($selected_folder);
1626 if (!empty($terms) && isset($terms->term_id)) {
1627 wp_set_post_terms($post_id, $terms->term_id, $post_type, false);
1628 }
1629 }
1630
1631 }//end save_media_terms()
1632
1633
1634 /**
1635 * Filter attachment data by folder
1636 *
1637 * @since 1.0.0
1638 * @access public
1639 * @return $folders
1640 */
1641 public function filter_attachments_grid($args)
1642 {
1643 $taxonomy = 'media_folder';
1644 if (! isset($args[$taxonomy])) {
1645 return $args;
1646 }
1647
1648 $term = sanitize_text_field($args[$taxonomy]);
1649 if ($term != "-1") {
1650 return $args;
1651 }
1652
1653 unset($args[$taxonomy]);
1654 $args['tax_query'] = [
1655 [
1656 'taxonomy' => $taxonomy,
1657 'operator' => 'NOT EXISTS',
1658 ],
1659 ];
1660 $args = apply_filters('media_library_organizer_media_filter_attachments_grid', $args);
1661 return $args;
1662
1663 }//end filter_attachments_grid()
1664
1665
1666 /**
1667 * Returns total folders
1668 *
1669 * @since 1.0.0
1670 * @access public
1671 */
1672 public function get_tempt_posts($post_type="")
1673 {
1674 global $wpdb;
1675
1676 $post_table = $wpdb->prefix."posts";
1677 $term_table = $wpdb->prefix."term_relationships";
1678 $term_taxonomy_table = $wpdb->prefix."term_taxonomy";
1679 $term_meta = $wpdb->prefix."termmeta";
1680 $taxonomy = self::get_custom_post_type($post_type);
1681 $tlrcds = null;
1682 if(has_filter("premio_folder_un_categorized_items")) {
1683 $tlrcds = apply_filters("premio_folder_un_categorized_items", $post_type, $taxonomy);
1684 }
1685 if($tlrcds === null) {
1686 $user_filter = false;
1687
1688 if(!$user_filter) {
1689 if ($post_type != "attachment") {
1690 $query = "SELECT COUNT(DISTINCT({$post_table}.ID)) AS total_records FROM {$post_table} WHERE 1=1 AND (
1691 NOT EXISTS (
1692 SELECT 1
1693 FROM {$term_table}
1694 INNER JOIN {$term_taxonomy_table}
1695 ON {$term_taxonomy_table}.term_taxonomy_id = {$term_table}.term_taxonomy_id
1696 WHERE {$term_taxonomy_table}.taxonomy = '%s'
1697 AND {$term_table}.object_id = {$post_table}.ID
1698 )
1699 ) AND {$post_table}.post_type = '%s' AND (({$post_table}.post_status = 'publish' OR {$post_table}.post_status = 'future' OR {$post_table}.post_status = 'draft' OR {$post_table}.post_status = 'private' OR {$post_table}.post_status = 'pending'))";
1700 } else {
1701 $select = "SELECT COUNT(DISTINCT(P.ID)) AS total_records FROM {$post_table} AS P";
1702 $where = ["post_type = 'attachment' "];
1703 $where[] = "(post_status = 'inherit' OR post_status = 'private')";
1704 $where[] = "(NOT EXISTS (
1705 SELECT 1
1706 FROM {$term_table}
1707 INNER JOIN {$term_taxonomy_table}
1708 ON {$term_taxonomy_table}.term_taxonomy_id = {$term_table}.term_taxonomy_id
1709 WHERE {$term_taxonomy_table}.taxonomy = '%s'
1710 AND {$term_table}.object_id = P.ID
1711 )
1712 )";
1713
1714 $join = apply_filters( 'folders_count_join_query', "" );
1715 $where = apply_filters( 'folders_count_where_query', $where );
1716
1717 $query = $select . $join . " WHERE ".implode( ' AND ', $where );
1718
1719 $query = $wpdb->prepare($query, $taxonomy);
1720 }
1721 } else {
1722 if ($post_type != "attachment") {
1723 $query = "SELECT COUNT(DISTINCT({$post_table}.ID)) AS total_records FROM {$post_table} WHERE 1=1 AND (
1724 NOT EXISTS (
1725 SELECT 1
1726 FROM {$term_table}
1727 INNER JOIN {$term_taxonomy_table}
1728 ON {$term_taxonomy_table}.term_taxonomy_id = {$term_table}.term_taxonomy_id
1729 INNER JOIN {$term_meta}
1730 ON {$term_meta}.term_id = {$term_table}.term_taxonomy_id AND {$term_meta}.meta_key = 'created_by' AND {$term_meta}.meta_value = {$user_id}
1731 WHERE {$term_taxonomy_table}.taxonomy = '%s'
1732 AND {$term_table}.object_id = {$post_table}.ID
1733 )
1734 ) AND {$post_table}.post_type = '%s' AND (({$post_table}.post_status = 'publish' OR {$post_table}.post_status = 'future' OR {$post_table}.post_status = 'draft' OR {$post_table}.post_status = 'private' OR {$post_table}.post_status = 'pending'))";
1735 } else {
1736 $select = "SELECT COUNT(DISTINCT(P.ID)) AS total_records FROM {$post_table} AS P";
1737 $where = ["post_type = 'attachment' "];
1738 $where[] = "(post_status = 'inherit' OR post_status = 'private')";
1739 $where[] = "(
1740 NOT EXISTS (
1741 SELECT 1
1742 FROM {$term_table}
1743 INNER JOIN {$term_taxonomy_table}
1744 ON {$term_taxonomy_table}.term_taxonomy_id = {$term_table}.term_taxonomy_id
1745 INNER JOIN {$term_meta}
1746 ON {$term_meta}.term_id = {$term_table}.term_taxonomy_id AND {$term_meta}.meta_key = 'created_by' AND {$term_meta}.meta_value = {$user_id}
1747 WHERE {$term_taxonomy_table}.taxonomy = '%s'
1748 AND {$term_table}.object_id = P.ID
1749 )
1750 )";
1751
1752 $join = apply_filters( 'folders_count_join_query', "" );
1753 $where = apply_filters( 'folders_count_where_query', $where );
1754
1755 $query = $select . $join . " WHERE ".implode( ' AND ', $where );
1756
1757 $query = $wpdb->prepare($query, $taxonomy);
1758 }
1759 }
1760
1761 $query = $wpdb->prepare($query, $taxonomy, $post_type);
1762
1763 $tlrcds = $wpdb->get_var($query);
1764 }
1765
1766 if(!empty($tlrcds)) {
1767 return $tlrcds;
1768 } else {
1769 return 0;
1770 }
1771
1772 }//end get_tempt_posts()
1773
1774
1775 /**
1776 * Filter input data
1777 *
1778 * @since 1.0.0
1779 * @access public
1780 * @return $folders
1781 */
1782 public function getRequestVar($var)
1783 {
1784 $response = filter_input(INPUT_POST, $var);
1785 if (empty($response)) {
1786 $response = filter_input(INPUT_GET, $var);
1787 }
1788
1789 return $response;
1790
1791 }//end getRequestVar()
1792
1793
1794 /**
1795 * Redirect to default folder
1796 *
1797 * @since 1.0.0
1798 * @access public
1799 * @return $folders
1800 */
1801 public function output_backbone_view_filters()
1802 {
1803
1804 global $typenow, $current_screen;
1805 $isAjax = (defined('DOING_AJAX') && DOING_AJAX) ? 1 : 0;
1806 $options = get_option('folders_settings');
1807 $options = (empty($options) || !is_array($options)) ? [] : $options;
1808 $last_status = get_option("last_folder_status_for".$typenow);
1809 if (!$isAjax && (in_array($typenow, $options) || !empty($last_status)) && (isset($current_screen->base) && ($current_screen->base == "edit" || ($current_screen->base == "upload")))) {
1810 $default_folders = get_option('default_folders');
1811 $default_folders = (empty($default_folders) || !is_array($default_folders)) ? [] : $default_folders;
1812
1813 if (!empty($last_status)) {
1814 $status = 1;
1815 if ($last_status != "-1" && $last_status != "all") {
1816 $type = self::get_custom_post_type($typenow);
1817 $term = get_term_by('slug', $last_status, $type);
1818 if (empty($term) || !is_object($term)) {
1819 $status = 0;
1820 }
1821 }
1822
1823 delete_option("last_folder_status_for".$typenow);
1824 if ($last_status == "all") {
1825 $last_status = "";
1826 }
1827
1828 if ($status) {
1829 if ($typenow == "attachment") {
1830 if (!isset($_REQUEST['media_folder'])) {
1831 ?>
1832 <script>
1833 window.location = '<?php echo admin_url("upload.php?post_type=attachment")."&media_folder=".esc_attr($last_status) ?>';
1834 </script>
1835 <?php
1836 exit;
1837 }
1838 }
1839 }
1840 }//end if
1841
1842 $status = 1;
1843 if (isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
1844 $type = self::get_custom_post_type($typenow);
1845 if ($default_folders[$typenow] != -1) {
1846 $term = get_term_by('slug', $default_folders[$typenow], $type);
1847 if (empty($term) || !is_object($term)) {
1848 $status = 0;
1849 }
1850 }
1851 } else {
1852 $status = 0;
1853 }
1854
1855 if ($status) {
1856 if ($typenow == "attachment") {
1857 if (!isset($_REQUEST['media_folder'])) {
1858 if (isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
1859 ?>
1860 <script>
1861 window.location = '<?php echo admin_url("upload.php?post_type=attachment")."&media_folder=".esc_attr($default_folders[$typenow]) ?>';
1862 </script>
1863 <?php
1864 exit;
1865 }
1866 }
1867 }
1868 }
1869 }//end if
1870
1871 if (!(self::is_for_this_post_type('attachment') || self::is_for_this_post_type('media'))) {
1872 return;
1873 }
1874
1875 if ($typenow == "attachment") {
1876 // Free/Pro URL Change
1877 global $typenow;
1878 $is_active = 1;
1879 $folders = -1;
1880
1881 $hasStars = self::check_for_setting("has_stars", "general");
1882 $hasChild = self::check_for_setting("has_child", "general");
1883 $hasChild = empty($hasChild) ? 0 : 1;
1884 $hasStars = empty($hasStars) ? 0 : 1;
1885 // Free/Pro URL Change
1886 wp_enqueue_script('folders-media', WCP_FOLDER_URL.'assets/js/media.js', [ 'media-editor', 'media-views' ], WCP_FOLDER_VERSION, true);
1887 wp_localize_script(
1888 'folders-media',
1889 'folders_media_options',
1890 [
1891 'terms' => self::get_terms_hierarchical('media_folder'),
1892 'taxonomy' => get_taxonomy('media_folder'),
1893 'ajax_url' => admin_url("admin-ajax.php"),
1894 'activate_url' => $this->getFoldersUpgradeURL(),
1895 'nonce' => wp_create_nonce('wcp_folder_nonce_attachment'),
1896 'is_key_active' => $is_active,
1897 'hasStars' => $hasStars,
1898 'hasChildren' => $hasChild,
1899 ]
1900 );
1901 // Free/Pro URL Change
1902 wp_enqueue_style('folders-media', WCP_FOLDER_URL.'assets/css/media.css', [], WCP_FOLDER_VERSION);
1903 } else if (!self::is_active_for_screen() && self::is_for_this_post_type('attachment')) {
1904 // Free/Pro URL Change
1905 global $typenow;
1906 global $current_screen;
1907 // echo "<pre>"; print_r($current_screen); die;
1908 if (!isset($current_screen->base) || $current_screen->base != "plugins") {
1909 $is_active = 1;
1910 $folders = -1;
1911
1912 remove_filter("terms_clauses", "TO_apply_order_filter");
1913
1914 // Free/Pro URL Change
1915 $is_rtl = 0;
1916 if (function_exists('is_rtl') && is_rtl()) {
1917 $is_rtl = 1;
1918 }
1919
1920 $can_manage_folder = current_user_can("manage_categories") ? 1 : 0;
1921 $width = 275;
1922 $taxonomy_status = 0;
1923 $selected_taxonomy = "";
1924 $show_in_page = false;
1925 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
1926
1927 $taxonomies = self::get_terms_hierarchical('media_folder');
1928
1929 $folder_settings = [];
1930 foreach ($taxonomies as $taxonomy) {
1931 $is_sticky = get_term_meta($taxonomy->term_id, "is_folder_sticky", true);
1932 $is_high = get_term_meta($taxonomy->term_id, "is_highlighted", true);
1933 $folder_settings[] = [
1934 'folder_id' => $taxonomy->term_id,
1935 'is_sticky' => intval($is_sticky),
1936 'is_high' => intval($is_high),
1937 'nonce' => wp_create_nonce('wcp_folder_term_'.$taxonomy->term_id),
1938 'is_deleted' => 0,
1939 'slug' => $taxonomy->slug,
1940 'folder_count' => intval($taxonomy->trash_count),
1941 ];
1942 }
1943
1944 $hasStars = self::check_for_setting("has_stars", "general");
1945 $hasChild = self::check_for_setting("has_child", "general");
1946 $hasChild = empty($hasChild) ? 0 : 1;
1947 $hasStars = empty($hasStars) ? 0 : 1;
1948
1949 $customize_folders = get_option('customize_folders');
1950 $use_folder_undo = !isset($customize_folders['use_folder_undo']) ? "yes" : $customize_folders['use_folder_undo'];
1951 $defaultTimeout = !isset($customize_folders['default_timeout']) ? 5 : intval($customize_folders['default_timeout']);
1952 if (empty($defaultTimeout) || !is_numeric($defaultTimeout) || $defaultTimeout < 0) {
1953 $defaultTimeout = 5;
1954 }
1955
1956 $defaultTimeout = ($defaultTimeout * 1000);
1957
1958 $default_folders = get_option("default_folders");
1959 $default_folder = "";
1960 if (isset($default_folders["attachment"])) {
1961 $default_folder = $default_folders["attachment"];
1962 }
1963
1964 $use_shortcuts = !isset($customize_folders['use_shortcuts']) ? "yes" : $customize_folders['use_shortcuts'];
1965
1966 $lang = $this->js_strings();
1967 wp_dequeue_script("jquery-jstree");
1968 // CMS Tree Page View Conflict
1969 wp_enqueue_script('folders-overlayscrollbars', WCP_FOLDER_URL.'assets/js/jquery.overlayscrollbars.min.js', [], WCP_FOLDER_VERSION);
1970 wp_enqueue_script('folders-tree', WCP_FOLDER_URL.'assets/js/jstree.min.js', [], WCP_FOLDER_VERSION);
1971 wp_enqueue_script('wcp-folders-media', WCP_FOLDER_URL.'assets/js/page-post-media.min.js', ['jquery', 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'backbone'], WCP_FOLDER_VERSION, true);
1972 wp_enqueue_script('wcp-jquery-touch', plugin_dir_url(dirname(__FILE__)).'assets/js/jquery.ui.touch-punch.min.js', ['jquery'], WCP_FOLDER_VERSION);
1973 wp_localize_script(
1974 'wcp-folders-media',
1975 'folders_media_options',
1976 [
1977 'terms' => $taxonomies,
1978 'taxonomy' => get_taxonomy('media_folder'),
1979 'ajax_url' => admin_url("admin-ajax.php"),
1980 'media_page_url' => admin_url("upload.php?media_folder="),
1981 'activate_url' => $this->getFoldersUpgradeURL(),
1982 'nonce' => wp_create_nonce('wcp_folder_nonce_attachment'),
1983 'is_key_active' => $is_active,
1984 'folders' => $folders,
1985 'upgrade_url' => $this->getFoldersUpgradeURL(),
1986 'post_type' => 'attachment',
1987 'page_url' => $admin_url,
1988 'current_url' => "",
1989 'ajax_image' => plugin_dir_url(dirname(__FILE__))."assets/images/ajax-loader.gif",
1990 'register_url' => "",
1991 'isRTL' => $is_rtl,
1992 'can_manage_folder' => $can_manage_folder,
1993 'folder_width' => $width,
1994 'taxonomy_status' => $taxonomy_status,
1995 'selected_taxonomy' => $selected_taxonomy,
1996 'show_in_page' => $show_in_page,
1997 'svg_file' => WCP_FOLDER_URL.'assets/images/pin.png',
1998 'folder_settings' => $folder_settings,
1999 'hasStars' => $hasStars,
2000 'hasChildren' => $hasChild,
2001 'useFolderUndo' => $use_folder_undo,
2002 'defaultTimeout' => $defaultTimeout,
2003 'default_folder' => $default_folder,
2004 'use_shortcuts' => $use_shortcuts,
2005 'lang' => $lang
2006 ]
2007 );
2008 // Free/Pro URL Change
2009 wp_enqueue_style('folders-jstree', WCP_FOLDER_URL.'assets/css/jstree.min.css', [], WCP_FOLDER_VERSION);
2010 wp_enqueue_style('folder-overlayscrollbars', WCP_FOLDER_URL.'assets/css/overlayscrollbars.min.css', [], WCP_FOLDER_VERSION);
2011 wp_enqueue_style('folder-folders', WCP_FOLDER_URL.'assets/css/folders.min.css', [], WCP_FOLDER_VERSION);
2012 wp_enqueue_style('folders-media', WCP_FOLDER_URL.'assets/css/page-post-media.min.css', [], WCP_FOLDER_VERSION);
2013 wp_enqueue_style('folder-icon', WCP_FOLDER_URL.'assets/css/folder-icon.css', [], WCP_FOLDER_VERSION);
2014 $width = 275;
2015 $string = "";
2016 $css_text = "";
2017 $customize_folders = get_option('customize_folders');
2018 if (!isset($customize_folders['new_folder_color']) || empty($customize_folders['new_folder_color'])) {
2019 $customize_folders['new_folder_color'] = "#FA166B";
2020 }
2021
2022 $css_text .= ".media-frame a.add-new-folder { background-color: ".esc_attr($customize_folders['new_folder_color'])."; border-color: ".esc_attr($customize_folders['new_folder_color'])."}";
2023 $css_text .= ".wcp-hide-show-buttons .toggle-buttons { background-color: ".esc_attr($customize_folders['new_folder_color'])."; }";
2024 $css_text .= ".folders-toggle-button span { background-color: ".esc_attr($customize_folders['new_folder_color'])."; }";
2025 $css_text .= ".ui-resizable-handle.ui-resizable-e:before, .ui-resizable-handle.ui-resizable-w:before {border-color: ".esc_attr($customize_folders['new_folder_color'])." !important}";
2026
2027 if (!isset($customize_folders['folder_bg_color']) || empty($customize_folders['folder_bg_color'])) {
2028 $customize_folders['folder_bg_color'] = "#FA166B";
2029 }
2030
2031 $rgbColor = self::hexToRgb($customize_folders['folder_bg_color']);
2032 $css_text .= "body:not(.no-hover-css) #custom-scroll-menu .jstree-hovered:not(.jstree-clicked), body:not(.no-hover-css) #custom-scroll-menu .jstree-hovered:not(.jstree-clicked):hover { background: rgba(".esc_attr($rgbColor['r']).",".esc_attr($rgbColor['g']).",".esc_attr($rgbColor['b']).", 0.08) !important; color: #333333;}";
2033 $css_text .= "body:not(.no-hover-css) #custom-scroll-menu .jstree-clicked, body:not(.no-hover-css) #custom-scroll-menu .jstree-clicked:not(.jstree-clicked):focus, #custom-scroll-menu .jstree-clicked, #custom-scroll-menu .jstree-clicked:hover { background: ".esc_attr($customize_folders['folder_bg_color'])." !important; color: #ffffff !important; }";
2034 $css_text .= "body:not(.no-hover-css) #custom-scroll-menu .jstree-clicked .folder-actions { background: ".esc_attr($customize_folders['folder_bg_color'])." !important; color: #ffffff !important; }";
2035 $css_text .= "#custom-scroll-menu .jstree-hovered.wcp-drop-hover, #custom-scroll-menu .jstree-hovered.wcp-drop-hover:hover, #custom-scroll-menu .jstree-clicked.wcp-drop-hover, #custom-scroll-menu .jstree-clicked.wcp-drop-hover:hover, body #custom-scroll-menu *.drag-in >, body #custom-scroll-menu *.drag-in > a:hover { background: ".esc_attr($customize_folders['folder_bg_color'])." !important; color: #ffffff !important; }";
2036 $css_text .= ".drag-bot > a { border-bottom: solid 2px ".esc_attr($customize_folders['folder_bg_color'])."}";
2037 $css_text .= ".drag-up > a { border-top: solid 2px ".esc_attr($customize_folders['folder_bg_color'])."}";
2038 $css_text .= "body:not(.no-hover-css) #custom-scroll-menu *.drag-in > a.jstree-hovered, body:not(.no-hover-css) #custom-scroll-menu *.drag-in > a.jstree-hovered:hover {background: ".esc_attr($customize_folders['folder_bg_color'])." !important; color: #fff !important;}";
2039 $css_text .= ".orange-bg > span, .jstree-clicked, .header-posts a.active-item, .un-categorised-items.active-item, .sticky-folders ul li a.active-item { background-color: ".esc_attr($customize_folders['folder_bg_color'])." !important; color: #ffffff !important; }";
2040 $css_text .= "body:not(.no-hover-css) .wcp-container .route .title:hover, body:not(.no-hover-css) .header-posts a:hover, body:not(.no-hover-css) .un-categorised-items:hover, body:not(.no-hover-css) .sticky-folders ul li a:hover { background: rgba(".esc_attr($rgbColor['r'].",".$rgbColor['g'].",".$rgbColor['b'].", 0.08")."); color: #333333;}";
2041 $css_text .= ".wcp-drop-hover {background-color: ".esc_attr($customize_folders['folder_bg_color'])." !important; color: #ffffff; }";
2042 $css_text .= "#custom-menu .route .nav-icon .wcp-icon {color: ".esc_attr($customize_folders['folder_bg_color'])." !important;}";
2043 $css_text .= ".mCS-3d.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar {background-color: ".esc_attr($customize_folders['folder_bg_color'])." !important;}";
2044 $css_text .= ".os-theme-dark>.os-scrollbar>.os-scrollbar-track>.os-scrollbar-handle {background-color: ".esc_attr($customize_folders['folder_bg_color'])." !important;}";
2045 $css_text .= "body:not(.no-hover-css) .jstree-hovered {background: rgba(".esc_attr($rgbColor['r'].",".$rgbColor['g'].",".$rgbColor['b'].", 0.08").") }";
2046 $css_text .= ".jstree-default .jstree-clicked { background-color:".esc_attr($customize_folders['folder_bg_color'])."}";
2047 $css_text .= ".jstree-node.drag-in > a.jstree-anchor.jstree-hovered { background-color: ".esc_attr($customize_folders['folder_bg_color'])."; color: #ffffff; }";
2048 $css_text .= "#custom-scroll-menu .jstree-hovered:not(.jstree-clicked) .pfolder-folder-close { color: ".esc_attr($customize_folders['folder_bg_color'])."; }";
2049
2050 if (!isset($customize_folders['bulk_organize_button_color']) || empty($customize_folders['bulk_organize_button_color'])) {
2051 $customize_folders['bulk_organize_button_color'] = "#FA166B";
2052 }
2053
2054 $css_text .= "button.button.organize-button { background-color: ".esc_attr($customize_folders['bulk_organize_button_color'])."; border-color: ".esc_attr($customize_folders['bulk_organize_button_color'])."; }";
2055 $css_text .= "button.button.organize-button:hover { background-color: ".esc_attr($customize_folders['bulk_organize_button_color'])."; border-color: ".esc_attr($customize_folders['bulk_organize_button_color'])."; }";
2056
2057 $font_family = "";
2058 if (isset($customize_folders['folder_font']) && !empty($customize_folders['folder_font'])) {
2059 $folder_fonts = self::get_font_list();
2060 $font_family = $customize_folders['folder_font'];
2061 if (isset($folder_fonts[$font_family])) {
2062 $css_text .= ".wcp-container, .folder-popup-form { font-family: ".esc_attr($font_family)." !important; }";
2063 }
2064
2065 if ($folder_fonts[$font_family] == "Default") {
2066 $font_family = "";
2067 }
2068 }
2069
2070 if (isset($customize_folders['folder_size']) && !empty($customize_folders['folder_size'])) {
2071 $css_text .= ".wcp-container .route span.title-text, .header-posts a, .un-categorised-items a, .sticky-title { font-size: ".esc_attr($customize_folders['folder_size'])."px; }";
2072 }
2073
2074 if (!empty($font_family)) {
2075 wp_enqueue_style('custom-google-fonts', 'https://fonts.googleapis.com/css?family='.urlencode($font_family), false);
2076 }
2077
2078 wp_add_inline_style('folders-media', $css_text);
2079 }//end if
2080 }//end if
2081
2082 }//end output_backbone_view_filters()
2083
2084
2085 /**
2086 * Get folders by hierarchy
2087 *
2088 * @since 1.0.0
2089 * @access public
2090 * @return $folders
2091 */
2092 public function get_terms_hierarchical($taxonomy)
2093 {
2094 $terms = get_terms(
2095 [
2096 'taxonomy' => $taxonomy,
2097 'hide_empty' => false,
2098 'parent' => 0,
2099 'orderby' => 'meta_value_num',
2100 'order' => 'ASC',
2101 'hierarchical' => false,
2102 'update_count_callback' => '_update_generic_term_count',
2103 'meta_query' => [
2104 [
2105 'key' => 'wcp_custom_order',
2106 'type' => 'NUMERIC',
2107 ],
2108 ],
2109 ]
2110 );
2111 $hierarchical_terms = [];
2112 if (!empty($terms)) {
2113 foreach ($terms as $term) {
2114 if (!empty($term) && isset($term->term_id)) {
2115 $term->term_name = $term->name;
2116 $hierarchical_terms[] = $term;
2117 $hierarchical_terms = self::get_child_terms($taxonomy, $hierarchical_terms, $term->term_id, "-");
2118 }
2119 }
2120 }
2121
2122 return $hierarchical_terms;
2123
2124 }//end get_terms_hierarchical()
2125
2126
2127 /**
2128 * Get Child folders
2129 *
2130 * @since 1.0.0
2131 * @access public
2132 * @return $folders
2133 */
2134 public static function get_child_terms($taxonomy, $hierarchical_terms, $term_id, $separator="-")
2135 {
2136 $terms = get_terms(
2137 [
2138 'taxonomy' => $taxonomy,
2139 'hide_empty' => false,
2140 'parent' => $term_id,
2141 'orderby' => 'meta_value_num',
2142 'order' => 'ASC',
2143 'hierarchical' => false,
2144 'update_count_callback' => '_update_generic_term_count',
2145 'meta_query' => [
2146 [
2147 'key' => 'wcp_custom_order',
2148 'type' => 'NUMERIC',
2149 ],
2150 ],
2151 ]
2152 );
2153 if (!empty($terms)) {
2154 foreach ($terms as $term) {
2155 if (isset($term->name)) {
2156 $term->name = $separator." ".$term->name;
2157 $term->term_name = trim($term->name, "-");
2158 $hierarchical_terms[] = $term;
2159 $hierarchical_terms = self::get_child_terms($taxonomy, $hierarchical_terms, $term->term_id, $separator."-");
2160 }
2161 }
2162 }
2163
2164 return $hierarchical_terms;
2165
2166 }//end get_child_terms()
2167
2168
2169 /**
2170 * Update folders data for page, post, media
2171 *
2172 * @since 1.0.0
2173 * @access public
2174 * @return $folders
2175 */
2176 public function update_folder_new_term_relationships($object_id="", $term_ids=[], $taxonomy="")
2177 {
2178 if (is_array($term_ids) && !empty($term_ids)) {
2179 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
2180 if ($trash_folders === false) {
2181 $trash_folders = [];
2182 $initial_trash_folders = [];
2183 }
2184
2185 foreach ($term_ids as $term_id) {
2186 $term = get_term($term_id, $taxonomy);
2187 if (isset($term->term_taxonomy_id) && isset($trash_folders[$term->term_taxonomy_id])) {
2188 unset($trash_folders[$term->term_taxonomy_id]);
2189 }
2190 }
2191
2192 if ($initial_trash_folders != $trash_folders) {
2193 delete_transient("premio_folders_without_trash");
2194 set_transient("premio_folders_without_trash", $trash_folders, (3 * DAY_IN_SECONDS));
2195 }
2196 }
2197
2198 }//end update_folder_new_term_relationships()
2199
2200
2201 /**
2202 * Update folders data for page, post, media
2203 *
2204 * @since 1.0.0
2205 * @access public
2206 * @return $folders
2207 */
2208 public function update_folder_term_relationships($object_id="", $term_ids=[], $taxonomy="")
2209 {
2210 if (is_array($term_ids) && !empty($term_ids)) {
2211 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
2212 if ($trash_folders === false) {
2213 $trash_folders = [];
2214 $initial_trash_folders = [];
2215 }
2216
2217 foreach ($term_ids as $term_id) {
2218 $term = get_term($term_id, $taxonomy);
2219 if (isset($term->term_taxonomy_id) && isset($trash_folders[$term_id])) {
2220 unset($trash_folders[$term->term_taxonomy_id]);
2221 }
2222 }
2223
2224 if ($initial_trash_folders != $trash_folders) {
2225 delete_transient("premio_folders_without_trash");
2226 set_transient("premio_folders_without_trash", $trash_folders, (3 * DAY_IN_SECONDS));
2227 }
2228 }
2229
2230 }//end update_folder_term_relationships()
2231
2232
2233 /**
2234 * Get child folders
2235 *
2236 * @since 1.0.0
2237 * @access public
2238 * @return $folders
2239 */
2240 private function add_child_terms_recursive($taxonomy, $hierarchical_terms, $hierarchy, $current_term_id, $current_depth)
2241 {
2242
2243 if (! isset($hierarchy[$current_term_id])) {
2244 return $hierarchical_terms;
2245 }
2246
2247 foreach ($hierarchy[$current_term_id] as $child_term_id) {
2248 $child_term = get_term($child_term_id, $taxonomy);
2249
2250 $child_term->name = str_pad('', $current_depth, '-', STR_PAD_LEFT).' '.$child_term->name;
2251
2252 $hierarchical_terms[] = $child_term;
2253
2254 $hierarchical_terms = self::add_child_terms_recursive($taxonomy, $hierarchical_terms, $hierarchy, $child_term_id, ( $current_depth + 1 ));
2255 }
2256
2257 return $hierarchical_terms;
2258
2259 }//end add_child_terms_recursive()
2260
2261
2262 /**
2263 * Filter data for attachments
2264 *
2265 * @since 1.0.0
2266 * @access public
2267 * @return $folders
2268 */
2269 public function filter_attachments_list($query)
2270 {
2271
2272 if (! isset($query->query['post_type'])) {
2273 return $query;
2274 }
2275
2276 if (is_array($query->query['post_type']) && ! in_array('attachment', $query->query['post_type'])) {
2277 return $query;
2278 }
2279
2280 if (! is_array($query->query['post_type']) && strpos($query->query['post_type'], 'attachment') === false) {
2281 return $query;
2282 }
2283
2284 if (! isset($_REQUEST['media_folder'])) {
2285 return $query;
2286 }
2287
2288 $term = sanitize_text_field(wp_unslash($_REQUEST['media_folder']));
2289 if ($term != "-1") {
2290 return $query;
2291 }
2292
2293 unset($query->query_vars['media_folder']);
2294
2295 $tax_query = [
2296 'taxonomy' => 'media_folder',
2297 'operator' => 'NOT EXISTS',
2298 ];
2299
2300 $query->set('tax_query', [ $tax_query ]);
2301 $query->tax_query = new WP_Tax_Query([ $tax_query ]);
2302
2303 $query = apply_filters('media_library_organizer_media_filter_attachments', $query, $_REQUEST);
2304
2305 return $query;
2306
2307 }//end filter_attachments_list()
2308
2309
2310 /**
2311 * Filter data for attachments
2312 *
2313 * @since 1.0.0
2314 * @access public
2315 * @return $folders
2316 */
2317 public function output_list_table_filters($post_type, $view_name = "")
2318 {
2319 if ($post_type != 'attachment') {
2320 return;
2321 }
2322
2323 if ($view_name != 'bar') {
2324 return;
2325 }
2326
2327 if (!self::is_for_this_post_type('attachment')) {
2328 return;
2329 }
2330
2331 $current_term = false;
2332 if (isset($_REQUEST['media_folder'])) {
2333 $current_term = sanitize_text_field($_REQUEST['media_folder']);
2334 }
2335
2336 wp_dropdown_categories(
2337 [
2338 'show_option_all' => esc_html__('All Folders', 'folders'),
2339 'show_option_none' => esc_html__('(Unassigned)', 'folders'),
2340 'option_none_value' => -1,
2341 'orderby' => 'meta_value_num',
2342 'order' => 'ASC',
2343 'show_count' => true,
2344 'hide_empty' => false,
2345 'update_count_callback' => '_update_generic_term_count',
2346 'echo' => true,
2347 'selected' => $current_term,
2348 'hierarchical' => true,
2349 'name' => 'media_folder',
2350 'id' => '',
2351 'class' => '',
2352 'taxonomy' => 'media_folder',
2353 'value_field' => 'slug',
2354 'meta_query' => [
2355 [
2356 'key' => 'wcp_custom_order',
2357 'type' => 'NUMERIC',
2358 ],
2359 ],
2360 ]
2361 );
2362
2363 }//end output_list_table_filters()
2364
2365
2366 /**
2367 * Update folder relationship with page, post, media
2368 *
2369 * @since 1.0.0
2370 * @access public
2371 * @return $folders
2372 */
2373 function new_to_auto_draft($post)
2374 {
2375
2376 $post_type = $post->post_type;
2377
2378 if (self::is_for_this_post_type($post_type) && !isset($_REQUEST["folder_for_media"])) {
2379 $post_type = self::get_custom_post_type($post_type);
2380 $selected_folder = get_option("selected_".esc_attr($post_type)."_folder");
2381
2382 if ($selected_folder != null && !empty($selected_folder)) {
2383 $terms = get_term($selected_folder);
2384 if (!empty($terms) && isset($terms->slug)) {
2385 wp_set_object_terms($post->ID, $terms->slug, $post_type);
2386 }
2387 }
2388 }
2389
2390 }//end new_to_auto_draft()
2391
2392
2393 /**
2394 * Send message to owner for Help
2395 *
2396 * @since 1.0.0
2397 * @access public
2398 * @return $response
2399 */
2400 public function wcp_folder_send_message_to_owner()
2401 {
2402 if (current_user_can('manage_options')) {
2403 $response = [];
2404 $response['status'] = 0;
2405 $response['error'] = 0;
2406 $response['errors'] = [];
2407 $response['message'] = "";
2408 $errorArray = [];
2409 $errorMessage = esc_html__("%s is required", 'folders');
2410 $postData = filter_input_array(INPUT_POST);
2411 if (!isset($postData['textarea_text']) || trim($postData['textarea_text']) == "") {
2412 $error = [
2413 "key" => "textarea_text",
2414 "message" => esc_html__("Please enter your message", 'folders'),
2415 ];
2416 $errorArray[] = $error;
2417 }
2418
2419 if (!isset($postData['user_email']) || trim($postData['user_email']) == "") {
2420 $error = [
2421 "key" => "user_email",
2422 "message" => sprintf($errorMessage, __("Email", 'folders')),
2423 ];
2424 $errorArray[] = $error;
2425 } else if (!filter_var($postData['user_email'], FILTER_VALIDATE_EMAIL)) {
2426 $error = [
2427 'key' => "user_email",
2428 "message" => "Email is not valid",
2429 ];
2430 $errorArray[] = $error;
2431 }
2432
2433 if (empty($errorArray)) {
2434 if (!isset($postData['folder_help_nonce']) || trim($postData['folder_help_nonce']) == "") {
2435 $error = [
2436 "key" => "nonce",
2437 "message" => esc_html__("Your request is not valid", 'folders'),
2438 ];
2439 $errorArray[] = $error;
2440 } else {
2441 if (!wp_verify_nonce($postData['folder_help_nonce'], 'wcp_folder_help_nonce')) {
2442 $error = [
2443 "key" => "nonce",
2444 "message" => esc_html__("Your request is not valid", 'folders'),
2445 ];
2446 $errorArray[] = $error;
2447 }
2448 }
2449 }
2450
2451 if (empty($errorArray)) {
2452 $text_message = self::sanitize_options($postData['textarea_text']);
2453 $email = self::sanitize_options($postData['user_email'], "email");
2454 $domain = site_url();
2455 $current_user = wp_get_current_user();
2456 $user_name = $current_user->first_name." ".$current_user->last_name;
2457
2458 $response['status'] = 1;
2459
2460 // sending message to Crisp
2461 $post_message = [];
2462
2463 $message_data = [];
2464 $message_data['key'] = "Plugin";
2465 $message_data['value'] = "Folders";
2466 $post_message[] = $message_data;
2467
2468 $message_data = [];
2469 $message_data['key'] = "Domain";
2470 $message_data['value'] = $domain;
2471 $post_message[] = $message_data;
2472
2473 $message_data = [];
2474 $message_data['key'] = "Email";
2475 $message_data['value'] = $email;
2476 $post_message[] = $message_data;
2477
2478 $message_data = [];
2479 $message_data['key'] = "Message";
2480 $message_data['value'] = $text_message;
2481 $post_message[] = $message_data;
2482
2483 $api_params = [
2484 'domain' => $domain,
2485 'email' => $email,
2486 'url' => site_url(),
2487 'name' => $user_name,
2488 'message' => $post_message,
2489 'plugin' => "Folders",
2490 'type' => "Need Help",
2491 ];
2492
2493 // Sending message to Crisp API
2494 $crisp_response = wp_safe_remote_post("https://go.premio.io/crisp/crisp-send-message.php", ['body' => $api_params, 'timeout' => 15, 'sslverify' => true]);
2495
2496 if (is_wp_error($crisp_response)) {
2497 wp_safe_remote_post("https://go.premio.io/crisp/crisp-send-message.php", ['body' => $api_params, 'timeout' => 15, 'sslverify' => false]);
2498 }
2499 } else {
2500 $response['error'] = 1;
2501 $response['errors'] = $errorArray;
2502 }//end if
2503
2504 echo json_encode($response);
2505 }//end if
2506
2507 }//end wcp_folder_send_message_to_owner()
2508
2509
2510 /**
2511 * Send message to owner when folder is deactivated
2512 *
2513 * @since 1.0.0
2514 * @access public
2515 * @return $response
2516 */
2517 public function folder_plugin_deactivate()
2518 {
2519 if (current_user_can('manage_options')) {
2520 $postData = filter_input_array(INPUT_POST);
2521 $errorCounter = 0;
2522 $response = [];
2523 $response['status'] = 0;
2524 $response['message'] = "";
2525 $response['valid'] = 1;
2526 if (!isset($postData['reason']) || empty($postData['reason'])) {
2527 $errorCounter++;
2528 $response['message'] = "Please provide reason";
2529 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2530 $response['message'] = esc_html__("Your request is not valid", 'folders');
2531 $errorCounter++;
2532 $response['valid'] = 0;
2533 } else {
2534 $nonce = self::sanitize_options($postData['nonce']);
2535 if (!wp_verify_nonce($nonce, 'wcp_folder_deactivate_nonce')) {
2536 $response['message'] = esc_html__("Your request is not valid", 'folders');
2537 $errorCounter++;
2538 $response['valid'] = 0;
2539 }
2540 }
2541
2542 if ($errorCounter == 0) {
2543 $reason = $postData['reason'];
2544 $email = "none@none.none";
2545 if (isset($postData['email_id']) && !empty($postData['email_id']) && filter_var($postData['email_id'], FILTER_VALIDATE_EMAIL)) {
2546 $email = $postData['email_id'];
2547 }
2548
2549 $domain = site_url();
2550 $current_user = wp_get_current_user();
2551 $user_name = $current_user->first_name." ".$current_user->last_name;
2552
2553 $response['status'] = 1;
2554
2555 // sending message to Crisp
2556 $post_message = [];
2557
2558 $message_data = [];
2559 $message_data['key'] = "Plugin";
2560 $message_data['value'] = "Folders";
2561 $post_message[] = $message_data;
2562
2563 $message_data = [];
2564 $message_data['key'] = "Plugin Version";
2565 $message_data['value'] = WCP_FOLDER_VERSION;
2566 $post_message[] = $message_data;
2567
2568 $message_data = [];
2569 $message_data['key'] = "Domain";
2570 $message_data['value'] = $domain;
2571 $post_message[] = $message_data;
2572
2573 $message_data = [];
2574 $message_data['key'] = "Email";
2575 $message_data['value'] = $email;
2576 $post_message[] = $message_data;
2577
2578 $message_data = [];
2579 $message_data['key'] = "WordPress Version";
2580 $message_data['value'] = esc_attr(get_bloginfo('version'));
2581 $post_message[] = $message_data;
2582
2583 $message_data = [];
2584 $message_data['key'] = "PHP Version";
2585 $message_data['value'] = PHP_VERSION;
2586 $post_message[] = $message_data;
2587
2588 $message_data = [];
2589 $message_data['key'] = "Message";
2590 $message_data['value'] = $reason;
2591 $post_message[] = $message_data;
2592
2593 $api_params = [
2594 'domain' => $domain,
2595 'email' => $email,
2596 'url' => site_url(),
2597 'name' => $user_name,
2598 'message' => $post_message,
2599 'plugin' => "Folders",
2600 'type' => "Uninstall",
2601 ];
2602
2603 // Sending message to Crisp API
2604 $crisp_response = wp_safe_remote_post("https://go.premio.io/crisp/crisp-send-message.php", ['body' => $api_params, 'timeout' => 15, 'sslverify' => true]);
2605
2606 if (is_wp_error($crisp_response)) {
2607 wp_safe_remote_post("https://go.premio.io/crisp/crisp-send-message.php", ['body' => $api_params, 'timeout' => 15, 'sslverify' => false]);
2608 }
2609 }//end if
2610
2611 echo json_encode($response);
2612 wp_die();
2613 }//end if
2614
2615 }//end folder_plugin_deactivate()
2616
2617
2618 /**
2619 * Returns total folders
2620 *
2621 * @since 1.0.0
2622 * @access public
2623 * @return $total
2624 */
2625 public static function ttl_fldrs()
2626 {
2627 $post_types = get_option('folders_settings');
2628 $post_types = is_array($post_types) ? $post_types : [];
2629 $total = 0;
2630 foreach ($post_types as $post_type) {
2631 $post_type = self::get_custom_post_type($post_type);
2632 $total += wp_count_terms($post_type);
2633 }
2634
2635 return $total;
2636
2637 }//end ttl_fldrs()
2638
2639
2640 /**
2641 * Remove post
2642 *
2643 * @since 1.0.0
2644 * @access public
2645 * @return $response
2646 */
2647 public function wcp_remove_post_item()
2648 {
2649 $response = [];
2650 $response['status'] = 0;
2651 $response['error'] = 0;
2652 $response['data'] = [];
2653 $response['message'] = "";
2654 $postData = filter_input_array(INPUT_POST);
2655 if (isset($postData['post_id']) && !empty($postData['post_id'])) {
2656 wp_delete_post($postData['post_id']);
2657 $response['status'] = 1;
2658 }
2659
2660 echo json_encode($response);
2661 wp_die();
2662
2663 }//end wcp_remove_post_item()
2664
2665
2666 /**
2667 * Mark all folders
2668 *
2669 * @since 1.0.0
2670 * @access public
2671 * @return $response
2672 */
2673 public function wcp_change_all_status()
2674 {
2675 $response = [];
2676 $response['status'] = 0;
2677 $response['error'] = 0;
2678 $response['data'] = [];
2679 $response['message'] = "";
2680 $postData = filter_input_array(INPUT_POST);
2681 $errorCounter = 0;
2682 if (!isset($postData['type']) || empty($postData['type'])) {
2683 $response['message'] = esc_html__("Your request is not valid", 'folders');
2684 $errorCounter++;
2685 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2686 $response['message'] = esc_html__("Your request is not valid", 'folders');
2687 $errorCounter++;
2688 } else if (!current_user_can("manage_categories") || ($postData['type'] == "page" && !current_user_can("edit_pages"))) {
2689 $response['message'] = esc_html__("You have not permission to update width", 'folders');
2690 $errorCounter++;
2691 } else if (!current_user_can("manage_categories") || ($postData['type'] != "page" && !current_user_can("edit_posts"))) {
2692 $response['message'] = esc_html__("You have not permission to update width", 'folders');
2693 $errorCounter++;
2694 } else {
2695 $type = self::sanitize_options($postData['type']);
2696 $nonce = self::sanitize_options($postData['nonce']);
2697 if (!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
2698 $response['message'] = esc_html__("Your request is not valid", 'folders');
2699 $errorCounter++;
2700 }
2701 }
2702
2703 if ($errorCounter == 0) {
2704 if (isset($postData['folders']) || !empty($postData['folders'])) {
2705 $status = isset($postData['status']) ? $postData['status'] : 0;
2706 $status = self::sanitize_options($status);
2707 $folders = self::sanitize_options($postData['folders']);
2708 $folders = trim($folders, ",");
2709 $folders = explode(",", $folders);
2710 foreach ($folders as $folder) {
2711 update_term_meta($folder, "is_active", $status);
2712 }
2713 }
2714
2715 $response['status'] = 1;
2716 }
2717
2718 echo json_encode($response);
2719 wp_die();
2720
2721 }//end wcp_change_all_status()
2722
2723
2724 /**
2725 * Change folder width
2726 *
2727 * @since 1.0.0
2728 * @access public
2729 * @return $response
2730 */
2731 public function wcp_change_post_width()
2732 {
2733 $response = [];
2734 $response['status'] = 0;
2735 $response['error'] = 0;
2736 $response['data'] = [];
2737 $response['message'] = "";
2738 $postData = filter_input_array(INPUT_POST);
2739 $errorCounter = 0;
2740 if (!isset($postData['width']) || empty($postData['width'])) {
2741 $response['message'] = esc_html__("Your request is not valid", 'folders');
2742 $errorCounter++;
2743 } else if (!isset($postData['type']) || empty($postData['type'])) {
2744 $response['message'] = esc_html__("Your request is not valid", 'folders');
2745 $errorCounter++;
2746 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2747 $response['message'] = esc_html__("Your request is not valid", 'folders');
2748 $errorCounter++;
2749 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
2750 $response['message'] = esc_html__("You have not permission to update width", 'folders');
2751 $errorCounter++;
2752 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
2753 $response['message'] = esc_html__("You have not permission to update width", 'folders');
2754 $errorCounter++;
2755 } else {
2756 $type = self::sanitize_options($postData['type']);
2757 $nonce = self::sanitize_options($postData['nonce']);
2758 if (!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
2759 $response['message'] = esc_html__("Your request is not valid", 'folders');
2760 $errorCounter++;
2761 }
2762 }//end if
2763
2764 if ($errorCounter == 0) {
2765 $type = self::sanitize_options($postData['type']);
2766 $width = self::sanitize_options($postData['width'], "int");
2767 $optionName = "wcp_dynamic_width_for_".$type;
2768 update_option($optionName, $width);
2769 $response['status'] = 1;
2770 }
2771
2772 echo json_encode($response);
2773 wp_die();
2774
2775 }//end wcp_change_post_width()
2776
2777
2778 /**
2779 * Assign folder to multiple posts, pages, attachments
2780 *
2781 * @since 1.0.0
2782 * @access public
2783 * @return $response
2784 */
2785 public function wcp_change_multiple_post_folder()
2786 {
2787 $response = [];
2788 $response['status'] = 0;
2789 $response['error'] = 0;
2790 $response['data'] = [];
2791 $response['message'] = "";
2792 $postData = filter_input_array(INPUT_POST);
2793 $errorCounter = 0;
2794 if (!isset($postData['post_ids']) || empty($postData['post_ids'])) {
2795 $response['message'] = esc_html__("Your request is not valid", 'folders');
2796 $errorCounter++;
2797 } else if (!isset($postData['folder_id']) || empty($postData['folder_id'])) {
2798 $response['message'] = esc_html__("Your request is not valid", 'folders');
2799 $errorCounter++;
2800 } else if (!isset($postData['type']) || empty($postData['type'])) {
2801 $response['message'] = esc_html__("Your request is not valid", 'folders');
2802 $errorCounter++;
2803 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2804 $response['message'] = esc_html__("Your request is not valid", 'folders');
2805 $errorCounter++;
2806 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
2807 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2808 $errorCounter++;
2809 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
2810 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2811 $errorCounter++;
2812 } else {
2813 $folder_id = self::sanitize_options($postData['folder_id']);
2814 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$folder_id)) {
2815 $response['message'] = esc_html__("Your request is not valid", 'folders');
2816 $errorCounter++;
2817 }
2818 }//end if
2819
2820 if ($errorCounter == 0) {
2821 $folderUndoSettings = [];
2822 $postID = self::sanitize_options($postData['post_ids']);
2823 $postID = trim($postID, ",");
2824 $folderID = self::sanitize_options($postData['folder_id']);
2825 $type = self::sanitize_options($postData['type']);
2826 $postArray = explode(",", $postID);
2827 $status = 0;
2828 if (isset($postData['status'])) {
2829 $status = self::sanitize_options($postData['status']);
2830 }
2831
2832 $status = true;
2833
2834 $taxonomy = "";
2835 if (isset($postData['taxonomy'])) {
2836 $taxonomy = self::sanitize_options($postData['taxonomy']);
2837 }
2838
2839 if (is_array($postArray)) {
2840 $post_type = self::get_custom_post_type($type);
2841 foreach ($postArray as $post) {
2842 $terms = get_the_terms($post, $post_type);
2843 $post_terms = [
2844 'post_id' => $post,
2845 'terms' => $terms,
2846 ];
2847 $folderUndoSettings[] = $post_terms;
2848 if (!empty($terms)) {
2849 foreach ($terms as $term) {
2850 if (!empty($taxonomy) && ($term->term_id == $taxonomy || $term->slug == $taxonomy)) {
2851 wp_remove_object_terms($post, $term->term_id, $post_type);
2852 }
2853 }
2854 }
2855
2856 wp_set_post_terms($post, $folderID, $post_type, $status);
2857 }
2858 }
2859
2860 $response['status'] = 1;
2861 delete_transient("folder_undo_settings");
2862 delete_transient("premio_folders_without_trash");
2863 set_transient("folder_undo_settings", $folderUndoSettings, DAY_IN_SECONDS);
2864 }//end if
2865
2866 echo json_encode($response);
2867 wp_die();
2868
2869 }//end wcp_change_multiple_post_folder()
2870
2871
2872 /**
2873 * Undo folder changes
2874 *
2875 * @since 1.0.0
2876 * @access public
2877 * @return $response
2878 */
2879 public function wcp_undo_folder_changes()
2880 {
2881 $response = [];
2882 $response['status'] = 0;
2883 $response['error'] = 0;
2884 $response['data'] = [];
2885 $response['message'] = "";
2886 $postData = filter_input_array(INPUT_POST);
2887 $errorCounter = 0;
2888 if (!isset($postData['post_type']) || empty($postData['post_type'])) {
2889 $response['message'] = esc_html__("Your request is not valid", 'folders');
2890 $errorCounter++;
2891 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2892 $response['message'] = esc_html__("Your request is not valid", 'folders');
2893 $errorCounter++;
2894 } else {
2895 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$postData['post_type'])) {
2896 $response['message'] = esc_html__("Your request is not valid", 'folders');
2897 $errorCounter++;
2898 }
2899 }
2900
2901 if ($errorCounter == 0) {
2902 $response['status'] = 1;
2903 $folder_undo_settings = get_transient("folder_undo_settings");
2904 $type = self::sanitize_options($postData['post_type']);
2905 $post_type = self::get_custom_post_type($type);
2906 if (!empty($folder_undo_settings) && is_array($folder_undo_settings)) {
2907 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
2908 if ($trash_folders === false) {
2909 $trash_folders = [];
2910 $initial_trash_folders = [];
2911 }
2912
2913 foreach ($folder_undo_settings as $item) {
2914 $terms = get_the_terms($item['post_id'], $post_type);
2915 if (!empty($terms)) {
2916 foreach ($terms as $term) {
2917 wp_remove_object_terms($item['post_id'], $term->term_id, $post_type);
2918 if (isset($trash_folders[$term->term_taxonomy_id])) {
2919 unset($trash_folders[$term->term_taxonomy_id]);
2920 }
2921 }
2922 }
2923
2924 if (!empty($item['terms']) && is_array($item['terms'])) {
2925 foreach ($item['terms'] as $term) {
2926 wp_set_post_terms($item['post_id'], $term->term_id, $post_type, true);
2927 if (isset($trash_folders[$term->term_taxonomy_id])) {
2928 unset($trash_folders[$term->term_taxonomy_id]);
2929 }
2930 }
2931 }
2932 }
2933
2934 if (!empty($terms) && $initial_trash_folders != $trash_folders) {
2935 delete_transient("premio_folders_without_trash");
2936 set_transient("premio_folders_without_trash", $trash_folders, (3 * DAY_IN_SECONDS));
2937 }
2938 }//end if
2939 }//end if
2940
2941 echo json_encode($response);
2942 die;
2943
2944 }//end wcp_undo_folder_changes()
2945
2946
2947 /**
2948 * Change post, page, attachment folder
2949 *
2950 * @since 1.0.0
2951 * @access public
2952 * @return $response
2953 */
2954 public function wcp_change_post_folder()
2955 {
2956 $response = [];
2957 $response['status'] = 0;
2958 $response['error'] = 0;
2959 $response['data'] = [];
2960 $response['message'] = "";
2961 $postData = filter_input_array(INPUT_POST);
2962 $errorCounter = 0;
2963 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
2964 $errorCounter++;
2965 $response['message'] = esc_html__("Your request is not valid", 'folders');
2966 } else if (!isset($postData['folder_id']) || empty($postData['folder_id'])) {
2967 $errorCounter++;
2968 $response['message'] = esc_html__("Your request is not valid", 'folders');
2969 } else if (!isset($postData['type']) || empty($postData['type'])) {
2970 $errorCounter++;
2971 $response['message'] = esc_html__("Your request is not valid", 'folders');
2972 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2973 $response['message'] = esc_html__("Your request is not valid", 'folders');
2974 $errorCounter++;
2975 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
2976 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2977 $errorCounter++;
2978 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
2979 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2980 $errorCounter++;
2981 } else {
2982 $term_id = self::sanitize_options($postData['folder_id']);
2983 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
2984 $response['message'] = esc_html__("Your request is not valid", 'folders');
2985 $errorCounter++;
2986 }
2987 }//end if
2988
2989 if ($errorCounter == 0) {
2990 $postID = self::sanitize_options($postData['post_id']);
2991 $folderID = self::sanitize_options($postData['folder_id']);
2992 $type = self::sanitize_options($postData['type']);
2993 $folder_post_type = self::get_custom_post_type($type);
2994 $status = 0;
2995 if (isset($postData['status'])) {
2996 $status = self::sanitize_options($postData['status']);
2997 }
2998
2999 $status = ($status == 1) ? true : false;
3000 $taxonomy = "";
3001 if (isset($postData['taxonomy'])) {
3002 $taxonomy = self::sanitize_options($postData['taxonomy']);
3003 }
3004
3005 $terms = get_the_terms($postID, $folder_post_type);
3006 if (!empty($terms)) {
3007 foreach ($terms as $term) {
3008 if (!empty($taxonomy) && ($term->term_id == $taxonomy || $term->slug == $taxonomy)) {
3009 wp_remove_object_terms($postID, $term->term_id, $folder_post_type);
3010 }
3011 }
3012 }
3013
3014 wp_set_post_terms($postID, $folderID, $folder_post_type, true);
3015 $response['status'] = 1;
3016 }//end if
3017
3018 echo json_encode($response);
3019 wp_die();
3020
3021 }//end wcp_change_post_folder()
3022
3023
3024 /**
3025 * Mark/Unmark folder
3026 *
3027 * @since 1.0.0
3028 * @access public
3029 * @return $response
3030 */
3031 public function wcp_mark_un_mark_folder()
3032 {
3033 $response = [];
3034 $response['status'] = 0;
3035 $response['error'] = 0;
3036 $response['data'] = [];
3037 $response['message'] = "";
3038 $postData = filter_input_array(INPUT_POST);
3039 $errorCounter = 0;
3040 if (!current_user_can("manage_categories")) {
3041 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
3042 $errorCounter++;
3043 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
3044 $errorCounter++;
3045 $response['message'] = esc_html__("Your request is not valid", 'folders');
3046 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3047 $response['message'] = esc_html__("Your request is not valid", 'folders');
3048 $errorCounter++;
3049 } else {
3050 $term_id = self::sanitize_options($postData['term_id']);
3051 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
3052 $response['message'] = esc_html__("Your request is not valid", 'folders');
3053 $errorCounter++;
3054 }
3055 }
3056
3057 if ($errorCounter == 0) {
3058 $term_id = self::sanitize_options($postData['term_id']);
3059 $status = get_term_meta($term_id, "is_highlighted", true);
3060 if ($status == 1) {
3061 update_term_meta($term_id, "is_highlighted", 0);
3062 $status = 0;
3063 } else {
3064 update_term_meta($term_id, "is_highlighted", 1);
3065 $status = 1;
3066 }
3067
3068 $response['marked'] = $status;
3069 $response['id'] = $postData['term_id'];
3070 $response['status'] = 1;
3071 }
3072
3073 echo json_encode($response);
3074 wp_die();
3075
3076 }//end wcp_mark_un_mark_folder()
3077
3078
3079 /**
3080 * Make folder Sticky
3081 *
3082 * @since 1.0.0
3083 * @access public
3084 * @return $response
3085 */
3086 public function wcp_make_sticky_folder()
3087 {
3088 $response = [];
3089 $response['status'] = 0;
3090 $response['error'] = 0;
3091 $response['data'] = [];
3092 $response['message'] = "";
3093 $postData = filter_input_array(INPUT_POST);
3094 $errorCounter = 0;
3095 if (!current_user_can("manage_categories")) {
3096 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
3097 $errorCounter++;
3098 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
3099 $errorCounter++;
3100 $response['message'] = esc_html__("Your request is not valid", 'folders');
3101 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3102 $response['message'] = esc_html__("Your request is not valid", 'folders');
3103 $errorCounter++;
3104 } else {
3105 $term_id = self::sanitize_options($postData['term_id']);
3106 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
3107 $response['message'] = esc_html__("Your request is not valid", 'folders');
3108 $errorCounter++;
3109 }
3110 }
3111
3112 if ($errorCounter == 0) {
3113 $term_id = self::sanitize_options($postData['term_id']);
3114 $status = get_term_meta($term_id, "is_folder_sticky", true);
3115 if ($status == 1) {
3116 update_term_meta($term_id, "is_folder_sticky", 0);
3117 $status = 0;
3118 } else {
3119 update_term_meta($term_id, "is_folder_sticky", 1);
3120 $status = 1;
3121 }
3122
3123 $response['is_folder_sticky'] = $status;
3124 $response['id'] = $postData['term_id'];
3125 $response['status'] = 1;
3126 }
3127
3128 echo json_encode($response);
3129 wp_die();
3130
3131 }//end wcp_make_sticky_folder()
3132
3133
3134 /**
3135 * Save folder order
3136 *
3137 * @since 1.0.0
3138 * @access public
3139 * @return $response
3140 */
3141 public function wcp_save_folder_order()
3142 {
3143 $response = [];
3144 $response['status'] = 0;
3145 $response['error'] = 0;
3146 $response['data'] = [];
3147 $response['message'] = "";
3148 $postData = filter_input_array(INPUT_POST);
3149 $errorCounter = 0;
3150 if (!current_user_can("manage_categories")) {
3151 $response['message'] = esc_html__("You have not permission to update folder order", 'folders');
3152 $errorCounter++;
3153 } else if (!isset($postData['term_ids']) || empty($postData['term_ids'])) {
3154 $errorCounter++;
3155 $response['message'] = esc_html__("Your request is not valid", 'folders');
3156 } else if (!isset($postData['type']) || empty($postData['type'])) {
3157 $errorCounter++;
3158 $response['message'] = esc_html__("Your request is not valid", 'folders');
3159 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3160 $response['message'] = esc_html__("Your request is not valid", 'folders');
3161 $errorCounter++;
3162 } else {
3163 $type = self::sanitize_options($postData['type']);
3164 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
3165 $response['message'] = esc_html__("Your request is not valid", 'folders');
3166 $errorCounter++;
3167 }
3168 }
3169
3170 if ($errorCounter == 0) {
3171 $termIds = self::sanitize_options(($postData['term_ids']));
3172 $type = self::sanitize_options($postData['type']);
3173 $termIds = trim($termIds, ",");
3174 $termArray = explode(",", $termIds);
3175 $order = 1;
3176 foreach ($termArray as $term) {
3177 if (!empty($term)) {
3178 update_term_meta($term, "wcp_custom_order", $order);
3179 $order++;
3180 }
3181 }
3182
3183 $term_id = self::sanitize_options($postData['term_id']);
3184 $parent_id = self::sanitize_options($postData['parent_id']);
3185 $type = self::sanitize_options($postData['type']);
3186 $folder_type = self::get_custom_post_type($type);
3187 wp_update_term(
3188 $term_id,
3189 $folder_type,
3190 ['parent' => $parent_id]
3191 );
3192
3193 if ($parent_id != "#" || !empty($parent_id)) {
3194 update_term_meta($parent_id, "is_active", 1);
3195 }
3196
3197 $response['status'] = 1;
3198 $folder_type = self::get_custom_post_type($type);
3199 // Free/Pro Class name change
3200 $response['options'] = WCP_Tree::get_option_data_for_select($folder_type);
3201 }//end if
3202
3203 echo json_encode($response);
3204 wp_die();
3205
3206 }//end wcp_save_folder_order()
3207
3208
3209 /**
3210 * Make folder State open/closed
3211 *
3212 * @since 1.0.0
3213 * @access public
3214 * @return $response
3215 */
3216 public function save_wcp_folder_state()
3217 {
3218 $response = [];
3219 $response['status'] = 0;
3220 $response['error'] = 0;
3221 $response['data'] = [];
3222 $response['message'] = "";
3223 $postData = filter_input_array(INPUT_POST);
3224 $errorCounter = 0;
3225 if (!current_user_can("manage_categories")) {
3226 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
3227 $errorCounter++;
3228 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
3229 $response['message'] = esc_html__("Your request is not valid", 'folders');
3230 $errorCounter++;
3231 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3232 $response['message'] = esc_html__("Unable to create folder, Your request is not valid", 'folders');
3233 $errorCounter++;
3234 } else {
3235 $term_id = self::sanitize_options($postData['term_id']);
3236 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
3237 $response['message'] = esc_html__("Your request is not valid", 'folders');
3238 $errorCounter++;
3239 }
3240 }
3241
3242 if ($errorCounter == 0) {
3243 $response['status'] = 1;
3244 $term_id = self::sanitize_options($postData['term_id']);
3245 $is_active = isset($postData['is_active']) ? $postData['is_active'] : 0;
3246 $is_active = self::sanitize_options($is_active);
3247 if ($is_active == 1) {
3248 update_term_meta($term_id, "is_active", 1);
3249 } else {
3250 update_term_meta($term_id, "is_active", 0);
3251 }
3252 }
3253
3254 echo json_encode($response);
3255 wp_die();
3256
3257 }//end save_wcp_folder_state()
3258
3259
3260 /**
3261 * Save parent folder information with order
3262 *
3263 * @since 1.0.0
3264 * @access public
3265 * @return $response
3266 */
3267 public function wcp_update_parent_information()
3268 {
3269 $response = [];
3270 $response['status'] = 0;
3271 $response['error'] = 0;
3272 $response['data'] = [];
3273 $response['message'] = "";
3274 $postData = filter_input_array(INPUT_POST);
3275 $errorCounter = 0;
3276 if (!current_user_can("manage_categories")) {
3277 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
3278 $errorCounter++;
3279 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
3280 $response['message'] = esc_html__("Your request is not valid", 'folders');
3281 $errorCounter++;
3282 } else if (!isset($postData['type']) || empty($postData['type'])) {
3283 $response['message'] = esc_html__("Your request is not valid", 'folders');
3284 $errorCounter++;
3285 } else if (!isset($postData['parent_id'])) {
3286 $response['message'] = esc_html__("Your request is not valid", 'folders');
3287 $errorCounter++;
3288 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3289 $response['message'] = esc_html__("Your request is not valid", 'folders');
3290 $errorCounter++;
3291 } else {
3292 $term_id = self::sanitize_options($postData['term_id']);
3293 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
3294 $response['message'] = esc_html__("Your request is not valid", 'folders');
3295 $errorCounter++;
3296 }
3297 }//end if
3298
3299 if ($errorCounter == 0) {
3300 $term_id = self::sanitize_options($postData['term_id']);
3301 $parent_id = self::sanitize_options($postData['parent_id']);
3302 $type = self::sanitize_options($postData['type']);
3303 $folder_type = self::get_custom_post_type($type);
3304 wp_update_term(
3305 $term_id,
3306 $folder_type,
3307 ['parent' => $parent_id]
3308 );
3309 update_term_meta($parent_id, "is_active", 1);
3310 $response['status'] = 1;
3311 }
3312
3313 echo json_encode($response);
3314 wp_die();
3315
3316 }//end wcp_update_parent_information()
3317
3318
3319 /**
3320 * Save parent folder data
3321 *
3322 * @since 1.0.0
3323 * @access public
3324 * @return $response
3325 */
3326 public function wcp_save_parent_data()
3327 {
3328 $response = [];
3329 $response['status'] = 0;
3330 $response['error'] = 0;
3331 $response['data'] = [];
3332 $response['message'] = "";
3333 $postData = filter_input_array(INPUT_POST);
3334 $errorCounter = 0;
3335 if (!isset($postData['type']) || empty($postData['type'])) {
3336 $response['message'] = esc_html__("Your request is not valid", 'folders');
3337 $errorCounter++;
3338 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3339 $response['message'] = esc_html__("Your request is not valid", 'folders');
3340 $errorCounter++;
3341 } else if (!current_user_can("manage_categories")) {
3342 $response['message'] = esc_html__("Your request is not valid", 'folders');
3343 $errorCounter++;
3344 } else {
3345 $type = self::sanitize_options($postData['type']);
3346 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
3347 $response['message'] = esc_html__("Your request is not valid", 'folders');
3348 $errorCounter++;
3349 }
3350 }
3351
3352 if ($errorCounter == 0) {
3353 $type = self::sanitize_options($postData['type']);
3354 $optionName = $type."_parent_status";
3355 $response['status'] = 1;
3356 $is_active = isset($postData['is_active']) ? $postData['is_active'] : 0;
3357 $is_active = self::sanitize_options($is_active);
3358 if ($is_active == 1) {
3359 update_option($optionName, 1);
3360 } else {
3361 update_option($optionName, 0);
3362 }
3363 }
3364
3365 echo json_encode($response);
3366 wp_die();
3367
3368 }//end wcp_save_parent_data()
3369
3370
3371 /**
3372 * Remove multiple folders
3373 *
3374 * @since 1.0.0
3375 * @access public
3376 * @return $response
3377 */
3378 public function remove_muliple_folder()
3379 {
3380 $response = [];
3381 $response['status'] = 0;
3382 $response['error'] = 0;
3383 $response['data'] = [];
3384 $response['message'] = "";
3385 $postData = filter_input_array(INPUT_POST);
3386 $errorCounter = 0;
3387 $error = "";
3388 if (!current_user_can("manage_categories")) {
3389 $error = esc_html__("You have not permission to remove folder", 'folders');
3390 $errorCounter++;
3391 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
3392 $error = esc_html__("Your request is not valid", 'folders');
3393 $errorCounter++;
3394 } else if (!isset($postData['type']) || empty($postData['type'])) {
3395 $error = esc_html__("Your request is not valid", 'folders');
3396 $errorCounter++;
3397 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3398 $response['message'] = esc_html__("Your request is not valid", 'folders');
3399 $errorCounter++;
3400 } else {
3401 $type = self::sanitize_options($postData['type']);
3402 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
3403 $error = esc_html__("Your request is not valid", 'folders');
3404 $errorCounter++;
3405 }
3406 }
3407
3408 if ($errorCounter == 0) {
3409 $term_id = self::sanitize_options($postData['term_id']);
3410 $type = self::sanitize_options($postData['type']);
3411 $response['term_ids'] = [];
3412 if (!empty($term_id)) {
3413 $term_id = trim($term_id, ",");
3414 $term_ids = explode(",", $term_id);
3415 if (is_array($term_ids) && count($term_ids) > 0) {
3416 foreach ($term_ids as $term) {
3417 self::remove_folder_child_items($term, $type);
3418 }
3419
3420 $response['term_ids'] = $term_ids;
3421 }
3422 }
3423
3424 $is_active = 1;
3425 $folders = -1;
3426 $response['status'] = 1;
3427 $response['folders'] = $folders;
3428 $response['is_key_active'] = $is_active;
3429 } else {
3430 $response['error'] = 1;
3431 $response['message'] = $error;
3432 }//end if
3433
3434 echo json_encode($response);
3435 wp_die();
3436
3437 }//end remove_muliple_folder()
3438
3439
3440 /**
3441 * Remove folder
3442 *
3443 * @since 1.0.0
3444 * @access public
3445 * @return $response
3446 */
3447 public function wcp_remove_folder()
3448 {
3449 $response = [];
3450 $response['status'] = 0;
3451 $response['error'] = 0;
3452 $response['data'] = [];
3453 $response['message'] = "";
3454 $postData = filter_input_array(INPUT_POST);
3455 $errorCounter = 0;
3456 if (!current_user_can("manage_categories")) {
3457 $error = esc_html__("You have not permission to remove folder", 'folders');
3458 $errorCounter++;
3459 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
3460 $error = esc_html__("Your request is not valid", 'folders');
3461 $errorCounter++;
3462 } else if (!isset($postData['type']) || empty($postData['type'])) {
3463 $error = esc_html__("Your request is not valid", 'folders');
3464 $errorCounter++;
3465 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3466 $error = esc_html__("Unable to delete folder, Your request is not valid", 'folders');
3467 $errorCounter++;
3468 } else {
3469 $term_id = self::sanitize_options($postData['term_id']);
3470 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
3471 $error = esc_html__("Unable to delete folder, Your request is not valid", 'folders');
3472 $errorCounter++;
3473 }
3474 }
3475
3476 if ($errorCounter == 0) {
3477 $term_id = self::sanitize_options($postData['term_id']);
3478 $type = self::sanitize_options($postData['type']);
3479 self::remove_folder_child_items($term_id, $type);
3480 $response['status'] = 1;
3481 $is_active = 1;
3482 $folders = -1;
3483 $response['folders'] = $folders;
3484 $response['term_id'] = $term_id;
3485 $response['is_key_active'] = $is_active;
3486 } else {
3487 $response['error'] = 1;
3488 $response['message'] = $error;
3489 }
3490
3491 echo json_encode($response);
3492 wp_die();
3493
3494 }//end wcp_remove_folder()
3495
3496
3497 /**
3498 * Remove folders for page, post, attachment
3499 *
3500 * @since 1.0.0
3501 * @access public
3502 * @return $response
3503 */
3504 public function remove_folder_child_items($term_id, $post_type)
3505 {
3506 $folder_type = self::get_custom_post_type($post_type);
3507 $terms = get_terms(
3508 $folder_type,
3509 [
3510 'hide_empty' => false,
3511 'parent' => $term_id,
3512 ]
3513 );
3514
3515 if (!empty($terms)) {
3516 foreach ($terms as $term) {
3517 self::remove_folder_child_items($term->term_id, $post_type);
3518 }
3519
3520 wp_delete_term($term_id, $folder_type);
3521 } else {
3522 wp_delete_term($term_id, $folder_type);
3523 }
3524
3525 }//end remove_folder_child_items()
3526
3527
3528 /**
3529 * Update Folder
3530 *
3531 * @since 1.0.0
3532 * @access public
3533 * @return $response
3534 */
3535 public function wcp_update_folder()
3536 {
3537 $response = [];
3538 $response['status'] = 0;
3539 $response['error'] = 0;
3540 $response['data'] = [];
3541 $response['message'] = "";
3542 $postData = filter_input_array(INPUT_POST);
3543 $errorCounter = 0;
3544 if (!current_user_can("manage_categories")) {
3545 $error = esc_html__("You have not permission to update folder", 'folders');
3546 $errorCounter++;
3547 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
3548 $error = esc_html__("Unable to rename folder, Your request is not valid", 'folders');
3549 $errorCounter++;
3550 } else if (!isset($postData['name']) || empty($postData['name'])) {
3551 $error = esc_html__("Folder name can no be empty", 'folders');
3552 $errorCounter++;
3553 } else if (!isset($postData['type']) || empty($postData['type'])) {
3554 $error = esc_html__("Your request is not valid", 'folders');
3555 $errorCounter++;
3556 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
3557 $error = esc_html__("Unable to rename folder, Your request is not valid", 'folders');
3558 $errorCounter++;
3559 } else {
3560 $term_id = self::sanitize_options($postData['term_id']);
3561 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
3562 $error = esc_html__("Unable to rename folder, Your request is not valid", 'folders');
3563 $errorCounter++;
3564 }
3565 }//end if
3566
3567 if ($errorCounter == 0) {
3568 $type = self::sanitize_options($postData['type']);
3569 $folder_type = self::get_custom_post_type($type);
3570 $name = self::sanitize_options($postData['name']);
3571 $term_id = self::sanitize_options($postData['term_id']);
3572 $result = wp_update_term(
3573 $term_id,
3574 $folder_type,
3575 ['name' => $name]
3576 );
3577 if (!empty($result)) {
3578 $term_nonce = wp_create_nonce('wcp_folder_term_'.$result['term_id']);
3579 $response['id'] = $result['term_id'];
3580 $response['slug'] = $result['slug'];
3581 $response['status'] = 1;
3582 $response['term_title'] = $postData['name'];
3583 $response['nonce'] = $term_nonce;
3584 } else {
3585 $response['message'] = esc_html__("Unable to rename folder", 'folders');
3586 }
3587 } else {
3588 $response['error'] = 1;
3589 $response['message'] = $error;
3590 }//end if
3591
3592 echo json_encode($response);
3593 wp_die();
3594
3595 }//end wcp_update_folder()
3596
3597
3598 /**
3599 * Create slug from string
3600 *
3601 * @since 1.0.0
3602 * @access public
3603 * @return $slug
3604 */
3605 public function create_slug_from_string($str)
3606 {
3607 $a = [
3608 'À',
3609 'Á',
3610 'Â',
3611 'Ã',
3612 'Ä',
3613 '�
3614 ',
3615 'Æ',
3616 'Ç',
3617 'È',
3618 'É',
3619 'Ê',
3620 'Ë',
3621 'Ì',
3622 'Í',
3623 'Î',
3624 'Ï',
3625 'Ð',
3626 'Ñ',
3627 'Ò',
3628 'Ó',
3629 'Ô',
3630 'Õ',
3631 'Ö',
3632 'Ø',
3633 'Ù',
3634 'Ú',
3635 'Û',
3636 'Ü',
3637 'Ý',
3638 'ß',
3639 'à',
3640 'á',
3641 'â',
3642 'ã',
3643 'ä',
3644 'å',
3645 'æ',
3646 'ç',
3647 'è',
3648 'é',
3649 'ê',
3650 'ë',
3651 'ì',
3652 'í',
3653 'î',
3654 'ï',
3655 'ñ',
3656 'ò',
3657 'ó',
3658 'ô',
3659 'õ',
3660 'ö',
3661 'ø',
3662 'ù',
3663 'ú',
3664 'û',
3665 'ü',
3666 'ý',
3667 'ÿ',
3668 'A',
3669 'a',
3670 'A',
3671 'a',
3672 'A',
3673 'a',
3674 'C',
3675 'c',
3676 'C',
3677 'c',
3678 'C',
3679 'c',
3680 'C',
3681 'c',
3682 'D',
3683 'd',
3684 'Ð',
3685 'd',
3686 'E',
3687 'e',
3688 'E',
3689 'e',
3690 'E',
3691 'e',
3692 'E',
3693 'e',
3694 'E',
3695 'e',
3696 'G',
3697 'g',
3698 'G',
3699 'g',
3700 'G',
3701 'g',
3702 'G',
3703 'g',
3704 'H',
3705 'h',
3706 'H',
3707 'h',
3708 'I',
3709 'i',
3710 'I',
3711 'i',
3712 'I',
3713 'i',
3714 'I',
3715 'i',
3716 'I',
3717 'i',
3718 '?',
3719 '?',
3720 'J',
3721 'j',
3722 'K',
3723 'k',
3724 'L',
3725 'l',
3726 'L',
3727 'l',
3728 'L',
3729 'l',
3730 '?',
3731 '?',
3732 'L',
3733 'l',
3734 'N',
3735 'n',
3736 'N',
3737 'n',
3738 'N',
3739 'n',
3740 '?',
3741 'O',
3742 'o',
3743 'O',
3744 'o',
3745 'O',
3746 'o',
3747 'Œ',
3748 'œ',
3749 'R',
3750 'r',
3751 'R',
3752 'r',
3753 'R',
3754 'r',
3755 'S',
3756 's',
3757 'S',
3758 's',
3759 'S',
3760 's',
3761 'Š',
3762 'š',
3763 'T',
3764 't',
3765 'T',
3766 't',
3767 'T',
3768 't',
3769 'U',
3770 'u',
3771 'U',
3772 'u',
3773 'U',
3774 'u',
3775 'U',
3776 'u',
3777 'U',
3778 'u',
3779 'U',
3780 'u',
3781 'W',
3782 'w',
3783 'Y',
3784 'y',
3785 'Ÿ',
3786 'Z',
3787 'z',
3788 'Z',
3789 'z',
3790 'Ž',
3791 'ž',
3792 '?',
3793 'ƒ',
3794 'O',
3795 'o',
3796 'U',
3797 'u',
3798 'A',
3799 'a',
3800 'I',
3801 'i',
3802 'O',
3803 'o',
3804 'U',
3805 'u',
3806 'U',
3807 'u',
3808 'U',
3809 'u',
3810 'U',
3811 'u',
3812 'U',
3813 'u',
3814 '?',
3815 '?',
3816 '?',
3817 '?',
3818 '?',
3819 '?',
3820 ];
3821 $b = [
3822 'A',
3823 'A',
3824 'A',
3825 'A',
3826 'A',
3827 'A',
3828 'AE',
3829 'C',
3830 'E',
3831 'E',
3832 'E',
3833 'E',
3834 'I',
3835 'I',
3836 'I',
3837 'I',
3838 'D',
3839 'N',
3840 'O',
3841 'O',
3842 'O',
3843 'O',
3844 'O',
3845 'O',
3846 'U',
3847 'U',
3848 'U',
3849 'U',
3850 'Y',
3851 's',
3852 'a',
3853 'a',
3854 'a',
3855 'a',
3856 'a',
3857 'a',
3858 'ae',
3859 'c',
3860 'e',
3861 'e',
3862 'e',
3863 'e',
3864 'i',
3865 'i',
3866 'i',
3867 'i',
3868 'n',
3869 'o',
3870 'o',
3871 'o',
3872 'o',
3873 'o',
3874 'o',
3875 'u',
3876 'u',
3877 'u',
3878 'u',
3879 'y',
3880 'y',
3881 'A',
3882 'a',
3883 'A',
3884 'a',
3885 'A',
3886 'a',
3887 'C',
3888 'c',
3889 'C',
3890 'c',
3891 'C',
3892 'c',
3893 'C',
3894 'c',
3895 'D',
3896 'd',
3897 'D',
3898 'd',
3899 'E',
3900 'e',
3901 'E',
3902 'e',
3903 'E',
3904 'e',
3905 'E',
3906 'e',
3907 'E',
3908 'e',
3909 'G',
3910 'g',
3911 'G',
3912 'g',
3913 'G',
3914 'g',
3915 'G',
3916 'g',
3917 'H',
3918 'h',
3919 'H',
3920 'h',
3921 'I',
3922 'i',
3923 'I',
3924 'i',
3925 'I',
3926 'i',
3927 'I',
3928 'i',
3929 'I',
3930 'i',
3931 'IJ',
3932 'ij',
3933 'J',
3934 'j',
3935 'K',
3936 'k',
3937 'L',
3938 'l',
3939 'L',
3940 'l',
3941 'L',
3942 'l',
3943 'L',
3944 'l',
3945 'l',
3946 'l',
3947 'N',
3948 'n',
3949 'N',
3950 'n',
3951 'N',
3952 'n',
3953 'n',
3954 'O',
3955 'o',
3956 'O',
3957 'o',
3958 'O',
3959 'o',
3960 'OE',
3961 'oe',
3962 'R',
3963 'r',
3964 'R',
3965 'r',
3966 'R',
3967 'r',
3968 'S',
3969 's',
3970 'S',
3971 's',
3972 'S',
3973 's',
3974 'S',
3975 's',
3976 'T',
3977 't',
3978 'T',
3979 't',
3980 'T',
3981 't',
3982 'U',
3983 'u',
3984 'U',
3985 'u',
3986 'U',
3987 'u',
3988 'U',
3989 'u',
3990 'U',
3991 'u',
3992 'U',
3993 'u',
3994 'W',
3995 'w',
3996 'Y',
3997 'y',
3998 'Y',
3999 'Z',
4000 'z',
4001 'Z',
4002 'z',
4003 'Z',
4004 'z',
4005 's',
4006 'f',
4007 'O',
4008 'o',
4009 'U',
4010 'u',
4011 'A',
4012 'a',
4013 'I',
4014 'i',
4015 'O',
4016 'o',
4017 'U',
4018 'u',
4019 'U',
4020 'u',
4021 'U',
4022 'u',
4023 'U',
4024 'u',
4025 'U',
4026 'u',
4027 'A',
4028 'a',
4029 'AE',
4030 'ae',
4031 'O',
4032 'o',
4033 ];
4034 return strtolower(preg_replace(['/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'], ['', '-', ''], str_replace($a, $b, $str)));
4035
4036 }//end create_slug_from_string()
4037
4038
4039 /**
4040 * Sanitize input options
4041 *
4042 * @since 1.0.0
4043 * @access public
4044 * @return $value
4045 */
4046 public static function sanitize_options($value, $type="")
4047 {
4048 $value = stripslashes($value);
4049 if ($type == "int") {
4050 $value = filter_var($value, FILTER_SANITIZE_NUMBER_INT);
4051 } else if ($type == "email") {
4052 $value = filter_var($value, FILTER_SANITIZE_EMAIL);
4053 } else {
4054 $value = sanitize_text_field($value);
4055 }
4056
4057 return $value;
4058
4059 }//end sanitize_options()
4060
4061
4062 /**
4063 * Add new folder
4064 *
4065 * @since 1.0.0
4066 * @access public
4067 * @return $response
4068 */
4069 public function wcp_add_new_folder()
4070 {
4071 $response = [];
4072 $response['status'] = 0;
4073 $response['error'] = 0;
4074 $response['login'] = 1;
4075 $response['data'] = [];
4076 $response['message'] = "";
4077 $response['message2'] = "";
4078 $postData = filter_input_array(INPUT_POST);
4079 $errorCounter = 0;
4080 $error = esc_html__("Your request is not valid", 'folders');
4081 if (!current_user_can("manage_categories")) {
4082 $error = esc_html__("You have not permission to add folder", 'folders');
4083 $errorCounter++;
4084 } else if (!isset($postData['name']) || empty($postData['name'])) {
4085 $error = esc_html__("Folder name can no be empty", 'folders');
4086 $errorCounter++;
4087 } else if (!isset($postData['type']) || empty($postData['type'])) {
4088 $error = esc_html__("Your request is not valid", 'folders');
4089 $errorCounter++;
4090 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
4091 $response['login'] = 0;
4092 $error = esc_html__("Unable to create folder, Your request is not valid", 'folders');
4093 $errorCounter++;
4094 } else {
4095 $type = self::sanitize_options($postData['type']);
4096 if (!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
4097 $response['login'] = 0;
4098 $error = esc_html__("Unable to create folder, Your request is not valid", 'folders');
4099 $errorCounter++;
4100 }
4101 }//end if
4102
4103 if ($errorCounter == 0) {
4104 $parent = isset($postData['parent_id']) && !empty($postData['parent_id']) ? $postData['parent_id'] : 0;
4105 $parent = self::sanitize_options($parent);
4106 $type = self::sanitize_options($postData['type']);
4107 $folder_type = self::get_custom_post_type($type);
4108 $term_name = self::sanitize_options($postData['name']);
4109 $term = term_exists($term_name, $folder_type, $parent);
4110 $user_id = get_current_user_id();
4111 if (!empty($term) && isset($term['term_id']) && !empty($term['term_id'])) {
4112 $term_user = get_term_meta($term['term_id'], "created_by", true);
4113 if ($term_user == $user_id) {
4114 $response['error'] = 1;
4115 $response['message'] = esc_html__("Folder name already exists", 'folders');
4116 echo json_encode($response);
4117 wp_die();
4118 }
4119 }
4120
4121 $folders = $postData['name'];
4122 $folders = explode(",", $folders);
4123 $foldersArray = [];
4124 //$order = isset($postData['order']) ? $postData['order'] : 0;
4125 //$order = self::sanitize_options($order);
4126
4127 $is_active = 1;
4128 $created_folders = 0;
4129
4130 foreach ($folders as $key => $folder) {
4131 $term = term_exists($folder, $folder_type, $parent);
4132 if (!empty($term) && isset($term['term_id']) && !empty($term['term_id'])) {
4133 $term_user = get_term_meta($term['term_id'], "created_by", true);
4134 if ($term_user == $user_id) {
4135 continue;
4136 }
4137 }
4138
4139 $folder = trim($folder);
4140 $slug = self::create_slug_from_string($folder)."-".time()."-".$user_id;
4141
4142 $result = wp_insert_term(
4143 urldecode($folder),
4144 // the term
4145 $folder_type,
4146 // the taxonomy
4147 [
4148 'parent' => $parent,
4149 'slug' => $slug,
4150 ]
4151 );
4152
4153 if (!empty($result)) {
4154 $created_folders++;
4155 $response['id'] = $result['term_id'];
4156 $response['status'] = 1;
4157 $term = get_term($result['term_id'], $folder_type);
4158 $order = $key+1;
4159 $term_nonce = wp_create_nonce('wcp_folder_term_'.$term->term_id);
4160
4161 $folder_item = [];
4162 $folder_item['parent_id'] = $parent;
4163 $folder_item['slug'] = $term->slug;
4164 $folder_item['nonce'] = $term_nonce;
4165 $folder_item['term_id'] = $result['term_id'];
4166 $folder_item['title'] = $folder;
4167 $folder_item['parent_id'] = empty($postData['parent_id']) ? "0" : $postData['parent_id'];
4168 $folder_item['is_sticky'] = 0;
4169 $folder_item['is_high'] = 0;
4170 $folder_item['is_locked'] = 0;
4171 $folder_item['folder_count'] = 0;
4172
4173 add_term_meta($result['term_id'], "created_by", $user_id);
4174
4175 update_term_meta($result['term_id'], "wcp_custom_order", $order);
4176 if ($parent != 0) {
4177 update_term_meta($parent, "is_active", 1);
4178 }
4179
4180 if (isset($postData['is_duplicate']) && $postData['is_duplicate'] == true) {
4181 if (isset($postData['duplicate_from']) && !empty($postData['duplicate_from'])) {
4182 $term_id = $postData['duplicate_from'];
4183
4184 $term_data = get_term($term_id, $folder_type);
4185 if (!empty($term_data)) {
4186 $is_sticky = get_term_meta($term_id, "is_folder_sticky", true);
4187
4188 if ($is_sticky == 1) {
4189 add_term_meta($term->term_id, "is_folder_sticky", 1);
4190 $folder_item['is_sticky'] = 1;
4191 }
4192
4193 $is_locked = get_term_meta($term_id, "is_locked", true);
4194 if ($is_locked == 1) {
4195 add_term_meta($term->term_id, "is_locked", 1);
4196 $folder_item['is_locked'] = 1;
4197 }
4198
4199 $status = get_term_meta($term_id, "is_highlighted", true);
4200 if ($status == 1) {
4201 add_term_meta($term->term_id, "is_highlighted", 1);
4202 $folder_item['is_high'] = 1;
4203 }
4204
4205 $postArray = get_posts(
4206 [
4207 'posts_per_page' => -1,
4208 'post_type' => $type,
4209 'tax_query' => [
4210 [
4211 'taxonomy' => $folder_type,
4212 'field' => 'term_id',
4213 'terms' => $term_id,
4214 ],
4215 ],
4216 ]
4217 );
4218 if (!empty($postArray)) {
4219 foreach ($postArray as $p) {
4220 wp_set_post_terms($p->ID, $term->term_id, $folder_type, true);
4221 }
4222
4223 $folder_item['folder_count'] = count($postArray);
4224 }
4225 }//end if
4226 }//end if
4227 }//end if
4228
4229 $foldersArray[] = $folder_item;
4230 }//end if
4231
4232 $folders = $postData['folders'];
4233 if(is_array($folders) && count($folders) > 0) {
4234 foreach($folders as $folder) {
4235 $order++;
4236 update_term_meta($folder, "wcp_custom_order", $order);
4237 }
4238 }
4239
4240 if (!empty($foldersArray)) {
4241 $response['is_key_active'] = $is_active;
4242 $response['folders'] = $created_folders;
4243 $response['parent_id'] = empty($parent) ? "#" : $parent;
4244
4245 $response['status'] = 1;
4246 $response['data'] = $foldersArray;
4247 }
4248 }//end foreach
4249 } else {
4250 $response['error'] = 1;
4251 $response['message'] = $error;
4252 }//end if
4253
4254 echo json_encode($response);
4255 wp_die();
4256
4257 }//end wcp_add_new_folder()
4258
4259
4260 /**
4261 * Check is folder active for post, page, attachment
4262 *
4263 * @since 1.0.0
4264 * @access public
4265 * @return $post_type
4266 */
4267 public function is_for_this_post_type($post_type)
4268 {
4269 $post_types = get_option('folders_settings');
4270 $post_types = is_array($post_types) ? $post_types : [];
4271 return in_array($post_type, $post_types);
4272
4273 }//end is_for_this_post_type()
4274
4275
4276 /**
4277 * Check is folder active for current screen
4278 *
4279 * @since 1.0.0
4280 * @access public
4281 * @return $status
4282 */
4283 public function is_active_for_screen()
4284 {
4285 global $typenow, $current_screen;
4286
4287 $postData = filter_input_array(INPUT_POST);
4288
4289 global $current_screen;
4290
4291 if (self::is_for_this_post_type($typenow) && ('edit' == $current_screen->base || 'upload' == $current_screen->base)) {
4292 return true;
4293 }
4294
4295 $post_types = get_option('folders_settings');
4296 $post_types = is_array($post_types) ? $post_types : [];
4297
4298 if (empty($typenow) && (isset($current_screen->base) && 'upload' == $current_screen->base)) {
4299 $typenow = "attachment";
4300 if (self::is_for_this_post_type($typenow)) {
4301 return true;
4302 }
4303 }
4304
4305 return false;
4306
4307 }//end is_active_for_screen()
4308
4309
4310 /**
4311 * Check is post update screen
4312 *
4313 * @since 1.0.0
4314 * @access public
4315 * @return $status
4316 */
4317 public function is_add_update_screen()
4318 {
4319 global $current_screen;
4320 $current_type = $current_screen->base;
4321 $action = $current_screen->action;
4322 $post_types = get_option('folders_settings');
4323 $post_types = is_array($post_types) ? $post_types : [];
4324 global $typenow;
4325 if (in_array($current_type, $post_types) && in_array($action, ["add", ""])) {
4326 $license_data = self::get_license_key_data();
4327
4328 $is_active = 1;
4329 $folders = -1;
4330 $response['folders'] = $folders;
4331 $response['is_key_active'] = $is_active;
4332 }
4333
4334 }//end is_add_update_screen()
4335
4336
4337 /**
4338 * Get folder type for page, post, attachment
4339 *
4340 * @since 1.0.0
4341 * @access public
4342 * @return $status
4343 */
4344 public static function get_custom_post_type($post_type)
4345 {
4346 if ($post_type == "post") {
4347 return "post_folder";
4348 } else if ($post_type == "page") {
4349 return "folder";
4350 } else if ($post_type == "attachment") {
4351 return "media_folder";
4352 }
4353
4354 return $post_type.'_folder';
4355
4356 }//end get_custom_post_type()
4357
4358
4359 /**
4360 * Add folders data to footer
4361 *
4362 * @since 1.0.0
4363 * @access public
4364 * @return $html
4365 */
4366 public function admin_footer()
4367 {
4368 if (self::is_active_for_screen()) {
4369 global $typenow;
4370
4371 self::set_default_values_if_not_exists();
4372
4373 $ttpsts = self::get_ttlpst($typenow);
4374
4375 $ttemp = self::get_tempt_posts($typenow);
4376
4377 $folder_type = self::get_custom_post_type($typenow);
4378 // Do not change: Free/Pro Class name change
4379 $tree_data = WCP_Tree::get_full_tree_data($folder_type);
4380 $terms_data = $tree_data['string'];
4381 $sticky_string = $tree_data['sticky_string'];
4382 $terms_html = WCP_Tree::get_option_data_for_select($folder_type);
4383 $form_html = WCP_Forms::get_form_html($terms_html);
4384 include_once dirname(dirname(__FILE__)).WCP_DS."/templates".WCP_DS."admin".WCP_DS."admin-content.php";
4385 }
4386
4387 global $pagenow;
4388 if ('plugins.php' !== $pagenow) {
4389 } else {
4390 if (current_user_can('manage_options')) {
4391 include_once dirname(dirname(__FILE__)).WCP_DS."/templates".WCP_DS."admin".WCP_DS."folder-deactivate-form.php";
4392 }
4393 }
4394
4395 }//end admin_footer()
4396
4397
4398 /**
4399 * Get total posts
4400 *
4401 * @since 1.0.0
4402 * @access public
4403 * @return $item_count
4404 */
4405 public function get_ttlpst($post_type="")
4406 {
4407 global $typenow;
4408 if (empty($post_type)) {
4409 $post_type = $typenow;
4410 }
4411 $item_count = null;
4412 if(has_filter("premio_folder_all_categorized_items")) {
4413 $item_count = apply_filters("premio_folder_all_categorized_items", $post_type);
4414 }
4415 if($item_count === null) {
4416 if ($post_type == "attachment") {
4417 global $wpdb;
4418
4419 $select = "SELECT COUNT(ID) FROM ".$wpdb->posts." as P ";
4420
4421 $where = ["post_type = 'attachment' "];
4422 $where[] = "(post_status = 'inherit' OR post_status = 'private')";
4423
4424 $join = apply_filters( 'folders_count_join_query', "" );
4425 $where = apply_filters( 'folders_count_where_query', $where );
4426
4427 $query = $select . $join . " WHERE ".implode( ' AND ', $where );
4428
4429 $item_count = $wpdb->get_var($query);
4430 } else {
4431 $item_count = wp_count_posts($post_type)->publish + wp_count_posts($post_type)->draft + wp_count_posts($post_type)->future + wp_count_posts($post_type)->private + wp_count_posts($post_type)->pending;
4432 }
4433 }
4434 return $item_count;
4435 }//end get_ttlpst()
4436
4437 /**
4438 * Condition for Media hooks for Elementor, BuddyPress
4439 *
4440 * @since 2.9
4441 * @access public
4442 */
4443 public function folders_count_where_query($where) {
4444 global $wpdb;
4445 if(class_exists( 'Better_Messages' )) {
4446 $where[] = " BMPM.post_id IS NULL ";
4447 }
4448 if(class_exists( 'buddypress' )) {
4449 $where[] = " bb_mt1.post_id IS NULL ";
4450 $where[] = " bb_mt2.post_id IS NULL ";
4451 $where[] = " bb_mt3.post_id IS NULL ";
4452 }
4453 if ( function_exists( '_is_elementor_installed' ) ) {
4454 $where[] = " ELPM.post_id IS NULL ";
4455 }
4456 if(class_exists("Web_Stories_Compatibility")) {
4457 $query = "SELECT t.term_id
4458 FROM ".$wpdb->terms." AS t
4459 INNER JOIN ".$wpdb->term_taxonomy." AS tt
4460 ON t.term_id = tt.term_id
4461 WHERE tt.taxonomy IN ('web_story_media_source')
4462 AND t.slug IN ('poster-generation', 'source-video', 'source-image', 'page-template')";
4463 $results = $wpdb->get_results($query);
4464 if(!empty($results)) {
4465 $termsIds = [];
4466 foreach($results as $result) {
4467 if(isset($result->term_id) && !empty($result->term_id)) {
4468 $termsIds[] = $result->term_id;
4469 }
4470 }
4471
4472 if(!empty($termsIds)) {
4473 $termsIds = implode(",", $termsIds);
4474 $where[] = "(P.ID NOT IN (SELECT object_id
4475 FROM ".$wpdb->term_relationships."
4476 WHERE term_taxonomy_id IN ($termsIds)))";
4477 }
4478 }
4479 }
4480 return $where;
4481 }
4482
4483 /**
4484 * Folders Query for Media
4485 *
4486 * @since 2.9
4487 * @access public
4488 */
4489 public function folders_count_join_query($join) {
4490 global $wpdb;
4491 if(class_exists( 'Better_Messages' )) {
4492 $join .= " LEFT JOIN " . $wpdb->postmeta . " AS BMPM
4493 ON ( P.ID = BMPM.post_id
4494 AND BMPM.meta_key = 'bp-better-messages-attachment') ";
4495 }
4496 if(class_exists( 'buddypress' )) {
4497 $join .= " LEFT JOIN ".$wpdb->postmeta." AS bb_mt1
4498 ON (P.ID = bb_mt1.post_id
4499 AND bb_mt1.meta_key = 'bp_media_upload' ) ";
4500
4501 $join .= " LEFT JOIN ".$wpdb->postmeta." AS bb_mt2
4502 ON (P.ID = bb_mt2.post_id
4503 AND bb_mt2.meta_key = 'bp_document_upload' ) ";
4504
4505 $join .= " LEFT JOIN ".$wpdb->postmeta." AS bb_mt3
4506 ON (P.ID = bb_mt3.post_id
4507 AND bb_mt3.meta_key = 'bp_video_upload' ) ";
4508
4509 }
4510 if ( function_exists( '_is_elementor_installed' ) ) {
4511 $join .= " LEFT JOIN ".$wpdb->postmeta." AS ELPM
4512 ON ( P.ID = ELPM.post_id
4513 AND ELPM.meta_key = '_elementor_is_screenshot') ";
4514 }
4515 return $join;
4516 }
4517
4518 /**
4519 * Autoload folders librarires
4520 *
4521 * @since 1.0.0
4522 * @access public
4523 * @return $files
4524 */
4525 public function autoload()
4526 {
4527 $files = [
4528 'WCP_Tree_View' => WCP_DS."includes".WCP_DS."tree.class.php",
4529 'WCP_Form_View' => WCP_DS."includes".WCP_DS."form.class.php",
4530 'WCP_Folder_WPML' => WCP_DS."includes".WCP_DS."class-wpml.php",
4531 'WCP_Folder_PolyLang' => WCP_DS."includes".WCP_DS."class-polylang.php",
4532 ];
4533
4534 foreach ($files as $file) {
4535 if (file_exists(dirname(dirname(__FILE__)).$file)) {
4536 include_once dirname(dirname(__FILE__)).$file;
4537 }
4538 }
4539
4540 }//end autoload()
4541
4542
4543 /**
4544 * Create folder taxonomies
4545 *
4546 * @since 1.0.0
4547 * @access public
4548 * @return $taxonomies
4549 */
4550 public function create_folder_terms()
4551 {
4552 $options = get_option('folders_settings');
4553 $options = is_array($options) ? $options : [];
4554 $old_plugin_status = 0;
4555 $posts = [];
4556 if (!empty($options)) {
4557 foreach ($options as $option) {
4558 if (!(strpos($option, 'folder4') === false) && $old_plugin_status == 0) {
4559 $old_plugin_status = 1;
4560 }
4561
4562 if (in_array($option, ["page", "post", "attachment"])) {
4563 $posts[] = str_replace("folder4", "", $option);
4564 } else {
4565 $posts[] = $option;
4566 }
4567 }
4568
4569 if (!empty($posts)) {
4570 update_option('folders_settings', $posts);
4571 }
4572 }
4573
4574 if ($old_plugin_status == 1) {
4575 update_option("folders_show_in_menu", "on");
4576 $old_plugin_var = get_option("folder_old_plugin_status");
4577 if (empty($old_plugin_var) || $old_plugin_var == null) {
4578 update_option("folder_old_plugin_status", "1");
4579 }
4580 }
4581
4582 $posts = get_option('folders_settings');
4583 if (!empty($posts)) {
4584 foreach ($posts as $post_type) {
4585 $labels = [
4586 'name' => esc_html__('Folders', 'folders'),
4587 'singular_name' => esc_html__('Folder', 'folders'),
4588 'all_items' => esc_html__('All Folders', 'folders'),
4589 'edit_item' => esc_html__('Edit Folder', 'folders'),
4590 'update_item' => esc_html__('Update Folder', 'folders'),
4591 'add_new_item' => esc_html__('Add New Folder', 'folders'),
4592 'new_item_name' => esc_html__('Add folder name', 'folders'),
4593 'menu_name' => esc_html__('Folders', 'folders'),
4594 'search_items' => esc_html__('Search Folders', 'folders'),
4595 'parent_item' => esc_html__('Parent Folder', 'folders'),
4596 ];
4597
4598 $args = [
4599 'label' => esc_html__('Folder', 'folders'),
4600 'labels' => $labels,
4601 'show_tagcloud' => false,
4602 'hierarchical' => true,
4603 'public' => false,
4604 'show_ui' => true,
4605 'show_in_menu' => false,
4606 'show_in_rest' => true,
4607 'show_admin_column' => true,
4608 'update_count_callback' => '_update_post_term_count',
4609 // 'update_count_callback' => '_update_generic_term_count',
4610 'query_var' => true,
4611 'rewrite' => false,
4612 'capabilities' => [
4613 'manage_terms' => 'manage_categories',
4614 'edit_terms' => 'manage_categories',
4615 'delete_terms' => 'manage_categories',
4616 'assign_terms' => 'manage_categories',
4617 ],
4618 ];
4619
4620 $folder_post_type = self::get_custom_post_type($post_type);
4621
4622 register_taxonomy(
4623 $folder_post_type,
4624 $post_type,
4625 $args
4626 );
4627 }//end foreach
4628 }//end if
4629
4630 $postData = filter_input_array(INPUT_POST);
4631
4632 if (current_user_can("manage_categories") && isset($postData['folder_nonce'])) {
4633 if (wp_verify_nonce($postData['folder_nonce'], "folder_settings")) {
4634 if (isset($postData['folders_show_in_menu']) && !empty($postData['folders_show_in_menu'])) {
4635 $show_menu = "off";
4636 if ($postData['folders_show_in_menu'] == "on") {
4637 $show_menu = "on";
4638 }
4639
4640 update_option("folders_show_in_menu", $show_menu);
4641 }
4642
4643 if (isset($postData['folders_settings1'])) {
4644 $posts = [];
4645 if (isset($postData['folders_settings']) && is_array($postData['folders_settings'])) {
4646 foreach ($postData['folders_settings'] as $key => $val) {
4647 $posts[] = $val;
4648 }
4649 }
4650
4651 update_option("folders_settings", $posts);
4652 }
4653
4654 $postData = filter_input_array(INPUT_POST);
4655
4656 if (isset($postData['folders_settings1'])) {
4657 $posts = [];
4658 if (isset($postData['default_folders']) && is_array($postData['default_folders'])) {
4659 foreach ($postData['default_folders'] as $key => $val) {
4660 $posts[$key] = $val;
4661 }
4662 }
4663
4664 update_option("default_folders", $posts);
4665 }
4666
4667 if (isset($postData['customize_folders'])) {
4668 $posts = [];
4669 if (isset($postData['customize_folders']) && is_array($postData['customize_folders'])) {
4670 foreach ($postData['customize_folders'] as $key => $val) {
4671 $posts[$key] = $val;
4672 }
4673 }
4674
4675 update_option("customize_folders", $posts);
4676 }
4677
4678 $setting_page = $this->getFolderSettingsURL();
4679 if (!empty($setting_page)) {
4680 $page = filter_input(INPUT_POST, 'tab_page');
4681 $type = filter_input(INPUT_GET, 'setting_page');
4682 $type = empty($type) ? "" : "&setting_page=".esc_attr($type);
4683 $setting_page = $setting_page.$type;
4684 if (!empty($page)) {
4685 $setting_page .= "&setting_page=".esc_attr($page);
4686 }
4687
4688 wp_redirect($setting_page."&note=1");
4689 exit;
4690 } else {
4691 $folder_page = filter_input(INPUT_POST, 'folder_page');
4692 if (!empty($folder_page)) {
4693 wp_redirect($folder_page);
4694 exit;
4695 }
4696 }
4697 }//end if
4698 }//end if
4699
4700 // $old_version = get_option("folder_old_plugin_status");
4701 // if($old_version !== false && $old_version == 1) {
4702 // $tlfs = get_option("folder_old_plugin_folder_status");
4703 // if($tlfs === false) {
4704 // $total = self::ttl_fldrs();
4705 // if($total <= 10) {
4706 // $total = 10;
4707 // };
4708 // update_option("folder_old_plugin_folder_status", $total);
4709 // self::$folders = $total;
4710 // } else {
4711 // self::$folders = $tlfs;
4712 // }
4713 // }
4714 //
4715 // $tlfs = get_option("folder_old_plugin_folder_status");
4716 // if($tlfs === false) {
4717 // self::$folders = 10;
4718 // } else {
4719 // self::$folders = $tlfs;
4720 // }
4721
4722 }//end create_folder_terms()
4723
4724
4725 /**
4726 * Search for data from list
4727 *
4728 * @since 1.0.0
4729 * @access public
4730 * @return $key
4731 */
4732 function searchForId($id, $menu)
4733 {
4734 if ($menu) {
4735 foreach ($menu as $key => $val) {
4736 if (array_key_exists(2, $val)) {
4737 $stripVal = explode('=', $val[2]);
4738 }
4739
4740 if (array_key_exists(1, $stripVal)) {
4741 $stripVal = $stripVal[1];
4742 }
4743
4744 if ($stripVal === $id) {
4745 return $key;
4746 }
4747 }
4748 }
4749
4750 }//end searchForId()
4751
4752
4753 /**
4754 * Create setting menu for folders
4755 *
4756 * @since 1.0.0
4757 * @access public
4758 */
4759 function create_menu_for_folders()
4760 {
4761 global $menu;
4762 self::check_and_set_post_type();
4763
4764 $folder_types = get_option("folders_settings");
4765 if (empty($folder_types)) {
4766 return;
4767 }
4768
4769 foreach ($folder_types as $type) {
4770 $itemKey = self::searchForId($type, $menu);
4771 switch (true) {
4772 case ($type == 'attachment'):
4773 $itemKey = 10;
4774 $edit = 'upload.php';
4775 break;
4776 case ($type === 'post'):
4777 $edit = 'edit.php';
4778 $itemKey = 5;
4779 break;
4780 default:
4781 $edit = 'edit.php';
4782 break;
4783 }
4784
4785 $folder = $type == 'attachment' ? 'media' : $type;
4786 $upper = $type == 'attachment' ? 'Media' : ucwords(str_replace(['-', '_'], ' ', $type));
4787 if ($type == 'page') {
4788 $tax_slug = 'folder';
4789 } else {
4790 $tax_slug = $folder.'_folder';
4791 }
4792
4793 $hide_empty = true;
4794 if ($type == 'attachment') {
4795 $hide_empty = false;
4796 add_menu_page('Media Folders', 'Media Folders', 'publish_pages', "{$edit}?post_type=attachment&media_folder=", false, 'dashicons-portfolio', "{$itemKey}.5");
4797 } else {
4798 add_menu_page($upper.' Folders', "{$upper} Folders", 'publish_pages', "{$edit}?post_type={$type}&type=folder", false, 'dashicons-portfolio', "{$itemKey}.5");
4799 }
4800
4801 $terms = get_terms(
4802 $tax_slug,
4803 [
4804 'hide_empty' => $hide_empty,
4805 'parent' => 0,
4806 'orderby' => 'meta_value_num',
4807 'order' => 'ASC',
4808 'hierarchical' => false,
4809 'meta_query' => [
4810 [
4811 'key' => 'wcp_custom_order',
4812 'type' => 'NUMERIC',
4813 ],
4814 ],
4815 ]
4816 );
4817
4818 if ($terms) {
4819 foreach ($terms as $term) {
4820 if (isset($term->trash_count) && !empty($term->trash_count)) {
4821 if ($type == 'attachment') {
4822 add_submenu_page("{$edit}?type=folder", $term->name, $term->name, 'publish_pages', "{$edit}?post_type=attachment&media_folder={$term->slug}", false);
4823 } else {
4824 add_submenu_page("{$edit}?post_type={$type}&type=folder", $term->name, $term->name, 'publish_pages', "{$edit}?post_type={$type}&{$tax_slug}={$term->slug}", false);
4825 }
4826 }
4827 }
4828 }
4829 }//end foreach
4830
4831 }//end create_menu_for_folders()
4832
4833
4834 /**
4835 * Add Folder Styles
4836 *
4837 * @since 1.0.0
4838 * @access public
4839 */
4840 function folders_admin_styles($page)
4841 {
4842 // echo $page; die;
4843 if($page == "folders-settings_page_folders-upgrade-to-pro" || ($page == "settings_page_wcp_folders_settings" && isset($_GET['setting_page']) && $_GET['setting_page'] == 'upgrade-to-pro')) {
4844 wp_enqueue_style('folder-pricing-table', plugin_dir_url(dirname(__FILE__)).'assets/css/pricing-table.css', [], WCP_FOLDER_VERSION);
4845 $queryArgs = [
4846 'family' => 'Poppins:wght@400;500;600;700&display=swap',
4847 'subset' => 'latin,latin-ext',
4848 ];
4849 wp_enqueue_style('google-poppins-fonts', add_query_arg($queryArgs, "//fonts.googleapis.com/css2"), [], null);
4850 } else if ($page == "toplevel_page_wcp_folders_settings" || $page == "settings_page_wcp_folders_settings") {
4851 wp_enqueue_style('folder-settings', plugin_dir_url(dirname(__FILE__)).'assets/css/settings.css', [], WCP_FOLDER_VERSION);
4852
4853 wp_enqueue_style('folders-icon', plugin_dir_url(dirname(__FILE__)).'assets/css/folder-icon.css', [], WCP_FOLDER_VERSION);
4854 wp_enqueue_style('folders-spectrum', plugin_dir_url(dirname(__FILE__)).'assets/css/spectrum.min.css', [], WCP_FOLDER_VERSION);
4855 } else if ($page == "folders-settings_page_folders-upgrade-to-pro" || $page == "toplevel_page_wcp_folders_settings" || $page == "settings_page_wcp_folders_settings" || ($page == "settings_page_wcp_folders_settings" && isset($_GET['setting_page']) && $_GET['setting_page'] == "upgrade-to-pro")) {
4856 wp_enqueue_style('wcp-select2', plugin_dir_url(dirname(__FILE__)).'assets/css/select2.min.css', [], WCP_FOLDER_VERSION);
4857 if ($page == "folders-settings_page_folders-upgrade-to-pro" || ($page == "settings_page_wcp_folders_settings" && isset($_GET['setting_page']) && $_GET['setting_page'] == "upgrade-to-pro")) {
4858 wp_enqueue_style('wcp-admin-setting', plugin_dir_url(dirname(__FILE__)).'assets/css/admin-setting.css', [], WCP_FOLDER_VERSION);
4859 }
4860 }
4861
4862 if (self::is_active_for_screen()) {
4863 wp_enqueue_style('wcp-folders-fa', plugin_dir_url(dirname(__FILE__)).'assets/css/folder-icon.css', [], WCP_FOLDER_VERSION);
4864 wp_enqueue_style('wcp-folders-admin', plugin_dir_url(dirname(__FILE__)).'assets/css/design.min.css', [], WCP_FOLDER_VERSION);
4865 wp_enqueue_style('wcp-folders-jstree', plugin_dir_url(dirname(__FILE__)).'assets/css/jstree.min.css', [], WCP_FOLDER_VERSION);
4866 wp_enqueue_style('folder-overlayscrollbars', WCP_FOLDER_URL.'assets/css/overlayscrollbars.min.css', [], WCP_FOLDER_VERSION);
4867 wp_enqueue_style('wcp-folders-css', plugin_dir_url(dirname(__FILE__)).'assets/css/folders.min.css', [], WCP_FOLDER_VERSION);
4868 }
4869
4870 if ($page == "media_page_folders-media-cleaning") {
4871 wp_enqueue_style('wcp-folders-media', plugin_dir_url(dirname(__FILE__)).'assets/css/media-clean.css', [], WCP_FOLDER_VERSION);
4872 }
4873
4874 wp_register_style('wcp-css-handle', false);
4875 wp_enqueue_style('wcp-css-handle');
4876 $css = "
4877 .wcp-folder-upgrade-button {color: #FF5983; font-weight: bold; display: inline-block;border: solid 1px #FF5983;border-radius: 4px;padding: 0 5px;}
4878 ";
4879 if (self::is_active_for_screen()) {
4880 global $typenow;
4881 $width = get_option("wcp_dynamic_width_for_".$typenow);
4882 $width = esc_attr($width);
4883 $width = intval($width);
4884 $width = empty($width)||!is_numeric($width) ? 280 : $width;
4885 if ($width > 1200) {
4886 $width = 280;
4887 }
4888
4889 $width = intval($width);
4890 $display_status = "wcp_dynamic_display_status_".$typenow;
4891 $display_status = get_option($display_status);
4892 if ($display_status != "hide") {
4893 if (!empty($width) && is_numeric($width)) {
4894 if (function_exists('is_rtl') && is_rtl()) {
4895 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-right:".($width + 20)."px}";
4896 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-left:0px}";
4897 } else {
4898 $css .= "body.wp-admin #wpcontent {padding-left:".($width + 20)."px}";
4899 }
4900 }
4901 } else {
4902 if (function_exists('is_rtl') && is_rtl()) {
4903 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-right:20px}";
4904 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-left:0px}";
4905 } else {
4906 $css .= "body.wp-admin #wpcontent {padding-left:20px}";
4907 }
4908 }
4909
4910 if (!empty($width) && is_numeric($width)) {
4911 if ($width > 1200) {
4912 $width = 280;
4913 }
4914
4915 $width = intval($width);
4916 $css .= ".wcp-content {width: ".esc_attr($width)."px}";
4917 }
4918
4919 global $typenow;
4920 $post_type = self::get_custom_post_type($typenow);
4921 $css .= "body:not(.woocommerce-page) .wp-list-table th#taxonomy-".esc_attr($post_type)." { width: 130px !important; } @media screen and (max-width: 1180px) { body:not(.woocommerce-page) .wp-list-table th#taxonomy-".esc_attr($post_type)." { width: 90px !important; }} @media screen and (max-width: 960px) { body:not(.woocommerce-page) .wp-list-table th#taxonomy-".esc_attr($post_type)." { width: auto !important; }}";
4922 }//end if
4923
4924 wp_add_inline_style('wcp-css-handle', $css);
4925
4926 if (self::is_active_for_screen()) {
4927 global $typenow;
4928 add_filter('views_edit-'.$typenow, [$this, 'wcp_check_for_child_folders']);
4929 }
4930
4931 }//end folders_admin_styles()
4932
4933
4934 /**
4935 * Get Child folder information
4936 *
4937 * @since 1.0.0
4938 * @access public
4939 * @return $folders
4940 */
4941 function wcp_check_for_child_folders($content)
4942 {
4943 $termId = 0;
4944 global $typenow;
4945 $post_type = self::get_custom_post_type($typenow);
4946 $term = filter_input(INPUT_GET, $post_type);
4947 if (!empty($term)) {
4948 $term = get_term_by("slug", $term, $post_type);
4949 if (!empty($term)) {
4950 $termId = $term->term_id;
4951 }
4952 }
4953
4954 $terms = get_terms(
4955 $post_type,
4956 [
4957 'hide_empty' => false,
4958 'parent' => $termId,
4959 'orderby' => 'meta_value_num',
4960 'order' => 'ASC',
4961 'hierarchical' => false,
4962 'update_count_callback' => '_update_generic_term_count',
4963 'meta_query' => [
4964 [
4965 'key' => 'wcp_custom_order',
4966 'type' => 'NUMERIC',
4967 ],
4968 ],
4969 ]
4970 );
4971 $optionName = "wcp_folder_display_status_".$typenow;
4972 $optionValue = get_option($optionName);
4973 $class = (!empty($optionValue) && $optionValue == "hide") ? "" : "active";
4974 $customize_folders = get_option('customize_folders');
4975 $show_in_page = isset($customize_folders['show_in_page']) ? $customize_folders['show_in_page'] : "hide";
4976 if (empty($show_in_page)) {
4977 $show_in_page = "hide";
4978 }
4979
4980 if ($show_in_page == "show") {
4981 echo '<div class="tree-structure-content '.$class.'"><div class="tree-structure" id="list-folder-'.$termId.'" data-id="'.$termId.'">';
4982 echo '<ul>';
4983 foreach ($terms as $term) {
4984 $status = get_term_meta($term->term_id, "is_highlighted", true);
4985 ?>
4986 <li class="grid-view" data-id="<?php echo esc_attr($term->term_id) ?>" id="folder_<?php echo esc_attr($term->term_id) ?>">
4987 <div class="folder-item is-folder" data-id="<?php echo esc_attr($term->term_id) ?>">
4988 <a title='<?php echo esc_attr($term->name) ?>' id="folder_view_<?php echo esc_attr($term->term_id) ?>" class="folder-view <?php echo ($status == 1) ? "is-high" : "" ?>" data-id="<?php echo esc_attr($term->term_id) ?>">
4989 <span class="folder item-name"><span id="wcp_folder_text_<?php echo esc_attr($term->term_id) ?>" class="folder-title"><?php echo esc_attr($term->name) ?></span></span>
4990 </a>
4991 </div>
4992 </li>
4993 <?php
4994 }
4995
4996 echo '</ul>';
4997 echo '<div class="clear clearfix"></div>';
4998 echo '</div>';
4999 echo '<div class="folders-toggle-button"><span></span></div>';
5000 echo '</div>';
5001 }//end if
5002
5003 $allowedTags = [
5004 'a' => [
5005 'href' => [],
5006 'title' => [],
5007 'target' => [],
5008 'class' => []
5009 ],
5010 "span" => [
5011 'class' => []
5012 ]
5013 ];
5014
5015 if(isset($content['mine'])) {
5016 unset($content['mine']);
5017 }
5018 if (!empty($content) && is_array($content)) {
5019 echo '<ul class="subsubsub">';
5020 foreach ($content as $k => $v) {
5021 echo "<li class='".esc_attr($k)."'>".wp_kses($v, $allowedTags)."</li>";
5022 }
5023
5024 echo '</ul>';
5025 }
5026
5027 }//end wcp_check_for_child_folders()
5028
5029
5030 /**
5031 * Add Folder Scripts to admin
5032 *
5033 * @since 1.0.0
5034 * @access public
5035 * @return $folders
5036 */
5037 function folders_admin_scripts($hook)
5038 {
5039 if ($hook == "toplevel_page_wcp_folders_settings" || $hook == "settings_page_wcp_folders_settings") {
5040 wp_enqueue_script('folders-spectrum', plugin_dir_url(dirname(__FILE__)).'assets/js/spectrum.min.js', ['jquery'], WCP_FOLDER_VERSION);
5041 }
5042
5043 if ($hook == "folders-settings_page_folders-upgrade-to-pro" || $hook == "toplevel_page_wcp_folders_settings" || $hook == "settings_page_wcp_folders_settings" || ($hook == "settings_page_wcp_folders_settings" && isset($_GET['setting_page']) && $_GET['setting_page'] == "upgrade-to-pro")) {
5044 wp_enqueue_script('folders-select2', plugin_dir_url(dirname(__FILE__)).'assets/js/select2.min.js', ['jquery'], WCP_FOLDER_VERSION);
5045 }
5046
5047 if ($hook == "folders-settings_page_folders-upgrade-to-pro" || ($hook == "settings_page_wcp_folders_settings" && isset($_GET['setting_page']) && $_GET['setting_page'] == "upgrade-to-pro")) {
5048 wp_enqueue_script('folders-slick', plugin_dir_url(dirname(__FILE__)).'assets/js/slick.min.js', ['jquery'], WCP_FOLDER_VERSION);
5049 }
5050
5051 if (self::is_active_for_screen()) {
5052 remove_filter("terms_clauses", "TO_apply_order_filter");
5053
5054 global $typenow;
5055 // Free/Pro Version change
5056 wp_dequeue_script("jquery-jstree");
5057 wp_enqueue_script('wcp-folders-jstree', plugin_dir_url(dirname(__FILE__)).'assets/js/jstree.min.js', ['jquery'], WCP_FOLDER_VERSION);
5058 wp_enqueue_script('folders-overlayscrollbars', WCP_FOLDER_URL.'assets/js/jquery.overlayscrollbars.min.js', [], WCP_FOLDER_VERSION);
5059 wp_enqueue_script('wcp-folders-custom', plugin_dir_url(dirname(__FILE__)).'assets/js/folders.min.js', ['jquery', 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'backbone'], WCP_FOLDER_VERSION);
5060 wp_enqueue_script('wcp-jquery-touch', plugin_dir_url(dirname(__FILE__)).'assets/js/jquery.ui.touch-punch.min.js', ['jquery'], WCP_FOLDER_VERSION);
5061
5062 $post_type = self::get_custom_post_type($typenow);
5063
5064 $post_status = "";
5065 if (isset($_GET['post_status']) && !empty($_GET['post_status'])) {
5066 $post_status = folders_sanitize_text('post_status', 'get');
5067 }
5068
5069 if ($typenow == "attachment") {
5070 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
5071 } else {
5072 $admin_url = admin_url("edit.php?post_type=".$typenow);
5073 $search = filter_input(INPUT_GET, "s");
5074 if (!empty($search)) {
5075 $admin_url .= "&s=".esc_attr($search);
5076 }
5077
5078 if (!empty($post_status)) {
5079 $admin_url .= "&post_status=".sanitize_text_field($post_status);
5080 }
5081
5082 $admin_url .= "&".esc_attr($post_type)."=";
5083 }
5084
5085 $current_url = $admin_url;
5086 $post_value = filter_input(INPUT_GET, $post_type);
5087 if (!empty($post_value)) {
5088 $current_url .= esc_attr($post_value);
5089 }
5090
5091 $is_active = 1;
5092 $folders = -1;
5093 // For free: upgrade URL, for Pro: Register Key URL
5094 $register_url = $this->getFoldersUpgradeURL();
5095
5096 $is_rtl = 0;
5097 if (function_exists('is_rtl') && is_rtl()) {
5098 $is_rtl = 1;
5099 }
5100
5101 $can_manage_folder = current_user_can("manage_categories") ? 1 : 0;
5102 $width = get_option("wcp_dynamic_width_for_".$typenow);
5103 $width = intval($width);
5104 $width = empty($width)||!is_numeric($width) ? 280 : $width;
5105 if ($width > 1200) {
5106 $width = 280;
5107 }
5108
5109 $post_type = self::get_custom_post_type($typenow);
5110 $taxonomy_status = 0;
5111 $selected_taxonomy = "";
5112 $post_value = filter_input(INPUT_GET, $post_type);
5113 if (empty($post_value)) {
5114 $taxonomy_status = 1;
5115 } else {
5116 $selected_taxonomy = esc_attr($post_value);
5117
5118 $term = get_term_by('slug', $selected_taxonomy, $post_type);
5119 if (!empty($term) && is_object($term)) {
5120 $selected_taxonomy = $term->term_id;
5121 } else {
5122 $selected_taxonomy = "";
5123 }
5124 }
5125
5126 $customize_folders = get_option('customize_folders');
5127 $show_in_page = isset($customize_folders['show_in_page']) ? $customize_folders['show_in_page'] : "hide";
5128 if (empty($show_in_page)) {
5129 $show_in_page = "hide";
5130 }
5131
5132 $taxonomies = self::get_terms_hierarchical($post_type);
5133 $use_folder_undo = !isset($customize_folders['use_folder_undo']) ? "yes" : $customize_folders['use_folder_undo'];
5134 $defaultTimeout = !isset($customize_folders['default_timeout']) ? 5 : intval($customize_folders['default_timeout']);
5135 if (empty($defaultTimeout) || !is_numeric($defaultTimeout) || $defaultTimeout < 0) {
5136 $defaultTimeout = 5;
5137 }
5138
5139 $defaultTimeout = ($defaultTimeout * 1000);
5140
5141 $folder_settings = [];
5142 foreach ($taxonomies as $taxonomy) {
5143 $is_sticky = get_term_meta($taxonomy->term_id, "is_folder_sticky", true);
5144 $is_high = get_term_meta($taxonomy->term_id, "is_highlighted", true);
5145 $folder_settings[] = [
5146 'folder_id' => $taxonomy->term_id,
5147 'is_sticky' => intval($is_sticky),
5148 'is_high' => intval($is_high),
5149 'nonce' => wp_create_nonce('wcp_folder_term_'.$taxonomy->term_id),
5150 'is_deleted' => 0,
5151 'slug' => $taxonomy->slug,
5152 'folder_count' => intval($taxonomy->trash_count),
5153 ];
5154 }
5155
5156 $default_folders = get_option("default_folders");
5157 $default_folder = "";
5158 if (isset($default_folders["attachment"])) {
5159 $default_folder = $default_folders["attachment"];
5160 }
5161
5162 $use_shortcuts = !isset($customize_folders['use_shortcuts']) ? "yes" : $customize_folders['use_shortcuts'];
5163
5164 $currentPage = filter_input(INPUT_GET, 'paged');
5165 if (!empty($currentPage)) {
5166 $currentPage = intval($currentPage);
5167 } else {
5168 $currentPage = 1;
5169 }
5170
5171 $lang = $this->js_strings();
5172
5173 $hasStars = self::check_for_setting("has_stars", "general");
5174 $hasChild = self::check_for_setting("has_child", "general");
5175 $hasChild = empty($hasChild) ? 0 : 1;
5176 $hasStars = empty($hasStars) ? 0 : 1;
5177 wp_localize_script(
5178 'wcp-folders-custom',
5179 'wcp_settings',
5180 [
5181 'ajax_url' => admin_url('admin-ajax.php'),
5182 'upgrade_url' => $this->getFoldersUpgradeURL(),
5183 'post_type' => $typenow,
5184 'custom_type' => $post_type,
5185 'page_url' => $admin_url,
5186 'current_url' => $current_url,
5187 'ajax_image' => plugin_dir_url(dirname(__FILE__))."assets/images/ajax-loader.gif",
5188 'is_key_active' => $is_active,
5189 'folders' => $folders,
5190 'register_url' => $register_url,
5191 'isRTL' => $is_rtl,
5192 'nonce' => wp_create_nonce('wcp_folder_nonce_'.$typenow),
5193 'can_manage_folder' => $can_manage_folder,
5194 'folder_width' => $width,
5195 'taxonomy_status' => $taxonomy_status,
5196 'selected_taxonomy' => $selected_taxonomy,
5197 'show_in_page' => $show_in_page,
5198 'svg_file' => WCP_FOLDER_URL.'assets/images/pin.png',
5199 'taxonomies' => $taxonomies,
5200 'folder_settings' => $folder_settings,
5201 'hasStars' => $hasStars,
5202 'hasChildren' => $hasChild,
5203 'currentPage' => $currentPage,
5204 'useFolderUndo' => $use_folder_undo,
5205 'defaultTimeout' => $defaultTimeout,
5206 'default_folder' => $default_folder,
5207 'use_shortcuts' => $use_shortcuts,
5208 'post_status' => $post_status,
5209 'lang' => $lang,
5210 ]
5211 );
5212 } else {
5213 self::is_add_update_screen();
5214 }//end if
5215
5216 if ($hook == "media-new.php") {
5217 if (self::is_for_this_post_type('attachment') || self::is_for_this_post_type('media')) {
5218 wp_enqueue_style('folders-media', WCP_FOLDER_URL.'assets/css/new-media.css');
5219 $is_active = 1;
5220 $folders = -1;
5221
5222 $hasStars = self::check_for_setting("has_stars", "general");
5223 $hasChild = self::check_for_setting("has_child", "general");
5224 $hasChild = empty($hasChild) ? 0 : 1;
5225 $hasStars = empty($hasStars) ? 0 : 1;
5226
5227 wp_enqueue_script('wcp-folders-add-new-media', plugin_dir_url(dirname(__FILE__)).'assets/js/new-media.js', ['jquery'], WCP_FOLDER_VERSION);
5228 wp_localize_script(
5229 'wcp-folders-add-new-media',
5230 'folders_media_options',
5231 [
5232 'terms' => self::get_terms_hierarchical('media_folder'),
5233 'taxonomy' => get_taxonomy('media_folder'),
5234 'ajax_url' => admin_url("admin-ajax.php"),
5235 'activate_url' => $this->getFoldersUpgradeURL(),
5236 'nonce' => wp_create_nonce('wcp_folder_nonce_attachment'),
5237 'is_key_active' => $is_active,
5238 'folders' => $folders,
5239 'hasStars' => $hasStars,
5240 'hasChildren' => $hasChild,
5241 ]
5242 );
5243 }//end if
5244 }//end if
5245
5246 }//end folders_admin_scripts()
5247
5248
5249 /**
5250 * Translated strings for javascript
5251 *
5252 * @since 1.0.0
5253 * @access public
5254 */
5255 public function js_strings()
5256 {
5257 return [
5258 "ALL_FOLDERS" => esc_html__("All Folders", "folders"),
5259 "NEW_FOLDER" => esc_html__("New folder", "folders"),
5260 "NEW_SUB_FOLDER" => esc_html__("New Sub-folder", "folders"),
5261 "RENAME" => esc_html__("Rename", "folders"),
5262 "REMOVE_STICKY_FOLDER" => esc_html__("Remove Sticky Folder", "folders"),
5263 "STICKY_FOLDER" => esc_html__("Sticky Folder", "folders"),
5264 "REMOVE_STAR" => esc_html__("Remove Star", "folders"),
5265 "ADD_STAR" => esc_html__("Add Star", "folders"),
5266 "LOCK_FOLDER" => esc_html__("Lock Folder", "folders"),
5267 "UNLOCK_FOLDER" => esc_html__("Unlock Folder", "folders"),
5268 "DUPLICATE_FOLDER" => esc_html__("Duplicate folder", "folders"),
5269 "DOWNLOAD_ZIP" => esc_html__("Download Zip", "folders"),
5270 "OPEN_THIS_FOLDER" => esc_html__("Open this folder by default", "folders"),
5271 "REMOVE_THIS_FOLDER" => esc_html__("Remove default folder", "folders"),
5272 "CUT" => esc_html__("Cut", "folders"),
5273 "COPY" => esc_html__("Copy", "folders"),
5274 "PASTE" => esc_html__("Paste", "folders"),
5275 "DELETE" => esc_html__("Delete", "folders"),
5276 "BULK_ORGANIZE" => esc_html__("Bulk Organize", "folders"),
5277 "DRAG_AND_DROP" => esc_html__("Drag and drop your media files to the relevant folders", "folders"),
5278 "SELECT_ALL" => esc_html__("Select All", "folders"),
5279 "MOVE_SELECTED_FILES" => esc_html__("Move Selected files to:", "folders"),
5280 "UPLOADING_FILES" => esc_html__("Uploading files", "folders"),
5281 "SELECT_ITEMS_TO_MOVE" => esc_html__("Please select items to move in folder", "folders"),
5282 "LOADING_FILES" => esc_html__("Loading...", "folders"),
5283 "SELECT_FOLDER" => esc_html__("Select Folder", "folders"),
5284 "UNASSIGNED" => esc_html__("(Unassigned)", "folders"),
5285 "SELECT_ITEMS" => esc_html__("Select Items to move", "folders"),
5286 "ONE_ITEM" => esc_html__("1 Item", "folders"),
5287 "ITEMS" => esc_html__("Items", "folders"),
5288 "SELECTED" => esc_html__("Selected", "folders"),
5289 "MOVE_TO_FOLDER" => esc_html__("Move to Folder", "folders"),
5290 "DELETE_FOLDER_MESSAGE" => esc_html__("Are you sure you want to delete the selected folder?", "folders"),
5291 "ITEM_NOT_DELETED" => esc_html__("Items in the folder will not be deleted.", "folders"),
5292 "DELETE_FOLDERS_MESSAGE" => esc_html__("Are you sure you want to delete the selected folders?", "folders"),
5293 "ITEMS_NOT_DELETED" => esc_html__("Items in the selected folders will not be deleted.", "folders"),
5294 "SELECT_AT_LEAST_ONE_FOLDER" => esc_html__("Please select at least one folder to delete", "folders"),
5295 "YES_DELETE_IT" => esc_html__("Yes, Delete it!", "folders"),
5296 "SUBMIT" => esc_html__("Submit", "folders"),
5297 "EXPAND" => esc_html__("Expand", "folders"),
5298 "COLLAPSE" => esc_html__("Collapse", "folders"),
5299 "DUPLICATING_FOLDER" => esc_html__("Duplicating to a new folder", "folders"),
5300 "ADD_NEW_FOLDER" => esc_html__("Add a new folder", "folders"),
5301 "ACTIVATE" => [
5302 "REMOVE_STAR" => esc_html__("Remove Star (Activate)", "folders"),
5303 "ADD_STAR" => esc_html__("Add a Star (Activate)", "folders"),
5304 "STICKY_FOLDER" => esc_html__("Sticky Folder (Activate)", "folders"),
5305 "NEW_SUB_FOLDER" => esc_html__("New Sub-folder (Activate)", "folders"),
5306 "LOCK_FOLDER" => esc_html__("Lock Folder (Activate)", "folders"),
5307 "DUPLICATE_FOLDER" => esc_html__("Duplicate folder (Activate)", "folders"),
5308 "DOWNLOAD_ZIP" => esc_html__("Download Zip (Activate)", "folders"),
5309 ],
5310 "PRO" => [
5311 "ADD_STAR" => esc_html__("Add a Star (Pro)", "folders"),
5312 "REMOVE_STAR" => esc_html__("Remove Star (Pro)", "folders"),
5313 "STICKY_FOLDER" => esc_html__("Sticky Folder (Pro)", "folders"),
5314 "NEW_SUB_FOLDER" => esc_html__("New Sub-folder (Pro)", "folders"),
5315 "LOCK_FOLDER" => esc_html__("Lock Folder (Pro)", "folders"),
5316 "DUPLICATE_FOLDER" => esc_html__("Duplicate folder (Pro)", "folders"),
5317 "DOWNLOAD_ZIP" => esc_html__("Download Zip (Pro)", "folders"),
5318 "OPEN_THIS_FOLDER" => esc_html__("Open this folder by default (Pro)", "folders"),
5319 ],
5320 ];
5321
5322 }//end js_strings()
5323
5324
5325 /**
5326 * Redirect to folders settings page on Plugin activation
5327 *
5328 * @since 1.0.0
5329 * @access public
5330 */
5331 public function plugin_action_links($links)
5332 {
5333 array_unshift($links, '<a href="'.admin_url("admin.php?page=wcp_folders_settings").'" >'.esc_html__('Settings', 'folders').'</a>');
5334 $links['need_help'] = '<a target="_blank" href="https://premio.io/help/folders/?utm_source=pluginspage" >'.__('Need help?', 'folders').'</a>';
5335
5336 // PRO link for only for FREE
5337 $links['pro'] = '<a class="wcp-folder-upgrade-button" href="'.$this->getFoldersUpgradeURL().'" >'.__('Upgrade', 'folders').'</a>';
5338 return $links;
5339
5340 }//end plugin_action_links()
5341
5342
5343 /**
5344 * Create instance of Folder class
5345 *
5346 * @since 1.0.0
5347 * @access public
5348 * @return $folders
5349 */
5350 public static function get_instance()
5351 {
5352 if (empty(self::$instance)) {
5353 // Do not change Class name here
5354 self::$instance = new WCP_Folders();
5355 }
5356
5357 return self::$instance;
5358
5359 }//end get_instance()
5360
5361
5362 /**
5363 * Will check for empty folder order
5364 *
5365 * @since 1.0.0
5366 * @access public
5367 */
5368 public function check_and_set_post_type()
5369 {
5370 $options = get_option('folders_settings');
5371 $old_plugin_status = 0;
5372 $post_array = [];
5373 if (!empty($options) && is_array($options)) {
5374 foreach ($options as $key => $val) {
5375 if (!(strpos($key, 'folders4') === false) && $old_plugin_status == 0) {
5376 $old_plugin_status = 1;
5377 }
5378
5379 if (in_array($key, ["folders4page", "folders4post", "folders4attachment"])) {
5380 $post_array[] = str_replace("folders4", "", $key);
5381 }
5382 }
5383 } else {
5384 $post_array = [
5385 "page",
5386 "post",
5387 "attachment",
5388 ];
5389 }
5390
5391 if ($old_plugin_status == 1) {
5392 update_option("folders_show_in_menu", "on");
5393 $old_plugin_var = get_option("folder_old_plugin_status");
5394 if (empty($old_plugin_var) || $old_plugin_var == null) {
5395 update_option("folder_old_plugin_status", "1");
5396 }
5397
5398 update_option('folders_settings', $post_array);
5399 self::set_default_values_if_not_exists();
5400 }
5401
5402 if (!empty($post_array) && get_option('folders_settings') === false) {
5403 update_option('folders_settings', $post_array);
5404 update_option("folders_show_in_menu", "off");
5405 }
5406
5407 }//end check_and_set_post_type()
5408
5409
5410 /**
5411 * Migrate data for old versions
5412 *
5413 * @since 1.0.0
5414 * @access public
5415 */
5416 public static function activate()
5417 {
5418 premio_folders_plugin_check_for_setting();
5419 $folder_setting = get_option("folders_settings");
5420 if ($folder_setting === false) {
5421 add_option("wcp_folder_version_267", 1);
5422 }
5423
5424 update_option("folders_show_in_menu", "off");
5425 $option = get_option("folder_redirect_status");
5426 if ($option === false) {
5427 add_option("folder_intro_box", "show");
5428 }
5429
5430 update_option("folder_redirect_status", 1);
5431
5432 }//end activate()
5433
5434
5435 /**
5436 * Remove folder data on deactivation
5437 *
5438 * @since 1.0.0
5439 * @access public
5440 */
5441 public static function deactivate()
5442 {
5443 $customize_folders = get_option('customize_folders');
5444 $DS = DIRECTORY_SEPARATOR;
5445 $dirName = ABSPATH."wp-content{$DS}plugins{$DS}folders-pro{$DS}";
5446 $is_pro = get_option("folders_pro_is_in_process");
5447 if (!is_dir($dirName) && $is_pro === false && isset($customize_folders['remove_folders_when_removed']) && $customize_folders['remove_folders_when_removed'] == "on") {
5448 self::$folders = 0;
5449 self::remove_folder_by_taxonomy("media_folder");
5450 self::remove_folder_by_taxonomy("folder");
5451 self::remove_folder_by_taxonomy("post_folder");
5452 $post_types = get_post_types([], 'objects');
5453 $post_array = [
5454 "page",
5455 "post",
5456 "attachment",
5457 ];
5458 foreach ($post_types as $post_type) {
5459 if (!in_array($post_type->name, $post_array)) {
5460 self::remove_folder_by_taxonomy($post_type->name.'_folder');
5461 }
5462 }
5463
5464 delete_option('customize_folders');
5465 delete_option('default_folders');
5466 delete_option('folders_show_in_menu');
5467 delete_option('folder_redirect_status');
5468 delete_option('folders_settings');
5469 delete_option('premio_folder_options');
5470 delete_option('folders_settings_updated');
5471 }//end if
5472
5473 }//end deactivate()
5474
5475
5476 /**
5477 * Register folder settings
5478 *
5479 * @since 1.0.0
5480 * @access public
5481 */
5482 function folders_register_settings()
5483 {
5484 register_setting('folders_settings', 'folders_settings1', 'folders_settings_validate');
5485 register_setting('default_folders', 'default_folders');
5486 register_setting('customize_folders', 'customize_folders');
5487
5488 self::check_and_set_post_type();
5489
5490 $getData = filter_input_array(INPUT_GET);
5491 if (isset($getData['hide_menu']) && $getData['hide_menu'] == "scan-files" && isset($getData['nonce'])) {
5492 if (current_user_can('manage_options')) {
5493 $nonce = $getData['nonce'];
5494 if (wp_verify_nonce($nonce, "folders-scan-files")) {
5495 $customize_folders = get_option('customize_folders');
5496 $customize_folders['folders_media_cleaning'] = "no";
5497 update_option("customize_folders", $customize_folders);
5498 wp_redirect(admin_url("upload.php"));
5499 exit;
5500 }
5501 }
5502 }
5503
5504 $option = get_option("folder_redirect_status");
5505 if ($option == 1) {
5506 update_option("folder_redirect_status", 2);
5507 wp_redirect(admin_url("admin.php?page=wcp_folders_settings"));
5508 exit;
5509 }
5510
5511 }//end folders_register_settings()
5512
5513
5514 /**
5515 * Folders upgrade URL
5516 *
5517 * @since 1.0.0
5518 * @access public
5519 * @return $url
5520 */
5521 function getFoldersUpgradeURL()
5522 {
5523 $customize_folders = get_option("customize_folders");
5524 if (isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") {
5525 return admin_url("options-general.php?page=wcp_folders_settings&setting_page=upgrade-to-pro");
5526 } else {
5527 return admin_url("admin.php?page=folders-upgrade-to-pro");
5528 }
5529
5530 }//end getFoldersUpgradeURL()
5531
5532
5533 /**
5534 * Returns folders settings URL
5535 *
5536 * @since 1.0.0
5537 * @access public
5538 * @return $url
5539 */
5540 function getFolderSettingsURL()
5541 {
5542 $customize_folders = get_option("customize_folders");
5543 if (isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") {
5544 return admin_url("options-general.php?page=wcp_folders_settings");
5545 } else {
5546 return admin_url("admin.php?page=wcp_folders_settings");
5547 }
5548
5549 }//end getFolderSettingsURL()
5550
5551
5552 /**
5553 * Checking folders setting is inside wordpress setting menu
5554 *
5555 * @since 1.0.0
5556 * @access public
5557 */
5558 function isFoldersInSettings()
5559 {
5560 $customize_folders = get_option("customize_folders");
5561 if (isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") {
5562 return true;
5563 }
5564
5565 return false;
5566
5567 }//end isFoldersInSettings()
5568
5569
5570 /**
5571 * Add Checkbox to table head for page, post, attachments
5572 *
5573 * @since 1.0.0
5574 * @access public
5575 * @return $defaults
5576 */
5577 function wcp_manage_columns_head($defaults, $d="")
5578 {
5579 global $typenow;
5580 $type = $typenow;
5581 $action = $this->getRequestVar("action");
5582 if ($action == 'inline-save') {
5583 $post_type = $this->getRequestVar('post_type');
5584 $type = self::sanitize_options($post_type);
5585 }
5586
5587 $options = get_option("folders_settings");
5588 if (is_array($options) && in_array($type, $options)) {
5589 $columns = ([
5590 'wcp_move' => '<div class="wcp-move-multiple wcp-col" title="'.esc_html__('Move selected items', 'folders').'"><span class="dashicons dashicons-move"></span><div class="wcp-items"></div></div>',
5591 ] + $defaults);
5592 return $columns;
5593 }
5594
5595 return $defaults;
5596
5597 }//end wcp_manage_columns_head()
5598
5599
5600 /**
5601 * Add Checkbox to table body content for page, post, attachments
5602 *
5603 * @since 1.0.0
5604 * @access public
5605 * @return $column_name
5606 */
5607 function wcp_manage_columns_content($column_name, $post_ID)
5608 {
5609 $postIDs = self::$postIds;
5610 if (!is_array($postIDs)) {
5611 $postIDs = [];
5612 }
5613
5614 if (!in_array($post_ID, $postIDs)) {
5615 $postIDs[] = $post_ID;
5616 self::$postIds = $postIDs;
5617 global $typenow;
5618 $type = $typenow;
5619 $action = $this->getRequestVar('action');
5620 if ($action == 'inline-save') {
5621 $post_type = $this->getRequestVar('post_type');
5622 $type = self::sanitize_options($post_type);
5623 }
5624
5625 $options = get_option("folders_settings");
5626 if (is_array($options) && in_array($type, $options)) {
5627 if ($column_name == 'wcp_move') {
5628 $title = get_the_title();
5629 if (strlen($title) > 20) {
5630 $title = substr($title, 0, 20)."...";
5631 }
5632
5633 echo "<div class='wcp-move-file' data-id='".esc_attr($post_ID)."'><span class='wcp-move dashicons dashicons-move' data-id='".esc_attr($post_ID)."'></span><span class='wcp-item' data-object-id='".esc_attr($post_ID)."'>".esc_attr($title)."</span></div>";
5634 }
5635 }
5636 }//end if
5637
5638 }//end wcp_manage_columns_content()
5639
5640
5641 /**
5642 * Exclude empty folders
5643 *
5644 * @since 1.0.0
5645 * @access public
5646 * @return $query
5647 */
5648 function taxonomy_archive_exclude_children($query)
5649 {
5650 $options = get_option("folders_settings");
5651 if (!empty($options)) {
5652 $taxonomy_slugs = [];
5653 foreach ($options as $option) {
5654 $taxonomy_slugs[] = self::get_custom_post_type($option);
5655 }
5656
5657 if (!empty($taxonomy_slugs)) {
5658 $i = 0;
5659 foreach ($query->tax_query->queries as $tax_query_item) {
5660 if (empty($taxonomy_slugs) || (isset($tax_query_item['taxonomy']) && in_array($tax_query_item['taxonomy'], $taxonomy_slugs))) {
5661 $query->tax_query->queries[$i]['include_children'] = 0;
5662 }
5663 }
5664 }
5665 }
5666
5667 }//end taxonomy_archive_exclude_children()
5668
5669
5670 /**
5671 * Add folder settins to WP menu
5672 *
5673 * @since 1.0.0
5674 * @access public
5675 */
5676 public function admin_menu()
5677 {
5678 $customize_folders = get_option("customize_folders");
5679 if (isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") {
5680 add_options_page(
5681 esc_html__('Folders Settings', 'folders'),
5682 esc_html__('Folders Settings', 'folders'),
5683 'manage_options',
5684 'wcp_folders_settings',
5685 [
5686 $this,
5687 'wcp_folders_settings',
5688 ]
5689 );
5690 } else {
5691 $menu_slug = 'wcp_folders_settings';
5692
5693 // Add menu item for settings page
5694 $page_title = esc_html__('Folders', 'folders');
5695 $menu_title = esc_html__('Folders Settings', 'folders');
5696 $capability = 'manage_options';
5697 $callback = [
5698 $this,
5699 "wcp_folders_settings",
5700 ];
5701 $icon_url = 'dashicons-category';
5702 $position = 99;
5703 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $callback, $icon_url, $position);
5704
5705 $getData = filter_input_array(INPUT_GET);
5706 if (isset($getData['hide_folder_recommended_plugin']) && isset($getData['nonce'])) {
5707 if (current_user_can('manage_options')) {
5708 $nonce = $getData['nonce'];
5709 if (wp_verify_nonce($nonce, "folder_recommended_plugin")) {
5710 update_option('hide_folder_recommended_plugin', "1");
5711 }
5712 }
5713 }
5714
5715 $recommended_plugin = get_option("hide_folder_recommended_plugin");
5716 if ($recommended_plugin === false) {
5717 add_submenu_page(
5718 $menu_slug,
5719 esc_html__('Recommended Plugins', 'folders'),
5720 esc_html__('Recommended Plugins', 'folders'),
5721 'manage_options',
5722 'recommended-folder-plugins',
5723 [
5724 $this,
5725 'recommended_plugins',
5726 ]
5727 );
5728 }
5729
5730 // Do not Change Free/Pro Change for menu
5731 add_submenu_page(
5732 $menu_slug,
5733 esc_html__('Upgrade to Pro', 'folders'),
5734 esc_html__('Upgrade to Pro', 'folders'),
5735 'manage_options',
5736 'folders-upgrade-to-pro',
5737 [
5738 $this,
5739 'wcp_folders_upgrade_or_register',
5740 ]
5741 );
5742
5743 // Add menu for media cleaning
5744 $show_in_page = !isset($customize_folders['folders_media_cleaning']) ? "yes" : $customize_folders['folders_media_cleaning'];
5745
5746 if ($show_in_page == "yes") {
5747 add_submenu_page(
5748 "upload.php",
5749 esc_html__('Media Cleaning', 'folders'),
5750 esc_html__('Media Cleaning', 'folders'),
5751 'manage_options',
5752 'folders-media-cleaning',
5753 [
5754 $this,
5755 'wcp_folders_media_cleaning',
5756 ]
5757 );
5758 }
5759 }//end if
5760
5761 self::check_and_set_post_type();
5762
5763 $show_menu = get_option("folders_show_in_menu", true);
5764 if ($show_menu == "on") {
5765 self::create_menu_for_folders();
5766 }
5767
5768 }//end admin_menu()
5769
5770
5771 /**
5772 * Media Cleaner Page
5773 *
5774 * @since 1.0.0
5775 * @access public
5776 * @return $html
5777 */
5778 public function wcp_folders_media_cleaning()
5779 {
5780 include_once dirname(dirname(__FILE__))."/templates/admin/media-cleaning.php";
5781
5782 }//end wcp_folders_media_cleaning()
5783
5784
5785 /**
5786 * Recommended plugins Page
5787 *
5788 * @since 1.0.0
5789 * @access public
5790 * @return $html
5791 */
5792 public function recommended_plugins()
5793 {
5794 include_once dirname(dirname(__FILE__))."/templates/admin/recommended-plugins.php";
5795
5796 }//end recommended_plugins()
5797
5798
5799 /**
5800 * Folders Upgrade Page
5801 *
5802 * @since 1.0.0
5803 * @access public
5804 * @return $html
5805 */
5806 public function wcp_folders_upgrade_or_register()
5807 {
5808 self::set_default_values_if_not_exists();
5809 include_once dirname(dirname(__FILE__))."/templates/admin/upgrade-to-pro.php";
5810
5811 }//end wcp_folders_upgrade_or_register()
5812
5813
5814 /**
5815 * Folders Settings Page
5816 *
5817 * @since 1.0.0
5818 * @access public
5819 * @return $html
5820 */
5821 public function wcp_folders_settings()
5822 {
5823 self::set_default_values_if_not_exists();
5824 // Only in Free, Get Folders update confirmation popup
5825 $is_shown = get_option("folder_update_message");
5826 if ($is_shown === false) {
5827 include_once dirname(dirname(__FILE__))."/templates/admin/update.php";
5828 } else {
5829 $setting_page = filter_input(INPUT_GET, 'setting_page');
5830 if (empty($setting_page)) {
5831 $setting_page = "folder-settings";
5832 }
5833 if($setting_page == "upgrade-to-pro") {
5834 $hasBackButton = true;
5835 include_once dirname(dirname(__FILE__)) . "/templates/admin/upgrade-to-pro.php";
5836 } else {
5837 $options = get_option('folders_settings');
5838 $options = (empty($options) || !is_array($options)) ? [] : $options;
5839 $post_types = get_post_types(['public' => true], 'objects');
5840 $terms_data = [];
5841 foreach ($post_types as $post_type) {
5842 if (in_array($post_type->name, $options)) {
5843 $term = $post_type->name;
5844 $term = self::get_custom_post_type($term);
5845 $categories = self::get_terms_hierarchical($term);
5846 $terms_data[$post_type->name] = $categories;
5847 } else {
5848 $terms_data[$post_type->name] = [];
5849 }
5850 }
5851
5852 $fonts = self::get_font_list();
5853
5854 $plugins = new WCP_Folder_Plugins();
5855 $plugin_info = $plugins->get_plugin_information();
5856 $is_plugin_exists = $plugins->is_exists;
5857 $settingURL = $this->getFolderSettingsURL();
5858
5859 $setting_page = in_array($setting_page, ["folder-settings", "customize-folders", "folders-import", "upgrade-to-pro", "folders-by-user"]) ? $setting_page : "folder-settings";
5860 $isInSettings = $this->isFoldersInSettings();
5861
5862 include_once dirname(dirname(__FILE__)) . "/templates/admin/general-settings.php";
5863
5864 $option = get_option("folder_intro_box");
5865 if ($option == "show") {
5866 include_once dirname(dirname(__FILE__)) . "/templates/admin/folder-popup.php";
5867 }
5868 }
5869 }//end if
5870
5871 }//end wcp_folders_settings()
5872
5873
5874 /**
5875 * Font List
5876 *
5877 * @since 1.0.0
5878 * @access public
5879 * @return $fonts
5880 */
5881 public static function get_font_list()
5882 {
5883 return [
5884 // System fonts.
5885 'Default' => 'Default',
5886 "System Stack" => 'Default',
5887 'Arial' => 'Default',
5888 'Tahoma' => 'Default',
5889 'Verdana' => 'Default',
5890 'Helvetica' => 'Default',
5891 'Times New Roman' => 'Default',
5892 'Trebuchet MS' => 'Default',
5893 'Georgia' => 'Default',
5894
5895 // Google Fonts (last update: 23/10/2018).
5896 'ABeeZee' => 'Google Fonts',
5897 'Abel' => 'Google Fonts',
5898 'Abhaya Libre' => 'Google Fonts',
5899 'Abril Fatface' => 'Google Fonts',
5900 'Aclonica' => 'Google Fonts',
5901 'Acme' => 'Google Fonts',
5902 'Actor' => 'Google Fonts',
5903 'Adamina' => 'Google Fonts',
5904 'Advent Pro' => 'Google Fonts',
5905 'Aguafina Script' => 'Google Fonts',
5906 'Akronim' => 'Google Fonts',
5907 'Aladin' => 'Google Fonts',
5908 'Aldrich' => 'Google Fonts',
5909 'Alef' => 'Google Fonts',
5910 'Alef Hebrew' => 'Google Fonts',
5911 // Hack for Google Early Access.
5912 'Alegreya' => 'Google Fonts',
5913 'Alegreya SC' => 'Google Fonts',
5914 'Alegreya Sans' => 'Google Fonts',
5915 'Alegreya Sans SC' => 'Google Fonts',
5916 'Alex Brush' => 'Google Fonts',
5917 'Alfa Slab One' => 'Google Fonts',
5918 'Alice' => 'Google Fonts',
5919 'Alike' => 'Google Fonts',
5920 'Alike Angular' => 'Google Fonts',
5921 'Allan' => 'Google Fonts',
5922 'Allerta' => 'Google Fonts',
5923 'Allerta Stencil' => 'Google Fonts',
5924 'Allura' => 'Google Fonts',
5925 'Almendra' => 'Google Fonts',
5926 'Almendra Display' => 'Google Fonts',
5927 'Almendra SC' => 'Google Fonts',
5928 'Amarante' => 'Google Fonts',
5929 'Amaranth' => 'Google Fonts',
5930 'Amatic SC' => 'Google Fonts',
5931 'Amethysta' => 'Google Fonts',
5932 'Amiko' => 'Google Fonts',
5933 'Amiri' => 'Google Fonts',
5934 'Amita' => 'Google Fonts',
5935 'Anaheim' => 'Google Fonts',
5936 'Andada' => 'Google Fonts',
5937 'Andika' => 'Google Fonts',
5938 'Angkor' => 'Google Fonts',
5939 'Annie Use Your Telescope' => 'Google Fonts',
5940 'Anonymous Pro' => 'Google Fonts',
5941 'Antic' => 'Google Fonts',
5942 'Antic Didone' => 'Google Fonts',
5943 'Antic Slab' => 'Google Fonts',
5944 'Anton' => 'Google Fonts',
5945 'Arapey' => 'Google Fonts',
5946 'Arbutus' => 'Google Fonts',
5947 'Arbutus Slab' => 'Google Fonts',
5948 'Architects Daughter' => 'Google Fonts',
5949 'Archivo' => 'Google Fonts',
5950 'Archivo Black' => 'Google Fonts',
5951 'Archivo Narrow' => 'Google Fonts',
5952 'Aref Ruqaa' => 'Google Fonts',
5953 'Arima Madurai' => 'Google Fonts',
5954 'Arimo' => 'Google Fonts',
5955 'Arizonia' => 'Google Fonts',
5956 'Armata' => 'Google Fonts',
5957 'Arsenal' => 'Google Fonts',
5958 'Artifika' => 'Google Fonts',
5959 'Arvo' => 'Google Fonts',
5960 'Arya' => 'Google Fonts',
5961 'Asap' => 'Google Fonts',
5962 'Asap Condensed' => 'Google Fonts',
5963 'Asar' => 'Google Fonts',
5964 'Asset' => 'Google Fonts',
5965 'Assistant' => 'Google Fonts',
5966 'Astloch' => 'Google Fonts',
5967 'Asul' => 'Google Fonts',
5968 'Athiti' => 'Google Fonts',
5969 'Atma' => 'Google Fonts',
5970 'Atomic Age' => 'Google Fonts',
5971 'Aubrey' => 'Google Fonts',
5972 'Audiowide' => 'Google Fonts',
5973 'Autour One' => 'Google Fonts',
5974 'Average' => 'Google Fonts',
5975 'Average Sans' => 'Google Fonts',
5976 'Averia Gruesa Libre' => 'Google Fonts',
5977 'Averia Libre' => 'Google Fonts',
5978 'Averia Sans Libre' => 'Google Fonts',
5979 'Averia Serif Libre' => 'Google Fonts',
5980 'Bad Script' => 'Google Fonts',
5981 'Bahiana' => 'Google Fonts',
5982 'Bai Jamjuree' => 'Google Fonts',
5983 'Baloo' => 'Google Fonts',
5984 'Baloo Bhai' => 'Google Fonts',
5985 'Baloo Bhaijaan' => 'Google Fonts',
5986 'Baloo Bhaina' => 'Google Fonts',
5987 'Baloo Chettan' => 'Google Fonts',
5988 'Baloo Da' => 'Google Fonts',
5989 'Baloo Paaji' => 'Google Fonts',
5990 'Baloo Tamma' => 'Google Fonts',
5991 'Baloo Tammudu' => 'Google Fonts',
5992 'Baloo Thambi' => 'Google Fonts',
5993 'Balthazar' => 'Google Fonts',
5994 'Bangers' => 'Google Fonts',
5995 'Barlow' => 'Google Fonts',
5996 'Barlow Condensed' => 'Google Fonts',
5997 'Barlow Semi Condensed' => 'Google Fonts',
5998 'Barrio' => 'Google Fonts',
5999 'Basic' => 'Google Fonts',
6000 'Battambang' => 'Google Fonts',
6001 'Baumans' => 'Google Fonts',
6002 'Bayon' => 'Google Fonts',
6003 'Belgrano' => 'Google Fonts',
6004 'Bellefair' => 'Google Fonts',
6005 'Belleza' => 'Google Fonts',
6006 'BenchNine' => 'Google Fonts',
6007 'Bentham' => 'Google Fonts',
6008 'Berkshire Swash' => 'Google Fonts',
6009 'Bevan' => 'Google Fonts',
6010 'Bigelow Rules' => 'Google Fonts',
6011 'Bigshot One' => 'Google Fonts',
6012 'Bilbo' => 'Google Fonts',
6013 'Bilbo Swash Caps' => 'Google Fonts',
6014 'BioRhyme' => 'Google Fonts',
6015 'BioRhyme Expanded' => 'Google Fonts',
6016 'Biryani' => 'Google Fonts',
6017 'Bitter' => 'Google Fonts',
6018 'Black And White Picture' => 'Google Fonts',
6019 'Black Han Sans' => 'Google Fonts',
6020 'Black Ops One' => 'Google Fonts',
6021 'Bokor' => 'Google Fonts',
6022 'Bonbon' => 'Google Fonts',
6023 'Boogaloo' => 'Google Fonts',
6024 'Bowlby One' => 'Google Fonts',
6025 'Bowlby One SC' => 'Google Fonts',
6026 'Brawler' => 'Google Fonts',
6027 'Bree Serif' => 'Google Fonts',
6028 'Bubblegum Sans' => 'Google Fonts',
6029 'Bubbler One' => 'Google Fonts',
6030 'Buda' => 'Google Fonts',
6031 'Buenard' => 'Google Fonts',
6032 'Bungee' => 'Google Fonts',
6033 'Bungee Hairline' => 'Google Fonts',
6034 'Bungee Inline' => 'Google Fonts',
6035 'Bungee Outline' => 'Google Fonts',
6036 'Bungee Shade' => 'Google Fonts',
6037 'Butcherman' => 'Google Fonts',
6038 'Butterfly Kids' => 'Google Fonts',
6039 'Cabin' => 'Google Fonts',
6040 'Cabin Condensed' => 'Google Fonts',
6041 'Cabin Sketch' => 'Google Fonts',
6042 'Caesar Dressing' => 'Google Fonts',
6043 'Cagliostro' => 'Google Fonts',
6044 'Cairo' => 'Google Fonts',
6045 'Calligraffitti' => 'Google Fonts',
6046 'Cambay' => 'Google Fonts',
6047 'Cambo' => 'Google Fonts',
6048 'Candal' => 'Google Fonts',
6049 'Cantarell' => 'Google Fonts',
6050 'Cantata One' => 'Google Fonts',
6051 'Cantora One' => 'Google Fonts',
6052 'Capriola' => 'Google Fonts',
6053 'Cardo' => 'Google Fonts',
6054 'Carme' => 'Google Fonts',
6055 'Carrois Gothic' => 'Google Fonts',
6056 'Carrois Gothic SC' => 'Google Fonts',
6057 'Carter One' => 'Google Fonts',
6058 'Catamaran' => 'Google Fonts',
6059 'Caudex' => 'Google Fonts',
6060 'Caveat' => 'Google Fonts',
6061 'Caveat Brush' => 'Google Fonts',
6062 'Cedarville Cursive' => 'Google Fonts',
6063 'Ceviche One' => 'Google Fonts',
6064 'Chakra Petch' => 'Google Fonts',
6065 'Changa' => 'Google Fonts',
6066 'Changa One' => 'Google Fonts',
6067 'Chango' => 'Google Fonts',
6068 'Charmonman' => 'Google Fonts',
6069 'Chathura' => 'Google Fonts',
6070 'Chau Philomene One' => 'Google Fonts',
6071 'Chela One' => 'Google Fonts',
6072 'Chelsea Market' => 'Google Fonts',
6073 'Chenla' => 'Google Fonts',
6074 'Cherry Cream Soda' => 'Google Fonts',
6075 'Cherry Swash' => 'Google Fonts',
6076 'Chewy' => 'Google Fonts',
6077 'Chicle' => 'Google Fonts',
6078 'Chivo' => 'Google Fonts',
6079 'Chonburi' => 'Google Fonts',
6080 'Cinzel' => 'Google Fonts',
6081 'Cinzel Decorative' => 'Google Fonts',
6082 'Clicker Script' => 'Google Fonts',
6083 'Coda' => 'Google Fonts',
6084 'Coda Caption' => 'Google Fonts',
6085 'Codystar' => 'Google Fonts',
6086 'Coiny' => 'Google Fonts',
6087 'Combo' => 'Google Fonts',
6088 'Comfortaa' => 'Google Fonts',
6089 'Coming Soon' => 'Google Fonts',
6090 'Concert One' => 'Google Fonts',
6091 'Condiment' => 'Google Fonts',
6092 'Content' => 'Google Fonts',
6093 'Contrail One' => 'Google Fonts',
6094 'Convergence' => 'Google Fonts',
6095 'Cookie' => 'Google Fonts',
6096 'Copse' => 'Google Fonts',
6097 'Corben' => 'Google Fonts',
6098 'Cormorant' => 'Google Fonts',
6099 'Cormorant Garamond' => 'Google Fonts',
6100 'Cormorant Infant' => 'Google Fonts',
6101 'Cormorant SC' => 'Google Fonts',
6102 'Cormorant Unicase' => 'Google Fonts',
6103 'Cormorant Upright' => 'Google Fonts',
6104 'Courgette' => 'Google Fonts',
6105 'Cousine' => 'Google Fonts',
6106 'Coustard' => 'Google Fonts',
6107 'Covered By Your Grace' => 'Google Fonts',
6108 'Crafty Girls' => 'Google Fonts',
6109 'Creepster' => 'Google Fonts',
6110 'Crete Round' => 'Google Fonts',
6111 'Crimson Text' => 'Google Fonts',
6112 'Croissant One' => 'Google Fonts',
6113 'Crushed' => 'Google Fonts',
6114 'Cuprum' => 'Google Fonts',
6115 'Cute Font' => 'Google Fonts',
6116 'Cutive' => 'Google Fonts',
6117 'Cutive Mono' => 'Google Fonts',
6118 'Damion' => 'Google Fonts',
6119 'Dancing Script' => 'Google Fonts',
6120 'Dangrek' => 'Google Fonts',
6121 'David Libre' => 'Google Fonts',
6122 'Dawning of a New Day' => 'Google Fonts',
6123 'Days One' => 'Google Fonts',
6124 'Dekko' => 'Google Fonts',
6125 'Delius' => 'Google Fonts',
6126 'Delius Swash Caps' => 'Google Fonts',
6127 'Delius Unicase' => 'Google Fonts',
6128 'Della Respira' => 'Google Fonts',
6129 'Denk One' => 'Google Fonts',
6130 'Devonshire' => 'Google Fonts',
6131 'Dhurjati' => 'Google Fonts',
6132 'Didact Gothic' => 'Google Fonts',
6133 'Diplomata' => 'Google Fonts',
6134 'Diplomata SC' => 'Google Fonts',
6135 'Do Hyeon' => 'Google Fonts',
6136 'Dokdo' => 'Google Fonts',
6137 'Domine' => 'Google Fonts',
6138 'Donegal One' => 'Google Fonts',
6139 'Doppio One' => 'Google Fonts',
6140 'Dorsa' => 'Google Fonts',
6141 'Dosis' => 'Google Fonts',
6142 'Dr Sugiyama' => 'Google Fonts',
6143 'Droid Arabic Kufi' => 'Google Fonts',
6144 // Hack for Google Early Access.
6145 'Droid Arabic Naskh' => 'Google Fonts',
6146 // Hack for Google Early Access.
6147 'Duru Sans' => 'Google Fonts',
6148 'Dynalight' => 'Google Fonts',
6149 'EB Garamond' => 'Google Fonts',
6150 'Eagle Lake' => 'Google Fonts',
6151 'East Sea Dokdo' => 'Google Fonts',
6152 'Eater' => 'Google Fonts',
6153 'Economica' => 'Google Fonts',
6154 'Eczar' => 'Google Fonts',
6155 'El Messiri' => 'Google Fonts',
6156 'Electrolize' => 'Google Fonts',
6157 'Elsie' => 'Google Fonts',
6158 'Elsie Swash Caps' => 'Google Fonts',
6159 'Emblema One' => 'Google Fonts',
6160 'Emilys Candy' => 'Google Fonts',
6161 'Encode Sans' => 'Google Fonts',
6162 'Encode Sans Condensed' => 'Google Fonts',
6163 'Encode Sans Expanded' => 'Google Fonts',
6164 'Encode Sans Semi Condensed' => 'Google Fonts',
6165 'Encode Sans Semi Expanded' => 'Google Fonts',
6166 'Engagement' => 'Google Fonts',
6167 'Englebert' => 'Google Fonts',
6168 'Enriqueta' => 'Google Fonts',
6169 'Erica One' => 'Google Fonts',
6170 'Esteban' => 'Google Fonts',
6171 'Euphoria Script' => 'Google Fonts',
6172 'Ewert' => 'Google Fonts',
6173 'Exo' => 'Google Fonts',
6174 'Exo 2' => 'Google Fonts',
6175 'Expletus Sans' => 'Google Fonts',
6176 'Fahkwang' => 'Google Fonts',
6177 'Fanwood Text' => 'Google Fonts',
6178 'Farsan' => 'Google Fonts',
6179 'Fascinate' => 'Google Fonts',
6180 'Fascinate Inline' => 'Google Fonts',
6181 'Faster One' => 'Google Fonts',
6182 'Fasthand' => 'Google Fonts',
6183 'Fauna One' => 'Google Fonts',
6184 'Faustina' => 'Google Fonts',
6185 'Federant' => 'Google Fonts',
6186 'Federo' => 'Google Fonts',
6187 'Felipa' => 'Google Fonts',
6188 'Fenix' => 'Google Fonts',
6189 'Finger Paint' => 'Google Fonts',
6190 'Fira Mono' => 'Google Fonts',
6191 'Fira Sans' => 'Google Fonts',
6192 'Fira Sans Condensed' => 'Google Fonts',
6193 'Fira Sans Extra Condensed' => 'Google Fonts',
6194 'Fjalla One' => 'Google Fonts',
6195 'Fjord One' => 'Google Fonts',
6196 'Flamenco' => 'Google Fonts',
6197 'Flavors' => 'Google Fonts',
6198 'Fondamento' => 'Google Fonts',
6199 'Fontdiner Swanky' => 'Google Fonts',
6200 'Forum' => 'Google Fonts',
6201 'Francois One' => 'Google Fonts',
6202 'Frank Ruhl Libre' => 'Google Fonts',
6203 'Freckle Face' => 'Google Fonts',
6204 'Fredericka the Great' => 'Google Fonts',
6205 'Fredoka One' => 'Google Fonts',
6206 'Freehand' => 'Google Fonts',
6207 'Fresca' => 'Google Fonts',
6208 'Frijole' => 'Google Fonts',
6209 'Fruktur' => 'Google Fonts',
6210 'Fugaz One' => 'Google Fonts',
6211 'GFS Didot' => 'Google Fonts',
6212 'GFS Neohellenic' => 'Google Fonts',
6213 'Gabriela' => 'Google Fonts',
6214 'Gaegu' => 'Google Fonts',
6215 'Gafata' => 'Google Fonts',
6216 'Galada' => 'Google Fonts',
6217 'Galdeano' => 'Google Fonts',
6218 'Galindo' => 'Google Fonts',
6219 'Gamja Flower' => 'Google Fonts',
6220 'Gentium Basic' => 'Google Fonts',
6221 'Gentium Book Basic' => 'Google Fonts',
6222 'Geo' => 'Google Fonts',
6223 'Geostar' => 'Google Fonts',
6224 'Geostar Fill' => 'Google Fonts',
6225 'Germania One' => 'Google Fonts',
6226 'Gidugu' => 'Google Fonts',
6227 'Gilda Display' => 'Google Fonts',
6228 'Give You Glory' => 'Google Fonts',
6229 'Glass Antiqua' => 'Google Fonts',
6230 'Glegoo' => 'Google Fonts',
6231 'Gloria Hallelujah' => 'Google Fonts',
6232 'Goblin One' => 'Google Fonts',
6233 'Gochi Hand' => 'Google Fonts',
6234 'Gorditas' => 'Google Fonts',
6235 'Gothic A1' => 'Google Fonts',
6236 'Goudy Bookletter 1911' => 'Google Fonts',
6237 'Graduate' => 'Google Fonts',
6238 'Grand Hotel' => 'Google Fonts',
6239 'Gravitas One' => 'Google Fonts',
6240 'Great Vibes' => 'Google Fonts',
6241 'Griffy' => 'Google Fonts',
6242 'Gruppo' => 'Google Fonts',
6243 'Gudea' => 'Google Fonts',
6244 'Gugi' => 'Google Fonts',
6245 'Gurajada' => 'Google Fonts',
6246 'Habibi' => 'Google Fonts',
6247 'Halant' => 'Google Fonts',
6248 'Hammersmith One' => 'Google Fonts',
6249 'Hanalei' => 'Google Fonts',
6250 'Hanalei Fill' => 'Google Fonts',
6251 'Handlee' => 'Google Fonts',
6252 'Hanuman' => 'Google Fonts',
6253 'Happy Monkey' => 'Google Fonts',
6254 'Harmattan' => 'Google Fonts',
6255 'Headland One' => 'Google Fonts',
6256 'Heebo' => 'Google Fonts',
6257 'Henny Penny' => 'Google Fonts',
6258 'Herr Von Muellerhoff' => 'Google Fonts',
6259 'Hi Melody' => 'Google Fonts',
6260 'Hind' => 'Google Fonts',
6261 'Hind Guntur' => 'Google Fonts',
6262 'Hind Madurai' => 'Google Fonts',
6263 'Hind Siliguri' => 'Google Fonts',
6264 'Hind Vadodara' => 'Google Fonts',
6265 'Holtwood One SC' => 'Google Fonts',
6266 'Homemade Apple' => 'Google Fonts',
6267 'Homenaje' => 'Google Fonts',
6268 'IBM Plex Mono' => 'Google Fonts',
6269 'IBM Plex Sans' => 'Google Fonts',
6270 'IBM Plex Sans Condensed' => 'Google Fonts',
6271 'IBM Plex Serif' => 'Google Fonts',
6272 'IM Fell DW Pica' => 'Google Fonts',
6273 'IM Fell DW Pica SC' => 'Google Fonts',
6274 'IM Fell Double Pica' => 'Google Fonts',
6275 'IM Fell Double Pica SC' => 'Google Fonts',
6276 'IM Fell English' => 'Google Fonts',
6277 'IM Fell English SC' => 'Google Fonts',
6278 'IM Fell French Canon' => 'Google Fonts',
6279 'IM Fell French Canon SC' => 'Google Fonts',
6280 'IM Fell Great Primer' => 'Google Fonts',
6281 'IM Fell Great Primer SC' => 'Google Fonts',
6282 'Iceberg' => 'Google Fonts',
6283 'Iceland' => 'Google Fonts',
6284 'Imprima' => 'Google Fonts',
6285 'Inconsolata' => 'Google Fonts',
6286 'Inder' => 'Google Fonts',
6287 'Indie Flower' => 'Google Fonts',
6288 'Inika' => 'Google Fonts',
6289 'Inknut Antiqua' => 'Google Fonts',
6290 'Irish Grover' => 'Google Fonts',
6291 'Istok Web' => 'Google Fonts',
6292 'Italiana' => 'Google Fonts',
6293 'Italianno' => 'Google Fonts',
6294 'Itim' => 'Google Fonts',
6295 'Jacques Francois' => 'Google Fonts',
6296 'Jacques Francois Shadow' => 'Google Fonts',
6297 'Jaldi' => 'Google Fonts',
6298 'Jim Nightshade' => 'Google Fonts',
6299 'Jockey One' => 'Google Fonts',
6300 'Jolly Lodger' => 'Google Fonts',
6301 'Jomhuria' => 'Google Fonts',
6302 'Josefin Sans' => 'Google Fonts',
6303 'Josefin Slab' => 'Google Fonts',
6304 'Joti One' => 'Google Fonts',
6305 'Jua' => 'Google Fonts',
6306 'Judson' => 'Google Fonts',
6307 'Julee' => 'Google Fonts',
6308 'Julius Sans One' => 'Google Fonts',
6309 'Junge' => 'Google Fonts',
6310 'Jura' => 'Google Fonts',
6311 'Just Another Hand' => 'Google Fonts',
6312 'Just Me Again Down Here' => 'Google Fonts',
6313 'K2D' => 'Google Fonts',
6314 'Kadwa' => 'Google Fonts',
6315 'Kalam' => 'Google Fonts',
6316 'Kameron' => 'Google Fonts',
6317 'Kanit' => 'Google Fonts',
6318 'Kantumruy' => 'Google Fonts',
6319 'Karla' => 'Google Fonts',
6320 'Karma' => 'Google Fonts',
6321 'Katibeh' => 'Google Fonts',
6322 'Kaushan Script' => 'Google Fonts',
6323 'Kavivanar' => 'Google Fonts',
6324 'Kavoon' => 'Google Fonts',
6325 'Kdam Thmor' => 'Google Fonts',
6326 'Keania One' => 'Google Fonts',
6327 'Kelly Slab' => 'Google Fonts',
6328 'Kenia' => 'Google Fonts',
6329 'Khand' => 'Google Fonts',
6330 'Khmer' => 'Google Fonts',
6331 'Khula' => 'Google Fonts',
6332 'Kirang Haerang' => 'Google Fonts',
6333 'Kite One' => 'Google Fonts',
6334 'Knewave' => 'Google Fonts',
6335 'KoHo' => 'Google Fonts',
6336 'Kodchasan' => 'Google Fonts',
6337 'Kosugi' => 'Google Fonts',
6338 'Kosugi Maru' => 'Google Fonts',
6339 'Kotta One' => 'Google Fonts',
6340 'Koulen' => 'Google Fonts',
6341 'Kranky' => 'Google Fonts',
6342 'Kreon' => 'Google Fonts',
6343 'Kristi' => 'Google Fonts',
6344 'Krona One' => 'Google Fonts',
6345 'Krub' => 'Google Fonts',
6346 'Kumar One' => 'Google Fonts',
6347 'Kumar One Outline' => 'Google Fonts',
6348 'Kurale' => 'Google Fonts',
6349 'La Belle Aurore' => 'Google Fonts',
6350 'Laila' => 'Google Fonts',
6351 'Lakki Reddy' => 'Google Fonts',
6352 'Lalezar' => 'Google Fonts',
6353 'Lancelot' => 'Google Fonts',
6354 'Lateef' => 'Google Fonts',
6355 'Lato' => 'Google Fonts',
6356 'League Script' => 'Google Fonts',
6357 'Leckerli One' => 'Google Fonts',
6358 'Ledger' => 'Google Fonts',
6359 'Lekton' => 'Google Fonts',
6360 'Lemon' => 'Google Fonts',
6361 'Lemonada' => 'Google Fonts',
6362 'Libre Barcode 128' => 'Google Fonts',
6363 'Libre Barcode 128 Text' => 'Google Fonts',
6364 'Libre Barcode 39' => 'Google Fonts',
6365 'Libre Barcode 39 Extended' => 'Google Fonts',
6366 'Libre Barcode 39 Extended Text' => 'Google Fonts',
6367 'Libre Barcode 39 Text' => 'Google Fonts',
6368 'Libre Baskerville' => 'Google Fonts',
6369 'Libre Franklin' => 'Google Fonts',
6370 'Life Savers' => 'Google Fonts',
6371 'Lilita One' => 'Google Fonts',
6372 'Lily Script One' => 'Google Fonts',
6373 'Limelight' => 'Google Fonts',
6374 'Linden Hill' => 'Google Fonts',
6375 'Lobster' => 'Google Fonts',
6376 'Lobster Two' => 'Google Fonts',
6377 'Londrina Outline' => 'Google Fonts',
6378 'Londrina Shadow' => 'Google Fonts',
6379 'Londrina Sketch' => 'Google Fonts',
6380 'Londrina Solid' => 'Google Fonts',
6381 'Lora' => 'Google Fonts',
6382 'Love Ya Like A Sister' => 'Google Fonts',
6383 'Loved by the King' => 'Google Fonts',
6384 'Lovers Quarrel' => 'Google Fonts',
6385 'Luckiest Guy' => 'Google Fonts',
6386 'Lusitana' => 'Google Fonts',
6387 'Lustria' => 'Google Fonts',
6388 'M PLUS 1p' => 'Google Fonts',
6389 'M PLUS Rounded 1c' => 'Google Fonts',
6390 'Macondo' => 'Google Fonts',
6391 'Macondo Swash Caps' => 'Google Fonts',
6392 'Mada' => 'Google Fonts',
6393 'Magra' => 'Google Fonts',
6394 'Maiden Orange' => 'Google Fonts',
6395 'Maitree' => 'Google Fonts',
6396 'Mako' => 'Google Fonts',
6397 'Mali' => 'Google Fonts',
6398 'Mallanna' => 'Google Fonts',
6399 'Mandali' => 'Google Fonts',
6400 'Manuale' => 'Google Fonts',
6401 'Marcellus' => 'Google Fonts',
6402 'Marcellus SC' => 'Google Fonts',
6403 'Marck Script' => 'Google Fonts',
6404 'Margarine' => 'Google Fonts',
6405 'Markazi Text' => 'Google Fonts',
6406 'Marko One' => 'Google Fonts',
6407 'Marmelad' => 'Google Fonts',
6408 'Martel' => 'Google Fonts',
6409 'Martel Sans' => 'Google Fonts',
6410 'Marvel' => 'Google Fonts',
6411 'Mate' => 'Google Fonts',
6412 'Mate SC' => 'Google Fonts',
6413 'Maven Pro' => 'Google Fonts',
6414 'McLaren' => 'Google Fonts',
6415 'Meddon' => 'Google Fonts',
6416 'MedievalSharp' => 'Google Fonts',
6417 'Medula One' => 'Google Fonts',
6418 'Meera Inimai' => 'Google Fonts',
6419 'Megrim' => 'Google Fonts',
6420 'Meie Script' => 'Google Fonts',
6421 'Merienda' => 'Google Fonts',
6422 'Merienda One' => 'Google Fonts',
6423 'Merriweather' => 'Google Fonts',
6424 'Merriweather Sans' => 'Google Fonts',
6425 'Metal' => 'Google Fonts',
6426 'Metal Mania' => 'Google Fonts',
6427 'Metamorphous' => 'Google Fonts',
6428 'Metrophobic' => 'Google Fonts',
6429 'Michroma' => 'Google Fonts',
6430 'Milonga' => 'Google Fonts',
6431 'Miltonian' => 'Google Fonts',
6432 'Miltonian Tattoo' => 'Google Fonts',
6433 'Mina' => 'Google Fonts',
6434 'Miniver' => 'Google Fonts',
6435 'Miriam Libre' => 'Google Fonts',
6436 'Mirza' => 'Google Fonts',
6437 'Miss Fajardose' => 'Google Fonts',
6438 'Mitr' => 'Google Fonts',
6439 'Modak' => 'Google Fonts',
6440 'Modern Antiqua' => 'Google Fonts',
6441 'Mogra' => 'Google Fonts',
6442 'Molengo' => 'Google Fonts',
6443 'Molle' => 'Google Fonts',
6444 'Monda' => 'Google Fonts',
6445 'Monofett' => 'Google Fonts',
6446 'Monoton' => 'Google Fonts',
6447 'Monsieur La Doulaise' => 'Google Fonts',
6448 'Montaga' => 'Google Fonts',
6449 'Montez' => 'Google Fonts',
6450 'Montserrat' => 'Google Fonts',
6451 'Montserrat Alternates' => 'Google Fonts',
6452 'Montserrat Subrayada' => 'Google Fonts',
6453 'Moul' => 'Google Fonts',
6454 'Moulpali' => 'Google Fonts',
6455 'Mountains of Christmas' => 'Google Fonts',
6456 'Mouse Memoirs' => 'Google Fonts',
6457 'Mr Bedfort' => 'Google Fonts',
6458 'Mr Dafoe' => 'Google Fonts',
6459 'Mr De Haviland' => 'Google Fonts',
6460 'Mrs Saint Delafield' => 'Google Fonts',
6461 'Mrs Sheppards' => 'Google Fonts',
6462 'Mukta' => 'Google Fonts',
6463 'Mukta Mahee' => 'Google Fonts',
6464 'Mukta Malar' => 'Google Fonts',
6465 'Mukta Vaani' => 'Google Fonts',
6466 'Muli' => 'Google Fonts',
6467 'Mystery Quest' => 'Google Fonts',
6468 'NTR' => 'Google Fonts',
6469 'Nanum Brush Script' => 'Google Fonts',
6470 'Nanum Gothic' => 'Google Fonts',
6471 'Nanum Gothic Coding' => 'Google Fonts',
6472 'Nanum Myeongjo' => 'Google Fonts',
6473 'Nanum Pen Script' => 'Google Fonts',
6474 'Neucha' => 'Google Fonts',
6475 'Neuton' => 'Google Fonts',
6476 'New Rocker' => 'Google Fonts',
6477 'News Cycle' => 'Google Fonts',
6478 'Niconne' => 'Google Fonts',
6479 'Niramit' => 'Google Fonts',
6480 'Nixie One' => 'Google Fonts',
6481 'Nobile' => 'Google Fonts',
6482 'Nokora' => 'Google Fonts',
6483 'Norican' => 'Google Fonts',
6484 'Nosifer' => 'Google Fonts',
6485 'Notable' => 'Google Fonts',
6486 'Nothing You Could Do' => 'Google Fonts',
6487 'Noticia Text' => 'Google Fonts',
6488 'Noto Kufi Arabic' => 'Google Fonts',
6489 // Hack for Google Early Access.
6490 'Noto Naskh Arabic' => 'Google Fonts',
6491 // Hack for Google Early Access.
6492 'Noto Sans' => 'Google Fonts',
6493 'Noto Sans Hebrew' => 'Google Fonts',
6494 // Hack for Google Early Access.
6495 'Noto Sans JP' => 'Google Fonts',
6496 'Noto Sans KR' => 'Google Fonts',
6497 'Noto Serif' => 'Google Fonts',
6498 'Noto Serif JP' => 'Google Fonts',
6499 'Noto Serif KR' => 'Google Fonts',
6500 'Nova Cut' => 'Google Fonts',
6501 'Nova Flat' => 'Google Fonts',
6502 'Nova Mono' => 'Google Fonts',
6503 'Nova Oval' => 'Google Fonts',
6504 'Nova Round' => 'Google Fonts',
6505 'Nova Script' => 'Google Fonts',
6506 'Nova Slim' => 'Google Fonts',
6507 'Nova Square' => 'Google Fonts',
6508 'Numans' => 'Google Fonts',
6509 'Nunito' => 'Google Fonts',
6510 'Nunito Sans' => 'Google Fonts',
6511 'Odor Mean Chey' => 'Google Fonts',
6512 'Offside' => 'Google Fonts',
6513 'Old Standard TT' => 'Google Fonts',
6514 'Oldenburg' => 'Google Fonts',
6515 'Oleo Script' => 'Google Fonts',
6516 'Oleo Script Swash Caps' => 'Google Fonts',
6517 'Open Sans' => 'Google Fonts',
6518 'Open Sans Condensed' => 'Google Fonts',
6519 'Open Sans Hebrew' => 'Google Fonts',
6520 // Hack for Google Early Access.
6521 'Open Sans Hebrew Condensed' => 'Google Fonts',
6522 // Hack for Google Early Access.
6523 'Oranienbaum' => 'Google Fonts',
6524 'Orbitron' => 'Google Fonts',
6525 'Oregano' => 'Google Fonts',
6526 'Orienta' => 'Google Fonts',
6527 'Original Surfer' => 'Google Fonts',
6528 'Oswald' => 'Google Fonts',
6529 'Over the Rainbow' => 'Google Fonts',
6530 'Overlock' => 'Google Fonts',
6531 'Overlock SC' => 'Google Fonts',
6532 'Overpass' => 'Google Fonts',
6533 'Overpass Mono' => 'Google Fonts',
6534 'Ovo' => 'Google Fonts',
6535 'Oxygen' => 'Google Fonts',
6536 'Oxygen Mono' => 'Google Fonts',
6537 'PT Mono' => 'Google Fonts',
6538 'PT Sans' => 'Google Fonts',
6539 'PT Sans Caption' => 'Google Fonts',
6540 'PT Sans Narrow' => 'Google Fonts',
6541 'PT Serif' => 'Google Fonts',
6542 'PT Serif Caption' => 'Google Fonts',
6543 'Pacifico' => 'Google Fonts',
6544 'Padauk' => 'Google Fonts',
6545 'Palanquin' => 'Google Fonts',
6546 'Palanquin Dark' => 'Google Fonts',
6547 'Pangolin' => 'Google Fonts',
6548 'Paprika' => 'Google Fonts',
6549 'Parisienne' => 'Google Fonts',
6550 'Passero One' => 'Google Fonts',
6551 'Passion One' => 'Google Fonts',
6552 'Pathway Gothic One' => 'Google Fonts',
6553 'Patrick Hand' => 'Google Fonts',
6554 'Patrick Hand SC' => 'Google Fonts',
6555 'Pattaya' => 'Google Fonts',
6556 'Patua One' => 'Google Fonts',
6557 'Pavanam' => 'Google Fonts',
6558 'Paytone One' => 'Google Fonts',
6559 'Peddana' => 'Google Fonts',
6560 'Peralta' => 'Google Fonts',
6561 'Permanent Marker' => 'Google Fonts',
6562 'Petit Formal Script' => 'Google Fonts',
6563 'Petrona' => 'Google Fonts',
6564 'Philosopher' => 'Google Fonts',
6565 'Piedra' => 'Google Fonts',
6566 'Pinyon Script' => 'Google Fonts',
6567 'Pirata One' => 'Google Fonts',
6568 'Plaster' => 'Google Fonts',
6569 'Play' => 'Google Fonts',
6570 'Playball' => 'Google Fonts',
6571 'Playfair Display' => 'Google Fonts',
6572 'Playfair Display SC' => 'Google Fonts',
6573 'Podkova' => 'Google Fonts',
6574 'Poiret One' => 'Google Fonts',
6575 'Poller One' => 'Google Fonts',
6576 'Poly' => 'Google Fonts',
6577 'Pompiere' => 'Google Fonts',
6578 'Pontano Sans' => 'Google Fonts',
6579 'Poor Story' => 'Google Fonts',
6580 'Poppins' => 'Google Fonts',
6581 'Port Lligat Sans' => 'Google Fonts',
6582 'Port Lligat Slab' => 'Google Fonts',
6583 'Pragati Narrow' => 'Google Fonts',
6584 'Prata' => 'Google Fonts',
6585 'Preahvihear' => 'Google Fonts',
6586 'Press Start 2P' => 'Google Fonts',
6587 'Pridi' => 'Google Fonts',
6588 'Princess Sofia' => 'Google Fonts',
6589 'Prociono' => 'Google Fonts',
6590 'Prompt' => 'Google Fonts',
6591 'Prosto One' => 'Google Fonts',
6592 'Proza Libre' => 'Google Fonts',
6593 'Puritan' => 'Google Fonts',
6594 'Purple Purse' => 'Google Fonts',
6595 'Quando' => 'Google Fonts',
6596 'Quantico' => 'Google Fonts',
6597 'Quattrocento' => 'Google Fonts',
6598 'Quattrocento Sans' => 'Google Fonts',
6599 'Questrial' => 'Google Fonts',
6600 'Quicksand' => 'Google Fonts',
6601 'Quintessential' => 'Google Fonts',
6602 'Qwigley' => 'Google Fonts',
6603 'Racing Sans One' => 'Google Fonts',
6604 'Radley' => 'Google Fonts',
6605 'Rajdhani' => 'Google Fonts',
6606 'Rakkas' => 'Google Fonts',
6607 'Raleway' => 'Google Fonts',
6608 'Raleway Dots' => 'Google Fonts',
6609 'Ramabhadra' => 'Google Fonts',
6610 'Ramaraja' => 'Google Fonts',
6611 'Rambla' => 'Google Fonts',
6612 'Rammetto One' => 'Google Fonts',
6613 'Ranchers' => 'Google Fonts',
6614 'Rancho' => 'Google Fonts',
6615 'Ranga' => 'Google Fonts',
6616 'Rasa' => 'Google Fonts',
6617 'Rationale' => 'Google Fonts',
6618 'Ravi Prakash' => 'Google Fonts',
6619 'Redressed' => 'Google Fonts',
6620 'Reem Kufi' => 'Google Fonts',
6621 'Reenie Beanie' => 'Google Fonts',
6622 'Revalia' => 'Google Fonts',
6623 'Rhodium Libre' => 'Google Fonts',
6624 'Ribeye' => 'Google Fonts',
6625 'Ribeye Marrow' => 'Google Fonts',
6626 'Righteous' => 'Google Fonts',
6627 'Risque' => 'Google Fonts',
6628 'Roboto' => 'Google Fonts',
6629 'Roboto Condensed' => 'Google Fonts',
6630 'Roboto Mono' => 'Google Fonts',
6631 'Roboto Slab' => 'Google Fonts',
6632 'Rochester' => 'Google Fonts',
6633 'Rock Salt' => 'Google Fonts',
6634 'Rokkitt' => 'Google Fonts',
6635 'Romanesco' => 'Google Fonts',
6636 'Ropa Sans' => 'Google Fonts',
6637 'Rosario' => 'Google Fonts',
6638 'Rosarivo' => 'Google Fonts',
6639 'Rouge Script' => 'Google Fonts',
6640 'Rozha One' => 'Google Fonts',
6641 'Rubik' => 'Google Fonts',
6642 'Rubik Mono One' => 'Google Fonts',
6643 'Ruda' => 'Google Fonts',
6644 'Rufina' => 'Google Fonts',
6645 'Ruge Boogie' => 'Google Fonts',
6646 'Ruluko' => 'Google Fonts',
6647 'Rum Raisin' => 'Google Fonts',
6648 'Ruslan Display' => 'Google Fonts',
6649 'Russo One' => 'Google Fonts',
6650 'Ruthie' => 'Google Fonts',
6651 'Rye' => 'Google Fonts',
6652 'Sacramento' => 'Google Fonts',
6653 'Sahitya' => 'Google Fonts',
6654 'Sail' => 'Google Fonts',
6655 'Saira' => 'Google Fonts',
6656 'Saira Condensed' => 'Google Fonts',
6657 'Saira Extra Condensed' => 'Google Fonts',
6658 'Saira Semi Condensed' => 'Google Fonts',
6659 'Salsa' => 'Google Fonts',
6660 'Sanchez' => 'Google Fonts',
6661 'Sancreek' => 'Google Fonts',
6662 'Sansita' => 'Google Fonts',
6663 'Sarala' => 'Google Fonts',
6664 'Sarina' => 'Google Fonts',
6665 'Sarpanch' => 'Google Fonts',
6666 'Satisfy' => 'Google Fonts',
6667 'Sawarabi Gothic' => 'Google Fonts',
6668 'Sawarabi Mincho' => 'Google Fonts',
6669 'Scada' => 'Google Fonts',
6670 'Scheherazade' => 'Google Fonts',
6671 'Schoolbell' => 'Google Fonts',
6672 'Scope One' => 'Google Fonts',
6673 'Seaweed Script' => 'Google Fonts',
6674 'Secular One' => 'Google Fonts',
6675 'Sedgwick Ave' => 'Google Fonts',
6676 'Sedgwick Ave Display' => 'Google Fonts',
6677 'Sevillana' => 'Google Fonts',
6678 'Seymour One' => 'Google Fonts',
6679 'Shadows Into Light' => 'Google Fonts',
6680 'Shadows Into Light Two' => 'Google Fonts',
6681 'Shanti' => 'Google Fonts',
6682 'Share' => 'Google Fonts',
6683 'Share Tech' => 'Google Fonts',
6684 'Share Tech Mono' => 'Google Fonts',
6685 'Shojumaru' => 'Google Fonts',
6686 'Short Stack' => 'Google Fonts',
6687 'Shrikhand' => 'Google Fonts',
6688 'Siemreap' => 'Google Fonts',
6689 'Sigmar One' => 'Google Fonts',
6690 'Signika' => 'Google Fonts',
6691 'Signika Negative' => 'Google Fonts',
6692 'Simonetta' => 'Google Fonts',
6693 'Sintony' => 'Google Fonts',
6694 'Sirin Stencil' => 'Google Fonts',
6695 'Six Caps' => 'Google Fonts',
6696 'Skranji' => 'Google Fonts',
6697 'Slabo 13px' => 'Google Fonts',
6698 'Slabo 27px' => 'Google Fonts',
6699 'Slackey' => 'Google Fonts',
6700 'Smokum' => 'Google Fonts',
6701 'Smythe' => 'Google Fonts',
6702 'Sniglet' => 'Google Fonts',
6703 'Snippet' => 'Google Fonts',
6704 'Snowburst One' => 'Google Fonts',
6705 'Sofadi One' => 'Google Fonts',
6706 'Sofia' => 'Google Fonts',
6707 'Song Myung' => 'Google Fonts',
6708 'Sonsie One' => 'Google Fonts',
6709 'Sorts Mill Goudy' => 'Google Fonts',
6710 'Source Code Pro' => 'Google Fonts',
6711 'Source Sans Pro' => 'Google Fonts',
6712 'Source Serif Pro' => 'Google Fonts',
6713 'Space Mono' => 'Google Fonts',
6714 'Special Elite' => 'Google Fonts',
6715 'Spectral' => 'Google Fonts',
6716 'Spectral SC' => 'Google Fonts',
6717 'Spicy Rice' => 'Google Fonts',
6718 'Spinnaker' => 'Google Fonts',
6719 'Spirax' => 'Google Fonts',
6720 'Squada One' => 'Google Fonts',
6721 'Sree Krushnadevaraya' => 'Google Fonts',
6722 'Sriracha' => 'Google Fonts',
6723 'Srisakdi' => 'Google Fonts',
6724 'Stalemate' => 'Google Fonts',
6725 'Stalinist One' => 'Google Fonts',
6726 'Stardos Stencil' => 'Google Fonts',
6727 'Stint Ultra Condensed' => 'Google Fonts',
6728 'Stint Ultra Expanded' => 'Google Fonts',
6729 'Stoke' => 'Google Fonts',
6730 'Strait' => 'Google Fonts',
6731 'Stylish' => 'Google Fonts',
6732 'Sue Ellen Francisco' => 'Google Fonts',
6733 'Suez One' => 'Google Fonts',
6734 'Sumana' => 'Google Fonts',
6735 'Sunflower' => 'Google Fonts',
6736 'Sunshiney' => 'Google Fonts',
6737 'Supermercado One' => 'Google Fonts',
6738 'Sura' => 'Google Fonts',
6739 'Suranna' => 'Google Fonts',
6740 'Suravaram' => 'Google Fonts',
6741 'Suwannaphum' => 'Google Fonts',
6742 'Swanky and Moo Moo' => 'Google Fonts',
6743 'Syncopate' => 'Google Fonts',
6744 'Tajawal' => 'Google Fonts',
6745 'Tangerine' => 'Google Fonts',
6746 'Taprom' => 'Google Fonts',
6747 'Tauri' => 'Google Fonts',
6748 'Taviraj' => 'Google Fonts',
6749 'Teko' => 'Google Fonts',
6750 'Telex' => 'Google Fonts',
6751 'Tenali Ramakrishna' => 'Google Fonts',
6752 'Tenor Sans' => 'Google Fonts',
6753 'Text Me One' => 'Google Fonts',
6754 'The Girl Next Door' => 'Google Fonts',
6755 'Tienne' => 'Google Fonts',
6756 'Tillana' => 'Google Fonts',
6757 'Timmana' => 'Google Fonts',
6758 'Tinos' => 'Google Fonts',
6759 'Titan One' => 'Google Fonts',
6760 'Titillium Web' => 'Google Fonts',
6761 'Trade Winds' => 'Google Fonts',
6762 'Trirong' => 'Google Fonts',
6763 'Trocchi' => 'Google Fonts',
6764 'Trochut' => 'Google Fonts',
6765 'Trykker' => 'Google Fonts',
6766 'Tulpen One' => 'Google Fonts',
6767 'Ubuntu' => 'Google Fonts',
6768 'Ubuntu Condensed' => 'Google Fonts',
6769 'Ubuntu Mono' => 'Google Fonts',
6770 'Ultra' => 'Google Fonts',
6771 'Uncial Antiqua' => 'Google Fonts',
6772 'Underdog' => 'Google Fonts',
6773 'Unica One' => 'Google Fonts',
6774 'UnifrakturCook' => 'Google Fonts',
6775 'UnifrakturMaguntia' => 'Google Fonts',
6776 'Unkempt' => 'Google Fonts',
6777 'Unlock' => 'Google Fonts',
6778 'Unna' => 'Google Fonts',
6779 'VT323' => 'Google Fonts',
6780 'Vampiro One' => 'Google Fonts',
6781 'Varela' => 'Google Fonts',
6782 'Varela Round' => 'Google Fonts',
6783 'Vast Shadow' => 'Google Fonts',
6784 'Vesper Libre' => 'Google Fonts',
6785 'Vibur' => 'Google Fonts',
6786 'Vidaloka' => 'Google Fonts',
6787 'Viga' => 'Google Fonts',
6788 'Voces' => 'Google Fonts',
6789 'Volkhov' => 'Google Fonts',
6790 'Vollkorn' => 'Google Fonts',
6791 'Vollkorn SC' => 'Google Fonts',
6792 'Voltaire' => 'Google Fonts',
6793 'Waiting for the Sunrise' => 'Google Fonts',
6794 'Wallpoet' => 'Google Fonts',
6795 'Walter Turncoat' => 'Google Fonts',
6796 'Warnes' => 'Google Fonts',
6797 'Wellfleet' => 'Google Fonts',
6798 'Wendy One' => 'Google Fonts',
6799 'Wire One' => 'Google Fonts',
6800 'Work Sans' => 'Google Fonts',
6801 'Yanone Kaffeesatz' => 'Google Fonts',
6802 'Yantramanav' => 'Google Fonts',
6803 'Yatra One' => 'Google Fonts',
6804 'Yellowtail' => 'Google Fonts',
6805 'Yeon Sung' => 'Google Fonts',
6806 'Yeseva One' => 'Google Fonts',
6807 'Yesteryear' => 'Google Fonts',
6808 'Yrsa' => 'Google Fonts',
6809 'Zeyada' => 'Google Fonts',
6810 'Zilla Slab' => 'Google Fonts',
6811 'Zilla Slab Highlight' => 'Google Fonts',
6812 ];
6813
6814 }//end get_font_list()
6815
6816
6817 /**
6818 * Set Default folder order if not exists
6819 *
6820 * @since 1.0.0
6821 * @access public
6822 * @return $fonts
6823 */
6824 public function set_default_values_if_not_exists()
6825 {
6826 if (is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
6827 $options = get_option('folders_settings');
6828 $options = empty($options) || !is_array($options) ? [] : $options;
6829 foreach ($options as $option) {
6830 $post_type = self::get_custom_post_type($option);
6831 $terms = get_terms(
6832 $post_type,
6833 [
6834 'hide_empty' => false,
6835 'meta_query' => [
6836 [
6837 'key' => 'wcp_custom_order',
6838 'compare' => 'NOT EXISTS',
6839 ],
6840 ],
6841 ]
6842 );
6843 if (!empty($terms)) {
6844 foreach ($terms as $term) {
6845 $order = get_term_meta($term->term_id, "wcp_custom_order", true);
6846 if (empty($order) || $order == null) {
6847 update_term_meta($term->term_id, "wcp_custom_order", "1");
6848 }
6849 }
6850 }
6851 }//end foreach
6852 }//end if
6853
6854 }//end set_default_values_if_not_exists()
6855
6856
6857 // Free and Pro major changes
6858
6859
6860 /**
6861 * Hide Folder intro Popup
6862 *
6863 * @since 1.0.0
6864 * @access public
6865 */
6866 public function premio_hide_child_popup()
6867 {
6868 $post_type = $this->getRequestVar('post_type');
6869 $nonce = $this->getRequestVar('nonce');
6870 if (!empty($post_type) && wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$post_type)) {
6871 $status = $this->getRequestVar('status');
6872 $status = ($status == 1) ? 1 : 0;
6873 if ($status) {
6874 add_option("premio_hide_child_popup", 1);
6875 } else {
6876 delete_option("premio_hide_child_popup");
6877 }
6878 }
6879
6880 echo esc_attr("1");
6881 die;
6882
6883 }//end premio_hide_child_popup()
6884
6885
6886 /**
6887 * Hide Folder intro Popup
6888 *
6889 * @since 1.0.0
6890 * @access public
6891 */
6892 public function folder_update_popup_status()
6893 {
6894 $nonce = $this->getRequestVar('nonce');
6895 if (!empty($nonce) && wp_verify_nonce($nonce, 'folder_update_popup_status')) {
6896 update_option("folder_intro_box", "hide");
6897 }
6898
6899 echo esc_attr("1");
6900 die;
6901
6902 }//end folder_update_popup_status()
6903
6904
6905 /**
6906 * Hide Folder import Popup
6907 *
6908 * @since 1.0.0
6909 * @access public
6910 */
6911 public function update_folders_import_status()
6912 {
6913 $nonce = $this->getRequestVar('nonce');
6914 if (!empty($nonce) && wp_verify_nonce($nonce, 'folders_import_3rd_party_data')) {
6915 update_option("folder_redirect_status", "3");
6916 }
6917
6918 echo esc_attr("1");
6919 die;
6920
6921 }//end update_folders_import_status()
6922
6923
6924 /**
6925 * Check folders has valid key
6926 *
6927 * @since 1.0.0
6928 * @access public
6929 */
6930 public function check_has_valid_key()
6931 {
6932 // Free/Pro: checking for key, for Free return 0, for Pro check for Key
6933 return 0;
6934
6935 }//end check_has_valid_key()
6936
6937
6938 /**
6939 * Get license information
6940 *
6941 * @since 1.0.0
6942 * @access public
6943 */
6944 public function get_license_key_information($licenseKey)
6945 {
6946 return [];
6947
6948 }//end get_license_key_information()
6949
6950
6951 /**
6952 * Get license key data
6953 *
6954 * @since 1.0.0
6955 * @access public
6956 */
6957 public function get_license_key_data($licenseKey='')
6958 {
6959 return [];
6960
6961 }//end get_license_key_data()
6962
6963
6964 /**
6965 * Check for license key data
6966 *
6967 * @since 1.0.0
6968 * @access public
6969 */
6970 public function check_for_license_key()
6971 {
6972 return false;
6973
6974 }//end check_for_license_key()
6975
6976
6977 }//end class
6978
6979
6980 if(!function_exists("folders_sanitize_text")) {
6981 function folders_sanitize_text($key ,$type = "post") {
6982 if($type == "post") {
6983 $string = isset($_POST[$key])?sanitize_text_field($_POST[$key]):"";
6984 } else {
6985 $string = isset($_GET[$key])?sanitize_text_field($_GET[$key]):"";
6986 }
6987 $string = stripslashes($string);
6988 $str = preg_replace('/\x00|<[^>]*>?/', '', $string);
6989 return str_replace(["'", '"'], ['&#39;', '&#34;'], $str);
6990 }
6991 }
6992