| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Presenters\Admin; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Config\Indexing_Reasons; |
| 6 |
use Yoast\WP\SEO\Helpers\Short_Link_Helper; |
| 7 |
use Yoast\WP\SEO\Presenters\Abstract_Presenter; |
| 8 |
|
| 9 |
/** |
| 10 |
* Class Indexing_Notification_Presenter. |
| 11 |
* |
| 12 |
* @package Yoast\WP\SEO\Presenters\Admin |
| 13 |
*/ |
| 14 |
class Indexing_Notification_Presenter extends Abstract_Presenter { |
| 15 |
|
| 16 |
/** |
| 17 |
* The total number of unindexed objects. |
| 18 |
* |
| 19 |
* @var int |
| 20 |
*/ |
| 21 |
protected $total_unindexed; |
| 22 |
|
| 23 |
/** |
| 24 |
* The message to show in the notification. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
protected $reason; |
| 29 |
|
| 30 |
/** |
| 31 |
* The short link helper. |
| 32 |
* |
| 33 |
* @var Short_Link_Helper |
| 34 |
*/ |
| 35 |
protected $short_link_helper; |
| 36 |
|
| 37 |
/** |
| 38 |
* Indexing_Notification_Presenter constructor. |
| 39 |
* |
| 40 |
* @param Short_Link_Helper $short_link_helper The short link helper. |
| 41 |
* @param int $total_unindexed Total number of unindexed objects. |
| 42 |
* @param string $reason The reason to show in the notification. |
| 43 |
*/ |
| 44 |
public function __construct( $short_link_helper, $total_unindexed, $reason ) { |
| 45 |
$this->short_link_helper = $short_link_helper; |
| 46 |
$this->total_unindexed = $total_unindexed; |
| 47 |
$this->reason = $reason; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Returns the notification as an HTML string. |
| 52 |
* |
| 53 |
* @return string The HTML string representation of the notification. |
| 54 |
*/ |
| 55 |
public function present() { |
| 56 |
$notification_text = '<p>' . $this->get_message( $this->reason ) . '</p>'; |
| 57 |
$notification_text .= '<p>' . $this->get_time_estimate( $this->total_unindexed ) . '</p>'; |
| 58 |
$notification_text .= '<a class="button" href="' . \get_admin_url( null, 'admin.php?page=wpseo_tools&start-indexation=true' ) . '">'; |
| 59 |
$notification_text .= \esc_html__( 'Start SEO data optimization', 'wordpress-seo' ); |
| 60 |
$notification_text .= '</a>'; |
| 61 |
|
| 62 |
return $notification_text; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Determines the message to show in the indexing notification. |
| 67 |
* |
| 68 |
* @param string $reason The reason identifier. |
| 69 |
* |
| 70 |
* @return string The message to show in the notification. |
| 71 |
*/ |
| 72 |
protected function get_message( $reason ) { |
| 73 |
switch ( $reason ) { |
| 74 |
case Indexing_Reasons::REASON_PERMALINK_SETTINGS: |
| 75 |
$text = \esc_html__( 'Because of a change in your permalink structure, some of your SEO data needs to be reprocessed.', 'wordpress-seo' ); |
| 76 |
break; |
| 77 |
case Indexing_Reasons::REASON_HOME_URL_OPTION: |
| 78 |
$text = \esc_html__( 'Because of a change in your home URL setting, some of your SEO data needs to be reprocessed.', 'wordpress-seo' ); |
| 79 |
break; |
| 80 |
case Indexing_Reasons::REASON_CATEGORY_BASE_PREFIX: |
| 81 |
$text = \esc_html__( 'Because of a change in your category base setting, some of your SEO data needs to be reprocessed.', 'wordpress-seo' ); |
| 82 |
break; |
| 83 |
case Indexing_Reasons::REASON_TAG_BASE_PREFIX: |
| 84 |
$text = \esc_html__( 'Because of a change in your tag base setting, some of your SEO data needs to be reprocessed.', 'wordpress-seo' ); |
| 85 |
break; |
| 86 |
default: |
| 87 |
$text = \esc_html__( 'You can speed up your site and get insight into your internal linking structure by letting us perform a few optimizations to the way SEO data is stored. ', 'wordpress-seo' ); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Filter: 'wpseo_indexables_indexation_alert' - Allow developers to filter the reason of the indexation |
| 92 |
* |
| 93 |
* @param string $text The text to show as reason. |
| 94 |
* @param string $reason The reason value. |
| 95 |
*/ |
| 96 |
return (string) \apply_filters( 'wpseo_indexables_indexation_alert', $text, $reason ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Creates a time estimate based on the total number on unindexed objects. |
| 101 |
* |
| 102 |
* @param int $total_unindexed The total number of unindexed objects. |
| 103 |
* |
| 104 |
* @return string The time estimate as a HTML string. |
| 105 |
*/ |
| 106 |
protected function get_time_estimate( $total_unindexed ) { |
| 107 |
if ( $total_unindexed < 400 ) { |
| 108 |
return \esc_html__( 'We estimate this will take less than a minute.', 'wordpress-seo' ); |
| 109 |
} |
| 110 |
|
| 111 |
if ( $total_unindexed < 2500 ) { |
| 112 |
return \esc_html__( 'We estimate this will take a couple of minutes.', 'wordpress-seo' ); |
| 113 |
} |
| 114 |
|
| 115 |
$estimate = \esc_html__( 'We estimate this could take a long time, due to the size of your site. As an alternative to waiting, you could:', 'wordpress-seo' ); |
| 116 |
$estimate .= '<ul class="ul-disc">'; |
| 117 |
$estimate .= '<li>'; |
| 118 |
$estimate .= \sprintf( |
| 119 |
/* translators: 1: Expands to Yoast SEO */ |
| 120 |
\esc_html__( 'Wait for a week or so, until %1$s automatically processes most of your content in the background.', 'wordpress-seo' ), |
| 121 |
'Yoast SEO' |
| 122 |
); |
| 123 |
$estimate .= '</li>'; |
| 124 |
$estimate .= '<li>'; |
| 125 |
$estimate .= \sprintf( |
| 126 |
/* translators: 1: Link to article about indexation command, 2: Anchor closing tag, 3: Link to WP CLI. */ |
| 127 |
\esc_html__( '%1$sRun the indexation process on your server%2$s using %3$sWP CLI%2$s.', 'wordpress-seo' ), |
| 128 |
'<a href="' . \esc_url( $this->short_link_helper->get( 'https://yoa.st/3-w' ) ) . '" target="_blank">', |
| 129 |
'</a>', |
| 130 |
'<a href="https://wp-cli.org/" target="_blank">' |
| 131 |
); |
| 132 |
|
| 133 |
$estimate .= '</li>'; |
| 134 |
$estimate .= '</ul>'; |
| 135 |
|
| 136 |
return $estimate; |
| 137 |
} |
| 138 |
} |
| 139 |
|