PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 3.0
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v3.0
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 3 years ago class-polylang.php 2 years ago class-review-box.php 2 years ago class-upgrade-box.php 3 years ago class-wpml.php 3 years ago folders.class.php 2 years ago form.class.php 3 years ago media.replace.php 2 years ago plugins.class.php 2 years ago tree.class.php 2 years ago
plugins.class.php
796 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 $postTypes Post types to import
30 * @since 1.0.0
31 * @access public
32 */
33 public $postTypes = [];
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 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 'hide_empty' => false,
233 'parent' => $parent,
234 'hierarchical' => false,
235 'update_count_callback' => '_update_generic_term_count',
236 ];
237 $terms = get_terms($taxonomy, $arg);
238 $position = count($terms);
239
240 if ($plugin == 'mediamatic' || $plugin == 'happyfiles') {
241 $meta_key = "";
242 if ($plugin == 'mediamatic') {
243 $meta_key = "folder_position";
244 } else if ($plugin == 'happyfiles') {
245 $meta_key = "happyfiles_position";
246 }
247
248 if (!empty($meta_key)) {
249 $folder_position = get_term_meta($new_term['term_id'], $meta_key, true);
250 if (empty($folder_position)) {
251 $position = intval($folder_position);
252 }
253 }
254 }
255
256 update_term_meta($new_term['term_id'], 'wcp_custom_order', $position);
257
258 $foldersImported[] = $new_term;
259
260 $categoryByID[$folder_id] = [
261 'term_id' => $new_term['term_id'],
262 'parent' => $parent,
263 'name' => $folder->name,
264 ];
265
266 $newTermID = $new_term['term_id'];
267 $folderItems = 0;
268 $failedItems = 0;
269 $query = "SELECT object_id FROM ".$wpdb->term_relationships." WHERE term_taxonomy_id = %d";
270 $query = $wpdb->prepare($query, [$folder->term_taxonomy_id]);
271 $results = $wpdb->get_results($query);
272 $found_results = count($results);
273 if ($currentFolder >= $startFrom && $currentFolder < $endFolder) {
274 if (count($results)) {
275 foreach ($results as $result) {
276 $term_set = wp_set_object_terms($result->object_id, $newTermID, $taxonomy, true);
277
278 if (is_wp_error($term_set)) {
279 $failedItems++;
280 continue;
281 }
282
283 $folderItems++;
284
285 $attachmentsImported[] = [
286 'cat_id' => $newTermID,
287 'term_ids' => $result->object_id,
288 'set' => $term_set,
289 ];
290 }
291 }
292
293 $dataSet[] = [
294 'id' => $newTermID,
295 'old_id' => $folder->term_taxonomy_id,
296 'name' => $folder->name,
297 'items' => $folderItems,
298 'failed' => $failedItems,
299 'results' => $found_results,
300 ];
301 }//end if
302 }//end foreach
303 } else {
304 $attachments = $this->filter_categories_by_term_id($attachments);
305 $currentFolder = -1;
306 foreach ($folders as $folder) {
307 $currentFolder++;
308 $parent = intval($folder->parent);
309 if ($parent == -1) {
310 $parent = 0;
311 }
312
313 $parentID = 0;
314
315 if ($parent && isset($categoryByID[$parent]['term_id'])) {
316 $parentID = $categoryByID[$parent]['term_id'];
317 }
318
319 $new_term = wp_insert_term($folder->name, "media_folder", ['parent' => $parentID]);
320
321 if (is_wp_error($new_term)) {
322 if (isset($new_term->errors['term_exists']) && $new_term->error_data['term_exists']) {
323 $termId = $new_term->error_data['term_exists'];
324 $termData = get_term($termId, "", ARRAY_A);
325 if (!empty($termData)) {
326 $new_term = $termData;
327 } else {
328 continue;
329 }
330 } else {
331 continue;
332 }
333 }
334
335 $taxonomy = 'media_folder';
336
337 $arg = [
338 'hide_empty' => false,
339 'parent' => $parentID,
340 'hierarchical' => false,
341 'update_count_callback' => '_update_generic_term_count',
342 ];
343 $terms = get_terms($taxonomy, $arg);
344 $position = count($terms);
345
346 update_term_meta($new_term['term_id'], 'wcp_custom_order', intval($position));
347
348 $foldersImported[] = $new_term;
349
350 $categoryByID[$folder->id] = [
351 'name' => $folder->name,
352 'parent' => $parent,
353 'term_id' => $new_term['term_id'],
354 ];
355
356 $newTermID = $new_term['term_id'];
357 $folderItems = 0;
358 $failedItems = 0;
359 $found_results = 0;
360 if ($currentFolder >= $startFrom && $currentFolder < $endFolder) {
361 if (isset($attachments[$folder->id]) && count($attachments[$folder->id]) > 0) {
362 foreach ($attachments[$folder->id] as $result) {
363 $term_set = wp_set_object_terms($result, $newTermID, $taxonomy, true);
364
365 if (is_wp_error($term_set)) {
366 $failedItems++;
367 continue;
368 }
369
370 $folderItems++;
371
372 $attachmentsImported[] = [
373 'cat_id' => $newTermID,
374 'term_ids' => $result->object_id,
375 'set' => $term_set,
376 ];
377 }
378
379 $dataSet[] = [
380 'id' => $newTermID,
381 'old_id' => $folder->id,
382 'name' => $folder->name,
383 'items' => $folderItems,
384 'failed' => $failedItems,
385 'results' => $found_results,
386 ];
387 }//end if
388 }//end if
389 }//end foreach
390 }//end if
391
392 delete_transient("premio_folders_without_trash");
393
394 $totalPages = ceil($totalFolders / 10);
395 $response['status'] = 1;
396 $response['data']['imported'] = count($foldersImported);
397 $response['data']['attachments'] = (count($attachmentsImported) + $attachedItems);
398 $response['data']['data_set'] = $dataSet;
399 $response['data']['folders'] = $totalFolders;
400 $response['data']['pages'] = $totalPages;
401 $response['data']['current'] = $paged;
402 $response['data']['plugin'] = $plugin;
403 $response['message'] = sprintf(esc_html__('%s folders imported and %s attachments categorized.', 'folders'), count($foldersImported), (count($attachmentsImported) + $attachedItems));
404 }//end if
405
406 echo json_encode($response);
407 exit;
408
409 }//end import_plugin_folders_data()
410
411
412 /**
413 * Get installed Plugins list
414 *
415 * @since 1.0.0
416 * @access public
417 * @return $plugins
418 */
419 public function get_plugin_information()
420 {
421 $this->get_other_plugins_data();
422 return $this->plugins;
423
424 }//end get_plugin_information()
425
426
427 /**
428 * Get installed Plugins list to Import data
429 *
430 * @since 1.0.0
431 * @access public
432 * @return $plugins
433 */
434 public function get_other_plugins_data()
435 {
436 if (!empty($this->plugins)) {
437 return $this->plugins;
438 }
439
440 $this->plugins = [
441 // FileBird
442 'filebird' => [
443 'name' => 'FileBird (v4)',
444 'taxonomy' => 'filebird',
445 // has custom DB table
446 'folders' => [],
447 'attachments' => [],
448 'total_folders' => 0,
449 'total_attachments' => 0,
450 'is_exists' => 0,
451 ],
452 'enhanced-media-library' => [
453 // Enhanced Media Library
454 'name' => 'Enhanced Media Library',
455 'taxonomy' => 'media_category',
456 'folders' => [],
457 'attachments' => [],
458 'total_folders' => 0,
459 'total_attachments' => 0,
460 'is_exists' => 0,
461 ],
462 'wicked-folders' => [
463 // Wicked Folders
464 'name' => 'Wicked Folders',
465 'taxonomy' => 'wf_attachment_folders',
466 'folders' => [],
467 'attachments' => [],
468 'total_folders' => 0,
469 'total_attachments' => 0,
470 'is_exists' => 0,
471 ],
472 'real-media-library' => [
473 // Real Media Library
474 'name' => 'Real Media Library (by DevOwl)',
475 'taxonomy' => 'rml',
476 // has custom DB table
477 'folders' => [],
478 'attachments' => [],
479 'total_folders' => 0,
480 'total_attachments' => 0,
481 'is_exists' => 0,
482 ],
483 'wp-media-folder' => [
484 // WP Media Folder
485 'name' => 'WP Media Folder (by JoomUnited)',
486 'taxonomy' => 'wpmf-category',
487 'folders' => [],
488 'attachments' => [],
489 'total_folders' => 0,
490 'total_attachments' => 0,
491 'is_exists' => 0,
492 ],
493 'mediamatic' => [
494 // Mediamatic
495 'name' => 'WordPress Media Library Folders | Mediamatic',
496 'taxonomy' => 'mediamatic_wpfolder',
497 'folders' => [],
498 'attachments' => [],
499 'total_folders' => 0,
500 'total_attachments' => 0,
501 'is_exists' => 0,
502 ],
503 'happyfiles' => [
504 // HappyFiles
505 'name' => 'HappyFiles',
506 'taxonomy' => 'happyfiles_category',
507 'folders' => [],
508 'attachments' => [],
509 'total_folders' => 0,
510 'total_attachments' => 0,
511 'is_exists' => 0,
512 ],
513 'catfolders' => [
514 'name' => 'CatFolders Lite - WP Media Folders',
515 'taxonomy' => 'catfolders',
516 'folders' => [],
517 'attachments' => [],
518 'total_folders' => 0,
519 'total_attachments' => 0,
520 'is_exists' => 0,
521 ],
522 ];
523 $post_types = get_post_types([]);
524 $this->post_types = array_keys($post_types);
525
526 foreach ($this->plugins as $slug => $plugin_data) {
527 $taxonomy = $plugin_data['taxonomy'];
528
529 if ($slug === 'wicked-folders') {
530 // Run for all registered post types
531 $folders = [];
532
533 foreach ($this->post_types as $post_type) {
534 $wicked_folders = $this->get_plugin_folders('wf_'.$post_type.'_folders', $slug);
535
536 if (is_array($wicked_folders)) {
537 $folders = array_merge($folders, $wicked_folders);
538 }
539 }
540 } else {
541 $folders = $this->get_plugin_folders($taxonomy, $slug);
542 }
543
544 if (in_array($taxonomy, ['filebird', 'rml','catfolders'])) {
545 $folders = is_array($folders) && count($folders) ? $this->map_plugin_folders($taxonomy, $folders) : [];
546 }
547
548 $this->plugins[$slug]['folders'] = $folders;
549
550 $attachments = is_array($folders) && count($folders) ? $this->get_plugin_attachments($taxonomy, $folders) : [];
551
552 if (in_array($taxonomy, ['filebird', 'rml','catfolders'])) {
553 $attachments = $this->map_plugin_attachments($taxonomy, $attachments);
554 }
555
556 $this->plugins[$slug]['attachments'] = $attachments;
557 }//end foreach
558
559 foreach ($this->plugins as $key => $plugin) {
560 $folders = isset($plugin['folders'])&&is_array($plugin['folders']) ? $plugin['folders'] : [];
561 $this->plugins[$key]['total_folders'] = count($folders);
562
563 $attachments = isset($plugin['attachments'])&&is_array($plugin['attachments']) ? $plugin['attachments'] : [];
564 $this->plugins[$key]['total_attachments'] = count($attachments);
565
566 if (count($folders) > 0 || count($attachments) > 0) {
567 $this->plugins[$key]['is_exists'] = 1;
568 $this->is_exists = 1;
569 }
570 }
571
572 }//end get_other_plugins_data()
573
574
575 /**
576 * Get Folders Data From Imported Plugins
577 *
578 * @since 1.0.0
579 * @access public
580 * @return $taxonomy
581 */
582 public function get_plugin_folders($taxonomy, $slug)
583 {
584 global $wpdb;
585
586 // FileBird has its own db table
587 if ($taxonomy === 'filebird') {
588 $filebird_folders_table = $wpdb->prefix.'fbv';
589
590 // Get FileBird folders (order by 'parent' to create parent categories first)
591 if ($wpdb->get_var("SHOW TABLES LIKE '$filebird_folders_table'") == $filebird_folders_table) {
592 return $wpdb->get_results("SELECT * FROM $filebird_folders_table ORDER BY parent ASC");
593 } else {
594 $taxonomy = "nt_wmc_folder";
595
596 $query = "SELECT * FROM ".$wpdb->term_taxonomy."
597 LEFT JOIN ".$wpdb->terms."
598 ON ".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id
599 WHERE ".$wpdb->term_taxonomy.".taxonomy = '%d'
600 ORDER BY parent ASC";
601 $query = $wpdb->prepare($query, $taxonomy);
602 $folders = $wpdb->get_results($query);
603
604 // WP Media Folder (JoomUnited): Remove root folder
605 if ($slug === 'wp-media-folder') {
606 foreach ($folders as $index => $folder) {
607 if ($folder->slug === 'wp-media-folder-root') {
608 unset($folders[$index]);
609 }
610 }
611 }
612
613 return array_values($folders);
614 }
615 } else if ($taxonomy === 'catfolders') {
616 $filebird_folders_table = $wpdb->prefix.'catfolders';
617
618 // Get FileBird folders (order by 'parent' to create parent categories first)
619 if ($wpdb->get_var("SHOW TABLES LIKE '$filebird_folders_table'") == $filebird_folders_table) {
620 return $wpdb->get_results("SELECT * FROM $filebird_folders_table ORDER BY parent ASC");
621 }
622 }
623
624 // Real Media Library has its own db table
625 else if ($taxonomy === 'rml') {
626 $rml_folders_table = $wpdb->prefix.'realmedialibrary';
627
628 // Get FileBird folders (order by 'parent' to create parent categories first)
629 if ($wpdb->get_var("SHOW TABLES LIKE '$rml_folders_table'") == $rml_folders_table) {
630 return $wpdb->get_results("SELECT * FROM $rml_folders_table ORDER BY parent ASC");
631 }
632 }
633
634 // Default: Plugins with custom taxonomy terms
635 else {
636 $query = "SELECT * FROM ".$wpdb->term_taxonomy."
637 LEFT JOIN ".$wpdb->terms."
638 ON ".$wpdb->term_taxonomy.".term_id = ".$wpdb->terms.".term_id
639 WHERE ".$wpdb->term_taxonomy.".taxonomy = '%d'
640 ORDER BY parent ASC";
641 $query = $wpdb->prepare($query, $taxonomy);
642 $folders = $wpdb->get_results($query);
643
644 // WP Media Folder (JoomUnited): Remove root folder
645 if ($slug === 'wp-media-folder') {
646 foreach ($folders as $index => $folder) {
647 if ($folder->slug === 'wp-media-folder-root') {
648 unset($folders[$index]);
649 }
650 }
651 }
652
653 return array_values($folders);
654 }
655
656 }//end get_plugin_folders()
657
658
659 /**
660 * Get Folders Data From Imported Plugins
661 *
662 * @since 1.0.0
663 * @access public
664 * @return $taxonomy
665 */
666 public function map_plugin_folders($taxonomy, $folders)
667 {
668 $mapped_folders = [];
669
670 foreach ($folders as $folder) {
671 // FileBird, Real Media Library
672 if ($taxonomy === 'filebird' || $taxonomy === 'rml' || $taxonomy === "catfolders") {
673 $folderObj = new \stdClass();
674
675 if($taxonomy == "catfolders") {
676 $folderObj->name = $folder->title;
677 } else {
678 $folderObj->name = $folder->name;
679 }
680 $folderObj->id = intval($folder->id);
681 $folderObj->parent = intval($folder->parent);
682 $folderObj->position = intval($folder->ord);
683
684 $mapped_folders[] = $folderObj;
685 }
686 }
687
688 return $mapped_folders;
689
690 }//end map_plugin_folders()
691
692
693 /**
694 * Save Folders and it's attachment Data From Imported Plugins
695 *
696 * @since 1.0.0
697 * @access public
698 * @return $files
699 */
700 public function map_plugin_attachments($taxonomy, $attachments)
701 {
702 $mapped_attachments = [];
703
704 foreach ($attachments as $folder) {
705 // FileBird
706 if ($taxonomy === 'filebird') {
707 $folderObj = new \stdClass();
708
709 $folderObj->folder_id = intval($folder->folder_id);
710 $folderObj->attachment_id = intval($folder->attachment_id);
711
712 $mapped_attachments[] = $folderObj;
713 }
714
715 // Real Media Library
716 if ($taxonomy === 'rml') {
717 $folderObj = new \stdClass();
718
719 $folderObj->folder_id = intval($folder->fid);
720 $folderObj->attachment_id = intval($folder->attachment);
721
722 $mapped_attachments[] = $folderObj;
723 }
724
725 if($taxonomy === "catfolders") {
726 $folderObj = new \stdClass();
727
728 $folderObj->folder_id = intval($folder->folder_id);
729 $folderObj->attachment_id = intval($folder->post_id);
730
731 $mapped_attachments[] = $folderObj;
732 }
733 }//end foreach
734
735 return $mapped_attachments;
736
737 }//end map_plugin_attachments()
738
739
740 /**
741 * Get Folders and it's attachment Data From Imported Plugins
742 *
743 * @since 1.0.0
744 * @access public
745 * @return $files
746 */
747 public function get_plugin_attachments($taxonomy, $folders)
748 {
749 global $wpdb;
750
751 // FileBird has its own db table
752 if ($taxonomy === 'filebird') {
753 $filebirdTable = $wpdb->prefix.'fbv_attachment_folder';
754
755 // Get FileBird attachments
756 if ($wpdb->get_var("SHOW TABLES LIKE '{$filebirdTable}'") == $filebirdTable) {
757 return $wpdb->get_results("SELECT * FROM {$filebirdTable} ORDER BY folder_id ASC");
758 }
759 }
760
761 else if ($taxonomy === 'catfolders') {
762 $filebirdTable = $wpdb->prefix.'catfolders_posts';
763
764 // Get FileBird attachments
765 if ($wpdb->get_var("SHOW TABLES LIKE '{$filebirdTable}'") == $filebirdTable) {
766 return $wpdb->get_results("SELECT * FROM {$filebirdTable} ORDER BY folder_id ASC");
767 }
768 }
769
770 // Real Media Library has its own db table
771 else if ($taxonomy === 'rml') {
772 $rmlTable = $wpdb->prefix.'realmedialibrary_posts';
773
774 // Get Data from Real Media Library DB Table
775 if ($wpdb->get_var("SHOW TABLES LIKE '{$rmlTable}'") == $rmlTable) {
776 return $wpdb->get_results("SELECT * FROM {$rmlTable} ORDER BY fid ASC");
777 }
778 }
779
780 // Default: Plugins with custom taxonomy terms
781 else {
782 return $wpdb->get_results(
783 "SELECT TR.object_id,
784 TR.term_taxonomy_id
785 FROM ".$wpdb->term_relationships." AS TR
786 WHERE TR.term_taxonomy_id IN (".implode(',', array_column($folders, 'term_taxonomy_id')).")"
787 );
788 }
789
790 }//end get_plugin_attachments()
791
792
793 }//end class
794
795 $WCP_Folder_Plugins = new WCP_Folder_Plugins();
796