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;
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Structuring_content/Basic_HTML_syntax
class THtml
{
// element - opening tag, closing tag, content, attributes (key, value), boolean attributes
// open_tag(), cose_tag(), element()
public $html;
public function open_tag($tag, $attributes = [], $bools = [])
{
$output = '<' . $tag;
// Remove spaces from class attribute
if (isset($attributes['class']) && $attributes['class'])
{
$attributes['class'] = trim(preg_replace('/\s+/', ' ', $attributes['class']));
}
if (!empty($attributes))
{
foreach ($attributes as $k => $v)
{
// Replace underscore with dashes for aria and data attributes
$k = str_replace('_', '-', $k);
if (trim($v))
{
$output .= ' ' . $k . '="' . $v . '"';
}
}
}
// $bools - boolean attributes
foreach ($bools as $b)
{
$output .= ' ' . $b;
}
$output .= '>' . "\n";
$this->html .= $output;
return $output;
}
public function close_tag($tag)
{
$output = '</' . $tag . '>' . "\n";
$this->html .= $output;
return $output;
}
// Element - opening tag (with attributes), closing tag, content
public function element($tag, $content, $attributes = [], $bools = [])
{
if (empty($content) || $content == '')
{
return;
}
$output = $this->open_tag($tag, $attributes, $bools);
$output .= $content . "\n";
$output .= $this->close_tag($tag);
$this->html .= $output;
return $output;
}
public function add_content($content = '')
{
$this->html .= $content;
return $content;
}
public function get_output()
{
return $this->html;
}
}
/*
Common attributes - class, id, style, title
*/