author | Dan |
Sat, 12 Jul 2008 04:49:30 -0400 | |
changeset 631 | f4f4146d8b6c |
parent 32 | 4d87aad3c4c0 |
permissions | -rw-r--r-- |
1 | 1 |
<?php |
2 |
||
3 |
/** |
|
4 |
* |
|
5 |
* Parses for implied line breaks indicated by newlines. |
|
6 |
* |
|
7 |
* @category Text |
|
8 |
* |
|
9 |
* @package Text_Wiki |
|
10 |
* |
|
11 |
* @author Paul M. Jones <pmjones@php.net> |
|
12 |
* |
|
13 |
* @license LGPL |
|
14 |
* |
|
15 |
* @version $Id: Newline.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $ |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
/** |
|
20 |
* |
|
21 |
* Parses for implied line breaks indicated by newlines. |
|
22 |
* |
|
23 |
* This class implements a Text_Wiki_Parse to mark implied line breaks in the |
|
24 |
* source text, usually a single carriage return in the middle of a paragraph |
|
25 |
* or block-quoted text. |
|
26 |
* |
|
27 |
* @category Text |
|
28 |
* |
|
29 |
* @package Text_Wiki |
|
30 |
* |
|
31 |
* @author Paul M. Jones <pmjones@php.net> |
|
32 |
* |
|
33 |
*/ |
|
34 |
||
35 |
class Text_Wiki_Parse_Newline extends Text_Wiki_Parse { |
|
36 |
||
37 |
||
38 |
/** |
|
39 |
* |
|
40 |
* The regular expression used to parse the source text and find |
|
41 |
* matches conforming to this rule. Used by the parse() method. |
|
42 |
* |
|
43 |
* @access public |
|
44 |
* |
|
45 |
* @var string |
|
46 |
* |
|
47 |
* @see parse() |
|
48 |
* |
|
49 |
*/ |
|
50 |
||
51 |
var $regex = '/([^\n])\n([^\n])/m'; |
|
52 |
||
53 |
||
54 |
/** |
|
55 |
* |
|
56 |
* Generates a replacement token for the matched text. |
|
57 |
* |
|
58 |
* @access public |
|
59 |
* |
|
60 |
* @param array &$matches The array of matches from parse(). |
|
61 |
* |
|
62 |
* @return string A delimited token to be used as a placeholder in |
|
63 |
* the source text. |
|
64 |
* |
|
65 |
*/ |
|
66 |
||
67 |
function process(&$matches) |
|
68 |
{ |
|
69 |
return $matches[1] . |
|
70 |
$this->wiki->addToken($this->rule) . |
|
71 |
$matches[2]; |
|
72 |
} |
|
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
73 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
74 |
/** |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
75 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
76 |
* Abstrct method to parse source text for matches. |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
77 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
78 |
* Applies the rule's regular expression to the source text, passes |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
79 |
* every match to the process() method, and replaces the matched text |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
80 |
* with the results of the processing. |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
81 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
82 |
* @access public |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
83 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
84 |
* @see Text_Wiki_Parse::process() |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
85 |
* |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
86 |
*/ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
87 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
88 |
function parse() |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
89 |
{ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
90 |
$source =& $this->wiki->source; |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
91 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
92 |
// This regex attempts to find HTML tags that can be safely compacted together without formatting loss |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
93 |
// The idea is to make it easier for the HTML parser to find litewiki elements |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
94 |
//$source = preg_replace('/<\/([a-z0-9:-]+?)>([\s]*[\n]+[\s]+|[\s]+[\n]+[\s]*|[\n]+)<([a-z0-9:-]+)(.*?)>/i', '</\\1><\\3\\4>', $source); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
95 |
$source = wikiformat_process_block($source); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
96 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
97 |
$rand_key = md5( str_rot13(strval(dechex(time()))) . microtime() . strval(mt_rand()) ); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
98 |
preg_match_all('/<(litewiki|pre)([^>]*?)>(.*?)<\/\\1>/is', $this->wiki->source, $matches); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
99 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
100 |
$poslist = array(); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
101 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
102 |
foreach ( $matches[0] as $i => $match ) |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
103 |
{ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
104 |
$source = str_replace($match, "{LITEWIKI:$i:$rand_key}", $source); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
105 |
} |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
106 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
107 |
$this->wiki->source = preg_replace_callback( |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
108 |
$this->regex, |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
109 |
array(&$this, 'process'), |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
110 |
$this->wiki->source |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
111 |
); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
112 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
113 |
foreach ( $matches[3] as $i => $match ) |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
114 |
{ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
115 |
$source = str_replace("{LITEWIKI:$i:$rand_key}", $match, $source); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
116 |
} |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
117 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
118 |
// die('<pre>'.htmlspecialchars($source).'</pre>'); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
119 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
120 |
unset($matches, $source, $rand_key); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
1
diff
changeset
|
121 |
} |
1 | 122 |
} |
123 |
||
124 |
?> |