PluginProbe ʕ •ᴥ•ʔ
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager / 2.8.9
Folders – Unlimited Folders to Organize Media Library Folder, Pages, Posts, File Manager v2.8.9
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 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 plugins.class.php 3 years ago tree.class.php 3 years ago
class-wpml.php
260 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 $query = "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 AND wpmlt.language_code = '%s'";
148 if ($post_type == 'attachment') {
149 $query .= " AND (p.post_status = 'inherit' OR p.post_status = 'private')";
150 } else {
151 $query .= " AND p.post_status != 'trash'";
152 }
153
154 $query = $wpdb->prepare($query, [$this->lang]);
155 $this->total = (int) $wpdb->get_var($query);
156 }
157
158 }//end set_total()
159
160
161 /**
162 * To get the items in taxonomies
163 *
164 * @since 1.0.0
165 * @access public
166 * @return $total
167 */
168 public function items_in_taxonomy($term_id, $arg=[])
169 {
170 $post_type = isset($arg['post_type']) ? $arg['post_type'] : "";
171 $taxonomy = isset($arg['taxonomy']) ? $arg['taxonomy'] : "";
172 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
173 global $wpdb;
174 $term_taxonomy_id = get_term_by('id', (int) $term_id, $taxonomy, OBJECT)->term_taxonomy_id;
175 $query = "SELECT wpmlt.element_id FROM {$this->tableIclTranslations} AS wpmlt
176 INNER JOIN {$wpdb->term_relationships} AS term_rela ON term_rela.object_id = wpmlt.element_id
177 WHERE wpmlt.element_type = 'post_".esc_attr($post_type)."'
178 AND term_rela.term_taxonomy_id = '%s'
179 AND wpmlt.language_code = '%s'";
180 $query = $wpdb->prepare($query, [$term_taxonomy_id, $this->lang]);
181 $all_ids = $wpdb->get_col($query);
182 $counter = 0;
183 if (count($all_ids) > 0) {
184 if ($post_type == 'attachment') {
185 $query = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `ID` IN (%s) AND (post_status = 'inherit' OR post_status = 'private')";
186 $query = $wpdb->prepare($query, [implode(',', $all_ids)]);
187 $counter = $wpdb->get_var($query);
188 } else {
189 $query = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE `ID` IN (%s) AND post_status != 'trash'";
190 $query = $wpdb->prepare($query, [implode(',', $all_ids)]);
191 $counter = $wpdb->get_var($query);
192 }
193 }
194
195 return !empty($counter) ? $counter : 0;
196 }//end if
197
198 return null;
199
200 }//end items_in_taxonomy()
201
202
203 /**
204 * To get the items in taxonomies in uncategorized
205 *
206 * @since 1.0.0
207 * @access public
208 * @return $total
209 */
210 public function un_categorized_items($post_type, $taxonomy)
211 {
212
213 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
214 global $wpdb;
215 $query = "SELECT COUNT(DISTINCT(tmp_table.ID))
216 FROM (SELECT * FROM {$this->tableIclTranslations} as wpmlt
217 INNER JOIN {$wpdb->posts} as p on p.id = wpmlt.element_id
218 WHERE wpmlt.element_type = 'post_.".esc_attr($post_type)."'
219 and wpmlt.language_code = '%s') as tmp_table
220 JOIN {$wpdb->term_relationships} as term_relationships on tmp_table.element_id = term_relationships.object_id
221 JOIN {$wpdb->term_taxonomy} as term_taxonomy on term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id
222 WHERE taxonomy = '%s'";
223 $query = $wpdb->prepare($query, [$this->lang, $taxonomy]);
224 $fileInFolder = (int) $wpdb->get_var($query);
225
226 $this->set_total($post_type);
227
228 return ($this->total - $fileInFolder);
229 }
230
231 return null;
232
233 }//end un_categorized_items()
234
235
236 /**
237 * To get the items in taxonomies in all categories
238 *
239 * @since 1.0.0
240 * @access public
241 * @return $total
242 */
243 public function all_categorized_items($post_type)
244 {
245 if ($this->isWPMLActive && isset($this->settings[$post_type]) && $this->settings[$post_type]) {
246 $this->set_total($post_type);
247 return $this->total;
248 }
249
250 return null;
251
252 }//end all_categorized_items()
253
254
255 }//end class
256
257 if (class_exists('WCP_Folder_WPML')) {
258 $folder_WPML = new WCP_Folder_WPML();
259 }
260