1<?php
2
3/**
4 *
5 * Parse structured wiki text and render into arbitrary formats such as XHTML.
6 * This is the Text_Wiki extension for Mediawiki markup
7 *
8 * PHP versions 4 and 5
9 *
10 * @category   Text
11 *
12 * @package    Text_Wiki
13 *
14 * @author     Michele Tomaiuolo <tomamic@yahoo.it>
15 *
16 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
17 *
18 * @link       http://pear.php.net/package/Text_Wiki
19 *
20 * @version    CVS: $Id$
21 *
22 */
23
24/**
25 *
26 * "Master" class for handling the management and convenience
27 *
28 */
29
30require_once 'Text/Wiki.php';
31
32/**
33 *
34 * Base Text_Wiki handler class extension for Creole markup
35 *
36 * @category   Text
37 *
38 * @package    Text_Wiki
39 *
40 * @author     Michele Tomaiuolo <tomamic@yahoo.it>
41 *
42 * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
43 *
44 * @link       http://pear.php.net/package/Text_Wiki
45 *
46 * @see        Text_Wiki::Text_Wiki()
47 *
48 */
49
50class Text_Wiki_Creole extends Text_Wiki {
51
52    // *single newlines* are handled as in most wikis (ignored)
53    // if Newline is removed from rules, they will be handled as in word-processors (meaning a paragraph break)
54
55    var $rules = array(
56        'Prefilter',
57        'Delimiter',
58        'Preformatted',
59        'Tt',
60        'Trim',
61        'Break',
62        'Raw',
63        'Box',
64        'Footnote',
65        'Heading',
66        'Newline',
67        'Deflist',
68        'Blockquote',
69        'Newline',
70        'Url',
71        'Wikilink',
72        'Image',
73        //'Heading',
74        'Table',
75        'Center',
76        'Horiz',
77        'Deflist',
78        'List',
79        'Address',
80        'Paragraph',
81        'Superscript',
82        'Subscript',
83        'Underline',
84        'Emphasis',
85        'Strong',
86        //'Italic',
87        //'Bold',
88        'Tighten'
89    );
90
91    /**
92     * Constructor: just adds the path to Creole rules
93     *
94     * @access public
95     * @param array $rules The set of rules to load for this object.
96     */
97
98    function __construct($rules = null) {
99        parent::__construct($rules);
100        $this->addPath('parse', $this->fixPath(dirname(__FILE__)).'Parse/Creole');
101        $this->renderingType = 'char';
102        $this->setRenderConf('xhtml', 'center', 'css', 'center');
103        $this->setRenderConf('xhtml', 'url', 'target', null);
104    }
105
106    function checkInnerTags(&$text) {
107        $started = array();
108		$i = false;
109        while (($i = strpos($text, $this->delim, $i)) !== false) {
110            $j = strpos($text, $this->delim, $i + 1);
111            $t = substr($text, $i + 1, $j - $i - 1);
112            $i = $j + 1;
113            $rule = strtolower($this->tokens[$t][0]);
114            $type = $this->tokens[$t][1]['type'];
115
116            if ($type == 'start') {
117				if (empty($started[$rule])) {
118					$started[$rule] = 0;
119				}
120                $started[$rule] += 1;
121            }
122            else if ($type == 'end') {
123                if (empty($started[$rule])) return false;
124
125                $started[$rule] -= 1;
126                if (! $started[$rule]) unset($started[$rule]);
127            }
128        }
129        return ! (count($started) > 0);
130    }
131
132    function restoreRaw($text) {
133		$i = false;
134        while (($i = strpos($text, $this->delim, $i)) !== false) {
135            $j = strpos($text, $this->delim, $i + 1);
136            $t = substr($text, $i + 1, $j - $i - 1);
137            $rule = strtolower($this->tokens[$t][0]);
138
139            if ($rule == 'raw') {
140                $text = str_replace($this->delim. $t. $this->delim, $this->tokens[$t][1]['text'], $text);
141            }
142            else {
143                $i = $j + 1;
144            }
145        }
146        return $text;
147    }
148}
149
150?>
151