| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Base class to manage the static front page and the page for posts |
| 8 | 5 | * |
| @@ -7,43 +4,13 @@ | ||
| 7 | 4 | * Base class to manage the static front page and the page for posts |
| 8 | 5 | * |
| 9 | 6 | * @since 1.8 |
| 10 | 7 | */ |
| 11 | -class PLL_Static_Pages { | |
| 12 | - /** | |
| 13 | - * Id of the page on front. | |
| 14 | - * | |
| 15 | - * @var int | |
| 16 | - */ | |
| 17 | - public $page_on_front; | |
| 8 | +abstract class PLL_Static_Pages { | |
| 9 | + public $model, $options; | |
| 10 | + public $page_on_front, $page_for_posts; | |
| 18 | 11 | |
| 19 | 12 | /** |
| 20 | - * Id of the page for posts. | |
| 21 | - * | |
| 22 | - * @var int | |
| 23 | - */ | |
| 24 | - public $page_for_posts; | |
| 25 | - | |
| 26 | - /** | |
| 27 | - * Stores the plugin options. | |
| 28 | - * | |
| 29 | - * @var array | |
| 30 | - */ | |
| 31 | - protected $options; | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * @var PLL_Model | |
| 35 | - */ | |
| 36 | - protected $model; | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * Current language. | |
| 40 | - * | |
| 41 | - * @var PLL_Language | |
| 42 | - */ | |
| 43 | - protected $curlang; | |
| 44 | - | |
| 45 | - /** | |
| 46 | 13 | * Constructor: setups filters and actions |
| 47 | 14 | * |
| 48 | 15 | * @since 1.8 |
| 49 | 16 | * |
| @@ -49,9 +16,9 @@ | ||
| 49 | 16 | * |
| 50 | 17 | * @param object $polylang |
| 51 | 18 | */ |
| 52 | 19 | public function __construct( &$polylang ) { |
| 53 | - $this->model = &$polylang->model; | |
| 20 | + $this->model = &$polylang->model; | |
| 54 | 21 | $this->options = &$polylang->options; |
| 55 | 22 | $this->curlang = &$polylang->curlang; |
| 56 | 23 | |
| 57 | 24 | $this->init(); |
| @@ -65,11 +32,8 @@ | ||
| 65 | 32 | add_action( 'update_option_page_for_posts', array( $this->model, 'clean_languages_cache' ) ); |
| 66 | 33 | |
| 67 | 34 | // Refresh rewrite rules when the page on front is modified |
| 68 | 35 | add_action( 'update_option_page_on_front', 'flush_rewrite_rules' ); |
| 69 | - | |
| 70 | - // OEmbed | |
| 71 | - add_filter( 'oembed_request_post_id', array( $this, 'oembed_request_post_id' ), 10, 2 ); | |
| 72 | 36 | } |
| 73 | 37 | |
| 74 | 38 | /** |
| 75 | 39 | * Stores the page on front and page for posts ids |
| @@ -74,16 +38,16 @@ | ||
| 74 | 38 | /** |
| 75 | 39 | * Stores the page on front and page for posts ids |
| 76 | 40 | * |
| 77 | 41 | * @since 1.8 |
| 78 | - * | |
| 79 | - * @return void | |
| 80 | 42 | */ |
| 81 | 43 | public function init() { |
| 82 | 44 | if ( 'page' == get_option( 'show_on_front' ) ) { |
| 83 | 45 | $this->page_on_front = get_option( 'page_on_front' ); |
| 84 | 46 | $this->page_for_posts = get_option( 'page_for_posts' ); |
| 85 | - } else { | |
| 47 | + } | |
| 48 | + | |
| 49 | + else { | |
| 86 | 50 | $this->page_on_front = 0; |
| 87 | 51 | $this->page_for_posts = 0; |
| 88 | 52 | } |
| 89 | 53 | } |
| @@ -97,11 +61,9 @@ | ||
| 97 | 61 | * @param int $id post id of the page |
| 98 | 62 | * @return string modified link |
| 99 | 63 | */ |
| 100 | 64 | public function page_link( $link, $id ) { |
| 101 | - $lang = $this->model->post->get_language( $id ); | |
| 102 | - | |
| 103 | - if ( $lang && $id == $lang->page_on_front ) { | |
| 65 | + if ( ( $lang = $this->model->post->get_language( $id ) ) && $id == $lang->page_on_front ) { | |
| 104 | 66 | return $lang->home_url; |
| 105 | 67 | } |
| 106 | 68 | return $link; |
| 107 | 69 | } |
| @@ -106,15 +68,14 @@ | ||
| 106 | 68 | return $link; |
| 107 | 69 | } |
| 108 | 70 | |
| 109 | 71 | /** |
| 110 | - * Adds page_on_front and page_for_posts properties to the language objects. | |
| 72 | + * Adds page_on_front and page_for_posts properties to the language objects | |
| 111 | 73 | * |
| 112 | 74 | * @since 1.8 |
| 113 | 75 | * |
| 114 | - * @param PLL_Language[] $languages The list of languages. | |
| 115 | - * @param PLL_Model $model The instance of PLL_Model. | |
| 116 | - * @return PLL_Language[] | |
| 76 | + * @param array $languages | |
| 77 | + * @param object $model | |
| 117 | 78 | */ |
| 118 | 79 | public static function pll_languages_list( $languages, $model ) { |
| 119 | 80 | if ( 'page' === get_option( 'show_on_front' ) ) { |
| 120 | 81 | foreach ( $languages as $k => $language ) { |
| @@ -135,26 +96,7 @@ | ||
| 135 | 96 | * @return int |
| 136 | 97 | */ |
| 137 | 98 | public function translate_page_for_posts( $v ) { |
| 138 | 99 | // Don't attempt to translate in a 'switch_blog' action as there is a risk to call this function while initializing the languages cache |
| 139 | - return isset( $this->curlang->page_for_posts ) && ( $this->curlang->page_for_posts ) && ! doing_action( 'switch_blog' ) ? $this->curlang->page_for_posts : $v; | |
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | - * Fixes the oembed for the translated static front page | |
| 144 | - * when the language page is redirected to the front page | |
| 145 | - * | |
| 146 | - * @since 2.6 | |
| 147 | - * | |
| 148 | - * @param int $post_id The post ID. | |
| 149 | - * @param string $url The requested URL. | |
| 150 | - * @return int | |
| 151 | - */ | |
| 152 | - public function oembed_request_post_id( $post_id, $url ) { | |
| 153 | - foreach ( $this->model->get_languages_list() as $lang ) { | |
| 154 | - if ( trailingslashit( $url ) === trailingslashit( $lang->home_url ) ) { | |
| 155 | - $post_id = $lang->page_on_front; | |
| 156 | - } | |
| 157 | - } | |
| 158 | - return $post_id; | |
| 100 | + return isset( $this->curlang->page_for_posts ) && ! doing_action( 'switch_blog' ) ? $this->curlang->page_for_posts : $v; | |
| 159 | 101 | } |
| 160 | 102 | } |