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

Issue #183: $sc_style not working with new SC batch methods:

- Wrapper support added (shortcode batches only, needs explicit
wrapper registration)
- new $SC_STYLE - not global, same format as the new wrapper
- $sc_style is deprecated now
- more detailed info in GitHub comments of the issue
This commit is contained in:
SecretR
2013-04-28 19:14:14 +03:00
parent 31f096cd14
commit 3ec9e7487e
4 changed files with 152 additions and 31 deletions

View File

@@ -164,8 +164,10 @@ if(SITECONTACTINFO && $CONTACT_INFO)
if(isset($pref['sitecontacts']) && $pref['sitecontacts'] != 255)
{
// require_once(e_CORE."shortcodes/batch/contact_shortcodes.php");
$contact_shortcodes = e107::getScBatch('contact');
// Wrapper support
$contact_shortcodes->wrapper('contact/form');
$text = $tp->parseTemplate($CONTACT_FORM, TRUE, $contact_shortcodes);
if(trim($text) != "")

View File

@@ -40,28 +40,24 @@ $CONTACT_TEMPLATE['menu'] = '
';
///XXX This.....
// Option I - new sc style variable and format, global available per shortcode (mode also applied)
// sc_style is uppercased now - distinguished from the legacy $sc_style variable and compatible with the new template standards, we deprecate $sc_style soon
$sc_style['CONTACT_EMAIL_COPY']['pre'] = "<tr><td>";
$sc_style['CONTACT_EMAIL_COPY']['post'] = LANCONTACT_07."</td></tr>";
$sc_style['CONTACT_PERSON']['pre'] = "<tr><td>".LANCONTACT_14."<br /> ";
$sc_style['CONTACT_PERSON']['post'] = "</td></tr>";
$sc_style['CONTACT_IMAGECODE']['pre'] = "<tr><td>".LANCONTACT_16."<br />";
$sc_style['CONTACT_IMAGECODE']['post'] = "";
$sc_style['CONTACT_IMAGECODE_INPUT']['pre'] = "";
$sc_style['CONTACT_IMAGECODE_INPUT']['post'] = "</td></tr>";
$SC_STYLE['CONTACT_EMAIL_COPY'] = "<tr><td>{---}".LANCONTACT_07."</td></tr>";
$SC_STYLE['CONTACT_PERSON'] = "<tr><td>".LANCONTACT_14."<br />{---}</td></tr>";
$SC_STYLE['CONTACT_IMAGECODE'] = "<tr><td>".LANCONTACT_16."<br />{---}";
$SC_STYLE['CONTACT_IMAGECODE_INPUT'] = "{---}</td></tr>";
//XXX Becomes This..... ( New Format for v2 - losing the pre/post and using a shortcode 'wildcard' that can be split later)
// Option II - Wrappers, used ONLY with batch objects, requires explicit wrapper registration
// In this case (see contact.php) e107::getScBatch('contact')->wrapper('contact/form')
// Only one Option is used - WRAPPER > SC_STYLE
$CONTACT_WRAPPER['form']['CONTACT_IMAGECODE'] = "<tr><td>".LANCONTACT_16."<br />{---}";
$CONTACT_WRAPPER['form']['CONTACT_IMAGECODE_INPUT'] = "{---}</td></tr>";
$CONTACT_WRAPPER['form']['CONTACT_EMAIL_COPY'] = "<tr><td>{---}".LANCONTACT_07."</td></tr>";
$CONTACT_WRAPPER['form']['CONTACT_PERSON'] = "<tr><td>".LANCONTACT_14."<br />{---}</td></tr>";
// $CONTACT_WRAPPER['form']['CONTACT_IMAGECODE'] = "<tr><td>".LANCONTACT_16."<br />{---}";
// $CONTACT_WRAPPER['form']['CONTACT_IMAGECODE_INPUT'] = "{---}</td></tr>";
//
// $CONTACT_WRAPPER['form']['CONTACT_EMAIL_COPY'] = "<tr><td>{---}".LANCONTACT_07."</td></tr>";
// $CONTACT_WRAPPER['form']['CONTACT_PERSON'] = "<tr><td>".LANCONTACT_14."<br />{---}</td></tr>";
$CONTACT_TEMPLATE['form'] = "

View File

@@ -2022,6 +2022,50 @@ class e107
return (is_array($ret_plug) ? array_merge($ret_plug, $ret) : $ret);
}
/**
* Register sc_style registry
* @param string $templateId e.g. 'contact/form' or 'contact' for all contact template wrappers
* @param string $scName [optional] shortcode name - if provided, wrapper (string) for the corresponding code will be returned
* @return array|string
*/
public static function templateWrapper($templateId, $scName = null)
{
if(!$templateId) return array();
list($templateId, $templateKey) = explode('/', $templateId, 2);
$wrapperRegPath = 'templates/wrapper/'.$templateId;
$wrapper = self::getRegistry($wrapperRegPath);
if(empty($wrapper) || !is_array($wrapper)) $wrapper = array();
if($templateKey) $wrapper = (isset($wrapper[$templateKey]) ? $wrapper[$templateKey] : array());
if(null !== $scName)
{
$scName = strtoupper($scName);
return isset($wrapper[$scName]) ? $wrapper[$scName] : '';
}
return $wrapper;
}
/**
* Retrieve/set sc_style array (global shortcode wrapper)
* @param array $set template defined $sc_style, will be merged with current registry content
* @return array
*/
public static function scStyle($set = null)
{
$_sc_style = self::getRegistry('shortcodes/sc_style');
if(!is_array($_sc_style)) $_sc_style = array();
if(is_array($set) && !empty($set))
{
self::setRegistry('shortcodes/sc_style', array_merge($_sc_style, $set));
}
return $_sc_style;
}
/**
* Get Template Info array.
@@ -2132,6 +2176,7 @@ class e107
$var_info = strtoupper($id).'_INFO';
$wrapper = strtoupper($id).'_WRAPPER'; // see contact_template.php
$wrapperRegPath = 'templates/wrapper/'.$id;
//FIXME XXX URGENT - Add support for _WRAPPER and $sc_style BC. - save in registry and retrieve in getScBatch()?
// Use: list($pre,$post) = explode("{---}",$text,2);
@@ -2140,6 +2185,18 @@ class e107
{
(deftrue('E107_DEBUG_LEVEL') ? include_once($path) : @include_once($path));
self::setRegistry($regPath, (isset($$var) ? $$var : array()));
// sc_style not a global anymore and uppercase
if(isset($SC_STYLE))
{
self::scStyle($SC_STYLE);
}
// ID_WRAPPER support
if(isset($$wrapper) && !empty($$wrapper) && is_array($$wrapper))
{
self::setRegistry($wrapperRegPath, $$wrapper);
}
}
if(null === self::getRegistry($regPathInfo))
{

View File

@@ -73,6 +73,18 @@ class e_parse_shortcode
* @var e_vars
*/
protected $eVars = null;
/**
* Wrappers array for the current parsing cycle, see contact_template.php and $CONTACT_WRAPPER variable
* @var array
*/
protected $wrappers = array();
/**
* Former $sc_style global variable. Internally used - performance reasons
* @var array
*/
protected $sc_style = array();
function __construct()
{
@@ -665,6 +677,8 @@ class e_parse_shortcode
*/
function parseCodes($text, $useSCFiles = true, $extraCodes = null, $eVars = null)
{
global $sc_style; //legacy, will be removed soon, use the non-global $SC_STYLE instead
$saveParseSCFiles = $this->parseSCFiles; // In case of nested call
$this->parseSCFiles = $useSCFiles;
$saveVars = $this->eVars; // In case of nested call
@@ -672,11 +686,26 @@ class e_parse_shortcode
$this->eVars = $eVars;
$this->addedCodes = NULL;
// former $sc_style - do it once here and not on every doCode loop - performance
$this->sc_style = e107::scStyle();
if(isset($sc_style) && is_array($sc_style))
{
$this->sc_style = array_merge($sc_style, $this->sc_style);
}
//object support
if (is_object($extraCodes))
{
$this->addedCodes = &$extraCodes;
// TEMPLATEID_WRAPPER support - see contact template
// must be registered in e_shortcode object (batch) via wrapper() method before parsing
// Do it only once per parsing cylcle and not on every doCode() loop - performance
if(method_exists($this->addedCodes, 'wrapper'))
{
$this->wrappers = e107::templateWrapper($this->addedCodes->wrapper());
}
/*
$classname = get_class($extraCodes);
@@ -717,8 +746,8 @@ class e_parse_shortcode
*/
function doCode($matches)
{
global $pref, $e107cache, $menu_pref, $sc_style, $parm, $sql;
// XXX remove all globals, $sc_style removed
global $pref, $e107cache, $menu_pref, $parm, $sql;
$parmArray = false;
@@ -859,7 +888,8 @@ class e_parse_shortcode
// XXX - removal candidate - I really think it should be done manually (outside the parser)
// via e107::getScBatch(name)->setParserVars($eVars);
// $this->callScFunc($_class, 'setParserVars', $this->eVars);
$wrapper = $this->callScFunc($_class, 'wrapper', null);
$ret = $this->callScFuncA($_class, $_method, array($parm, $sc_mode));
/*if (method_exists($this->scClasses[$_class], $_method))
@@ -962,20 +992,41 @@ class e_parse_shortcode
if (isset($ret) && ($ret != '' || is_numeric($ret)))
{
//if $sc_mode exists, we need it to parse $sc_style
if ($sc_mode)
// Wrapper support - see contact_template.php
if(isset($this->wrappers[$code]) && !empty($this->wrappers[$code]))
{
$code = $code.'|'.$sc_mode;
list($pre, $post) = explode("{---}", $this->wrappers[$code], 2);
$ret = $pre.$ret.$post;
}
if (isset($sc_style) && is_array($sc_style) && array_key_exists($code, $sc_style))
else
{
if (isset($sc_style[$code]['pre']))
//if $sc_mode exists, we need it to parse $sc_style
if ($sc_mode)
{
$ret = $sc_style[$code]['pre'].$ret;
$code = $code.'|'.$sc_mode;
}
if (isset($sc_style[$code]['post']))
if (is_array($this->sc_style) && array_key_exists($code, $this->sc_style))
{
$ret = $ret.$sc_style[$code]['post'];
$pre = $post = '';
// old way - pre/post keys
if(is_array($this->sc_style[$code]))
{
if (isset($this->sc_style[$code]['pre']))
{
$pre = $this->sc_style[$code]['pre'];
}
if (isset($this->sc_style[$code]['post']))
{
$post = $ret.$this->sc_style[$code]['post'];
}
}
// new way - same format as wrapper
else
{
list($pre, $post) = explode("{---}", $this->sc_style[$code], 2);
}
$ret = $pre.$ret.$post;
}
}
}
@@ -1106,7 +1157,7 @@ class e_shortcode
protected $mode = 'view'; // or edit. Used within shortcodes for form elements vs values only.
protected $wrapper = array(); // hold values of pre/post styling for each shortcode - 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.
/**
* Storage for shortcode values
@@ -1123,6 +1174,21 @@ class e_shortcode
* Startup code for child class
*/
public function init() {}
/**
* 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
*/
public function wrapper($id = null)
{
if(null === $id) return $this->wrapper;
if(false === $id) $id = null;
$this->wrapper = $id;
return $this;
}
/**
* Set external array data to be used in the batch