diff --git a/class2.php b/class2.php index a390c6977..06070eec7 100755 --- a/class2.php +++ b/class2.php @@ -2079,6 +2079,13 @@ $dbg->logTime('(After Go online)'); */ function cookie($name, $value, $expire=0, $path = e_HTTP, $domain = '', $secure = 0) { + global $_E107; + + if(!empty($_E107['cli'])) + { + return null; + } + if(!e_SUBDOMAIN || (defined('MULTILANG_SUBDOMAIN') && MULTILANG_SUBDOMAIN === true)) { $domain = (e_DOMAIN !== false) ? ".".e_DOMAIN : ""; diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 1317c6e61..17db5a884 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -1071,7 +1071,32 @@ class e_parse return $drain; } + /** + * Universal text/bbcode/html truncate method. + * new in v2.3.1 + * @param $text + * @param int $length + * @param string $ending + */ + public function truncate($text, $length = 100, $ending = '...') + { + if($this->isHtml($text)) + { + return $this->html_truncate($text, $length, $ending); + } + + if($this->isBBcode($text)) + { + $text = $this->toText($text); + } + + return $this->text_truncate($text, $length, $ending); + + } + + /** + * @deprecated Soon to be made private. Use $tp->truncate() instead. * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org) * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @@ -1177,25 +1202,34 @@ class e_parse } + + + + /** - * Truncate a string of text to a maximum length $len ­ append the string $more if it was truncated - * Uses current CHARSET ­ for utf-8, returns $len characters rather than $len bytes + * @deprecated for public use. Will be made private. Use $tp->truncate() instead. + * Truncate a string of text to a maximum length $len append the string $more if it was truncated + * Uses current CHARSET for utf-8, returns $len characters rather than $len bytes * - * @param string $text ­ string to process - * @param integer $len ­ length of characters to be truncated - * @param string $more ­ string which will be added if truncation - * @return string + * @param string $text string to process + * @param integer $len length of characters to be truncated + * @param string $more string which will be added if truncation + * @return string Always returns text. */ public function text_truncate($text, $len = 200, $more = ' ... ') { - - // Always valid - + if($this->ustrlen($text) <= $len) { return $text; } + if($this->isBBcode($text) || $this->isHtml($text)) + { + $text = $this->toText($text); + } + + $text = html_entity_decode($text, ENT_QUOTES, 'utf-8'); if(function_exists('mb_strimwidth')) diff --git a/e107_tests/tests/unit/e107Test.php b/e107_tests/tests/unit/e107Test.php index 2bf6eb441..a2357e2a5 100644 --- a/e107_tests/tests/unit/e107Test.php +++ b/e107_tests/tests/unit/e107Test.php @@ -988,6 +988,11 @@ class e107Test extends \Codeception\Test\Unit $all = e107::getAddonConfig('e_url'); foreach($all as $plugin => $var) { + if($plugin === 'gallery') // fixme - sef may be enabled or disabled each time tests are run + { + continue; + } + foreach($var as $key => $value) { $rows = $this->generateRows($value, $plugin); diff --git a/e107_tests/tests/unit/e107_user_extendedTest.php b/e107_tests/tests/unit/e107_user_extendedTest.php index 68064f6b3..20dd3ef4d 100644 --- a/e107_tests/tests/unit/e107_user_extendedTest.php +++ b/e107_tests/tests/unit/e107_user_extendedTest.php @@ -213,7 +213,7 @@ */ public function testUserExtendedShortcode() { - e107::setRegistry('corelan/English_user_extended_front'); + // e107::setRegistry('corelan/English_user_extended_front'); foreach($this->userValues as $field => $value) { @@ -351,6 +351,8 @@ $sc->template = $template; + $this->assertNotEmpty($sc->template); + $result = e107::getParser()->parseTemplate('{SIGNUP_EXTENDED_USER_FIELDS}', false, $sc); $this->assertSame($expected, $result); diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php index b79d51d6b..539922eec 100644 --- a/e107_tests/tests/unit/e_parseTest.php +++ b/e107_tests/tests/unit/e_parseTest.php @@ -1162,14 +1162,39 @@ while($row = $sql->fetch()) public function testText_truncate() { $string = "This is a long string that will be truncated." ; - $expected = 'This is a long ... '; $result = $this->tp->text_truncate($string, 20); - $this->assertSame($expected, $result); + $this->assertSame('This is a long ... ', $result); $string = "This is has something & something" ; - $expected = 'This is has something & ... '; $result = $this->tp->text_truncate($string, 29); - $this->assertSame($expected, $result); + $this->assertSame('This is has something & ... ', $result); + + $string = "Can't fail me now [b]Bold[/b]"; + $result = $this->tp->text_truncate($string, 25); + $this->assertSame("Can't fail me now Bold", $result); + + $string = "Can't fail me now Bold"; + $result = $this->tp->text_truncate($string, 25); + $this->assertSame("Can't fail me now Bold", $result); + + } + + public function testTruncate() + { + // html + $string = "Can't fail me now Bold"; + $result = $this->tp->truncate($string, 25); + $this->assertSame("Can't fail me now Bold", $result); // html ignored in char count. + + // bbcode - stripped. + $string = "Can't fail me now [b]Bold[/b]"; + $result = $this->tp->truncate($string, 25); + $this->assertSame("Can't fail me now Bold", $result); + + // text + $string = "This is a long string that will be truncated." ; + $result = $this->tp->truncate($string, 20); + $this->assertSame('This is a long st...', $result); } /* diff --git a/e107_tests/tests/unit/e_parse_shortcodeTest.php b/e107_tests/tests/unit/e_parse_shortcodeTest.php index 7bd40e0bb..f73c41388 100644 --- a/e107_tests/tests/unit/e_parse_shortcodeTest.php +++ b/e107_tests/tests/unit/e_parse_shortcodeTest.php @@ -337,7 +337,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit $sc->setVars($ret[0]); $actual = e107::getParser()->parseTemplate('{LINK_SUB}', true, $sc); - $this->assertStringContainsString('General', $actual); + $this->assertStringContainsString('General', $actual); $this->assertStringContainsString('