[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/plugins/ -> _auto_p.plugin.php (source)

   1  <?php
   2  /**

   3   * This file implements the Auto P plugin for b2evolution

   4   *

   5   * @author blueyed: Daniel HAHLER - {@link http://daniel.hahler.de/}

   6   *

   7   * @package plugins

   8   */
   9  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  10  
  11  
  12  /**

  13   * The Auto-P Plugin.

  14   *

  15   * It wraps text blocks, which are devided by newline(s) into HTML P tags (paragraphs)

  16   * and optionally replaces single newlines with BR tags (line breaks).

  17   *

  18   * @package plugins

  19   */
  20  class auto_p_plugin extends Plugin
  21  {
  22      var $code = 'b2WPAutP';
  23      var $name = 'Auto P';
  24      var $priority = 70;
  25      var $version = '1.9';
  26      var $apply_rendering = 'opt-out';
  27      var $group = 'rendering';
  28      var $short_desc;
  29      var $long_desc;
  30      var $number_of_installs = 1;
  31  
  32      /**

  33       * List of block elements (we want a paragraph before and after), excludes: address, added: td, th

  34       * @var string

  35       */
  36      var $block_tags = 'blockquote|dd|div|dl|dt|fieldset|form|h[1-6]|hr|li|ol|p|pre|select|script|table|td|th|ul';
  37  
  38  
  39      var $p_allowed_in = array('address', 'applet', 'blockquote', 'body', 'button', 'center', 'dd', 'del', 'div', 'fieldset', 'form', 'iframe', 'ins', 'li', 'map', 'noframes', 'noscript', 'object', 'td', 'th' );
  40  
  41  
  42      var $br_allowed_in = array(
  43          // Block level:

  44          'address', 'center', 'dl', 'dir', 'div', 'fieldset', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'isindex', 'menu', 'noframes', 'noscript', 'p', 'pre',
  45          // Inline:

  46          'a', 'abbr', 'acronym', 'applet', 'b', 'basefont', 'bdo', 'big', 'button', 'cite', 'code', 'dfn', 'em', 'font', 'i', 'img', 'input', 'iframe', 'kbd', 'label', 'li', 'map', 'object', 'q', 'samp', 'select', 'small', 'span', 'strong', 'sub', 'sup', 'textarea', 'td', 'th', 'tt', 'var' );
  47  
  48  
  49      /**

  50       * Init

  51       */
  52  	function PluginInit( & $params )
  53      {
  54          $this->short_desc = T_('Automatic &lt;P&gt; and &lt;BR&gt; tags');
  55          $this->long_desc = T_('This renderer will automatically detect paragraphs on double line-breaks. and mark them with appropriate HTML &lt;P&gt; tags.<br />
  56              Optionally, it will also mark single line breaks with HTML &lt;BR&gt; tags.');
  57      }
  58  
  59  
  60      /**

  61       * @return array

  62       */
  63  	function GetDefaultSettings()
  64      {
  65          return array(
  66                  'br' => array(
  67                      'label' => T_('Line breaks'),
  68                      'type' => 'checkbox',
  69                      'defaultvalue' => 1,
  70                      'note' => T_('Make line breaks (&lt;br /&gt;) for single newlines.'),
  71                  ),
  72                  'add_p_in_block' => array(
  73                      'label' => T_('Add P tags in blocks (e.g. DIV)'),
  74                      'type' => 'checkbox',
  75                      'defaultvalue' => 1,
  76                      'note' => '',
  77                  ),
  78                  'skip_tags' => array(
  79                      'label' => T_('Ignore tags'),
  80                      'type' => 'text',
  81                      'defaultvalue' => 'pre',
  82                      'note' => T_('A list of tags, in which no P or BR tags should get added.'),
  83                  ),
  84              );
  85      }
  86  
  87  
  88      /**

  89       * Perform rendering

  90       */
  91  	function RenderItemAsHtml( & $params )
  92      {
  93          #echo '<hr style="border:1em solid blue;" />';

  94  
  95          $this->use_auto_br = $this->Settings->get('br');
  96          $this->add_p_in_block = $this->Settings->get('add_p_in_block');
  97          $this->skip_tags = preg_split( '~\s+~', $this->Settings->get('skip_tags'), -1, PREG_SPLIT_NO_EMPTY );
  98  
  99          $content = & $params['data'];
 100  
 101          $content = preg_replace( "~(\r\n|\r)~", "\n", $content ); // cross-platform newlines

 102  
 103          // Handle blocks, splitted by comments. This includes especially the "meta-comments"

 104          // ("<!--more-->", "<!--nextpage-->" or "<!--noteaser-->"):

 105          $content_parts = preg_split( '~(<!--.*?-->)~s', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
 106          $content_parts[] = '';
 107  
 108          $content = '';
 109          for( $i = 0; $i < count($content_parts); $i = $i+2 )
 110          {
 111              $content .= $this->handle_blocks( $content_parts[$i] );
 112              $content .= $content_parts[$i+1];
 113          }
 114  
 115          return true;
 116      }
 117  
 118  
 119      /**

 120       * - Split text into blocks, using $block_tags pattern.

 121       *

 122       * @param string Text

 123       * @param string The HTML tag where $text is in

 124       * @return string

 125       */
 126  	function handle_blocks( $text, $in_tag = '' )
 127      {
 128          #echo '<h1>HANDLE_BLOCKS</h1>'; pre_dump( $text, $in_tag );

 129  
 130          $new_text = '';
 131  
 132          if( preg_match( '~^(.*?)(<\s*('.$this->block_tags.')(\b[^>]*)?>)~is', $text, $match ) )
 133          { // there's a block tag:
 134              $tag = $match[3];
 135              $before_tag = $match[1];
 136  
 137              if( ! empty($before_tag) )
 138              { // Recurse (one pattern/callback deeper):
 139                  $new_text .= $this->handle_pre_blocks( $before_tag, $in_tag );
 140              }
 141  
 142              $text_after_tag = substr( $text, strlen($match[0]) );
 143  
 144  
 145              if( empty($match[4]) || strpos($match[4], '/') === false )
 146              { // No self-closing tag: handle text in tag:
 147                  // Opening tag:

 148                  $new_text .= $match[2];
 149  
 150                  // Find closing tag:

 151                  list( $text_in_tag, $closing_tag, $NL_before, $NL_after ) = $this->split_text_for_tag($tag, $text_after_tag);
 152  
 153                  if( ! empty($text_in_tag) )
 154                  { // Recurse (same level):
 155                      $text_in_tag = $this->handle_blocks( $text_in_tag, $tag );
 156                  }
 157  
 158                  $new_text .= $NL_before.$text_in_tag.$NL_after;
 159  
 160                  $new_text .= $closing_tag;
 161              }
 162              else
 163              { // self-closing tag:
 164                  $new_text .= $match[2];
 165              }
 166  
 167              if( ! empty($text_after_tag) )
 168              {
 169                  #echo '<h1>RECURSE: text_after_tag (block)</h1>';

 170                  // Recurse (same level):

 171                  $new_text .= $this->handle_blocks( $text_after_tag, $in_tag );
 172              }
 173          }
 174          else
 175          { // No BLOCKS in this $text:
 176              $new_text = $this->handle_pre_blocks($text, $in_tag);
 177          }
 178  
 179          #pre_dump( 'HANDLE_BLOCKS return: ', $new_text, $in_tag );

 180          return $new_text;
 181      }
 182  
 183  
 184      /**

 185       * Handle text which may contain inline tags

 186       *

 187       * - Explode by \n\n

 188       * - Merge blocks that span over multiple tags

 189       * - Apply BR to blocks

 190       * - Wrap block in P

 191       *

 192       * @param string Text

 193       * @param string Tag where $text is in

 194       * @return string

 195       */
 196  	function handle_pre_blocks( $text, $in_tag )
 197      {
 198          #echo '<h2>HANDLE_PRE_BLOCKS</h2>'; pre_dump( $text, $in_tag );

 199  
 200          if( $in_tag )
 201          {
 202              if( in_array($in_tag, $this->skip_tags) )
 203              {
 204                  return $text;
 205              }
 206  
 207              if( ! in_array($in_tag, $this->p_allowed_in) )
 208              { // we're in a tag, where no P tags are allowed, so just do the BRs:
 209                  return $this->handle_br( $text, $in_tag );
 210              }
 211          }
 212  
 213          $text_lines = preg_split( '~(\n\n+)~', $text, -1, /*PREG_SPLIT_NO_EMPTY |*/ PREG_SPLIT_DELIM_CAPTURE );
 214          $text_lines[] = ''; // dummy

 215  
 216          #echo '<strong>text_lines</strong><br />'; pre_dump( $text_lines, $in_tag );

 217  
 218          $new_blocks = array();
 219          $count_new_blocks = 0;
 220          for( $i = 0, $n = count($text_lines); $i < $n; $i = $i+2 /* every second block is a real one */ )
 221          {
 222              if( ! isset($new_blocks[$count_new_blocks]) )
 223              {
 224                  $new_blocks[$count_new_blocks] = '';
 225              }
 226              if( $text_lines[$i] == '' )
 227              {
 228                  $new_blocks[$count_new_blocks] .= $text_lines[$i+1];
 229                  $new_blocks[$count_new_blocks+1] = ''; // dummy

 230                  continue;
 231              }
 232              $new_blocks[$count_new_blocks] .= $text_lines[$i];
 233              $new_blocks[$count_new_blocks+1] = $text_lines[$i+1];
 234              $count_new_blocks = $count_new_blocks+2;
 235          }
 236  
 237          $text_lines = $new_blocks;
 238          #echo '<strong>new text_lines</strong><br />'; pre_dump( $new_blocks );

 239  
 240          if( trim($text) == '' )
 241          { // there's only whitespace
 242              return $text;
 243          }
 244  
 245  
 246          // fix it, so no (inline) tags span across multiple blocks:

 247          $new_blocks = array();
 248          $new_blocks_nowrap = array(); // blocks that should not be wrapped in P (opening without closing tag or vice versa)

 249          $count_new_blocks = 0;
 250          $looking_for_close_tag = array();
 251  
 252          for( $i = 0, $n = count($text_lines); $i < $n; $i = $i+2 /* every 2nd line is a real block */ )
 253          {
 254              $line = $text_lines[$i];
 255              if( ! isset($new_blocks[$count_new_blocks]) )
 256              {
 257                  $new_blocks[$count_new_blocks] = '';
 258  
 259                  $line_copy = $line;
 260                  preg_match( '~^(.*?)(<\s*/\s*(\w+)(\s+[^>]*?)?>)~is', $line_copy, $match );
 261  
 262                  while( preg_match( '~^(.*?)(<\s*/\s*(\w+)(\s+[^>]*?)?>)~is', $line_copy, $match )
 263                      && ! (preg_match( '~^(.*?)(<\s*'.$match[3].'(\s+[^>]*?(\s*/\s*)?)?>)~is', $new_blocks[$count_new_blocks].$match[1] )) )
 264                  { // a closing tag:
 265                      $new_blocks[$count_new_blocks] .= $match[0];
 266                      $line_copy = substr($line_copy, strlen($match[0]));
 267                  }
 268                  if( ! empty($new_blocks[$count_new_blocks]) )
 269                  { // we've found a closing tag with no opening tag, this must not get wrapped in P:
 270                      $new_blocks_nowrap[] = $count_new_blocks;
 271                      $new_blocks[$count_new_blocks+1] = ''; // dummy

 272                      $new_blocks[$count_new_blocks+2] = ''; // init new

 273                      $line = substr( $line, strlen($new_blocks[$count_new_blocks]) );
 274                      $count_new_blocks = $count_new_blocks+2;
 275                  }
 276              }
 277              else
 278              { // we're looking for a closing tag:
 279                  // Find closing tag:

 280                  $line_copy = $line;
 281                  list( $text_in_tag, $closing_tag, $NL_before, $NL_after ) = $this->split_text_for_tag( $looking_for_close_tag['tag'], $line_copy /* by ref */ );
 282                  if( empty($closing_tag) )
 283                  { // not in this whole block:
 284                      $new_blocks[ $count_new_blocks ] .= $line.$text_lines[$i+1];
 285                      continue;
 286                  }
 287  
 288                  // Tag has been found:

 289                  $looking_for_close_tag = array();
 290              }
 291  
 292              if( preg_match( '~^(.*?)(<\s*(\w+)(\s+[^>]*)?(\s*/\s*)?>)~is', $line, $match ) )
 293              { // a opening tag:
 294                  $tag = $match[3];
 295                  $pos_after_tag = strlen($match[0]);
 296                  while( ! empty($match[4]) )
 297                  { // self-closing tag, find next:
 298                      $tag = false;
 299                      if( preg_match( '~^(.*?)(<\s*(\w+)(\s+[^>]*)?(\s*/\s*)?>)~is', substr($line, $pos_after_tag), $match ) )
 300                      {
 301                          $tag = $match[3];
 302                          $pos_after_tag += strlen($match[0]);
 303                      }
 304                  }
 305                  $text_after_tag = substr($line, $pos_after_tag);
 306  
 307                  if( $tag )
 308                  {
 309                      // Find closing tag:

 310                      list( $text_in_tag, $closing_tag, $NL_before, $NL_after ) = $this->split_text_for_tag($tag, $text_after_tag /* by ref */ );
 311                      if( empty($closing_tag) )
 312                      {
 313                          $looking_for_close_tag = array(
 314                                  'tag' => $tag,
 315                                  'block' => $i,
 316                                  'pos' => strlen($new_blocks[ $count_new_blocks ])+strlen($match[1]), // position where the unclosed tag begins
 317                              );
 318                          $new_blocks[ $count_new_blocks ] .= $line.$text_lines[$i+1];
 319                          continue;
 320                      }
 321                  }
 322              }
 323              $new_blocks[ $count_new_blocks ] .= $line;
 324              $new_blocks[ ++$count_new_blocks ] = $text_lines[$i+1];
 325  
 326              $count_new_blocks++;
 327          }
 328          if( $looking_for_close_tag )
 329          {
 330              #echo '<h1>looking_for_close_tag</h1>'; pre_dump( $looking_for_close_tag );

 331              $new_blocks[ $count_new_blocks+1 ] = ''; // dummy

 332  
 333              if( $looking_for_close_tag['pos'] > 0 )
 334              { // move part of last block without closing tag to an own block:
 335                  $new_blocks[ $count_new_blocks+2 ] = substr($new_blocks[ $count_new_blocks ], $looking_for_close_tag['pos']);
 336                  $new_blocks[ $count_new_blocks ] = substr($new_blocks[ $count_new_blocks ], 0, $looking_for_close_tag['pos']);
 337                  $new_blocks[ $count_new_blocks+3 ] = ''; // dummy

 338  
 339                  $new_blocks_nowrap[] = $count_new_blocks+2;
 340              }
 341              else
 342              { // the whole block should not get wrapped!
 343                  $new_blocks_nowrap[] = $count_new_blocks;
 344              }
 345          }
 346  
 347          #echo '<h1>new_blocks:</h1>'; pre_dump( $new_blocks, $new_blocks_nowrap );

 348  
 349          $after_block_wp = '';
 350          $before_block_wp = '';
 351          if( empty($in_tag) )
 352          {
 353              $wrap_in_p = true;
 354          }
 355          elseif( in_array($in_tag, $this->p_allowed_in) )
 356          {
 357              if( ! $this->add_p_in_block )
 358              {
 359                  $wrap_in_p = false;
 360              }
 361              elseif( count($new_blocks) > 2 )
 362              {
 363                  $wrap_in_p = true;
 364              }
 365              else
 366              {
 367                  $wrap_in_p = false;
 368                  if( substr( $new_blocks[0], 0, 1 ) == "\n" )
 369                  {
 370                      $before_block_wp = "\n";
 371                      $new_blocks[0] = substr( $new_blocks[0], 1 );
 372                      $wrap_in_p = true;
 373                  }
 374                  if( substr( $new_blocks[0], -1 ) == "\n" )
 375                  {
 376                      $after_block_wp = "\n";
 377                      $new_blocks[0] = substr( $new_blocks[0], 0, -1 );
 378                      $wrap_in_p = true;
 379                  }
 380              }
 381          }
 382          else
 383          {
 384              $wrap_in_p = false;
 385          }
 386  
 387          if( $new_blocks[count($new_blocks)-2] == '' )
 388          {
 389              array_pop($new_blocks);
 390              array_pop($new_blocks);
 391          }
 392  
 393          $new_text = '';
 394  
 395          for( $i = 0, $n = count($new_blocks); $i < $n; $i = $i+2 )
 396          {
 397              #echo '<h2>--new_blocks['.$i.']: '; pre_dump( $new_blocks[$i] ); echo '</h2>';

 398  
 399              $this_wrap_in_p = $wrap_in_p && ! in_array( $i, $new_blocks_nowrap ); // only wrap this, if it's a valid block

 400  
 401              if( empty($new_blocks[$i]) )
 402              {
 403                  if( $this_wrap_in_p )
 404                  { // not the last one
 405                      $block = '<p></p>';
 406                  }
 407                  else
 408                  {
 409                      $block = '';
 410                  }
 411                  $new_text .= $before_block_wp.$block.$after_block_wp.$new_blocks[$i+1];
 412                  continue;
 413              }
 414  
 415              list($new_block, $has_p) = $this->handle_pre_blocks_helper( $new_blocks[$i], $in_tag, $this_wrap_in_p );
 416  
 417  
 418              $new_text .= $before_block_wp.$new_block.$after_block_wp.$new_blocks[$i+1];
 419          }
 420  
 421          #pre_dump( 'HANDLE_PRE_BLOCKS return: ', $new_text, $in_tag );

 422          return $new_text;
 423      }
 424  
 425  
 426      /**

 427       * This is a helper for handling blocks from {@link handle_pre_blocks_helper()}.

 428       *

 429       * What comes here is supposed to have no block tags.

 430       *

 431       * @return array array( $text, $has_p )

 432       */
 433  	function handle_pre_blocks_helper( $block, $in_tag, $wrap_in_p, $ignore_NL = true )
 434      {
 435          #pre_dump( 'HANDLE_PRE_BLOCKS_HELPER begin', $block, $in_tag );

 436          $has_p = NULL;
 437          $r = '';
 438  
 439          if( $in_tag == 'blockquote' )
 440          { // XHTML strict: blockquote content needs to be in block tag
 441              $in_tag = 'p';
 442              $wrap_in_p = true; // at the end

 443          }
 444  
 445          // Remove newlines at start and end (will get re-applied later):

 446          $NL_start = '';
 447          $NL_end = '';
 448          if( $ignore_NL )
 449          {
 450              while( $block{0} == "\n" )
 451              {
 452                  $NL_start .= $block{0};
 453                  $block = substr($block, 1);
 454              }
 455              while( substr($block, -1) == "\n" )
 456              {
 457                  $NL_end .= substr($block, -1);
 458                  $block = substr($block, 0, -1);
 459              }
 460          }
 461  
 462          if( preg_match( '~^(.*?)(<\s*(\w+)(\s+[^>]*)?>)~is', $block, $match ) )
 463          { // a tag:
 464              $tag = $match[3];
 465              $before_tag = $match[1];
 466  
 467              if( ! empty($before_tag) )
 468              { // Delegate to handle_br:
 469                  $r .= $this->handle_br( $before_tag, $in_tag );
 470              }
 471  
 472              // Opening tag:

 473              $r .= $match[2];
 474  
 475              $text_after_tag = substr( $block, strlen($match[0]) );
 476  
 477              // Find closing tag:

 478              list( $text_in_tag, $closing_tag, $NL_before, $NL_after ) = $this->split_text_for_tag($tag, $text_after_tag);
 479  
 480              if( ! empty($text_in_tag) )
 481              { // Recurse (same level) - with the optional newlines at start and end, because in an inline tag every linebreak should become a BR:
 482                  list($text_in_tag, $sub_has_p) = $this->handle_pre_blocks_helper( $NL_before.$text_in_tag.$NL_after, $tag, false, false );
 483              }
 484              $r .= $text_in_tag;
 485  
 486              $r .= $closing_tag;
 487  
 488              if( ! empty($text_after_tag) )
 489              {
 490                  #echo '<h1>RECURSE: text_after_tag (handle_pre_blocks)</h1>';

 491                  // Recurse (same level):

 492                  list( $text_after_tag, $sub_has_p ) = $this->handle_pre_blocks_helper( $text_after_tag, $in_tag, false, false );
 493                  $r .= $text_after_tag;
 494              }
 495          }
 496          else
 497          { // No tags in this $text:
 498              $r .= $this->handle_br( $block, $in_tag );
 499          }
 500  
 501          if( ! empty($wrap_in_p) )
 502          {
 503              $r = '<p>'.$r.'</p>';
 504              $has_p = true;
 505          }
 506  
 507          // re-apply newlines from start and end:

 508          $r = $NL_start.$r.$NL_end;
 509  
 510          #pre_dump( 'HANDLE_PRE_BLOCKS_HELPER return: ', $r, $has_p );

 511          return array( $r, $has_p );
 512      }
 513  
 514  
 515      /**

 516       * Handles adding BR.

 517       *

 518       * @return string

 519       */
 520  	function handle_br( $text, $in_tag )
 521      {
 522          #echo '<h3>LEVEL>1 (BR)</h3>'; pre_dump( $text );

 523  
 524          if( empty($in_tag) || in_array($in_tag, $this->br_allowed_in) )
 525          {
 526              $new_text = $this->autobr($text);
 527          }
 528          else
 529          {
 530              $new_text = $text;
 531          }
 532  
 533          #pre_dump( 'HANDLE_BR return: ', $new_text, $in_tag );

 534          return $new_text;
 535      }
 536  
 537  
 538      /**

 539       * Split the text for a given tag, mainly to find the closing tag.

 540       *

 541       * @return array

 542       */
 543  	function split_text_for_tag($tag, & $text_after_tag)
 544      {
 545          #echo '<strong>split_text_for_tag</strong><br />'; pre_dump( $tag, $text_after_tag );

 546          $depth = 1;
 547          $text_in_tag = '';
 548  
 549          $loop_text = $text_after_tag;
 550          while( 1 )
 551          {
 552              #echo '<hr />loop_text:'; pre_dump( $loop_text );

 553              if( preg_match( '~^(.*?)(<\s*(/)?\s*'.$tag.'\s*(/\s*)?>)~is', $loop_text, $after_match ) )
 554              {
 555                  #pre_dump( 'after_match', $after_match );

 556                  $text_in_tag .= $after_match[1];
 557                  $found_tag = $after_match[2];
 558                  $is_closing = ( ! empty($after_match[3]) || ! empty($after_match[4]) /* self-closing */ );
 559  
 560                  if( $is_closing )
 561                  {
 562                      $depth--;
 563                      if( $depth == 0 )
 564                      { // found the matching closing tag:
 565                          $closing_tag = $found_tag;
 566                          break;
 567                      }
 568                      else
 569                      { // this closing tag is part of the outer:
 570                          $text_in_tag .= $found_tag;
 571                      }
 572                  }
 573                  else
 574                  { // found the same, but opening tag (nested)
 575                      $text_in_tag .= $found_tag;
 576                      $depth++;
 577                  }
 578  
 579                  // skip what we've matched:

 580                  $loop_text = substr($loop_text, strlen($after_match[0]) );
 581              }
 582              else
 583              { // did not find the closing tag.. :/
 584                  $closing_tag = '';
 585                  return array( false, false, false, false );
 586              }
 587          }
 588  
 589          // remove newline at start and end:

 590          if( substr($text_in_tag, 0, 1) == "\n" )
 591          {
 592              $NL_before = "\n";
 593              $text_in_tag = substr($text_in_tag, 1);
 594          }
 595          else
 596          {
 597              $NL_before = '';
 598          }
 599          if( substr($text_in_tag, -1) == "\n" )
 600          {
 601              $NL_after = "\n";
 602              $text_in_tag = substr($text_in_tag, 0, -1);
 603          }
 604          else
 605          {
 606              $NL_after = '';
 607          }
 608  
 609          $text_after_tag = substr( $text_after_tag, strlen($NL_before.$text_in_tag.$NL_after)+strlen($closing_tag) );
 610          $r = array( $text_in_tag, $closing_tag, $NL_before, $NL_after );
 611  
 612          #pre_dump( 'return: ', $r, $text_after_tag );

 613          return $r;
 614      }
 615  
 616  
 617      /**

 618       * Add "<br />" to the end of newlines, which do not end with "<br />" already and which aren't

 619       * the last line, if the "Auto-BR" setting is enabled.

 620       *

 621       * @return string

 622       */
 623  	function autobr( $text, $replace_last = true )
 624      {
 625          if( ! $this->use_auto_br )
 626          { // don't make <br />'s
 627              return $text;
 628          }
 629  
 630          return preg_replace( '~(?<!<br />)\n'.( $replace_last ? '' : '(?!\z)' ).'~i', "<br />\n", $text );
 631      }
 632  
 633  }
 634  
 635  
 636  /*

 637   * $Log: _auto_p.plugin.php,v $

 638   * Revision 1.40  2007/07/04 19:59:12  blueyed

 639   * Auto-P: Do not add BR in html comments, nor wrap it in a P

 640   *

 641   * Revision 1.39  2007/07/04 19:52:00  blueyed

 642   * Auto-P: Do not add BR in SCRIPT, nor wrap it in a paragraph

 643   *

 644   * Revision 1.38  2007/05/21 17:44:10  blueyed

 645   * Auto-P: Fixed adding linebreaks/BR tags directly in OL elements

 646   *

 647   * Revision 1.37  2007/04/20 02:53:13  fplanque

 648   * limited number of installs

 649   *

 650   * Revision 1.36  2007/01/17 23:35:58  blueyed

 651   * Removed obsolete question/todo

 652   *

 653   * Revision 1.35  2006/12/26 03:19:12  fplanque

 654   * assigned a few significant plugin groups

 655   *

 656   * Revision 1.34  2006/12/20 13:42:54  blueyed

 657   * Made Auto-P plugin work again and let it handle also nextpage and noteaser special tags

 658   *

 659   * Revision 1.33  2006/12/18 13:31:12  fplanque

 660   * fixed broken more tag

 661   *

 662   * Revision 1.32  2006/12/07 23:13:13  fplanque

 663   * @var needs to have only one argument: the variable type

 664   * Otherwise, I can't code!

 665   *

 666   * Revision 1.31  2006/11/09 22:19:39  blueyed

 667   * Fix: split blocks by "<!--more-->" before working on them

 668   *

 669   * Revision 1.30  2006/08/26 15:57:39  blueyed

 670   * Fixed handling of self-closing inline tags in Auto-P

 671   *

 672   * Revision 1.29  2006/08/24 01:00:28  fplanque

 673   * Versioning

 674   *

 675   * Revision 1.28  2006/08/21 01:34:04  blueyed

 676   * Auto-P: BR is not allowed in UL, but LI

 677   *

 678   * Revision 1.27  2006/08/21 00:42:29  blueyed

 679   * Fix for leading and trailing newline in inline tags

 680   *

 681   * Revision 1.26  2006/08/20 23:37:46  blueyed

 682   * Fix: there were no <br /> after inline tags

 683   *

 684   * Revision 1.25  2006/08/20 22:41:36  blueyed

 685   * Fixed Auto-P: "the web is not a type-writer". Split blocks by two or more newlines and do not pee <br/> everywhere.

 686   *

 687   * Revision 1.24  2006/08/16 01:13:29  blueyed

 688   * Auto-P plugin: fix for self-closing block tags

 689   *

 690   * Revision 1.23  2006/07/31 22:03:01  blueyed

 691   * More fixes to the Auto-P plugin

 692   *

 693   * Revision 1.22  2006/07/27 21:35:54  blueyed

 694   * fix

 695   *

 696   * Revision 1.21  2006/07/27 21:17:29  blueyed

 697   * Fixed Auto-P plugin

 698   *

 699   * Revision 1.20  2006/07/10 20:19:30  blueyed

 700   * Fixed PluginInit behaviour. It now gets called on both installed and non-installed Plugins, but with the "is_installed" param appropriately set.

 701   *

 702   * Revision 1.19  2006/07/07 21:26:49  blueyed

 703   * Bumped to 1.9-dev

 704   *

 705   * Revision 1.18  2006/07/05 21:41:17  blueyed

 706   * fixes

 707   *

 708   * Revision 1.17  2006/07/05 20:10:17  blueyed

 709   * Merge/Parse error fixed

 710   *

 711   * Revision 1.16  2006/07/05 19:54:02  blueyed

 712   * Auto-P-plugin: respect newlines to create empty paragraphs

 713   *

 714   * Revision 1.15  2006/06/19 19:25:28  blueyed

 715   * Fixed auto-p plugin: <code> is an inline element

 716   *

 717   * Revision 1.14  2006/06/16 21:30:57  fplanque

 718   * Started clean numbering of plugin versions (feel free do add dots...)

 719   *

 720   * Revision 1.13  2006/05/30 19:39:55  fplanque

 721   * plugin cleanup

 722   *

 723   * Revision 1.12  2006/05/22 18:14:16  blueyed

 724   * Fixed the fixed auto-p-plugin

 725   *

 726   * Revision 1.11  2006/05/21 01:42:39  blueyed

 727   * Fixed Auto-P Plugin

 728   *

 729   * Revision 1.10  2006/04/22 01:30:26  blueyed

 730   * Fix for HR, CODE and FIELDSET by balupton (http://forums.b2evolution.net/viewtopic.php?p=35709#35709)

 731   *

 732   * Revision 1.9  2006/04/11 21:22:26  fplanque

 733   * partial cleanup

 734   *

 735   */
 736  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics