Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Html/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Html/TBody.php

<?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 TBody extends THtml
{
    // 1. Paragraph
    public function p($content, $attributes = [])
    {        
        return $this->element('p', $content, $attributes);
    }
    
    // 2. Headings
    public function heading($content, $attributes = [], $level = 'h1')
    {
        return $this->element($level, $content, $attributes);
    }

    public function h1($content, $attributes = [])
    {        
        return $this->element('h1', $content, $attributes);
    }

    public function h2($content, $attributes = [])
    {        
        return $this->element('h2', $content, $attributes);
    }

    public function h3($content, $attributes = [])
    {        
        return $this->element('h3', $content, $attributes);
    }

    public function h4($content, $attributes = [])
    {        
        return $this->element('h4', $content, $attributes);
    }

    public function h5($content, $attributes = [])
    {        
        return $this->element('h5', $content, $attributes);
    }

    public function h6($content, $attributes = [])
    {        
        return $this->element('h6', $content, $attributes);
    }
    
    // 3. Links
    public function a($content, $attributes = [], $bool = [])
    {
        // href, title, target
        // download
        
        if (!isset($attributes['href']) || $attributes['href'] == '')
        {
            $attributes['href'] = '#';
        }

        return $this->element('a', $content, $attributes, $bool);
    }
    
    // 4. Image
  	public function img($src, $attributes = [])
    {
    	// src, alt, width, height, title

        // For Absolute URLs
      	if (isset(parse_url($src)['host']))
        {
        	
        }
      	else
        {
        	$image = HTMLHelper::cleanImageURL($src);
        	$image_url = $image->url;
          	$src = $image_url;
        }

        $image_info = getimagesize($image_url);
        
        if (!$image_info)
        {
            return;
        }
        
        $attributes['src'] = $src;

        return $this->open_tag('img', $attributes);
    }

    // 5. Lists - Unordered, Ordered, Definition
    public function ul($items, $attributes = [], $li_attributes = [])
    {
        if (empty($items))
        {
            return;
        }

        $output = $this->open_tag('ul', $attributes);
        
        foreach ($items as $item)
        {
            $output .= $this->element('li', $item, $li_attributes);
        }
        
        $output .= $this->close_tag('ul');
        
        return $output;
    }

    public function ol($items, $attributes = [], $li_attributes = [])
    {
        if (empty($items))
        {
            return;
        }

        $output = $this->open_tag('ol', $attributes);
        
        foreach ($items as $item)
        {
            $output .= $this->element('li', $item, $li_attributes);
        }
        
        $output .= $this->close_tag('ol');
        
        return $output;
    }

    public function dl($items, $attributes = [])
    {
        $output = $this->open_tag('dl');
        
        foreach ($items as $dt => $dd)
        {
            $output .= $this->element('dt', $dt);
            $output .= $this->element('dd', $dd);
        }

        $output = $this->close_tag('dl');
    }
    
    // 6. Table
    public function table($items = [], $attributes = [])
    {
        if (empty($items))
        {
            return;
        }

        $theads = $items['theads'] ?? [];
        unset($items['theads']);

        $output = $this->open_tag('table', $attributes);

        if ($theads)
        {
            $output .= $this->open_tag('thead');
            $output .= $this->open_tag('tr');

            foreach ($theads as $head)
            {
                $output .= $this->element('th', $head);
            }

            $output .= $this->close_tag('tr');
            $output .= $this->close_tag('thead');
        }
        
        $output .= $this->open_tag('tbody');

        foreach ($items as $row)
        {
            $output .= $this->open_tag('tr');
                foreach ($row as $column)
                {
                    $output .= $this->element('td', $column);
                }
            $output .= $this->close_tag('tr');
        }

        $output .= $this->close_tag('tbody');
        
        $output .= $this->close_tag('table');
        
        return $output;
    }
    
    // 7. Div
  	public function div($content, $attributes = [], $bool = [])
    {
        $output = $this->open_div($attributes, $bool);

        $output .= $this->add_content($content);

        $output .= $this->close_div();

        return $output;
    }

    public function open_div($attributes = [], $bool = [])
    {
        return $this->open_tag('div', $attributes, $bool);
    }
  
  	public function close_div()
    {
        return $this->close_tag('div');
    }

    // 8. span
    public function span($content, $attributes = [])
    {
        // Empty content is allowed
        
        $output = $this->open_tag('span', $attributes);

        $output .= $this->add_content($content);

        $output .= $this->close_tag('span');

        return $output;
    }

    // 9. button
    public function button($content, $attributes = [], $bool = [])
    {
        // Empty content is allowed
        
        $output = $this->open_tag('button', $attributes, $bool);

        $output .= $content;

        $output .= $this->close_tag('button');

        return $output;
    }
    
    // 10. blockquote
    public function blockquote($content, $attributes = [])
    {
        $output = This->open_tag('blockquote');

        $output .= $this->close_tag('blockquote');

        return $output;
    }

    // 9. Video
    public function video($src, $attributes = [], $bool = [])
    {
        // $attribs - width, height, poster
        // $bool - controls, autoplay, loop, muted
        
        if ($src == '')
        {
            return;
        }

        $output = $this->open_tag('video', $attributes, $bool);
        $output .= $this->close_tag('video');

        return $output;
    }

    // 10. Audio
    public function audio($src, $attributes = [], $bool = [])
    {
        // $attribs
        // $bool - controls, autoplay, loop, muted
        
        if ($src == '')
        {
            return;
        }

        $output = $this->open_tag('audio', $attributes, $bool);
        $output .= $this->close_tag('audio');

        return $output;
    }

    // To Do: hr, pre and code

    /*
    Semantic Elements - header, nav, main (article, section, div, aside), footer
        address, time
    */
}