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

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/builders
File: indexable-link-builder.php
}
[500] Fix | Delete
[501] Fix | Delete
[ , $width, $height ] = \wp_get_attachment_image_src( $model->target_post_id, 'full' );
[502] Fix | Delete
$model->width = $width;
[503] Fix | Delete
$model->height = $height;
[504] Fix | Delete
}
[505] Fix | Delete
else {
[506] Fix | Delete
$model->width = 0;
[507] Fix | Delete
$model->height = 0;
[508] Fix | Delete
$model->size = 0;
[509] Fix | Delete
}
[510] Fix | Delete
}
[511] Fix | Delete
}
[512] Fix | Delete
[513] Fix | Delete
return $model;
[514] Fix | Delete
}
[515] Fix | Delete
[516] Fix | Delete
/**
[517] Fix | Delete
* Enhances the link model with information from its indexable.
[518] Fix | Delete
*
[519] Fix | Delete
* @param SEO_Links $model The link's model.
[520] Fix | Delete
* @param string $permalink The link's permalink.
[521] Fix | Delete
*
[522] Fix | Delete
* @return SEO_Links The enhanced link model.
[523] Fix | Delete
*/
[524] Fix | Delete
protected function enhance_link_from_indexable( $model, $permalink ) {
[525] Fix | Delete
$target = $this->indexable_repository->find_by_permalink( $permalink );
[526] Fix | Delete
[527] Fix | Delete
if ( ! $target ) {
[528] Fix | Delete
// If target indexable cannot be found, create one based on the post's post ID.
[529] Fix | Delete
$post_id = $this->get_post_id( $model->type, $permalink );
[530] Fix | Delete
if ( $post_id && $post_id !== 0 ) {
[531] Fix | Delete
$target = $this->indexable_repository->find_by_id_and_type( $post_id, 'post' );
[532] Fix | Delete
}
[533] Fix | Delete
}
[534] Fix | Delete
[535] Fix | Delete
if ( ! $target ) {
[536] Fix | Delete
return $model;
[537] Fix | Delete
}
[538] Fix | Delete
[539] Fix | Delete
$model->target_indexable_id = $target->id;
[540] Fix | Delete
if ( $target->object_type === 'post' ) {
[541] Fix | Delete
$model->target_post_id = $target->object_id;
[542] Fix | Delete
}
[543] Fix | Delete
[544] Fix | Delete
if ( $model->target_indexable_id ) {
[545] Fix | Delete
$model->language = $target->language;
[546] Fix | Delete
$model->region = $target->region;
[547] Fix | Delete
}
[548] Fix | Delete
[549] Fix | Delete
return $model;
[550] Fix | Delete
}
[551] Fix | Delete
[552] Fix | Delete
/**
[553] Fix | Delete
* Builds the link's permalink.
[554] Fix | Delete
*
[555] Fix | Delete
* @param string $url The url of the link.
[556] Fix | Delete
* @param array $home_url The home url, as parsed by wp_parse_url.
[557] Fix | Delete
*
[558] Fix | Delete
* @return string The link's permalink.
[559] Fix | Delete
*/
[560] Fix | Delete
protected function build_permalink( $url, $home_url ) {
[561] Fix | Delete
$permalink = $this->get_permalink( $url, $home_url );
[562] Fix | Delete
[563] Fix | Delete
if ( $this->url_helper->is_relative( $permalink ) ) {
[564] Fix | Delete
// Make sure we're checking against the absolute URL, and add a trailing slash if the site has a trailing slash in its permalink settings.
[565] Fix | Delete
$permalink = $this->url_helper->ensure_absolute_url( \user_trailingslashit( $permalink ) );
[566] Fix | Delete
}
[567] Fix | Delete
[568] Fix | Delete
return $permalink;
[569] Fix | Delete
}
[570] Fix | Delete
[571] Fix | Delete
/**
[572] Fix | Delete
* Filters out links that point to the same page with a fragment or query.
[573] Fix | Delete
*
[574] Fix | Delete
* @param SEO_Links $link The link.
[575] Fix | Delete
* @param array $current_url The url of the page the link is on, as parsed by wp_parse_url.
[576] Fix | Delete
*
[577] Fix | Delete
* @return bool Whether or not the link should be filtered.
[578] Fix | Delete
*/
[579] Fix | Delete
protected function filter_link( SEO_Links $link, $current_url ) {
[580] Fix | Delete
$url = $link->parsed_url;
[581] Fix | Delete
[582] Fix | Delete
// Always keep external links.
[583] Fix | Delete
if ( $link->type === SEO_Links::TYPE_EXTERNAL ) {
[584] Fix | Delete
return true;
[585] Fix | Delete
}
[586] Fix | Delete
[587] Fix | Delete
// Always keep links with an empty path or pointing to other pages.
[588] Fix | Delete
if ( isset( $url['path'] ) ) {
[589] Fix | Delete
return empty( $url['path'] ) || $url['path'] !== $current_url['path'];
[590] Fix | Delete
}
[591] Fix | Delete
[592] Fix | Delete
// Only keep links to the current page without a fragment or query.
[593] Fix | Delete
return ( ! isset( $url['fragment'] ) && ! isset( $url['query'] ) );
[594] Fix | Delete
}
[595] Fix | Delete
[596] Fix | Delete
/**
[597] Fix | Delete
* Updates the link counts for related indexables.
[598] Fix | Delete
*
[599] Fix | Delete
* @param Indexable $indexable The indexable.
[600] Fix | Delete
* @param SEO_Links[] $links The link models.
[601] Fix | Delete
*
[602] Fix | Delete
* @return void
[603] Fix | Delete
*/
[604] Fix | Delete
protected function update_related_indexables( $indexable, $links ) {
[605] Fix | Delete
// Old links were only stored by post id, so remove all old seo links for this post that have no indexable id.
[606] Fix | Delete
// This can be removed if we ever fully clear all seo links.
[607] Fix | Delete
if ( $indexable->object_type === 'post' ) {
[608] Fix | Delete
$this->seo_links_repository->delete_all_by_post_id_where_indexable_id_null( $indexable->object_id );
[609] Fix | Delete
}
[610] Fix | Delete
[611] Fix | Delete
$updated_indexable_ids = [];
[612] Fix | Delete
$old_links = $this->seo_links_repository->find_all_by_indexable_id( $indexable->id );
[613] Fix | Delete
[614] Fix | Delete
$links_to_remove = $this->links_diff( $old_links, $links );
[615] Fix | Delete
$links_to_add = $this->links_diff( $links, $old_links );
[616] Fix | Delete
[617] Fix | Delete
if ( ! empty( $links_to_remove ) ) {
[618] Fix | Delete
$this->seo_links_repository->delete_many_by_id( \wp_list_pluck( $links_to_remove, 'id' ) );
[619] Fix | Delete
}
[620] Fix | Delete
[621] Fix | Delete
if ( ! empty( $links_to_add ) ) {
[622] Fix | Delete
$this->seo_links_repository->insert_many( $links_to_add );
[623] Fix | Delete
}
[624] Fix | Delete
[625] Fix | Delete
foreach ( $links_to_add as $link ) {
[626] Fix | Delete
if ( $link->target_indexable_id ) {
[627] Fix | Delete
$updated_indexable_ids[] = $link->target_indexable_id;
[628] Fix | Delete
}
[629] Fix | Delete
}
[630] Fix | Delete
foreach ( $links_to_remove as $link ) {
[631] Fix | Delete
if ( $link->target_indexable_id ) {
[632] Fix | Delete
$updated_indexable_ids[] = $link->target_indexable_id;
[633] Fix | Delete
}
[634] Fix | Delete
}
[635] Fix | Delete
[636] Fix | Delete
$this->update_incoming_links_for_related_indexables( $updated_indexable_ids );
[637] Fix | Delete
}
[638] Fix | Delete
[639] Fix | Delete
/**
[640] Fix | Delete
* Creates a diff between two arrays of SEO links, based on urls.
[641] Fix | Delete
*
[642] Fix | Delete
* @param SEO_Links[] $links_a The array to compare.
[643] Fix | Delete
* @param SEO_Links[] $links_b The array to compare against.
[644] Fix | Delete
*
[645] Fix | Delete
* @return SEO_Links[] Links that are in $links_a, but not in $links_b.
[646] Fix | Delete
*/
[647] Fix | Delete
protected function links_diff( $links_a, $links_b ) {
[648] Fix | Delete
return \array_udiff(
[649] Fix | Delete
$links_a,
[650] Fix | Delete
$links_b,
[651] Fix | Delete
static function ( SEO_Links $link_a, SEO_Links $link_b ) {
[652] Fix | Delete
return \strcmp( $link_a->url, $link_b->url );
[653] Fix | Delete
}
[654] Fix | Delete
);
[655] Fix | Delete
}
[656] Fix | Delete
[657] Fix | Delete
/**
[658] Fix | Delete
* Returns the number of internal links in an array of link models.
[659] Fix | Delete
*
[660] Fix | Delete
* @param SEO_Links[] $links The link models.
[661] Fix | Delete
*
[662] Fix | Delete
* @return int The number of internal links.
[663] Fix | Delete
*/
[664] Fix | Delete
protected function get_internal_link_count( $links ) {
[665] Fix | Delete
$internal_link_count = 0;
[666] Fix | Delete
[667] Fix | Delete
foreach ( $links as $link ) {
[668] Fix | Delete
if ( $link->type === SEO_Links::TYPE_INTERNAL ) {
[669] Fix | Delete
++$internal_link_count;
[670] Fix | Delete
}
[671] Fix | Delete
}
[672] Fix | Delete
[673] Fix | Delete
return $internal_link_count;
[674] Fix | Delete
}
[675] Fix | Delete
[676] Fix | Delete
/**
[677] Fix | Delete
* Returns a cleaned permalink for a given link.
[678] Fix | Delete
*
[679] Fix | Delete
* @param string $link The raw URL.
[680] Fix | Delete
* @param array $home_url The home URL, as parsed by wp_parse_url.
[681] Fix | Delete
*
[682] Fix | Delete
* @return string The cleaned permalink.
[683] Fix | Delete
*/
[684] Fix | Delete
protected function get_permalink( $link, $home_url ) {
[685] Fix | Delete
// Get rid of the #anchor.
[686] Fix | Delete
$url_split = \explode( '#', $link );
[687] Fix | Delete
$link = $url_split[0];
[688] Fix | Delete
[689] Fix | Delete
// Get rid of URL ?query=string.
[690] Fix | Delete
$url_split = \explode( '?', $link );
[691] Fix | Delete
$link = $url_split[0];
[692] Fix | Delete
[693] Fix | Delete
// Set the correct URL scheme.
[694] Fix | Delete
$link = \set_url_scheme( $link, $home_url['scheme'] );
[695] Fix | Delete
[696] Fix | Delete
// Add 'www.' if it is absent and should be there.
[697] Fix | Delete
if ( \strpos( $home_url['host'], 'www.' ) === 0 && \strpos( $link, '://www.' ) === false ) {
[698] Fix | Delete
$link = \str_replace( '://', '://www.', $link );
[699] Fix | Delete
}
[700] Fix | Delete
[701] Fix | Delete
// Strip 'www.' if it is present and shouldn't be.
[702] Fix | Delete
if ( \strpos( $home_url['host'], 'www.' ) !== 0 ) {
[703] Fix | Delete
$link = \str_replace( '://www.', '://', $link );
[704] Fix | Delete
}
[705] Fix | Delete
[706] Fix | Delete
return $link;
[707] Fix | Delete
}
[708] Fix | Delete
[709] Fix | Delete
/**
[710] Fix | Delete
* Updates incoming link counts for related indexables.
[711] Fix | Delete
*
[712] Fix | Delete
* @param int[] $related_indexable_ids The IDs of all related indexables.
[713] Fix | Delete
*
[714] Fix | Delete
* @return void
[715] Fix | Delete
*/
[716] Fix | Delete
protected function update_incoming_links_for_related_indexables( $related_indexable_ids ) {
[717] Fix | Delete
if ( empty( $related_indexable_ids ) ) {
[718] Fix | Delete
return;
[719] Fix | Delete
}
[720] Fix | Delete
[721] Fix | Delete
$counts = $this->seo_links_repository->get_incoming_link_counts_for_indexable_ids( $related_indexable_ids );
[722] Fix | Delete
if ( \wp_cache_supports( 'flush_group' ) ) {
[723] Fix | Delete
\wp_cache_flush_group( 'orphaned_counts' );
[724] Fix | Delete
}
[725] Fix | Delete
[726] Fix | Delete
foreach ( $counts as $count ) {
[727] Fix | Delete
$this->indexable_repository->update_incoming_link_count( $count['target_indexable_id'], $count['incoming'] );
[728] Fix | Delete
}
[729] Fix | Delete
}
[730] Fix | Delete
}
[731] Fix | Delete
[732] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function