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;
class TfView extends BaseHtmlView
{
// General view class for frontend
use TfViewDisplayTrait;
public $app;
public $input;
public $option;
public $layout;
public $params;
public $cparams;
public $view_name;
public $today;
public $date_sql;
public $date_unix;
public $date_lc3;
public $juser;
public $user_levels;
public $url;
public $post;
public $get;
public $load_bs = 0;
public $load_rs;
public $title;
public function __construct($config = [])
{
parent::__construct($config);
$this->app = Factory::getApplication();
$this->input = Factory::getApplication()->input;
$this->option = $this->input->get('option');
$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->juser = $this->app->getIdentity();
$this->user_levels = $this->juser->getAuthorisedViewLevels();
$this->cparams = ComponentHelper::getParams($this->option);
$this->url = Uri::getInstance()->toString();
$this->post = $this->input->post->getArray();
$this->get = $this->input->get->getArray();
}
// Depreciated - Divided into two parts: init_view1 and init_view2
public function initiate_view()
{
$this->layout = $this->getLayout();
$this->view_name = $this->getName();
// Active menu parameters
$this->params = $this->app->getMenu()->getActive()->getParams();
// Load Resources
$r = new TResource();
$r->add_resources($this->cparams->get('load_rs'));
$this->_prepareDocument();
}
public function init_view1()
{
$this->layout = $this->getLayout();
$this->view_name = $this->getName();
}
public function init_view2()
{
if (count($errors = $this->get('Errors')))
{
//throw new GenericDataException(implode("\n", $errors), 500);
}
// Active menu parameters
$this->params = $this->app->getMenu()->getActive()->getParams();
// Load Resources
$r = new TResource();
$r->add_resources($this->cparams->get('load_rs'));
$this->_prepareDocument();
}
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);
}
//
public function action_buttons($actions = array())
{
$output = '';
foreach ($actions as $action)
{
$output .= $this->action_button($action[0], $action[1], $action[2], $action[3]);
}
return $output;
}
public function action_button($text, $task, $class = 'btn btn-primary', $icon = '', $hidden = [])
{
$output = '<form method="post" class="d-inline">';
$output .= '<input type="hidden" name="option" value="' . $this->option . '">';
$output .= '<input type="hidden" name="task" value="' . $task . '">';
foreach ($hidden as $k => $v)
{
$output .= '<input type="hidden" name="' . $k . '" value="' . $v . '">';
}
$output .= '<button type="submit" class="me-2 ' . $class . '">';
if (!empty($icon))
{
$output .= '<i class="' . $icon . '"></i> ';
}
if (!empty($text))
{
$output .= Text::_($text);
}
$output .= '</button>';
$output .= '</form>';
return $output;
}
// 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);
}
}
// Override to get custom message
public function get_no_results_msg()
{
return Text::_('JGLOBAL_NO_MATCHING_RESULTS');
}
// 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>';
}
}