b2evolution PHP Cross Reference Blogging Systems

Source: /plugins/_gmcode.plugin.php - 128 lines - 2978 bytes - Summary - Text - Print

Description: This file implements the GMcode plugin for b2evolution GreyMatter style formatting

   1  <?php
   2  /**
   3   * This file implements the GMcode plugin for b2evolution
   4   *
   5   * GreyMatter 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-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   * Replaces GreyMatter markup in HTML (not XML).
  17   *
  18   * @todo dh> Do not replace in tags, it matches e.g. the following for italic:
  19   *           """<img src="//url" /> [...] http://"""!
  20   *
  21   * @package plugins
  22   */
  23  class gmcode_plugin extends Plugin
  24  {
  25      var $code = 'b2evGMco';
  26      var $name = 'GM code';
  27      var $priority = 45;
  28      var $group = 'rendering';
  29      var $short_desc;
  30      var $long_desc;
  31      var $version = '5.0.0';
  32      var $number_of_installs = 1;
  33  
  34  
  35      /**
  36       * GreyMatter formatting search array
  37       *
  38       * @access private
  39       */
  40      var $search = array(
  41              '# \*\* (.+?) \*\* #x',                // **bold**
  42              '# \x5c\x5c (.+?) \x5c\x5c #x',        // \\italics\\
  43              '# (?<!:) \x2f\x2f (.+?) \x2f\x2f #x', // //italics// (not preceded by : as in http://)
  44              '# __ (.+?) __ #x',                    // __underline__
  45              '/ \#\# (.+?) \#\# /x',                // ##tt##
  46              '/ %%
  47                  ( \s*? \n )?      # Eat optional blank line after %%%
  48                  (.+?)
  49                  ( \n \s*? )?      # Eat optional blank line before %%%
  50                  %%
  51              /sx'                                   // %%codeblock%%
  52          );
  53  
  54      /**
  55       * HTML replace array
  56       *
  57       * @access private
  58       */
  59      var $replace = array(
  60              '<strong>$1</strong>',
  61              '<em>$1</em>',
  62              '<em>$1</em>',
  63              '<span style="text-decoration:underline">$1</span>',
  64              '<tt>$1</tt>',
  65              '<div class="codeblock"><pre><code>$2</code></pre></div>'
  66          );
  67  
  68  
  69      /**
  70       * Init
  71       */
  72  	function PluginInit( & $params )
  73      {
  74          $this->short_desc = T_('GreyMatter style formatting');
  75          $this->long_desc = T_('**bold** \\italics\\ //italics// __underline__ ##tt## %%codeblock%%');
  76      }
  77  
  78  
  79      /**
  80       * Perform rendering
  81       *
  82       * @see Plugin::RenderItemAsHtml()
  83       */
  84  	function RenderItemAsHtml( & $params )
  85      {
  86          $content = & $params['data'];
  87  
  88          if( stristr( $content, '<code' ) !== false || stristr( $content, '<pre' ) !== false )
  89          {    // Call replace_content() on everything outside code/pre:
  90              $content = callback_on_non_matching_blocks( $content,
  91                  '~<(code|pre)[^>]*>.*?</\1>~is',
  92                  array( $this, 'replace_out_tags' ) );
  93          }
  94          else
  95          {    // No code/pre blocks, replace on the whole thing
  96              $content = $this->replace_out_tags( $content );
  97          }
  98  
  99          return true;
 100      }
 101  
 102  
 103      /**
 104       * Replace text outside of html tags
 105       *
 106       * @param string
 107       * @return string
 108       */
 109  	function replace_out_tags( $text )
 110      {
 111          return callback_on_non_matching_blocks( $text, '~<[^>]*>~s', array( $this, 'replace_callback' ) );
 112      }
 113  
 114  
 115      /**
 116       * Replace callback
 117       *
 118       * @param string
 119       * @return string
 120       */
 121  	function replace_callback( $text )
 122      {
 123          return preg_replace( $this->search, $this->replace, $text );
 124      }
 125  
 126  }
 127  
 128  ?>

title

Description

title

Description

title

Description

title

title

Body