[ 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/ -> _wacko.plugin.php (source)

   1  <?php
   2  /**

   3   * This file implements the Wacko plugin for b2evolution

   4   *

   5   * Wacko style formatting

   6   *

   7   * b2evolution - {@link http://b2evolution.net/}

   8   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}

   9   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

  10   *

  11   * @package plugins

  12   * @ignore

  13   */
  14  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  15  
  16  
  17  /**

  18   * @package plugins

  19   */
  20  class wacko_plugin extends Plugin
  21  {
  22      var $code = 'b2evWcko';
  23      var $name = 'Wacko formatting';
  24      var $priority = 30;
  25      var $version = '1.9-dev';
  26      var $apply_rendering = 'opt-in';
  27      var $group = 'rendering';
  28      var $short_desc;
  29      var $long_desc;
  30      var $number_of_installs = 1;
  31  
  32      /**

  33       * GreyMatter formatting search array

  34       *

  35       * @access private

  36       */
  37      var $search = array(
  38              '#( ^ | \s ) ====== (.+?) ====== #x',
  39              '#( ^ | \s ) ===== (.+?) ===== #x',
  40              '#( ^ | \s ) ==== (.+?) ==== #x',
  41              '#( ^ | \s ) === (.+?) === #x',
  42              '#( ^ | \s ) == (.+?) == #x',
  43              '#^ \s* --- \s* $#xm',    // multiline start/stop checking
  44              '/ %%%
  45                  ( \s*? \n )?                 # Eat optional blank line after %%%
  46                  (.+?)
  47                  ( \n \s*? )?                 # Eat optional blank line before %%%
  48                  %%%
  49              /sxe'        // %%%escaped codeblock%%%
  50          );
  51  
  52      /**

  53       * HTML replace array

  54       *

  55       * @access private

  56       */
  57      var $replace = array(
  58              '$1<h6>$2</h6>',
  59              '$1<h5>$2</h5>',
  60              '$1<h4>$2</h4>',
  61              '$1<h3>$2</h3>',
  62              '$1<h2>$2</h2>',
  63              '<hr />',
  64              '\'<div class="codeblock"><pre><code>\'.
  65              htmlspecialchars(stripslashes(\'$2\'),ENT_NOQUOTES).
  66              \'</code></pre></div>\''
  67          );
  68  
  69      /**

  70       * Init

  71       */
  72  	function PluginInit( & $params )
  73      {
  74          $this->short_desc = T_('Wacko style formatting');
  75          $this->long_desc = T_('Accepted formats:<br />
  76              == h2 ==<br />
  77              === h3 ===<br />
  78              ==== h4 ====<br />
  79              ===== h5 =====<br />
  80              ====== h6 ======<br />
  81              --- (horinzontal rule)<br />
  82              %%%codeblock%%%<br />');
  83      }
  84  
  85  
  86      /**

  87       * Perform rendering

  88       *

  89       * @param array Associative array of parameters

  90       *   'data': the data (by reference). You probably want to modify this.

  91       *   'format': see {@link format_to_output()}. Only 'htmlbody' and 'entityencoded' will arrive here.

  92       * @return boolean true if we can render something for the required output format

  93       */
  94  	function RenderItemAsHtml( & $params )
  95      {
  96          $content = & $params['data'];
  97  
  98          $content = preg_replace( $this->search, $this->replace, $content );
  99  
 100          // Find bullet lists

 101          $lines = explode( "\n", $content );
 102          $lists = array();
 103          $current_depth = 0;
 104          $content = '';
 105          foreach( $lines as $line )
 106          {
 107              if( ! preg_match( '#^ /s $#xm', $line ) )
 108              {     // If not blank line
 109                  $matches = array();
 110  
 111                  if( preg_match( '#^((  )+)\*(.*)$#m', $line, $matches ) )
 112                  {    // We have a list item
 113                      $req_depth = strlen( $matches[1] ) / 2;
 114                      while( $current_depth < $req_depth )
 115                      {    // We must indent
 116                          $content .= "<ul>\n";
 117                          array_push( $lists, 'ul' );
 118                          $current_depth++;
 119                      }
 120  
 121                      while( $current_depth > $req_depth )
 122                      {    // We must close lists
 123                          $content .= '</'.array_pop( $lists ).">\n";
 124                          $current_depth--;
 125                      }
 126  
 127                      $content .= $matches[1].'<li>'.$matches[3]."</li>\n";
 128                      continue;
 129                  }
 130  
 131                  if( preg_match( '#^((  )+)([0-9]+)(.*)$#m', $line, $matches ) )
 132                  {    // We have an ordered list item
 133                      $req_depth = strlen( $matches[1] ) / 2;
 134                      while( $current_depth < $req_depth )
 135                      {    // We must indent
 136                          $content .= '<ol start="'.$matches[3].'">'."\n";
 137                          array_push( $lists, 'ol' );
 138                          $current_depth++;
 139                      }
 140  
 141                      while( $current_depth > $req_depth )
 142                      {    // We must close lists
 143                          $content .= '</'.array_pop( $lists ).">\n";
 144                          $current_depth--;
 145                      }
 146  
 147                      $content .= $matches[1].'<li>'.$matches[4]."</li>\n";
 148                      continue;
 149                  }
 150  
 151                  // Normal line.

 152  
 153                  if( $current_depth )
 154                  { // We must go back to 0
 155                      $content .= '</'.implode( ">\n</", $lists ).">\n";
 156                      $lists = array();
 157                      $current_depth = 0;
 158                  }
 159  
 160                  $content .= $line."\n";
 161  
 162              }
 163          }
 164  
 165          if( $current_depth )
 166          { // We must go back to 0
 167              $content .= '</'.implode( ">\n</", $lists ).">\n";
 168          }
 169  
 170          return true;
 171      }
 172  }
 173  
 174  
 175  /*

 176   * $Log: _wacko.plugin.php,v $

 177   * Revision 1.16  2007/04/26 00:11:04  fplanque

 178   * (c) 2007

 179   *

 180   * Revision 1.15  2007/04/20 02:53:13  fplanque

 181   * limited number of installs

 182   *

 183   * Revision 1.14  2006/12/26 03:19:12  fplanque

 184   * assigned a few significant plugin groups

 185   *

 186   * Revision 1.13  2006/07/10 20:19:30  blueyed

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

 188   *

 189   * Revision 1.12  2006/07/07 21:26:49  blueyed

 190   * Bumped to 1.9-dev

 191   *

 192   * Revision 1.11  2006/07/03 21:04:51  fplanque

 193   * translation cleanup

 194   *

 195   * Revision 1.10  2006/06/16 21:30:57  fplanque

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

 197   *

 198   * Revision 1.9  2006/05/30 19:39:56  fplanque

 199   * plugin cleanup

 200   *

 201   * Revision 1.8  2006/04/11 21:22:26  fplanque

 202   * partial cleanup

 203   *

 204   */
 205  ?>


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