diff --git a/class2.php b/class2.php
index 6933ab3cf..c65899290 100644
--- a/class2.php
+++ b/class2.php
@@ -717,7 +717,7 @@ $sql -> db_Mark_Time('Start: Misc resources. Online user tracking, cache');
$e107cache = e107::getCache(); //TODO - find & replace $e107cache, $e107->ecache
//DEPRECATED, BC, call the method only when needed, $e107->override caught by __get()
-$override = e107::getSingleton('override', e_HANDLER.'override_class.php'); //TODO - find & replace $override, $e107->override
+$override = e107::getSingleton('override', true); //TODO - find & replace $override, $e107->override
//DEPRECATED, BC, call the method only when needed, $e107->user_class caught by __get()
$e_userclass = e107::getUserClass(); //TODO - find & replace $e_userclass, $e107->user_class
diff --git a/e107_core/shortcodes/batch/news_shortcodes.php b/e107_core/shortcodes/batch/news_shortcodes.php
index 802a9aa24..47cbd3e5d 100644
--- a/e107_core/shortcodes/batch/news_shortcodes.php
+++ b/e107_core/shortcodes/batch/news_shortcodes.php
@@ -14,49 +14,27 @@
*/
if (!defined('e107_INIT')) { exit; }
-//include_once(e_HANDLER.'shortcode_handler.php');
-/*
-$codes = array(
-'newstitle', 'newsbody', 'newsicon','newsauthor', 'newscomments',
-'trackback', 'newsheader', 'newscategory', 'newsdate', 'newscommentlink',
-'newscommentcount', 'emailicon', 'printicon', 'pdficon', 'newsid', 'adminoptions',
-'extended', 'captionclass', 'admincaption', 'adminbody', 'newssummary',
-'newsthumbnail', 'newsimage', 'sticky_icon', 'newstitlelink', 'newscaticon', 'newsinfo'
-);
-*/
-
-$codes = array();
-/*
-$tmp = get_class_methods('news_shortcodes');
-foreach($tmp as $c)
-{
- if(strpos($c, 'sc_') === 0)
- {
- $codes[] = substr($c, 3);
- }
-}
-unset($tmp);
-*/
+/* DEPRECATED
register_shortcode('news_shortcodes', TRUE);
initShortcodeClass('news_shortcodes');
+*/
-class news_shortcodes
+e107::getScParser()->registerShortcode('news_shortcodes', true)
+ ->initShortcodeClass('news_shortcodes');
+
+class news_shortcodes extends e_shortcode
{
- var $news_item, $param, $e107;
-
- function news_shortcodes()
+ //protected $news_item; - shouldn't be set - see __set/__get methods of e_shortcode & news::render_newsitem()
+ protected $e107;
+ //protected $param; - shouldn't be set - see __set/__get methods of e_shortcode & news::render_newsitem()
+
+ function __construct($eVars = null)
{
+ parent::__construct($eVars);
$this->e107 = e107::getInstance();
}
- function loadNewsItem()
- {
- $e107 = e107::getInstance();
- $e107->tp->e_sc->scClasses['news_shortcodes']->news_item = getcachedvars('current_news_item');
- $e107->tp->e_sc->scClasses['news_shortcodes']->param = getcachedvars('current_news_param');
- }
-
function sc_newstitle()
{
return $this->e107->tp->toHTML($this->news_item['news_title'], TRUE, 'TITLE');
diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php
index a972f8476..fb34fab51 100644
--- a/e107_handlers/e107_class.php
+++ b/e107_handlers/e107_class.php
@@ -158,6 +158,7 @@ class e107
'e_parse' => '{e_HANDLER}e_parse_class.php',
'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php',
'e_ranks' => '{e_HANDLER}e_ranks_class.php',
+ 'e_shortcode' => '{e_HANDLER}shortcode_handler.php',
'e_upgrade' => '{e_HANDLER}e_upgrade_class.php',
'e_user_model' => '{e_HANDLER}user_model.php',
'e_user' => '{e_HANDLER}user_model.php',
@@ -168,6 +169,7 @@ class e107
'ecache' => '{e_HANDLER}cache_handler.php',
'news' => '{e_HANDLER}news_class.php',
'notify' => '{e_HANDLER}notify_class.php',
+ 'override' => '{e_HANDLER}override_class.php',
'redirection' => '{e_HANDLER}redirection_class.php',
'sitelinks' => '{e_HANDLER}sitelinks_class.php',
'themeHandler' => '{e_HANDLER}theme_handler.php',
@@ -859,12 +861,14 @@ class e107
/**
* Retrieve registered sc object (batch) by class name
+ * Note - '_shortcodes' part of the class is added by the method
+ *
*
* @return e_shortcode
*/
- public static function getScObject($className)
+ public static function getScBatch($className)
{
- return self::getScParser($className);
+ return self::getScParser()->getScObject($className.'_shortcodes');
}
/**
diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php
index 3b34ce74c..4d6878f6c 100644
--- a/e107_handlers/e_parse_class.php
+++ b/e107_handlers/e_parse_class.php
@@ -2140,7 +2140,9 @@ class e_vars
*/
public function __set($key, $value)
{
- $this->vars[$key] = $value;
+ // Unset workaround - PHP < 5.1.0
+ if(null === $value) unset($this->vars[$key]);
+ else $this->vars[$key] = $value;
}
/**
diff --git a/e107_handlers/news_class.php b/e107_handlers/news_class.php
index 224001d6f..970f4f44e 100644
--- a/e107_handlers/news_class.php
+++ b/e107_handlers/news_class.php
@@ -30,8 +30,7 @@ class news {
$tp = e107::getParser();
$sql = e107::getDb();
- require_once (e_HANDLER."message_handler.php");
- $emessage = eMessage::getInstance();
+ $emessage = e107::getMessage();
$error = false;
if(empty($news['news_title']))
@@ -498,15 +497,15 @@ class news {
function render_newsitem($news, $mode = 'default', $n_restrict = '', $NEWS_TEMPLATE = '', $param = array())
{
- global $e107, $tp, $sql, $override, $pref, $ns, $NEWSSTYLE, $NEWSLISTSTYLE, $news_shortcodes, $loop_uid;
- if ($override_newsitem = $override -> override_check('render_newsitem')) {
+ global $NEWSSTYLE, $NEWSLISTSTYLE;
+
+ if ($override_newsitem = e107::getSingleton('override', true)->override_check('render_newsitem')) {
$result = call_user_func($override_newsitem, $news, $mode, $n_restrict, $NEWS_TEMPLATE, $param);
if ($result == 'return')
{
return;
}
}
- if (!is_object($e107->tp)) $e107->tp = new e_parse;
if ($n_restrict == 'userclass')
{
@@ -587,12 +586,19 @@ class news {
}
}
}
- $loop_uid = $news['news_author'];
+ //$loop_uid = $news['news_author']; - no references found
require_once(e_CORE.'shortcodes/batch/news_shortcodes.php');
+ /* DEPRECATED
setScVar('news_shortcodes', 'news_item', $news);
setScVar('news_shortcodes', 'param', $param);
- $text = $e107->tp->parseTemplate($NEWS_PARSE, true);
+ */
+ // Retrieve batch sc object, set required vars
+ e107::getScBatch('news')
+ ->setScVar('news_item', $news)
+ ->setScVar('param', $param);
+
+ $text = e107::getParser()->parseTemplate($NEWS_PARSE, true);
if ($mode == 'return')
{
@@ -608,9 +614,7 @@ class news {
//@TDODO deprecated?
function make_xml_compatible($original)
{
- global $e107;
- if (!is_object($e107->tp)) $e107->tp = new e_parse;
- $original = $e107->tp->toHTML($original, TRUE);
+ $original = e107::getParser()->toHTML($original, TRUE);
$original = str_replace('£', '£', $original);
$original = str_replace('©', '(c)', $original);
return htmlspecialchars($original, ENT_COMPAT, CHARSET);
diff --git a/e107_handlers/shortcode_handler.php b/e107_handlers/shortcode_handler.php
index e0f0fecd2..4685fc6a2 100644
--- a/e107_handlers/shortcode_handler.php
+++ b/e107_handlers/shortcode_handler.php
@@ -14,6 +14,17 @@
if (!defined('e107_INIT')) { exit; }
+/**
+ *
+ * @package e107
+ * @subpackage e107_handlers
+ * @version $Id$
+ * @author e107inc
+ *
+ * e_parse_shortcode - shortcode parser/manager, former e_shortcode
+ * e_shortcode - abstract batch class
+ */
+
/**
* FIXME: to be removed
*/
@@ -207,7 +218,7 @@ class e_parse_shortcode
{
if(isset($this->scClasses[$className]))
{
- return call_user_func(array($this->scClasses[$className], $scFuncName), $param);
+ return $this->scClasses[$className];
}
// TODO - throw exception?
return null;
@@ -349,7 +360,7 @@ class e_parse_shortcode
* Register Core Shortcode Batches.
* FIXME - currently loaded all the time (even on front-end)
*
- * @return void
+ * @return e_parse_shortcode
*/
function loadCoreShortcodes()
{
@@ -363,6 +374,7 @@ class e_parse_shortcode
$this->registerClassMethods($cb, $path);
}
}
+ return $this;
}
function isRegistered($code)
@@ -710,24 +722,47 @@ class e_shortcode
protected $eVars = null;
/**
- * Storage for external values
+ * Storage for shortcode values
* @var e_vars
*/
protected $scVars = null;
public function __construct($eVars = null)
{
- $this->eVars = $eVars;
+ $this->setVars($eVars);
$this->scVars = new e_vars();
}
+ /**
+ * Set external simple parser object
+ *
+ * @param e_vars $eVars
+ * @return e_shortcode
+ */
+ public function setVars($eVars)
+ {
+ if(null === $eVars) $eVars = new e_vars();
+ $this->eVars = $eVars;
+ return $this;
+ }
+
+ /**
+ * Get external simple parser object
+ *
+ * @return e_vars
+ */
+ public function getVars()
+ {
+ return $this->eVars;
+ }
+
/**
* Add shortcode value
* e107::getScObject('class_name')->setScVar('some_property', $some_value);
*
* @param string $name
* @param mixed $value
- * @return e_parse_shortcode
+ * @return e_shortcode
*/
public function setScVar($name, $value)
{
@@ -737,7 +772,7 @@ class e_shortcode
/**
* Retrieve shortcode value
- * code>$some_value = e107::getScObject('class_name')->getScVar('some_property');
+ * $some_value = e107::getScObject('class_name')->getScVar('some_property');
*
* @param string $name
* @return mixed
@@ -746,4 +781,77 @@ class e_shortcode
{
return $this->scVars->$name;
}
+
+ /**
+ * Check if shortcode variable is set
+ * if(e107::getScObject('class_name')->issetScVar('some_property'))
+ * {
+ * //do something
+ * }
+ *
+ * @param string $name
+ * @return boolean
+ */
+ public function issetScVar($name)
+ {
+ return isset($this->scVars->$name);
+ }
+
+ /**
+ * Unset shortcode value
+ * e107::getScObject('class_name')->unsetScVar('some_property');
+ *
+ * @param string $name
+ * @return void
+ */
+ public function unsetScVar($name)
+ {
+ $this->scVars->$name = null;
+ unset($this->scVars->$name);
+ }
+
+ /**
+ * Magic setter - bind to eVars object
+ *
+ * @param string $name
+ * @param mixed $value
+ */
+ public function __set($name, $value)
+ {
+ $this->setScVar($name, $value);
+ }
+
+ /**
+ * Magic getter - bind to eVars object
+ *
+ * @param string $name
+ * @return mixed value or null if key not found
+ */
+ public function __get($name)
+ {
+ return $this->getScVar($name);
+ }
+
+ /**
+ * Magic method - bind to eVars object
+ * NOTE: works on PHP 5.1.0+
+ *
+ * @param string $name
+ * @return boolean
+ */
+ public function __isset($name)
+ {
+ return $this->issetScVar($name);
+ }
+
+ /**
+ * Magic method - bind to eVars object
+ * NOTE: works on PHP 5.1.0+
+ *
+ * @param string $name
+ */
+ public function __unset($name)
+ {
+ $this->unsetScVar($name);
+ }
}
\ No newline at end of file