PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.9.4
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.9.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 / class-wpml.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 3 years ago tree.class.php 2 years ago
class-wpml.php
286 lines
1 <?php
2 /**
3 * Class Folders WPML
4 *
5 * @author : Premio <contact@premio.io>
6 * @license : GPL2
7 * */
8
9 if (! defined('ABSPATH')) {
10 exit;
11 }
12
13 class WCP_Folder_WPML
14 {
15
16 /**
17 * The Name of this plugin.
18 *
19 * @var string $isWPMLActive The Name of this plugin.
20 * @since 1.0.0
21 * @access private
22 */
23 private $isWPMLActive;
24
25 /**
26 * The Name of this plugin.
27 *
28 * @var string $total Total number of taxonomies
29 * @since 1.0.0
30 * @access private
31 */
32 private $total;
33
34 /**
35 * The Name of this plugin.
36 *
37 * @var string $lang Current Selected language
38 * @since 1.0.0
39 * @access private
40 */
41 private $lang;
42
43 /**
44 * The Name of this plugin.
45 *
46 * @var string $tableIclTranslations WPML translation table
47 * @since 1.0.0
48 * @access private
49 */
50 private $tableIclTranslations;
51
52 /**
53 * The Name of this plugin.
54 *
55 * @var string $tableIclTranslations WPML translated post
56 * @since 1.0.0
57 * @access protected
58 */
59 protected $post_translations;
60
61 /**
62 * The Name of this plugin.
63 *
64 * @var string $sitepress sitepress
65 * @since 1.0.0
66 * @access protected
67 */
68 private $sitepress;
69
70 /**
71 * The Name of this plugin.
72 *
73 * @var string $sitepress WPML Settings
74 * @since 1.0.0
75 * @access protected
76 */
77 private $settings;
78
79
80 /**
81 * Define the core functionality of the plugin.
82 *
83 * Set the WPML installation status and settings.
84 * Load the dependencies, define the locale, and set the hooks for the admin area and
85 * the public-facing side of the site.
86 *
87 * @since 1.0.0
88 */
89 public function __construct()
90 {
91 $this->isWPMLActive = false;
92 $this->total = 0;
93 add_action("admin_init", [$this, 'init']);
94
95 }//end __construct()
96
97
98 /**
99 * Check for the WPML settings and status
100 *
101 * @since 1.0.0
102 * @access public
103 * @return $isWPMLActive
104 */
105 public function init()
106 {
107 global $sitepress, $wpdb;
108 $isWPMLActive = $sitepress !== null && get_class($sitepress) === "SitePress";
109
110 if ($isWPMLActive) {
111 $settings = $sitepress->get_setting('custom_posts_sync_option', []);
112 if ($sitepress->get_current_language() !== 'all') {
113 $this->isWPMLActive = true;
114 $this->settings = $settings;
115 $this->lang = $sitepress->get_current_language();
116 $this->tableIclTranslations = $wpdb->prefix.'icl_translations';
117 }
118
119 $this->sitepress = $sitepress;
120 $this->post_translations = $sitepress->post_translations();
121 }
122
123 if ($this->isWPMLActive) {
124 add_filter('premio_folder_item_in_taxonomy', [$this, 'items_in_taxonomy'], 10, 2);
125 add_filter('premio_folder_un_categorized_items', [$this, 'un_categorized_items'], 10, 2);
126 add_filter('premio_folder_all_categorized_items', [$this, 'all_categorized_items'], 10, 2);
127 }
128
129 }//end init()
130
131
132 /**
133 * Get the total taxonomies used in WPML
134 *
135 * @since 1.0.0
136 * @access public
137 * @return $total
138 */
139 public function set_total($post_type)
140 {
141 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
142 global $wpdb;
143 $select = "SELECT COUNT(DISTINCT(P.id))
144 FROM {$this->tableIclTranslations} AS wpmlt
145 INNER JOIN {$wpdb->posts} AS P ON P.id = wpmlt.element_id";
146 $where = ["wpmlt.element_type = 'post_".esc_attr($post_type)."'"];
147 $where[] = "wpmlt.language_code = '%s'";
148 if ($post_type == 'attachment') {
149 $where[] = " (P.post_status = 'inherit' OR P.post_status = 'private')";
150 } else {
151 $where[] = " P.post_status != 'trash'";
152 }
153
154 $join = apply_filters( 'folders_count_join_query', "" );
155 $where = apply_filters( 'folders_count_where_query', $where );
156
157 $query = $select . $join . " WHERE ".implode( ' AND ', $where );
158
159 $query = $wpdb->prepare($query, [$this->lang]);
160 $this->total = (int) $wpdb->get_var($query);
161 }
162
163 }//end set_total()
164
165
166 /**
167 * To get the items in taxonomies
168 *
169 * @since 1.0.0
170 * @access public
171 * @return $total
172 */
173 public function items_in_taxonomy($term_id, $arg=[])
174 {
175 $post_type = isset($arg['post_type']) ? $arg['post_type'] : "";
176 $taxonomy = isset($arg['taxonomy']) ? $arg['taxonomy'] : "";
177 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
178 global $wpdb;
179 $term_taxonomy_id = get_term_by('id', (int) $term_id, $taxonomy, OBJECT)->term_taxonomy_id;
180 $query = "SELECT count(wpmlt.element_id) as total_records FROM {$this->tableIclTranslations} AS wpmlt
181 INNER JOIN {$wpdb->term_relationships} AS term_rela ON term_rela.object_id = wpmlt.element_id
182 WHERE wpmlt.element_type = 'post_".esc_attr($post_type)."'
183 AND term_rela.term_taxonomy_id = '%s'
184 AND wpmlt.language_code = '%s'";
185
186 $query = $wpdb->prepare($query, [$term_taxonomy_id, $this->lang]);
187 $all_ids = $wpdb->get_var($query);
188 // $counter = 0;
189 // if (count($all_ids) > 0) {
190 // $select = "SELECT COUNT(P.ID) as total_records FROM {$wpdb->posts} AS P";
191 // $where = ["P.ID = (%s)"];
192 //
193 // if($post_type == 'attachment') {
194 // $where[] = " (P.post_status = 'inherit' OR P.post_status = 'private')";
195 // } else {
196 // $where[] = " P.post_status != 'trash'";
197 // }
198 //
199 // $join = apply_filters( 'folders_count_join_query', "" );
200 // $where = apply_filters( 'folders_count_where_query', $where );
201 //
202 // $query = $select . $join . " WHERE ".implode( ' AND ', $where );
203 //// $query = $wpdb->prepare($query, [implode(',', $all_ids)]);
204 //// $counter = $wpdb->get_var($query);
205 // }
206
207 return !empty($all_ids) ? $all_ids : 0;
208 }//end if
209
210 return null;
211
212 }//end items_in_taxonomy()
213
214
215 /**
216 * To get the items in taxonomies in uncategorized
217 *
218 * @since 1.0.0
219 * @access public
220 * @return $total
221 */
222 public function un_categorized_items($post_type, $taxonomy)
223 {
224
225 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
226 global $wpdb;
227 $subQuery = "SELECT * FROM {$this->tableIclTranslations} as wpmlt
228 INNER JOIN {$wpdb->posts} as p on p.id = wpmlt.element_id
229 WHERE wpmlt.element_type = 'post_".esc_attr($post_type)."'
230 and wpmlt.language_code = '%s'";
231 $select = "SELECT COUNT(DISTINCT(tmp_table.ID))
232 FROM ({$subQuery}) as tmp_table";
233 $join = " JOIN {$wpdb->term_relationships} as term_relationships on tmp_table.element_id = term_relationships.object_id ";
234 $join .= " JOIN {$wpdb->term_taxonomy} as term_taxonomy on term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id ";
235 $where = ["taxonomy = '%s'"];
236
237 if ( $this->sitepress->is_translated_taxonomy( $taxonomy ) ) {
238 $icl_taxonomies = "tax_" . $taxonomy;
239 $join .= " LEFT JOIN {$wpdb->prefix}icl_translations AS icl_t
240 ON icl_t.element_id = term_taxonomy.term_taxonomy_id
241 AND icl_t.element_type = '{$icl_taxonomies}'";
242
243 $where[] = " ( ( icl_t.element_type = '{$icl_taxonomies}' AND icl_t.language_code = '{$this->lang}' )
244 OR icl_t.element_type != '{$icl_taxonomies}' OR icl_t.element_type IS NULL ) ";
245 }
246
247 $query = $select . $join . " WHERE ".implode( ' AND ', $where );
248
249 $query = $wpdb->prepare($query, [$this->lang, $taxonomy]);
250 $fileInFolder = (int) $wpdb->get_var($query);
251
252 $this->set_total($post_type);
253
254 return ($this->total - $fileInFolder);
255 }
256
257 return null;
258
259 }//end un_categorized_items()
260
261
262 /**
263 * To get the items in taxonomies in all categories
264 *
265 * @since 1.0.0
266 * @access public
267 * @return $total
268 */
269 public function all_categorized_items($post_type)
270 {
271 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
272 $this->set_total($post_type);
273 return $this->total;
274 }
275
276 return null;
277
278 }//end all_categorized_items()
279
280
281 }//end class
282
283 if (class_exists('WCP_Folder_WPML')) {
284 $folder_WPML = new WCP_Folder_WPML();
285 }
286