b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: plugins ] [ index: plugins ] [ all elements ]

Source for file _auto_p.renderer.php

Documentation is available at _auto_p.renderer.php

  1. <?php
  2. /**
  3.  * This file implements the Auto P plugin for b2evolution
  4.  *
  5.  * @author WordPress team - http://sourceforge.net/project/memberlist.php?group_id=51422
  6.  *
  7.  * @package plugins
  8.  */
  9. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  10.  
  11. /**
  12.  * Includes:
  13.  */
  14. require_once dirname(__FILE__).'/../renderer.class.php';
  15.  
  16. /**
  17.  * @package plugins
  18.  */
  19. {
  20.     var $code = 'b2WPAutP';
  21.     var $name = 'Auto P';
  22.     var $priority = 70;
  23.     
  24.     var $apply_when = 'opt-out';
  25.     var $apply_to_html = true
  26.     var $apply_to_xml = false
  27.     var $short_desc;
  28.     var $long_desc;
  29.  
  30.     var $br = true;     // optionally make line breaks
  31.  
  32.  
  33.     /**
  34.      * Constructor
  35.      *
  36.      * {@internal auto_p_Rendererplugin::auto_p_Rendererplugin(-)}}
  37.      */
  38.     function auto_p_Rendererplugin()
  39.     {
  40.         $this->short_desc = T_('Automatic &lt;P&gt; and &lt;BR&gt; tags');
  41.         $this->long_desc = T_('No description available');
  42.     }
  43.  
  44.  
  45.     /**
  46.      * Perform rendering
  47.      *
  48.      * {@internal auto_p_Rendererplugin::render(-)}}
  49.      *
  50.      * @param string content to render (by reference) / rendered content
  51.      * @param string Output format, see {@link format_to_output()}
  52.      * @return boolean true if we can render something for the required output format
  53.      */
  54.     function render$content$format )
  55.     {
  56.         ifparent::render$content$format ) )
  57.         {    // We cannot render the required format
  58.             return false;
  59.         }
  60.  
  61.         // REPLACE:  But not in code blocks.
  62.         ifstrpos$content '<pre>' !== false )
  63.         // If there are code tags run this substitution
  64.             $content_parts preg_split("/<\/?pre>/"$content);
  65.             $content '';
  66.             for $x $x count$content_parts $x++ )
  67.             {
  68.                 if ( ( $x == )
  69.                 // If x is even then it's not code and replace any smiles
  70.                     $content .= $this->autop$content_parts[$x);
  71.                 }
  72.                 else
  73.                 // If x is odd don't replace smiles. and put code tags back in.
  74.                     $content .= '<pre>' $content_parts[$x'</pre>';
  75.                 }
  76.             }
  77.         }
  78.         else
  79.         // No code blocks, replace on the whole thing
  80.             $content $this->autop$content );
  81.         }
  82.         return true;
  83.     }
  84.  
  85.     function autop$pee )
  86.     {    
  87.         $pee $pee"\n"// just to make things a little easier, pad the end
  88.         
  89.         $pee preg_replace('|<br />\s*<br />|'"\n\n"$pee);    // Change double BRs to double newlines
  90.         
  91.         // Space things out a little:
  92.         $pee preg_replace('!(<(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)!'"\n$1"$pee)
  93.         $pee preg_replace('!(</(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])>)!'"$1\n"$pee);
  94.                 
  95.         $pee preg_replace("/(\r\n|\r)/""\n"$pee)// cross-platform newlines 
  96.  
  97.         $pee preg_replace("/\n\n+/""\n\n"$pee)// take care of duplicates
  98.  
  99.         // make paragraphs, including one at the end :
  100.         $pee preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s'"\t<p>$1</p>\n"$pee)
  101.  
  102.         // Now fix all the extra Ps...
  103.         
  104.         $pee preg_replace('|\t<p>\s*?</p>\n|'''$pee)// under certain strange conditions it could create a P of entirely whitespace # dh: fixed creation of unnecessary <br />
  105.  
  106.         $pee preg_replace('!<p>\s*(</?(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*</p>!'"$1"$pee)// don't pee all over a tag
  107.         
  108.         $pee preg_replace("|<p>(<li.+?)</p>|""$1"$pee)// problem with nested lists
  109.         
  110.         $pee preg_replace('|<p><blockquote([^>]*)>|i'"<blockquote$1><p>"$pee);
  111.         $pee str_replace('</blockquote></p>''</p></blockquote>'$pee);
  112.         
  113.         $pee preg_replace('!<p>\s*(</?(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)!'"$1"$pee);
  114.         $pee preg_replace('!(</?(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*</p>!'"$1"$pee)
  115.         
  116.         if ($this->br$pee preg_replace('|(?<!<br />)\s*\n|'"<br />\n"$pee)// optionally make line breaks
  117.         
  118.         $pee preg_replace('!(</?(?:table|thead|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*<br />!'"$1"$pee);
  119.         $pee preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!''$1'$pee);
  120.         
  121.         // $content = preg_replace('!(<pre.*? >)(.*?)</pre>!ise', "'$1'.clean_pre('$2').'</pre>' ", $pee);
  122.         
  123.         // $content = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $pee);
  124.         
  125.         return $pee;
  126.     }
  127. }
  128.  
  129. // Register the plugin:
  130. $this->registernew auto_p_Rendererplugin() );
  131.  
  132. ?>

Documentation generated on Tue, 20 May 2008 01:52:17 +0200 by phpDocumentor 1.4.2