Skip to content

Commit

Permalink
Null checks for e107TinyMceParserTest
Browse files Browse the repository at this point in the history
- FIX: Do not redefine e_ADMIN_AREA in parser.php
- FIX: Null checks for e107TinyMceParser
- FIX: Array type check for e_bbcode::imgToBBcode()
- FIX: Optional query string in e_parse::thumbUrlDecode()
- FIX: Don't redefine TINYMCE_UNIT_TEST
  • Loading branch information
Deltik committed Jan 18, 2020
1 parent c604b30 commit b2bd676
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions e107_handlers/bbcode_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ function imgToBBcode($html, $fromDB = false)
print_a($arr);
}

$arr['img'] = isset($arr['img']) && is_array($arr['img']) ? $arr['img'] : [];
foreach($arr['img'] as $img)
{
if(/*substr($img['src'],0,4) == 'http' ||*/ strpos($img['src'], e_IMAGE_ABS.'emotes/')!==false) // dont resize external images or emoticons.
Expand Down
2 changes: 1 addition & 1 deletion e107_handlers/e_parse_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2914,7 +2914,7 @@ public function thumbUrl($url=null, $options = array(), $raw = false, $full = fa
*/
function thumbUrlDecode($src)
{
list($url,$qry) = explode("?",$src);
list($url,$qry) = array_pad(explode("?",$src), 2, null);

$ret = array();

Expand Down
18 changes: 14 additions & 4 deletions e107_plugins/tinymce4/plugins/e107/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$_E107['no_forceuserupdate'] = true;
$_E107['no_maintenance'] = true;

define('e_ADMIN_AREA', true);
if (!defined('e_ADMIN_AREA')) define('e_ADMIN_AREA', true);
if(!defined('TINYMCE_DEBUG') && !defined('TINYMCE_UNIT_TEST'))
{
require_once("../../../../class2.php");
Expand All @@ -42,6 +42,9 @@ class e107TinyMceParser
*/
function __construct()
{
$_POST['mode'] = isset($_POST['mode']) ? $_POST['mode'] : 'tohtml';
$_POST['content'] = isset($_POST['content']) ? $_POST['content'] : '';

$html = '';

if(defined('TINYMCE_DEBUG') || defined('TINYMCE_UNIT_TEST'))
Expand Down Expand Up @@ -70,7 +73,6 @@ function __construct()
TEMPL;
}
$_POST['content'] = $text;
$_POST['mode'] = 'tohtml';
}
else
{
Expand Down Expand Up @@ -119,7 +121,7 @@ public function toHTML($content)
$content = stripslashes($content);

// $content = e107::getBB()->htmltoBBcode($content); //XXX This breaks inserted images from media-manager. :/
e107::getBB()->setClass($_SESSION['media_category']);
e107::getBB()->setClass($this->getMediaCategory());

if(check_class($pref['post_html'])) // raw HTML within [html] tags.
{
Expand Down Expand Up @@ -197,7 +199,7 @@ function toBBcode($content)
$pref = e107::getPref();
// $tp = e107::getParser();

e107::getBB()->setClass($_SESSION['media_category']);
e107::getBB()->setClass($this->getMediaCategory());

$content = stripslashes($content);

Expand Down Expand Up @@ -231,6 +233,14 @@ function toBBcode($content)

}

/**
* @return mixed|null
*/
private function getMediaCategory()
{
return isset($_SESSION['media_category']) ? $_SESSION['media_category'] : null;
}




Expand Down
2 changes: 1 addition & 1 deletion e107_tests/tests/unit/plugins/e107TinyMceParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class e107TinyMceParserTest extends \Codeception\Test\Unit

protected function _before()
{
define('TINYMCE_UNIT_TEST', true);
@define('TINYMCE_UNIT_TEST', true);
require_once(e_PLUGIN."tinymce4/plugins/e107/parser.php");
try
{
Expand Down

0 comments on commit b2bd676

Please sign in to comment.