PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.7
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.7
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 5 years ago class-polylang.php 5 years ago class-review-box.php 5 years ago class-wpml.php 5 years ago folders.class.php 5 years ago form.class.php 5 years ago media.replace.php 5 years ago plugin.updates.php 5 years ago plugins.class.php 5 years ago tree.class.php 5 years ago
folders.class.php
4756 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3 /* Free/Pro Class name change */
4 class WCP_Folders
5 {
6
7 private static $instance;
8
9 private static $license_key_data = null;
10
11 private static $folders;
12
13 public $tlfs = 0;
14
15 private static $postIds;
16
17 private static $folderSettings = false;
18
19 public function __construct()
20 {
21
22
23 spl_autoload_register(array($this, 'autoload'));
24 add_action('init', array($this, 'create_folder_terms'), 15);
25 add_action('admin_init', array($this, 'folders_register_settings'));
26 add_action('admin_menu', array($this, 'admin_menu'), 10000);
27 add_action('admin_enqueue_scripts', array($this, 'folders_admin_styles'));
28 add_action('admin_enqueue_scripts', array($this, 'folders_admin_scripts'));
29 add_filter('plugin_action_links_' . WCP_FOLDERS_PLUGIN_BASE, [$this, 'plugin_action_links']);
30 add_action('admin_footer', array($this, 'admin_footer'));
31
32 /* check for polygon media */
33 // $polylang_options = get_option("polylang");
34 // if(is_array($polylang_options) && isset($polylang_options['media_support']) && $polylang_options['media_support'] == 1) {
35 // $polylang_options['media_support'] = 0;
36 // update_option("polylang", $polylang_options);
37 // }
38
39 $old_status = get_option("wcp_folder_version_267");
40
41 add_action('parse_tax_query', array($this, 'taxonomy_archive_exclude_children'));
42 add_action('admin_footer', array($this, 'admin_footer_for_media'));
43
44 /* Save Data */
45 add_action('wp_ajax_wcp_add_new_folder', array($this, 'wcp_add_new_folder'));
46 /* Update Data */
47 add_action('wp_ajax_wcp_update_folder', array($this, 'wcp_update_folder'));
48 /* Remove Data */
49 add_action('wp_ajax_wcp_remove_folder', array($this, 'wcp_remove_folder'));
50 /* Remove Multple Folder */
51 add_action('wp_ajax_wcp_remove_muliple_folder', array($this, 'remove_muliple_folder'));
52 /* Save State Data */
53 add_action('wp_ajax_save_wcp_folder_state', array($this, 'save_wcp_folder_state'));
54 /* Save State Data */
55 add_action('wp_ajax_wcp_save_parent_data', array($this, 'wcp_save_parent_data'));
56 /* Update Parent Data */
57 add_action('wp_ajax_wcp_update_parent_information', array($this, 'wcp_update_parent_information'));
58 /* Update Parent Data */
59 add_action('wp_ajax_wcp_save_folder_order', array($this, 'wcp_save_folder_order'));
60 /* Update Parent Data */
61 add_action('wp_ajax_wcp_mark_un_mark_folder', array($this, 'wcp_mark_un_mark_folder'));
62 /* Update Parent Data */
63 add_action('wp_ajax_wcp_make_sticky_folder', array($this, 'wcp_make_sticky_folder'));
64 /* Update Parent Data */
65 add_action('wp_ajax_wcp_change_post_folder', array($this, 'wcp_change_post_folder'));
66 /* Update Parent Data */
67 add_action('wp_ajax_wcp_change_multiple_post_folder', array($this, 'wcp_change_multiple_post_folder'));
68 /* Update width Data */
69 add_action('wp_ajax_wcp_change_post_width', array($this, 'wcp_change_post_width'));
70 /* Update width Data */
71 add_action('wp_ajax_wcp_change_folder_display_status', array($this, 'wcp_change_folder_display_status'));
72 /* Update width Data */
73 add_action('wp_ajax_wcp_change_all_status', array($this, 'wcp_change_all_status'));
74 /* Update width Data */
75 add_action('wp_ajax_save_folder_last_status', array($this, 'save_folder_last_status'));
76 /* Update width Data */
77 add_action('wp_ajax_wcp_folders_by_order', array($this, 'wcp_folders_by_order'));
78 /* Update width Data */
79 add_action('wp_ajax_wcp_remove_all_folders_data', array($this, 'remove_all_folders_data'));
80 /* Update folders Status */
81 add_action('wp_ajax_wcp_update_folders_uninstall_status', array($this, 'update_folders_uninstall_status'));
82 /* Undo Functionality */
83 add_action('wp_ajax_wcp_undo_folder_changes', array($this, 'wcp_undo_folder_changes'));
84 self::$folders = 10;
85
86 /* Send message on plugin deactivate */
87 add_action( 'wp_ajax_folder_plugin_deactivate', array( $this, 'folder_plugin_deactivate' ) );
88 /* Update Parent Data */
89 add_action('wp_ajax_wcp_remove_post_folder', array($this, 'wcp_remove_post_folder'));
90 /* Send message on owner */
91 add_action( 'wp_ajax_wcp_folder_send_message_to_owner', array( $this, 'wcp_folder_send_message_to_owner' ) );
92 /* Get default list */
93 add_action('wp_ajax_premio_check_for_other_folders', array($this, 'premio_check_for_other_folders'));
94 /* Send message on owner */
95 add_action( 'wp_ajax_wcp_get_default_list', array( $this, 'wcp_get_default_list' ) );
96 /* Get default list */
97 add_action( 'wp_ajax_get_folders_default_list', array( $this, 'get_folders_default_list' ) );
98 /* Auto select folder for new page, post */
99 add_action('new_to_auto-draft', array($this, 'new_to_auto_draft'), 10);
100 /* for media */
101 add_action('restrict_manage_posts', array($this, 'output_list_table_filters'), 10, 2);
102 add_filter('pre_get_posts', array($this, 'filter_attachments_list'));
103 add_action('wp_enqueue_media', array($this, 'output_backbone_view_filters'));
104 add_filter('ajax_query_attachments_args', array($this, 'filter_attachments_grid'));
105 add_filter('add_attachment', array($this, 'save_media_terms'));
106
107 /* to filter un assigned items*/
108 add_filter('pre_get_posts', array($this, 'filter_record_list'));
109 add_filter('pre-upload-ui', array($this, 'show_dropdown_on_media_screen'));
110 add_action('add_attachment', array($this, 'add_attachment_category'));
111
112 $options = get_option("folders_settings");
113
114 $options = is_array($options)?$options:array();
115
116 if (in_array("post", $options)) {
117 add_filter('manage_posts_columns', array($this, 'wcp_manage_columns_head'));
118 add_action('manage_posts_custom_column', array($this, 'wcp_manage_columns_content'), 10, 2);
119 add_filter( 'bulk_actions-edit-post', array($this, 'custom_bulk_action' ));
120 }
121
122 if (in_array("page", $options)) {
123 add_filter('manage_page_posts_columns', array($this, 'wcp_manage_columns_head'));
124 add_action('manage_page_posts_custom_column', array($this, 'wcp_manage_columns_content'), 10, 2);
125 add_filter( 'bulk_actions-edit-page', array($this, 'custom_bulk_action' ));
126 }
127
128 if (in_array("attachment", $options)) {
129 add_filter('manage_media_columns', array($this, 'wcp_manage_columns_head'));
130 add_action('manage_media_custom_column', array($this, 'wcp_manage_columns_content'), 10, 2);
131 //add_filter('bulk_actions-edit-media', array($this, 'custom_bulk_action' ));
132 }
133
134 foreach ($options as $option) {
135 if ($option != "post" && $option != "page" && $option != "attachment") {
136 add_filter('manage_edit-'.$option.'_columns', array($this, 'wcp_manage_columns_head'), 99999);
137 add_action('manage_'.$option.'_posts_custom_column', array($this, 'wcp_manage_columns_content'), 2, 2);
138 add_filter( 'bulk_actions-edit-'.$option, array($this, 'custom_bulk_action' ));
139 }
140 }
141
142 /* check for default folders */
143 add_filter('pre_get_posts', array($this, 'check_for_default_folders'));
144
145 add_action("wp_ajax_folder_update_status", array($this, 'folder_update_status'));
146
147 /* load language files */
148 add_action( 'plugins_loaded', array( $this, 'folders_text' ) );
149
150 add_action("wp_ajax_folder_update_popup_status", array($this, 'folder_update_popup_status'));
151
152 add_action("wp_ajax_premio_hide_child_popup", array($this, 'premio_hide_child_popup'));
153
154 add_action("wp_ajax_wcp_update_folders_import_status", array($this, 'update_folders_import_status'));
155
156 add_filter('get_terms', array( $this, 'get_terms_filter_without_trash'), 10, 3);
157
158 add_filter('mla_media_modal_query_final_terms', array( $this, 'media_modal_query_final_terms'), 10, 3);
159
160 /* reset count when post/page updated */
161 add_action( 'deleted_term_relationships', array($this, 'update_folder_term_relationships'), 10, 3 );
162
163 add_action( 'added_term_relationship', array($this, 'update_folder_new_term_relationships'), 10, 3 );
164 }
165
166 public static function check_for_setting($key, $setting, $default = "") {
167 if(self::$folderSettings === false) {
168 $options = get_option("premio_folder_options");
169 if($options === false || !is_array($options)) {
170 $options = array();
171 }
172 self::$folderSettings = $options;
173 }
174 if($setting == "folders_settings") {
175 if(isset(self::$folderSettings[ $setting ]) && is_array(self::$folderSettings[ $setting ])) {
176 return in_array($key, self::$folderSettings[ $setting ]);
177 }
178 } else {
179 if ( isset( self::$folderSettings[ $setting ][ $key ] ) ) {
180 return self::$folderSettings[ $setting ][ $key ];
181 }
182 }
183 return false;
184 }
185
186 public function update_folders_uninstall_status() {
187 $response = array();
188 $response['status'] = 0;
189 $response['error'] = 0;
190 $response['data'] = array();
191 $response['message'] = "";
192 $postData = filter_input_array(INPUT_POST);
193 $errorCounter = 0;
194
195 if (!isset($postData['nonce']) || empty($postData['nonce'])) {
196 $response['message'] = esc_html__("Your request is not valid", 'folders');
197 $errorCounter++;
198 } else {
199 $nonce = self::sanitize_options($postData['nonce']);
200 if(!wp_verify_nonce($nonce, 'wcp_folders_uninstall_status')) {
201 $response['message'] = esc_html__("Your request is not valid", 'folders');
202 $errorCounter++;
203 }
204 }
205 if ($errorCounter == 0) {
206 $status = isset($postData['status'])?$postData['status']:"";
207 $status = ($status == "on")?"on":"off";
208 $customize_folders = get_option('customize_folders');
209 $customize_folders['remove_folders_when_removed'] = $status;
210 update_option("customize_folders", $customize_folders);
211 $response['status'] = 1;
212 }
213 echo json_encode($response); die;
214 }
215
216 public function remove_all_folders_data() {
217 $response = array();
218 $response['status'] = 0;
219 $response['error'] = 0;
220 $response['data'] = array();
221 $response['message'] = "";
222 $postData = filter_input_array(INPUT_POST);
223 $errorCounter = 0;
224
225 if (!isset($postData['nonce']) || empty($postData['nonce'])) {
226 $response['message'] = esc_html__("Your request is not valid", 'folders');
227 $errorCounter++;
228 } else {
229 $type = self::sanitize_options($postData['type']);
230 $nonce = self::sanitize_options($postData['nonce']);
231 if(!wp_verify_nonce($nonce, 'remove_folders_data')) {
232 $response['message'] = esc_html__("Your request is not valid", 'folders');
233 $errorCounter++;
234 }
235 }
236 if ($errorCounter == 0) {
237 self::$folders = 0;
238 self::remove_folder_by_taxonomy("media_folder");
239 self::remove_folder_by_taxonomy("folder");
240 self::remove_folder_by_taxonomy("post_folder");
241 $post_types = get_post_types( array( ), 'objects' );
242 $post_array = array("page", "post", "attachment");
243 foreach ( $post_types as $post_type ) {
244 if(!in_array($post_type->name, $post_array)){
245 self::remove_folder_by_taxonomy($post_type->name . '_folder');
246 }
247 }
248 delete_option('default_folders');
249 $response['status'] = 1;
250 $response['data'] = array(
251 'items' => self::$folders
252 );
253 }
254 echo json_encode($response); die;
255 }
256
257 public static function remove_folder_by_taxonomy($taxonomy) {
258 global $wpdb;
259 $folders = $wpdb->get_results(
260 "SELECT * FROM " . $wpdb->term_taxonomy . "
261 LEFT JOIN " . $wpdb->terms . "
262 ON " . $wpdb->term_taxonomy . ".term_id = " . $wpdb->terms . ".term_id
263 WHERE " . $wpdb->term_taxonomy . ".taxonomy = '" . $taxonomy . "'
264 ORDER BY parent ASC"
265 );
266 $folders = array_values( $folders );
267 foreach ( $folders as $folder ) {
268 $term_id = intval( $folder->term_id );
269 if ( $term_id ) {
270 $wpdb->delete( $wpdb->prefix . 'term_relationships', ['term_taxonomy_id' => $term_id] );
271 $wpdb->delete( $wpdb->prefix . 'term_taxonomy', ['term_id' => $term_id] );
272 $wpdb->delete( $wpdb->prefix . 'terms', ['term_id' => $term_id] );
273 $wpdb->delete( $wpdb->prefix . 'termmeta', ['term_id' => $term_id] );
274 self::$folders++;
275 }
276 }
277 }
278
279 public static function hexToRgb($hex, $alpha = false) {
280 $hex = str_replace('#', '', $hex);
281 $length = strlen($hex);
282 $rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
283 $rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
284 $rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
285 if ( $alpha ) {
286 $rgb['a'] = $alpha;
287 }
288 return $rgb;
289 }
290
291 public function wcp_folders_by_order(){
292 $response = array();
293 $response['status'] = 0;
294 $response['error'] = 0;
295 $response['data'] = array();
296 $response['message'] = "";
297 $postData = filter_input_array(INPUT_POST);
298 $errorCounter = 0;
299
300 if (!isset($postData['order']) || empty($postData['order'])) {
301 $response['message'] = esc_html__("Your request is not valid", 'folders');
302 $errorCounter++;
303 } else if (!isset($postData['type']) || empty($postData['type'])) {
304 $response['message'] = esc_html__("Your request is not valid", 'folders');
305 $errorCounter++;
306 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
307 $response['message'] = esc_html__("Your request is not valid", 'folders');
308 $errorCounter++;
309 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
310 $response['message'] = esc_html__("You have not permission to update width", 'folders');
311 $errorCounter++;
312 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
313 $response['message'] = esc_html__("You have not permission to update width", 'folders');
314 $errorCounter++;
315 } else {
316 $type = self::sanitize_options($postData['type']);
317 $nonce = self::sanitize_options($postData['nonce']);
318 if(!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
319 $response['message'] = esc_html__("Your request is not valid", 'folders');
320 $errorCounter++;
321 }
322 }
323 if ($errorCounter == 0) {
324 $response['status'] = 1;
325
326 $order_field = $postData['order'];
327
328 $order_by = "";
329 $order = "ASC";
330
331 if($order_field == "a-z" || $order_field == "z-a") {
332 $order_by = 'title';
333 if($order_field == "z-a") {
334 $order = "DESC";
335 }
336 } else if($order_field == "n-o" || $order_field == "o-n") {
337 $order_by = 'ID';
338 if($order_field == "o-n") {
339 $order = "ASC";
340 } else {
341 $order = "DESC";
342 }
343 }
344
345 if(empty($order_by)) {
346 $order = "";
347 }
348
349 $folder_type = self::get_custom_post_type($postData['type']);
350 /* Do not change: Free/Pro Class name change */
351 $tree_data = WCP_Tree::get_full_tree_data($folder_type, $order_by, $order);
352
353 $response['data'] = $tree_data['string'];
354 $taxonomies = array();
355 if($postData['type'] == "attachment") {
356 $taxonomies = self::get_terms_hierarchical($folder_type);
357 }
358 $response['terms'] = $taxonomies;
359 }
360 echo json_encode($response); die;
361 }
362
363 public function save_folder_last_status(){
364 $postData = filter_input_array(INPUT_POST);
365 $error = 0;
366 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
367 $response['message'] = esc_html__("Your request is not valid", 'folders');
368 $error = 1;
369 } else if (!isset($postData['post_type']) || empty($postData['type'])) {
370 $response['message'] = esc_html__("Your request is not valid", 'folders');
371 $error = 1;
372 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
373 $response['message'] = esc_html__("Your request is not valid", 'folders');
374 $error = 1;
375 } else if ($postData['post_type'] == "page" && !current_user_can("edit_pages")) {
376 $response['message'] = esc_html__("You have not permission to update width", 'folders');
377 $error = 1;
378 } else if ($postData['post_type'] != "page" && !current_user_can("edit_posts")) {
379 $response['message'] = esc_html__("You have not permission to update width", 'folders');
380 $error = 1;
381 }
382 if($error == 0) {
383 $post_type = filter_input(INPUT_POST, 'post_type', FILTER_SANITIZE_STRING);
384 $post_id = filter_input(INPUT_POST, 'post_id', FILTER_SANITIZE_STRING);
385 if (!empty($post_type) && !empty($post_id)) {
386 delete_option("last_folder_status_for" . $post_type);
387 add_option("last_folder_status_for" . $post_type, $post_id);
388 }
389 }
390 }
391
392 public function media_modal_query_final_terms($request)
393 {
394 if (isset($_REQUEST['action']) && $_REQUEST['action'] == "mla-query-attachments") {
395 $query = isset($_REQUEST['query']) ? $_REQUEST['query'] : array();
396 if (isset($query['media_folder']) && !empty($query['media_folder'])) {
397 if ($query['media_folder'] == -1) {
398 $tax_query = array(
399 'taxonomy' => 'media_folder',
400 'operator' => 'NOT EXISTS',
401 );
402 $request['tax_query'] = array($tax_query);
403 $request = apply_filters('media_library_organizer_media_filter_attachments', $request, $_REQUEST);
404 } else {
405 $request['media_folder'] = $query['media_folder'];
406 }
407 }
408 }
409 return $request;
410 }
411
412 public function get_terms_filter_without_trash($terms, $taxonomies, $args) {
413 global $wpdb;
414 if ( ! is_array($terms) && count($terms) < 1 ) {
415 return $terms;
416 }
417
418 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
419 if($trash_folders === false) {
420 $trash_folders = array();
421 $initial_trash_folders = array();
422 }
423
424 $post_table = $wpdb->prefix."posts";
425 $term_table = $wpdb->prefix."term_relationships";
426 $options = get_option('folders_settings');
427 $option_array = array();
428 if(!empty($options)) {
429 foreach ($options as $option) {
430 $option_array[] = self::get_custom_post_type($option);
431 }
432 }
433 foreach ($terms as $key=>$term ) {
434 if(isset($term->term_id) && isset($term->taxonomy) && !empty($term->taxonomy) && in_array($term->taxonomy, $option_array)) {
435 $trash_count = null;
436 if(isset($trash_folders[$term->term_taxonomy_id])) {
437 $trash_count = $trash_folders[$term->term_taxonomy_id];
438 } else {
439 if (has_filter("premio_folder_item_in_taxonomy")) {
440 $post_type = "";
441 $taxonomy = $term->taxonomy;
442
443 if ($taxonomy == "post_folder") {
444 $post_type = "post";
445 } else if ($taxonomy == "folder") {
446 $post_type = "page";
447 } else if ($taxonomy == "media_folder") {
448 $post_type = "attachment";
449 } else {
450 $post_type = trim($taxonomy, "'_folder'");
451 }
452 $arg = array(
453 'post_type' => $post_type,
454 'taxonomy' => $taxonomy,
455 );
456 $trash_count = apply_filters("premio_folder_item_in_taxonomy", $term->term_id, $arg);
457 }
458
459 if ($trash_count === null) {
460 $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");
461 $query = "SELECT COUNT(DISTINCT(p.ID))
462 FROM {$post_table} p
463 JOIN {$term_table} rl ON p.ID = rl.object_id
464 WHERE rl.term_taxonomy_id = '{$term->term_taxonomy_id}' AND p.post_status != 'trash' LIMIT 1";
465 $result = $wpdb->get_var($query);
466 if (intval($result) > 0) {
467 $trash_count = intval($result);
468 } else {
469 $trash_count = 0;
470 }
471 }
472 }
473 if($trash_count === null) {
474 $trash_count = 0;
475 }
476 $terms[$key]->trash_count = $trash_count;
477 $trash_folders[$term->term_taxonomy_id] = $trash_count;
478 }
479 }
480
481 if(!empty($terms) && $initial_trash_folders != $trash_folders) {
482 set_transient("premio_folders_without_trash", $trash_folders, 3*DAY_IN_SECONDS);
483 }
484 return $terms;
485 }
486
487 public function custom_bulk_action($bulk_actions) {
488 $bulk_actions['move_to_folder'] = __( 'Move to Folder', 'email_to_eric');
489 return $bulk_actions;
490 }
491
492 public function folders_text() {
493 load_plugin_textdomain("folders", FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
494 }
495
496 public function admin_footer_for_media(){
497 echo "<style>";
498 $customize_folders = get_option('customize_folders');
499 if(isset($customize_folders['dropdown_color']) && !empty($customize_folders['dropdown_color'])) {
500 ?>
501 #media-attachment-taxonomy-filter, .post-upload-ui .folder_for_media, select.media-select-folder { border-color: <?php echo esc_attr($customize_folders['dropdown_color']) ?>; color: <?php echo esc_attr($customize_folders['dropdown_color']) ?> }
502 .folder_for_media option {color:#000000;}
503 .folder_for_media option:first-child {
504 font-weight: bold;
505 }
506 <?php
507 }
508 echo "</style>";
509 }
510
511 public function check_for_default_folders() {
512 global $typenow, $current_screen;
513 $isAjax = (defined('DOING_AJAX') && DOING_AJAX)?1:0;
514 $options = get_option('folders_settings');
515 $options = (empty($options) || !is_array($options))?array():$options;
516 $post_status = filter_input(INPUT_GET, 'post_status', FILTER_SANITIZE_STRING);
517 $last_status = get_option("last_folder_status_for".$typenow);
518 if(empty($post_status) && !$isAjax && (in_array($typenow, $options) || !empty($last_status)) && (isset($current_screen->base) && ($current_screen->base == "edit" || ($current_screen->base == "upload")))) {
519
520 $requests = filter_input_array(INPUT_GET);
521 $requests = empty($requests)||!is_array($requests)?array():$requests;
522
523 if ($typenow == "attachment") {
524 if(count($requests) > 0) {
525 return;
526 }
527 } else if ($typenow == "post") {
528 if(count($requests) > 0) {
529 return;
530 }
531 } else {
532 if(count($requests) > 1) {
533 return;
534 }
535 }
536
537 if(!empty($last_status)) {
538 $status = 1;
539 if($last_status != "-1" && $last_status != "all") {
540 $type = self::get_custom_post_type($typenow);
541 $term = get_term_by('slug', $last_status, $type);
542 if (empty($term) || !is_object($term)) {
543 $status = 0;
544 }
545 }
546 delete_option("last_folder_status_for".$typenow);
547 if($last_status == "all") {
548 $last_status = "";
549 }
550 if($status) {
551 if ($typenow == "attachment") {
552 if (!isset($_REQUEST['media_folder'])) {
553 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
554 $admin_url .= $last_status;
555 ?>
556 <script>
557 window.location = '<?php echo $admin_url ?>';
558 </script>
559 <?php
560 exit;
561 }
562 } else {
563 $post_type = self::get_custom_post_type($typenow);
564 $admin_url = admin_url("edit.php?post_type=" . $typenow);
565 $admin_url .= "&{$post_type}=";
566 if (!isset($_REQUEST[$post_type])) {
567 $admin_url .= $last_status;
568 ?>
569 <script>
570 window.location = '<?php echo $admin_url ?>';
571 </script>
572 <?php
573 exit;
574 }
575 }
576 }
577 }
578
579 $default_folders = get_option('default_folders');
580 $default_folders = (empty($default_folders) || !is_array($default_folders))?array():$default_folders;
581
582 $status = 1;
583 if(isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
584 $type = self::get_custom_post_type($typenow);
585 if($default_folders[$typenow] != -1) {
586 $term = get_term_by('slug', $default_folders[$typenow], $type);
587 if (empty($term) || !is_object($term)) {
588 $status = 0;
589 }
590 }
591 } else {
592 $status = 0;
593 }
594 if($status) {
595 if ($typenow == "attachment") {
596 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
597 if (!isset($_REQUEST['media_folder'])) {
598 if (isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
599 $admin_url .= $default_folders[$typenow];
600 ?>
601 <script>
602 window.location = '<?php echo $admin_url ?>';
603 </script>
604 <?php
605 exit;
606 }
607 }
608 } else {
609 $admin_url = admin_url("edit.php?post_type=" . $typenow);
610 if (isset($_GET['s']) && !empty($_GET['s'])) {
611 $admin_url .= "&s=" . $_GET['s'];
612 }
613 $post_type = self::get_custom_post_type($typenow);
614 $admin_url .= "&{$post_type}=";
615 if (!isset($_REQUEST[$post_type])) {
616 if (isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
617 $admin_url .= $default_folders[$typenow];
618 ?>
619 <script>
620 window.location = '<?php echo $admin_url ?>';
621 </script>
622 <?php
623 exit;
624 }
625 }
626 }
627 }
628 }
629 }
630
631 public function folder_update_status() {
632 if(!empty($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'folder_update_status')) {
633 $status = filter_input(INPUT_POST, 'status', FILTER_SANITIZE_STRING);
634 $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_STRING);
635 update_option("folder_update_message", 2);
636 if($status == 1) {
637 $url = 'https://go.premio.io/api/update.php?email='.$email.'&plugin=folders';
638 $handle = curl_init();
639 curl_setopt($handle, CURLOPT_URL, $url);
640 curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
641 $response = curl_exec($handle);
642 curl_close($handle);
643 }
644 }
645 echo "1";
646 die;
647 }
648
649 public function add_attachment_category($post_ID)
650 {
651 if(self::is_for_this_post_type('attachment') || self::is_for_this_post_type('media')) {
652 $folder_id = isset($_REQUEST["folder_for_media"]) ? $_REQUEST["folder_for_media"] : null;
653 if ($folder_id !== null) {
654 $folder_id = (int)$folder_id;
655 $folder_id = self::sanitize_options($folder_id, "int");
656 if ($folder_id > 0) {
657 $post_type = self::get_custom_post_type("attachment");
658 $term = get_term($folder_id);
659 if(!empty($term) && isset($term->slug)) {
660 wp_set_object_terms($post_ID, $term->slug, $post_type );
661
662 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
663 if($trash_folders === false) {
664 $trash_folders = array();
665 $initial_trash_folders = array();
666 }
667
668 if(isset($trash_folders[$folder_id])) {
669 unset($trash_folders[$folder_id]);
670 }
671
672 if($initial_trash_folders != $trash_folders) {
673 delete_transient("premio_folders_without_trash");
674 set_transient("premio_folders_without_trash", $trash_folders, 3*DAY_IN_SECONDS);
675 }
676 }
677 }
678 }
679 }
680 }
681
682 public function show_dropdown_on_media_screen() {
683 if(self::is_for_this_post_type('attachment')) {
684 $post_type = self::get_custom_post_type('attachment');
685 global $typenow, $current_screen;
686 /* Free/Pro Class name change */
687 if(!class_exists('WCP_Tree')) {
688 $files = array(
689 'WCP_Tree' => WCP_DS . "includes" . WCP_DS . "tree.class.php"
690 );
691
692 foreach ($files as $file) {
693 if (file_exists(dirname(dirname(__FILE__)) . $file)) {
694 include_once dirname(dirname(__FILE__)) . $file;
695 }
696 }
697 }
698 /* Free/Pro Class name change */
699 $options = WCP_Tree::get_folder_option_data($post_type);?>
700 <p class="attachments-category"><?php esc_html_e("Select a folder (Optional)", 'folders'); ?></p>
701 <p class="attachments-category"><?php esc_html_e("First select the folder, and then upload the files", 'folders'); ?><br/></p>
702 <p>
703 <?php
704 $request = $_SERVER['REQUEST_URI'];
705 $request = strpos($request, "post.php");
706 ?>
707 <select name="folder_for_media" class="folder_for_media">
708 <option value="-1">- <?php esc_html_e('Unassigned', 'folders'); ?></option>
709 <?php echo $options ?>
710 <?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')) {?>
711 <option value="add-folder"><?php esc_html_e('+ Create a New Folder', 'folders'); ?></option>
712 <?php } ?>
713 </select>
714 </p>
715 <?php
716 }
717 }
718
719 public function wcp_hide_folders()
720 {
721 $response = array();
722 $response['status'] = 0;
723 $response['error'] = 0;
724 $response['data'] = array();
725 $response['message'] = "";
726 $postData = filter_input_array(INPUT_POST);
727 $errorCounter = 0;
728
729 if (!isset($postData['status']) || empty($postData['status'])) {
730 $response['message'] = esc_html__("Your request is not valid", 'folders');
731 $errorCounter++;
732 } else if (!isset($postData['type']) || empty($postData['type'])) {
733 $response['message'] = esc_html__("Your request is not valid", 'folders');
734 $errorCounter++;
735 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
736 $response['message'] = esc_html__("Your request is not valid", 'folders');
737 $errorCounter++;
738 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
739 $response['message'] = esc_html__("You have not permission to update width", 'folders');
740 $errorCounter++;
741 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
742 $response['message'] = esc_html__("You have not permission to update width", 'folders');
743 $errorCounter++;
744 } else {
745 $type = self::sanitize_options($postData['type']);
746 $nonce = self::sanitize_options($postData['nonce']);
747 if(!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
748 $response['message'] = esc_html__("Your request is not valid", 'folders');
749 $errorCounter++;
750 }
751 }
752 if ($errorCounter == 0) {
753 $type = self::sanitize_options($postData['type']);
754 $status = self::sanitize_options($postData['status']);
755 $optionName = "wcp_folder_display_status_" . $type;
756 update_option($optionName, $status);
757 $response['status'] = 1;
758 }
759 echo json_encode($response);
760 wp_die();
761 }
762
763 public function wcp_change_folder_display_status()
764 {
765 $response = array();
766 $response['status'] = 0;
767 $response['error'] = 0;
768 $response['data'] = array();
769 $response['message'] = "";
770 $postData = filter_input_array(INPUT_POST);
771 $errorCounter = 0;
772 if (!isset($postData['status']) || empty($postData['status'])) {
773 $response['message'] = esc_html__("Your request is not valid", 'folders');
774 $errorCounter++;
775 } else if (!isset($postData['type']) || empty($postData['type'])) {
776 $response['message'] = esc_html__("Your request is not valid", 'folders');
777 $errorCounter++;
778 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
779 $response['message'] = esc_html__("Your request is not valid", 'folders');
780 $errorCounter++;
781 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
782 $response['message'] = esc_html__("You have not permission to update width", 'folders');
783 $errorCounter++;
784 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
785 $response['message'] = esc_html__("You have not permission to update width", 'folders');
786 $errorCounter++;
787 } else {
788 $type = self::sanitize_options($postData['type']);
789 $nonce = self::sanitize_options($postData['nonce']);
790 if(!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
791 $response['message'] = esc_html__("Your request is not valid", 'folders');
792 $errorCounter++;
793 }
794 }
795 if ($errorCounter == 0) {
796 $type = self::sanitize_options($postData['type']);
797 $width = self::sanitize_options($postData['status']);
798 $optionName = "wcp_dynamic_display_status_" . $type;
799 update_option($optionName, $width);
800 $response['status'] = 1;
801 }
802 echo json_encode($response);
803 wp_die();
804 }
805
806 public function premio_check_for_other_folders() {
807 $response = array();
808 $response['status'] = 0;
809 $response['error'] = 0;
810 $response['data'] = array();
811 $response['message'] = "";
812 $postData = filter_input_array(INPUT_POST);
813 $errorCounter = 0;
814 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
815 $response['message'] = esc_html__("Your request is not valid", 'folders');
816 $errorCounter++;
817 } else if (!isset($postData['type']) || empty($postData['type'])) {
818 $response['message'] = esc_html__("Your request is not valid", 'folders');
819 $errorCounter++;
820 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
821 $response['message'] = esc_html__("Your request is not valid", 'folders');
822 $errorCounter++;
823 } else if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$postData['type'])) {
824 $response['message'] = esc_html__("Your request is not valid", 'folders');
825 $errorCounter++;
826 } else if(!current_user_can("manage_categories")) {
827 $response['message'] = esc_html__("Your request is not valid", 'folders');
828 $errorCounter++;
829 }
830 if ($errorCounter == 0) {
831 $folderUndoSettings = array();
832 $type = self::sanitize_options($postData['type']);
833 $post_id = self::sanitize_options($postData['post_id']);
834
835 $post_id = explode(",", $post_id);
836
837 $taxonomy = self::get_custom_post_type($type);
838
839 foreach ($post_id as $id) {
840 $terms = get_the_terms($id, $taxonomy);
841 if(!empty($terms) && is_array($terms)) {
842 foreach($terms as $term) {
843 if($term->term_id != $postData['taxonomy']) {
844 $response['status'] = -1;
845 $response['data']['post_id'] = $postData['post_id'];
846 echo json_encode($response);
847 wp_die();
848 }
849 }
850 }
851 }
852 $this->wcp_remove_post_folder();
853 }
854 echo json_encode($response);
855 wp_die();
856 }
857
858 public function wcp_remove_post_folder() {
859 $response = array();
860 $response['status'] = 0;
861 $response['error'] = 0;
862 $response['data'] = array();
863 $response['message'] = "";
864 $postData = filter_input_array(INPUT_POST);
865 $errorCounter = 0;
866 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
867 $response['message'] = esc_html__("Your request is not valid", 'folders');
868 $errorCounter++;
869 } else if (!isset($postData['type']) || empty($postData['type'])) {
870 $response['message'] = esc_html__("Your request is not valid", 'folders');
871 $errorCounter++;
872 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
873 $response['message'] = esc_html__("Your request is not valid", 'folders');
874 $errorCounter++;
875 } else if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$postData['type'])) {
876 $response['message'] = esc_html__("Your request is not valid", 'folders');
877 $errorCounter++;
878 } else if(!current_user_can("manage_categories")) {
879 $response['message'] = esc_html__("Your request is not valid", 'folders');
880 $errorCounter++;
881 }
882 if ($errorCounter == 0) {
883 $folderUndoSettings = array();
884 $type = self::sanitize_options($postData['type']);
885 $post_id = self::sanitize_options($postData['post_id']);
886
887 $post_id = explode(",", $post_id);
888
889 $taxonomy = self::get_custom_post_type($type);
890
891 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
892 if($trash_folders === false) {
893 $trash_folders = array();
894 $initial_trash_folders = array();
895 }
896
897 foreach($post_id as $id) {
898 if(!empty($id) && is_numeric($id) && $id > 0) {
899 $terms = get_the_terms($id, $taxonomy);
900 $post_terms = array(
901 'post_id' => $id,
902 'terms' => $terms
903 );
904 if(!empty($terms) && count($terms)>0) {
905 foreach($terms as $term) {
906 if(isset($term->term_id) && isset($trash_folders[$term->term_id])) {
907 unset($trash_folders[$term->term_id]);
908 }
909 }
910 }
911 $folderUndoSettings[] = $post_terms;
912 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'])) {
913 wp_remove_object_terms($id, intval($postData['active_folder']), $taxonomy);
914 } else {
915 wp_delete_object_term_relationships($id, $taxonomy);
916 }
917 }
918 }
919 delete_transient("folder_undo_settings");
920 set_transient("folder_undo_settings", $folderUndoSettings, DAY_IN_SECONDS);
921
922 if($initial_trash_folders != $trash_folders) {
923 delete_transient("premio_folders_without_trash");
924 set_transient("premio_folders_without_trash", $trash_folders, 3*DAY_IN_SECONDS);
925 }
926 $response['status'] = 1;
927 }
928 echo json_encode($response);
929 wp_die();
930 }
931
932 public function filter_record_list($query) {
933 global $typenow;
934
935 if($typenow == "attachment") {
936 return;
937 }
938
939 if(!self::is_for_this_post_type($typenow)) {
940 return $query;
941 }
942
943 $taxonomy = self::get_custom_post_type($typenow);
944
945 if ( ! isset( $query->query['post_type'] ) ) {
946 return $query;
947 }
948
949 if ( ! isset( $_REQUEST[$taxonomy] ) ) {
950 return $query;
951 }
952
953 $term = sanitize_text_field( $_REQUEST[$taxonomy] );
954 if ( $term != "-1" ) {
955 return $query;
956 }
957
958 unset( $query->query_vars[$taxonomy] );
959
960 $tax_query = array(
961 'taxonomy' => $taxonomy,
962 'operator' => 'NOT EXISTS',
963 );
964
965 $query->set( 'tax_query', array( $tax_query ) );
966 $query->tax_query = new WP_Tax_Query( array( $tax_query ) );
967
968 return $query;
969 }
970
971 public function wcp_get_default_list() {
972
973 $postData = filter_input_array(INPUT_POST);
974
975 $post_type = $postData['type'];
976
977 $ttpsts = $this->get_ttlpst($post_type);
978
979 $empty_items = self::get_tempt_posts($post_type);
980
981 $post_type = self::get_custom_post_type($post_type);
982
983 $taxonomies = self::get_terms_hierarchical($post_type);
984
985 $response = array(
986 'status' => 1,
987 'total_items' => $ttpsts,
988 'taxonomies' => $taxonomies,
989 'empty_items' => $empty_items
990 );
991 echo json_encode($response);
992 wp_die();
993 }
994
995 function get_folders_default_list() {
996 $postData = filter_input_array(INPUT_POST);
997
998 $post_type = $postData['type'];
999
1000 $ttpsts = $this->get_ttlpst($post_type);
1001
1002 $empty_items = self::get_tempt_posts($post_type);
1003
1004 $post_type = self::get_custom_post_type($post_type);
1005
1006 $taxonomies = self::get_terms_hierarchical($post_type);
1007
1008 $response = array(
1009 'status' => 1,
1010 'total_items' => $ttpsts,
1011 'empty_items' => $empty_items,
1012 'taxonomies' => $taxonomies
1013 );
1014 echo json_encode($response);
1015 die;
1016
1017 }
1018
1019 function save_media_terms( $post_id ) {
1020 if ( wp_is_post_revision( $post_id ) ) {
1021 return;
1022 }
1023 $post = get_post($post_id);
1024 if($post->post_type !== 'attachment') {
1025 return;
1026 }
1027 $post_type = self::get_custom_post_type('attachment');
1028 $selected_folder = get_option("selected_{$post_type}_folder");
1029 if($selected_folder != null && !empty($selected_folder)) {
1030 $terms = get_term($selected_folder);
1031 if(!empty($terms) && isset($terms->term_id)) {
1032 wp_set_post_terms($post_id, $terms->term_id, $post_type, false);
1033 }
1034 }
1035 }
1036
1037 public function filter_attachments_grid( $args ) {
1038 $taxonomy = 'media_folder';
1039 if ( ! isset( $args[ $taxonomy ] ) ) {
1040 return $args;
1041 }
1042 $term = sanitize_text_field( $args[ $taxonomy ] );
1043 if ( $term != "-1" ) {
1044 return $args;
1045 }
1046 unset( $args[ $taxonomy ] );
1047 $args['tax_query'] = array(
1048 array(
1049 'taxonomy' => $taxonomy,
1050 'operator' => 'NOT EXISTS',
1051 ),
1052 );
1053 $args = apply_filters( 'media_library_organizer_media_filter_attachments_grid', $args );
1054 return $args;
1055 }
1056
1057 public function get_tempt_posts($post_type = "")
1058 {
1059 global $wpdb;
1060
1061 $post_table = $wpdb->prefix."posts";
1062 $term_table = $wpdb->prefix."term_relationships";
1063 $term_taxonomy_table = $wpdb->prefix."term_taxonomy";
1064 $taxonomy = self::get_custom_post_type($post_type);
1065 $tlrcds = null;
1066 if(has_filter("premio_folder_un_categorized_items")) {
1067 $tlrcds = apply_filters("premio_folder_un_categorized_items", $post_type, $taxonomy);
1068 }
1069 if($tlrcds === null) {
1070 if ($post_type != "attachment") {
1071 $query = "SELECT COUNT(DISTINCT({$post_table}.ID)) AS total_records FROM {$post_table} WHERE 1=1 AND (
1072 NOT EXISTS (
1073 SELECT 1
1074 FROM {$term_table}
1075 INNER JOIN {$term_taxonomy_table}
1076 ON {$term_taxonomy_table}.term_taxonomy_id = {$term_table}.term_taxonomy_id
1077 WHERE {$term_taxonomy_table}.taxonomy = '%s'
1078 AND {$term_table}.object_id = {$post_table}.ID
1079 )
1080 ) 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'))";
1081 } else {
1082 $query = "SELECT COUNT(DISTINCT({$post_table}.ID)) AS total_records FROM {$post_table} WHERE 1=1 AND (
1083 NOT EXISTS (
1084 SELECT 1
1085 FROM {$term_table}
1086 INNER JOIN {$term_taxonomy_table}
1087 ON {$term_taxonomy_table}.term_taxonomy_id = {$term_table}.term_taxonomy_id
1088 WHERE {$term_taxonomy_table}.taxonomy = '%s'
1089 AND {$term_table}.object_id = {$post_table}.ID
1090 )
1091 ) AND {$post_table}.post_type = '%s' AND {$post_table}.post_status = 'inherit'";
1092 }
1093
1094 $query = $wpdb->prepare($query, $taxonomy, $post_type);
1095
1096 $tlrcds = $wpdb->get_var($query);
1097 }
1098
1099 if(!empty($tlrcds)) {
1100 return $tlrcds;
1101 } else {
1102 return 0;
1103 }
1104 }
1105
1106 public function output_backbone_view_filters() {
1107
1108 global $typenow, $current_screen;
1109 $isAjax = (defined('DOING_AJAX') && DOING_AJAX)?1:0;
1110 $options = get_option('folders_settings');
1111 $options = (empty($options) || !is_array($options))?array():$options;
1112 $last_status = get_option("last_folder_status_for".$typenow);
1113 if(!$isAjax && (in_array($typenow, $options) || !empty($last_status)) && (isset($current_screen->base) && ($current_screen->base == "edit" || ($current_screen->base == "upload")))) {
1114
1115 $default_folders = get_option('default_folders');
1116 $default_folders = (empty($default_folders) || !is_array($default_folders))?array():$default_folders;
1117
1118 if(!empty($last_status)) {
1119 $status = 1;
1120 if($last_status != "-1" && $last_status != "all") {
1121 $type = self::get_custom_post_type($typenow);
1122 $term = get_term_by('slug', $last_status, $type);
1123 if (empty($term) || !is_object($term)) {
1124 $status = 0;
1125 }
1126 }
1127 delete_option("last_folder_status_for".$typenow);
1128 if($last_status == "all") {
1129 $last_status = "";
1130 }
1131 if($status) {
1132 if ($typenow == "attachment") {
1133 if (!isset($_REQUEST['media_folder'])) {
1134 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
1135 $admin_url .= $last_status;
1136 ?>
1137 <script>
1138 window.location = '<?php echo $admin_url ?>';
1139 </script>
1140 <?php
1141 exit;
1142 }
1143 }
1144 }
1145 }
1146
1147 $status = 1;
1148 if(isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
1149 $type = self::get_custom_post_type($typenow);
1150 if($default_folders[$typenow] != -1) {
1151 $term = get_term_by('slug', $default_folders[$typenow], $type);
1152 if (empty($term) || !is_object($term)) {
1153 $status = 0;
1154 }
1155 }
1156 } else {
1157 $status = 0;
1158 }
1159 if($status) {
1160 if ($typenow == "attachment") {
1161 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
1162 if (!isset($_REQUEST['media_folder'])) {
1163 if (isset($default_folders[$typenow]) && !empty($default_folders[$typenow])) {
1164 $admin_url .= $default_folders[$typenow];
1165 ?>
1166 <script>
1167 window.location = '<?php echo $admin_url ?>';
1168 </script>
1169 <?php
1170 exit;
1171 }
1172 }
1173 }
1174 }
1175 }
1176
1177 if(!(self::is_for_this_post_type('attachment') || self::is_for_this_post_type('media'))) {
1178 return;
1179 }
1180
1181 if (($typenow == "attachment" || !is_admin()) && self::is_for_this_post_type('attachment')) {
1182 /* Free/Pro URL Change */
1183 global $typenow;
1184 $is_active = 1;
1185 $folders = -1;
1186
1187 $hasStars = self::check_for_setting("has_stars", "general");
1188 $hasChild = self::check_for_setting("has_child", "general");
1189 $hasChild = empty($hasChild)?0:1;
1190 $hasStars = empty($hasStars)?0:1;
1191 /* Free/Pro URL Change */
1192 wp_enqueue_script( 'folders-media', WCP_FOLDER_URL.'assets/js/media.js', array( 'media-editor', 'media-views' ), WCP_FOLDER_VERSION, true );
1193 wp_localize_script( 'folders-media', 'folders_media_options', array(
1194 'terms' => self::get_terms_hierarchical('media_folder'),
1195 'taxonomy' => get_taxonomy('media_folder'),
1196 'ajax_url' => admin_url("admin-ajax.php"),
1197 'activate_url' => $this->getFoldersUpgradeURL(),
1198 'nonce' => wp_create_nonce('wcp_folder_nonce_attachment'),
1199 'is_key_active' => $is_active,
1200 'hasStars' => $hasStars,
1201 'hasChildren' => $hasChild
1202 ));
1203 /* Free/Pro URL Change */
1204 wp_enqueue_style( 'folders-media', WCP_FOLDER_URL . 'assets/css/media.css' , array(), WCP_FOLDER_VERSION);
1205 } else if(!self::is_active_for_screen() && self::is_for_this_post_type('attachment')) {
1206 /* Free/Pro URL Change */
1207 global $typenow;
1208 global $current_screen;
1209 // echo "<pre>"; print_r($current_screen); die;
1210 if(!isset($current_screen->base) || $current_screen->base != "plugins") {
1211 $is_active = 1;
1212 $folders = -1;
1213
1214 /* Free/Pro URL Change */
1215
1216 $is_rtl = 0;
1217 if (function_exists('is_rtl') && is_rtl()) {
1218 $is_rtl = 1;
1219 }
1220 $can_manage_folder = current_user_can("manage_categories") ? 1 : 0;
1221 $width = 275;
1222 $taxonomy_status = 0;
1223 $selected_taxonomy = "";
1224 $show_in_page = false;
1225 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
1226
1227 $taxonomies = self::get_terms_hierarchical('media_folder');
1228
1229 $folder_settings = array();
1230 foreach($taxonomies as $taxonomy) {
1231 $is_sticky = get_term_meta($taxonomy->term_id, "is_folder_sticky", true);
1232 $is_high = get_term_meta($taxonomy->term_id, "is_highlighted", true);
1233 $folder_settings[] = array(
1234 'folder_id' => $taxonomy->term_id,
1235 'is_sticky' => intval($is_sticky),
1236 'is_high' => intval($is_high),
1237 'nonce' => wp_create_nonce('wcp_folder_term_'.$taxonomy->term_id),
1238 'is_deleted' => 0,
1239 'slug' => $taxonomy->slug,
1240 'folder_count' => intval($taxonomy->trash_count)
1241 );
1242 }
1243
1244 $hasStars = self::check_for_setting("has_stars", "general");
1245 $hasChild = self::check_for_setting("has_child", "general");
1246 $hasChild = empty($hasChild)?0:1;
1247 $hasStars = empty($hasStars)?0:1;
1248
1249 $customize_folders = get_option('customize_folders');
1250 $use_folder_undo = !isset($customize_folders['use_folder_undo'])?"yes":$customize_folders['use_folder_undo'];
1251 $defaultTimeout = !isset($customize_folders['default_timeout'])?5:intval($customize_folders['default_timeout']);
1252 if(empty($defaultTimeout) || !is_numeric($defaultTimeout) || $defaultTimeout < 0) {
1253 $defaultTimeout = 5;
1254 }
1255 $defaultTimeout = $defaultTimeout*1000;
1256
1257 wp_enqueue_script('folders-tree', WCP_FOLDER_URL . 'assets/js/jstree.min.js', array(), WCP_FOLDER_VERSION);
1258 wp_enqueue_script('wcp-folders-mcustomscrollbar', WCP_FOLDER_URL . 'assets/js/jquery.mcustomscrollbar.min.js', array(), WCP_FOLDER_VERSION);
1259 wp_enqueue_script('wcp-folders-media', WCP_FOLDER_URL . 'assets/js/page-post-media.min.js', array('jquery', 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'backbone'), WCP_FOLDER_VERSION, true);
1260 wp_enqueue_script('wcp-jquery-touch', plugin_dir_url(dirname(__FILE__)) . 'assets/js/jquery.ui.touch-punch.min.js', array('jquery'), WCP_FOLDER_VERSION);
1261 wp_localize_script('wcp-folders-media', 'folders_media_options', array(
1262 'terms' => $taxonomies,
1263 'taxonomy' => get_taxonomy('media_folder'),
1264 'ajax_url' => admin_url("admin-ajax.php"),
1265 'media_page_url' => admin_url("upload.php"),
1266 'activate_url' => $this->getFoldersUpgradeURL(),
1267 'nonce' => wp_create_nonce('wcp_folder_nonce_attachment'),
1268 'is_key_active' => $is_active,
1269 'folders' => $folders,
1270 'upgrade_url' => $this->getFoldersUpgradeURL(),
1271 'post_type' => 'attachment',
1272 'page_url' => $admin_url,
1273 'current_url' => "",
1274 'ajax_image' => plugin_dir_url(dirname(__FILE__)) . "assets/images/ajax-loader.gif",
1275 'register_url' => "",
1276 'isRTL' => $is_rtl,
1277 'can_manage_folder' => $can_manage_folder,
1278 'folder_width' => $width,
1279 'taxonomy_status' => $taxonomy_status,
1280 'selected_taxonomy' => $selected_taxonomy,
1281 'show_in_page' => $show_in_page,
1282 'svg_file' => WCP_FOLDER_URL . 'assets/images/pin.png',
1283 'folder_settings' => $folder_settings,
1284 'hasStars' => $hasStars,
1285 'hasChildren' => $hasChild,
1286 'useFolderUndo' => $use_folder_undo,
1287 'defaultTimeout' => $defaultTimeout,
1288 ));
1289 /* Free/Pro URL Change */
1290 wp_enqueue_style('folders-jstree', WCP_FOLDER_URL . 'assets/css/jstree.min.css', array(), WCP_FOLDER_VERSION);
1291 wp_enqueue_style('wcp-folders-mcustomscrollbar', WCP_FOLDER_URL . 'assets/css/jquery.mcustomscrollbar.min.css', array(),WCP_FOLDER_VERSION);
1292 wp_enqueue_style('folder-folders', WCP_FOLDER_URL . 'assets/css/folders.min.css', array(), WCP_FOLDER_VERSION);
1293 wp_enqueue_style('folders-media', WCP_FOLDER_URL . 'assets/css/page-post-media.min.css', array(), WCP_FOLDER_VERSION);
1294 wp_enqueue_style('folder-icon', WCP_FOLDER_URL . 'assets/css/folder-icon.css', array(), WCP_FOLDER_VERSION);
1295 $width = 275;
1296 $string = "";
1297 $css_text = "";
1298 $customize_folders = get_option('customize_folders');
1299 if (!isset($customize_folders['new_folder_color']) || empty($customize_folders['new_folder_color'])) {
1300 $customize_folders['new_folder_color'] = "#FA166B";
1301 }
1302 $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']) . "}";
1303 $css_text .= ".wcp-hide-show-buttons .toggle-buttons { background-color: " . esc_attr($customize_folders['new_folder_color']) . "; }";
1304 $css_text .= ".folders-toggle-button span { background-color: " . esc_attr($customize_folders['new_folder_color']) . "; }";
1305 $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}";
1306
1307 if (!isset($customize_folders['folder_bg_color']) || empty($customize_folders['folder_bg_color'])) {
1308 $customize_folders['folder_bg_color'] = "#FA166B";
1309 }
1310 $rgbColor = self::hexToRgb($customize_folders['folder_bg_color']);
1311 $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(".$rgbColor['r'].",".$rgbColor['g'].",".$rgbColor['b'].", 0.08) !important; color: #333333;}";
1312 $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: ".$customize_folders['folder_bg_color']." !important; color: #ffffff !important; }";
1313 $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: ".$customize_folders['folder_bg_color']." !important; color: #ffffff !important; }";
1314 $css_text .= ".drag-bot > a { border-bottom: solid 2px ".$customize_folders['folder_bg_color']."}";
1315 $css_text .= ".drag-up > a { border-top: solid 2px ".$customize_folders['folder_bg_color']."}";
1316 $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: ".$customize_folders['folder_bg_color']." !important; color: #fff !important;}";
1317 $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; }";
1318 $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;}";
1319 //$css_text .= "body:not(.no-hover-css) .wcp-container .route .title:hover, .header-posts a:hover, .un-categorised-items.active-item, .un-categorised-items:hover, .sticky-folders ul li a:hover {background: rgba(" . esc_attr($rgbColor['r'] . "," . $rgbColor['g'] . "," . $rgbColor['b'] . ", 0.08") . "); color:#444444;}";
1320 $css_text .= ".wcp-drop-hover {background-color: " . esc_attr($customize_folders['folder_bg_color']) . " !important; color: #ffffff; }";
1321 $css_text .= "#custom-menu .route .nav-icon .wcp-icon {color: " . esc_attr($customize_folders['folder_bg_color']) . " !important;}";
1322 $css_text .= ".mCS-3d.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar {background-color: " . esc_attr($customize_folders['folder_bg_color']) . " !important;}";
1323 $css_text .= "body:not(.no-hover-css) .jstree-hovered {background: rgba(" . esc_attr($rgbColor['r'] . "," . $rgbColor['g'] . "," . $rgbColor['b'] . ", 0.08") . ") }";
1324 $css_text .= ".jstree-default .jstree-clicked { background-color:" . esc_attr($customize_folders['folder_bg_color']) . "}";
1325 $css_text .= ".jstree-node.drag-in > a.jstree-anchor.jstree-hovered { background-color: " . esc_attr($customize_folders['folder_bg_color']) . "; color: #ffffff; }";
1326 $css_text .= "#custom-scroll-menu .jstree-hovered:not(.jstree-clicked) .pfolder-folder-close { color: " . esc_attr($customize_folders['folder_bg_color']) . "; }";
1327
1328 if (!isset($customize_folders['bulk_organize_button_color']) || empty($customize_folders['bulk_organize_button_color'])) {
1329 $customize_folders['bulk_organize_button_color'] = "#FA166B";
1330 }
1331 $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']) . "; }";
1332 $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']) . "; }";
1333
1334 $font_family = "";
1335 if (isset($customize_folders['folder_font']) && !empty($customize_folders['folder_font'])) {
1336 $folder_fonts = self::get_font_list();
1337 $font_family = $customize_folders['folder_font'];
1338 if (isset($folder_fonts[$font_family])) {
1339 $css_text .= ".wcp-container, .folder-popup-form { font-family: " . esc_attr($font_family) . " !important; }";
1340 }
1341 if ($folder_fonts[$font_family] == "Default") {
1342 $font_family = "";
1343 }
1344 }
1345 if (isset($customize_folders['folder_size']) && !empty($customize_folders['folder_size'])) {
1346 $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; }";
1347 }
1348 if (!empty($font_family)) {
1349 wp_enqueue_style('custom-google-fonts', 'https://fonts.googleapis.com/css?family=' . urlencode($font_family), false);
1350 }
1351 wp_add_inline_style('folders-media', $css_text);
1352 }
1353 }
1354 }
1355
1356 public function get_terms_hierarchical( $taxonomy ) {
1357 // $terms = get_terms( array(
1358 // 'taxonomy' => $taxonomy,
1359 // 'hide_empty' => false,
1360 // 'parent' => 0,
1361 // 'orderby' => 'meta_value_num',
1362 // 'order' => 'ASC',
1363 // 'update_count_callback' => '_update_generic_term_count',
1364 // 'meta_query' => [[
1365 // 'key' => 'wcp_custom_order',
1366 // 'type' => 'NUMERIC',
1367 // ]]
1368 // ) );
1369 //
1370 // if ( empty( $terms ) ) {
1371 // return false;
1372 // }
1373 //
1374 // $hierarchy = _get_term_hierarchy( $taxonomy );
1375 //
1376 // $hierarchical_terms = array();
1377 // if(!empty($terms)) {
1378 // foreach ($terms as $term) {
1379 // if(isset($term->term_id)) {
1380 // $hierarchical_terms[] = $term;
1381 // $hierarchical_terms = self::add_child_terms_recursive($taxonomy, $hierarchical_terms, $hierarchy, $term->term_id, 1);
1382 // }
1383 // }
1384 // }
1385 //
1386 // return $hierarchical_terms;
1387 $terms = get_terms( array(
1388 'taxonomy' => $taxonomy,
1389 'hide_empty' => false,
1390 'parent' => 0,
1391 'orderby' => 'meta_value_num',
1392 'order' => 'ASC',
1393 'hierarchical' => false,
1394 'update_count_callback' => '_update_generic_term_count',
1395 'meta_query' => [[
1396 'key' => 'wcp_custom_order',
1397 'type' => 'NUMERIC',
1398 ]]
1399 ));
1400 $hierarchical_terms = array();
1401 if(!empty($terms)) {
1402 foreach ($terms as $term) {
1403 if(!empty($term) && isset($term->term_id)) {
1404 $term->term_name = $term->name;
1405 $hierarchical_terms[] = $term;
1406 $hierarchical_terms = self::get_child_terms($taxonomy, $hierarchical_terms, $term->term_id, "-");
1407 }
1408 }
1409 }
1410 return $hierarchical_terms;
1411 }
1412
1413 public static function get_child_terms($taxonomy, $hierarchical_terms, $term_id, $separator = "-") {
1414 $terms = get_terms( array(
1415 'taxonomy' => $taxonomy,
1416 'hide_empty' => false,
1417 'parent' => $term_id,
1418 'orderby' => 'meta_value_num',
1419 'order' => 'ASC',
1420 'hierarchical' => false,
1421 'update_count_callback' => '_update_generic_term_count',
1422 'meta_query' => [[
1423 'key' => 'wcp_custom_order',
1424 'type' => 'NUMERIC',
1425 ]]
1426 ));
1427 if(!empty($terms)) {
1428 foreach ($terms as $term) {
1429 if(isset($term->name)) {
1430 $term->name = $separator . " " . $term->name;
1431 $term->term_name = trim($term->name, "-");
1432 $hierarchical_terms[] = $term;
1433 $hierarchical_terms = self::get_child_terms($taxonomy, $hierarchical_terms, $term->term_id, $separator . "-");
1434 }
1435 }
1436 }
1437
1438 return $hierarchical_terms;
1439 }
1440
1441 public function update_folder_new_term_relationships($object_id = "", $term_ids = array(), $taxonomy = "") {
1442 if(is_array($term_ids) && !empty($term_ids)) {
1443 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
1444 if($trash_folders === false) {
1445 $trash_folders = array();
1446 $initial_trash_folders = array();
1447 }
1448
1449 foreach($term_ids as $term_id) {
1450 if(isset($trash_folders[$term_id])) {
1451 unset($trash_folders[$term_id]);
1452 }
1453 }
1454
1455 if($initial_trash_folders != $trash_folders) {
1456 delete_transient("premio_folders_without_trash");
1457 set_transient("premio_folders_without_trash", $trash_folders, 3*DAY_IN_SECONDS);
1458 }
1459 }
1460 }
1461
1462 public function update_folder_term_relationships($object_id = "", $term_ids = array(), $taxonomy = "") {
1463 if(is_array($term_ids) && !empty($term_ids)) {
1464 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
1465 if($trash_folders === false) {
1466 $trash_folders = array();
1467 $initial_trash_folders = array();
1468 }
1469
1470 foreach($term_ids as $term_id) {
1471 if(isset($trash_folders[$term_id])) {
1472 unset($trash_folders[$term_id]);
1473 }
1474 }
1475
1476 if($initial_trash_folders != $trash_folders) {
1477 delete_transient("premio_folders_without_trash");
1478 set_transient("premio_folders_without_trash", $trash_folders, 3*DAY_IN_SECONDS);
1479 }
1480 }
1481 }
1482
1483 private function add_child_terms_recursive( $taxonomy, $hierarchical_terms, $hierarchy, $current_term_id, $current_depth ) {
1484
1485 if ( ! isset( $hierarchy[ $current_term_id ] ) ) {
1486 return $hierarchical_terms;
1487 }
1488
1489 foreach ( $hierarchy[ $current_term_id ] as $child_term_id ) {
1490
1491 $child_term = get_term( $child_term_id, $taxonomy );
1492
1493 $child_term->name = str_pad( '', $current_depth, '-', STR_PAD_LEFT ) . ' ' . $child_term->name;
1494
1495 $hierarchical_terms[] = $child_term;
1496
1497 $hierarchical_terms = self::add_child_terms_recursive( $taxonomy, $hierarchical_terms, $hierarchy, $child_term_id, ( $current_depth + 1 ) );
1498 }
1499
1500 return $hierarchical_terms;
1501 }
1502
1503 public function filter_attachments_list( $query ) {
1504
1505 if ( ! isset( $query->query['post_type'] ) ) {
1506 return $query;
1507 }
1508
1509 if ( is_array( $query->query['post_type'] ) && ! in_array( 'attachment', $query->query['post_type'] ) ) {
1510 return $query;
1511 }
1512 if ( ! is_array( $query->query['post_type'] ) && strpos( $query->query['post_type'], 'attachment' ) === false ) {
1513 return $query;
1514 }
1515
1516 if ( ! isset( $_REQUEST['media_folder'] ) ) {
1517 return $query;
1518 }
1519
1520 $term = sanitize_text_field(wp_unslash($_REQUEST['media_folder']));
1521 if ( $term != "-1" ) {
1522 return $query;
1523 }
1524
1525 unset( $query->query_vars['media_folder'] );
1526
1527 $tax_query = array(
1528 'taxonomy' => 'media_folder',
1529 'operator' => 'NOT EXISTS',
1530 );
1531
1532 $query->set( 'tax_query', array( $tax_query ) );
1533 $query->tax_query = new WP_Tax_Query( array( $tax_query ) );
1534
1535 $query = apply_filters( 'media_library_organizer_media_filter_attachments', $query, $_REQUEST );
1536
1537 return $query;
1538
1539 }
1540
1541 public function output_list_table_filters( $post_type, $view_name )
1542 {
1543 if ($post_type != 'attachment') {
1544 return;
1545 }
1546
1547 if ($view_name != 'bar') {
1548 return;
1549 }
1550
1551 if(!self::is_for_this_post_type('attachment')) {
1552 return;
1553 }
1554
1555 $current_term = false;
1556 if ( isset( $_REQUEST['media_folder'] ) ) {
1557 $current_term = sanitize_text_field($_REQUEST['media_folder']);
1558 }
1559
1560 wp_dropdown_categories( array(
1561 'show_option_all' => esc_html__( 'All Folders', 'folders'),
1562 'show_option_none' => esc_html__( '(Unassigned)', 'folders'),
1563 'option_none_value' => -1,
1564 'orderby' => 'meta_value_num',
1565 'order' => 'ASC',
1566 'show_count' => true,
1567 'hide_empty' => false,
1568 'update_count_callback' => '_update_generic_term_count',
1569 'echo' => true,
1570 'selected' => $current_term,
1571 'hierarchical' => true,
1572 'name' => 'media_folder',
1573 'id' => '',
1574 'class' => '',
1575 'taxonomy' => 'media_folder',
1576 'value_field' => 'slug',
1577 'meta_query' => [[
1578 'key' => 'wcp_custom_order',
1579 'type' => 'NUMERIC',
1580 ]]
1581 ) );
1582
1583 }
1584
1585
1586 function new_to_auto_draft($post) {
1587
1588 $post_type = $post->post_type;
1589
1590 if(self::is_for_this_post_type($post_type) && !isset($_REQUEST["folder_for_media"])) {
1591
1592 $post_type = self::get_custom_post_type($post_type);
1593 $selected_folder = get_option("selected_{$post_type}_folder");
1594
1595 if($selected_folder != null && !empty($selected_folder)) {
1596 $terms = get_term($selected_folder);
1597 if(!empty($terms) && isset($terms->slug)) {
1598 wp_set_object_terms($post->ID, $terms->slug, $post_type );
1599 }
1600
1601 }
1602 }
1603 }
1604
1605 public function wcp_folder_send_message_to_owner() {
1606 if (current_user_can('manage_options')) {
1607 $response = array();
1608 $response['status'] = 0;
1609 $response['error'] = 0;
1610 $response['errors'] = array();
1611 $response['message'] = "";
1612 $errorArray = [];
1613 $errorMessage = esc_html__("%s is required", 'folders');
1614 $postData = filter_input_array(INPUT_POST);
1615 if (!isset($postData['textarea_text']) || trim($postData['textarea_text']) == "") {
1616 $error = array(
1617 "key" => "textarea_text",
1618 "message" => esc_html__("Please enter your message", 'folders')
1619 );
1620 $errorArray[] = $error;
1621 }
1622 if (!isset($postData['user_email']) || trim($postData['user_email']) == "") {
1623 $error = array(
1624 "key" => "user_email",
1625 "message" => sprintf($errorMessage, __("Email", 'folders'))
1626 );
1627 $errorArray[] = $error;
1628 } else if (!filter_var($postData['user_email'], FILTER_VALIDATE_EMAIL)) {
1629 $error = array(
1630 'key' => "user_email",
1631 "message" => "Email is not valid"
1632 );
1633 $errorArray[] = $error;
1634 }
1635 if (empty($errorArray)) {
1636 if (!isset($postData['folder_help_nonce']) || trim($postData['folder_help_nonce']) == "") {
1637 $error = array(
1638 "key" => "nonce",
1639 "message" => esc_html__("Your request is not valid", 'folders')
1640 );
1641 $errorArray[] = $error;
1642 } else {
1643 if (!wp_verify_nonce($postData['folder_help_nonce'], 'wcp_folder_help_nonce')) {
1644 $error = array(
1645 "key" => "nonce",
1646 "message" => esc_html__("Your request is not valid", 'folders')
1647 );
1648 $errorArray[] = $error;
1649 }
1650 }
1651 }
1652 if (empty($errorArray)) {
1653 $text_message = self::sanitize_options($postData['textarea_text']);
1654 $email = self::sanitize_options($postData['user_email'], "email");
1655 $domain = site_url();
1656 $current_user = wp_get_current_user();
1657 $user_name = $current_user->first_name . " " . $current_user->last_name;
1658
1659 $response['status'] = 1;
1660
1661 /* sending message to Crisp */
1662 $post_message = array();
1663
1664 $message_data = array();
1665 $message_data['key'] = "Plugin";
1666 $message_data['value'] = "Folders";
1667 $post_message[] = $message_data;
1668
1669 $message_data = array();
1670 $message_data['key'] = "Domain";
1671 $message_data['value'] = $domain;
1672 $post_message[] = $message_data;
1673
1674 $message_data = array();
1675 $message_data['key'] = "Email";
1676 $message_data['value'] = $email;
1677 $post_message[] = $message_data;
1678
1679 $message_data = array();
1680 $message_data['key'] = "Message";
1681 $message_data['value'] = $text_message;
1682 $post_message[] = $message_data;
1683
1684 $api_params = array(
1685 'domain' => $domain,
1686 'email' => $email,
1687 'url' => site_url(),
1688 'name' => $user_name,
1689 'message' => $post_message,
1690 'plugin' => "Folders",
1691 'type' => "Need Help",
1692 );
1693
1694 /* Sending message to Crisp API */
1695 $crisp_response = wp_safe_remote_post("https://go.premio.io/crisp/crisp-send-message.php", array('body' => $api_params, 'timeout' => 15, 'sslverify' => true));
1696
1697 if (is_wp_error($crisp_response)) {
1698 wp_safe_remote_post("https://go.premio.io/crisp/crisp-send-message.php", array('body' => $api_params, 'timeout' => 15, 'sslverify' => false));
1699 }
1700 } else {
1701 $response['error'] = 1;
1702 $response['errors'] = $errorArray;
1703 }
1704 echo json_encode($response);
1705 }
1706 }
1707
1708 public function folder_plugin_deactivate() {
1709 if (current_user_can('manage_options')) {
1710 $postData = filter_input_array(INPUT_POST);
1711 $errorCounter = 0;
1712 $response = array();
1713 $response['status'] = 0;
1714 $response['message'] = "";
1715 $response['valid'] = 1;
1716 if(!isset($postData['reason']) || empty($postData['reason'])) {
1717 $errorCounter++;
1718 $response['message'] = "Please provide reason";
1719 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1720 $response['message'] = esc_html__("Your request is not valid", 'folders');
1721 $errorCounter++;
1722 $response['valid'] = 0;
1723 } else {
1724 $nonce = self::sanitize_options($postData['nonce']);
1725 if(!wp_verify_nonce($nonce, 'wcp_folder_deactivate_nonce')) {
1726 $response['message'] = esc_html__("Your request is not valid", 'folders');
1727 $errorCounter++;
1728 $response['valid'] = 0;
1729 }
1730 }
1731 if($errorCounter == 0) {
1732 $reason = $postData['reason'];
1733 $email = "none@none.none";
1734 if (isset($postData['email_id']) && !empty($postData['email_id']) && filter_var($postData['email_id'], FILTER_VALIDATE_EMAIL)) {
1735 $email = $postData['email_id'];
1736 }
1737 $domain = site_url();
1738 $current_user = wp_get_current_user();
1739 $user_name = $current_user->first_name." ".$current_user->last_name;
1740
1741 $response['status'] = 1;
1742
1743 /* sending message to Crisp */
1744 $post_message = array();
1745
1746 $message_data = array();
1747 $message_data['key'] = "Plugin";
1748 $message_data['value'] = "Folders";
1749 $post_message[] = $message_data;
1750
1751 $message_data = array();
1752 $message_data['key'] = "Plugin Version";
1753 $message_data['value'] = WCP_FOLDER_VERSION;
1754 $post_message[] = $message_data;
1755
1756 $message_data = array();
1757 $message_data['key'] = "Domain";
1758 $message_data['value'] = $domain;
1759 $post_message[] = $message_data;
1760
1761 $message_data = array();
1762 $message_data['key'] = "Email";
1763 $message_data['value'] = $email;
1764 $post_message[] = $message_data;
1765
1766 $message_data = array();
1767 $message_data['key'] = "WordPress Version";
1768 $message_data['value'] = esc_attr(get_bloginfo('version'));
1769 $post_message[] = $message_data;
1770
1771 $message_data = array();
1772 $message_data['key'] = "PHP Version";
1773 $message_data['value'] = PHP_VERSION;
1774 $post_message[] = $message_data;
1775
1776 $message_data = array();
1777 $message_data['key'] = "Message";
1778 $message_data['value'] = $reason;
1779 $post_message[] = $message_data;
1780
1781 $api_params = array(
1782 'domain' => $domain,
1783 'email' => $email,
1784 'url' => site_url(),
1785 'name' => $user_name,
1786 'message' => $post_message,
1787 'plugin' => "Folders",
1788 'type' => "Uninstall",
1789 );
1790
1791 /* Sending message to Crisp API */
1792 $crisp_response = wp_safe_remote_post("https://go.premio.io/crisp/crisp-send-message.php", array('body' => $api_params, 'timeout' => 15, 'sslverify' => true));
1793
1794 if (is_wp_error($crisp_response)) {
1795 wp_safe_remote_post("https://go.premio.io/crisp/crisp-send-message.php", array('body' => $api_params, 'timeout' => 15, 'sslverify' => false));
1796 }
1797 }
1798 echo json_encode($response);
1799 wp_die();
1800 }
1801 }
1802
1803 public static function ttl_fldrs() {
1804 $post_types = get_option('folders_settings');
1805 $post_types = is_array($post_types) ? $post_types : array();
1806 $total = 0;
1807 foreach ($post_types as $post_type) {
1808 $post_type = self::get_custom_post_type($post_type);
1809 $total += wp_count_terms($post_type);
1810 }
1811 return $total;
1812 }
1813
1814 public function wcp_remove_post_item()
1815 {
1816 $response = array();
1817 $response['status'] = 0;
1818 $response['error'] = 0;
1819 $response['data'] = array();
1820 $response['message'] = "";
1821 $postData = filter_input_array(INPUT_POST);
1822 if (isset($postData['post_id']) && !empty($postData['post_id'])) {
1823 wp_delete_post($postData['post_id']);
1824 $response['status'] = 1;
1825 }
1826 echo json_encode($response);
1827 wp_die();
1828 }
1829
1830 public function wcp_change_all_status()
1831 {
1832 $response = array();
1833 $response['status'] = 0;
1834 $response['error'] = 0;
1835 $response['data'] = array();
1836 $response['message'] = "";
1837 $postData = filter_input_array(INPUT_POST);
1838 $errorCounter = 0;
1839 if (!isset($postData['type']) || empty($postData['type'])) {
1840 $response['message'] = esc_html__("Your request is not valid", 'folders');
1841 $errorCounter++;
1842 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1843 $response['message'] = esc_html__("Your request is not valid", 'folders');
1844 $errorCounter++;
1845 } else if (!current_user_can("manage_categories") || ($postData['type'] == "page" && !current_user_can("edit_pages"))) {
1846 $response['message'] = esc_html__("You have not permission to update width", 'folders');
1847 $errorCounter++;
1848 } else if (!current_user_can("manage_categories") || ($postData['type'] != "page" && !current_user_can("edit_posts"))) {
1849 $response['message'] = esc_html__("You have not permission to update width", 'folders');
1850 $errorCounter++;
1851 } else {
1852 $type = self::sanitize_options($postData['type']);
1853 $nonce = self::sanitize_options($postData['nonce']);
1854 if(!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
1855 $response['message'] = esc_html__("Your request is not valid", 'folders');
1856 $errorCounter++;
1857 }
1858 }
1859 if ($errorCounter == 0) {
1860 if (isset($postData['folders']) || !empty($postData['folders'])) {
1861 $status = isset($postData['status']) ? $postData['status'] : 0;
1862 $status = self::sanitize_options($status);
1863 $folders = self::sanitize_options($postData['folders']);
1864 $folders = trim($folders, ",");
1865 $folders = explode(",", $folders);
1866 foreach ($folders as $folder) {
1867 update_term_meta($folder, "is_active", $status);
1868 }
1869 }
1870 $response['status'] = 1;
1871 }
1872 echo json_encode($response);
1873 wp_die();
1874 }
1875
1876 public function wcp_change_post_width()
1877 {
1878 $response = array();
1879 $response['status'] = 0;
1880 $response['error'] = 0;
1881 $response['data'] = array();
1882 $response['message'] = "";
1883 $postData = filter_input_array(INPUT_POST);
1884 $errorCounter = 0;
1885 if (!isset($postData['width']) || empty($postData['width'])) {
1886 $response['message'] = esc_html__("Your request is not valid", 'folders');
1887 $errorCounter++;
1888 } else if (!isset($postData['type']) || empty($postData['type'])) {
1889 $response['message'] = esc_html__("Your request is not valid", 'folders');
1890 $errorCounter++;
1891 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1892 $response['message'] = esc_html__("Your request is not valid", 'folders');
1893 $errorCounter++;
1894 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
1895 $response['message'] = esc_html__("You have not permission to update width", 'folders');
1896 $errorCounter++;
1897 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
1898 $response['message'] = esc_html__("You have not permission to update width", 'folders');
1899 $errorCounter++;
1900 } else {
1901 $type = self::sanitize_options($postData['type']);
1902 $nonce = self::sanitize_options($postData['nonce']);
1903 if(!wp_verify_nonce($nonce, 'wcp_folder_nonce_'.$type)) {
1904 $response['message'] = esc_html__("Your request is not valid", 'folders');
1905 $errorCounter++;
1906 }
1907 }
1908 if ($errorCounter == 0) {
1909 $type = self::sanitize_options($postData['type']);
1910 $width = self::sanitize_options($postData['width'], "int");
1911 $optionName = "wcp_dynamic_width_for_" . $type;
1912 update_option($optionName, $width);
1913 $response['status'] = 1;
1914 }
1915 echo json_encode($response);
1916 wp_die();
1917 }
1918
1919 public function wcp_change_multiple_post_folder()
1920 {
1921 $response = array();
1922 $response['status'] = 0;
1923 $response['error'] = 0;
1924 $response['data'] = array();
1925 $response['message'] = "";
1926 $postData = filter_input_array(INPUT_POST);
1927 $errorCounter = 0;
1928 if (!isset($postData['post_ids']) || empty($postData['post_ids'])) {
1929 $response['message'] = esc_html__("Your request is not valid", 'folders');
1930 $errorCounter++;
1931 } else if (!isset($postData['folder_id']) || empty($postData['folder_id'])) {
1932 $response['message'] = esc_html__("Your request is not valid", 'folders');
1933 $errorCounter++;
1934 } else if (!isset($postData['type']) || empty($postData['type'])) {
1935 $response['message'] = esc_html__("Your request is not valid", 'folders');
1936 $errorCounter++;
1937 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
1938 $response['message'] = esc_html__("Your request is not valid", 'folders');
1939 $errorCounter++;
1940 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
1941 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
1942 $errorCounter++;
1943 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
1944 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
1945 $errorCounter++;
1946 } else {
1947 $folder_id = self::sanitize_options($postData['folder_id']);
1948 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$folder_id)) {
1949 $response['message'] = esc_html__("Your request is not valid", 'folders');
1950 $errorCounter++;
1951 }
1952 }
1953 if ($errorCounter == 0) {
1954
1955 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
1956 if($trash_folders === false) {
1957 $trash_folders = array();
1958 $initial_trash_folders = array();
1959 }
1960
1961 $folderUndoSettings = array();
1962 $postID = self::sanitize_options($postData['post_ids']);
1963 $postID = trim($postID, ",");
1964 $folderID = self::sanitize_options($postData['folder_id']);
1965 $type = self::sanitize_options($postData['type']);
1966 $postArray = explode(",", $postID);
1967 $status = 0;
1968 if(isset($postData['status'])) {
1969 $status = self::sanitize_options($postData['status']);
1970 }
1971 $status = true;
1972
1973 $taxonomy = "";
1974 if(isset($postData['taxonomy'])) {
1975 $taxonomy = self::sanitize_options($postData['taxonomy']);
1976 }
1977 if (is_array($postArray)) {
1978 $post_type = self::get_custom_post_type($type);
1979 foreach ($postArray as $post) {
1980 $terms = get_the_terms($post, $post_type);
1981 $post_terms = array(
1982 'post_id' => $post,
1983 'terms' => $terms
1984 );
1985 foreach($post_terms as $term) {
1986 if(isset($trash_folders[$term->term_id])) {
1987 unset($trash_folders[$term->term_id]);
1988 }
1989 }
1990 $folderUndoSettings[] = $post_terms;
1991 if (!empty($terms)) {
1992 foreach ($terms as $term) {
1993 if(!empty($taxonomy) && ($term->term_id == $taxonomy || $term->slug == $taxonomy)) {
1994 if(isset($trash_folders[$term->term_id])) {
1995 unset($trash_folders[$term->term_id]);
1996 }
1997 wp_remove_object_terms($post, $term->term_id, $post_type);
1998 }
1999 }
2000 }
2001 wp_set_post_terms($post, $folderID, $post_type, $status);
2002 }
2003 }
2004 $response['status'] = 1;
2005 delete_transient("folder_undo_settings");
2006 set_transient("folder_undo_settings", $folderUndoSettings, DAY_IN_SECONDS);
2007
2008 if(isset($trash_folders[$folderID])) {
2009 unset($trash_folders[$folderID]);
2010 }
2011
2012 if($initial_trash_folders != $trash_folders) {
2013 set_transient("premio_folders_without_trash", $trash_folders, 3*DAY_IN_SECONDS);
2014 }
2015 }
2016 echo json_encode($response);
2017 wp_die();
2018 }
2019
2020 public function wcp_undo_folder_changes() {
2021 $response = array();
2022 $response['status'] = 0;
2023 $response['error'] = 0;
2024 $response['data'] = array();
2025 $response['message'] = "";
2026 $postData = filter_input_array(INPUT_POST);
2027 $errorCounter = 0;
2028 if (!isset($postData['post_type']) || empty($postData['post_type'])) {
2029 $response['message'] = esc_html__("Your request is not valid", 'folders');
2030 $errorCounter++;
2031 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2032 $response['message'] = esc_html__("Your request is not valid", 'folders');
2033 $errorCounter++;
2034 } else {
2035 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$postData['post_type'])) {
2036 $response['message'] = esc_html__("Your request is not valid", 'folders');
2037 $errorCounter++;
2038 }
2039 }
2040 if ($errorCounter == 0) {
2041 $response['status'] = 1;
2042 $folder_undo_settings = get_transient("folder_undo_settings");
2043 $type = self::sanitize_options($postData['post_type']);
2044 $post_type = self::get_custom_post_type($type);
2045 if(!empty($folder_undo_settings) && is_array($folder_undo_settings)) {
2046 $trash_folders = $initial_trash_folders = get_transient("premio_folders_without_trash");
2047 if($trash_folders === false) {
2048 $trash_folders = array();
2049 $initial_trash_folders = array();
2050 }
2051 foreach($folder_undo_settings as $item) {
2052 $terms = get_the_terms($item['post_id'], $post_type);
2053 if (!empty($terms)) {
2054 foreach ($terms as $term) {
2055 wp_remove_object_terms($item['post_id'], $term->term_id, $post_type);
2056 if(isset($trash_folders[$term->term_id])) {
2057 unset($trash_folders[$term->term_id]);
2058 }
2059 }
2060 }
2061 if(!empty($item['terms']) && is_array($item['terms'])) {
2062 foreach($item['terms'] as $term) {
2063 wp_set_post_terms($item['post_id'], $term->term_id, $post_type, true);
2064 if(isset($trash_folders[$term->term_id])) {
2065 unset($trash_folders[$term->term_id]);
2066 }
2067 }
2068 }
2069 }
2070
2071 if(!empty($terms) && $initial_trash_folders != $trash_folders) {
2072 delete_transient("premio_folders_without_trash");
2073 set_transient("premio_folders_without_trash", $trash_folders, 3*DAY_IN_SECONDS);
2074 }
2075 }
2076 }
2077 echo json_encode($response);
2078 die;
2079 }
2080
2081 public function wcp_change_post_folder()
2082 {
2083 $response = array();
2084 $response['status'] = 0;
2085 $response['error'] = 0;
2086 $response['data'] = array();
2087 $response['message'] = "";
2088 $postData = filter_input_array(INPUT_POST);
2089 $errorCounter = 0;
2090 if (!isset($postData['post_id']) || empty($postData['post_id'])) {
2091 $errorCounter++;
2092 $response['message'] = esc_html__("Your request is not valid", 'folders');
2093 } else if (!isset($postData['folder_id']) || empty($postData['folder_id'])) {
2094 $errorCounter++;
2095 $response['message'] = esc_html__("Your request is not valid", 'folders');
2096 } else if (!isset($postData['type']) || empty($postData['type'])) {
2097 $errorCounter++;
2098 $response['message'] = esc_html__("Your request is not valid", 'folders');
2099 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2100 $response['message'] = esc_html__("Your request is not valid", 'folders');
2101 $errorCounter++;
2102 } else if ($postData['type'] == "page" && !current_user_can("edit_pages")) {
2103 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2104 $errorCounter++;
2105 } else if ($postData['type'] != "page" && !current_user_can("edit_posts")) {
2106 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2107 $errorCounter++;
2108 } else {
2109 $term_id = self::sanitize_options($postData['folder_id']);
2110 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
2111 $response['message'] = esc_html__("Your request is not valid", 'folders');
2112 $errorCounter++;
2113 }
2114 }
2115 if ($errorCounter == 0) {
2116 $postID = self::sanitize_options($postData['post_id']);
2117 $folderID = self::sanitize_options($postData['folder_id']);
2118 $type = self::sanitize_options($postData['type']);
2119 $folder_post_type = self::get_custom_post_type($type);
2120 $status = 0;
2121 if(isset($postData['status'])) {
2122 $status = self::sanitize_options($postData['status']);
2123 }
2124 $status = ($status == 1)?true:false;
2125 $taxonomy = "";
2126 if(isset($postData['taxonomy'])) {
2127 $taxonomy = self::sanitize_options($postData['taxonomy']);
2128 }
2129 $terms = get_the_terms($postID, $folder_post_type);
2130 if (!empty($terms)) {
2131 foreach ($terms as $term) {
2132 if(!empty($taxonomy) && ($term->term_id == $taxonomy || $term->slug == $taxonomy)) {
2133 wp_remove_object_terms($postID, $term->term_id, $folder_post_type);
2134 }
2135 }
2136 }
2137 wp_set_post_terms($postID, $folderID, $folder_post_type, true);
2138 $response['status'] = 1;
2139 }
2140 echo json_encode($response);
2141 wp_die();
2142 }
2143
2144 public function wcp_mark_un_mark_folder()
2145 {
2146 $response = array();
2147 $response['status'] = 0;
2148 $response['error'] = 0;
2149 $response['data'] = array();
2150 $response['message'] = "";
2151 $postData = filter_input_array(INPUT_POST);
2152 $errorCounter = 0;
2153 if (!current_user_can("manage_categories")) {
2154 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2155 $errorCounter++;
2156 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
2157 $errorCounter++;
2158 $response['message'] = esc_html__("Your request is not valid", 'folders');
2159 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2160 $response['message'] = esc_html__("Your request is not valid", 'folders');
2161 $errorCounter++;
2162 } else {
2163 $term_id = self::sanitize_options($postData['term_id']);
2164 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
2165 $response['message'] = esc_html__("Your request is not valid", 'folders');
2166 $errorCounter++;
2167 }
2168 }
2169 if ($errorCounter == 0) {
2170 $term_id = self::sanitize_options($postData['term_id']);
2171 $status = get_term_meta($term_id, "is_highlighted", true);
2172 if ($status == 1) {
2173 update_term_meta($term_id, "is_highlighted", 0);
2174 $status = 0;
2175 } else {
2176 update_term_meta($term_id, "is_highlighted", 1);
2177 $status = 1;
2178 }
2179 $response['marked'] = $status;
2180 $response['id'] = $postData['term_id'];
2181 $response['status'] = 1;
2182 }
2183 echo json_encode($response);
2184 wp_die();
2185 }
2186
2187 public function wcp_make_sticky_folder()
2188 {
2189 $response = array();
2190 $response['status'] = 0;
2191 $response['error'] = 0;
2192 $response['data'] = array();
2193 $response['message'] = "";
2194 $postData = filter_input_array(INPUT_POST);
2195 $errorCounter = 0;
2196 if (!current_user_can("manage_categories")) {
2197 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2198 $errorCounter++;
2199 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
2200 $errorCounter++;
2201 $response['message'] = esc_html__("Your request is not valid", 'folders');
2202 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2203 $response['message'] = esc_html__("Your request is not valid", 'folders');
2204 $errorCounter++;
2205 } else {
2206 $term_id = self::sanitize_options($postData['term_id']);
2207 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
2208 $response['message'] = esc_html__("Your request is not valid", 'folders');
2209 $errorCounter++;
2210 }
2211 }
2212 if ($errorCounter == 0) {
2213 $term_id = self::sanitize_options($postData['term_id']);
2214 $status = get_term_meta($term_id, "is_folder_sticky", true);
2215 if ($status == 1) {
2216 update_term_meta($term_id, "is_folder_sticky", 0);
2217 $status = 0;
2218 } else {
2219 update_term_meta($term_id, "is_folder_sticky", 1);
2220 $status = 1;
2221 }
2222 $response['is_folder_sticky'] = $status;
2223 $response['id'] = $postData['term_id'];
2224 $response['status'] = 1;
2225 }
2226 echo json_encode($response);
2227 wp_die();
2228 }
2229
2230 public function wcp_save_folder_order()
2231 {
2232 $response = array();
2233 $response['status'] = 0;
2234 $response['error'] = 0;
2235 $response['data'] = array();
2236 $response['message'] = "";
2237 $postData = filter_input_array(INPUT_POST);
2238 $errorCounter = 0;
2239 if (!current_user_can("manage_categories")) {
2240 $response['message'] = esc_html__("You have not permission to update folder order", 'folders');
2241 $errorCounter++;
2242 } else if (!isset($postData['term_ids']) || empty($postData['term_ids'])) {
2243 $errorCounter++;
2244 $response['message'] = esc_html__("Your request is not valid", 'folders');
2245 } else if (!isset($postData['type']) || empty($postData['type'])) {
2246 $errorCounter++;
2247 $response['message'] = esc_html__("Your request is not valid", 'folders');
2248 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2249 $response['message'] = esc_html__("Your request is not valid", 'folders');
2250 $errorCounter++;
2251 } else {
2252 $type = self::sanitize_options($postData['type']);
2253 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
2254 $response['message'] = esc_html__("Your request is not valid", 'folders');
2255 $errorCounter++;
2256 }
2257 }
2258 if ($errorCounter == 0) {
2259 $termIds = self::sanitize_options(($postData['term_ids']));
2260 $type = self::sanitize_options($postData['type']);
2261 $termIds = trim($termIds, ",");
2262 $termArray = explode(",", $termIds);
2263 $order = 1;
2264 foreach ($termArray as $term) {
2265 if (!empty($term)) {
2266 update_term_meta($term, "wcp_custom_order", $order);
2267 $order++;
2268 }
2269 }
2270 $term_id = self::sanitize_options($postData['term_id']);
2271 $parent_id = self::sanitize_options($postData['parent_id']);
2272 $type = self::sanitize_options($postData['type']);
2273 $folder_type = self::get_custom_post_type($type);
2274 wp_update_term($term_id, $folder_type, array(
2275 'parent' => $parent_id
2276 ));
2277
2278 if($parent_id != "#" || !empty($parent_id)) {
2279 update_term_meta($parent_id, "is_active", 1);
2280 }
2281 $response['status'] = 1;
2282 $folder_type = self::get_custom_post_type($type);
2283 /* Free/Pro Class name change */
2284 $response['options'] = WCP_Tree::get_option_data_for_select($folder_type);
2285 }
2286 echo json_encode($response);
2287 wp_die();
2288 }
2289
2290 public function save_wcp_folder_state()
2291 {
2292 $response = array();
2293 $response['status'] = 0;
2294 $response['error'] = 0;
2295 $response['data'] = array();
2296 $response['message'] = "";
2297 $postData = filter_input_array(INPUT_POST);
2298 $errorCounter = 0;
2299 if (!current_user_can("manage_categories")) {
2300 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2301 $errorCounter++;
2302 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
2303 $response['message'] = esc_html__("Your request is not valid", 'folders');
2304 $errorCounter++;
2305 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2306 $response['message'] = esc_html__("Unable to create folder, Your request is not valid", 'folders');
2307 $errorCounter++;
2308 } else {
2309 $term_id = self::sanitize_options($postData['term_id']);
2310 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
2311 $response['message'] = esc_html__("Your request is not valid", 'folders');
2312 $errorCounter++;
2313 }
2314 }
2315 if ($errorCounter == 0) {
2316 $response['status'] = 1;
2317 $term_id = self::sanitize_options($postData['term_id']);
2318 $is_active = isset($postData['is_active'])?$postData['is_active']:0;
2319 $is_active = self::sanitize_options($is_active);
2320 if ($is_active == 1) {
2321 update_term_meta($term_id, "is_active", 1);
2322 } else {
2323 update_term_meta($term_id, "is_active", 0);
2324 }
2325 }
2326 echo json_encode($response);
2327 wp_die();
2328 }
2329
2330 public function wcp_update_parent_information()
2331 {
2332 $response = array();
2333 $response['status'] = 0;
2334 $response['error'] = 0;
2335 $response['data'] = array();
2336 $response['message'] = "";
2337 $postData = filter_input_array(INPUT_POST);
2338 $errorCounter = 0;
2339 if (!current_user_can("manage_categories")) {
2340 $response['message'] = esc_html__("You have not permission to update folder", 'folders');
2341 $errorCounter++;
2342 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
2343 $response['message'] = esc_html__("Your request is not valid", 'folders');
2344 $errorCounter++;
2345 } else if (!isset($postData['type']) || empty($postData['type'])) {
2346 $response['message'] = esc_html__("Your request is not valid", 'folders');
2347 $errorCounter++;
2348 } else if (!isset($postData['parent_id'])) {
2349 $response['message'] = esc_html__("Your request is not valid", 'folders');
2350 $errorCounter++;
2351 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2352 $response['message'] = esc_html__("Your request is not valid", 'folders');
2353 $errorCounter++;
2354 } else {
2355 $term_id = self::sanitize_options($postData['term_id']);
2356 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
2357 $response['message'] = esc_html__("Your request is not valid", 'folders');
2358 $errorCounter++;
2359 }
2360 }
2361 if($errorCounter == 0) {
2362 $term_id = self::sanitize_options($postData['term_id']);
2363 $parent_id = self::sanitize_options($postData['parent_id']);
2364 $type = self::sanitize_options($postData['type']);
2365 $folder_type = self::get_custom_post_type($type);
2366 wp_update_term($term_id, $folder_type, array(
2367 'parent' => $parent_id
2368 ));
2369 update_term_meta($parent_id, "is_active", 1);
2370 $response['status'] = 1;
2371 }
2372 echo json_encode($response);
2373 wp_die();
2374 }
2375
2376 public function wcp_save_parent_data()
2377 {
2378 $response = array();
2379 $response['status'] = 0;
2380 $response['error'] = 0;
2381 $response['data'] = array();
2382 $response['message'] = "";
2383 $postData = filter_input_array(INPUT_POST);
2384 $errorCounter = 0;
2385 if (!isset($postData['type']) || empty($postData['type'])) {
2386 $response['message'] = esc_html__("Your request is not valid", 'folders');
2387 $errorCounter++;
2388 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2389 $response['message'] = esc_html__("Your request is not valid", 'folders');
2390 $errorCounter++;
2391 } else if (!current_user_can("manage_categories")) {
2392 $response['message'] = esc_html__("Your request is not valid", 'folders');
2393 $errorCounter++;
2394 } else {
2395 $type = self::sanitize_options($postData['type']);
2396 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
2397 $response['message'] = esc_html__("Your request is not valid", 'folders');
2398 $errorCounter++;
2399 }
2400 }
2401 if ($errorCounter == 0) {
2402 $type = self::sanitize_options($postData['type']);
2403 $optionName = $type . "_parent_status";
2404 $response['status'] = 1;
2405 $is_active = isset($postData['is_active'])?$postData['is_active']:0;
2406 $is_active = self::sanitize_options($is_active);
2407 if ($is_active == 1) {
2408 update_option($optionName, 1);
2409 } else {
2410 update_option($optionName, 0);
2411 }
2412 }
2413 echo json_encode($response);
2414 wp_die();
2415 }
2416
2417 public function remove_muliple_folder(){
2418 $response = array();
2419 $response['status'] = 0;
2420 $response['error'] = 0;
2421 $response['data'] = array();
2422 $response['message'] = "";
2423 $postData = filter_input_array(INPUT_POST);
2424 $errorCounter = 0;
2425 $error = "";
2426 if (!current_user_can("manage_categories")) {
2427 $error = esc_html__("You have not permission to remove folder", 'folders');
2428 $errorCounter++;
2429 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
2430 $error = esc_html__("Your request is not valid", 'folders');
2431 $errorCounter++;
2432 } else if (!isset($postData['type']) || empty($postData['type'])) {
2433 $error = esc_html__("Your request is not valid", 'folders');
2434 $errorCounter++;
2435 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2436 $response['message'] = esc_html__("Your request is not valid", 'folders');
2437 $errorCounter++;
2438 } else {
2439 $type = self::sanitize_options($postData['type']);
2440 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
2441 $error = esc_html__("Your request is not valid", 'folders');
2442 $errorCounter++;
2443 }
2444 }
2445 if ($errorCounter == 0) {
2446 $term_id = self::sanitize_options($postData['term_id']);
2447 $type = self::sanitize_options($postData['type']);
2448 $response['term_ids'] = array();
2449 if(!empty($term_id)) {
2450 $term_id = trim($term_id,",");
2451 $term_ids = explode(",", $term_id);
2452 if(is_array($term_ids) && count($term_ids) > 0) {
2453 foreach ($term_ids as $term) {
2454 self::remove_folder_child_items($term, $type);
2455 }
2456 $response['term_ids'] = $term_ids;
2457 }
2458 }
2459 $is_active = 1;
2460 $folders = -1;
2461 $response['status'] = 1;
2462 $response['folders'] = $folders;
2463 $response['is_key_active'] = $is_active;
2464 } else {
2465 $response['error'] = 1;
2466 $response['message'] = $error;
2467 }
2468 echo json_encode($response);
2469 wp_die();
2470 }
2471
2472 public function wcp_remove_folder()
2473 {
2474 $response = array();
2475 $response['status'] = 0;
2476 $response['error'] = 0;
2477 $response['data'] = array();
2478 $response['message'] = "";
2479 $postData = filter_input_array(INPUT_POST);
2480 $errorCounter = 0;
2481 if (!current_user_can("manage_categories")) {
2482 $error = esc_html__("You have not permission to remove folder", 'folders');
2483 $errorCounter++;
2484 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
2485 $error = esc_html__("Your request is not valid", 'folders');
2486 $errorCounter++;
2487 } else if (!isset($postData['type']) || empty($postData['type'])) {
2488 $error = esc_html__("Your request is not valid", 'folders');
2489 $errorCounter++;
2490 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2491 $error = esc_html__("Unable to delete folder, Your request is not valid", 'folders');
2492 $errorCounter++;
2493 } else {
2494 $term_id = self::sanitize_options($postData['term_id']);
2495 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
2496 $error = esc_html__("Unable to delete folder, Your request is not valid", 'folders');
2497 $errorCounter++;
2498 }
2499 }
2500 if ($errorCounter == 0) {
2501 $term_id = self::sanitize_options($postData['term_id']);
2502 $type = self::sanitize_options($postData['type']);
2503 self::remove_folder_child_items($term_id, $type);
2504 $response['status'] = 1;
2505 $is_active = 1;
2506 $folders = -1;
2507 $response['folders'] = $folders;
2508 $response['term_id'] = $term_id;
2509 $response['is_key_active'] = $is_active;
2510 } else {
2511 $response['error'] = 1;
2512 $response['message'] = $error;
2513 }
2514 echo json_encode($response);
2515 wp_die();
2516 }
2517
2518 public function remove_folder_child_items($term_id, $post_type)
2519 {
2520 $folder_type = self::get_custom_post_type($post_type);
2521 $terms = get_terms($folder_type, array(
2522 'hide_empty' => false,
2523 'parent' => $term_id
2524 ));
2525
2526 if (!empty($terms)) {
2527 foreach ($terms as $term) {
2528 self::remove_folder_child_items($term->term_id, $post_type);
2529 }
2530 wp_delete_term($term_id, $folder_type);
2531 } else {
2532 wp_delete_term($term_id, $folder_type);
2533 }
2534 }
2535
2536 public function wcp_update_folder()
2537 {
2538 $response = array();
2539 $response['status'] = 0;
2540 $response['error'] = 0;
2541 $response['data'] = array();
2542 $response['message'] = "";
2543 $postData = $_REQUEST;
2544 $errorCounter = 0;
2545 if (!current_user_can("manage_categories")) {
2546 $error = esc_html__("You have not permission to update folder", 'folders');
2547 $errorCounter++;
2548 } else if (!isset($postData['term_id']) || empty($postData['term_id'])) {
2549 $error = esc_html__("Unable to rename folder, Your request is not valid", 'folders');
2550 $errorCounter++;
2551 } else if (!isset($postData['name']) || empty($postData['name'])) {
2552 $error = esc_html__("Folder name can no be empty", 'folders');
2553 $errorCounter++;
2554 } else if (!isset($postData['type']) || empty($postData['type'])) {
2555 $error = esc_html__("Your request is not valid", 'folders');
2556 $errorCounter++;
2557 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2558 $error = esc_html__("Unable to rename folder, Your request is not valid", 'folders');
2559 $errorCounter++;
2560 } else {
2561 $term_id = self::sanitize_options($postData['term_id']);
2562 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_term_'.$term_id)) {
2563 $error = esc_html__("Unable to rename folder, Your request is not valid", 'folders');
2564 $errorCounter++;
2565 }
2566 }
2567 if ($errorCounter == 0) {
2568 $type = self::sanitize_options($postData['type']);
2569 $folder_type = self::get_custom_post_type($type);
2570 $name = self::sanitize_options($postData['name']);
2571 $term_id = self::sanitize_options($postData['term_id']);
2572 $result = wp_update_term(
2573 $term_id,
2574 $folder_type,
2575 array(
2576 'name' => $name,
2577 )
2578 );
2579 if (!empty($result)) {
2580 $term_nonce = wp_create_nonce('wcp_folder_term_'.$result['term_id']);
2581 $response['id'] = $result['term_id'];
2582 $response['slug'] = $result['slug'];
2583 $response['status'] = 1;
2584 $response['term_title'] = $postData['name'];
2585 $response['nonce'] = $term_nonce;
2586 } else {
2587 $response['message'] = esc_html__("Unable to rename folder", 'folders');
2588 }
2589 } else {
2590 $response['error'] = 1;
2591 $response['message'] = $error;
2592 }
2593 echo json_encode($response);
2594 wp_die();
2595 }
2596
2597 public function create_slug_from_string($str)
2598 {
2599 $a = array('À', 'Á', 'Â', 'Ã', 'Ä', '�
2600 ', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?');
2601 $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
2602 return strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), str_replace($a, $b, $str)));
2603 }
2604
2605 public static function sanitize_options($value, $type = "") {
2606 $value = stripslashes($value);
2607 if($type == "int") {
2608 $value = filter_var($value, FILTER_SANITIZE_NUMBER_INT);
2609 } else if($type == "email") {
2610 $value = filter_var($value, FILTER_SANITIZE_EMAIL);
2611 } else {
2612 $value = filter_var($value, FILTER_SANITIZE_STRING);
2613 }
2614 return $value;
2615 }
2616
2617 public function wcp_add_new_folder()
2618 {
2619 $response = array();
2620 $response['status'] = 0;
2621 $response['error'] = 0;
2622 $response['login'] = 1;
2623 $response['data'] = array();
2624 $response['message'] = "";
2625 $response['message2'] = "";
2626 $postData = $_REQUEST;
2627 $errorCounter = 0;
2628 $error= "";
2629 if (!current_user_can("manage_categories")) {
2630 $error = esc_html__("You have not permission to add folder", 'folders');
2631 $errorCounter++;
2632 } else if (!isset($postData['name']) || empty($postData['name'])) {
2633 $error = esc_html__("Folder name can no be empty", 'folders');
2634 $errorCounter++;
2635 } else if (!isset($postData['type']) || empty($postData['type'])) {
2636 $error = esc_html__("Your request is not valid", 'folders');
2637 $errorCounter++;
2638 } else if (!isset($postData['nonce']) || empty($postData['nonce'])) {
2639 $response['login'] = 0;
2640 $error = esc_html__("Unable to create folder, Your request is not valid", 'folders');
2641 $errorCounter++;
2642 } else {
2643 $type = self::sanitize_options($postData['type']);
2644 if(!wp_verify_nonce($postData['nonce'], 'wcp_folder_nonce_'.$type)) {
2645 $response['login'] = 0;
2646 $error = esc_html__("Unable to create folder, Your request is not valid", 'folders');
2647 $errorCounter++;
2648 }
2649 }
2650 if ($errorCounter == 0) {
2651 $parent = isset($postData['parent_id']) && !empty($postData['parent_id']) ? $postData['parent_id'] : 0;
2652 $parent_menu = isset($postData['parent_menu']) && !empty($postData['parent_menu']) ? $postData['parent_menu'] : 0;
2653 $parent_ids = isset($postData['parent_ids']) && !empty($postData['parent_ids']) ? $postData['parent_ids'] : 0;
2654 $parent = self::sanitize_options($parent);
2655 $type = self::sanitize_options($postData['type']);
2656 $folder_type = self::get_custom_post_type($type);
2657 $term_name = self::sanitize_options($postData['name']);
2658 $term = term_exists($term_name, $folder_type, $parent);
2659 $term_id = 0;
2660 if (!(0 !== $term && null !== $term)) {
2661 $folders = $postData['name'];
2662 $folders = explode(",", $folders);
2663 $foldersArray = array();
2664 $order = isset($postData['order']) ? $postData['order'] : 0;
2665 $order = self::sanitize_options($order);
2666
2667 $is_active = 1;
2668 $total_folders = -1;
2669
2670 if(!$is_active) {
2671 if (($total_folders + count($folders)) > 10) {
2672 $response['status'] = -1;
2673 echo json_encode($response);
2674 wp_die();
2675 }
2676 }
2677 foreach ($folders as $key => $folder) {
2678 $folder = trim($folder);
2679 $slug = self::create_slug_from_string($folder) . "-" . time();
2680
2681 $result = wp_insert_term(
2682 urldecode($folder), // the term
2683 $folder_type, // the taxonomy
2684 array(
2685 'parent' => $parent,
2686 'slug' => $slug
2687 )
2688 );
2689 if (!empty($result)) {
2690 $term_id = $result['term_id'];
2691 $total_folders++;
2692 $response['id'] = $result['term_id'];
2693 $response['status'] = 1;
2694 $term = get_term($result['term_id'], $folder_type);
2695 $order = $order + $key;
2696 $term_nonce = wp_create_nonce('wcp_folder_term_' . $term->term_id);
2697
2698 $folder_item = array();
2699 $folder_item['parent_id'] = $parent;
2700 $folder_item['slug'] = $term->slug;
2701 $folder_item['nonce'] = $term_nonce;
2702 $folder_item['term_id'] = $result['term_id'];
2703 $folder_item['title'] = $folder;
2704 $folder_item['parent_id'] = empty($postData['parent_id']) ? "0" : $postData['parent_id'];
2705 $folder_item['is_sticky'] = 0;
2706 $folder_item['is_high'] = 0;
2707
2708 update_term_meta($result['term_id'], "wcp_custom_order", $order);
2709 if ($parent != 0) {
2710 update_term_meta($parent, "is_active", 1);
2711 }
2712
2713 if (isset($postData['is_duplicate']) && $postData['is_duplicate'] == true) {
2714 if (isset($postData['duplicate_from']) && !empty($postData['duplicate_from'])) {
2715 $term_id = $postData['duplicate_from'];
2716
2717 $term_data = get_term($term_id, $folder_type);
2718 if (!empty($term_data)) {
2719 $is_sticky = get_term_meta($term_id, "is_folder_sticky", true);
2720
2721 if ($is_sticky == 1) {
2722 add_term_meta($term->term_id, "is_folder_sticky", 1);
2723 $folder_item['is_sticky'] = 1;
2724 }
2725
2726 $status = get_term_meta($term_id, "is_highlighted", true);
2727 if ($status == 1) {
2728 add_term_meta($term->term_id, "is_highlighted", 1);
2729 $folder_item['is_high'] = 1;
2730 }
2731
2732 $postArray = get_posts(
2733 array(
2734 'posts_per_page' => -1,
2735 'post_type' => $type,
2736 'tax_query' => array(
2737 array(
2738 'taxonomy' => $folder_type,
2739 'field' => 'term_id',
2740 'terms' => $term_id,
2741 )
2742 )
2743 )
2744 );
2745 if (!empty($postArray)) {
2746 foreach ($postArray as $p) {
2747 wp_set_post_terms($p->ID, $term->term_id, $folder_type, true);
2748 }
2749 }
2750 }
2751 }
2752 }
2753
2754 if($parent_menu && !empty($parent_ids)) {
2755 $order = isset($postData['order']) ? $postData['order'] : 0;
2756 $parent_ids = trim($parent_ids, ",");
2757 $parent_ids = explode(",", $parent_ids);
2758 $folder_order = 0;
2759 $parents = "";
2760 if(is_array($parent_ids) && count($parent_ids)>0) {
2761 foreach ($parent_ids as $key=>$value) {
2762 if($value != "#") {
2763 delete_term_meta($value, "wcp_custom_order");
2764 add_term_meta( $value, "wcp_custom_order", $folder_order );
2765 } else if(!empty($term_id)) {
2766 delete_term_meta($term_id, "wcp_custom_order");
2767 add_term_meta( $term_id, "wcp_custom_order", $folder_order );
2768 }
2769 $folder_order++;
2770 }
2771 }
2772 }
2773
2774 $foldersArray[] = $folder_item;
2775 }
2776
2777 if (!empty($foldersArray)) {
2778 $response['is_key_active'] = $is_active;
2779 $response['folders'] = $total_folders;
2780 $response['parent_id'] = empty($parent) ? "#" : $parent;
2781
2782 $response['status'] = 1;
2783 $response['data'] = $foldersArray;
2784 }
2785 }
2786 } else {
2787 $response['error'] = 1;
2788 $response['message'] = esc_html__("Folder name already exists", 'folders');
2789 }
2790 } else {
2791 $response['error'] = 1;
2792 $response['message'] = $error;
2793 }
2794 echo json_encode($response);
2795 wp_die();
2796 }
2797
2798 public function is_for_this_post_type($post_type)
2799 {
2800 $post_types = get_option('folders_settings');
2801 $post_types = is_array($post_types)?$post_types:array();
2802 return in_array($post_type, $post_types);
2803 }
2804
2805 public function is_active_for_screen()
2806 {
2807 global $typenow, $current_screen;
2808
2809 $postData = filter_input_array(INPUT_POST);
2810
2811 global $current_screen;
2812
2813 if (self::is_for_this_post_type($typenow) && ('edit' == $current_screen->base || 'upload' == $current_screen->base)) {
2814 return true;
2815 }
2816
2817 $post_types = get_option('folders_settings');
2818 $post_types = is_array($post_types)?$post_types:array();
2819
2820 if(empty($typenow) && 'upload' == $current_screen->base ) {
2821 $typenow = "attachment";
2822 if (self::is_for_this_post_type($typenow)) {
2823 return true;
2824 }
2825 }
2826 return false;
2827 }
2828
2829 public function is_add_update_screen()
2830 {
2831 global $current_screen;
2832 $current_type = $current_screen->base;
2833 $action = $current_screen->action;
2834 $post_types = get_option('folders_settings');
2835 $post_types = is_array($post_types)?$post_types:array();
2836 global $typenow;
2837 if (in_array($current_type, $post_types) && in_array($action, array("add", ""))) {
2838 $license_data = self::get_license_key_data();
2839
2840 $is_active = 1;
2841 $folders = -1;
2842 $response['folders'] = $folders;
2843 $response['is_key_active'] = $is_active;
2844 }
2845 }
2846
2847 public static function get_custom_post_type($post_type)
2848 {
2849 if ($post_type == "post") {
2850 return "post_folder";
2851 } else if ($post_type == "page") {
2852 return "folder";
2853 } else if ($post_type == "attachment") {
2854 return "media_folder";
2855 }
2856 return $post_type . '_folder';
2857 }
2858
2859 public function admin_footer()
2860 {
2861 if (self::is_active_for_screen()) {
2862 global $typenow;
2863
2864 self::set_default_values_if_not_exists();
2865
2866 $ttpsts = self::get_ttlpst($typenow);
2867
2868 $ttemp = self::get_tempt_posts($typenow);
2869
2870 $folder_type = self::get_custom_post_type($typenow);
2871 /* Do not change: Free/Pro Class name change */
2872 $tree_data = WCP_Tree::get_full_tree_data($folder_type);
2873 $terms_data = $tree_data['string'];
2874 $sticky_string = $tree_data['sticky_string'];
2875 $terms_html = WCP_Tree::get_option_data_for_select($folder_type);
2876 $form_html = WCP_Forms::get_form_html($terms_html);
2877 include_once dirname(dirname(__FILE__)) . WCP_DS . "/templates" . WCP_DS . "admin" . WCP_DS . "admin-content.php";
2878 }
2879
2880 global $pagenow;
2881 if ( 'plugins.php' !== $pagenow ) {
2882
2883 } else {
2884 if (current_user_can('manage_options')) {
2885 include_once dirname(dirname(__FILE__)) . WCP_DS . "/templates" . WCP_DS . "admin" . WCP_DS . "folder-deactivate-form.php";
2886 }
2887 }
2888 }
2889
2890 public function get_ttlpst($post_type = "")
2891 {
2892 global $typenow;
2893 if (empty($post_type)) {
2894 $post_type = $typenow;
2895 }
2896 $item_count = null;
2897 if(has_filter("premio_folder_all_categorized_items")) {
2898 $item_count = apply_filters("premio_folder_all_categorized_items", $post_type);
2899 }
2900 if($item_count === null) {
2901 if ($post_type == "attachment") {
2902 $item_count = wp_count_posts($post_type)->inherit;
2903 } else {
2904 $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;
2905 }
2906 }
2907 return $item_count;
2908 }
2909
2910 public function autoload()
2911 {
2912 $files = array(
2913 'WCP_Tree_View' => WCP_DS . "includes" . WCP_DS . "tree.class.php",
2914 'WCP_Form_View' => WCP_DS . "includes" . WCP_DS . "form.class.php",
2915 'WCP_Folder_WPML' => WCP_DS . "includes" . WCP_DS . "class-wpml.php",
2916 'WCP_Folder_PolyLang' => WCP_DS . "includes" . WCP_DS . "class-polylang.php",
2917 );
2918
2919 foreach ($files as $file) {
2920 if (file_exists(dirname(dirname(__FILE__)) . $file)) {
2921 include_once dirname(dirname(__FILE__)) . $file;
2922 }
2923 }
2924 }
2925
2926 public function create_folder_terms()
2927 {
2928 $options = get_option('folders_settings');
2929 $options = is_array($options)?$options:array();
2930 $old_plugin_status = 0;
2931 $posts = array();
2932 if (!empty($options)) {
2933 foreach ($options as $option) {
2934 if (!(strpos($option, 'folder4') === false) && $old_plugin_status == 0) {
2935 $old_plugin_status = 1;
2936 }
2937 if (in_array($option, array("page", "post", "attachment"))) {
2938 $posts[] = str_replace("folder4", "", $option);
2939 } else {
2940 $posts[] = $option;
2941 }
2942 }
2943 if(!empty($posts)) {
2944 update_option('folders_settings', $posts);
2945 }
2946 }
2947 if ($old_plugin_status == 1) {
2948 update_option("folders_show_in_menu", "on");
2949 $old_plugin_var = get_option("folder_old_plugin_status");
2950 if (empty($old_plugin_var) || $old_plugin_var == null) {
2951 update_option("folder_old_plugin_status", "1");
2952 }
2953 }
2954 $posts = get_option('folders_settings');
2955 if (!empty($posts)) {
2956 foreach ($posts as $post_type) {
2957 $labels = array(
2958 'name' => esc_html__('Folders', 'folders'),
2959 'singular_name' => esc_html__('Folder', 'folders'),
2960 'all_items' => esc_html__('All Folders', 'folders'),
2961 'edit_item' => esc_html__('Edit Folder', 'folders'),
2962 'update_item' => esc_html__('Update Folder', 'folders'),
2963 'add_new_item' => esc_html__('Add New Folder', 'folders'),
2964 'new_item_name' => esc_html__('Add folder name', 'folders'),
2965 'menu_name' => esc_html__('Folders', 'folders'),
2966 'search_items' => esc_html__('Search Folders', 'folders'),
2967 'parent_item' => esc_html__('Parent Folder', 'folders'),
2968 );
2969
2970 $args = array(
2971 'label' => esc_html__('Folder', 'folders'),
2972 'labels' => $labels,
2973 'show_tagcloud' => false,
2974 'hierarchical' => true,
2975 'public' => false,
2976 'show_ui' => true,
2977 'show_in_menu' => false,
2978 'show_in_rest' => true,
2979 'show_admin_column' => true,
2980 'update_count_callback' => '_update_post_term_count',
2981 // 'update_count_callback' => '_update_generic_term_count',
2982 'query_var' => true,
2983 'rewrite' => false,
2984 'capabilities' => array(
2985 'manage_terms' => 'manage_categories',
2986 'edit_terms' => 'manage_categories',
2987 'delete_terms' => 'manage_categories',
2988 'assign_terms' => 'manage_categories'
2989 )
2990 );
2991
2992 $folder_post_type = self::get_custom_post_type($post_type);
2993
2994 register_taxonomy(
2995 $folder_post_type,
2996 $post_type,
2997 $args
2998 );
2999 }
3000 }
3001
3002 $postData = filter_input_array(INPUT_POST);
3003
3004 if(current_user_can("manage_categories") && isset($postData['folder_nonce'])) {
3005 if(wp_verify_nonce($postData['folder_nonce'], "folder_settings")) {
3006 if (isset($postData['folders_show_in_menu']) && !empty($postData['folders_show_in_menu'])) {
3007 $show_menu = "off";
3008 if ($postData['folders_show_in_menu'] == "on") {
3009 $show_menu = "on";
3010 }
3011 update_option("folders_show_in_menu", $show_menu);
3012 }
3013
3014 if (isset($postData['folders_settings1'])) {
3015 $posts = array();
3016 if (isset($postData['folders_settings']) && is_array($postData['folders_settings'])) {
3017 foreach ($postData['folders_settings'] as $key => $val) {
3018 $posts[] = $val;
3019 }
3020 }
3021 update_option("folders_settings", $posts);
3022 }
3023
3024 if (isset($_POST['folders_settings1'])) {
3025 $posts = array();
3026 if (isset($_POST['default_folders']) && is_array($_POST['default_folders'])) {
3027 foreach ($_POST['default_folders'] as $key => $val) {
3028 $posts[$key] = $val;
3029 }
3030 }
3031 update_option("default_folders", $posts);
3032 }
3033
3034 if (isset($_POST['customize_folders'])) {
3035 $posts = array();
3036 if (isset($_POST['customize_folders']) && is_array($_POST['customize_folders'])) {
3037 foreach ($_POST['customize_folders'] as $key => $val) {
3038 $posts[$key] = $val;
3039 }
3040 }
3041 update_option("customize_folders", $posts);
3042 }
3043
3044 $setting_page = $this->getFolderSettingsURL();
3045 if(!empty($setting_page)) {
3046 $page = isset($_POST['tab_page'])?$_POST['tab_page']:"";
3047 $type = filter_input(INPUT_GET, 'setting_page', FILTER_SANITIZE_STRING);
3048 $type = empty($type)?"":"&setting_page=".$type;
3049 $setting_page = $setting_page.$type;
3050 if(!empty($page)) {
3051 $setting_page .= "&setting_page=".$page;
3052 }
3053 wp_redirect($setting_page."&note=1");
3054 exit;
3055 } else if(isset($_POST['folder_page']) && !empty($_POST['folder_page'])) {
3056 wp_redirect($_POST['folder_page']);
3057 exit;
3058 }
3059 }
3060 }
3061
3062 // $old_version = get_option("folder_old_plugin_status");
3063 // if($old_version !== false && $old_version == 1) {
3064 // $tlfs = get_option("folder_old_plugin_folder_status");
3065 // if($tlfs === false) {
3066 // $total = self::ttl_fldrs();
3067 // if($total <= 10) {
3068 // $total = 10;
3069 // };
3070 // update_option("folder_old_plugin_folder_status", $total);
3071 // self::$folders = $total;
3072 // } else {
3073 // self::$folders = $tlfs;
3074 // }
3075 // }
3076 //
3077 // $tlfs = get_option("folder_old_plugin_folder_status");
3078 // if($tlfs === false) {
3079 // self::$folders = 10;
3080 // } else {
3081 // self::$folders = $tlfs;
3082 // }
3083 }
3084
3085 function searchForId($id, $menu)
3086 {
3087 if ($menu) {
3088 foreach ($menu as $key => $val) {
3089 if (array_key_exists(2, $val)) {
3090 $stripVal = explode('=', $val[2]);
3091 }
3092 if (array_key_exists(1, $stripVal)) {
3093 $stripVal = $stripVal[1];
3094 }
3095 if ($stripVal === $id) {
3096 return $key;
3097 }
3098 }
3099 }
3100 }
3101
3102 function create_menu_for_folders()
3103 {
3104 global $menu;
3105 self::check_and_set_post_type();
3106
3107 $folder_types = get_option("folders_settings");
3108 if (empty($folder_types)) {
3109 return;
3110 }
3111
3112 foreach ($folder_types as $type) {
3113 $itemKey = self::searchForId($type, $menu);
3114 switch (true) {
3115 case ($type == 'attachment'):
3116 $itemKey = 10;
3117 $edit = 'upload.php';
3118 break;
3119 case ($type === 'post'):
3120 $edit = 'edit.php';
3121 $itemKey = 5;
3122 break;
3123 default:
3124 $edit = 'edit.php';
3125 break;
3126 }
3127
3128 $folder = $type == 'attachment' ? 'media' : $type;
3129 $upper = $type == 'attachment' ? 'Media' : ucwords(str_replace(array('-', '_'), ' ', $type));
3130 if ($type == 'page') {
3131 $tax_slug = 'folder';
3132 } else {
3133 $tax_slug = $folder . '_folder';
3134 }
3135
3136
3137 if ($type == 'attachment') {
3138 add_menu_page('Media Folders', 'Media Folders', 'publish_pages', "{$edit}?type=folder", false, 'dashicons-portfolio', "{$itemKey}.5");
3139 } else {
3140 add_menu_page($upper . ' Folders', "{$upper} Folders", 'publish_pages', "{$edit}?post_type={$type}&type=folder", false, 'dashicons-portfolio', "{$itemKey}.5");
3141 }
3142 $terms = get_terms($tax_slug, array(
3143 'hide_empty' => true,
3144 'parent' => 0,
3145 'orderby' => 'meta_value_num',
3146 'order' => 'ASC',
3147 'hierarchical' => false,
3148 'meta_query' => [[
3149 'key' => 'wcp_custom_order',
3150 'type' => 'NUMERIC',
3151 ]]
3152 )
3153 );
3154
3155 if ($terms) {
3156 foreach ($terms as $term) {
3157 if ($type == 'attachment') {
3158 add_submenu_page("{$edit}?type=folder", $term->name, $term->name, 'publish_pages', "{$edit}?post_type=attachment&media_folder={$term->slug}", false);
3159 } else {
3160 add_submenu_page("{$edit}?post_type={$type}&type=folder", $term->name, $term->name, 'publish_pages', "{$edit}?post_type={$type}&{$tax_slug}={$term->slug}", false);
3161 }
3162 }
3163 }
3164 }
3165 }
3166
3167 function folders_admin_styles()
3168 {
3169 if (self::is_active_for_screen()) {
3170 wp_enqueue_style('wcp-folders-fa', plugin_dir_url(dirname(__FILE__)) . 'assets/css/folder-icon.css', array(), WCP_FOLDER_VERSION);
3171 wp_enqueue_style('wcp-folders-admin', plugin_dir_url(dirname(__FILE__)) . 'assets/css/design.min.css', array(), WCP_FOLDER_VERSION);
3172 wp_enqueue_style('wcp-folders-jstree', plugin_dir_url(dirname(__FILE__)) . 'assets/css/jstree.min.css', array(), WCP_FOLDER_VERSION);
3173 wp_enqueue_style('wcp-folders-mcustomscrollbar', WCP_FOLDER_URL . 'assets/css/jquery.mcustomscrollbar.min.css', array(),WCP_FOLDER_VERSION);
3174 wp_enqueue_style('wcp-folders-css', plugin_dir_url(dirname(__FILE__)) . 'assets/css/folders.min.css', array(), WCP_FOLDER_VERSION);
3175 }
3176 wp_register_style('wcp-css-handle', false);
3177 wp_enqueue_style('wcp-css-handle');
3178 $css = "
3179 .wcp-folder-upgrade-button {color: #FF5983; font-weight: bold; display: inline-block;border: solid 1px #FF5983;border-radius: 4px;padding: 0 5px;}
3180 ";
3181 if (self::is_active_for_screen()) {
3182 global $typenow;
3183 $width = get_option("wcp_dynamic_width_for_" . $typenow);
3184 $width = esc_attr($width);
3185 $width = intval($width);
3186 $width = empty($width)||!is_numeric($width)?280:$width;
3187 if($width > 1200) {
3188 $width = 280;
3189 }
3190 $width = intval($width);
3191 $display_status = "wcp_dynamic_display_status_" . $typenow;
3192 $display_status = get_option($display_status);
3193 if($display_status != "hide") {
3194 if (!empty($width) && is_numeric($width)) {
3195 if (function_exists('is_rtl') && is_rtl()) {
3196 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-right:" . ($width + 20) . "px}";
3197 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-left:0px}";
3198 } else {
3199 $css .= "body.wp-admin #wpcontent {padding-left:" . ($width + 20) . "px}";
3200 }
3201 }
3202 } else {
3203 if (function_exists('is_rtl') && is_rtl()) {
3204 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-right:20px}";
3205 $css .= "html[dir='rtl'] body.wp-admin #wpcontent {padding-left:0px}";
3206 } else {
3207 $css .= "body.wp-admin #wpcontent {padding-left:20px}";
3208 }
3209 }
3210 if (!empty($width) && is_numeric($width)) {
3211 if($width > 1200) {
3212 $width = 280;
3213 }
3214 $width = intval($width);
3215 $css .= ".wcp-content {width: {$width}px}";
3216 }
3217 global $typenow;
3218 $post_type = self::get_custom_post_type($typenow);
3219 $css .= "body:not(.woocommerce-page) .wp-list-table th#taxonomy-{$post_type} { width: 130px !important; } @media screen and (max-width: 1180px) { body:not(.woocommerce-page) .wp-list-table th#taxonomy-{$post_type} { width: 90px !important; }} @media screen and (max-width: 960px) { body:not(.woocommerce-page) .wp-list-table th#taxonomy-{$post_type} { width: auto !important; }}";
3220 }
3221 wp_add_inline_style('wcp-css-handle', $css);
3222
3223 if (self::is_active_for_screen()) {
3224 global $typenow;
3225 add_filter('views_edit-' . $typenow, array($this, 'wcp_check_for_child_folders'));
3226 }
3227 }
3228
3229 function wcp_check_for_child_folders($content)
3230 {
3231 $termId = 0;
3232 global $typenow;
3233 $post_type = self::get_custom_post_type($typenow);
3234 if (isset($_GET[$post_type]) && !empty($_GET[$post_type])) {
3235 $term = $_GET[$post_type];
3236 $term = get_term_by("slug", $term, $post_type);
3237 if (!empty($term)) {
3238 $termId = $term->term_id;
3239 }
3240 }
3241 $terms = get_terms($post_type, array(
3242 'hide_empty' => false,
3243 'parent' => $termId,
3244 'orderby' => 'meta_value_num',
3245 'order' => 'ASC',
3246 'hierarchical' => false,
3247 'update_count_callback' => '_update_generic_term_count',
3248 'meta_query' => [[
3249 'key' => 'wcp_custom_order',
3250 'type' => 'NUMERIC',
3251 ]]
3252 ));
3253 $optionName = "wcp_folder_display_status_" . $typenow;
3254 $optionValue = get_option($optionName);
3255 $class = (!empty($optionValue) && $optionValue == "hide")?"":"active";
3256 $customize_folders = get_option('customize_folders');
3257 $show_in_page = isset($customize_folders['show_in_page'])?$customize_folders['show_in_page']:"hide";
3258 if(empty($show_in_page)) {
3259 $show_in_page = "hide";
3260 }
3261 if($show_in_page == "show") {
3262 echo '<div class="tree-structure-content ' . $class . '"><div class="tree-structure" id="list-folder-' . $termId . '" data-id="' . $termId . '">';
3263 echo '<ul>';
3264 foreach ($terms as $term) {
3265 $status = get_term_meta($term->term_id, "is_highlighted", true);
3266 ?>
3267 <li class="grid-view" data-id="<?php echo $term->term_id ?>" id="folder_<?php echo $term->term_id ?>">
3268 <div class="folder-item is-folder" data-id="<?php echo $term->term_id ?>">
3269 <a title='<?php echo $term->name ?>' id="folder_view_<?php echo $term->term_id ?>"
3270 class="folder-view <?php echo ($status == 1) ? "is-high" : "" ?>"
3271 data-id="<?php echo $term->term_id ?>">
3272 <span class="folder item-name"><span id="wcp_folder_text_<?php echo $term->term_id ?>"
3273 class="folder-title"><?php echo $term->name ?></span></span>
3274 <!--<span class="folder-option"></span>-->
3275 </a>
3276 </div>
3277 </li>
3278 <?php
3279 }
3280 echo '</ul>';
3281 echo '<div class="clear clearfix"></div>';
3282 echo '</div>';
3283 echo '<div class="folders-toggle-button"><span></span></div>';
3284 echo '</div>';
3285 }
3286 if(!empty($content) && is_array($content)) {
3287 echo '<ul class="subsubsub">';
3288 foreach($content as $k=>$v) {
3289 echo "<li class='{$k}'>{$v}</li>";
3290 }
3291 echo '</ul>';
3292 }
3293 }
3294
3295 function folders_admin_scripts($hook)
3296 {
3297 if (self::is_active_for_screen()) {
3298 global $typenow;
3299 /* Free/Pro Version change */
3300 wp_enqueue_script('wcp-folders-jstree', plugin_dir_url(dirname(__FILE__)) . 'assets/js/jstree.min.js', array('jquery'), WCP_FOLDER_VERSION);
3301 wp_enqueue_script('wcp-folders-mcustomscrollbar', plugin_dir_url(dirname(__FILE__)) . 'assets/js/jquery.mcustomscrollbar.min.js', array(), WCP_FOLDER_VERSION);
3302 wp_enqueue_script('wcp-folders-custom', plugin_dir_url(dirname(__FILE__)) . 'assets/js/folders.min.js', array('jquery', 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'backbone'), WCP_FOLDER_VERSION);
3303 wp_enqueue_script('wcp-jquery-touch', plugin_dir_url(dirname(__FILE__)) . 'assets/js/jquery.ui.touch-punch.min.js', array('jquery'), WCP_FOLDER_VERSION);
3304
3305 $post_type = self::get_custom_post_type($typenow);
3306
3307 if ($typenow == "attachment") {
3308 $admin_url = admin_url("upload.php?post_type=attachment&media_folder=");
3309 } else {
3310 $admin_url = admin_url("edit.php?post_type=" . $typenow);
3311 if (isset($_GET['s']) && !empty($_GET['s'])) {
3312 $admin_url .= "&s=" . $_GET['s'];
3313 }
3314 $admin_url .= "&{$post_type}=";
3315 }
3316
3317 $current_url = $admin_url;
3318 if(isset($_GET[$post_type]) && !empty($_GET[$post_type])) {
3319 $current_url .= $_GET[$post_type];
3320 }
3321
3322
3323 $is_active = 1;
3324 $folders = -1;
3325 /* For free: upgrade URL, for Pro: Register Key URL */
3326 $register_url = $this->getFoldersUpgradeURL();
3327
3328 $is_rtl = 0;
3329 if ( function_exists( 'is_rtl' ) && is_rtl() ) {
3330 $is_rtl = 1;
3331 }
3332
3333 $can_manage_folder = current_user_can("manage_categories")?1:0;
3334 $width = get_option("wcp_dynamic_width_for_" . $typenow);
3335 $width = intval($width);
3336 $width = empty($width)||!is_numeric($width)?280:$width;
3337 if($width > 1200) {
3338 $width = 280;
3339 }
3340 $post_type = self::get_custom_post_type($typenow);
3341 $taxonomy_status = 0;
3342 $selected_taxonomy = "";
3343 if(!isset($_GET[$post_type]) || empty($_GET[$post_type])) {
3344 $taxonomy_status = 1;
3345 } else if(isset($_GET[$post_type]) && !empty($_GET[$post_type])) {
3346 $selected_taxonomy = $_GET[$post_type];
3347
3348 $term = get_term_by('slug', $selected_taxonomy, $post_type);
3349 if (!empty($term) && is_object($term)) {
3350 $selected_taxonomy = $term->term_id;
3351 } else {
3352 $selected_taxonomy = "";
3353 $selected_taxonomy = "";
3354 }
3355 }
3356 $customize_folders = get_option('customize_folders');
3357 $show_in_page = isset($customize_folders['show_in_page'])?$customize_folders['show_in_page']:"hide";
3358 if(empty($show_in_page)) {
3359 $show_in_page = "hide";
3360 }
3361 $taxonomies = self::get_terms_hierarchical($post_type);
3362 $use_folder_undo = !isset($customize_folders['use_folder_undo'])?"yes":$customize_folders['use_folder_undo'];
3363 $defaultTimeout = !isset($customize_folders['default_timeout'])?5:intval($customize_folders['default_timeout']);
3364 if(empty($defaultTimeout) || !is_numeric($defaultTimeout) || $defaultTimeout < 0) {
3365 $defaultTimeout = 5;
3366 }
3367 $defaultTimeout = $defaultTimeout*1000;
3368
3369 $folder_settings = array();
3370 foreach($taxonomies as $taxonomy) {
3371 $is_sticky = get_term_meta($taxonomy->term_id, "is_folder_sticky", true);
3372 $is_high = get_term_meta($taxonomy->term_id, "is_highlighted", true);
3373 $folder_settings[] = array(
3374 'folder_id' => $taxonomy->term_id,
3375 'is_sticky' => intval($is_sticky),
3376 'is_high' => intval($is_high),
3377 'nonce' => wp_create_nonce('wcp_folder_term_'.$taxonomy->term_id),
3378 'is_deleted' => 0,
3379 'slug' => $taxonomy->slug,
3380 'folder_count' => intval($taxonomy->trash_count)
3381 );
3382 }
3383
3384 $response['terms'] = $taxonomies;
3385 $currentPage = (isset($_GET['paged']) && !empty($_GET['paged']) && is_numeric($_GET['paged']) && $_GET['paged'] > 0)?$_GET['paged']:1;
3386 $hasStars = self::check_for_setting("has_stars", "general");
3387 $hasChild = self::check_for_setting("has_child", "general");
3388 $hasChild = empty($hasChild)?0:1;
3389 $hasStars = empty($hasStars)?0:1;
3390 wp_localize_script('wcp-folders-custom', 'wcp_settings', array(
3391 'ajax_url' => admin_url('admin-ajax.php'),
3392 'upgrade_url' => $this->getFoldersUpgradeURL(),
3393 'post_type' => $typenow,
3394 'page_url' => $admin_url,
3395 'current_url' => $current_url,
3396 'ajax_image' => plugin_dir_url(dirname(__FILE__)) . "assets/images/ajax-loader.gif",
3397 'is_key_active' => $is_active,
3398 'folders' => $folders,
3399 'register_url' => $register_url,
3400 'isRTL' => $is_rtl,
3401 'nonce' => wp_create_nonce('wcp_folder_nonce_'.$typenow),
3402 'can_manage_folder' => $can_manage_folder,
3403 'folder_width' => $width,
3404 'taxonomy_status' => $taxonomy_status,
3405 'selected_taxonomy' => $selected_taxonomy,
3406 'show_in_page' => $show_in_page,
3407 'svg_file' => WCP_FOLDER_URL.'assets/images/pin.png',
3408 'taxonomies' => $taxonomies,
3409 'folder_settings' => $folder_settings,
3410 'hasStars' => $hasStars,
3411 'hasChildren' => $hasChild,
3412 'currentPage' => $currentPage,
3413 'useFolderUndo' => $use_folder_undo,
3414 'defaultTimeout' => $defaultTimeout,
3415 ));
3416 } else {
3417 self::is_add_update_screen();
3418 }
3419
3420 if($hook == "media-new.php") {
3421 if(self::is_for_this_post_type('attachment') || self::is_for_this_post_type('media')) {
3422 wp_enqueue_style( 'folders-media', WCP_FOLDER_URL . 'assets/css/new-media.css' );
3423 $is_active = 1;
3424 $folders = -1;
3425
3426 $hasStars = self::check_for_setting("has_stars", "general");
3427 $hasChild = self::check_for_setting("has_child", "general");
3428 $hasChild = empty($hasChild)?0:1;
3429 $hasStars = empty($hasStars)?0:1;
3430
3431 wp_enqueue_script('wcp-folders-add-new-media', plugin_dir_url(dirname(__FILE__)) . 'assets/js/new-media.js', array('jquery'), WCP_FOLDER_VERSION);
3432 wp_localize_script( 'wcp-folders-add-new-media', 'folders_media_options', array(
3433 'terms' => self::get_terms_hierarchical('media_folder'),
3434 'taxonomy' => get_taxonomy('media_folder'),
3435 'ajax_url' => admin_url("admin-ajax.php"),
3436 'activate_url' => $this->getFoldersUpgradeURL(),
3437 'nonce' => wp_create_nonce('wcp_folder_nonce_attachment'),
3438 'is_key_active' => $is_active,
3439 'folders' => $folders,
3440 'hasStars' => $hasStars,
3441 'hasChildren' => $hasChild
3442 ));
3443 }
3444 }
3445 }
3446
3447 public function plugin_action_links($links)
3448 {
3449 array_unshift($links, '<a href="' . admin_url("admin.php?page=wcp_folders_settings") . '" >' . esc_html__('Settings', 'folders') . '</a>');
3450 $links['need_help'] = '<a target="_blank" href="https://premio.io/help/folders/?utm_source=pluginspage" >'.__( 'Need help?', 'folders').'</a>';
3451
3452 /* PRO link for only for FREE*/
3453 $links['pro'] = '<a class="wcp-folder-upgrade-button" href="'.$this->getFoldersUpgradeURL().'" >'.__( 'Upgrade', 'folders').'</a>';
3454 return $links;
3455 }
3456
3457 public static function get_instance()
3458 {
3459 if (empty(self::$instance)) {
3460 /* Do not change Class name here */
3461 self::$instance = new WCP_Folders();
3462 }
3463 return self::$instance;
3464 }
3465
3466 public function check_and_set_post_type() {
3467 $options = get_option('folders_settings');
3468 $old_plugin_status = 0;
3469 $post_array = array();
3470 if (!empty($options) && is_array($options)) {
3471 foreach ($options as $key=>$val) {
3472 if (!(strpos($key, 'folders4') === false) && $old_plugin_status == 0) {
3473 $old_plugin_status = 1;
3474 }
3475 if (in_array($key, array("folders4page", "folders4post", "folders4attachment"))) {
3476 $post_array[] = str_replace("folders4", "", $key);
3477 }
3478 }
3479 } else {
3480 $post_array = array("page", "post", "attachment");
3481 }
3482 if ($old_plugin_status == 1) {
3483 update_option("folders_show_in_menu", "on");
3484 $old_plugin_var = get_option("folder_old_plugin_status");
3485 if (empty($old_plugin_var) || $old_plugin_var == null) {
3486 update_option("folder_old_plugin_status", "1");
3487 }
3488 update_option('folders_settings', $post_array);
3489 self::set_default_values_if_not_exists();
3490 }
3491 if (!empty($post_array) && get_option('folders_settings') === false) {
3492 update_option('folders_settings', $post_array);
3493 update_option("folders_show_in_menu", "off");
3494 }
3495 }
3496
3497 public static function activate()
3498 {
3499 premio_folders_plugin_check_for_setting();
3500 $folder_setting = get_option("folders_settings");
3501 if($folder_setting === false) {
3502 add_option("wcp_folder_version_267", 1);
3503 }
3504 update_option("folders_show_in_menu", "off");
3505 $option = get_option("folder_redirect_status");
3506 if($option === false) {
3507 add_option("folder_intro_box", "show");
3508 }
3509 update_option("folder_redirect_status", 1);
3510 }
3511
3512 public static function deactivate() {
3513 $customize_folders = get_option('customize_folders');
3514 $DS = DIRECTORY_SEPARATOR;
3515 $dirName = ABSPATH . "wp-content{$DS}plugins{$DS}folders-pro{$DS}";
3516 $is_pro = get_option("folders_pro_is_in_process");
3517 if(!is_dir($dirName) && $is_pro === false && isset($customize_folders['remove_folders_when_removed']) && $customize_folders['remove_folders_when_removed'] == "on") {
3518 self::$folders = 0;
3519 self::remove_folder_by_taxonomy("media_folder");
3520 self::remove_folder_by_taxonomy("folder");
3521 self::remove_folder_by_taxonomy("post_folder");
3522 $post_types = get_post_types(array(), 'objects');
3523 $post_array = array("page", "post", "attachment");
3524 foreach ($post_types as $post_type) {
3525 if (!in_array($post_type->name, $post_array)) {
3526 self::remove_folder_by_taxonomy($post_type->name . '_folder');
3527 }
3528 }
3529 delete_option('customize_folders');
3530 delete_option('default_folders');
3531 delete_option('folders_show_in_menu');
3532 delete_option('folder_redirect_status');
3533 delete_option('folders_settings');
3534 delete_option('premio_folder_options');
3535 delete_option('folders_settings_updated');
3536 }
3537 }
3538
3539 function folders_register_settings()
3540 {
3541 register_setting('folders_settings', 'folders_settings1', 'folders_settings_validate');
3542 register_setting('default_folders', 'default_folders');
3543 register_setting('customize_folders', 'customize_folders');
3544
3545 self::check_and_set_post_type();
3546
3547 $option = get_option("folder_redirect_status");
3548 if ($option == 1) {
3549 update_option("folder_redirect_status", 2);
3550 wp_redirect(admin_url("admin.php?page=wcp_folders_settings"));
3551 exit;
3552 }
3553 }
3554
3555 function getFoldersUpgradeURL() {
3556 $customize_folders = get_option("customize_folders");
3557 if(isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") {
3558 return admin_url("options-general.php?page=wcp_folders_settings&setting_page=upgrade-to-pro");
3559 } else {
3560 return admin_url("admin.php?page=folders-upgrade-to-pro");
3561 }
3562 }
3563
3564 function getFolderSettingsURL() {
3565 $customize_folders = get_option("customize_folders");
3566 if(isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") {
3567 return admin_url("options-general.php?page=wcp_folders_settings");
3568 } else {
3569 return admin_url("admin.php?page=wcp_folders_settings");
3570 }
3571 }
3572
3573 function isFoldersInSettings() {
3574 $customize_folders = get_option("customize_folders");
3575 if (isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") {
3576 return true;
3577 }
3578 return false;
3579 }
3580
3581 function wcp_manage_columns_head($defaults, $d = "")
3582 {
3583 global $typenow;
3584 $type = $typenow;
3585 if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'inline-save') {
3586 $type = self::sanitize_options($_REQUEST['post_type']);
3587 }
3588
3589 $options = get_option("folders_settings");
3590 if (is_array($options) && in_array($type, $options)) {
3591 $columns = array(
3592 '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>',
3593 ) + $defaults;
3594 return $columns;
3595 }
3596 return $defaults;
3597 }
3598
3599 function wcp_manage_columns_content($column_name, $post_ID)
3600 {
3601 $postIDs = self::$postIds;
3602 if(!is_array($postIDs)) {
3603 $postIDs = array();
3604 }
3605 if(!in_array($post_ID, $postIDs)) {
3606 $postIDs[] = $post_ID;
3607 self::$postIds = $postIDs;
3608 global $typenow;
3609 $type = $typenow;
3610 if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'inline-save') {
3611 $type = self::sanitize_options($_REQUEST['post_type']);
3612 }
3613
3614 $options = get_option("folders_settings");
3615 if (is_array($options) && in_array($type, $options)) {
3616 if ($column_name == 'wcp_move') {
3617 $title = get_the_title();
3618 if (strlen($title) > 20) {
3619 $title = substr($title, 0, 20) . "...";
3620 }
3621 echo "<div class='wcp-move-file' data-id='{$post_ID}'><span class='wcp-move dashicons dashicons-move' data-id='{$post_ID}'></span><span class='wcp-item' data-object-id='{$post_ID}'>" . $title . "</span></div>";
3622 }
3623 }
3624 }
3625 }
3626
3627 function taxonomy_archive_exclude_children($query)
3628 {
3629 $options = get_option("folders_settings");
3630 if (!empty($options)) {
3631 $taxonomy_slugs = array();
3632 foreach ($options as $option) {
3633 $taxonomy_slugs[] = self::get_custom_post_type($option);
3634 }
3635 if (!empty($taxonomy_slugs)) {
3636 $i = 0;
3637 foreach ($query->tax_query->queries as $tax_query_item) {
3638 if (empty($taxonomy_slugs) || (isset($tax_query_item['taxonomy']) && in_array($tax_query_item['taxonomy'], $taxonomy_slugs))) {
3639 $query->tax_query->queries[$i]['include_children'] = 0;
3640 }
3641 }
3642 }
3643 }
3644 }
3645
3646 public function admin_menu() {
3647 $customize_folders = get_option("customize_folders");
3648 if (isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") {
3649 add_options_page(
3650 esc_html__('Folders Settings', 'folders'),
3651 esc_html__('Folders Settings', 'folders'),
3652 'manage_options',
3653 'wcp_folders_settings',
3654 array($this, 'wcp_folders_settings')
3655 );
3656 } else {
3657 $menu_slug = 'wcp_folders_settings';
3658
3659 // Add menu item for settings page
3660 $page_title = esc_html__('Folders', 'folders');
3661 $menu_title = esc_html__('Folders Settings', 'folders');
3662 $capability = 'manage_options';
3663 $callback = array($this, "wcp_folders_settings");
3664 $icon_url = 'dashicons-category';
3665 $position = 99;
3666 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $callback, $icon_url, $position);
3667
3668 $getData = filter_input_array(INPUT_GET);
3669 if(isset($getData['hide_folder_recommended_plugin']) && isset($getData['nonce'])) {
3670 if(current_user_can('manage_options')) {
3671 $nonce = $getData['nonce'];
3672 if(wp_verify_nonce($nonce, "folder_recommended_plugin")) {
3673 update_option('hide_folder_recommended_plugin',"1");
3674 }
3675 }
3676 }
3677
3678 $recommended_plugin = get_option("hide_folder_recommended_plugin");
3679 if($recommended_plugin === false) {
3680 add_submenu_page(
3681 $menu_slug,
3682 esc_html__('Recommended Plugins', 'folders'),
3683 esc_html__('Recommended Plugins', 'folders'),
3684 'manage_options',
3685 'recommended-folder-plugins',
3686 array($this, 'recommended_plugins')
3687 );
3688 }
3689
3690 /* Do not Change Free/Pro Change for menu */
3691 add_submenu_page(
3692 $menu_slug,
3693 esc_html__('Upgrade to Pro', 'folders'),
3694 esc_html__('Upgrade to Pro', 'folders'),
3695 'manage_options',
3696 'folders-upgrade-to-pro',
3697 array($this, 'wcp_folders_upgrade_or_register')
3698 );
3699 }
3700
3701 self::check_and_set_post_type();
3702
3703 $show_menu = get_option("folders_show_in_menu", true);
3704 if ($show_menu == "on") {
3705 self::create_menu_for_folders();
3706 }
3707 }
3708
3709 public function recommended_plugins() {
3710 include_once dirname(dirname(__FILE__)) . "/templates/admin/recommended-plugins.php";
3711 }
3712
3713 public function wcp_folders_upgrade_or_register()
3714 {
3715 self::set_default_values_if_not_exists();
3716 include_once dirname(dirname(__FILE__)) . "/templates/admin/upgrade-to-pro.php";
3717 }
3718
3719 public function wcp_folders_settings()
3720 {
3721 self::set_default_values_if_not_exists();
3722 /* Only in Free, Get Folders update confirmation popup */
3723 $is_shown = get_option("folder_update_message");
3724 if($is_shown === false) {
3725 include_once dirname(dirname(__FILE__)) . "/templates/admin/update.php";
3726 } else {
3727 $options = get_option('folders_settings');
3728 $options = (empty($options) || !is_array($options)) ? array() : $options;
3729 $post_types = get_post_types(array('public' => true), 'objects');
3730 $terms_data = array();
3731 foreach ($post_types as $post_type) {
3732 if (in_array($post_type->name, $options)) {
3733 $term = $post_type->name;
3734 $term = self::get_custom_post_type($term);
3735 $categories = self::get_terms_hierarchical($term);
3736 $terms_data[$post_type->name] = $categories;
3737 } else {
3738 $terms_data[$post_type->name] = array();
3739 }
3740 }
3741 $fonts = self::get_font_list();
3742
3743 $plugins = new WCP_Folder_Plugins();
3744 $plugin_info = $plugins->get_plugin_information();
3745 $is_plugin_exists = $plugins->is_exists;
3746 $settingURL = $this->getFolderSettingsURL();
3747 $setting_page = isset($_GET['setting_page'])?$_GET['setting_page']:"folder-settings";
3748 $setting_page = in_array($setting_page, array("folder-settings", "customize-folders", "folders-import", "upgrade-to-pro", "folders-by-user"))?$setting_page:"folder-settings";
3749 $isInSettings = $this->isFoldersInSettings();
3750
3751 include_once dirname(dirname(__FILE__)) . "/templates/admin/general-settings.php";
3752
3753 $option = get_option("folder_intro_box");
3754 if($option == "show") {
3755 include_once dirname(dirname(__FILE__)) . "/templates/admin/folder-popup.php";
3756 }
3757 }
3758 }
3759
3760 public static function get_font_list(){
3761 return array(
3762 // System fonts.
3763 'Default' => 'Default',
3764 "System Stack" => 'Default',
3765 'Arial' => 'Default',
3766 'Tahoma' => 'Default',
3767 'Verdana' => 'Default',
3768 'Helvetica' => 'Default',
3769 'Times New Roman' => 'Default',
3770 'Trebuchet MS' => 'Default',
3771 'Georgia' => 'Default',
3772
3773 // Google Fonts (last update: 23/10/2018).
3774 'ABeeZee' => 'Google Fonts',
3775 'Abel' => 'Google Fonts',
3776 'Abhaya Libre' => 'Google Fonts',
3777 'Abril Fatface' => 'Google Fonts',
3778 'Aclonica' => 'Google Fonts',
3779 'Acme' => 'Google Fonts',
3780 'Actor' => 'Google Fonts',
3781 'Adamina' => 'Google Fonts',
3782 'Advent Pro' => 'Google Fonts',
3783 'Aguafina Script' => 'Google Fonts',
3784 'Akronim' => 'Google Fonts',
3785 'Aladin' => 'Google Fonts',
3786 'Aldrich' => 'Google Fonts',
3787 'Alef' => 'Google Fonts',
3788 'Alef Hebrew' => 'Google Fonts', // Hack for Google Early Access.
3789 'Alegreya' => 'Google Fonts',
3790 'Alegreya SC' => 'Google Fonts',
3791 'Alegreya Sans' => 'Google Fonts',
3792 'Alegreya Sans SC' => 'Google Fonts',
3793 'Alex Brush' => 'Google Fonts',
3794 'Alfa Slab One' => 'Google Fonts',
3795 'Alice' => 'Google Fonts',
3796 'Alike' => 'Google Fonts',
3797 'Alike Angular' => 'Google Fonts',
3798 'Allan' => 'Google Fonts',
3799 'Allerta' => 'Google Fonts',
3800 'Allerta Stencil' => 'Google Fonts',
3801 'Allura' => 'Google Fonts',
3802 'Almendra' => 'Google Fonts',
3803 'Almendra Display' => 'Google Fonts',
3804 'Almendra SC' => 'Google Fonts',
3805 'Amarante' => 'Google Fonts',
3806 'Amaranth' => 'Google Fonts',
3807 'Amatic SC' => 'Google Fonts',
3808 'Amethysta' => 'Google Fonts',
3809 'Amiko' => 'Google Fonts',
3810 'Amiri' => 'Google Fonts',
3811 'Amita' => 'Google Fonts',
3812 'Anaheim' => 'Google Fonts',
3813 'Andada' => 'Google Fonts',
3814 'Andika' => 'Google Fonts',
3815 'Angkor' => 'Google Fonts',
3816 'Annie Use Your Telescope' => 'Google Fonts',
3817 'Anonymous Pro' => 'Google Fonts',
3818 'Antic' => 'Google Fonts',
3819 'Antic Didone' => 'Google Fonts',
3820 'Antic Slab' => 'Google Fonts',
3821 'Anton' => 'Google Fonts',
3822 'Arapey' => 'Google Fonts',
3823 'Arbutus' => 'Google Fonts',
3824 'Arbutus Slab' => 'Google Fonts',
3825 'Architects Daughter' => 'Google Fonts',
3826 'Archivo' => 'Google Fonts',
3827 'Archivo Black' => 'Google Fonts',
3828 'Archivo Narrow' => 'Google Fonts',
3829 'Aref Ruqaa' => 'Google Fonts',
3830 'Arima Madurai' => 'Google Fonts',
3831 'Arimo' => 'Google Fonts',
3832 'Arizonia' => 'Google Fonts',
3833 'Armata' => 'Google Fonts',
3834 'Arsenal' => 'Google Fonts',
3835 'Artifika' => 'Google Fonts',
3836 'Arvo' => 'Google Fonts',
3837 'Arya' => 'Google Fonts',
3838 'Asap' => 'Google Fonts',
3839 'Asap Condensed' => 'Google Fonts',
3840 'Asar' => 'Google Fonts',
3841 'Asset' => 'Google Fonts',
3842 'Assistant' => 'Google Fonts',
3843 'Astloch' => 'Google Fonts',
3844 'Asul' => 'Google Fonts',
3845 'Athiti' => 'Google Fonts',
3846 'Atma' => 'Google Fonts',
3847 'Atomic Age' => 'Google Fonts',
3848 'Aubrey' => 'Google Fonts',
3849 'Audiowide' => 'Google Fonts',
3850 'Autour One' => 'Google Fonts',
3851 'Average' => 'Google Fonts',
3852 'Average Sans' => 'Google Fonts',
3853 'Averia Gruesa Libre' => 'Google Fonts',
3854 'Averia Libre' => 'Google Fonts',
3855 'Averia Sans Libre' => 'Google Fonts',
3856 'Averia Serif Libre' => 'Google Fonts',
3857 'Bad Script' => 'Google Fonts',
3858 'Bahiana' => 'Google Fonts',
3859 'Bai Jamjuree' => 'Google Fonts',
3860 'Baloo' => 'Google Fonts',
3861 'Baloo Bhai' => 'Google Fonts',
3862 'Baloo Bhaijaan' => 'Google Fonts',
3863 'Baloo Bhaina' => 'Google Fonts',
3864 'Baloo Chettan' => 'Google Fonts',
3865 'Baloo Da' => 'Google Fonts',
3866 'Baloo Paaji' => 'Google Fonts',
3867 'Baloo Tamma' => 'Google Fonts',
3868 'Baloo Tammudu' => 'Google Fonts',
3869 'Baloo Thambi' => 'Google Fonts',
3870 'Balthazar' => 'Google Fonts',
3871 'Bangers' => 'Google Fonts',
3872 'Barlow' => 'Google Fonts',
3873 'Barlow Condensed' => 'Google Fonts',
3874 'Barlow Semi Condensed' => 'Google Fonts',
3875 'Barrio' => 'Google Fonts',
3876 'Basic' => 'Google Fonts',
3877 'Battambang' => 'Google Fonts',
3878 'Baumans' => 'Google Fonts',
3879 'Bayon' => 'Google Fonts',
3880 'Belgrano' => 'Google Fonts',
3881 'Bellefair' => 'Google Fonts',
3882 'Belleza' => 'Google Fonts',
3883 'BenchNine' => 'Google Fonts',
3884 'Bentham' => 'Google Fonts',
3885 'Berkshire Swash' => 'Google Fonts',
3886 'Bevan' => 'Google Fonts',
3887 'Bigelow Rules' => 'Google Fonts',
3888 'Bigshot One' => 'Google Fonts',
3889 'Bilbo' => 'Google Fonts',
3890 'Bilbo Swash Caps' => 'Google Fonts',
3891 'BioRhyme' => 'Google Fonts',
3892 'BioRhyme Expanded' => 'Google Fonts',
3893 'Biryani' => 'Google Fonts',
3894 'Bitter' => 'Google Fonts',
3895 'Black And White Picture' => 'Google Fonts',
3896 'Black Han Sans' => 'Google Fonts',
3897 'Black Ops One' => 'Google Fonts',
3898 'Bokor' => 'Google Fonts',
3899 'Bonbon' => 'Google Fonts',
3900 'Boogaloo' => 'Google Fonts',
3901 'Bowlby One' => 'Google Fonts',
3902 'Bowlby One SC' => 'Google Fonts',
3903 'Brawler' => 'Google Fonts',
3904 'Bree Serif' => 'Google Fonts',
3905 'Bubblegum Sans' => 'Google Fonts',
3906 'Bubbler One' => 'Google Fonts',
3907 'Buda' => 'Google Fonts',
3908 'Buenard' => 'Google Fonts',
3909 'Bungee' => 'Google Fonts',
3910 'Bungee Hairline' => 'Google Fonts',
3911 'Bungee Inline' => 'Google Fonts',
3912 'Bungee Outline' => 'Google Fonts',
3913 'Bungee Shade' => 'Google Fonts',
3914 'Butcherman' => 'Google Fonts',
3915 'Butterfly Kids' => 'Google Fonts',
3916 'Cabin' => 'Google Fonts',
3917 'Cabin Condensed' => 'Google Fonts',
3918 'Cabin Sketch' => 'Google Fonts',
3919 'Caesar Dressing' => 'Google Fonts',
3920 'Cagliostro' => 'Google Fonts',
3921 'Cairo' => 'Google Fonts',
3922 'Calligraffitti' => 'Google Fonts',
3923 'Cambay' => 'Google Fonts',
3924 'Cambo' => 'Google Fonts',
3925 'Candal' => 'Google Fonts',
3926 'Cantarell' => 'Google Fonts',
3927 'Cantata One' => 'Google Fonts',
3928 'Cantora One' => 'Google Fonts',
3929 'Capriola' => 'Google Fonts',
3930 'Cardo' => 'Google Fonts',
3931 'Carme' => 'Google Fonts',
3932 'Carrois Gothic' => 'Google Fonts',
3933 'Carrois Gothic SC' => 'Google Fonts',
3934 'Carter One' => 'Google Fonts',
3935 'Catamaran' => 'Google Fonts',
3936 'Caudex' => 'Google Fonts',
3937 'Caveat' => 'Google Fonts',
3938 'Caveat Brush' => 'Google Fonts',
3939 'Cedarville Cursive' => 'Google Fonts',
3940 'Ceviche One' => 'Google Fonts',
3941 'Chakra Petch' => 'Google Fonts',
3942 'Changa' => 'Google Fonts',
3943 'Changa One' => 'Google Fonts',
3944 'Chango' => 'Google Fonts',
3945 'Charmonman' => 'Google Fonts',
3946 'Chathura' => 'Google Fonts',
3947 'Chau Philomene One' => 'Google Fonts',
3948 'Chela One' => 'Google Fonts',
3949 'Chelsea Market' => 'Google Fonts',
3950 'Chenla' => 'Google Fonts',
3951 'Cherry Cream Soda' => 'Google Fonts',
3952 'Cherry Swash' => 'Google Fonts',
3953 'Chewy' => 'Google Fonts',
3954 'Chicle' => 'Google Fonts',
3955 'Chivo' => 'Google Fonts',
3956 'Chonburi' => 'Google Fonts',
3957 'Cinzel' => 'Google Fonts',
3958 'Cinzel Decorative' => 'Google Fonts',
3959 'Clicker Script' => 'Google Fonts',
3960 'Coda' => 'Google Fonts',
3961 'Coda Caption' => 'Google Fonts',
3962 'Codystar' => 'Google Fonts',
3963 'Coiny' => 'Google Fonts',
3964 'Combo' => 'Google Fonts',
3965 'Comfortaa' => 'Google Fonts',
3966 'Coming Soon' => 'Google Fonts',
3967 'Concert One' => 'Google Fonts',
3968 'Condiment' => 'Google Fonts',
3969 'Content' => 'Google Fonts',
3970 'Contrail One' => 'Google Fonts',
3971 'Convergence' => 'Google Fonts',
3972 'Cookie' => 'Google Fonts',
3973 'Copse' => 'Google Fonts',
3974 'Corben' => 'Google Fonts',
3975 'Cormorant' => 'Google Fonts',
3976 'Cormorant Garamond' => 'Google Fonts',
3977 'Cormorant Infant' => 'Google Fonts',
3978 'Cormorant SC' => 'Google Fonts',
3979 'Cormorant Unicase' => 'Google Fonts',
3980 'Cormorant Upright' => 'Google Fonts',
3981 'Courgette' => 'Google Fonts',
3982 'Cousine' => 'Google Fonts',
3983 'Coustard' => 'Google Fonts',
3984 'Covered By Your Grace' => 'Google Fonts',
3985 'Crafty Girls' => 'Google Fonts',
3986 'Creepster' => 'Google Fonts',
3987 'Crete Round' => 'Google Fonts',
3988 'Crimson Text' => 'Google Fonts',
3989 'Croissant One' => 'Google Fonts',
3990 'Crushed' => 'Google Fonts',
3991 'Cuprum' => 'Google Fonts',
3992 'Cute Font' => 'Google Fonts',
3993 'Cutive' => 'Google Fonts',
3994 'Cutive Mono' => 'Google Fonts',
3995 'Damion' => 'Google Fonts',
3996 'Dancing Script' => 'Google Fonts',
3997 'Dangrek' => 'Google Fonts',
3998 'David Libre' => 'Google Fonts',
3999 'Dawning of a New Day' => 'Google Fonts',
4000 'Days One' => 'Google Fonts',
4001 'Dekko' => 'Google Fonts',
4002 'Delius' => 'Google Fonts',
4003 'Delius Swash Caps' => 'Google Fonts',
4004 'Delius Unicase' => 'Google Fonts',
4005 'Della Respira' => 'Google Fonts',
4006 'Denk One' => 'Google Fonts',
4007 'Devonshire' => 'Google Fonts',
4008 'Dhurjati' => 'Google Fonts',
4009 'Didact Gothic' => 'Google Fonts',
4010 'Diplomata' => 'Google Fonts',
4011 'Diplomata SC' => 'Google Fonts',
4012 'Do Hyeon' => 'Google Fonts',
4013 'Dokdo' => 'Google Fonts',
4014 'Domine' => 'Google Fonts',
4015 'Donegal One' => 'Google Fonts',
4016 'Doppio One' => 'Google Fonts',
4017 'Dorsa' => 'Google Fonts',
4018 'Dosis' => 'Google Fonts',
4019 'Dr Sugiyama' => 'Google Fonts',
4020 'Droid Arabic Kufi' => 'Google Fonts', // Hack for Google Early Access.
4021 'Droid Arabic Naskh' => 'Google Fonts', // Hack for Google Early Access.
4022 'Duru Sans' => 'Google Fonts',
4023 'Dynalight' => 'Google Fonts',
4024 'EB Garamond' => 'Google Fonts',
4025 'Eagle Lake' => 'Google Fonts',
4026 'East Sea Dokdo' => 'Google Fonts',
4027 'Eater' => 'Google Fonts',
4028 'Economica' => 'Google Fonts',
4029 'Eczar' => 'Google Fonts',
4030 'El Messiri' => 'Google Fonts',
4031 'Electrolize' => 'Google Fonts',
4032 'Elsie' => 'Google Fonts',
4033 'Elsie Swash Caps' => 'Google Fonts',
4034 'Emblema One' => 'Google Fonts',
4035 'Emilys Candy' => 'Google Fonts',
4036 'Encode Sans' => 'Google Fonts',
4037 'Encode Sans Condensed' => 'Google Fonts',
4038 'Encode Sans Expanded' => 'Google Fonts',
4039 'Encode Sans Semi Condensed' => 'Google Fonts',
4040 'Encode Sans Semi Expanded' => 'Google Fonts',
4041 'Engagement' => 'Google Fonts',
4042 'Englebert' => 'Google Fonts',
4043 'Enriqueta' => 'Google Fonts',
4044 'Erica One' => 'Google Fonts',
4045 'Esteban' => 'Google Fonts',
4046 'Euphoria Script' => 'Google Fonts',
4047 'Ewert' => 'Google Fonts',
4048 'Exo' => 'Google Fonts',
4049 'Exo 2' => 'Google Fonts',
4050 'Expletus Sans' => 'Google Fonts',
4051 'Fahkwang' => 'Google Fonts',
4052 'Fanwood Text' => 'Google Fonts',
4053 'Farsan' => 'Google Fonts',
4054 'Fascinate' => 'Google Fonts',
4055 'Fascinate Inline' => 'Google Fonts',
4056 'Faster One' => 'Google Fonts',
4057 'Fasthand' => 'Google Fonts',
4058 'Fauna One' => 'Google Fonts',
4059 'Faustina' => 'Google Fonts',
4060 'Federant' => 'Google Fonts',
4061 'Federo' => 'Google Fonts',
4062 'Felipa' => 'Google Fonts',
4063 'Fenix' => 'Google Fonts',
4064 'Finger Paint' => 'Google Fonts',
4065 'Fira Mono' => 'Google Fonts',
4066 'Fira Sans' => 'Google Fonts',
4067 'Fira Sans Condensed' => 'Google Fonts',
4068 'Fira Sans Extra Condensed' => 'Google Fonts',
4069 'Fjalla One' => 'Google Fonts',
4070 'Fjord One' => 'Google Fonts',
4071 'Flamenco' => 'Google Fonts',
4072 'Flavors' => 'Google Fonts',
4073 'Fondamento' => 'Google Fonts',
4074 'Fontdiner Swanky' => 'Google Fonts',
4075 'Forum' => 'Google Fonts',
4076 'Francois One' => 'Google Fonts',
4077 'Frank Ruhl Libre' => 'Google Fonts',
4078 'Freckle Face' => 'Google Fonts',
4079 'Fredericka the Great' => 'Google Fonts',
4080 'Fredoka One' => 'Google Fonts',
4081 'Freehand' => 'Google Fonts',
4082 'Fresca' => 'Google Fonts',
4083 'Frijole' => 'Google Fonts',
4084 'Fruktur' => 'Google Fonts',
4085 'Fugaz One' => 'Google Fonts',
4086 'GFS Didot' => 'Google Fonts',
4087 'GFS Neohellenic' => 'Google Fonts',
4088 'Gabriela' => 'Google Fonts',
4089 'Gaegu' => 'Google Fonts',
4090 'Gafata' => 'Google Fonts',
4091 'Galada' => 'Google Fonts',
4092 'Galdeano' => 'Google Fonts',
4093 'Galindo' => 'Google Fonts',
4094 'Gamja Flower' => 'Google Fonts',
4095 'Gentium Basic' => 'Google Fonts',
4096 'Gentium Book Basic' => 'Google Fonts',
4097 'Geo' => 'Google Fonts',
4098 'Geostar' => 'Google Fonts',
4099 'Geostar Fill' => 'Google Fonts',
4100 'Germania One' => 'Google Fonts',
4101 'Gidugu' => 'Google Fonts',
4102 'Gilda Display' => 'Google Fonts',
4103 'Give You Glory' => 'Google Fonts',
4104 'Glass Antiqua' => 'Google Fonts',
4105 'Glegoo' => 'Google Fonts',
4106 'Gloria Hallelujah' => 'Google Fonts',
4107 'Goblin One' => 'Google Fonts',
4108 'Gochi Hand' => 'Google Fonts',
4109 'Gorditas' => 'Google Fonts',
4110 'Gothic A1' => 'Google Fonts',
4111 'Goudy Bookletter 1911' => 'Google Fonts',
4112 'Graduate' => 'Google Fonts',
4113 'Grand Hotel' => 'Google Fonts',
4114 'Gravitas One' => 'Google Fonts',
4115 'Great Vibes' => 'Google Fonts',
4116 'Griffy' => 'Google Fonts',
4117 'Gruppo' => 'Google Fonts',
4118 'Gudea' => 'Google Fonts',
4119 'Gugi' => 'Google Fonts',
4120 'Gurajada' => 'Google Fonts',
4121 'Habibi' => 'Google Fonts',
4122 'Halant' => 'Google Fonts',
4123 'Hammersmith One' => 'Google Fonts',
4124 'Hanalei' => 'Google Fonts',
4125 'Hanalei Fill' => 'Google Fonts',
4126 'Handlee' => 'Google Fonts',
4127 'Hanuman' => 'Google Fonts',
4128 'Happy Monkey' => 'Google Fonts',
4129 'Harmattan' => 'Google Fonts',
4130 'Headland One' => 'Google Fonts',
4131 'Heebo' => 'Google Fonts',
4132 'Henny Penny' => 'Google Fonts',
4133 'Herr Von Muellerhoff' => 'Google Fonts',
4134 'Hi Melody' => 'Google Fonts',
4135 'Hind' => 'Google Fonts',
4136 'Hind Guntur' => 'Google Fonts',
4137 'Hind Madurai' => 'Google Fonts',
4138 'Hind Siliguri' => 'Google Fonts',
4139 'Hind Vadodara' => 'Google Fonts',
4140 'Holtwood One SC' => 'Google Fonts',
4141 'Homemade Apple' => 'Google Fonts',
4142 'Homenaje' => 'Google Fonts',
4143 'IBM Plex Mono' => 'Google Fonts',
4144 'IBM Plex Sans' => 'Google Fonts',
4145 'IBM Plex Sans Condensed' => 'Google Fonts',
4146 'IBM Plex Serif' => 'Google Fonts',
4147 'IM Fell DW Pica' => 'Google Fonts',
4148 'IM Fell DW Pica SC' => 'Google Fonts',
4149 'IM Fell Double Pica' => 'Google Fonts',
4150 'IM Fell Double Pica SC' => 'Google Fonts',
4151 'IM Fell English' => 'Google Fonts',
4152 'IM Fell English SC' => 'Google Fonts',
4153 'IM Fell French Canon' => 'Google Fonts',
4154 'IM Fell French Canon SC' => 'Google Fonts',
4155 'IM Fell Great Primer' => 'Google Fonts',
4156 'IM Fell Great Primer SC' => 'Google Fonts',
4157 'Iceberg' => 'Google Fonts',
4158 'Iceland' => 'Google Fonts',
4159 'Imprima' => 'Google Fonts',
4160 'Inconsolata' => 'Google Fonts',
4161 'Inder' => 'Google Fonts',
4162 'Indie Flower' => 'Google Fonts',
4163 'Inika' => 'Google Fonts',
4164 'Inknut Antiqua' => 'Google Fonts',
4165 'Irish Grover' => 'Google Fonts',
4166 'Istok Web' => 'Google Fonts',
4167 'Italiana' => 'Google Fonts',
4168 'Italianno' => 'Google Fonts',
4169 'Itim' => 'Google Fonts',
4170 'Jacques Francois' => 'Google Fonts',
4171 'Jacques Francois Shadow' => 'Google Fonts',
4172 'Jaldi' => 'Google Fonts',
4173 'Jim Nightshade' => 'Google Fonts',
4174 'Jockey One' => 'Google Fonts',
4175 'Jolly Lodger' => 'Google Fonts',
4176 'Jomhuria' => 'Google Fonts',
4177 'Josefin Sans' => 'Google Fonts',
4178 'Josefin Slab' => 'Google Fonts',
4179 'Joti One' => 'Google Fonts',
4180 'Jua' => 'Google Fonts',
4181 'Judson' => 'Google Fonts',
4182 'Julee' => 'Google Fonts',
4183 'Julius Sans One' => 'Google Fonts',
4184 'Junge' => 'Google Fonts',
4185 'Jura' => 'Google Fonts',
4186 'Just Another Hand' => 'Google Fonts',
4187 'Just Me Again Down Here' => 'Google Fonts',
4188 'K2D' => 'Google Fonts',
4189 'Kadwa' => 'Google Fonts',
4190 'Kalam' => 'Google Fonts',
4191 'Kameron' => 'Google Fonts',
4192 'Kanit' => 'Google Fonts',
4193 'Kantumruy' => 'Google Fonts',
4194 'Karla' => 'Google Fonts',
4195 'Karma' => 'Google Fonts',
4196 'Katibeh' => 'Google Fonts',
4197 'Kaushan Script' => 'Google Fonts',
4198 'Kavivanar' => 'Google Fonts',
4199 'Kavoon' => 'Google Fonts',
4200 'Kdam Thmor' => 'Google Fonts',
4201 'Keania One' => 'Google Fonts',
4202 'Kelly Slab' => 'Google Fonts',
4203 'Kenia' => 'Google Fonts',
4204 'Khand' => 'Google Fonts',
4205 'Khmer' => 'Google Fonts',
4206 'Khula' => 'Google Fonts',
4207 'Kirang Haerang' => 'Google Fonts',
4208 'Kite One' => 'Google Fonts',
4209 'Knewave' => 'Google Fonts',
4210 'KoHo' => 'Google Fonts',
4211 'Kodchasan' => 'Google Fonts',
4212 'Kosugi' => 'Google Fonts',
4213 'Kosugi Maru' => 'Google Fonts',
4214 'Kotta One' => 'Google Fonts',
4215 'Koulen' => 'Google Fonts',
4216 'Kranky' => 'Google Fonts',
4217 'Kreon' => 'Google Fonts',
4218 'Kristi' => 'Google Fonts',
4219 'Krona One' => 'Google Fonts',
4220 'Krub' => 'Google Fonts',
4221 'Kumar One' => 'Google Fonts',
4222 'Kumar One Outline' => 'Google Fonts',
4223 'Kurale' => 'Google Fonts',
4224 'La Belle Aurore' => 'Google Fonts',
4225 'Laila' => 'Google Fonts',
4226 'Lakki Reddy' => 'Google Fonts',
4227 'Lalezar' => 'Google Fonts',
4228 'Lancelot' => 'Google Fonts',
4229 'Lateef' => 'Google Fonts',
4230 'Lato' => 'Google Fonts',
4231 'League Script' => 'Google Fonts',
4232 'Leckerli One' => 'Google Fonts',
4233 'Ledger' => 'Google Fonts',
4234 'Lekton' => 'Google Fonts',
4235 'Lemon' => 'Google Fonts',
4236 'Lemonada' => 'Google Fonts',
4237 'Libre Barcode 128' => 'Google Fonts',
4238 'Libre Barcode 128 Text' => 'Google Fonts',
4239 'Libre Barcode 39' => 'Google Fonts',
4240 'Libre Barcode 39 Extended' => 'Google Fonts',
4241 'Libre Barcode 39 Extended Text' => 'Google Fonts',
4242 'Libre Barcode 39 Text' => 'Google Fonts',
4243 'Libre Baskerville' => 'Google Fonts',
4244 'Libre Franklin' => 'Google Fonts',
4245 'Life Savers' => 'Google Fonts',
4246 'Lilita One' => 'Google Fonts',
4247 'Lily Script One' => 'Google Fonts',
4248 'Limelight' => 'Google Fonts',
4249 'Linden Hill' => 'Google Fonts',
4250 'Lobster' => 'Google Fonts',
4251 'Lobster Two' => 'Google Fonts',
4252 'Londrina Outline' => 'Google Fonts',
4253 'Londrina Shadow' => 'Google Fonts',
4254 'Londrina Sketch' => 'Google Fonts',
4255 'Londrina Solid' => 'Google Fonts',
4256 'Lora' => 'Google Fonts',
4257 'Love Ya Like A Sister' => 'Google Fonts',
4258 'Loved by the King' => 'Google Fonts',
4259 'Lovers Quarrel' => 'Google Fonts',
4260 'Luckiest Guy' => 'Google Fonts',
4261 'Lusitana' => 'Google Fonts',
4262 'Lustria' => 'Google Fonts',
4263 'M PLUS 1p' => 'Google Fonts',
4264 'M PLUS Rounded 1c' => 'Google Fonts',
4265 'Macondo' => 'Google Fonts',
4266 'Macondo Swash Caps' => 'Google Fonts',
4267 'Mada' => 'Google Fonts',
4268 'Magra' => 'Google Fonts',
4269 'Maiden Orange' => 'Google Fonts',
4270 'Maitree' => 'Google Fonts',
4271 'Mako' => 'Google Fonts',
4272 'Mali' => 'Google Fonts',
4273 'Mallanna' => 'Google Fonts',
4274 'Mandali' => 'Google Fonts',
4275 'Manuale' => 'Google Fonts',
4276 'Marcellus' => 'Google Fonts',
4277 'Marcellus SC' => 'Google Fonts',
4278 'Marck Script' => 'Google Fonts',
4279 'Margarine' => 'Google Fonts',
4280 'Markazi Text' => 'Google Fonts',
4281 'Marko One' => 'Google Fonts',
4282 'Marmelad' => 'Google Fonts',
4283 'Martel' => 'Google Fonts',
4284 'Martel Sans' => 'Google Fonts',
4285 'Marvel' => 'Google Fonts',
4286 'Mate' => 'Google Fonts',
4287 'Mate SC' => 'Google Fonts',
4288 'Maven Pro' => 'Google Fonts',
4289 'McLaren' => 'Google Fonts',
4290 'Meddon' => 'Google Fonts',
4291 'MedievalSharp' => 'Google Fonts',
4292 'Medula One' => 'Google Fonts',
4293 'Meera Inimai' => 'Google Fonts',
4294 'Megrim' => 'Google Fonts',
4295 'Meie Script' => 'Google Fonts',
4296 'Merienda' => 'Google Fonts',
4297 'Merienda One' => 'Google Fonts',
4298 'Merriweather' => 'Google Fonts',
4299 'Merriweather Sans' => 'Google Fonts',
4300 'Metal' => 'Google Fonts',
4301 'Metal Mania' => 'Google Fonts',
4302 'Metamorphous' => 'Google Fonts',
4303 'Metrophobic' => 'Google Fonts',
4304 'Michroma' => 'Google Fonts',
4305 'Milonga' => 'Google Fonts',
4306 'Miltonian' => 'Google Fonts',
4307 'Miltonian Tattoo' => 'Google Fonts',
4308 'Mina' => 'Google Fonts',
4309 'Miniver' => 'Google Fonts',
4310 'Miriam Libre' => 'Google Fonts',
4311 'Mirza' => 'Google Fonts',
4312 'Miss Fajardose' => 'Google Fonts',
4313 'Mitr' => 'Google Fonts',
4314 'Modak' => 'Google Fonts',
4315 'Modern Antiqua' => 'Google Fonts',
4316 'Mogra' => 'Google Fonts',
4317 'Molengo' => 'Google Fonts',
4318 'Molle' => 'Google Fonts',
4319 'Monda' => 'Google Fonts',
4320 'Monofett' => 'Google Fonts',
4321 'Monoton' => 'Google Fonts',
4322 'Monsieur La Doulaise' => 'Google Fonts',
4323 'Montaga' => 'Google Fonts',
4324 'Montez' => 'Google Fonts',
4325 'Montserrat' => 'Google Fonts',
4326 'Montserrat Alternates' => 'Google Fonts',
4327 'Montserrat Subrayada' => 'Google Fonts',
4328 'Moul' => 'Google Fonts',
4329 'Moulpali' => 'Google Fonts',
4330 'Mountains of Christmas' => 'Google Fonts',
4331 'Mouse Memoirs' => 'Google Fonts',
4332 'Mr Bedfort' => 'Google Fonts',
4333 'Mr Dafoe' => 'Google Fonts',
4334 'Mr De Haviland' => 'Google Fonts',
4335 'Mrs Saint Delafield' => 'Google Fonts',
4336 'Mrs Sheppards' => 'Google Fonts',
4337 'Mukta' => 'Google Fonts',
4338 'Mukta Mahee' => 'Google Fonts',
4339 'Mukta Malar' => 'Google Fonts',
4340 'Mukta Vaani' => 'Google Fonts',
4341 'Muli' => 'Google Fonts',
4342 'Mystery Quest' => 'Google Fonts',
4343 'NTR' => 'Google Fonts',
4344 'Nanum Brush Script' => 'Google Fonts',
4345 'Nanum Gothic' => 'Google Fonts',
4346 'Nanum Gothic Coding' => 'Google Fonts',
4347 'Nanum Myeongjo' => 'Google Fonts',
4348 'Nanum Pen Script' => 'Google Fonts',
4349 'Neucha' => 'Google Fonts',
4350 'Neuton' => 'Google Fonts',
4351 'New Rocker' => 'Google Fonts',
4352 'News Cycle' => 'Google Fonts',
4353 'Niconne' => 'Google Fonts',
4354 'Niramit' => 'Google Fonts',
4355 'Nixie One' => 'Google Fonts',
4356 'Nobile' => 'Google Fonts',
4357 'Nokora' => 'Google Fonts',
4358 'Norican' => 'Google Fonts',
4359 'Nosifer' => 'Google Fonts',
4360 'Notable' => 'Google Fonts',
4361 'Nothing You Could Do' => 'Google Fonts',
4362 'Noticia Text' => 'Google Fonts',
4363 'Noto Kufi Arabic' => 'Google Fonts', // Hack for Google Early Access.
4364 'Noto Naskh Arabic' => 'Google Fonts', // Hack for Google Early Access.
4365 'Noto Sans' => 'Google Fonts',
4366 'Noto Sans Hebrew' => 'Google Fonts', // Hack for Google Early Access.
4367 'Noto Sans JP' => 'Google Fonts',
4368 'Noto Sans KR' => 'Google Fonts',
4369 'Noto Serif' => 'Google Fonts',
4370 'Noto Serif JP' => 'Google Fonts',
4371 'Noto Serif KR' => 'Google Fonts',
4372 'Nova Cut' => 'Google Fonts',
4373 'Nova Flat' => 'Google Fonts',
4374 'Nova Mono' => 'Google Fonts',
4375 'Nova Oval' => 'Google Fonts',
4376 'Nova Round' => 'Google Fonts',
4377 'Nova Script' => 'Google Fonts',
4378 'Nova Slim' => 'Google Fonts',
4379 'Nova Square' => 'Google Fonts',
4380 'Numans' => 'Google Fonts',
4381 'Nunito' => 'Google Fonts',
4382 'Nunito Sans' => 'Google Fonts',
4383 'Odor Mean Chey' => 'Google Fonts',
4384 'Offside' => 'Google Fonts',
4385 'Old Standard TT' => 'Google Fonts',
4386 'Oldenburg' => 'Google Fonts',
4387 'Oleo Script' => 'Google Fonts',
4388 'Oleo Script Swash Caps' => 'Google Fonts',
4389 'Open Sans' => 'Google Fonts',
4390 'Open Sans Condensed' => 'Google Fonts',
4391 'Open Sans Hebrew' => 'Google Fonts', // Hack for Google Early Access.
4392 'Open Sans Hebrew Condensed' => 'Google Fonts', // Hack for Google Early Access.
4393 'Oranienbaum' => 'Google Fonts',
4394 'Orbitron' => 'Google Fonts',
4395 'Oregano' => 'Google Fonts',
4396 'Orienta' => 'Google Fonts',
4397 'Original Surfer' => 'Google Fonts',
4398 'Oswald' => 'Google Fonts',
4399 'Over the Rainbow' => 'Google Fonts',
4400 'Overlock' => 'Google Fonts',
4401 'Overlock SC' => 'Google Fonts',
4402 'Overpass' => 'Google Fonts',
4403 'Overpass Mono' => 'Google Fonts',
4404 'Ovo' => 'Google Fonts',
4405 'Oxygen' => 'Google Fonts',
4406 'Oxygen Mono' => 'Google Fonts',
4407 'PT Mono' => 'Google Fonts',
4408 'PT Sans' => 'Google Fonts',
4409 'PT Sans Caption' => 'Google Fonts',
4410 'PT Sans Narrow' => 'Google Fonts',
4411 'PT Serif' => 'Google Fonts',
4412 'PT Serif Caption' => 'Google Fonts',
4413 'Pacifico' => 'Google Fonts',
4414 'Padauk' => 'Google Fonts',
4415 'Palanquin' => 'Google Fonts',
4416 'Palanquin Dark' => 'Google Fonts',
4417 'Pangolin' => 'Google Fonts',
4418 'Paprika' => 'Google Fonts',
4419 'Parisienne' => 'Google Fonts',
4420 'Passero One' => 'Google Fonts',
4421 'Passion One' => 'Google Fonts',
4422 'Pathway Gothic One' => 'Google Fonts',
4423 'Patrick Hand' => 'Google Fonts',
4424 'Patrick Hand SC' => 'Google Fonts',
4425 'Pattaya' => 'Google Fonts',
4426 'Patua One' => 'Google Fonts',
4427 'Pavanam' => 'Google Fonts',
4428 'Paytone One' => 'Google Fonts',
4429 'Peddana' => 'Google Fonts',
4430 'Peralta' => 'Google Fonts',
4431 'Permanent Marker' => 'Google Fonts',
4432 'Petit Formal Script' => 'Google Fonts',
4433 'Petrona' => 'Google Fonts',
4434 'Philosopher' => 'Google Fonts',
4435 'Piedra' => 'Google Fonts',
4436 'Pinyon Script' => 'Google Fonts',
4437 'Pirata One' => 'Google Fonts',
4438 'Plaster' => 'Google Fonts',
4439 'Play' => 'Google Fonts',
4440 'Playball' => 'Google Fonts',
4441 'Playfair Display' => 'Google Fonts',
4442 'Playfair Display SC' => 'Google Fonts',
4443 'Podkova' => 'Google Fonts',
4444 'Poiret One' => 'Google Fonts',
4445 'Poller One' => 'Google Fonts',
4446 'Poly' => 'Google Fonts',
4447 'Pompiere' => 'Google Fonts',
4448 'Pontano Sans' => 'Google Fonts',
4449 'Poor Story' => 'Google Fonts',
4450 'Poppins' => 'Google Fonts',
4451 'Port Lligat Sans' => 'Google Fonts',
4452 'Port Lligat Slab' => 'Google Fonts',
4453 'Pragati Narrow' => 'Google Fonts',
4454 'Prata' => 'Google Fonts',
4455 'Preahvihear' => 'Google Fonts',
4456 'Press Start 2P' => 'Google Fonts',
4457 'Pridi' => 'Google Fonts',
4458 'Princess Sofia' => 'Google Fonts',
4459 'Prociono' => 'Google Fonts',
4460 'Prompt' => 'Google Fonts',
4461 'Prosto One' => 'Google Fonts',
4462 'Proza Libre' => 'Google Fonts',
4463 'Puritan' => 'Google Fonts',
4464 'Purple Purse' => 'Google Fonts',
4465 'Quando' => 'Google Fonts',
4466 'Quantico' => 'Google Fonts',
4467 'Quattrocento' => 'Google Fonts',
4468 'Quattrocento Sans' => 'Google Fonts',
4469 'Questrial' => 'Google Fonts',
4470 'Quicksand' => 'Google Fonts',
4471 'Quintessential' => 'Google Fonts',
4472 'Qwigley' => 'Google Fonts',
4473 'Racing Sans One' => 'Google Fonts',
4474 'Radley' => 'Google Fonts',
4475 'Rajdhani' => 'Google Fonts',
4476 'Rakkas' => 'Google Fonts',
4477 'Raleway' => 'Google Fonts',
4478 'Raleway Dots' => 'Google Fonts',
4479 'Ramabhadra' => 'Google Fonts',
4480 'Ramaraja' => 'Google Fonts',
4481 'Rambla' => 'Google Fonts',
4482 'Rammetto One' => 'Google Fonts',
4483 'Ranchers' => 'Google Fonts',
4484 'Rancho' => 'Google Fonts',
4485 'Ranga' => 'Google Fonts',
4486 'Rasa' => 'Google Fonts',
4487 'Rationale' => 'Google Fonts',
4488 'Ravi Prakash' => 'Google Fonts',
4489 'Redressed' => 'Google Fonts',
4490 'Reem Kufi' => 'Google Fonts',
4491 'Reenie Beanie' => 'Google Fonts',
4492 'Revalia' => 'Google Fonts',
4493 'Rhodium Libre' => 'Google Fonts',
4494 'Ribeye' => 'Google Fonts',
4495 'Ribeye Marrow' => 'Google Fonts',
4496 'Righteous' => 'Google Fonts',
4497 'Risque' => 'Google Fonts',
4498 'Roboto' => 'Google Fonts',
4499 'Roboto Condensed' => 'Google Fonts',
4500 'Roboto Mono' => 'Google Fonts',
4501 'Roboto Slab' => 'Google Fonts',
4502 'Rochester' => 'Google Fonts',
4503 'Rock Salt' => 'Google Fonts',
4504 'Rokkitt' => 'Google Fonts',
4505 'Romanesco' => 'Google Fonts',
4506 'Ropa Sans' => 'Google Fonts',
4507 'Rosario' => 'Google Fonts',
4508 'Rosarivo' => 'Google Fonts',
4509 'Rouge Script' => 'Google Fonts',
4510 'Rozha One' => 'Google Fonts',
4511 'Rubik' => 'Google Fonts',
4512 'Rubik Mono One' => 'Google Fonts',
4513 'Ruda' => 'Google Fonts',
4514 'Rufina' => 'Google Fonts',
4515 'Ruge Boogie' => 'Google Fonts',
4516 'Ruluko' => 'Google Fonts',
4517 'Rum Raisin' => 'Google Fonts',
4518 'Ruslan Display' => 'Google Fonts',
4519 'Russo One' => 'Google Fonts',
4520 'Ruthie' => 'Google Fonts',
4521 'Rye' => 'Google Fonts',
4522 'Sacramento' => 'Google Fonts',
4523 'Sahitya' => 'Google Fonts',
4524 'Sail' => 'Google Fonts',
4525 'Saira' => 'Google Fonts',
4526 'Saira Condensed' => 'Google Fonts',
4527 'Saira Extra Condensed' => 'Google Fonts',
4528 'Saira Semi Condensed' => 'Google Fonts',
4529 'Salsa' => 'Google Fonts',
4530 'Sanchez' => 'Google Fonts',
4531 'Sancreek' => 'Google Fonts',
4532 'Sansita' => 'Google Fonts',
4533 'Sarala' => 'Google Fonts',
4534 'Sarina' => 'Google Fonts',
4535 'Sarpanch' => 'Google Fonts',
4536 'Satisfy' => 'Google Fonts',
4537 'Sawarabi Gothic' => 'Google Fonts',
4538 'Sawarabi Mincho' => 'Google Fonts',
4539 'Scada' => 'Google Fonts',
4540 'Scheherazade' => 'Google Fonts',
4541 'Schoolbell' => 'Google Fonts',
4542 'Scope One' => 'Google Fonts',
4543 'Seaweed Script' => 'Google Fonts',
4544 'Secular One' => 'Google Fonts',
4545 'Sedgwick Ave' => 'Google Fonts',
4546 'Sedgwick Ave Display' => 'Google Fonts',
4547 'Sevillana' => 'Google Fonts',
4548 'Seymour One' => 'Google Fonts',
4549 'Shadows Into Light' => 'Google Fonts',
4550 'Shadows Into Light Two' => 'Google Fonts',
4551 'Shanti' => 'Google Fonts',
4552 'Share' => 'Google Fonts',
4553 'Share Tech' => 'Google Fonts',
4554 'Share Tech Mono' => 'Google Fonts',
4555 'Shojumaru' => 'Google Fonts',
4556 'Short Stack' => 'Google Fonts',
4557 'Shrikhand' => 'Google Fonts',
4558 'Siemreap' => 'Google Fonts',
4559 'Sigmar One' => 'Google Fonts',
4560 'Signika' => 'Google Fonts',
4561 'Signika Negative' => 'Google Fonts',
4562 'Simonetta' => 'Google Fonts',
4563 'Sintony' => 'Google Fonts',
4564 'Sirin Stencil' => 'Google Fonts',
4565 'Six Caps' => 'Google Fonts',
4566 'Skranji' => 'Google Fonts',
4567 'Slabo 13px' => 'Google Fonts',
4568 'Slabo 27px' => 'Google Fonts',
4569 'Slackey' => 'Google Fonts',
4570 'Smokum' => 'Google Fonts',
4571 'Smythe' => 'Google Fonts',
4572 'Sniglet' => 'Google Fonts',
4573 'Snippet' => 'Google Fonts',
4574 'Snowburst One' => 'Google Fonts',
4575 'Sofadi One' => 'Google Fonts',
4576 'Sofia' => 'Google Fonts',
4577 'Song Myung' => 'Google Fonts',
4578 'Sonsie One' => 'Google Fonts',
4579 'Sorts Mill Goudy' => 'Google Fonts',
4580 'Source Code Pro' => 'Google Fonts',
4581 'Source Sans Pro' => 'Google Fonts',
4582 'Source Serif Pro' => 'Google Fonts',
4583 'Space Mono' => 'Google Fonts',
4584 'Special Elite' => 'Google Fonts',
4585 'Spectral' => 'Google Fonts',
4586 'Spectral SC' => 'Google Fonts',
4587 'Spicy Rice' => 'Google Fonts',
4588 'Spinnaker' => 'Google Fonts',
4589 'Spirax' => 'Google Fonts',
4590 'Squada One' => 'Google Fonts',
4591 'Sree Krushnadevaraya' => 'Google Fonts',
4592 'Sriracha' => 'Google Fonts',
4593 'Srisakdi' => 'Google Fonts',
4594 'Stalemate' => 'Google Fonts',
4595 'Stalinist One' => 'Google Fonts',
4596 'Stardos Stencil' => 'Google Fonts',
4597 'Stint Ultra Condensed' => 'Google Fonts',
4598 'Stint Ultra Expanded' => 'Google Fonts',
4599 'Stoke' => 'Google Fonts',
4600 'Strait' => 'Google Fonts',
4601 'Stylish' => 'Google Fonts',
4602 'Sue Ellen Francisco' => 'Google Fonts',
4603 'Suez One' => 'Google Fonts',
4604 'Sumana' => 'Google Fonts',
4605 'Sunflower' => 'Google Fonts',
4606 'Sunshiney' => 'Google Fonts',
4607 'Supermercado One' => 'Google Fonts',
4608 'Sura' => 'Google Fonts',
4609 'Suranna' => 'Google Fonts',
4610 'Suravaram' => 'Google Fonts',
4611 'Suwannaphum' => 'Google Fonts',
4612 'Swanky and Moo Moo' => 'Google Fonts',
4613 'Syncopate' => 'Google Fonts',
4614 'Tajawal' => 'Google Fonts',
4615 'Tangerine' => 'Google Fonts',
4616 'Taprom' => 'Google Fonts',
4617 'Tauri' => 'Google Fonts',
4618 'Taviraj' => 'Google Fonts',
4619 'Teko' => 'Google Fonts',
4620 'Telex' => 'Google Fonts',
4621 'Tenali Ramakrishna' => 'Google Fonts',
4622 'Tenor Sans' => 'Google Fonts',
4623 'Text Me One' => 'Google Fonts',
4624 'The Girl Next Door' => 'Google Fonts',
4625 'Tienne' => 'Google Fonts',
4626 'Tillana' => 'Google Fonts',
4627 'Timmana' => 'Google Fonts',
4628 'Tinos' => 'Google Fonts',
4629 'Titan One' => 'Google Fonts',
4630 'Titillium Web' => 'Google Fonts',
4631 'Trade Winds' => 'Google Fonts',
4632 'Trirong' => 'Google Fonts',
4633 'Trocchi' => 'Google Fonts',
4634 'Trochut' => 'Google Fonts',
4635 'Trykker' => 'Google Fonts',
4636 'Tulpen One' => 'Google Fonts',
4637 'Ubuntu' => 'Google Fonts',
4638 'Ubuntu Condensed' => 'Google Fonts',
4639 'Ubuntu Mono' => 'Google Fonts',
4640 'Ultra' => 'Google Fonts',
4641 'Uncial Antiqua' => 'Google Fonts',
4642 'Underdog' => 'Google Fonts',
4643 'Unica One' => 'Google Fonts',
4644 'UnifrakturCook' => 'Google Fonts',
4645 'UnifrakturMaguntia' => 'Google Fonts',
4646 'Unkempt' => 'Google Fonts',
4647 'Unlock' => 'Google Fonts',
4648 'Unna' => 'Google Fonts',
4649 'VT323' => 'Google Fonts',
4650 'Vampiro One' => 'Google Fonts',
4651 'Varela' => 'Google Fonts',
4652 'Varela Round' => 'Google Fonts',
4653 'Vast Shadow' => 'Google Fonts',
4654 'Vesper Libre' => 'Google Fonts',
4655 'Vibur' => 'Google Fonts',
4656 'Vidaloka' => 'Google Fonts',
4657 'Viga' => 'Google Fonts',
4658 'Voces' => 'Google Fonts',
4659 'Volkhov' => 'Google Fonts',
4660 'Vollkorn' => 'Google Fonts',
4661 'Vollkorn SC' => 'Google Fonts',
4662 'Voltaire' => 'Google Fonts',
4663 'Waiting for the Sunrise' => 'Google Fonts',
4664 'Wallpoet' => 'Google Fonts',
4665 'Walter Turncoat' => 'Google Fonts',
4666 'Warnes' => 'Google Fonts',
4667 'Wellfleet' => 'Google Fonts',
4668 'Wendy One' => 'Google Fonts',
4669 'Wire One' => 'Google Fonts',
4670 'Work Sans' => 'Google Fonts',
4671 'Yanone Kaffeesatz' => 'Google Fonts',
4672 'Yantramanav' => 'Google Fonts',
4673 'Yatra One' => 'Google Fonts',
4674 'Yellowtail' => 'Google Fonts',
4675 'Yeon Sung' => 'Google Fonts',
4676 'Yeseva One' => 'Google Fonts',
4677 'Yesteryear' => 'Google Fonts',
4678 'Yrsa' => 'Google Fonts',
4679 'Zeyada' => 'Google Fonts',
4680 'Zilla Slab' => 'Google Fonts',
4681 'Zilla Slab Highlight' => 'Google Fonts',
4682 );
4683 }
4684
4685 public function set_default_values_if_not_exists()
4686 {
4687 $options = get_option('folders_settings');
4688 $options = empty($options) || !is_array($options) ? array() : $options;
4689 foreach ($options as $option) {
4690 $post_type = self::get_custom_post_type($option);
4691 $terms = get_terms($post_type, array(
4692 'hide_empty' => false,
4693 )
4694 );
4695 if (!empty($terms)) {
4696 foreach ($terms as $term) {
4697 $order = get_term_meta($term->term_id, "wcp_custom_order", true);
4698 if (empty($order) || $order == null) {
4699 update_term_meta($term->term_id, "wcp_custom_order", "1");
4700 }
4701 }
4702 }
4703 }
4704 }
4705
4706 /* Free and Pro major changes */
4707 public function premio_hide_child_popup() {
4708 if(isset($_REQUEST['post_type']) && isset($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'wcp_folder_nonce_'.$_REQUEST['post_type'])) {
4709 $status = (isset($_REQUEST['status']) && $_REQUEST['status'] == 1)?1:0;
4710 if($status) {
4711 add_option("premio_hide_child_popup", 1);
4712 } else {
4713 delete_option("premio_hide_child_popup");
4714 }
4715 }
4716 echo esc_attr("1");
4717 die;
4718 }
4719
4720 public function folder_update_popup_status() {
4721 if(!empty($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'folder_update_popup_status')) {
4722 update_option("folder_intro_box", "hide");
4723 }
4724 echo esc_attr("1");
4725 die;
4726 }
4727
4728 public function update_folders_import_status() {
4729 if(!empty($_REQUEST['nonce']) && wp_verify_nonce($_REQUEST['nonce'], 'folders_import_3rd_party_data')) {
4730 update_option("folder_redirect_status", "3");
4731 }
4732 echo esc_attr("1");
4733 die;
4734 }
4735
4736 public function check_has_valid_key()
4737 {
4738 /* Free/Pro: checking for key, for Free return 0, for Pro check for Key */
4739 return 0;
4740 }
4741
4742 public function get_license_key_information($licenseKey)
4743 {
4744 return array();
4745 }
4746
4747 public function get_license_key_data($licenseKey = '')
4748 {
4749 return array();
4750 }
4751
4752 public function check_for_license_key()
4753 {
4754 return false;
4755 }
4756 }