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/helpers
File: indexing-helper.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Helpers;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_General_Indexation_Action;
[4] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Post_Indexation_Action;
[5] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Post_Type_Archive_Indexation_Action;
[6] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Term_Indexation_Action;
[7] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexation_Action_Interface;
[8] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Limited_Indexing_Action_Interface;
[9] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Post_Link_Indexing_Action;
[10] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Term_Link_Indexing_Action;
[11] Fix | Delete
use Yoast\WP\SEO\Config\Indexing_Reasons;
[12] Fix | Delete
use Yoast\WP\SEO\Integrations\Admin\Indexing_Notification_Integration;
[13] Fix | Delete
use Yoast\WP\SEO\Repositories\Indexable_Repository;
[14] Fix | Delete
use Yoast_Notification_Center;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* A helper object for indexing.
[18] Fix | Delete
*/
[19] Fix | Delete
class Indexing_Helper {
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* The options helper.
[23] Fix | Delete
*
[24] Fix | Delete
* @var Options_Helper
[25] Fix | Delete
*/
[26] Fix | Delete
protected $options_helper;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* The date helper.
[30] Fix | Delete
*
[31] Fix | Delete
* @var Date_Helper
[32] Fix | Delete
*/
[33] Fix | Delete
protected $date_helper;
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* The notification center.
[37] Fix | Delete
*
[38] Fix | Delete
* @var Yoast_Notification_Center
[39] Fix | Delete
*/
[40] Fix | Delete
protected $notification_center;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* The indexation actions.
[44] Fix | Delete
*
[45] Fix | Delete
* @var Indexation_Action_Interface[]|Limited_Indexing_Action_Interface[]
[46] Fix | Delete
*/
[47] Fix | Delete
protected $indexing_actions;
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* The indexation actions that can be done in the background.
[51] Fix | Delete
*
[52] Fix | Delete
* @var Indexation_Action_Interface[]|Limited_Indexing_Action_Interface[]
[53] Fix | Delete
*/
[54] Fix | Delete
protected $background_indexing_actions;
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* The indexable repository.
[58] Fix | Delete
*
[59] Fix | Delete
* @var Indexable_Repository
[60] Fix | Delete
*/
[61] Fix | Delete
protected $indexable_repository;
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Indexing_Helper constructor.
[65] Fix | Delete
*
[66] Fix | Delete
* @param Options_Helper $options_helper The options helper.
[67] Fix | Delete
* @param Date_Helper $date_helper The date helper.
[68] Fix | Delete
* @param Yoast_Notification_Center $notification_center The notification center.
[69] Fix | Delete
*/
[70] Fix | Delete
public function __construct(
[71] Fix | Delete
Options_Helper $options_helper,
[72] Fix | Delete
Date_Helper $date_helper,
[73] Fix | Delete
Yoast_Notification_Center $notification_center
[74] Fix | Delete
) {
[75] Fix | Delete
$this->options_helper = $options_helper;
[76] Fix | Delete
$this->date_helper = $date_helper;
[77] Fix | Delete
$this->notification_center = $notification_center;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Sets the actions.
[82] Fix | Delete
*
[83] Fix | Delete
* @required
[84] Fix | Delete
*
[85] Fix | Delete
* @param Indexable_Post_Indexation_Action $post_indexation The post indexing action.
[86] Fix | Delete
* @param Indexable_Term_Indexation_Action $term_indexation The term indexing action.
[87] Fix | Delete
* @param Indexable_Post_Type_Archive_Indexation_Action $post_type_archive_indexation The posttype indexing action.
[88] Fix | Delete
* @param Indexable_General_Indexation_Action $general_indexation The general indexing (homepage etc) action.
[89] Fix | Delete
* @param Post_Link_Indexing_Action $post_link_indexing_action The post crosslink indexing action.
[90] Fix | Delete
* @param Term_Link_Indexing_Action $term_link_indexing_action The term crossling indexing action.
[91] Fix | Delete
*
[92] Fix | Delete
* @return void
[93] Fix | Delete
*/
[94] Fix | Delete
public function set_indexing_actions(
[95] Fix | Delete
Indexable_Post_Indexation_Action $post_indexation,
[96] Fix | Delete
Indexable_Term_Indexation_Action $term_indexation,
[97] Fix | Delete
Indexable_Post_Type_Archive_Indexation_Action $post_type_archive_indexation,
[98] Fix | Delete
Indexable_General_Indexation_Action $general_indexation,
[99] Fix | Delete
Post_Link_Indexing_Action $post_link_indexing_action,
[100] Fix | Delete
Term_Link_Indexing_Action $term_link_indexing_action
[101] Fix | Delete
) {
[102] Fix | Delete
$this->indexing_actions = [
[103] Fix | Delete
$post_indexation,
[104] Fix | Delete
$term_indexation,
[105] Fix | Delete
$post_type_archive_indexation,
[106] Fix | Delete
$general_indexation,
[107] Fix | Delete
$post_link_indexing_action,
[108] Fix | Delete
$term_link_indexing_action,
[109] Fix | Delete
];
[110] Fix | Delete
[111] Fix | Delete
// Coincidentally, the background indexing actions are the same with the Free indexing actions for now.
[112] Fix | Delete
$this->background_indexing_actions = $this->indexing_actions;
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Sets the indexable repository for the indexing helper class.
[117] Fix | Delete
*
[118] Fix | Delete
* @required
[119] Fix | Delete
*
[120] Fix | Delete
* @param Indexable_Repository $indexable_repository The indexable repository.
[121] Fix | Delete
*
[122] Fix | Delete
* @return void
[123] Fix | Delete
*/
[124] Fix | Delete
public function set_indexable_repository(
[125] Fix | Delete
Indexable_Repository $indexable_repository
[126] Fix | Delete
) {
[127] Fix | Delete
$this->indexable_repository = $indexable_repository;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Prepares the indexing process by setting several database options and removing the indexing notification.
[132] Fix | Delete
*
[133] Fix | Delete
* @return void
[134] Fix | Delete
*/
[135] Fix | Delete
public function prepare() {
[136] Fix | Delete
$this->set_first_time( false );
[137] Fix | Delete
$this->set_started( $this->date_helper->current_time() );
[138] Fix | Delete
$this->remove_indexing_notification();
[139] Fix | Delete
// Do not set_reason here; if the process is cancelled, the reason to start indexing is still valid.
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Sets several database options when the indexing process is finished.
[144] Fix | Delete
*
[145] Fix | Delete
* @return void
[146] Fix | Delete
*/
[147] Fix | Delete
public function complete() {
[148] Fix | Delete
$this->set_reason( '' );
[149] Fix | Delete
$this->set_started( null );
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/**
[153] Fix | Delete
* Sets appropriate flags when the indexing process fails.
[154] Fix | Delete
*
[155] Fix | Delete
* @return void
[156] Fix | Delete
*/
[157] Fix | Delete
public function indexing_failed() {
[158] Fix | Delete
$this->set_reason( Indexing_Reasons::REASON_INDEXING_FAILED );
[159] Fix | Delete
$this->set_started( null );
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
/**
[163] Fix | Delete
* Sets the indexing reason.
[164] Fix | Delete
*
[165] Fix | Delete
* @param string $reason The indexing reason.
[166] Fix | Delete
*
[167] Fix | Delete
* @return void
[168] Fix | Delete
*/
[169] Fix | Delete
public function set_reason( $reason ) {
[170] Fix | Delete
$this->options_helper->set( 'indexing_reason', $reason );
[171] Fix | Delete
$this->remove_indexing_notification();
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Removes any pre-existing notification, so that a new notification (with a possible new reason) can be added.
[176] Fix | Delete
*
[177] Fix | Delete
* @return void
[178] Fix | Delete
*/
[179] Fix | Delete
protected function remove_indexing_notification() {
[180] Fix | Delete
$this->notification_center->remove_notification_by_id(
[181] Fix | Delete
Indexing_Notification_Integration::NOTIFICATION_ID
[182] Fix | Delete
);
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Determines whether an indexing reason has been set in the options.
[187] Fix | Delete
*
[188] Fix | Delete
* @return bool Whether an indexing reason has been set in the options.
[189] Fix | Delete
*/
[190] Fix | Delete
public function has_reason() {
[191] Fix | Delete
$reason = $this->get_reason();
[192] Fix | Delete
[193] Fix | Delete
return ! empty( $reason );
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Returns the indexing reason. The reason why the site-wide indexing process should be run.
[198] Fix | Delete
*
[199] Fix | Delete
* @return string The indexing reason, defaults to the empty string if no reason has been set.
[200] Fix | Delete
*/
[201] Fix | Delete
public function get_reason() {
[202] Fix | Delete
return $this->options_helper->get( 'indexing_reason', '' );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
/**
[206] Fix | Delete
* Sets the start time when the indexing process has started but not completed.
[207] Fix | Delete
*
[208] Fix | Delete
* @param int|bool $timestamp The start time when the indexing process has started but not completed, false otherwise.
[209] Fix | Delete
*
[210] Fix | Delete
* @return void
[211] Fix | Delete
*/
[212] Fix | Delete
public function set_started( $timestamp ) {
[213] Fix | Delete
$this->options_helper->set( 'indexing_started', $timestamp );
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* Gets the start time when the indexing process has started but not completed.
[218] Fix | Delete
*
[219] Fix | Delete
* @return int|bool The start time when the indexing process has started but not completed, false otherwise.
[220] Fix | Delete
*/
[221] Fix | Delete
public function get_started() {
[222] Fix | Delete
return $this->options_helper->get( 'indexing_started' );
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
/**
[226] Fix | Delete
* Sets a boolean that indicates whether or not a site still has to be indexed for the first time.
[227] Fix | Delete
*
[228] Fix | Delete
* @param bool $is_first_time_indexing Whether or not a site still has to be indexed for the first time.
[229] Fix | Delete
*
[230] Fix | Delete
* @return void
[231] Fix | Delete
*/
[232] Fix | Delete
public function set_first_time( $is_first_time_indexing ) {
[233] Fix | Delete
$this->options_helper->set( 'indexing_first_time', $is_first_time_indexing );
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Gets a boolean that indicates whether or not the site still has to be indexed for the first time.
[238] Fix | Delete
*
[239] Fix | Delete
* @return bool Whether the site still has to be indexed for the first time.
[240] Fix | Delete
*/
[241] Fix | Delete
public function is_initial_indexing() {
[242] Fix | Delete
return $this->options_helper->get( 'indexing_first_time', true );
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
/**
[246] Fix | Delete
* Gets a boolean that indicates whether or not the indexing of the indexables has completed.
[247] Fix | Delete
*
[248] Fix | Delete
* @return bool Whether the indexing of the indexables has completed.
[249] Fix | Delete
*/
[250] Fix | Delete
public function is_finished_indexables_indexing() {
[251] Fix | Delete
return $this->options_helper->get( 'indexables_indexing_completed', false );
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
/**
[255] Fix | Delete
* Returns the total number of unindexed objects.
[256] Fix | Delete
*
[257] Fix | Delete
* @return int The total number of unindexed objects.
[258] Fix | Delete
*/
[259] Fix | Delete
public function get_unindexed_count() {
[260] Fix | Delete
$unindexed_count = 0;
[261] Fix | Delete
[262] Fix | Delete
foreach ( $this->indexing_actions as $indexing_action ) {
[263] Fix | Delete
$unindexed_count += $indexing_action->get_total_unindexed();
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
return $unindexed_count;
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
/**
[270] Fix | Delete
* Returns the amount of un-indexed posts expressed in percentage, which will be needed to set a threshold.
[271] Fix | Delete
*
[272] Fix | Delete
* @param int $unindexed_count The number of unindexed objects.
[273] Fix | Delete
*
[274] Fix | Delete
* @return int The amount of unindexed posts expressed in percentage.
[275] Fix | Delete
*/
[276] Fix | Delete
public function get_unindexed_percentage( $unindexed_count ) {
[277] Fix | Delete
// Gets the amount of indexed objects in the site.
[278] Fix | Delete
$indexed_count = $this->indexable_repository->get_total_number_of_indexables();
[279] Fix | Delete
// The total amount of objects in the site.
[280] Fix | Delete
$total_objects_count = ( $indexed_count + $unindexed_count );
[281] Fix | Delete
[282] Fix | Delete
return ( ( $unindexed_count / $total_objects_count ) * 100 );
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
/**
[286] Fix | Delete
* Returns whether the SEO optimization button should show.
[287] Fix | Delete
*
[288] Fix | Delete
* @return bool Whether the SEO optimization button should show.
[289] Fix | Delete
*/
[290] Fix | Delete
public function should_show_optimization_button() {
[291] Fix | Delete
// Gets the amount of unindexed objects in the site.
[292] Fix | Delete
$unindexed_count = $this->get_filtered_unindexed_count();
[293] Fix | Delete
[294] Fix | Delete
// If the amount of unidexed posts is <10 don't show configuration button.
[295] Fix | Delete
if ( $unindexed_count <= 10 ) {
[296] Fix | Delete
return false;
[297] Fix | Delete
}
[298] Fix | Delete
// If the amount of unidexed posts is >10, but the total amount of unidexed posts is ≤4% of the total amount of objects in the site, don't show configuration button.
[299] Fix | Delete
if ( $this->get_unindexed_percentage( $unindexed_count ) <= 4 ) {
[300] Fix | Delete
return false;
[301] Fix | Delete
}
[302] Fix | Delete
return true;
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* Returns the total number of unindexed objects and applies a filter for third party integrations.
[307] Fix | Delete
*
[308] Fix | Delete
* @return int The total number of unindexed objects.
[309] Fix | Delete
*/
[310] Fix | Delete
public function get_filtered_unindexed_count() {
[311] Fix | Delete
$unindexed_count = $this->get_unindexed_count();
[312] Fix | Delete
[313] Fix | Delete
/**
[314] Fix | Delete
* Filter: 'wpseo_indexing_get_unindexed_count' - Allow changing the amount of unindexed objects.
[315] Fix | Delete
*
[316] Fix | Delete
* @param int $unindexed_count The amount of unindexed objects.
[317] Fix | Delete
*/
[318] Fix | Delete
return \apply_filters( 'wpseo_indexing_get_unindexed_count', $unindexed_count );
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
/**
[322] Fix | Delete
* Returns a limited number of unindexed objects.
[323] Fix | Delete
*
[324] Fix | Delete
* @param int $limit Limit the number of unindexed objects that are counted.
[325] Fix | Delete
* @param Indexation_Action_Interface[]|Limited_Indexing_Action_Interface[] $actions The actions whose counts will be calculated.
[326] Fix | Delete
*
[327] Fix | Delete
* @return int The total number of unindexed objects.
[328] Fix | Delete
*/
[329] Fix | Delete
public function get_limited_unindexed_count( $limit, $actions = [] ) {
[330] Fix | Delete
$unindexed_count = 0;
[331] Fix | Delete
[332] Fix | Delete
if ( empty( $actions ) ) {
[333] Fix | Delete
$actions = $this->indexing_actions;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
foreach ( $actions as $action ) {
[337] Fix | Delete
$unindexed_count += $action->get_limited_unindexed_count( $limit - $unindexed_count + 1 );
[338] Fix | Delete
if ( $unindexed_count > $limit ) {
[339] Fix | Delete
return $unindexed_count;
[340] Fix | Delete
}
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
return $unindexed_count;
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
/**
[347] Fix | Delete
* Returns the total number of unindexed objects and applies a filter for third party integrations.
[348] Fix | Delete
*
[349] Fix | Delete
* @param int $limit Limit the number of unindexed objects that are counted.
[350] Fix | Delete
*
[351] Fix | Delete
* @return int The total number of unindexed objects.
[352] Fix | Delete
*/
[353] Fix | Delete
public function get_limited_filtered_unindexed_count( $limit ) {
[354] Fix | Delete
$unindexed_count = $this->get_limited_unindexed_count( $limit, $this->indexing_actions );
[355] Fix | Delete
[356] Fix | Delete
if ( $unindexed_count > $limit ) {
[357] Fix | Delete
return $unindexed_count;
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
/**
[361] Fix | Delete
* Filter: 'wpseo_indexing_get_limited_unindexed_count' - Allow changing the amount of unindexed objects,
[362] Fix | Delete
* and allow for a maximum number of items counted to improve performance.
[363] Fix | Delete
*
[364] Fix | Delete
* @param int $unindexed_count The amount of unindexed objects.
[365] Fix | Delete
* @param int|false $limit Limit the number of unindexed objects that need to be counted.
[366] Fix | Delete
* False if it doesn't need to be limited.
[367] Fix | Delete
*/
[368] Fix | Delete
return \apply_filters( 'wpseo_indexing_get_limited_unindexed_count', $unindexed_count, $limit );
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
/**
[372] Fix | Delete
* Returns the total number of unindexed objects that can be indexed in the background and applies a filter for third party integrations.
[373] Fix | Delete
*
[374] Fix | Delete
* @param int $limit Limit the number of unindexed objects that are counted.
[375] Fix | Delete
*
[376] Fix | Delete
* @return int The total number of unindexed objects that can be indexed in the background.
[377] Fix | Delete
*/
[378] Fix | Delete
public function get_limited_filtered_unindexed_count_background( $limit ) {
[379] Fix | Delete
$unindexed_count = $this->get_limited_unindexed_count( $limit, $this->background_indexing_actions );
[380] Fix | Delete
[381] Fix | Delete
if ( $unindexed_count > $limit ) {
[382] Fix | Delete
return $unindexed_count;
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Filter: 'wpseo_indexing_get_limited_unindexed_count_background' - Allow changing the amount of unindexed objects that can be indexed in the background,
[387] Fix | Delete
* and allow for a maximum number of items counted to improve performance.
[388] Fix | Delete
*
[389] Fix | Delete
* @param int $unindexed_count The amount of unindexed objects.
[390] Fix | Delete
* @param int|false $limit Limit the number of unindexed objects that need to be counted.
[391] Fix | Delete
* False if it doesn't need to be limited.
[392] Fix | Delete
*/
[393] Fix | Delete
return \apply_filters( 'wpseo_indexing_get_limited_unindexed_count_background', $unindexed_count, $limit );
[394] Fix | Delete
}
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function