|
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
|
|
|
use XoopsModules\Publisher\Utility; |
|
25
|
|
|
|
|
26
|
|
|
require_once \dirname(__DIR__) . '/include/common.php'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param $options |
|
30
|
|
|
* |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
function publisher_items_recent_show($options) |
|
34
|
|
|
{ |
|
35
|
|
|
$helper = Helper::getInstance(); |
|
36
|
|
|
/** @var ItemHandler $itemHandler */ |
|
37
|
|
|
$itemHandler = $helper->getHandler('Item'); |
|
38
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
39
|
|
|
|
|
40
|
|
|
$block = $newItems = []; |
|
41
|
|
|
|
|
42
|
|
|
$selectedcatids = explode(',', $options[0]); |
|
43
|
|
|
|
|
44
|
|
|
$allcats = false; |
|
45
|
|
|
if (in_array(0, $selectedcatids, false)) { |
|
46
|
|
|
$allcats = true; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$sort = $options[1]; |
|
50
|
|
|
$order = Utility::getOrderBy($sort); |
|
51
|
|
|
$limit = $options[2]; |
|
52
|
|
|
$start = 0; |
|
53
|
|
|
|
|
54
|
|
|
// creating the ITEM objects that belong to the selected category |
|
55
|
|
|
if ($allcats) { |
|
56
|
|
|
$criteria = null; |
|
57
|
|
|
} else { |
|
58
|
|
|
$criteria = new \CriteriaCompo(); |
|
59
|
|
|
$criteria->add(new \Criteria('categoryid', '(' . $options[0] . ')', 'IN')); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$publisherIsAdmin = $helper->isUserAdmin(); |
|
63
|
|
|
if (!$publisherIsAdmin) { |
|
64
|
|
|
if (null === $criteria) { |
|
65
|
|
|
$criteria = new \CriteriaCompo(); |
|
66
|
|
|
} |
|
67
|
|
|
$criteriaDateSub = new \Criteria('datesub', time(), '<='); |
|
68
|
|
|
$criteria->add($criteriaDateSub); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$itemsObj = $itemHandler->getItems($limit, $start, [Constants::PUBLISHER_STATUS_PUBLISHED], -1, $sort, $order, '', true, $criteria, 'none'); |
|
72
|
|
|
|
|
73
|
|
|
$totalItems = count($itemsObj); |
|
74
|
|
|
|
|
75
|
|
|
if ($itemsObj && $totalItems > 0) { |
|
76
|
|
|
foreach ($itemsObj as $iValue) { |
|
77
|
|
|
$newItems['itemid'] = $iValue->itemid(); |
|
78
|
|
|
$newItems['itemurl'] = $iValue->getItemUrl(); |
|
79
|
|
|
$newItems['title'] = $iValue->getTitle(); |
|
80
|
|
|
$newItems['alt'] = strip_tags($iValue->getItemLink()); |
|
81
|
|
|
$newItems['categoryname'] = $iValue->getCategoryName(); |
|
82
|
|
|
$newItems['categoryid'] = $iValue->categoryid(); |
|
83
|
|
|
$newItems['date'] = $iValue->getDatesub(); |
|
84
|
|
|
$newItems['poster'] = $iValue->getLinkedPosterName(); |
|
85
|
|
|
$newItems['itemlink'] = $iValue->getItemLink(false, $options[3] ?? 65); |
|
86
|
|
|
$newItems['categorylink'] = $iValue->getCategoryLink(); |
|
87
|
|
|
$newItems['hits'] = ' ' . $iValue->counter() . ' ' . _READS; |
|
88
|
|
|
$newItems['summary'] = $iValue->getBlockSummary(300, true); //show complete summary but truncate to 300 if only body available |
|
89
|
|
|
|
|
90
|
|
|
$mainImage = $iValue->getMainImage(); // check to see if GD function exist |
|
91
|
|
|
if (empty($mainImage['image_path'])) { |
|
92
|
|
|
$mainImage['image_path'] = PUBLISHER_URL . '/assets/images/default_image.jpg'; |
|
93
|
|
|
} |
|
94
|
|
|
if (function_exists('imagecreatetruecolor')) { |
|
95
|
|
|
$newItems['item_image'] = PUBLISHER_URL . '/thumb.php?src=' . $mainImage['image_path']; |
|
96
|
|
|
$newItems['image_path'] = $mainImage['image_path']; |
|
97
|
|
|
} else { |
|
98
|
|
|
$newItems['item_image'] = $mainImage['image_path']; |
|
99
|
|
|
} |
|
100
|
|
|
$newItems['cancomment'] = $iValue->cancomment(); |
|
101
|
|
|
$comments = $iValue->comments(); |
|
102
|
|
|
if ($comments > 0) { |
|
103
|
|
|
//shows 1 comment instead of 1 comm. if comments ==1 |
|
104
|
|
|
//langugage file modified accordingly |
|
105
|
|
|
if (1 == $comments) { |
|
106
|
|
|
$newItems['comment'] = ' ' . _MB_PUBLISHER_ONECOMMENT . ' '; |
|
107
|
|
|
} else { |
|
108
|
|
|
$newItems['comment'] = ' ' . $comments . ' ' . _MB_PUBLISHER_COMMENTS . ' '; |
|
109
|
|
|
} |
|
110
|
|
|
} else { |
|
111
|
|
|
$newItems['comment'] = ' ' . _MB_PUBLISHER_NO_COMMENTS . ' '; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
$block['items'][] = $newItems; |
|
115
|
|
|
} |
|
116
|
|
|
$block['publisher_url'] = PUBLISHER_URL; |
|
117
|
|
|
$block['lang_title'] = _MB_PUBLISHER_ITEMS; |
|
118
|
|
|
$block['lang_category'] = _MB_PUBLISHER_CATEGORY; |
|
119
|
|
|
$block['lang_poster'] = _MB_PUBLISHER_POSTEDBY; |
|
120
|
|
|
$block['lang_date'] = _MB_PUBLISHER_DATE; |
|
121
|
|
|
$moduleName = $myts->displayTarea( |
|
122
|
|
|
$helper->getModule() |
|
|
|
|
|
|
123
|
|
|
->getVar('name') |
|
124
|
|
|
); |
|
125
|
|
|
$block['lang_visitItem'] = _MB_PUBLISHER_VISITITEM . ' ' . $moduleName; |
|
126
|
|
|
|
|
127
|
|
|
$block['show_image'] = $options[4] ?? 0; |
|
128
|
|
|
$block['show_summary'] = $options[5] ?? 0; |
|
129
|
|
|
$block['show_category'] = $options[6] ?? 0; |
|
130
|
|
|
$block['show_poster'] = $options[7] ?? 0; |
|
131
|
|
|
$block['show_date'] = $options[8] ?? 0; |
|
132
|
|
|
$block['show_hits'] = $options[9] ?? 0; |
|
133
|
|
|
$block['show_comment'] = $options[10] ?? 0; |
|
134
|
|
|
$block['show_morelink'] = $options[11] ?? 0; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
return $block; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param $options |
|
142
|
|
|
* |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
|
|
function publisher_items_recent_edit($options) |
|
146
|
|
|
{ |
|
147
|
|
|
// require_once PUBLISHER_ROOT_PATH . '/class/blockform.php'; |
|
148
|
|
|
xoops_load('XoopsFormLoader'); |
|
149
|
|
|
|
|
150
|
|
|
$form = new BlockForm(); |
|
151
|
|
|
|
|
152
|
|
|
$catEle = new \XoopsFormLabel(_MB_PUBLISHER_SELECTCAT, Utility::createCategorySelect($options[0], 0, true, 'options[0]')); |
|
153
|
|
|
$orderEle = new \XoopsFormSelect(_MB_PUBLISHER_ORDER, 'options[1]', $options[1]); |
|
154
|
|
|
$orderEle->addOptionArray( |
|
155
|
|
|
[ |
|
156
|
|
|
'datesub' => _MB_PUBLISHER_DATE, |
|
157
|
|
|
'counter' => _MB_PUBLISHER_HITS, |
|
158
|
|
|
'weight' => _MB_PUBLISHER_WEIGHT, |
|
159
|
|
|
] |
|
160
|
|
|
); |
|
161
|
|
|
$dispEle = new \XoopsFormText(_MB_PUBLISHER_DISP, 'options[2]', 10, 255, $options[2]); |
|
162
|
|
|
$charsEle = new \XoopsFormText(_MB_PUBLISHER_CHARS, 'options[3]', 10, 255, $options[3]); |
|
163
|
|
|
$showImage = new \XoopsFormRadioYN(_MB_PUBLISHER_IMGDISPLAY, 'options[4]', $options[4] ?? 0); |
|
164
|
|
|
$showSummary = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_SUMMARY, 'options[5]', $options[5] ?? 0); |
|
165
|
|
|
$showCategory = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_TOPICLINK, 'options[6]', $options[6] ?? 0); |
|
166
|
|
|
$showPoster = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_POSTEDBY, 'options[7]', $options[7] ?? 0); |
|
167
|
|
|
$showDate = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_POSTTIME, 'options[8]', $options[8] ?? 0); |
|
168
|
|
|
$showHits = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_READ, 'options[9]', $options[9] ?? 0); |
|
169
|
|
|
$showComment = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_COMMENT, 'options[10]', $options[10] ?? 0); |
|
170
|
|
|
$dispMoreEle = new \XoopsFormRadioYN(_MB_PUBLISHER_DISPLAY_MORELINK, 'options[11]', $options[11] ?? 0); |
|
171
|
|
|
|
|
172
|
|
|
$form->addElement($catEle); |
|
173
|
|
|
$form->addElement($orderEle); |
|
174
|
|
|
$form->addElement($dispEle); |
|
175
|
|
|
$form->addElement($charsEle); |
|
176
|
|
|
$form->addElement($showImage); |
|
177
|
|
|
$form->addElement($showSummary); |
|
178
|
|
|
$form->addElement($showCategory); |
|
179
|
|
|
$form->addElement($showPoster); |
|
180
|
|
|
$form->addElement($showDate); |
|
181
|
|
|
$form->addElement($showHits); |
|
182
|
|
|
$form->addElement($showComment); |
|
183
|
|
|
$form->addElement($dispMoreEle); |
|
184
|
|
|
|
|
185
|
|
|
return $form->render(); |
|
186
|
|
|
} |
|
187
|
|
|
|