PluginProbe
FileBird – WordPress Media Library Folders & File Manager / 5.6
FileBird – WordPress Media Library Folders & File Manager v5.6
6.5.8 6.5.7 6.5.5 6.5.4 trunk 4.3.1 5.1.6 5.3 5.3.2 5.4.3 5.4.4 5.4.5 5.5 5.5.3 5.5.5 5.5.8 5.5.8.1 5.6 5.6.1 5.6.2 5.6.3 5.6.4 6.2.3 6.2.5 6.3 All 36 releases
filebird / includes / Classes / Helpers.php

Helpers.php in FileBird – WordPress Media Library Folders & File Manager 5.6, at includes/Classes/Helpers.php

212 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace FileBird\Classes;
3
4 defined( 'ABSPATH' ) || exit;
5
6 use FileBird\Model\Folder as FolderModel;
7
8 class Helpers {
9 protected static $instance = null;
10
11 public static function getInstance() {
12 if ( null == self::$instance ) {
13 self::$instance = new self();
14 }
15 return self::$instance;
16 }
17
18 public static function foldersFromEnhanced( $parent = 0, $flat = false ) {
19 global $wpdb;
20 $folders = $wpdb->get_results( $wpdb->prepare( 'SELECT t.term_id as id, t.name as title, tt.term_taxonomy_id FROM %1$s as t INNER JOIN %2$s as tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy = \'media_category\' AND tt.parent = %3$d', $wpdb->terms, $wpdb->term_taxonomy, $parent ) );
21 foreach ( $folders as $k => $folder ) {
22 $folders[ $k ]->parent = $parent;
23 }
24 if ( $flat ) {
25 foreach ( $folders as $k => $folder ) {
26 $children = self::foldersFromEnhanced( $folder->id, $flat );
27 foreach ( $children as $k2 => $v2 ) {
28 $folders[] = $v2;
29 }
30 }
31 } else {
32 foreach ( $folders as $k => $folder ) {
33 $folders[ $k ]->children = self::foldersFromEnhanced( $folder->id, $flat );
34 }
35 }
36 return $folders;
37 }
38 public static function foldersFromWpmlf( $parent = 0, $flat = false ) {
39 global $wpdb;
40 $table_name = $wpdb->prefix . 'mgmlp_folders';
41 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
42 if ( ! $wpdb->get_var( $query ) == $table_name ) {
43 return array();
44 }
45
46 $folders = $wpdb->get_results( $wpdb->prepare( 'select p.ID as id, p.post_title as title, mlf.folder_id as parent from %1$s as p LEFT JOIN %2$s as mlf ON(p.ID = mlf.post_id) where p.post_type = \'mgmlp_media_folder\' and mlf.folder_id = \'%3$s\' order by mlf.folder_id', $wpdb->posts, $wpdb->prefix . 'mgmlp_folders', $parent ) );
47
48 if ( $flat ) {
49 foreach ( $folders as $k => $folder ) {
50 $children = self::foldersFromWpmlf( $folder->id, $flat );
51 foreach ( $children as $k2 => $v2 ) {
52 $folders[] = $v2;
53 }
54 }
55 } else {
56 foreach ( $folders as $k => $folder ) {
57 $folders[ $k ]->children = self::foldersFromWpmlf( $folder->id, $flat );
58 }
59 }
60 return $folders;
61 }
62 public static function foldersFromWpfeml( $parent = 0, $flat = false ) {
63 global $wpdb;
64 $folders = $wpdb->get_results( $wpdb->prepare( "SELECT t.term_id as id, t.name as title, tt.term_taxonomy_id FROM $wpdb->terms as t INNER JOIN $wpdb->term_taxonomy as tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy = 'feml-folder' AND tt.parent = %d", $parent ) );
65 foreach ( $folders as $k => $folder ) {
66 $folders[ $k ]->parent = $parent;
67 }
68 if ( $flat ) {
69 foreach ( $folders as $k => $folder ) {
70 $children = self::foldersFromWpfeml( $folder->id, $flat );
71 foreach ( $children as $k2 => $v2 ) {
72 $folders[] = $v2;
73 }
74 }
75 } else {
76 foreach ( $folders as $k => $folder ) {
77 $folders[ $k ]->children = self::foldersFromWpfeml( $folder->id, $flat );
78 }
79 }
80 return $folders;
81 }
82 public static function foldersFromWpmf( $parent = 0, $flat = false ) {
83 global $wpdb;
84 $folders = $wpdb->get_results( $wpdb->prepare( 'SELECT t.term_id as id, t.name as title, tt.term_taxonomy_id FROM %1$s as t INNER JOIN %2$s as tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy = \'wpmf-category\' AND tt.parent = %3$d', $wpdb->terms, $wpdb->term_taxonomy, $parent ) );
85 foreach ( $folders as $k => $folder ) {
86 $folders[ $k ]->parent = $parent;
87 }
88 if ( $flat ) {
89 foreach ( $folders as $k => $folder ) {
90 $children = self::foldersFromWpmf( $folder->id, $flat );
91 foreach ( $children as $k2 => $v2 ) {
92 $folders[] = $v2;
93 }
94 }
95 } else {
96 foreach ( $folders as $k => $folder ) {
97 $folders[ $k ]->children = self::foldersFromWpmf( $folder->id, $flat );
98 }
99 }
100 return $folders;
101 }
102 public static function foldersFromRealMedia( $parent = 0, $flat = false ) {
103 global $wpdb;
104 $table_name = $wpdb->prefix . 'realmedialibrary';
105 $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) );
106 if ( ! $wpdb->get_var( $query ) == $table_name ) {
107 return array();
108 }
109
110 $folders = $wpdb->get_results( $wpdb->prepare( 'select r.id as id, r.name as title, r.parent as parent from %1$s as r where r.parent = %2$d order by r.ord', $table_name, $parent ) );
111
112 if ( $flat ) {
113 foreach ( $folders as $k => $folder ) {
114 $children = self::foldersFromRealMedia( $folder->id, $flat );
115 foreach ( $children as $k2 => $v2 ) {
116 $folders[] = $v2;
117 }
118 }
119 } else {
120 foreach ( $folders as $k => $folder ) {
121 $folders[ $k ]->children = self::foldersFromRealMedia( $folder->id, $flat );
122 }
123 }
124 return $folders;
125 }
126 public static function foldersFromHappyFiles( $parent = 0, $flat = false ) {
127 global $wpdb;
128 $folders = $wpdb->get_results( $wpdb->prepare( 'SELECT t.term_id as id, t.name as title, tt.term_taxonomy_id FROM %1$s as t INNER JOIN %2$s as tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy = \'happyfiles_category\' AND tt.parent = %3$d', $wpdb->terms, $wpdb->term_taxonomy, $parent ) );
129 foreach ( $folders as $k => $folder ) {
130 $folders[ $k ]->parent = $parent;
131 }
132 if ( $flat ) {
133 foreach ( $folders as $k => $folder ) {
134 $children = self::foldersFromHappyFiles( $folder->id, $flat );
135 foreach ( $children as $k2 => $v2 ) {
136 $folders[] = $v2;
137 }
138 }
139 } else {
140 foreach ( $folders as $k => $folder ) {
141 $folders[ $k ]->children = self::foldersFromHappyFiles( $folder->id, $flat );
142 }
143 }
144 return $folders;
145 }
146 public static function foldersFromPremio( $parent = 0, $flat = false ) {
147 global $wpdb;
148 $folders = $wpdb->get_results( $wpdb->prepare( 'SELECT t.term_id as id, t.name as title, tt.term_taxonomy_id FROM %1$s as t INNER JOIN %2$s as tt ON (t.term_id = tt.term_id) WHERE tt.taxonomy = \'media_folder\' AND tt.parent = %3$d', $wpdb->terms, $wpdb->term_taxonomy, $parent ) );
149 foreach ( $folders as $k => $folder ) {
150 $folders[ $k ]->parent = $parent;
151 }
152 if ( $flat ) {
153 foreach ( $folders as $k => $folder ) {
154 $children = self::foldersFromPremio( $folder->id, $flat );
155 foreach ( $children as $k2 => $v2 ) {
156 $folders[] = $v2;
157 }
158 }
159 } else {
160 foreach ( $folders as $k => $folder ) {
161 $folders[ $k ]->children = self::foldersFromPremio( $folder->id, $flat );
162 }
163 }
164 return $folders;
165 }
166 public static function sanitize_array( $var ) {
167 if ( is_array( $var ) ) {
168 return array_map( 'self::sanitize_array', $var );
169 } else {
170 return is_scalar( $var ) ? sanitize_text_field( $var ) : $var;
171 }
172 }
173 public static function getAttachmentIdsByFolderId( $folder_id ) {
174 global $wpdb;
175 return $wpdb->get_col( 'SELECT `attachment_id` FROM ' . $wpdb->prefix . 'fbv_attachment_folder WHERE `folder_id` = ' . (int) $folder_id );
176 }
177
178 public static function getAttachmentCountByFolderId( $folder_id ) {
179 return Tree::getCount( $folder_id );
180 }
181
182 public static function view( $path, $data = array() ) {
183 extract( $data );
184 ob_start();
185 include_once NJFB_PLUGIN_PATH . 'views/' . $path . '.php';
186 return ob_get_clean();
187 }
188
189 public static function isListMode() {
190 if ( function_exists( 'get_current_screen' ) ) {
191 $screen = get_current_screen();
192 return ( isset( $screen->id ) && 'upload' == $screen->id );
193 }
194 return false;
195 }
196
197 public static function findFolder( $folder_id, $tree ) {
198 foreach ( $tree as $k => $v ) {
199 if ( $v['id'] == $folder_id ) {
200 return $v;
201 }
202 if ( isset( $v['children'] ) ) {
203 $folder = self::findFolder( $folder_id, $v['children'] );
204 if ( $folder ) {
205 return $folder;
206 }
207 }
208 }
209 return null;
210 }
211 }
212