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
*/
2016-05-01 09:30:33 -07:00
/**
* @ deprecated
* @ param $classFunc
* @ param $codes
* @ param string $path
* @ param bool $force
* @ return e_parse_shortcode
*/
function register_shortcode ( $classFunc , $codes , $path = '' , $force = false )
{
return e107 :: getScParser () -> registerShortcode ( $classFunc , $codes , $path , $force );
}
2006-12-02 04:36:16 +00:00
2010-04-25 13:52:14 +00:00
/**
2016-05-01 09:30:33 -07:00
* @ deprecated
* @ param $className
* @ param $scVarName
* @ param $value
* @ return e_parse_shortcode
2010-04-25 13:52:14 +00:00
*/
2016-05-01 09:30:33 -07:00
function setScVar ( $className , $scVarName , $value )
{
return e107 :: getScParser () -> setScVar ( $className , $scVarName , $value );
}
2013-04-28 19:14:14 +03:00
/**
2016-05-01 09:30:33 -07:00
* @ deprecated FIXME : to be removed ( once event calendar changed )
* @ param $className
* @ param $scFuncName
* @ param string $param
* @ return bool | mixed
2013-04-28 19:14:14 +03:00
*/
2016-05-01 09:30:33 -07:00
function callScFunc ( $className , $scFuncName , $param = '' )
{
return e107 :: getScParser () -> callScFunc ( $className , $scFuncName , $param );
}
2013-04-28 19:14:14 +03:00
/**
2016-05-01 09:30:33 -07:00
* @ deprecated FIXME : to be removed
* @ param $class
* @ param bool $force
* @ param null $eVars
* @ return e_shortcode
2013-04-28 19:14:14 +03:00
*/
2016-05-01 09:30:33 -07:00
function initShortcodeClass ( $class , $force = false , $eVars = null )
{
return e107 :: getScParser () -> initShortcodeClass ( $class , $eVars , $force );
}
class e_parse_shortcode
{
protected $scList = array (); // The actual code - added by parsing files or when plugin codes encountered. Array key is the shortcode name.
protected $parseSCFiles = true ; // True if individual shortcode files are to be used
protected $addedCodes = null ; // Pointer to a class or array to be used on a single call
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/shortcodes dir
protected $scBatchOverride = array (); // Array of codes found in override/shortcodes/batch dir
protected $ignoreCodes = array (); // Shortcodes to be ignored and remain unchanged. (ie. {THEME}, {e_PLUGIN} etc. )
protected $addonOverride = array (); // Overrides coming from e_shortcode.php
private $legacyBatch = array (); // List of legacy batch file codes. eg. using SC_BEGIN etc.
2016-05-03 15:52:02 -07:00
private $legacyBatchFile = null ;
2016-05-01 09:30:33 -07:00
private $debug_legacy = array ();
protected $eVars = null ;
protected $wrappers = array (); // Wrappers array for the current parsing cycle, see contact_template.php and $CONTACT_WRAPPER variable
protected $wrapper = null ; // current wrapper being processed.
protected $wrapperDebugDone = array (); // Flag to avoid repetition of debug info.
protected $sc_style = array (); // Former $sc_style global variable. Internally used - performance reasons
2016-05-28 19:03:08 -07:00
protected $editableCodes = array (); // Array of editable shortcode data.
2016-06-09 16:44:40 -07:00
protected $editableActive = false ;
2016-12-10 16:38:39 -08:00
protected $nowrap = false ;
2010-04-23 15:54:11 +00:00
function __construct ()
2006-12-02 04:36:16 +00:00
{
2016-05-28 19:03:08 -07:00
// $_SESSION['editable'] = array();
2016-05-01 09:30:33 -07:00
$this -> ignoreCodes = e107 :: getParser () -> getUrlConstants (); // ignore all URL shortcodes. ie. {e_PLUGIN}
2017-01-23 10:33:00 -08:00
if ( e_ADMIN_AREA !== true )
{
$this -> loadOverrideShortcodes ();
$this -> loadThemeShortcodes ();
}
2017-01-29 09:29:30 -08:00
$this -> loadPluginShortcodes ();
$this -> loadPluginSCFiles ();
2013-02-08 16:49:57 +02:00
//$this->loadCoreShortcodes(); DEPRECATED
2012-04-23 01:21:06 +00:00
2016-06-09 16:44:40 -07:00
$editableActivePref = e107 :: getPref ( 'inline_editing' , 255 );
if ( check_class ( $editableActivePref ))
{
$this -> editableActive = true ;
}
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 );
2016-04-22 11:54:18 -07:00
if (( ! $this -> isRegistered ( $codes ) || $force == true ) && ! $this -> isOverride ( $codes ))
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
2016-05-01 09:30:33 -07: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
2016-05-01 09:30:33 -07:00
* @ param array $args
* @ return bool | mixed - NULL if class / method doesn ' t exist ; otherwise whatever the function returns .
* @ internal param array $param - arguments passed to function
2010-04-25 13:52:14 +00:00
*
*/
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 ;
}
2016-05-01 09:30:33 -07:00
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 ();
2016-04-22 11:54:18 -07:00
2012-08-23 11:42:54 +00:00
if ( method_exists ( $this -> scClasses [ $class ], 'init' ))
{
$this -> scClasses [ $class ] -> init ();
}
2016-04-22 11:54:18 -07:00
if ( ! empty ( $this -> scClasses [ $class ] -> override ))
{
$methods = get_class_methods ( $class );
foreach ( $methods as $meth )
{
if ( substr ( $meth , 0 , 3 ) == 'sc_' )
{
$this -> addonOverride [ $meth ] = $class ;
}
}
}
2010-04-23 15:54:11 +00:00
return $this -> scClasses [ $class ];
}
2016-04-22 11:54:18 -07:00
2010-04-23 15:54:11 +00:00
return null ;
}
2010-04-25 13:52:14 +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 ()
2013-02-09 19:05:51 +02:00
* Global File Override ClassName / Path examples :
* 1. Core signup shortcodes
2016-05-01 09:30:33 -07:00
* - Origin ClassName : signup_shortcodes
* - Origin Location : core / shortcodes / batch / signup_shortcodes . php
* - File Override ClassName : override_signup_shortcodes
* - File Override Location : core / override / shortcodes / batch / signup_shortcodes . php
*
* 2. Plugin 'gallery' global shortcode batch ( e_shortcode . php )
* - Origin ClassName : gallery_shortcodes //FIXME Should be gallery_shortcode? (more below)
* - Origin Location : plugins / gallery / e_shortcode . php
* - File Override ClassName : override_gallery_shortcodes
* - File Override Location : core / override / shortcodes / batch / gallery_shortcodes . php
*
2013-02-09 19:05:51 +02:00
* 3. Plugin 'forum' regular shortcode batch
2016-05-01 09:30:33 -07:00
* - Origin ClassName : plugin_forum_view_shortcodes //FIXME Should be forum_shortcodes? (more below)
* - Origin Location : plugins / forum / shortcodes / batch / view_shortcodes . php
* - File Override ClassName : override_plugin_forum_view_shortcodes
* - File Override Location : core / override / shortcodes / batch / forum_view_shortcodes . php
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
2016-05-01 09:30:33 -07:00
* @ param null $pluginName
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
2016-05-01 09:30:33 -07:00
* @ internal param string $plugName if true className is used . , if string , string value is used .
2010-04-23 15:54:11 +00:00
*/
2010-04-25 13:52:14 +00:00
public function getScObject ( $className , $pluginName = null , $overrideClass = null )
2010-04-23 15:54:11 +00:00
{
2013-02-22 21:30:14 -08:00
/* FIXME Discuss Generic plugin Class naming . ( excluding specific calls with $overrideClass .
// Defaults should be:
e_shortcode . php = { plugin } _shortcode
{ plugin } _shortcodes . php = { plugin } _shortcodes
*/
2016-05-01 09:30:33 -07:00
$path = null ;
2013-02-22 21:30:14 -08:00
2016-05-01 09:30:33 -07:00
if ( trim ( $className ) == " " ){ return null ; }
2013-02-09 19:05:51 +02:00
2010-04-26 15:05:59 +00:00
$_class_fname = $className ;
2013-02-22 21:30:14 -08:00
if ( $pluginName === TRUE ) //XXX When called manually by a plugin, not e_shortcode.php eg. $sc = e107::getScBatch('faqs',TRUE); for faqs_shortcode.php with class faqs_shortcode
2013-02-09 19:05:51 +02:00
{
2013-02-22 21:30:14 -08:00
$pluginName = str_replace ( " _shortcodes " , " " , $className );
$manualCall = true ;
2013-02-09 19:05:51 +02:00
}
elseif ( is_string ( $pluginName ))
2013-02-08 16:49:57 +02:00
{
2013-02-22 21:30:14 -08:00
// FIXME "plugin_ " should NOT be used or be necessary.
// FIXME Core classes should use special naming to avoid comflicts, not plugins.
$className = 'plugin_' . $pluginName . '_' . str_replace ( '/' , '_' , $className );
2013-02-08 16:49:57 +02:00
}
2013-02-11 15:12:30 +02:00
$globalOverride = $this -> isBatchOverride ( str_replace ( 'plugin_' , '' , $className ));
2013-02-08 16:49:57 +02:00
// forced override
2010-04-25 13:52:14 +00:00
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
2013-02-01 17:35:56 -08:00
if ( $pluginName != null )
{
$_class_fname = $overrideClass ;
$className = 'plugin_' . $pluginName . '_' . str_replace ( '/' , '_' , $overrideClass );
}
else
{
$className = $overrideClass ;
}
2010-04-25 13:52:14 +00:00
}
2012-11-02 00:23:59 +00:00
2013-06-19 22:50:51 -07:00
if ( $className == '_theme__shortcodes' ) // Check for theme shortcode batch. - @see header_default.php //XXX Discuss.
{
$className = 'theme_shortcodes' ;
$path = THEME . 'theme_shortcodes.php' ;
}
elseif ( ! $pluginName )
2012-11-02 00:23:59 +00:00
{
2013-02-09 19:05:51 +02:00
if ( ! $globalOverride )
{
$path = e_CORE . 'shortcodes/batch/' . $_class_fname . '.php' ;
}
else
{
$path = e_CORE . 'override/shortcodes/batch/' . $_class_fname . '.php' ;
$className = 'override_' . $className ;
}
2013-02-08 16:49:57 +02:00
}
else
{
2013-02-22 21:30:14 -08:00
2013-02-09 19:05:51 +02:00
if ( ! $globalOverride )
2013-02-22 21:30:14 -08:00
{
2013-02-09 19:05:51 +02:00
// do nothing if it's e_shortcode batch global
2013-02-22 21:30:14 -08:00
if ( $pluginName . '_shortcodes' !== $className || $manualCall == true ) // manual call by plugin, not e_shortcode.php
{
2013-02-09 19:05:51 +02:00
// BC - required.
$pathBC = e_PLUGIN . $pluginName . '/' ;
$path = ( is_readable ( $pathBC . $_class_fname . '.php' ) ? $pathBC : e_PLUGIN . $pluginName . '/shortcodes/batch/' ) . $_class_fname . '.php' ;
}
}
else
{
2013-02-11 15:12:30 +02:00
$path = e_CORE . 'override/shortcodes/batch/' . $pluginName . '_' . $_class_fname . '.php' ;
2013-02-09 19:05:51 +02:00
$className = 'override_' . $className ;
}
}
2013-06-19 22:50:51 -07:00
2013-02-09 19:05:51 +02:00
// Includes global Shortcode Classes (e_shortcode.php) or already loaded batch
if ( $this -> isScClass ( $className ))
{
return $this -> scClasses [ $className ];
2013-02-08 16:49:57 +02:00
}
2012-04-23 01:21:06 +00:00
2012-12-11 15:08:29 -08:00
// If it already exists - don't include it again.
if ( class_exists ( $className , false )) // don't allow __autoload()
{
2013-05-31 18:40:56 -07:00
// $this->registerClassMethods($className, $path); // XXX Global registration should happen separately - here we want only the object.
2013-06-19 22:50:51 -07:00
$this -> scClasses [ $className ] = new $className ();
2012-12-11 15:08:29 -08:00
return $this -> scClasses [ $className ];
}
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
2013-06-19 22:50:51 -07:00
$this -> scClasses [ $className ] = new $className ();
2013-06-01 14:08:42 -07:00
// $this->registerClassMethods($className, $path); // XXX Global registration should happen separately - here we want only the object.
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 )
{
2016-04-27 14:37:43 -07:00
// echo "<h3>Couldn't Find Class '".$className."' in <b>".$path."</b></h3>";
echo " <div class='alert alert-danger'>Couldn't Load: <b> " . $path . " </b> with class-name:<b> { $className } </b> and pluginName <b> { $pluginName } </b></div> " ;
2012-04-23 01:21:06 +00:00
}
}
2016-04-28 13:17:36 -07:00
elseif ( E107_DBG_INCLUDES )
{
// echo "<h3>Couldn't Find Class '".$className."' in <b>".$path."</b></h3>";
}
2016-12-10 16:38:39 -08:00
// e107::getDebug()->log( "<div class='alert alert-danger'>Couldn't Load: <b>".$path."</b> with class-name:<b> {$className}</b> and pluginName <b>{$pluginName}</b></div>");
2016-04-27 14:37:43 -07:00
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' ;
2013-02-08 16:49:57 +02:00
$this -> registered_codes [ $code ][ 'path' ] = e_CORE . 'override/shortcodes/single/' ;
$this -> registered_codes [ $code ][ 'function' ] = 'override_' . strtolower ( $code ) . '_shortcode' ;
2009-01-16 01:02:41 +00:00
$this -> scOverride [] = $code ;
}
2010-01-23 16:41:56 +00:00
}
2013-02-08 16:49:57 +02:00
if ( e107 :: getPref ( 'sc_batch_override' ))
{
$tmp = explode ( ',' , e107 :: getPref ( 'sc_batch_override' ));
foreach ( $tmp as $code )
{
//$code = strtoupper(trim($code));
//$this->registered_codes[$code]['type'] = 'override';
$this -> scBatchOverride [] = $code ;
}
}
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
*/
2016-05-28 19:03:08 -07:00
public function loadThemeShortcodes ()
2009-09-19 17:43:19 +00:00
{
global $register_sc ;
2013-06-19 22:50:51 -07:00
2016-04-23 15:23:45 -07:00
if ( file_exists ( THEME . " theme_shortcodes.php " ))
2015-05-31 09:25:59 -07:00
{
2016-04-23 15:23:45 -07:00
$classFunc = 'theme_shortcodes' ;
$path = THEME . " theme_shortcodes.php " ;
include_once ( $path );
$this -> registerClassMethods ( $classFunc , $path , false );
2015-05-31 09:25:59 -07:00
}
2016-04-23 15:23:45 -07:00
2013-06-19 22:50:51 -07:00
2016-04-23 15:23:45 -07:00
if ( isset ( $register_sc ) && is_array ( $register_sc )) // legacy load.
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
}
2013-06-19 22:50:51 -07: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' );
2013-02-11 14:25:59 +02:00
$prefl = e107 :: getPref ( 'shortcode_legacy_list' );
2010-02-10 21:53:56 +00:00
2013-02-11 14:25:59 +02:00
// new shortcodes - functions, shortcode/single/*.php
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
{
2013-02-11 14:25:59 +02:00
$code = strtoupper ( $code );
if ( ! $this -> isRegistered ( $code ))
{
if ( $this -> isOverride ( $code ))
{
$this -> registered_codes [ $code ][ 'type' ] = 'override' ;
$this -> registered_codes [ $code ][ 'function' ] = 'override_' . strtolower ( $code ) . '_shortcode' ;
$this -> registered_codes [ $code ][ 'path' ] = e_CORE . 'override/shortcodes/single/' ;
$this -> registered_codes [ $code ][ 'perms' ] = $uclass ;
continue ;
}
$this -> registered_codes [ $code ][ 'type' ] = 'plugin' ;
$this -> registered_codes [ $code ][ 'function' ] = strtolower ( $code ) . '_shortcode' ;
$this -> registered_codes [ $code ][ 'path' ] = e_PLUGIN . $path . '/shortcodes/single/' ;
$this -> registered_codes [ $code ][ 'perms' ] = $uclass ;
}
}
}
}
// legacy .sc - plugin root
if ( $prefl )
{
foreach ( $prefl as $path => $namearray )
{
foreach ( $namearray as $code => $uclass )
{
// XXX old? investigate
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
{
2013-02-11 14:25:59 +02:00
$code = strtoupper ( $code );
2010-04-25 13:52:14 +00:00
if ( ! $this -> isRegistered ( $code ))
2009-01-08 17:23:13 +00:00
{
2013-02-11 14:25:59 +02:00
$this -> registered_codes [ $code ][ 'type' ] = 'plugin_legacy' ;
2009-01-08 17:23:13 +00:00
$this -> registered_codes [ $code ][ 'path' ] = $path ;
2013-02-11 14:25:59 +02:00
$this -> registered_codes [ $code ][ 'perms' ] = $uclass ;
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
}
2013-02-11 14:25:59 +02: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
}
2013-02-09 19:05:51 +02:00
2010-04-25 13:52:14 +00:00
foreach ( $pref as $key => $val )
2009-09-18 22:20:40 +00:00
{
2013-02-09 19:05:51 +02:00
$globalOverride = $this -> isBatchOverride ( $key . '_shortcodes' );
if ( $globalOverride )
{
$path = e_CORE . 'override/shortcodes/batch/' . $key . '_shortcodes.php' ;
$classFunc = 'override_' . $key . '_shortcodes' ;
}
else
{
$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
{
2013-02-09 19:05:51 +02:00
// try to switch back to the batch origin in case it's an override
if ( $globalOverride )
{
$path = e_PLUGIN . $key . '/e_shortcode.php' ;
$classFunc = $key . '_shortcodes' ;
if ( ! include_once ( $path ))
{
continue ;
}
}
else continue ;
2009-09-18 22:20:40 +00:00
}
2012-04-23 01:21:06 +00:00
2013-02-09 19:05:51 +02:00
$this -> registerClassMethods ( $classFunc , $path , false );
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 .
2016-05-01 09:30:33 -07:00
* @ param $class
* @ param $path
* @ param bool $force
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-08-24 09:05:32 +00:00
$this -> initShortcodeClass ( $className );
// if (class_exists($className, false))
// {
// $this->scClasses[$className] = new $className(); // Required. Test with e107::getScBatch($className)
// echo "CLASS=:".$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
2016-04-23 15:23:45 -07:00
2006-12-02 04:36:16 +00:00
2009-01-08 17:23:13 +00:00
function isRegistered ( $code )
{
2013-02-11 14:25:59 +02:00
return array_key_exists ( $code , $this -> registered_codes );
2009-01-08 17:23:13 +00:00
}
2010-02-10 21:53:56 +00:00
2016-04-23 15:23:45 -07: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 );
}
2013-02-09 19:05:51 +02:00
function isBatchOverride ( $name )
{
return in_array ( $name , $this -> scBatchOverride );
}
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
{
2013-04-28 19:14:14 +03:00
global $sc_style ; //legacy, will be removed soon, use the non-global $SC_STYLE instead
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 ;
2013-04-18 12:41:32 -07:00
2013-04-28 19:14:14 +03:00
// former $sc_style - do it once here and not on every doCode loop - performance
2015-07-20 12:11:49 -07:00
$this -> sc_style = e107 :: scStyle (); //FIXME - BC Problems and conflicts.
2013-05-07 18:30:02 -07:00
/* --------- BUG TEST Scenario --------------
* Front - end Theme : Bootstrap
* MENU - 1 contains '{NAVIGATION=side}' on top and chatbox_menu below
* URL to use : / usersettings . php - 'Signature' input should be enabled .
* Expected Result :
* 1 ) { NAVIGATION = side } wrapped with $SC_WRAPPER ie . enclosed in box .
* 2 ) Internal styling of chatbox_class not to be damaged by what happens globally ie . the text 'Display name' should not appear in the chatbox
* 3 ) Usersettings Signature box to appear wrapped in BC $sc_style pre / post - ie . should appear at the bottom of the html table . ( not at the top )
* 4 ) Existing Chatbox Styling ( v1 . x ) not broken ( ie . test with v1 theme ) .
* - All of the above to occur without changes to usersetting_template . php - since its logic is that of v1 . x templates .
*
* Things that may help :
* Modify e107 :: getScBatch () so that it never registers shortcodes globally ; ie . no overriding of existing shortcodes with it , as it is a replacement for non - global shortcode declaration in v1
* ONLY globally register shortcodes when they are declared in e_shortcode . php - this is consistent with the logic of e_xxxx which affect e107 Outside of the plugin / sript . ( gallery plugin follows this logic )
*
*/
2016-05-01 09:30:33 -07:00
2013-04-28 19:14:14 +03:00
if ( isset ( $sc_style ) && is_array ( $sc_style ))
{
2013-05-07 18:30:02 -07:00
$this -> sc_style = array_merge ( $sc_style , $this -> sc_style ); // XXX Commenting this out will fix #2 above.
2013-04-28 19:14:14 +03:00
}
2010-01-23 16:41:56 +00:00
2009-08-20 16:41:29 +00:00
//object support
2013-05-07 18:30:02 -07:00
2010-04-25 13:52:14 +00:00
if ( is_object ( $extraCodes ))
2009-08-20 16:41:29 +00:00
{
2016-02-29 15:13:32 -08:00
2011-03-24 21:29:45 +00:00
$this -> addedCodes = & $extraCodes ;
2016-04-22 11:54:18 -07:00
// e107::getDebug()->log("Codes".print_a($this->addedCodes,true));
2013-04-28 19:14:14 +03:00
// TEMPLATEID_WRAPPER support - see contact template
2016-04-02 10:51:18 -07:00
// must be registered in e_shortcode object (batch) via () method before parsing
2013-04-28 19:14:14 +03:00
// Do it only once per parsing cylcle and not on every doCode() loop - performance
if ( method_exists ( $this -> addedCodes , 'wrapper' ))
{
2015-08-22 00:17:07 -07:00
// $cname = get_class($this->addedCodes);
2015-07-20 12:11:49 -07:00
$tmpWrap = e107 :: templateWrapper ( $this -> addedCodes -> wrapper ());
if ( ! empty ( $tmpWrap )) // FIX for #3 above.
{
$this -> wrappers = array_merge ( $this -> wrappers , $tmpWrap );
2016-04-02 10:51:18 -07:00
$this -> wrapper = $this -> addedCodes -> getWrapperID ();
2015-07-20 12:11:49 -07:00
}
2016-04-05 13:15:58 -07:00
elseif ( E107_DBG_BBSC )
{
2016-04-09 16:12:08 -07:00
$this -> wrapper = $this -> addedCodes -> getWrapperID ();
2016-04-05 13:15:58 -07:00
// e107::getMessage()->addDebug("Wrapper Empty: ".$this->addedCodes->wrapper());
}
2015-08-22 00:17:07 -07:00
2013-04-28 19:14:14 +03:00
}
2015-07-20 12:11:49 -07:00
2016-05-28 19:03:08 -07:00
if ( method_exists ( $this -> addedCodes , 'editable' ))
{
$this -> editableCodes = $this -> addedCodes -> editable ();
if ( isset ( $this -> editableCodes [ 'perms' ]) && getperms ( $this -> editableCodes [ 'perms' ]))
{
e107 :: js ( 'core' , 'jquery.contenteditable.js' , 'jquery' );
$_SESSION [ 'editable' ][ e_TOKEN ] = $this -> editableCodes ;
e107 :: js ( 'footer-inline' , ' $ ( " .e-editable-front " ) . each ( function ()
{
var sc = $ ( this ) . attr ( " data-edit-sc " );
var id = $ ( this ) . attr ( " data-edit-id " );
var token = " '.e_TOKEN.' " ;
$ ( this ) . contentEditable ({
" placeholder " : " " ,
" onBlur " : function ( element ){
var edited_content = element . content ;
$ . post ( " '.e_WEB_ABS.'js/inline.php " ,{ content : edited_content , sc : sc , id : id , token : token }, function ( data ){
console . log ( data );
try
{
var d = $ . parseJSON ( data );
} catch ( e )
{
// Not JSON.
return ;
}
console . log ( d );
// Show pop-up message.
if ( d . msg )
{
var alertType = " info " ;
if ( d . status == " ok " )
{
alertType = " success " ;
}
if ( d . status == " error " )
{
alertType = " danger " ;
}
if ( jQuery () . notify )
{
$ ( " #uiAlert " ) . notify ({
type : alertType ,
message : { text : d . msg },
fadeOut : { enabled : true , delay : 3000 }
}) . show ();
}
else
{
alert ( d . msg );
// location.reload();
return ;
}
}
});
}
});
});
' );
}
}
2015-07-20 12:11:49 -07:00
2011-03-24 21:29:45 +00:00
/*
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
}
2014-08-17 20:53:44 -07:00
elseif ( is_array ( $extraCodes )) // Array value contains the contents of a .sc file which is then parsed. ie. return " whatever ";
2008-02-13 02:57:17 +00:00
{
2015-08-22 00:17:07 -07:00
$this -> addedCodes = & $extraCodes ;
2016-05-04 15:56:41 -07:00
if ( isset ( $extraCodes [ '_WRAPPER_' ]))
{
$tmpWrap = e107 :: templateWrapper ( $extraCodes [ '_WRAPPER_' ]);
$this -> wrappers = array_merge ( $this -> wrappers , $tmpWrap );
$this -> wrapper = $extraCodes [ '_WRAPPER_' ];
unset ( $extraCodes [ '_WRAPPER_' ]);
}
2011-03-24 21:29:45 +00:00
/*
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
*/
2014-08-17 20:53:44 -07:00
// print_a($this);
2006-12-02 04:36:16 +00:00
}
2015-08-22 00:17:07 -07:00
2016-01-24 20:08:47 -08:00
$ret = preg_replace_callback ( '#\{([A-Z][^\x02]*?\S)\}#' , array ( & $this , 'doCode' ), $text ); // must always start with uppercase letter
// $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
2013-04-18 12:41:32 -07:00
$this -> debug_legacy = null ;
2016-05-03 15:52:02 -07:00
2016-05-01 09:30:33 -07:00
2014-08-17 20:53:44 -07:00
// $this->sc_style = array(); //XXX Adding this will also fix #2 above.
2013-05-07 18:30:02 -07:00
2006-12-02 04:36:16 +00:00
return $ret ;
}
2011-03-24 21:29:45 +00:00
/**
2016-05-01 09:30:33 -07:00
* Callback looks up and substitutes a shortcode
* @ param $matches
* @ return bool | int | mixed | string
2011-03-24 21:29:45 +00:00
*/
2006-12-02 04:36:16 +00:00
function doCode ( $matches )
{
2014-08-18 22:57:18 -07:00
// print_a($matches);
2016-05-01 09:30:33 -07:00
2014-08-18 22:57:18 -07:00
if ( in_array ( $matches [ 0 ], $this -> ignoreCodes )) // Ignore all {e_PLUGIN}, {THEME} etc. otherwise it will just return blank for these items.
{
return $matches [ 0 ];
}
2013-04-28 19:14:14 +03:00
// XXX remove all globals, $sc_style removed
global $pref , $e107cache , $menu_pref , $parm , $sql ;
2013-03-11 05:11:58 -07:00
2016-04-30 12:02:02 -07:00
$parmArray = false ;
$fullShortcodeKey = null ;
$noDebugLog = false ;
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 ]))
{
2016-02-15 19:59:47 -08:00
$match1 = $matches [ 1 ]; // php7 fix.
2016-04-30 12:02:02 -07:00
// e107::getDebug()->log("Using eVars ".$match1);
2016-02-15 19:59:47 -08:00
return $this -> eVars -> $match1 ;
2010-01-23 16:41:56 +00:00
}
}
2010-04-25 13:52:14 +00:00
if ( strpos ( $matches [ 1 ], E_NL ) !== false )
{
return $matches [ 0 ];
}
2013-03-11 02:41:48 -07:00
2016-01-24 20:08:47 -08:00
2016-04-19 10:23:02 -07:00
if ( preg_match ( '/^([A-Z_]*\d?):(.*)/' , $matches [ 1 ], $newMatch ))
2013-03-11 05:11:58 -07:00
{
2015-08-22 00:17:07 -07:00
$fullShortcodeKey = $newMatch [ 0 ];
2013-03-11 05:11:58 -07:00
$code = $newMatch [ 1 ];
$parmStr = trim ( $newMatch [ 2 ]);
2013-04-29 19:38:26 -07:00
$debugParm = $parmStr ;
2013-03-11 05:11:58 -07:00
parse_str ( $parmStr , $parm );
$parmArray = true ;
}
elseif ( strpos ( $matches [ 1 ], '=' ))
2006-12-02 04:36:16 +00:00
{
2013-03-11 02:41:48 -07:00
list ( $code , $parm ) = explode ( '=' , $matches [ 1 ], 2 );
2006-12-02 04:36:16 +00:00
}
else
{
2013-03-11 02:41:48 -07:00
$code = $matches [ 1 ];
$parm = '' ;
2006-12-02 04:36:16 +00:00
}
2013-03-11 02:41:48 -07:00
//look for the $sc_mode
if ( strpos ( $code , '|' ))
2007-06-13 02:53:21 +00:00
{
2013-03-11 02:41:48 -07: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
{
2013-03-11 02:41:48 -07:00
$sc_mode = '' ;
2007-03-30 13:33:29 +00:00
}
2013-03-11 05:11:58 -07:00
if ( $parmArray == false )
{
$parm = trim ( $parm );
$parm = str_replace ( array ( '[[' , ']]' ), array ( '{' , '}' ), $parm );
}
2016-12-16 10:53:59 -08:00
if ( empty ( $parm ))
{
$parm = array ();
}
2013-03-11 05:11:58 -07: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
{
2016-05-01 09:30:33 -07:00
$sql -> db_Mark_Time ( " SC " . $code );
2006-12-02 04:36:16 +00:00
}
2010-04-25 13:52:14 +00:00
if ( E107_DBG_SC )
2006-12-02 04:36:16 +00:00
{
2013-04-18 12:41:32 -07:00
$dbg = " <strong> " ;
$dbg .= '{' ;
$dbg .= $code ;
$dbg .= ( $parm ) ? '=' . htmlentities ( $parm ) : " " ;
$dbg .= '}' ;
$dbg .= " </strong> " ;
// echo $dbg;
return $dbg ;
2010-04-25 13:52:14 +00:00
// trigger_error('starting shortcode {'.$code.'}', E_USER_ERROR); // no longer useful - use ?[debug=bbsc]
2013-04-18 12:41:32 -07:00
}
2009-01-08 17:23:13 +00:00
$scCode = '' ;
$scFile = '' ;
2015-07-02 14:15:17 -07:00
$_path = '' ;
2011-03-24 21:29:45 +00:00
$ret = '' ;
$_method = 'sc_' . strtolower ( $code );
2016-04-22 11:54:18 -07:00
2016-04-23 15:23:45 -07:00
2016-04-22 11:54:18 -07:00
// Display e_shortcode.php override info.
if (( E107_DBG_BBSC || E107_DBG_SC ) && isset ( $this -> addonOverride [ $_method ]) && is_object ( $this -> addedCodes ) && method_exists ( $this -> addedCodes , $_method ))
{
$debugArr = array ( 'class_original' => get_class ( $this -> addedCodes ), 'class_override' => $this -> addonOverride [ $_method ], 'function' => $_method );
e107 :: getDebug () -> logCode ( 4 , $code , null , print_a ( $debugArr , true ));
2016-04-30 12:02:02 -07:00
$noDebugLog = true ;
2016-04-22 11:54:18 -07:00
}
if ( ! isset ( $this -> addonOverride [ $_method ]) && is_object ( $this -> addedCodes ) && method_exists ( $this -> addedCodes , $_method )) //It is class-based batch shortcode. Class already loaded; call the method
2011-03-24 21:29:45 +00:00
{
2013-04-18 12:41:32 -07:00
2013-04-29 19:38:26 -07:00
$ret = $this -> addedCodes -> $_method ( $parm , $sc_mode );
2016-04-22 11:54:18 -07:00
2013-04-29 19:38:26 -07:00
if ( E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS )
{
$_class = get_class ( $this -> addedCodes ); // "(class loaded)"; // debug.
$_function = $_method ;
$_path = " (already loaded) " ;
2016-04-22 11:54:18 -07:00
2013-04-29 19:38:26 -07:00
}
2011-03-24 21:29:45 +00:00
}
2016-05-01 09:30:33 -07:00
elseif ( is_array ( $this -> addedCodes ) && array_key_exists ( $code , $this -> addedCodes )) // Its array-based shortcode. Load the code for evaluation later.
2011-03-24 21:29:45 +00:00
{
2016-05-01 09:30:33 -07:00
// $ret = $this->addedCodes[$code];
//$this->legacyBatch
if ( in_array ( $code , $this -> legacyBatch ))
{
2016-05-03 15:52:02 -07:00
$_type = 'legacy batch' ;
$_path = $this -> legacyBatchFile ;
2016-05-01 09:30:33 -07:00
$scCode = $this -> addedCodes [ $code ];
}
else
{
2016-05-03 15:52:02 -07:00
$_type = 'array' ;
$_path = " (direct to parser) " ;
2016-05-01 09:30:33 -07:00
$ret = $this -> addedCodes [ $code ];
2016-05-03 15:52:02 -07:00
2016-05-01 09:30:33 -07:00
}
2016-04-23 15:23:45 -07:00
2011-03-24 21:29:45 +00:00
}
2013-04-29 19:38:26 -07:00
elseif ( array_key_exists ( $code , $this -> scList )) // Check to see if we've already loaded the .sc file contents
2009-01-08 17:23:13 +00:00
{
2013-04-18 12:41:32 -07:00
2009-01-08 17:23:13 +00:00
$scCode = $this -> scList [ $code ];
2013-04-18 12:41:32 -07:00
$_path = " (loaded earlier) " ; // debug.
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
{
2013-04-18 12:41:32 -07: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
2013-04-18 12:41:32 -07:00
$_class = $this -> registered_codes [ $code ][ 'class' ];
$_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);
2013-04-28 19:14:14 +03:00
$wrapper = $this -> callScFunc ( $_class , 'wrapper' , null );
2015-08-22 00:17:07 -07:00
2010-04-25 13:52:14 +00:00
$ret = $this -> callScFuncA ( $_class , $_method , array ( $parm , $sc_mode ));
2013-04-18 12:41:32 -07:00
2010-04-25 13:52:14 +00:00
/* 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 ;
2013-02-08 16:49:57 +02:00
case 'override' :
2009-01-08 17:23:13 +00:00
case 'func' :
2013-02-11 14:25:59 +02:00
case 'plugin' :
2009-01-08 17:23:13 +00:00
//It is a function, so include the file and call the function
$_function = $this -> registered_codes [ $code ][ 'function' ];
2013-02-08 16:49:57 +02:00
if ( ! function_exists ( $_function ) && $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
}
2013-02-11 14:25:59 +02: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 ;
2013-02-11 14:25:59 +02:00
case 'plugin_legacy' :
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 ;
2013-02-08 16:49:57 +02:00
// case 'override':
// $scFile = e_CORE.'override/shortcodes/'.strtolower($code).'.sc';
// break;
2009-01-16 01:02:41 +00:00
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 );
2013-04-18 12:41:32 -07:00
$_path = e_CORE . 'shortcodes/single/' . strtolower ( $code ) . '.php' ;
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
2009-11-23 10:27:43 +00:00
{
2013-08-27 13:56:36 +03:00
// SecretR - fix array(parm, sc_mode) causing parm to become an array, see issue 424
$ret = call_user_func ( array ( $_class , $_function ), $parm , $sc_mode );
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
{
2013-03-11 05:11:58 -07:00
$ret = call_user_func ( $_function , $parm , $sc_mode );
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' ;
2013-04-18 12:41:32 -07:00
$_path = $scFile ;
2006-12-02 04:36:16 +00:00
}
}
2016-04-23 15:23:45 -07:00
if ( ! empty ( $scFile ))
2014-08-18 22:57:18 -07:00
{
2016-05-01 09:30:33 -07:00
$_type = 'file' ;
2016-04-23 15:23:45 -07:00
if ( file_exists ( $scFile ))
{
$scCode = file_get_contents ( $scFile );
$this -> scList [ $code ] = $scCode ;
$_path = $scFile ;
2016-05-01 09:30:33 -07:00
2016-04-23 15:23:45 -07:00
}
else
{
$_path .= $scFile . " MISSING! " ;
}
2009-01-08 17:23:13 +00:00
}
2016-04-23 15:23:45 -07:00
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
2016-04-23 15:23:45 -07:00
// if (E107_DBG_SC && $scFile)
// {
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>";
2016-04-23 15:23:45 -07:00
// }
2009-01-08 17:23:13 +00:00
}
2006-12-02 04:36:16 +00:00
2016-04-23 15:23:45 -07:00
if ( $scCode ) // legacy shortode to be evaluated.
2009-01-08 17:23:13 +00:00
{
2016-05-01 09:30:33 -07:00
2016-04-23 15:23:45 -07:00
try
{
$ret = @ eval ( $scCode );
}
catch ( Throwable $t ) { // Executed only in PHP 7, will not match in PHP 5.x
2016-05-01 09:30:33 -07:00
$error = $this -> debug_legacy ;
$error [ 'code' ] = $code ;
$error [ 'problem' ] = $scCode ;
e107 :: getDebug () -> logCode ( - 2 , $code , null , print_a ( $error , true ));
2016-04-23 15:23:45 -07:00
}
2016-05-01 09:30:33 -07:00
if ( $ret === false && E107_DEBUG_LEVEL > 0 ) // Error in Code.
2014-10-03 20:59:05 -07:00
{
2016-05-01 09:30:33 -07:00
$error = $this -> debug_legacy ;
$error [ 'code' ] = $code ;
$error [ 'problem' ] = $scCode ;
$error [ 'error' ] = error_get_last ();
e107 :: getDebug () -> logCode ( - 2 , $code , null , print_a ( $error , true ));
2014-10-03 20:59:05 -07:00
}
2006-12-02 04:36:16 +00:00
}
2016-04-09 16:12:08 -07:00
if ( E107_DBG_BBSC && $this -> wrapperDebugDone [ $this -> wrapper ] == false && ! empty ( $this -> wrapper ))
2016-04-02 10:51:18 -07:00
{
list ( $wrapTmpl , $wrapID1 , $wrapID2 ) = explode ( '/' , $this -> wrapper , 3 );
2015-08-22 00:17:07 -07:00
2016-05-04 15:56:41 -07:00
$wrapActive = strtoupper ( $wrapTmpl ) . " _WRAPPER " ;
if ( ! empty ( $wrapID1 ))
{
$wrapActive .= " [' " . $wrapID1 . " '] " ;
}
2016-04-02 10:51:18 -07:00
if ( ! empty ( $wrapID2 ))
{
$wrapActive .= " [' " . $wrapID2 . " '] " ;
}
// e107::getMessage()->addDebug("Active Wrapper: \$".$wrapActive);
2016-04-09 16:12:08 -07:00
$this -> wrapperDebugDone [ $this -> wrapper ] = true ;
2016-04-02 10:51:18 -07:00
global $db_debug ;
2016-04-09 16:12:08 -07:00
$db_debug -> logCode ( 3 , $this -> wrapper , null , '<pre>To use, add to the file ' . $wrapTmpl . '_template.php:<br />$' . $wrapActive . '[\'SHORTCODE_NAME\'] = "(html before){---}(html after)";</pre>' );
2016-04-02 10:51:18 -07:00
}
2015-08-22 00:17:07 -07:00
2010-04-25 13:52:14 +00:00
if ( isset ( $ret ) && ( $ret != '' || is_numeric ( $ret )))
2006-12-02 04:36:16 +00:00
{
2016-05-28 19:03:08 -07:00
$ret = $this -> makeEditable ( $ret , $code );
2016-12-05 19:16:33 +00:00
if ( ! $this -> nowrap == $code )
{
$ret = $this -> makeWrapper ( $ret , $code , $fullShortcodeKey , $sc_mode );
}
2006-12-02 04:36:16 +00:00
}
2016-05-28 19:03:08 -07:00
2010-09-10 01:00:36 +00:00
if ( E107_DBG_SC || E107_DBG_TIMEDETAILS )
2008-02-13 02:57:17 +00:00
{
2017-01-21 10:49:04 -08:00
// $sql->db_Mark_Time("(After SC {$code})");
2006-12-05 09:15:08 +00:00
}
2013-04-18 12:41:32 -07:00
2016-04-30 12:02:02 -07:00
if (( $noDebugLog != true ) && ( E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS ))
2013-04-18 12:41:32 -07:00
{
global $db_debug ;
$other = array ();
2016-04-23 15:23:45 -07:00
if ( ! empty ( $_type ))
{
$other [ 'type' ] = $_type ;
}
2013-04-29 19:38:26 -07:00
2016-04-23 15:23:45 -07:00
if ( ! empty ( $_class ))
2013-04-18 12:41:32 -07:00
{
$other [ 'class' ] = $_class ;
}
2016-04-23 15:23:45 -07:00
if ( ! empty ( $_function ))
2013-04-18 12:41:32 -07:00
{
$other [ 'function' ] = $_function ;
}
2016-04-23 15:23:45 -07:00
if ( ! empty ( $_path ))
2013-04-18 12:41:32 -07:00
{
$other [ 'path' ] = str_replace ( '../' , '' , $_path );
}
2016-04-23 15:23:45 -07:00
2013-04-18 12:41:32 -07:00
if ( $this -> debug_legacy )
{
2013-04-29 19:38:26 -07:00
$other = $this -> debug_legacy ;
2013-04-18 12:41:32 -07:00
}
2015-08-22 00:17:07 -07:00
if ( ! empty ( $this -> wrappers [ $code ]))
{
2016-05-28 19:03:08 -07:00
$other [ 'wrapper' ] = str_replace ( array ( " \n " , " \t " ), " " , $this -> wrappers [ $code ]);
2015-08-22 00:17:07 -07:00
}
elseif ( ! empty ( $this -> wrappers [ $fullShortcodeKey ]) )
{
$other [ 'wrapper' ] = $this -> wrappers [ $fullShortcodeKey ];
}
2013-04-18 12:41:32 -07:00
$info = ( isset ( $this -> registered_codes [ $code ])) ? print_a ( $this -> registered_codes [ $code ], true ) : print_a ( $other , true );
2013-04-29 19:38:26 -07:00
$tmp = isset ( $debugParm ) ? $debugParm : $parm ;
$db_debug -> logCode ( 2 , $code , $tmp , $info );
2015-08-22 00:17:07 -07:00
2013-04-18 12:41:32 -07:00
}
2016-05-28 19:03:08 -07:00
return isset ( $ret ) ? $ret : '' ;
2006-12-02 04:36:16 +00:00
}
2016-05-01 09:30:33 -07:00
2016-05-28 19:03:08 -07:00
/**
* Add Wrapper to Shortcode ( when detected )
* @ param mixed $ret
* @ param string $code
* @ param string $fullShortcodeKey
* @ param string $sc_mode
* // Wrapper support - see contact_template.php
* @ return string
*/
private function makeWrapper ( $ret , $code , $fullShortcodeKey , $sc_mode )
{
2016-11-15 11:11:19 -08:00
$pre = $post = '' ;
2016-05-28 19:03:08 -07:00
if ( isset ( $this -> wrappers [ $code ]) && ! empty ( $this -> wrappers [ $code ])) // eg: $NEWS_WRAPPER['view']['item']['NEWSIMAGE']
{
list ( $pre , $post ) = explode ( " { ---} " , $this -> wrappers [ $code ], 2 );
}
2016-11-15 11:11:19 -08:00
elseif ( ! empty ( $fullShortcodeKey ) && ! empty ( $this -> wrappers [ $fullShortcodeKey ]) ) // eg: $NEWS_WRAPPER['view']['item']['NEWSIMAGE: item=1']
2016-05-28 19:03:08 -07:00
{
list ( $pre , $post ) = explode ( " { ---} " , $this -> wrappers [ $fullShortcodeKey ], 2 );
}
2016-11-15 11:11:19 -08:00
else
2016-05-28 19:03:08 -07:00
{
2016-11-15 11:11:19 -08:00
//if $sc_mode exists, we need it to parse $sc_style
if ( $sc_mode )
{
$code = $code . '|' . $sc_mode ;
}
2016-05-28 19:03:08 -07:00
2016-11-15 11:11:19 -08:00
if ( is_array ( $this -> sc_style ) && array_key_exists ( $code , $this -> sc_style ))
2016-05-28 19:03:08 -07:00
{
2016-11-15 11:11:19 -08:00
// old way - pre/post keys
if ( is_array ( $this -> sc_style [ $code ]))
2016-05-28 19:03:08 -07:00
{
2016-11-15 11:11:19 -08:00
if ( isset ( $this -> sc_style [ $code ][ 'pre' ]))
{
$pre = $this -> sc_style [ $code ][ 'pre' ];
}
if ( isset ( $this -> sc_style [ $code ][ 'post' ]))
{
$post = $this -> sc_style [ $code ][ 'post' ];
}
2016-05-28 19:03:08 -07:00
}
2016-11-15 11:11:19 -08:00
else // new way - same format as wrapper
2016-05-28 19:03:08 -07:00
{
2016-11-15 11:11:19 -08:00
list ( $pre , $post ) = explode ( " { ---} " , $this -> sc_style [ $code ], 2 );
2016-05-28 19:03:08 -07:00
}
2016-11-15 11:11:19 -08:00
2016-05-28 19:03:08 -07:00
}
}
2016-11-15 11:11:19 -08:00
if ( strpos ( $pre , '{' ) !== false ) // shortcode found in wrapper
{
2016-12-05 19:16:33 +00:00
$this -> nowrap = $code ;
2016-11-16 13:12:27 -08:00
$pre = $this -> parseCodes ( $pre , true , $this -> addedCodes );
2016-12-06 19:01:08 +00:00
$this -> nowrap = false ;
2016-11-15 11:11:19 -08:00
}
if ( strpos ( $post , '{' ) !== false ) // shortcode found in wrapper
{
2016-12-05 19:16:33 +00:00
$this -> nowrap = $code ;
2016-11-16 13:12:27 -08:00
$post = $this -> parseCodes ( $post , true , $this -> addedCodes );
2016-12-06 19:01:08 +00:00
$this -> nowrap = false ;
2016-11-15 11:11:19 -08:00
}
2016-05-28 19:03:08 -07:00
2016-11-15 11:11:19 -08:00
return $pre . $ret . $post ;
2016-05-28 19:03:08 -07:00
}
/**
* Add Editable Container to shortcode ( when detected )
* @ param string $text
* @ param string $code
* @ return string
*/
private function makeEditable ( $text , $code )
{
2016-06-09 16:44:40 -07:00
if ( $this -> editableActive === false )
{
return $text ; // unchanged.
}
2016-06-10 08:19:39 -07:00
2016-06-09 16:44:40 -07:00
2016-05-28 19:03:08 -07:00
$lcode = strtolower ( $code );
if ( empty ( $code )
|| empty ( $this -> editableCodes )
|| empty ( $this -> editableCodes [ 'shortcodes' ][ $lcode ])
|| ! isset ( $this -> editableCodes [ 'perms' ])
|| empty ( $this -> editableCodes [ 'table' ])
|| empty ( $this -> editableCodes [ 'pid' ])
|| ! getperms ( $this -> editableCodes [ 'perms' ])
|| empty ( $this -> editableCodes [ 'shortcodes' ][ $lcode ][ 'field' ])
)
{
return $text ;
}
if ( ! empty ( $this -> editableCodes [ 'vars' ]))
{
$varID = $this -> editableCodes [ 'vars' ];
$var = $this -> addedCodes -> getScVar ( $varID );
}
else
{
$var = $this -> addedCodes -> getVars ();
}
$container = empty ( $this -> editableCodes [ 'shortcodes' ][ $lcode ][ 'container' ]) ? 'span' : $this -> editableCodes [ 'shortcodes' ][ $lcode ][ 'container' ];
$pid = $this -> editableCodes [ 'pid' ];
$id = intval ( $var [ $pid ]);
2016-05-30 15:19:19 -07:00
$attributes = " title=' " . LAN_EDIT . " ' contenteditable='true' class='e-editable-front' data-edit-id=' " . $id . " ' data-edit-sc=' " . $lcode . " ' " ;
2016-05-28 19:03:08 -07:00
return ( $container == 'div' ) ? " <div " . $attributes . " > " . $text . " </div> " : " <span " . $attributes . " > " . $text . " </span> " ;
}
2016-05-01 09:30:33 -07:00
/**
* @ param $fname
* @ param string $type
* @ return array
*/
2006-12-03 07:03:22 +00:00
function parse_scbatch ( $fname , $type = 'file' )
{
2016-05-01 09:30:33 -07:00
// 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}");
2016-05-01 09:30:33 -07:00
$sc_cache = e107 :: getCache () -> 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
{
2015-02-14 23:34:15 -08:00
$cur_shortcodes = e107 :: unserialize ( $sc_cache );
2006-12-03 07:03:22 +00:00
$sc_batch = " " ;
}
2006-12-02 04:36:16 +00:00
}
else
{
$sc_batch = $fname ;
}
2013-04-18 12:41:32 -07:00
$this -> debug_legacy = array ( 'type' => $type , 'path' => str_replace ( e_ROOT , " " , $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
{
2016-05-01 09:30:33 -07:00
$sc_cache = e107 :: serialize ( $cur_shortcodes , false );
e107 :: getCache () -> 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
}
}
}
2016-05-01 09:30:33 -07:00
$this -> legacyBatch = array_keys ( $cur_shortcodes );
2016-05-03 15:52:02 -07:00
$this -> legacyBatchFile = str_replace ( e_ROOT , '' , $fname );
2016-05-01 09:30:33 -07: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
{
/**
2012-08-23 11:42:54 +00:00
* Stores passed to shortcode handler array data
* Usage : $this -> var [ 'someKey' ]
* Assigned via setVars () and addVars () methods
* @ var array
2010-04-23 15:54:11 +00:00
*/
2012-08-23 11:42:54 +00:00
protected $var = array (); // value available to each shortcode.
2012-06-17 10:51:13 +00:00
protected $mode = 'view' ; // or edit. Used within shortcodes for form elements vs values only.
2010-04-25 13:52:14 +00:00
2013-04-28 19:14:14 +03:00
protected $wrapper = null ; // holds template/key value of the currently used wrapper (if any) - see contact_template.php for an example.
2016-04-22 11:54:18 -07:00
protected $override = false ;
2016-05-28 19:03:08 -07:00
protected $editable = null ;
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
2016-03-23 16:43:41 -07:00
/**
* e_shortcode constructor .
*/
2016-04-28 18:13:41 -07:00
public function __construct ( $eVars = null )
2010-04-23 15:54:11 +00:00
{
2016-04-28 18:13:41 -07:00
$this -> scVars = ! empty ( $eVars ) ? $eVars : new e_vars ();
2010-04-23 15:54:11 +00:00
}
2012-08-23 11:42:54 +00:00
/**
* Startup code for child class
*/
public function init () {}
2016-04-22 11:54:18 -07:00
2013-04-28 19:14:14 +03:00
/**
* Sets wrapper id ( to be retrieved from the registry while parsing )
* Example e107 :: getScBatch ( 'contact' ) -> wrapper ( 'contact/form' );
* which results in using the $CONTACT_WRAPPER [ 'form' ] wrapper in the parsing phase
2016-02-29 15:13:32 -08:00
* Template cannot be loaded via include , only by getTemplate or getCoreTemplate
* e107 :: getScBatch () must be used also .
2016-05-01 09:30:33 -07:00
* @ param string $id
* @ return $this | null
2013-04-28 19:14:14 +03:00
*/
public function wrapper ( $id = null )
{
if ( null === $id ) return $this -> wrapper ;
if ( false === $id ) $id = null ;
$this -> wrapper = $id ;
2015-08-22 00:17:07 -07:00
2013-04-28 19:14:14 +03:00
return $this ;
}
2010-04-25 13:52:14 +00:00
2016-04-02 10:51:18 -07:00
public function getWrapperID ()
{
return $this -> wrapper ;
}
2016-05-28 19:03:08 -07:00
public function editable ( $data = null )
{
if ( null === $data ) return $this -> editable ;
$this -> editable = $data ;
return $this ;
}
2010-04-24 11:39:14 +00:00
/**
2012-08-23 11:42:54 +00:00
* Set external array data to be used in the batch
2012-11-02 00:23:59 +00:00
* Use setVars () - preferred .
2013-06-23 19:06:46 -07:00
* //XXX will soon become private. Use setVars() instead.
2012-08-23 11:42:54 +00:00
* @ param array $eVars
2010-04-24 11:39:14 +00:00
* @ return e_shortcode
*/
2013-06-23 19:06:46 -07: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 ;
}
2016-05-01 09:30:33 -07:00
2012-11-02 00:23:59 +00:00
/**
2016-04-22 09:44:01 -07:00
* Alias of setParserVars - Preferred use by Plugins .
* Sets the value of $sc -> var
2016-05-01 09:30:33 -07:00
* @ param $eVars
* @ return e_shortcode
2012-11-02 00:23:59 +00:00
*/
2012-06-19 09:08:41 +00:00
public function setVars ( $eVars ) // Alias of setParserVars();
{
return $this -> setParserVars ( $eVars );
}
2012-08-23 11:42:54 +00:00
/**
* Add array to current parser array data
* @ param array $array
* @ return e_shortcode
*/
public function addParserVars ( $array )
2012-06-17 10:51:13 +00:00
{
2012-08-23 13:06:01 +00:00
if ( ! is_array ( $array )) return $this ;
2012-08-23 11:42:54 +00:00
$this -> var = array_merge ( $this -> var , $array );
return $this ;
}
/**
* Alias of addParserVars ()
* @ param array $array
* @ return e_shortcode
*/
public function addVars ( $array )
{
return $this -> addParserVars ( $array );
2012-06-17 10:51:13 +00:00
}
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
*
2012-08-23 11:42:54 +00:00
* @ return array
2010-04-24 11:39:14 +00:00
*/
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
return $this -> var ;
2010-04-24 11:39:14 +00:00
}
2010-04-25 13:52:14 +00:00
2012-08-23 11:42:54 +00:00
/**
* Alias of getParserVars ()
*
* @ return array
*/
public function getVars ()
{
return $this -> getParserVars ();
}
/**
* Batch mod
* @ param string mod
* @ return e_shortcode
*/
public function setMode ( $mode )
{
$this -> mode = ( $mode == 'edit' ) ? 'edit' : 'view' ;
return $this ;
}
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
}