|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package SimplePortal |
|
5
|
|
|
* |
|
6
|
|
|
* @author SimplePortal Team |
|
7
|
|
|
* @copyright 2015-2021 SimplePortal Team |
|
8
|
|
|
* @license BSD 3-clause |
|
9
|
|
|
* @version 1.0.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Gallery Block, show a gallery box with gallery items |
|
15
|
|
|
* |
|
16
|
|
|
* @param mixed[] $parameters |
|
17
|
|
|
* 'limit' => number of gallery items to show |
|
18
|
|
|
* 'type' => 0 recent 1 random |
|
19
|
|
|
* 'direction' => 0 horizontal or 1 vertical display in the block |
|
20
|
|
|
* @param int $id - not used in this block |
|
21
|
|
|
* @param boolean $return_parameters if true returns the configuration options for the block |
|
22
|
|
|
*/ |
|
23
|
|
|
class Gallery_Block extends SP_Abstract_Block |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Constructor, used to define block parameters |
|
27
|
|
|
* |
|
28
|
|
|
* @param Database|null $db |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct($db = null) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->block_parameters = array( |
|
33
|
|
|
'limit' => 'int', |
|
34
|
|
|
'type' => 'select', |
|
35
|
|
|
'direction' => 'select', |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
parent::__construct($db); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Initializes a block for use. |
|
43
|
|
|
* |
|
44
|
|
|
* - Called from portal.subs as part of the sportal_load_blocks process |
|
45
|
|
|
* |
|
46
|
|
|
* @param mixed[] $parameters |
|
47
|
|
|
* @param int $id |
|
48
|
|
|
*/ |
|
49
|
|
|
public function setup($parameters, $id = 0) |
|
50
|
|
|
{ |
|
51
|
|
|
global $txt; |
|
52
|
|
|
|
|
53
|
|
|
$limit = empty($parameters['limit']) ? 1 : (int) $parameters['limit']; |
|
54
|
|
|
$type = empty($parameters['type']) ? 0 : 1; |
|
55
|
|
|
$this->data['direction'] = empty($parameters['direction']) ? 0 : 1; |
|
56
|
|
|
|
|
57
|
|
|
// Find what gallery is installed |
|
58
|
|
|
$this->data['mod'] = $this->_getGallery(); |
|
59
|
|
|
|
|
60
|
|
|
// No gallery, no images I'm afraid |
|
61
|
|
|
if (empty($this->data['mod'])) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->data['error_msg'] = $txt['error_sp_no_gallery_found']; |
|
64
|
|
|
$this->setTemplate('template_sp_gallery_error'); |
|
65
|
|
|
|
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// Set the appropriate template for the gallery in use |
|
70
|
|
|
$this->data['gallery_template'] = 'template_sp_gallery_' . $this->data['mod']; |
|
71
|
|
|
$this->data['items'] = $this->_getItems($limit, $type); |
|
72
|
|
|
$this->data['fancybox_enabled'] = !empty($this->_modSettings['fancybox_enabled']); |
|
73
|
|
|
|
|
74
|
|
|
// No items in the gallery? |
|
75
|
|
|
if (empty($this->data['items'])) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->data['error_msg'] = $txt['error_sp_no_pictures_found']; |
|
78
|
|
|
$this->setTemplate('template_sp_gallery_error'); |
|
79
|
|
|
} |
|
80
|
|
|
else |
|
81
|
|
|
{ |
|
82
|
|
|
$this->setTemplate('template_sp_gallery'); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Returns of list of gallery's that this block can work with |
|
88
|
|
|
* |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function _getGallery() |
|
92
|
|
|
{ |
|
93
|
|
|
$mod = ''; |
|
94
|
|
|
|
|
95
|
|
|
// This does exist for ElkArte, but can't be shared I'm afraid |
|
96
|
|
|
if (file_exists(SOURCEDIR . '/Aeva-Media.php')) |
|
97
|
|
|
$mod = 'aeva_media'; |
|
98
|
|
|
|
|
99
|
|
|
// This does exist and is available! |
|
100
|
|
|
if (file_exists(SOURCEDIR . '/levgal_src/LevGal-Bootstrap.php')) |
|
101
|
|
|
$mod = 'levgal'; |
|
102
|
|
|
|
|
103
|
|
|
return $mod; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Load a set of media items from the gallery |
|
108
|
|
|
* |
|
109
|
|
|
* @param int $limit |
|
110
|
|
|
* @param string $type |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function _getItems($limit, $type) |
|
113
|
|
|
{ |
|
114
|
|
|
$data = array(); |
|
115
|
|
|
|
|
116
|
|
|
if ($this->data['mod'] === 'aeva_media') |
|
117
|
|
|
{ |
|
118
|
|
|
require_once(SUBSDIR . '/Aeva-Subs.php'); |
|
119
|
|
|
require_once(SUBSDIR . '/Aeva-Subs-Vital.php'); |
|
120
|
|
|
|
|
121
|
|
|
aeva_loadSettings(); |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
// Just images |
|
124
|
|
|
return aeva_getMediaItems(0, $limit, $type ? 'RAND()' : 'm.id_media DESC', true, array(), 'm.type = \'image\''); |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
if ($this->data['mod'] === 'levgal') |
|
128
|
|
|
{ |
|
129
|
|
|
if (!allowedTo(array('lgal_view', 'lgal_manage'))) |
|
130
|
|
|
{ |
|
131
|
|
|
return array(); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
switch ($type) |
|
135
|
|
|
{ |
|
136
|
|
|
case 0: |
|
137
|
|
|
default: |
|
138
|
|
|
$itemList = LevGal_Bootstrap::getModel('LevGal_Model_ItemList'); |
|
|
|
|
|
|
139
|
|
|
$data = $itemList->getLatestItems($limit); |
|
140
|
|
|
break; |
|
141
|
|
|
case 1: |
|
142
|
|
|
$itemList = LevGal_Bootstrap::getModel('LevGal_Model_ItemList'); |
|
143
|
|
|
$data = $itemList->getRandomItems($limit); |
|
144
|
|
|
break; |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
return $data; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Error template for this block |
|
154
|
|
|
* |
|
155
|
|
|
* @param mixed[] $data |
|
156
|
|
|
*/ |
|
157
|
|
|
function template_sp_gallery_error($data) |
|
158
|
|
|
{ |
|
159
|
|
|
echo ' |
|
160
|
|
|
', $data['error_msg']; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Main template for Levertine Block |
|
165
|
|
|
* |
|
166
|
|
|
* @param mixed[] $data |
|
167
|
|
|
*/ |
|
168
|
|
|
function template_sp_gallery_levgal($item, $data) |
|
169
|
|
|
{ |
|
170
|
|
|
global $scripturl, $txt; |
|
171
|
|
|
|
|
172
|
|
|
echo ' |
|
173
|
|
|
<a class="sp_attach_title" href="', $item['item_url'], '">', $item['item_name'], '</a> |
|
174
|
|
|
<br />' . ($data['fancybox_enabled'] |
|
175
|
|
|
? '<a href="' . $item['item_url'] . '" rel="gallery" data-fancybox="1">' |
|
176
|
|
|
: '<a href="' . $item['item_url'] . '">') . ' |
|
177
|
|
|
<img src="', $item['thumbnail'], '" alt="', $item['item_name'], '" title="', $item['item_name'], '" /></a> |
|
178
|
|
|
</a> |
|
179
|
|
|
<br /> |
|
180
|
|
|
<div class="sp_image_topic"> |
|
181
|
|
|
', $txt['lgal_sort_by_views'], ': ', $item['num_views'], '<br /> |
|
182
|
|
|
', $txt['lgal_posted_by'], ' ', !empty($item['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $item['id_member'] . '">' . $item['poster_name'] . '</a>' : $item['poster_name'], '<br /> |
|
183
|
|
|
', $txt['lgal_posted_in'], ' <a href="', $item['album_url'], '">', $item['album_name'], '</a> |
|
184
|
|
|
</div>'; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Template for aeva block |
|
189
|
|
|
* |
|
190
|
|
|
* @param mixed[] $data |
|
191
|
|
|
*/ |
|
192
|
|
|
function template_sp_gallery_aeva_media($item, $data) |
|
193
|
|
|
{ |
|
194
|
|
|
global $scripturl, $txt; |
|
195
|
|
|
|
|
196
|
|
|
echo ' |
|
197
|
|
|
<a class="sp_attach_title" href="', $scripturl, '?action=media;sa=item;in=', $item['id'], '">', $item['title'], '</a> |
|
198
|
|
|
<br />' . ($data['fancybox_enabled'] |
|
199
|
|
|
? '<a href="' . $scripturl . '?action=media;sa=media;in=' . $item['id'] . '" rel="gallery" data-fancybox="1">' |
|
200
|
|
|
: '<a href="' . $scripturl . '?action=media;sa=item;in=' . $item['id'] . '">') . ' |
|
201
|
|
|
<img src="', $scripturl, '?action=media;sa=media;in=', $item['id'], ';thumb" alt="" /> |
|
202
|
|
|
</a> |
|
203
|
|
|
<br /> |
|
204
|
|
|
<div class="sp_image_topic"> |
|
205
|
|
|
', $txt['aeva_views'], ': ', $item['views'], '<br /> |
|
206
|
|
|
', $txt['aeva_posted_by'], ': <a href="', $scripturl, '?action=profile;u=', $item['poster_id'], '">', $item['poster_name'], '</a><br /> |
|
207
|
|
|
', $txt['aeva_in_album'], ': <a href="', $scripturl, '?action=media;sa=album;in=', $item['id_album'], '">', $item['album_name'], '</a> |
|
208
|
|
|
</div>'; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Main wrapper template for this block |
|
213
|
|
|
* |
|
214
|
|
|
* @param mixed[] $data |
|
215
|
|
|
*/ |
|
216
|
|
|
function template_sp_gallery($data) |
|
217
|
|
|
{ |
|
218
|
|
|
// We have gallery items to show! |
|
219
|
|
|
echo ' |
|
220
|
|
|
<table class="sp_auto_align">', $data['direction'] ? ' |
|
221
|
|
|
<tr>' : ''; |
|
222
|
|
|
|
|
223
|
|
|
$before = $data['direction'] ? '' : ' |
|
224
|
|
|
<tr>'; |
|
225
|
|
|
|
|
226
|
|
|
$after = $data['direction'] ? '' : ' |
|
227
|
|
|
</tr>'; |
|
228
|
|
|
|
|
229
|
|
|
foreach ($data['items'] as $item) |
|
230
|
|
|
{ |
|
231
|
|
|
echo $before, ' |
|
232
|
|
|
<td> |
|
233
|
|
|
<div class="sp_image smalltext">'; |
|
234
|
|
|
|
|
235
|
|
|
$data['gallery_template']($item, $data); |
|
236
|
|
|
|
|
237
|
|
|
echo ' |
|
238
|
|
|
</div> |
|
239
|
|
|
</td>', $after; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
echo $data['direction'] ? ' |
|
243
|
|
|
</tr>' : '', ' |
|
244
|
|
|
</table>'; |
|
245
|
|
|
} |
|
246
|
|
|
|