1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
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";
}
|