diff --git a/class2.php b/class2.php index 06070eec7..d393169e7 100755 --- a/class2.php +++ b/class2.php @@ -792,372 +792,19 @@ if(!defined('USERTHEME') && !isset($_E107['no_theme'])) $dbg->logTime('Misc Setup'); //------------------------------------------------------------------------------------------------------------------------------------// -if (!class_exists('e107table', false)) + +if(!isset($_E107['no_theme'])) { - /** - * @package e107 - */ - class e107table + $ns = e107::getRender(); // load theme render class. + + if (!class_exists('e107table', false)) // BC Fix. { - - 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 "
Please place all theme code inside the theme class.
"; - } - - /** @var e_theme_render $thm */ - $this->thm = new $this->themeClass(); - - if(ADMIN && !$this->thm instanceof e_theme_render) - { - // debug - no need to translate. - echo "
class ".$this->themeClass." is missing 'implements e_theme_render'. Make sure there is an init() method also!
"; - } - } - 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) + class e107table extends e_render { - - $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), '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 $e107 = e107::getInstance(); // Is this needed now? diff --git a/e107_handlers/comment_class.php b/e107_handlers/comment_class.php index 0c9bc2d7f..6254f6a69 100644 --- a/e107_handlers/comment_class.php +++ b/e107_handlers/comment_class.php @@ -185,7 +185,7 @@ class comment if ($this->getCommentPermissions() == 'rw') { $itemid = $id; - $ns = new e107table; + if ($action == "reply" && substr($subject, 0, 4) != "Re: ") { $subject = COMLAN_325.' '.$subject; @@ -309,7 +309,7 @@ class comment if ($tablerender) { - $text = $ns->tablerender($caption, $text, '', TRUE); + $text = e107::getRender()->tablerender($caption, $text, '', TRUE); } } else @@ -554,7 +554,7 @@ class comment 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)) { while ($row1 = $sql_nc->fetch()) @@ -757,6 +757,7 @@ class comment $subject = $tp->toDB($subject); $cuser_id = 0; $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)."' ")) { diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 45e8de472..6a8ce80ed 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -210,8 +210,9 @@ class e107 'e_parser' => '{e_HANDLER}e_parse_class.php', 'e_parse_shortcode' => '{e_HANDLER}shortcode_handler.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_render' => '{e_HANDLER}e_render_class.php', 'e_shortcode' => '{e_HANDLER}shortcode_handler.php', 'e_system_user' => '{e_HANDLER}user_model.php', 'e_theme' => '{e_HANDLER}theme_handler.php', @@ -1525,11 +1526,11 @@ class e107 /** * Retrieve render singleton object * - * @return e107table + * @return e_render */ public static function getRender() { - return self::getSingleton('e107table'); + return self::getSingleton('e_render'); } /** diff --git a/e107_handlers/e_render_class.php b/e107_handlers/e_render_class.php new file mode 100644 index 000000000..16d71dfd2 --- /dev/null +++ b/e107_handlers/e_render_class.php @@ -0,0 +1,379 @@ +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 "
Please place all theme code inside the theme class.
"; + } + + /** @var e_theme_render $thm */ + $this->thm = new $this->themeClass(); + + if(ADMIN && !$this->thm instanceof e_theme_render) + { + // debug - no need to translate. + echo "
class " . $this->themeClass . " is missing 'implements e_theme_render'. Make sure there is an init() method also!
"; + } + } + 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), '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; + + } + + + } \ No newline at end of file diff --git a/e107_handlers/message_handler.php b/e107_handlers/message_handler.php index 3753f40c6..46db919f3 100644 --- a/e107_handlers/message_handler.php +++ b/e107_handlers/message_handler.php @@ -1090,9 +1090,9 @@ $SYSTEM_DIRECTORY = "e107_system/"; } - if (class_exists('e107table')) + if (class_exists('e_render')) { - $ns = new e107table; + $ns = new e_render; } switch($mode) diff --git a/e107_tests/tests/unit/e107tableTest.php b/e107_tests/tests/unit/e107tableTest.php index 2519c2b69..47360dae7 100644 --- a/e107_tests/tests/unit/e107tableTest.php +++ b/e107_tests/tests/unit/e107tableTest.php @@ -1,101 +1,106 @@ 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'; - - $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->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 testGetMagicShortcodes() - { - - } - - public function testGetContent() - { - - } - - public function testGetMainCaption() - { - - } - - public function testTablerender() - { - - } - - public function testSetStyle() - { - - } - - public function testGetUniqueId() - { - - } -*/ - + $result = $this->ns->getContent('title'); + $this->assertEquals('news-title', $result); } + /* + public function testGetMagicShortcodes() + { + + } + + public function testGetContent() + { + + } + + public function testGetMainCaption() + { + + } + + public function testTablerender() + { + + } + + public function testSetStyle() + { + + } + + public function testGetUniqueId() + { + + } + */ + + +} diff --git a/e107_tests/tests/unit/e_renderTest.php b/e107_tests/tests/unit/e_renderTest.php new file mode 100644 index 000000000..705e8380c --- /dev/null +++ b/e107_tests/tests/unit/e_renderTest.php @@ -0,0 +1,108 @@ +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", "

My Content

", 'default', true); + $this->assertStringContainsString('

My Caption

My Content

', $result); + } +/* + public function testGetMagicShortcodes() + { + + } + + public function testGetUniqueId() + { + + } + + public function testSetContent() + { + + } + + public function testInit() + { + + } + + public function testGetMainCaption() + { + + } +*/ + +}