PageRenderTime 24ms CodeModel.GetById 10ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

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