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