includes/wikiformat.php
author Dan
Thu, 02 Jul 2009 08:57:13 -0400
changeset 1029 1d9846ec37f5
parent 1027 98c052fc3337
child 1031 8a4b75e73137
permissions -rw-r--r--
Installer: now compatible with new rendering engine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
<?php
536
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
     2
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
     3
/*
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
801
eb8b23f11744 Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
parents: 685
diff changeset
     5
 * Version 1.1.6 (Caoineag beta 1)
536
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
     6
 * Copyright (C) 2006-2008 Dan Fuhry
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
     7
 *
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
    10
 *
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
    13
 */
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 460
diff changeset
    14
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    15
/**
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    16
 * Framework for parsing and rendering various formats. In Enano by default, this is MediaWiki-style wikitext being
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    17
 * rendered to XHTML, but this framework allows other formats to be supported as well.
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    18
 *
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    19
 * @package Enano
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    20
 * @subpackage Content
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    21
 * @author Dan Fuhry <dan@enanocms.org>
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    22
 * @copyright (C) 2009 Enano CMS Project
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    23
 * @license GNU General Public License, version 2 or later <http://www.gnu.org/licenses/gpl-2.0.html>
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    24
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    25
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    26
class Carpenter
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    27
{
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    28
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    29
   * Parser token
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    30
   * @const string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    31
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    32
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    33
  const PARSER_TOKEN = "\xFF";
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    34
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    35
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    36
   * Parsing engine
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    37
   * @var string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    38
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    39
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    40
  private $parser = 'mediawiki';
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    41
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    42
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    43
   * Rendering engine
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    44
   * @var string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    45
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    46
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    47
  private $renderer = 'xhtml';
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    48
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    49
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    50
   * Rendering flags
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    51
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    52
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    53
  public $flags = RENDER_WIKI_DEFAULT;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    54
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    55
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    56
   * List of rendering rules
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    57
   * @var array
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    58
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    59
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    60
  private $rules = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    61
      'lang',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    62
      'templates',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    63
      'tables',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    64
      'heading',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    65
      // note: can't be named list ("list" is a PHP language construct)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    66
      'multilist',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    67
      'bold',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    68
      'italic',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    69
      'underline',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    70
      'externalwithtext',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    71
      'externalnotext',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    72
      'image',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    73
      'internallink',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    74
      'paragraph'
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    75
    );
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    76
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    77
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    78
   * List of render hooks
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    79
   * @var array
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    80
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    81
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    82
  private $hooks = array();
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    83
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    84
  /* private $rules = array('prefilter', 'delimiter', 'code', 'function', 'html', 'raw', 'include', 'embed', 'anchor',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    85
           'heading', 'toc', 'horiz', 'break', 'blockquote', 'list', 'deflist', 'table', 'image',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    86
           'phplookup', 'center', 'newline', 'paragraph', 'url', 'freelink', 'interwiki',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    87
           'wikilink', 'colortext', 'strong', 'bold', 'emphasis', 'italic', 'underline', 'tt',
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    88
           'superscript', 'subscript', 'revise', 'tighten'); */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    89
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    90
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    91
   * Render the text!
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    92
   * @param string Text to render
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    93
   * @return string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    94
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    95
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    96
  public function render($text)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    97
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    98
    $parser_class = "Carpenter_Parse_" . ucwords($this->parser);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
    99
    $renderer_class = "Carpenter_Render_" . ucwords($this->renderer);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   100
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   101
    // include files, if we haven't already
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   102
    if ( !class_exists($parser_class) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   103
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   104
      require_once( ENANO_ROOT . "/includes/wikiengine/parse_{$this->parser}.php");
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   105
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   106
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   107
    if ( !class_exists($renderer_class) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   108
    {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   109
      require_once( ENANO_ROOT . "/includes/wikiengine/render_{$this->renderer}.php");
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   110
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   111
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   112
    $parser = new $parser_class;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   113
    $renderer = new $renderer_class;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   114
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   115
    // run prehooks
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   116
    foreach ( $this->hooks as $hook )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   117
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   118
      if ( $hook['when'] === PO_FIRST )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   119
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   120
        $text = call_user_func($hook['callback'], $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   121
        if ( !is_string($text) || empty($text) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   122
        {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   123
          trigger_error("Hook returned empty/invalid text: " . print_r($hook['callback'], true), E_USER_WARNING);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   124
          // *sigh*
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   125
          $text = '';
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   126
        }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   127
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   128
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   129
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   130
    // perform render
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   131
    foreach ( $this->rules as $rule )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   132
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   133
      // run prehooks
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   134
      foreach ( $this->hooks as $hook )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   135
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   136
        if ( $hook['when'] === PO_BEFORE && $hook['rule'] === $rule )
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 371
diff changeset
   137
        {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   138
          $text = call_user_func($hook['callback'], $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   139
          if ( !is_string($text) || empty($text) )
438
c9522c961e10 Fixed broken installer due to bad $plugins object
Dan
parents: 407
diff changeset
   140
          {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   141
            trigger_error("Hook returned empty/invalid text: " . print_r($hook['callback'], true), E_USER_WARNING);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   142
            // *sigh*
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   143
            $text = '';
438
c9522c961e10 Fixed broken installer due to bad $plugins object
Dan
parents: 407
diff changeset
   144
          }
407
35d94240a197 Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents: 371
diff changeset
   145
        }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   146
      }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   147
      
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   148
      // execute rule
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   149
      $text = $this->perform_render_step($text, $rule, $parser, $renderer);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   150
      
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   151
      // run posthooks
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   152
      foreach ( $this->hooks as $hook )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   153
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   154
        if ( $hook['when'] === PO_AFTER && $hook['rule'] === $rule )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   155
        {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   156
          $text = call_user_func($hook['callback'], $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   157
          if ( !is_string($text) || empty($text) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   158
          {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   159
            trigger_error("Hook returned empty/invalid text: " . print_r($hook['callback'], true), E_USER_WARNING);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   160
            // *sigh*
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   161
            $text = '';
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   162
          }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   163
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   164
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   165
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   166
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   167
    // run posthooks
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   168
    foreach ( $this->hooks as $hook )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   169
    {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   170
      if ( $hook['when'] === PO_LAST )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   171
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   172
        $text = call_user_func($hook['callback'], $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   173
        if ( !is_string($text) || empty($text) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   174
        {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   175
          trigger_error("Hook returned empty/invalid text: " . print_r($hook['callback'], true), E_USER_WARNING);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   176
          // *sigh*
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   177
          $text = '';
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   178
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   179
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   180
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   181
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   182
    return (( defined('ENANO_DEBUG') && isset($_GET['parserdebug']) ) ? '<pre>' . htmlspecialchars($text) . '</pre>' : $text) . "\n\n";
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   183
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   184
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   185
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   186
   * Performs a step in the rendering process.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   187
   * @param string Text to render
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   188
   * @param string Rule to execute
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   189
   * @param object Parser instance
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   190
   * @param object Renderer instance
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   191
   * @return string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   192
   * @access private
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   193
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   194
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   195
  private function perform_render_step($text, $rule, $parser, $renderer)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   196
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   197
    // First look for a direct function
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   198
    if ( function_exists("parser_{$this->parser}_{$this->renderer}_{$rule}") )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   199
    {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   200
      return call_user_func("parser_{$this->parser}_{$this->renderer}_{$rule}", $text, $this->flags);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   201
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   202
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   203
    // We don't have that, so start looking for other ways or means of doing this
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   204
    if ( method_exists($parser, $rule) && method_exists($renderer, $rule) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   205
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   206
      // Both the parser and render have callbacks they want to use.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   207
      $pieces = $parser->$rule($text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   208
      $text = call_user_func(array($renderer, $rule), $text, $pieces);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   209
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   210
    else if ( method_exists($parser, $rule) && !method_exists($renderer, $rule) && isset($renderer->rules[$rule]) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   211
    {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   212
      // The parser has a callback, but the renderer does not
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   213
      $pieces = $parser->$rule($text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   214
      $text = $this->generic_render($text, $pieces, $renderer->rules[$rule]);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   215
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   216
    else if ( !method_exists($parser, $rule) && isset($parser->rules[$rule]) && method_exists($renderer, $rule) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   217
    {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   218
      // The parser has no callback, but the renderer does
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   219
      $text = preg_replace_callback($parser->rules[$rule], array($renderer, $rule), $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   220
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   221
    else if ( isset($parser->rules[$rule]) && isset($renderer->rules[$rule]) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   222
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   223
      // This is a straight-up regex only rule
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   224
      $text = preg_replace($parser->rules[$rule], $renderer->rules[$rule], $text);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   225
    }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   226
    else
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   227
    {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   228
      // Either the renderer or parser does not support this rule, ignore it
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   229
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   230
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   231
    return $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   232
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   233
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   234
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   235
   * Generic renderer
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   236
   * @access protected
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   237
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   238
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   239
  protected function generic_render($text, $pieces, $rule)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   240
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   241
    foreach ( $pieces as $i => $piece )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   242
    {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   243
      $replacement = $rule;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   244
      
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   245
      // if the piece is an array, replace $1, $2, etc. in the rule with each value in the piece
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   246
      if ( is_array($piece) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   247
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   248
        $j = 0;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   249
        foreach ( $piece as $part )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   250
        {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   251
          $j++;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   252
          $replacement = str_replace(array("\\$j", "\${$j}"), $part, $replacement);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   253
        }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   254
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   255
      // else, just replace \\1 or $1 in the rule with the piece
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   256
      else
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   257
      {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   258
        $replacement = str_replace(array("\\1", "\$1"), $piece, $replacement);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   259
      }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   260
      
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   261
      $text = str_replace(self::generate_token($i), $replacement, $text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   262
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   263
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   264
    return $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   265
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   266
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   267
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   268
   * Add a hook into the parser.
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   269
   * @param callback Function to call
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   270
   * @param int PO_* constant
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   271
   * @param string If PO_{BEFORE,AFTER} used, rule
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   272
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   273
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   274
  public function hook($callback, $when, $rule = false)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   275
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   276
    if ( !is_int($when) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   277
      return null;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   278
    if ( ($when == PO_BEFORE || $when == PO_AFTER) && !is_string($rule) )
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   279
      return null;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   280
    if ( ( is_string($callback) && !function_exists($callback) ) || ( is_array($callback) && !method_exists($callback[0], $callback[1]) ) || ( !is_string($callback) && !is_array($callback) ) )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   281
    {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   282
      trigger_error("Attempt to hook with undefined function/method " . print_r($callback, true), E_USER_ERROR);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   283
      return null;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   284
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   285
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   286
    $this->hooks[] = array(
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   287
        'callback' => $callback,
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   288
        'when'     => $when,
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   289
        'rule'     => $rule
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   290
      );
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   291
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   292
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   293
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   294
   * Generate a token
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   295
   * @param int Token index
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   296
   * @return string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   297
   * @static
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   298
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   299
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   300
  public static function generate_token($i)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   301
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   302
    return self::PARSER_TOKEN . $i . self::PARSER_TOKEN;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   303
  }
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   304
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   305
  /**
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   306
   * Tokenize string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   307
   * @param string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   308
   * @param array Matches
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   309
   * @return string
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   310
   * @static
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   311
   */
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   312
  
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   313
  public static function tokenize($text, $matches)
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   314
  {
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   315
    $matches = array_values($matches);
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   316
    foreach ( $matches as $i => $match )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   317
    {
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   318
      $text = str_replace_once($match, self::generate_token($i), $text);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   319
    }
1027
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   320
    
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   321
    return $text;
98c052fc3337 First implementation of new parser; Text_Wiki is now gone. VERY BETA! WiP.
Dan
parents: 801
diff changeset
   322
  }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   323
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   324