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