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\Sky;
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
class Card extends Bootstrap
{
public $layout;
public $image;
public $body;
public $class_options = array('column_class', 'card_class', 'align', 'shadow', 'column_bg', 'padding', 'border', 'border_radius', 'hover', 'transition');
// item - image, title, description, url, when
// config - button_class, button_text, card_class, image_class, image_hover, transition, card_hover, show_title, show_date, date_format
// title_class, desc_class, subtitle_class
// Image, Heading, Date, Description, Button
public function display()
{
$this->data = (object) $this->data;
if (!isset($this->data->image) || !$this->data->image)
{
$this->layout = 'no_image';
}
else
{
$this->layout = isset($this->config['layout']) && $this->config['layout'] ? $this->config['layout'] : 'image_top';
}
// Main Card Class
$card_class = 'card ' . $this->get_class();
// Description Class
$desc_class = 'card-text my-2';
if (isset($this->config['desc_class']))
{
$desc_class .= ' ' . $this->config['desc_class'];
}
// Image
$this->image = '';
if (isset($this->data->image) && $this->data->image)
{
$this->card_image();
}
$this->body = '';
$this->body .= $this->card_header();
$this->body .= $this->html->open_div(array('class' => 'card-body'));
$this->body .= $this->card_title();
$this->body .= $this->card_subtitle();
if (isset($this->data->description))
{
$this->body .= $this->html->div($this->data->description, array('class' => $desc_class));
}
$this->body .= $this->card_html();
if (isset($this->config['button_text']) && !empty($this->config['button_text']) && $this->data->url)
{
$this->body .= $this->card_button();
}
$this->body .= $this->html->close_div();
$this->body .= $this->card_footer();
$output = '';
$output .= $this->html->open_div(array('class' => $card_class));
$function = 'layout_' . $this->layout;
$output .= $this->$function();
$output .= $this->html->close_div();
return $output;
}
// Get Html for Card Image
public function card_image()
{
$image_class = $this->get_base_image_class($this->layout);
if (isset($this->config['image_class']) && $this->config['image_class'])
{
$this->config['image_class'] .= ' ' . $image_class;
}
else
{
$this->config['image_class'] = $image_class;
}
$img = HTMLHelper::cleanImageURL($this->data->image);
$image_size = filesize(JPATH_ROOT . '/' . $img->url);
if ($image_size > 0)
{
$this->image .= $this->html->open_div(array('class' => 'overflow-hidden'));
$image = new Image(array('url' => $img->url), $this->config);
$this->image .= $image->display();
if (isset($this->data->url) && $this->data->url)
{
$this->image = '<a href="' . $this->data->url . '">' . $this->image . '</a>';
}
$this->image .= $this->html->close_div();
}
}
// Get Html for Card Title
public function card_title()
{
if (!isset($this->data->title) || !$this->data->title)
{
return;
}
// Title Class
$title_class = 'card-title';
if (isset($this->config['title_class']))
{
$title_class .= ' ' . $this->config['title_class'];
}
$output = '';
$show_title = $this->config['show_title'] ?? 1;
$linked_title = $this->config['linked_title'] ?? 1;
if ($show_title)
{
$output .= $this->html->heading($this->data->title, array('class' => $title_class), 'h5');
if (isset($this->data->url) && $this->data->url && $linked_title)
{
$target = isset($this->config['target']) && $this->config['target'] ? ' target="' . $this->config['target'] . '"' : '';
$output = '<a href="' . $this->data->url . '"' . $target . '>' . $output . '</a>';
}
}
return $output;
}
// Get Html for Card Subtitle
public function card_subtitle()
{
if (!isset($this->data->subtitle) || !$this->data->subtitle)
{
return;
}
// Subtitle Class
$subtitle_class = 'card-subtitle';
if (isset($this->config['subtitle_class']))
{
$subtitle_class .= ' ' . $this->config['subtitle_class'];
}
$output = '';
$show_subtitle = $this->config['show_subtitle'] ?? 1;
if ($show_subtitle)
{
$output .= $this->html->div($this->data->subtitle, ['class' => $subtitle_class]);
}
return $output;
}
// Get Html for Card Header
public function card_header()
{
if (!isset($this->data->header) || !$this->data->header)
{
return;
}
// Header Class
$header_class = 'card-header';
if (isset($this->config['header_class']))
{
$header_class .= ' ' . $this->config['header_class'];
}
$output = '';
$output .= $this->html->div($this->data->header, array('class' => $header_class));
return $output;
}
// Get Html for Card Footer
public function card_footer()
{
if (!isset($this->data->footer) || !$this->data->footer)
{
return;
}
// Footer Class
$footer_class = 'card-footer';
if (isset($this->config['footer_class']))
{
$footer_class .= ' ' . $this->config['footer_class'];
}
$output = '';
$output .= $this->html->div($this->data->footer, array('class' => $footer_class));
return $output;
}
// Get Html for Card Button
public function card_button()
{
$button = array(
'url' => $this->data->url,
'title' => $this->config['button_text'],
'icon' => $this->config['button_icon'] ?? '',
'target' => $this->config['target'] ?? '',
);
$button_class = (isset($this->config['button_class']) && $this->config['button_class']) ? $this->config['button_class'] : '';
$btn = new Button($button, array('button_class' => $button_class));
return $btn->display();
}
// Add Card Html
public function card_html()
{
if (!isset($this->data->html) || !$this->data->html)
{
return;
}
return $this->data->html;
}
public function layout_no_image()
{
return $this->body;
}
public function layout_image_top()
{
$output = '';
$output .= $this->image;
$output .= $this->body;
return $output;
}
public function layout_image_bottom()
{
$output = '';
$output .= $this->body;
$output .= $this->image;
return $output;
}
public function layout_image_start()
{
$output = '';
$output .= '<div class="row g-0">';
$output .= '<div class="col-md-4">';
$output .= $this->image;
$output .= '</div>';
$output .= '<div class="col-md-8">';
$output .= $this->body;
$output .= '</div>';
$output .= '</div>';
return $output;
}
public function layout_image_end()
{
$output = '';
$output .= '<div class="row g-0">';
$output .= '<div class="col-md-8">';
$output .= $this->body;
$output .= '</div>';
$output .= '<div class="col-md-4">';
$output .= $this->image;
$output .= '</div>';
$output .= '</div>';
return $output;
}
public function layout_overlay()
{
$output = '';
$alert = new Alert('Overlay Layout Coming Soon!', ['type' => 'warning']);
$output .= $alert->display();
return $output;
}
public function get_base_image_class($layout)
{
switch ($layout)
{
case 'image_top' :
return 'img-fluid card-img-top';
break;
case 'image_bottom' :
return 'img-fluid card-img-bottom';
break;
case 'image_start' :
return 'img-fluid rounded-start';
break;
case 'image_end' :
return 'img-fluid rounded-end';
break;
case 'overlay' :
return 'img-fluid card-img';
break;
default :
return 'img-fluid card-img-top';
break;
}
}
}