b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/_quicktags.plugin.php - 421 lines - 10434 bytes - Summary - Text - Print

Description: This file implements the Quicktags Toolbar plugin for b2evolution This is Ron's remix! Includes code from the WordPress team - http://sourceforge.net/project/memberlist.php?group_id=51422

   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-2014 by Francois Planque - {@link http://fplanque.com/}
  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 = '5.0.0';
  26      var $group = 'editor';
  27      var $number_of_installs = 1;
  28  
  29      /**
  30       * Init
  31       */
  32  	function PluginInit( & $params )
  33      {
  34          $this->short_desc = T_('Easy HTML tags inserting');
  35          $this->long_desc = T_('This plugin will display a toolbar with buttons to quickly insert HTML tags around selected text in a post.');
  36      }
  37  
  38  
  39      /**
  40       * Display a toolbar
  41       *
  42       * @todo dh> This seems to be a lot of Javascript. Please try exporting it in a
  43       *       (dynamically created) .js src file. Then we could use cache headers
  44       *       to let the browser cache it.
  45       * @param array Associative array of parameters
  46       * @return boolean did we display a toolbar?
  47       */
  48  	function AdminDisplayToolbar( & $params )
  49      {
  50          global $Hit, $Blog;
  51  
  52          if( !empty( $Blog ) )
  53          {
  54              if( !$Blog->get_setting( 'allow_html_post' ) )
  55              {    // Only when HTML is allowed in post
  56                  return false;
  57              }
  58          }
  59  
  60          $simple = ( $params['edit_layout'] == 'simple' || $params['edit_layout'] == 'inskin' );
  61  
  62          if( $Hit->is_lynx() )
  63          { // let's deactivate quicktags on Lynx, because they don't work there.
  64              return false;
  65          }
  66          ?>
  67  
  68          <script type="text/javascript">
  69          //<![CDATA[
  70          var b2evoButtons = new Array();
  71          var b2evoLinks = new Array();
  72          var b2evoOpenTags = new Array();
  73  
  74  		function b2evoButton(id, display, style, tagStart, tagEnd, access, tit, open)
  75          {
  76              this.id = id;                            // used to name the toolbar button
  77              this.display = display;        // label on button
  78              this.style = style;                // style on button
  79              this.tagStart = tagStart; // open tag
  80              this.tagEnd = tagEnd;            // close tag
  81              this.access = access;            // access key
  82              this.tit = tit;                        // title
  83              this.open = open;                    // set to -1 if tag does not need to be closed
  84          }
  85  
  86      <?php
  87      if( $simple )
  88      { ?>
  89          b2evoButtons[b2evoButtons.length] = new b2evoButton(
  90                  'b2evo_bold'
  91                  ,'bold', 'font-weight:bold;'
  92                  ,'<b>','</b>'
  93                  ,'b'
  94                  ,'<?php echo T_('Bold [Alt-B]') ?>'
  95              );
  96  
  97          b2evoButtons[b2evoButtons.length] = new b2evoButton(
  98                  'b2evo_italic'
  99                  ,'italic', 'font-style:italic;'
 100                  ,'<i>','</i>'
 101                  ,'i'
 102                  ,'<?php echo T_('Italic [Alt-I]') ?>'
 103              );
 104          <?php
 105      }
 106      else
 107      {
 108          ?>
 109          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 110                  'b2evo_ins'
 111                  ,'ins', ''
 112                  ,'<ins>','</ins>'
 113                  ,'b'
 114                  ,'<?php echo T_('INSerted') ?>'
 115              );
 116  
 117          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 118                  'b2evo_del'
 119                  ,'del', 'text-decoration:line-through;'
 120                  ,'<del>','</del>'
 121                  ,'i'
 122                  ,'<?php echo T_('DELeted') ?>'
 123              );
 124  
 125          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 126                  'b2evo_strong'
 127                  ,'str', 'font-weight:bold;'
 128                  ,'<strong>','</strong>'
 129                  ,'s'
 130                  ,'<?php echo T_('STRong [Alt-S]') ?>'
 131              );
 132  
 133          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 134                  'b2evo_em'
 135                  ,'em', 'font-style:italic;'
 136                  ,'<em>','</em>'
 137                  ,'e'
 138                  ,'<?php echo T_('EMphasis [Alt-E]') ?>'
 139              );
 140  
 141          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 142                  'b2evo_code'
 143                  ,'code', ''
 144                  ,'<code>','</code>'
 145                  ,'c'
 146                  ,'<?php echo T_('CODE [Alt-C]') ?>'
 147              );
 148  
 149          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 150                  'b2evo_par'
 151                  ,'p', 'margin-left:8px;'
 152                  ,'<p>','</p>'
 153                  ,'p'
 154                  ,'<?php echo T_('Paragraph [Alt-P]') ?>'
 155              );
 156  
 157          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 158                  'b2evo_block'
 159                  ,'block', ''
 160                  ,'<blockquote>','</blockquote>'
 161                  ,'b'
 162                  ,'<?php echo T_('BLOCKQUOTE [Alt-B]') ?>'
 163              );
 164  
 165          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 166                  'b2evo_pre'
 167                  ,'pre', ''
 168                  ,'<pre>','</pre>'
 169                  ,'r'
 170                  ,'<?php echo T_('PREformatted text [Alt-R]') ?>'
 171              );
 172  
 173          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 174                  'b2evo_ul'
 175                  ,'ul', ''
 176                  ,'<ul>\n','</ul>\n\n'
 177                  ,'u'
 178                  ,'<?php echo T_('Unordered List [Alt-U]') ?>'
 179              );
 180  
 181          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 182                  'b2evo_ol'
 183                  ,'ol', ''
 184                  ,'<ol>\n','</ol>\n\n'
 185                  ,'o'
 186                  ,'<?php echo T_('Ordered List [Alt-O]') ?>'
 187              );
 188  
 189          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 190                  'b2evo_li'
 191                  ,'li', ''
 192                  ,'  <li>','</li>\n'
 193                  ,'l'
 194                  ,'<?php echo T_('List Item [Alt-L]') ?>'
 195              );
 196  
 197          <?php
 198      }
 199      ?>
 200  
 201          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 202                  'b2evo_img'
 203                  ,'<?php echo ($simple ? 'image' : 'img') ?>', 'margin-left:8px;'
 204                  ,'',''
 205                  ,'g'
 206                  ,'<?php echo T_('IMaGe [Alt-G]') ?>'
 207                  ,-1
 208              ); // special case
 209  
 210          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 211                  'b2evo_link'
 212                  ,'link', 'text-decoration:underline;'
 213                  ,'','</a>'
 214                  ,'a'
 215                  ,'<?php echo T_('A href [Alt-A]') ?>'
 216              ); // special case
 217  
 218          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 219                  'b2evo_more'
 220                  ,'<?php echo ($simple ? 'more separator' : '!M') ?>', 'margin-left:8px;'
 221                  ,'<!-'+'-more-'+'->',''
 222                  ,'m'
 223                  ,'<?php echo T_('More [Alt-M]') ?>'
 224                  ,-1
 225              );
 226  
 227      <?php
 228          if( !$simple )
 229          { ?>
 230          b2evoButtons[b2evoButtons.length] = new b2evoButton(
 231                  'b2evo_next'
 232                  ,'!NP', ''
 233                  ,'<!-'+'-nextpage-'+'->',''
 234                  ,'q'
 235                  ,'<?php echo T_('next page [Alt-Q]') ?>'
 236                  ,-1
 237              );
 238              <?php
 239          }
 240      ?>
 241  
 242  		function b2evoShowButton(button, i)
 243          {
 244              if( button.id == 'b2evo_img' )
 245              {
 246                  document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit
 247                          + '" style="' + button.style + '" class="quicktags" onclick="b2evoInsertImage(b2evoCanvas);" value="' + button.display + '" />');
 248              }
 249              else if( button.id == 'b2evo_link' )
 250              {
 251                  document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit
 252                          + '" style="' + button.style + '" class="quicktags" onclick="b2evoInsertLink(b2evoCanvas, ' + i + ');" value="' + button.display + '" />');
 253              }
 254              else
 255              {    // Normal buttons:
 256                  document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit
 257                          + '" style="' + button.style + '" class="quicktags" onclick="b2evoInsertTag(b2evoCanvas, ' + i + ');" value="' + button.display + '"  />');
 258              }
 259          }
 260  
 261          // Memorize a new open tag
 262  		function b2evoAddTag(button)
 263          {
 264              if( b2evoButtons[button].tagEnd != '' )
 265              {
 266                  b2evoOpenTags[b2evoOpenTags.length] = button;
 267                  document.getElementById(b2evoButtons[button].id).value = '/' + document.getElementById(b2evoButtons[button].id).value;
 268              }
 269          }
 270  
 271          // Forget about an open tag
 272  		function b2evoRemoveTag(button)
 273          {
 274              for (i = 0; i < b2evoOpenTags.length; i++)
 275              {
 276                  if (b2evoOpenTags[i] == button)
 277                  {
 278                      b2evoOpenTags.splice(i, 1);
 279                      document.getElementById(b2evoButtons[button].id).value = document.getElementById(b2evoButtons[button].id).value.replace('/', '');
 280                  }
 281              }
 282          }
 283  
 284  		function b2evoCheckOpenTags(button)
 285          {
 286              var tag = 0;
 287              for (i = 0; i < b2evoOpenTags.length; i++)
 288              {
 289                  if (b2evoOpenTags[i] == button)
 290                  {
 291                      tag++;
 292                  }
 293              }
 294  
 295              if (tag > 0)
 296              {
 297                  return true; // tag found
 298              }
 299              else
 300              {
 301                  return false; // tag not found
 302              }
 303          }
 304  
 305  		function b2evoCloseAllTags()
 306          {
 307              var count = b2evoOpenTags.length;
 308              for (o = 0; o < count; o++)
 309              {
 310                  b2evoInsertTag(b2evoCanvas, b2evoOpenTags[b2evoOpenTags.length - 1]);
 311              }
 312          }
 313  
 314  		function b2evoToolbar()
 315          {
 316              document.write('<div>');
 317              for (var i = 0; i < b2evoButtons.length; i++)
 318              {
 319                  b2evoShowButton(b2evoButtons[i], i);
 320              }
 321              document.write('<input type="button" id="b2evo_close" class="quicktags" onclick="b2evoCloseAllTags();" title="<?php echo T_('Close all tags') ?>" value="<?php echo ($simple ? 'close all tags' : 'X') ?>" style="margin-left:8px;" />');
 322              document.write('</div>');
 323          }
 324  
 325          /**
 326           * insertion code
 327           */
 328  		function b2evoInsertTag( myField, i )
 329          {
 330              // we need to know if something is selected.
 331              // First, ask plugins, then try IE and Mozilla.
 332              var sel_text = b2evo_Callbacks.trigger_callback("get_selected_text_for_"+myField.id);
 333              var focus_when_finished = false; // used for IE
 334  
 335              if( sel_text == null )
 336              { // detect selection:
 337                  //IE support
 338                  if(document.selection)
 339                  {
 340                      myField.focus();
 341                      var sel = document.selection.createRange();
 342                      sel_text = sel.text;
 343                      focus_when_finished = true;
 344                  }
 345                  //MOZILLA/NETSCAPE support
 346                  else if(myField.selectionStart || myField.selectionStart == '0')
 347                  {
 348                      var startPos = myField.selectionStart;
 349                      var endPos = myField.selectionEnd;
 350                      sel_text = (startPos != endPos);
 351                  }
 352              }
 353  
 354              if( sel_text )
 355              { // some text selected
 356                  textarea_wrap_selection( myField, b2evoButtons[i].tagStart, b2evoButtons[i].tagEnd, 0 );
 357              }
 358              else
 359              {
 360                  if( !b2evoCheckOpenTags(i) || b2evoButtons[i].tagEnd == '')
 361                  {
 362                      textarea_wrap_selection( myField, b2evoButtons[i].tagStart, '', 0 );
 363                      b2evoAddTag(i);
 364                  }
 365                  else
 366                  {
 367                      textarea_wrap_selection( myField, '', b2evoButtons[i].tagEnd, 0 );
 368                      b2evoRemoveTag(i);
 369                  }
 370              }
 371              if(focus_when_finished)
 372              {
 373                  myField.focus();
 374              }
 375          }
 376  
 377  
 378  		function b2evoInsertLink(myField, i, defaultValue)
 379          {
 380              if (!defaultValue)
 381              {
 382                  defaultValue = 'http://';
 383              }
 384  
 385              if (!b2evoCheckOpenTags(i)) {
 386                  var URL = prompt( '<?php echo T_('URL') ?>:', defaultValue);
 387                  if (URL)
 388                  {
 389                      b2evoButtons[i].tagStart = '<a href="' + URL + '">';
 390                      b2evoInsertTag(myField, i);
 391                  }
 392              }
 393              else
 394              {
 395                  b2evoInsertTag( myField, i );
 396              }
 397          }
 398  
 399  		function b2evoInsertImage(myField)
 400          {
 401              var myValue = prompt( '<?php echo T_('URL') ?>:', 'http://' );
 402              if (myValue) {
 403                  myValue = '<img src="'
 404                          + myValue
 405                          + '" alt="' + prompt('<?php echo T_('ALTernate text') ?>:', '')
 406                          + '" title="' + prompt('<?php echo T_('Title') ?>:', '')
 407                          + '" />';
 408                  textarea_wrap_selection( myField, myValue, '', 1 );
 409              }
 410          }
 411          //]]>
 412          </script>
 413  
 414          <div class="edit_toolbar"><script type="text/javascript">b2evoToolbar();</script></div>
 415  
 416          <?php
 417          return true;
 418      }
 419  }
 420  
 421  ?>

title

Description

title

Description

title

Description

title

title

Body