1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-29 10:38:08 +01:00

Gallery improvements: system URL routine, uses single entry point now (controller), more shortcode flexibility, some additional shortcodes

This commit is contained in:
secretr 2012-08-23 12:08:06 +00:00
parent 526f9b1a62
commit bb6e7d209b
8 changed files with 337 additions and 17 deletions

View File

@ -138,7 +138,7 @@ class gallery_cat_admin_ui extends e_admin_ui
'popup_w' => array('title'=> 'Image Max. Width', 'type' => 'text', 'data' => 'int', 'help'=>'Images will be auto-resized if greater than the width given here'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
'popup_h' => array('title'=> 'Image Max. Height', 'type' => 'text', 'data' => 'int', 'help'=>'Images will be auto-resized if greater than the height given here'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
'downloadable' => array('title'=> 'Show "download" link', 'type' => 'boolean', 'integer' => 'int', 'help'=>'A download option will be shown next to the popup caption'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
'downloadable' => array('title'=> 'Show "download" link', 'type' => 'boolean', 'data' => 'int', 'help'=>'A download option will be shown next to the popup caption'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
'slideshow_category' => array('title'=> 'Slideshow category', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Images from this category will be used in the sliding menu.'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
// 'slideshow_thumb_w' => array('title'=> 'Thumbnail Width', 'type' => 'number', 'data' => 'integer', 'help'=>'Width in px'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
@ -150,7 +150,8 @@ class gallery_cat_admin_ui extends e_admin_ui
'slideshow_freq' => array('title'=> 'Slide frequency', 'type' => 'number', 'data' => 'integer', 'help'=>'When auto-start is enabled, this dictates how long a slides stays put before the next jump. '), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
// 'slideshow_circular' => array('title'=> 'Slide circular-mode', 'type' => 'boolean', 'data' => 'integer', 'help'=>'By default when the first/last slide is reached, calling prev/next does nothing. If you want the effect to continue enable this option.'), //
'slideshow_effect' => array('title'=> 'Slide effect', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Type of effect. '), //
// 'slideshow_transition' => array('title'=> 'Slide transition', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Type of transition. ') //
// 'slideshow_transition' => array('title'=> 'Slide transition', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Type of transition. ') //
'perpage' => array('title'=> 'Images per page', 'type' => 'number', 'data' => 'int', 'help'=>'Number of images to be shown per page', 'validate' => 'required'), // 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')),
);

View File

@ -0,0 +1,153 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2012 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Cron Administration
*
* $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.8/e107_admin/cron.php $
* $Id: cron.php 12492 2011-12-30 16:09:10Z e107steved $
*
*/
/**
*
* @package e107
* @subpackage frontend
* @version $Id$
* Ultra-simple Image-Gallery
*/
/*
* THIS SCRIPT IS HIGHLY EXPERIMENTAL. USE AT OWN RISK.
*
*/
class plugin_gallery_index_controller extends eControllerFront
{
/**
* Plugin name - used to check if plugin is installed
* Set this only if plugin requires installation
* @var string
*/
protected $plugin = 'gallery';
/**
* Default controller access
* @var integer
*/
protected $userclass = e_UC_PUBLIC;
/**
* User input filter
* Format 'action' => array(var => validationArray)
* @var array
*/
protected $filter = array(
'category' => array(
'cat' => array('regex', '/[\w\pL\s\-+.,\']+/u'),
),
'list' => array(
'cat' => array('regex', '/[\w\pL\s\-+.,\']+/u'),
'frm' => array('int'),
),
);
/**
* @var array
*/
protected $catList;
public function init()
{
$this->catList = e107::getMedia()->getCategories('gallery');
}
public function actionIndex()
{
if(isset($_GET['cat']) && !empty($_GET['cat']))
{
$this->_forward('list');
}
else
{
$this->_forward('category');
}
}
public function actionCategory()
{
$template = e107::getTemplate('gallery');
$sc = e107::getScBatch('gallery',TRUE);
$text = "";
foreach($this->catList as $val)
{
$sc->setParserVars($val);
$text .= e107::getParser()->parseTemplate($template['CAT_ITEM'],TRUE);
}
$text = $template['CAT_START'].$text.$template['CAT_END'];
$this->addBody($text);
}
public function actionList()
{
$request = $this->getRequest();
// use only filtered variables
$cid = $request->getRequestParam('cat');
if($cid && !isset($this->catList[$cid]))
{
// get ID by SEF
$_cid = null;
foreach ($this->catList as $id => $row)
{
if($cid === $row['media_cat_title'])
{
$_cid = $id;
break;
}
}
$cid = $_cid;
}
if(empty($cid) || !isset($this->catList[$cid]))
{
$this->_forward('category');
return;
}
$tp = e107::getParser();
$template = e107::getTemplate('gallery');
$sc = e107::getScBatch('gallery',TRUE);
$sc->total = e107::getMedia()->countImages($cid);
$sc->amount = e107::getPlugPref('gallery','perpage', 12); // TODO Add Pref. amount per page.
$sc->curCat = $cid;
$sc->from = $request->getRequestParam('frm', 0);
$list = e107::getMedia()->getImages($cid,$sc->from,$sc->amount);
$catname = $tp->toHtml($this->catList[$cid]['media_cat_title'],false,'defs');
$cat = $this->catList[$cid];
$inner = "";
foreach($list as $row)
{
$sc->setVars($row)
->addVars($cat);
$inner .= $tp->parseTemplate($template['LIST_ITEM'],TRUE);
}
$text = $tp->parseTemplate($template['LIST_START'],TRUE);
$text .= $inner;
$text .= $tp->parseTemplate($template['LIST_END'],TRUE);
$this->addBody($text);
}
}

View File

@ -7,6 +7,13 @@
*/
if (!defined('e107_INIT')) { exit; }
// Override support
if(file_exists(e_PLUGIN.'gallery/custom_header.php'))
{
include(e_PLUGIN.'gallery/custom_header.php');
return;
}
e107::js('gallery', 'jslib/lightbox/js/lightbox.js','jquery');
e107::css('gallery', 'jslib/lightbox/css/lightbox.css','jquery');

View File

@ -20,7 +20,7 @@ class gallery_shortcodes extends e_shortcode
public $slideCount = 1;
private $downloadable = FALSE;
function __construct()
function init()
{
$this->downloadable = e107::getPlugPref('gallery','downloadable');
}
@ -34,21 +34,47 @@ class gallery_shortcodes extends e_shortcode
return $text;
}
function sc_gallery_description($parm='')
{
$tp = e107::getParser();
return $tp->toHTML($this->var['media_description'], true, 'BODY');
}
/**
* 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 size of the image (if available!), prefs will be ignored
*/
function sc_gallery_thumb($parm='')
{
$tp = e107::getParser();
$w = 190;
$h = 150;
$parms = eHelper::scParams($parm);
$w = vartrue($parms['w']) ? $parms['w'] : 190;
$h = vartrue($parms['h']) ? $parms['h'] : 150;
$class = ($this->slideMode == TRUE) ? 'gallery-slideshow-thumb' : 'gallery-thumb';
$rel = ($this->slideMode == TRUE) ? 'lightbox.SlideGallery' : 'lightbox.Gallery';
$att = vartrue($parm) ? $parm : 'aw='.$w.'&ah='.$h.'&x=1' ; // 'aw=190&ah=150';
$att = 'aw='.$w.'&ah='.$h.'&x=1'; // 'aw=190&ah=150';
$pop_w = vartrue(e107::getPlugPref('gallery','pop_w'),1024);
$pop_h = vartrue(e107::getPlugPref('gallery','pop_h'),768);
$attFull = 'w='.$pop_w.'&h='.$pop_h.'&x=1';
if(isset($parm['actualPreview']) && !empty($this->var['media_dimensions']))
{
list($pop_w, $pop_w) = array_map('trim', explode('x', $this->var['media_dimensions']));
}
$attFull = 'w='.$pop_w.'&h='.$pop_h.'&x=1';
// echo "<br /><br />".$attFull;
if(isset($parms['thumburl'])) return $tp->thumbUrl($this->var['media_url'], $attFull);
elseif(isset($parms['thumbsrc'])) return $tp->thumbUrl($this->var['media_url'],$att);
elseif(isset($parms['imageurl'])) return $tp->replaceConstants($this->var['media_url'], 'full');
$caption = $tp->toAttribute($this->var['media_caption']) ;
$caption .= ($this->downloadable) ? " <a class='e-tip smalltext' title='Right-click > Save Link As' href='".$tp->thumbUrl($this->var['media_url'], $attFull)."'>Download</a>" : "";
@ -63,16 +89,43 @@ class gallery_shortcodes extends e_shortcode
function sc_gallery_cat_title($parm='')
{
$tp = e107::getParser();
$text = "<a href='".e_SELF."?cat=".$this->var['media_cat_category']."'>";
$text .= $tp->toHtml($this->var['media_cat_title']);
$url = e107::getUrl()->create('gallery/index/list', $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::getUrl()->create('gallery/index/list', $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::getUrl()->create('gallery');
}
function sc_gallery_cat_thumb($parm='')
{
$att = ($parm) ?$parm : 'aw=190&ah=150';
$text = "<a href='".e_SELF."?cat=".$this->var['media_cat_category']."'>";
$parms = eHelper::scParams($parm);
$w = vartrue($parms['w']) ? $parms['w'] : 190;
$h = vartrue($parms['h']) ? $parms['h'] : 150;
$att = 'aw='.$w.'&ah='.$h.'&x=1'; // 'aw=190&ah=150';
$url = e107::getUrl()->create('gallery/index/list', $this->var);
if(isset($parms['thumbsrc'])) return e107::getParser()->thumbUrl($this->var['media_cat_image'],$att);
$text = "<a href='".$url."'>";
$text .= "<img src='".e107::getParser()->thumbUrl($this->var['media_cat_image'],$att)."' alt='' />";
$text .= "</a>";
return $text;
@ -80,8 +133,9 @@ class gallery_shortcodes extends e_shortcode
function sc_gallery_nextprev($parm='')
{
$url = e_SELF."?cat=".$this->curCat."--AMP--frm=--FROM--";
$parm = 'total='.$this->total.'&amount='.$this->amount.'&current='.$this->from.'&url='.$url; // .'&url='.$url;
// we passs both fields, the router will convert one of them to 'cat' variable, based on the current URL config
$url = 'url::gallery/index/list?media_cat_category='.$this->curCat.'--AMP--media_cat_title='.$this->var['media_cat_title'].'--AMP--frm=--FROM--::full=1';
$parm = 'total='.$this->total.'&amount='.$this->amount.'&current='.$this->from.'&url='.rawurlencode($url); // .'&url='.$url;
$text .= e107::getParser()->parseTemplate("{NEXTPREV=".$parm."}");
return $text;
}
@ -102,11 +156,13 @@ class gallery_shortcodes extends e_shortcode
$limit = varset($gp['slideshow_limit'],16);
$list = e107::getMedia()->getImages('gallery_'.$this->sliderCat,0,$limit);
$item_template = e107::getTemplate('gallery','gallery','SLIDESHOW_SLIDE_ITEM');
$cat = $this->catList[$this->sliderCat];
$count = 1;
foreach($list as $row)
{
$this->setParserVars($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";
@ -142,7 +198,5 @@ class gallery_shortcodes extends e_shortcode
return $text;
}
}
?>

View File

@ -26,5 +26,6 @@
<pref name="slideshow_auto">1</pref>
<pref name="slideshow_freq">4000</pref>
<pref name="slideshow_effect">scrollHorz</pref>
<pref name="perpage">12</pref>
</pluginPrefs>
</e107Plugin>

View File

@ -22,7 +22,7 @@ $GALLERY_TEMPLATE['LIST_END'] =
"</div>
<div class='gallery-list-end' >
<div class='gallery-list-nextprev'>{GALLERY_NEXTPREV}</div>
<div class='gallery-list-back'><a href='".e_SELF."'>Back to Categories</a></div>
<div class='gallery-list-back'><a href='{GALLERY_BASEURL}'>Back to Categories</a></div>
</div>
";

View File

@ -0,0 +1,54 @@
<?php
/*
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* System routing config
*/
class plugin_gallery_rewrite_url extends eUrlConfig
{
public function config()
{
return array(
'config' => array(
'allowMain' => true,
'format' => 'path',
'defaultRoute' => 'index/category',
// false - disable all parameters passed to assemble method by default
'allowVars' => array('cat', 'frm'),
// custom assemble/parse URL regex template
'varTemplates' => array('galleryCat' => '[\w\pL\s\-+.,\']+'),
),
// rule set array
'rules' => array(
'/' => 'index/category',
// allow only mapped vars - cat and frm parameters to be passed
'<cat:{galleryCat}>' => array('index/list', 'mapVars' => array('media_cat_title' => 'cat', 'from' => 'frm')),
)
);
}
/**
* Admin callback
* Language file not loaded as all language data is inside the lan_eurl.php (loaded by default on administration URL page)
*/
public function admin()
{
// static may be used for performance - XXX LANS
static $admin = array(
'labels' => array(
'name' => 'Gallery', // Module name
'label' => 'Gallery SEF', // Current profile name
'description' => 'SEF URLs enabled. Example: http://mysite.com/gallery/My Gallery Title', //
),
'form' => array(), // Under construction - additional configuration options
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
);
return $admin;
}
}

View File

@ -0,0 +1,50 @@
<?php
/*
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* System routing config
*/
class plugin_gallery_url extends eUrlConfig
{
public function config()
{
return array(
'config' => array(
'allowMain' => true,
'format' => 'path', // get|path - notify core for the current URL format, if set to 'get' rules will be ignored
'defaultRoute' => 'index/category', // [optional] default empty; route (no leading module) used when module is found with no additional controller/action information e.g. /news/
// false - disable all parameters passed to assemble method by default
'allowVars' => array('cat', 'frm'),
),
// rule set array
'rules' => array(
'/' => 'index/category',
'list' => array('index/list', 'mapVars' => array('media_cat_category' => 'cat', 'from' => 'frm'), 'allowVars' => array('cat', 'frm'),),
)
);
}
/**
* Admin callback
* Language file not loaded as all language data is inside the lan_eurl.php (loaded by default on administration URL page)
*/
public function admin()
{
// static may be used for performance - XXX LANS
static $admin = array(
'labels' => array(
'name' => 'Gallery', // Module name
'label' => 'Gallery default', // Current profile name
'description' => 'SEF URLs disabled. Example: http://mysite.com/gallery/?cat=gallery_1', //
),
'form' => array(), // Under construction - additional configuration options
'callbacks' => array(), // Under construction - could be used for e.g. URL generator functionallity
);
return $admin;
}
}