1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 06:07:32 +02:00

Scan overrides looking at the proper location for override batch/shortcode; shortcode handler now respects override settings; admin shortcodes are not auto loaded anymore

This commit is contained in:
SecretR
2013-02-08 16:49:57 +02:00
parent d6825155ea
commit 65d8985571
2 changed files with 84 additions and 38 deletions

View File

@@ -819,24 +819,46 @@ class system_tools
$mes = e107::getMessage(); $mes = e107::getMessage();
$f = e107::getFile(); $f = e107::getFile();
$config = e107::getConfig();
$scList = ''; $scList = '';
$fList = $f->get_files(e_CORE.'override/shortcodes', '\.sc$'); $fList = $f->get_files(e_CORE.'override/shortcodes/single', '\.php$');
if(count($fList)) if(count($fList))
{ {
$tmp = array(); $tmp = array();
foreach($fList as $file) foreach($fList as $file)
{ {
$tmp[] = strtoupper(substr($file['fname'], 0, -3)); $tmp[] = strtoupper(substr($file['fname'], 0, -4));
} }
$scList = implode(',', $tmp); $scList = implode(',', $tmp);
unset($tmp); unset($tmp);
} }
$pref['sc_override'] = $scList; $config->set('sc_override', $scList)->save(false);
save_prefs();
$fList = $f->get_files(e_CORE.'override/shortcodes/batch', '\.php$');
if(count($fList))
{
$tmp = array();
foreach($fList as $file)
{
$tmp[] = substr($file['fname'], 0, -4);
}
$scList = implode(',', $tmp);
unset($tmp);
}
$config->set('sc_batch_override', $scList)->save(false);
//$pref['sc_override'] = $scList;
//save_prefs();
// $mes->add(DBLAN_57.':<br />'.$pref['sc_override'], E_MESSAGE_SUCCESS); // $mes->add(DBLAN_57.':<br />'.$pref['sc_override'], E_MESSAGE_SUCCESS);
e107::getRender()->tablerender(DBLAN_56, DBLAN_57.':<br />'.$pref['sc_override']); // FIXME lan
e107::getRender()->tablerender(
DBLAN_56, DBLAN_57.': '
.($config->get('sc_override') ? '<br />'.$config->get('sc_override') : '(empty)')
.'<br />Batch shortcodes: '
.($config->get('sc_batch_override') ? '<br />'.$config->get('sc_batch_override') : '(empty)')
);
} }
/** /**

View File

@@ -67,7 +67,8 @@ class e_parse_shortcode
protected $addedCodes = NULL; // Pointer to a class or array to be used on a single call 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 $registered_codes = array(); // Shortcodes added by plugins TODO make it private
protected $scClasses = array(); // Batch shortcode classes - TODO make it private protected $scClasses = array(); // Batch shortcode classes - TODO make it private
protected $scOverride = array(); // Array of codes found in override/ dir protected $scOverride = array(); // Array of codes found in override/shortcodes dir
protected $scBatchOverride = array(); // Array of codes found in override/shortcodes/batch dir
/** /**
* @var e_vars * @var e_vars
*/ */
@@ -81,7 +82,7 @@ class e_parse_shortcode
$this->loadThemeShortcodes(); $this->loadThemeShortcodes();
$this->loadPluginShortcodes(); $this->loadPluginShortcodes();
$this->loadPluginSCFiles(); $this->loadPluginSCFiles();
$this->loadCoreShortcodes(); //$this->loadCoreShortcodes(); DEPRECATED
} }
@@ -263,11 +264,18 @@ class e_parse_shortcode
{ {
if(trim($className)==""){ return; } if(trim($className)==""){ return; }
$_class_fname = $className; $_class_fname = $className;
$globalOverride = false;
if(null === $overrideClass && in_array($className, $this->scBatchOverride))
{
$className = 'override_'.$className;
$globalOverride = true;
}
// plugin override // forced override
if($overrideClass) if($overrideClass)
{ {
if(true === $overrideClass) if(true === $overrideClass)
@@ -299,15 +307,17 @@ class e_parse_shortcode
{ {
return $this->scClasses[$className]; return $this->scClasses[$className];
} }
$path = ($pluginName ? e_PLUGIN.$pluginName.'/shortcodes/batch/' : e_CORE.'shortcodes/batch/').$_class_fname.'.php';
$pathBC = e_PLUGIN.$pluginName.'/'.$_class_fname.'.php'; if(!$pluginName)
if(is_readable($pathBC)) // BC - required.
{ {
$path = $pathBC; $path = ($globalOverride ? e_CORE.'override/shortcodes/batch/' : e_CORE.'shortcodes/batch/').$_class_fname.'.php';
} }
else
{
// BC - required.
$pathBC = e_PLUGIN.$pluginName.'/';
$path = (is_readable($pathBC.$_class_fname.'.php') ? $pathBC : e_PLUGIN.$pluginName.'/shortcodes/batch/').$_class_fname.'.php';
}
// If it already exists - don't include it again. // If it already exists - don't include it again.
if (class_exists($className, false)) // don't allow __autoload() if (class_exists($className, false)) // don't allow __autoload()
@@ -355,9 +365,21 @@ class e_parse_shortcode
{ {
$code = strtoupper(trim($code)); $code = strtoupper(trim($code));
$this->registered_codes[$code]['type'] = 'override'; $this->registered_codes[$code]['type'] = 'override';
$this->registered_codes[$code]['path'] = e_CORE.'override/shortcodes/single/';
$this->registered_codes[$code]['function'] = 'override_'.strtolower($code).'_shortcode';
$this->scOverride[] = $code; $this->scOverride[] = $code;
} }
} }
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;
}
}
return $this; return $this;
} }
@@ -483,26 +505,27 @@ class e_parse_shortcode
return $this; return $this;
} }
/** /**
* DEPRECATED admin_shortcodes now loaded inside admin parse function (see boot.php)
* Register Core Shortcode Batches. * Register Core Shortcode Batches.
* FIXME - make it smarter - currently loaded all the time (even on front-end) * FIXME - make it smarter - currently loaded all the time (even on front-end)
* *
* @return e_parse_shortcode * @return e_parse_shortcode
*/ */
function loadCoreShortcodes() // function loadCoreShortcodes()
{ // {
$coreBatchList = array('admin_shortcodes'); // $coreBatchList = array('admin_shortcodes');
//
foreach ($coreBatchList as $cb) // foreach ($coreBatchList as $cb)
{ // {
$path = e_CORE.'shortcodes/batch/'.$cb.".php"; // $path = e_CORE.'shortcodes/batch/'.$cb.".php";
if (include_once($path)) // if (include_once($path))
{ // {
$this->registerClassMethods($cb, $path); // $this->registerClassMethods($cb, $path);
} // }
} // }
return $this; // return $this;
} // }
function isRegistered($code) function isRegistered($code)
{ {
@@ -727,11 +750,12 @@ class e_parse_shortcode
}*/ }*/
break; break;
case 'override':
case 'func': case 'func':
//It is a function, so include the file and call the function //It is a function, so include the file and call the function
$_function = $this->registered_codes[$code]['function']; $_function = $this->registered_codes[$code]['function'];
if ($this->registered_codes[$code]['path']) if (!function_exists($_function) && $this->registered_codes[$code]['path'])
{ {
include_once($this->registered_codes[$code]['path'].strtolower($code).'.php'); include_once($this->registered_codes[$code]['path'].strtolower($code).'.php');
@@ -746,9 +770,9 @@ class e_parse_shortcode
$scFile = e_PLUGIN.strtolower($this->registered_codes[$code]['path']).'/'.strtolower($code).'.sc'; $scFile = e_PLUGIN.strtolower($this->registered_codes[$code]['path']).'/'.strtolower($code).'.sc';
break; break;
case 'override': // case 'override':
$scFile = e_CORE.'override/shortcodes/'.strtolower($code).'.sc'; // $scFile = e_CORE.'override/shortcodes/'.strtolower($code).'.sc';
break; // break;
case 'theme': case 'theme':
$scFile = THEME.strtolower($code).'.sc'; $scFile = THEME.strtolower($code).'.sc';