Your IP : 216.73.216.240
<?php
/*
* @package Tech Fry Library
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
*/
namespace TechFry\Library\View\Html;
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
class THead extends THtml
{
// 1. Title
public function title($title)
{
return $this->element('title', $title);
}
// 2. Meta tag in head - author, description, generator
public function meta($attributes = [])
{
// $attributes - name (author, description), content
return $this->open_tag('meta', $attributes);
}
// Character encoding
public function charset($charset = 'UTF-8')
{
return $this->meta(array('charset' => strtolower($charset)));
}
public function author($content)
{
return $this->meta(array('name' => 'author', 'content' => $content));
}
public function description($content)
{
return $this->meta(array('name' => 'description', 'content' => $content));
}
public function responsive()
{
return $this->meta(array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'));
}
// 3. Open Graph Tags
public function og_image($content)
{
return $this->meta(array('property' => 'og:image', 'content' => $content));
}
public function og_description($content)
{
return $this->meta(array('property' => 'og:description', 'content' => $content));
}
public function og_title($content)
{
return $this->meta(array('property' => 'og:title', 'content' => $content));
}
// 4. Favicon
public function favicon($href)
{
// <link rel="icon" href="favicon.ico" type="image/x-icon" />
$attributes = array(
'rel' => 'icon',
'href' => $href,
'type' => 'image/x-icon',
);
return $this->open_tag('link', $attributes);
}
// 5. Link
public function link($attributes = [])
{
return $this->open_tag('link', $attributes);
}
public function stylesheet($href)
{
// <link rel="stylesheet" href="my-css-file.css" />
if (empty($href))
{
return;
}
$attributes = array(
'rel' => 'stylesheet',
'href' => $href,
'type' => 'text/css',
);
return $this->link($attributes);
}
public function script($src = '')
{
// <script src="my-js-file.js" defer></script>
if (empty($src))
{
return;
}
$output = '<script src="' . $src . '" defer></script>';
$attributes = array(
'src' => $src,
);
$bools = array('defer'); // Load the JavaScript after the page has finished parsing the HTML
$output = $this->open_tag('script', $attributes, $bools);
$output .= $this->close_tag('script');
return $output;
}
public function js($code, $attribs = [])
{
$output = $this->element('script', $code, $attribs);
return $output;
}
public function style($code)
{
$output = '<style>';
$output .= $code;
$output .= '</style>' . "\n";
return $output;
}
// CSS Code
public function css($selector, $defs = [])
{
$output = '';
if (!empty($defs))
{
foreach ($defs as $k => $v)
{
if ($v != '')
{
$output .= $k . ':' . $v . ';';
}
}
}
if ($output)
{
return $selector . '{' . $output . '}' . "\n";
}
return;
}
}