PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.6.4
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.6.4
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 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
plugins.class.php
529 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 checkForLimit($folders) {
82 $response = array();
83 $response['status'] = 0;
84 $response['message'] = esc_html__("Invalid request", "folders");
85 $response['data'] = array();
86 $response['data']['plugin'] = array();
87 if($folders >= 10) {
88 $response['status'] = -1;
89 echo json_encode($response);
90 exit;
91 }
92 }
93
94 public function import_plugin_folders_data() {
95 $postData = filter_input_array(INPUT_POST);
96
97 $plugin = isset($postData['plugin']) ?$postData['plugin']:"";
98 $nonce = isset($postData['nonce']) ?$postData['nonce']:"";
99 $response = array();
100 $response['status'] = 0;
101 $response['message'] = esc_html__("Invalid request", "folders");
102 $response['data'] = array();
103 $response['data']['plugin'] = $plugin;
104 if(wp_verify_nonce($nonce, "import_data_from_".$plugin)) {
105 $this->get_plugin_information();
106 $folders = isset($this->plugins[$plugin]['folders']) ? $this->plugins[$plugin]['folders'] : array();
107 $attachments = isset($this->plugins[$plugin]['attachments']) ? $this->plugins[$plugin]['attachments'] : array();
108
109 $categoryByID = array();
110 $foldersImported = array();
111 $attachmentsImported = array();
112
113 $total_folders = WCP_Folders::get_ttl_fldrs();
114
115 $this->checkForLimit($total_folders);
116
117 if($plugin != 'filebird' && $plugin != 'real-media-library') {
118
119 foreach ($folders as $folder) {
120 $folder_id = $folder->term_id;
121 $parent = intval($folder->parent);
122
123 $taxonomy = 'media_folder';
124
125 foreach ($this->post_types as $post_type) {
126 if (strpos($folder->taxonomy, $post_type) !== false) {
127 if ($post_type == "post") {
128 $taxonomy = "post_folder";
129 } else if ($post_type == "page") {
130 $taxonomy = "folder";
131 } else if ($post_type == "attachment") {
132 $taxonomy = "media_folder";
133 } else {
134 $taxonomy = $post_type . '_folder';
135 }
136 }
137 }
138
139 if ($parent && isset($categoryByID[$parent]['term_id'])) {
140 $parent = intval($categoryByID[$parent]['term_id']);
141 }
142
143 $new_term = wp_insert_term($folder->name, $taxonomy, ['parent' => $parent]);
144
145 if (is_wp_error($new_term)) {
146 continue;
147 }
148
149 $total_folders++;
150 $this->checkForLimit($total_folders);
151
152 $arg = array(
153 'hide_empty' => false,
154 'parent' => $parent,
155 'hierarchical' => false,
156 'update_count_callback' => '_update_generic_term_count',
157 );
158 $terms = get_terms( $taxonomy, $arg);
159 $position = count($terms);
160
161 update_term_meta($new_term['term_id'], 'wcp_custom_order', $position);
162
163 $foldersImported[] = $new_term;
164
165 $categoryByID[$folder_id] = [
166 'term_id' => $new_term['term_id'],
167 'parent' => $parent,
168 'name' => $folder->name,
169 ];
170 }
171
172 // STEP: Assign plugin categories to HF categories
173 foreach ($attachments as $attachment) {
174 $hf_category_id = isset($categoryByID[$attachment->term_taxonomy_id]['term_id']) ? intval($categoryByID[$attachment->term_taxonomy_id]['term_id']) : 0;
175 $attachment_id = isset($attachment->object_id) ? intval($attachment->object_id) : 0;
176
177 if (!$hf_category_id || !$attachment_id) {
178 continue;
179 }
180
181 // Get attachment taxonomy by post type
182 $post_type = get_post_type($attachment_id);
183 if ($post_type == "post") {
184 $taxonomy = "post_folder";
185 } else if ($post_type == "page") {
186 $taxonomy = "folder";
187 } else if ($post_type == "attachment") {
188 $taxonomy = "media_folder";
189 } else {
190 $taxonomy = $post_type . '_folder';
191 }
192
193 $term_ids = wp_get_object_terms($attachment_id, $taxonomy, ['fields' => 'ids']);
194 $term_ids[] = $hf_category_id;
195
196 $term_set = wp_set_object_terms($attachment_id, $term_ids, $taxonomy);
197
198 if (is_wp_error($term_set)) {
199 continue;
200 }
201
202 $attachmentsImported[] = [
203 'cat_id' => $hf_category_id,
204 'term_ids' => $term_ids,
205 'set' => $term_set,
206 ];
207 }
208 } else {
209 foreach ( $folders as $folder ) {
210 $parent = intval( $folder->parent );
211 $parentID = 0;
212
213 if ( $parent && isset( $categoryByID[$parent]['term_id'] ) ) {
214 $parentID = $categoryByID[$parent]['term_id'];
215 }
216
217 $new_term = wp_insert_term( $folder->name, "media_folder", ['parent' => $parentID] );
218
219 if ( is_wp_error( $new_term ) ) {
220 continue;
221 }
222
223 $total_folders++;
224 $this->checkForLimit($total_folders);
225
226 $taxonomy = 'media_folder';
227
228 $arg = array(
229 'hide_empty' => false,
230 'parent' => $parentID,
231 'hierarchical' => false,
232 'update_count_callback' => '_update_generic_term_count',
233 );
234 $terms = get_terms( $taxonomy, $arg);
235 $position = count($terms);
236
237
238 update_term_meta( $new_term['term_id'], 'wcp_custom_order', intval( $position ) );
239
240 $foldersImported[] = $new_term;
241
242 $categoryByID[$folder->id] = [
243 'name' => $folder->name,
244 'parent' => $parent,
245 'term_id' => $new_term['term_id'],
246 ];
247 }
248
249 foreach ( $attachments as $attachment ) {
250 $hf_category_id = isset( $categoryByID[$attachment->folder_id]['term_id'] ) ? intval( $categoryByID[$attachment->folder_id]['term_id'] ) : 0;
251 $attachment_id = isset( $attachment->attachment_id ) ? intval( $attachment->attachment_id ) : 0;
252
253 if ( ! $hf_category_id || ! $attachment_id ) {
254 continue;
255 }
256
257 $term_ids = wp_get_object_terms( $attachment_id, "media_folder", ['fields' => 'ids'] );
258 $term_ids[] = $hf_category_id;
259
260 $term_set = wp_set_object_terms( $attachment_id, $term_ids, "media_folder" );
261
262 if ( is_wp_error( $term_set ) ) {
263 continue;
264 }
265
266 $attachmentsImported[] = [
267 'cat_id' => $hf_category_id,
268 'term_ids' => $term_ids,
269 'set' => $term_set,
270 ];
271 }
272 }
273
274 $response['status'] = 1;
275 $response['data']['imported'] = count($foldersImported);
276 $response['data']['attachments'] = count($attachmentsImported);
277 $response['data']['plugin'] = $plugin;
278 $response['message'] = sprintf(esc_html__( '%s folders imported and %s attachments categorized.', 'folders'), count($foldersImported), count($attachmentsImported));
279 }
280 echo json_encode($response);
281 exit;
282 }
283
284 public function get_plugin_information() {
285 $this->get_other_plugins_data();
286 return $this->plugins;
287 }
288
289 public function get_other_plugins_data() {
290 if(!empty($this->plugins)) {
291 return $this->plugins;
292 }
293 $this->plugins = array(
294 // FileBird
295 'filebird' => array(
296 'name' => 'FileBird (v4)',
297 'taxonomy' => 'filebird', // has custom DB table
298 'folders' => array(),
299 'attachments' => array(),
300 'total_folders' => 0,
301 'total_attachments' => 0,
302 'is_exists' => 0
303 ),
304 'enhanced-media-library' => array(
305 // Enhanced Media Library
306 'name' => 'Enhanced Media Library',
307 'taxonomy' => 'media_category',
308 'folders' => array(),
309 'attachments' => array(),
310 'total_folders' => 0,
311 'total_attachments' => 0,
312 'is_exists' => 0
313 ),
314 'wicked-folders' => array(
315 // Enhanced Media Library
316 'name' => 'Wicked Folders',
317 'taxonomy' => 'wf_attachment_folders',
318 'folders' => array(),
319 'attachments' => array(),
320 'total_folders' => 0,
321 'total_attachments' => 0,
322 'is_exists' => 0
323 ),
324 'real-media-library' => array(
325 // Real Media Library
326 'name' => 'Real Media Library (by DevOwl)',
327 'taxonomy' => 'rml', // has custom DB table
328 'folders' => array(),
329 'attachments' => array(),
330 'total_folders' => 0,
331 'total_attachments' => 0,
332 'is_exists' => 0
333 ),
334 'wp-media-folder' => array(
335 // Real Media Library
336 'name' => 'WP Media Folder (by JoomUnited)',
337 'taxonomy' => 'wpmf-category',
338 'folders' => array(),
339 'attachments' => array(),
340 'total_folders' => 0,
341 'total_attachments' => 0,
342 'is_exists' => 0
343 )
344 );
345 $post_types = get_post_types(array());
346 $this->post_types = array_keys($post_types);
347
348 foreach ($this->plugins as $slug => $plugin_data ) {
349 $taxonomy = $plugin_data['taxonomy'];
350
351 if ( $slug === 'wicked-folders' ) {
352 // Run for all registered post types
353 $folders = [];
354
355 foreach ( $this->post_types as $post_type ) {
356 $wicked_folders = $this->get_plugin_folders( 'wf_' . $post_type . '_folders', $slug );
357
358 if ( is_array( $wicked_folders ) ) {
359 $folders = array_merge( $folders, $wicked_folders );
360 }
361 }
362 }
363
364 else {
365 $folders = $this->get_plugin_folders( $taxonomy, $slug );
366 }
367
368 if ( in_array( $taxonomy, ['filebird', 'rml'] ) ) {
369 $folders = is_array( $folders ) && count( $folders ) ? $this->map_plugin_folders( $taxonomy, $folders ) : [];
370 }
371
372 $this->plugins[$slug]['folders'] = $folders;
373
374 $attachments = is_array( $folders ) && count( $folders ) ? $this->get_plugin_attachments( $taxonomy, $folders ) : [];
375
376 if ( in_array( $taxonomy, ['filebird', 'rml'] ) ) {
377 $attachments = $this->map_plugin_attachments( $taxonomy, $attachments );
378 }
379
380 $this->plugins[$slug]['attachments'] = $attachments;
381 }
382
383 foreach ($this->plugins as $key=>$plugin) {
384 $folders = isset($plugin['folders'])&&is_array($plugin['folders'])?$plugin['folders']:array();
385 $this->plugins[$key]['total_folders'] = count($folders);
386
387 $attachments = isset($plugin['attachments'])&&is_array($plugin['attachments'])?$plugin['attachments']:array();
388 $this->plugins[$key]['total_attachments'] = count($attachments);
389
390 if(count($folders) > 0 || count($attachments)>0) {
391 $this->plugins[$key]['is_exists'] = 1;
392 $this->is_exists = 1;
393 }
394 }
395 }
396
397 public function get_plugin_folders( $taxonomy, $slug ) {
398 global $wpdb;
399
400 // FileBird has its own db table
401 if ( $taxonomy === 'filebird' ) {
402 $filebird_folders_table = $wpdb->prefix . 'fbv';
403
404 // Get FileBird folders (order by 'parent' to create parent categories first)
405 if ( $wpdb->get_var( "SHOW TABLES LIKE '$filebird_folders_table'") == $filebird_folders_table ) {
406 return $wpdb->get_results( "SELECT * FROM $filebird_folders_table ORDER BY parent ASC" );
407 }
408 }
409
410 // Real Media Library has its own db table
411 else if ( $taxonomy === 'rml' ) {
412 $rml_folders_table = $wpdb->prefix . 'realmedialibrary';
413
414 // Get FileBird folders (order by 'parent' to create parent categories first)
415 if ( $wpdb->get_var( "SHOW TABLES LIKE '$rml_folders_table'") == $rml_folders_table ) {
416 return $wpdb->get_results( "SELECT * FROM $rml_folders_table ORDER BY parent ASC" );
417 }
418 }
419
420 // Default: Plugins with custom taxonomy terms
421 else {
422 $folders = $wpdb->get_results(
423 "SELECT * FROM " . $wpdb->term_taxonomy . "
424 LEFT JOIN " . $wpdb->terms . "
425 ON " . $wpdb->term_taxonomy . ".term_id = " . $wpdb->terms . ".term_id
426 WHERE " . $wpdb->term_taxonomy . ".taxonomy = '" . $taxonomy . "'
427 ORDER BY parent ASC"
428 );
429
430 // WP Media Folder (JoomUnited): Remove root folder
431 if ( $slug === 'wp-media-folder' ) {
432 foreach ( $folders as $index => $folder ) {
433 if ( $folder->slug === 'wp-media-folder-root' ) {
434 unset( $folders[$index] );
435 }
436 }
437 }
438
439 return array_values( $folders );
440 }
441 }
442
443 public function map_plugin_folders( $taxonomy, $folders ) {
444 $mapped_folders = [];
445
446 foreach ( $folders as $folder ) {
447
448 // FileBird, Real Media Library
449 if ( $taxonomy === 'filebird' || $taxonomy === 'rml' ) {
450 $folder_object = new \stdClass();
451
452 $folder_object->name = $folder->name;
453 $folder_object->id = intval( $folder->id );
454 $folder_object->parent = intval( $folder->parent );
455 $folder_object->position = intval( $folder->ord );
456
457 $mapped_folders[] = $folder_object;
458 }
459
460 }
461
462 return $mapped_folders;
463 }
464
465 public function map_plugin_attachments( $taxonomy, $attachments ) {
466 $mapped_attachments = [];
467
468 foreach ( $attachments as $folder ) {
469
470 // FileBird
471 if ( $taxonomy === 'filebird' ) {
472 $folder_object = new \stdClass();
473
474 $folder_object->folder_id = intval( $folder->folder_id );
475 $folder_object->attachment_id = intval( $folder->attachment_id );
476
477 $mapped_attachments[] = $folder_object;
478 }
479
480 // Real Media Library
481 if ( $taxonomy === 'rml' ) {
482 $folder_object = new \stdClass();
483
484 $folder_object->folder_id = intval( $folder->fid );
485 $folder_object->attachment_id = intval( $folder->attachment );
486
487 $mapped_attachments[] = $folder_object;
488 }
489
490 }
491
492 return $mapped_attachments;
493 }
494
495 public function get_plugin_attachments( $taxonomy, $folders ) {
496 global $wpdb;
497
498 // FileBird has its own db table
499 if ( $taxonomy === 'filebird' ) {
500 $filebird_attachments_table = $wpdb->prefix . 'fbv_attachment_folder';
501
502 // Get FileBird attachments (order by 'folder_id')
503 if ( $wpdb->get_var( "SHOW TABLES LIKE '$filebird_attachments_table'") == $filebird_attachments_table ) {
504 return $wpdb->get_results( "SELECT * FROM $filebird_attachments_table ORDER BY folder_id ASC" );
505 }
506 }
507
508 // Real Media Library has its own db table
509 else if ( $taxonomy === 'rml' ) {
510 $rml_attachments_table = $wpdb->prefix . 'realmedialibrary_posts';
511
512 // Get FileBird folders (order by 'parent' to create parent categories first)
513 if ( $wpdb->get_var( "SHOW TABLES LIKE '$rml_attachments_table'") == $rml_attachments_table ) {
514 return $wpdb->get_results( "SELECT * FROM $rml_attachments_table ORDER BY fid ASC" );
515 }
516 }
517
518 // Default: Plugins with custom taxonomy terms
519 else {
520 return $wpdb->get_results(
521 "SELECT " . $wpdb->term_relationships . ".object_id,
522 " . $wpdb->term_relationships . ".term_taxonomy_id
523 FROM " . $wpdb->term_relationships . "
524 WHERE " . $wpdb->term_relationships . ".term_taxonomy_id IN (" . implode( ',', array_column( $folders, 'term_id' ) ) . ")"
525 );
526 }
527 }
528 }
529 $WCP_Folder_Plugins = new WCP_Folder_Plugins();