PluginProbe
Polylang / 1.4.4
Polylang v1.4.4
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 / links-default.php

links-default.php in Polylang 1.4.4, at include/links-default.php

94 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * links model for default permalinks
5 * for example mysite.com/?somevar=something&lang=en
6 * implements the "links_model interface"
7 *
8 * @since 1.2
9 */
10 class PLL_Links_Default {
11 public $model, $options;
12 protected $home;
13
14 /*
15 * constructor
16 *
17 * @since 1.2
18 *
19 * @param object $model PLL_Model instance
20 */
21 public function __construct(&$model) {
22 $this->model = &$model;
23 $this->options = &$model->options;
24
25 $this->home = get_option('home');
26 }
27
28 /*
29 * adds language information to an url
30 * links_model interface
31 *
32 * @since 1.2
33 *
34 * @param string $url url to modify
35 * @param object $lang language
36 * @return string modified url
37 */
38 public function add_language_to_link($url, $lang) {
39 return !empty($lang) && '_get_page_link' != current_filter() ? add_query_arg( 'lang', $lang->slug, $url ) : $url;
40 }
41
42 /*
43 * removes the language information from an url
44 * links_model interface
45 *
46 * @since 1.2
47 *
48 * @param string $url url to modify
49 * @return string modified url
50 */
51 public function remove_language_from_link($url) {
52 return remove_query_arg('lang', $url);
53 }
54
55 /*
56 * returns the link to the first page
57 * links_model interface
58 *
59 * @since 1.2
60 *
61 * @param string $url url to modify
62 * @return string modified url
63 */
64 function remove_paged_from_link($url) {
65 return remove_query_arg('paged', $url);
66 }
67
68 /*
69 * gets the language slug from the url if present
70 * links_model interface
71 *
72 * @since 1.2
73 *
74 * @return string language slug
75 */
76 public function get_language_from_url() {
77 $pattern = '#lang=('.implode('|', $this->model->get_languages_list(array('fields' => 'slug'))).')#';
78 return preg_match($pattern, trailingslashit($_SERVER['REQUEST_URI']), $matches) ? $matches[1] : ''; // $matches[1] is the slug of the requested language
79 }
80
81 /*
82 * returns the home url
83 * links_model interface
84 *
85 * @since 1.3.1
86 *
87 * @param object $lang PLL_Language object
88 * @return string
89 */
90 public function home_url($lang) {
91 return $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ? $this->home : get_term_link($lang, 'language');
92 }
93 }
94