mirror of
https://github.com/e107inc/e107.git
synced 2025-04-20 04:32:01 +02:00
New e107::isCompatible() method added for checking plugins/themes are compatible with the current version of e107.
New parser method stripBlockTags($html) to remove p, div etc. {CPAGEBODY: strip=blocks} shortcode option added (uses the method above)
This commit is contained in:
parent
85ae08e8ff
commit
17a9aa2822
@ -103,9 +103,17 @@ class cpage_shortcodes extends e_shortcode
|
||||
}
|
||||
|
||||
|
||||
function sc_cpagebody($parm='')
|
||||
function sc_cpagebody($parm=null)
|
||||
{
|
||||
$text = $this->var['page_text'];
|
||||
|
||||
|
||||
if(varset($parm['strip']) === 'blocks')
|
||||
{
|
||||
$text = e107::getParser()->stripBlockTags($text);
|
||||
}
|
||||
|
||||
|
||||
return $text ? e107::getParser()->toHTML($text, true, 'BODY') : '';
|
||||
}
|
||||
|
||||
|
@ -5448,6 +5448,43 @@ class e107
|
||||
return self::getConfig()->isData('plug_installed/'.$plugname);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the number is compatible with this version of e107.
|
||||
* @param string $version The minimum version requirement
|
||||
* @return bool
|
||||
*/
|
||||
public static function isCompatible($version)
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
|
||||
$e107info = [];
|
||||
include(e_ADMIN."ver.php"); // $e107info['e107_version'];
|
||||
|
||||
$e107 = $tp->filter($e107info['e107_version'], 'version');
|
||||
$version = $tp->filter($version, 'version');
|
||||
|
||||
$tmp = explode('.', $version);
|
||||
|
||||
if((int) $tmp[0] === 1) // version 1, assumed to be incompatible.
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isset($tmp[2])) // ie. 2.3.1
|
||||
{
|
||||
return version_compare($e107 ,$version, '>=');
|
||||
}
|
||||
elseif(isset($tmp[1]))
|
||||
{
|
||||
return ((float) $e107 >= $version);
|
||||
}
|
||||
|
||||
return ((int) $e107 >= (int) $version);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe way to set ini var
|
||||
* @param string $var
|
||||
|
@ -296,7 +296,7 @@ class e_parse
|
||||
'onwheel', 'oncopy', 'oncut', 'onpaste'
|
||||
);
|
||||
|
||||
private $blockTags = array('pre', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote'); // element includes its own line-break.
|
||||
private $blockTags = array('p', 'pre', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote'); // element includes its own line-break.
|
||||
|
||||
|
||||
private $scriptAccess = false; // nobody.
|
||||
@ -1364,6 +1364,25 @@ class e_parse
|
||||
return e107::getBB()->parseBBCodes($text, $postID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips block tags from html.
|
||||
* ie. <p> <div> <blockquote> <h1> <h2> <h3> etc are removed.
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public function stripBlockTags($html)
|
||||
{
|
||||
$diff = array_diff($this->allowedTags, $this->blockTags);
|
||||
|
||||
$parm = '';
|
||||
foreach($diff as $tag)
|
||||
{
|
||||
$parm .= '<'.$tag.'>';
|
||||
}
|
||||
|
||||
return strip_tags($html, $parm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts the text (presumably retrieved from the database) for HTML output.
|
||||
|
@ -1623,6 +1623,39 @@ class e107Test extends \Codeception\Test\Unit
|
||||
|
||||
// var_dump($result);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
|
||||
public function testIsCompatible()
|
||||
{
|
||||
// version => expected
|
||||
$tests = array (
|
||||
'1' => false, // assumed incompatible.
|
||||
'2' => true, // assumed to work with all versions from 2+
|
||||
'2.0' => true, // assumed to work with all versions from 2+
|
||||
'2.3' => true, // assumed to work with all versions from 2.3 onward.
|
||||
'2.1.0' => true,
|
||||
'2.2.0' => true,
|
||||
'2.3.0' => true,
|
||||
'2.3.1' => true,
|
||||
'1.7b' => false,
|
||||
'2.9' => false,
|
||||
'2.9.2' => false,
|
||||
'3' => false,
|
||||
|
||||
);
|
||||
|
||||
$e107 = $this->e107;
|
||||
// $ret = [];
|
||||
foreach($tests as $input=>$expected)
|
||||
{
|
||||
$result = $e107::isCompatible($input);
|
||||
$this->assertSame($expected, $result);
|
||||
// $ret[$input] = $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
public function testIni_set()
|
||||
|
@ -33,8 +33,34 @@
|
||||
$this->tp->init();
|
||||
}
|
||||
|
||||
public function testStripBlockTags()
|
||||
{
|
||||
$tests = array(
|
||||
0 => array(
|
||||
'text' => '<p>Paragraph 1</p><p><b>Paragraph 2<br >Line 3</b></p>',
|
||||
'expected' => "Paragraph 1<b>Paragraph 2<br >Line 3</b>",
|
||||
),
|
||||
|
||||
|
||||
);
|
||||
|
||||
foreach($tests as $var)
|
||||
{
|
||||
$result = $this->tp->stripBlockTags($var['text']);
|
||||
|
||||
if(empty($var['expected']))
|
||||
{
|
||||
echo $result."\n\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertEquals($var['expected'], $result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public function testHtmlAbuseFilter()
|
||||
{
|
||||
|
@ -493,7 +493,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
|
||||
'page_metakeys' => 'keywords',
|
||||
'page_metadscr' => 'Meta Description',
|
||||
'page_metarobots' => 'noindex',
|
||||
'page_text' => '[html]<p>Lorem ipsum dolor sit amet, <sup>1</sup> consectetur adipiscing elit. Donec libero ipsum; imperdiet at risus non.</p>[/html]',
|
||||
'page_text' => '[html]<p>Lorem ipsum dolor sit amet</p><p>Suspendisse <b>placerat</b> nunc orci</p>[/html]',
|
||||
'page_author' => '1',
|
||||
'page_datestamp' => '1371420000',
|
||||
'page_rating_flag' => '1',
|
||||
@ -519,6 +519,17 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
|
||||
|
||||
$exclude = array('sc_cpagemessage'); // system messages
|
||||
|
||||
$parms = array(
|
||||
'cpagebody' => array(
|
||||
': strip=blocks' => '<!-- bbcode-html-start --><p>Main Body</p><!-- bbcode-html-end -->',
|
||||
'=extended' => '<!-- bbcode-html-start --><p><strong>Extended Body</strong></p><!-- bbcode-html-end -->',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$this->processShortcodeMethods($sc, null, $exclude);
|
||||
|
||||
}
|
||||
@ -928,7 +939,7 @@ class e_parse_shortcodeTest extends \Codeception\Test\Unit
|
||||
|
||||
}
|
||||
|
||||
public function testFpwShortcodes() // todo move fpw shortcodes out of fpw.php to its own file.
|
||||
public function testFpwShortcodes()
|
||||
{
|
||||
require_once(e_CORE."shortcodes/batch/fpw_shortcodes.php");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user