[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the Quicktags Toolbar plugin for b2evolution 4 * 5 * This is Ron's remix! 6 * Includes code from the WordPress team - 7 * http://sourceforge.net/project/memberlist.php?group_id=51422 8 * 9 * b2evolution - {@link http://b2evolution.net/} 10 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html} 11 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 12 * 13 * @package plugins 14 */ 15 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 16 17 /** 18 * @package plugins 19 */ 20 class quicktags_plugin extends Plugin 21 { 22 var $code = 'b2evQTag'; 23 var $name = 'Quick Tags'; 24 var $priority = 30; 25 var $version = '1.10'; 26 var $number_of_installs = 1; 27 28 /** 29 * Init 30 */ 31 function PluginInit( & $params ) 32 { 33 $this->short_desc = T_('Easy HTML tags inserting'); 34 $this->long_desc = T_('This plugin will display a toolbar with buttons to quickly insert HTML tags around selected text in a post.'); 35 } 36 37 38 /** 39 * Display a toolbar 40 * 41 * @todo dh> This seems to be a lot of Javascript. Please try exporting it in a 42 * (dynamically created) .js src file. Then we could use cache headers 43 * to let the browser cache it. 44 * @param array Associative array of parameters 45 * @return boolean did we display a toolbar? 46 */ 47 function AdminDisplayToolbar( & $params ) 48 { 49 global $Hit; 50 51 if( $params['edit_layout'] == 'simple' ) 52 { // This is too complex for simple mode, don't display it: 53 return false; 54 } 55 56 if( $Hit->is_lynx ) 57 { // let's deactivate quicktags on Lynx, because they don't work there. 58 return false; 59 } 60 ?> 61 62 <script type="text/javascript"> 63 //<![CDATA[ 64 var b2evoButtons = new Array(); 65 var b2evoLinks = new Array(); 66 var b2evoOpenTags = new Array(); 67 68 function b2evoButton(id, display, style, tagStart, tagEnd, access, tit, open) 69 { 70 this.id = id; // used to name the toolbar button 71 this.display = display; // label on button 72 this.style = style; // style on button 73 this.tagStart = tagStart; // open tag 74 this.tagEnd = tagEnd; // close tag 75 this.access = access; // access key 76 this.tit = tit; // title 77 this.open = open; // set to -1 if tag does not need to be closed 78 } 79 80 b2evoButtons[b2evoButtons.length] = new b2evoButton( 81 'b2evo_ins' 82 ,'ins', '' 83 ,'<ins>','</ins>' 84 ,'' 85 ,'<?php echo T_('INSerted') ?>' 86 ); 87 88 b2evoButtons[b2evoButtons.length] = new b2evoButton( 89 'b2evo_del' 90 ,'del', 'text-decoration:line-through;' 91 ,'<del>','</del>' 92 ,'' 93 ,'<?php echo T_('DELeted') ?>' 94 ); 95 96 /* 97 b2evoButtons[b2evoButtons.length] = new b2evoButton( 98 'b2evo_bold' 99 ,'b', 'font-weight:bold;' 100 ,'<b>','</b>' 101 ,'b' 102 ,'<?php echo T_('Bold [Alt-B]') ?>' 103 ); 104 105 b2evoButtons[b2evoButtons.length] = new b2evoButton( 106 'b2evo_italic' 107 ,'i', 'font-style:italic;' 108 ,'<i>','</i>' 109 ,'i' 110 ,'<?php echo T_('Italic [Alt-I]') ?>' 111 ); 112 */ 113 114 b2evoButtons[b2evoButtons.length] = new b2evoButton( 115 'b2evo_strong' 116 ,'str', 'font-weight:bold;' 117 ,'<strong>','</strong>' 118 ,'s' 119 ,'<?php echo T_('STRong [Alt-S]') ?>' 120 ); 121 122 b2evoButtons[b2evoButtons.length] = new b2evoButton( 123 'b2evo_em' 124 ,'em', 'font-style:italic;' 125 ,'<em>','</em>' 126 ,'e' 127 ,'<?php echo T_('EMphasis [Alt-E]') ?>' 128 ); 129 130 b2evoButtons[b2evoButtons.length] = new b2evoButton( 131 'b2evo_code' 132 ,'code', '' 133 ,'<code>','</code>' 134 ,'c' 135 ,'<?php echo T_('CODE [Alt-C]') ?>' 136 ); 137 138 b2evoButtons[b2evoButtons.length] = new b2evoButton( 139 'b2evo_par' 140 ,'p', 'margin-left:8px;' 141 ,'<p>','</p>' 142 ,'p' 143 ,'<?php echo T_('Paragraph [Alt-P]') ?>' 144 ); 145 146 b2evoButtons[b2evoButtons.length] = new b2evoButton( 147 'b2evo_block' 148 ,'block', '' 149 ,'<blockquote>','</blockquote>' 150 ,'b' 151 ,'<?php echo T_('BLOCKQUOTE [Alt-B]') ?>' 152 ); 153 154 b2evoButtons[b2evoButtons.length] = new b2evoButton( 155 'b2evo_pre' 156 ,'pre', '' 157 ,'<pre>','</pre>' 158 ,'r' 159 ,'<?php echo T_('PREformatted text [Alt-R]') ?>' 160 ); 161 162 b2evoButtons[b2evoButtons.length] = new b2evoButton( 163 'b2evo_ul' 164 ,'ul', '' 165 ,'<ul>\n','</ul>\n\n' 166 ,'u' 167 ,'<?php echo T_('Unordered List [Alt-U]') ?>' 168 ); 169 170 b2evoButtons[b2evoButtons.length] = new b2evoButton( 171 'b2evo_ol' 172 ,'ol', '' 173 ,'<ol>\n','</ol>\n\n' 174 ,'o' 175 ,'<?php echo T_('Ordered List [Alt-O]') ?>' 176 ); 177 178 b2evoButtons[b2evoButtons.length] = new b2evoButton( 179 'b2evo_li' 180 ,'li', '' 181 ,' <li>','</li>\n' 182 ,'l' 183 ,'<?php echo T_('List Item [Alt-L]') ?>' 184 ); 185 186 b2evoButtons[b2evoButtons.length] = new b2evoButton( 187 'b2evo_img' 188 ,'img', 'margin-left:8px;' 189 ,'','' 190 ,'g' 191 ,'<?php echo T_('IMaGe [Alt-G]') ?>' 192 ,-1 193 ); // special case 194 195 b2evoButtons[b2evoButtons.length] = new b2evoButton( 196 'b2evo_link' 197 ,'link', 'text-decoration:underline;' 198 ,'','</a>' 199 ,'a' 200 ,'<?php echo T_('A href [Alt-A]') ?>' 201 ); // special case 202 203 b2evoButtons[b2evoButtons.length] = new b2evoButton( 204 'b2evo_more' 205 ,'!M', 'margin-left:8px;' 206 ,'<!-'+'-more-'+'->','' 207 ,'m' 208 ,'<?php echo T_('More [Alt-M]') ?>' 209 ,-1 210 ); 211 212 b2evoButtons[b2evoButtons.length] = new b2evoButton( 213 'b2evo_noteaser' 214 ,'!NT', '' 215 ,'<!-'+'-noteaser-'+'->','' 216 ,'t' 217 ,'<?php echo T_('no teaser [Alt-T]') ?>' 218 ,-1 219 ); 220 221 b2evoButtons[b2evoButtons.length] = new b2evoButton( 222 'b2evo_next' 223 ,'!NP', 'margin-right:8px;' 224 ,'<!-'+'-nextpage-'+'->','' 225 ,'q' 226 ,'<?php echo T_('next page [Alt-Q]') ?>' 227 ,-1 228 ); 229 230 function b2evoShowButton(button, i) 231 { 232 if( button.id == 'b2evo_img' ) 233 { 234 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit 235 + '" style="' + button.style + '" class="quicktags" onclick="b2evoInsertImage(b2evoCanvas);" value="' + button.display + '" />'); 236 } 237 else if( button.id == 'b2evo_link' ) 238 { 239 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit 240 + '" style="' + button.style + '" class="quicktags" onclick="b2evoInsertLink(b2evoCanvas, ' + i + ');" value="' + button.display + '" />'); 241 } 242 else 243 { // Normal buttons: 244 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit 245 + '" style="' + button.style + '" class="quicktags" onclick="b2evoInsertTag(b2evoCanvas, ' + i + ');" value="' + button.display + '" />'); 246 } 247 } 248 249 // Memorize a new open tag 250 function b2evoAddTag(button) 251 { 252 if( b2evoButtons[button].tagEnd != '' ) 253 { 254 b2evoOpenTags[b2evoOpenTags.length] = button; 255 document.getElementById(b2evoButtons[button].id).value = '/' + document.getElementById(b2evoButtons[button].id).value; 256 } 257 } 258 259 // Forget about an open tag 260 function b2evoRemoveTag(button) 261 { 262 for (i = 0; i < b2evoOpenTags.length; i++) 263 { 264 if (b2evoOpenTags[i] == button) 265 { 266 b2evoOpenTags.splice(i, 1); 267 document.getElementById(b2evoButtons[button].id).value = document.getElementById(b2evoButtons[button].id).value.replace('/', ''); 268 } 269 } 270 } 271 272 function b2evoCheckOpenTags(button) 273 { 274 var tag = 0; 275 for (i = 0; i < b2evoOpenTags.length; i++) 276 { 277 if (b2evoOpenTags[i] == button) 278 { 279 tag++; 280 } 281 } 282 283 if (tag > 0) 284 { 285 return true; // tag found 286 } 287 else 288 { 289 return false; // tag not found 290 } 291 } 292 293 function b2evoCloseAllTags() 294 { 295 var count = b2evoOpenTags.length; 296 for (o = 0; o < count; o++) 297 { 298 b2evoInsertTag(b2evoCanvas, b2evoOpenTags[b2evoOpenTags.length - 1]); 299 } 300 } 301 302 function b2evoToolbar() 303 { 304 document.write('<div>'); 305 for (var i = 0; i < b2evoButtons.length; i++) 306 { 307 b2evoShowButton(b2evoButtons[i], i); 308 } 309 document.write('<input type="button" id="b2evo_close" class="quicktags" onclick="b2evoCloseAllTags();" title="<?php echo T_('Close all tags') ?>" value="X" />'); 310 document.write('</div>'); 311 } 312 313 /** 314 * insertion code 315 */ 316 function b2evoInsertTag( myField, i ) 317 { 318 // we need to know if something is selected. 319 // First, ask plugins, then try IE and Mozilla. 320 var sel_text = b2evo_Callbacks.trigger_callback("get_selected_text_for_"+myField.id); 321 var focus_when_finished = false; // used for IE 322 323 if( sel_text == null ) 324 { // detect selection: 325 //IE support 326 if(document.selection) 327 { 328 myField.focus(); 329 var sel = document.selection.createRange(); 330 sel_text = sel.text; 331 focus_when_finished = true; 332 } 333 //MOZILLA/NETSCAPE support 334 else if(myField.selectionStart || myField.selectionStart == '0') 335 { 336 var startPos = myField.selectionStart; 337 var endPos = myField.selectionEnd; 338 sel_text = (startPos != endPos); 339 } 340 } 341 342 if( sel_text ) 343 { // some text selected 344 textarea_wrap_selection( myField, b2evoButtons[i].tagStart, b2evoButtons[i].tagEnd, 0 ); 345 } 346 else 347 { 348 if( !b2evoCheckOpenTags(i) || b2evoButtons[i].tagEnd == '') 349 { 350 textarea_wrap_selection( myField, b2evoButtons[i].tagStart, '', 0 ); 351 b2evoAddTag(i); 352 } 353 else 354 { 355 textarea_wrap_selection( myField, '', b2evoButtons[i].tagEnd, 0 ); 356 b2evoRemoveTag(i); 357 } 358 } 359 if(focus_when_finished) 360 { 361 myField.focus(); 362 } 363 } 364 365 366 function b2evoInsertLink(myField, i, defaultValue) 367 { 368 if (!defaultValue) 369 { 370 defaultValue = 'http://'; 371 } 372 373 if (!b2evoCheckOpenTags(i)) { 374 var URL = prompt( '<?php echo T_('URL') ?>:', defaultValue); 375 if (URL) 376 { 377 b2evoButtons[i].tagStart = '<a href="' + URL + '">'; 378 b2evoInsertTag(myField, i); 379 } 380 } 381 else 382 { 383 b2evoInsertTag( myField, i ); 384 } 385 } 386 387 function b2evoInsertImage(myField) 388 { 389 var myValue = prompt( '<?php echo T_('URL') ?>:', 'http://' ); 390 if (myValue) { 391 myValue = '<img src="' 392 + myValue 393 + '" alt="' + prompt('<?php echo T_('ALTernate text') ?>:', '') 394 + '" title="' + prompt('<?php echo T_('Title') ?>:', '') 395 + '" />'; 396 textarea_wrap_selection( myField, myValue, '', 1 ); 397 } 398 } 399 //]]> 400 </script> 401 402 <div class="edit_toolbar"><script type="text/javascript">b2evoToolbar();</script></div> 403 404 <?php 405 return true; 406 } 407 } 408 409 /* 410 * $Log: _quicktags.plugin.php,v $ 411 * Revision 1.30 2007/09/17 20:04:40 fplanque 412 * UI improvements 413 * 414 * Revision 1.29 2007/09/03 16:46:58 fplanque 415 * minor 416 * 417 * Revision 1.28 2007/06/29 23:12:18 blueyed 418 * todo 419 * 420 * Revision 1.27 2007/06/29 23:10:01 blueyed 421 * - Cleaned up code duplication in b2evoInsertTag() 422 * - Added get_selected_text_for_ID-JS callback 423 * 424 * Revision 1.26 2007/04/26 00:11:04 fplanque 425 * (c) 2007 426 * 427 * Revision 1.25 2007/04/20 01:42:32 fplanque 428 * removed excess javascript 429 * 430 * Revision 1.24 2006/09/23 15:06:03 blueyed 431 * Javascript fixes: use CDATA 432 * 433 * Revision 1.23 2006/07/16 23:04:05 fplanque 434 * Most plugins should keep as quiet as possible in simple mode. 435 * Smilies are about the only thing simple enough for simple mode. 436 * 437 * Revision 1.22 2006/07/12 21:13:17 blueyed 438 * Javascript callback handler (e.g., for interaction of WYSIWYG editors with toolbar plugins) 439 * 440 * Revision 1.21 2006/07/10 20:19:30 blueyed 441 * Fixed PluginInit behaviour. It now gets called on both installed and non-installed Plugins, but with the "is_installed" param appropriately set. 442 * 443 * Revision 1.20 2006/07/07 21:26:49 blueyed 444 * Bumped to 1.9-dev 445 * 446 * Revision 1.19 2006/07/06 19:56:29 fplanque 447 * no message 448 * 449 * Revision 1.18 2006/06/26 23:10:24 fplanque 450 * minor / doc 451 * 452 * Revision 1.17 2006/06/24 05:19:39 smpdawg 453 * Fixed various javascript warnings and errors. 454 * Spelling corrections. 455 * Fixed PHP warnings. 456 * 457 * Revision 1.16 2006/06/16 21:30:57 fplanque 458 * Started clean numbering of plugin versions (feel free do add dots...) 459 * 460 * Revision 1.15 2006/05/30 20:31:18 blueyed 461 * typo 462 * 463 * Revision 1.14 2006/05/30 19:39:55 fplanque 464 * plugin cleanup 465 * 466 * Revision 1.13 2006/03/12 23:09:28 fplanque 467 * doc cleanup 468 * 469 * Revision 1.12 2005/12/22 23:13:40 blueyed 470 * Plugins' API changed and handling optimized 471 * 472 * Revision 1.11 2005/11/21 18:16:29 fplanque 473 * okay, a TWO liner :P 474 * 475 */ 476 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |