Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Sky/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Sky/Carousel.php

<?php
/*
* @package		Tech Fry Library
* @license		https://www.gnu.org/licenses/gpl-3.0.en.html
*/

namespace TechFry\Library\View\Sky;

defined('_JEXEC') or die;

use Joomla\CMS\HTML\HTMLHelper;
use TechFry\Library\TResource;

class Carousel extends Bootstrap
{
  	public $total_slides;

    public $items = array();
    
    public $images = array();
  
  	public function display()
    {
    	// config - controls, indicators, fade, auto_play, theme, item_class, title_class, description_class, button_class, button_text
		// item - image, title, description, url

        $this->items = (array) $this->data;

        $this->total_slides = \count($this->items);

		$carousel_class = 'carousel slide';
		if ($this->config['effect'] == 'fade')
		{
			$carousel_class .= ' carousel-fade';
		}
	
		$ride = $this->config['auto_play'] ? ' data-bs-ride="carousel"' : '';

      	$output = '<div id="carousel" class="' . $carousel_class . '"' . $ride . '>';

			// Indicators
			if ($this->config['indicators'])
			{
				$output .= $this->indicators();
			}

            // Carouse Items
            $output .= '<div class="carousel-inner">';
				$output .= $this->carousel_items();
			$output .= '</div>';
      	
      		// Previous and Next Controls
			if ($this->config['controls'])
			{
				$output .= $this->controls();
			}
      	
      	$output .= '</div>';

		// Add CSS
		$this->include_tfcss('carousel');

		// Add JavaScript
		$this->include_bsjs('carousel');
      
      	return $output;
    }

    // Carousel Indicators
    public function indicators()
    {
        $output = '<div class="carousel-indicators">';
		for ($n = 0; $n < $this->total_slides; $n++)
		{
			$active = ($n == 0) ? ' class="active" aria-current="true"' : '';
				
			$output .= '<button type="button" data-bs-target="#carousel" data-bs-slide-to="' . $n . '"' . $active . ' aria-label="Slide ' . $n . '"></button>';
		}
		$output .=  '</div>';

        return $output;
    }

    // Carousel Controls (Arrows)
    public function controls()
    {
        $output = '';
        
        // Previous
        $output .= '<button class="carousel-control-prev" type="button" data-bs-target="#carousel" data-bs-slide="prev">';
    		$output .= '<span class="carousel-control-prev-icon" aria-hidden="true"></span>';
    		$output .= '<span class="visually-hidden">Previous</span>';
  		$output .= '</button>';
      	
        // Next
      	$output .= '<button class="carousel-control-next" type="button" data-bs-target="#carousel" data-bs-slide="next">';
    		$output .= '<span class="carousel-control-next-icon" aria-hidden="true"></span>';
    		$output .= '<span class="visually-hidden">Next</span>';
  		$output .= '</button>';

        return $output;
    }

	// Carouse Items
	public function carousel_items()
	{
		$output = '';

		$interval = $this->config['auto_play'] ? ' data-bs-interval="' . $this->config['auto_play'] * 1000 . '"' : '';
		
		$slide_number = 0;
		foreach ($this->items as $item)
		{
			$item = (array) $item;
		
			$image = HTMLHelper::cleanImageURL($item['image']);
			
			$active = ($slide_number == 0) ? ' active' : '';
			
			$output .= '<div class="carousel-item' . $active . '"' . $interval . '>';
				$output .= '<img src="' . $image->url . '" class="d-block w-100">';

				$output .= '<div class="carousel-caption">';

					if (isset($item['title']) && $item['title'])
					{
						$output .= '<h2>' . $item['title'] . '</h2>';
					}

					if (isset($item['description']) && $item['description'])
					{
						$output .= '<p class="lead">' . $item['description'] . '</p>';
					}

					if (isset($item['url']) && $item['url'])
					{
						$button = array(
							'url' => $item['url'],
							'title' => $this->config['button_text'],
							'icon' => $this->config['button_icon'] ?? '',
						);

						$btn = new Button($button, array('button_class' => $this->config['button_class']));

						$output .= $btn->display();
					}

				$output .= '</div>';

			$output .= '</div>';

			$slide_number++;
		}

		return $output;
	}
  
  	public function get_output_amp()
    {
        foreach ($this->data as $i => $item)
        {
            $item = (array) $item;
            
            $image = HTMLHelper::cleanImageURL($item['image']);
            $this->images[] = $image->url;
        }
      
        $r = new TResource();     
      	$r->add_resource('https://cdn.ampproject.org/v0/amp-carousel-0.2.js', 'js', array('async' => 'async', 'custom-element' => 'amp-carousel'));
      	
        $output = '';
      
      	$output .= '<amp-carousel width="750" height="100" layout="responsive" type="slides" role="region" aria-label="Carousel">';
      	foreach ($this->images as $image)
        {
         	$output .= '<amp-img src="' . $image . '"  width="750" height="100" layout="responsive">';
            $output .= '</amp-img>';
        }
      	$output .= '</amp-carousel>';

      	return $output;
    }
}