Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/wordpres.../src/surfaces
File: meta-surface.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Surfaces;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Context\Meta_Tags_Context;
[4] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexable_Helper;
[5] Fix | Delete
use Yoast\WP\SEO\Memoizers\Meta_Tags_Context_Memoizer;
[6] Fix | Delete
use Yoast\WP\SEO\Models\Indexable;
[7] Fix | Delete
use Yoast\WP\SEO\Repositories\Indexable_Repository;
[8] Fix | Delete
use Yoast\WP\SEO\Surfaces\Values\Meta;
[9] Fix | Delete
use Yoast\WP\SEO\Wrappers\WP_Rewrite_Wrapper;
[10] Fix | Delete
use YoastSEO_Vendor\Symfony\Component\DependencyInjection\ContainerInterface;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Meta_Surface class.
[14] Fix | Delete
*
[15] Fix | Delete
* Surface for the indexables.
[16] Fix | Delete
*/
[17] Fix | Delete
class Meta_Surface {
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* The container.
[21] Fix | Delete
*
[22] Fix | Delete
* @var ContainerInterface
[23] Fix | Delete
*/
[24] Fix | Delete
private $container;
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* The memoizer for the meta tags context.
[28] Fix | Delete
*
[29] Fix | Delete
* @var Meta_Tags_Context_Memoizer
[30] Fix | Delete
*/
[31] Fix | Delete
private $context_memoizer;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* The indexable repository.
[35] Fix | Delete
*
[36] Fix | Delete
* @var Indexable_Repository
[37] Fix | Delete
*/
[38] Fix | Delete
private $repository;
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Holds the WP rewrite wrapper instance.
[42] Fix | Delete
*
[43] Fix | Delete
* @var WP_Rewrite_Wrapper
[44] Fix | Delete
*/
[45] Fix | Delete
private $wp_rewrite_wrapper;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* The indexable helper.
[49] Fix | Delete
*
[50] Fix | Delete
* @var Indexable_Helper
[51] Fix | Delete
*/
[52] Fix | Delete
private $indexable_helper;
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Meta_Surface constructor.
[56] Fix | Delete
*
[57] Fix | Delete
* @param ContainerInterface $container The DI container.
[58] Fix | Delete
* @param Meta_Tags_Context_Memoizer $context_memoizer The meta tags context memoizer.
[59] Fix | Delete
* @param Indexable_Repository $indexable_repository The indexable repository.
[60] Fix | Delete
* @param WP_Rewrite_Wrapper $wp_rewrite_wrapper The WP rewrite wrapper.
[61] Fix | Delete
* @param Indexable_Helper $indexable_helper The indexable helper.
[62] Fix | Delete
*/
[63] Fix | Delete
public function __construct(
[64] Fix | Delete
ContainerInterface $container,
[65] Fix | Delete
Meta_Tags_Context_Memoizer $context_memoizer,
[66] Fix | Delete
Indexable_Repository $indexable_repository,
[67] Fix | Delete
WP_Rewrite_Wrapper $wp_rewrite_wrapper,
[68] Fix | Delete
Indexable_Helper $indexable_helper
[69] Fix | Delete
) {
[70] Fix | Delete
$this->container = $container;
[71] Fix | Delete
$this->context_memoizer = $context_memoizer;
[72] Fix | Delete
$this->repository = $indexable_repository;
[73] Fix | Delete
$this->wp_rewrite_wrapper = $wp_rewrite_wrapper;
[74] Fix | Delete
$this->indexable_helper = $indexable_helper;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Returns the meta tags context for the current page.
[79] Fix | Delete
*
[80] Fix | Delete
* @return Meta The meta values.
[81] Fix | Delete
*/
[82] Fix | Delete
public function for_current_page() {
[83] Fix | Delete
return $this->build_meta( $this->context_memoizer->for_current_page() );
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Returns the meta tags context for the home page.
[88] Fix | Delete
*
[89] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[90] Fix | Delete
*/
[91] Fix | Delete
public function for_home_page() {
[92] Fix | Delete
$front_page_id = (int) \get_option( 'page_on_front' );
[93] Fix | Delete
if ( \get_option( 'show_on_front' ) === 'page' && $front_page_id !== 0 ) {
[94] Fix | Delete
$indexable = $this->repository->find_by_id_and_type( $front_page_id, 'post' );
[95] Fix | Delete
[96] Fix | Delete
if ( ! $indexable ) {
[97] Fix | Delete
return false;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Static_Home_Page' ) );
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
$indexable = $this->repository->find_for_home_page();
[104] Fix | Delete
[105] Fix | Delete
if ( ! $indexable ) {
[106] Fix | Delete
return false;
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Home_Page' ) );
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Returns the meta tags context for the posts page.
[114] Fix | Delete
*
[115] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[116] Fix | Delete
*/
[117] Fix | Delete
public function for_posts_page() {
[118] Fix | Delete
$posts_page_id = (int) \get_option( 'page_for_posts' );
[119] Fix | Delete
if ( $posts_page_id !== 0 ) {
[120] Fix | Delete
$indexable = $this->repository->find_by_id_and_type( $posts_page_id, 'post' );
[121] Fix | Delete
[122] Fix | Delete
if ( ! $indexable ) {
[123] Fix | Delete
return false;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Static_Posts_Page' ) );
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
$indexable = $this->repository->find_for_home_page();
[130] Fix | Delete
[131] Fix | Delete
if ( ! $indexable ) {
[132] Fix | Delete
return false;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Home_Page' ) );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Returns the meta tags context for a post type archive.
[140] Fix | Delete
*
[141] Fix | Delete
* @param string|null $post_type Optional. The post type to get the archive meta for. Defaults to the current post type.
[142] Fix | Delete
*
[143] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[144] Fix | Delete
*/
[145] Fix | Delete
public function for_post_type_archive( $post_type = null ) {
[146] Fix | Delete
if ( $post_type === null ) {
[147] Fix | Delete
$post_type = \get_post_type();
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
$indexable = $this->repository->find_for_post_type_archive( $post_type );
[151] Fix | Delete
[152] Fix | Delete
if ( ! $indexable ) {
[153] Fix | Delete
return false;
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Post_Type_Archive' ) );
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Returns the meta tags context for the search result page.
[161] Fix | Delete
*
[162] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[163] Fix | Delete
*/
[164] Fix | Delete
public function for_search_result() {
[165] Fix | Delete
$indexable = $this->repository->find_for_system_page( 'search-result' );
[166] Fix | Delete
[167] Fix | Delete
if ( ! $indexable ) {
[168] Fix | Delete
return false;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Search_Result_Page' ) );
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Returns the meta tags context for the search result page.
[176] Fix | Delete
*
[177] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[178] Fix | Delete
*/
[179] Fix | Delete
public function for_404() {
[180] Fix | Delete
$indexable = $this->repository->find_for_system_page( '404' );
[181] Fix | Delete
[182] Fix | Delete
if ( ! $indexable ) {
[183] Fix | Delete
return false;
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Error_Page' ) );
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Returns the meta tags context for a post.
[191] Fix | Delete
*
[192] Fix | Delete
* @param int $id The ID of the post.
[193] Fix | Delete
*
[194] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[195] Fix | Delete
*/
[196] Fix | Delete
public function for_post( $id ) {
[197] Fix | Delete
$indexable = $this->repository->find_by_id_and_type( $id, 'post' );
[198] Fix | Delete
[199] Fix | Delete
if ( ! $indexable ) {
[200] Fix | Delete
return false;
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Post_Type' ) );
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
/**
[207] Fix | Delete
* Returns the meta tags context for a number of posts.
[208] Fix | Delete
*
[209] Fix | Delete
* @param int[] $ids The IDs of the posts.
[210] Fix | Delete
*
[211] Fix | Delete
* @return Meta[]|false The meta values. False if none could be found.
[212] Fix | Delete
*/
[213] Fix | Delete
public function for_posts( $ids ) {
[214] Fix | Delete
$indexables = $this->repository->find_by_multiple_ids_and_type( $ids, 'post' );
[215] Fix | Delete
[216] Fix | Delete
if ( empty( $indexables ) ) {
[217] Fix | Delete
return false;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
// Remove all false values.
[221] Fix | Delete
$indexables = \array_filter( $indexables );
[222] Fix | Delete
[223] Fix | Delete
return \array_map(
[224] Fix | Delete
function ( $indexable ) {
[225] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Post_Type' ) );
[226] Fix | Delete
},
[227] Fix | Delete
$indexables
[228] Fix | Delete
);
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
/**
[232] Fix | Delete
* Returns the meta tags context for a term.
[233] Fix | Delete
*
[234] Fix | Delete
* @param int $id The ID of the term.
[235] Fix | Delete
*
[236] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[237] Fix | Delete
*/
[238] Fix | Delete
public function for_term( $id ) {
[239] Fix | Delete
$indexable = $this->repository->find_by_id_and_type( $id, 'term' );
[240] Fix | Delete
[241] Fix | Delete
if ( ! $indexable ) {
[242] Fix | Delete
return false;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Term_Archive' ) );
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Returns the meta tags context for an author.
[250] Fix | Delete
*
[251] Fix | Delete
* @param int $id The ID of the author.
[252] Fix | Delete
*
[253] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[254] Fix | Delete
*/
[255] Fix | Delete
public function for_author( $id ) {
[256] Fix | Delete
$indexable = $this->repository->find_by_id_and_type( $id, 'user' );
[257] Fix | Delete
[258] Fix | Delete
if ( ! $indexable ) {
[259] Fix | Delete
return false;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, 'Author_Archive' ) );
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Returns the meta for an indexable.
[267] Fix | Delete
*
[268] Fix | Delete
* @param Indexable $indexable The indexable.
[269] Fix | Delete
* @param string|null $page_type Optional. The page type if already known.
[270] Fix | Delete
*
[271] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[272] Fix | Delete
*/
[273] Fix | Delete
public function for_indexable( $indexable, $page_type = null ) {
[274] Fix | Delete
[275] Fix | Delete
if ( ! \is_a( $indexable, Indexable::class ) ) {
[276] Fix | Delete
return false;
[277] Fix | Delete
}
[278] Fix | Delete
if ( \is_null( $page_type ) ) {
[279] Fix | Delete
$page_type = $this->indexable_helper->get_page_type_for_indexable( $indexable );
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, $page_type ) );
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
/**
[286] Fix | Delete
* Returns the meta for an indexable.
[287] Fix | Delete
*
[288] Fix | Delete
* @param Indexable[] $indexables The indexables.
[289] Fix | Delete
* @param string|null $page_type Optional. The page type if already known.
[290] Fix | Delete
*
[291] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[292] Fix | Delete
*/
[293] Fix | Delete
public function for_indexables( $indexables, $page_type = null ) {
[294] Fix | Delete
$closure = function ( $indexable ) use ( $page_type ) {
[295] Fix | Delete
$this_page_type = $page_type;
[296] Fix | Delete
if ( \is_null( $this_page_type ) ) {
[297] Fix | Delete
$this_page_type = $this->indexable_helper->get_page_type_for_indexable( $indexable );
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, $this_page_type ) );
[301] Fix | Delete
};
[302] Fix | Delete
[303] Fix | Delete
return \array_map( $closure, $indexables );
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
/**
[307] Fix | Delete
* Returns the meta tags context for a url.
[308] Fix | Delete
*
[309] Fix | Delete
* @param string $url The url of the page. Required to be relative to the site url.
[310] Fix | Delete
*
[311] Fix | Delete
* @return Meta|false The meta values. False if none could be found.
[312] Fix | Delete
*/
[313] Fix | Delete
public function for_url( $url ) {
[314] Fix | Delete
$url_parts = \wp_parse_url( $url );
[315] Fix | Delete
$site_parts = \wp_parse_url( \site_url() );
[316] Fix | Delete
[317] Fix | Delete
if ( ( ! \is_array( $url_parts ) || ! \is_array( $site_parts ) )
[318] Fix | Delete
|| ! isset( $url_parts['host'], $url_parts['path'], $site_parts['host'], $site_parts['scheme'] )
[319] Fix | Delete
) {
[320] Fix | Delete
return false;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
if ( $url_parts['host'] !== $site_parts['host'] ) {
[324] Fix | Delete
return false;
[325] Fix | Delete
}
[326] Fix | Delete
// Ensure the scheme is consistent with values in the DB.
[327] Fix | Delete
$url = $site_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path'];
[328] Fix | Delete
[329] Fix | Delete
if ( $this->is_date_archive_url( $url ) ) {
[330] Fix | Delete
$indexable = $this->repository->find_for_date_archive();
[331] Fix | Delete
}
[332] Fix | Delete
else {
[333] Fix | Delete
$indexable = $this->repository->find_by_permalink( $url );
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
// If we still don't have an indexable abort, the WP globals could be anything so we can't use the unknown indexable.
[337] Fix | Delete
if ( ! $indexable ) {
[338] Fix | Delete
return false;
[339] Fix | Delete
}
[340] Fix | Delete
$page_type = $this->indexable_helper->get_page_type_for_indexable( $indexable );
[341] Fix | Delete
[342] Fix | Delete
if ( $page_type === false ) {
[343] Fix | Delete
return false;
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
return $this->build_meta( $this->context_memoizer->get( $indexable, $page_type ) );
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
/**
[350] Fix | Delete
* Checks if a given URL is a date archive URL.
[351] Fix | Delete
*
[352] Fix | Delete
* @param string $url The url.
[353] Fix | Delete
*
[354] Fix | Delete
* @return bool
[355] Fix | Delete
*/
[356] Fix | Delete
protected function is_date_archive_url( $url ) {
[357] Fix | Delete
$path = \wp_parse_url( $url, \PHP_URL_PATH );
[358] Fix | Delete
if ( $path === null ) {
[359] Fix | Delete
return false;
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
$path = \ltrim( $path, '/' );
[363] Fix | Delete
$wp_rewrite = $this->wp_rewrite_wrapper->get();
[364] Fix | Delete
$date_rewrite = $wp_rewrite->generate_rewrite_rules( $wp_rewrite->get_date_permastruct(), \EP_DATE );
[365] Fix | Delete
$date_rewrite = \apply_filters( 'date_rewrite_rules', $date_rewrite );
[366] Fix | Delete
[367] Fix | Delete
foreach ( (array) $date_rewrite as $match => $query ) {
[368] Fix | Delete
if ( \preg_match( "#^$match#", $path ) ) {
[369] Fix | Delete
return true;
[370] Fix | Delete
}
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
return false;
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* Creates a new meta value object
[378] Fix | Delete
*
[379] Fix | Delete
* @param Meta_Tags_Context $context The meta tags context.
[380] Fix | Delete
*
[381] Fix | Delete
* @return Meta The meta value
[382] Fix | Delete
*/
[383] Fix | Delete
protected function build_meta( Meta_Tags_Context $context ) {
[384] Fix | Delete
return new Meta( $context, $this->container );
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function