| 1 |
<?php |
| 2 |
namespace FileBird\Controller; |
| 3 |
|
| 4 |
use FileBird\Model\Folder as FolderModel; |
| 5 |
|
| 6 |
defined('ABSPATH') || exit; |
| 7 |
|
| 8 |
class CompatiblePolylang extends Controller { |
| 9 |
protected static $instance = null; |
| 10 |
|
| 11 |
private $active; |
| 12 |
private $total; |
| 13 |
private $table_filebird_polylang; |
| 14 |
public $delete_process_id; |
| 15 |
private $lang; |
| 16 |
|
| 17 |
public function __construct() { |
| 18 |
global $wpdb, $polylang; |
| 19 |
|
| 20 |
$this->total = 0; |
| 21 |
$this->delete_process_id = null; |
| 22 |
|
| 23 |
$this->active = function_exists("pll_get_post_translations"); |
| 24 |
if ($this->active) { |
| 25 |
if ($polylang->options['media_support'] == 1) |
| 26 |
{ |
| 27 |
$this->lang = PLL()->model->get_language( get_user_meta( get_current_user_id(), 'pll_filter_content', true ) ); |
| 28 |
add_action('pll_translate_media', array($this, 'duplicateAttachmentToFolder'), 10, 3); |
| 29 |
//add_filter( 'pll_filter_query_excluded_query_vars', array($this, 'excludedQueryVars'), 10, 3); |
| 30 |
// add_filter('fbv_in_not_in_select_query', array($this, 'inNotInSelectQuery'), 10, 4); |
| 31 |
// add_filter('fbv_in_not_in_where_query', array($this, 'inNotInWhereQuery'), 10, 2); |
| 32 |
add_filter('fbv_count_args', array($this, 'countArgs')); |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
public function duplicateAttachmentToFolder($post_id, $tr_id, $lang_slug) { |
| 38 |
$folders_of_source = FolderModel::getFoldersOfPost($post_id); |
| 39 |
FolderModel::setFoldersForPosts($tr_id, $folders_of_source); |
| 40 |
} |
| 41 |
public function excludedQueryVars($excludes, $query, $lang) { |
| 42 |
if(isset($query->query['fbv_count']) && $query->query_vars['post_type'] == 'attachment' ) { |
| 43 |
$excludes = array_values(array_diff($excludes, array('post__in', 'post__not_in'))); |
| 44 |
} |
| 45 |
return $excludes; |
| 46 |
} |
| 47 |
public function inNotInSelectQuery($query, $fbv, $fbv_table, $fbv_relation_table) { |
| 48 |
global $wpdb; |
| 49 |
if($fbv !== 0 && is_object($this->lang)) { |
| 50 |
$query = "SELECT `attachment_id` FROM " . |
| 51 |
$fbv_relation_table . |
| 52 |
" JOIN ".$wpdb->prefix."term_relationships ON " . |
| 53 |
$fbv_relation_table . ".attachment_id = ".$wpdb->prefix."term_relationships.object_id "; |
| 54 |
} |
| 55 |
return $query; |
| 56 |
} |
| 57 |
public function inNotInWhereQuery($where, $fbv) { |
| 58 |
if($fbv !== 0 && is_object($this->lang)) { |
| 59 |
$where[] = 'term_taxonomy_id = ' . $this->lang->term_taxonomy_id; |
| 60 |
} |
| 61 |
return $where; |
| 62 |
} |
| 63 |
public function countArgs($args) { |
| 64 |
if(is_object($this->lang)) { |
| 65 |
$args['lang'] = $this->lang->slug; |
| 66 |
} |
| 67 |
|
| 68 |
return $args; |
| 69 |
} |
| 70 |
public static function getInstance() { |
| 71 |
if (null == self::$instance) { |
| 72 |
self::$instance = new self; |
| 73 |
} |
| 74 |
return self::$instance; |
| 75 |
} |
| 76 |
} |
| 77 |
|