/wp-content/plugins/wordpress-seo/admin/banner/class-admin-banner-sidebar.php

https://bitbucket.org/carloskikea/helpet · PHP · 348 lines · 226 code · 41 blank · 81 comment · 7 complexity · 3bc61e04f8aea4d01fee8877cad53830 MD5 · raw file

  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Banner
  6. */
  7. /**
  8. * Represents the render object for generating the html for the given banner.
  9. */
  10. class WPSEO_Admin_Banner_Sidebar {
  11. /** @var string */
  12. protected $title = '';
  13. /** @var WPSEO_Admin_Banner_Spot[] */
  14. protected $banner_spots = array();
  15. /** @var WPSEO_Admin_Banner_Renderer */
  16. protected $banner_renderer;
  17. /**
  18. * WPSEO_Admin_Banner_Sidebar constructor.
  19. *
  20. * @param string $title The title for the sidebar.
  21. * @param WPSEO_Admin_Banner_Renderer $banner_renderer The render class for banners.
  22. */
  23. public function __construct( $title, WPSEO_Admin_Banner_Renderer $banner_renderer ) {
  24. $this->title = $title;
  25. $this->banner_renderer = $banner_renderer;
  26. }
  27. /**
  28. * Returns the set title.
  29. *
  30. * @return string
  31. */
  32. public function get_title() {
  33. return $this->title;
  34. }
  35. /**
  36. * Initializes the banner sidebar by setting its banner spots.
  37. *
  38. * @param WPSEO_Features $features Class regarding WPSEO Features.
  39. */
  40. public function initialize( WPSEO_Features $features ) {
  41. if ( $features->is_free() ) {
  42. $this->add_banner_spot( $this->get_premium_spot() );
  43. }
  44. $this->add_banner_spot( $this->get_services_spot() );
  45. $extensions_spot = $this->get_extensions_spot( $this->get_active_extensions() );
  46. if ( $extensions_spot->has_banners() ) {
  47. $this->add_banner_spot( $extensions_spot );
  48. }
  49. $this->add_banner_spot( $this->get_courses_spot() );
  50. $this->add_banner_spot( $this->get_remove_banner_spot() );
  51. }
  52. /**
  53. * Returns array with bannerspots.
  54. *
  55. * @return WPSEO_Admin_Banner_Spot[]
  56. */
  57. public function get_banner_spots() {
  58. return $this->banner_spots;
  59. }
  60. /**
  61. * Adds a banner spot.
  62. *
  63. * @param WPSEO_Admin_Banner_Spot $spot The spot to add.
  64. */
  65. protected function add_banner_spot( WPSEO_Admin_Banner_Spot $spot ) {
  66. $this->banner_spots[] = $spot;
  67. }
  68. /**
  69. * Returns the premium banner spot.
  70. *
  71. * @return WPSEO_Admin_Banner_Spot
  72. */
  73. protected function get_premium_spot() {
  74. $premium_spot = new WPSEO_Admin_Banner_Spot( '', $this->banner_renderer );
  75. $premium_uri = WPSEO_Shortlinker::get( 'https://yoa.st/jj' );
  76. $premium_spot->set_extra(
  77. /* translators: %1$s expands to the plugin name */
  78. '<h2>' . sprintf( esc_html__( 'Upgrade to %1$s', 'wordpress-seo' ), 'Yoast SEO Premium' ) . '</h2>' .
  79. '<ul>' .
  80. '<li><strong>' . esc_html__( 'Rank for up to 5 focus keywords per page', 'wordpress-seo' ) . '</strong></li>' .
  81. '<li><strong>' . esc_html__( 'Preview your page in Facebook and Twitter', 'wordpress-seo' ) . '</strong></li>' .
  82. '<li><strong>' . esc_html__( 'Get real-time suggestions for internal links', 'wordpress-seo' ) . '</strong></li>' .
  83. '<li><strong>' . esc_html__( 'No more dead links a.k.a. 404 pages', 'wordpress-seo' ) . '</strong></li>' .
  84. '<li><strong>' . esc_html__( '24/7 email support', 'wordpress-seo' ) . '</strong></li>' .
  85. '<li><strong>' . esc_html__( 'No ads', 'wordpress-seo' ) . '</strong></li>' .
  86. '</ul>' .
  87. /* translators: %s expands to Yoast SEO Premium */
  88. '<a id="wpseo-premium-button" class="button button-primary" href="' . $premium_uri . '" target="_blank">' . sprintf( __( 'Get %s now', 'wordpress-seo' ), 'Yoast SEO Premium' ) . '</a><br/>'
  89. );
  90. return $premium_spot;
  91. }
  92. /**
  93. * Returns the services banner spot.
  94. *
  95. * @return WPSEO_Admin_Banner_Spot
  96. */
  97. protected function get_services_spot() {
  98. $service_spot = new WPSEO_Admin_Banner_Spot( __( 'Services', 'wordpress-seo' ), $this->banner_renderer );
  99. $service_spot->set_description(
  100. sprintf(
  101. /* translators: %1$s expands to a link start tag to the Yoast Services page, %2$s to Yoast, %3$s is the link closing tag. */
  102. __( 'Do you want to know how to improve your rankings? %1$sLet team %2$s help you!%3$s', 'wordpress-seo' ),
  103. '<a target="_blank" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/jk' ) . '">',
  104. 'Yoast',
  105. '</a>'
  106. )
  107. );
  108. $service_spot->add_banner(
  109. new WPSEO_Admin_Banner(
  110. WPSEO_Shortlinker::get( 'https://yoa.st/jm' ),
  111. 'configuration-service.png',
  112. 261,
  113. 152,
  114. sprintf(
  115. /* translators: %1$s expands to Yoast SEO Premium. */
  116. __( 'Let our experts set up your %1$s plugin!', 'wordpress-seo' ),
  117. 'Yoast SEO Premium'
  118. )
  119. )
  120. );
  121. return $service_spot;
  122. }
  123. /**
  124. * Returns an array with the Yoast SEO extensions with the value true when they are active.
  125. *
  126. * @return array
  127. */
  128. protected function get_active_extensions() {
  129. return array(
  130. 'video' => class_exists( 'wpseo_Video_Sitemap' ),
  131. 'woocommerce' => class_exists( 'Woocommerce' ) && class_exists( 'Yoast_WooCommerce_SEO' ),
  132. 'news' => class_exists( 'WPSEO_News' ),
  133. 'local' => defined( 'WPSEO_LOCAL_VERSION' ),
  134. );
  135. }
  136. /**
  137. * Returns the extensions banner spot.
  138. *
  139. * @param array $active_extensions The active extensions.
  140. *
  141. * @return WPSEO_Admin_Banner_Spot
  142. */
  143. protected function get_extensions_spot( array $active_extensions ) {
  144. $extension_spot = new WPSEO_Admin_Banner_Spot( __( 'Extensions', 'wordpress-seo' ), $this->banner_renderer );
  145. $extension_spot->set_description(
  146. sprintf(
  147. /* translators: %1$s expands to a link start tag to the Yoast plugin page, %2$s is the link closing tag. */
  148. __( 'Take your SEO to the next level and outrank your competition with our %1$sSEO plugins%2$s.', 'wordpress-seo' ),
  149. '<a target="_blank" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/jn' ) . '">',
  150. '</a>'
  151. )
  152. );
  153. if ( empty( $active_extensions['video'] ) ) {
  154. $extension_spot->add_banner(
  155. new WPSEO_Admin_Banner(
  156. WPSEO_Shortlinker::get( 'https://yoa.st/jo' ),
  157. 'video-seo.png',
  158. 261,
  159. 152,
  160. sprintf(
  161. /* translators: %1$s expands to Yoast Video SEO. */
  162. __( 'Buy the %1$s plugin now and optimize your videos for video search results and social media!', 'wordpress-seo' ),
  163. 'Yoast Video SEO'
  164. )
  165. )
  166. );
  167. }
  168. if ( empty( $active_extensions['woocommerce'] ) ) {
  169. $extension_spot->add_banner(
  170. new WPSEO_Admin_Banner(
  171. WPSEO_Shortlinker::get( 'https://yoa.st/jp' ),
  172. 'woocommerce-seo.png',
  173. 261,
  174. 152,
  175. sprintf(
  176. /* translators: %1$s expands to Yoast WooCommerce SEO. */
  177. __( 'Buy the %1$s plugin now and optimize your shop today to improve your product promotion!', 'wordpress-seo' ),
  178. 'Yoast WooCommerce SEO'
  179. )
  180. )
  181. );
  182. }
  183. if ( empty( $active_extensions['local'] ) ) {
  184. $extension_spot->add_banner(
  185. new WPSEO_Admin_Banner(
  186. WPSEO_Shortlinker::get( 'https://yoa.st/jq' ),
  187. 'local-seo.png', 261,
  188. 152,
  189. sprintf(
  190. /* translators: %1$s expands to Yoast Local SEO. */
  191. __( 'Buy the %1$s plugin now to improve your site&#8217;s Local SEO and ranking in Google Maps!', 'wordpress-seo' ),
  192. 'Yoast Local SEO'
  193. )
  194. )
  195. );
  196. }
  197. if ( empty( $active_extensions['news'] ) ) {
  198. $extension_spot->add_banner(
  199. new WPSEO_Admin_Banner(
  200. WPSEO_Shortlinker::get( 'https://yoa.st/jr' ),
  201. 'news-seo.png',
  202. 261,
  203. 152,
  204. sprintf(
  205. /* translators: %1$s expands to Yoast News SEO. */
  206. __( 'Buy the %1$s plugin now and start optimizing to get your site featured in Google News!', 'wordpress-seo' ),
  207. 'Yoast News SEO'
  208. )
  209. )
  210. );
  211. }
  212. return $extension_spot;
  213. }
  214. /**
  215. * Returns the courses banner spot.
  216. *
  217. * @return WPSEO_Admin_Banner_Spot
  218. */
  219. protected function get_courses_spot() {
  220. $courses_spot = new WPSEO_Admin_Banner_Spot( __( 'Improve your SEO skills', 'wordpress-seo' ), $this->banner_renderer );
  221. $courses_spot->set_description(
  222. sprintf(
  223. /* translators: %1$s expands to a link start tag to the Yoast Services page, %2$s is the link closing tag. */
  224. __( 'We believe SEO should be for everyone. That’s why we develop courses on any topic related to SEO. %1$sDiscover our online SEO courses &raquo;%2$s', 'wordpress-seo' ),
  225. '<a target="_blank" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/jt' ) . '">',
  226. '</a>'
  227. )
  228. );
  229. $courses_spot->add_banner(
  230. new WPSEO_Admin_Banner(
  231. WPSEO_Shortlinker::get( 'https://yoa.st/ju' ),
  232. 'basic-seo-training.png',
  233. 261,
  234. 152,
  235. __( 'Take the online Basic SEO Training course and learn the fundamentals of SEO!', 'wordpress-seo' )
  236. )
  237. );
  238. $courses_spot->add_banner(
  239. new WPSEO_Admin_Banner(
  240. WPSEO_Shortlinker::get( 'https://yoa.st/jv' ),
  241. 'yoast-seo-for-wordpress-training.png',
  242. 261,
  243. 152,
  244. sprintf(
  245. /* translators: %1$s expands to Yoast SEO for WordPress Training, %2$s to Yoast SEO for WordPress. */
  246. __( 'Take the %1$s course and become a certified %2$s expert!', 'wordpress-seo' ),
  247. 'Yoast SEO for WordPress Training',
  248. 'Yoast SEO for WordPress'
  249. )
  250. )
  251. );
  252. $courses_spot->add_banner(
  253. new WPSEO_Admin_Banner(
  254. WPSEO_Shortlinker::get( 'https://yoa.st/jw' ),
  255. 'seo-copywriting-training.png',
  256. 261,
  257. 152,
  258. __( 'Take the online SEO Copywriting Training course and learn how to write awesome copy that ranks!', 'wordpress-seo' )
  259. )
  260. );
  261. $courses_spot->add_banner(
  262. new WPSEO_Admin_Banner(
  263. WPSEO_Shortlinker::get( 'https://yoa.st/qy' ),
  264. 'site-structure-training.png',
  265. 261,
  266. 152,
  267. __( 'Take the online Site Structure Training course and learn how to structure your website!', 'wordpress-seo' )
  268. )
  269. );
  270. $courses_spot->add_banner(
  271. new WPSEO_Admin_Banner(
  272. WPSEO_Shortlinker::get( 'https://yoa.st/jaa' ),
  273. 'technical-seo-training.png',
  274. 261,
  275. 152,
  276. __( 'Take the online Technical SEO Training course and learn essential technical SEO-concepts!', 'wordpress-seo' )
  277. )
  278. );
  279. $courses_spot->add_banner(
  280. new WPSEO_Admin_Banner(
  281. WPSEO_Shortlinker::get( 'https://yoa.st/15h' ),
  282. 'structured-data-course.png',
  283. 261,
  284. 152,
  285. __( 'Take the online Structured Data Training course and learn how to create rich snippets!', 'wordpress-seo' )
  286. )
  287. );
  288. return $courses_spot;
  289. }
  290. /**
  291. * Returns the remove banner spot.
  292. *
  293. * @return WPSEO_Admin_Banner_Spot
  294. */
  295. protected function get_remove_banner_spot() {
  296. $remove_banner_spot = new WPSEO_Admin_Banner_Spot(
  297. __( 'Remove these ads?', 'wordpress-seo' )
  298. );
  299. $remove_banner_spot->set_description(
  300. '<a target="_blank" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/jy' ) . '">' .
  301. /* translators: %1$s expands to Yoast SEO Premium */
  302. sprintf( __( 'Upgrade to %1$s &raquo;', 'wordpress-seo' ), 'Yoast SEO Premium' ) .
  303. '</a>'
  304. );
  305. return $remove_banner_spot;
  306. }
  307. }