PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 3.0.3
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v3.0.3
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 / plugins.class.php
folders / includes Last commit date
class-affiliate.php 2 years ago class-polylang.php 2 years ago class-review-box.php 2 years ago class-upgrade-box.php 2 years ago class-wpml.php 2 years ago folders.class.php 2 years ago form.class.php 2 years ago media.replace.php 2 years ago plugins.class.php 2 years ago tree.class.php 2 years ago
plugins.class.php
813 lines
1 <?php
2 /**
3 * Class Folders Plugins import/export
4 *
5 * @author : Premio <contact@premio.io>
6 * @license : GPL2
7 * */
8
9 if (! defined('ABSPATH')) {
10 exit;
11 }
12
13 // Free/Pro Class name change
14 class WCP_Folder_Plugins
15 {
16
17 /**
18 * Collection of Plugins to import Data
19 *
20 * @var array $plugins Collection of Plugins
21 * @since 1.0.0
22 * @access public
23 */
24 public $plugins = [];
25
26 /**
27 * Collection of Post types to Import
28 *
29 * @var array $post_types Post types to import
30 * @since 1.0.0
31 * @access public
32 */
33 public $post_types = [];
34
35 /**
36 * Check is there any data to import
37 *
38 * @var integer $is_exists 0/1
39 * @since 1.0.0
40 * @access public
41 */
42 public $is_exists = 0;
43
44
45 /**
46 * Define the core functionality of the import data functionality.
47 * Define the core functionality of the import data functionality.
48 *
49 * Import data from other plugins
50 * Remove data from other plugins
51 *
52 * @since 1.0.0
53 */
54 public function __construct()
55 {
56
57 // Import plugin data
58 add_action('wp_ajax_wcp_import_plugin_folders_data', [$this, 'import_plugin_folders_data']);
59 add_action('wp_ajax_wcp_remove_plugin_folders_data', [$this, 'remove_plugin_folders_data']);
60
61 }//end __construct()
62
63
64 /**
65 * Remove data from other plugins
66 *
67 * @since 1.0.0
68 * @access public
69 * @return $response
70 */
71 public function remove_plugin_folders_data()
72 {
73 global $wpdb;
74 $postData = filter_input_array(INPUT_POST);
75
76 $plugin = isset($postData['plugin']) ? sanitize_text_field($postData['plugin']) : "";
77 $nonce = isset($postData['nonce']) ? sanitize_text_field($postData['nonce']) : "";
78 $response = [];
79 $response['status'] = 0;
80 $response['message'] = esc_html__("Invalid request", "folders");
81 $response['data'] = [];
82 $response['data']['plugin'] = $plugin;
83 if (wp_verify_nonce($nonce, "import_data_from_".$plugin)) {
84 $this->get_plugin_information();
85 $folders = isset($this->plugins[$plugin]['folders']) ? $this->plugins[$plugin]['folders'] : [];
86 $attachments = isset($this->plugins[$plugin]['attachments']) ? $this->plugins[$plugin]['attachments'] : [];
87
88 if ($plugin != 'filebird' && $plugin != 'real-media-library' && $plugin != 'catfolders') {
89 $deleted = [];
90
91 foreach ($folders as $folder) {
92 $term_id = intval($folder->term_id);
93
94 if ($term_id) {
95 $deleted[$term_id]['term_relationships'] = $wpdb->delete($wpdb->prefix.'term_relationships', ['term_taxonomy_id' => $term_id]);
96 $deleted[$term_id]['term_taxonomy'] = $wpdb->delete($wpdb->prefix.'term_taxonomy', ['term_id' => $term_id]);
97 $deleted[$term_id]['terms'] = $wpdb->delete($wpdb->prefix.'terms', ['term_id' => $term_id]);
98
99 if ($plugin === 'folders') {
100 $deleted[$term_id]['termmeta'] = $wpdb->delete($wpdb->prefix.'termmeta', ['term_id' => $term_id]);
101 }
102 }
103 }
104 } else {
105 if (count($folders)) {
106 if ($plugin === 'filebird') {
107 $wpdb->query('DELETE FROM '.$wpdb->prefix.'fbv');
108 }
109
110 if ($plugin === 'real-media-library') {
111 $wpdb->query('DELETE FROM '.$wpdb->prefix.'realmedialibrary');
112
113 $wpdb->query('DELETE FROM '.$wpdb->prefix.'realmedialibrary_meta');
114 }
115
116 if ($plugin === 'catfolders') {
117 $wpdb->query('DELETE FROM '.$wpdb->prefix.'catfolders');
118 }
119 }
120
121 if (count($attachments)) {
122 if ($plugin === 'filebird') {
123 $wpdb->query('DELETE FROM '.$wpdb->prefix.'fbv_attachment_folder');
124 }
125
126 if ($plugin === 'real-media-library') {
127 $wpdb->query('DELETE FROM '.$wpdb->prefix.'realmedialibrary_posts');
128 }
129
130 if ($plugin === 'catfolders') {
131 $wpdb->query('DELETE FROM '.$wpdb->prefix.'catfolders_posts');
132 }
133 }
134 }//end if
135
136 $response['status'] = 1;
137 }//end if
138
139 echo wp_json_encode($response);
140 exit;
141
142 }//end remove_plugin_folders_data()
143
144
145 public function filter_categories_by_term_id($attachments)
146 {
147 $termsData = [];
148 foreach ($attachments as $attachment) {
149 $termsData[$attachment->folder_id][] = $attachment->attachment_id;
150 }
151
152 return $termsData;
153
154 }//end filter_categories_by_term_id()
155
156
157 public function import_plugin_folders_data()
158 {
159
160 global $wpdb;
161
162 $postData = filter_input_array(INPUT_POST);
163
164 $paged = isset($postData['paged']) && is_numeric($postData['paged']) && $postData['paged'] > 0 ? intval(sanitize_text_field($postData['paged'])) : 1;
165 $attachedItems = isset($postData['attached']) && is_numeric($postData['attached']) && $postData['attached'] > 0 ? intval(sanitize_text_field($postData['attached'])) : 0;
166 $startFrom = (10 * ($paged - 1));
167 $endFolder = (10 * $paged);
168 $totalFolders = 0;
169
170 $plugin = isset($postData['plugin']) ? $postData['plugin'] : "";
171 $nonce = isset($postData['nonce']) ? $postData['nonce'] : "";
172
173 $dataSet = [];
174 $response = [];
175 $response['status'] = 0;
176 $response['message'] = esc_html__("Invalid request", "folders");
177 $response['data'] = [];
178 $response['data']['plugin'] = $plugin;
179 if (wp_verify_nonce($nonce, "import_data_from_".$plugin)) {
180 $this->get_plugin_information();
181 $folders = isset($this->plugins[$plugin]['folders']) ? $this->plugins[$plugin]['folders'] : [];
182 $totalFolders = count($folders);
183 $attachments = isset($this->plugins[$plugin]['attachments']) ? $this->plugins[$plugin]['attachments'] : [];
184
185 $categoryByID = [];
186 $foldersImported = [];
187 $attachmentsImported = [];
188 if ($plugin != 'filebird' && $plugin != 'real-media-library' && $plugin != "catfolders") {
189 $currentFolder = -1;
190 foreach ($folders as $folder) {
191 $currentFolder++;
192 $folder_id = $folder->term_id;
193 $parent = intval($folder->parent);
194
195 $taxonomy = 'media_folder';
196
197 foreach ($this->post_types as $post_type) {
198 if (strpos($folder->taxonomy, $post_type) !== false) {
199 if ($post_type == "post") {
200 $taxonomy = "post_folder";
201 } else if ($post_type == "page") {
202 $taxonomy = "folder";
203 } else if ($post_type == "attachment") {
204 $taxonomy = "media_folder";
205 } else {
206 $taxonomy = $post_type.'_folder';
207 }
208 }
209 }
210
211 if ($parent && isset($categoryByID[$parent]['term_id'])) {
212 $parent = intval($categoryByID[$parent]['term_id']);
213 }
214
215 $new_term = wp_insert_term($folder->name, $taxonomy, ['parent' => $parent]);
216
217 if (is_wp_error($new_term)) {
218 if (isset($new_term->errors['term_exists']) && $new_term->error_data['term_exists']) {
219 $termId = $new_term->error_data['term_exists'];
220 $termData = get_term($termId, "", ARRAY_A);
221 if (!empty($termData)) {
222 $new_term = $termData;
223 } else {
224 continue;
225 }
226 } else {
227 continue;
228 }
229 }
230
231 $arg = [
232 'taxonomy' => $taxonomy,
233 'hide_empty' => false,
234 'parent' => $parent,
235 'hierarchical' => false,
236 'update_count_callback' => '_update_generic_term_count',
237 ];
238 $terms = get_terms($arg);
239 $position = count($terms);
240
241 if ($plugin == 'mediamatic' || $plugin == 'happyfiles') {
242 $meta_key = "";
243 if ($plugin == 'mediamatic') {
244 $meta_key = "folder_position";
245 } else if ($plugin == 'happyfiles') {
246 $meta_key = "happyfiles_position";
247 }
248
249 if (!empty($meta_key)) {
250 $folder_position = get_term_meta($new_term['term_id'], $meta_key, true);
251 if (empty($folder_position)) {
252 $position = intval($folder_position);
253 }
254 }
255 }
256
257 update_term_meta($new_term['term_id'], 'wcp_custom_order', $position);
258
259 $foldersImported[] = $new_term;
260
261 $categoryByID[$folder_id] = [
262 'term_id' => $new_term['term_id'],
263 'parent' => $parent,
264 'name' => $folder->name,
265 ];
266
267 $newTermID = $new_term['term_id'];
268 $folderItems = 0;
269 $failedItems = 0;
270 $query = "SELECT object_id FROM ".$wpdb->term_relationships." WHERE term_taxonomy_id = %d AND object_id != 1";
271 $query = $wpdb->prepare($query, $folder->term_taxonomy_id);
272 $results = $wpdb->get_results($query);
273 $found_results = count($results);
274 if ($currentFolder >= $startFrom && $currentFolder < $endFolder) {
275 if (count($results)) {
276 foreach ($results as $result) {
277 $term_set = wp_set_object_terms($result->object_id, $newTermID, $taxonomy, true);
278
279 if (is_wp_error($term_set)) {
280 $failedItems++;
281 continue;
282 }
283
284 $folderItems++;
285
286 $attachmentsImported[] = [
287 'cat_id' => $newTermID,
288 'term_ids' => $result->object_id,
289 'set' => $term_set,
290 ];
291 }
292 }
293
294 $dataSet[] = [
295 'id' => $newTermID,
296 'old_id' => $folder->term_taxonomy_id,
297 'name' => $folder->name,
298 'items' => $folderItems,
299 'failed' => $failedItems,
300 'results' => $found_results,
301 ];
302 }//end if
303 }//end foreach
304 } else {
305 $attachments = $this->filter_categories_by_term_id($attachments);
306 $currentFolder = -1;
307 foreach ($folders as $folder) {
308 $currentFolder++;
309 $parent = intval($folder->parent);
310 if ($parent == -1) {
311 $parent = 0;
312 }
313
314 $parentID = 0;
315
316 if ($parent && isset($categoryByID[$parent]['term_id'])) {
317 $parentID = $categoryByID[$parent]['term_id'];
318 }
319
320 $new_term = wp_insert_term($folder->name, "media_folder", ['parent' => $parentID]);
321
322 if (is_wp_error($new_term)) {
323 if (isset($new_term->errors['term_exists']) && $new_term->error_data['term_exists']) {
324 $termId = $new_term->error_data['term_exists'];
325 $termData = get_term($termId, "", ARRAY_A);
326 if (!empty($termData)) {
327 $new_term = $termData;
328 } else {
329 continue;
330 }
331 } else {
332 continue;
333 }
334 }
335
336 $taxonomy = 'media_folder';
337
338 $arg = [
339 'taxonomy' => $taxonomy,
340 'hide_empty' => false,
341 'parent' => $parentID,
342 'hierarchical' => false,
343 'update_count_callback' => '_update_generic_term_count',
344 ];
345 $terms = get_terms($arg);
346 $position = count($terms);
347
348 update_term_meta($new_term['term_id'], 'wcp_custom_order', intval($position));
349
350 $foldersImported[] = $new_term;
351
352 $categoryByID[$folder->id] = [
353 'name' => $folder->name,
354 'parent' => $parent,
355 'term_id' => $new_term['term_id'],
356 ];
357
358 $newTermID = $new_term['term_id'];
359 $folderItems = 0;
360 $failedItems = 0;
361 $found_results = 0;
362 if ($currentFolder >= $startFrom && $currentFolder < $endFolder) {
363 if (isset($attachments[$folder->id]) && count($attachments[$folder->id]) > 0) {
364 foreach ($attachments[$folder->id] as $result) {
365 $term_set = wp_set_object_terms($result, $newTermID, $taxonomy, true);
366
367 if (is_wp_error($term_set)) {
368 $failedItems++;
369 continue;
370 }
371
372 $folderItems++;
373
374 $attachmentsImported[] = [
375 'cat_id' => $newTermID,
376 'term_ids' => $result->object_id,
377 'set' => $term_set,
378 ];
379 }
380
381 $dataSet[] = [
382 'id' => $newTermID,
383 'old_id' => $folder->id,
384 'name' => $folder->name,
385 'items' => $folderItems,
386 'failed' => $failedItems,
387 'results' => $found_results,
388 ];
389 }//end if
390 }//end if
391 }//end foreach
392 }//end if
393
394 delete_transient("premio_folders_without_trash");
395
396 $totalPages = ceil($totalFolders / 10);
397 $response['status'] = 1;
398 $response['data']['imported'] = count($foldersImported);
399 $response['data']['attachments'] = (count($attachmentsImported) + $attachedItems);
400 $response['data']['data_set'] = $dataSet;
401 $response['data']['folders'] = $totalFolders;
402 $response['data']['pages'] = $totalPages;
403 $response['data']['current'] = $paged;
404 $response['data']['plugin'] = $plugin;
405 $response['message'] = sprintf(esc_html__("%1\$s folders imported and %2\$s attachments categorized.", 'folders'), count($foldersImported), (count($attachmentsImported) + $attachedItems));
406 }//end if
407
408 echo wp_json_encode($response);
409 exit;
410
411 }//end import_plugin_folders_data()
412
413
414 /**
415 * Get installed Plugins list
416 *
417 * @since 1.0.0
418 * @access public
419 * @return $plugins
420 */
421 public function get_plugin_information()
422 {
423 $this->get_other_plugins_data();
424 return $this->plugins;
425
426 }//end get_plugin_information()
427
428
429 /**
430 * Get installed Plugins list to Import data
431 *
432 * @since 1.0.0
433 * @access public
434 * @return $plugins
435 */
436 public function get_other_plugins_data()
437 {
438 if (!empty($this->plugins)) {
439 return $this->plugins;
440 }
441
442 $this->plugins = [
443 // FileBird
444 'filebird' => [
445 'name' => 'FileBird (v4)',
446 'taxonomy' => 'filebird',
447 // has custom DB table
448 'folders' => [],
449 'attachments' => [],
450 'total_folders' => 0,
451 'total_attachments' => 0,
452 'is_exists' => 0,
453 ],
454 'enhanced-media-library' => [
455 // Enhanced Media Library
456 'name' => 'Enhanced Media Library',
457 'taxonomy' => 'media_category',
458 'folders' => [],
459 'attachments' => [],
460 'total_folders' => 0,
461 'total_attachments' => 0,
462 'is_exists' => 0,
463 ],
464 'wicked-folders' => [
465 // Wicked Folders
466 'name' => 'Wicked Folders',
467 'taxonomy' => 'wf_attachment_folders',
468 'folders' => [],
469 'attachments' => [],
470 'total_folders' => 0,
471 'total_attachments' => 0,
472 'is_exists' => 0,
473 ],
474 'real-media-library' => [
475 // Real Media Library
476 'name' => 'Real Media Library (by DevOwl)',
477 'taxonomy' => 'rml',
478 // has custom DB table
479 'folders' => [],
480 'attachments' => [],
481 'total_folders' => 0,
482 'total_attachments' => 0,
483 'is_exists' => 0,
484 ],
485 'wp-media-folder' => [
486 // WP Media Folder
487 'name' => 'WP Media Folder (by JoomUnited)',
488 'taxonomy' => 'wpmf-category',
489 'folders' => [],
490 'attachments' => [],
491 'total_folders' => 0,
492 'total_attachments' => 0,
493 'is_exists' => 0,
494 ],
495 'mediamatic' => [
496 // Mediamatic
497 'name' => 'WordPress Media Library Folders | Mediamatic',
498 'taxonomy' => 'mediamatic_wpfolder',
499 'folders' => [],
500 'attachments' => [],
501 'total_folders' => 0,
502 'total_attachments' => 0,
503 'is_exists' => 0,
504 ],
505 'happyfiles' => [
506 // HappyFiles
507 'name' => 'HappyFiles',
508 'taxonomy' => 'happyfiles_category',
509 'folders' => [],
510 'attachments' => [],
511 'total_folders' => 0,
512 'total_attachments' => 0,
513 'is_exists' => 0,
514 ],
515 'catfolders' => [
516 'name' => 'CatFolders Lite - WP Media Folders',
517 'taxonomy' => 'catfolders',
518 'folders' => [],
519 'attachments' => [],
520 'total_folders' => 0,
521 'total_attachments' => 0,
522 'is_exists' => 0,
523 ]
524 ];
525 $DS = DIRECTORY_SEPARATOR;
526 $dirName = ABSPATH."wp-content{$DS}plugins{$DS}wp-media-library-categories{$DS}";
527 if (is_dir($dirName)) {
528 $settings = get_option("wpmlc_settings");
529 $category = isset($settings['wpmediacategory_taxonomy'])&&!empty($settings['wpmediacategory_taxonomy'])?$settings['wpmediacategory_taxonomy']:'category';
530 $this->plugins['media_library_categories'] = [
531 'name' => 'Media Library Categories',
532 'taxonomy' => $category,
533 'folders' => [],
534 'attachments' => [],
535 'total_folders' => 0,
536 'total_attachments' => 0,
537 'is_exists' => 0,
538 ];
539 }
540
541 $post_types = get_post_types([]);
542 $this->post_types = array_keys($post_types);
543
544 foreach ($this->plugins as $slug => $plugin_data) {
545 $taxonomy = $plugin_data['taxonomy'];
546
547 if ($slug === 'wicked-folders') {
548 // Run for all registered post types
549 $folders = [];
550
551 foreach ($this->post_types as $post_type) {
552 $wicked_folders = $this->get_plugin_folders('wf_'.$post_type.'_folders', $slug);
553
554 if (is_array($wicked_folders)) {
555 $folders = array_merge($folders, $wicked_folders);
556 }
557 }
558 } else {
559 $folders = $this->get_plugin_folders($taxonomy, $slug);
560 }
561
562 if (in_array($taxonomy, ['filebird', 'rml','catfolders'])) {
563 $folders = is_array($folders) && count($folders) ? $this->map_plugin_folders($taxonomy, $folders) : [];
564 }
565
566 $this->plugins[$slug]['folders'] = $folders;
567
568 $attachments = is_array($folders) && count($folders) ? $this->get_plugin_attachments($taxonomy, $folders) : [];
569
570 if (in_array($taxonomy, ['filebird', 'rml','catfolders'])) {
571 $attachments = $this->map_plugin_attachments($taxonomy, $attachments);
572 }
573
574 $this->plugins[$slug]['attachments'] = $attachments;
575 }//end foreach
576
577 foreach ($this->plugins as $key => $plugin) {
578 $folders = isset($plugin['folders'])&&is_array($plugin['folders']) ? $plugin['folders'] : [];
579 $this->plugins[$key]['total_folders'] = count($folders);
580
581 $attachments = isset($plugin['attachments'])&&is_array($plugin['attachments']) ? $plugin['attachments'] : [];
582 $this->plugins[$key]['total_attachments'] = count($attachments);
583
584 if (count($folders) > 0 || count($attachments) > 0) {
585 $this->plugins[$key]['is_exists'] = 1;
586 $this->is_exists = 1;
587 }
588 }
589 }//end get_other_plugins_data()
590
591
592 /**
593 * Get Folders Data From Imported Plugins
594 *
595 * @since 1.0.0
596 * @access public
597 * @return $taxonomy
598 */
599 public function get_plugin_folders($taxonomy, $slug)
600 {
601 global $wpdb;
602
603 // FileBird has its own db table
604 if ($taxonomy === 'filebird') {
605 $filebird_folders_table = $wpdb->prefix.'fbv';
606
607 // Get FileBird folders (order by 'parent' to create parent categories first)
608 if ($wpdb->get_var("SHOW TABLES LIKE '$filebird_folders_table'") == $filebird_folders_table) {
609 return $wpdb->get_results("SELECT * FROM $filebird_folders_table ORDER BY parent ASC");
610 } else {
611 $taxonomy = "nt_wmc_folder";
612
613 $query = "SELECT * FROM ".$wpdb->term_taxonomy."
614 LEFT JOIN ".$wpdb->terms."
615 ON ".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id
616 WHERE ".$wpdb->term_taxonomy.".taxonomy = '%s'
617 ORDER BY parent ASC";
618 $query = $wpdb->prepare($query, $taxonomy);
619 $folders = $wpdb->get_results($query);
620
621 // WP Media Folder (JoomUnited): Remove root folder
622 if ($slug === 'wp-media-folder') {
623 foreach ($folders as $index => $folder) {
624 if ($folder->slug === 'wp-media-folder-root') {
625 unset($folders[$index]);
626 }
627 }
628 }
629
630 return array_values($folders);
631 }
632 } else if ($taxonomy === 'catfolders') {
633 $filebird_folders_table = $wpdb->prefix.'catfolders';
634
635 // Get FileBird folders (order by 'parent' to create parent categories first)
636 if ($wpdb->get_var("SHOW TABLES LIKE '$filebird_folders_table'") == $filebird_folders_table) {
637 return $wpdb->get_results("SELECT * FROM $filebird_folders_table ORDER BY parent ASC");
638 }
639 }
640
641 // Real Media Library has its own db table
642 else if ($taxonomy === 'rml') {
643 $rml_folders_table = $wpdb->prefix.'realmedialibrary';
644
645 // Get FileBird folders (order by 'parent' to create parent categories first)
646 if ($wpdb->get_var("SHOW TABLES LIKE '$rml_folders_table'") == $rml_folders_table) {
647 return $wpdb->get_results("SELECT * FROM $rml_folders_table ORDER BY parent ASC");
648 }
649 }
650
651 // Default: Plugins with custom taxonomy terms
652 else {
653 $query = "SELECT * FROM ".$wpdb->term_taxonomy."
654 LEFT JOIN ".$wpdb->terms."
655 ON ".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id
656 WHERE ".$wpdb->term_taxonomy.".taxonomy = '%s'
657 ORDER BY parent ASC";
658 $query = $wpdb->prepare($query, $taxonomy);
659 $folders = $wpdb->get_results($query);
660
661 // WP Media Folder (JoomUnited): Remove root folder
662 if ($slug === 'wp-media-folder') {
663 foreach ($folders as $index => $folder) {
664 if ($folder->slug === 'wp-media-folder-root') {
665 unset($folders[$index]);
666 }
667 }
668 }
669
670 return array_values($folders);
671 }
672
673 }//end get_plugin_folders()
674
675
676 /**
677 * Get Folders Data From Imported Plugins
678 *
679 * @since 1.0.0
680 * @access public
681 * @return $taxonomy
682 */
683 public function map_plugin_folders($taxonomy, $folders)
684 {
685 $mapped_folders = [];
686
687 foreach ($folders as $folder) {
688 // FileBird, Real Media Library
689 if ($taxonomy === 'filebird' || $taxonomy === 'rml' || $taxonomy === "catfolders") {
690 $folderObj = new \stdClass();
691
692 if($taxonomy == "catfolders") {
693 $folderObj->name = $folder->title;
694 } else {
695 $folderObj->name = $folder->name;
696 }
697 $folderObj->id = intval($folder->id);
698 $folderObj->parent = intval($folder->parent);
699 $folderObj->position = intval($folder->ord);
700
701 $mapped_folders[] = $folderObj;
702 }
703 }
704
705 return $mapped_folders;
706
707 }//end map_plugin_folders()
708
709
710 /**
711 * Save Folders and it's attachment Data From Imported Plugins
712 *
713 * @since 1.0.0
714 * @access public
715 * @return $files
716 */
717 public function map_plugin_attachments($taxonomy, $attachments)
718 {
719 $mapped_attachments = [];
720
721 foreach ($attachments as $folder) {
722 // FileBird
723 if ($taxonomy === 'filebird') {
724 $folderObj = new \stdClass();
725
726 $folderObj->folder_id = intval($folder->folder_id);
727 $folderObj->attachment_id = intval($folder->attachment_id);
728
729 $mapped_attachments[] = $folderObj;
730 }
731
732 // Real Media Library
733 if ($taxonomy === 'rml') {
734 $folderObj = new \stdClass();
735
736 $folderObj->folder_id = intval($folder->fid);
737 $folderObj->attachment_id = intval($folder->attachment);
738
739 $mapped_attachments[] = $folderObj;
740 }
741
742 if($taxonomy === "catfolders") {
743 $folderObj = new \stdClass();
744
745 $folderObj->folder_id = intval($folder->folder_id);
746 $folderObj->attachment_id = intval($folder->post_id);
747
748 $mapped_attachments[] = $folderObj;
749 }
750 }//end foreach
751
752 return $mapped_attachments;
753
754 }//end map_plugin_attachments()
755
756
757 /**
758 * Get Folders and it's attachment Data From Imported Plugins
759 *
760 * @since 1.0.0
761 * @access public
762 * @return $files
763 */
764 public function get_plugin_attachments($taxonomy, $folders)
765 {
766 global $wpdb;
767
768 // FileBird has its own db table
769 if ($taxonomy === 'filebird') {
770 $filebirdTable = $wpdb->prefix.'fbv_attachment_folder';
771
772 // Get FileBird attachments
773 if ($wpdb->get_var("SHOW TABLES LIKE '{$filebirdTable}'") == $filebirdTable) {
774 return $wpdb->get_results("SELECT * FROM {$filebirdTable} ORDER BY folder_id ASC");
775 }
776 }
777
778 else if ($taxonomy === 'catfolders') {
779 $filebirdTable = $wpdb->prefix.'catfolders_posts';
780
781 // Get FileBird attachments
782 if ($wpdb->get_var("SHOW TABLES LIKE '{$filebirdTable}'") == $filebirdTable) {
783 return $wpdb->get_results("SELECT * FROM {$filebirdTable} ORDER BY folder_id ASC");
784 }
785 }
786
787 // Real Media Library has its own db table
788 else if ($taxonomy === 'rml') {
789 $rmlTable = $wpdb->prefix.'realmedialibrary_posts';
790
791 // Get Data from Real Media Library DB Table
792 if ($wpdb->get_var("SHOW TABLES LIKE '{$rmlTable}'") == $rmlTable) {
793 return $wpdb->get_results("SELECT * FROM {$rmlTable} ORDER BY fid ASC");
794 }
795 }
796
797 // Default: Plugins with custom taxonomy terms
798 else {
799 return $wpdb->get_results(
800 "SELECT TR.object_id,
801 TR.term_taxonomy_id
802 FROM ".$wpdb->term_relationships." AS TR
803 WHERE TR.object_id != 1 && TR.term_taxonomy_id IN (".implode(',', array_column($folders, 'term_taxonomy_id')).")"
804 );
805 }
806
807 }//end get_plugin_attachments()
808
809
810 }//end class
811
812 $WCP_Folder_Plugins = new WCP_Folder_Plugins();
813