1
"Recently, thanks to an idea Michael came up with for the Publisher module, creating independent blocks has become much easier, and I wanted to test it with a nice theme. Very soon, I will release the PodTalk theme compatible with Publisher."
Demo: https://erenyumak.com/ato/
Code added by
Michael to theme_autorun.php
/** @var XoopsTpl */
global $xoopsTpl;
if (!empty($xoopsTpl)) {
$xoopsTpl->addConfigDir(__DIR__);
}
require dirname(__DIR__,2) . '/modules/publisher/preloads/autoloader.php';
use XoopsModulesPublisher{
Constants,
Helper,
Item
};
// Initialize helper and text sanitizer
$myts = MyTextSanitizer::getInstance();
/**
* Function to fetch items
*/
function getPublisherItems($limit, $sort = 'RAND()', $order = '')
{
$helper = Helper::getInstance();
$itemsObj = $helper->getHandler('Item')->getItems(
$limit,
$start = 0,
[Constants::PUBLISHER_STATUS_PUBLISHED],
-1,
$sort,
$order,
'',
true,
$criteria = null
);
$items = [];
if ($itemsObj) {
foreach ($itemsObj as $itemObj) {
$newItem = [
'itemid' => $itemObj->itemid(),
'title' => $itemObj->title(),
'body' => $itemObj->body(),
'votes' => $itemObj->votes(),
'counter' => $itemObj->counter(),
'comments' => $itemObj->comments(),
'image' => XOOPS_URL . '/uploads/blank.gif',
];
$images = $itemObj->getImages();
if (isset($images['main']) && is_object($images['main'])) {
$newItem['image'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name');
}
$items[] = $newItem;
}
}
return $items;
}
// Fetch and assign items for each template
$xoopsTpl->assign('breakingItems', getPublisherItems(4));
$xoopsTpl->assign('featuredItems', getPublisherItems(3));
$xoopsTpl->assign('fourLastedRandomItems', getPublisherItems(4));
$xoopsTpl->assign('itemBreakingItems', getPublisherItems(10));
$xoopsTpl->assign('lastedRandomItems', getPublisherItems(4));
$xoopsTpl->assign('newsItems', getPublisherItems(4));
$xoopsTpl->assign('oneLastedRandomItem', getPublisherItems(1));
$xoopsTpl->assign('rightLastedRandomItems', getPublisherItems(8));
$xoopsTpl->assign('sliderItems', getPublisherItems(9));
// Assign XOOPS URL
$xoopsTpl->assign('xoops_url', XOOPS_URL);
Example block usage
<{foreach item=item from=$sliderItems}>
<div class="owl-carousel-info-wrap item">
<img src="<{$item.image}>"
class="owl-carousel-image img-fluid" alt="<{$item.title}>">
<div class="owl-carousel-info">
<h4 class="mb-2">
<a href="<{$xoops_url}>/modules/publisher/item.php?itemid=<{$item.itemid}>">
<{$item.title|truncate:15}>
a>
<img src="<{xoImgUrl}>images/verified.png" class="owl-carousel-verified-image img-fluid" alt="<{$item.title}>">
h4>
<span class="badge">Reads: <{$item.counter}>span>
<span class="badge">Votes: <{$item.votes}>span>
div>
div>
<{/foreach}>