mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
Fix for HTML used on text_truncate(). Ignore setcookie() in CLI mode.
This commit is contained in:
@@ -2079,6 +2079,13 @@ $dbg->logTime('(After Go online)');
|
|||||||
*/
|
*/
|
||||||
function cookie($name, $value, $expire=0, $path = e_HTTP, $domain = '', $secure = 0)
|
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))
|
if(!e_SUBDOMAIN || (defined('MULTILANG_SUBDOMAIN') && MULTILANG_SUBDOMAIN === true))
|
||||||
{
|
{
|
||||||
$domain = (e_DOMAIN !== false) ? ".".e_DOMAIN : "";
|
$domain = (e_DOMAIN !== false) ? ".".e_DOMAIN : "";
|
||||||
|
@@ -1071,7 +1071,32 @@ class e_parse
|
|||||||
return $drain;
|
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)
|
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
||||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.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
|
* @deprecated for public use. Will be made private. Use $tp->truncate() instead.
|
||||||
* Uses current CHARSET for utf-8, returns $len characters rather than $len bytes
|
* 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 string $text string to process
|
||||||
* @param integer $len length of characters to be truncated
|
* @param integer $len length of characters to be truncated
|
||||||
* @param string $more string which will be added if truncation
|
* @param string $more string which will be added if truncation
|
||||||
* @return string
|
* @return string Always returns text.
|
||||||
*/
|
*/
|
||||||
public function text_truncate($text, $len = 200, $more = ' ... ')
|
public function text_truncate($text, $len = 200, $more = ' ... ')
|
||||||
{
|
{
|
||||||
|
|
||||||
// Always valid
|
|
||||||
|
|
||||||
if($this->ustrlen($text) <= $len)
|
if($this->ustrlen($text) <= $len)
|
||||||
{
|
{
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->isBBcode($text) || $this->isHtml($text))
|
||||||
|
{
|
||||||
|
$text = $this->toText($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$text = html_entity_decode($text, ENT_QUOTES, 'utf-8');
|
$text = html_entity_decode($text, ENT_QUOTES, 'utf-8');
|
||||||
|
|
||||||
if(function_exists('mb_strimwidth'))
|
if(function_exists('mb_strimwidth'))
|
||||||
|
@@ -988,6 +988,11 @@ class e107Test extends \Codeception\Test\Unit
|
|||||||
$all = e107::getAddonConfig('e_url');
|
$all = e107::getAddonConfig('e_url');
|
||||||
foreach($all as $plugin => $var)
|
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)
|
foreach($var as $key => $value)
|
||||||
{
|
{
|
||||||
$rows = $this->generateRows($value, $plugin);
|
$rows = $this->generateRows($value, $plugin);
|
||||||
|
@@ -213,7 +213,7 @@
|
|||||||
*/
|
*/
|
||||||
public function testUserExtendedShortcode()
|
public function testUserExtendedShortcode()
|
||||||
{
|
{
|
||||||
e107::setRegistry('corelan/English_user_extended_front');
|
// e107::setRegistry('corelan/English_user_extended_front');
|
||||||
|
|
||||||
foreach($this->userValues as $field => $value)
|
foreach($this->userValues as $field => $value)
|
||||||
{
|
{
|
||||||
@@ -351,6 +351,8 @@
|
|||||||
|
|
||||||
$sc->template = $template;
|
$sc->template = $template;
|
||||||
|
|
||||||
|
$this->assertNotEmpty($sc->template);
|
||||||
|
|
||||||
$result = e107::getParser()->parseTemplate('{SIGNUP_EXTENDED_USER_FIELDS}', false, $sc);
|
$result = e107::getParser()->parseTemplate('{SIGNUP_EXTENDED_USER_FIELDS}', false, $sc);
|
||||||
$this->assertSame($expected, $result);
|
$this->assertSame($expected, $result);
|
||||||
|
|
||||||
|
@@ -1162,14 +1162,39 @@ while($row = $sql->fetch())
|
|||||||
public function testText_truncate()
|
public function testText_truncate()
|
||||||
{
|
{
|
||||||
$string = "This is a long string that will be truncated." ;
|
$string = "This is a long string that will be truncated." ;
|
||||||
$expected = 'This is a long ... ';
|
|
||||||
$result = $this->tp->text_truncate($string, 20);
|
$result = $this->tp->text_truncate($string, 20);
|
||||||
$this->assertSame($expected, $result);
|
$this->assertSame('This is a long ... ', $result);
|
||||||
|
|
||||||
$string = "This is has something & something" ;
|
$string = "This is has something & something" ;
|
||||||
$expected = 'This is has something & ... ';
|
|
||||||
$result = $this->tp->text_truncate($string, 29);
|
$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 <strong class='bbcode bold bbcode-b'>Bold</strong>";
|
||||||
|
$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 <strong class='bbcode bold bbcode-b'>Bold</strong>";
|
||||||
|
$result = $this->tp->truncate($string, 25);
|
||||||
|
$this->assertSame("Can't fail me now <strong class='bbcode bold bbcode-b'>Bold</strong>", $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);
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@@ -337,7 +337,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
|
|||||||
|
|
||||||
$sc->setVars($ret[0]);
|
$sc->setVars($ret[0]);
|
||||||
$actual = e107::getParser()->parseTemplate('{LINK_SUB}', true, $sc);
|
$actual = e107::getParser()->parseTemplate('{LINK_SUB}', true, $sc);
|
||||||
$this->assertStringContainsString('<a href="https://localhost/e107/page.php?bk=1">General</a>', $actual);
|
$this->assertStringContainsString('General</a>', $actual);
|
||||||
$this->assertStringContainsString('<li role="menuitem" class="dropdown-submenu lower">', $actual);
|
$this->assertStringContainsString('<li role="menuitem" class="dropdown-submenu lower">', $actual);
|
||||||
$this->assertStringContainsString('<li role="menuitem" class="link-depth-3">', $actual);
|
$this->assertStringContainsString('<li role="menuitem" class="link-depth-3">', $actual);
|
||||||
|
|
||||||
|
@@ -247,6 +247,76 @@
|
|||||||
$this->pluginUninstall('tagcloud');
|
$this->pluginUninstall('tagcloud');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function testThirdParty()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$coreList = e107::getPlug()->getCorePluginList();
|
||||||
|
$all = scandir(e_PLUGIN);
|
||||||
|
unset($all[0], $all[1]);
|
||||||
|
|
||||||
|
$diff = array_diff($all, $coreList);
|
||||||
|
|
||||||
|
foreach($diff as $plug)
|
||||||
|
{
|
||||||
|
if(!is_dir(e_PLUGIN.$plug) || !is_dir(e_PLUGIN.$plug.'/tests'))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tests = scandir(e_PLUGIN.$plug.'/tests');
|
||||||
|
unset($tests[0], $tests[1]);
|
||||||
|
|
||||||
|
foreach($tests as $t)
|
||||||
|
{
|
||||||
|
require_once(e_PLUGIN.$plug.'/tests/'.$t);
|
||||||
|
$Codecept = new \Codeception\Codecept(array(
|
||||||
|
'steps' => true,
|
||||||
|
'verbosity' => 1,
|
||||||
|
// some other options (see Codeception docs/sources)
|
||||||
|
));
|
||||||
|
|
||||||
|
// var_export($Codecept);
|
||||||
|
|
||||||
|
$Codecept->run('unit');
|
||||||
|
// require_once '/path/to/codeception/autoload.php';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//array_intersect(
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public function testVstore()
|
||||||
|
{
|
||||||
|
if(!is_dir(e_PLUGIN."vstore"))
|
||||||
|
{
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pluginInstall('vstore');
|
||||||
|
$this->pluginRefresh('vstore');
|
||||||
|
|
||||||
|
$links = e107::getDb()->retrieve('links', '*', 'link_owner = "vstore"', true);
|
||||||
|
$this->assertNotEmpty($links);
|
||||||
|
$this->assertCount(2, $links);
|
||||||
|
|
||||||
|
$this->pluginUninstall('vstore');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testplugInstalledStatus()
|
public function testplugInstalledStatus()
|
||||||
{
|
{
|
||||||
$sql = e107::getDb();
|
$sql = e107::getDb();
|
||||||
@@ -384,7 +454,10 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function pluginRefresh($pluginDir)
|
||||||
|
{
|
||||||
|
$return_text = e107::getPlugin()->refresh($pluginDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function pluginInstall($pluginDir)
|
private function pluginInstall($pluginDir)
|
||||||
@@ -1288,3 +1361,5 @@ DATA
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
global $_E107;
|
global $_E107;
|
||||||
$_E107['cli'] = true;
|
$_E107['cli'] = true;
|
||||||
$_E107['no_theme'] = true; //FIXME unable to change to admin theme in testing environment.
|
// $_E107['no_theme'] = true; //FIXME unable to change to admin theme in testing environment.
|
||||||
|
|
||||||
foreach($list as $file)
|
foreach($list as $file)
|
||||||
{
|
{
|
||||||
|
@@ -327,21 +327,20 @@ class theme_shortcodes extends e_shortcode
|
|||||||
function sc_bootstrap_megamenu_example($data)
|
function sc_bootstrap_megamenu_example($data)
|
||||||
{
|
{
|
||||||
// include a plugin, custom code, whatever you wish.
|
// include a plugin, custom code, whatever you wish.
|
||||||
|
|
||||||
// return print_a($data,true);
|
// return print_a($data,true);
|
||||||
|
|
||||||
$parm= array();
|
$parm= array();
|
||||||
$parm['caption'] = '';
|
$parm['caption'] = '';
|
||||||
$parm['titleLimit'] = 25; // number of chars fo news title
|
$parm['titleLimit'] = 25; // number of chars fo news title
|
||||||
$parm['summaryLimit'] = 50; // number of chars for new summary
|
$parm['summaryLimit'] = 50; // number of chars for new summary
|
||||||
$parm['source'] = 'latest'; // latest (latest news items) | sticky (news items) | template (assigned to news-grid layout)
|
$parm['source'] = 'latest'; // latest (latest news items) | sticky (news items) | template (assigned to news-grid layout)
|
||||||
$parm['order'] = 'DESC'; // n.news_datestamp DESC
|
$parm['order'] = 'n.news_datestamp DESC'; // n.news_datestamp DESC
|
||||||
$parm['limit'] = '6'; // 10
|
$parm['limit'] = 4; // number of items
|
||||||
$parm['layout'] = 'media-list'; // default | or any key as defined in news_grid_template.php
|
$parm['layout'] = 'media-list'; // default | or any key as defined in news_grid_template.php
|
||||||
$parm['featured'] = 0;
|
$parm['featured'] = 0;
|
||||||
|
|
||||||
unset($data);
|
unset($data);
|
||||||
return "<div class='container'>". e107::getObject('news')->render_newsgrid($parm) ."</div>";
|
return '<div class="container mega-menu-example">'. e107::getObject('news')->render_newsgrid($parm) ."</div>";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user