| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
namespace Yoast\WP\SEO\Llms_Txt\User_Interface\Health_Check; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Services\Health_Check\Report_Builder_Factory; |
| 7 |
use Yoast\WP\SEO\Services\Health_Check\Reports_Trait; |
| 8 |
|
| 9 |
/** |
| 10 |
* Presents a set of different messages for the File_Generation health check. |
| 11 |
*/ |
| 12 |
class File_Reports { |
| 13 |
|
| 14 |
use Reports_Trait; |
| 15 |
|
| 16 |
/** |
| 17 |
* Constructor |
| 18 |
* |
| 19 |
* @param Report_Builder_Factory $report_builder_factory The factory for result builder objects. |
| 20 |
* This class uses the report builder to generate WordPress-friendly |
| 21 |
* health check results. |
| 22 |
*/ |
| 23 |
public function __construct( Report_Builder_Factory $report_builder_factory ) { |
| 24 |
$this->report_builder_factory = $report_builder_factory; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Returns the message for a successful health check. |
| 29 |
* |
| 30 |
* @return string[] The message as a WordPress site status report. |
| 31 |
*/ |
| 32 |
public function get_success_result() { |
| 33 |
$label = \sprintf( |
| 34 |
/* translators: %s: Yoast SEO. */ |
| 35 |
\__( 'Your llms.txt file is auto-generated by %s', 'wordpress-seo' ), |
| 36 |
'Yoast SEO', |
| 37 |
); |
| 38 |
|
| 39 |
$description = \sprintf( |
| 40 |
/* translators: %s: Yoast SEO. */ |
| 41 |
\__( '%s keeps your llms.txt file up-to-date. This helps LLMs access and provide your site\'s information more easily.', 'wordpress-seo' ), |
| 42 |
'Yoast SEO', |
| 43 |
); |
| 44 |
|
| 45 |
return $this->get_report_builder() |
| 46 |
->set_label( $label ) |
| 47 |
->set_status_good() |
| 48 |
->set_description( $description ) |
| 49 |
->build(); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Returns the message for a failed health check. In this case, when the llms.txt file couldn't be auto-generated. |
| 54 |
* |
| 55 |
* @param string $reason The reason why the llms.txt file couldn't be auto-generated. |
| 56 |
* |
| 57 |
* @return string[] The message as a WordPress site status report. |
| 58 |
*/ |
| 59 |
public function get_generation_failure_result( $reason ) { |
| 60 |
switch ( $reason ) { |
| 61 |
case 'not_managed_by_yoast_seo': |
| 62 |
$title = \__( 'Your llms.txt file couldn\'t be auto-generated', 'wordpress-seo' ); |
| 63 |
$message = \sprintf( |
| 64 |
/* translators: 1,3,5: expand to opening paragraph tag, 2,4,6: expand to opening paragraph tag. */ |
| 65 |
\__( '%1$sYou have activated the Yoast llms.txt feature, but we couldn\'t generate an llms.txt file.%2$s%3$sIt looks like there is an llms.txt file already that wasn\'t created by Yoast, or the llms.txt file created by Yoast has been edited manually.%4$s%5$sWe don\'t want to overwrite this file\'s content, so if you want to let Yoast keep auto-generating the llms.txt file, you can manually delete the existing one. Otherwise, consider disabling the Yoast feature.%6$s', 'wordpress-seo' ), |
| 66 |
'<p>', |
| 67 |
'</p>', |
| 68 |
'<p>', |
| 69 |
'</p>', |
| 70 |
'<p>', |
| 71 |
'</p>', |
| 72 |
); |
| 73 |
break; |
| 74 |
case 'filesystem_permissions': |
| 75 |
$title = \__( 'Your llms.txt file couldn\'t be auto-generated', 'wordpress-seo' ); |
| 76 |
$message = \sprintf( |
| 77 |
/* translators: 1,3: expand to opening paragraph tag, 2,4: expand to opening paragraph tag. */ |
| 78 |
\__( '%1$sYou have activated the Yoast llms.txt feature, but we couldn\'t generate an llms.txt file.%2$s%3$sIt looks like there aren\'t sufficient permissions on the web server\'s filesystem.%4$s', 'wordpress-seo' ), |
| 79 |
'<p>', |
| 80 |
'</p>', |
| 81 |
'<p>', |
| 82 |
'</p>', |
| 83 |
); |
| 84 |
break; |
| 85 |
default: |
| 86 |
$title = \__( 'Your llms.txt file couldn\'t be auto-generated', 'wordpress-seo' ); |
| 87 |
$message = \__( 'You have activated the Yoast llms.txt feature, but we couldn\'t generate an llms.txt file, for unknown reasons.', 'wordpress-seo' ); |
| 88 |
break; |
| 89 |
} |
| 90 |
|
| 91 |
return $this->get_report_builder() |
| 92 |
->set_label( $title ) |
| 93 |
->set_status_recommended() |
| 94 |
->set_description( $message ) |
| 95 |
->build(); |
| 96 |
} |
| 97 |
} |
| 98 |
|