PLL_Links_Model

Links model abstract class.

Defined (1)

The class is defined in the following location(s).

/include/links-model.php  
  1. abstract class PLL_Links_Model { 
  2. public $model, $options; 
  3. public $home; // used to store the home url before it is filtered 
  4. public $using_permalinks; 
  5.  
  6. /** 
  7. * Constructor 
  8. * @since 1.5 
  9. * @param object $model PLL_Model instance 
  10. */ 
  11. public function __construct( &$model ) { 
  12. $this->model = &$model; 
  13. $this->options = &$model->options; 
  14.  
  15. $this->home = home_url(); 
  16.  
  17. add_filter( 'pll_languages_list', array( $this, 'pll_languages_list' ), 4 ); // after PLL_Static_Pages 
  18. add_filter( 'pll_after_languages_cache', array( $this, 'pll_after_languages_cache' ) ); 
  19.  
  20. // adds our domains or subdomains to allowed hosts for safe redirection 
  21. add_filter( 'allowed_redirect_hosts', array( $this, 'allowed_redirect_hosts' ) ); 
  22.  
  23. /** 
  24. * Changes the language code in url 
  25. * @since 1.5 
  26. * @param string $url url to modify 
  27. * @param object $lang language 
  28. * @return string modified url 
  29. */ 
  30. public function switch_language_in_link( $url, $lang ) { 
  31. $url = $this->remove_language_from_link( $url ); 
  32. return $this->add_language_to_link( $url, $lang ); 
  33.  
  34. /** 
  35. * Get hosts managed on the website 
  36. * @since 1.5 
  37. * @return array list of hosts 
  38. */ 
  39. public function get_hosts() { 
  40. return array( parse_url( $this->home, PHP_URL_HOST ) ); 
  41.  
  42. /** 
  43. * Returns the home url 
  44. * @since 1.3.1 
  45. * @param object $lang PLL_Language object 
  46. * @return string 
  47. */ 
  48. public function home_url( $lang ) { 
  49. $url = trailingslashit( $this->home ); 
  50. return $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ? $url: $this->add_language_to_link( $url, $lang ); 
  51.  
  52. /** 
  53. * Sets the home urls 
  54. * @since 1.8 
  55. * @param object $language 
  56. */ 
  57. protected function set_home_url( $language ) { 
  58. $search_url = $this->home_url( $language ); 
  59. $home_url = empty( $language->page_on_front ) || $this->options['redirect_lang'] ? $search_url : $this->front_page_url( $language ); 
  60. $language->set_home_url( $search_url, $home_url ); 
  61.  
  62. /** 
  63. * Sets the home urls and flags before the languages are persistently cached 
  64. * @since 1.8 
  65. * @param array $languages array of PLL_Language objects 
  66. * @return array 
  67. */ 
  68. public function pll_languages_list( $languages ) { 
  69. foreach ( $languages as $language ) { 
  70. $this->set_home_url( $language ); 
  71. $language->set_flag(); 
  72. return $languages; 
  73.  
  74. /** 
  75. * Sets the home urls when not cached 
  76. * Sets the home urls scheme 
  77. * @since 1.8 
  78. * @param array $languages array of PLL_Language objects 
  79. * @return array 
  80. */ 
  81. public function pll_after_languages_cache( $languages ) { 
  82. foreach ( $languages as $language ) { 
  83. // Get the home urls when not cached 
  84. if ( ( defined( 'PLL_CACHE_LANGUAGES' ) && ! PLL_CACHE_LANGUAGES ) || ( defined( 'PLL_CACHE_HOME_URL' ) && ! PLL_CACHE_HOME_URL ) ) { 
  85. $this->set_home_url( $language ); 
  86.  
  87. // Ensures that the ( possibly cached ) home url uses the right scheme http or https 
  88. $language->set_home_url_scheme(); 
  89. return $languages; 
  90.  
  91. /** 
  92. * Adds our domains or subdomains to allowed hosts for safe redirection 
  93. * @since 1.4.3 
  94. * @param array $hosts allowed hosts 
  95. * @return array 
  96. */ 
  97. public function allowed_redirect_hosts( $hosts ) { 
  98. return array_unique( array_merge( $hosts, array_values( $this->get_hosts() ) ) );