Edit File by line
/home/barbar84/www/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_Notification_Center;
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* A helper object for indexing.
[17] Fix | Delete
*/
[18] Fix | Delete
class Indexing_Helper {
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* The options helper.
[22] Fix | Delete
*
[23] Fix | Delete
* @var Options_Helper
[24] Fix | Delete
*/
[25] Fix | Delete
protected $options_helper;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* The date helper.
[29] Fix | Delete
*
[30] Fix | Delete
* @var Date_Helper
[31] Fix | Delete
*/
[32] Fix | Delete
protected $date_helper;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* The notification center.
[36] Fix | Delete
*
[37] Fix | Delete
* @var Yoast_Notification_Center
[38] Fix | Delete
*/
[39] Fix | Delete
protected $notification_center;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* The indexation actions.
[43] Fix | Delete
*
[44] Fix | Delete
* @var Indexation_Action_Interface[]|Limited_Indexing_Action_Interface[]
[45] Fix | Delete
*/
[46] Fix | Delete
protected $indexing_actions;
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Indexing_Helper constructor.
[50] Fix | Delete
*
[51] Fix | Delete
* @param Options_Helper $options_helper The options helper.
[52] Fix | Delete
* @param Date_Helper $date_helper The date helper.
[53] Fix | Delete
* @param Yoast_Notification_Center $notification_center The notification center.
[54] Fix | Delete
*/
[55] Fix | Delete
public function __construct(
[56] Fix | Delete
Options_Helper $options_helper,
[57] Fix | Delete
Date_Helper $date_helper,
[58] Fix | Delete
Yoast_Notification_Center $notification_center
[59] Fix | Delete
) {
[60] Fix | Delete
$this->options_helper = $options_helper;
[61] Fix | Delete
$this->date_helper = $date_helper;
[62] Fix | Delete
$this->notification_center = $notification_center;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* Sets the actions.
[67] Fix | Delete
*
[68] Fix | Delete
* @required
[69] Fix | Delete
*
[70] Fix | Delete
* @param Indexable_Post_Indexation_Action $post_indexation The post indexing action.
[71] Fix | Delete
* @param Indexable_Term_Indexation_Action $term_indexation The term indexing action.
[72] Fix | Delete
* @param Indexable_Post_Type_Archive_Indexation_Action $post_type_archive_indexation The posttype indexing action.
[73] Fix | Delete
* @param Indexable_General_Indexation_Action $general_indexation The general indexing (homepage etc) action.
[74] Fix | Delete
* @param Post_Link_Indexing_Action $post_link_indexing_action The post crosslink indexing action.
[75] Fix | Delete
* @param Term_Link_Indexing_Action $term_link_indexing_action The term crossling indexing action.
[76] Fix | Delete
*/
[77] Fix | Delete
public function set_indexing_actions(
[78] Fix | Delete
Indexable_Post_Indexation_Action $post_indexation,
[79] Fix | Delete
Indexable_Term_Indexation_Action $term_indexation,
[80] Fix | Delete
Indexable_Post_Type_Archive_Indexation_Action $post_type_archive_indexation,
[81] Fix | Delete
Indexable_General_Indexation_Action $general_indexation,
[82] Fix | Delete
Post_Link_Indexing_Action $post_link_indexing_action,
[83] Fix | Delete
Term_Link_Indexing_Action $term_link_indexing_action
[84] Fix | Delete
) {
[85] Fix | Delete
$this->indexing_actions = [
[86] Fix | Delete
$post_indexation,
[87] Fix | Delete
$term_indexation,
[88] Fix | Delete
$post_type_archive_indexation,
[89] Fix | Delete
$general_indexation,
[90] Fix | Delete
$post_link_indexing_action,
[91] Fix | Delete
$term_link_indexing_action,
[92] Fix | Delete
];
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Sets several database options when the indexing process is started.
[97] Fix | Delete
*
[98] Fix | Delete
* @deprecated 17.4 This method was renamed to prepare for internal consistency.
[99] Fix | Delete
* @codeCoverageIgnore
[100] Fix | Delete
*
[101] Fix | Delete
* @return void
[102] Fix | Delete
*/
[103] Fix | Delete
public function start() {
[104] Fix | Delete
$this->prepare();
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Prepares the indexing process by setting several database options and removing the indexing notification.
[109] Fix | Delete
*
[110] Fix | Delete
* @return void
[111] Fix | Delete
*/
[112] Fix | Delete
public function prepare() {
[113] Fix | Delete
$this->set_first_time( false );
[114] Fix | Delete
$this->set_started( $this->date_helper->current_time() );
[115] Fix | Delete
$this->remove_indexing_notification();
[116] Fix | Delete
// Do not set_reason here; if the process is cancelled, the reason to start indexing is still valid.
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Sets several database options when the indexing process is finished.
[121] Fix | Delete
*
[122] Fix | Delete
* @deprecated 17.4 This method was renamed to complete for internal consistency.
[123] Fix | Delete
* @codeCoverageIgnore
[124] Fix | Delete
*
[125] Fix | Delete
* @return void
[126] Fix | Delete
*/
[127] Fix | Delete
public function finish() {
[128] Fix | Delete
$this->complete();
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Sets several database options when the indexing process is finished.
[133] Fix | Delete
*
[134] Fix | Delete
* @return void
[135] Fix | Delete
*/
[136] Fix | Delete
public function complete() {
[137] Fix | Delete
$this->set_reason( '' );
[138] Fix | Delete
$this->set_started( null );
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Sets appropriate flags when the indexing process fails.
[143] Fix | Delete
*
[144] Fix | Delete
* @return void
[145] Fix | Delete
*/
[146] Fix | Delete
public function indexing_failed() {
[147] Fix | Delete
$this->set_reason( Indexing_Reasons::REASON_INDEXING_FAILED );
[148] Fix | Delete
$this->set_started( null );
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Sets the indexing reason.
[153] Fix | Delete
*
[154] Fix | Delete
* @param string $reason The indexing reason.
[155] Fix | Delete
*
[156] Fix | Delete
* @return void
[157] Fix | Delete
*/
[158] Fix | Delete
public function set_reason( $reason ) {
[159] Fix | Delete
$this->options_helper->set( 'indexing_reason', $reason );
[160] Fix | Delete
$this->remove_indexing_notification();
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Removes any pre-existing notification, so that a new notification (with a possible new reason) can be added.
[165] Fix | Delete
*/
[166] Fix | Delete
protected function remove_indexing_notification() {
[167] Fix | Delete
$this->notification_center->remove_notification_by_id(
[168] Fix | Delete
Indexing_Notification_Integration::NOTIFICATION_ID
[169] Fix | Delete
);
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
/**
[173] Fix | Delete
* Determines whether an indexing reason has been set in the options.
[174] Fix | Delete
*
[175] Fix | Delete
* @return bool Whether an indexing reason has been set in the options.
[176] Fix | Delete
*/
[177] Fix | Delete
public function has_reason() {
[178] Fix | Delete
$reason = $this->get_reason();
[179] Fix | Delete
[180] Fix | Delete
return ! empty( $reason );
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* Returns the indexing reason. The reason why the site-wide indexing process should be run.
[185] Fix | Delete
*
[186] Fix | Delete
* @return string The indexing reason, defaults to the empty string if no reason has been set.
[187] Fix | Delete
*/
[188] Fix | Delete
public function get_reason() {
[189] Fix | Delete
return $this->options_helper->get( 'indexing_reason', '' );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Sets the start time when the indexing process has started but not completed.
[194] Fix | Delete
*
[195] Fix | Delete
* @param int|bool $timestamp The start time when the indexing process has started but not completed, false otherwise.
[196] Fix | Delete
*
[197] Fix | Delete
* @return void
[198] Fix | Delete
*/
[199] Fix | Delete
public function set_started( $timestamp ) {
[200] Fix | Delete
$this->options_helper->set( 'indexing_started', $timestamp );
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Gets the start time when the indexing process has started but not completed.
[205] Fix | Delete
*
[206] Fix | Delete
* @return int|bool The start time when the indexing process has started but not completed, false otherwise.
[207] Fix | Delete
*/
[208] Fix | Delete
public function get_started() {
[209] Fix | Delete
return $this->options_helper->get( 'indexing_started' );
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
/**
[213] Fix | Delete
* Sets a boolean that indicates whether or not a site still has to be indexed for the first time.
[214] Fix | Delete
*
[215] Fix | Delete
* @param bool $is_first_time_indexing Whether or not a site still has to be indexed for the first time.
[216] Fix | Delete
*
[217] Fix | Delete
* @return void
[218] Fix | Delete
*/
[219] Fix | Delete
public function set_first_time( $is_first_time_indexing ) {
[220] Fix | Delete
$this->options_helper->set( 'indexing_first_time', $is_first_time_indexing );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Gets a boolean that indicates whether or not the site still has to be indexed for the first time.
[225] Fix | Delete
*
[226] Fix | Delete
* @return bool Whether the site still has to be indexed for the first time.
[227] Fix | Delete
*/
[228] Fix | Delete
public function is_initial_indexing() {
[229] Fix | Delete
return $this->options_helper->get( 'indexing_first_time', true );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Returns the total number of unindexed objects.
[234] Fix | Delete
*
[235] Fix | Delete
* @return int The total number of unindexed objects.
[236] Fix | Delete
*/
[237] Fix | Delete
public function get_unindexed_count() {
[238] Fix | Delete
$unindexed_count = 0;
[239] Fix | Delete
[240] Fix | Delete
foreach ( $this->indexing_actions as $indexing_action ) {
[241] Fix | Delete
$unindexed_count += $indexing_action->get_total_unindexed();
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
return $unindexed_count;
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
/**
[248] Fix | Delete
* Returns the total number of unindexed objects and applies a filter for third party integrations.
[249] Fix | Delete
*
[250] Fix | Delete
* @return int The total number of unindexed objects.
[251] Fix | Delete
*/
[252] Fix | Delete
public function get_filtered_unindexed_count() {
[253] Fix | Delete
$unindexed_count = $this->get_unindexed_count();
[254] Fix | Delete
[255] Fix | Delete
/**
[256] Fix | Delete
* Filter: 'wpseo_indexing_get_unindexed_count' - Allow changing the amount of unindexed objects.
[257] Fix | Delete
*
[258] Fix | Delete
* @param int $unindexed_count The amount of unindexed objects.
[259] Fix | Delete
*/
[260] Fix | Delete
return \apply_filters( 'wpseo_indexing_get_unindexed_count', $unindexed_count );
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Returns a limited number of unindexed objects.
[265] Fix | Delete
*
[266] Fix | Delete
* @param int $limit Limit the number of unindexed objects that are counted.
[267] Fix | Delete
*
[268] Fix | Delete
* @return int The total number of unindexed objects.
[269] Fix | Delete
*/
[270] Fix | Delete
public function get_limited_unindexed_count( $limit ) {
[271] Fix | Delete
$unindexed_count = 0;
[272] Fix | Delete
[273] Fix | Delete
foreach ( $this->indexing_actions as $indexing_action ) {
[274] Fix | Delete
$unindexed_count += $indexing_action->get_limited_unindexed_count( $limit - $unindexed_count + 1 );
[275] Fix | Delete
if ( $unindexed_count > $limit ) {
[276] Fix | Delete
return $unindexed_count;
[277] Fix | Delete
}
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
return $unindexed_count;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
/**
[284] Fix | Delete
* Returns the total number of unindexed objects and applies a filter for third party integrations.
[285] Fix | Delete
*
[286] Fix | Delete
* @param int $limit Limit the number of unindexed objects that are counted.
[287] Fix | Delete
*
[288] Fix | Delete
* @return int The total number of unindexed objects.
[289] Fix | Delete
*/
[290] Fix | Delete
public function get_limited_filtered_unindexed_count( $limit ) {
[291] Fix | Delete
$unindexed_count = $this->get_limited_unindexed_count( $limit );
[292] Fix | Delete
[293] Fix | Delete
if ( $unindexed_count > $limit ) {
[294] Fix | Delete
return $unindexed_count;
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* Filter: 'wpseo_indexing_get_limited_unindexed_count' - Allow changing the amount of unindexed objects,
[299] Fix | Delete
* and allow for a maximum number of items counted to improve performance.
[300] Fix | Delete
*
[301] Fix | Delete
* @param int $unindexed_count The amount of unindexed objects.
[302] Fix | Delete
* @param int|false $limit Limit the number of unindexed objects that need to be counted.
[303] Fix | Delete
* False if it doesn't need to be limited.
[304] Fix | Delete
*/
[305] Fix | Delete
return \apply_filters( 'wpseo_indexing_get_limited_unindexed_count', $unindexed_count, $limit );
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function