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
← All changes | include/links-model.php +35 -95 2.71.5 View file →
@@ -1,136 +1,76 @@
1 1 <?php
2 2
3 -/**
4 - * Links model abstract class
3 +/*
4 + * links model abstract class
5 5 *
6 6 * @since 1.5
7 7 */
8 8 abstract class PLL_Links_Model {
9 9 public $model, $options;
10 - public $home; // used to store the home url before it is filtered
11 - public $using_permalinks;
10 + protected $home;
12 11
13 - /**
14 - * Constructor
12 + /*
13 + * constructor
15 14 *
16 15 * @since 1.5
17 16 *
18 17 * @param object $model PLL_Model instance
19 18 */
20 - public function __construct( &$model ) {
19 + public function __construct(&$model) {
21 20 $this->model = &$model;
22 21 $this->options = &$model->options;
23 22
24 - $this->home = home_url();
25 -
26 - add_filter( 'pll_languages_list', array( $this, 'pll_languages_list' ), 4 ); // after PLL_Static_Pages
27 - add_filter( 'pll_after_languages_cache', array( $this, 'pll_after_languages_cache' ) );
28 -
29 - // adds our domains or subdomains to allowed hosts for safe redirection
30 - add_filter( 'allowed_redirect_hosts', array( $this, 'allowed_redirect_hosts' ) );
23 + $this->home = get_option('home');
31 24 }
32 25
33 - /**
34 - * Changes the language code in url
26 + /*
27 + * returns the link to the first page when using pretty permalinks
35 28 *
36 - * @since 1.5
29 + * @since 1.2
37 30 *
38 - * @param string $url url to modify
39 - * @param object $lang language
31 + * @param string $url url to modify
40 32 * @return string modified url
41 33 */
42 - public function switch_language_in_link( $url, $lang ) {
43 - $url = $this->remove_language_from_link( $url );
44 - return $this->add_language_to_link( $url, $lang );
34 + public function remove_paged_from_link($url) {
35 + return preg_replace('#\/page\/[0-9]+\/#', '/', $url); // FIXME trailing slash ?
45 36 }
46 37
47 - /**
48 - * Get hosts managed on the website
38 + /*
39 + * returns the link to the paged page when using pretty permalinks
49 40 *
50 41 * @since 1.5
51 42 *
52 - * @return array list of hosts
43 + * @param string $url url to modify
44 + * @param int $page
45 + * @return string modified url
53 46 */
54 - public function get_hosts() {
55 - return array( wp_parse_url( $this->home, PHP_URL_HOST ) );
47 + public function add_paged_to_link($url, $page) {
48 + return trailingslashit($url) . 'page/' . $page; // FIXME trailing slash ?
56 49 }
57 50
58 - /**
59 - * Returns the home url
60 - *
61 - * @since 1.3.1
62 - *
63 - * @param object $lang PLL_Language object
64 - * @return string
65 - */
66 - public function home_url( $lang ) {
67 - $url = trailingslashit( $this->home );
68 - return $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ? $url : $this->add_language_to_link( $url, $lang );
69 - }
70 51
71 - /**
72 - * Sets the home urls
52 + /*
53 + * changes the language code in url
73 54 *
74 - * @since 1.8
55 + * @since 1.5
75 56 *
76 - * @param object $language
57 + * @param string $url url to modify
58 + * @param object $lang language
59 + * @return string modified url
77 60 */
78 - protected function set_home_url( $language ) {
79 - // We should always have a default language here, except, temporarily, in PHPUnit tests. The test here protects against PHP notices.
80 - if ( isset( $this->options['default_lang'] ) ) {
81 - $search_url = $this->home_url( $language );
82 - $home_url = empty( $language->page_on_front ) || $this->options['redirect_lang'] ? $search_url : $this->front_page_url( $language );
83 - $language->set_home_url( $search_url, $home_url );
84 - }
61 + public function switch_language_in_link($url, $lang) {
62 + $url = $this->remove_language_from_link($url);
63 + return $this->add_language_to_link($url, $lang);
85 64 }
86 65
87 - /**
88 - * Sets the home urls and flags before the languages are persistently cached
66 + /*
67 + * get hosts managed on the website
89 68 *
90 - * @since 1.8
69 + * @since 1.5
91 70 *
92 - * @param array $languages array of PLL_Language objects
93 - * @return array
71 + * @return array list of hosts
94 72 */
95 - public function pll_languages_list( $languages ) {
96 - foreach ( $languages as $language ) {
97 - $this->set_home_url( $language );
98 - $language->set_flag();
99 - }
100 - return $languages;
101 - }
102 -
103 - /**
104 - * Sets the home urls when not cached
105 - * Sets the home urls scheme
106 - *
107 - * @since 1.8
108 - *
109 - * @param array $languages array of PLL_Language objects
110 - * @return array
111 - */
112 - public function pll_after_languages_cache( $languages ) {
113 - foreach ( $languages as $language ) {
114 - // Get the home urls when not cached
115 - if ( ( defined( 'PLL_CACHE_LANGUAGES' ) && ! PLL_CACHE_LANGUAGES ) || ( defined( 'PLL_CACHE_HOME_URL' ) && ! PLL_CACHE_HOME_URL ) ) {
116 - $this->set_home_url( $language );
117 - }
118 -
119 - // Ensures that the ( possibly cached ) home url uses the right scheme http or https
120 - $language->set_home_url_scheme();
121 - }
122 - return $languages;
123 - }
124 -
125 - /**
126 - * Adds our domains or subdomains to allowed hosts for safe redirection
127 - *
128 - * @since 1.4.3
129 - *
130 - * @param array $hosts allowed hosts
131 - * @return array
132 - */
133 - public function allowed_redirect_hosts( $hosts ) {
134 - return array_unique( array_merge( $hosts, array_values( $this->get_hosts() ) ) );
73 + public function get_hosts() {
74 + return array(parse_url($this->home, PHP_URL_HOST));
135 75 }
136 76 }