| @@ -1,20 +1,17 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | - * Base class to manage the static front page and the page for posts | |
| 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 { | |
| 8 | +abstract class PLL_Static_Pages { | |
| 12 | 9 | public $model, $options; |
| 13 | 10 | public $page_on_front, $page_for_posts; |
| 14 | 11 | |
| 15 | 12 | /** |
| 16 | - * Constructor: setups filters and actions | |
| 13 | + * constructor: setups filters and actions | |
| 17 | 14 | * |
| 18 | 15 | * @since 1.8 |
| 19 | 16 | * |
| 20 | 17 | * @param object $polylang |
| @@ -19,11 +16,10 @@ | ||
| 19 | 16 | * |
| 20 | 17 | * @param object $polylang |
| 21 | 18 | */ |
| 22 | 19 | public function __construct( &$polylang ) { |
| 23 | - $this->model = &$polylang->model; | |
| 20 | + $this->model = &$polylang->model; | |
| 24 | 21 | $this->options = &$polylang->options; |
| 25 | - $this->curlang = &$polylang->curlang; | |
| 26 | 22 | |
| 27 | 23 | $this->init(); |
| 28 | 24 | |
| 29 | 25 | // Modifies the page link in case the front page is not in the default language |
| @@ -28,22 +24,18 @@ | ||
| 28 | 24 | |
| 29 | 25 | // Modifies the page link in case the front page is not in the default language |
| 30 | 26 | add_filter( 'page_link', array( $this, 'page_link' ), 20, 2 ); |
| 31 | 27 | |
| 32 | - // Clean the languages cache when editing page of front, page for posts | |
| 33 | - add_action( 'update_option_show_on_front', array( $this->model, 'clean_languages_cache' ) ); | |
| 28 | + // clean the languages cache when editing page of front, page for posts | |
| 34 | 29 | add_action( 'update_option_page_on_front', array( $this->model, 'clean_languages_cache' ) ); |
| 35 | 30 | add_action( 'update_option_page_for_posts', array( $this->model, 'clean_languages_cache' ) ); |
| 36 | 31 | |
| 37 | - // Refresh rewrite rules when the page on front is modified | |
| 32 | + // refresh rewrite rules when the page on front is modified | |
| 38 | 33 | add_action( 'update_option_page_on_front', 'flush_rewrite_rules' ); |
| 39 | - | |
| 40 | - // OEmbed | |
| 41 | - add_filter( 'oembed_request_post_id', array( $this, 'oembed_request_post_id' ), 10, 2 ); | |
| 42 | 34 | } |
| 43 | 35 | |
| 44 | 36 | /** |
| 45 | - * Stores the page on front and page for posts ids | |
| 37 | + * stores the page on front and page for posts ids | |
| 46 | 38 | * |
| 47 | 39 | * @since 1.8 |
| 48 | 40 | */ |
| 49 | 41 | public function init() { |
| @@ -49,9 +41,11 @@ | ||
| 49 | 41 | public function init() { |
| 50 | 42 | if ( 'page' == get_option( 'show_on_front' ) ) { |
| 51 | 43 | $this->page_on_front = get_option( 'page_on_front' ); |
| 52 | 44 | $this->page_for_posts = get_option( 'page_for_posts' ); |
| 53 | - } else { | |
| 45 | + } | |
| 46 | + | |
| 47 | + else { | |
| 54 | 48 | $this->page_on_front = 0; |
| 55 | 49 | $this->page_for_posts = 0; |
| 56 | 50 | } |
| 57 | 51 | } |
| @@ -65,11 +59,9 @@ | ||
| 65 | 59 | * @param int $id post id of the page |
| 66 | 60 | * @return string modified link |
| 67 | 61 | */ |
| 68 | 62 | public function page_link( $link, $id ) { |
| 69 | - $lang = $this->model->post->get_language( $id ); | |
| 70 | - | |
| 71 | - if ( $lang && $id == $lang->page_on_front ) { | |
| 63 | + if ( ( $lang = $this->model->post->get_language( $id ) ) && $id == $lang->page_on_front ) { | |
| 72 | 64 | return $lang->home_url; |
| 73 | 65 | } |
| 74 | 66 | return $link; |
| 75 | 67 | } |
| @@ -74,53 +66,20 @@ | ||
| 74 | 66 | return $link; |
| 75 | 67 | } |
| 76 | 68 | |
| 77 | 69 | /** |
| 78 | - * Adds page_on_front and page_for_posts properties to the language objects | |
| 70 | + * adds page_on_front and page_for_posts properties to the language objects | |
| 79 | 71 | * |
| 80 | 72 | * @since 1.8 |
| 81 | 73 | * |
| 82 | - * @param array $languages | |
| 74 | + * @param array $languages | |
| 83 | 75 | * @param object $model |
| 84 | 76 | */ |
| 85 | 77 | public static function pll_languages_list( $languages, $model ) { |
| 86 | - if ( 'page' === get_option( 'show_on_front' ) ) { | |
| 87 | - foreach ( $languages as $k => $language ) { | |
| 88 | - $languages[ $k ]->page_on_front = $model->post->get( get_option( 'page_on_front' ), $language ); | |
| 89 | - $languages[ $k ]->page_for_posts = $model->post->get( get_option( 'page_for_posts' ), $language ); | |
| 90 | - } | |
| 78 | + foreach ( $languages as $k => $language ) { | |
| 79 | + $languages[ $k ]->page_on_front = $model->post->get( get_option( 'page_on_front' ), $language ); | |
| 80 | + $languages[ $k ]->page_for_posts = $model->post->get( get_option( 'page_for_posts' ), $language ); | |
| 91 | 81 | } |
| 92 | 82 | |
| 93 | 83 | return $languages; |
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * Translates page for posts | |
| 98 | - * | |
| 99 | - * @since 1.8 | |
| 100 | - * | |
| 101 | - * @param int $v page for posts page id | |
| 102 | - * @return int | |
| 103 | - */ | |
| 104 | - public function translate_page_for_posts( $v ) { | |
| 105 | - // Don't attempt to translate in a 'switch_blog' action as there is a risk to call this function while initializing the languages cache | |
| 106 | - return isset( $this->curlang->page_for_posts ) && ( $this->curlang->page_for_posts ) && ! doing_action( 'switch_blog' ) ? $this->curlang->page_for_posts : $v; | |
| 107 | - } | |
| 108 | - | |
| 109 | - /** | |
| 110 | - * Fixes the oembed for the translated static front page | |
| 111 | - * when the language page is redirected to the front page | |
| 112 | - * | |
| 113 | - * @since 2.6 | |
| 114 | - * | |
| 115 | - * @param int $post_id The post ID. | |
| 116 | - * @param string $url The requested URL. | |
| 117 | - */ | |
| 118 | - public function oembed_request_post_id( $post_id, $url ) { | |
| 119 | - foreach ( $this->model->get_languages_list() as $lang ) { | |
| 120 | - if ( trailingslashit( $url ) === trailingslashit( $lang->home_url ) ) { | |
| 121 | - $post_id = $lang->page_on_front; | |
| 122 | - } | |
| 123 | - } | |
| 124 | - return $post_id; | |
| 125 | 84 | } |
| 126 | 85 | } |