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\Front;
defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\Router\Route;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Uri\Uri;
use TechFry\Library\TResource;
use TechFry\Library\View\Html\TBody;
// Common Objects for All Views
class TView extends BaseHtmlView
{
use TViewDisplayTrait;
public $app;
public $input;
public $active;
public $option;
public $layout;
public $cparams; // Component Parameters
public $mparams; // Menu Parameters
public $params;
public $view_name;
public $today;
public $date_sql;
public $date_unix;
public $date_lc3;
public $user;
public $user_levels;
public $url;
public $post;
public $get;
public $load_bs = 0;
public $load_rs;
public $title;
public $html;
public function __construct($config = [])
{
parent::__construct($config);
$this->app = Factory::getApplication();
$this->user = $this->getCurrentUser();
$this->user_levels = $this->user->getAuthorisedViewLevels();
$this->active = $this->app->getMenu()->getActive();
$this->mparams = $this->active->getParams();
$this->layout = $this->getLayout();
$this->view_name = $this->getName();
$this->input = $this->app->input;
$this->option = $this->input->get('option');
$this->cparams = ComponentHelper::getParams($this->option);
// Merge component and menu parameters
$this->params = clone $this->cparams;
$this->params->merge($this->mparams);
$this->com_name = substr($this->option, 6);
$this->title_prefix = 'TF ' . ucwords($this->com_name) . ': ';
$this->today = Factory::getDate();
$this->date_sql = $this->today->toSql();
$this->date_unix = $this->today->toUnix();
$this->date_lc3 = $this->today->format(Text::_('DATE_FORMAT_LC3'));
$this->url = Uri::getInstance()->toString();
$this->post = $this->input->post->getArray();
$this->get = $this->input->get->getArray();
// Load Resources
$r = new TResource();
$r->add_resources($this->cparams->get('load_rs'));
$this->html = new TBody();
}
protected function _prepareDocument()
{
$pathway = $this->app->getPathway();
// 01. Page heading of document
$menus = $this->app->getMenu();
$menu = $menus->getActive();
if ($menu)
{
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
}
// 02. Add item path to breadcrumb
// $pathway->addItem($this->title);
// 03. Title of document
if ($this->title)
{
$title = $this->title;
}
else
{
$title = $this->params->get('page_title', $menu->title);
}
$this->setDocumentTitle($title);
}
// Handle access if frontend view is not permitted
public function handle_access($message = '', $type = 'error')
{
$app = Factory::getApplication();
// 1. Login for guest user
if ($this->juser->get('guest'))
{
$return = base64_encode(Uri::getInstance());
$login_url_with_return = Route::_('index.php?option=com_users&view=login&return=' . $return);
$app->enqueueMessage(Text::_('COM_TF_LOGIN_TO_CONTINUE'), 'notice');
$app->redirect($login_url_with_return, 403);
}
// 2. Display message
else
{
if (empty($message))
{
$message = Text::_('JERROR_ALERTNOAUTHOR');
}
$app->enqueueMessage($message, $type);
$app->setHeader('status', 403, true);
}
}
// Start page display
public function start_page_layout()
{
if (!empty($this->params->get('view_class')))
{
echo '<div class="' . $this->params->get('view_class') . '">';
}
if ($this->params->get('show_page_heading'))
{
echo '<h1>' . $this->escape($this->params->get('page_heading')) . '</h1>';
}
if (!empty($this->params->get('image')))
{
echo '<img class="img-thumbnail mb-3" src="' . $this->params->get('image') . '" title="' . $this->escape($this->params->get('page_heading')) . '">';
}
if (!empty($this->params->get('description')))
{
echo $this->params->get('description');
}
}
// End page display
public function end_page_layout()
{
if (!empty($this->params->get('view_class')))
{
echo '</div>';
}
}
// Use for Debugging
public function printme($data)
{
echo '<pre>';
print_r($data);
echo '</pre>';
}
}