PluginProbe
Polylang / 1.5
Polylang v1.5
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-domain.php

links-domain.php in Polylang 1.5, at include/links-domain.php

79 lines 1.9 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 use when using one domain per language
5 * for example mysite.com/sth and mysite.fr/qqch
6 * implements the "links_model interface"
7 *
8 * @since 1.2
9 */
10 class PLL_Links_Domain extends PLL_Links_Model {
11
12 /*
13 * adds the language code in url
14 * links_model interface
15 *
16 * @since 1.2
17 *
18 * @param string $url url to modify
19 * @param object $lang language
20 * @return string modified url
21 */
22 public function add_language_to_link($url, $lang) {
23 if (!empty($lang) && !empty($this->options['domains'][$lang->slug]))
24 $url = str_replace($this->home, $this->options['domains'][$lang->slug], $url);
25 return $url;
26 }
27
28 /*
29 * returns the url without language code
30 * links_model interface
31 *
32 * @since 1.2
33 *
34 * @param string $url url to modify
35 * @return string modified url
36 */
37 public function remove_language_from_link($url) {
38 if (!empty($this->options['domains']))
39 $url = preg_replace('#^('.implode('|', $this->options['domains']).')#', $this->home , $url);
40 return $url;
41 }
42
43 /*
44 * returns the language based on language code in url
45 * links_model interface
46 *
47 * @since 1.2
48 *
49 * @return string language slug
50 */
51 public function get_language_from_url() {
52 return ($lang = array_search( (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'], $this->options['domains'] ) ) ? $lang : $this->options['default_lang'];
53 }
54
55 /*
56 * returns the home url
57 * links_model interface
58 *
59 * @since 1.3.1
60 *
61 * @param object $lang PLL_Language object
62 * @return string
63 */
64 function home_url($lang) {
65 return empty($this->options['domains'][$lang->slug]) ? $this->home : $this->options['domains'][$lang->slug];
66 }
67
68 /*
69 * get hosts managed on the website
70 *
71 * @since 1.5
72 *
73 * @return array list of hosts
74 */
75 public function get_hosts() {
76 return array_map(create_function('$v', 'return parse_url($v, PHP_URL_HOST);'), $this->options['domains']);
77 }
78 }
79