2009-11-25 12:01:25 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Copyright (c) e107 Inc 2009 - e107.org, Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
2009-12-12 16:35:46 +00:00
|
|
|
* $Id: e_shortcode.php,v 1.11 2009-12-12 16:35:45 secretr Exp $
|
2009-11-25 12:01:25 +00:00
|
|
|
*
|
2009-12-08 17:21:36 +00:00
|
|
|
* Featurebox shortcode batch class - shortcodes available site-wide. ie. equivalent to multiple .sc files.
|
2009-11-25 12:01:25 +00:00
|
|
|
*/
|
|
|
|
|
2009-12-09 18:33:43 +00:00
|
|
|
if (!defined('e107_INIT')) { exit; }
|
|
|
|
|
|
|
|
e107::includeLan(e_PLUGIN.'featurebox/languages/'.e_LANGUAGE.'_front_featurebox.php');
|
|
|
|
|
2009-11-25 12:01:25 +00:00
|
|
|
class featurebox_shortcodes // must match the plugin's folder name. ie. [PLUGIN_FOLDER]_shortcodes
|
|
|
|
{
|
2009-12-10 22:46:46 +00:00
|
|
|
protected $_categories = array();
|
|
|
|
|
2009-12-09 18:33:43 +00:00
|
|
|
/**
|
|
|
|
* Available parameters (GET string format)
|
|
|
|
* - cols (integer): number of items per column, default 1
|
|
|
|
* - no_fill_empty (boolean): don't fill last column with empty items (if required), default 0
|
|
|
|
* - tablestyle (string): mode to be used with <code>tablerender()</code>, default 'featurebox'
|
|
|
|
* - notablestyle (null): if isset - disable <code>tablerender()</code>
|
|
|
|
*
|
|
|
|
* @param string $parm parameters
|
|
|
|
* @param string $mod category template
|
|
|
|
*/
|
2009-12-08 17:21:36 +00:00
|
|
|
function sc_featurebox($parm, $mod = '')
|
2009-11-25 12:01:25 +00:00
|
|
|
{
|
2009-12-08 17:21:36 +00:00
|
|
|
// TODO cache
|
2009-12-09 18:33:43 +00:00
|
|
|
if(!e107::isInstalled('featurebox')) //just in case
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2009-12-08 17:21:36 +00:00
|
|
|
if(!$mod)
|
|
|
|
{
|
2009-12-09 18:33:43 +00:00
|
|
|
$ctemplate = 'default';
|
2009-12-08 17:21:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-09 18:33:43 +00:00
|
|
|
$ctemplate = $mod;
|
2009-12-08 17:21:36 +00:00
|
|
|
}
|
|
|
|
|
2009-12-09 18:33:43 +00:00
|
|
|
parse_str($parm, $parm);
|
|
|
|
|
2009-12-10 22:46:46 +00:00
|
|
|
$category = $this->getCategoryModel($ctemplate);
|
2009-12-08 17:21:36 +00:00
|
|
|
if(!$category->hasData())
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2009-12-12 16:35:46 +00:00
|
|
|
$tmpl = $this->getFboxTemplate($ctemplate);
|
2009-12-08 17:21:36 +00:00
|
|
|
$tp = e107::getParser();
|
2009-12-12 16:35:46 +00:00
|
|
|
$category->updateParams($parm);
|
2009-12-09 18:33:43 +00:00
|
|
|
|
2009-12-12 16:35:46 +00:00
|
|
|
$ret = $tp->parseTemplate($tmpl['list_start'], true, $category).$this->render($category, $ctemplate, $parm).$tp->parseTemplate($tmpl['list_end'], true, $category);
|
2009-12-09 18:33:43 +00:00
|
|
|
if(isset($parm['notablestyle']))
|
|
|
|
{
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return e107::getRender()->tablerender(FBLAN_01, $ret, vartrue($parm['tablestyle'], 'featurebox'), true);
|
|
|
|
}
|
|
|
|
|
2009-12-10 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Render featurebox navigation
|
|
|
|
* Available parameters (GET string format)
|
|
|
|
* - loop (boolean): loop using 'nav_loop' template, default 0
|
|
|
|
* - base (string): template key prefix, default is 'nav'. Example: 'mynav' base key will search templates 'mynav_start', 'mynav_loop', 'mynav_end'.
|
2009-12-12 16:35:46 +00:00
|
|
|
* - nolimit (boolean): ignore 'limit' field , use 'total' items number for navigation looping
|
|
|
|
* - uselimit (boolean): ignore 'limit' field , use 'total' items number for navigation looping
|
2009-12-10 22:46:46 +00:00
|
|
|
*
|
|
|
|
* @param string $parm parameters
|
|
|
|
* @param string $mod category template
|
|
|
|
*/
|
|
|
|
function sc_featurebox_navigation($parm, $mod = '')
|
|
|
|
{
|
|
|
|
// TODO cache
|
|
|
|
if(!e107::isInstalled('featurebox')) //just in case
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$mod)
|
|
|
|
{
|
|
|
|
$ctemplate = 'default';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ctemplate = $mod;
|
|
|
|
}
|
|
|
|
parse_str($parm, $parm);
|
|
|
|
|
2009-12-11 13:11:36 +00:00
|
|
|
$category = $this->getCategoryModel($ctemplate);
|
2009-12-10 22:46:46 +00:00
|
|
|
if(!$category->hasData())
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$tree = $category->getItemTree();
|
|
|
|
if($tree->isEmpty())
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
2009-12-12 16:35:46 +00:00
|
|
|
$tmpl = $this->getFboxTemplate($ctemplate);
|
2009-12-10 22:46:46 +00:00
|
|
|
if($category->get('fb_category_random'))
|
|
|
|
{
|
|
|
|
$parm['loop'] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$base = vartrue($parm['base'], 'nav').'_';
|
2009-12-12 16:35:46 +00:00
|
|
|
$tree_ids = array_keys($tree->getTree()); //all available item ids
|
|
|
|
|
2009-12-10 22:46:46 +00:00
|
|
|
$ret = $category->toHTML(varset($tmpl[$base.'start']), true);
|
2009-12-12 16:35:46 +00:00
|
|
|
$cols = $category->getParam('cols');
|
2009-12-11 13:11:36 +00:00
|
|
|
|
2009-12-10 22:46:46 +00:00
|
|
|
if(isset($parm['loop']) && $tree->getTotal() > 0 && vartrue($tmpl[$base.'item']))
|
|
|
|
{
|
2009-12-12 16:35:46 +00:00
|
|
|
// loop for all
|
|
|
|
if(isset($parm['nolimit']))
|
|
|
|
{
|
|
|
|
$total = $tree->getTotal();
|
|
|
|
}
|
|
|
|
// loop for limit number
|
|
|
|
elseif(isset($parm['uselimit']))
|
|
|
|
{
|
|
|
|
$total = $category->sc_featurebox_category_limit() ? intval($category->sc_featurebox_category_limit()) : $tree->getTotal();
|
|
|
|
}
|
|
|
|
// default - number based on all / limit (usefull for ajax navigation)
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$total = ceil($tree->getTotal() / ($category->sc_featurebox_category_limit() ? intval($category->sc_featurebox_category_limit()) : $tree->getTotal()) );
|
|
|
|
}
|
|
|
|
if($cols > 1)
|
|
|
|
{
|
|
|
|
$total = ceil($total / $cols);
|
|
|
|
}
|
2009-12-10 22:46:46 +00:00
|
|
|
$model = clone $category;
|
2009-12-12 16:35:46 +00:00
|
|
|
$item = new plugin_featurebox_item();
|
2009-12-10 22:46:46 +00:00
|
|
|
$tmp = array();
|
2009-12-12 16:35:46 +00:00
|
|
|
for ($index = 1; $index <= $total; $index++)
|
2009-12-10 22:46:46 +00:00
|
|
|
{
|
2009-12-12 16:35:46 +00:00
|
|
|
$nodeid = varset($tree_ids[($index - 1) * $cols], 0);
|
|
|
|
if($nodeid && $tree->hasNode($nodeid))
|
|
|
|
{
|
|
|
|
$model->setParam('counter', $index)
|
|
|
|
->setParam('total', $total)
|
|
|
|
->setParam('active', $index == varset($parm['from'], 1));
|
|
|
|
|
|
|
|
$node = $tree->getNode($nodeid);
|
|
|
|
|
|
|
|
e107::getScParser()->resetScClass('plugin_featurebox_category', $model);
|
|
|
|
$node->setCategory($model)
|
|
|
|
->setParam('counter', $index)
|
|
|
|
->setParam('total', $total)
|
|
|
|
->setParam('limit', $category->get('fb_category_limit'))
|
|
|
|
;
|
|
|
|
|
|
|
|
$tmp[] = $node->toHTML($tmpl[$base.'item'], true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
e107::getScParser()->resetScClass('plugin_featurebox_item', $item);
|
2009-12-10 22:46:46 +00:00
|
|
|
$tmp[] = $model->setParam('counter', $index)
|
|
|
|
->setParam('active', $index == varset($parm['from'], 1))
|
|
|
|
->toHTML($tmpl[$base.'item'], true);
|
2009-12-12 16:35:46 +00:00
|
|
|
}
|
2009-12-10 22:46:46 +00:00
|
|
|
$ret .= implode(varset($tmpl[$base.'separator']), $tmp);
|
|
|
|
unset($model, $tmp);
|
|
|
|
}
|
|
|
|
$ret .= $category->toHTML(varset($tmpl[$base.'end']), true);
|
|
|
|
|
|
|
|
if(vartrue($tmpl['js']))
|
|
|
|
{
|
|
|
|
e107::getJs()->footerFile(explode(',', $tmpl['js']));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vartrue($tmpl['js_inline']))
|
|
|
|
{
|
|
|
|
e107::getJs()->footerInline($tmpl['js_inline'], 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2009-12-09 18:33:43 +00:00
|
|
|
/**
|
2009-12-11 13:11:36 +00:00
|
|
|
* Get & Render featurebox items (custom)
|
2009-12-09 18:33:43 +00:00
|
|
|
* Available parameters (GET string format)
|
|
|
|
* - cols (integer): number of items per column, default 1
|
|
|
|
* - no_fill_empty (boolean): don't fill last column with empty items (if required), default 0
|
2009-12-10 22:46:46 +00:00
|
|
|
* - from (integer): start load at
|
|
|
|
* - limit (integer): load to
|
2009-12-09 18:33:43 +00:00
|
|
|
*
|
|
|
|
* @param string $parm parameters
|
|
|
|
* @param string $mod category template
|
|
|
|
*/
|
2009-12-10 22:46:46 +00:00
|
|
|
function sc_featurebox_items($parm, $mod = '')
|
2009-12-09 18:33:43 +00:00
|
|
|
{
|
|
|
|
// TODO cache
|
|
|
|
if(!e107::isInstalled('featurebox')) //just in case
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$mod)
|
|
|
|
{
|
|
|
|
$ctemplate = 'default';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ctemplate = $mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_str($parm, $parm);
|
|
|
|
|
2009-12-10 22:46:46 +00:00
|
|
|
$category = clone $this->getCategoryModel($ctemplate);
|
2009-12-09 18:33:43 +00:00
|
|
|
if(!$category->hasData())
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
2009-12-12 16:35:46 +00:00
|
|
|
return $this->render($category, $ctemplate, $parm);
|
2009-12-11 14:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render featurebox list
|
|
|
|
* @param plugin_featurebox_category $category
|
2009-12-12 16:35:46 +00:00
|
|
|
* @param string $ctemplate category template
|
2009-12-11 14:33:31 +00:00
|
|
|
* @param array $parm
|
|
|
|
*/
|
2009-12-12 16:35:46 +00:00
|
|
|
public function render($category, $ctemplate, $parm)
|
2009-12-11 14:33:31 +00:00
|
|
|
{
|
2009-12-12 16:35:46 +00:00
|
|
|
$tmpl = $this->getFboxTemplate($ctemplate);
|
2009-12-10 22:46:46 +00:00
|
|
|
$cols = intval(vartrue($parm['cols'], 1));
|
|
|
|
$limit = intval(varset($parm['limit'], $category->sc_featurebox_category_limit()));
|
2009-12-11 13:45:12 +00:00
|
|
|
$from = (intval(vartrue($parm['from'], 1)) - 1) * $limit;
|
2009-12-10 22:46:46 +00:00
|
|
|
$category->setParam('cols', $cols)
|
|
|
|
->setParam('no_fill_empty', isset($parm['no_fill_empty']) ? 1 : 0)
|
|
|
|
->setParam('limit', $limit)
|
|
|
|
->setParam('from', $from);
|
|
|
|
|
2009-12-11 13:11:36 +00:00
|
|
|
$tree = $category->getItemTree(true);
|
2009-12-09 18:33:43 +00:00
|
|
|
if($tree->isEmpty())
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2009-12-11 14:33:31 +00:00
|
|
|
$total = $tree->getTotal();
|
2009-12-10 22:46:46 +00:00
|
|
|
$category->setParam('total', $total);
|
|
|
|
$counter = 1;
|
|
|
|
$col_counter = 1;
|
2009-12-11 14:33:31 +00:00
|
|
|
$cols_counter = 1; // column counter
|
2009-12-10 22:46:46 +00:00
|
|
|
$ret = '';
|
2009-12-11 13:11:36 +00:00
|
|
|
|
2009-12-10 22:46:46 +00:00
|
|
|
foreach ($tree->getTree() as $id => $node)
|
|
|
|
{
|
|
|
|
$tmpl_item = e107::getTemplate('featurebox', 'featurebox', $node->get('fb_template'));
|
|
|
|
if(!$tmpl_item)
|
|
|
|
{
|
2009-12-11 12:51:10 +00:00
|
|
|
$tmpl_item = e107::getTemplate('featurebox', 'featurebox', 'default', true, true);
|
2009-12-10 22:46:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// reset column counter
|
|
|
|
if($col_counter > $cols)
|
|
|
|
{
|
|
|
|
$col_counter = 1;
|
|
|
|
}
|
2009-12-11 14:33:31 +00:00
|
|
|
|
|
|
|
// item container (category template)
|
|
|
|
$tmpl_item = $tmpl['item_start'].$tmpl_item.$tmpl['item_end'];
|
2009-12-10 22:46:46 +00:00
|
|
|
|
|
|
|
// add column start
|
|
|
|
if(1 == $col_counter && vartrue($tmpl['col_start']))
|
|
|
|
{
|
|
|
|
$tmpl_item = $tmpl['col_start'].$tmpl_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
// there is more
|
|
|
|
if(($total - $counter) > 0)
|
|
|
|
{
|
|
|
|
// add column end if column end reached
|
|
|
|
if($cols == $col_counter && vartrue($tmpl['col_end']))
|
|
|
|
{
|
2009-12-11 14:33:31 +00:00
|
|
|
$tmpl_item .= $tmpl['col_end'];
|
2009-12-10 22:46:46 +00:00
|
|
|
}
|
|
|
|
// else add item separator
|
2009-12-12 16:35:46 +00:00
|
|
|
elseif($cols != $col_counter && 1 != $col_counter)
|
2009-12-10 22:46:46 +00:00
|
|
|
{
|
2009-12-11 14:33:31 +00:00
|
|
|
$tmpl_item .= $tmpl['item_separator'];
|
2009-12-10 22:46:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// no more items - clean & close
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$empty_cnt = $cols - $col_counter;
|
|
|
|
if($empty_cnt > 0 && !$category->getParam('no_fill_empty'))
|
|
|
|
{
|
|
|
|
// empty items fill
|
2009-12-11 14:33:31 +00:00
|
|
|
$tmp = new plugin_featurebox_item();
|
|
|
|
$tmp->setCategory($category);
|
|
|
|
$tmp_tmpl_item = $tmpl['item_separator'].$tmpl['item_start'].varset($tmpl['item_empty'], '<div><!-- --></div>').$tmpl['item_end'];
|
2009-12-10 22:46:46 +00:00
|
|
|
for ($index = 1; $index <= $empty_cnt; $index++)
|
|
|
|
{
|
2009-12-11 14:33:31 +00:00
|
|
|
$tmpl_item .= $tmp->setParam('counter', $counter + $index)
|
|
|
|
->setParam('cols', $cols)
|
|
|
|
->setParam('col_counter', $col_counter + $index)
|
|
|
|
->setParam('cols_counter', $cols_counter)
|
|
|
|
->setParam('limit', $category->get('fb_category_limit'))
|
|
|
|
->setParam('total', $total)
|
|
|
|
->toHTML($tmp_tmpl_item);
|
2009-12-10 22:46:46 +00:00
|
|
|
}
|
2009-12-11 14:33:31 +00:00
|
|
|
unset($tmp, $tmp_tmpl_item);
|
2009-12-10 22:46:46 +00:00
|
|
|
}
|
|
|
|
// add column end
|
|
|
|
$tmpl_item .= varset($tmpl['col_end']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ret .= $node->setParam('counter', $counter)
|
|
|
|
->setParam('cols', $cols)
|
|
|
|
->setParam('col_counter', $col_counter)
|
2009-12-11 14:38:26 +00:00
|
|
|
->setParam('cols_counter', $cols_counter)
|
2009-12-10 22:46:46 +00:00
|
|
|
->setParam('limit', $category->get('fb_category_limit'))
|
|
|
|
->setParam('total', $total)
|
|
|
|
->setCategory($category)
|
|
|
|
->toHTML($tmpl_item);
|
2009-12-11 14:38:26 +00:00
|
|
|
|
|
|
|
if($cols == $col_counter)
|
|
|
|
{
|
|
|
|
$cols_counter++;
|
|
|
|
}
|
2009-12-10 22:46:46 +00:00
|
|
|
|
|
|
|
$counter++;
|
|
|
|
$col_counter++;
|
|
|
|
}
|
|
|
|
return $ret;
|
2009-12-09 18:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve template array by category
|
|
|
|
*
|
2009-12-12 16:35:46 +00:00
|
|
|
* @param string $ctemplate
|
2009-12-09 18:33:43 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2009-12-12 16:35:46 +00:00
|
|
|
public function getFboxTemplate($ctemplate)
|
2009-12-09 18:33:43 +00:00
|
|
|
{
|
2009-12-12 16:35:46 +00:00
|
|
|
$tmpl = e107::getTemplate('featurebox', 'featurebox_category', $ctemplate, 'front');
|
|
|
|
if(!$tmpl && e107::getTemplate('featurebox', 'featurebox_category', $ctemplate, false))
|
2009-12-09 18:33:43 +00:00
|
|
|
{
|
2009-12-12 16:35:46 +00:00
|
|
|
$tmpl = e107::getTemplate('featurebox', 'featurebox_category', $ctemplate, false); // plugin template
|
2009-12-09 18:33:43 +00:00
|
|
|
}
|
|
|
|
elseif(!$tmpl && e107::getTemplate('featurebox', 'featurebox_category', 'default'))
|
|
|
|
{
|
|
|
|
$tmpl = e107::getTemplate('featurebox', 'featurebox_category', 'default'); // theme/plugin default template
|
|
|
|
}
|
|
|
|
elseif(!$tmpl)
|
|
|
|
{
|
|
|
|
$tmpl = e107::getTemplate('featurebox', 'featurebox_category', 'default', false); //plugin default
|
|
|
|
}
|
|
|
|
return $tmpl;
|
2009-11-25 12:01:25 +00:00
|
|
|
}
|
2009-12-10 22:46:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get category model by template
|
|
|
|
* @param string $template
|
|
|
|
* @return plugin_featurebox_category
|
|
|
|
*/
|
|
|
|
public function getCategoryModel($template, $force = false)
|
|
|
|
{
|
|
|
|
if(!isset($this->_categories[$template]))
|
|
|
|
{
|
|
|
|
$this->_categories[$template] = new plugin_featurebox_category();
|
|
|
|
$this->_categories[$template]->loadByTemplate($template, $force);
|
|
|
|
}
|
|
|
|
return $this->_categories[$template];
|
|
|
|
}
|
2009-11-25 12:01:25 +00:00
|
|
|
}
|