2006-12-02 04:36:16 +00:00
|
|
|
<?php
|
|
|
|
/*
|
2009-08-20 16:41:29 +00:00
|
|
|
* e107 website system
|
|
|
|
*
|
2010-04-23 15:54:11 +00:00
|
|
|
* Copyright (C) 2008-2010 e107 Inc (e107.org)
|
2009-08-20 16:41:29 +00:00
|
|
|
* Released under the terms and conditions of the
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
|
|
|
*
|
|
|
|
* e107 Shortcode handler
|
|
|
|
*
|
2010-04-23 15:54:11 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2010-04-25 13:52:14 +00:00
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!defined('e107_INIT'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-04-24 11:39:14 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package e107
|
|
|
|
* @subpackage e107_handlers
|
|
|
|
* @version $Id$
|
|
|
|
* @author e107inc
|
|
|
|
*
|
|
|
|
* e_parse_shortcode - shortcode parser/manager, former e_shortcode
|
|
|
|
* e_shortcode - abstract batch class
|
|
|
|
*/
|
|
|
|
|
2009-08-20 16:41:29 +00:00
|
|
|
/**
|
2010-04-23 15:54:11 +00:00
|
|
|
* FIXME: to be removed
|
2009-08-20 16:41:29 +00:00
|
|
|
*/
|
2010-04-25 13:52:14 +00:00
|
|
|
function register_shortcode($classFunc, $codes, $path = '', $force = false)
|
2007-06-13 02:53:21 +00:00
|
|
|
{
|
2010-04-23 15:54:11 +00:00
|
|
|
return e107::getScParser()->registerShortcode($classFunc, $codes, $path, $force);
|
2009-01-15 22:04:45 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 16:41:29 +00:00
|
|
|
/**
|
2010-04-23 15:54:11 +00:00
|
|
|
* FIXME: to be removed
|
2009-08-20 16:41:29 +00:00
|
|
|
*/
|
|
|
|
function setScVar($className, $scVarName, $value)
|
2009-01-25 17:44:13 +00:00
|
|
|
{
|
2010-04-23 15:54:11 +00:00
|
|
|
return e107::getScParser()->setScVar($className, $scVarName, $value);
|
2009-01-25 17:44:13 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 22:23:02 +00:00
|
|
|
/**
|
2011-03-24 21:29:45 +00:00
|
|
|
* FIXME: to be removed (once event calendar changed)
|
2009-11-20 22:23:02 +00:00
|
|
|
*/
|
2010-04-23 15:54:11 +00:00
|
|
|
function callScFunc($className, $scFuncName, $param = '')
|
2009-11-20 22:23:02 +00:00
|
|
|
{
|
2010-04-23 15:54:11 +00:00
|
|
|
return e107::getScParser()->callScFunc($className, $scFuncName, $param);
|
2009-11-20 22:23:02 +00:00
|
|
|
}
|
|
|
|
|
2009-08-20 16:41:29 +00:00
|
|
|
/**
|
2010-04-23 15:54:11 +00:00
|
|
|
* FIXME: to be removed
|
2009-08-20 16:41:29 +00:00
|
|
|
*/
|
2010-04-23 15:54:11 +00:00
|
|
|
function initShortcodeClass($class, $force = false, $eVars = null)
|
2009-01-15 22:04:45 +00:00
|
|
|
{
|
2010-04-23 15:54:11 +00:00
|
|
|
return e107::getScParser()->initShortcodeClass($class, $eVars, $force);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
class e_parse_shortcode
|
2008-02-13 02:57:17 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
protected $scList = array(); // The actual code - added by parsing files or when plugin codes encountered. Array key is the shortcode name.
|
|
|
|
protected $parseSCFiles; // True if individual shortcode files are to be used
|
2011-03-24 21:29:45 +00:00
|
|
|
protected $addedCodes = NULL; // Pointer to a class or array to be used on a single call
|
2010-04-25 13:52:14 +00:00
|
|
|
protected $registered_codes = array(); // Shortcodes added by plugins TODO make it private
|
|
|
|
protected $scClasses = array(); // Batch shortcode classes - TODO make it private
|
|
|
|
protected $scOverride = array(); // Array of codes found in override/ dir
|
|
|
|
/**
|
|
|
|
* @var e_vars
|
|
|
|
*/
|
|
|
|
protected $eVars = null;
|
2010-04-23 15:54:11 +00:00
|
|
|
|
|
|
|
function __construct()
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->parseSCFiles = true; // Default probably never used, but make sure its defined.
|
2012-04-23 01:21:06 +00:00
|
|
|
|
2009-09-19 17:43:19 +00:00
|
|
|
$this->loadOverrideShortcodes();
|
|
|
|
$this->loadThemeShortcodes();
|
|
|
|
$this->loadPluginShortcodes();
|
|
|
|
$this->loadPluginSCFiles();
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->loadCoreShortcodes();
|
2012-04-23 01:21:06 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
/**
|
|
|
|
* Register shortcode
|
|
|
|
* $classFunc could be function name, class name or object
|
|
|
|
* $code could be 'true' when class name/object is passed to automate the
|
|
|
|
* registration of shortcode methods
|
|
|
|
*
|
|
|
|
* @param mixed $classFunc
|
|
|
|
* @param mixed $codes
|
|
|
|
* @param string $path
|
|
|
|
* @param boolean $force override
|
|
|
|
* @return e_parse_shortcode
|
|
|
|
*/
|
|
|
|
function registerShortcode($classFunc, $codes, $path = '', $force = false)
|
|
|
|
{
|
|
|
|
//If codes is set to true, let's go get a list of shortcode methods
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($codes === true)
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
|
|
|
$codes = array();
|
|
|
|
$tmp = get_class_methods($classFunc);
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($tmp as $c)
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (strpos($c, 'sc_') === 0)
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
|
|
|
$codes[] = substr($c, 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($tmp);
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
//Register object feature
|
|
|
|
$classObj = null;
|
2010-04-25 13:52:14 +00:00
|
|
|
if (is_object($classFunc))
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
|
|
|
$classObj = $classFunc;
|
|
|
|
$classFunc = get_class($classObj);
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
//We only register these shortcodes if they have not already been registered in some manner
|
|
|
|
//ie theme or other plugin .sc files
|
2010-04-25 13:52:14 +00:00
|
|
|
if (is_array($codes))
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($codes as $code)
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
|
|
|
$code = strtoupper($code);
|
2010-04-25 13:52:14 +00:00
|
|
|
if ((!$this->isRegistered($code) || $force == true) && !$this->isOverride($code))
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
|
|
|
$this->registered_codes[$code] = array('type' => 'class', 'path' => $path, 'class' => $classFunc);
|
|
|
|
}
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
//register object if required
|
2010-04-25 13:52:14 +00:00
|
|
|
if (null !== $classObj && (!$this->isScClass($classFunc) || $force == true))
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
|
|
|
$this->scClasses[$classFunc] = $classObj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$codes = strtoupper($codes);
|
2010-04-25 13:52:14 +00:00
|
|
|
if ((!$this->isRegistered($code) || $force == true) && !$this->isOverride($code))
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
|
|
|
$this->registered_codes[$codes] = array('type' => 'func', 'path' => $path, 'function' => $classFunc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
/**
|
|
|
|
* Add value to already registered SC object
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @param string $scVarName
|
|
|
|
* @param mixed $value
|
|
|
|
* @return e_parse_shortcode
|
|
|
|
*/
|
|
|
|
public function setScVar($className, $scVarName, $value)
|
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($this->isScClass($className))
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
2010-04-24 09:58:02 +00:00
|
|
|
// new way - batch should extend e_shortcode class
|
2010-04-25 13:52:14 +00:00
|
|
|
if (method_exists($this->scClasses[$className], 'setScVar'))
|
2010-04-24 09:58:02 +00:00
|
|
|
{
|
|
|
|
$this->scClasses[$className]->setScVar($scVarName, $value);
|
|
|
|
}
|
|
|
|
else // Old - DEPRECATED
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2010-04-24 09:58:02 +00:00
|
|
|
{
|
|
|
|
$this->scClasses[$className]->$scVarName = $value;
|
|
|
|
}
|
2010-04-23 15:54:11 +00:00
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
/**
|
|
|
|
* Call function on an already registered SC object
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @param string $scFuncName
|
|
|
|
* @param mixed $param - passed to function
|
|
|
|
*
|
2010-04-25 13:52:14 +00:00
|
|
|
* @return mixed|boolean - NULL if class/method doesn't exist; otherwise whatever the function returns.
|
2010-04-23 15:54:11 +00:00
|
|
|
*/
|
|
|
|
public function callScFunc($className, $scFuncName, $param = '')
|
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($this->isScClass($className))
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
return method_exists($this->scClasses[$className], $scFuncName) ? call_user_func(array($this->scClasses[$className], $scFuncName), $param) : null;
|
2010-04-23 15:54:11 +00:00
|
|
|
}
|
2010-04-24 09:58:02 +00:00
|
|
|
return null;
|
2010-04-23 15:54:11 +00:00
|
|
|
}
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
/**
|
2010-04-26 15:05:59 +00:00
|
|
|
* same as e_parse_shortcode::callScFunc(), but passes the last argument (array)
|
2010-04-25 13:52:14 +00:00
|
|
|
* to the called method as multiple arguments
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @param string $scFuncName
|
|
|
|
* @param array $param - arguments passed to function
|
|
|
|
*
|
|
|
|
* @return mixed|boolean - NULL if class/method doesn't exist; otherwise whatever the function returns.
|
|
|
|
*/
|
|
|
|
protected function callScFuncA($className, $scFuncName, $args = array())
|
|
|
|
{
|
|
|
|
if ($this->isScClass($className))
|
|
|
|
{
|
|
|
|
// avoid warnings
|
|
|
|
return method_exists($this->scClasses[$className], $scFuncName) ? call_user_func_array(array($this->scClasses[$className], $scFuncName), $args) : null;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
/**
|
|
|
|
* Create shortcode object - don't forget you still can use e_shortcode.php
|
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
* @param boolean $force
|
|
|
|
* @return e_shortcode
|
|
|
|
*/
|
2010-04-25 13:52:14 +00:00
|
|
|
public function initShortcodeClass($class, $force = false)
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
2011-11-22 12:52:34 +00:00
|
|
|
if (class_exists($class, false) && ($force || !$this->isScClass($class)))
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->scClasses[$class] = new $class();
|
2010-04-23 15:54:11 +00:00
|
|
|
return $this->scClasses[$class];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
|
|
|
/*public function getScObject($className)
|
|
|
|
{
|
|
|
|
if (isset($this->scClasses[$className]))
|
|
|
|
{
|
|
|
|
return $this->scClasses[$className];
|
|
|
|
}
|
|
|
|
// TODO - throw exception?
|
|
|
|
return null;
|
|
|
|
}*/
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
/**
|
|
|
|
* Get registered SC object
|
2010-04-25 13:52:14 +00:00
|
|
|
* Normally you would use the proxy of this method - e107::getScBatch()
|
|
|
|
* DRAFT!
|
2010-04-26 15:05:59 +00:00
|
|
|
*
|
|
|
|
* <code><?php
|
2010-04-25 13:52:14 +00:00
|
|
|
* // simple use
|
2012-04-23 01:21:06 +00:00
|
|
|
* e107::getScParser()->getScObject('news_shortcodes'); // For Globally Registered shortcodes, including plugins using e_shortcode.php
|
2010-04-26 15:05:59 +00:00
|
|
|
*
|
2012-01-06 10:05:32 +00:00
|
|
|
* // plugin override - e107_plugins/myplug/shortcodes/batch/news_shortcodes.php -> class plugin_myplug_news_shortcodes
|
2010-04-25 13:52:14 +00:00
|
|
|
* e107::getScParser()->getScObject('news_shortcodes', 'myplug', true);
|
2010-04-26 15:05:59 +00:00
|
|
|
*
|
2010-04-25 13:52:14 +00:00
|
|
|
* // more complex plugin override
|
2012-01-06 10:05:32 +00:00
|
|
|
* // e107_plugins/myplug/shortcodes/batch/news2_shortcodes.php -> class plugin_myplug_news2_shortcodes
|
2010-04-25 13:52:14 +00:00
|
|
|
* e107::getScParser()->getScObject('news_shortcodes', 'myplug', 'news2_shortcodes');
|
|
|
|
* </code>
|
2010-04-23 15:54:11 +00:00
|
|
|
* @param string $className
|
2012-04-23 01:21:06 +00:00
|
|
|
* @param string $plugName if true className is used., if string, string value is used.
|
2010-04-25 13:52:14 +00:00
|
|
|
* @param string $overrideClass if true, $className is used
|
2010-04-23 15:54:11 +00:00
|
|
|
* @return e_shortcode
|
|
|
|
*/
|
2010-04-25 13:52:14 +00:00
|
|
|
public function getScObject($className, $pluginName = null, $overrideClass = null)
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
2012-04-23 01:21:06 +00:00
|
|
|
if(trim($className)==""){ return; }
|
|
|
|
|
2010-04-26 15:05:59 +00:00
|
|
|
$_class_fname = $className;
|
2012-04-23 01:21:06 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
// plugin override
|
|
|
|
if($overrideClass)
|
|
|
|
{
|
|
|
|
if(true === $overrideClass)
|
|
|
|
{
|
|
|
|
$overrideClass = $className;
|
2010-04-26 15:05:59 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
// e.g. class plugin_myplug_news_shortcodes
|
|
|
|
$_class_fname = $overrideClass;
|
2010-12-07 13:30:22 +00:00
|
|
|
$className = 'plugin_'.$pluginName.'_'.str_replace('/', '_', $overrideClass);
|
2010-04-25 13:52:14 +00:00
|
|
|
}
|
2012-04-23 01:21:06 +00:00
|
|
|
elseif(is_string($pluginName))
|
2010-04-26 13:16:44 +00:00
|
|
|
{
|
2010-12-07 13:30:22 +00:00
|
|
|
$className = 'plugin_'.$pluginName.'_'.str_replace('/', '_', $className);
|
2010-04-26 13:16:44 +00:00
|
|
|
}
|
2012-04-23 01:21:06 +00:00
|
|
|
elseif($pluginName === TRUE)
|
|
|
|
{
|
|
|
|
$pluginName = str_replace("_shortcodes","",$className);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isScClass($className)) // Includes global Shortcode Classes. ie. e_shortcode.php
|
2010-04-26 15:05:59 +00:00
|
|
|
{
|
|
|
|
return $this->scClasses[$className];
|
|
|
|
}
|
|
|
|
|
2012-01-06 10:05:32 +00:00
|
|
|
$path = ($pluginName ? e_PLUGIN.$pluginName.'/shortcodes/batch/' : e_CORE.'shortcodes/batch/').$_class_fname.'.php';
|
2012-04-23 01:21:06 +00:00
|
|
|
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if (is_readable($path))
|
|
|
|
{
|
2010-04-26 15:05:59 +00:00
|
|
|
require_once($path);
|
|
|
|
if (class_exists($className, false)) // don't allow __autoload()
|
2010-04-25 13:52:14 +00:00
|
|
|
{
|
|
|
|
// register instance directly to allow override
|
2012-04-23 01:21:06 +00:00
|
|
|
// $this->scClasses[$className] = new $className(); // located inside registerClassMethods()
|
2010-10-26 08:25:01 +00:00
|
|
|
$this->registerClassMethods($className, $path);
|
2010-04-25 13:52:14 +00:00
|
|
|
return $this->scClasses[$className];
|
|
|
|
}
|
2012-04-23 01:21:06 +00:00
|
|
|
elseif(E107_DBG_BBSC || E107_DBG_SC)
|
|
|
|
{
|
|
|
|
echo "Couldn't Find Class '".$className."' in <b>".$path."</b>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif(E107_DBG_BBSC || E107_DBG_SC)
|
|
|
|
{
|
|
|
|
echo "Couldn't Load: <b>".$path."</b>";
|
2010-04-25 13:52:14 +00:00
|
|
|
}
|
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
// TODO - throw exception?
|
2010-04-24 09:58:02 +00:00
|
|
|
return null;
|
2009-09-19 17:43:19 +00:00
|
|
|
}
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2009-09-19 17:43:19 +00:00
|
|
|
/**
|
2010-02-10 22:18:57 +00:00
|
|
|
* Register any shortcode from the override/shortcodes/ directory
|
2009-11-17 15:29:33 +00:00
|
|
|
*
|
2010-04-24 09:58:02 +00:00
|
|
|
* @return e_parse_shortcode
|
2009-09-19 17:43:19 +00:00
|
|
|
*/
|
|
|
|
protected function loadOverrideShortcodes()
|
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (e107::getPref('sc_override'))
|
2009-01-16 01:02:41 +00:00
|
|
|
{
|
2010-04-23 15:54:11 +00:00
|
|
|
$tmp = explode(',', e107::getPref('sc_override'));
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($tmp as $code)
|
2009-01-16 01:02:41 +00:00
|
|
|
{
|
|
|
|
$code = strtoupper(trim($code));
|
|
|
|
$this->registered_codes[$code]['type'] = 'override';
|
|
|
|
$this->scOverride[] = $code;
|
|
|
|
}
|
2010-01-23 16:41:56 +00:00
|
|
|
}
|
2010-04-24 09:58:02 +00:00
|
|
|
return $this;
|
2009-09-19 17:43:19 +00:00
|
|
|
}
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2009-09-19 17:43:19 +00:00
|
|
|
/**
|
|
|
|
* Register any shortcodes that were registered by the theme
|
|
|
|
* $register_sc[] = 'MY_THEME_CODE'
|
2009-11-17 15:29:33 +00:00
|
|
|
*
|
2010-04-24 09:58:02 +00:00
|
|
|
* @return e_parse_shortcode
|
2009-09-19 17:43:19 +00:00
|
|
|
*/
|
2010-07-27 10:45:55 +00:00
|
|
|
public function loadThemeShortcodes()
|
2009-09-19 17:43:19 +00:00
|
|
|
{
|
|
|
|
global $register_sc;
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if (isset($register_sc) && is_array($register_sc))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($register_sc as $code)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!$this->isRegistered($code))
|
2009-01-16 01:02:41 +00:00
|
|
|
{
|
|
|
|
$code = strtoupper($code);
|
|
|
|
$this->registered_codes[$code]['type'] = 'theme';
|
|
|
|
}
|
2009-01-08 17:23:13 +00:00
|
|
|
}
|
2010-01-23 16:41:56 +00:00
|
|
|
}
|
2010-04-24 09:58:02 +00:00
|
|
|
return $this;
|
2009-09-19 17:43:19 +00:00
|
|
|
}
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2009-09-19 17:43:19 +00:00
|
|
|
/**
|
|
|
|
* Register all .sc files found in plugin directories (via pref)
|
2009-11-17 15:29:33 +00:00
|
|
|
*
|
2010-04-24 09:58:02 +00:00
|
|
|
* @return e_parse_shortcode
|
2009-09-19 17:43:19 +00:00
|
|
|
*/
|
|
|
|
protected function loadPluginSCFiles()
|
2010-01-23 16:41:56 +00:00
|
|
|
{
|
2010-04-24 09:58:02 +00:00
|
|
|
$pref = e107::getPref('shortcode_list');
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($pref)
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($pref as $path => $namearray)
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($namearray as $code => $uclass)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($code == 'shortcode_config')
|
2007-06-13 02:53:21 +00:00
|
|
|
{
|
|
|
|
include_once(e_PLUGIN.$path.'/shortcode_config.php');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$code = strtoupper($code);
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!$this->isRegistered($code))
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
|
|
|
$this->registered_codes[$code]['type'] = 'plugin';
|
|
|
|
$this->registered_codes[$code]['path'] = $path;
|
2010-04-24 09:58:02 +00:00
|
|
|
$this->registered_codes[$code]['perms'] = $uclass; // XXX how we get this?
|
2009-01-08 17:23:13 +00:00
|
|
|
}
|
2007-06-13 02:53:21 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-23 16:41:56 +00:00
|
|
|
}
|
2010-04-24 09:58:02 +00:00
|
|
|
return $this;
|
2009-01-08 21:47:44 +00:00
|
|
|
}
|
2009-10-20 16:00:38 +00:00
|
|
|
|
2009-09-18 22:20:40 +00:00
|
|
|
/**
|
2010-01-23 16:41:56 +00:00
|
|
|
* Register Plugin Shortcode Batch files (e_shortcode.php) for use site-wide.
|
|
|
|
* Equivalent to multiple .sc files in the plugin's folder.
|
2009-11-17 15:29:33 +00:00
|
|
|
*
|
2010-04-24 09:58:02 +00:00
|
|
|
* @return e_parse_shortcode
|
2009-09-18 22:20:40 +00:00
|
|
|
*/
|
2009-09-19 17:43:19 +00:00
|
|
|
protected function loadPluginShortcodes()
|
2009-09-18 22:20:40 +00:00
|
|
|
{
|
2010-04-24 09:58:02 +00:00
|
|
|
$pref = e107::getPref('e_shortcode_list');
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!$pref)
|
2009-09-18 22:20:40 +00:00
|
|
|
{
|
2010-04-24 09:58:02 +00:00
|
|
|
return $this;
|
2009-09-18 22:20:40 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($pref as $key => $val)
|
2009-09-18 22:20:40 +00:00
|
|
|
{
|
2010-04-24 09:58:02 +00:00
|
|
|
$path = e_PLUGIN.$key.'/e_shortcode.php';
|
|
|
|
$classFunc = $key.'_shortcodes';
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!include_once($path))
|
2009-09-18 22:20:40 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-10 23:11:54 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->registerClassMethods($classFunc, $path, false);
|
2012-04-23 01:21:06 +00:00
|
|
|
|
|
|
|
|
2010-02-10 23:11:54 +00:00
|
|
|
}
|
2010-04-24 09:58:02 +00:00
|
|
|
return $this;
|
2010-02-10 23:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common Auto-Register function for class methods.
|
2010-04-25 13:52:14 +00:00
|
|
|
* @return e_parse_shortcode
|
2010-02-10 23:11:54 +00:00
|
|
|
*/
|
2010-04-25 13:52:14 +00:00
|
|
|
protected function registerClassMethods($class, $path, $force = false)
|
2010-02-10 23:11:54 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
$tmp = get_class_methods($class);
|
|
|
|
$className = is_object($class) ? get_class($class) : $class;
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($tmp as $c)
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (strpos($c, 'sc_') === 0)
|
2010-01-23 16:41:56 +00:00
|
|
|
{
|
2010-04-23 15:54:11 +00:00
|
|
|
$sc_func = substr($c, 3);
|
|
|
|
$code = strtoupper($sc_func);
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($force || !$this->isRegistered($code))
|
2009-09-18 22:20:40 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->registered_codes[$code] = array('type' => 'class', 'path' => $path, 'class' => $className);
|
2012-04-23 01:21:06 +00:00
|
|
|
|
|
|
|
if (class_exists($className, false))
|
|
|
|
{
|
|
|
|
$this->scClasses[$className] = new $className(); // Required. Test with e107::getScBatch($className)
|
|
|
|
}
|
2009-09-18 22:20:40 +00:00
|
|
|
}
|
2010-01-23 16:41:56 +00:00
|
|
|
}
|
2010-04-23 15:54:11 +00:00
|
|
|
}
|
2012-04-23 01:21:06 +00:00
|
|
|
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
return $this;
|
2009-09-18 22:20:40 +00:00
|
|
|
}
|
2009-01-08 21:47:44 +00:00
|
|
|
|
2009-09-19 17:43:19 +00:00
|
|
|
/**
|
2010-01-23 16:41:56 +00:00
|
|
|
* Register Core Shortcode Batches.
|
2010-04-25 13:52:14 +00:00
|
|
|
* FIXME - make it smarter - currently loaded all the time (even on front-end)
|
2009-11-17 15:29:33 +00:00
|
|
|
*
|
2010-04-24 11:39:14 +00:00
|
|
|
* @return e_parse_shortcode
|
2009-09-19 17:43:19 +00:00
|
|
|
*/
|
2009-01-08 21:47:44 +00:00
|
|
|
function loadCoreShortcodes()
|
|
|
|
{
|
2010-02-10 23:11:54 +00:00
|
|
|
$coreBatchList = array('admin_shortcodes');
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($coreBatchList as $cb)
|
2009-01-08 21:47:44 +00:00
|
|
|
{
|
2010-02-10 23:11:54 +00:00
|
|
|
$path = e_CORE.'shortcodes/batch/'.$cb.".php";
|
2010-04-25 13:52:14 +00:00
|
|
|
if (include_once($path))
|
2010-02-10 23:11:54 +00:00
|
|
|
{
|
2010-04-24 09:58:02 +00:00
|
|
|
$this->registerClassMethods($cb, $path);
|
2010-02-10 23:11:54 +00:00
|
|
|
}
|
2009-01-08 21:47:44 +00:00
|
|
|
}
|
2010-04-24 11:39:14 +00:00
|
|
|
return $this;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2009-01-08 17:23:13 +00:00
|
|
|
function isRegistered($code)
|
|
|
|
{
|
|
|
|
return in_array($code, $this->registered_codes);
|
|
|
|
}
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2009-12-12 16:40:41 +00:00
|
|
|
public function resetScClass($className, $object)
|
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if(null === $object)
|
|
|
|
{
|
|
|
|
unset($this->scClasses[$className]);
|
|
|
|
}
|
|
|
|
elseif ($this->isScClass($className))
|
2009-12-12 16:40:41 +00:00
|
|
|
{
|
|
|
|
$this->scClasses[$className] = $object;
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
return $this;
|
2009-12-12 16:40:41 +00:00
|
|
|
}
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2009-08-20 16:41:29 +00:00
|
|
|
function isScClass($className)
|
|
|
|
{
|
|
|
|
return isset($this->scClasses[$className]);
|
|
|
|
}
|
2007-06-13 02:53:21 +00:00
|
|
|
|
2009-01-16 01:02:41 +00:00
|
|
|
function isOverride($code)
|
|
|
|
{
|
|
|
|
return in_array($code, $this->scOverride);
|
|
|
|
}
|
|
|
|
|
2011-03-24 21:29:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the shortcodes in some text
|
|
|
|
*
|
|
|
|
* @param string $text - the text containing the shortcodes
|
|
|
|
* @param boolean $useSCFiles - if TRUE, all currently registered shortcodes can be used.
|
|
|
|
* - if FALSE, only those passed are used.
|
|
|
|
* @param array|object|null $extraCodes - if passed, defines additional shortcodes:
|
|
|
|
* - if an object or an array, the shortcodes defined by the class of the object are available for this parsing only.
|
|
|
|
* @param array|null $eVars - if defined, details values to be substituted for shortcodes. Array key (lower case) is shortcode name (upper case)
|
|
|
|
*
|
|
|
|
* @return string with shortcodes substituted
|
|
|
|
*/
|
2010-04-25 15:04:53 +00:00
|
|
|
function parseCodes($text, $useSCFiles = true, $extraCodes = null, $eVars = null)
|
2008-02-13 02:57:17 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
$saveParseSCFiles = $this->parseSCFiles; // In case of nested call
|
2006-12-02 04:36:16 +00:00
|
|
|
$this->parseSCFiles = $useSCFiles;
|
2010-04-25 13:52:14 +00:00
|
|
|
$saveVars = $this->eVars; // In case of nested call
|
2011-03-24 21:29:45 +00:00
|
|
|
$saveCodes = $this->addedCodes;
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->eVars = $eVars;
|
2011-03-24 21:29:45 +00:00
|
|
|
$this->addedCodes = NULL;
|
2010-01-23 16:41:56 +00:00
|
|
|
|
2009-08-20 16:41:29 +00:00
|
|
|
//object support
|
2010-04-25 13:52:14 +00:00
|
|
|
if (is_object($extraCodes))
|
2009-08-20 16:41:29 +00:00
|
|
|
{
|
2011-03-24 21:29:45 +00:00
|
|
|
$this->addedCodes = &$extraCodes;
|
|
|
|
/*
|
2009-09-25 20:15:19 +00:00
|
|
|
$classname = get_class($extraCodes);
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2009-09-25 20:15:19 +00:00
|
|
|
//register once
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!$this->isScClass($classname))
|
2009-09-25 20:15:19 +00:00
|
|
|
{
|
2011-03-24 21:29:45 +00:00
|
|
|
$this->registerShortcode($extraCodes, true); // Register class if not already registered
|
2009-09-25 20:15:19 +00:00
|
|
|
}
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2009-09-25 20:15:19 +00:00
|
|
|
//always overwrite object
|
|
|
|
$this->scClasses[$classname] = $extraCodes;
|
2011-03-24 21:29:45 +00:00
|
|
|
*/
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
// auto-register eVars if possible - call it manually?
|
2010-04-25 15:04:53 +00:00
|
|
|
// $this->callScFunc($classname, 'setParserVars', $this->eVars);
|
2009-08-20 16:41:29 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
elseif (is_array($extraCodes))
|
2008-02-13 02:57:17 +00:00
|
|
|
{
|
2011-03-24 21:29:45 +00:00
|
|
|
$this->addedCodes = &$extraCodes;
|
|
|
|
/*
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($extraCodes as $sc => $code)
|
2008-02-13 02:57:17 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$this->scList[$sc] = $code;
|
|
|
|
}
|
2011-03-24 21:29:45 +00:00
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-02-13 02:57:17 +00:00
|
|
|
$ret = preg_replace_callback('#\{(\S[^\x02]*?\S)\}#', array(&$this, 'doCode'), $text);
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->parseSCFiles = $saveParseSCFiles; // Restore previous value
|
2011-03-24 21:29:45 +00:00
|
|
|
$this->addedCodes = $saveCodes;
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->eVars = $saveVars; // restore eVars
|
2006-12-02 04:36:16 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2011-03-24 21:29:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback looks up and substitutes a shortcode
|
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
function doCode($matches)
|
|
|
|
{
|
2009-01-08 17:23:13 +00:00
|
|
|
global $pref, $e107cache, $menu_pref, $sc_style, $parm, $sql;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($this->eVars)
|
|
|
|
{
|
|
|
|
if ($this->eVars->isVar($matches[1]))
|
|
|
|
{
|
2010-01-23 16:41:56 +00:00
|
|
|
return $this->eVars->$matches[1];
|
|
|
|
}
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
if (strpos($matches[1], E_NL) !== false)
|
|
|
|
{
|
|
|
|
return $matches[0];
|
|
|
|
}
|
2007-03-30 13:33:29 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
if (strpos($matches[1], '='))
|
|
|
|
{
|
2009-01-08 17:23:13 +00:00
|
|
|
list($code, $parm) = explode('=', $matches[1], 2);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$code = $matches[1];
|
|
|
|
$parm = '';
|
|
|
|
}
|
2007-03-30 13:33:29 +00:00
|
|
|
//look for the $sc_mode
|
2007-06-13 02:53:21 +00:00
|
|
|
if (strpos($code, '|'))
|
|
|
|
{
|
2007-03-30 13:33:29 +00:00
|
|
|
list($code, $sc_mode) = explode("|", $code, 2);
|
|
|
|
$code = trim($code);
|
|
|
|
$sc_mode = trim($sc_mode);
|
2007-06-13 02:53:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-30 13:33:29 +00:00
|
|
|
$sc_mode = '';
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
$parm = trim($parm);
|
2008-02-19 19:33:45 +00:00
|
|
|
$parm = str_replace(array('[[', ']]'), array('{', '}'), $parm);
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-09-10 01:00:36 +00:00
|
|
|
if (E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
global $db_debug;
|
2006-12-05 09:15:08 +00:00
|
|
|
$sql->db_Mark_Time("SC $code");
|
2006-12-02 04:36:16 +00:00
|
|
|
$db_debug->logCode(2, $code, $parm, "");
|
|
|
|
}
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if (E107_DBG_SC)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2009-07-12 02:29:24 +00:00
|
|
|
echo "<strong>";
|
2010-04-25 13:52:14 +00:00
|
|
|
echo '{';
|
2009-07-12 02:29:24 +00:00
|
|
|
echo $code;
|
2010-04-25 13:52:14 +00:00
|
|
|
echo($parm) ? '='.htmlentities($parm) : "";
|
2009-07-12 02:29:24 +00:00
|
|
|
echo '}';
|
|
|
|
echo "</strong>";
|
2010-04-25 13:52:14 +00:00
|
|
|
// trigger_error('starting shortcode {'.$code.'}', E_USER_ERROR); // no longer useful - use ?[debug=bbsc]
|
|
|
|
}
|
2009-01-08 17:23:13 +00:00
|
|
|
|
|
|
|
$scCode = '';
|
|
|
|
$scFile = '';
|
2011-03-24 21:29:45 +00:00
|
|
|
$ret = '';
|
|
|
|
$_method = 'sc_'.strtolower($code);
|
|
|
|
if (is_object($this->addedCodes) && method_exists($this->addedCodes, $_method))
|
|
|
|
{
|
|
|
|
//It is class-based batch shortcode. Class already loaded; call the method
|
|
|
|
$ret = $this->addedCodes->$_method($parm, $sc_mode);
|
|
|
|
}
|
|
|
|
elseif (is_array($this->addedCodes) && array_key_exists($code, $this->addedCodes))
|
|
|
|
{
|
|
|
|
// Its array-based shortcode. Load the code for evaluation later.
|
|
|
|
$scCode = $this->addedCodes[$code];
|
|
|
|
}
|
2009-01-08 17:23:13 +00:00
|
|
|
// Check to see if we've already loaded the .sc file contents
|
2011-03-24 21:29:45 +00:00
|
|
|
elseif (array_key_exists($code, $this->scList))
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
|
|
|
$scCode = $this->scList[$code];
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-08 17:23:13 +00:00
|
|
|
//.sc file not yet loaded, or shortcode is new function type
|
|
|
|
if ($this->parseSCFiles == true)
|
2007-06-13 02:53:21 +00:00
|
|
|
{
|
2009-01-08 17:23:13 +00:00
|
|
|
if (array_key_exists($code, $this->registered_codes))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2009-01-08 20:16:47 +00:00
|
|
|
//shortcode is registered, let's proceed.
|
2010-04-25 13:52:14 +00:00
|
|
|
if (isset($this->registered_codes[$code]['perms']))
|
2009-01-08 20:16:47 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!check_class($this->registered_codes[$code]['perms']))
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
2009-01-08 20:16:47 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
switch ($this->registered_codes[$code]['type'])
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2009-01-08 17:23:13 +00:00
|
|
|
case 'class':
|
2009-01-08 20:16:47 +00:00
|
|
|
//It is batch shortcode. Load the class and call the method
|
2009-01-08 17:23:13 +00:00
|
|
|
$_class = $this->registered_codes[$code]['class'];
|
2009-07-21 06:31:23 +00:00
|
|
|
$_method = 'sc_'.strtolower($code);
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!$this->isScClass($_class))
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!class_exists($_class) && $this->registered_codes[$code]['path'])
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
2009-01-09 01:12:18 +00:00
|
|
|
include_once($this->registered_codes[$code]['path']);
|
2009-01-08 17:23:13 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
$this->initShortcodeClass($_class, false);
|
|
|
|
if(!$this->isScClass($_class))
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
// egister passed eVars object on init - call it manually?
|
2012-04-24 11:22:07 +00:00
|
|
|
// $this->callScFunc($_class, 'setVars', $this->var);
|
2009-01-08 17:23:13 +00:00
|
|
|
}
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
// FIXME - register passed eVars object - BAD solution - called on EVERY sc method call
|
|
|
|
// XXX - removal candidate - I really think it should be done manually (outside the parser)
|
2010-04-25 15:04:53 +00:00
|
|
|
// via e107::getScBatch(name)->setParserVars($eVars);
|
|
|
|
// $this->callScFunc($_class, 'setParserVars', $this->eVars);
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
$ret = $this->callScFuncA($_class, $_method, array($parm, $sc_mode));
|
|
|
|
/*if (method_exists($this->scClasses[$_class], $_method))
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
2009-01-15 20:18:46 +00:00
|
|
|
$ret = $this->scClasses[$_class]->$_method($parm, $sc_mode);
|
2009-01-08 17:23:13 +00:00
|
|
|
}
|
2009-01-25 17:44:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
echo $_class.'::'.$_method.' NOT FOUND!<br />';
|
2010-04-25 13:52:14 +00:00
|
|
|
}*/
|
2010-02-10 21:53:56 +00:00
|
|
|
|
2009-01-08 17:23:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'func':
|
|
|
|
//It is a function, so include the file and call the function
|
|
|
|
$_function = $this->registered_codes[$code]['function'];
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($this->registered_codes[$code]['path'])
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
|
|
|
include_once($this->registered_codes[$code]['path'].strtolower($code).'.php');
|
2009-11-23 10:27:43 +00:00
|
|
|
|
2009-01-08 17:23:13 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
if (function_exists($_function))
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
2009-01-15 20:18:46 +00:00
|
|
|
$ret = call_user_func($_function, $parm, $sc_mode);
|
2009-01-08 17:23:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'plugin':
|
2007-06-13 02:53:21 +00:00
|
|
|
$scFile = e_PLUGIN.strtolower($this->registered_codes[$code]['path']).'/'.strtolower($code).'.sc';
|
2009-01-08 17:23:13 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-16 01:02:41 +00:00
|
|
|
case 'override':
|
2010-02-10 22:18:57 +00:00
|
|
|
$scFile = e_CORE.'override/shortcodes/'.strtolower($code).'.sc';
|
2009-01-16 01:02:41 +00:00
|
|
|
break;
|
|
|
|
|
2009-01-08 17:23:13 +00:00
|
|
|
case 'theme':
|
|
|
|
$scFile = THEME.strtolower($code).'.sc';
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2008-03-02 21:08:31 +00:00
|
|
|
}
|
2009-01-08 17:23:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Code is not registered, let's look for .sc or .php file
|
|
|
|
// .php file takes precedence over .sc file
|
2010-04-25 13:52:14 +00:00
|
|
|
if (is_readable(e_CORE.'shortcodes/single/'.strtolower($code).'.php'))
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
|
|
|
$_function = strtolower($code).'_shortcode';
|
2009-11-23 10:27:43 +00:00
|
|
|
$_class = strtolower($code);
|
2010-02-10 21:53:56 +00:00
|
|
|
|
|
|
|
include_once(e_CORE.'shortcodes/single/'.strtolower($code).'.php');
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if (class_exists($_class, false)) // prevent __autoload - performance
|
2010-04-26 15:05:59 +00:00
|
|
|
|
2009-11-23 10:27:43 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
$ret = call_user_func(array($_class, $_function), $parm);
|
2009-11-23 10:27:43 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
elseif (function_exists($_function))
|
2007-06-13 02:53:21 +00:00
|
|
|
{
|
2009-01-08 17:23:13 +00:00
|
|
|
$ret = call_user_func($_function, $parm);
|
2007-06-13 02:53:21 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-10 21:53:56 +00:00
|
|
|
$scFile = e_CORE.'shortcodes/single/'.strtolower($code).'.sc';
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-08 17:23:13 +00:00
|
|
|
if ($scFile && file_exists($scFile))
|
|
|
|
{
|
|
|
|
$scCode = file_get_contents($scFile);
|
|
|
|
$this->scList[$code] = $scCode;
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-02-13 02:57:17 +00:00
|
|
|
|
2009-01-08 17:23:13 +00:00
|
|
|
if (!isset($scCode))
|
2007-06-13 02:53:21 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (E107_DBG_BBSC)
|
|
|
|
{
|
|
|
|
trigger_error('shortcode not found:{'.$code.'}', E_USER_ERROR);
|
|
|
|
}
|
2008-02-13 02:57:17 +00:00
|
|
|
return $matches[0];
|
2007-06-13 02:53:21 +00:00
|
|
|
}
|
2007-03-05 21:24:47 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if (E107_DBG_SC && $scFile)
|
2007-06-13 02:53:21 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
// echo (isset($scFile)) ? "<br />sc_file= ".str_replace(e_CORE.'shortcodes/single/', '', $scFile).'<br />' : '';
|
|
|
|
// echo "<br />sc= <b>$code</b>";
|
2011-03-24 21:29:45 +00:00
|
|
|
}
|
2009-01-08 17:23:13 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($scCode)
|
2009-01-08 17:23:13 +00:00
|
|
|
{
|
|
|
|
$ret = eval($scCode);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if (isset($ret) && ($ret != '' || is_numeric($ret)))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-03-30 13:33:29 +00:00
|
|
|
//if $sc_mode exists, we need it to parse $sc_style
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($sc_mode)
|
2008-02-13 02:57:17 +00:00
|
|
|
{
|
2009-01-08 17:23:13 +00:00
|
|
|
$code = $code.'|'.$sc_mode;
|
2007-03-30 13:33:29 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
if (isset($sc_style) && is_array($sc_style) && array_key_exists($code, $sc_style))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (isset($sc_style[$code]['pre']))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
$ret = $sc_style[$code]['pre'].$ret;
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
if (isset($sc_style[$code]['post']))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
$ret = $ret.$sc_style[$code]['post'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-10 01:00:36 +00:00
|
|
|
if (E107_DBG_SC || E107_DBG_TIMEDETAILS)
|
2008-02-13 02:57:17 +00:00
|
|
|
{
|
2010-09-10 01:00:36 +00:00
|
|
|
$sql->db_Mark_Time("(After SC {$code})");
|
2006-12-05 09:15:08 +00:00
|
|
|
}
|
2009-12-17 22:47:20 +00:00
|
|
|
return isset($ret) ? $ret : '';
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2006-12-03 07:03:22 +00:00
|
|
|
function parse_scbatch($fname, $type = 'file')
|
|
|
|
{
|
|
|
|
global $e107cache, $eArrayStorage;
|
2006-12-05 09:15:08 +00:00
|
|
|
$cur_shortcodes = array();
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($type == 'file')
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2009-01-08 17:23:13 +00:00
|
|
|
$batch_cachefile = 'nomd5_scbatch_'.md5($fname);
|
2008-02-13 02:57:17 +00:00
|
|
|
// $cache_filename = $e107cache->cache_fname("nomd5_{$batchfile_md5}");
|
2007-02-04 17:36:16 +00:00
|
|
|
$sc_cache = $e107cache->retrieve_sys($batch_cachefile);
|
2010-04-25 13:52:14 +00:00
|
|
|
if (!$sc_cache)
|
2006-12-03 07:03:22 +00:00
|
|
|
{
|
|
|
|
$sc_batch = file($fname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cur_shortcodes = $eArrayStorage->ReadArray($sc_cache);
|
|
|
|
$sc_batch = "";
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sc_batch = $fname;
|
|
|
|
}
|
2006-12-03 07:03:22 +00:00
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($sc_batch)
|
2006-12-03 07:03:22 +00:00
|
|
|
{
|
2006-12-05 09:15:08 +00:00
|
|
|
$cur_sc = '';
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach ($sc_batch as $line)
|
2006-12-03 07:03:22 +00:00
|
|
|
{
|
|
|
|
if (trim($line) == 'SC_END')
|
|
|
|
{
|
|
|
|
$cur_sc = '';
|
|
|
|
}
|
|
|
|
if ($cur_sc)
|
|
|
|
{
|
|
|
|
$cur_shortcodes[$cur_sc] .= $line;
|
|
|
|
}
|
2009-08-20 16:41:29 +00:00
|
|
|
if (preg_match('#^SC_BEGIN (\w*).*#', $line, $matches))
|
2006-12-03 07:03:22 +00:00
|
|
|
{
|
|
|
|
$cur_sc = $matches[1];
|
2010-04-25 13:52:14 +00:00
|
|
|
$cur_shortcodes[$cur_sc] = varset($cur_shortcodes[$cur_sc], '');
|
2006-12-03 07:03:22 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($type == 'file')
|
2006-12-03 07:03:22 +00:00
|
|
|
{
|
|
|
|
$sc_cache = $eArrayStorage->WriteArray($cur_shortcodes, false);
|
2007-02-04 17:36:16 +00:00
|
|
|
$e107cache->set_sys($batch_cachefile, $sc_cache);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2006-12-03 07:03:22 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 13:52:14 +00:00
|
|
|
foreach (array_keys($cur_shortcodes) as $cur_sc)
|
2006-12-03 07:03:22 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if (array_key_exists($cur_sc, $this->registered_codes))
|
2008-02-13 02:57:17 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
if ($this->registered_codes[$cur_sc]['type'] == 'plugin')
|
2008-02-13 02:57:17 +00:00
|
|
|
{
|
2010-04-25 13:52:14 +00:00
|
|
|
$scFile = e_PLUGIN.strtolower($this->registered_codes[$cur_sc]['path']).'/'.strtolower($cur_sc).'.sc';
|
2008-02-13 02:57:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-12-03 07:03:22 +00:00
|
|
|
$scFile = THEME.strtolower($cur_sc).'.sc';
|
|
|
|
}
|
2008-02-13 02:57:17 +00:00
|
|
|
if (is_readable($scFile))
|
|
|
|
{
|
2006-12-03 07:03:22 +00:00
|
|
|
$cur_shortcodes[$cur_sc] = file_get_contents($scFile);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-03 07:03:22 +00:00
|
|
|
return $cur_shortcodes;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-23 15:54:11 +00:00
|
|
|
|
|
|
|
class e_shortcode
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Stores passed to shortcode handler simple parser object
|
|
|
|
* @var e_vars
|
|
|
|
*/
|
2012-04-24 11:22:07 +00:00
|
|
|
protected $var = null; // value returned by each shortcode.
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
/**
|
2010-04-24 11:39:14 +00:00
|
|
|
* Storage for shortcode values
|
2010-04-23 15:54:11 +00:00
|
|
|
* @var e_vars
|
|
|
|
*/
|
|
|
|
protected $scVars = null;
|
2010-04-25 13:52:14 +00:00
|
|
|
|
|
|
|
public function __construct()
|
2010-04-23 15:54:11 +00:00
|
|
|
{
|
|
|
|
$this->scVars = new e_vars();
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-24 11:39:14 +00:00
|
|
|
/**
|
|
|
|
* Set external simple parser object
|
2010-04-25 13:52:14 +00:00
|
|
|
*
|
2010-04-24 11:39:14 +00:00
|
|
|
* @param e_vars $eVars
|
|
|
|
* @return e_shortcode
|
|
|
|
*/
|
2010-04-25 15:04:53 +00:00
|
|
|
public function setParserVars($eVars)
|
2010-04-24 11:39:14 +00:00
|
|
|
{
|
2012-04-24 11:22:07 +00:00
|
|
|
$this->var = $eVars;
|
2010-04-24 11:39:14 +00:00
|
|
|
return $this;
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-24 11:39:14 +00:00
|
|
|
/**
|
|
|
|
* Get external simple parser object
|
2010-04-25 13:52:14 +00:00
|
|
|
*
|
2010-04-24 11:39:14 +00:00
|
|
|
* @return e_vars
|
|
|
|
*/
|
2010-04-25 15:04:53 +00:00
|
|
|
public function getParserVars()
|
2010-04-24 11:39:14 +00:00
|
|
|
{
|
2012-04-24 11:22:07 +00:00
|
|
|
if(null === $this->var) $this->var = new e_vars();
|
|
|
|
return $this->var;
|
2010-04-24 11:39:14 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
/**
|
|
|
|
* Add shortcode value
|
2010-12-07 13:30:22 +00:00
|
|
|
* <code>e107::getScBatch('class_name')->setScVar('some_property', $some_value);</code>
|
2010-04-23 15:54:11 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
2010-04-24 11:39:14 +00:00
|
|
|
* @return e_shortcode
|
2010-04-23 15:54:11 +00:00
|
|
|
*/
|
|
|
|
public function setScVar($name, $value)
|
|
|
|
{
|
|
|
|
$this->scVars->$name = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
2010-12-07 13:30:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add shortcode values
|
|
|
|
* <code>e107::getScBatch('class_name')->addScVars(array('some_property', $some_value));</code>
|
|
|
|
*
|
|
|
|
* @param array $vars
|
|
|
|
* @return e_shortcode
|
|
|
|
*/
|
|
|
|
public function addScVars($vars)
|
|
|
|
{
|
|
|
|
$this->scVars->addVars($vars);
|
|
|
|
return $this;
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-23 15:54:11 +00:00
|
|
|
/**
|
|
|
|
* Retrieve shortcode value
|
2010-12-07 13:30:22 +00:00
|
|
|
* <code>$some_value = e107::getScBatch('class_name')->getScVar('some_property');</code>
|
2010-04-23 15:54:11 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getScVar($name)
|
|
|
|
{
|
|
|
|
return $this->scVars->$name;
|
|
|
|
}
|
2010-12-07 13:30:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve all shortcode values
|
|
|
|
* <code>$some_value = e107::getScBatch('class_name')->getScVars();</code>
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getScVars()
|
|
|
|
{
|
|
|
|
return $this->scVars->getVars();
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-24 11:39:14 +00:00
|
|
|
/**
|
|
|
|
* Check if shortcode variable is set
|
2010-12-07 13:30:22 +00:00
|
|
|
* <code>if(e107::getScBatch('class_name')->issetScVar('some_property'))
|
2010-04-25 13:52:14 +00:00
|
|
|
* {
|
2010-04-24 11:39:14 +00:00
|
|
|
* //do something
|
|
|
|
* }</code>
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function issetScVar($name)
|
|
|
|
{
|
|
|
|
return isset($this->scVars->$name);
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-24 11:39:14 +00:00
|
|
|
/**
|
|
|
|
* Unset shortcode value
|
2010-12-07 13:30:22 +00:00
|
|
|
* <code>e107::getScBatch('class_name')->unsetScVar('some_property');</code>
|
2010-04-24 11:39:14 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
2010-12-07 13:30:22 +00:00
|
|
|
* @return e_shortcode
|
2010-04-24 11:39:14 +00:00
|
|
|
*/
|
|
|
|
public function unsetScVar($name)
|
|
|
|
{
|
|
|
|
$this->scVars->$name = null;
|
2010-04-25 13:52:14 +00:00
|
|
|
unset($this->scVars->$name);
|
2010-12-07 13:30:22 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty scvar object data
|
|
|
|
* @return e_shortcode
|
|
|
|
*/
|
|
|
|
public function emptyScVars()
|
|
|
|
{
|
|
|
|
$this->scVars->emptyVars();
|
|
|
|
return $this;
|
2010-04-24 11:39:14 +00:00
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-24 11:39:14 +00:00
|
|
|
/**
|
|
|
|
* Magic setter - bind to eVars object
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
|
|
|
public function __set($name, $value)
|
|
|
|
{
|
|
|
|
$this->setScVar($name, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Magic getter - bind to eVars object
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return mixed value or null if key not found
|
|
|
|
*/
|
|
|
|
public function __get($name)
|
|
|
|
{
|
|
|
|
return $this->getScVar($name);
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-24 11:39:14 +00:00
|
|
|
/**
|
|
|
|
* Magic method - bind to eVars object
|
|
|
|
* NOTE: works on PHP 5.1.0+
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function __isset($name)
|
|
|
|
{
|
|
|
|
return $this->issetScVar($name);
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
|
2010-04-24 11:39:14 +00:00
|
|
|
/**
|
|
|
|
* Magic method - bind to eVars object
|
|
|
|
* NOTE: works on PHP 5.1.0+
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
*/
|
|
|
|
public function __unset($name)
|
|
|
|
{
|
|
|
|
$this->unsetScVar($name);
|
|
|
|
}
|
2010-04-25 13:52:14 +00:00
|
|
|
}
|