| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* This class generates the metabox on the edit term page. |
| 10 |
*/ |
| 11 |
class WPSEO_Taxonomy_Metabox { |
| 12 |
|
| 13 |
/** |
| 14 |
* The term currently being edited. |
| 15 |
* |
| 16 |
* @var WP_Term |
| 17 |
*/ |
| 18 |
private $term; |
| 19 |
|
| 20 |
/** |
| 21 |
* The term's taxonomy. |
| 22 |
* |
| 23 |
* @var string |
| 24 |
*/ |
| 25 |
private $taxonomy; |
| 26 |
|
| 27 |
/** |
| 28 |
* Whether or not the social tab is enabled for this metabox. |
| 29 |
* |
| 30 |
* @var bool |
| 31 |
*/ |
| 32 |
private $is_social_enabled; |
| 33 |
|
| 34 |
/** |
| 35 |
* Helper to determine whether or not the SEO analysis is enabled. |
| 36 |
* |
| 37 |
* @var WPSEO_Metabox_Analysis_SEO |
| 38 |
*/ |
| 39 |
protected $seo_analysis; |
| 40 |
|
| 41 |
/** |
| 42 |
* Helper to determine whether or not the readability analysis is enabled. |
| 43 |
* |
| 44 |
* @var WPSEO_Metabox_Analysis_Readability |
| 45 |
*/ |
| 46 |
protected $readability_analysis; |
| 47 |
|
| 48 |
/** |
| 49 |
* The constructor. |
| 50 |
* |
| 51 |
* @param string $taxonomy The taxonomy. |
| 52 |
* @param stdClass $term The term. |
| 53 |
*/ |
| 54 |
public function __construct( $taxonomy, $term ) { |
| 55 |
$this->term = $term; |
| 56 |
$this->taxonomy = $taxonomy; |
| 57 |
$this->is_social_enabled = WPSEO_Options::get( 'opengraph', false ) || WPSEO_Options::get( 'twitter', false ); |
| 58 |
|
| 59 |
$this->seo_analysis = new WPSEO_Metabox_Analysis_SEO(); |
| 60 |
$this->readability_analysis = new WPSEO_Metabox_Analysis_Readability(); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Shows the Yoast SEO metabox for the term. |
| 65 |
*/ |
| 66 |
public function display() { |
| 67 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: $this->get_product_title() returns a hard-coded string. |
| 68 |
printf( '<div id="wpseo_meta" class="postbox yoast wpseo-taxonomy-metabox-postbox"><h2><span>%1$s</span></h2>', $this->get_product_title() ); |
| 69 |
|
| 70 |
echo '<div class="inside">'; |
| 71 |
echo '<div id="taxonomy_overall"></div>'; |
| 72 |
|
| 73 |
$this->render_hidden_fields(); |
| 74 |
$this->render_tabs(); |
| 75 |
|
| 76 |
echo '</div>'; |
| 77 |
echo '</div>'; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Renders the metabox hidden fields. |
| 82 |
* |
| 83 |
* @return void |
| 84 |
*/ |
| 85 |
protected function render_hidden_fields() { |
| 86 |
$fields_presenter = new WPSEO_Taxonomy_Fields_Presenter( $this->term ); |
| 87 |
$field_definitions = new WPSEO_Taxonomy_Fields(); |
| 88 |
|
| 89 |
echo $fields_presenter->html( $field_definitions->get( 'content' ) ); |
| 90 |
if ( WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || WPSEO_Options::get( 'disableadvanced_meta' ) === false ) { |
| 91 |
echo $fields_presenter->html( $field_definitions->get( 'settings' ) ); |
| 92 |
} |
| 93 |
|
| 94 |
if ( $this->is_social_enabled ) { |
| 95 |
echo $fields_presenter->html( $field_definitions->get( 'social' ) ); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Renders the metabox tabs. |
| 101 |
* |
| 102 |
* @return void |
| 103 |
*/ |
| 104 |
protected function render_tabs() { |
| 105 |
echo '<div class="wpseo-metabox-content">'; |
| 106 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: $this->get_product_title() returns a hard-coded string. |
| 107 |
printf( '<div class="wpseo-metabox-menu"><ul role="tablist" class="yoast-aria-tabs" aria-label="%s">', $this->get_product_title() ); |
| 108 |
|
| 109 |
$tabs = $this->get_tabs(); |
| 110 |
|
| 111 |
foreach ( $tabs as $tab ) { |
| 112 |
$tab->display_link(); |
| 113 |
} |
| 114 |
|
| 115 |
echo '</ul></div>'; |
| 116 |
|
| 117 |
foreach ( $tabs as $tab ) { |
| 118 |
$tab->display_content(); |
| 119 |
} |
| 120 |
|
| 121 |
echo '</div>'; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Returns the relevant metabox sections for the current view. |
| 126 |
* |
| 127 |
* @return WPSEO_Metabox_Section[] |
| 128 |
*/ |
| 129 |
private function get_tabs() { |
| 130 |
$tabs = []; |
| 131 |
|
| 132 |
$label = __( 'SEO', 'wordpress-seo' ); |
| 133 |
if ( $this->seo_analysis->is_enabled() ) { |
| 134 |
$label = '<span class="wpseo-score-icon-container" id="wpseo-seo-score-icon"></span>' . $label; |
| 135 |
} |
| 136 |
|
| 137 |
$tabs[] = new WPSEO_Metabox_Section_React( 'content', $label ); |
| 138 |
|
| 139 |
if ( $this->readability_analysis->is_enabled() ) { |
| 140 |
$tabs[] = new WPSEO_Metabox_Section_Readability(); |
| 141 |
} |
| 142 |
|
| 143 |
if ( $this->is_social_enabled ) { |
| 144 |
$tabs[] = new WPSEO_Metabox_Section_React( |
| 145 |
'social', |
| 146 |
'<span class="dashicons dashicons-share"></span>' . __( 'Social', 'wordpress-seo' ), |
| 147 |
'', |
| 148 |
[ |
| 149 |
'html_after' => '<div id="wpseo-section-social"></div>', |
| 150 |
] |
| 151 |
); |
| 152 |
} |
| 153 |
|
| 154 |
return $tabs; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Retrieves the product title. |
| 159 |
* |
| 160 |
* @return string The product title. |
| 161 |
*/ |
| 162 |
protected function get_product_title() { |
| 163 |
return YoastSEO()->helpers->product->get_product_name(); |
| 164 |
} |
| 165 |
} |
| 166 |
|