0
+ − 1
<?php
+ − 2
/**
+ − 3
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 4
* @Version 1.0 (Banshee)
0
+ − 5
* Copyright (C) 2006-2007 Dan Fuhry
+ − 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
+ − 15
// Set up gzip encoding before any output is sent
+ − 16
15
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 17
$aggressive_optimize_html = false;
0
+ − 18
+ − 19
global $do_gzip;
+ − 20
$do_gzip = false;
+ − 21
+ − 22
if(isset($_SERVER['PATH_INFO'])) $v = $_SERVER['PATH_INFO'];
+ − 23
elseif(isset($_GET['title'])) $v = $_GET['title'];
+ − 24
else $v = '';
+ − 25
+ − 26
error_reporting(E_ALL);
+ − 27
+ − 28
// if(!strstr($v, 'CSS') && !strstr($v, 'UploadFile') && !strstr($v, 'DownloadFile')) // These pages are blacklisted because we can't have debugConsole's HTML output disrupting the flow of header() calls and whatnot
+ − 29
// {
+ − 30
// $do_gzip = ( function_exists('gzcompress') && ( isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') ) ) ? true : false;
+ − 31
// // Uncomment the following line to enable debugConsole (requires PHP 5 or later)
+ − 32
// // define('ENANO_DEBUG', '');
+ − 33
// }
+ − 34
+ − 35
if(defined('ENANO_DEBUG')) $do_gzip = false;
+ − 36
+ − 37
if($aggressive_optimize_html || $do_gzip)
+ − 38
{
+ − 39
ob_start();
+ − 40
}
+ − 41
+ − 42
require('includes/common.php');
+ − 43
+ − 44
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 45
+ − 46
if(!isset($_GET['do'])) $_GET['do'] = 'view';
+ − 47
switch($_GET['do'])
+ − 48
{
+ − 49
default:
+ − 50
die_friendly('Invalid action', '<p>The action "'.$_GET['do'].'" is not defined. Return to <a href="'.makeUrl($paths->page).'">viewing this page\'s text</a>.</p>');
+ − 51
break;
+ − 52
case 'view':
+ − 53
// echo PageUtils::getpage($paths->page, true, ( (isset($_GET['oldid'])) ? $_GET['oldid'] : false ));
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 54
$rev_id = ( (isset($_GET['oldid'])) ? intval($_GET['oldid']) : 0 );
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 55
$page = new PageProcessor( $paths->cpage['urlname_nons'], $paths->namespace, $rev_id );
0
+ − 56
$page->send_headers = true;
+ − 57
$page->send();
+ − 58
break;
+ − 59
case 'comments':
+ − 60
$template->header();
+ − 61
$sub = ( isset ($_GET['sub']) ) ? $_GET['sub'] : false;
+ − 62
switch($sub)
+ − 63
{
+ − 64
case 'admin':
+ − 65
default:
+ − 66
$act = ( isset ($_GET['action']) ) ? $_GET['action'] : false;
+ − 67
$id = ( isset ($_GET['id']) ) ? intval($_GET['id']) : -1;
+ − 68
echo PageUtils::comments_html($paths->cpage['urlname_nons'], $paths->namespace, $act, Array('id'=>$id));
+ − 69
break;
+ − 70
case 'postcomment':
+ − 71
if(empty($_POST['name']) ||
+ − 72
empty($_POST['subj']) ||
+ − 73
empty($_POST['text'])
+ − 74
) { echo 'Invalid request'; break; }
+ − 75
$cid = ( isset($_POST['captcha_id']) ) ? $_POST['captcha_id'] : false;
+ − 76
$cin = ( isset($_POST['captcha_input']) ) ? $_POST['captcha_input'] : false;
+ − 77
PageUtils::addcomment($paths->cpage['urlname_nons'], $paths->namespace, $_POST['name'], $_POST['subj'], $_POST['text'], $cin, $cid); // All filtering, etc. is handled inside this method
+ − 78
echo PageUtils::comments_html($paths->cpage['urlname_nons'], $paths->namespace);
+ − 79
break;
+ − 80
case 'editcomment':
+ − 81
if(!isset($_GET['id']) || ( isset($_GET['id']) && !preg_match('#^([0-9]+)$#', $_GET['id']) )) { echo '<p>Invalid comment ID</p>'; break; }
+ − 82
$q = $db->sql_query('SELECT subject,comment_data,comment_id FROM '.table_prefix.'comments WHERE comment_id='.$_GET['id']);
+ − 83
if(!$q) $db->_die('The comment data could not be selected.');
+ − 84
$row = $db->fetchrow();
+ − 85
$db->free_result();
+ − 86
echo '<form action="'.makeUrl($paths->page, 'do=comments&sub=savecomment').'" method="post">';
+ − 87
echo "<br /><div class='tblholder'><table border='0' width='100%' cellspacing='1' cellpadding='4'>
+ − 88
<tr><td class='row1'>Subject:</td><td class='row1'><input type='text' name='subj' value='{$row['subject']}' /></td></tr>
+ − 89
<tr><td class='row2'>Comment:</td><td class='row2'><textarea rows='10' cols='40' style='width: 98%;' name='text'>{$row['comment_data']}</textarea></td></tr>
+ − 90
<tr><td class='row1' colspan='2' class='row1' style='text-align: center;'><input type='hidden' name='id' value='{$row['comment_id']}' /><input type='submit' value='Save Changes' /></td></tr>
+ − 91
</table></div>";
+ − 92
echo '</form>';
+ − 93
break;
+ − 94
case 'savecomment':
+ − 95
if(empty($_POST['subj']) || empty($_POST['text'])) { echo '<p>Invalid request</p>'; break; }
+ − 96
$r = PageUtils::savecomment_neater($paths->cpage['urlname_nons'], $paths->namespace, $_POST['subj'], $_POST['text'], (int)$_POST['id']);
+ − 97
if($r != 'good') { echo "<pre>$r</pre>"; break; }
+ − 98
echo PageUtils::comments_html($paths->cpage['urlname_nons'], $paths->namespace);
+ − 99
break;
+ − 100
case 'deletecomment':
+ − 101
if(!empty($_GET['id']))
+ − 102
{
+ − 103
PageUtils::deletecomment_neater($paths->cpage['urlname_nons'], $paths->namespace, (int)$_GET['id']);
+ − 104
}
+ − 105
echo PageUtils::comments_html($paths->cpage['urlname_nons'], $paths->namespace);
+ − 106
break;
+ − 107
}
+ − 108
$template->footer();
+ − 109
break;
+ − 110
case 'edit':
+ − 111
if(isset($_POST['_cancel'])) { header('Location: '.makeUrl($paths->page)); echo '<html><head><title>Redirecting...</title></head><body>If you haven\'t been redirected yet, <a href="'.makeUrl($paths->page).'">click here</a>.'; break; }
+ − 112
if(isset($_POST['_save'])) {
+ − 113
$e = PageUtils::savepage($paths->cpage['urlname_nons'], $paths->namespace, $_POST['page_text'], $_POST['edit_summary'], isset($_POST['minor']));
+ − 114
header('Location: '.makeUrl($paths->page)); echo '<html><head><title>Redirecting...</title></head><body>If you haven\'t been redirected yet, <a href="'.makeUrl($paths->page).'">click here</a>.'; break;
+ − 115
}
+ − 116
$template->header();
+ − 117
if(isset($_POST['_preview']))
+ − 118
{
+ − 119
$text = $_POST['page_text'];
+ − 120
echo PageUtils::genPreview($_POST['page_text']);
+ − 121
}
+ − 122
else $text = RenderMan::getPage($paths->cpage['urlname_nons'], $paths->namespace, 0, false, false, false, false);
+ − 123
echo '
+ − 124
<form action="'.makeUrl($paths->page, 'do=edit').'" method="post" enctype="multipart/form-data">
+ − 125
<br />
+ − 126
<textarea name="page_text" rows="20" cols="60" style="width: 97%;">'.$text.'</textarea><br />
+ − 127
<br />
+ − 128
';
+ − 129
if($paths->wiki_mode)
+ − 130
echo 'Edit summary: <input name="edit_summary" type="text" size="40" /><br /><label><input type="checkbox" name="minor" /> This is a minor edit</label><br />';
+ − 131
echo '<br />
+ − 132
<input type="submit" name="_save" value="Save changes" style="font-weight: bold;" />
+ − 133
<input type="submit" name="_preview" value="Preview changes" />
+ − 134
<input type="submit" name="_revert" value="Revert changes" />
+ − 135
<input type="submit" name="_cancel" value="Cancel" />
+ − 136
</form>
+ − 137
';
+ − 138
$template->footer();
+ − 139
break;
+ − 140
case 'viewsource':
+ − 141
$template->header();
+ − 142
$text = RenderMan::getPage($paths->cpage['urlname_nons'], $paths->namespace, 0, false, false, false, false);
+ − 143
echo '
+ − 144
<form action="'.makeUrl($paths->page, 'do=edit').'" method="post">
+ − 145
<br />
+ − 146
<textarea readonly="readonly" name="page_text" rows="20" cols="60" style="width: 97%;">'.$text.'</textarea>';
+ − 147
echo '<br />
+ − 148
<input type="submit" name="_cancel" value="Close viewer" />
+ − 149
</form>
+ − 150
';
+ − 151
$template->footer();
+ − 152
break;
+ − 153
case 'history':
+ − 154
$hist = PageUtils::histlist($paths->cpage['urlname_nons'], $paths->namespace);
+ − 155
$template->header();
+ − 156
echo $hist;
+ − 157
$template->footer();
+ − 158
break;
+ − 159
case 'rollback':
+ − 160
$id = (isset($_GET['id'])) ? $_GET['id'] : false;
+ − 161
if(!$id || !preg_match('#^([0-9]+)$#', $id)) die_friendly('Invalid action ID', '<p>The URL parameter "id" is not an integer. Exiting to prevent nasties like SQL injection, etc.</p>');
+ − 162
$rb = PageUtils::rollback( (int) $id );
+ − 163
$template->header();
+ − 164
echo '<p>'.$rb.' <a href="'.makeUrl($paths->page).'">Return to the page</a>.</p>';
+ − 165
$template->footer();
+ − 166
break;
+ − 167
case 'catedit':
+ − 168
if(isset($_POST['__enanoSaveButton']))
+ − 169
{
+ − 170
unset($_POST['__enanoSaveButton']);
+ − 171
$val = PageUtils::catsave($paths->cpage['urlname_nons'], $paths->namespace, $_POST);
+ − 172
if($val == 'GOOD')
+ − 173
{
+ − 174
header('Location: '.makeUrl($paths->page)); echo '<html><head><title>Redirecting...</title></head><body>If you haven\'t been redirected yet, <a href="'.makeUrl($paths->page).'">click here</a>.'; break;
+ − 175
} else {
+ − 176
die_friendly('Error saving category information', '<p>'.$val.'</p>');
+ − 177
}
+ − 178
}
+ − 179
elseif(isset($_POST['__enanoCatCancel']))
+ − 180
{
+ − 181
header('Location: '.makeUrl($paths->page)); echo '<html><head><title>Redirecting...</title></head><body>If you haven\'t been redirected yet, <a href="'.makeUrl($paths->page).'">click here</a>.'; break;
+ − 182
}
+ − 183
$template->header();
+ − 184
$c = PageUtils::catedit_raw($paths->cpage['urlname_nons'], $paths->namespace);
+ − 185
echo $c[1];
+ − 186
$template->footer();
+ − 187
break;
+ − 188
case 'moreoptions':
+ − 189
$template->header();
+ − 190
echo '<div class="pagebar" id="pagebarpopup2" style="width: 150px; padding: 0;">'.$template->tpl_strings['TOOLBAR_EXTRAS'].'</div>';
+ − 191
$template->footer();
+ − 192
break;
+ − 193
case 'protect':
+ − 194
if (!isset($_REQUEST['level'])) die_friendly('Invalid request', '<p>No protection level specified</p>');
+ − 195
if(!empty($_POST['reason']))
+ − 196
{
+ − 197
if(!preg_match('#^([0-2]*){1}$#', $_POST['level'])) die_friendly('Error protecting page', '<p>Request validation failed</p>');
+ − 198
PageUtils::protect($paths->cpage['urlname_nons'], $paths->namespace, intval($_POST['level']), $_POST['reason']);
+ − 199
die_friendly('Page protected', '<p>The protection setting has been applied. <a href="'.makeUrl($paths->page).'">Return to the page</a>.</p>');
+ − 200
}
+ − 201
$template->header();
+ − 202
?>
+ − 203
<form action="<?php echo makeUrl($paths->page, 'do=protect'); ?>" method="post">
+ − 204
<input type="hidden" name="level" value="<?php echo $_REQUEST['level']; ?>" />
+ − 205
<?php if(isset($_POST['reason'])) echo '<p style="color: red;">Error: you must enter a reason for protecting this page.</p>'; ?>
+ − 206
<p>Reason for protecting the page:</p>
+ − 207
<p><input type="text" name="reason" size="40" /><br />
+ − 208
Protecion level to be applied: <b><?php
+ − 209
switch($_REQUEST['level'])
+ − 210
{
+ − 211
case '0':
+ − 212
echo 'No protection';
+ − 213
break;
+ − 214
case '1':
+ − 215
echo 'Full protection';
+ − 216
break;
+ − 217
case '2':
+ − 218
echo 'Semi-protection';
+ − 219
break;
+ − 220
default:
+ − 221
echo 'None;</b> Warning: request validation will fail after clicking submit<b>';
+ − 222
}
+ − 223
?></b></p>
+ − 224
<p><input type="submit" value="Protect page" style="font-weight: bold;" /></p>
+ − 225
</form>
+ − 226
<?php
+ − 227
$template->footer();
+ − 228
break;
+ − 229
case 'rename':
+ − 230
if(!empty($_POST['newname']))
+ − 231
{
+ − 232
$r = PageUtils::rename($paths->cpage['urlname_nons'], $paths->namespace, $_POST['newname']);
+ − 233
die_friendly('Page renamed', '<p>'.nl2br($r).' <a href="'.makeUrl($paths->page).'">Return to the page</a>.</p>');
+ − 234
}
+ − 235
$template->header();
+ − 236
?>
+ − 237
<form action="<?php echo makeUrl($paths->page, 'do=rename'); ?>" method="post">
+ − 238
<?php if(isset($_POST['newname'])) echo '<p style="color: red;">Error: you must enter a new name for this page.</p>'; ?>
+ − 239
<p>Please enter a new name for this page:</p>
+ − 240
<p><input type="text" name="newname" size="40" /></p>
+ − 241
<p><input type="submit" value="Rename page" style="font-weight: bold;" /></p>
+ − 242
</form>
+ − 243
<?php
+ − 244
$template->footer();
+ − 245
break;
+ − 246
case 'flushlogs':
+ − 247
if(!$session->get_permissions('clear_logs')) die_friendly('Access denied', '<p>Flushing the logs for a page <u>requires</u> administrative rights.</p>');
+ − 248
if(isset($_POST['_downthejohn']))
+ − 249
{
+ − 250
$template->header();
+ − 251
$result = PageUtils::flushlogs($paths->cpage['urlname_nons'], $paths->namespace);
+ − 252
echo '<p>'.$result.' <a href="'.makeUrl($paths->page).'">Return to the page</a>.</p>';
+ − 253
$template->footer();
+ − 254
break;
+ − 255
}
+ − 256
$template->header();
+ − 257
?>
+ − 258
<form action="<?php echo makeUrl($paths->page, 'do=flushlogs'); ?>" method="post">
+ − 259
<h3>You are about to <span style="color: red;">destroy</span> all logged edits and actions on this page.</h3>
+ − 260
<p>Unlike deleting or editing this page, this action is <u>not reversible</u>! You should only do this if you are desperate for
+ − 261
database space.</p>
+ − 262
<p>Do you really want to continue?</p>
+ − 263
<p><input type="submit" name="_downthejohn" value="Flush logs" style="color: red; font-weight: bold;" /></p>
+ − 264
</form>
+ − 265
<?php
+ − 266
$template->footer();
+ − 267
break;
+ − 268
case 'delvote':
+ − 269
if(isset($_POST['_ballotbox']))
+ − 270
{
+ − 271
$template->header();
+ − 272
$result = PageUtils::delvote($paths->cpage['urlname_nons'], $paths->namespace);
+ − 273
echo '<p>'.$result.' <a href="'.makeUrl($paths->page).'">Return to the page</a>.</p>';
+ − 274
$template->footer();
+ − 275
break;
+ − 276
}
+ − 277
$template->header();
+ − 278
?>
+ − 279
<form action="<?php echo makeUrl($paths->page, 'do=delvote'); ?>" method="post">
+ − 280
<h3>Your vote counts.</h3>
+ − 281
<p>If you think that this page is not relavent to the content on this site, or if it looks like this page was only created in
+ − 282
an attempt to spam the site, you can request that this page be deleted by an administrator.</p>
+ − 283
<p>After you vote, you should leave a comment explaining the reason for your vote, especially if you are the first person to
+ − 284
vote against this page.</p>
+ − 285
<p>So far, <?php echo ( $paths->cpage['delvotes'] == 1 ) ? $paths->cpage['delvotes'] . ' person has' : $paths->cpage['delvotes'] . ' people have'; ?> voted to delete this page.</p>
+ − 286
<p><input type="submit" name="_ballotbox" value="Vote to delete this page" /></p>
+ − 287
</form>
+ − 288
<?php
+ − 289
$template->footer();
+ − 290
break;
+ − 291
case 'resetvotes':
+ − 292
if(!$session->get_permissions('vote_reset')) die_friendly('Access denied', '<p>Resetting the deletion votes against this page <u>requires</u> admin rights.</p>');
+ − 293
if(isset($_POST['_youmaylivealittlelonger']))
+ − 294
{
+ − 295
$template->header();
+ − 296
$result = PageUtils::resetdelvotes($paths->cpage['urlname_nons'], $paths->namespace);
+ − 297
echo '<p>'.$result.' <a href="'.makeUrl($paths->page).'">Return to the page</a>.</p>';
+ − 298
$template->footer();
+ − 299
break;
+ − 300
}
+ − 301
$template->header();
+ − 302
?>
+ − 303
<form action="<?php echo makeUrl($paths->page, 'do=resetvotes'); ?>" method="post">
+ − 304
<p>This action will reset the number of votes against this page to zero. Are you sure you want to do this?</p>
+ − 305
<p><input type="submit" name="_youmaylivealittlelonger" value="Reset votes" /></p>
+ − 306
</form>
+ − 307
<?php
+ − 308
$template->footer();
+ − 309
break;
+ − 310
case 'deletepage':
+ − 311
if(!$session->get_permissions('delete_page')) die_friendly('Access denied', '<p>Deleting pages <u>requires</u> admin rights.</p>');
+ − 312
if(isset($_POST['_adiossucker']))
+ − 313
{
28
+ − 314
$reason = ( isset($_POST['reason']) ) ? $_POST['reason'] : false;
+ − 315
if ( empty($reason) )
+ − 316
$error = 'Please enter a reason for deleting this page.';
+ − 317
else
+ − 318
{
+ − 319
$template->header();
+ − 320
$result = PageUtils::deletepage($paths->cpage['urlname_nons'], $paths->namespace, $reason);
+ − 321
echo '<p>'.$result.' <a href="'.makeUrl($paths->page).'">Return to the page</a>.</p>';
+ − 322
$template->footer();
+ − 323
break;
+ − 324
}
0
+ − 325
}
+ − 326
$template->header();
+ − 327
?>
+ − 328
<form action="<?php echo makeUrl($paths->page, 'do=deletepage'); ?>" method="post">
+ − 329
<h3>You are about to <span style="color: red;">destroy</span> this page.</h3>
+ − 330
<p>While the deletion of the page itself is completely reversible, it is impossible to recover any comments or category information on this page. If this is a file page, the file along with all older revisions of it will be permanently deleted. Also, any custom information that this page is tagged with, such as a custom name, protection status, or additional settings such as whether to allow comments, will be permanently lost.</p>
+ − 331
<p>Are you <u>absolutely sure</u> that you want to continue?<br />
+ − 332
You will not be asked again.</p>
28
+ − 333
<?php if ( isset($error) ) echo "<p>$error</p>"; ?>
+ − 334
<p>Reason for deleting: <input type="text" name="reason" size="50" /></p>
0
+ − 335
<p><input type="submit" name="_adiossucker" value="Delete this page" style="color: red; font-weight: bold;" /></p>
+ − 336
</form>
+ − 337
<?php
+ − 338
$template->footer();
+ − 339
break;
+ − 340
case 'setwikimode':
+ − 341
if(!$session->get_permissions('set_wiki_mode')) die_friendly('Access denied', '<p>Changing the wiki mode setting <u>requires</u> admin rights.</p>');
+ − 342
if(!isset($_GET['level']) || ( isset($_GET['level']) && !preg_match('#^([0-9])$#', $_GET['level']))) die_friendly('Invalid request', '<p>Level not specified</p>');
+ − 343
$template->header();
+ − 344
$template->footer();
+ − 345
break;
+ − 346
case 'diff':
+ − 347
$template->header();
+ − 348
$id1 = ( isset($_GET['diff1']) ) ? (int)$_GET['diff1'] : false;
+ − 349
$id2 = ( isset($_GET['diff2']) ) ? (int)$_GET['diff2'] : false;
+ − 350
if(!$id1 || !$id2) { echo '<p>Invalid request.</p>'; $template->footer(); break; }
+ − 351
if(!preg_match('#^([0-9]+)$#', (string)$_GET['diff1']) ||
+ − 352
!preg_match('#^([0-9]+)$#', (string)$_GET['diff2'] )) { echo '<p>SQL injection attempt</p>'; $template->footer(); break; }
+ − 353
echo PageUtils::pagediff($paths->cpage['urlname_nons'], $paths->namespace, $id1, $id2);
+ − 354
$template->footer();
+ − 355
break;
+ − 356
case 'aclmanager':
+ − 357
$data = ( isset($_POST['data']) ) ? $_POST['data'] : Array('mode' => 'listgroups');
+ − 358
PageUtils::aclmanager($data);
+ − 359
break;
+ − 360
}
+ − 361
+ − 362
//
+ − 363
// Optimize HTML by replacing newlines with spaces (excludes <pre>, <script>, and <style> blocks)
+ − 364
//
+ − 365
if ($aggressive_optimize_html)
+ − 366
{
+ − 367
// Load up the HTML
+ − 368
$html = ob_get_contents();
+ − 369
ob_end_clean();
+ − 370
+ − 371
// Which tags to strip - you can change this if needed
+ − 372
$strip_tags = Array('pre', 'script', 'style', 'enano:no-opt');
+ − 373
$strip_tags = implode('|', $strip_tags);
+ − 374
+ − 375
// Strip out the tags and replace with placeholders
+ − 376
preg_match_all("#<($strip_tags)(.*?)>(.*?)</($strip_tags)>#is", $html, $matches);
+ − 377
$seed = md5(microtime() . mt_rand()); // Random value used for placeholders
+ − 378
for ($i = 0;$i < sizeof($matches[1]); $i++)
+ − 379
{
+ − 380
$html = str_replace("<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
+ − 381
}
+ − 382
+ − 383
// Finally, process the HTML
+ − 384
$html = preg_replace("#\n([ ]*)#", " ", $html);
+ − 385
+ − 386
// Remove annoying spaces between tags
+ − 387
$html = preg_replace("#>([ ]*?){2,}<#", "> <", $html);
+ − 388
+ − 389
// Re-insert untouchable tags
+ − 390
for ($i = 0;$i < sizeof($matches[1]); $i++)
+ − 391
{
+ − 392
$html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
+ − 393
}
+ − 394
+ − 395
// Remove <enano:no-opt> blocks (can be used by themes that don't want their HTML optimized)
+ − 396
$html = preg_replace('#<(\/|)enano:no-opt(.*?)>#', '', $html);
+ − 397
+ − 398
// Tell snoopish users what's going on
+ − 399
$html = str_replace('<html>', "\n<!-- NOTE: This HTML document has been Aggressively Optimized(TM) by Enano to make page loading faster. -->\n<html>", $html);
+ − 400
+ − 401
// Re-enable output buffering to allow the Gzip function (below) to work
+ − 402
ob_start();
+ − 403
+ − 404
// Done, send it to the user
+ − 405
echo( $html );
+ − 406
}
+ − 407
+ − 408
//
+ − 409
// Compress buffered output if required and send to browser
+ − 410
//
+ − 411
if ( $do_gzip )
+ − 412
{
+ − 413
//
+ − 414
// Copied from phpBB, which was in turn borrowed from php.net
+ − 415
//
+ − 416
$gzip_contents = ob_get_contents();
+ − 417
ob_end_clean();
+ − 418
+ − 419
$gzip_size = strlen($gzip_contents);
+ − 420
$gzip_crc = crc32($gzip_contents);
+ − 421
+ − 422
$gzip_contents = gzcompress($gzip_contents, 9);
+ − 423
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
+ − 424
+ − 425
header('Content-encoding: gzip');
+ − 426
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
+ − 427
echo $gzip_contents;
+ − 428
echo pack('V', $gzip_crc);
+ − 429
echo pack('V', $gzip_size);
+ − 430
}
+ − 431
+ − 432
$db->close();
+ − 433
+ − 434
?>