[3305] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | function set_bbcode_bar() |
---|
| 5 | { |
---|
[10011] | 6 | global $template, $conf, $pwg_loaded_plugins, $page; |
---|
[9682] | 7 | load_language('plugin.lang', dirname(__FILE__) . '/'); |
---|
[9965] | 8 | $conf_bbcode_bar = unserialize($conf['bbcode_bar']); |
---|
[3305] | 9 | |
---|
[9682] | 10 | // buttons |
---|
[9965] | 11 | foreach(unserialize(BBcode_codes) as $key) { |
---|
| 12 | if ($conf_bbcode_bar[$key]) $template->assign('BBC_'.$key, true); |
---|
[9682] | 13 | } |
---|
| 14 | |
---|
[9765] | 15 | // edit field has different id |
---|
[9965] | 16 | // if ( |
---|
| 17 | // (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') |
---|
| 18 | // OR (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage') |
---|
| 19 | // ) { |
---|
| 20 | // $template->assign('form_name', 'editComment'); |
---|
| 21 | // } else { |
---|
| 22 | // $template->assign('form_name', 'addComment'); |
---|
| 23 | // } |
---|
| 24 | $template->assign('form_name', 'addComment'); |
---|
[6297] | 25 | |
---|
[10024] | 26 | if (isset($pwg_loaded_plugins['SmiliesSupport'])) { |
---|
| 27 | $template->assign('BBC_smilies', true); |
---|
| 28 | } |
---|
| 29 | |
---|
[9787] | 30 | $template->assign('BBCODE_PATH', BBcode_PATH); |
---|
| 31 | $template->set_filename('bbcode_bar', dirname(__FILE__).'/template/bbcode_bar.tpl'); |
---|
[9965] | 32 | $template->parse('bbcode_bar', true); |
---|
| 33 | |
---|
[10011] | 34 | // smilies support >2.2.a ## must be parsed after bbcode_bar, because the javascript must be after bbc's one |
---|
| 35 | if (isset($pwg_loaded_plugins['SmiliesSupport']) AND version_compare($pwg_loaded_plugins['SmiliesSupport']['version'], '2.2.a') != -1) { |
---|
| 36 | set_smiliessupport(); |
---|
[9965] | 37 | } |
---|
[3305] | 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | //Check tags and eventually close malformed tags, return BBCoded String |
---|
| 42 | function CheckTags($str) |
---|
| 43 | { |
---|
[9682] | 44 | //storage stack |
---|
| 45 | $tags = array(); |
---|
[3305] | 46 | |
---|
[9682] | 47 | for ($pos = 0; $pos<strlen($str); $pos++) |
---|
| 48 | { |
---|
| 49 | if ($str{$pos} == '[') |
---|
| 50 | { |
---|
| 51 | $end_pos = strpos($str, ']', $pos); |
---|
| 52 | $tag = substr($str, ++$pos, $end_pos-$pos); |
---|
| 53 | //deals with tags which contains arguments (ie quote) |
---|
| 54 | if ( ($equal_pos = strpos($tag, '=', 0)) !== FALSE) |
---|
| 55 | $tag = substr($tag, 0, $equal_pos); |
---|
| 56 | //check whether we have a defined tag or not. |
---|
[9965] | 57 | if (in_array(strtolower($tag),unserialize(BBcode_codes)) || in_array(strtolower(substr($tag,1)),unserialize(BBcode_codes))) |
---|
[9682] | 58 | { |
---|
| 59 | //closing tag |
---|
| 60 | if ($tag{0} == '/') |
---|
| 61 | { |
---|
| 62 | //cleaned tag |
---|
| 63 | $tag = substr($tag, 1); |
---|
| 64 | $before_tag = substr($str, 0, $pos-1); |
---|
| 65 | $after_tag = substr($str, $end_pos+1); |
---|
| 66 | //pop stack |
---|
| 67 | while (($temp = array_pop($tags))) |
---|
| 68 | { |
---|
[9765] | 69 | if ($temp != $tag) { |
---|
[9682] | 70 | $before_tag.='[/'.$temp.']'; |
---|
[9765] | 71 | } else { |
---|
[9682] | 72 | $before_tag.='[/'.$tag.']'; |
---|
| 73 | break; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | $end_pos += strlen($before_tag)+strlen($after_tag)-strlen($str); |
---|
| 77 | $str = $before_tag.$after_tag; |
---|
[9765] | 78 | } else { // push stack |
---|
[9682] | 79 | array_push($tags,$tag); |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | $pos = $end_pos; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | // empty stack and closing tags |
---|
| 86 | while ($temp = array_pop($tags)) |
---|
| 87 | { |
---|
| 88 | $str.='[/'.$temp.']'; |
---|
| 89 | } |
---|
| 90 | return $str; |
---|
[3305] | 91 | } |
---|
| 92 | |
---|
| 93 | // return string, HTML version of BBCoded $str |
---|
| 94 | function BBCodeParse($str) |
---|
| 95 | { |
---|
[9682] | 96 | global $conf; |
---|
[3305] | 97 | |
---|
[9965] | 98 | $conf_bbcode_bar = unserialize($conf['bbcode_bar']); |
---|
[9682] | 99 | $str = CheckTags(nl2br($str)); |
---|
[3305] | 100 | |
---|
[9682] | 101 | $patterns = array(); |
---|
| 102 | $replacements = array(); |
---|
[3305] | 103 | |
---|
[9965] | 104 | if ($conf_bbcode_bar['p']) |
---|
[9682] | 105 | { |
---|
| 106 | //Paragraph |
---|
| 107 | $patterns[] = '#\[p\](.*?)\[/p\]#is'; |
---|
| 108 | $replacements[] = '<p>\\1</p>'; |
---|
| 109 | } |
---|
[9965] | 110 | if ($conf_bbcode_bar['b']) |
---|
[9682] | 111 | { |
---|
| 112 | // Bold |
---|
| 113 | $patterns[] = '#\[b\](.*?)\[/b\]#is'; |
---|
[9965] | 114 | $replacements[] = '<b>\\1</b>'; |
---|
[9682] | 115 | } |
---|
[9965] | 116 | if ($conf_bbcode_bar['i']) |
---|
[9682] | 117 | { |
---|
| 118 | //Italic |
---|
| 119 | $patterns[] = '#\[i\](.*?)\[/i\]#is'; |
---|
[9965] | 120 | $replacements[] = '<i>\\1</i>'; |
---|
[9682] | 121 | } |
---|
[9965] | 122 | if ($conf_bbcode_bar['u']) |
---|
[9682] | 123 | { |
---|
| 124 | //Underline |
---|
| 125 | $patterns[] = '#\[u\](.*?)\[\/u\]#is'; |
---|
| 126 | $replacements[] = '<u>\\1</u>'; |
---|
| 127 | } |
---|
[9965] | 128 | if ($conf_bbcode_bar['s']) |
---|
[9682] | 129 | { |
---|
| 130 | //Strikethrough |
---|
| 131 | $patterns[] = '#\[s\](.*?)\[/s\]#is'; |
---|
[9965] | 132 | $replacements[] = '<s>\\1</s>'; |
---|
[9682] | 133 | } |
---|
[9965] | 134 | if ($conf_bbcode_bar['center']) |
---|
[9682] | 135 | { |
---|
| 136 | //Center |
---|
| 137 | $patterns[] = '#\[center\](.*?)\[/center\]#is'; |
---|
| 138 | $replacements[] = '<div align="center"><p>\\1</p></div>'; |
---|
| 139 | } |
---|
[9965] | 140 | if ($conf_bbcode_bar['right']) |
---|
[9682] | 141 | { |
---|
| 142 | //Right |
---|
| 143 | $patterns[] = '#\[right\](.*?)\[/right\]#is'; |
---|
| 144 | $replacements[] = '<div align="right"><p>\\1</p></div>'; |
---|
| 145 | } |
---|
[9965] | 146 | if ($conf_bbcode_bar['ol']) |
---|
[9682] | 147 | { |
---|
| 148 | //Olist |
---|
| 149 | $patterns[] = '#\[ol\](.*?)\[/ol\]#is'; |
---|
| 150 | $replacements[] = '<ol>\\1</ol>'; |
---|
| 151 | } |
---|
[9965] | 152 | if ($conf_bbcode_bar['ul']) |
---|
[9682] | 153 | { |
---|
| 154 | //Ulist |
---|
| 155 | $patterns[] = '#\[ul\](.*?)\[/ul\]#is'; |
---|
| 156 | $replacements[] = '<ul>\\1</ul>'; |
---|
| 157 | } |
---|
[9965] | 158 | if ($conf_bbcode_bar['ol'] || $conf_bbcode_bar['ul']) |
---|
[9682] | 159 | { |
---|
| 160 | //List |
---|
| 161 | $patterns[] = '#\[li\](.*?)\[/li\]#is'; |
---|
| 162 | $replacements[] = '<li>\\1</li>'; |
---|
| 163 | } |
---|
[9965] | 164 | if ($conf_bbcode_bar['quote']) |
---|
[9682] | 165 | { |
---|
| 166 | // Quotes |
---|
| 167 | $patterns[] = "#\[quote\](.*?)\[/quote\]#is"; |
---|
[9965] | 168 | $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal">\\1</span></blockquote>'; |
---|
[3305] | 169 | |
---|
[9682] | 170 | //Quotes with "user" |
---|
| 171 | $patterns[] = "#\[quote="(.*?)"\](.*?)\[/quote\]#is"; |
---|
[9965] | 172 | $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal"><b>\\1 : </b><br/>\\2</span></blockquote>'; |
---|
[3305] | 173 | |
---|
[9682] | 174 | //Quotes with user |
---|
| 175 | $patterns[] = "#\[quote=(.*?)\](.*?)\[/quote\]#is"; |
---|
[9965] | 176 | $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal"><b>\\1 : </b><br/>\\2</span></blockquote>'; |
---|
[9682] | 177 | } |
---|
[9965] | 178 | if ($conf_bbcode_bar['img']) |
---|
[9682] | 179 | { |
---|
| 180 | //Images |
---|
| 181 | $patterns[] = "#\[img\](.*?)\[/img\]#si"; |
---|
| 182 | $replacements[] = '<img src="\\1" />'; |
---|
| 183 | } |
---|
[9965] | 184 | if ($conf_bbcode_bar['url']) |
---|
[9682] | 185 | { |
---|
| 186 | //[url]xxxx://www.zzzz.yyy[/url] |
---|
| 187 | $patterns[] = "#\[url\]([\w]+?://[^ \"\n\r\t<]*?)\[/url\]#is"; |
---|
| 188 | $replacements[] = '<a href="\\1" target="_blank">\\1</a>'; |
---|
[3305] | 189 | |
---|
[9682] | 190 | //[url]www.zzzzz.yyy[/url] |
---|
| 191 | $patterns[] = "#\[url\]((www|ftp)\.[^ \"\n\r\t<]*?)\[/url\]#is"; |
---|
| 192 | $replacements[] = '<a href="http://\\1" target="_blank">\\1</a>'; |
---|
[3305] | 193 | |
---|
[9682] | 194 | //[url=xxxx://www.zzzzz.yyy]ZzZzZ[/url] |
---|
| 195 | $patterns[] = "#\[url=([\w]+?://[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is"; |
---|
| 196 | $replacements[] = '<a href="\\1" target="_blank">\\2</a>'; |
---|
[3305] | 197 | |
---|
[9965] | 198 | //[url=www.zzzzz.yyy]zZzZz[/url] |
---|
[9682] | 199 | $patterns[] = "#\[url=((www|ftp)\.[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is"; |
---|
| 200 | $replacements[] = '<a href="http://\\1" target="_blank">\\2</a>'; |
---|
[3305] | 201 | |
---|
[9965] | 202 | //[url="www.zzzzz.yyy"]zZzZz[/url] |
---|
[9682] | 203 | $patterns[] = "#\[url="((www|ftp)\.[^ \n\r\t<]*?)"\](.*?)\[/url\]#is"; |
---|
| 204 | $replacements[] = '<a href="http://\\1" target="_blank">\\3</a>'; |
---|
| 205 | |
---|
| 206 | //[url="http://www.zzzzz.yyy"]zZzZz[/url] |
---|
| 207 | $patterns[] = "#\[url="([\w]+?://[^ \n\r\t<]*?)"\](.*?)\[/url\]#is"; |
---|
| 208 | $replacements[] = '<a href="\\1" target="_blank">\\2</a>'; |
---|
| 209 | } |
---|
[9965] | 210 | if ($conf_bbcode_bar['email']) |
---|
[9682] | 211 | { |
---|
| 212 | //[email]samvure@gmail.com[/email] |
---|
| 213 | $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#is"; |
---|
| 214 | $replacements[] = '<a href="mailto:\\1">\\1</a>'; |
---|
| 215 | } |
---|
[9965] | 216 | if ($conf_bbcode_bar['size']) |
---|
[9682] | 217 | { |
---|
| 218 | //Size |
---|
| 219 | $patterns[] = "#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si"; |
---|
| 220 | $replacements[] = '<span style="font-size: \\1px; line-height: normal">\\2</span>'; |
---|
| 221 | } |
---|
[9965] | 222 | if ($conf_bbcode_bar['color']) |
---|
[9682] | 223 | { |
---|
| 224 | //Colours |
---|
| 225 | $patterns[] = "#\[color=(\#[0-9A-F]{6}|[a-z]+)\](.*?)\[/color\]#si"; |
---|
| 226 | $replacements[] = '<span style="color: \\1">\\2</span>'; |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | return preg_replace($patterns, $replacements, $str); |
---|
[3305] | 230 | } |
---|
[9765] | 231 | |
---|
[3305] | 232 | ?> |
---|