PluginProbe
Polylang / 1.2.2
Polylang v1.2.2
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / language.php

language.php in Polylang 1.2.2, at include/language.php

89 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * a language object is made of two terms in 'language' and 'term_language' taxonomies
5 * manipulating only one object per language instead of two terms should make things easier
6 *
7 * properties:
8 * term_id => id of term in 'language' taxonomy
9 * name => language name. Ex: English
10 * slug => language code used in url. Ex: en
11 * term_group => order of the language when displayed in a list of languages
12 * term_taxonomy_id => term taxonomy id in 'language' taxonomy
13 * taxonomy => 'language'
14 * description => language locale for backward compatibility
15 * parent => 0 / not used
16 * count => number of posts and pages in that language
17 * tl_term_id => id of the term in 'term_language' taxonomy
18 * tl_term_taxonomy_id => term taxonomy id in 'term_language' taxonomy
19 * tl_count => number of terms in that language (not used by Polylang)
20 * locale => language locale. Ex: en_US
21 * is_rtl => 1 if the language is rtl
22 * flag_url => url of the flag
23 * flag => html img of the flag
24 *
25 * @since 1.2
26 */
27 class PLL_Language {
28
29 /*
30 * constructor: builds a language object given its two corresponding terms in language and term_language taxonomies
31 *
32 * @since 1.2
33 *
34 * @param object $language 'language' term
35 * @param object $term_language corresponding 'term_language' term
36 */
37 public function __construct($language, $term_language) {
38 foreach ($language as $prop => $value)
39 $this->$prop = in_array($prop, array('term_id', 'term_taxonomy_id', 'count')) ? (int) $language->$prop : $language->$prop;
40
41 // although it would be convenient here, don't assume the term is shared between taxonomies as it may not be the case in future
42 // http://make.wordpress.org/core/2013/07/28/potential-roadmap-for-taxonomy-meta-and-post-relationships/
43 $this->tl_term_id = (int) $term_language->term_id;
44 $this->tl_term_taxonomy_id = (int) $term_language->term_taxonomy_id;
45 $this->tl_count = (int) $term_language->count;
46
47 $description = maybe_unserialize($language->description);
48 $this->locale = $description['locale'];
49 $this->is_rtl = $description['rtl'];
50
51 $this->description = &$this->locale; // backward compatibility with Polylang < 1.2
52 }
53
54 /*
55 * sets flag_url and flag properties
56 *
57 * @since 1.2
58 */
59 public function set_flag() {
60 if (file_exists(POLYLANG_DIR.($file = '/flags/'.$this->locale.'.png')))
61 $url = POLYLANG_URL.$file;
62
63 // overwrite with custom flags
64 // never use custom flags on admin side
65 if (!PLL_ADMIN && ( file_exists(PLL_LOCAL_DIR.($file = '/'.$this->locale.'.png')) || file_exists(PLL_LOCAL_DIR.($file = '/'.$this->locale.'.jpg')) ))
66 $url = PLL_LOCAL_URL.$file;
67
68 $this->flag_url = empty($url) ? '' : esc_url($url);
69
70 $this->flag = apply_filters('pll_get_flag', empty($this->flag_url) ? '' :
71 sprintf(
72 '<img src="%s" title="%s" alt="%s" />',
73 esc_url($this->flag_url),
74 esc_attr(apply_filters('pll_flag_title', $this->name, $this->slug, $this->locale)),
75 esc_attr($this->name)
76 ));
77 }
78
79 /*
80 * updates post and term count
81 *
82 * @since 1.2
83 */
84 public function update_count() {
85 wp_update_term_count($this->term_taxonomy_id, 'language'); // posts count
86 wp_update_term_count($this->tl_term_taxonomy_id, 'term_language'); // terms count
87 }
88 }
89