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

Committed wrong version of file earlier

This commit is contained in:
e107steved 2007-12-30 23:31:18 +00:00
parent 70ce209d84
commit ab8aa3ee78

View File

@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/e_parse_class.php,v $
| $Revision: 1.25 $
| $Date: 2007-12-30 16:54:31 $
| $Revision: 1.26 $
| $Date: 2007-12-30 23:31:18 $
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/
@ -55,7 +55,8 @@ class e_parse
// Disabled by Default
'defs' => FALSE, // Convert defines(constants) within text.
'constants' => FALSE, // replace all {e_XXX} constants with their e107 value
'parse_sc' => FALSE // Parse shortcodes - TRUE enables parsing
'parse_sc' => FALSE, // Parse shortcodes - TRUE enables parsing
'no_tags' => FALSE // remove HTML tags.
);
// Super modifiers adjust default option values
@ -97,14 +98,13 @@ class e_parse
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,
'defs'=>TRUE,'parse_sc'=>TRUE),
'rawtext' => // text is used (for admin edit) without fancy conversions
'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,
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,'no_tags'=>TRUE
// leave opt-in options off
)
);
function e_parse()
{
// Preprocess the supermods to be useful default arrays with all values
@ -123,28 +123,28 @@ class e_parse
// Initialise the shortcode handler - has to be done when $prefs valid, so can't be done in constructor ATM
function sch_load()
{
if (!is_object($this->e_sc))
{
require_once(e_HANDLER."shortcode_handler.php");
$this->e_sc = new e_shortcode;
}
if (!is_object($this->e_sc))
{
require_once(e_HANDLER."shortcode_handler.php");
$this->e_sc = new e_shortcode;
}
}
function toDB($data, $nostrip = false, $no_encode = false, $original_author = false, $mod = false)
function toDB($data, $nostrip = false, $no_encode = false, $mod = false, $original_author = false)
{
/**
* $nostrip: toDB() assumes all data is GPC ($_GET, $_POST, $_COOKIE) unless you indicate otherwise by setting this var to true.
* If magic quotes is enabled on the server and you do not tell toDB() that the data is non GPC then slashes will be stripped when they should not be.
* $no_encode: This var should nearly always be false. It is used by the save_prefs() function to preserve html content within prefs even when
* the save_prefs() function has been called by a non admin user / user without html posting permissions.
* $mod: although not used in core, the 'no_html' and 'no_php' modifiers are available for plugins to blanket prevent html and php posting regardless
* of posting permissions.
* $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) {
$ret[$key] = $this -> toDB($var, $nostrip, $no_encode, $original_author, $mod);
$ret[$key] = $this -> toDB($var, $nostrip, $no_encode, $mod, $original_author);
}
} else {
if (MAGIC_QUOTES_GPC == true && $nostrip == false) {
@ -168,7 +168,7 @@ class e_parse
$data = str_replace('\\', '\', $data);
$ret = preg_replace("/&#(\d*?);/", "&#\\1;", $data);
}
if (!check_class($pref['php_bbcode']) || (is_numeric($original_author) && !check_class($pref['php_bbcode'], '', $original_author)) || strpos($mod, 'no_php') !== false)
if (strpos($mod, 'no_php') !== false)
{
$ret = str_replace(array("[php]", "[/php]"), array("[php]", "[/php]"), $ret);
}
@ -201,89 +201,135 @@ class e_parse
function post_toHTML($text, $original_author = false, $extra = '', $mod = false) {
$text = $this -> toDB($text, false, false, $original_author, $mod);
$text = $this -> toDB($text, false, false, $mod, $original_author);
return $this -> toHTML($text, true, $extra);
}
function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = "")
{
if (!is_object($this->e_sc))
{
require_once(e_HANDLER."shortcode_handler.php");
$this->e_sc = new e_shortcode;
}
return $this->e_sc->parseCodes($text, $parseSCFiles, $extraCodes);
function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = "") {
return $this->e_sc->parseCodes($text, $parseSCFiles, $extraCodes);
}
function htmlwrap($str, $width, $break = "\n", $nobreak = "", $nobr = "pre", $utf = false)
{
/*
* htmlwrap() function - v1.1
* Parts of code from htmlwrap() function - v1.6
* Copyright (c) 2004 Brian Huisman AKA GreyWyvern
* http://www.greywyvern.com/code/php/htmlwrap_1.1.php.txt
*
* This program may be distributed under the terms of the GPL
* - http://www.gnu.org/licenses/gpl.txt
*
* Other mods by steved
*/
$content = preg_split("/([<>])/", $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$nobreak = explode(" ", $nobreak);
$nobr = explode(" ", $nobr);
$intag = false;
$innbk = array();
$innbr = array();
$drain = "";
$utf = ($utf || CHARSET == 'utf-8') ? "u" : "";
$lbrks = "/?!%)-}]\\\"':;";
if ($break == "\r")
// Transform protected element lists into arrays
$nobreak = explode(" ", strtolower($nobreak));
// Variable setup
$intag = false;
$innbk = array();
$drain = "";
// List of characters it is "safe" to insert line-breaks at
// It is not necessary to add < and > as they are automatically implied
$lbrks = "/?!%)-}]\\\"':;&";
// Is $str a UTF8 string?
$utf8 = ($utf || CHARSET == 'utf-8') ? "u" : "";
// Start of the serious stuff - split into HTML tags and text between
$content = preg_split('#(<.*?>)#mis', $str, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
foreach($content as $value)
{
if ($value[0] == "<")
{ // We are within an HTML tag
// Create a lowercase copy of this tag's contents
$lvalue = strtolower(substr($value,1,-1));
if ($lvalue)
{ // Tag of non-zero length
// If the first character is not a / then this is an opening tag
if ($lvalue[0] != "/")
{ // Collect the tag name
preg_match("/^(\w*?)(\s|$)/", $lvalue, $t);
// If this is a protected element, activate the associated protection flag
if (in_array($t[1], $nobreak)) array_unshift($innbk, $t[1]);
}
else
{ // Otherwise this is a closing tag
// If this is a closing tag for a protected element, unset the flag
if (in_array(substr($lvalue, 1), $nobreak))
{
reset($innbk);
while (list($key, $tag) = each($innbk))
{
if (substr($lvalue, 1) == $tag)
{
unset($innbk[$key]);
break;
}
}
$innbk = array_values($innbk);
}
}
}
else
{
$value = ''; // Eliminate any empty tags altogether
}
// Else if we're outside any tags, and with non-zero length string...
}
elseif ($value)
{
$break = "\n";
}
while (list(, $value) = each($content))
{
switch ($value)
// If unprotected...
if (!count($innbk))
{
// Use the ACK (006) ASCII symbol to replace all HTML entities temporarily
$value = str_replace("\x06", "", $value);
preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $value, $ents);
$value = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $value);
// Enter the line-break loop
do
{
case "<": $intag = true; break;
case ">": $intag = false; break;
default:
if ($intag)
$store = $value;
// Find the first stretch of characters over the $width limit
if (preg_match("/^(.*?\s)?(\S{".$width."})(?!(".preg_quote($break, "/")."|\s))(.*)$/s".(($utf8) ? "u" : ""), $value, $match))
{
if (strlen($match[2]))
{
if ($value{0} != "/")
{
preg_match('/^(.*?)(\s|$)/'.$utf, $value, $t);
if ((!count($innbk) && in_array($t[1], $nobreak)) || in_array($t[1], $innbk)) $innbk[] = $t[1];
if ((!count($innbr) && in_array($t[1], $nobr)) || in_array($t[1], $innbr)) $innbr[] = $t[1];
} else {
if (in_array(substr($value, 1), $innbk)) unset($innbk[count($innbk)]);
if (in_array(substr($value, 1), $innbr)) unset($innbr[count($innbr)]);
}
} else if ($value)
{
if (!count($innbr)) $value = str_replace("\n", "\r", str_replace("\r", "", $value));
if (!count($innbk))
{
do
{
$store = $value;
if (preg_match("/^(.*?\s|^)(([^\s&]|&(\w{2,5}|#\d{2,4});){".$width."})(?!(".preg_quote($break, "/").'|\s))(.*)$/s'.$utf, $value, $match))
{
for ($x = 0, $ledge = 0; $x < strlen($lbrks); $x++) $ledge = max($ledge, strrpos($match[2], $lbrks{$x}));
if (!$ledge) $ledge = strlen($match[2]) - 1;
$value = $match[1].substr($match[2], 0, $ledge + 1).$break.substr($match[2], $ledge + 1).$match[6];
}
}
while ($store != $value);
}
if (!count($innbr)) $value = str_replace("\r", E_NL, $value);
}
}
$drain .= $value;
}
return $drain;
// Determine the last "safe line-break" character within this match
for ($x = 0, $ledge = 0; $x < strlen($lbrks); $x++) $ledge = max($ledge, strrpos($match[2], $lbrks{$x}));
if (!$ledge) $ledge = strlen($match[2]) - 1;
// Insert the modified string
$value = $match[1].substr($match[2], 0, $ledge + 1).$break.substr($match[2], $ledge + 1).$match[4];
}
}
// Loop while overlimit strings are still being found
} while ($store != $value);
// Put captured HTML entities back into the string
foreach ($ents[0] as $ent) $value = preg_replace("/\x06/", $ent, $value, 1);
}
}
// Send the modified segment down the drain
$drain .= $value;
}
// Return contents of the drain
return $drain;
}
function html_truncate ($text, $len = 200, $more = "[more]")
{
$pos = 0;
@ -461,6 +507,7 @@ class e_parse
$opts[$mod] = TRUE; // Change mods as spec'd
}
}
if (0) // php 5 code - not tested, and may not be faster anyway
{
$aMods = array_flip(
@ -480,16 +527,18 @@ class e_parse
$fromadmin = $opts['fromadmin'];
// Convert defines(constants) within text. eg. Lan_XXXX - must be the entire text string (i.e. not embedded)
if ($opts['defs'] && (strlen($text) < 25) && defined(trim($text)))
// The check for '::' is a workaround for a bug in the Zend Optimiser 3.3.0 and PHP 5.2.4 combination - causes crashes if '::' in site name
if ($opts['defs'] && (strlen($text) < 25) && ((strpos($text,'::') === FALSE) && defined(trim($text))))
{
return constant(trim($text));
}
// replace all {e_XXX} constants with their e107 value
if ($opts['constants'])
if ($opts['no_tags'])
{
$text = $this->replaceConstants($text);
$text = strip_tags($text);
}
@ -511,22 +560,23 @@ class e_parse
{
if ($pref['link_replace'] && !$opts['no_replace'])
{
$_ext = ($pref['links_new_window'] ? " rel=\"external\"" : "");
$text = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\" {$_ext}>".$pref['link_text']."</a>", $text);
// $text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is", "\\1<a href=\"http://\\2\" {$_ext}>".$pref['link_text']."</a>", $text);
$text = preg_replace("#(^|[\n ])((www|ftp)\.[\w+-]+?\.[\w+\-.]*(?(?=/)(/.+?(?=\s|,\s))|(?=\W)))#is", "\\1<a href=\"http://\\2\" {$_ext}>".$pref['link_text']."</a>", $text);
if(CHARSET != "utf-8" && CHARSET != "UTF-8"){
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2&copy;\\3";
}else{
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\\\3";
}
$_ext = ($pref['links_new_window'] ? " rel=\"external\"" : "");
$text = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<]*)#is", "\\1<a href=\"\\2\" {$_ext}>".$pref['link_text']."</a>", $text);
$text = preg_replace("#(^|[\n \]])((www|ftp)\.[\w+-]+?\.[\w+\-.]*(?(?=/)(/.+?(?=\s|,\s))|(?=\W)))#is", "\\1<a href=\"http://\\2\" {$_ext}>".$pref['link_text']."</a>", $text);
if(CHARSET != "utf-8" && CHARSET != "UTF-8")
{
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2&copy;\\3";
}
else
{
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\\\3";
}
$text = 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>", $text);
}
else
{
$text = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<,]*)#is", "\\1<a href=\"\\2\" rel=\"external\">\\2</a>", $text);
// $text = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<,]*)#is", "\\1<a href=\"http://\\2\" rel=\"external\">\\2</a>", $text);
$text = preg_replace("#(^|[\n ])((www|ftp)\.[\w+-]+?\.[\w+\-.]*(?(?=/)(/.+?(?=\s|,\s))|(?=\W)))#is", "\\1<a href=\"http://\\2\" rel=\"external\">\\2</a>", $text);
$text = preg_replace("#(^|[\n ])([\w]+?://[^ \"\n\r\t<,]*)#is", "\\1<a href=\"\\2\" rel=\"external\">\\2</a>", $text);
$text = preg_replace("#(^|[\n \]])((www|ftp)\.[\w+-]+?\.[\w+\-.]*(?(?=/)(/.+?(?=\s|,\s))|(?=\W)))#is", "\\1<a href=\"http://\\2\" rel=\"external\">\\2</a>", $text);
$text = 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>", $text);
}
}
@ -567,6 +617,8 @@ class e_parse
}
// Start parse [bb][/bb] codes
if ($parseBB === TRUE)
{
@ -579,6 +631,12 @@ class e_parse
// End parse [bb][/bb] codes
// replace all {e_XXX} constants with their e107 value AFTER the bbcodes have been parsed.
if ($opts['constants'])
{
$text = $this->replaceConstants($text);
}
// profanity filter
if ($pref['profanity_filter']) {
if (!is_object($this->e_pf)) {
@ -645,10 +703,11 @@ class e_parse
function toAttribute($text) {
$text = str_replace("&amp;","&",$text); // URLs posted without HTML access may have an &amp; in them.
$text = htmlspecialchars($text); // Xhtml compliance.
if (!preg_match('/&#|\'|"|\(|\)|<|>/s', $text)) {
$text = $this->replaceConstants($text);
return $text;
$text = htmlspecialchars($text, ENT_QUOTES, CHARSET); // Xhtml compliance.
if (!preg_match('/&#|\'|"|\(|\)|<|>/s', $text))
{
$text = $this->replaceConstants($text);
return $text;
} else {
return '';
}
@ -714,9 +773,23 @@ class e_parse
if($nonrelative != "")
{
global $IMAGES_DIRECTORY, $PLUGINS_DIRECTORY, $FILES_DIRECTORY, $THEMES_DIRECTORY,$DOWNLOADS_DIRECTORY,$ADMIN_DIRECTORY;
$replace_relative = array("",$IMAGES_DIRECTORY,$PLUGINS_DIRECTORY,$FILES_DIRECTORY,$THEMES_DIRECTORY,$DOWNLOADS_DIRECTORY);
$replace_absolute = array(SITEURL,SITEURL.$IMAGES_DIRECTORY,SITEURL.$PLUGINS_DIRECTORY,SITEURL.$FILES_DIRECTORY,SITEURL.$THEMES_DIRECTORY,SITEURL.$DOWNLOADS_DIRECTORY);
$search = array("{e_BASE}","{e_IMAGE}","{e_PLUGIN}","{e_FILE}","{e_THEME}","{e_DOWNLOAD}");
$replace_relative = array("",
SITEURL.$IMAGES_DIRECTORY,
SITEURL.$THEMES_DIRECTORY,
$IMAGES_DIRECTORY,
$PLUGINS_DIRECTORY,
$FILES_DIRECTORY,
$THEMES_DIRECTORY,
$DOWNLOADS_DIRECTORY);
$replace_absolute = array(SITEURL,
SITEURL.$IMAGES_DIRECTORY,
SITEURL.$THEMES_DIRECTORY,
SITEURL.$IMAGES_DIRECTORY,
SITEURL.$PLUGINS_DIRECTORY,
SITEURL.$FILES_DIRECTORY,
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) {
$replace_relative[] = $ADMIN_DIRECTORY;
$replace_absolute[] = SITEURL.$ADMIN_DIRECTORY;
@ -738,7 +811,8 @@ class e_parse
$replace = ((string)$nonrelative == "full" ) ? $replace_absolute : $replace_relative;
return str_replace($search,$replace,$text);
}
$pattern = ($all ? "#\{([A-Za-z_0-9]*)\}#s" : "#\{(e_[A-Z]*)\}#s");
// $pattern = ($all ? "#\{([A-Za-z_0-9]*)\}#s" : "#\{(e_[A-Z]*)\}#s");
$pattern = ($all ? "#\{([A-Za-z_0-9]*)\}#s" : "#\{(e_[A-Z]*(?:_ABS){0,1})\}#s");
$text = preg_replace_callback($pattern, array($this, 'doReplace'), $text);
$theme_path = (defined("THEME")) ? constant("THEME") : "";
$text = str_replace("{THEME}",$theme_path,$text);
@ -803,17 +877,19 @@ class e_parse
return $text;
}
function toEmail($text,$posted="",$mods="parse_sc, no_make_clickable")
{
if ($posted === TRUE && MAGIC_QUOTES_GPC) {
if ($posted === TRUE && MAGIC_QUOTES_GPC)
{
$text = stripslashes($text);
}
$text = ($mods != "rawtext") ? $this->replaceConstants($text,"full") : $text;
$text = (strtolower($mods) != "rawtext") ? $this->replaceConstants($text,"full") : $text;
$text = $this->toHTML($text,TRUE,$mods);
return $text;
}
}
?>
?>