1027
+ − 1
<?php
+ − 2
+ − 3
/*
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
diff
changeset
+ − 5
* Copyright (C) 2006-2009 Dan Fuhry
1027
+ − 6
*
+ − 7
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ − 8
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ − 9
*
+ − 10
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ − 11
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ − 12
*/
+ − 13
+ − 14
class Carpenter_Render_Xhtml
+ − 15
{
+ − 16
public $rules = array(
+ − 17
'lang' => '',
+ − 18
'templates' => '',
+ − 19
'bold' => '<strong>\\1</strong>',
+ − 20
'italic' => '<em>\\1</em>',
+ − 21
'underline' => '<span style="text-decoration: underline;">\\1</span>',
+ − 22
'externalwithtext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\2</a>',
1106
+ − 23
'externalnotext' => '<a href="\\1" onclick="window.open(this.href); return false;">\\1</a>',
+ − 24
'hr' => '<hr />'
1027
+ − 25
);
+ − 26
+ − 27
public function heading($text, $pieces)
+ − 28
{
+ − 29
foreach ( $pieces as $i => $piece )
+ − 30
{
1096
86feb1c7ca3f
Wiki formatter: heading IDs are now name based ("head:" . sanitize_page_id($text)) instead of tocN.
Dan
diff
changeset
+ − 31
$tocid = sanitize_page_id(trim($piece['text']));
1127
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 32
// (bad) workaround for links in headings
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 33
$tocid = str_replace(array('[', ']'), '', $tocid);
1096
86feb1c7ca3f
Wiki formatter: heading IDs are now name based ("head:" . sanitize_page_id($text)) instead of tocN.
Dan
diff
changeset
+ − 34
$tag = '<h' . $piece['level'] . ' id="head:' . $tocid . '">';
1027
+ − 35
$tag .= trim($piece['text']);
+ − 36
$tag .= '</h' . $piece['level'] . '>';
+ − 37
+ − 38
$text = str_replace(Carpenter::generate_token($i), $tag, $text);
+ − 39
}
+ − 40
+ − 41
return $text;
+ − 42
}
+ − 43
+ − 44
public function multilist($text, $pieces)
+ − 45
{
+ − 46
foreach ( $pieces as $i => $piece )
+ − 47
{
+ − 48
switch($piece['type'])
+ − 49
{
+ − 50
case 'unordered':
+ − 51
default:
+ − 52
$btag = 'ul';
+ − 53
$itag = 'li';
+ − 54
break;
+ − 55
case 'ordered':
+ − 56
$btag = 'ol';
+ − 57
$itag = 'li';
+ − 58
break;
+ − 59
case 'indent':
+ − 60
$btag = 'dl';
+ − 61
$itag = 'dd';
+ − 62
break;
+ − 63
}
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 64
$list = "<_paragraph_bypass><$btag>\n";
1027
+ − 65
$spacing = '';
+ − 66
$depth = 1;
+ − 67
foreach ( $piece['items'] as $j => $item )
+ − 68
{
+ − 69
// most of this just goes into pretty formatting.
+ − 70
// everything else goes into meeting the PITA requirement that if you're going
+ − 71
// another level deep, HTML requires the next level to be INSIDE of the <dd>/<li> tag.
+ − 72
$itemdepth = $item['depth'];
+ − 73
if ( $itemdepth > $depth )
+ − 74
{
+ − 75
while ( $depth < $itemdepth )
+ − 76
{
+ − 77
$spacing .= ' ';
+ − 78
$list .= "{$spacing}<$btag>\n";
+ − 79
$depth++;
+ − 80
}
+ − 81
}
+ − 82
else if ( $itemdepth < $depth )
+ − 83
{
+ − 84
while ( $depth > $itemdepth )
+ − 85
{
+ − 86
$list .= "{$spacing}</$btag>\n";
+ − 87
$spacing = substr($spacing, 4);
+ − 88
$list .= "{$spacing}</$itag>\n";
+ − 89
$spacing = substr($spacing, 4);
+ − 90
$depth--;
+ − 91
}
+ − 92
}
+ − 93
$list .= "{$spacing} <$itag>" . nl2br($item['text']);
+ − 94
if ( ( isset($piece['items'][ ++$j ]) && $piece['items'][ $j ]['depth'] <= $itemdepth ) || !isset($piece['items'][ $j ]) )
+ − 95
{
+ − 96
$list .= "</$itag>\n";
+ − 97
}
+ − 98
else
+ − 99
{
+ − 100
$list .= "\n";
+ − 101
$spacing .= " ";
+ − 102
}
+ − 103
}
+ − 104
while ( $depth > 1 )
+ − 105
{
+ − 106
$list .= "{$spacing}</$btag>\n";
+ − 107
$spacing = substr($spacing, 4);
+ − 108
$list .= "{$spacing}</$itag>\n";
+ − 109
$spacing = substr($spacing, 4);
+ − 110
$depth--;
+ − 111
}
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 112
$list .= "</$btag></_paragraph_bypass>\n";
1027
+ − 113
$text = str_replace(Carpenter::generate_token($i), $list, $text);
+ − 114
}
+ − 115
return $text;
+ − 116
}
+ − 117
1078
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 118
public function blockquote($text)
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 119
{
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 120
return $text;
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 121
}
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 122
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 123
public function blockquotepost($text, $rand_id)
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 124
{
1078
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 125
$text = strtr($text, array(
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 126
"<p>{blockquote:$rand_id}<br />" => '<blockquote>',
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 127
"<br />\n{/blockquote:$rand_id}</p>" => '</blockquote>',
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 128
"{blockquote:$rand_id}" => '<blockquote>',
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 129
"{/blockquote:$rand_id}" => '</blockquote>'
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 130
));
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 131
$text = strtr($text, array(
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 132
"<blockquote><br />" => '<blockquote>',
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 133
"</blockquote><br />" => '</blockquote>'
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 134
));
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 135
return $text;
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 136
}
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 137
1027
+ − 138
public function paragraph($text, $pieces)
+ − 139
{
+ − 140
foreach ( $pieces as $i => $piece )
+ − 141
{
+ − 142
$text = str_replace(Carpenter::generate_token($i), '<p>' . nl2br($piece) . '</p>', $text);
+ − 143
}
+ − 144
+ − 145
return $text;
+ − 146
}
1156
+ − 147
+ − 148
public function mailtonotext($pieces)
+ − 149
{
+ − 150
$pieces[2] = $pieces[1];
+ − 151
return $this->mailtowithtext($pieces);
+ − 152
}
+ − 153
+ − 154
public function mailtowithtext($pieces)
+ − 155
{
+ − 156
global $email;
+ − 157
return $email->encryptEmail($pieces[1], '', '', $pieces[2]);
+ − 158
}
1174
+ − 159
+ − 160
public function code($match)
+ − 161
{
+ − 162
return '<pre>' . htmlspecialchars($match[0]) . '</pre>';
+ − 163
}
1027
+ − 164
}
+ − 165
+ − 166
// Alias internal link parsing to RenderMan's method
+ − 167
function parser_mediawiki_xhtml_internallink($text)
+ − 168
{
+ − 169
return RenderMan::parse_internal_links($text);
+ − 170
}
+ − 171