<?php
/**
* Lys
*
* GNU General Public License
*
* Copyright © 2007 - 2023, Yohann Schwan. All rights reserved.
*/
namespace Lys\Layout {
class Html extends \Lys\Layout {
use XmlHelper, HtmlHelper, HtmlParserHelper, HtmlFormHelper;
/**
* @args void
* @return void
*/
function __wakeup()
{
parent::__wakeup();
#
# Fix headers
#
header('Content-Type:text/html;charset=UTF-8');
header('X-UA-Compatible:IE=edge');
#
# Fix Self
#
$self = $this['self'];
foreach(array('title', 'subtitle', 'date') as $k)
{
if($v = array_value($k, $self))
{
$self[$k] = $this->_analyse($v);
}
}
foreach(array('text') as $k)
{
if($v = array_value($k, $self))
{
$self[$k] = $this->parse($v);
}
}
$this['self'] = $self;
#
# Compress
#
if(!DEBUG_LEVEL)
{
ob_start('ob_gzhandler');
}
}
/**
* @args string $str = ''
* @return void
*/
function send($str = '')
{
if(is_empty($str = trim($str)))
{
$str = $this->fallback();
}
parent::send(''
. '<!DOCTYPE html>'
. '<html lang="' . $this['user']['language'] . '"'
. ' itemscope'
. ' itemtype="http://schema.org/' . $this['self']['schema'] . '">'
. '<head>'
. '<meta charset="' . $this['user']['charset'] . '">'
. '<meta http-equiv="x-ua-compatible" content="IE=edge">'
# META
. $this->head()
# Default CSS
. '<link rel="stylesheet" ' . $this->href('css') . ' type="text/css">'
. '</head>'
. '<body class="' . strtoupper($this['route']['prefix_name']) . '">'
. '<!--[if lt IE 7]>'
. '<div class="ie ie6">'
. '<![endif]-->'
. '<!--[if IE 7]>'
. '<div class="ie ie7">'
. '<![endif]-->'
. (($tmp = $this->banner())
? ''
. '<header class="container">'
. $tmp
. '</header>'
: ''
)
. $this->before()
. '<div class="container" id="main">'
. $str
. '</div>'
. $this->after()
. (($tmp = $this->contentinfo())
? ''
. '<footer class="container">'
. $tmp
. '</footer>'
: ''
)
. '<!--[if lt IE 7]>'
. '<div class="container">'
. '<div class="inner">'
. '<div class="c6 warning">'
. $this->L('E_IE_6')
. '</div>'
. '</div>'
. '</div>'
. '</div>'
. '<![endif]-->'
. '<!--[if IE 7]>'
. '<div class="container">'
. '<div class="inner">'
. '<div class="c6 warning">'
. $this->L('E_IE_7')
. '</div>'
. '</div>'
. '</div>'
. '</div>'
. '<![endif]-->'
. $this->message()
. '<!--[if gt IE 7]><!-->'
. '<noscript class="container">'
. '<div class="inner">'
. '<div class="c6 warning">'
. $this->L('E_NO_JS')
. '</div>'
. '</div>'
. '</noscript>'
# Default JS
. $this->script()
. '<!--<![endif]-->'
. '</body>'
. '</html>'
);
}
/**
* @args string $str = ''
* @return string
*/
protected function head($str = '')
{
$self = $this['self'];
if(empty($self['image']))
{
$self['image'] = $this['U_IMG_DEFAULT'];
}
$site = $this->L('site_title');
$meta = $this['meta'];
#
# Title
#
if('home' == $this['route']['name'])
{
$str .= $site;
}
else {
$str .= $self['title'] . ($self['subtitle'] ? ' - ' . $self['subtitle'] : '') . $str . ' - ' . $site;
}
$str = '<title>' . $this->clear($str) . '</title>';
#
# Fix OpenGraph
#
$og = (array) $this['og'] + array(
'site_name' => $site,
'locale' => $this['user']['locale'],
'title' => $self['title'],
'url' => SITE_HTTP . SITE_HOST . $this['route']['path'],
'image' => site_path($self['image'], true),
);
if($self['text'])
{
$meta['description'] = substr(($self['subtitle'] ? $self['subtitle'] . ' - ' : '') . strip_tags($self['text']), 0, 158);
}
#
# Append META and LINK
#
foreach($meta as $k => $v)
{
$str .= '<meta name="' . $k . '" content="' . $this->clear($v) . '">';
}
foreach($og as $k => $v)
{
$str .= '<meta property="og:' . $k . '" content="' . $this->clear($v) . '">';
}
foreach((array) $this['fb'] as $k => $v)
{
$str .= '<meta property="fb:' . $k . '" content="' . $this->clear($v) . '">';
}
foreach((array) $this['link'] as $k => $v)
{
$str .= '<link rel="' . $k . '" href="' . $this->escape($v) . '">';
}
return $str;
}
/**
* @args string $str = ''
* @return string
*/
protected function message($str = '')
{
if($str)
{
# Ok !
$id = 'message';
}
elseif($str = $this['self']['result'])
{
# Ok !
$id = 'result';
}
else {
return '';
}
return ''
. '<div id="' . $id . '" class="fullscreen">'
. '<div class="off">'
. '<div class="inner">'
. $str
. '<div class="c6 uRight">'
. '<nav class="u1 off">'
. '<span class="box ok"><a href="#return">' . $this->L('message_close') . '</a></span>'
. '</nav>'
. '</div>'
. '</div>'
. '</div>'
. '</div>';
}
/**
* @args string $str = ''
* @return string
*/
protected function banner($str = '')
{
return ''
. '<div id="banner" class="inner">'
. '<h1 class="u4">'
. $this->a('banner', array(), 'image')
. (($tmp = $this->L('site_subtitle'))
? '<small>' . $tmp . '</small>'
: ''
)
. '</h1>'
. $str
. '</div>';
}
/**
* @args string $str = ''
* @return string
*/
protected function before($str = '')
{
if('home' == $this['route']['name'])
{
return '';
}
return ''
. '<div class="container" id="before">'
. '<div class="inner">'
. '<h1 class="u4">'
. '<a href="' . $this['route']['path'] . '">' . str_replace(array('. ', '! ', '? '), array('.<br>', '!<br>', '?<br>'), $this['self']['title']) . '</a>'
. '</h1>'
. '</div>'
. (($tmp = $this->informations())
? ''
. '<div class="inner">'
. $tmp
. '</div>'
: ''
)
. $str
. '</div>';
}
/**
* @args string $str = ''
* @return string
*/
protected function informations($str = '')
{
if($dt = $this['self']['date'])
{
$dt = ucfirst($this->datetime($dt));
}
else {
$dt = '';
}
if($tmp = $this['self']['subtitle'])
{
$str .= ''
. '<b>' . $tmp . '</b>'
. ($dt
? '<span class="date"><span class="os"><br></span><span class="hs"> | </span>' . $dt . '</span>'
: ''
);
}
elseif($dt)
{
$str .= $dt;
}
if($str)
{
return '<p class="u4">' . $str . '</p>';
}
}
/**
* @args string $str = ''
* @return string
*/
protected function after($str = '')
{
if($str)
{
return ''
. '<div class="container" id="after">'
. '<div class="inner">'
. $str
. '</div>'
. '</div>';
}
}
/**
* @args string $str = ''
* @return string
*/
protected function contentinfo($str = '')
{
if($tmp = $this->L('site_copyright'))
{
$str .= ''
. '<div class="u4">'
. $tmp
. '</div>';
}
if($str)
{
return '<div class="inner">' . $str . '</div>';
}
}
/**
* @args string $str = ''
* @return string
*/
protected function script($str = '')
{
$str .= (self::$useMathJax
? 'var useMathJax = true;'
: 'var useMathJax = false;'
);
return ''
. '<script type="text/javascript">' . $str . '</script>'
. '<script type="text/javascript" ' . $this->src('js', array(), true) . '></script>';
}
}
}