mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 12:20:44 +02:00
e107table class moved out of class2.php to e_render_class.php and renamed to e_render. BC fix added.
This commit is contained in:
365
class2.php
365
class2.php
@@ -792,372 +792,19 @@ if(!defined('USERTHEME') && !isset($_E107['no_theme']))
|
|||||||
$dbg->logTime('Misc Setup');
|
$dbg->logTime('Misc Setup');
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------------------------------------------//
|
//------------------------------------------------------------------------------------------------------------------------------------//
|
||||||
if (!class_exists('e107table', false))
|
|
||||||
|
if(!isset($_E107['no_theme']))
|
||||||
{
|
{
|
||||||
/**
|
$ns = e107::getRender(); // load theme render class.
|
||||||
* @package e107
|
|
||||||
*/
|
if (!class_exists('e107table', false)) // BC Fix.
|
||||||
class e107table
|
|
||||||
{
|
{
|
||||||
|
class e107table extends e_render
|
||||||
public $eMenuCount = 0;
|
|
||||||
public $eMenuArea;
|
|
||||||
public $eMenuTotal = array();
|
|
||||||
public $eSetStyle;
|
|
||||||
private $themeClass = 'theme'; // v2.3.0+
|
|
||||||
private $legacyThemeClass;
|
|
||||||
private $adminThemeClass;
|
|
||||||
public $frontend = false;
|
|
||||||
private $uniqueId = null;
|
|
||||||
private $content = array();
|
|
||||||
private $contentTypes = array('header','footer','text','title','image', 'list');
|
|
||||||
private $mainRenders = array(); // all renderered with style = 'default' or 'main'.
|
|
||||||
private $thm;
|
|
||||||
|
|
||||||
|
|
||||||
public function _init()
|
|
||||||
{
|
|
||||||
$this->legacyThemeClass = e107::getPref('sitetheme'). '_theme'; // disabled at the moment.
|
|
||||||
$this->adminThemeClass = e107::getPref('admintheme'). '_admintheme'; // Check for a class.
|
|
||||||
|
|
||||||
$this->load();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called in header.
|
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
if(empty($this->thm) || !method_exists($this->thm, 'init'))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ob_start(); // don't allow init() to echo.
|
|
||||||
$this->thm->init();
|
|
||||||
ob_end_clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load theme class if necessary.
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
private function load()
|
|
||||||
{
|
|
||||||
if(!empty($this->thm))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(($this->frontend === false) && class_exists($this->adminThemeClass))
|
|
||||||
{
|
|
||||||
/** @var e_theme_render $thm */
|
|
||||||
$this->thm = new $this->adminThemeClass();
|
|
||||||
}
|
|
||||||
elseif(class_exists($this->themeClass)) // v2.3.0+
|
|
||||||
{
|
|
||||||
|
|
||||||
if(ADMIN && $this->hasLegacyCode()) // debug - no translation needed.
|
|
||||||
{
|
|
||||||
echo "<div class='alert alert-danger'>Please place all theme code inside the <b>theme</b> class. </div>";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var e_theme_render $thm */
|
|
||||||
$this->thm = new $this->themeClass();
|
|
||||||
|
|
||||||
if(ADMIN && !$this->thm instanceof e_theme_render)
|
|
||||||
{
|
|
||||||
// debug - no need to translate.
|
|
||||||
echo "<div class='alert alert-danger'>class <b>".$this->themeClass."</b> is missing 'implements e_theme_render'. Make sure there is an init() method also!</div>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif(class_exists($this->legacyThemeClass)) // legacy v2.x
|
|
||||||
{
|
|
||||||
/** @var e_theme_render $thm */
|
|
||||||
$this->thm = new $this->legacyThemeClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return content options for the main render that uses {SETSTYLE=default} or {SETSTYLE=main}
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function getMainRender()
|
|
||||||
{
|
|
||||||
if(isset($this->mainRenders[0]))
|
|
||||||
{
|
|
||||||
return $this->mainRenders[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return array();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the first caption rendered with {SETSTYLE=default} or {SETSTYLE=main}
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getMainCaption()
|
|
||||||
{
|
|
||||||
if(isset($this->mainRenders[0]['caption']))
|
|
||||||
{
|
|
||||||
return $this->mainRenders[0]['caption'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function getMagicShortcodes()
|
|
||||||
{
|
|
||||||
$ret = array();
|
|
||||||
|
|
||||||
$val = $this->getMainRender();
|
|
||||||
|
|
||||||
$types = array('caption') + $this->contentTypes;
|
|
||||||
|
|
||||||
foreach($types as $var)
|
|
||||||
{
|
|
||||||
$sc = '{---'.strtoupper($var).'---}';
|
|
||||||
$ret[$sc] = isset($val[$var]) ? (string) $val[$var] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$bread = e107::breadcrumb();
|
|
||||||
$ret['{---BREADCRUMB---}'] = e107::getForm()->breadcrumb($bread, true);
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the style mode for use in tablestyle() method/function
|
|
||||||
* @param string $style
|
|
||||||
*/
|
|
||||||
public function setStyle($style)
|
|
||||||
{
|
|
||||||
$this->eSetStyle = (string) $style;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a unique id for use in tablestyle() method/function
|
|
||||||
*
|
|
||||||
* @param string $id
|
|
||||||
* @return e107table
|
|
||||||
*/
|
|
||||||
public function setUniqueId($id)
|
|
||||||
{
|
|
||||||
$this->uniqueId = !empty($id) ? eHelper::dasherize($id) : null;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Advanced Page/Menu content (beyond just $caption and $text)
|
|
||||||
*
|
|
||||||
* @param string|array $type header|footer|text|title|image|list
|
|
||||||
* @param string $val
|
|
||||||
* @return bool|e107table
|
|
||||||
*/
|
|
||||||
public function setContent($type, $val)
|
|
||||||
{
|
|
||||||
if(is_array($type))
|
|
||||||
{
|
|
||||||
foreach($this->contentTypes as $t)
|
|
||||||
{
|
|
||||||
$this->content[$t] = (string) $type[$t];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(!in_array($type, $this->contentTypes, true))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->uniqueId !== null)
|
|
||||||
{
|
|
||||||
$key = $this->uniqueId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$key = '_generic_';
|
|
||||||
e107::getDebug()->log("Possible issue: Missing a Unique Tablerender ID. Use \$ns->setUniqueId() in the plugin script prior to setContent(). See 'source code' for more information."); // debug only, no LAN.
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->content[$key][$type] = (string) $val;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the value of custom content
|
|
||||||
* @param string $type header|footer|text|title|image|list
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getContent($type='')
|
|
||||||
{
|
|
||||||
$key = ($this->uniqueId !== null) ? $this->uniqueId : '_generic_';
|
|
||||||
|
|
||||||
if(empty($type))
|
|
||||||
{
|
|
||||||
return $this->content[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $this->content[$key][$type];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the current value of {SETSTYLE}
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getStyle()
|
|
||||||
{
|
|
||||||
return $this->eSetStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the currenty set uniqueId.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getUniqueId()
|
|
||||||
{
|
|
||||||
return $this->uniqueId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $caption caption text
|
|
||||||
* @param string $text
|
|
||||||
* @param string $mode unique identifier
|
|
||||||
* @param boolean $return : return the html instead of echo it.
|
|
||||||
* @return null
|
|
||||||
*/
|
|
||||||
public function tablerender($caption, $text, $mode = 'default', $return = false)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
$override_tablerender = e107::getSingleton('override', e_HANDLER.'override_class.php')->override_check('tablerender');
|
|
||||||
|
|
||||||
if ($override_tablerender)
|
|
||||||
{
|
|
||||||
$result = $override_tablerender($caption, $text, $mode, $return);
|
|
||||||
|
|
||||||
if ($result === 'return')
|
|
||||||
{
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
extract($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($return)
|
|
||||||
{
|
|
||||||
if(!empty($text) && $this->eMenuArea)
|
|
||||||
{
|
|
||||||
$this->eMenuCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
$this->tablestyle($caption, $text, $mode);
|
|
||||||
|
|
||||||
return ob_get_clean();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($text) && $this->eMenuArea)
|
|
||||||
{
|
|
||||||
$this->eMenuCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->tablestyle($caption, $text, $mode);
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function hasLegacyCode()
|
|
||||||
{
|
|
||||||
$legacy = ['VIEWPORT','THEME_DISCLAIMER', 'IMODE', 'BODYTAG', 'COMMENTLINK', 'OTHERNEWS_LIMIT',
|
|
||||||
'PRE_EXTENDEDSTRING', 'COMMENTOFFSTRING', 'CORE_CSS', 'TRACKBACKSTRING', 'TRACKBACKBEFORESTRING'];
|
|
||||||
|
|
||||||
foreach($legacy as $const)
|
|
||||||
{
|
|
||||||
if(defined($const))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Output the styled template.
|
|
||||||
* @param $caption
|
|
||||||
* @param $text
|
|
||||||
* @param $mode
|
|
||||||
*/
|
|
||||||
private function tablestyle($caption, $text, $mode)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Automatic list detection .
|
|
||||||
$isList = (strncmp(ltrim($text), '<ul', 3) === 0 );
|
|
||||||
$this->setContent('list', $isList);
|
|
||||||
|
|
||||||
$options = $this->getContent();
|
|
||||||
|
|
||||||
$options['uniqueId'] = (string) $this->uniqueId;
|
|
||||||
$options['menuArea'] = (int) $this->eMenuArea;
|
|
||||||
$options['menuCount'] = (int) $this->eMenuCount;
|
|
||||||
$options['menuTotal'] = (int) varset($this->eMenuTotal[$this->eMenuArea]);
|
|
||||||
$options['setStyle'] = (string) $this->eSetStyle;
|
|
||||||
|
|
||||||
$options['caption'] = e107::getParser()->toText($caption);
|
|
||||||
|
|
||||||
if($this->eSetStyle === 'default' || $this->eSetStyle === 'main')
|
|
||||||
{
|
|
||||||
$this->mainRenders[] = $options;
|
|
||||||
}
|
|
||||||
|
|
||||||
//XXX Optional feature may be added if needed - define magic shortcodes inside $thm class. eg. function msc_custom();
|
|
||||||
|
|
||||||
if(!empty($this->thm) && is_object($this->thm))
|
|
||||||
{
|
|
||||||
$this->thm->tablestyle($caption, $text, $mode, $options);
|
|
||||||
}
|
|
||||||
elseif(function_exists('tablestyle'))
|
|
||||||
{
|
|
||||||
tablestyle($caption, $text, $mode, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$key = ($this->uniqueId !== null) ? $this->uniqueId : '_generic_';
|
|
||||||
$this->content[$key] = array();
|
|
||||||
$this->uniqueId = null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//#############################################################
|
|
||||||
|
|
||||||
//DEPRECATED, BC, call the method only when needed, $e107->ns caught by __get()
|
|
||||||
$ns = e107::getRender(); // load theme class.
|
|
||||||
|
|
||||||
// EONE-134 - bad e_module could destroy e107 instance
|
// EONE-134 - bad e_module could destroy e107 instance
|
||||||
$e107 = e107::getInstance(); // Is this needed now?
|
$e107 = e107::getInstance(); // Is this needed now?
|
||||||
|
@@ -185,7 +185,7 @@ class comment
|
|||||||
if ($this->getCommentPermissions() == 'rw')
|
if ($this->getCommentPermissions() == 'rw')
|
||||||
{
|
{
|
||||||
$itemid = $id;
|
$itemid = $id;
|
||||||
$ns = new e107table;
|
|
||||||
if ($action == "reply" && substr($subject, 0, 4) != "Re: ")
|
if ($action == "reply" && substr($subject, 0, 4) != "Re: ")
|
||||||
{
|
{
|
||||||
$subject = COMLAN_325.' '.$subject;
|
$subject = COMLAN_325.' '.$subject;
|
||||||
@@ -309,7 +309,7 @@ class comment
|
|||||||
|
|
||||||
if ($tablerender)
|
if ($tablerender)
|
||||||
{
|
{
|
||||||
$text = $ns->tablerender($caption, $text, '', TRUE);
|
$text = e107::getRender()->tablerender($caption, $text, '', TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -554,7 +554,7 @@ class comment
|
|||||||
|
|
||||||
ORDER BY comment_datestamp
|
ORDER BY comment_datestamp
|
||||||
";
|
";
|
||||||
$sql_nc = new db; /* a new db must be created here, for nested comment */
|
$sql_nc = e107::getDb('nc'); /* a new db must be created here, for nested comment */
|
||||||
if ($sub_total = $sql_nc->gen($sub_query))
|
if ($sub_total = $sql_nc->gen($sub_query))
|
||||||
{
|
{
|
||||||
while ($row1 = $sql_nc->fetch())
|
while ($row1 = $sql_nc->fetch())
|
||||||
@@ -757,6 +757,7 @@ class comment
|
|||||||
$subject = $tp->toDB($subject);
|
$subject = $tp->toDB($subject);
|
||||||
$cuser_id = 0;
|
$cuser_id = 0;
|
||||||
$cuser_name = 'Anonymous'; // Preset as an anonymous comment
|
$cuser_name = 'Anonymous'; // Preset as an anonymous comment
|
||||||
|
$cuser_mail = '';
|
||||||
|
|
||||||
if (!$sql->select("comments", "*", "comment_comment='".$comment."' AND comment_item_id='".intval($id)."' AND comment_type='".$tp->toDB($type, true)."' "))
|
if (!$sql->select("comments", "*", "comment_comment='".$comment."' AND comment_item_id='".intval($id)."' AND comment_type='".$tp->toDB($type, true)."' "))
|
||||||
{
|
{
|
||||||
|
@@ -210,8 +210,9 @@ class e107
|
|||||||
'e_parser' => '{e_HANDLER}e_parse_class.php',
|
'e_parser' => '{e_HANDLER}e_parse_class.php',
|
||||||
'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php',
|
'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.php',
|
||||||
'e_plugin' => '{e_HANDLER}plugin_class.php',
|
'e_plugin' => '{e_HANDLER}plugin_class.php',
|
||||||
'e_profanity' => '{e_HANDLER}e_profanity_class.php',
|
'e_profanity' => '{e_HANDLER}e_profanity_class.php',
|
||||||
'e_ranks' => '{e_HANDLER}e_ranks_class.php',
|
'e_ranks' => '{e_HANDLER}e_ranks_class.php',
|
||||||
|
'e_render' => '{e_HANDLER}e_render_class.php',
|
||||||
'e_shortcode' => '{e_HANDLER}shortcode_handler.php',
|
'e_shortcode' => '{e_HANDLER}shortcode_handler.php',
|
||||||
'e_system_user' => '{e_HANDLER}user_model.php',
|
'e_system_user' => '{e_HANDLER}user_model.php',
|
||||||
'e_theme' => '{e_HANDLER}theme_handler.php',
|
'e_theme' => '{e_HANDLER}theme_handler.php',
|
||||||
@@ -1525,11 +1526,11 @@ class e107
|
|||||||
/**
|
/**
|
||||||
* Retrieve render singleton object
|
* Retrieve render singleton object
|
||||||
*
|
*
|
||||||
* @return e107table
|
* @return e_render
|
||||||
*/
|
*/
|
||||||
public static function getRender()
|
public static function getRender()
|
||||||
{
|
{
|
||||||
return self::getSingleton('e107table');
|
return self::getSingleton('e_render');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
379
e107_handlers/e_render_class.php
Normal file
379
e107_handlers/e_render_class.php
Normal file
@@ -0,0 +1,379 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for rendering content via the theme tablestyle() method.
|
||||||
|
* Previously known as 'e107table'
|
||||||
|
* @package e107
|
||||||
|
*/
|
||||||
|
class e_render
|
||||||
|
{
|
||||||
|
|
||||||
|
public $eMenuCount = 0;
|
||||||
|
public $eMenuArea;
|
||||||
|
public $eMenuTotal = array();
|
||||||
|
public $eSetStyle;
|
||||||
|
private $themeClass = 'theme'; // v2.3.0+
|
||||||
|
private $legacyThemeClass;
|
||||||
|
private $adminThemeClass;
|
||||||
|
public $frontend = false;
|
||||||
|
private $uniqueId = null;
|
||||||
|
private $content = array();
|
||||||
|
private $contentTypes = array('header', 'footer', 'text', 'title', 'image', 'list');
|
||||||
|
private $mainRenders = array(); // all renderered with style = 'default' or 'main'.
|
||||||
|
private $thm;
|
||||||
|
|
||||||
|
|
||||||
|
public function _init()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->legacyThemeClass = e107::getPref('sitetheme') . '_theme'; // disabled at the moment.
|
||||||
|
$this->adminThemeClass = e107::getPref('admintheme') . '_admintheme'; // Check for a class.
|
||||||
|
|
||||||
|
$this->load();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called in header.
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(empty($this->thm) || !method_exists($this->thm, 'init'))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start(); // don't allow init() to echo.
|
||||||
|
$this->thm->init();
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load theme class if necessary.
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
private function load()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!empty($this->thm))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(($this->frontend === false) && class_exists($this->adminThemeClass))
|
||||||
|
{
|
||||||
|
/** @var e_theme_render $thm */
|
||||||
|
$this->thm = new $this->adminThemeClass();
|
||||||
|
}
|
||||||
|
elseif(class_exists($this->themeClass)) // v2.3.0+
|
||||||
|
{
|
||||||
|
|
||||||
|
if(ADMIN && $this->hasLegacyCode()) // debug - no translation needed.
|
||||||
|
{
|
||||||
|
echo "<div class='alert alert-danger'>Please place all theme code inside the <b>theme</b> class. </div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var e_theme_render $thm */
|
||||||
|
$this->thm = new $this->themeClass();
|
||||||
|
|
||||||
|
if(ADMIN && !$this->thm instanceof e_theme_render)
|
||||||
|
{
|
||||||
|
// debug - no need to translate.
|
||||||
|
echo "<div class='alert alert-danger'>class <b>" . $this->themeClass . "</b> is missing 'implements e_theme_render'. Make sure there is an init() method also!</div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif(class_exists($this->legacyThemeClass)) // legacy v2.x
|
||||||
|
{
|
||||||
|
/** @var e_theme_render $thm */
|
||||||
|
$this->thm = new $this->legacyThemeClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return content options for the main render that uses {SETSTYLE=default} or {SETSTYLE=main}
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getMainRender()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(isset($this->mainRenders[0]))
|
||||||
|
{
|
||||||
|
return $this->mainRenders[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the first caption rendered with {SETSTYLE=default} or {SETSTYLE=main}
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getMainCaption()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(isset($this->mainRenders[0]['caption']))
|
||||||
|
{
|
||||||
|
return $this->mainRenders[0]['caption'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getMagicShortcodes()
|
||||||
|
{
|
||||||
|
|
||||||
|
$ret = array();
|
||||||
|
|
||||||
|
$val = $this->getMainRender();
|
||||||
|
|
||||||
|
$types = array('caption') + $this->contentTypes;
|
||||||
|
|
||||||
|
foreach($types as $var)
|
||||||
|
{
|
||||||
|
$sc = '{---' . strtoupper($var) . '---}';
|
||||||
|
$ret[$sc] = isset($val[$var]) ? (string) $val[$var] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$bread = e107::breadcrumb();
|
||||||
|
$ret['{---BREADCRUMB---}'] = e107::getForm()->breadcrumb($bread, true);
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the style mode for use in tablestyle() method/function
|
||||||
|
*
|
||||||
|
* @param string $style
|
||||||
|
*/
|
||||||
|
public function setStyle($style)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->eSetStyle = (string) $style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a unique id for use in tablestyle() method/function
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @return e_render
|
||||||
|
*/
|
||||||
|
public function setUniqueId($id)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->uniqueId = !empty($id) ? eHelper::dasherize($id) : null;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Advanced Page/Menu content (beyond just $caption and $text)
|
||||||
|
*
|
||||||
|
* @param string|array $type header|footer|text|title|image|list
|
||||||
|
* @param string $val
|
||||||
|
* @return bool|e_render
|
||||||
|
*/
|
||||||
|
public function setContent($type, $val)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(is_array($type))
|
||||||
|
{
|
||||||
|
foreach($this->contentTypes as $t)
|
||||||
|
{
|
||||||
|
$this->content[$t] = (string) $type[$t];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!in_array($type, $this->contentTypes, true))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->uniqueId !== null)
|
||||||
|
{
|
||||||
|
$key = $this->uniqueId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$key = '_generic_';
|
||||||
|
e107::getDebug()->log("Possible issue: Missing a Unique Tablerender ID. Use \$ns->setUniqueId() in the plugin script prior to setContent(). See 'source code' for more information."); // debug only, no LAN.
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->content[$key][$type] = (string) $val;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the value of custom content
|
||||||
|
*
|
||||||
|
* @param string $type header|footer|text|title|image|list
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getContent($type = '')
|
||||||
|
{
|
||||||
|
|
||||||
|
$key = ($this->uniqueId !== null) ? $this->uniqueId : '_generic_';
|
||||||
|
|
||||||
|
if(empty($type))
|
||||||
|
{
|
||||||
|
return $this->content[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $this->content[$key][$type];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current value of {SETSTYLE}
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->eSetStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the currenty set uniqueId.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getUniqueId()
|
||||||
|
{
|
||||||
|
|
||||||
|
return $this->uniqueId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $caption caption text
|
||||||
|
* @param string $text
|
||||||
|
* @param string $mode unique identifier
|
||||||
|
* @param boolean $return : return the html instead of echo it.
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function tablerender($caption, $text, $mode = 'default', $return = false)
|
||||||
|
{
|
||||||
|
|
||||||
|
$override_tablerender = e107::getSingleton('override', e_HANDLER . 'override_class.php')->override_check('tablerender');
|
||||||
|
|
||||||
|
if($override_tablerender)
|
||||||
|
{
|
||||||
|
$result = $override_tablerender($caption, $text, $mode, $return);
|
||||||
|
|
||||||
|
if($result === 'return')
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
extract($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($return)
|
||||||
|
{
|
||||||
|
if(!empty($text) && $this->eMenuArea)
|
||||||
|
{
|
||||||
|
$this->eMenuCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$this->tablestyle($caption, $text, $mode);
|
||||||
|
|
||||||
|
return ob_get_clean();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($text) && $this->eMenuArea)
|
||||||
|
{
|
||||||
|
$this->eMenuCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tablestyle($caption, $text, $mode);
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function hasLegacyCode()
|
||||||
|
{
|
||||||
|
|
||||||
|
$legacy = ['VIEWPORT', 'THEME_DISCLAIMER', 'IMODE', 'BODYTAG', 'COMMENTLINK', 'OTHERNEWS_LIMIT',
|
||||||
|
'PRE_EXTENDEDSTRING', 'COMMENTOFFSTRING', 'CORE_CSS', 'TRACKBACKSTRING', 'TRACKBACKBEFORESTRING'];
|
||||||
|
|
||||||
|
foreach($legacy as $const)
|
||||||
|
{
|
||||||
|
if(defined($const))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output the styled template.
|
||||||
|
*
|
||||||
|
* @param $caption
|
||||||
|
* @param $text
|
||||||
|
* @param $mode
|
||||||
|
*/
|
||||||
|
private function tablestyle($caption, $text, $mode)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Automatic list detection .
|
||||||
|
$isList = (strncmp(ltrim($text), '<ul', 3) === 0);
|
||||||
|
$this->setContent('list', $isList);
|
||||||
|
|
||||||
|
$options = $this->getContent();
|
||||||
|
|
||||||
|
$options['uniqueId'] = (string) $this->uniqueId;
|
||||||
|
$options['menuArea'] = (int) $this->eMenuArea;
|
||||||
|
$options['menuCount'] = (int) $this->eMenuCount;
|
||||||
|
$options['menuTotal'] = (int) varset($this->eMenuTotal[$this->eMenuArea]);
|
||||||
|
$options['setStyle'] = (string) $this->eSetStyle;
|
||||||
|
|
||||||
|
$options['caption'] = e107::getParser()->toText($caption);
|
||||||
|
|
||||||
|
if($this->eSetStyle === 'default' || $this->eSetStyle === 'main')
|
||||||
|
{
|
||||||
|
$this->mainRenders[] = $options;
|
||||||
|
}
|
||||||
|
|
||||||
|
//XXX Optional feature may be added if needed - define magic shortcodes inside $thm class. eg. function msc_custom();
|
||||||
|
|
||||||
|
if(!empty($this->thm) && is_object($this->thm))
|
||||||
|
{
|
||||||
|
$this->thm->tablestyle($caption, $text, $mode, $options);
|
||||||
|
}
|
||||||
|
elseif(function_exists('tablestyle'))
|
||||||
|
{
|
||||||
|
tablestyle($caption, $text, $mode, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = ($this->uniqueId !== null) ? $this->uniqueId : '_generic_';
|
||||||
|
$this->content[$key] = array();
|
||||||
|
$this->uniqueId = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -1090,9 +1090,9 @@ $SYSTEM_DIRECTORY = "e107_system/";</pre>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (class_exists('e107table'))
|
if (class_exists('e_render'))
|
||||||
{
|
{
|
||||||
$ns = new e107table;
|
$ns = new e_render;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($mode)
|
switch($mode)
|
||||||
|
@@ -1,101 +1,106 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* e107 website system
|
* e107 website system
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008-2019 e107 Inc (e107.org)
|
* Copyright (C) 2008-2019 e107 Inc (e107.org)
|
||||||
* Released under the terms and conditions of the
|
* Released under the terms and conditions of the
|
||||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class e107tableTest extends \Codeception\Test\Unit
|
/**
|
||||||
|
* This is a BC test for e107table, now e_render
|
||||||
|
* Class e107tableTest
|
||||||
|
*/
|
||||||
|
class e107tableTest extends \Codeception\Test\Unit
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var e107table */
|
||||||
|
protected $ns;
|
||||||
|
|
||||||
|
|
||||||
|
protected function _before()
|
||||||
{
|
{
|
||||||
|
|
||||||
/** @var e107table */
|
try
|
||||||
protected $ns;
|
|
||||||
|
|
||||||
protected function _before()
|
|
||||||
{
|
{
|
||||||
|
$this->ns = $this->make('e107table');
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
$this->assertTrue(false, "Couldn't load e107table object");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
$this->ns->_init();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function testGetStyle()
|
||||||
{
|
{
|
||||||
$this->ns = $this->make('e107table');
|
|
||||||
}
|
|
||||||
catch(Exception $e)
|
|
||||||
{
|
|
||||||
$this->assertTrue(false, "Couldn't load e107table object");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->ns->_init();
|
public function testSetUniqueId()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
*/
|
||||||
public function testGetStyle()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public function testSetGetContent()
|
||||||
|
{
|
||||||
|
|
||||||
public function testSetUniqueId()
|
$unique = 'news-view-default';
|
||||||
{
|
|
||||||
|
|
||||||
}
|
$this->ns->setUniqueId($unique);
|
||||||
*/
|
$this->ns->setContent('title', 'news-title');
|
||||||
|
$this->ns->setContent('text', 'news-summary');
|
||||||
|
$this->ns->setUniqueId(false); // reset the ID.
|
||||||
|
|
||||||
public function testSetGetContent()
|
$this->ns->tablerender('caption', 'other', 'default', true); // render a different table.
|
||||||
{
|
|
||||||
|
|
||||||
$unique = 'news-view-default';
|
$result = $this->ns->setUniqueId($unique)->getContent(); // get content using uniqueId.
|
||||||
|
$expected = array('title' => 'news-title', 'text' => 'news-summary',);
|
||||||
$this->ns->setUniqueId($unique);
|
$this->assertEquals($expected, $result);
|
||||||
$this->ns->setContent('title', 'news-title');
|
|
||||||
$this->ns->setContent('text', 'news-summary');
|
|
||||||
$this->ns->setUniqueId(false); // reset the ID.
|
|
||||||
|
|
||||||
$this->ns->tablerender('caption', 'other', 'default', true); // render a different table.
|
|
||||||
|
|
||||||
$result = $this->ns->setUniqueId($unique)->getContent(); // get content using uniqueId.
|
|
||||||
$expected = array ( 'title' => 'news-title', 'text' => 'news-summary', );
|
|
||||||
$this->assertEquals($expected, $result);
|
|
||||||
|
|
||||||
|
|
||||||
$result = $this->ns->getContent('title');
|
$result = $this->ns->getContent('title');
|
||||||
$this->assertEquals('news-title', $result);
|
$this->assertEquals('news-title', $result);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
public function testGetMagicShortcodes()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetContent()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetMainCaption()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testTablerender()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSetStyle()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetUniqueId()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
public function testGetMagicShortcodes()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetContent()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetMainCaption()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTablerender()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetStyle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetUniqueId()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
108
e107_tests/tests/unit/e_renderTest.php
Normal file
108
e107_tests/tests/unit/e_renderTest.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
class e_renderTest extends \Codeception\Test\Unit
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var e_render */
|
||||||
|
protected $ns;
|
||||||
|
|
||||||
|
protected function _before()
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$this->ns = $this->make('e_render');
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
$this->assertTrue(false, $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->ns->_init(); // load theme preferences.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetGetContent()
|
||||||
|
{
|
||||||
|
|
||||||
|
$unique = 'news-view-default';
|
||||||
|
|
||||||
|
$this->ns->setUniqueId($unique);
|
||||||
|
$this->ns->setContent('title', 'news-title');
|
||||||
|
$this->ns->setContent('text', 'news-summary');
|
||||||
|
$this->ns->setUniqueId(false); // reset the ID.
|
||||||
|
|
||||||
|
$this->ns->tablerender('caption', 'other', 'default', true); // render a different table.
|
||||||
|
|
||||||
|
$result = $this->ns->setUniqueId($unique)->getContent(); // get content using uniqueId.
|
||||||
|
$expected = array('title' => 'news-title', 'text' => 'news-summary',);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
|
||||||
|
$result = $this->ns->getContent('title');
|
||||||
|
$this->assertEquals('news-title', $result);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* public function test_init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetStyle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetUniqueId()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetContent()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetStyle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public function testTablerender()
|
||||||
|
{
|
||||||
|
|
||||||
|
$result = $this->ns->tablerender("My Caption", "<p>My Content</p>", 'default', true);
|
||||||
|
$this->assertStringContainsString('<h2 class="caption">My Caption</h2><p>My Content</p>', $result);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public function testGetMagicShortcodes()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetUniqueId()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetContent()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetMainCaption()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user