PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/carloskikea/helpet
PHP | 120 lines | 41 code | 16 blank | 63 comment | 1 complexity | 2f16480741d490056da0ab7785c43853 MD5 | raw file
  1<?php
  2/**
  3 * WPSEO plugin file.
  4 *
  5 * @package WPSEO\Admin\Banner
  6 */
  7
  8/**
  9 * Represents the an admin banner spot.
 10 */
 11class WPSEO_Admin_Banner_Spot {
 12
 13	/** @var string */
 14	private $title;
 15
 16	/** @var string */
 17	private $description = '';
 18
 19	/** @var string */
 20	private $extra = '';
 21
 22	/** @var WPSEO_Admin_Banner[] */
 23	private $banners = array();
 24
 25	/**
 26	 * WPSEO_Admin_Banner_Spot constructor.
 27	 *
 28	 * @param string                      $title           The title for the spot.
 29	 * @param WPSEO_Admin_Banner_Renderer $banner_renderer The renderer for the banner.
 30	 */
 31	public function __construct( $title, WPSEO_Admin_Banner_Renderer $banner_renderer = null ) {
 32		$this->title           = $title;
 33		$this->banner_renderer = ( is_null( $banner_renderer ) ? new WPSEO_Admin_Banner_Renderer() : $banner_renderer );
 34	}
 35
 36	/**
 37	 * Returns the title.
 38	 *
 39	 * @return string
 40	 */
 41	public function get_title() {
 42		return $this->title;
 43	}
 44
 45	/**
 46	 * Returns the description.
 47	 *
 48	 * @return string
 49	 */
 50	public function get_description() {
 51		return $this->description;
 52	}
 53
 54	/**
 55	 * Returns the extra content.
 56	 *
 57	 * @return string
 58	 */
 59	public function get_extra() {
 60		return $this->extra;
 61	}
 62
 63	/**
 64	 * Sets the description
 65	 *
 66	 * @param string $description The description.
 67	 */
 68	public function set_description( $description ) {
 69		$this->description = $description;
 70	}
 71
 72	/**
 73	 * Sets the "extra"
 74	 *
 75	 * @param string $extra The "extra".
 76	 */
 77	public function set_extra( $extra ) {
 78		$this->extra = $extra;
 79	}
 80
 81	/**
 82	 * Adds an admin banner.
 83	 *
 84	 * @param WPSEO_Admin_Banner $banner The banner to add.
 85	 */
 86	public function add_banner( WPSEO_Admin_Banner $banner ) {
 87		$this->banners[] = $banner;
 88	}
 89
 90	/**
 91	 * Renders the banner.
 92	 *
 93	 * @return string
 94	 */
 95	public function render_banner() {
 96		if ( ! $this->has_banners() ) {
 97			return '';
 98		}
 99
100		return $this->banner_renderer->render( $this->get_random_banner() );
101	}
102
103	/**
104	 * Checks if there are any banners set.
105	 *
106	 * @return bool
107	 */
108	public function has_banners() {
109		return ! empty( $this->banners );
110	}
111
112	/**
113	 * Returns a random banner.
114	 *
115	 * @return null|WPSEO_Admin_Banner
116	 */
117	protected function get_random_banner() {
118		return $this->banners[ array_rand( $this->banners, 1 ) ];
119	}
120}