mirror of
https://github.com/e107inc/e107.git
synced 2025-07-14 11:36:21 +02:00
Global shortcode override improvements, batch override examples added (phpDoc), work in progress, testing phase
This commit is contained in:
@ -824,39 +824,38 @@ class system_tools
|
|||||||
$scList = '';
|
$scList = '';
|
||||||
|
|
||||||
$fList = $f->get_files(e_CORE.'override/shortcodes/single', '\.php$');
|
$fList = $f->get_files(e_CORE.'override/shortcodes/single', '\.php$');
|
||||||
|
$scList = array();
|
||||||
if(count($fList))
|
if(count($fList))
|
||||||
{
|
{
|
||||||
$tmp = array();
|
|
||||||
foreach($fList as $file)
|
foreach($fList as $file)
|
||||||
{
|
{
|
||||||
$tmp[] = strtoupper(substr($file['fname'], 0, -4));
|
$scList[] = strtoupper(substr($file['fname'], 0, -4));
|
||||||
}
|
}
|
||||||
$scList = implode(',', $tmp);
|
$scList = implode(',', $scList);
|
||||||
unset($tmp);
|
|
||||||
}
|
}
|
||||||
$config->set('sc_override', $scList)->save(false);
|
$config->set('sc_override', $scList)->save(false);
|
||||||
|
|
||||||
|
// core batch overrides
|
||||||
$fList = $f->get_files(e_CORE.'override/shortcodes/batch', '\.php$');
|
$fList = $f->get_files(e_CORE.'override/shortcodes/batch', '\.php$');
|
||||||
|
$scList = array();
|
||||||
if(count($fList))
|
if(count($fList))
|
||||||
{
|
{
|
||||||
$tmp = array();
|
|
||||||
foreach($fList as $file)
|
foreach($fList as $file)
|
||||||
{
|
{
|
||||||
$tmp[] = substr($file['fname'], 0, -4);
|
$scList[] = substr($file['fname'], 0, -4);
|
||||||
}
|
}
|
||||||
$scList = implode(',', $tmp);
|
$scList = implode(',', $scList);
|
||||||
unset($tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->set('sc_batch_override', $scList)->save(false);
|
$config->set('sc_batch_override', $scList)->save(false);
|
||||||
//$pref['sc_override'] = $scList;
|
//$pref['sc_override'] = $scList;
|
||||||
//save_prefs();
|
//save_prefs();
|
||||||
// $mes->add(DBLAN_57.':<br />'.$pref['sc_override'], E_MESSAGE_SUCCESS);
|
// $mes->add(DBLAN_57.':<br />'.$pref['sc_override'], E_MESSAGE_SUCCESS);
|
||||||
// FIXME lan
|
// FIXME lan
|
||||||
e107::getRender()->tablerender(
|
e107::getRender()->tablerender(
|
||||||
DBLAN_56, DBLAN_57.': '
|
'<strong>'.DBLAN_56, DBLAN_57.':</strong> '
|
||||||
.($config->get('sc_override') ? '<br />'.$config->get('sc_override') : '(empty)')
|
.($config->get('sc_override') ? '<br />'.$config->get('sc_override') : '(empty)')
|
||||||
.'<br />Batch shortcodes: '
|
.'<br /><br /><strong>Batch shortcodes:</strong>'
|
||||||
.($config->get('sc_batch_override') ? '<br />'.$config->get('sc_batch_override') : '(empty)')
|
.($config->get('sc_batch_override') ? '<br />'.$config->get('sc_batch_override') : '(empty)')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,24 @@ class e_parse_shortcode
|
|||||||
/**
|
/**
|
||||||
* Get registered SC object
|
* Get registered SC object
|
||||||
* Normally you would use the proxy of this method - e107::getScBatch()
|
* Normally you would use the proxy of this method - e107::getScBatch()
|
||||||
* DRAFT!
|
* Global File Override ClassName/Path examples:
|
||||||
|
* 1. Core signup shortcodes
|
||||||
|
* - 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
|
||||||
|
* - Origin Location: plugins/gallery/e_shortcode.php
|
||||||
|
* - File Override ClassName: override_gallery_shortcodes
|
||||||
|
* - File Override Location: core/override/shortcodes/batch/gallery_shortcodes.php
|
||||||
|
*
|
||||||
|
* 3. Plugin 'forum' regular shortcode batch
|
||||||
|
* - Origin ClassName: plugin_forum_view_shortcodes
|
||||||
|
* - 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
|
||||||
*
|
*
|
||||||
* <code><?php
|
* <code><?php
|
||||||
* // simple use
|
* // simple use
|
||||||
@ -263,18 +280,19 @@ class e_parse_shortcode
|
|||||||
public function getScObject($className, $pluginName = null, $overrideClass = null)
|
public function getScObject($className, $pluginName = null, $overrideClass = null)
|
||||||
{
|
{
|
||||||
if(trim($className)==""){ return; }
|
if(trim($className)==""){ return; }
|
||||||
|
|
||||||
$_class_fname = $className;
|
$_class_fname = $className;
|
||||||
|
if($pluginName === TRUE)
|
||||||
$globalOverride = false;
|
|
||||||
if(null === $overrideClass && in_array($className, $this->scBatchOverride))
|
|
||||||
{
|
{
|
||||||
$className = 'override_'.$className;
|
$pluginName = str_replace("_shortcodes","",$className);
|
||||||
$globalOverride = true;
|
}
|
||||||
|
elseif(is_string($pluginName))
|
||||||
|
{
|
||||||
|
$className = 'plugin_'.$pluginName.'_'.str_replace('/', '_', $className);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$globalOverride = $this->isBatchOverride($className);
|
||||||
|
|
||||||
|
|
||||||
// forced override
|
// forced override
|
||||||
if($overrideClass)
|
if($overrideClass)
|
||||||
{
|
{
|
||||||
@ -294,29 +312,42 @@ class e_parse_shortcode
|
|||||||
$className = $overrideClass;
|
$className = $overrideClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif(is_string($pluginName))
|
|
||||||
{
|
|
||||||
$className = 'plugin_'.$pluginName.'_'.str_replace('/', '_', $className);
|
|
||||||
}
|
|
||||||
elseif($pluginName === TRUE)
|
|
||||||
{
|
|
||||||
$pluginName = str_replace("_shortcodes","",$className);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isScClass($className)) // Includes global Shortcode Classes. ie. e_shortcode.php
|
|
||||||
{
|
|
||||||
return $this->scClasses[$className];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$pluginName)
|
if(!$pluginName)
|
||||||
{
|
{
|
||||||
$path = ($globalOverride ? e_CORE.'override/shortcodes/batch/' : e_CORE.'shortcodes/batch/').$_class_fname.'.php';
|
if(!$globalOverride)
|
||||||
|
{
|
||||||
|
$path = e_CORE.'shortcodes/batch/'.$_class_fname.'.php';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$path = e_CORE.'override/shortcodes/batch/'.$_class_fname.'.php';
|
||||||
|
$className = 'override_'.$className;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// BC - required.
|
if(!$globalOverride)
|
||||||
$pathBC = e_PLUGIN.$pluginName.'/';
|
{
|
||||||
$path = (is_readable($pathBC.$_class_fname.'.php') ? $pathBC : e_PLUGIN.$pluginName.'/shortcodes/batch/').$_class_fname.'.php';
|
// do nothing if it's e_shortcode batch global
|
||||||
|
if($pluginName.'_shortcodes' !== $className)
|
||||||
|
{
|
||||||
|
// BC - required.
|
||||||
|
$pathBC = e_PLUGIN.$pluginName.'/';
|
||||||
|
$path = (is_readable($pathBC.$_class_fname.'.php') ? $pathBC : e_PLUGIN.$pluginName.'/shortcodes/batch/').$_class_fname.'.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$path = e_CORE.'override/shortcodes/batch/'.$pluginName.'/'.$_class_fname.'.php';
|
||||||
|
$className = 'override_'.$className;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Includes global Shortcode Classes (e_shortcode.php) or already loaded batch
|
||||||
|
if ($this->isScClass($className))
|
||||||
|
{
|
||||||
|
return $this->scClasses[$className];
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it already exists - don't include it again.
|
// If it already exists - don't include it again.
|
||||||
@ -456,19 +487,37 @@ class e_parse_shortcode
|
|||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($pref as $key => $val)
|
foreach ($pref as $key => $val)
|
||||||
{
|
{
|
||||||
$path = e_PLUGIN.$key.'/e_shortcode.php';
|
$globalOverride = $this->isBatchOverride($key.'_shortcodes');
|
||||||
$classFunc = $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';
|
||||||
|
}
|
||||||
|
|
||||||
if (!include_once($path))
|
if (!include_once($path))
|
||||||
{
|
{
|
||||||
continue;
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->registerClassMethods($classFunc, $path, false);
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->registerClassMethods($classFunc, $path, false);
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -555,8 +604,10 @@ class e_parse_shortcode
|
|||||||
return in_array($code, $this->scOverride);
|
return in_array($code, $this->scOverride);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isBatchOverride($name)
|
||||||
|
{
|
||||||
|
return in_array($name, $this->scBatchOverride);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the shortcodes in some text
|
* Parse the shortcodes in some text
|
||||||
|
Reference in New Issue
Block a user