Changeset 10983 for extensions/bbcode_bar/bbcode_bar.inc.php
- Timestamp:
- May 22, 2011, 12:23:03 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/bbcode_bar/bbcode_bar.inc.php
r10597 r10983 4 4 function set_bbcode_bar() 5 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 $template->parse('bbcode_bar', true); 33 34 35 36 37 } 6 global $template, $conf, $pwg_loaded_plugins, $page; 7 load_language('plugin.lang', dirname(__FILE__) . '/'); 8 $conf_bbcode_bar = unserialize($conf['bbcode_bar']); 9 10 // buttons 11 foreach(unserialize(BBcode_codes) as $key) { 12 if ($conf_bbcode_bar[$key]) $template->assign('BBC_'.$key, true); 13 } 14 15 // edit field has different id 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'); 25 26 if (isset($pwg_loaded_plugins['SmiliesSupport'])) { 27 $template->assign('BBC_smilies', true); 28 } 29 30 $template->assign('BBCODE_PATH', BBcode_PATH); 31 $template->set_filename('bbcode_bar', dirname(__FILE__).'/template/bbcode_bar.tpl'); 32 $template->parse('bbcode_bar', true); 33 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 strcmp($pwg_loaded_plugins['SmiliesSupport']['version'], '2.2.a') != -1) { 36 set_smiliessupport(); 37 } 38 38 } 39 39 … … 42 42 function CheckTags($str) 43 43 { 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 $tag = substr($tag, 1); 64 65 $after_tag = substr($str, $end_pos+1); 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 $pos = $end_pos; 83 84 85 86 87 { 88 89 90 44 //storage stack 45 $tags = array(); 46 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. 57 if (in_array(strtolower($tag),unserialize(BBcode_codes)) || in_array(strtolower(substr($tag,1)),unserialize(BBcode_codes))) 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 { 69 if ($temp != $tag) { 70 $before_tag.='[/'.$temp.']'; 71 } else { 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; 78 } else { // push stack 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; 91 91 } 92 92 … … 94 94 function BBCodeParse($str) 95 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 //Underline 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 228 229 96 global $conf; 97 98 $conf_bbcode_bar = unserialize($conf['bbcode_bar']); 99 $str = CheckTags(nl2br($str)); 100 101 $patterns = array(); 102 $replacements = array(); 103 104 if ($conf_bbcode_bar['p']) 105 { 106 //Paragraph 107 $patterns[] = '#\[p\](.*?)\[/p\]#is'; 108 $replacements[] = '<p>\\1</p>'; 109 } 110 if ($conf_bbcode_bar['b']) 111 { 112 // Bold 113 $patterns[] = '#\[b\](.*?)\[/b\]#is'; 114 $replacements[] = '<b>\\1</b>'; 115 } 116 if ($conf_bbcode_bar['i']) 117 { 118 //Italic 119 $patterns[] = '#\[i\](.*?)\[/i\]#is'; 120 $replacements[] = '<i>\\1</i>'; 121 } 122 if ($conf_bbcode_bar['u']) 123 { 124 //Underline 125 $patterns[] = '#\[u\](.*?)\[\/u\]#is'; 126 $replacements[] = '<u>\\1</u>'; 127 } 128 if ($conf_bbcode_bar['s']) 129 { 130 //Strikethrough 131 $patterns[] = '#\[s\](.*?)\[/s\]#is'; 132 $replacements[] = '<s>\\1</s>'; 133 } 134 if ($conf_bbcode_bar['center']) 135 { 136 //Center 137 $patterns[] = '#\[center\](.*?)\[/center\]#is'; 138 $replacements[] = '<div align="center"><p>\\1</p></div>'; 139 } 140 if ($conf_bbcode_bar['right']) 141 { 142 //Right 143 $patterns[] = '#\[right\](.*?)\[/right\]#is'; 144 $replacements[] = '<div align="right"><p>\\1</p></div>'; 145 } 146 if ($conf_bbcode_bar['ol']) 147 { 148 //Olist 149 $patterns[] = '#\[ol\](.*?)\[/ol\]#is'; 150 $replacements[] = '<ol>\\1</ol>'; 151 } 152 if ($conf_bbcode_bar['ul']) 153 { 154 //Ulist 155 $patterns[] = '#\[ul\](.*?)\[/ul\]#is'; 156 $replacements[] = '<ul>\\1</ul>'; 157 } 158 if ($conf_bbcode_bar['ol'] || $conf_bbcode_bar['ul']) 159 { 160 //List 161 $patterns[] = '#\[li\](.*?)\[/li\]#is'; 162 $replacements[] = '<li>\\1</li>'; 163 } 164 if ($conf_bbcode_bar['quote']) 165 { 166 // Quotes 167 $patterns[] = "#\[quote\](.*?)\[/quote\]#is"; 168 $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal">\\1</span></blockquote>'; 169 170 //Quotes with "user" 171 $patterns[] = "#\[quote="(.*?)"\](.*?)\[/quote\]#is"; 172 $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal"><b>\\1 : </b><br/>\\2</span></blockquote>'; 173 174 //Quotes with user 175 $patterns[] = "#\[quote=(.*?)\](.*?)\[/quote\]#is"; 176 $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal"><b>\\1 : </b><br/>\\2</span></blockquote>'; 177 } 178 if ($conf_bbcode_bar['img']) 179 { 180 //Images 181 $patterns[] = "#\[img\](.*?)\[/img\]#si"; 182 $replacements[] = '<img src="\\1" />'; 183 } 184 if ($conf_bbcode_bar['url']) 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>'; 189 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>'; 193 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>'; 197 198 //[url=www.zzzzz.yyy]zZzZz[/url] 199 $patterns[] = "#\[url=((www|ftp)\.[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is"; 200 $replacements[] = '<a href="http://\\1" target="_blank">\\2</a>'; 201 202 //[url="www.zzzzz.yyy"]zZzZz[/url] 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 } 210 if ($conf_bbcode_bar['email']) 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 } 216 if ($conf_bbcode_bar['size']) 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 } 222 if ($conf_bbcode_bar['color']) 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); 230 230 } 231 231
Note: See TracChangeset
for help on using the changeset viewer.