mirror of
https://github.com/e107inc/e107.git
synced 2025-08-11 09:04:38 +02:00
More [code] bbcode work.
This commit is contained in:
101
e107_core/bbcodes/bb_code.php
Normal file
101
e107_core/bbcodes/bb_code.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (C) e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
|
||||||
|
* [code] bbcode
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('e107_INIT')) { exit; }
|
||||||
|
|
||||||
|
|
||||||
|
class bb_code extends e_bb_base
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Called prior to save
|
||||||
|
* Re-assemble the bbcode
|
||||||
|
*/
|
||||||
|
function toDB($code_text, $parm)
|
||||||
|
{
|
||||||
|
$paramet = ($parm == 'inline') ? 'inline' : '';
|
||||||
|
|
||||||
|
$code_text = htmlspecialchars($code_text, ENT_QUOTES, 'UTF-8');
|
||||||
|
return $paramet ? '[code='.$paramet.']'.$code_text.'[/code]' : '[code]'.$code_text.'[/code]';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send output to browser.
|
||||||
|
*/
|
||||||
|
function toHTML($code_text, $parm)
|
||||||
|
{
|
||||||
|
global $e107cache;
|
||||||
|
|
||||||
|
$class = e107::getBB()->getClass('code');
|
||||||
|
$pref = e107::getPref();
|
||||||
|
$tp = e107::getParser();
|
||||||
|
|
||||||
|
if($pref['smiley_activate'])
|
||||||
|
{
|
||||||
|
if (!is_object($tp->e_emote))
|
||||||
|
{
|
||||||
|
$tp->e_emote = new e_emoteFilter;
|
||||||
|
}
|
||||||
|
$code_text = $tp->e_emote->filterEmotesRev($code_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
$search = array(E_NL,'\','$', '<');
|
||||||
|
$replace = array("\r\n","\\",'$', '<');
|
||||||
|
$code_text = str_replace($search, $replace, $code_text);
|
||||||
|
|
||||||
|
|
||||||
|
if(isset($pref['useGeshi']) && $pref['useGeshi'] && file_exists(e_PLUGIN."geshi/geshi.php"))
|
||||||
|
{
|
||||||
|
$code_md5 = md5($code_text);
|
||||||
|
if(!$CodeCache = $e107cache->retrieve('GeshiParsed_'.$code_md5))
|
||||||
|
{
|
||||||
|
require_once(e_PLUGIN."geshi/geshi.php");
|
||||||
|
if($parm)
|
||||||
|
{
|
||||||
|
$geshi = new GeSHi($code_text, $parm, e_PLUGIN."geshi/geshi/");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$geshi = new GeSHi($code_text, ($pref['defaultLanGeshi'] ? $pref['defaultLanGeshi'] : 'php'), e_PLUGIN."geshi/geshi/");
|
||||||
|
}
|
||||||
|
|
||||||
|
$geshi->line_style1 = "font-family: 'Courier New', Courier, monospace; font-weight: normal; font-style: normal;";
|
||||||
|
$geshi->set_encoding('utf-8');
|
||||||
|
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
|
||||||
|
$geshi->set_header_type(GESHI_HEADER_DIV);
|
||||||
|
$CodeCache = $geshi->parse_code();
|
||||||
|
$e107cache->set('GeshiParsed_'.$code_md5, $CodeCache);
|
||||||
|
}
|
||||||
|
$ret = "<code class='code_highlight code-box {$class}' style='unicode-bidi: embed; direction: ltr'>".str_replace("&", "&", $CodeCache)."</code>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$code_text = html_entity_decode($code_text, ENT_QUOTES, 'utf-8');
|
||||||
|
$code_text = trim($code_text);
|
||||||
|
$code_text = htmlspecialchars($code_text, ENT_QUOTES, 'utf-8');
|
||||||
|
|
||||||
|
if($parm == 'inline')
|
||||||
|
{
|
||||||
|
return "<code style='unicode-bidi: embed; direction: ltr'>".$code_text."</code>";
|
||||||
|
}
|
||||||
|
|
||||||
|
// $highlighted_text = highlight_string($code_text, TRUE);
|
||||||
|
// highlighted_text = str_replace(array("<code>","</code>"),"",$highlighted_text);
|
||||||
|
$divClass = ($parm) ? $parm : 'code_highlight';
|
||||||
|
$ret = "<pre class='prettyprint linenums ".$tp -> toAttribute($divClass)." code-box {$class}' style='unicode-bidi: embed; direction: ltr'>".$code_text."</pre>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret = str_replace("[", "[", $ret);
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
@@ -1,68 +0,0 @@
|
|||||||
//<?php
|
|
||||||
$class = e107::getBB()->getClass('code');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
global $pref, $e107cache;
|
|
||||||
|
|
||||||
$tp = e107::getParser();
|
|
||||||
|
|
||||||
if($pref['smiley_activate'])
|
|
||||||
{
|
|
||||||
if (!is_object($tp->e_emote))
|
|
||||||
{
|
|
||||||
// require_once(e_HANDLER.'emote_filter.php');
|
|
||||||
$tp->e_emote = new e_emoteFilter;
|
|
||||||
}
|
|
||||||
$code_text = $tp->e_emote->filterEmotesRev($code_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
$search = array(E_NL,'\','$', '<');
|
|
||||||
$replace = array("\r\n","\\",'$', '<');
|
|
||||||
$code_text = str_replace($search, $replace, $code_text);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(isset($pref['useGeshi']) && $pref['useGeshi'] && file_exists(e_PLUGIN."geshi/geshi.php")) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$code_md5 = md5($code_text);
|
|
||||||
if(!$CodeCache = $e107cache->retrieve('GeshiParsed_'.$code_md5)) {
|
|
||||||
require_once(e_PLUGIN."geshi/geshi.php");
|
|
||||||
if($parm) {
|
|
||||||
$geshi = new GeSHi($code_text, $parm, e_PLUGIN."geshi/geshi/");
|
|
||||||
} else {
|
|
||||||
$geshi = new GeSHi($code_text, ($pref['defaultLanGeshi'] ? $pref['defaultLanGeshi'] : 'php'), e_PLUGIN."geshi/geshi/");
|
|
||||||
}
|
|
||||||
$geshi->line_style1 = "font-family: 'Courier New', Courier, monospace; font-weight: normal; font-style: normal;";
|
|
||||||
$geshi->set_encoding('utf-8');
|
|
||||||
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
|
|
||||||
$geshi->set_header_type(GESHI_HEADER_DIV);
|
|
||||||
$CodeCache = $geshi->parse_code();
|
|
||||||
$e107cache->set('GeshiParsed_'.$code_md5, $CodeCache);
|
|
||||||
}
|
|
||||||
$ret = "<code class='code_highlight code-box {$class}' style='unicode-bidi: embed; direction: ltr'>".str_replace("&", "&", $CodeCache)."</code>";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$code_text = html_entity_decode($code_text, ENT_QUOTES, 'utf-8');
|
|
||||||
$code_text = trim($code_text);
|
|
||||||
$code_text = htmlspecialchars($code_text, ENT_QUOTES, 'utf-8');
|
|
||||||
|
|
||||||
if($parm == 'inline')
|
|
||||||
{
|
|
||||||
return "<code style='unicode-bidi: embed; direction: ltr'>".$code_text."</code>";
|
|
||||||
}
|
|
||||||
|
|
||||||
// $highlighted_text = highlight_string($code_text, TRUE);
|
|
||||||
// highlighted_text = str_replace(array("<code>","</code>"),"",$highlighted_text);
|
|
||||||
$divClass = ($parm) ? $parm : 'code_highlight';
|
|
||||||
$ret = "<pre class='prettyprint linenums ".$tp -> toAttribute($divClass)." code-box {$class}' style='unicode-bidi: embed; direction: ltr'>".$code_text."</pre>";
|
|
||||||
}
|
|
||||||
$ret = str_replace("[", "[", $ret);
|
|
||||||
return $ret;
|
|
@@ -487,7 +487,7 @@ class e_parse extends e_parser
|
|||||||
if ($mod != 'pReFs') //XXX We're not saving prefs.
|
if ($mod != 'pReFs') //XXX We're not saving prefs.
|
||||||
{
|
{
|
||||||
$data = $this->preFilter($data);
|
$data = $this->preFilter($data);
|
||||||
$data = str_replace('<?','<?',$data); // replace <? so that it can still be used in [code][/code] bbcode.
|
|
||||||
|
|
||||||
if (strip_tags($data) != $data) // html tags present.
|
if (strip_tags($data) != $data) // html tags present.
|
||||||
{
|
{
|
||||||
@@ -504,7 +504,7 @@ class e_parse extends e_parser
|
|||||||
$data = str_replace(array('[html]','[/html]'),'',$data);
|
$data = str_replace(array('[html]','[/html]'),'',$data);
|
||||||
// $data = $this->dataFilter($data);
|
// $data = $this->dataFilter($data);
|
||||||
}
|
}
|
||||||
$data = str_replace('<?','<?',$data); // replace <? so that it can still be used in [code][/code] bbcode.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_class($core_pref->get('post_html'))) /*$core_pref->is('post_html') && */
|
if (check_class($core_pref->get('post_html'))) /*$core_pref->is('post_html') && */
|
||||||
@@ -1417,15 +1417,16 @@ class e_parse extends e_parser
|
|||||||
// $matches[4] - bit between the tags (i.e. text to process)
|
// $matches[4] - bit between the tags (i.e. text to process)
|
||||||
// $matches[5] - closing tag
|
// $matches[5] - closing tag
|
||||||
// In case we decide to load a file
|
// In case we decide to load a file
|
||||||
$bbPath = e_CORE.'bbcodes/';
|
|
||||||
$bbFile = strtolower(str_replace('_', '', $matches[2]));
|
|
||||||
$bbcode = '';
|
|
||||||
$className = '';
|
|
||||||
$full_text = '';
|
|
||||||
$code_text = $matches[4];
|
|
||||||
|
|
||||||
$parm = $matches[3] ? substr($matches[3],1) : '';
|
$bbPath = e_CORE.'bbcodes/';
|
||||||
$last_bbcode = $matches[2];
|
$bbFile = strtolower(str_replace('_', '', $matches[2]));
|
||||||
|
$bbcode = '';
|
||||||
|
$className = '';
|
||||||
|
$full_text = '';
|
||||||
|
$code_text = $matches[4];
|
||||||
|
$parm = $matches[3] ? substr($matches[3],1) : '';
|
||||||
|
$last_bbcode = $matches[2];
|
||||||
|
|
||||||
switch ($matches[2])
|
switch ($matches[2])
|
||||||
{
|
{
|
||||||
case 'php' :
|
case 'php' :
|
||||||
@@ -1474,11 +1475,10 @@ class e_parse extends e_parser
|
|||||||
if (file_exists($bbPath.'bb_'.$bbFile.'.php'))
|
if (file_exists($bbPath.'bb_'.$bbFile.'.php'))
|
||||||
{ // Its a bbcode class file
|
{ // Its a bbcode class file
|
||||||
require_once($bbPath.'bb_'.$bbFile.'.php');
|
require_once($bbPath.'bb_'.$bbFile.'.php');
|
||||||
//echo "Load: {$bbFile}.php<br />";
|
$className = 'bb_'.$last_bbcode;
|
||||||
$className = 'bb_'.$code;
|
$this->bbList[$last_bbcode] = new $className();
|
||||||
$this->bbList[$code] = new $className();
|
|
||||||
}
|
}
|
||||||
elseif (file_exists($bbPath.$bbFile.'.bb'))
|
elseif(file_exists($bbPath.$bbFile.'.bb'))
|
||||||
{
|
{
|
||||||
$bbcode = file_get_contents($bbPath.$bbFile.'.bb');
|
$bbcode = file_get_contents($bbPath.$bbFile.'.bb');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user