1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Parser - first cut of restructuring of control logic

This commit is contained in:
e107steved
2009-01-03 22:32:54 +00:00
parent 5732bc1f4c
commit adce648182

View File

@@ -1,20 +1,18 @@
<?php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
| Steve Dunstan 2001-2002
| http://e107.org
| jalist@e107.org
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $
| $Revision: 1.47 $
| $Date: 2008-12-30 13:51:41 $
| $Author: secretr $
+----------------------------------------------------------------------------+
* e107 website system
*
* Copyright (C) 2001-2008 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Text processing and parsing functions
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $
* $Revision: 1.48 $
* $Date: 2009-01-03 22:32:54 $
* $Author: e107steved $
*
*/
if (!defined('e107_INIT')) { exit; }
@@ -23,91 +21,130 @@ define('E_UTF8_PACK',e_HANDLER.'utf8/'); // Directory for the hard-coded utf-8
define ("E_NL", chr(2));
class e_parse
{
var $isutf8 = FALSE; // Flag for global use indicates whether utf-8 character set
var $utfAction; // Determine how to handle utf-8. 0 = 'do nothing' 1 = 'use mb_string' 2 = emulation
var $e_sc;
var $e_bb;
var $e_pf;
var $e_emote;
var $e_hook;
var $e_sc; // Shortcode processor
var $e_bb; // BBCode processor
var $e_pf; // Profanity filter
var $e_emote; // Emote filter
var $e_hook; // 'Hooked' parsers (array)
var $search = array('&#39;', '&#039;', '&quot;', 'onerror', '&gt;', '&amp;#039;', '&amp;quot;', ' & ');
var $replace = array("'", "'", '"', 'one<i></i>rror', '>', "'", '"', ' &amp; ');
var $e_highlighting; // Set to TRUE or FALSE once it has been calculated
var $e_query; // Highlight query
// toHTML Action defaults. For now these match existing convention.
// Let's reverse the logic on the first set ASAP; too confusing!
// Set up the defaults
var $e_optDefault = array(
'context' => 'olddefault', // default context: all "opt-out" conversions :(
'context' => 'OLDDEFAULT', // default context: reflects legacy settings (many items enabled)
'fromadmin' => FALSE,
// Enabled by Default
'emotes' => TRUE, // Enable emote display
'defs' => FALSE, // Convert defines(constants) within text.
'constants' => FALSE, // replace all {e_XXX} constants with their e107 value - 'rel' or 'abs'
'hook' => TRUE, // Enable hooked parsers
'scripts' => TRUE, // Allow scripts through (new for 0.8)
'link_click' => TRUE, // Make links clickable
'link_replace' => TRUE, // Substitute on clickable links (only if link_click == TRUE)
'parse_sc' => FALSE, // Parse shortcodes - TRUE enables parsing
'no_tags' => FALSE, // remove HTML tags.
'value' => FALSE, // Restore entity form of quotes and such to single characters - TRUE disables
'nobreak' => FALSE, // Line break compression - TRUE removes multiple line breaks
'retain_nl' => FALSE, // Retain newlines - wraps to \n instead of <br /> if TRUE
'no_make_clickable' => FALSE, // URLs etc are clickable - TRUE disables
'no_replace' => FALSE, // Replace clickable links - TRUE disables (only if no_make_clickable not set)
'emotes_off' => FALSE, // Convert emoticons to graphical icons - TRUE disables conversion
'emotes_on' => FALSE, // FORCE conversion to emotes, even if syspref is disabled
'no_hook' => FALSE, // Hooked parsers (TRUE disables completely) (deprecated)
// Disabled by Default
'defs' => FALSE, // Convert defines(constants) within text.
'constants' => FALSE, // replace all {e_XXX} constants with their e107 value
'abs_links' => FALSE, // Convert constants to absolute paths if TRUE
'parse_sc' => FALSE, // Parse shortcodes - TRUE enables parsing
'no_tags' => FALSE // remove HTML tags.
'retain_nl' => FALSE // Retain newlines - wraps to \n instead of <br /> if TRUE
);
// Super modifiers adjust default option values
// First line of adjustments change default-ON options
// Second line changes default-OFF options
// Super modifiers override default option values
var $e_SuperMods = array(
'TITLE' => //text is part of a title (e.g. news title)
array(
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,
'defs'=>TRUE,'parse_sc'=>TRUE),
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'link_click' => FALSE, 'emotes'=>FALSE, 'defs'=>TRUE, 'parse_sc'=>TRUE
),
'USER_TITLE' => //text is user-entered (i.e. untrusted) and part of a title (e.g. forum title)
array(
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'link_click' => FALSE, 'scripts' => FALSE, 'emotes'=>FALSE, 'hook'=>FALSE
),
'E_TITLE' => // text is 'body' of email or similar - being sent 'off-site' so don't rely on server availability
array(
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'defs'=>TRUE, 'parse_sc'=>TRUE, 'emotes'=>FALSE, 'scripts' => FALSE, 'link_click' => FALSE
),
'SUMMARY' => // text is part of the summary of a longer item (e.g. content summary)
array(
// no changes to default-on items
'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
'defs'=>TRUE, 'constants'=>'rel', 'parse_sc'=>TRUE
),
'DESCRIPTION' => // text is the description of an item (e.g. download, link)
array(
// no changes to default-on items
'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
'defs'=>TRUE, 'constants'=>'rel', 'parse_sc'=>TRUE
),
'BODY' => // text is 'body' or 'bulk' text (e.g. custom page body, content body)
array(
// no changes to default-on items
'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
'defs'=>TRUE, 'constants'=>'rel', 'parse_sc'=>TRUE
),
'USER_BODY' => // text is user-entered (i.e. untrusted)'body' or 'bulk' text (e.g. custom page body, content body)
array(
'constants'=>TRUE
'constants'=>TRUE, 'scripts' => FALSE
),
'E_BODY' => // text is 'body' of email or similar - being sent 'off-site' so don't rely on server availability
array(
'defs'=>TRUE, 'constants'=>'abs', 'parse_sc'=>TRUE, 'emotes'=>FALSE, 'scripts' => FALSE, 'link_click' => FALSE
),
'LINKTEXT' => // text is the 'content' of a link (A tag, etc)
array(
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,
'defs'=>TRUE,'parse_sc'=>TRUE),
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'link_click' => FALSE, 'emotes_on'=>FALSE, 'hook'=>FALSE, 'defs'=>TRUE, 'parse_sc'=>TRUE
),
'RAWTEXT' => // text is used (for admin edit) without fancy conversions or html.
array(
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,'no_tags'=>TRUE
// leave opt-in options off
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'link_click' => FALSE, 'emotes'=>FALSE, 'hook'=>FALSE, 'no_tags'=>TRUE
)
);
// Individual modifiers change the current context
var $e_Modifiers = array(
'emotes_off' => array('emotes_on' => FALSE),
'emotes_on' => array('emotes_on' => TRUE),
'no_hook' => array('hook' => FALSE),
'do_hook' => array('hook' => TRUE),
'scripts_off' => array('scripts' => FALSE), // New for 0.8
'scripts_on' => array('scripts' => TRUE), // New for 0.8
'no_make_clickable' => array('link_click' => FALSE),
'make_clickable' => array('link_click' => TRUE),
'no_replace' => array('link_replace' => FALSE),
'replace' => array('link_replace' => TRUE), // Replace text of clickable links (only if make_clickable option set)
'consts_off' => array('constants' => FALSE), // No path replacement
'consts_rel' => array('constants' => 'rel'), // Relative path replacement
'consts_abs' => array('constants' => 'abs'), // Absolute path replacement
'scparse_off' => array('parse_sc' => FALSE), // No shortcode parsing
'scparse_on' => array('parse_sc' => TRUE),
'no_tags' => array('no_tags' => TRUE), // Strip tags
'do_tags' => array('no_tags' => FALSE), // Leave tags
'fromadmin' => array('fromadmin' => TRUE),
'notadmin' => array('fromadmin' => FALSE),
'er_off' => array('value' => FALSE), // entity replacement
'er_on' => array('value' => TRUE),
'defs_off' => array('defs' => FALSE), // Decode constant if exists
'defs_on' => array('defs' => TRUE),
'dobreak' => array('nobreak' => TRUE),
'nobreak' => array('nobreak' => FALSE),
'lb_nl' => array('retain_nl' => TRUE), // Line break using \n
'lb_br' => array('retain_nl' => FALSE), // Line break using <br />
// Legacy option names below here - discontinue later
'retain_nl' => array('retain_nl' => TRUE),
'defs' => array('defs' => TRUE),
'parse_sc' => array('parse_sc' => TRUE),
'constants' => array('constants' => 'rel'),
'value' => array('value' => TRUE)
);
function e_parse()
{
// Preprocess the supermods to be useful default arrays with all values
@@ -125,7 +162,10 @@ class e_parse
{
// Start by working out what, if anything, we do about utf-8 handling.
$this->utfAction = 0; // 'Do nothing' is the simple option
if ((strtolower(CHARSET) == 'utf-8') && (version_compare(PHP_VERSION, '6.0.0') < 1))
if (strtolower(CHARSET) == 'utf-8')
{
$this->isutf8 = TRUE;
if (version_compare(PHP_VERSION, '6.0.0') < 1)
{ // Need to do something here
if(extension_loaded('mbstring'))
{
@@ -144,6 +184,7 @@ class e_parse
}
}
}
}
function uStrLen($str)
@@ -170,6 +211,7 @@ class e_parse
return utf8_strtolower($str);
}
function uStrToUpper($str)
{
switch ($this->utfAction)
@@ -193,6 +235,7 @@ class e_parse
utf8_strpos($haystack, $needle, $offset);
}
function uStrrPos($haystack, $needle, $offset = 0)
{
switch ($this->utfAction)
@@ -248,12 +291,17 @@ class e_parse
* $mod: the 'no_html' and 'no_php' modifiers blanket prevent html and php posting regardless of posting permissions. (used in logging)
*/
global $pref;
if (is_array($data)) {
foreach ($data as $key => $var) {
if (is_array($data))
{
foreach ($data as $key => $var)
{
$ret[$key] = $this -> toDB($var, $nostrip, $no_encode, $mod, $original_author);
}
} else {
if (MAGIC_QUOTES_GPC == true && $nostrip == false) {
}
else
{
if (MAGIC_QUOTES_GPC == true && $nostrip == false)
{
$data = stripslashes($data);
}
if (isset($pref['post_html']) && check_class($pref['post_html']))
@@ -269,7 +317,9 @@ class e_parse
$search = array('$', '"', "'", '\\', '<?');
$replace = array('&#036;','&quot;','&#039;', '&#092;', '&lt;?');
$ret = str_replace($search, $replace, $data);
} else {
}
else
{
$data = htmlspecialchars($data, ENT_QUOTES, CHARSET);
$data = str_replace('\\', '&#092;', $data);
$ret = preg_replace("/&amp;#(\d*?);/", "&#\\1;", $data);
@@ -278,9 +328,7 @@ class e_parse
{
$ret = str_replace(array("[php]", "[/php]"), array("&#91;php&#93;", "&#91;/php&#93;"), $ret);
}
}
return $ret;
}
@@ -291,28 +339,33 @@ class e_parse
$search = array('&#036;', '&quot;', '<', '>');
$replace = array('$', '"', '&lt;', '&gt;');
$text = str_replace($search, $replace, $text);
if (e_WYSIWYG !== true){
if (e_WYSIWYG !== true)
{
$text = str_replace("&nbsp;", " ", $text); // fix for utf-8 issue with html_entity_decode();
}
return $text;
}
function post_toForm($text) {
if (MAGIC_QUOTES_GPC == true) {
function post_toForm($text)
{
if (MAGIC_QUOTES_GPC == true)
{
$text = stripslashes($text);
}
return str_replace(array( "'", '"', "<", ">"), array("&#039;", "&quot;", "&lt;", "&gt;"), $text);
}
function post_toHTML($text, $original_author = false, $extra = '', $mod = false) {
function post_toHTML($text, $original_author = false, $extra = '', $mod = false)
{
$text = $this -> toDB($text, false, false, $mod, $original_author);
return $this -> toHTML($text, true, $extra);
}
function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = "") {
function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = "")
{
$this->sch_load();
return $this->e_sc->parseCodes($text, $parseSCFiles, $extraCodes);
}
@@ -328,6 +381,8 @@ class e_parse
$nobreak is a list of tags within which word wrap is to be inactive
*/
return $str;
if (!ctype_digit($width)) return $str; // Don't wrap if non-numeric width
if ($width < 6) return $str; // Trap stupid wrap counts, as well
@@ -593,19 +648,20 @@ class e_parse
}
function textclean ($text, $wrap=100)
{
$text = str_replace ("\n\n\n", "\n\n", $text);
$text = $this->htmlwrap($text, $wrap);
$text = str_replace (array ("<br /> ", " <br />", " <br /> "), "<br />", $text);
$text = str_replace (array ('<br /> ', ' <br />', ' <br /> '), '<br />', $text);
/* we can remove any linebreaks added by htmlwrap function as any \n's will be converted later anyway */
return $text;
}
//
// Test for text highlighting, and determine the text highlighting transformation
// Returns TRUE if highlighting is active for this page display
//
function checkHighlighting()
{
global $pref;
@@ -633,6 +689,8 @@ class e_parse
}
function toHTML($text, $parseBB = FALSE, $modifiers = "", $postID = "", $wrap=FALSE)
{
if ($text == '') return $text;
@@ -643,30 +701,38 @@ class e_parse
$opts = $this->e_optDefault;
// Now process any modifiers that are specified
if (strlen($modifiers))
if ($modifiers)
{
$aMods = explode(',',$modifiers);
// If there's a supermodifier, it must be first, and in uppercase
$psm = trim($aMods[0]);
if (isset($this->e_SuperMods[$psm]))
{
$opts = array_merge($this->e_optDefault,$this->e_SuperMods[$psm]);
{ // Supermodifier found - it simply overrides the default
$opts = $this->e_SuperMods[$psm];
$opts['context'] = $psm;
unset($aMods[0]);
}
else
{
// Set default modifiers
$opts = $this->e_optDefault;
}
// Now find any regular mods (could check each exists, but unnecessary processing really)
// Now find any regular modifiers; use them to modify the context (there should only be one or two out of the list of possibles)
foreach ($aMods as $mod)
{
$opts[trim($mod)] = TRUE; // Change mods as spec'd
$mod = trim($mod); // Slight concession to varying coding styles
if (isset($this->e_Modifiers[$mod]))
{
foreach ($this->e_Modifiers[$mod] as $k => $v) // This is probably quicker than array_merge - especially as usually only one or two loops
{
$opts[$k] = $v; // Update our context-specific options
}
}
}
}
// Turn off a few things if not enabled in options
if (!varsettrue($pref['smiley_activate'])) $opts['emotes'] = FALSE;
if (!varsettrue($pref['make_clickable'])) $opts['link_click'] = FALSE;
if (!varsettrue($pref['link_replace'])) $opts['link_replace'] = FALSE;
$fromadmin = $opts['fromadmin'];
@@ -678,6 +744,7 @@ class e_parse
}
if ($opts['no_tags'])
{
$text = strip_tags($text);
@@ -685,8 +752,11 @@ class e_parse
// Make sure we have a valid count for word wrapping
if(!$wrap && $pref['main_wordwrap']) $wrap = $pref['main_wordwrap'];
$text = " ".$text;
if (!$wrap && $pref['main_wordwrap'])
{
$wrap = $pref['main_wordwrap'];
}
// $text = " ".$text;
@@ -781,14 +851,16 @@ class e_parse
$subcon = preg_split('#((?:<s)(?:cript[^>]+>.*?</script>|tyle[^>]+>.*?</style>))#mis', $full_text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
foreach ($subcon as $sub_blk)
{
// if (preg_match('#^<(script|style)[^>]+>#',$sub_blk)) //
if ((substr($sub_blk,0,7) == '<script') || (substr($sub_blk,0,6) == '<style'))
{ // Its a script/style block - just pass it through unaltered - except, do we need the line break stuff? - QUERY XXX-01
if (DB_INF_SHOW) echo "Processing script: {$sub_blk}<br />";
if (!$opts['nobreak'])
if (substr($sub_blk,0,7) == '<script')
{
$sub_blk = preg_replace("#>\s*[\r]*\n[\r]*#", ">", $sub_blk);
if ($opts['scripts'])
{
$ret_parser .= $sub_blk; // Strip scripts unless permitted
}
}
elseif (substr($sub_blk,0,6) == '<style')
{ // Its a style block - just pass it through unaltered - except, do we need the line break stuff? - QUERY XXX-01
if (DB_INF_SHOW) echo "Processing stylesheet: {$sub_blk}<br />";
$ret_parser .= $sub_blk;
}
else
@@ -798,50 +870,44 @@ class e_parse
// Could put tag stripping in here
// Line break compression (why?)
// Prepare for line-break compression. Avoid compressing newlines in embedded scripts and CSS
/*
// Line break compression - filter white space after HTML tags
if (!$opts['nobreak'])
{
$sub_blk = preg_replace("#>\s*[\r]*\n[\r]*#", ">", $sub_blk);
}
*/
// Link substitution
// Convert URL's to clickable links, unless modifiers or prefs override
if ($pref['make_clickable'] && !$opts['no_make_clickable'])
if ($opts['link_click'])
{
if ($pref['link_replace'] && !$opts['no_replace'])
if ($opts['link_replace'])
{
$_ext = ($pref['links_new_window'] ? " rel=\"external\"" : "");
// $sub_blk = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<,]*)#is", "\\1<a href=\"\\2\" {$_ext}>".$pref['link_text']."</a>", $sub_blk);
$sub_blk = preg_replace("#(^|[\s])([\w]+?://(?:[\w-%]+?)(?:\.[\w-%]+?)+.*?)(?=$|[\s()[\]<]|\.\s|\.$|,\s|,$)#is", "\\1<a href=\"\\2\" {$_ext}>".$pref['link_text']."</a>", $sub_blk);
// $sub_blk = preg_replace("#(^|[\n \]])((www|ftp)\.[\w+-]+?\.[\w+\-.]*(?(?=/)(/.+?(?=\s|,\s))|(?=\W)))#is", "\\1<a href=\"http://\\2\" {$_ext}>".$pref['link_text']."</a>", $sub_blk);
$sub_blk = preg_replace("#(^|[\s])((?:www|ftp)(?:\.[\w-%]+?){2}.*?)(?=$|[\s()[\]<]|\.\s|\.$|,\s|,$)#is", "\\1<a href=\"http://\\2\" {$_ext}>".$pref['link_text']."</a>", $sub_blk);
if(CHARSET != "utf-8" && CHARSET != "UTF-8")
if ($this->isutf8)
{
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2&copy;\\3";
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2©\\3";
}
else
{
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2©\\3";
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2&copy;\\3";
}
$sub_blk = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a rel='external' href='javascript:window.location=\"mai\"+\"lto:\"+\"\\2\"+\"@\"+\"\\3\";self.close();' onmouseover='window.status=\"mai\"+\"lto:\"+\"\\2\"+\"@\"+\"\\3\"; return true;' onmouseout='window.status=\"\";return true;'>".$email_text."</a>", $sub_blk);
}
else
{
// $sub_blk = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<,]*)#is", "\\1<a href=\"\\2\" rel=\"external\">\\2</a>", $sub_blk);
$sub_blk = preg_replace("#(^|[\s])([\w]+?://(?:[\w-%]+?)(?:\.[\w-%]+?)+.*?)(?=$|[\s()[\]<]|\.\s|\.$|,\s|,$)#is", "\\1<a href=\"\\2\" rel=\"external\">\\2</a>", $sub_blk);
// $sub_blk = preg_replace("#(^|[\n \]])((www|ftp)\.[\w+-]+?\.[\w+\-.]*(?(?=/)(/.+?(?=\s|,\s))|(?=\W)))#is", "\\1<a href=\"http://\\2\" rel=\"external\">\\2</a>", $sub_blk);
$sub_blk = preg_replace("#(^|[\s])((?:www|ftp)(?:\.[\w-%]+?){2}.*?)(?=$|[\s()[\]<]|\.\s|\.$|,\s|,$)#is", "\\1<a href=\"http://\\2\" rel=\"external\">\\2</a>", $sub_blk);
$sub_blk = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a rel='external' href='javascript:window.location=\"mai\"+\"lto:\"+\"\\2\"+\"@\"+\"\\3\";self.close();' onmouseover='window.status=\"mai\"+\"lto:\"+\"\\2\"+\"@\"+\"\\3\"; return true;' onmouseout='window.status=\"\";return true;'>".LAN_EMAIL_SUBS."</a>", $sub_blk);
}
}
// Emoticons
// Convert emoticons to graphical icons, unless modifiers override
if (!$opts['emotes_off'] && ($pref['smiley_activate'] || $opts['emotes_on']))
// Convert emoticons to graphical icons, if enabled
if ($opts['emotes'])
{
if (!is_object($this->e_emote))
{
@@ -853,8 +919,7 @@ class e_parse
// Newline processing (more)
// Reduce multiple newlines in all forms to a single newline character, except for embedded scripts and CSS
// Reduce newlines in all forms to a single newline character (finds '\n', '\r\n', '\n\r')
if (!$opts['nobreak'])
{
$sub_blk = preg_replace("#[\r]*\n[\r]*#", E_NL, $sub_blk);
@@ -864,18 +929,18 @@ class e_parse
// Entity conversion
// Restore entity form of quotes and such to single characters, except for text destined for tag attributes or JS.
if (!$opts['value'])
{ // output not used for attribute values.
$sub_blk = str_replace($this -> search, $this -> replace, $sub_blk);
}
else
if ($opts['value'])
{ // output used for attribute values.
$sub_blk = str_replace($this -> replace, $this -> search, $sub_blk);
}
else
{ // output not used for attribute values.
$sub_blk = str_replace($this -> search, $this -> replace, $sub_blk);
}
// BBCode processing (other than the four already done, which shouldn't appear at all in the text)
// Start parse [bb][/bb] codes
if ($parseBB !== FALSE)
{
if (!is_object($this->e_bb))
@@ -896,7 +961,6 @@ class e_parse
$sub_blk = $this->e_bb->parseBBCodes($sub_blk, $postID, 'default', $parseBB); // Need to strip just some BBCodes
}
}
// End parse [bb][/bb] codes
@@ -904,7 +968,7 @@ class e_parse
// (Moved to after bbcode processing by Cameron)
if ($opts['constants'])
{
$sub_blk = $this->replaceConstants($sub_blk, ($opts['abs_links'] ? 'full' : ''));
$sub_blk = $this->replaceConstants($sub_blk, ($opts['constants'] == 'abs' ? 'full' : ''));
}
@@ -931,7 +995,7 @@ class e_parse
//Run any hooked in parsers
if (!$opts['no_hook'])
if ($opts['hook'])
{
if ( varset($pref['tohtml_hook']))
{ //Process the older tohtml_hook pref (deprecated)
@@ -963,9 +1027,8 @@ class e_parse
}
// Word wrap
if (!$opts['nobreak'])
if ($wrap && !$opts['nobreak'])
{
$sub_blk = $this -> textclean($sub_blk, $wrap);
}
@@ -973,8 +1036,7 @@ class e_parse
// Search highlighting
// Search Highlight
if (!$opts['emotes_off'])
if ($opts['emotes']) // Why??
{
if ($this->checkHighlighting())
{
@@ -983,8 +1045,7 @@ class e_parse
}
// Purpose of this block?
$nl_replace = "<br />";
$nl_replace = '<br />'; // Default replaces all \n with <br /> for HTML display
if ($opts['nobreak'])
{
$nl_replace = '';
@@ -1001,7 +1062,6 @@ class e_parse
} // End of 'foreach() on each block of non-script text
} // End of 'normal' parsing (non-script text)
else
{
@@ -1012,19 +1072,26 @@ class e_parse
}
function toAttribute($text) {
function toAttribute($text)
{
$text = str_replace("&amp;","&",$text); // URLs posted without HTML access may have an &amp; in them.
$text = htmlspecialchars($text, ENT_QUOTES, CHARSET); // Xhtml compliance.
if (!preg_match('/&#|\'|"|\(|\)|<|>/s', $text))
{
$text = $this->replaceConstants($text);
return $text;
} else {
}
else
{
return '';
}
}
function toJS($stringarray) {
// Convert text blocks which are to be embedded within JS
function toJS($stringarray)
{
$search = array("\r\n","\r","<br />","'");
$replace = array("\\n","","\\n","\'");
$stringarray = str_replace($search, $replace, $stringarray);
@@ -1036,9 +1103,10 @@ class e_parse
return strtr ($stringarray, $trans_tbl);
}
function toRss($text,$tags=FALSE)
{
if($tags != TRUE)
{
$text = $this -> toHTML($text,TRUE);
@@ -1101,12 +1169,14 @@ class e_parse
SITEURL.$THEMES_DIRECTORY,
SITEURL.$DOWNLOADS_DIRECTORY);
$search = array("{e_BASE}","{e_IMAGE_ABS}","{e_THEME_ABS}","{e_IMAGE}","{e_PLUGIN}","{e_FILE}","{e_THEME}","{e_DOWNLOAD}");
if (ADMIN) {
if (ADMIN)
{
$replace_relative[] = $ADMIN_DIRECTORY;
$replace_absolute[] = SITEURL.$ADMIN_DIRECTORY;
$search[] = "{e_ADMIN}";
}
if ($all) {
if ($all)
{
if (USER)
{ // Can only replace with valid number for logged in users
$replace_relative[] = USERID;
@@ -1131,6 +1201,7 @@ class e_parse
return $text;
}
function doReplace($matches)
{
if(defined($matches[1]) && ($matches[1] != 'e_ADMIN' || ADMIN))
@@ -1178,11 +1249,13 @@ class e_parse
}
function e_highlight($text, $match) {
function e_highlight($text, $match)
{
preg_match_all("#<[^>]+>#", $text, $tags);
$text = preg_replace("#<[^>]+>#", "<|>", $text);
$text = preg_replace("#(\b".$match."\b)#i", "<span class='searchhighlight'>\\1</span>", $text);
foreach ($tags[0] as $tag) {
foreach ($tags[0] as $tag)
{
$text = preg_replace("#<\|>#", $tag, $text, 1);
}
return $text;