Changeset 9682 for extensions/bbcode_bar/bbcode_bar.inc.php
- Timestamp:
- Mar 14, 2011, 9:35:14 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/bbcode_bar/bbcode_bar.inc.php
r6297 r9682 1 1 <?php 2 3 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 4 3 5 4 function set_bbcode_bar() 6 5 { 7 global $template, $conf, $lang, $user, $pwg_loaded_plugins; 8 9 load_language('plugin.lang', dirname(__FILE__) . '/'); 10 11 $conf_bbcode_bar = explode("," , $conf['bbcode_bar']); 12 13 $template->set_filename('bbcode_bar', dirname(__FILE__).'/bbcode_bar.tpl'); 14 15 if ($conf_bbcode_bar[0] == 1) $template->assign('BBCode_bar_button_00',true); 16 if ($conf_bbcode_bar[1] == 1) $template->assign('BBCode_bar_button_01',true); 17 if ($conf_bbcode_bar[2] == 1) $template->assign('BBCode_bar_button_02',true); 18 if ($conf_bbcode_bar[3] == 1) $template->assign('BBCode_bar_button_03',true); 19 if ($conf_bbcode_bar[4] == 1) $template->assign('BBCode_bar_button_04',true); 20 if ($conf_bbcode_bar[5] == 1) $template->assign('BBCode_bar_button_05',true); 21 if ($conf_bbcode_bar[6] == 1) $template->assign('BBCode_bar_button_06',true); 22 if ($conf_bbcode_bar[7] == 1) $template->assign('BBCode_bar_button_07',true); 23 if ($conf_bbcode_bar[8] == 1) $template->assign('BBCode_bar_button_08',true); 24 if ($conf_bbcode_bar[9] == 1) $template->assign('BBCode_bar_button_09',true); 25 if ($conf_bbcode_bar[10] == 1) $template->assign('BBCode_bar_button_10',true); 26 if ($conf_bbcode_bar[11] == 1) $template->assign('BBCode_bar_button_11',true); 27 if ($conf_bbcode_bar[12] == 1) $template->assign('BBCode_bar_button_12',true); 28 if ($conf_bbcode_bar[13] == 1) $template->assign('BBCode_bar_button_13',true); 29 if ($conf_bbcode_bar[14] == 1) $template->assign('BBCode_bar_button_14',true); 30 if ($conf_bbcode_bar[15] == 1) $template->assign('BBCode_bar_button_15',true); 31 $template->assign('repicon', $conf_bbcode_bar[17]); 32 33 if (isset($pwg_loaded_plugins['SmiliesSupport'])) 34 { 35 $template->assign('BBCode_bar_SmiliesSupport', array('SMILIESSUPPORT_PAGE' => SmiliesTable())); 36 } 37 38 $lang['Comment'] .= $template->parse('bbcode_bar', true); 6 global $template, $conf, $lang, $user, $pwg_loaded_plugins; 7 load_language('plugin.lang', dirname(__FILE__) . '/'); 8 $conf_bbcode_bar = explode("," , $conf['bbcode_bar']); 9 $template->set_filename('bbcode_bar', dirname(__FILE__).'/bbcode_bar.tpl'); 10 11 // buttons 12 for ($i=0; $i<=15; $i++) 13 { 14 if ($conf_bbcode_bar[$i] == 1) $template->assign('BBCode_bar_button_'.sprintf("%02d", $i), true); 15 } 16 $template->assign('repicon', $conf_bbcode_bar[16]); 17 18 // edit field has a different id 19 if (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') 20 { 21 $template->assign('form_name', 'editComment'); 22 } 23 else 24 { 25 $template->assign('form_name', 'addComment'); 26 } 27 28 // smilies support 29 if (isset($pwg_loaded_plugins['SmiliesSupport'])) 30 { 31 $template->assign('BBCode_bar_SmiliesSupport', array('SMILIESSUPPORT_PAGE' => SmiliesTable())); 32 } 33 34 $lang['Comment'] .= $template->parse('bbcode_bar', true); 39 35 } 40 36 … … 43 39 function CheckTags($str) 44 40 { 45 //array of known tags 46 $known = array('p','b','i','u','s','center','right','ol','ul','li','quote', 'img','url','email','color', 'size'); 47 //storage stack 48 $tags = array(); 49 50 for ($pos = 0; $pos<strlen($str); $pos++) 51 { 52 if ($str{$pos} == '[') 53 { 54 $end_pos = strpos($str, ']', $pos); 55 $tag = substr($str, ++$pos, $end_pos-$pos); 56 //deals with tags which contains arguments (ie quote) 57 if ( ($equal_pos = strpos($tag, '=', 0)) !== FALSE) 58 $tag = substr($tag, 0, $equal_pos); 59 //check whether we have a defined tag or not. 60 if (in_array(strtolower($tag),$known) || in_array(strtolower(substr($tag,1)),$known)) 61 { 62 //closing tag 63 if ($tag{0} == '/') 64 { 65 //cleaned tag 66 $tag = substr($tag, 1); 67 $before_tag = substr($str, 0, $pos-1); 68 $after_tag = substr($str, $end_pos+1); 69 //pop stack 70 while (($temp = array_pop($tags))) 71 { 72 if ($temp != $tag) 73 $before_tag.='[/'.$temp.']'; 74 else 75 { 76 $before_tag.='[/'.$tag.']'; 77 break; 78 } 79 } 80 $end_pos += strlen($before_tag)+strlen($after_tag)-strlen($str); 81 $str = $before_tag.$after_tag; 82 } 83 else 84 { // push stack 85 array_push($tags,$tag); 86 } 87 } 88 $pos = $end_pos; 89 } 90 } 91 // empty stack and closing tags 92 while ($temp = array_pop($tags)) 93 { 94 $str.='[/'.$temp.']'; 95 } 96 return $str; 41 //array of known tags 42 $known = array('p','b','i','u','s','center','right','ol','ul','li','quote', 'img','url','email','color', 'size'); 43 //storage stack 44 $tags = array(); 45 46 for ($pos = 0; $pos<strlen($str); $pos++) 47 { 48 if ($str{$pos} == '[') 49 { 50 $end_pos = strpos($str, ']', $pos); 51 $tag = substr($str, ++$pos, $end_pos-$pos); 52 //deals with tags which contains arguments (ie quote) 53 if ( ($equal_pos = strpos($tag, '=', 0)) !== FALSE) 54 $tag = substr($tag, 0, $equal_pos); 55 //check whether we have a defined tag or not. 56 if (in_array(strtolower($tag),$known) || in_array(strtolower(substr($tag,1)),$known)) 57 { 58 //closing tag 59 if ($tag{0} == '/') 60 { 61 //cleaned tag 62 $tag = substr($tag, 1); 63 $before_tag = substr($str, 0, $pos-1); 64 $after_tag = substr($str, $end_pos+1); 65 //pop stack 66 while (($temp = array_pop($tags))) 67 { 68 if ($temp != $tag) 69 { 70 $before_tag.='[/'.$temp.']'; 71 } 72 else 73 { 74 $before_tag.='[/'.$tag.']'; 75 break; 76 } 77 } 78 $end_pos += strlen($before_tag)+strlen($after_tag)-strlen($str); 79 $str = $before_tag.$after_tag; 80 } 81 else 82 { // push stack 83 array_push($tags,$tag); 84 } 85 } 86 $pos = $end_pos; 87 } 88 } 89 // empty stack and closing tags 90 while ($temp = array_pop($tags)) 91 { 92 $str.='[/'.$temp.']'; 93 } 94 return $str; 97 95 } 98 96 … … 100 98 function BBCodeParse($str) 101 99 { 102 103 104 105 106 $str = CheckTags(nl2br($str)); 107 108 $patterns = array();109 $replacements = array(); 110 111 if ( $conf_bbcode_bar[0] == 1 ) 112 { 113 //Paragraph 114 $patterns[] = '#\[p\](.*?)\[/p\]#is';115 $replacements[] = '<p>\\1</p>'; 116 } 117 if ( $conf_bbcode_bar[1] == 1 ) 118 { 119 // Bold 120 $patterns[] = '#\[b\](.*?)\[/b\]#is';121 $replacements[] = '<strong>\\1</strong>'; 122 } 123 if ( $conf_bbcode_bar[2] == 1 ) 124 { 125 //Italic 126 $patterns[] = '#\[i\](.*?)\[/i\]#is';127 $replacements[] = '<em>\\1</em>'; 128 } 129 if ( $conf_bbcode_bar[3] == 1 ) 130 { 131 //Underline 132 $patterns[] = '#\[u\](.*?)\[\/u\]#is';133 $replacements[] = '<u>\\1</u>'; 134 } 135 if ( $conf_bbcode_bar[4] == 1 ) 136 { 137 //Strikethrough 138 $patterns[] = '#\[s\](.*?)\[/s\]#is';139 $replacements[] = '<del>\\1</del>'; 140 } 141 if ( $conf_bbcode_bar[5] == 1 ) 142 { 143 //Center 144 $patterns[] = '#\[center\](.*?)\[/center\]#is';145 $replacements[] = '</p><div align="center"><p>\\1</p></div><p>'; 146 } 147 if ( $conf_bbcode_bar[6] == 1 ) 148 { 149 //Right 150 $patterns[] = '#\[right\](.*?)\[/right\]#is';151 $replacements[] = '</p><div align="right"><p>\\1</p></div><p>'; 152 } 153 if ( $conf_bbcode_bar[7] == 1 ) 154 { 155 //Olist 156 $patterns[] = '#\[ol\](.*?)\[/ol\]#is';157 $replacements[] = '<ol>\\1</ol>'; 158 } 159 if ( $conf_bbcode_bar[8] == 1 ) 160 { 161 //Ulist 162 $patterns[] = '#\[ul\](.*?)\[/ul\]#is';163 $replacements[] = '<ul>\\1</ul>'; 164 } 165 if (( $conf_bbcode_bar[7] == 1 ) || ( $conf_bbcode_bar[8] == 1 )) 166 { 167 //List 168 $patterns[] = '#\[li\](.*?)\[/li\]#is';169 $replacements[] = '<li>\\1</li>'; 170 } 171 if ( $conf_bbcode_bar[9] == 1 ) 172 { 173 // Quotes 174 $patterns[] = "#\[quote\](.*?)\[/quote\]#is";175 $replacements[] = '</p><blockquote><span style="font-size: 11px; line-height: normal">\\1</span></blockquote><p>'; 176 177 //Quotes with "user" 178 $patterns[] = "#\[quote="(.*?)"\](.*?)\[/quote\]#is";179 $replacements[] = '</p><blockquote><span style="font-size: 11px; line-height: normal"><b>\\1 : </b><br/>\\2</span></blockquote><p>'; 180 181 //Quotes with user 182 $patterns[] = "#\[quote=(.*?)\](.*?)\[/quote\]#is";183 $replacements[] = '</p><blockquote><span style="font-size: 11px; line-height: normal"><b>\\1 : </b><br/>\\2</span></blockquote><p>'; 184 } 185 if ( $conf_bbcode_bar[10] == 1 ) 186 { 187 //Images 188 $patterns[] = "#\[img\](.*?)\[/img\]#si";189 $replacements[] = "<img src='\\1' alt='' />"; 190 } 191 if ( $conf_bbcode_bar[11] == 1 ) 192 { 193 //[url]xxxx://www.zzzz.yyy[/url] 194 $patterns[] = "#\[url\]([\w]+?://[^ \"\n\r\t<]*?)\[/url\]#is";195 $replacements[] = '<a href="\\1" target="_blank">\\1</a>'; 196 197 //[url]www.zzzzz.yyy[/url] 198 $patterns[] = "#\[url\]((www|ftp)\.[^ \"\n\r\t<]*?)\[/url\]#is";199 $replacements[] = '<a href="http://\\1" target="_blank">\\1</a>'; 200 201 //[url=xxxx://www.zzzzz.yyy]ZzZzZ[/url] /*No I ain't sleeping yet*/ 202 $patterns[] = "#\[url=([\w]+?://[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is";203 $replacements[] = '<a href="\\1" target="_blank">\\2</a>'; 204 205 // [url=www.zzzzz.yyy]zZzZz[/url] /*But I'm thinking about*/ 206 $patterns[] = "#\[url=((www|ftp)\.[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is";207 $replacements[] = '<a href="http://\\1" target="_blank">\\2</a>'; 208 209 // [url="www.zzzzz.yyy"]zZzZz[/url] /* It's nearly 2 am now */ 210 $patterns[] = "#\[url="((www|ftp)\.[^ \n\r\t<]*?)"\](.*?)\[/url\]#is";211 $replacements[] = '<a href="http://\\1" target="_blank">\\3</a>'; 212 213 //[url="http://www.zzzzz.yyy"]zZzZz[/url] /*I really dislike commenting code*/ 214 $patterns[] = "#\[url="([\w]+?://[^ \n\r\t<]*?)"\](.*?)\[/url\]#is";215 $replacements[] = '<a href="\\1" target="_blank">\\2</a>'; 216 } 217 if ( $conf_bbcode_bar[12] == 1 ) 218 { 219 //[email]samvure@gmail.com[/email] 220 $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#is";221 $replacements[] = '<a href="mailto:\\1">\\1</a>'; 222 } 223 if ( $conf_bbcode_bar[13] == 1 ) 224 { 225 //Size 226 $patterns[] = "#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si";227 $replacements[] = '<span style="font-size: \\1px; line-height: normal">\\2</span>'; 228 } 229 if ( $conf_bbcode_bar[14] == 1 ) 230 { 231 //Colours 232 $patterns[] = "#\[color=(\#[0-9A-F]{6}|[a-z]+)\](.*?)\[/color\]#si";233 $replacements[] = '<span style="color: \\1">\\2</span>'; 234 } 235 100 global $conf; 101 102 $conf_bbcode_bar = explode("," , $conf['bbcode_bar']); 103 $str = CheckTags(nl2br($str)); 104 105 $patterns = array(); 106 $replacements = array(); 107 108 if ( $conf_bbcode_bar[0] == 1 ) 109 { 110 //Paragraph 111 $patterns[] = '#\[p\](.*?)\[/p\]#is'; 112 $replacements[] = '<p>\\1</p>'; 113 } 114 if ( $conf_bbcode_bar[1] == 1 ) 115 { 116 // Bold 117 $patterns[] = '#\[b\](.*?)\[/b\]#is'; 118 $replacements[] = '<strong>\\1</strong>'; 119 } 120 if ( $conf_bbcode_bar[2] == 1 ) 121 { 122 //Italic 123 $patterns[] = '#\[i\](.*?)\[/i\]#is'; 124 $replacements[] = '<em>\\1</em>'; 125 } 126 if ( $conf_bbcode_bar[3] == 1 ) 127 { 128 //Underline 129 $patterns[] = '#\[u\](.*?)\[\/u\]#is'; 130 $replacements[] = '<u>\\1</u>'; 131 } 132 if ( $conf_bbcode_bar[4] == 1 ) 133 { 134 //Strikethrough 135 $patterns[] = '#\[s\](.*?)\[/s\]#is'; 136 $replacements[] = '<del>\\1</del>'; 137 } 138 if ( $conf_bbcode_bar[5] == 1 ) 139 { 140 //Center 141 $patterns[] = '#\[center\](.*?)\[/center\]#is'; 142 $replacements[] = '<div align="center"><p>\\1</p></div>'; 143 } 144 if ( $conf_bbcode_bar[6] == 1 ) 145 { 146 //Right 147 $patterns[] = '#\[right\](.*?)\[/right\]#is'; 148 $replacements[] = '<div align="right"><p>\\1</p></div>'; 149 } 150 if ( $conf_bbcode_bar[7] == 1 ) 151 { 152 //Olist 153 $patterns[] = '#\[ol\](.*?)\[/ol\]#is'; 154 $replacements[] = '<ol>\\1</ol>'; 155 } 156 if ( $conf_bbcode_bar[8] == 1 ) 157 { 158 //Ulist 159 $patterns[] = '#\[ul\](.*?)\[/ul\]#is'; 160 $replacements[] = '<ul>\\1</ul>'; 161 } 162 if (( $conf_bbcode_bar[7] == 1 ) || ( $conf_bbcode_bar[8] == 1 )) 163 { 164 //List 165 $patterns[] = '#\[li\](.*?)\[/li\]#is'; 166 $replacements[] = '<li>\\1</li>'; 167 } 168 if ( $conf_bbcode_bar[9] == 1 ) 169 { 170 // Quotes 171 $patterns[] = "#\[quote\](.*?)\[/quote\]#is"; 172 $replacements[] = '<blockquote><span style="font-size: 11px; line-height: normal">\\1</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 //Quotes with user 179 $patterns[] = "#\[quote=(.*?)\](.*?)\[/quote\]#is"; 180 $replacements[] = '<blockquote><span style="font-size: 11px; line-height: normal"><b>\\1 : </b><br/>\\2</span></blockquote>'; 181 } 182 if ( $conf_bbcode_bar[10] == 1 ) 183 { 184 //Images 185 $patterns[] = "#\[img\](.*?)\[/img\]#si"; 186 $replacements[] = '<img src="\\1" />'; 187 } 188 if ( $conf_bbcode_bar[11] == 1 ) 189 { 190 //[url]xxxx://www.zzzz.yyy[/url] 191 $patterns[] = "#\[url\]([\w]+?://[^ \"\n\r\t<]*?)\[/url\]#is"; 192 $replacements[] = '<a href="\\1" target="_blank">\\1</a>'; 193 194 //[url]www.zzzzz.yyy[/url] 195 $patterns[] = "#\[url\]((www|ftp)\.[^ \"\n\r\t<]*?)\[/url\]#is"; 196 $replacements[] = '<a href="http://\\1" target="_blank">\\1</a>'; 197 198 //[url=xxxx://www.zzzzz.yyy]ZzZzZ[/url] 199 $patterns[] = "#\[url=([\w]+?://[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is"; 200 $replacements[] = '<a href="\\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">\\2</a>'; 205 206 // [url="www.zzzzz.yyy"]zZzZz[/url] 207 $patterns[] = "#\[url="((www|ftp)\.[^ \n\r\t<]*?)"\](.*?)\[/url\]#is"; 208 $replacements[] = '<a href="http://\\1" target="_blank">\\3</a>'; 209 210 //[url="http://www.zzzzz.yyy"]zZzZz[/url] 211 $patterns[] = "#\[url="([\w]+?://[^ \n\r\t<]*?)"\](.*?)\[/url\]#is"; 212 $replacements[] = '<a href="\\1" target="_blank">\\2</a>'; 213 } 214 if ( $conf_bbcode_bar[12] == 1 ) 215 { 216 //[email]samvure@gmail.com[/email] 217 $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#is"; 218 $replacements[] = '<a href="mailto:\\1">\\1</a>'; 219 } 220 if ( $conf_bbcode_bar[13] == 1 ) 221 { 222 //Size 223 $patterns[] = "#\[size=([1-2]?[0-9])\](.*?)\[/size\]#si"; 224 $replacements[] = '<span style="font-size: \\1px; line-height: normal">\\2</span>'; 225 } 226 if ( $conf_bbcode_bar[14] == 1 ) 227 { 228 //Colours 229 $patterns[] = "#\[color=(\#[0-9A-F]{6}|[a-z]+)\](.*?)\[/color\]#si"; 230 $replacements[] = '<span style="color: \\1">\\2</span>'; 231 } 232 233 return preg_replace($patterns, $replacements, $str); 236 234 } 237 235 ?>
Note: See TracChangeset
for help on using the changeset viewer.