Your IP : 216.73.216.240
<?php
/**
* @copyright
* @package Easybook Reloaded - EBR for Joomla! 3.x
* @author Viktor Vogel <admin@kubik-rubik.de>
* @version 3.4.1.1-FREE - 2021-08-29
* @link https://kubik-rubik.de/ebr-easybook-reloaded
*
* @license GNU/GPL
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
defined('_JEXEC') || die('Restricted access');
use EasybookReloaded\{Helper, Content};
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\{Factory, Uri\Uri, HTML\HTMLHelper, Router\Route, Menu\AbstractMenu, Document\HtmlDocument};
/**
* Class EasybookReloadedViewEasybookReloaded
*
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
class EasybookReloadedViewEasybookReloaded extends HtmlView
{
/**
* @var object $entries
* @since 3.4.0-FREE
*/
protected $entries;
/**
* @var object $gbData
* @since 3.4.0-FREE
*/
protected $gbData;
/**
* @var int $count
* @since 3.4.0-FREE
*/
protected $count;
/**
* @var object $pagination
* @since 3.4.0-FREE
*/
protected $pagination;
/**
* @var string $heading
* @since 3.4.0-FREE
*/
protected $heading;
/**
* @var int $entryId
* @since 3.4.0-FREE
*/
protected $entryId;
/**
* @var int $gbId
* @since 3.4.0-FREE
*/
protected $gbId;
/**
* Executes and displays a template file
*
* @param string|null $tpl
*
* @return mixed
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
public function display($tpl = null)
{
// Check whether a guestbook ID is set in the request
$gbId = $this->get('GbId');
if (!is_int($gbId)) {
return parent::display('error');
}
// Get the required data
$this->entries = $this->get('Data');
$this->gbData = $this->get('GbData');
$this->count = $this->get('Total');
$this->pagination = $this->get('Pagination');
$this->entryId = Factory::getApplication()->input->getInt('entryid');
$this->gbId = $gbId;
// Set the head data
$this->addHeadData();
// Remove cache from Page Cache plugin if required
Content::cleanCache($gbId);
if ($gbId === 0) {
$this->setLayout('all');
return parent::display();
}
parent::display($tpl);
}
/**
* Adds the head data
*
* @throws Exception
* @since 3.4.0-FREE
* @version 3.4.1.0-FREE
*/
private function addHeadData(): void
{
/** @var HtmlDocument $document */
$document = Factory::getDocument();
// Set CSS File
$cssFile = 'easybookreloaded';
$template = (int)Helper::getParams('template', 0);
if ($template === 1) {
$cssFile .= 'dark';
} elseif ($template === 2) {
$cssFile .= 'transparent';
}
$document->addStyleSheet(Uri::root() . 'components/com_easybookreloaded/css/' . $cssFile . '.css');
// JavaScript
HTMLHelper::_('jquery.framework');
$jsCode = 'jQuery(document).ready(function() {
jQuery(".easy_top", this).each(function() {
jQuery(this).css("cursor", "pointer");
jQuery(this).click(function() {
let url = new URL(window.location.href);
if (!url.href.match(/entryid/)) {
url.searchParams.append("entryid", jQuery(this).attr("data-id"));
window.location.href = url.href;
}
});
});
});';
$document->addScriptDeclaration($jsCode);
// Show RSS Feed
$link = '&format=feed&limitstart=';
$attribs = ['type' => 'application/rss+xml', 'title' => 'RSS 2.0'];
$document->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
$attribs = ['type' => 'application/atom+xml', 'title' => 'Atom 1.0'];
$document->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
// Add meta data from menu link
$menus = AbstractMenu::getInstance('site');
$menu = $menus->getActive();
if (!empty($menu)) {
if ($menu->params->get('menu-meta_description')) {
$document->setDescription($menu->params->get('menu-meta_description'));
}
if ($menu->params->get('menu-meta_keywords')) {
$document->setMetaData('keywords', $menu->params->get('menu-meta_keywords'));
}
if ($menu->params->get('robots')) {
$document->setMetaData('robots', $menu->params->get('robots'));
}
}
$this->heading = $document->getTitle();
// Add HTML Head Link
if (method_exists($document, 'addHeadLink')) {
$paginationData = $this->pagination->getData();
if ($paginationData->start->link) {
$document->addHeadLink($paginationData->start->link, 'first');
}
if ($paginationData->previous->link) {
$document->addHeadLink($paginationData->previous->link, 'prev');
}
if ($paginationData->next->link) {
$document->addHeadLink($paginationData->next->link, 'next');
}
if ($paginationData->end->link) {
$document->addHeadLink($paginationData->end->link, 'last');
}
}
}
}