* @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3 * @package IVV */ /** * Page superclass. * * Every visitable page type must inherit from this one. * * @category Page */ abstract class Page{ /** * @var string[] List of CSS files required for the page. */ private $css = []; /** * @var string Path to the view associated with the page. */ private $view; /** * @var string Title of the page, in the defined language. */ private $title; /** * @var string Site name. */ private $name; /** * @var string Page description, in the defined language. */ private $description; /** * @var string URL to the site favicon. */ private $favicon; /** * @var string URL to the page icon or main image. */ private $icon; /** * @var string Canonical URL. */ private $canonical; /** * @var string Autjhor URL. */ private $author; /** * @var integer HTTP status code. */ private $code = 0; /** * @var string HTTP status message. */ private $message = ""; /** * Constructor. */ public function __construct(){ $this->favicon = URL::IMG["LOGO"] . "sw.png"; $this->icon = URL::IMG["LOGO"] . "sw.png"; $this->name = "SWDB"; $this->author = URL::BASE; $this->add_css("ui.css"); } /** * Adds a CSS file to the list. * * @param string $css Css file. Can be the absolute URL, or just the filename. */ protected function add_css($css){ if (strripos($css, URL::CSS) === false){ $file = URL::CSS . $css; } else{ $file = $css; } array_push($this->css, $file); } /** * Retrieves the CSS file URLs for the page. * * @return string[] CSS files (by absolute URL.) */ public function get_css(){ return $this->css; } /** * Sets the page view. * * @param string $view View file. Can be the relative path, or just the filename. */ protected function set_view($view){ if (strripos($view, PATH::VIEW) === false){ $file = PATH::VIEW . $view; } else{ $file = $view; } $this->view = $file; } /** * Retrieves the page view file. * * @return string Path to the view file. */ public function get_view(){ return $this->view; } /** * Sets the page title. * * The string " - SWDB" will always be added at the end. * * @param string $title Page title. */ protected function set_title($title){ $this->title = htmlentities($title, ENT_QUOTES) . " - SWDB"; } /** * Retrieves the page title. * * @return string Page title. */ public function get_title(){ return $this->title; } /** * Retrieves the site name. * * @return string Site name. */ public function get_name(){ return $this->name; } /** * Sets the page description. * * The string " - Summoners War DataBase" will always be added at the end. * * @param string $description Page description text. */ protected function set_description($description){ $this->description = htmlentities($description, ENT_QUOTES) . " - " . Text::get("USER_TAGLINE"); } /** * Retrieves the page description * * @return string Page description. */ public function get_description(){ return $this->description; } /** * Retrieves the URL to the favicon. * * @return string Favicon URL. */ public function get_favicon(){ return $this->favicon; } /** * Retrieves the URL to the thumbnail image. * * @return string Thmbnail icon URL. */ public function get_icon(){ return $this->icon; } /** * Sets the page canonical URL. * * @param string $canonical Canonical URL, absolute or relative. */ protected function set_canonical($canonical){ if (strripos($canonical, URL::BASE) === false){ $file = URL::BASE . $canonical; } else{ $file = $canonical; } $this->canonical = $file; } /** * Retrieves the canonical URL to the page. * * @return string Canonical URL. */ public function get_canonical(){ return $this->canonical; } /** * Retrieves the author URL (site main URL). * * @return string AUthor URL. */ public function get_author(){ return $this->author; } /** * Sets the HTTP status code for the page to return. * * @param int HTTP status code. */ protected function set_code($code){ if (is_int($code) && $code >= 200 && $code <= 500){ $this->code = $code; } } /** * Retrieves the page HTTP status code. * * @return int HTTP status code */ public function get_code(){ return $this->code; } /** * Sets the HTTP status message for the page to return. * * @param string HTTP status message. */ protected function set_message($mesage){ $this->message = strval($mesage); } /** * Retrieves the page HTTP status message. * * @return string HTTP status code */ public function get_message(){ return $this->message; } /** * Generates the content to be inserted in the HTML
section. * * It must go between the and tags, and anything can go behind it before closing * the section. It includes page title, description, css files and metadata. * * @return string HTML head content. */ public function generate_head(){ $head = "