class-taxonomy-metabox.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * This class generates the metabox on the edit term page.
  9. */
  10. class WPSEO_Taxonomy_Metabox {
  11. /**
  12. * @var WP_Term
  13. */
  14. private $term;
  15. /**
  16. * @var string
  17. */
  18. private $taxonomy;
  19. /**
  20. * @var WPSEO_Taxonomy_Fields_Presenter
  21. */
  22. private $taxonomy_tab_content;
  23. /**
  24. * @var WPSEO_Taxonomy_Social_Fields
  25. */
  26. private $taxonomy_social_fields;
  27. /**
  28. * @var WPSEO_Social_Admin
  29. */
  30. private $social_admin;
  31. /**
  32. * The constructor.
  33. *
  34. * @param string $taxonomy The taxonomy.
  35. * @param stdClass $term The term.
  36. */
  37. public function __construct( $taxonomy, $term ) {
  38. $this->term = $term;
  39. $this->taxonomy = $taxonomy;
  40. $this->taxonomy_tab_content = new WPSEO_Taxonomy_Fields_Presenter( $this->term );
  41. }
  42. /**
  43. * Shows the Yoast SEO metabox for the term.
  44. */
  45. public function display() {
  46. $asset_manager = new WPSEO_Admin_Asset_Manager();
  47. $asset_manager->enqueue_script( 'help-center' );
  48. $content_sections = $this->get_content_sections();
  49. $product_title = 'Yoast SEO';
  50. if ( file_exists( WPSEO_PATH . 'premium/' ) ) {
  51. $product_title .= ' Premium';
  52. }
  53. printf( '<div id="wpseo_meta" class="postbox yoast wpseo-taxonomy-metabox-postbox"><h2><span>%1$s</span></h2>', $product_title );
  54. echo '<div class="inside">';
  55. $helpcenter_tab = new WPSEO_Option_Tab( 'tax-metabox', __( 'Meta box', 'wordpress-seo' ),
  56. array( 'video_url' => WPSEO_Shortlinker::get( 'https://yoa.st/metabox-taxonomy-screencast' ) ) );
  57. $helpcenter = new WPSEO_Help_Center( 'tax-metabox', $helpcenter_tab, WPSEO_Utils::is_yoast_seo_premium() );
  58. $helpcenter->localize_data();
  59. $helpcenter->mount();
  60. echo '<div id="taxonomy_overall"></div>';
  61. if ( ! defined( 'WPSEO_PREMIUM_FILE' ) ) {
  62. echo $this->get_buy_premium_link();
  63. }
  64. echo '<div class="wpseo-metabox-content">';
  65. echo '<div class="wpseo-metabox-sidebar"><ul>';
  66. foreach ( $content_sections as $content_section ) {
  67. if ( $content_section->name === 'premium' ) {
  68. continue;
  69. }
  70. $content_section->display_link();
  71. }
  72. echo '</ul></div>';
  73. foreach ( $content_sections as $content_section ) {
  74. $content_section->display_content();
  75. }
  76. echo '</div></div>';
  77. echo '</div>';
  78. }
  79. /**
  80. * Returns the relevant metabox sections for the current view.
  81. *
  82. * @return WPSEO_Metabox_Section[]
  83. */
  84. private function get_content_sections() {
  85. $content_sections = array();
  86. $content_sections[] = $this->get_content_meta_section();
  87. $content_sections[] = $this->get_social_meta_section();
  88. $content_sections[] = $this->get_settings_meta_section();
  89. if ( ! defined( 'WPSEO_PREMIUM_FILE' ) ) {
  90. $content_sections[] = $this->get_buy_premium_section();
  91. }
  92. return $content_sections;
  93. }
  94. /**
  95. * Returns the metabox section for the content analysis.
  96. *
  97. * @return WPSEO_Metabox_Section
  98. */
  99. private function get_content_meta_section() {
  100. $taxonomy_content_fields = new WPSEO_Taxonomy_Content_Fields( $this->term );
  101. $content = $this->taxonomy_tab_content->html( $taxonomy_content_fields->get( $this->term ) );
  102. return new WPSEO_Metabox_Section_React(
  103. 'content',
  104. '<span class="screen-reader-text">' . __( 'Content optimization', 'wordpress-seo' ) . '</span><span class="yst-traffic-light-container">' . WPSEO_Utils::traffic_light_svg() . '</span>',
  105. $content,
  106. array(
  107. 'link_aria_label' => __( 'Content optimization', 'wordpress-seo' ),
  108. 'link_class' => 'yoast-tooltip yoast-tooltip-e',
  109. )
  110. );
  111. }
  112. /**
  113. * Returns the metabox section for the settings.
  114. *
  115. * @return WPSEO_Metabox_Section
  116. */
  117. private function get_settings_meta_section() {
  118. $taxonomy_settings_fields = new WPSEO_Taxonomy_Settings_Fields( $this->term );
  119. $content = $this->taxonomy_tab_content->html( $taxonomy_settings_fields->get() );
  120. $tab = new WPSEO_Metabox_Form_Tab(
  121. 'settings',
  122. $content,
  123. __( 'Settings', 'wordpress-seo' ),
  124. array(
  125. 'single' => true,
  126. )
  127. );
  128. return new WPSEO_Metabox_Tab_Section(
  129. 'settings',
  130. '<span class="screen-reader-text">' . __( 'Settings', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-admin-generic"></span>',
  131. array( $tab ),
  132. array(
  133. 'link_aria_label' => __( 'Settings', 'wordpress-seo' ),
  134. 'link_class' => 'yoast-tooltip yoast-tooltip-e',
  135. )
  136. );
  137. }
  138. /**
  139. * Returns the metabox section for the social settings.
  140. *
  141. * @return WPSEO_Metabox_Section
  142. */
  143. private function get_social_meta_section() {
  144. $this->taxonomy_social_fields = new WPSEO_Taxonomy_Social_Fields( $this->term );
  145. $this->social_admin = new WPSEO_Social_Admin();
  146. $tabs = array();
  147. $tabs[] = $this->create_tab( 'facebook', 'opengraph', 'facebook-alt', __( 'Facebook / Open Graph metadata', 'wordpress-seo' ) );
  148. $tabs[] = $this->create_tab( 'twitter', 'twitter', 'twitter', __( 'Twitter metadata', 'wordpress-seo' ) );
  149. return new WPSEO_Metabox_Tab_Section(
  150. 'social',
  151. '<span class="screen-reader-text">' . __( 'Social', 'wordpress-seo' ) . '</span><span class="dashicons dashicons-share"></span>',
  152. $tabs,
  153. array(
  154. 'link_aria_label' => __( 'Social', 'wordpress-seo' ),
  155. 'link_class' => 'yoast-tooltip yoast-tooltip-e',
  156. )
  157. );
  158. }
  159. /**
  160. * Creates a social network tab.
  161. *
  162. * @param string $name The name of the tab.
  163. * @param string $network The network of the tab.
  164. * @param string $icon The icon for the tab.
  165. * @param string $label The label for the tab.
  166. *
  167. * @return WPSEO_Metabox_Form_Tab A WPSEO_Metabox_Form_Tab instance.
  168. */
  169. private function create_tab( $name, $network, $icon, $label ) {
  170. if ( WPSEO_Options::get( $network ) !== true ) {
  171. return new WPSEO_Metabox_Null_Tab();
  172. }
  173. $meta_fields = $this->taxonomy_social_fields->get_by_network( $network );
  174. $tab_settings = new WPSEO_Metabox_Form_Tab(
  175. $name,
  176. $this->social_admin->get_premium_notice( $network ) . $this->taxonomy_tab_content->html( $meta_fields ),
  177. '<span class="screen-reader-text">' . $label . '</span><span class="dashicons dashicons-' . $icon . '"></span>',
  178. array(
  179. 'link_aria_label' => $label,
  180. 'link_class' => 'yoast-tooltip yoast-tooltip-se',
  181. 'single' => $this->has_single_social_tab(),
  182. )
  183. );
  184. return $tab_settings;
  185. }
  186. /**
  187. * Determine whether we only show one social network or two.
  188. *
  189. * @return bool
  190. */
  191. private function has_single_social_tab() {
  192. return ( WPSEO_Options::get( 'opengraph' ) === false || WPSEO_Options::get( 'twitter' ) === false );
  193. }
  194. /**
  195. * Returns a link to activate the Buy Premium tab.
  196. *
  197. * @return string
  198. */
  199. private function get_buy_premium_link() {
  200. return sprintf( "<div class='%s'><a href='#wpseo-meta-section-premium' class='wpseo-meta-section-link'><span class='dashicons dashicons-star-filled wpseo-buy-premium'></span>%s</a></div>",
  201. 'wpseo-metabox-buy-premium',
  202. __( 'Go Premium', 'wordpress-seo' )
  203. );
  204. }
  205. /**
  206. * Returns the metabox section for the Premium section..
  207. *
  208. * @return WPSEO_Metabox_Section
  209. */
  210. private function get_buy_premium_section() {
  211. $content = sprintf( "<div class='wpseo-premium-description'>
  212. %s
  213. <ul class='wpseo-premium-advantages-list'>
  214. <li>
  215. <strong>%s</strong> - %s
  216. </li>
  217. <li>
  218. <strong>%s</strong> - %s
  219. </li>
  220. <li>
  221. <strong>%s</strong> - %s
  222. </li>
  223. <li>
  224. <strong>%s</strong> - %s
  225. </li>
  226. </ul>
  227. <a target='_blank' id='wpseo-buy-premium-popup-button' class='button button-buy-premium wpseo-metabox-go-to' href='%s'>
  228. %s
  229. </a>
  230. <p><a target='_blank' class='wpseo-metabox-go-to' href='%s'>%s</a></p>
  231. </div>",
  232. /* translators: %1$s expands to Yoast SEO Premium. */
  233. sprintf( __( 'You\'re not getting the benefits of %1$s yet. If you had %1$s, you could use its awesome features:', 'wordpress-seo' ), 'Yoast SEO Premium' ),
  234. __( 'Redirect manager', 'wordpress-seo' ),
  235. __( 'Create and manage redirects within your WordPress install.', 'wordpress-seo' ),
  236. __( 'Multiple focus keywords', 'wordpress-seo' ),
  237. __( 'Optimize a single post for up to 5 keywords.', 'wordpress-seo' ),
  238. __( 'Social Previews', 'wordpress-seo' ),
  239. __( 'Check what your Facebook or Twitter post will look like.', 'wordpress-seo' ),
  240. __( 'Premium support', 'wordpress-seo' ),
  241. __( 'Gain access to our 24/7 support team.', 'wordpress-seo' ),
  242. WPSEO_Shortlinker::get( 'https://yoa.st/pe-buy-premium' ),
  243. /* translators: %s expands to Yoast SEO Premium. */
  244. sprintf( __( 'Get %s now!', 'wordpress-seo' ), 'Yoast SEO Premium' ),
  245. WPSEO_Shortlinker::get( 'https://yoa.st/pe-premium-page' ),
  246. __( 'More info', 'wordpress-seo' )
  247. );
  248. $tab = new WPSEO_Metabox_Form_Tab(
  249. 'premium',
  250. $content,
  251. 'Yoast SEO Premium',
  252. array(
  253. 'single' => true,
  254. )
  255. );
  256. return new WPSEO_Metabox_Tab_Section(
  257. 'premium',
  258. '<span class="dashicons dashicons-star-filled wpseo-buy-premium"></span>',
  259. array( $tab ),
  260. array(
  261. 'link_aria_label' => 'Yoast SEO Premium',
  262. 'link_class' => 'yoast-tooltip yoast-tooltip-e',
  263. )
  264. );
  265. }
  266. }