250 lines
8.6 KiB
PHP
250 lines
8.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace core\site\structure;
|
||
|
|
|
||
|
|
class HTMLPage {
|
||
|
|
// HEAD
|
||
|
|
|
||
|
|
static $doctype = '<!DOCTYPE html>';
|
||
|
|
static $html = '<html lang="%LANG%" %CLASS% xmlns="http://www.w3.org/1999/xhtml">';
|
||
|
|
static $charset = 'UTF-8';
|
||
|
|
static $favicon = 'favicon.ico';
|
||
|
|
static $scripts = array();
|
||
|
|
static $styles = array();
|
||
|
|
static $title = '';
|
||
|
|
static $image_url = '';
|
||
|
|
static $titles = array();
|
||
|
|
static $meta = array();
|
||
|
|
static $links = array();
|
||
|
|
static $titles_delimetr = ' ';
|
||
|
|
static $description;
|
||
|
|
static $keywords;
|
||
|
|
static $google;
|
||
|
|
static $yandex;
|
||
|
|
static $vk_comments;
|
||
|
|
static $redirect;
|
||
|
|
static $data = [];
|
||
|
|
|
||
|
|
static $html_class = array();
|
||
|
|
static $lang = "ru";
|
||
|
|
|
||
|
|
static $stylesCode = array();
|
||
|
|
static $scriptCode = array();
|
||
|
|
static $metaCode = array();
|
||
|
|
|
||
|
|
static $stylesEnd = array();
|
||
|
|
|
||
|
|
static $body = array();
|
||
|
|
static $foot;
|
||
|
|
// СВОЙСТВА СТРАНИЦЫ
|
||
|
|
static $text_id;
|
||
|
|
static $head_crumbs = array();
|
||
|
|
static $body_class = array();
|
||
|
|
static $is_404 = false;
|
||
|
|
|
||
|
|
static $canonical;
|
||
|
|
|
||
|
|
/** @var \core\site\structure\SchemaOrg $schemaOrg */
|
||
|
|
protected static $schemaOrg;
|
||
|
|
static function schemaOrg(): SchemaOrg{
|
||
|
|
if(isset(self::$schemaOrg)) return self::$schemaOrg;
|
||
|
|
return self::$schemaOrg = new SchemaOrg();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/* КОНСТАНТЫ */
|
||
|
|
const BODY_VALUE='BODY_VALUE';
|
||
|
|
const BODY_TYPE='BODY_TYPE';
|
||
|
|
const BODY_TYPE_TEXT = 'BODY_TYPE_TEXT';
|
||
|
|
const BODY_TYPE_LOAD_LIBRARY = 'BODY_TYPE_LOAD_LIBRARY';
|
||
|
|
|
||
|
|
const SUBS_PAGES_LINK = "SUBS_PAGES_LINK";
|
||
|
|
const SUBS_PAGES_NAME = "SUBS_PAGES_NAME";
|
||
|
|
|
||
|
|
public function __construct() {
|
||
|
|
self::init();
|
||
|
|
}
|
||
|
|
static function init()
|
||
|
|
{
|
||
|
|
$a = ['utm_campaign', 'utm_content', 'utm_medium', 'utm_source', 'utm_term',];
|
||
|
|
self::$schemaOrg = new SchemaOrg();
|
||
|
|
foreach ($a as $v){
|
||
|
|
if($_GET[$v]){ \Core::setCookie($v,trim($_GET[$v])); }
|
||
|
|
}
|
||
|
|
$url = parse_url($_SERVER['REQUEST_URI']);
|
||
|
|
self::$canonical = \Site::sectionUrl(substr($url['path'],1),true);
|
||
|
|
}
|
||
|
|
|
||
|
|
static function addBodyClass($x){
|
||
|
|
array_push(self::$body_class,$x);
|
||
|
|
}
|
||
|
|
|
||
|
|
static function getBodyContent() {
|
||
|
|
$res = implode(self::$body);
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function addData($key,$value){
|
||
|
|
self::$data[$key] = $value;
|
||
|
|
}
|
||
|
|
static function getBody() {
|
||
|
|
$res = '<body'.(self::$body_class?' class="'.implode(" ",self::$body_class).'"':'').'>'.self::getBodyContent();
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function addBodyText($x) {
|
||
|
|
array_push(self::$body,$x);
|
||
|
|
}
|
||
|
|
static function getFoot() {
|
||
|
|
return self::getStylesEnd().self::$foot;
|
||
|
|
}
|
||
|
|
static function getPage() {
|
||
|
|
return self::getHead().self::getBody().self::getFoot()."</body></html>";
|
||
|
|
|
||
|
|
}
|
||
|
|
static function addCrumb($name,$link) {
|
||
|
|
array_push(self::$head_crumbs,array($name,$link));
|
||
|
|
}
|
||
|
|
// Функция, которая возвращает хлебные крошки к странице
|
||
|
|
function getHeadCrumbs() {
|
||
|
|
$res = '<div id="crumbs" class="fb">';
|
||
|
|
$sep = '<div class="crumb_sep fb">»</div>';
|
||
|
|
foreach(self::$head_crumbs as $k=>$v) {
|
||
|
|
$res .= (($k!=0)?$sep:"").'<a href="'.($v[self::SUBS_PAGES_LINK]).'" title="Перейти к '.htmlspecialchars($v[self::SUBS_PAGES_NAME]).'">'.$v[self::SUBS_PAGES_NAME].'</a>';
|
||
|
|
}
|
||
|
|
$res .= "</div>";
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
static function addLink($href,$rel,$type=''){
|
||
|
|
$s = array('href'=>$href,'rel'=>$rel,'type'=>$type);
|
||
|
|
array_push(self::$links,$s);
|
||
|
|
}
|
||
|
|
static function getLinks(){
|
||
|
|
$res = '';
|
||
|
|
foreach(self::$links as $k) {
|
||
|
|
$type = trim($k['type']);
|
||
|
|
$res .= '<link href="'.trim($k['href']).'" rel="'.trim($k['rel']).'" '.($type?'type="'.trim($k['type']).'"':'').'>';
|
||
|
|
}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
|
||
|
|
static function addHtmlClass($x){ array_push(self::$html_class,$x); }
|
||
|
|
|
||
|
|
static function htmlStyleCSS($href) { return "<link rel='stylesheet' type='text/css' href='".$href."'>"; }
|
||
|
|
static function htmlScriptJS($href) { return "<script src='".$href."' ></script>"; }
|
||
|
|
//static function htmlScriptJS($href) { return "<script type='text/javascript' src='".$href."' ></script>"; }
|
||
|
|
|
||
|
|
static function addScript($s){array_push(self::$scripts,$s);}
|
||
|
|
static function getScripts(){
|
||
|
|
$res = '';
|
||
|
|
foreach(self::$scripts as $k) {$res .= self::htmlScriptJS($k);}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function addStyle($s){array_push(self::$styles,$s);}
|
||
|
|
static function addStyleEnd($s){array_push(self::$stylesEnd,$s);}
|
||
|
|
static function getStyles(){
|
||
|
|
$res = '';
|
||
|
|
foreach(self::$styles as $k) {$res .= self::htmlStyleCSS($k);}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function getStylesEnd(){
|
||
|
|
$res = '';
|
||
|
|
foreach(self::$stylesEnd as $k) {$res .= self::htmlStyleCSS($k);}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function addStyleCode($s){array_push(self::$stylesCode,$s);}
|
||
|
|
static function getStylesCode(){
|
||
|
|
$res = '';
|
||
|
|
foreach(self::$stylesCode as $k) {$res .= trim($k);}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function addScriptCode($s){array_push(self::$scriptCode,$s);}
|
||
|
|
static function getScriptsCode(){
|
||
|
|
$res = '';
|
||
|
|
foreach(self::$scriptCode as $k) {$res .= trim($k);}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function addMetaCode($s){array_push(self::$metaCode,$s);}
|
||
|
|
static function getMetaCode(){
|
||
|
|
$res = '';
|
||
|
|
foreach(self::$metaCode as $k) {$res .= trim($k);}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function getHead() {
|
||
|
|
$res = self::$doctype.
|
||
|
|
str_replace(
|
||
|
|
array("%CLASS%","%LANG%"),array(count(self::$html_class)?'class="'.implode(' ',self::$html_class).'"':'',self::$lang),self::$html).
|
||
|
|
"<head>";
|
||
|
|
$res .= self::getCharset();
|
||
|
|
$res .= self::getTitle();
|
||
|
|
$res .= self::getKeywords();
|
||
|
|
$res .= self::getDescription();
|
||
|
|
$res .= self::getMeta();
|
||
|
|
$res .= self::getMetaCode();
|
||
|
|
$res .= self::getFavicon();
|
||
|
|
$res .= self::getStyles();
|
||
|
|
$res .= self::getStylesCode();
|
||
|
|
$res .= self::getScriptsCode();
|
||
|
|
$res .= self::getScripts();
|
||
|
|
$res .= self::getLinks();
|
||
|
|
$res .= self::getOpenGraph();
|
||
|
|
$res .= self::getSchemaOrg();
|
||
|
|
$res .= "</head>";
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
|
||
|
|
static function getOpenGraph(){
|
||
|
|
$res = '';
|
||
|
|
$res .= '<meta property="og:url" content="'.(\Site::$URL[0] ? \Site::sectionUrl(implode('/',\Site::$URL).'/',true) : \Site::sectionUrl('',true)).'" />';
|
||
|
|
$res .= '<meta property="og:type" content="website" />';
|
||
|
|
$res .= '<meta property="og:title" content="'.h(self::getTitleText()).'" />';
|
||
|
|
$res .= '<meta property="og:description" content="'.h(self::$description).'" />';
|
||
|
|
if(self::$image_url) {
|
||
|
|
$res .= '<meta property="og:image" content="'.self::$image_url.'" />';
|
||
|
|
}
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function getSchemaOrg()
|
||
|
|
{
|
||
|
|
$data = self::schemaOrg()->toJson();
|
||
|
|
if(!$data['@graph']) return '';
|
||
|
|
return '<script type="application/ld+json">'.je($data).'</script>';
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
static function getCharset() {
|
||
|
|
return '<meta http-equiv="Content-Type" content="text/html; charset='.self::$charset.'">';
|
||
|
|
}
|
||
|
|
static function getFavicon() {
|
||
|
|
$res = '<link rel="icon" href="'.self::$favicon.'" type="image/x-icon">';
|
||
|
|
$res.= '<link rel="shortcut icon" href="'.self::$favicon.'" type="image/x-icon">';
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function addTitle($x) {
|
||
|
|
array_push(self::$titles,htmlspecialchars($x));
|
||
|
|
}
|
||
|
|
static function addMeta($key,$value) {
|
||
|
|
self::$meta[$key] = $value;
|
||
|
|
}
|
||
|
|
static function getTitleText(){
|
||
|
|
$res = self::$title;
|
||
|
|
//if (count(self::$titles)>0) for($i = count(self::$titles)-1;$i>=0;$i--) {$res = self::$titles[$i].self::$titles_delimetr.$res;}
|
||
|
|
return implode(self::$titles_delimetr,self::$titles);
|
||
|
|
//if (count(self::$titles)>0) for($i = 0;$i<count(self::$titles);$i++) {$res = self::$titles[$i].self::$titles_delimetr.$res;}
|
||
|
|
//return $res;
|
||
|
|
}
|
||
|
|
static function getTitle() {
|
||
|
|
return "<title>".self::getTitleText()."</title>";
|
||
|
|
}
|
||
|
|
|
||
|
|
static function getMeta() {
|
||
|
|
$res = "";
|
||
|
|
foreach(self::$meta as $k=>$v) $res .= "<meta name='".$k."' content='".$v."' />";
|
||
|
|
return $res;
|
||
|
|
}
|
||
|
|
static function getKeywords(){ /*if (self::$keywords) /**/ return '<meta name="keywords" content="'.h(self::$keywords).'">';}
|
||
|
|
static function getDescription(){ /*if (self::$description)/**/ return '<meta name="description" content="'.h(self::$description).'">';}
|
||
|
|
|
||
|
|
}
|