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
plugin.updates.php
5 years ago
tree.class.php
5 years ago
class-polylang.php
131 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 | class WCP_Folder_PolyLang { |
| 4 | private $active; |
| 5 | private $pl_term_taxonomy_id; |
| 6 | private $total; |
| 7 | private $table_filebird_polylang; |
| 8 | public $delete_process_id; |
| 9 | |
| 10 | public function __construct() |
| 11 | { |
| 12 | $this->active = false; |
| 13 | $this->total = 0; |
| 14 | $this->delete_process_id = null; |
| 15 | add_action("admin_init", array($this, 'init')); |
| 16 | } |
| 17 | |
| 18 | |
| 19 | public function init() |
| 20 | { |
| 21 | global $wpdb, $polylang; |
| 22 | $this->active = function_exists("pll_get_post_translations"); |
| 23 | |
| 24 | if ($this->active) { |
| 25 | if (isset($polylang->curlang) && is_object($polylang->curlang)) |
| 26 | { |
| 27 | $this->pl_term_taxonomy_id = $polylang->curlang->term_taxonomy_id; |
| 28 | |
| 29 | add_filter('premio_folder_item_in_taxonomy', array($this, 'items_in_taxonomy'), 10, 2); |
| 30 | add_filter('premio_folder_un_categorized_items', array($this, 'un_categorized_items'), 10, 2); |
| 31 | add_filter('premio_folder_all_categorized_items', array($this, 'all_categorized_items'), 10, 2); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public function set_total($post_type){ |
| 37 | if ($this->active) { |
| 38 | $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'"; |
| 39 | if($post_type != 'attachment') { |
| 40 | $where = "post_status != 'trash'"; |
| 41 | } |
| 42 | global $wpdb; |
| 43 | $query = "SELECT COUNT(tmp.ID) FROM |
| 44 | ( |
| 45 | SELECT posts.ID |
| 46 | FROM {$wpdb->posts} AS posts |
| 47 | LEFT JOIN {$wpdb->term_relationships} AS trs |
| 48 | ON posts.ID = trs.object_id |
| 49 | LEFT JOIN {$wpdb->postmeta} AS postmeta |
| 50 | ON (posts.ID = postmeta.post_id AND postmeta.meta_key = '_wp_attached_file') |
| 51 | WHERE posts.post_type = '{$post_type}' |
| 52 | AND trs.term_taxonomy_id IN ({$this->pl_term_taxonomy_id}) |
| 53 | AND ({$where}) |
| 54 | GROUP BY posts.ID |
| 55 | ) as tmp"; |
| 56 | $this->total = (int)$wpdb->get_var($query); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | public function items_in_taxonomy($term_id, $arg = array()) { |
| 61 | if ($this->active) { |
| 62 | $post_type = isset($arg['post_type']) ? $arg['post_type'] : ""; |
| 63 | $taxonomy = isset($arg['taxonomy']) ? $arg['taxonomy'] : ""; |
| 64 | $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'"; |
| 65 | if($post_type != 'attachment') { |
| 66 | $where = "post_status != 'trash'"; |
| 67 | } |
| 68 | global $wpdb; |
| 69 | $term_taxonomy_id = get_term_by('id', (int)$term_id, $taxonomy, OBJECT)->term_taxonomy_id; |
| 70 | $query = "SELECT COUNT(tmp.ID) FROM |
| 71 | ( |
| 72 | SELECT posts.ID FROM {$wpdb->posts} AS posts |
| 73 | LEFT JOIN {$wpdb->term_relationships} AS tr1 |
| 74 | ON (posts.ID = tr1.object_id) |
| 75 | INNER JOIN {$wpdb->term_relationships} AS tr2 |
| 76 | ON (posts.ID = tr2.object_id and tr2.term_taxonomy_id IN ($term_taxonomy_id)) |
| 77 | LEFT JOIN {$wpdb->postmeta} AS postmeta ON ( posts.ID = postmeta.post_id AND postmeta.meta_key = '_wp_attached_file' ) |
| 78 | WHERE (tr1.term_taxonomy_id IN ({$this->pl_term_taxonomy_id})) |
| 79 | AND posts.post_type = '{$post_type}' |
| 80 | AND (({$where})) |
| 81 | GROUP BY posts.ID |
| 82 | ) as tmp |
| 83 | "; |
| 84 | $counter = (int)$wpdb->get_var($query); |
| 85 | return $counter ? $counter : 0; |
| 86 | } |
| 87 | return null; |
| 88 | } |
| 89 | |
| 90 | public function un_categorized_items($post_type, $taxonomy) { |
| 91 | if ($this->active) { |
| 92 | global $wpdb; |
| 93 | $where = "posts.post_status = 'inherit' OR posts.post_status = 'private'"; |
| 94 | if($post_type != 'attachment') { |
| 95 | $where = "post_status != 'trash'"; |
| 96 | } |
| 97 | $query = "SELECT COUNT(tmp.ID) FROM |
| 98 | ( |
| 99 | SELECT posts.ID |
| 100 | FROM {$wpdb->posts} AS posts |
| 101 | INNER JOIN {$wpdb->term_relationships} AS tr1 |
| 102 | ON posts.ID = tr1.object_id AND tr1.term_taxonomy_id IN ({$this->pl_term_taxonomy_id}) |
| 103 | INNER JOIN {$wpdb->term_relationships} AS tr2 |
| 104 | ON (tr2.object_id = posts.ID) |
| 105 | JOIN {$wpdb->term_taxonomy} as tx |
| 106 | ON tx.term_taxonomy_id = tr2.term_taxonomy_id AND tx.taxonomy = '{$taxonomy}' |
| 107 | |
| 108 | WHERE posts.post_type = '{$post_type}' |
| 109 | AND ({$where}) |
| 110 | GROUP BY posts.ID |
| 111 | ) as tmp"; |
| 112 | $fileInFolder = (int)$wpdb->get_var($query); |
| 113 | $fileInFolder = !($fileInFolder)?0:$fileInFolder; |
| 114 | $this->set_total($post_type); |
| 115 | return $this->total - $fileInFolder; |
| 116 | } |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | public function all_categorized_items($post_type) { |
| 121 | if ($this->active) { |
| 122 | $this->set_total($post_type); |
| 123 | return $this->total; |
| 124 | } |
| 125 | return null; |
| 126 | } |
| 127 | } |
| 128 | if(class_exists('WCP_Folder_PolyLang')) { |
| 129 | $WCP_Folder_PolyLang = new WCP_Folder_PolyLang(); |
| 130 | |
| 131 | } |