Changeset 26076 for extensions/bbcode_bar/include
- Timestamp:
- Dec 21, 2013, 11:02:24 PM (10 years ago)
- Location:
- extensions/bbcode_bar/include
- Files:
-
- 3 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
extensions/bbcode_bar/include/events.inc.php
r24342 r26076 1 1 <?php 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 4 // add BBCodeBar to textarea 5 function set_bbcode_bar($prefilter='picture', $textarea_id='contentid') 2 defined('BBCODE_ID') or die('Hacking attempt!'); 3 4 function bbcode_bar_admin_menu($menu) 6 5 { 7 global $template, $conf, $pwg_loaded_plugins, $page; 8 9 load_language('plugin.lang', dirname(__FILE__) . '/'); 10 $conf_bbcode_bar = unserialize($conf['bbcode_bar']); 11 12 13 // buttons 14 $tpl_codes = array(); 15 foreach (unserialize(BBcode_codes) as $key) 16 { 17 $tpl_codes[$key] = (bool)$conf_bbcode_bar[$key]; 18 } 19 $tpl_codes['smilies'] = isset($pwg_loaded_plugins['SmiliesSupport']); 20 6 $menu[] = array( 7 'NAME' => 'BBCode Bar', 8 'URL' => BBCODE_ADMIN, 9 ); 10 return $menu; 11 } 12 13 function add_bbcode_bar() 14 { 15 global $page, $pwg_loaded_plugins, $template, $conf; 16 17 if (script_basename() == 'picture') 18 { 19 $prefilter = 'picture'; 20 $textarea_id = 'contentid'; 21 } 22 else if (isset($page['section'])) 23 { 24 if ( 25 script_basename() == 'index' and isset($pwg_loaded_plugins['Comments_on_Albums']) 26 and $page['section'] == 'categories' and isset($page['category']) 27 ) 28 { 29 $prefilter = 'comments_on_albums'; 30 $textarea_id = 'contentid'; 31 } 32 else if ($page['section'] == 'guestbook') 33 { 34 $prefilter = 'guestbook'; 35 $textarea_id = 'contentid'; 36 } 37 else if ($page['section'] == 'contact') 38 { 39 $prefilter = 'contactform'; 40 $textarea_id = 'cf_content'; 41 } 42 } 43 44 if (!isset($prefilter)) 45 { 46 return; 47 } 48 49 $conf['bbcode_bar']['smilies'] = isset($pwg_loaded_plugins['SmiliesSupport']); 21 50 22 51 // calculate separators between groups … … 37 66 foreach ($groups[$i] as $code) 38 67 { 39 if ($ tpl_codes[$code]) $count++;68 if ($conf['bbcode_bar'][$code]) $count++; 40 69 } 41 70 if ($count>0) … … 43 72 foreach ($groups[$i+1] as $code) 44 73 { 45 if ($ tpl_codes[$code]) $separator = true;74 if ($conf['bbcode_bar'][$code]) $separator = true; 46 75 } 47 76 } … … 54 83 55 84 $template->assign(array( 56 'BBC' => $tpl_codes, 57 'SEP' => $tpl_groups, 58 'BBCODE_PATH' => BBcode_PATH, 59 'BBCODE_ID' => $textarea_id, 85 'BBCODE_PATH' => BBCODE_PATH, 86 'BBCODE' => array( 87 'codes' => $conf['bbcode_bar'], 88 'separators' => $tpl_groups, 89 'textarea_id' => $textarea_id, 90 ), 60 91 )); 61 62 $template->set_prefilter($prefilter, 'set_bbcode_bar_prefilter'); 63 64 // smilies support > 2.3 ## must be parsed after bbcode_bar, because the javascript must be after bbc's one 65 if (isset($pwg_loaded_plugins['SmiliesSupport'])) 66 { 67 set_smiliessupport($prefilter, $textarea_id); 68 } 69 } 70 71 function set_bbcode_bar_prefilter($content, &$smarty) 72 { 73 $search = '#(<div id="guestbookAdd">|<div id="commentAdd">|<div class="contact">)#'; 74 $replace = file_get_contents(BBcode_PATH.'/template/bbcode_bar.tpl').'$1'; 75 return preg_replace($search, $replace, $content); 76 } 77 78 79 // check tags and eventually close malformed tags, return BBCoded String 80 function CheckTags($str) 81 { 82 //storage stack 83 $tags = array(); 84 85 for ($pos = 0; $pos<strlen($str); $pos++) 86 { 87 if ($str{$pos} == '[') 88 { 89 $end_pos = strpos($str, ']', $pos); 90 $tag = substr($str, ++$pos, $end_pos-$pos); 91 //deals with tags which contains arguments (ie quote) 92 if ( ($equal_pos = strpos($tag, '=', 0)) !== FALSE) 93 $tag = substr($tag, 0, $equal_pos); 94 //check whether we have a defined tag or not. 95 if (in_array(strtolower($tag),unserialize(BBcode_codes)) || in_array(strtolower(substr($tag,1)),unserialize(BBcode_codes))) 96 { 97 //closing tag 98 if ($tag{0} == '/') 99 { 100 //cleaned tag 101 $tag = substr($tag, 1); 102 $before_tag = substr($str, 0, $pos-1); 103 $after_tag = substr($str, $end_pos+1); 104 //pop stack 105 while (($temp = array_pop($tags))) 106 { 107 if ($temp != $tag) { 108 $before_tag.='[/'.$temp.']'; 109 } else { 110 $before_tag.='[/'.$tag.']'; 111 break; 112 } 113 } 114 $end_pos += strlen($before_tag)+strlen($after_tag)-strlen($str); 115 $str = $before_tag.$after_tag; 116 } else { // push stack 117 array_push($tags,$tag); 118 } 119 } 120 $pos = $end_pos; 121 } 122 } 123 // empty stack and closing tags 124 while ($temp = array_pop($tags)) 125 { 126 $str.='[/'.$temp.']'; 127 } 128 return $str; 92 93 $template->set_filename('bbcodebar', realpath(BBCODE_PATH.'/template/bbcode_bar.tpl')); 94 $template->parse('bbcodebar'); 129 95 } 130 96 … … 134 100 global $conf; 135 101 136 $conf_bbcode_bar = unserialize($conf['bbcode_bar']); 137 $str = CheckTags(nl2br($str)); 102 $str = bbcode_checktags(nl2br($str)); 138 103 139 104 $patterns = array(); 140 105 $replacements = array(); 141 106 142 if ($conf _bbcode_bar['p'])107 if ($conf['bbcode_bar']['p']) 143 108 { 144 109 //Paragraph … … 146 111 $replacements[] = '<p>\\1</p>'; 147 112 } 148 if ($conf _bbcode_bar['b'])113 if ($conf['bbcode_bar']['b']) 149 114 { 150 115 // Bold … … 152 117 $replacements[] = '<b>\\1</b>'; 153 118 } 154 if ($conf _bbcode_bar['i'])119 if ($conf['bbcode_bar']['i']) 155 120 { 156 121 //Italic … … 158 123 $replacements[] = '<i>\\1</i>'; 159 124 } 160 if ($conf _bbcode_bar['u'])125 if ($conf['bbcode_bar']['u']) 161 126 { 162 127 //Underline … … 164 129 $replacements[] = '<u>\\1</u>'; 165 130 } 166 if ($conf _bbcode_bar['s'])131 if ($conf['bbcode_bar']['s']) 167 132 { 168 133 //Strikethrough … … 170 135 $replacements[] = '<s>\\1</s>'; 171 136 } 172 if ($conf _bbcode_bar['center'])137 if ($conf['bbcode_bar']['center']) 173 138 { 174 139 //Center 175 140 $patterns[] = '#\[center\](.*?)\[/center\]#is'; 176 $replacements[] = '<div align="center"> <p>\\1</p></div>';177 } 178 if ($conf _bbcode_bar['right'])141 $replacements[] = '<div align="center">\\1</div>'; 142 } 143 if ($conf['bbcode_bar']['right']) 179 144 { 180 145 //Right 181 146 $patterns[] = '#\[right\](.*?)\[/right\]#is'; 182 $replacements[] = '<div align="right"> <p>\\1</p></div>';183 } 184 if ($conf _bbcode_bar['ol'])147 $replacements[] = '<div align="right">\\1</div>'; 148 } 149 if ($conf['bbcode_bar']['ol']) 185 150 { 186 151 //Olist … … 188 153 $replacements[] = '<ol>\\1</ol>'; 189 154 } 190 if ($conf _bbcode_bar['ul'])155 if ($conf['bbcode_bar']['ul']) 191 156 { 192 157 //Ulist … … 194 159 $replacements[] = '<ul>\\1</ul>'; 195 160 } 196 if ($conf _bbcode_bar['ol'] || $conf_bbcode_bar['ul'])161 if ($conf['bbcode_bar']['ol'] || $conf['bbcode_bar']['ul']) 197 162 { 198 163 //List … … 200 165 $replacements[] = '<li>\\1</li>'; 201 166 } 202 if ($conf _bbcode_bar['quote'])167 if ($conf['bbcode_bar']['quote']) 203 168 { 204 169 // Quotes … … 214 179 $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal"><b>\\1 : </b><br/>\\2</span></blockquote>'; 215 180 } 216 if ($conf _bbcode_bar['img'])181 if ($conf['bbcode_bar']['img']) 217 182 { 218 183 //Images … … 220 185 $replacements[] = '<img src="\\1" />'; 221 186 } 222 if ($conf _bbcode_bar['url'])187 if ($conf['bbcode_bar']['url']) 223 188 { 224 189 //[url]xxxx://www.zzzz.yyy[/url] … … 246 211 $replacements[] = '<a href="\\1" target="_blank">\\2</a>'; 247 212 } 248 if ($conf _bbcode_bar['email'])213 if ($conf['bbcode_bar']['email']) 249 214 { 250 215 //[email]samvure@gmail.com[/email] … … 252 217 $replacements[] = '<a href="mailto:\\1">\\1</a>'; 253 218 } 254 if ($conf _bbcode_bar['size'])219 if ($conf['bbcode_bar']['size']) 255 220 { 256 221 //Size … … 258 223 $replacements[] = '<span style="font-size: \\1px; line-height: normal">\\2</span>'; 259 224 } 260 if ($conf _bbcode_bar['color'])225 if ($conf['bbcode_bar']['color']) 261 226 { 262 227 //Colours … … 267 232 return preg_replace($patterns, $replacements, $str); 268 233 } 269 270 ?>
Note: See TracChangeset
for help on using the changeset viewer.