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