| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* base class for both admin and frontend |
| 5 |
* |
| 6 |
* @since 1.2 |
| 7 |
*/ |
| 8 |
abstract class PLL_Base { |
| 9 |
public $links_model, $model, $options; |
| 10 |
|
| 11 |
/* |
| 12 |
* constructor |
| 13 |
* |
| 14 |
* @since 1.2 |
| 15 |
* |
| 16 |
* @param object $links_model |
| 17 |
*/ |
| 18 |
public function __construct(&$links_model) { |
| 19 |
$this->links_model = &$links_model; |
| 20 |
$this->model = &$links_model->model; |
| 21 |
$this->options = &$this->model->options; |
| 22 |
|
| 23 |
add_action('widgets_init', array(&$this, 'widgets_init')); |
| 24 |
|
| 25 |
// user defined strings translations |
| 26 |
add_action('pll_language_defined', array(&$this, 'load_strings_translations'), 5); |
| 27 |
} |
| 28 |
|
| 29 |
/* |
| 30 |
* registers our widgets |
| 31 |
* |
| 32 |
* @since 0.1 |
| 33 |
*/ |
| 34 |
public function widgets_init() { |
| 35 |
register_widget('PLL_Widget_Languages'); |
| 36 |
|
| 37 |
// overwrites the calendar widget to filter posts by language |
| 38 |
if (!defined('PLL_WIDGET_CALENDAR') || PLL_WIDGET_CALENDAR) { |
| 39 |
unregister_widget('WP_Widget_Calendar'); |
| 40 |
register_widget('PLL_Widget_Calendar'); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/* |
| 45 |
* loads user defined strings translations |
| 46 |
* |
| 47 |
* @since 1.2 |
| 48 |
*/ |
| 49 |
public function load_strings_translations() { |
| 50 |
$mo = new PLL_MO(); |
| 51 |
$mo->import_from_db($this->model->get_language(get_locale())); |
| 52 |
$GLOBALS['l10n']['pll_string'] = &$mo; |
| 53 |
} |
| 54 |
|
| 55 |
/* |
| 56 |
* some backward compatibility with Polylang < 1.2 |
| 57 |
* allows for example to call $polylang->get_languages_list() instead of $polylang->model->get_languages_list() |
| 58 |
* this works but should be slower than the direct call, thus an error is triggered in debug mode |
| 59 |
* |
| 60 |
* @since 1.2 |
| 61 |
* |
| 62 |
* @param string $func function name |
| 63 |
* @param array $args function arguments |
| 64 |
*/ |
| 65 |
public function __call($func, $args) { |
| 66 |
foreach ($this as $prop => &$obj) |
| 67 |
if (is_object($obj) && method_exists($obj, $func)) { |
| 68 |
if (WP_DEBUG) { |
| 69 |
$debug = debug_backtrace(); |
| 70 |
trigger_error(sprintf( |
| 71 |
'%1$s was called incorrectly in %3$s on line %4$s: the call to $polylang->%1$s() has been deprecated in Polylang 1.2, use $polylang->%2$s->%1$s() instead.' . "\nError handler", |
| 72 |
$func, $prop, $debug[1]['file'], $debug[1]['line'] |
| 73 |
)); |
| 74 |
} |
| 75 |
return call_user_func_array(array($obj, $func), $args); |
| 76 |
} |
| 77 |
|
| 78 |
$debug = debug_backtrace(); |
| 79 |
trigger_error(sprintf('Call to undefined function $polylang->%1$s() in %2$s on line %3$s' . "\nError handler", $func, $debug[0]['file'], $debug[0]['line']), E_USER_ERROR); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
/* |
| 84 |
* helpers functions |
| 85 |
*/ |
| 86 |
|
| 87 |
|
| 88 |
/* |
| 89 |
* returns all page ids *not in* language defined by $lang_id |
| 90 |
* works for all translated hierarchical post types |
| 91 |
* |
| 92 |
* @since 1.2 |
| 93 |
* |
| 94 |
* @param object $lang language object |
| 95 |
* @return array list of page ids to exclude |
| 96 |
*/ |
| 97 |
function pll_exclude_pages($lang) { |
| 98 |
global $polylang; |
| 99 |
|
| 100 |
$args = array( |
| 101 |
'lang' => 0, // so this query is not filtered by our pre_get_post filter in PLL_Frontend_Filters |
| 102 |
'numberposts' => -1, |
| 103 |
'nopaging' => true, |
| 104 |
'post_type' => array_intersect(get_post_types(array('hierarchical' => 1)), $polylang->model->post_types), |
| 105 |
'fields' => 'ids', |
| 106 |
'tax_query' => array(array( |
| 107 |
'taxonomy' => 'language', |
| 108 |
'field' => 'term_taxonomy_id', // since WP 3.5 |
| 109 |
'terms' => $lang->term_taxonomy_id, |
| 110 |
'operator' => 'NOT IN' |
| 111 |
)) |
| 112 |
); |
| 113 |
|
| 114 |
// backward compatibility WP < 3.5 |
| 115 |
if (version_compare($GLOBALS['wp_version'], '3.5' , '<')) { |
| 116 |
unset($args['tax_query']['field']); |
| 117 |
$args['tax_query']['terms'] = $lang->term_id; |
| 118 |
} |
| 119 |
|
| 120 |
return get_posts($args); |
| 121 |
} |
| 122 |
|