b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/_bbcode.plugin.php - 712 lines - 20143 bytes - Summary - Text - Print

Description: This file implements the BBcode plugin for b2evolution BB style formatting, like [b]bold[/b]

   1  <?php
   2  /**
   3   * This file implements the BBcode plugin for b2evolution
   4   *
   5   * BB style formatting, like [b]bold[/b]
   6   *
   7   * b2evolution - {@link http://b2evolution.net/}
   8   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
   9   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
  10   *
  11   * @package plugins
  12   */
  13  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  14  
  15  
  16  /**
  17   * @package plugins
  18   */
  19  class bbcode_plugin extends Plugin
  20  {
  21      var $code = 'b2evBBco';
  22      var $name = 'BB code';
  23      var $priority = 50;
  24      var $version = '5.0.0';
  25      var $group = 'rendering';
  26      var $short_desc;
  27      var $long_desc;
  28      var $help_url = 'http://b2evolution.net/man/technical-reference/renderer-plugins/bb-code-plugin';
  29      var $number_of_installs = 1;
  30  
  31      /*
  32       * Internal
  33       */
  34      var $post_search_list;
  35      var $post_replace_list;
  36      var $comment_search_list;
  37      var $comment_replace_list;
  38  
  39  
  40      /**
  41       * Init
  42       */
  43  	function PluginInit( & $params )
  44      {
  45          $this->short_desc = T_('BB formatting e-g [b]bold[/b]');
  46          $this->long_desc = T_('Supported tags and the BB code toolbar are configurable.
  47          Supported tags by default are: [b] [i] [s] [color=...] [size=...] [font=...] [quote] [list=1] [list=a] [list] [*] [bg=]');
  48      }
  49  
  50  
  51      /**
  52       * Define here default collection/blog settings that are to be made available in the backoffice.
  53       *
  54       * @param array Associative array of parameters.
  55       * @return array See {@link Plugin::GetDefaultSettings()}.
  56       */
  57  	function get_coll_setting_definitions( & $params )
  58      {
  59          // TODO: Post and comment search/replace lists must be also converted to coll plugin settings
  60          $default_params = array_merge( $params, array( 'default_comment_rendering' => 'never' ) );
  61          return array_merge( parent::get_coll_setting_definitions( $default_params ),
  62              array(
  63                  'coll_post_search_list' => array(
  64                      'label' => $this->T_( 'Search list for posts'),
  65                      'note' => $this->T_( 'This is the BBcode search array for posts (one per line) ONLY CHANGE THESE IF YOU KNOW WHAT YOU\'RE DOING' ),
  66                      'type' => 'html_textarea',
  67                      'rows' => 10,
  68                      'cols' => 60,
  69                      'defaultvalue' => '[b] #\[b](.+?)\[/b]#is
  70  [i] #\[i](.+?)\[/i]#is
  71  [s] #\[s](.+?)\[/s]#is
  72  [color] !\[color=(#?[A-Za-z0-9]+?)](.+?)\[/color]!is
  73  [size] #\[size=([0-9]+?)](.+?)\[/size]#is
  74  [font] #\[font=([A-Za-z0-9 ;\-]+?)](.+?)\[/font]#is
  75   #\[quote(=?)](.+?)\[/quote]#is
  76   #\[quote=([^\]\#]*?)\#([cp][0-9]+)](.+?)\[/quote]#is
  77  [quote] #\[quote=([^\]]*?)](.+?)\[/quote]#is
  78  [list=1] #\[list=1](.+?)\[/list]#is
  79  [list=a] #\[list=a](.+?)\[/list]#is
  80  [list] #\[list](.+?)\[/list]#is
  81  [*] #\[\*](.+?)(\n|\[/list\])#is
  82  [bg] !\[bg=(#?[A-Za-z0-9]+?)](.+?)\[/bg]!is',
  83                  ),
  84                  'coll_post_replace_list' => array(
  85                      'label' => $this->T_( 'Replace list for posts'),
  86                      'note' => $this->T_( 'This is the replace array for posts (one per line) it must match the exact order of the search array' ),
  87                      'type' => 'html_textarea',
  88                      'rows' => 10,
  89                      'cols' => 60,
  90                      'defaultvalue' => '<strong>$1</strong>
  91  <em>$1</em>
  92  <span style="text-decoration:line-through">$1</span>
  93  <span style="color:$1">$2</span>
  94  <span style="font-size:$1px">$2</span>
  95  <span style="font-family:$1">$2</span>
  96  <blockquote>$2</blockquote>
  97  <strong class="quote_author">$1 wrote <a href="#$2">earlier</a>:</strong><blockquote>$3</blockquote>
  98  <strong class="quote_author">$1 wrote:</strong><blockquote>$2</blockquote>
  99  <ol type="1">$1</ol>
 100  <ol type="a">$1</ol>
 101  <ul>$1</ul>
 102  <li>$1</li>
 103  <span style="background-color:$1">$2</span>',
 104                  ),
 105                  'coll_comment_search_list' => array(
 106                      'label' => $this->T_( 'Search list for comments'),
 107                      'note' => $this->T_( 'This is the BBcode search array for COMMENTS (one per line) ONLY CHANGE THESE IF YOU KNOW WHAT YOU\'RE DOING' ),
 108                      'type' => 'html_textarea',
 109                      'rows' => 10,
 110                      'cols' => 60,
 111                      'defaultvalue' => '[b] #\[b](.+?)\[/b]#is
 112  [i] #\[i](.+?)\[/i]#is
 113  [s] #\[s](.+?)\[/s]#is
 114  [color] !\[color=(#?[A-Za-z0-9]+?)](.+?)\[/color]!is
 115  [size] #\[size=([0-9]+?)](.+?)\[/size]#is
 116  [font] #\[font=([A-Za-z0-9 ;\-]+?)](.+?)\[/font]#is
 117   #\[quote(=?)](.+?)\[/quote]#is
 118   #\[quote=([^\]\#]*?)\#([cp][0-9]+)](.+?)\[/quote]#is
 119  [quote] #\[quote=([^\]]*?)](.+?)\[/quote]#is
 120  [list=1] #\[list=1](.+?)\[/list]#is
 121  [list=a] #\[list=a](.+?)\[/list]#is
 122  [list] #\[list](.+?)\[/list]#is
 123  [*] #\[\*](.+?)(\n|\[/list\])#is
 124  [bg] !\[bg=(#?[A-Za-z0-9]+?)](.+?)\[/bg]!is',
 125                  ),
 126                  'coll_comment_replace_list' => array(
 127                      'label' => $this->T_( 'Replace list for comments'),
 128                      'note' => $this->T_( 'This is the replace array for COMMENTS (one per line) it must match the exact order of the search array' ),
 129                      'type' => 'html_textarea',
 130                      'rows' => 10,
 131                      'cols' => 60,
 132                      'defaultvalue' => '<strong>$1</strong>
 133  <em>$1</em>
 134  <span style="text-decoration:line-through">$1</span>
 135  <span style="color:$1">$2</span>
 136  <span style="font-size:$1px">$2</span>
 137  <span style="font-family:$1">$2</span>
 138  <blockquote>$2</blockquote>
 139  <strong class="quote_author">$1 wrote <a href="#$2">earlier</a>:</strong><blockquote>$3</blockquote>
 140  <strong class="quote_author">$1 wrote:</strong><blockquote>$2</blockquote>
 141  <ol type="1">$1</ol>
 142  <ol type="a">$1</ol>
 143  <ul>$1</ul>
 144  <li>$1</li>
 145  <span style="background-color:$1">$2</span>',
 146                  ),
 147              )
 148          );
 149      }
 150  
 151  
 152      /**
 153       * Perform rendering
 154       *
 155       * @see Plugin::RenderItemAsHtml()
 156       */
 157  	function RenderItemAsHtml( & $params )
 158      {
 159          $content = & $params['data'];
 160          $Item = $params['Item'];
 161          $item_Blog = & $Item->get_Blog();
 162          if( !isset( $this->post_search_list ) )
 163          {
 164              $this->post_search_list = $this->prepare_search_list( 'coll_post_search_list', $item_Blog );
 165          }
 166  
 167          if( !isset( $this->post_replace_list ) )
 168          {
 169              $this->post_replace_list = explode( "\n", str_replace( "\r", '', $this->get_coll_setting( 'coll_post_replace_list', $item_Blog ) ) );
 170          }
 171  
 172          $content = replace_content_outcode( $this->post_search_list, $this->post_replace_list, $content, array( $this, 'parse_bbcode' ) );
 173  
 174          return true;
 175      }
 176  
 177  
 178      /**
 179       * Parse BB code
 180       *   ( The main purpose of this function is to parsing multilevel lists tags,
 181       *     i.e. when one [list] is contained inside other [list] )
 182       *
 183       * @param string Content
 184       * @param array Search list
 185       * @param array Replace list
 186       * @return string Content
 187       */
 188  	function parse_bbcode( $content, $search_list, $replace_list )
 189      {
 190          if( empty( $content ) )
 191          { // No content, Exit here
 192              return $content;
 193          }
 194  
 195          $complex = array();
 196          $simple = array();
 197  
 198          foreach( $search_list as $i => $search_text )
 199          { // Split the masks to separate things
 200              preg_match( '#(\\\\\[.+\])\(.+\)(\\\\\[.+\])#is', $search_text, $search_tags );
 201              preg_match( '#(<.+>)\$.+(<.+>)#is', $replace_list[ $i ], $replace_tags );
 202              if( !empty( $search_tags ) )
 203              {
 204                  $complex[] = array(
 205                          's_full'  => $search_text,
 206                          's_start' => '!^'.$search_tags[1].'!is',
 207                          's_end'   => '!^'.$search_tags[2].'!is',
 208                          'r_full'  => $replace_list[ $i ],
 209                          'r_start' => $replace_tags[1],
 210                          'r_end'   => $replace_tags[2],
 211                      );
 212              }
 213              else
 214              {
 215                  $simple[] = array(
 216                          's_full' => $search_text,
 217                          'r_full' => $replace_list[ $i ],
 218                      );
 219              }
 220          }
 221          //pre_dump($complex);
 222  
 223          foreach( $simple as $tag_info )
 224          { // Make simple replacements
 225              $content = preg_replace( $tag_info['s_full'], $tag_info['r_full'], $content );
 226          }
 227  
 228          // Complex parsing with multilevel tags structure
 229          $c_pos = 0;
 230          $content_length = strlen( $content );
 231          $opened_tags = array();
 232          $new_content = $content;
 233          while( $c_pos < $content_length - 2 )
 234          {
 235              if( $content[ $c_pos ].$content[ $c_pos + 1 ] == '[/' )
 236              { // Closed tag
 237                  if( !empty( $opened_tags ) )
 238                  {    // Get closed tag that was opened as last
 239                      $sub_content = substr( $content, $c_pos );
 240                      $closed_tag_info = $complex[ $opened_tags[ count( $opened_tags ) - 1 ] ];
 241                      if( preg_match( $closed_tag_info['s_end'], $sub_content ) )
 242                      {
 243                          $first_part = str_replace( $sub_content, '', $new_content );
 244                          $sub_content = preg_replace( $closed_tag_info['s_end'], $closed_tag_info['r_end'], $sub_content );
 245                          $new_content = $first_part.$sub_content;
 246                          //pre_dump( 'CLOSE', $opened_tags, $closed_tag_info['r_end'], $closed_tag_info['s_end'], $new_content );
 247                          // Remove this tag from opened tags array
 248                          array_pop( $opened_tags );
 249                      }
 250                  }
 251              }
 252              elseif( $content[ $c_pos ] == '[' )
 253              { // Opened tag
 254                  $sub_content = substr( $content, $c_pos );
 255                  foreach( $complex as $tag_num => $tag_info )
 256                  {
 257                      if( preg_match( $tag_info['s_start'], $sub_content ) )
 258                      {
 259                          $first_part = str_replace( $sub_content, '', $new_content );
 260                          $sub_content = preg_replace( $tag_info['s_start'], $tag_info['r_start'], $sub_content );
 261                          $new_content = $first_part.$sub_content;
 262                          // Add this tag to know what tag was opened as last
 263                          $opened_tags[] = $tag_num;
 264                          //pre_dump( 'OPEN', $opened_tags, $tag_info['s_start'], $new_content );
 265                          break;
 266                      }
 267                  }
 268              }
 269              $c_pos++;
 270          }
 271          //pre_dump($new_content);
 272  
 273          $new_content = $this->parse_anchor_links( $new_content );
 274  
 275          return $new_content;
 276      }
 277  
 278  
 279      /**
 280       * Parse anchor links, Set absolute path for each link with relative anchor like <a href="#">
 281       *
 282       * @param string Content
 283       * @return string Content
 284       */
 285  	function parse_anchor_links( $content )
 286      {
 287          if( preg_match_all( '/ href="#(c|p)([0-9]+)"/i', $content, $matches ) )
 288          {
 289              $CommentCache = & get_CommentCache();
 290              $ItemCache = & get_ItemCache();
 291              foreach( $matches[0] as $m => $full_match )
 292              {
 293                  $object_ID = $matches[2][$m];
 294                  $new_url = '';
 295                  switch( $matches[1][$m] )
 296                  { // Object type:
 297                      case 'p':
 298                          // Item
 299                          if( $Item = & $ItemCache->get_by_ID( $object_ID, false, false ) )
 300                          { // Replace anchor url with item permanent url
 301                              $new_url = $Item->get_permanent_url().'#p'.$object_ID;
 302                          }
 303                          break;
 304  
 305                      case 'c':
 306                          // Comment
 307                          if( $Comment = & $CommentCache->get_by_ID( $object_ID, false, false ) )
 308                          { // Replace anchor url with comment permanent url
 309                              $new_url = $Comment->get_permanent_url();
 310                          }
 311                          break;
 312  
 313                      default:
 314                          // Incorrect object type, Skip this url
 315                          continue;
 316                  }
 317                  if( !empty( $new_url ) )
 318                  { // Replace relative anchor url with new absolute url
 319                      $content = str_replace( $full_match, ' href="'.$new_url.'"', $content );
 320                  }
 321              }
 322          }
 323  
 324          return $content;
 325      }
 326  
 327  
 328      /**
 329       * Do the same as for HTML.
 330       *
 331       * @see RenderItemAsHtml()
 332       */
 333  	function RenderItemAsXml( & $params )
 334      {
 335          $this->RenderItemAsHtml( $params );
 336      }
 337  
 338  
 339      /**
 340       *
 341       * Render comments if required
 342       *
 343       * @see Plugin::FilterCommentContent()
 344       */
 345  	function FilterCommentContent( & $params )
 346      {
 347          $Comment = & $params['Comment'];
 348          $comment_Item = & $Comment->get_Item();
 349          $item_Blog = & $comment_Item->get_Blog();
 350          if( in_array( $this->code, $Comment->get_renderers_validated() ) )
 351          { // apply_comment_rendering is set to always render
 352              $content = & $params['data'];
 353              if( !isset( $this->comment_search_list ) )
 354              {
 355                  $this->comment_search_list = $this->prepare_search_list( 'coll_comment_search_list', $item_Blog );
 356              }
 357  
 358              if( !isset( $this->comment_replace_list ) )
 359              {
 360                  $this->comment_replace_list = explode( "\n", str_replace( "\r", '', $this->get_coll_setting( 'coll_comment_replace_list', $item_Blog ) ) );
 361              }
 362  
 363              $content = replace_content_outcode( $this->comment_search_list, $this->comment_replace_list, $content, array( $this, 'parse_bbcode' ) );
 364          }
 365      }
 366  
 367  
 368      /**
 369       * Display a toolbar
 370       *
 371       * @param array Associative array of parameters
 372       * @return boolean did we display a toolbar?
 373       */
 374  	function AdminDisplayToolbar( & $params )
 375      {
 376          return $this->DisplayCodeToolbar( $params );
 377      }
 378  
 379  
 380      /**
 381       * Display a code toolbar
 382       *
 383       * @param array Associative array of parameters
 384       * @return boolean did we display a toolbar?
 385       */
 386  	function DisplayCodeToolbar( & $params )
 387      {
 388          global $Hit;
 389  
 390          if( $Hit->is_lynx() )
 391          { // let's deactivate quicktags on Lynx, because they don't work there.
 392              return false;
 393          }
 394  
 395          $params = array_merge( array(
 396                  'target_type' => 'Item'
 397              ), $params );
 398  
 399          switch( $params['target_type'] )
 400          {
 401              case 'Item':
 402                  $search_list_setting_name = 'coll_post_search_list';
 403                  $Item = $params['Item'];
 404                  $item_Blog = & $Item->get_Blog();
 405                  $apply_rendering = $this->get_coll_setting( 'coll_apply_rendering', $item_Blog );
 406                  break;
 407  
 408              case 'Comment':
 409                  $search_list_setting_name = 'coll_comment_search_list';
 410                  if( !empty( $params['Comment'] ) && !empty( $params['Comment']->item_ID ) )
 411                  {    // Get Blog from Comment
 412                      $Comment = & $params['Comment'];
 413                      $comment_Item = & $Comment->get_Item();
 414                      $item_Blog = & $comment_Item->get_Blog();
 415                  }
 416                  else if( !empty( $params['Item'] ) )
 417                  {    // Get Blog from Item
 418                      $comment_Item = & $params['Item'];
 419                      $item_Blog = & $comment_Item->get_Blog();
 420                  }
 421                  $apply_rendering = $this->get_coll_setting( 'coll_apply_comment_rendering', $item_Blog );
 422                  break;
 423  
 424              default:
 425                  // Incorrect param
 426                  return false;
 427                  break;
 428          }
 429  
 430          if( $apply_rendering == 'never' )
 431          {    // Don't display a toolbar if plugin is disabled
 432              return false;
 433          }
 434  
 435          $search_list = trim( $this->get_coll_setting( $search_list_setting_name, $item_Blog ) );
 436  
 437          if( empty( $search_list ) )
 438          {    // No list defined
 439              return false;
 440          }
 441  
 442          $search_list = explode( "\n", str_replace( array( '\r\n', '\n\n' ), '\n', $search_list ) );
 443  
 444          $bbButtons = array();
 445          foreach( $search_list as $line )
 446          {    // Init buttons from regexp lines
 447              $line = explode( ' ', $line, 2 );
 448              $button_name = $line[0];
 449              $button_exp = $line[1];
 450              if( !empty( $button_name ) && !empty( $button_exp ) )
 451              {
 452                  $start = preg_replace( '#(.+)\[([a-z0-1=\*\\\\]+)((\(.*\))*)\](.+)#is', '[$2]', $button_exp );
 453                  $end = preg_replace( '#(.+)\[\/(.+)\](.+)#is', '[/$2]', $button_exp );
 454                  $bbButtons[ $button_name ] = array(
 455                          'name'  => $button_name,
 456                          'start' => str_replace( '\\', '', $start ),
 457                          'end'   => $end == $button_exp ? '' : $end,
 458                          'title' => str_replace( array( '[', ']' ), '', $button_name ),
 459                      );
 460              }
 461          }
 462  
 463          if( empty( $bbButtons ) )
 464          {    // No buttons for toolbar
 465              return false;
 466          }
 467          ?>
 468  
 469          <script type="text/javascript">
 470          //<![CDATA[
 471          var bbButtons = new Array();
 472          var bbOpenTags = new Array();
 473  
 474  		function bbButton(id, display, style, tagStart, tagEnd, access, tit, open)
 475          {
 476              this.id = id;                            // used to name the toolbar button
 477              this.display = display;        // label on button
 478              this.style = style;                // style on button
 479              this.tagStart = tagStart; // open tag
 480              this.tagEnd = tagEnd;            // close tag
 481              this.access = access;            // access key
 482              this.tit = tit;                        // title
 483              this.open = open;                    // set to -1 if tag does not need to be closed
 484          }
 485  
 486          <?php
 487          foreach( $bbButtons as $bbButton )
 488          {    // Init each button
 489          ?>
 490          bbButtons[bbButtons.length] = new bbButton(
 491                  'bb_<?php echo $bbButton['title']; ?>'
 492                  ,'<?php echo $bbButton['name']; ?>', ''
 493                  ,'<?php echo $bbButton['start']; ?>', '<?php echo $bbButton['end']; ?>', ''
 494                  ,'<?php echo $bbButton['title']; ?>'
 495              );
 496          <?php
 497          }
 498          ?>
 499  
 500  		function bbGetButton(button, i)
 501          {
 502              return '<input type="button" id="' + button.id + '" accesskey="' + button.access + '" title="' + button.tit
 503                      + '" style="' + button.style + '" class="quicktags" onclick="bbInsertTag(b2evoCanvas, ' + i + ');" value="' + button.display + '" />';
 504          }
 505  
 506          // Memorize a new open tag
 507  		function bbAddTag(button)
 508          {
 509              if( bbButtons[button].tagEnd != '' )
 510              {
 511                  bbOpenTags[bbOpenTags.length] = button;
 512                  document.getElementById(bbButtons[button].id).style.fontWeight = 'bold';
 513              }
 514          }
 515  
 516          // Forget about an open tag
 517  		function bbRemoveTag(button)
 518          {
 519              for (i = 0; i < bbOpenTags.length; i++)
 520              {
 521                  if (bbOpenTags[i] == button)
 522                  {
 523                      bbOpenTags.splice(i, 1);
 524                      document.getElementById(bbButtons[button].id).style.fontWeight = 'normal';
 525                  }
 526              }
 527          }
 528  
 529  		function bbCheckOpenTags(button)
 530          {
 531              var tag = 0;
 532              for (i = 0; i < bbOpenTags.length; i++)
 533              {
 534                  if (bbOpenTags[i] == button)
 535                  {
 536                      tag++;
 537                  }
 538              }
 539  
 540              if (tag > 0)
 541              {
 542                  return true; // tag found
 543              }
 544              else
 545              {
 546                  return false; // tag not found
 547              }
 548          }
 549  
 550  		function bbCloseAllTags()
 551          {
 552              var count = bbOpenTags.length;
 553              for (o = 0; o < count; o++)
 554              {
 555                  bbInsertTag(b2evoCanvas, bbOpenTags[bbOpenTags.length - 1]);
 556              }
 557          }
 558  
 559  		function bbToolbar()
 560          {
 561              var bbcode_toolbar = '<div><?php echo T_('BB code:'); ?> ';
 562              for( var i = 0; i < bbButtons.length; i++ )
 563              {
 564                  bbcode_toolbar += bbGetButton( bbButtons[i], i );
 565              }
 566              bbcode_toolbar += '<input type="button" id="bb_close" class="quicktags" onclick="bbCloseAllTags();" title="<?php echo T_('Close all tags') ?>" value="close all tags" style="margin-left:8px;" />'
 567              bbcode_toolbar += '</div>';
 568              jQuery( '#bbcode_toolbar' ).html( bbcode_toolbar );
 569          }
 570  
 571          /**
 572           * insertion code
 573           */
 574  		function bbInsertTag( myField, i )
 575          {
 576              // we need to know if something is selected.
 577              // First, ask plugins, then try IE and Mozilla.
 578              var sel_text = b2evo_Callbacks.trigger_callback("get_selected_text_for_"+myField.id);
 579              var focus_when_finished = false; // used for IE
 580  
 581              if( sel_text == null )
 582              { // detect selection:
 583                  //IE support
 584                  if(document.selection)
 585                  {
 586                      myField.focus();
 587                      var sel = document.selection.createRange();
 588                      sel_text = sel.text;
 589                      focus_when_finished = true;
 590                  }
 591                  //MOZILLA/NETSCAPE support
 592                  else if(myField.selectionStart || myField.selectionStart == '0')
 593                  {
 594                      var startPos = myField.selectionStart;
 595                      var endPos = myField.selectionEnd;
 596                      sel_text = (startPos != endPos);
 597                  }
 598              }
 599  
 600              if( sel_text )
 601              { // some text selected
 602                  textarea_wrap_selection( myField, bbButtons[i].tagStart, bbButtons[i].tagEnd, 0 );
 603              }
 604              else
 605              {
 606                  if( !bbCheckOpenTags(i) || bbButtons[i].tagEnd == '')
 607                  {
 608                      textarea_wrap_selection( myField, bbButtons[i].tagStart, '', 0 );
 609                      bbAddTag(i);
 610                  }
 611                  else
 612                  {
 613                      textarea_wrap_selection( myField, '', bbButtons[i].tagEnd, 0 );
 614                      bbRemoveTag(i);
 615                  }
 616              }
 617              if(focus_when_finished)
 618              {
 619                  myField.focus();
 620              }
 621          }
 622          //]]>
 623          </script>
 624  
 625          <div id="bbcode_toolbar" class="edit_toolbar"><script type="text/javascript">bbToolbar();</script></div>
 626  
 627          <?php
 628          return true;
 629      }
 630  
 631  
 632      /**
 633       * Event handler: Called when displaying editor toolbars.
 634       *
 635       * @param array Associative array of parameters
 636       * @return boolean did we display a toolbar?
 637       */
 638  	function DisplayCommentToolbar( & $params )
 639      {
 640          if( !empty( $params['Comment'] ) )
 641          { // Comment is set, get Blog from comment
 642              $Comment = & $params['Comment'];
 643              if( !empty( $Comment->item_ID ) )
 644              {
 645                  $comment_Item = & $Comment->get_Item();
 646                  $Blog = & $comment_Item->get_Blog();
 647              }
 648          }
 649  
 650          if( !empty( $params['Item'] ) )
 651          {    // Get Blog from Item
 652              $comment_Item = & $params['Item'];
 653              $Blog = & $comment_Item->get_Blog();
 654          }
 655  
 656          if( empty( $Blog ) )
 657          { // Comment is not set, try global Blog
 658              global $Blog;
 659              if( empty( $Blog ) )
 660              { // We can't get a Blog, this way "apply_comment_rendering" plugin collection setting is not available
 661                  return false;
 662              }
 663          }
 664  
 665          if( $this->get_coll_setting( 'coll_apply_comment_rendering', $Blog ) )
 666          {
 667              $params['target_type'] = 'Comment';
 668              return $this->DisplayCodeToolbar( $params );
 669          }
 670          return false;
 671      }
 672  
 673  
 674      /**
 675       * Prepare a search list
 676       *
 677       * @param string Setting name of search list (' post_search_list', 'comment_search_list' )
 678       * @param object Blog
 679       * @return array Search list
 680       */
 681  	function prepare_search_list( $setting_name, $Blog )
 682      {
 683          $search_list = explode( "\n", str_replace( "\r", '', $this->get_coll_setting( $setting_name, $Blog ) ) );
 684  
 685          foreach( $search_list as $l => $line )
 686          {    // Remove button name from regexp string
 687              $line = explode( ' ', $line, 2 );
 688              $regexp = $line[1];
 689              if( empty( $regexp ) )
 690              {    // Bad format of search string
 691                  unset( $search_list[ $l ] );
 692              }
 693              else
 694              {    // Replace this line with regexp value (to delete a button name)
 695                  $search_list[ $l ] = $regexp;
 696              }
 697          }
 698  
 699          return $search_list;
 700      }
 701  
 702  
 703      /**
 704       * @see Plugin::SkinBeginHtmlHead()
 705       */
 706  	function SkinBeginHtmlHead()
 707      {
 708          require_js( 'functions.js', 'blog' );
 709      }
 710  }
 711  
 712  ?>

title

Description

title

Description

title

Description

title

title

Body