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