1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 11:50:30 +02:00

Closes #1484 - theme shortcodes are now registered globally by default. Shortcode handler cleanup.

This commit is contained in:
Cameron
2016-04-23 15:23:45 -07:00
parent b6f9122faa
commit b4a5a0b573

View File

@@ -100,6 +100,8 @@ class e_parse_shortcode
$this->loadPluginSCFiles();
//$this->loadCoreShortcodes(); DEPRECATED
}
/**
@@ -479,25 +481,16 @@ class e_parse_shortcode
{
global $register_sc;
// $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;
if(deftrue('e_DEVELOPER')) // experimental, could break something. - use theme shortcodes in other templates.
if(file_exists(THEME."theme_shortcodes.php"))
{
if(file_exists(THEME."theme_shortcodes.php"))
{
$classFunc = 'theme_shortcodes';
$path = THEME."theme_shortcodes.php";
include_once($path);
$this->registerClassMethods($classFunc, $path, false);
}
$classFunc = 'theme_shortcodes';
$path = THEME."theme_shortcodes.php";
include_once($path);
$this->registerClassMethods($classFunc, $path, false);
}
if (isset($register_sc) && is_array($register_sc))
if (isset($register_sc) && is_array($register_sc)) // legacy load.
{
foreach ($register_sc as $code)
{
@@ -659,33 +652,15 @@ class e_parse_shortcode
return $this;
}
/**
* DEPRECATED admin_shortcodes now loaded inside admin parse function (see boot.php)
* Register Core Shortcode Batches.
* FIXME - make it smarter - currently loaded all the time (even on front-end)
*
* @return e_parse_shortcode
*/
// function loadCoreShortcodes()
// {
// $coreBatchList = array('admin_shortcodes');
//
// foreach ($coreBatchList as $cb)
// {
// $path = e_CORE.'shortcodes/batch/'.$cb.".php";
// if (include_once($path))
// {
// $this->registerClassMethods($cb, $path);
// }
// }
// return $this;
// }
function isRegistered($code)
{
return array_key_exists($code, $this->registered_codes);
}
public function resetScClass($className, $object)
{
if(null === $object)
@@ -939,6 +914,7 @@ class e_parse_shortcode
$ret = '';
$_method = 'sc_'.strtolower($code);
// 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))
{
@@ -963,12 +939,13 @@ class e_parse_shortcode
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];
// $_path = print_a($this->backTrace,true);
//XXX $_path = print_a($this,true);
$ret = $this->addedCodes[$code];
// $_class = "n/a";
// $_function = "n/a";
$_type = 'array';
$_path = "(direct to parser)";
}
elseif (array_key_exists($code, $this->scList)) // Check to see if we've already loaded the .sc file contents
{
@@ -1093,17 +1070,21 @@ class e_parse_shortcode
$_path = $scFile;
}
}
if ($scFile && file_exists($scFile))
if(!empty($scFile))
{
$scCode = file_get_contents($scFile);
$this->scList[$code] = $scCode;
$_path = $scFile;
}
else
{
// $ret = 'Missing!';
$_path .= " MISSING!";
if(file_exists($scFile))
{
$scCode = file_get_contents($scFile);
$this->scList[$code] = $scCode;
$_path = $scFile;
}
else
{
$_path .= $scFile." MISSING!";
}
}
}
if (!isset($scCode))
@@ -1115,21 +1096,37 @@ class e_parse_shortcode
return $matches[0];
}
if (E107_DBG_SC && $scFile)
{
// if (E107_DBG_SC && $scFile)
// {
// echo (isset($scFile)) ? "<br />sc_file= ".str_replace(e_CORE.'shortcodes/single/', '', $scFile).'<br />' : '';
// echo "<br />sc= <b>$code</b>";
}
// }
}
if ($scCode)
if ($scCode) // legacy shortode to be evaluated.
{
$ret = @eval($scCode);
try
{
$ret = @eval($scCode);
}
catch (Throwable $t) { // Executed only in PHP 7, will not match in PHP 5.x
$string = print_a($scCode,true);
$string .= "<h4>Added Coded</h4>";
$string .= print_a($this->addedCodes,true);
e107::getMessage()->addDebug('Could not parse Shortcode '.$scFile.' :: {'.$code .'} '.$string);
}
catch (Exception $e)
{
echo $e->getMessage();
}
if($ret === false && E107_DEBUG_LEVEL > 0) // Error in Code.
{
$string = print_a($scCode,true);
e107::getMessage()->addDebug('Could not parse Shortcode '.$scFile.' :: {'.$code .'} '.$string);
// $string = print_a($scCode,true);
// e107::getMessage()->addDebug('Could not parse Shortcode '.$scFile.' :: {'.$code .'} '.$string);
}
}
@@ -1206,19 +1203,26 @@ class e_parse_shortcode
global $db_debug;
$other = array();
if(!empty($_type))
{
$other['type'] = $_type;
}
if($_class)
if(!empty($_class))
{
$other['class'] = $_class;
}
if(vartrue($_function))
if(!empty($_function))
{
$other['function'] = $_function;
}
if(vartrue($_path))
if(!empty($_path))
{
$other['path'] = str_replace('../','',$_path);
}
if($this->debug_legacy)
{