mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 21:27:25 +02:00
Issue #690 - Option added to enable e_shortcode.php to override other core/plugin shortcodes.
This commit is contained in:
@@ -514,8 +514,8 @@ class e107_db_debug {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>\n";
|
<tbody>\n";
|
||||||
|
|
||||||
$description = array(1=>'Bbcode',2=>'Shortcode',3=>'Wrapper');
|
$description = array(1=>'Bbcode',2=>'Shortcode',3=>'Wrapper', 4=>'Shortcode Override');
|
||||||
$style = array(1 => 'label-info', 2=>'label-primary', 3=>'label-warning');
|
$style = array(1 => 'label-info', 2=>'label-primary', 3=>'label-warning', 'label-danger');
|
||||||
|
|
||||||
foreach($this -> scbbcodes as $codes)
|
foreach($this -> scbbcodes as $codes)
|
||||||
{
|
{
|
||||||
|
@@ -70,6 +70,7 @@ class e_parse_shortcode
|
|||||||
protected $scOverride = array(); // Array of codes found in override/shortcodes dir
|
protected $scOverride = array(); // Array of codes found in override/shortcodes dir
|
||||||
protected $scBatchOverride = array(); // Array of codes found in override/shortcodes/batch 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 $ignoreCodes = array(); // Shortcodes to be ignored and remain unchanged. (ie. {THEME}, {e_PLUGIN} etc. )
|
||||||
|
protected $addonOverride = array(); // Overrides coming from e_shortcode.php
|
||||||
/**
|
/**
|
||||||
* @var e_vars
|
* @var e_vars
|
||||||
*/
|
*/
|
||||||
@@ -161,7 +162,7 @@ class e_parse_shortcode
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$codes = strtoupper($codes);
|
$codes = strtoupper($codes);
|
||||||
if ((!$this->isRegistered($code) || $force == true) && !$this->isOverride($code))
|
if ((!$this->isRegistered($codes) || $force == true) && !$this->isOverride($codes))
|
||||||
{
|
{
|
||||||
$this->registered_codes[$codes] = array('type' => 'func', 'path' => $path, 'function' => $classFunc);
|
$this->registered_codes[$codes] = array('type' => 'func', 'path' => $path, 'function' => $classFunc);
|
||||||
}
|
}
|
||||||
@@ -245,12 +246,29 @@ class e_parse_shortcode
|
|||||||
if (class_exists($class, false) && ($force || !$this->isScClass($class)))
|
if (class_exists($class, false) && ($force || !$this->isScClass($class)))
|
||||||
{
|
{
|
||||||
$this->scClasses[$class] = new $class();
|
$this->scClasses[$class] = new $class();
|
||||||
|
|
||||||
if(method_exists($this->scClasses[$class], 'init'))
|
if(method_exists($this->scClasses[$class], 'init'))
|
||||||
{
|
{
|
||||||
$this->scClasses[$class]->init();
|
$this->scClasses[$class]->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->scClasses[$class];
|
return $this->scClasses[$class];
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,6 +772,8 @@ class e_parse_shortcode
|
|||||||
|
|
||||||
|
|
||||||
$this->addedCodes = &$extraCodes;
|
$this->addedCodes = &$extraCodes;
|
||||||
|
|
||||||
|
// e107::getDebug()->log("Codes".print_a($this->addedCodes,true));
|
||||||
|
|
||||||
// TEMPLATEID_WRAPPER support - see contact template
|
// TEMPLATEID_WRAPPER support - see contact template
|
||||||
// must be registered in e_shortcode object (batch) via () method before parsing
|
// must be registered in e_shortcode object (batch) via () method before parsing
|
||||||
@@ -918,15 +938,26 @@ class e_parse_shortcode
|
|||||||
$_path = '';
|
$_path = '';
|
||||||
$ret = '';
|
$ret = '';
|
||||||
$_method = 'sc_'.strtolower($code);
|
$_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
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
{
|
{
|
||||||
|
|
||||||
$ret = $this->addedCodes->$_method($parm, $sc_mode);
|
$ret = $this->addedCodes->$_method($parm, $sc_mode);
|
||||||
|
|
||||||
if(E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS)
|
if(E107_DBG_BBSC || E107_DBG_SC || E107_DBG_TIMEDETAILS)
|
||||||
{
|
{
|
||||||
$_class = get_class($this->addedCodes); // "(class loaded)"; // debug.
|
$_class = get_class($this->addedCodes); // "(class loaded)"; // debug.
|
||||||
$_function = $_method;
|
$_function = $_method;
|
||||||
$_path = "(already loaded)";
|
$_path = "(already loaded)";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif (is_array($this->addedCodes) && array_key_exists($code, $this->addedCodes)) // Its array-based shortcode. Load the code for evaluation later.
|
elseif (is_array($this->addedCodes) && array_key_exists($code, $this->addedCodes)) // Its array-based shortcode. Load the code for evaluation later.
|
||||||
@@ -1308,7 +1339,8 @@ class e_shortcode
|
|||||||
protected $mode = 'view'; // or edit. Used within shortcodes for form elements vs values only.
|
protected $mode = 'view'; // or edit. Used within shortcodes for form elements vs values only.
|
||||||
|
|
||||||
protected $wrapper = null; // holds template/key value of the currently used wrapper (if any) - see contact_template.php for an example.
|
protected $wrapper = null; // holds template/key value of the currently used wrapper (if any) - see contact_template.php for an example.
|
||||||
|
|
||||||
|
protected $override = false;
|
||||||
/**
|
/**
|
||||||
* Storage for shortcode values
|
* Storage for shortcode values
|
||||||
* @var e_vars
|
* @var e_vars
|
||||||
@@ -1327,7 +1359,8 @@ class e_shortcode
|
|||||||
* Startup code for child class
|
* Startup code for child class
|
||||||
*/
|
*/
|
||||||
public function init() {}
|
public function init() {}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets wrapper id (to be retrieved from the registry while parsing)
|
* Sets wrapper id (to be retrieved from the registry while parsing)
|
||||||
* Example e107::getScBatch('contact')->wrapper('contact/form');
|
* Example e107::getScBatch('contact')->wrapper('contact/form');
|
||||||
|
@@ -15,6 +15,7 @@ if(!defined('e107_INIT'))
|
|||||||
|
|
||||||
class _blank_shortcodes extends e_shortcode
|
class _blank_shortcodes extends e_shortcode
|
||||||
{
|
{
|
||||||
|
public $override = false; // when set to true, existing core/plugin shortcodes matching methods below will be overridden.
|
||||||
|
|
||||||
// Example: {_BLANK_CUSTOM} shortcode - available site-wide.
|
// Example: {_BLANK_CUSTOM} shortcode - available site-wide.
|
||||||
function sc__blank_custom($parm = null) // Naming: "sc_" + [plugin-directory] + '_uniquename'
|
function sc__blank_custom($parm = null) // Naming: "sc_" + [plugin-directory] + '_uniquename'
|
||||||
|
Reference in New Issue
Block a user