|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
14
|
|
|
* @license https://www.fsf.org/copyleft/gpl.html GNU public license |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
* @author trabis <[email protected]> |
|
17
|
|
|
* @author The SmartFactory <www.smartfactory.ca> |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
use XoopsModules\Publisher\BlockForm; |
|
21
|
|
|
use XoopsModules\Publisher\Constants; |
|
22
|
|
|
use XoopsModules\Publisher\Helper; |
|
23
|
|
|
use XoopsModules\Publisher\ItemHandler; |
|
24
|
|
|
|
|
25
|
|
|
require_once \dirname(__DIR__) . '/include/common.php'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param $options |
|
29
|
|
|
* |
|
30
|
|
|
* @return array |
|
31
|
|
|
* @throws \Exception |
|
32
|
|
|
*/ |
|
33
|
|
|
function publisher_items_random_item_show($options) |
|
34
|
|
|
{ |
|
35
|
|
|
$block = []; |
|
36
|
|
|
|
|
37
|
|
|
$helper = Helper::getInstance(); |
|
38
|
|
|
/** @var ItemHandler $itemHandler */ |
|
39
|
|
|
$itemHandler = $helper->getHandler('Item'); |
|
40
|
|
|
|
|
41
|
|
|
$optItemsCount = (int)$options[8]; |
|
42
|
|
|
|
|
43
|
|
|
for ($k = 0; $k < $optItemsCount; $k++) { |
|
44
|
|
|
$item = []; |
|
45
|
|
|
|
|
46
|
|
|
// creating the ITEM object |
|
47
|
|
|
$itemsObj = $itemHandler->getRandomItem('', [Constants::PUBLISHER_STATUS_PUBLISHED]); |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
if (!is_object($itemsObj)) { |
|
50
|
|
|
return $item; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$item['content'] = $itemsObj->getBlockSummary(300, true); //show complete summary but truncate to 300 if only body available |
|
54
|
|
|
$item['id'] = $itemsObj->itemid(); |
|
55
|
|
|
$item['url'] = $itemsObj->getItemUrl(); |
|
56
|
|
|
$item['lang_fullitem'] = _MB_PUBLISHER_FULLITEM; |
|
57
|
|
|
$item['lang_poster'] = _MB_PUBLISHER_POSTEDBY; |
|
58
|
|
|
$item['lang_date'] = _MB_PUBLISHER_ON; |
|
59
|
|
|
$item['lang_category'] = _MB_PUBLISHER_CATEGORY; |
|
60
|
|
|
$item['lang_reads'] = _MB_PUBLISHER_HITS; |
|
61
|
|
|
$item['titlelink'] = $itemsObj->getItemLink('titlelink'); |
|
62
|
|
|
$item['alt'] = strip_tags($itemsObj->getItemLink()); |
|
63
|
|
|
$item['date'] = $itemsObj->getDatesub(); |
|
64
|
|
|
$item['poster'] = $itemsObj->getLinkedPosterName(); |
|
65
|
|
|
$item['categorylink'] = $itemsObj->getCategoryLink(); |
|
66
|
|
|
$item['hits'] = ' ' . $itemsObj->counter() . ' ' . _READS; |
|
67
|
|
|
|
|
68
|
|
|
$mainImage = $itemsObj->getMainImage(); // check to see if GD function exist |
|
69
|
|
|
if (empty($mainImage['image_path'])) { |
|
70
|
|
|
$mainImage['image_path'] = PUBLISHER_URL . '/assets/images/default_image.jpg'; |
|
71
|
|
|
} |
|
72
|
|
|
if (function_exists('imagecreatetruecolor')) { |
|
73
|
|
|
$item['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path']; |
|
74
|
|
|
$item['image_path'] = $mainImage['image_path']; |
|
75
|
|
|
} else { |
|
76
|
|
|
$item['item_image'] = $mainImage['image_path']; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$item['cancomment'] = $itemsObj->cancomment(); |
|
80
|
|
|
$comments = $itemsObj->comments(); |
|
81
|
|
|
if ($comments > 0) { |
|
82
|
|
|
//shows 1 comment instead of 1 comm. if comments ==1 |
|
83
|
|
|
//langugage file modified accordingly |
|
84
|
|
|
if (1 == $comments) { |
|
85
|
|
|
$item['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' '; |
|
86
|
|
|
} else { |
|
87
|
|
|
$item['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' '; |
|
88
|
|
|
} |
|
89
|
|
|
} else { |
|
90
|
|
|
$item['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' '; |
|
91
|
|
|
} |
|
92
|
|
|
$item['display_summary'] = $options[0]; |
|
93
|
|
|
$item['display_item_image'] = $options[1]; |
|
94
|
|
|
$item['display_poster'] = $options[2]; |
|
95
|
|
|
$item['display_date'] = $options[3]; |
|
96
|
|
|
$item['display_categorylink'] = $options[4]; |
|
97
|
|
|
$item['display_hits'] = $options[5]; |
|
98
|
|
|
$item['display_comment'] = $options[6]; |
|
99
|
|
|
$item['display_lang_fullitem'] = $options[7]; |
|
100
|
|
|
|
|
101
|
|
|
// $block['items'][] = $block; |
|
102
|
|
|
|
|
103
|
|
|
$block['items'][] = $item; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $block; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param $options |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
function publisher_items_random_item_edit($options) |
|
114
|
|
|
{ |
|
115
|
|
|
// require_once PUBLISHER_ROOT_PATH . '/class/blockform.php'; |
|
116
|
|
|
xoops_load('XoopsFormLoader'); |
|
117
|
|
|
|
|
118
|
|
|
$form = new BlockForm(); |
|
119
|
|
|
$showSummary = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_SUMMARY, 'options[0]', $options[0]); |
|
120
|
|
|
$showImage = new \XoopsFormRadioYN(_MB_PUBLISHER_IMGDISPLAY, 'options[1]', $options[1]); |
|
121
|
|
|
$showPoster = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_POSTEDBY, 'options[2]', $options[2]); |
|
122
|
|
|
$showDate = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_POSTTIME, 'options[3]', $options[3]); |
|
123
|
|
|
$showCategory = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_TOPICLINK, 'options[4]', $options[4]); |
|
124
|
|
|
$showHits = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_READ, 'options[5]', $options[5]); |
|
125
|
|
|
$showComment = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_COMMENT, 'options[6]', $options[6]); |
|
126
|
|
|
$dispMoreEle = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_READ_FULLITEM, 'options[7]', $options[7]); |
|
127
|
|
|
$countItems = new \XoopsFormText(_MB_PUBLISHER_RANDOM_ITEMS, 'options[8]', 10, 255, $options[8]); |
|
128
|
|
|
|
|
129
|
|
|
$form->addElement($showSummary); |
|
130
|
|
|
$form->addElement($showImage); |
|
131
|
|
|
$form->addElement($showPoster); |
|
132
|
|
|
$form->addElement($showDate); |
|
133
|
|
|
$form->addElement($showCategory); |
|
134
|
|
|
$form->addElement($showHits); |
|
135
|
|
|
$form->addElement($showComment); |
|
136
|
|
|
$form->addElement($dispMoreEle); |
|
137
|
|
|
$form->addElement($countItems); |
|
138
|
|
|
|
|
139
|
|
|
return $form->render(); |
|
140
|
|
|
} |
|
141
|
|
|
|