2006-12-02 04:36:16 +00:00
|
|
|
<?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 $
|
2007-12-30 09:49:46 +00:00
|
|
|
| $Revision: 1.24 $
|
|
|
|
| $Date: 2007-12-30 09:49:46 $
|
2007-12-07 21:24:55 +00:00
|
|
|
| $Author: e107steved $
|
2006-12-02 04:36:16 +00:00
|
|
|
+----------------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
if (!defined('e107_INIT')) { exit; }
|
|
|
|
|
|
|
|
define ("E_NL", chr(2));
|
|
|
|
class e_parse
|
|
|
|
{
|
|
|
|
var $e_sc;
|
|
|
|
var $e_bb;
|
|
|
|
var $e_pf;
|
|
|
|
var $e_emote;
|
|
|
|
var $e_hook;
|
2007-02-18 01:17:25 +00:00
|
|
|
var $search = array(''', ''', '"', 'onerror', '>', '&#039;', '&quot;', ' & ');
|
|
|
|
var $replace = array("'", "'", '"', 'one<i></i>rror', '>', "'", '"', ' & ');
|
2007-01-20 16:19:43 +00:00
|
|
|
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!
|
|
|
|
var $e_modSet = array();
|
|
|
|
var $e_optDefault = array(
|
|
|
|
'context' => 'olddefault', // default context: all "opt-out" conversions :(
|
|
|
|
'fromadmin' => FALSE,
|
|
|
|
|
|
|
|
// Enabled by Default
|
|
|
|
'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)
|
|
|
|
|
|
|
|
// Disabled by Default
|
|
|
|
'defs' => FALSE, // Convert defines(constants) within text.
|
|
|
|
'constants' => FALSE, // replace all {e_XXX} constants with their e107 value
|
2007-09-09 07:05:06 +00:00
|
|
|
'parse_sc' => FALSE, // Parse shortcodes - TRUE enables parsing
|
|
|
|
'no_tags' => FALSE // remove HTML tags.
|
2007-01-20 16:19:43 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Super modifiers adjust default option values
|
|
|
|
// First line of adjustments change default-ON options
|
|
|
|
// Second line changes default-OFF options
|
|
|
|
var $e_SuperMods = array(
|
|
|
|
'title' => //text is part of a title (e.g. news title)
|
2007-04-30 20:17:05 +00:00
|
|
|
array(
|
|
|
|
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,
|
2007-01-20 16:19:43 +00:00
|
|
|
'defs'=>TRUE,'parse_sc'=>TRUE),
|
|
|
|
|
2007-04-30 20:17:05 +00:00
|
|
|
'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
|
|
|
|
),
|
|
|
|
|
2007-01-20 16:19:43 +00:00
|
|
|
'summary' => // text is part of the summary of a longer item (e.g. content summary)
|
2007-04-30 20:17:05 +00:00
|
|
|
array(
|
2007-01-20 16:19:43 +00:00
|
|
|
// no changes to default-on items
|
|
|
|
'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
|
|
|
|
|
|
|
|
'description' => // text is the description of an item (e.g. download, link)
|
2007-04-30 20:17:05 +00:00
|
|
|
array(
|
2007-01-20 16:19:43 +00:00
|
|
|
// no changes to default-on items
|
|
|
|
'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
|
|
|
|
|
|
|
|
'body' => // text is 'body' or 'bulk' text (e.g. custom page body, content body)
|
2007-04-30 20:17:05 +00:00
|
|
|
array(
|
2007-01-20 16:19:43 +00:00
|
|
|
// no changes to default-on items
|
|
|
|
'defs'=>TRUE, 'constants'=>TRUE, 'parse_sc'=>TRUE),
|
|
|
|
|
2007-04-30 20:17:05 +00:00
|
|
|
'user_body' => // text is user-entered (i.e. untrusted)'body' or 'bulk' text (e.g. custom page body, content body)
|
|
|
|
array(
|
|
|
|
// no changes to default-on items
|
|
|
|
),
|
|
|
|
|
2007-01-20 16:19:43 +00:00
|
|
|
'linktext' => // text is the 'content' of a link (A tag, etc)
|
2007-04-30 20:17:05 +00:00
|
|
|
array(
|
2007-01-20 16:19:43 +00:00
|
|
|
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,
|
|
|
|
'defs'=>TRUE,'parse_sc'=>TRUE),
|
|
|
|
|
2007-09-09 07:05:06 +00:00
|
|
|
'rawtext' => // text is used (for admin edit) without fancy conversions or html.
|
2007-04-30 20:17:05 +00:00
|
|
|
array(
|
2007-09-09 07:05:06 +00:00
|
|
|
'nobreak'=>TRUE, 'retain_nl'=>TRUE, 'no_make_clickable'=>TRUE,'emotes_off'=>TRUE,'no_hook'=>TRUE,'no_tags'=>TRUE
|
2007-01-20 16:19:43 +00:00
|
|
|
// leave opt-in options off
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
function e_parse()
|
|
|
|
{
|
|
|
|
// Preprocess the supermods to be useful default arrays with all values
|
|
|
|
foreach ($this->e_SuperMods as $key=>$val)
|
|
|
|
{
|
|
|
|
$this->e_SuperMods[$key] = array_merge($this->e_optDefault,$this->e_SuperMods[$key]); // precalculate super defaults
|
|
|
|
$this->e_SuperMods[$key]['context']=$key;
|
|
|
|
}
|
|
|
|
foreach ($this->e_optDefault as $key=>$val)
|
|
|
|
{
|
|
|
|
$this->e_modSet[$key] = TRUE;
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2007-06-13 02:53:21 +00:00
|
|
|
if (!is_object($this->e_sc))
|
|
|
|
{
|
|
|
|
require_once(e_HANDLER."shortcode_handler.php");
|
|
|
|
$this->e_sc = new e_shortcode;
|
|
|
|
}
|
2007-01-20 16:19:43 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 09:05:13 +00:00
|
|
|
function toDB($data, $nostrip = false, $no_encode = false, $mod = false, $original_author = false)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-01-12 21:05:20 +00:00
|
|
|
/**
|
|
|
|
* $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.
|
2007-11-04 09:05:13 +00:00
|
|
|
* $mod: the 'no_html' and 'no_php' modifiers blanket prevent html and php posting regardless of posting permissions. (used in logging)
|
2007-01-12 21:05:20 +00:00
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
global $pref;
|
|
|
|
if (is_array($data)) {
|
|
|
|
foreach ($data as $key => $var) {
|
2007-11-04 09:05:13 +00:00
|
|
|
$ret[$key] = $this -> toDB($var, $nostrip, $no_encode, $mod, $original_author);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-01-12 21:05:20 +00:00
|
|
|
if (MAGIC_QUOTES_GPC == true && $nostrip == false) {
|
2006-12-02 04:36:16 +00:00
|
|
|
$data = stripslashes($data);
|
|
|
|
}
|
2007-01-12 21:05:20 +00:00
|
|
|
if (isset($pref['post_html']) && check_class($pref['post_html']))
|
|
|
|
{
|
|
|
|
$no_encode = true;
|
|
|
|
}
|
|
|
|
if (is_numeric($original_author) && !check_class($pref['post_html'], '', $original_author))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-01-12 21:05:20 +00:00
|
|
|
$no_encode = false;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2007-01-12 21:05:20 +00:00
|
|
|
if ($no_encode === true && strpos($mod, 'no_html') === false)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
$search = array('$', '"', "'", '\\', '<?');
|
|
|
|
$replace = array('$','"',''', '\', '<?');
|
|
|
|
$ret = str_replace($search, $replace, $data);
|
|
|
|
} else {
|
|
|
|
$data = htmlspecialchars($data, ENT_QUOTES, CHARSET);
|
|
|
|
$data = str_replace('\\', '\', $data);
|
|
|
|
$ret = preg_replace("/&#(\d*?);/", "&#\\1;", $data);
|
|
|
|
}
|
2007-11-10 19:24:42 +00:00
|
|
|
if (strpos($mod, 'no_php') !== false)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
$ret = str_replace(array("[php]", "[/php]"), array("[php]", "[/php]"), $ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2007-01-12 21:05:20 +00:00
|
|
|
|
|
|
|
function toForm($text)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-01-12 21:05:20 +00:00
|
|
|
if ($text == '') { return ''; }
|
|
|
|
$search = array('$', '"', '<', '>');
|
|
|
|
$replace = array('$', '"', '<', '>');
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = str_replace($search, $replace, $text);
|
2007-01-12 21:05:20 +00:00
|
|
|
if (e_WYSIWYG !== true){
|
|
|
|
$text = str_replace(" ", " ", $text); // fix for utf-8 issue with html_entity_decode();
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function post_toForm($text) {
|
2007-01-12 21:05:20 +00:00
|
|
|
if (MAGIC_QUOTES_GPC == true) {
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = stripslashes($text);
|
|
|
|
}
|
2007-01-12 21:05:20 +00:00
|
|
|
return str_replace(array( "'", '"', "<", ">"), array("'", """, "<", ">"), $text);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-12 21:05:20 +00:00
|
|
|
function post_toHTML($text, $original_author = false, $extra = '', $mod = false) {
|
2007-11-04 09:05:13 +00:00
|
|
|
$text = $this -> toDB($text, false, false, $mod, $original_author);
|
2007-01-12 21:05:20 +00:00
|
|
|
return $this -> toHTML($text, true, $extra);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2007-01-12 21:05:20 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function parseTemplate($text, $parseSCFiles = TRUE, $extraCodes = "") {
|
|
|
|
return $this->e_sc->parseCodes($text, $parseSCFiles, $extraCodes);
|
|
|
|
}
|
|
|
|
|
2007-01-12 21:05:20 +00:00
|
|
|
|
2007-12-30 09:49:46 +00:00
|
|
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function htmlwrap($str, $width, $break = "\n", $nobreak = "", $nobr = "pre", $utf = false)
|
|
|
|
{
|
|
|
|
/*
|
2007-12-30 09:49:46 +00:00
|
|
|
* Parts of code from htmlwrap() function - v1.6
|
2006-12-02 04:36:16 +00:00
|
|
|
* 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
|
2007-12-30 09:49:46 +00:00
|
|
|
*
|
|
|
|
* Other mods by steved
|
2006-12-02 04:36:16 +00:00
|
|
|
*/
|
|
|
|
|
2007-12-30 09:49:46 +00:00
|
|
|
// 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)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-12-30 09:49:46 +00:00
|
|
|
// 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
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-12-30 09:49:46 +00:00
|
|
|
$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]))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-12-30 09:49:46 +00:00
|
|
|
// 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;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2007-12-30 09:49:46 +00:00
|
|
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function html_truncate ($text, $len = 200, $more = "[more]")
|
|
|
|
{
|
|
|
|
$pos = 0;
|
|
|
|
$curlen = 0;
|
|
|
|
$tmp_pos = 0;
|
2007-05-16 20:24:44 +00:00
|
|
|
$intag = FALSE;
|
2006-12-02 04:36:16 +00:00
|
|
|
while($curlen < $len && $curlen < strlen($text))
|
|
|
|
{
|
|
|
|
switch($text{$pos})
|
|
|
|
{
|
|
|
|
case "<" :
|
|
|
|
if($text{$pos+1} == "/")
|
|
|
|
{
|
|
|
|
$closing_tag = TRUE;
|
|
|
|
}
|
|
|
|
$intag = TRUE;
|
|
|
|
$tmp_pos = $pos-1;
|
|
|
|
$pos++;
|
|
|
|
break;
|
2007-06-06 19:28:25 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
case ">" :
|
|
|
|
if($text{$pos-1} == "/")
|
|
|
|
{
|
|
|
|
$closing_tag = TRUE;
|
|
|
|
}
|
|
|
|
if($closing_tag == TRUE)
|
|
|
|
{
|
|
|
|
$tmp_pos = 0;
|
|
|
|
$closing_tag = FALSE;
|
|
|
|
}
|
|
|
|
$intag = FALSE;
|
|
|
|
$pos++;
|
|
|
|
break;
|
2007-06-06 19:28:25 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
case "&" :
|
|
|
|
if($text{$pos+1} == "#")
|
|
|
|
{
|
|
|
|
$end = strpos(substr($text, $pos, 7), ";");
|
|
|
|
if($end !== FALSE)
|
|
|
|
{
|
|
|
|
$pos+=($end+1);
|
|
|
|
if(!$intag) {$curlen++;}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$pos++;
|
|
|
|
if(!$intag) {$curlen++;}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
$pos++;
|
|
|
|
if(!$intag) {$curlen++;}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ret = ($tmp_pos > 0 ? substr($text, 0, $tmp_pos) : substr($text, 0, $pos));
|
|
|
|
if($pos < strlen($text))
|
|
|
|
{
|
|
|
|
$ret = $ret.$more;
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2007-06-06 19:28:25 +00:00
|
|
|
|
|
|
|
// Truncate a string 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
|
|
|
|
function text_truncate($text, $len = 200, $more = "[more]")
|
|
|
|
{
|
|
|
|
if (strlen($text) <= $len) return $text; // Always valid
|
|
|
|
if (CHARSET !== 'utf-8') return substr($text,0,$len).$more; // Non-utf-8 - one byte per character - simple
|
|
|
|
|
|
|
|
// Its a utf-8 string here - don't know whether its longer than allowed length yet
|
2007-06-07 19:19:37 +00:00
|
|
|
preg_match('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.
|
|
|
|
'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'})(.{0,1}).*#s',$text,$matches);
|
|
|
|
|
|
|
|
$ret = $matches[1];
|
|
|
|
if (!empty($matches[2])) $ret .= $more;
|
2007-06-06 19:28:25 +00:00
|
|
|
return $ret;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 19:28:25 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
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);
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
if (!defined('e_SELF'))
|
|
|
|
{
|
|
|
|
return FALSE; // Still in startup, so can't calculate highlighting
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($this->e_highlighting))
|
|
|
|
{
|
|
|
|
$this->e_highlighting = FALSE;
|
|
|
|
$shr = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
|
|
|
|
if ($pref['search_highlight'] && (strpos(e_SELF, 'search.php') === FALSE) && ((strpos($shr, 'q=') !== FALSE) || (strpos($shr, 'p=') !== FALSE)))
|
|
|
|
{
|
|
|
|
$this->e_highlighting = TRUE;
|
|
|
|
if (!isset($this -> e_query))
|
|
|
|
{
|
|
|
|
$query = preg_match('#(q|p)=(.*?)(&|$)#', $shr, $matches);
|
|
|
|
$this -> e_query = str_replace(array('+', '*', '"', ' '), array('', '.*?', '', '\b|\b'), trim(urldecode($matches[2])));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->e_highlighting;
|
|
|
|
}
|
|
|
|
|
2007-03-11 20:52:47 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function toHTML($text, $parseBB = FALSE, $modifiers = "", $postID = "", $wrap=FALSE) {
|
|
|
|
if ($text == '')
|
|
|
|
{
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
global $pref, $fromadmin;
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2007-01-20 16:19:43 +00:00
|
|
|
//
|
|
|
|
// SET MODIFIERS
|
|
|
|
//
|
|
|
|
|
|
|
|
// Get modifier strings for toHTML
|
|
|
|
// "super" modifiers set a baseline. Recommend entering in UPPER CASE to highlight
|
|
|
|
// other modifiers override
|
|
|
|
// modifiers SHOULD be delimited with commas (eventually this will be 'MUST')
|
|
|
|
// modifiers MAY have spaces in between as desired
|
|
|
|
|
|
|
|
$opts = $this->e_optDefault;
|
|
|
|
if (strlen($modifiers))
|
2007-01-17 21:29:28 +00:00
|
|
|
{
|
2007-01-20 16:19:43 +00:00
|
|
|
//
|
|
|
|
// Yes, the following code is strangely-written. It is one of the MOST used bits in
|
|
|
|
// all of e107. We "inlined" the assignments to optimize speed through
|
|
|
|
// some careful testing (19 Jan 2007).
|
|
|
|
//
|
|
|
|
// Some alternatives that do NOT speed things up (they make it slower)
|
|
|
|
// - use of array_intersect, array_walk, preg_replace, intermediate variables, etc etc etc.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (1) // php 4 code
|
|
|
|
{
|
|
|
|
$opts = $this->e_optDefault;
|
|
|
|
$aMods = explode( ',',
|
|
|
|
// convert blanks to comma, then comma-comma (from blank-comma) to single comma
|
|
|
|
str_replace(array(' ', ',,'), array(',', ',' ),
|
|
|
|
// work with all lower case
|
|
|
|
strtolower($modifiers)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($aMods as $mod)
|
|
|
|
{
|
|
|
|
if (isset($this->e_SuperMods[$mod]))
|
|
|
|
{
|
|
|
|
$opts = $this->e_SuperMods[$mod];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find any regular mods
|
|
|
|
foreach ($aMods as $mod)
|
|
|
|
{
|
|
|
|
$opts[$mod] = TRUE; // Change mods as spec'd
|
|
|
|
}
|
|
|
|
}
|
2007-09-09 07:05:06 +00:00
|
|
|
|
2007-01-20 16:19:43 +00:00
|
|
|
if (0) // php 5 code - not tested, and may not be faster anyway
|
|
|
|
{
|
|
|
|
$aMods = array_flip(
|
|
|
|
explode( ',',
|
|
|
|
// convert blanks to comma, then comma-comma (from blank-comma) to single comma
|
|
|
|
str_replace(array(' ', ',,'), array(',', ',' ),
|
|
|
|
// work with all lower case
|
|
|
|
strtolower($modifiers)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$opts = array_merge($opts, array_intersect_key($this->e_SuperMods,$aMods)); // merge in any supermods found
|
|
|
|
$opts = array_merge($opts, array_intersect_key($this->modSet, $aMods)); // merge in any other mods found
|
|
|
|
}
|
2007-01-17 21:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$fromadmin = $opts['fromadmin'];
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2007-01-20 16:19:43 +00:00
|
|
|
// Convert defines(constants) within text. eg. Lan_XXXX - must be the entire text string (i.e. not embedded)
|
2007-10-04 19:08:38 +00:00
|
|
|
// 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))))
|
2007-01-17 21:29:28 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
return constant(trim($text));
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2007-11-13 07:38:55 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2007-09-09 07:05:06 +00:00
|
|
|
if ($opts['no_tags'])
|
|
|
|
{
|
|
|
|
$text = strip_tags($text);
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
if(!$wrap && $pref['main_wordwrap']) $wrap = $pref['main_wordwrap'];
|
|
|
|
$text = " ".$text;
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2007-03-11 20:52:47 +00:00
|
|
|
// Prepare for line-break compression. Avoid compressing newlines in embedded scripts and CSS
|
2007-01-17 21:29:28 +00:00
|
|
|
if (!$opts['nobreak'])
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = preg_replace("#>\s*[\r]*\n[\r]*#", ">", $text);
|
|
|
|
preg_match_all("#<(script|style)[^>]+>.*?</(script|style)>#is", $text, $embeds);
|
|
|
|
$text = preg_replace("#<(script|style)[^>]+>.*?</(script|style)>#is", "<|>", $text);
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
// Convert URL's to clickable links, unless modifiers or prefs override
|
2007-01-17 21:29:28 +00:00
|
|
|
if ($pref['make_clickable'] && !$opts['no_make_clickable'])
|
|
|
|
{
|
|
|
|
if ($pref['link_replace'] && !$opts['no_replace'])
|
|
|
|
{
|
2007-11-08 22:46:49 +00:00
|
|
|
$_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);
|
2007-09-09 07:05:06 +00:00
|
|
|
if(CHARSET != "utf-8" && CHARSET != "UTF-8")
|
|
|
|
{
|
2007-11-08 22:46:49 +00:00
|
|
|
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2©\\3";
|
2007-09-09 07:05:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-08 22:46:49 +00:00
|
|
|
$email_text = ($pref['email_text']) ? $this->replaceConstants($pref['email_text']) : "\\1\\2©\\3";
|
2007-09-09 07:05:06 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
$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);
|
2007-01-17 21:29:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-08 22:46:49 +00:00
|
|
|
$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);
|
2007-05-28 18:02:47 +00:00
|
|
|
$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);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
// Convert emoticons to graphical icons, unless modifiers override
|
2007-01-17 21:29:28 +00:00
|
|
|
if (!$opts['emotes_off'])
|
|
|
|
{
|
|
|
|
if ($pref['smiley_activate'] || $opts['emotes_on'])
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
if (!is_object($this->e_emote)) {
|
|
|
|
require_once(e_HANDLER.'emote_filter.php');
|
|
|
|
$this->e_emote = new e_emoteFilter;
|
|
|
|
}
|
|
|
|
$text = $this->e_emote->filterEmotes($text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
// Reduce multiple newlines in all forms to a single newline character, except for embedded scripts and CSS
|
2007-01-17 21:29:28 +00:00
|
|
|
if (!$opts['nobreak'])
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = preg_replace("#[\r]*\n[\r]*#", E_NL, $text);
|
|
|
|
foreach ($embeds[0] as $embed) {
|
|
|
|
$text = preg_replace("#<\|>#", $embed, $text, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
// Restore entity form of quotes and such to single characters, except for text destined for tag attributes or JS.
|
2007-01-17 21:29:28 +00:00
|
|
|
if (!$opts['value'])
|
|
|
|
{ // output not used for attribute values.
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = str_replace($this -> search, $this -> replace, $text);
|
2007-01-17 21:29:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // output used for attribute values.
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = str_replace($this -> replace, $this -> search, $text);
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2007-11-13 07:38:55 +00:00
|
|
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
// Start parse [bb][/bb] codes
|
2007-01-17 21:29:28 +00:00
|
|
|
if ($parseBB === TRUE)
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
if (!is_object($this->e_bb)) {
|
|
|
|
require_once(e_HANDLER.'bbcode_handler.php');
|
|
|
|
$this->e_bb = new e_bbcode;
|
|
|
|
}
|
|
|
|
$text = $this->e_bb->parseBBCodes($text, $postID);
|
|
|
|
}
|
|
|
|
// End parse [bb][/bb] codes
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2007-11-13 07:38:55 +00:00
|
|
|
// replace all {e_XXX} constants with their e107 value AFTER the bbcodes have been parsed.
|
|
|
|
if ($opts['constants'])
|
|
|
|
{
|
|
|
|
$text = $this->replaceConstants($text);
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
// profanity filter
|
2006-12-02 04:36:16 +00:00
|
|
|
if ($pref['profanity_filter']) {
|
|
|
|
if (!is_object($this->e_pf)) {
|
|
|
|
require_once(e_HANDLER."profanity_filter.php");
|
|
|
|
$this->e_pf = new e_profanityFilter;
|
|
|
|
}
|
|
|
|
$text = $this->e_pf->filterProfanities($text);
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
// Optional short-code conversion
|
2007-01-17 21:29:28 +00:00
|
|
|
if ($opts['parse_sc'])
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
$text = $this->parseTemplate($text, TRUE);
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
//Run any hooked in parsers
|
2007-01-20 16:19:43 +00:00
|
|
|
if (!$opts['no_hook'] && varset($pref['tohtml_hook']))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-01-17 21:29:28 +00:00
|
|
|
foreach(explode(",",$pref['tohtml_hook']) as $hook)
|
|
|
|
{
|
|
|
|
if (!is_object($this->e_hook[$hook]))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-01-17 21:29:28 +00:00
|
|
|
require_once(e_PLUGIN.$hook."/".$hook.".php");
|
|
|
|
$hook_class = "e_".$hook;
|
|
|
|
$this->e_hook[$hook] = new $hook_class;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2007-01-20 16:19:43 +00:00
|
|
|
$text = $this->e_hook[$hook]->$hook($text,$opts['context']);
|
2007-01-17 21:29:28 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
|
|
|
if (!$opts['nobreak'])
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = $this -> textclean($text, $wrap);
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
// Search Highlight
|
2007-01-17 21:29:28 +00:00
|
|
|
if (!$opts['emotes_off'])
|
|
|
|
{
|
|
|
|
if ($this->checkHighlighting())
|
|
|
|
{
|
|
|
|
$text = $this -> e_highlight($text, $this -> e_query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
$nl_replace = "<br />";
|
2007-01-17 21:29:28 +00:00
|
|
|
if ($opts['nobreak'])
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
$nl_replace = '';
|
|
|
|
}
|
2007-01-17 21:29:28 +00:00
|
|
|
elseif ($opts['retain_nl'])
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
$nl_replace = "\n";
|
|
|
|
}
|
|
|
|
$text = str_replace(E_NL, $nl_replace, $text);
|
|
|
|
|
|
|
|
return trim($text);
|
|
|
|
}
|
|
|
|
|
2007-01-17 21:29:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function toAttribute($text) {
|
|
|
|
$text = str_replace("&","&",$text); // URLs posted without HTML access may have an & in them.
|
2007-10-16 19:05:32 +00:00
|
|
|
$text = htmlspecialchars($text, ENT_QUOTES, CHARSET); // Xhtml compliance.
|
|
|
|
if (!preg_match('/&#|\'|"|\(|\)|<|>/s', $text))
|
|
|
|
{
|
|
|
|
$text = $this->replaceConstants($text);
|
|
|
|
return $text;
|
2006-12-02 04:36:16 +00:00
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toJS($stringarray) {
|
|
|
|
$search = array("\r\n","\r","<br />","'");
|
|
|
|
$replace = array("\\n","","\\n","\'");
|
|
|
|
$stringarray = str_replace($search, $replace, $stringarray);
|
|
|
|
$stringarray = strip_tags($stringarray);
|
|
|
|
|
|
|
|
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
|
|
|
|
$trans_tbl = array_flip ($trans_tbl);
|
|
|
|
|
|
|
|
return strtr ($stringarray, $trans_tbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
function toRss($text,$tags=FALSE)
|
|
|
|
{
|
|
|
|
|
|
|
|
if($tags != TRUE)
|
|
|
|
{
|
|
|
|
$text = $this -> toHTML($text,TRUE);
|
|
|
|
$text = strip_tags($text);
|
|
|
|
}
|
|
|
|
|
|
|
|
$text = $this->toEmail($text);
|
|
|
|
$search = array("&#039;", "&#036;", "'", "$"," & ", e_BASE, "href='request.php");
|
|
|
|
$replace = array("'", '$', "'", '$',' & ', SITEURL, "href='".SITEURL."request.php" );
|
|
|
|
$text = str_replace($search, $replace, $text);
|
|
|
|
|
|
|
|
if($tags == TRUE && ($text))
|
|
|
|
{
|
|
|
|
$text = "<![CDATA[".$text."]]>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Convert specific characters back to original form, for use in storing code (or regex) values in the db.
|
|
|
|
function toText($text)
|
|
|
|
{
|
|
|
|
$search = array("&#039;", "&#036;", "'", "$", "\", "&#092;");
|
|
|
|
$replace = array("'", '$', "'", '$', "\\", "\\");
|
|
|
|
$text = str_replace($search, $replace, $text);
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// $nonrelative:
|
|
|
|
// "full" = produce absolute URL path, e.g. http://sitename.com/e107_plugins/etc
|
|
|
|
// TRUE = produce truncated URL path, e.g. e107plugins/etc
|
|
|
|
// "" (default) = URL's get relative path e.g. ../e107_plugins/etc
|
2007-01-20 16:19:43 +00:00
|
|
|
//
|
|
|
|
// $all - if TRUE, then
|
|
|
|
// when $nonrelative is "full" or TRUE, USERID is also replaced...
|
|
|
|
// when $nonrelative is "" (default), ALL other e107 constants are replaced
|
2006-12-02 04:36:16 +00:00
|
|
|
//
|
|
|
|
// only an ADMIN user can convert {e_ADMIN}
|
|
|
|
//
|
|
|
|
function replaceConstants($text, $nonrelative = "", $all = false)
|
|
|
|
{
|
|
|
|
if($nonrelative != "")
|
|
|
|
{
|
|
|
|
global $IMAGES_DIRECTORY, $PLUGINS_DIRECTORY, $FILES_DIRECTORY, $THEMES_DIRECTORY,$DOWNLOADS_DIRECTORY,$ADMIN_DIRECTORY;
|
2007-12-07 21:24:55 +00:00
|
|
|
$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}");
|
2006-12-02 04:36:16 +00:00
|
|
|
if (ADMIN) {
|
|
|
|
$replace_relative[] = $ADMIN_DIRECTORY;
|
|
|
|
$replace_absolute[] = SITEURL.$ADMIN_DIRECTORY;
|
|
|
|
$search[] = "{e_ADMIN}";
|
|
|
|
}
|
2007-01-20 16:19:43 +00:00
|
|
|
if ($all) {
|
2007-05-16 20:24:44 +00:00
|
|
|
if (USER)
|
|
|
|
{ // Can only replace with valid number for logged in users
|
2007-01-20 16:19:43 +00:00
|
|
|
$replace_relative[] = USERID;
|
|
|
|
$replace_absolute[] = USERID;
|
2007-05-16 20:24:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$replace_relative[] = '';
|
|
|
|
$replace_absolute[] = '';
|
|
|
|
}
|
|
|
|
$search[] = "{USERID}";
|
2007-01-20 16:19:43 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
$replace = ((string)$nonrelative == "full" ) ? $replace_absolute : $replace_relative;
|
|
|
|
return str_replace($search,$replace,$text);
|
|
|
|
}
|
2007-12-07 21:24:55 +00:00
|
|
|
// $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");
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = preg_replace_callback($pattern, array($this, 'doReplace'), $text);
|
|
|
|
$theme_path = (defined("THEME")) ? constant("THEME") : "";
|
|
|
|
$text = str_replace("{THEME}",$theme_path,$text);
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
function doReplace($matches)
|
|
|
|
{
|
|
|
|
if(defined($matches[1]) && ($matches[1] != 'e_ADMIN' || ADMIN))
|
|
|
|
{
|
|
|
|
return constant($matches[1]);
|
|
|
|
}
|
|
|
|
return $matches[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function createConstants($url,$mode=0){
|
|
|
|
global $IMAGES_DIRECTORY,$PLUGINS_DIRECTORY,$FILES_DIRECTORY,$THEMES_DIRECTORY,$DOWNLOADS_DIRECTORY,$ADMIN_DIRECTORY;
|
|
|
|
|
|
|
|
if($mode == 0) // folder name only.
|
|
|
|
{
|
|
|
|
$tmp = array(
|
|
|
|
"{"."e_IMAGE"."}"=>$IMAGES_DIRECTORY,
|
|
|
|
"{"."e_PLUGIN"."}"=>$PLUGINS_DIRECTORY,
|
|
|
|
"{"."e_FILE"."}"=>$FILES_DIRECTORY,
|
|
|
|
"{"."e_THEME"."}"=>$THEMES_DIRECTORY,
|
|
|
|
"{"."e_DOWNLOAD"."}"=>$DOWNLOADS_DIRECTORY,
|
|
|
|
"{"."e_ADMIN"."}"=>$ADMIN_DIRECTORY,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
elseif($mode == 1) // relative path
|
|
|
|
{
|
|
|
|
$tmp = array(
|
|
|
|
"{"."e_IMAGE"."}"=>e_IMAGE,
|
|
|
|
"{"."e_PLUGIN"."}"=>e_PLUGIN,
|
|
|
|
"{"."e_FILE"."}"=>e_FILE,
|
|
|
|
"{"."e_THEME"."}"=>e_THEME,
|
|
|
|
"{"."e_DOWNLOAD"."}"=>e_DOWNLOAD,
|
|
|
|
"{"."e_ADMIN"."}"=>e_ADMIN
|
|
|
|
);
|
|
|
|
}
|
|
|
|
foreach($tmp as $key=>$val)
|
|
|
|
{
|
|
|
|
$len = strlen($val);
|
|
|
|
if(substr($url,0,$len) == $val)
|
|
|
|
{
|
2007-01-20 16:19:43 +00:00
|
|
|
return substr_replace($url,$key,0,$len); // replace the first instance only
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
$text = preg_replace("#<\|>#", $tag, $text, 1);
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2007-09-09 07:05:06 +00:00
|
|
|
|
2007-03-26 06:34:56 +00:00
|
|
|
function toEmail($text,$posted="",$mods="parse_sc, no_make_clickable")
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-09-09 07:05:06 +00:00
|
|
|
if ($posted === TRUE && MAGIC_QUOTES_GPC)
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$text = stripslashes($text);
|
|
|
|
}
|
|
|
|
|
2007-11-04 20:25:02 +00:00
|
|
|
$text = (strtolower($mods) != "rawtext") ? $this->replaceConstants($text,"full") : $text;
|
2007-03-26 06:34:56 +00:00
|
|
|
$text = $this->toHTML($text,TRUE,$mods);
|
2006-12-02 04:36:16 +00:00
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-09-09 07:05:06 +00:00
|
|
|
?>
|