|
1 <?php |
|
2 |
|
3 /* |
|
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
5 * Version 1.1.6 (Caoineag beta 1) |
|
6 * Copyright (C) 2006-2008 Dan Fuhry |
|
7 * |
|
8 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 * |
|
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 */ |
|
14 |
|
15 class Carpenter_Render_Xhtml |
|
16 { |
|
17 public $rules = array( |
|
18 'lang' => '', |
|
19 'templates' => '', |
|
20 'bold' => '<strong>\\1</strong>', |
|
21 'italic' => '<em>\\1</em>', |
|
22 'underline' => '<span style="text-decoration: underline;">\\1</span>', |
|
23 'externalwithtext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\2</a>', |
|
24 'externalnotext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\1</a>', |
|
25 ); |
|
26 |
|
27 public function heading($text, $pieces) |
|
28 { |
|
29 static $tocid = -1; |
|
30 foreach ( $pieces as $i => $piece ) |
|
31 { |
|
32 $tocid++; |
|
33 $tag = '<h' . $piece['level'] . ' id="toc' . $tocid . '">'; |
|
34 $tag .= trim($piece['text']); |
|
35 $tag .= '</h' . $piece['level'] . '>'; |
|
36 |
|
37 $text = str_replace(Carpenter::generate_token($i), $tag, $text); |
|
38 } |
|
39 |
|
40 return $text; |
|
41 } |
|
42 |
|
43 public function multilist($text, $pieces) |
|
44 { |
|
45 foreach ( $pieces as $i => $piece ) |
|
46 { |
|
47 switch($piece['type']) |
|
48 { |
|
49 case 'unordered': |
|
50 default: |
|
51 $btag = 'ul'; |
|
52 $itag = 'li'; |
|
53 break; |
|
54 case 'ordered': |
|
55 $btag = 'ol'; |
|
56 $itag = 'li'; |
|
57 break; |
|
58 case 'indent': |
|
59 $btag = 'dl'; |
|
60 $itag = 'dd'; |
|
61 break; |
|
62 } |
|
63 $list = "<$btag><_paragraph_bypass>\n"; |
|
64 $spacing = ''; |
|
65 $depth = 1; |
|
66 foreach ( $piece['items'] as $j => $item ) |
|
67 { |
|
68 // most of this just goes into pretty formatting. |
|
69 // everything else goes into meeting the PITA requirement that if you're going |
|
70 // another level deep, HTML requires the next level to be INSIDE of the <dd>/<li> tag. |
|
71 $itemdepth = $item['depth']; |
|
72 if ( $itemdepth > $depth ) |
|
73 { |
|
74 while ( $depth < $itemdepth ) |
|
75 { |
|
76 $spacing .= ' '; |
|
77 $list .= "{$spacing}<$btag>\n"; |
|
78 $depth++; |
|
79 } |
|
80 } |
|
81 else if ( $itemdepth < $depth ) |
|
82 { |
|
83 while ( $depth > $itemdepth ) |
|
84 { |
|
85 $list .= "{$spacing}</$btag>\n"; |
|
86 $spacing = substr($spacing, 4); |
|
87 $list .= "{$spacing}</$itag>\n"; |
|
88 $spacing = substr($spacing, 4); |
|
89 $depth--; |
|
90 } |
|
91 } |
|
92 $list .= "{$spacing} <$itag>" . nl2br($item['text']); |
|
93 if ( ( isset($piece['items'][ ++$j ]) && $piece['items'][ $j ]['depth'] <= $itemdepth ) || !isset($piece['items'][ $j ]) ) |
|
94 { |
|
95 $list .= "</$itag>\n"; |
|
96 } |
|
97 else |
|
98 { |
|
99 $list .= "\n"; |
|
100 $spacing .= " "; |
|
101 } |
|
102 } |
|
103 while ( $depth > 1 ) |
|
104 { |
|
105 $list .= "{$spacing}</$btag>\n"; |
|
106 $spacing = substr($spacing, 4); |
|
107 $list .= "{$spacing}</$itag>\n"; |
|
108 $spacing = substr($spacing, 4); |
|
109 $depth--; |
|
110 } |
|
111 $list .= "</_paragraph_bypass></$btag>\n"; |
|
112 $text = str_replace(Carpenter::generate_token($i), $list, $text); |
|
113 } |
|
114 return $text; |
|
115 } |
|
116 |
|
117 public function paragraph($text, $pieces) |
|
118 { |
|
119 foreach ( $pieces as $i => $piece ) |
|
120 { |
|
121 $text = str_replace(Carpenter::generate_token($i), '<p>' . nl2br($piece) . '</p>', $text); |
|
122 } |
|
123 |
|
124 return $text; |
|
125 } |
|
126 } |
|
127 |
|
128 // Alias internal link parsing to RenderMan's method |
|
129 function parser_mediawiki_xhtml_internallink($text) |
|
130 { |
|
131 return RenderMan::parse_internal_links($text); |
|
132 } |
|
133 |