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.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/reposito...
File: seo-links-repository.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Repositories;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\Lib\Model;
[4] Fix | Delete
use Yoast\WP\Lib\ORM;
[5] Fix | Delete
use Yoast\WP\SEO\Models\SEO_Links;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Class SEO_Links_Repository.
[9] Fix | Delete
*/
[10] Fix | Delete
class SEO_Links_Repository {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Starts a query for this repository.
[14] Fix | Delete
*
[15] Fix | Delete
* @return ORM
[16] Fix | Delete
*/
[17] Fix | Delete
public function query() {
[18] Fix | Delete
return Model::of_type( 'SEO_Links' );
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Finds all SEO Links by post ID.
[23] Fix | Delete
*
[24] Fix | Delete
* @param int $post_id The post ID.
[25] Fix | Delete
*
[26] Fix | Delete
* @return SEO_Links[] The SEO Links.
[27] Fix | Delete
*/
[28] Fix | Delete
public function find_all_by_post_id( $post_id ) {
[29] Fix | Delete
return $this->query()
[30] Fix | Delete
->where( 'post_id', $post_id )
[31] Fix | Delete
->find_many();
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Finds all SEO Links by indexable ID.
[36] Fix | Delete
*
[37] Fix | Delete
* @param int $indexable_id The indexable ID.
[38] Fix | Delete
*
[39] Fix | Delete
* @return SEO_Links[] The SEO Links.
[40] Fix | Delete
*/
[41] Fix | Delete
public function find_all_by_indexable_id( $indexable_id ) {
[42] Fix | Delete
return $this->query()
[43] Fix | Delete
->where( 'indexable_id', $indexable_id )
[44] Fix | Delete
->find_many();
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Retrieves an SEO Link by url.
[49] Fix | Delete
*
[50] Fix | Delete
* @param string $url The SEO Link's url.
[51] Fix | Delete
*
[52] Fix | Delete
* @return SEO_Links|false The SEO Link, or false if none found.
[53] Fix | Delete
*/
[54] Fix | Delete
public function find_one_by_url( $url ) {
[55] Fix | Delete
return $this->query()
[56] Fix | Delete
->select( 'target_post_id' )
[57] Fix | Delete
->where( 'url', $url )
[58] Fix | Delete
->find_one();
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Retrieves all SEO Links by target post ID.
[63] Fix | Delete
*
[64] Fix | Delete
* @param string $target_post_id The SEO Link's target post ID.
[65] Fix | Delete
*
[66] Fix | Delete
* @return SEO_Links[] The SEO Links.
[67] Fix | Delete
*/
[68] Fix | Delete
public function find_all_by_target_post_id( $target_post_id ) {
[69] Fix | Delete
return $this->query()
[70] Fix | Delete
->where( 'target_post_id', $target_post_id )
[71] Fix | Delete
->find_many();
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Updates the ID of the target indexable of a link.
[76] Fix | Delete
*
[77] Fix | Delete
* @param int $link_id The ID of the link to be updated.
[78] Fix | Delete
* @param int $target_indexable_id The ID of the target indexable.
[79] Fix | Delete
*
[80] Fix | Delete
* @return bool Whether or not the update was succeful.
[81] Fix | Delete
*/
[82] Fix | Delete
public function update_target_indexable_id( $link_id, $target_indexable_id ) {
[83] Fix | Delete
return (bool) $this->query()
[84] Fix | Delete
->set( 'target_indexable_id', $target_indexable_id )
[85] Fix | Delete
->where( 'id', $link_id )
[86] Fix | Delete
->update_many();
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Clears all SEO Links by post ID.
[91] Fix | Delete
*
[92] Fix | Delete
* @param int $post_id The post ID.
[93] Fix | Delete
*
[94] Fix | Delete
* @return bool Whether or not the delete was succesfull.
[95] Fix | Delete
*/
[96] Fix | Delete
public function delete_all_by_post_id( $post_id ) {
[97] Fix | Delete
return $this->query()
[98] Fix | Delete
->where( 'post_id', $post_id )
[99] Fix | Delete
->delete_many();
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Clears all SEO Links by post ID where the indexable id is null.
[104] Fix | Delete
*
[105] Fix | Delete
* @param int $post_id The post ID.
[106] Fix | Delete
*
[107] Fix | Delete
* @return bool Whether or not the delete was succesfull.
[108] Fix | Delete
*/
[109] Fix | Delete
public function delete_all_by_post_id_where_indexable_id_null( $post_id ) {
[110] Fix | Delete
return $this->query()
[111] Fix | Delete
->where( 'post_id', $post_id )
[112] Fix | Delete
->where_null( 'indexable_id' )
[113] Fix | Delete
->delete_many();
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Clears all SEO Links by indexable ID.
[118] Fix | Delete
*
[119] Fix | Delete
* @param int $indexable_id The indexable ID.
[120] Fix | Delete
*
[121] Fix | Delete
* @return bool Whether or not the delete was succesfull.
[122] Fix | Delete
*/
[123] Fix | Delete
public function delete_all_by_indexable_id( $indexable_id ) {
[124] Fix | Delete
return $this->query()
[125] Fix | Delete
->where( 'indexable_id', $indexable_id )
[126] Fix | Delete
->delete_many();
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/**
[130] Fix | Delete
* Returns incoming link counts for a number of posts.
[131] Fix | Delete
*
[132] Fix | Delete
* @param array $post_ids The post IDs.
[133] Fix | Delete
*
[134] Fix | Delete
* @return array An array of associative arrays, each containing a post id and incoming property.
[135] Fix | Delete
*/
[136] Fix | Delete
public function get_incoming_link_counts_for_post_ids( $post_ids ) {
[137] Fix | Delete
return $this->query()
[138] Fix | Delete
->select_expr( 'COUNT( id )', 'incoming' )
[139] Fix | Delete
->select( 'target_post_id', 'post_id' )
[140] Fix | Delete
->where_in( 'target_post_id', $post_ids )
[141] Fix | Delete
->group_by( 'target_post_id' )
[142] Fix | Delete
->find_array();
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Returns incoming link counts for a number of indexables.
[147] Fix | Delete
*
[148] Fix | Delete
* @param array $indexable_ids The indexable IDs.
[149] Fix | Delete
*
[150] Fix | Delete
* @return array An array of associative arrays, each containing a indexable id and incoming property.
[151] Fix | Delete
*/
[152] Fix | Delete
public function get_incoming_link_counts_for_indexable_ids( $indexable_ids ) {
[153] Fix | Delete
if ( empty( $indexable_ids ) ) {
[154] Fix | Delete
return [];
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
// This query only returns ID's with an incoming count > 0. We need to restore any ID's with 0 incoming links later.
[158] Fix | Delete
$indexable_counts = $this->query()
[159] Fix | Delete
->select_expr( 'COUNT( id )', 'incoming' )
[160] Fix | Delete
->select( 'target_indexable_id' )
[161] Fix | Delete
->where_in( 'target_indexable_id', $indexable_ids )
[162] Fix | Delete
->group_by( 'target_indexable_id' )
[163] Fix | Delete
->find_array();
[164] Fix | Delete
[165] Fix | Delete
// If the above query fails, do not update anything.
[166] Fix | Delete
if ( ! \is_array( $indexable_counts ) ) {
[167] Fix | Delete
return [];
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
// Get all ID's returned from the query and set them as keys for easy access.
[171] Fix | Delete
$returned_ids = \array_flip( \array_column( $indexable_counts, 'target_indexable_id' ) );
[172] Fix | Delete
[173] Fix | Delete
// Loop over the original ID's and search them in the returned ID's. If they don't exist, add them with an incoming count of 0.
[174] Fix | Delete
foreach ( $indexable_ids as $id ) {
[175] Fix | Delete
// Cast the ID to string, as the arrays only contain stringified versions of the ID.
[176] Fix | Delete
$id = \strval( $id );
[177] Fix | Delete
if ( isset( $returned_ids[ $id ] ) === false ) {
[178] Fix | Delete
$indexable_counts[] = [
[179] Fix | Delete
'incoming' => '0',
[180] Fix | Delete
'target_indexable_id' => $id,
[181] Fix | Delete
];
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
return $indexable_counts;
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Deletes all seo links for the given ids.
[190] Fix | Delete
*
[191] Fix | Delete
* @param int[] $ids The seo link ids.
[192] Fix | Delete
*
[193] Fix | Delete
* @return bool Whether or not the delete was succesfull.
[194] Fix | Delete
*/
[195] Fix | Delete
public function delete_many_by_id( $ids ) {
[196] Fix | Delete
return $this->query()
[197] Fix | Delete
->where_in( 'id', $ids )
[198] Fix | Delete
->delete_many();
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Insert multiple seo links.
[203] Fix | Delete
*
[204] Fix | Delete
* @param SEO_Links[] $links The seo links to be inserted.
[205] Fix | Delete
*
[206] Fix | Delete
* @return bool Whether or not the insert was succesfull.
[207] Fix | Delete
*/
[208] Fix | Delete
public function insert_many( $links ) {
[209] Fix | Delete
return $this->query()
[210] Fix | Delete
->insert_many( $links );
[211] Fix | Delete
}
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function