Новости Joomla

0 Пользователей и 1 Гость просматривают эту тему.
  • 1 Ответов
  • 803 Просмотров
*

Bake

  • Осваиваюсь на форуме
  • 24
  • 0 / 0
  • обычный разработчик сайтов
Работаю над кастомизацией шаблона Кассиопея под новостной сайт.

В Joomla 3 работала конструкция вызова функции в начале страницы в макете (components/com_tags/views/tag/tmpl/default_items.php):
Код
if(!class_exists('ContentModelArticle')) require_once JPATH_ROOT.'/components/com_content/models/article.php';
$article = new ContentModelArticle;

Затем можно было вывести хиты для превью материала примерно так:
Код
<dd class="uk-article-meta">
<meta itemprop="interactionCount" content="UserPageVisits:<?php $youArticle = $article->getItem($item->content_item_id); ?>" />
<span data-uk-tooltip title=" <?= JText::_('COM_TAGS_SHOWHITS_LABEL')?>">&nbsp;<span uk-icon="icon:bolt"></span> <span class=""><?php echo JText::sprintf($youArticle->hits); ?></span></span>
</dd>

Однако, в Joomla 4 вызовы функции и хелперы переделали. Что-то не получается вывести хиты.

Просьба подсказать — куда копать.

Версия  Joomla! 4.0.0-rc4 Release Candidate [ Mañana ] 13-July-2021

Пробовал вызывать так:
Код
if(!class_exists('ArticleModel')) require_once JPATH_ROOT.'/components/com_content/src/Model/ArticleModel.php';
$article = new ArticleModel;
Но ничего не выходит. Выдает ошибку.

Пример страницы сверстанной:
https://vst.webmarka.kz/sport
 
