tags as it changes all.
So after making your edits to the core file, i thought of copying the whole function for the mycode_parse_code and added a copy of it below it and tried to create the custom code just by changing all the $code instances in that function with the new mycode name, but it had thrown some error when i used that code tags ex: [newtag] [/newtag]
Code USed:
[code]/**
* Parses quotes with post id and/or dateline.
*
* @param string The message to be parsed
* @param string The username to be parsed
* @param boolean Are we formatting as text?
* @return string The parsed message.
*/
function mycode_parse_post_quotes($message, $username, $text_only=false)
{
global $lang, $templates, $theme, $mybb;
$linkback = $date = "";
$message = trim($message);
$message = preg_replace("#(^<br(\s?)(\/?)>|<br(\s?)(\/?)>$)#i", "", $message);
if(!$message) return '';
$message = str_replace('\"', '"', $message);
$username = str_replace('\"', '"', $username)."'";
$delete_quote = true;
preg_match("#pid=(?:"|\"|')?([0-9]+)[\"']?(?:"|\"|')?#i", $username, $match);
if(intval($match[1]))
{
$pid = intval($match[1]);
$url = $mybb->settings['bburl']."/".get_post_link($pid)."#pid$pid";
if(defined("IN_ARCHIVE"))
{
$linkback = " <a href=\"{$url}\">[ -> ]</a>";
}
else
{
eval("\$linkback = \" ".$templates->get("postbit_gotopost", 1, 0)."\";");
}
$username = preg_replace("#(?:"|\"|')? pid=(?:"|\"|')?[0-9]+[\"']?(?:"|\"|')?#i", '', $username);
$delete_quote = false;
}
unset($match);
preg_match("#dateline=(?:"|\"|')?([0-9]+)(?:"|\"|')?#i", $username, $match);
if(intval($match[1]))
{
if($match[1] < TIME_NOW)
{
$postdate = my_date($mybb->settings['dateformat'], intval($match[1]));
$posttime = my_date($mybb->settings['timeformat'], intval($match[1]));
$date = " ({$postdate} {$posttime})";
}
$username = preg_replace("#(?:"|\"|')? dateline=(?:"|\"|')?[0-9]+(?:"|\"|')?#i", '', $username);
$delete_quote = false;
}
if($delete_quote)
{
$username = my_substr($username, 0, my_strlen($username)-1);
}
if($text_only)
{
return "\n".htmlspecialchars_uni($username)." $lang->wrote{$date}\n--\n{$message}\n--\n";
}
else
{
$span = "";
if(!$delete_quote)
{
$span = "<span>{$date}</span>";
}
return "<blockquote><cite>{$span}".htmlspecialchars_uni($username)." $lang->wrote{$linkback}</cite>{$message}</blockquote>\n";
}
}
/**
* Parses code MyCode.
*
* @param string The message to be parsed
* @param boolean Are we formatting as text?
* @return string The parsed message.
*/
/**function mycode_parse_code($code, $text_only=false)
{
global $lang;
if($text_only == true)
{
return "\n{$lang->code}\n--\n{$code}\n--\n";
}
// Clean the string before parsing.
$code = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $code);
$code = rtrim($code);
$original = preg_replace('#^\t*#', '', $code);
if(empty($original))
{
return;
}
$code = str_replace('$', '$', $code);
$code = preg_replace('#\$([0-9])#', '\\\$\\1', $code);
$code = str_replace('\\', '\', $code);
$code = preg_replace('#([>\s()]|^)((http|ftp|news)\://([^/"\s<\[.]+\.)+\w+(\:[0-9]+)?(/[^"\s<\[]*)?)#i', '$1<a href="$2">$2</a>', $code);
$code = str_replace("\t", ' ', $code);
$code = str_replace(" ", ' ', $code);
return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><code>".$code."</code></div></div>\n";
}
**/
function mycode_parse_cdkpu($cdkpu, $text_only=false)
{
global $lang;
if($text_only == true)
{
return "\n{$lang->code}\n--\n{$cdkpu}\n--\n";
}
// Clean the string before parsing.
$cdkpu = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $cdkpu);
$cdkpu = rtrim($cdkpu);
$original = preg_replace('#^\t*#', '', $cdkpu);
if(empty($original))
{
return;
}
$cdkpu = str_replace('$', '$', $cdkpu);
$cdkpu = preg_replace('#\$([0-9])#', '\\\$\\1', $cdkpu);
$cdkpu = str_replace('\\', '\', $cdkpu);
$cdkpu = preg_replace('#([>\s()]|^)((http|ftp|news)\://([^/"\s<\[.]+\.)+\w+(\:[0-9]+)?(/[^"\s<\[]*)?)#i', '$1<a href="$2">$2</a>', $cdkpu);
$cdkpu = str_replace("\t", ' ', $cdkpu);
$cdkpu = str_replace(" ", ' ', $cdkpu);
return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><cdkpu>".$cdkpu."</cdkpu></div></div>\n";
}
/**
* Parses PHP code MyCode.
*
* @param string The message to be parsed
* @param boolean Whether or not it should return it as pre-wrapped in a div or not.
* @param boolean Are we formatting as text?
* @return string The parsed message.
*/
function mycode_parse_php($str, $bare_return = false, $text_only = false)
{
global $lang;
if($text_only == true)
{
return "\n{$lang->php_code}\n--\n$str\n--\n";
}
// Clean the string before parsing except tab spaces.
$str = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $str);
$str = rtrim($str);
$original = preg_replace('#^\t*#', '', $str);
if(empty($original))
{
return;
}
$str = str_replace('&', '&', $str);
$str = str_replace('<', '<', $str);
$str = str_replace('>', '>', $str);
// See if open and close tags are provided.
$added_open_tag = false;
if(!preg_match("#^\s*<\?#si", $str))
{
$added_open_tag = true;
$str = "<?php \n".$str;
}
$added_end_tag = false;
if(!preg_match("#\?>\s*$#si", $str))
{
$added_end_tag = true;
$str = $str." \n?>";
}
$code = @highlight_string($str, true);
// Do the actual replacing.
$code = preg_replace('#<code>\s*<span style="color: \#000000">\s*#i', "<code>", $code);
$code = preg_replace("#</span>\s*</code>#", "</code>", $code);
$code = preg_replace("#</span>(\r\n?|\n?)</code>#", "</span></code>", $code);
$code = str_replace("\\", '\', $code);
$code = str_replace('$', '$', $code);
$code = preg_replace("#&\#([0-9]+);#si", "&#$1;", $code);
if($added_open_tag)
{
$code = preg_replace("#<code><span style=\"color: \#([A-Z0-9]{6})\"><\?php( | )(<br />?)#", "<code><span style=\"color: #$1\">", $code);
}
if($added_end_tag)
{
$code = str_replace("?></span></code>", "</span></code>", $code);
// Wait a minute. It fails highlighting? Stupid highlighter.
$code = str_replace("?></code>", "</code>", $code);
}
$code = preg_replace("#<span style=\"color: \#([A-Z0-9]{6})\"></span>#", "", $code);
$code = str_replace("<code>", "<div dir=\"ltr\"><code>", $code);
$code = str_replace("</code>", "</code></div>", $code);
$code = preg_replace("# *$#", "", $code);
if($bare_return)
{
return $code;
}
// Send back the code all nice and pretty
return "<div class=\"codeblock phpcodeblock\"><div class=\"title\">$lang->php_code\n</div><div class=\"body\">".$code."</div></div>\n";
}
|