This repository was archived by the owner on Dec 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe_shortcode.php
More file actions
392 lines (303 loc) · 11.2 KB
/
e_shortcode.php
File metadata and controls
392 lines (303 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php
/*
* Copyright (c) e107 Inc e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id: e_shortcode.php 12438 2011-12-05 15:12:56Z secretr $
*
* Featurebox shortcode batch class - shortcodes available site-wide. ie. equivalent to multiple .sc files.
*/
if(!defined('e107_INIT'))
{
exit;
}
// [PLUGINS]/gallery/languages/[LANGUAGE]/[LANGUAGE]_front.php
e107::lan('gallery', false, true);
class gallery_shortcodes extends e_shortcode
{
public $total = 0;
public $amount = 3;
public $from = 0;
public $page = 1;
public $curCat = null;
public $sliderCat = 1;
public $slideMode = false;
public $slideCount = 1;
private $attFull = null;
function init()
{
$prefW = e107::getPlugPref('gallery', 'pop_w');
$prefH = e107::getPlugPref('gallery', 'pop_h');
$pop_w = vartrue($prefW, 1024);
$pop_h = vartrue($prefH, 768);
$this->attFull = array('w' => $pop_w, 'h' => $pop_h, 'x' => 1, 'crop' => 0); // 'w='.$pop_w.'&h='.$pop_h.'&x=1';
}
function breadcrumb()
{
$breadcrumb = array();
$template = e107::getTemplate('gallery', 'gallery', 'cat');
$caption = isset($template['caption']) ? e107::getParser()->toText($template['caption']) : LAN_PLUGIN_GALLERY_TITLE;
if(!empty($this->var))
{
$breadcrumb[] = array('text' => $caption, 'url' => e107::url('gallery', 'gallery', $this->var));
}
if(vartrue($this->curCat))
{
$breadcrumb[] = array('text' => $this->sc_gallery_cat_title('title'), 'url' => e107::url('gallery', 'index', $this->var));
}
//var_dump($breadcrumb);
e107::breadcrumb($breadcrumb);
}
function sc_gallery_caption($parm = '')
{
$tp = e107::getParser();
if($parm === 'text')
{
return $tp->toAttribute($this->var['media_caption']);
}
e107_require_once(e_PLUGIN . 'gallery/includes/gallery_load.php');
// Load prettyPhoto settings and files.
gallery_load_prettyphoto();
$plugPrefs = e107::getPlugConfig('gallery')->getPref();
$hook = varset($plugPrefs['pp_hook'], 'data-gal');
$text = "<a class='gallery-caption' title='" . $tp->toAttribute($this->var['media_caption']) . "' href='" . $tp->thumbUrl($this->var['media_url'], $this->attFull) . "' " . $hook . "='prettyPhoto[slide]' >"; // Erase rel"lightbox.Gallery2" - Write "prettyPhoto[slide]"
$text .= $this->var['media_caption'];
$text .= "</a>";
return $text;
}
function sc_gallery_description($parm = '')
{
$tp = e107::getParser();
return $tp->toHTML($this->var['media_description'], true, 'BODY');
}
function sc_gallery_breadcrumb($parm = '')
{
// $this->breadcrumb();
$breadcrumb = e107::breadcrumb();
return e107::getForm()->breadcrumb($breadcrumb);
}
/**
* All possible parameters
* {GALLERY_THUMB=w=200&h=200&thumburl&thumbsrc&imageurl&orig}
* w and h - optional width and height of the thumbnail
* thumburl - return only the URL of the destination image (large one)
* thumbsrc - url to the thumb, as it's written in the src attribute of the image
* imageurl - full path to the destination image (no proxy)
* actualPreview - large preview will use the original path to the image (no proxy)
*/
function sc_gallery_thumb($parm = '')
{
e107_require_once(e_PLUGIN . 'gallery/includes/gallery_load.php');
// Load prettyPhoto settings and files.
gallery_load_prettyphoto();
$plugPrefs = e107::getPlugConfig('gallery')->getPref();
$hook = varset($plugPrefs['pp_hook'], 'data-gal');
$tp = e107::getParser();
$parms = eHelper::scParams($parm);
$w = vartrue($parms['w']) ? $parms['w'] : $tp->thumbWidth(); // 190; // 160;
$h = vartrue($parms['h']) ? $parms['h'] : $tp->thumbHeight(); // 130;
$class = ($this->slideMode == true) ? 'gallery-slideshow-thumb img-responsive img-fluid img-rounded rounded' : varset($parms['class'], 'gallery-thumb img-responsive img-fluid');
$rel = ($this->slideMode == true) ? 'prettyPhoto[pp_gal]' : 'prettyPhoto[pp_gal]';
//$att = array('aw'=>$w, 'ah'=>$h, 'x'=>1, 'crop'=>1);
$caption = $tp->toAttribute($this->var['media_caption']);
$att = array('w' => $w, 'h' => $h, 'class' => $class, 'alt' => $caption, 'x' => 1, 'crop' => 1);
$srcFull = $tp->thumbUrl($this->var['media_url'], $this->attFull);
if(vartrue($parms['actualPreview']))
{
$srcFull = $tp->replaceConstants($this->var['media_url'], 'full');
}
if(isset($parms['thumburl']))
{
return $srcFull;
}
elseif(isset($parms['thumbsrc']))
{
return $tp->thumbUrl($this->var['media_url'], $att);
}
elseif(isset($parms['imageurl']))
{
return $tp->replaceConstants($this->var['media_url'], 'full');
}
$description = $tp->toAttribute($this->var['media_description']);
$text = "<a class='" . $class . "' title='" . $description . "' href='" . $srcFull . "' " . $hook . "='" . $rel . "'>";
$text .= $tp->toImage($this->var['media_url'], $att);
$text .= "</a>";
return $text;
}
function sc_gallery_cat_title($parm = '')
{
$tp = e107::getParser();
$url = e107::url('gallery', 'gallery', $this->var);
if($parm == 'title')
{
return $tp->toHTML($this->var['media_cat_title'], false, 'TITLE');
}
$text = "<a href='" . $url . "'>";
$text .= $tp->toHTML($this->var['media_cat_title'], false, 'TITLE');
$text .= "</a>";
return $text;
}
function sc_gallery_cat_url($parm = '')
{
return e107::url('gallery', 'gallery', $this->var);
}
function sc_gallery_cat_description($parm = '')
{
$tp = e107::getParser();
return $tp->toHTML($this->var['media_cat_diz'], true, 'BODY');
}
function sc_gallery_baseurl()
{
return e107::url('gallery', 'index');
}
function sc_gallery_cat_thumb($parm = null)
{
$parms = eHelper::scParams($parm);
$w = !empty($parms['w']) ? $parms['w'] : 300; // 260;
$h = !empty($parms['h']) ? $parms['h'] : 200; // 180;
$att = 'aw=' . $w . '&ah=' . $h . '&x=1'; // 'aw=190&ah=150';
$class = isset($parms['class']) ? $parms['class'] : 'img-responsive img-fluid';
$url = e107::url('gallery', 'gallery', $this->var);
if(isset($parms['thumbsrc']))
{
return e107::getParser()->thumbUrl($this->var['media_cat_image'], $att);
}
$text = "<a class='thumbnail' href='" . $url . "'>";
$text .= "<img class='".$class."' data-src='holder.js/" . $w . "x" . $h . "' src='" . e107::getParser()->thumbUrl($this->var['media_cat_image'], $att) . "' alt='' />";
$text .= "</a>";
return $text;
}
function sc_gallery_nextprev()
{
$url = e_REQUEST_SELF . '?page=[FROM]';
$totalPages = $this->total > 0 ? ceil($this->total / $this->amount) : 1;
return e107::getForm()->pagination(
$url,
$totalPages, // total PAGES
$this->page, // current PAGE (1-based)
$this->amount,
array('type' => 'page')
);
}
function sc_gallery_slideshow($parm = '')
{
$slideCat = e107::getPlugPref('gallery', 'slideshow_category');
$this->sliderCat = ($parm) ? $parm : vartrue($slideCat, 1);
$tmpl = e107::getTemplate('gallery', 'gallery');
$template = array_change_key_case($tmpl);
return e107::getParser()->parseTemplate($template['slideshow_wrapper']);
}
/**
* Display a Grid of thumbnails - useful for home pages.
* Amount per row differs according to device, so they are not set here, only the amount.
* @example {GALLERY_PORTFOLIO: placeholder=1&category=2}
*/
function sc_gallery_portfolio($parm=null)
{
$ns = e107::getRender();
$tp = e107::getParser();
// $parm = eHelper::scParams($parms);
$slideCat = e107::getPlugPref('gallery', 'slideshow_category');
$cat = (!empty($parm['category'])) ? $parm['category'] : vartrue($slideCat, false); //TODO Separate pref?
$tmpl = e107::getTemplate('gallery', 'gallery');
$limit = vartrue($parm['limit'], 6);
$plugPrefs = e107::getPlugConfig('gallery')->getPref();
$orderBy = varset($plugPrefs['orderby'], 'media_id DESC');
$imageQry = (empty($cat) || $cat==1) ? "gallery_image|gallery_image_1|gallery_1" : 'gallery_' . $cat . '|gallery_image_' . $cat;
$list = e107::getMedia()->getImages($imageQry, 0, $limit, null, $orderBy);
if(count($list) < 1 && vartrue($parm['placeholder']))
{
$list = array();
for($i = 0; $i < $limit; $i++)
{
$list[] = array('media_url' => '');
}
}
$template = e107::getTemplate('gallery', 'gallery', 'portfolio');
if(!empty($template['start']))
{
$text = $tp->parseTemplate($template['start'],true, $this);
}
else
{
$text = '';
}
//NOTE: Using tablerender() allows the theme developer to set the number of columns etc using col-xx-xx
foreach($list as $val)
{
$this->var = $val;
if(empty($template['item']))
{
$text .= $ns->tablerender('', $this->sc_gallery_thumb('class=gallery_thumb img-responsive img-fluid img-home-portfolio'), 'gallery_portfolio', true);
}
else
{
$text .= $tp->parseTemplate($template['item'],true,$this);
}
}
if(!empty($template['end']))
{
$text .= $tp->parseTemplate($template['end'],true, $this);
}
return $text;
}
/**
* All possible parameters
* {GALLERY_SLIDES=4|limit=16&template=MY_SLIDESHOW_SLIDE_ITEM}
* first parameter is always number of slides, default is 3
* limit - (optional) total limit of pcitures to be shown
* template - (optional) template - name of template to be used for parsing the slideshow item
*/
function sc_gallery_slides($parm=null)
{
$plugPrefs = e107::getPlugConfig('gallery')->getPref();
$orderBy = varset($plugPrefs['orderby'], 'media_id DESC');
$tp = e107::getParser();
$this->slideMode = true;
$parms = eHelper::scDualParams($parm);
$amount = $parms[1] ? intval($parms[1]) : 3; // vartrue(e107::getPlugPref('gallery','slideshow_perslide'),3);
$parms = $parms[2];
$limit = (integer) vartrue($parms['limit'], 16);
$list = e107::getMedia()->getImages('gallery_image|gallery_image_' . $this->sliderCat, 0, $limit, null, $orderBy);
$tmpl = e107::getTemplate('gallery', 'gallery');
$tmpl = array_change_key_case($tmpl); // change template key to lowercase (BC fix)
$tmpl_key = vartrue($parms['template'], 'slideshow_slide_item');
$item_template = $tmpl[$tmpl_key]; // e107::getTemplate('gallery','gallery', vartrue($parms['template'], 'SLIDESHOW_SLIDE_ITEM'));
$catList = e107::getMedia()->getCategories('gallery');
$cat = varset($catList['gallery_' . $this->sliderCat]);
$count = 1;
$inner = '';
foreach($list as $row)
{
$this->setVars($row)
->addVars($cat);
$inner .= ($count == 1) ? "\n\n<!-- SLIDE " . $count . " -->\n<div class='slide' id='gallery-item-" . $this->slideCount . "'>\n" : "";
$inner .= "\n\t" . $tp->parseTemplate($item_template, true) . "\n";
$inner .= ($count == $amount) ? "\n</div>\n\n" : "";
if($count == $amount)
{
$count = 1;
$this->slideCount++;
}
else
{
$count++;
}
}
$inner .= ($count != 1) ? "</div><!-- END SLIDES -->" : "";
return $inner;
}
function sc_gallery_jumper($parm=null)
{
// echo "SlideCount=".$this->slideCount;
if($this->slideCount == 1 && deftrue('E107_DBG_BASIC'))
{
return "gallery-jumper must be loaded after Gallery-Slides";
}
$text = '';
for($i = 1; $i < ($this->slideCount); $i++)
{
$val = ($parm == 'space') ? " " : $i;
$text .= '<a href="#" class="gallery-slide-jumper" id="gallery-jumper-' . $i . '">' . $val . '</a>';
}
return $text;
}
}