Сам файл default_items.php (переопределенный):
Код
<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_tags
 *
 * [member=126442]copyright[/member]   (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Tags\Site\Helper\RouteHelper;

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('com_tags.tag-default');

// Get the user object.
$user = Factory::getUser();

// Check if user is allowed to add/edit based on tags permissions.
// Do we really have to make it so people can see unpublished tags???
$canEdit      = $user->authorise('core.edit', 'com_tags');
$canCreate    = $user->authorise('core.create', 'com_tags');
$canEditState = $user->authorise('core.edit.state', 'com_tags');

 

JLoader::register('JUImage',  JPATH_LIBRARIES . '/juimage/JUImage.php');

$juImg = new JUImage();
?>
<div class="com-content-category-blog blog">
<form action="<?php echo htmlspecialchars(Uri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm">
<?php if ($this->params->get('filter_field') || $this->params->get('show_pagination_limit')) : ?>
<?php if ($this->params->get('filter_field')) : ?>
<div class="com-tags-tags__filter btn-group">
<label class="filter-search-lbl visually-hidden" for="filter-search">
<?php echo Text::_('COM_TAGS_TITLE_FILTER_LABEL'); ?>
</label>
<input
type="text"
name="filter-search"
id="filter-search"
value="<?php echo $this->escape($this->state->get('list.filter')); ?>"
class="inputbox" onchange="document.adminForm.submit();"
placeholder="<?php echo Text::_('COM_TAGS_TITLE_FILTER_LABEL'); ?>"
>
<button type="submit" name="filter_submit" class="btn btn-primary"><?php echo Text::_('JGLOBAL_FILTER_BUTTON'); ?></button>
<button type="reset" name="filter-clear-button" class="btn btn-secondary"><?php echo Text::_('JSEARCH_FILTER_CLEAR'); ?></button>
</div>
<?php endif; ?>
<?php if ($this->params->get('show_pagination_limit')) : ?>
<div class="btn-group float-end">
<label for="limit" class="visually-hidden">
<?php echo Text::_('JGLOBAL_DISPLAY_NUM'); ?>
</label>
<?php echo $this->pagination->getLimitBox(); ?>
</div>
<?php endif; ?>

<input type="hidden" name="limitstart" value="">
<input type="hidden" name="task" value="">
<?php endif; ?>
</form>

<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('INFO'); ?></span>
<?php echo Text::_('COM_TAGS_NO_ITEMS'); ?>
</div>
<?php else : ?>
<div class="com-content-category-blog__items blog-items row columns-3">
<?php foreach ($this->items as $i => $item) : ?>
<?php if ($item->core_state == 0) : ?>
<div class="list-group-item-danger">
<?php else : ?>
<div class="com-content-category-blog__item blog-item"
<?php endif; ?>
<?php // Content is generated by content plugin event "onContentAfterTitle" ?>
<?php echo $item->event->afterDisplayTitle; ?>
<?php $images  = json_decode($item->core_images); ?>
<?php if ($this->params->get('tag_list_show_item_image', 1) == 1 && !empty($images->image_intro)) : ?>
<?php

$thumb = $juImg->render($images->image_intro, [
'w'      => '390',
'h'      => '260',
'q'         => '65',
'zc'        => 'C',
'far'        => 'C',
'webp'      => true,
'webp_q'    => '60',
'webp_maxq' => '65',
'cache'     => 'img'

]);
?>
<a href="<?php echo Route::_(RouteHelper::getItemRoute($item->content_item_id, $item->core_alias, $item->core_catid, $item->core_language, $item->type_alias, $item->router)); ?>">
<picture>


<source srcset="<?php echo $thumb->webp; ?>" type="image/webp" width="390" height="260">
<img <?php if ($images->image_intro_caption) {
                echo 'class="caption" title="' . htmlspecialchars($images->image_intro_caption) . '"';
            } ?> src="<?php echo $thumb->img; ?>" width="390" height="260" class="uk-transition-scale-up uk-transition-opaque uk-border-rounded uk-brightness2"
alt="<?php echo $this->escape($item->core_title); ?> "  itemprop="thumbnailUrl"/>
</picture>
</a>
<?php endif; ?>
<div  class="item-content">

<div class="page-header">
<h2 class="lh-1" itemprop="name">
<a href="<?php echo Route::_($item->link); ?>" itemprop="url" class="fs-3 text-decoration-none">
<?php echo $this->escape($item->core_title); ?></a>
</h2>
</div>
 <dl class="article-info text-muted d-flex p-2 ">


<dt class="article-info-term">
</dt>

 







<dd class="published">
<time datetime="<?php echo JHtml::_('date', $item->core_created_time, JText::_('DATE_FORMAT_LC4')); ?>" itemprop="datePublished" >
<span class="icon-calendar icon-fw" aria-hidden="true"></span> <span class=""><?php echo JHtml::_('date', $item->core_created_time, JText::_('d.m.Y')); ?></span>
</time>
</dd>
<dd class="hits">
<span class="icon-eye icon-fw" aria-hidden="true"></span>
<meta itemprop="interactionCount" content="UserPageVisits:<?php echo $item->core_hits; ?>">
<?php echo $item->core_hits; ?>
</dd>
</dl>
<?php if ($this->params->get('tag_list_show_item_description', 1)) : ?>
<?php // Content is generated by content plugin event "onContentBeforeDisplay" ?>
<?php echo $item->event->beforeDisplayContent; ?>
<span class="tag-body">
<?php echo HTMLHelper::_('string.truncate', $item->core_body, $this->params->get('tag_list_item_maximum_characters')); ?>
</span>
<?php // Content is generated by content plugin event "onContentAfterDisplay" ?>
<?php echo $item->event->afterDisplayContent; ?>
<?php endif; ?>
</div></div>
<?php endforeach; ?>
</div>

<?php endif; ?>
</div>

На сайте также используется библиотека ресайзинга изображений JUImage:
https://github.com/Joomla-Ukraine/JUImage
« Последнее редактирование: 14.02.2022, 10:16:53 от Bake »
*

Bake

  • Осваиваюсь на форуме
  • 24
  • 0 / 0
  • обычный разработчик сайтов
Ни у кого никаких идей нет?
Чтобы оставить сообщение,
Вам необходимо Войти или Зарегистрироваться