<?php
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
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.
*/
/**
* @copyright The XUUPS Project http://sourceforge.net/projects/xuups/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @package Publisher
* @subpackage Blocks
* @since 1.0
* @author trabis <lusopoemas@gmail.com>
* @author Bandit-x
* @author Mowaffak
*/
use XoopsModules\Publisher;
use XoopsModules\Publisher\Constants;
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
require_once dirname(__DIR__) . '/include/common.php';
/**
* @param $options
*
* @return bool|array
*/
function publisher_latest_news_show($options)
{
$block = [];
/** @var Publisher\Helper $helper */
$helper = Publisher\Helper::getInstance();
$helper->loadLanguage('main');
/** @var Publisher\ItemHandler $itemHandler */
$itemHandler = $helper->getHandler('Item');
// xoops_loadLanguage('main', 'publisher');
$start = $options[0]; // You can show articles from specified range
$limit = $options[1];
$columnCount = $options[2];
$letters = $options[3];
$selectedStories = $options[4];
$sort = $options[9];
$order = Publisher\Utility::getOrderBy($sort);
$imgWidth = $options[11];
$imgHeight = $options[12];
$border = $options[13];
$bordercolor = $options[14];
$block['spec']['columnwidth'] = (1 / $columnCount * 100);
$allcats = false;
if (!isset($options[29])) {
$allcats = true;
} elseif (in_array(0, explode(',', $options[29]))) {
$allcats = true;
}
// creating the ITEM objects that belong to the selected category
if ($allcats) {
$criteria = null;
} else {
$criteria = new \CriteriaCompo();
$criteria->add(new \Criteria('categoryid', '(' . $options[29] . ')', 'IN'));
}
// Use specific ITEMS
if (0 != $selectedStories) {
unset($criteria); //removes category option
$criteria = new \CriteriaCompo();
$criteria->add(new \Criteria('itemid', '(' . $selectedStories . ')', 'IN'));
}
$publisherIsAdmin = $helper->isUserAdmin();
if (!$publisherIsAdmin) {
if (null === $criteria) {
$criteria = new \CriteriaCompo();
}
$criteriaDateSub = new \Criteria('datesub', time(), '<=');
$criteria->add($criteriaDateSub);
}
$itemsObj = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, 'itemid');
$scount = count($itemsObj);
if (0 == $scount) {
return false;
}
$k = 0;
$columns = [];
foreach ($itemsObj as $itemid => $itemObj) {
$item = [];
$item['itemurl'] = $itemObj->getItemUrl();
$item['title'] = $itemObj->getItemLink();
$item['alt'] = strip_tags($itemObj->getItemLink());
$mainImage = $itemObj->getMainImage();
// check to see if GD function exist
if (!function_exists('imagecreatetruecolor')) {
$item['item_image'] = $mainImage['image_path'];
} else {
$item['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path'] . '&w=' . $imgWidth; // No $imgHeight for autoheight option
}
$item['text'] = $itemObj->getBlockSummary($letters);
$item = $itemObj->getMainImage($item); //returns an array
$lsHeight = $imgPosition = $lsMargin = '';
if (0 != $options[12]) {
$lsHeight = 'height="' . $imgHeight . '" ';
} // set height = 0 in block option for auto height
if ('LEFT' === $options[15]) {
$imgPosition = 'float: left';
$lsMargin = '-right';
}
if ('CENTER' === $options[15]) {
$imgPosition = 'text-align:center';
$lsMargin = '';
}
if ('RIGHT' === $options[15]) {
$imgPosition = 'float: right';
$lsMargin = '-left';
}
//Image
if (1 == $options[10] && '' != $item['image_path']) {
$startdiv = '<div style="' . $imgPosition . '"><a href="' . $item['itemurl'] . '">';
$style = 'style="margin' . $lsMargin . ': 10px; padding: 2px; border: ' . $border . 'px solid #' . $bordercolor . '"';
$enddiv = 'width="' . $imgWidth . '" ' . $lsHeight . '></a></div>';
$image = $startdiv . '<img ' . $style . ' src="' . $item['item_image'] . '" alt="' . $item['image_name'] . '" ' . $enddiv;
$item['image'] = $image;
}
if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isAdmin(-1)) {
$item['admin'] = "<a href='" . PUBLISHER_URL . '/submit.php?itemid=' . $itemObj->itemid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/edit.gif'" . " title='" . _CO_PUBLISHER_EDIT . "' alt='" . _CO_PUBLISHER_EDIT . "'></a> ";
$item['admin'] .= "<a href='" . PUBLISHER_URL . '/admin/item.php?op=del&itemid=' . $itemObj->itemid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/delete.png'" . " title='" . _CO_PUBLISHER_DELETE . "' alt='" . _CO_PUBLISHER_DELETE . "'></a>";
} else {
$item['admin'] = '';
}
$block['topiclink'] = '';
/*
if ($options[16] == 1) {
$block['topiclink'] = '| <a href="'.XOOPS_URL.'/modules/news/topics_directory.php">'._AM_NEWS_TOPICS_DIRECTORY.'</a> ';
}
*/
$block['archivelink'] = '';
if (1 == $options[17]) {
$block['archivelink'] = '| <a href="' . PUBLISHER_URL . '/archive.php">' . _MB_PUBLISHER_ARCHIVE . '</a> ';
}
//TODO: Should we not show link to Anonymous?
$block['submitlink'] = '';
if (1 == $options[18] && $GLOBALS['xoopsUser']) {
$block['submitlink'] = '| <a href="' . PUBLISHER_URL . '/submit.php">' . _MB_PUBLISHER_SUBMITNEWS . '</a> ';
}
$item['poster'] = '';
if (1 == $options[19]) {
$item['poster'] = _MB_PUBLISHER_POSTER . ' ' . $itemObj->posterName();
}
$item['posttime'] = '';
if (1 == $options[20]) {
$item['posttime'] = _ON . ' ' . $itemObj->getDatesub();
}
$item['topic_title'] = '';
if (1 == $options[21]) {
$item['topic_title'] = $itemObj->getCategoryLink() . _MB_PUBLISHER_SP;
}
$item['read'] = '';
if (1 == $options[22]) {
$item['read'] = ' (' . $itemObj->counter() . ' ' . _READS . ')';
}
$item['more'] = '';
if ('' != $itemObj->body() || $itemObj->comments() > 0) {
$item['more'] = '<a class="publisher_spotlight_readmore" href="' . $itemObj->getItemUrl() . '">' . _MB_PUBLISHER_READMORE . '</a>';
}
$comments = $itemObj->comments();
if (1 == $options[23]) {
if ($comments > 0) {
//shows 1 comment instead of 1 comm. if comments ==1
//langugage file modified accordingly
if (1 == $comments) {
$item['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' ';
} else {
$item['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' ';
}
} else {
$item['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' ';
}
}
$item['print'] = '';
if (1 == $options[24]) {
$item['print'] = '<a href="' . Publisher\Seo::generateUrl('print', $itemObj->itemid(), $itemObj->short_url()) . '" rel="nofollow"><img src="' . PUBLISHER_URL . '/assets/images/links/print.gif" title="' . _CO_PUBLISHER_PRINT . '" alt="' . _CO_PUBLISHER_PRINT . '"></a> ';
}
$item['pdf'] = '';
if ($helper->getConfig('display_pdf')) {
if (1 == $options[25]) {
$item['pdf'] = "<a href='" . PUBLISHER_URL . '/makepdf.php?itemid=' . $itemObj->itemid() . "' rel='nofollow'><img src='" . PUBLISHER_URL . "/assets/images/links/pdf.gif' title='" . _CO_PUBLISHER_PDF . "' alt='" . _CO_PUBLISHER_PDF . "'></a> ";
}
}
$item['email'] = '';
if (1 == $options[26] && xoops_isActiveModule('tellafriend')) {
$subject = sprintf(_CO_PUBLISHER_INTITEMFOUND, $GLOBALS['xoopsConfig']['sitename']);
$subject = $itemObj->convertForJapanese($subject);
$maillink = Publisher\Utility::tellAFriend($subject);
$item['email'] = '<a href="' . $maillink . '"><img src="' . PUBLISHER_URL . '/assets/images/links/friend.gif" title="' . _CO_PUBLISHER_MAIL . '" alt="' . _CO_PUBLISHER_MAIL . '"></a> ';
}
$block['morelink'] = '';
if (1 == $options[27]) {
$block['morelink'] = '<a href="' . PUBLISHER_URL . '/index.php">' . _MB_PUBLISHER_MORE_ITEMS . '</a> ';
}
$block['latestnews_scroll'] = false;
if (1 == $options[5]) {
$block['latestnews_scroll'] = true;
}
$block['scrollheight'] = $options[6];
$block['scrollspeed'] = $options[7];
$block['scrolldir'] = $options[8];
$block['template'] = $options[28];
$block['imgwidth'] = $options[11];
$block['imgheight'] = $options[12];
$block['letters'] = $letters;
$columns[$k][] = $item;
++$k;
if ($k == $columnCount) {
$k = 0;
}
}
unset($item);
$block['columns'] = $columns;
return $block;
}
/**
* @param $options
*
* @return string
*/
function publisher_latest_news_edit($options)
{
$tabletag1 = '<tr><td style="padding:3px;" width="37%">';
$tabletag2 = '</td><td style="padding:3px;">';
$tabletag3 = '<tr><td style="padding-top:20px;border-bottom:1px solid #000;" colspan="2">';
$tabletag4 = '</td></tr>';
$form = "<table border='0' cellpadding='0' cellspacing='0'>";
$form .= $tabletag3 . _MB_PUBLISHER_GENERALCONFIG . $tabletag4; // General Options
$form .= $tabletag1 . _MB_PUBLISHER_FIRST . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[0] . "' size='4'> " . _MB_PUBLISHER_ITEMS . '</td></tr>';
$form .= $tabletag1 . _MB_PUBLISHER_DISP . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[1] . "' size='4'> " . _MB_PUBLISHER_ITEMS . '</td></tr>';
$form .= $tabletag1 . _MB_PUBLISHER_COLUMNS . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[2] . "' size='4'> " . _MB_PUBLISHER_COLUMN . '</td></tr>';
$form .= $tabletag1 . _MB_PUBLISHER_TEXTLENGTH . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[3] . "' size='4'> " . _MB_PUBLISHER_LETTER . '</td></tr>';
$form .= $tabletag1 . _MB_PUBLISHER_SELECTEDSTORIES . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[4] . "' size='16'></td></tr>";
$form .= $tabletag1 . _MB_PUBLISHER_SCROLL . $tabletag2;
$form .= publisher_mk_chkbox($options, 5);
$form .= $tabletag1 . _MB_PUBLISHER_SCROLLHEIGHT . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[6] . "' size='4'></td></tr>";
$form .= $tabletag1 . _MB_PUBLISHER_SCROLLSPEED . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[7] . "' size='4'></td></tr>";
$form .= $tabletag1 . _MB_PUBLISHER_SCROLLDIR . $tabletag2;
$form .= "<select size='1' name='options[8]'>";
$directions = ['right' => _MB_PUBLISHER_SCROLL_RIGHT, 'left' => _MB_PUBLISHER_SCROLL_LEFT, 'up' => _MB_PUBLISHER_SCROLL_UP, 'down' => _MB_PUBLISHER_SCROLL_DOWN];
foreach ($directions as $key => $value) {
$form .= "<option value='{$key}'";
if ($options[8] == $key) {
$form .= ' selected';
}
$form .= ">{$value}</option>";
}
$form .= '</select></td></tr>';
$form .= $tabletag1 . _MB_PUBLISHER_ORDER . $tabletag2;
$form .= "<select name='options[9]'>";
$form .= "<option value='datesub'";
if ('datesub' === $options[9]) {
$form .= ' selected';
}
$form .= '>' . _MB_PUBLISHER_DATE . '</option>';
$form .= "<option value='counter'";
if ('counter' === $options[9]) {
$form .= ' selected';
}
$form .= '>' . _MB_PUBLISHER_HITS . '</option>';
$form .= "<option value='weight'";
if ('weight' === $options[9]) {
$form .= ' selected';
}
$form .= '>' . _MB_PUBLISHER_WEIGHT . '</option>';
$form .= '</select></td></tr>';
$form .= $tabletag3 . _MB_PUBLISHER_PHOTOSCONFIG . $tabletag4; // Photos Options
$form .= $tabletag1 . _MB_PUBLISHER_IMGDISPLAY . $tabletag2;
$form .= publisher_mk_chkbox($options, 10);
$form .= $tabletag1 . _MB_PUBLISHER_IMGWIDTH . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[11] . "' size='4'> " . _MB_PUBLISHER_PIXEL . '</td></tr>';
$form .= $tabletag1 . _MB_PUBLISHER_IMGHEIGHT . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[12] . "' size='4'> " . _MB_PUBLISHER_PIXEL . '</td></tr>';
$form .= $tabletag1 . _MB_PUBLISHER_BORDER . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[13] . "' size='4'> " . _MB_PUBLISHER_PIXEL . '</td></tr>';
$form .= $tabletag1 . _MB_PUBLISHER_BORDERCOLOR . $tabletag2;
$form .= "<input type='text' name='options[]' value='" . $options[14] . "' size='8'></td></tr>";
$form .= $tabletag1 . _MB_PUBLISHER_IMGPOSITION . $tabletag2;
$form .= "<select name='options[]'>";
$form .= "<option value='LEFT'";
if ('LEFT' === $options[15]) {
$form .= ' selected';
}
$form .= '>' . _LEFT . "</option>\n";
$form .= "<option value='CENTER'";
if ('CENTER' === $options[15]) {
$form .= ' selected';
}
$form .= '>' . _CENTER . "</option>\n";
$form .= "<option value='RIGHT'";
if ('RIGHT' === $options[15]) {
$form .= ' selected';
}
$form .= '>' . _RIGHT . '</option>';
$form .= '</select></td></tr>';
$form .= $tabletag3 . _MB_PUBLISHER_LINKSCONFIG . $tabletag4; // Links Options
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_TOPICLINK . $tabletag2;
$form .= publisher_mk_chkbox($options, 16);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_ARCHIVELINK . $tabletag2;
$form .= publisher_mk_chkbox($options, 17);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_SUBMITLINK . $tabletag2;
$form .= publisher_mk_chkbox($options, 18);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_POSTEDBY . $tabletag2;
$form .= publisher_mk_chkbox($options, 19);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_POSTTIME . $tabletag2;
$form .= publisher_mk_chkbox($options, 20);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_TOPICTITLE . $tabletag2;
$form .= publisher_mk_chkbox($options, 21);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_READ . $tabletag2;
$form .= publisher_mk_chkbox($options, 22);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_COMMENT . $tabletag2;
$form .= publisher_mk_chkbox($options, 23);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_PRINT . $tabletag2;
$form .= publisher_mk_chkbox($options, 24);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_PDF . $tabletag2;
$form .= publisher_mk_chkbox($options, 25);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_EMAIL . $tabletag2;
$form .= publisher_mk_chkbox($options, 26);
$form .= $tabletag1 . _MB_PUBLISHER_DISPLAY_MORELINK . $tabletag2;
$form .= publisher_mk_chkbox($options, 27);
$form .= $tabletag3 . _MB_PUBLISHER_TEMPLATESCONFIG . $tabletag4; // Templates Options
$form .= $tabletag1 . _MB_PUBLISHER_TEMPLATE . $tabletag2;
$form .= "<select size='1' name='options[28]'>";
$templates = [
'normal' => _MB_PUBLISHER_TEMPLATE_NORMAL,
'extended' => _MB_PUBLISHER_TEMPLATE_EXTENDED,
'ticker' => _MB_PUBLISHER_TEMPLATE_TICKER,
'slider1' => _MB_PUBLISHER_TEMPLATE_SLIDER1,
'slider2' => _MB_PUBLISHER_TEMPLATE_SLIDER2,
];
foreach ($templates as $key => $value) {
$form .= "<option value='{$key}'";
if ($options[28] == $key) {
$form .= ' selected';
}
$form .= ">{$value}</option>";
}
$form .= '</select></td></tr>';
//Select Which Categories To Show
$form .= $tabletag3 . _MB_PUBLISHER_TOPICSCONFIG . $tabletag4; // Topics Options
$form .= $tabletag1 . _MB_PUBLISHER_TOPICSDISPLAY . $tabletag2;
$form .= Publisher\Utility::createCategorySelect($options[29], 0, true, 'options[29]');
$form .= '</td></tr>';
$form .= '</table>';
return $form;
}
/**
* @param $options
* @param $number
*
* @return string
*/
function publisher_mk_chkbox($options, $number)
{
$chk = '';
if (1 == $options[$number]) {
$chk = ' checked';
}
$chkbox = "<input type='radio' name='options[{$number}]' value='1'" . $chk . '> ' . _YES . ' ';
$chk = '';
if (0 == $options[$number]) {
$chk = ' checked';
}
$chkbox .= "<input type='radio' name='options[{$number}]' value='0'" . $chk . '> ' . _NO . '</td></tr>';
return $chkbox;
}
/**
* @param $options
* @param $number
*
* @return string
*/
function publisher_mk_select($options, $number)
{
$slc = '';
if (2 == $options[$number]) {
$slc = ' checked';
}
$select = "<input type='radio' name='options[{$number}]' value='2'" . $slc . '> ' . _LEFT . ' ';
$slc = '';
if (1 == $options[$number]) {
$slc = ' checked';
}
$select = "<input type='radio' name='options[{$number}]' value='1'" . $slc . '> ' . _CENTER . ' ';
$slc = '';
if (0 == $options[$number]) {
$slc = ' checked';
}
$select .= "<input type='radio' name='options[{$number}]' value='0'" . $slc . '> ' . _RIGHT . '</td></tr>';
return $select;
}
|