1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-18 12:21:45 +02:00

Consolidate parsing classes into single file.

This commit is contained in:
Cameron
2013-05-20 17:10:38 -07:00
parent e55b3cbbd9
commit 4581b9986c
13 changed files with 234 additions and 53 deletions

View File

@@ -1272,8 +1272,10 @@ class e_parse extends e_parser
{
return $text;
}
$pref = e107::getPref();
global $pref, $fromadmin;
global $fromadmin;
// Set default modifiers to start
$opts = $this->e_optDefault;
@@ -1570,7 +1572,7 @@ class e_parse extends e_parser
{
if (!is_object($this->e_emote))
{
require_once(e_HANDLER.'emote_filter.php');
// require_once(e_HANDLER.'emote_filter.php');
$this->e_emote = new e_emoteFilter;
}
$sub_blk = $this->e_emote->filterEmotes($sub_blk);
@@ -1655,7 +1657,7 @@ class e_parse extends e_parser
{
if (!is_object($this->e_pf))
{
require_once(e_HANDLER."profanity_filter.php");
// require_once(e_HANDLER."profanity_filter.php");
$this->e_pf = new e_profanityFilter;
}
$sub_blk = $this->e_pf->filterProfanities($sub_blk);
@@ -2901,3 +2903,151 @@ return $html;
}
class e_emotefilter {
var $search;
var $replace;
var $emotes;
function e_emotefilter() /* constructor */
{
$pref = e107::getPref();
if(!$pref['emotepack'])
{
$pref['emotepack'] = "default";
save_prefs();
}
$this->emotes = e107::getConfig("emote")->getPref();
if(!vartrue($this->emotes))
{
return;
}
foreach($this->emotes as $key => $value)
{
$value = trim($value);
if ($value)
{ // Only 'activate' emote if there's a substitution string set
$key = preg_replace("#!(\w{3,}?)$#si", ".\\1", $key);
// Next two probably to sort out legacy issues - may not be required any more
$key = preg_replace("#_(\w{3})$#", ".\\1", $key);
$key = str_replace("!", "_", $key);
$filename = e_IMAGE."emotes/" . $pref['emotepack'] . "/" . $key;
$fileloc = SITEURLBASE.e_IMAGE_ABS."emotes/" . $pref['emotepack'] . "/" . $key;
if(file_exists($filename))
{
if(strstr($value, " "))
{
$tmp = explode(" ", $value);
foreach($tmp as $code)
{
$this->search[] = " ".$code;
$this->search[] = "\n".$code;
//TODO CSS class?
$this->replace[] = " <img src='".$fileloc."' alt='' style='vertical-align:middle; border:0' /> ";
$this->replace[] = "\n <img src='".$fileloc."' alt='' style='vertical-align:middle; border:0' /> ";
}
unset($tmp);
}
else
{
if($value)
{
$this->search[] = " ".$value;
$this->search[] = "\n".$value;
//TODO CSS class?
$this->replace[] = " <img src='".$filename."' alt='' style='vertical-align:middle; border:0' /> ";
$this->replace[] = "\n <img src='".$filename."' alt='' style='vertical-align:middle; border:0' /> ";
}
}
}
}
else
{
unset($this->emotes[$key]);
}
}
}
function filterEmotes($text)
{
$text = str_replace($this->search, $this->replace, $text);
return $text;
}
function filterEmotesRev($text)
{
$text = str_replace($this->replace, $this->search, $text);
return $text;
}
}
class e_profanityFilter
{
var $profanityList;
function e_profanityFilter()
{
global $pref;
$words = explode(",", $pref['profanity_words']);
$word_array = array();
foreach($words as $word)
{
$word = trim($word);
if($word != "")
{
$word_array[] = $word;
if (strpos($word, '&#036;') !== FALSE)
{
$word_array[] = str_replace('&#036;', '\$', $word); // Special case - '$' may be 'in clear' or as entity
}
}
}
if(count($word_array))
{
$this->profanityList = str_replace('#','\#',implode("\b|\b", $word_array)); // We can get entities in the string - confuse the regex delimiters
}
unset($words);
return TRUE;
}
function filterProfanities($text)
{
global $pref;
if (!$this->profanityList)
{
return $text;
}
if ($pref['profanity_replace'])
{
return preg_replace("#\b".$this->profanityList."\b#is", $pref['profanity_replace'], $text);
}
else
{
return preg_replace_callback("#\b".$this->profanityList."\b#is", array($this, 'replaceProfanities'), $text);
}
}
function replaceProfanities($matches)
{
/*!
@function replaceProfanities callback
@abstract replaces vowels in profanity words with stars
@param text string - text string to be filtered
@result filtered text
*/
return preg_replace("#a|e|i|o|u#i", "*" , $matches[0]);
}
}