PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.8.2
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.8.2
3.1.9 3.1.8 3.1.7 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 trunk 1.3.7 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9 2.9.1 2.9.2
folders / includes / plugins.class.php
folders / includes Last commit date
class-affiliate.php 3 years ago class-polylang.php 3 years ago class-review-box.php 3 years ago class-upgrade-box.php 3 years ago class-wpml.php 3 years ago folders.class.php 3 years ago form.class.php 3 years ago media.replace.php 3 years ago plugin.updates.php 3 years ago plugins.class.php 3 years ago tree.class.php 3 years ago
plugins.class.php
541 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3 /* Free/Pro Class name change */
4 class WCP_Folder_Plugins {
5
6 public $plugins = array();
7 public $post_types = array();
8 public $is_exists = 0;
9
10 public function __construct() {
11
12 /* Import plugin data */
13 add_action( 'wp_ajax_wcp_import_plugin_folders_data', array($this, 'import_plugin_folders_data'));
14 add_action( 'wp_ajax_wcp_remove_plugin_folders_data', array($this, 'remove_plugin_folders_data'));
15 }
16
17
18 public function remove_plugin_folders_data(){
19 global $wpdb;
20 $postData = filter_input_array(INPUT_POST);
21
22 $plugin = isset($postData['plugin']) ? $postData['plugin'] : "";
23 $nonce = isset($postData['nonce']) ? $postData['nonce'] : "";
24 $response = array();
25 $response['status'] = 0;
26 $response['message'] = esc_html__("Invalid request", "folders");
27 $response['data'] = array();
28 $response['data']['plugin'] = $plugin;
29 if (wp_verify_nonce($nonce, "import_data_from_" . $plugin)) {
30 $this->get_plugin_information();
31 $folders = isset($this->plugins[$plugin]['folders']) ? $this->plugins[$plugin]['folders'] : array();
32 $attachments = isset($this->plugins[$plugin]['attachments']) ? $this->plugins[$plugin]['attachments'] : array();
33
34 if($plugin != 'filebird' && $plugin != 'real-media-library') {
35 $deleted = [];
36
37 foreach ( $folders as $folder ) {
38 $term_id = intval( $folder->term_id );
39
40 if ( $term_id ) {
41 $deleted[$term_id]['term_relationships'] = $wpdb->delete( $wpdb->prefix . 'term_relationships', ['term_taxonomy_id' => $term_id] );
42 $deleted[$term_id]['term_taxonomy'] = $wpdb->delete( $wpdb->prefix . 'term_taxonomy', ['term_id' => $term_id] );
43 $deleted[$term_id]['terms'] = $wpdb->delete( $wpdb->prefix . 'terms', ['term_id' => $term_id] );
44
45 if ( $plugin === 'folders' ) {
46 $deleted[$term_id]['termmeta'] = $wpdb->delete( $wpdb->prefix . 'termmeta', ['term_id' => $term_id] );
47 }
48 }
49 }
50 } else {
51
52 if ( count( $folders ) ) {
53 if ( $plugin === 'filebird' ) {
54 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'fbv' );
55 }
56
57 if ( $plugin === 'real-media-library' ) {
58 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'realmedialibrary' );
59
60 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'realmedialibrary_meta' );
61 }
62 }
63
64 if ( count( $attachments ) ) {
65 if ( $plugin === 'filebird' ) {
66 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'fbv_attachment_folder' );
67 }
68
69 if ( $plugin === 'real-media-library' ) {
70 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'realmedialibrary_posts' );
71 }
72 }
73 }
74 $response['status'] = 1;
75
76 }
77 echo json_encode($response);
78 exit;
79 }
80
81 public function import_plugin_folders_data() {
82 $postData = filter_input_array(INPUT_POST);
83
84 $plugin = isset($postData['plugin']) ?$postData['plugin']:"";
85 $nonce = isset($postData['nonce']) ?$postData['nonce']:"";
86 $response = array();
87 $response['status'] = 0;
88 $response['message'] = esc_html__("Invalid request", "folders");
89 $response['data'] = array();
90 $response['data']['plugin'] = $plugin;
91 if(wp_verify_nonce($nonce, "import_data_from_".$plugin)) {
92 $this->get_plugin_information();
93 $folders = isset($this->plugins[$plugin]['folders']) ? $this->plugins[$plugin]['folders'] : array();
94 $attachments = isset($this->plugins[$plugin]['attachments']) ? $this->plugins[$plugin]['attachments'] : array();
95
96 $categoryByID = array();
97 $foldersImported = array();
98 $attachmentsImported = array();
99
100 if($plugin != 'filebird' && $plugin != 'real-media-library') {
101
102 foreach ($folders as $folder) {
103 $folder_id = $folder->term_id;
104 $parent = intval($folder->parent);
105
106 $taxonomy = 'media_folder';
107
108 foreach ($this->post_types as $post_type) {
109 if (strpos($folder->taxonomy, $post_type) !== false) {
110 if ($post_type == "post") {
111 $taxonomy = "post_folder";
112 } else if ($post_type == "page") {
113 $taxonomy = "folder";
114 } else if ($post_type == "attachment") {
115 $taxonomy = "media_folder";
116 } else {
117 $taxonomy = $post_type . '_folder';
118 }
119 }
120 }
121
122 if ($parent && isset($categoryByID[$parent]['term_id'])) {
123 $parent = intval($categoryByID[$parent]['term_id']);
124 }
125
126 $new_term = wp_insert_term($folder->name, $taxonomy, ['parent' => $parent]);
127
128 if (is_wp_error($new_term)) {
129 continue;
130 }
131
132 $arg = array(
133 'hide_empty' => false,
134 'parent' => $parent,
135 'hierarchical' => false,
136 'update_count_callback' => '_update_generic_term_count',
137 );
138 $terms = get_terms( $taxonomy, $arg);
139 $position = count($terms);
140
141 if($plugin == 'mediamatic' || $plugin == 'happyfiles') {
142 $meta_key = "";
143 if($plugin == 'mediamatic') {
144 $meta_key = "folder_position";
145 } else if($plugin == 'happyfiles') {
146 $meta_key = "happyfiles_position";
147 }
148 if(!empty($meta_key)) {
149 $folder_position = get_term_meta($new_term['term_id'], $meta_key, true);
150 if(empty($folder_position)) {
151 $position = intval($folder_position);
152 }
153 }
154 }
155
156 update_term_meta($new_term['term_id'], 'wcp_custom_order', $position);
157
158 $foldersImported[] = $new_term;
159
160 $categoryByID[$folder_id] = [
161 'term_id' => $new_term['term_id'],
162 'parent' => $parent,
163 'name' => $folder->name,
164 ];
165 }
166
167 // STEP: Assign plugin categories to HF categories
168 foreach ($attachments as $attachment) {
169 $hf_category_id = isset($categoryByID[$attachment->term_taxonomy_id]['term_id']) ? intval($categoryByID[$attachment->term_taxonomy_id]['term_id']) : 0;
170 $attachment_id = isset($attachment->object_id) ? intval($attachment->object_id) : 0;
171
172 if (!$hf_category_id || !$attachment_id) {
173 continue;
174 }
175
176 // Get attachment taxonomy by post type
177 $post_type = get_post_type($attachment_id);
178 if ($post_type == "post") {
179 $taxonomy = "post_folder";
180 } else if ($post_type == "page") {
181 $taxonomy = "folder";
182 } else if ($post_type == "attachment") {
183 $taxonomy = "media_folder";
184 } else {
185 $taxonomy = $post_type . '_folder';
186 }
187
188 $term_ids = wp_get_object_terms($attachment_id, $taxonomy, ['fields' => 'ids']);
189 $term_ids[] = $hf_category_id;
190
191 $term_set = wp_set_object_terms($attachment_id, $term_ids, $taxonomy);
192
193 if (is_wp_error($term_set)) {
194 continue;
195 }
196
197 $attachmentsImported[] = [
198 'cat_id' => $hf_category_id,
199 'term_ids' => $term_ids,
200 'set' => $term_set,
201 ];
202 }
203 } else {
204 foreach ( $folders as $folder ) {
205 $parent = intval( $folder->parent );
206 $parentID = 0;
207
208 if ( $parent && isset( $categoryByID[$parent]['term_id'] ) ) {
209 $parentID = $categoryByID[$parent]['term_id'];
210 }
211
212 $new_term = wp_insert_term( $folder->name, "media_folder", ['parent' => $parentID] );
213
214 if ( is_wp_error( $new_term ) ) {
215 continue;
216 }
217
218 $taxonomy = 'media_folder';
219
220 $arg = array(
221 'hide_empty' => false,
222 'parent' => $parentID,
223 'hierarchical' => false,
224 'update_count_callback' => '_update_generic_term_count',
225 );
226 $terms = get_terms( $taxonomy, $arg);
227 $position = count($terms);
228
229
230 update_term_meta( $new_term['term_id'], 'wcp_custom_order', intval( $position ) );
231
232 $foldersImported[] = $new_term;
233
234 $categoryByID[$folder->id] = [
235 'name' => $folder->name,
236 'parent' => $parent,
237 'term_id' => $new_term['term_id'],
238 ];
239 }
240
241 foreach ( $attachments as $attachment ) {
242 $hf_category_id = isset( $categoryByID[$attachment->folder_id]['term_id'] ) ? intval( $categoryByID[$attachment->folder_id]['term_id'] ) : 0;
243 $attachment_id = isset( $attachment->attachment_id ) ? intval( $attachment->attachment_id ) : 0;
244
245 if ( ! $hf_category_id || ! $attachment_id ) {
246 continue;
247 }
248
249 $term_ids = wp_get_object_terms( $attachment_id, "media_folder", ['fields' => 'ids'] );
250 $term_ids[] = $hf_category_id;
251
252 $term_set = wp_set_object_terms( $attachment_id, $term_ids, "media_folder" );
253
254 if ( is_wp_error( $term_set ) ) {
255 continue;
256 }
257
258 $attachmentsImported[] = [
259 'cat_id' => $hf_category_id,
260 'term_ids' => $term_ids,
261 'set' => $term_set,
262 ];
263 }
264 }
265
266 $response['status'] = 1;
267 $response['data']['imported'] = count($foldersImported);
268 $response['data']['attachments'] = count($attachmentsImported);
269 $response['data']['plugin'] = $plugin;
270 $response['message'] = sprintf(esc_html__( '%s folders imported and %s attachments categorized.', 'folders'), count($foldersImported), count($attachmentsImported));
271 }
272 echo json_encode($response);
273 exit;
274 }
275
276 public function get_plugin_information() {
277 $this->get_other_plugins_data();
278 return $this->plugins;
279 }
280
281 public function get_other_plugins_data() {
282 if(!empty($this->plugins)) {
283 return $this->plugins;
284 }
285 $this->plugins = array(
286 // FileBird
287 'filebird' => array(
288 'name' => 'FileBird (v4)',
289 'taxonomy' => 'filebird', // has custom DB table
290 'folders' => array(),
291 'attachments' => array(),
292 'total_folders' => 0,
293 'total_attachments' => 0,
294 'is_exists' => 0
295 ),
296 'enhanced-media-library' => array(
297 // Enhanced Media Library
298 'name' => 'Enhanced Media Library',
299 'taxonomy' => 'media_category',
300 'folders' => array(),
301 'attachments' => array(),
302 'total_folders' => 0,
303 'total_attachments' => 0,
304 'is_exists' => 0
305 ),
306 'wicked-folders' => array(
307 // Enhanced Media Library
308 'name' => 'Wicked Folders',
309 'taxonomy' => 'wf_attachment_folders',
310 'folders' => array(),
311 'attachments' => array(),
312 'total_folders' => 0,
313 'total_attachments' => 0,
314 'is_exists' => 0
315 ),
316 'real-media-library' => array(
317 // Real Media Library
318 'name' => 'Real Media Library (by DevOwl)',
319 'taxonomy' => 'rml', // has custom DB table
320 'folders' => array(),
321 'attachments' => array(),
322 'total_folders' => 0,
323 'total_attachments' => 0,
324 'is_exists' => 0
325 ),
326 'wp-media-folder' => array(
327 // Real Media Library
328 'name' => 'WP Media Folder (by JoomUnited)',
329 'taxonomy' => 'wpmf-category',
330 'folders' => array(),
331 'attachments' => array(),
332 'total_folders' => 0,
333 'total_attachments' => 0,
334 'is_exists' => 0
335 ),
336 'mediamatic' => array(
337 // Mediamatic
338 'name' => 'WordPress Media Library Folders | Mediamatic',
339 'taxonomy' => 'mediamatic_wpfolder',
340 'folders' => array(),
341 'attachments' => array(),
342 'total_folders' => 0,
343 'total_attachments' => 0,
344 'is_exists' => 0
345 ),
346 'happyfiles' => array(
347 // HappyFiles
348 'name' => 'HappyFiles',
349 'taxonomy' => 'happyfiles_category',
350 'folders' => array(),
351 'attachments' => array(),
352 'total_folders' => 0,
353 'total_attachments' => 0,
354 'is_exists' => 0
355 )
356 );
357 $post_types = get_post_types(array());
358 $this->post_types = array_keys($post_types);
359
360 foreach ($this->plugins as $slug => $plugin_data ) {
361 $taxonomy = $plugin_data['taxonomy'];
362
363 if ( $slug === 'wicked-folders' ) {
364 // Run for all registered post types
365 $folders = [];
366
367 foreach ( $this->post_types as $post_type ) {
368 $wicked_folders = $this->get_plugin_folders( 'wf_' . $post_type . '_folders', $slug );
369
370 if ( is_array( $wicked_folders ) ) {
371 $folders = array_merge( $folders, $wicked_folders );
372 }
373 }
374 }
375
376 else {
377 $folders = $this->get_plugin_folders( $taxonomy, $slug );
378 }
379
380 if ( in_array( $taxonomy, ['filebird', 'rml'] ) ) {
381 $folders = is_array( $folders ) && count( $folders ) ? $this->map_plugin_folders( $taxonomy, $folders ) : [];
382 }
383
384 $this->plugins[$slug]['folders'] = $folders;
385
386 $attachments = is_array( $folders ) && count( $folders ) ? $this->get_plugin_attachments( $taxonomy, $folders ) : [];
387
388 if ( in_array( $taxonomy, ['filebird', 'rml'] ) ) {
389 $attachments = $this->map_plugin_attachments( $taxonomy, $attachments );
390 }
391
392 $this->plugins[$slug]['attachments'] = $attachments;
393 }
394
395 foreach ($this->plugins as $key=>$plugin) {
396 $folders = isset($plugin['folders'])&&is_array($plugin['folders'])?$plugin['folders']:array();
397 $this->plugins[$key]['total_folders'] = count($folders);
398
399 $attachments = isset($plugin['attachments'])&&is_array($plugin['attachments'])?$plugin['attachments']:array();
400 $this->plugins[$key]['total_attachments'] = count($attachments);
401
402 if(count($folders) > 0 || count($attachments)>0) {
403 $this->plugins[$key]['is_exists'] = 1;
404 $this->is_exists = 1;
405 }
406 }
407 }
408
409 public function get_plugin_folders( $taxonomy, $slug ) {
410 global $wpdb;
411
412 // FileBird has its own db table
413 if ( $taxonomy === 'filebird' ) {
414 $filebird_folders_table = $wpdb->prefix . 'fbv';
415
416 // Get FileBird folders (order by 'parent' to create parent categories first)
417 if ( $wpdb->get_var( "SHOW TABLES LIKE '$filebird_folders_table'") == $filebird_folders_table ) {
418 return $wpdb->get_results( "SELECT * FROM $filebird_folders_table ORDER BY parent ASC" );
419 }
420 }
421
422 // Real Media Library has its own db table
423 else if ( $taxonomy === 'rml' ) {
424 $rml_folders_table = $wpdb->prefix . 'realmedialibrary';
425
426 // Get FileBird folders (order by 'parent' to create parent categories first)
427 if ( $wpdb->get_var( "SHOW TABLES LIKE '$rml_folders_table'") == $rml_folders_table ) {
428 return $wpdb->get_results( "SELECT * FROM $rml_folders_table ORDER BY parent ASC" );
429 }
430 }
431
432 // Default: Plugins with custom taxonomy terms
433 else {
434 $folders = $wpdb->get_results(
435 "SELECT * FROM " . $wpdb->term_taxonomy . "
436 LEFT JOIN " . $wpdb->terms . "
437 ON " . $wpdb->term_taxonomy . ".term_id = " . $wpdb->terms . ".term_id
438 WHERE " . $wpdb->term_taxonomy . ".taxonomy = '" . $taxonomy . "'
439 ORDER BY parent ASC"
440 );
441
442 // WP Media Folder (JoomUnited): Remove root folder
443 if ( $slug === 'wp-media-folder' ) {
444 foreach ( $folders as $index => $folder ) {
445 if ( $folder->slug === 'wp-media-folder-root' ) {
446 unset( $folders[$index] );
447 }
448 }
449 }
450
451 return array_values( $folders );
452 }
453 }
454
455 public function map_plugin_folders( $taxonomy, $folders ) {
456 $mapped_folders = [];
457
458 foreach ( $folders as $folder ) {
459
460 // FileBird, Real Media Library
461 if ( $taxonomy === 'filebird' || $taxonomy === 'rml' ) {
462 $folder_object = new \stdClass();
463
464 $folder_object->name = $folder->name;
465 $folder_object->id = intval( $folder->id );
466 $folder_object->parent = intval( $folder->parent );
467 $folder_object->position = intval( $folder->ord );
468
469 $mapped_folders[] = $folder_object;
470 }
471
472 }
473
474 return $mapped_folders;
475 }
476
477 public function map_plugin_attachments( $taxonomy, $attachments ) {
478 $mapped_attachments = [];
479
480 foreach ( $attachments as $folder ) {
481
482 // FileBird
483 if ( $taxonomy === 'filebird' ) {
484 $folder_object = new \stdClass();
485
486 $folder_object->folder_id = intval( $folder->folder_id );
487 $folder_object->attachment_id = intval( $folder->attachment_id );
488
489 $mapped_attachments[] = $folder_object;
490 }
491
492 // Real Media Library
493 if ( $taxonomy === 'rml' ) {
494 $folder_object = new \stdClass();
495
496 $folder_object->folder_id = intval( $folder->fid );
497 $folder_object->attachment_id = intval( $folder->attachment );
498
499 $mapped_attachments[] = $folder_object;
500 }
501
502 }
503
504 return $mapped_attachments;
505 }
506
507 public function get_plugin_attachments( $taxonomy, $folders ) {
508 global $wpdb;
509
510 // FileBird has its own db table
511 if ( $taxonomy === 'filebird' ) {
512 $filebird_attachments_table = $wpdb->prefix . 'fbv_attachment_folder';
513
514 // Get FileBird attachments (order by 'folder_id')
515 if ( $wpdb->get_var( "SHOW TABLES LIKE '$filebird_attachments_table'") == $filebird_attachments_table ) {
516 return $wpdb->get_results( "SELECT * FROM $filebird_attachments_table ORDER BY folder_id ASC" );
517 }
518 }
519
520 // Real Media Library has its own db table
521 else if ( $taxonomy === 'rml' ) {
522 $rml_attachments_table = $wpdb->prefix . 'realmedialibrary_posts';
523
524 // Get FileBird folders (order by 'parent' to create parent categories first)
525 if ( $wpdb->get_var( "SHOW TABLES LIKE '$rml_attachments_table'") == $rml_attachments_table ) {
526 return $wpdb->get_results( "SELECT * FROM $rml_attachments_table ORDER BY fid ASC" );
527 }
528 }
529
530 // Default: Plugins with custom taxonomy terms
531 else {
532 return $wpdb->get_results(
533 "SELECT " . $wpdb->term_relationships . ".object_id,
534 " . $wpdb->term_relationships . ".term_taxonomy_id
535 FROM " . $wpdb->term_relationships . "
536 WHERE " . $wpdb->term_relationships . ".term_taxonomy_id IN (" . implode( ',', array_column( $folders, 'term_id' ) ) . ")"
537 );
538 }
539 }
540 }
541 $WCP_Folder_Plugins = new WCP_Folder_Plugins();