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