1
+ − 1
<?php
+ − 2
+ − 3
/*
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
142
ca9118d9c0f2
Rebrand as 1.0.2 (Coblynau); internal links are now parsed by RenderMan::parse_internal_links()
Dan
diff
changeset
+ − 5
* Version 1.0.2 (Coblynau)
1
+ − 6
* Copyright (C) 2006-2007 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
*/
22
+ − 14
+ − 15
/**
+ − 16
* Fetch a value from the site configuration.
+ − 17
* @param string The identifier of the value ("site_name" etc.)
+ − 18
* @return string Configuration value, or bool(false) if the value is not set
+ − 19
*/
+ − 20
+ − 21
function getConfig($n)
+ − 22
{
1
+ − 23
global $enano_config;
22
+ − 24
if ( isset( $enano_config[ $n ] ) )
+ − 25
{
+ − 26
return $enano_config[$n];
+ − 27
}
+ − 28
else
+ − 29
{
+ − 30
return false;
+ − 31
}
1
+ − 32
}
+ − 33
22
+ − 34
/**
+ − 35
* Update or change a configuration value.
+ − 36
* @param string The identifier of the value ("site_name" etc.)
+ − 37
* @param string The new value
+ − 38
* @return null
+ − 39
*/
+ − 40
+ − 41
function setConfig($n, $v)
+ − 42
{
76
+ − 43
1
+ − 44
global $enano_config, $db;
+ − 45
$enano_config[$n] = $v;
+ − 46
$v = $db->escape($v);
76
+ − 47
22
+ − 48
$e = $db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';');
+ − 49
if ( !$e )
+ − 50
{
+ − 51
$db->_die('Error during generic setConfig() call row deletion.');
+ − 52
}
76
+ − 53
22
+ − 54
$e = $db->sql_query('INSERT INTO '.table_prefix.'config(config_name, config_value) VALUES(\''.$n.'\', \''.$v.'\')');
+ − 55
if ( !$e )
+ − 56
{
+ − 57
$db->_die('Error during generic setConfig() call row insertion.');
+ − 58
}
1
+ − 59
}
+ − 60
22
+ − 61
/**
+ − 62
* Create a URI for an internal link.
+ − 63
* @param string The full identifier of the page to link to (Special:Administration)
+ − 64
* @param string The GET query string to append
+ − 65
* @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe
+ − 66
* @return string
+ − 67
*/
+ − 68
1
+ − 69
function makeUrl($t, $query = false, $escape = false)
+ − 70
{
+ − 71
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 72
$flags = '';
+ − 73
$sep = urlSeparator;
91
+ − 74
$t = sanitize_page_id($t);
22
+ − 75
if ( isset($_GET['printable'] ) )
+ − 76
{
+ − 77
$flags .= $sep . 'printable=yes';
+ − 78
$sep = '&';
+ − 79
}
+ − 80
if ( isset($_GET['theme'] ) )
+ − 81
{
+ − 82
$flags .= $sep . 'theme='.$session->theme;
+ − 83
$sep = '&';
+ − 84
}
+ − 85
if ( isset($_GET['style'] ) ) {
76
+ − 86
$flags .= $sep . 'style='.$session->style;
22
+ − 87
$sep = '&';
+ − 88
}
76
+ − 89
1
+ − 90
$url = $session->append_sid(contentPath.$t.$flags);
+ − 91
if($query)
+ − 92
{
+ − 93
$sep = strstr($url, '?') ? '&' : '?';
+ − 94
$url = $url . $sep . $query;
+ − 95
}
76
+ − 96
1
+ − 97
return ($escape) ? htmlspecialchars($url) : $url;
+ − 98
}
+ − 99
22
+ − 100
/**
+ − 101
* Create a URI for an internal link, and be namespace-friendly. Watch out for this one because it's different from most other Enano functions, in that the namespace is the first parameter.
+ − 102
* @param string The namespace ID
+ − 103
* @param string The page ID
+ − 104
* @param string The GET query string to append
+ − 105
* @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe
+ − 106
* @return string
+ − 107
*/
+ − 108
1
+ − 109
function makeUrlNS($n, $t, $query = false, $escape = false)
+ − 110
{
+ − 111
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 112
$flags = '';
76
+ − 113
1
+ − 114
if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
+ − 115
{
22
+ − 116
$sep = urlSeparator;
1
+ − 117
}
+ − 118
else
+ − 119
{
22
+ − 120
$sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?';
+ − 121
}
+ − 122
if ( isset( $_GET['printable'] ) ) {
+ − 123
$flags .= $sep . 'printable';
+ − 124
$sep = '&';
+ − 125
}
76
+ − 126
if ( isset( $_GET['theme'] ) )
22
+ − 127
{
+ − 128
$flags .= $sep . 'theme='.$session->theme;
+ − 129
$sep = '&';
+ − 130
}
+ − 131
if ( isset( $_GET['style'] ) )
+ − 132
{
+ − 133
$flags .= $sep . 'style='.$session->style;
+ − 134
$sep = '&';
+ − 135
}
76
+ − 136
22
+ − 137
if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
+ − 138
{
+ − 139
$url = contentPath . $paths->nslist[$n] . $t . $flags;
+ − 140
}
+ − 141
else
+ − 142
{
+ − 143
// If the path manager hasn't been initted yet, take an educated guess at what the URI should be
+ − 144
$url = contentPath . $n . ':' . $t . $flags;
1
+ − 145
}
76
+ − 146
1
+ − 147
if($query)
+ − 148
{
76
+ − 149
if(strstr($url, '?'))
22
+ − 150
{
+ − 151
$sep = '&';
+ − 152
}
+ − 153
else
+ − 154
{
+ − 155
$sep = '?';
+ − 156
}
1
+ − 157
$url = $url . $sep . $query . $flags;
+ − 158
}
76
+ − 159
1
+ − 160
if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
+ − 161
{
+ − 162
$url = $session->append_sid($url);
+ − 163
}
76
+ − 164
1
+ − 165
return ($escape) ? htmlspecialchars($url) : $url;
+ − 166
}
+ − 167
22
+ − 168
/**
+ − 169
* Create a URI for an internal link, be namespace-friendly, and add http://hostname/scriptpath to the beginning if possible. Watch out for this one because it's different from most other Enano functions, in that the namespace is the first parameter.
+ − 170
* @param string The namespace ID
+ − 171
* @param string The page ID
+ − 172
* @param string The GET query string to append
+ − 173
* @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe
+ − 174
* @return string
+ − 175
*/
+ − 176
1
+ − 177
function makeUrlComplete($n, $t, $query = false, $escape = false)
+ − 178
{
+ − 179
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 180
$flags = '';
76
+ − 181
22
+ − 182
if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
+ − 183
{
+ − 184
$sep = urlSeparator;
+ − 185
}
+ − 186
else
+ − 187
{
+ − 188
$sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?';
+ − 189
}
+ − 190
if ( isset( $_GET['printable'] ) ) {
+ − 191
$flags .= $sep . 'printable';
+ − 192
$sep = '&';
+ − 193
}
76
+ − 194
if ( isset( $_GET['theme'] ) )
22
+ − 195
{
+ − 196
$flags .= $sep . 'theme='.$session->theme;
+ − 197
$sep = '&';
+ − 198
}
+ − 199
if ( isset( $_GET['style'] ) )
+ − 200
{
+ − 201
$flags .= $sep . 'style='.$session->style;
+ − 202
$sep = '&';
+ − 203
}
76
+ − 204
22
+ − 205
if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
+ − 206
{
+ − 207
$url = $session->append_sid(contentPath . $paths->nslist[$n] . $t . $flags);
+ − 208
}
+ − 209
else
+ − 210
{
+ − 211
// If the path manager hasn't been initted yet, take an educated guess at what the URI should be
+ − 212
$url = contentPath . $n . ':' . $t . $flags;
+ − 213
}
1
+ − 214
if($query)
+ − 215
{
+ − 216
if(strstr($url, '?')) $sep = '&';
+ − 217
else $sep = '?';
+ − 218
$url = $url . $sep . $query . $flags;
+ − 219
}
76
+ − 220
1
+ − 221
$baseprot = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'];
+ − 222
$url = $baseprot . $url;
76
+ − 223
1
+ − 224
return ($escape) ? htmlspecialchars($url) : $url;
+ − 225
}
+ − 226
+ − 227
/**
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 228
* Tells you the title for the given page ID string
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 229
* @param string Page ID string (ex: Special:Administration)
91
+ − 230
* @param bool Optional. If true, and if the namespace turns out to be something other than Article, the namespace prefix will be prepended to the return value.
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 231
* @return string
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 232
*/
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 233
91
+ − 234
function get_page_title($page_id, $show_ns = true)
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 235
{
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 236
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 237
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 238
$idata = RenderMan::strToPageID($page_id);
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 239
$page_id_key = $paths->nslist[ $idata[1] ] . $idata[0];
91
+ − 240
$page_id_key = sanitize_page_id($page_id_key);
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 241
$page_data = $paths->pages[$page_id_key];
91
+ − 242
$title = ( isset($page_data['name']) ) ?
+ − 243
( ( $page_data['namespace'] == 'Article' || !$show_ns ) ?
+ − 244
'' :
+ − 245
$paths->nslist[ $idata[1] ] )
+ − 246
. $page_data['name'] :
+ − 247
( $show_ns ? $paths->nslist[$idata[1]] : '' ) . str_replace('_', ' ', dirtify_page_id( $idata[0] ) );
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 248
return $title;
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 249
}
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 250
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 251
/**
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 252
* Tells you the title for the given page ID and namespace
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 253
* @param string Page ID
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 254
* @param string Namespace
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 255
* @return string
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 256
*/
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 257
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 258
function get_page_title_ns($page_id, $namespace)
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 259
{
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 260
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 261
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 262
$page_id_key = $paths->nslist[ $namespace ] . $page_id;
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 263
$page_data = $paths->pages[$page_id_key];
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 264
$title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$namespace] . str_replace('_', ' ', dirtify_page_id( $page_id ) );
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 265
return $title;
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 266
}
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 267
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 268
/**
1
+ − 269
* Redirect the user to the specified URL.
+ − 270
* @param string $url The URL, either relative or absolute.
+ − 271
* @param string $title The title of the message
+ − 272
* @param string $message A short message to show to the user
+ − 273
* @param string $timeout Timeout, in seconds, to delay the redirect. Defaults to 3.
+ − 274
*/
76
+ − 275
1
+ − 276
function redirect($url, $title = 'Redirecting...', $message = 'Please wait while you are redirected.', $timeout = 3)
+ − 277
{
+ − 278
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 279
1
+ − 280
if ( $timeout == 0 )
+ − 281
{
+ − 282
header('Location: ' . $url);
+ − 283
header('HTTP/1.1 307 Temporary Redirect');
+ − 284
}
218
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 285
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 286
if ( !is_object($template) )
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 287
{
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 288
$template = new template_nodb();
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 289
$template->load_theme('oxygen', 'bleu', false);
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 290
$template->tpl_strings['SITE_NAME'] = 'Enano';
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 291
$template->tpl_strings['SITE_DESC'] = 'This site is experiencing a critical error and cannot load.';
222
acfdccf7a2bf
Re-sync Oxygen and Mint and Oxygen simple with Oxygen main; a couple improvements to the redirect-on-no-config code
Dan
diff
changeset
+ − 292
$template->tpl_strings['COPYRIGHT'] = 'Powered by Enano CMS - © 2007 Dan Fuhry. This program is Free Software; see the <a href="' . scriptPath . '/install.php?mode=license">GPL file</a> included with this package for details.';
218
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 293
$template->tpl_strings['PAGE_NAME'] = htmlspecialchars($title);
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 294
}
76
+ − 295
1
+ − 296
$template->add_header('<meta http-equiv="refresh" content="' . $timeout . '; url=' . str_replace('"', '\\"', $url) . '" />');
+ − 297
$template->add_header('<script type="text/javascript">
+ − 298
function __r() {
+ − 299
// FUNCTION AUTOMATICALLY GENERATED
+ − 300
window.location="' . str_replace('"', '\\"', $url) . '";
+ − 301
}
+ − 302
setTimeout(\'__r();\', ' . $timeout . '000);
+ − 303
</script>
+ − 304
');
218
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 305
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 306
if ( get_class($template) == 'template_nodb' )
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 307
$template->init_vars();
76
+ − 308
1
+ − 309
$template->tpl_strings['PAGE_NAME'] = $title;
+ − 310
$template->header(true);
218
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 311
echo '<p>' . $message . '</p><p>If you are not redirected within ' . $timeout . ' seconds, <a href="' . str_replace('"', '\\"', $url) . '">please click here</a>.</p>';
1
+ − 312
$template->footer(true);
76
+ − 313
1
+ − 314
$db->close();
+ − 315
exit(0);
76
+ − 316
1
+ − 317
}
+ − 318
+ − 319
// Removed wikiFormat() from here, replaced with RenderMan::render
+ − 320
22
+ − 321
/**
+ − 322
* Tell me if the page exists or not.
+ − 323
* @param string the full page ID (Special:Administration) of the page to check for
+ − 324
* @return bool True if the page exists, false otherwise
+ − 325
*/
+ − 326
1
+ − 327
function isPage($p) {
+ − 328
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 329
22
+ − 330
// Try the easy way first ;-)
+ − 331
if ( isset( $paths->pages[ $p ] ) )
+ − 332
{
+ − 333
return true;
+ − 334
}
76
+ − 335
22
+ − 336
// Special case for Special, Template, and Admin pages that can't have slashes in their URIs
+ − 337
$ns_test = RenderMan::strToPageID( $p );
76
+ − 338
22
+ − 339
if($ns_test[1] != 'Special' && $ns_test[1] != 'Template' && $ns_test[1] != 'Admin')
+ − 340
{
+ − 341
return false;
+ − 342
}
76
+ − 343
22
+ − 344
$particles = explode('/', $p);
+ − 345
if ( isset ( $paths->pages[ $particles[ 0 ] ] ) )
+ − 346
{
+ − 347
return true;
+ − 348
}
+ − 349
else
+ − 350
{
+ − 351
return false;
+ − 352
}
1
+ − 353
}
+ − 354
76
+ − 355
/**
+ − 356
* These are some old functions that were used with the Midget codebase. They are deprecated and should not be used any more.
+ − 357
*/
+ − 358
1
+ − 359
function arrayItemUp($arr, $keyname) {
+ − 360
$keylist = array_keys($arr);
+ − 361
$keyflop = array_flip($keylist);
+ − 362
$idx = $keyflop[$keyname];
+ − 363
$idxm = $idx - 1;
+ − 364
$temp = $arr[$keylist[$idxm]];
+ − 365
if($arr[$keylist[0]] == $arr[$keyname]) return $arr;
+ − 366
$arr[$keylist[$idxm]] = $arr[$keylist[$idx]];
+ − 367
$arr[$keylist[$idx]] = $temp;
+ − 368
return $arr;
+ − 369
}
+ − 370
+ − 371
function arrayItemDown($arr, $keyname) {
+ − 372
$keylist = array_keys($arr);
+ − 373
$keyflop = array_flip($keylist);
+ − 374
$idx = $keyflop[$keyname];
+ − 375
$idxm = $idx + 1;
+ − 376
$temp = $arr[$keylist[$idxm]];
+ − 377
$sz = sizeof($arr); $sz--;
+ − 378
if($arr[$keylist[$sz]] == $arr[$keyname]) return $arr;
+ − 379
$arr[$keylist[$idxm]] = $arr[$keylist[$idx]];
+ − 380
$arr[$keylist[$idx]] = $temp;
+ − 381
return $arr;
+ − 382
}
+ − 383
+ − 384
function arrayItemTop($arr, $keyname) {
+ − 385
$keylist = array_keys($arr);
+ − 386
$keyflop = array_flip($keylist);
+ − 387
$idx = $keyflop[$keyname];
+ − 388
while( $orig != $arr[$keylist[0]] ) {
+ − 389
// echo 'Keyname: '.$keylist[$idx] . '<br />'; flush(); ob_flush(); // Debugger
+ − 390
if($idx < 0) return $arr;
+ − 391
if($keylist[$idx] == '' || $keylist[$idx] < 0 || !$keylist[$idx]) {
+ − 392
/* echo 'Infinite loop caught in arrayItemTop(<br /><pre>';
+ − 393
print_r($arr);
+ − 394
echo '</pre><br />, '.$keyname.');<br /><br />EnanoCMS: Critical error during function call, exiting to prevent excessive server load.';
+ − 395
exit; */
+ − 396
return $arr;
+ − 397
}
+ − 398
$arr = arrayItemUp($arr, $keylist[$idx]);
+ − 399
$idx--;
+ − 400
}
+ − 401
return $arr;
+ − 402
}
+ − 403
+ − 404
function arrayItemBottom($arr, $keyname) {
+ − 405
$keylist = array_keys($arr);
+ − 406
$keyflop = array_flip($keylist);
+ − 407
$idx = $keyflop[$keyname];
+ − 408
$sz = sizeof($arr); $sz--;
+ − 409
while( $orig != $arr[$keylist[$sz]] ) {
+ − 410
// echo 'Keyname: '.$keylist[$idx] . '<br />'; flush(); ob_flush(); // Debugger
+ − 411
if($idx > $sz) return $arr;
+ − 412
if($keylist[$idx] == '' || $keylist[$idx] < 0 || !$keylist[$idx]) {
+ − 413
echo 'Infinite loop caught in arrayItemBottom(<br /><pre>';
+ − 414
print_r($arr);
+ − 415
echo '</pre><br />, '.$keyname.');<br /><br />EnanoCMS: Critical error during function call, exiting to prevent excessive server load.';
+ − 416
exit;
+ − 417
}
+ − 418
$arr = arrayItemDown($arr, $keylist[$idx]);
+ − 419
$idx++;
+ − 420
}
+ − 421
return $arr;
+ − 422
}
+ − 423
+ − 424
// Convert IP address to hex string
+ − 425
// Input: 127.0.0.1 (string)
+ − 426
// Output: 0x7f000001 (string)
+ − 427
// Updated 12/8/06 to work with PHP4 and not use eval() (blech)
+ − 428
function ip2hex($ip) {
+ − 429
if ( preg_match('/^([0-9a-f:]+)$/', $ip) )
+ − 430
{
+ − 431
// this is an ipv6 address
+ − 432
return str_replace(':', '', $ip);
+ − 433
}
+ − 434
$nums = explode('.', $ip);
+ − 435
if(sizeof($nums) != 4) return false;
+ − 436
$str = '0x';
+ − 437
foreach($nums as $n)
+ − 438
{
+ − 439
$str .= (string)dechex($n);
+ − 440
}
+ − 441
return $str;
+ − 442
}
+ − 443
+ − 444
// Convert DWord to IP address
+ − 445
// Input: 0x7f000001
+ − 446
// Output: 127.0.0.1
+ − 447
// Updated 12/8/06 to work with PHP4 and not use eval() (blech)
+ − 448
function hex2ip($in) {
+ − 449
if(substr($in, 0, 2) == '0x') $ip = substr($in, 2, 8);
+ − 450
else $ip = substr($in, 0, 8);
+ − 451
$octets = enano_str_split($ip, 2);
+ − 452
$str = '';
+ − 453
$newoct = Array();
+ − 454
foreach($octets as $o)
+ − 455
{
+ − 456
$o = (int)hexdec($o);
+ − 457
$newoct[] = $o;
+ − 458
}
+ − 459
return implode('.', $newoct);
+ − 460
}
+ − 461
+ − 462
// Function strip_php moved to RenderMan class
+ − 463
76
+ − 464
/**
+ − 465
* Immediately brings the site to a halt with an error message. Unlike grinding_halt() this can only be called after the config has been
+ − 466
* fetched (plugin developers don't even need to worry since plugins are always loaded after the config) and shows the site name and
+ − 467
* description.
+ − 468
* @param string The title of the error message
+ − 469
* @param string The body of the message, this can be HTML, and should be separated into paragraphs using the <p> tag
+ − 470
*/
+ − 471
1
+ − 472
function die_semicritical($t, $p)
+ − 473
{
+ − 474
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 475
$db->close();
76
+ − 476
1
+ − 477
if ( ob_get_status() )
+ − 478
ob_end_clean();
76
+ − 479
1
+ − 480
$tpl = new template_nodb();
+ − 481
$tpl->load_theme('oxygen', 'bleu');
+ − 482
$tpl->tpl_strings['SITE_NAME'] = getConfig('site_name');
+ − 483
$tpl->tpl_strings['SITE_DESC'] = getConfig('site_desc');
+ − 484
$tpl->tpl_strings['COPYRIGHT'] = getConfig('copyright_notice');
+ − 485
$tpl->tpl_strings['PAGE_NAME'] = $t;
+ − 486
$tpl->header();
+ − 487
echo $p;
+ − 488
$tpl->footer();
76
+ − 489
1
+ − 490
exit;
+ − 491
}
+ − 492
76
+ − 493
/**
+ − 494
* Halts Enano execution with a message. This doesn't have to be an error message, it's sometimes used to indicate success at an operation.
+ − 495
* @param string The title of the message
+ − 496
* @param string The body of the message, this can be HTML, and should be separated into paragraphs using the <p> tag
+ − 497
*/
+ − 498
1
+ − 499
function die_friendly($t, $p)
+ − 500
{
+ − 501
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 502
1
+ − 503
if ( ob_get_status() )
+ − 504
ob_end_clean();
76
+ − 505
1
+ − 506
$paths->cpage['name'] = $t;
+ − 507
$template->tpl_strings['PAGE_NAME'] = $t;
+ − 508
$template->header();
+ − 509
echo $p;
+ − 510
$template->footer();
+ − 511
$db->close();
76
+ − 512
1
+ − 513
exit;
+ − 514
}
+ − 515
76
+ − 516
/**
+ − 517
* Immediately brings the site to a halt with an error message, and focuses on immediately closing the database connection and shutting down Enano in the event that an attack may happen. This should only be used very early on to indicate very severe errors, or if the site may be under attack (like if the DBAL detects a malicious query). In the vast majority of cases, die_semicritical() is more appropriate.
+ − 518
* @param string The title of the error message
+ − 519
* @param string The body of the message, this can be HTML, and should be separated into paragraphs using the <p> tag
+ − 520
*/
+ − 521
1
+ − 522
function grinding_halt($t, $p)
+ − 523
{
+ − 524
global $db, $session, $paths, $template, $plugins; // Common objects
125
+ − 525
+ − 526
if ( !defined('scriptPath') )
+ − 527
require( ENANO_ROOT . '/config.php' );
76
+ − 528
125
+ − 529
if ( is_object($db) )
+ − 530
$db->close();
76
+ − 531
1
+ − 532
if ( ob_get_status() )
+ − 533
ob_end_clean();
76
+ − 534
1
+ − 535
$tpl = new template_nodb();
+ − 536
$tpl->load_theme('oxygen', 'bleu');
+ − 537
$tpl->tpl_strings['SITE_NAME'] = 'Critical error';
+ − 538
$tpl->tpl_strings['SITE_DESC'] = 'This website is experiencing a serious error and cannot load.';
+ − 539
$tpl->tpl_strings['COPYRIGHT'] = 'Unable to retrieve copyright information';
+ − 540
$tpl->tpl_strings['PAGE_NAME'] = $t;
+ − 541
$tpl->header();
+ − 542
echo $p;
+ − 543
$tpl->footer();
+ − 544
exit;
+ − 545
}
+ − 546
76
+ − 547
/**
+ − 548
* Prints out the categorization box found on most regular pages. Doesn't take or return anything, but assumes that the page information is already set in $paths.
+ − 549
*/
+ − 550
+ − 551
function show_category_info()
+ − 552
{
+ − 553
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 554
+ − 555
if ( $paths->namespace == 'Category' )
+ − 556
{
+ − 557
// Show member pages and subcategories
+ − 558
$q = $db->sql_query('SELECT p.urlname, p.namespace, p.name, p.namespace=\'Category\' AS is_category FROM '.table_prefix.'categories AS c
+ − 559
LEFT JOIN '.table_prefix.'pages AS p
+ − 560
ON ( p.urlname = c.page_id AND p.namespace = c.namespace )
+ − 561
WHERE c.category_id=\'' . $db->escape($paths->cpage['urlname_nons']) . '\'
+ − 562
ORDER BY is_category DESC, p.name ASC;');
+ − 563
if ( !$q )
+ − 564
{
+ − 565
$db->_die();
+ − 566
}
+ − 567
echo '<h3>Subcategories</h3>';
+ − 568
echo '<div class="tblholder">';
+ − 569
echo '<table border="0" cellspacing="1" cellpadding="4">';
+ − 570
echo '<tr>';
+ − 571
$ticker = 0;
+ − 572
$counter = 0;
+ − 573
$switched = false;
+ − 574
$class = 'row1';
+ − 575
while ( $row = $db->fetchrow() )
+ − 576
{
+ − 577
if ( $row['is_category'] == 0 && !$switched )
+ − 578
{
+ − 579
if ( $counter > 0 )
+ − 580
{
+ − 581
// Fill-in
+ − 582
while ( $ticker < 3 )
+ − 583
{
+ − 584
$ticker++;
+ − 585
echo '<td class="' . $class . '" style="width: 33.3%;"></td>';
+ − 586
}
+ − 587
}
+ − 588
else
+ − 589
{
+ − 590
echo '<td class="' . $class . '">No subcategories.</td>';
+ − 591
}
+ − 592
echo '</tr></table></div>' . "\n\n";
+ − 593
echo '<h3>Pages</h3>';
+ − 594
echo '<div class="tblholder">';
+ − 595
echo '<table border="0" cellspacing="1" cellpadding="4">';
+ − 596
echo '<tr>';
+ − 597
$counter = 0;
129
0b5244001799
Rebranded as 1.0.1.1; fixed category page drawing bug; updated link to GPL in the about page to the GPLv2
Dan
diff
changeset
+ − 598
$ticker = -1;
76
+ − 599
$switched = true;
+ − 600
}
+ − 601
$counter++;
+ − 602
$ticker++;
+ − 603
if ( $ticker == 3 )
+ − 604
{
+ − 605
echo '</tr><tr>';
+ − 606
$ticker = 0;
+ − 607
$class = ( $class == 'row3' ) ? 'row1' : 'row3';
+ − 608
}
+ − 609
echo "<td class=\"{$class}\" style=\"width: 33.3%;\">"; // " to workaround stupid jEdit bug
+ − 610
+ − 611
$link = makeUrlNS($row['namespace'], sanitize_page_id($row['urlname']));
+ − 612
echo '<a href="' . $link . '"';
+ − 613
$key = $paths->nslist[$row['namespace']] . sanitize_page_id($row['urlname']);
+ − 614
if ( !isPage( $key ) )
+ − 615
{
+ − 616
echo ' class="wikilink-nonexistent"';
+ − 617
}
+ − 618
echo '>';
+ − 619
$title = get_page_title_ns($row['urlname'], $row['namespace']);
+ − 620
echo htmlspecialchars($title);
+ − 621
echo '</a>';
+ − 622
+ − 623
echo "</td>";
+ − 624
}
+ − 625
if ( !$switched )
+ − 626
{
+ − 627
if ( $counter > 0 )
+ − 628
{
+ − 629
// Fill-in
129
0b5244001799
Rebranded as 1.0.1.1; fixed category page drawing bug; updated link to GPL in the about page to the GPLv2
Dan
diff
changeset
+ − 630
while ( $ticker < 2 )
76
+ − 631
{
+ − 632
$ticker++;
+ − 633
echo '<td class="' . $class . '" style="width: 33.3%;"></td>';
+ − 634
}
+ − 635
}
+ − 636
else
+ − 637
{
+ − 638
echo '<td class="' . $class . '">No subcategories.</td>';
+ − 639
}
+ − 640
echo '</tr></table></div>' . "\n\n";
+ − 641
echo '<h3>Pages</h3>';
+ − 642
echo '<div class="tblholder">';
+ − 643
echo '<table border="0" cellspacing="1" cellpadding="4">';
+ − 644
echo '<tr>';
+ − 645
$counter = 0;
+ − 646
$ticker = 0;
+ − 647
$switched = true;
+ − 648
}
+ − 649
if ( $counter > 0 )
+ − 650
{
+ − 651
// Fill-in
129
0b5244001799
Rebranded as 1.0.1.1; fixed category page drawing bug; updated link to GPL in the about page to the GPLv2
Dan
diff
changeset
+ − 652
while ( $ticker < 2 )
76
+ − 653
{
+ − 654
$ticker++;
+ − 655
echo '<td class="' . $class . '" style="width: 33.3%;"></td>';
+ − 656
}
+ − 657
}
+ − 658
else
+ − 659
{
+ − 660
echo '<td class="' . $class . '">No pages in this category.</td>';
+ − 661
}
+ − 662
echo '</tr></table></div>' . "\n\n";
+ − 663
}
+ − 664
+ − 665
if ( $paths->namespace != 'Special' && $paths->namespace != 'Admin' )
+ − 666
{
86
c162ca39db8f
Finished pagination code (was incomplete in previous revision) and added a few hacks for an upcoming theme
Dan
diff
changeset
+ − 667
echo '<div class="mdg-comment" style="margin: 10px 0 0 0;" id="category_box_wrapper">';
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 668
echo '<div style="float: right;">';
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 669
echo '(<a href="#" onclick="ajaxCatToTag(); return false;">show page tags</a>)';
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 670
echo '</div>';
76
+ − 671
echo '<div id="mdgCatBox">Categories: ';
+ − 672
+ − 673
$where = '( c.page_id=\'' . $db->escape($paths->cpage['urlname_nons']) . '\' AND c.namespace=\'' . $db->escape($paths->namespace) . '\' )';
+ − 674
$prefix = table_prefix;
+ − 675
$sql = <<<EOF
+ − 676
SELECT c.category_id FROM {$prefix}categories AS c
+ − 677
LEFT JOIN {$prefix}pages AS p
+ − 678
ON ( ( p.urlname = c.page_id AND p.namespace = c.namespace ) OR ( p.urlname IS NULL AND p.namespace IS NULL ) )
+ − 679
WHERE $where
+ − 680
ORDER BY p.name ASC, c.page_id ASC;
+ − 681
EOF;
+ − 682
$q = $db->sql_query($sql);
+ − 683
if ( !$q )
+ − 684
$db->_die();
+ − 685
+ − 686
if ( $row = $db->fetchrow() )
+ − 687
{
+ − 688
$list = array();
+ − 689
do
+ − 690
{
+ − 691
$cid = sanitize_page_id($row['category_id']);
+ − 692
$title = get_page_title_ns($cid, 'Category');
+ − 693
$link = makeUrlNS('Category', $cid);
+ − 694
$list[] = '<a href="' . $link . '">' . htmlspecialchars($title) . '</a>';
+ − 695
}
+ − 696
while ( $row = $db->fetchrow() );
+ − 697
echo implode(', ', $list);
+ − 698
}
+ − 699
else
+ − 700
{
+ − 701
echo '(Uncategorized)';
+ − 702
}
+ − 703
+ − 704
$can_edit = ( $session->get_permissions('edit_cat') && ( !$paths->page_protected || $session->get_permissions('even_when_protected') ) );
+ − 705
if ( $can_edit )
+ − 706
{
+ − 707
$edit_link = '<a href="' . makeUrl($paths->page, 'do=catedit', true) . '" onclick="ajaxCatEdit(); return false;">edit categorization</a>';
+ − 708
echo ' [ ' . $edit_link . ' ]';
+ − 709
}
+ − 710
+ − 711
echo '</div></div>';
+ − 712
+ − 713
}
+ − 714
+ − 715
}
+ − 716
+ − 717
/**
+ − 718
* Prints out the file information box seen on File: pages. Doesn't take or return anything, but assumes that the page information is already set in $paths, and expects $paths->namespace to be File.
+ − 719
*/
1
+ − 720
+ − 721
function show_file_info()
+ − 722
{
+ − 723
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 724
if($paths->namespace != 'File') return null; // Prevent unnecessary work
+ − 725
$selfn = $paths->cpage['urlname_nons']; // substr($paths->page, strlen($paths->nslist['File']), strlen($paths->cpage));
+ − 726
if(substr($paths->cpage['name'], 0, strlen($paths->nslist['File']))==$paths->nslist['File']) $selfn = substr($paths->cpage['urlname_nons'], strlen($paths->nslist['File']), strlen($paths->cpage['urlname_nons']));
+ − 727
$q = $db->sql_query('SELECT mimetype,time_id,size FROM '.table_prefix.'files WHERE page_id=\''.$selfn.'\' ORDER BY time_id DESC;');
+ − 728
if(!$q) $db->_die('The file type could not be fetched.');
+ − 729
if($db->numrows() < 1) { echo '<div class="mdg-comment" style="margin-left: 0;"><h3>Uploaded file</h3><p>There are no files uploaded with this name yet. <a href="'.makeUrlNS('Special', 'UploadFile/'.$paths->cpage['urlname_nons']).'">Upload a file...</a></p></div><br />'; return; }
+ − 730
$r = $db->fetchrow();
+ − 731
$mimetype = $r['mimetype'];
+ − 732
$datestring = date('F d, Y h:i a', (int)$r['time_id']);
+ − 733
echo '<div class="mdg-comment" style="margin-left: 0;"><p><h3>Uploaded file</h3></p><p>Type: '.$r['mimetype'].'<br />Size: ';
+ − 734
$fs = $r['size'];
+ − 735
echo $fs.' bytes';
+ − 736
$fs = (int)$fs;
+ − 737
if($fs >= 1048576)
+ − 738
{
+ − 739
$fs = round($fs / 1048576, 1);
+ − 740
echo ' ('.$fs.' MB)';
+ − 741
} elseif($fs >= 1024) {
+ − 742
$fs = round($fs / 1024, 1);
+ − 743
echo ' ('.$fs.' KB)';
+ − 744
}
+ − 745
echo '<br />Uploaded: '.$datestring.'</p>';
+ − 746
if(substr($mimetype, 0, 6)!='image/' && ( substr($mimetype, 0, 5) != 'text/' || $mimetype == 'text/html' || $mimetype == 'text/javascript' ))
+ − 747
{
+ − 748
echo '<div class="warning-box">This file type may contain viruses or other code that could harm your computer. You should exercise caution if you download it.</div>';
+ − 749
}
+ − 750
if(substr($mimetype, 0, 6)=='image/')
+ − 751
{
+ − 752
echo '<p><a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn).'"><img style="border: 0;" alt="'.$paths->page.'" src="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.htmlspecialchars(urlSeparator).'preview').'" /></a></p>';
+ − 753
}
+ − 754
echo '<p><a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">Download this file</a>';
+ − 755
if(!$paths->page_protected && ( $paths->wiki_mode || $session->get_permissions('upload_new_version') ))
+ − 756
{
+ − 757
echo ' | <a href="'.makeUrlNS('Special', 'UploadFile'.'/'.$selfn).'">Upload new version</a>';
+ − 758
}
+ − 759
echo '</p>';
+ − 760
if($db->numrows() > 1)
+ − 761
{
+ − 762
echo '<h3>File history</h3><p>';
+ − 763
while($r = $db->fetchrow())
+ − 764
{
+ − 765
echo '(<a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">this ver</a>) ';
+ − 766
if($session->get_permissions('history_rollback'))
+ − 767
echo ' (<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">revert</a>) ';
+ − 768
$mimetype = $r['mimetype'];
+ − 769
$datestring = date('F d, Y h:i a', (int)$r['time_id']);
+ − 770
echo $datestring.': '.$r['mimetype'].', ';
+ − 771
$fs = $r['size'];
+ − 772
$fs = (int)$fs;
+ − 773
if($fs >= 1048576)
+ − 774
{
+ − 775
$fs = round($fs / 1048576, 1);
+ − 776
echo ' '.$fs.' MB';
+ − 777
} elseif($fs >= 1024) {
+ − 778
$fs = round($fs / 1024, 1);
+ − 779
echo ' '.$fs.' KB';
+ − 780
} else {
+ − 781
echo ' '.$fs.' bytes';
+ − 782
}
+ − 783
echo '<br />';
+ − 784
}
+ − 785
echo '</p>';
+ − 786
}
+ − 787
$db->free_result();
+ − 788
echo '</div><br />';
+ − 789
}
+ − 790
76
+ − 791
/**
+ − 792
* Shows header information on the current page. Currently this is only the delete-vote feature. Doesn't take or return anything, but assumes that the page information is already set in $paths.
+ − 793
*/
+ − 794
1
+ − 795
function display_page_headers()
+ − 796
{
+ − 797
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 798
if($session->get_permissions('vote_reset') && $paths->cpage['delvotes'] > 0)
+ − 799
{
112
+ − 800
$delvote_ips = unserialize($paths->cpage['delvote_ips']);
+ − 801
$hr = htmlspecialchars(implode(', ', $delvote_ips['u']));
1
+ − 802
$is = 'is';
+ − 803
$s = '';
+ − 804
$s2 = 's';
+ − 805
if ( $paths->cpage['delvotes'] > 1)
+ − 806
{
+ − 807
$is = 'are';
+ − 808
$s = 's';
+ − 809
$s2 = '';
+ − 810
}
+ − 811
echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;" id="mdgDeleteVoteNoticeBox">
+ − 812
<b>Notice:</b> There '.$is.' '.$paths->cpage['delvotes'].' user'.$s.' that think'.$s2.' this page should be deleted.<br />
+ − 813
<b>Users that voted:</b> ' . $hr . '<br />
+ − 814
<a href="'.makeUrl($paths->page, 'do=deletepage').'" onclick="ajaxDeletePage(); return false;">Delete page</a> | <a href="'.makeUrl($paths->page, 'do=resetvotes').'" onclick="ajaxResetDelVotes(); return false;">Reset votes</a>
+ − 815
</div>';
+ − 816
}
+ − 817
}
+ − 818
76
+ − 819
/**
+ − 820
* Displays page footer information including file and category info. This also has the send_page_footers hook. Doesn't take or return anything, but assumes that the page information is already set in $paths.
+ − 821
*/
+ − 822
1
+ − 823
function display_page_footers()
+ − 824
{
+ − 825
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 826
if(isset($_GET['nofooters'])) return;
+ − 827
$code = $plugins->setHook('send_page_footers');
+ − 828
foreach ( $code as $cmd )
+ − 829
{
+ − 830
eval($cmd);
+ − 831
}
+ − 832
show_file_info();
+ − 833
show_category_info();
+ − 834
}
+ − 835
76
+ − 836
/**
+ − 837
* Deprecated, do not use.
+ − 838
*/
+ − 839
1
+ − 840
function password_prompt($id = false)
+ − 841
{
+ − 842
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 843
if(!$id) $id = $paths->page;
+ − 844
if(isset($paths->pages[$id]['password']) && strlen($paths->pages[$id]['password']) == 40 && !isset($_REQUEST['pagepass']))
+ − 845
{
+ − 846
die_friendly('Password required', '<p>You must supply a password to access this page.</p><form action="'.makeUrl($paths->pages[$id]['urlname']).'" method="post"><p>Password: <input name="pagepass" type="password" /></p><p><input type="submit" value="Submit" /></p>');
+ − 847
} elseif(isset($_REQUEST['pagepass'])) {
+ − 848
$p = (preg_match('#^([a-f0-9]*){40}$#', $_REQUEST['pagepass'])) ? $_REQUEST['pagepass'] : sha1($_REQUEST['pagepass']);
+ − 849
if($p != $paths->pages[$id]['password']) die_friendly('Password required', '<p style="color: red;">The password you entered is incorrect.</p><form action="'.makeUrl($paths->page).'" method="post"><p>Password: <input name="pagepass" type="password" /></p><p><input type="submit" value="Submit" /></p>');
+ − 850
}
+ − 851
}
+ − 852
76
+ − 853
/**
+ − 854
* Some sort of primitive hex converter from back in the day. Deprecated, do not use.
+ − 855
* @param string Text to encode
+ − 856
* @return string
+ − 857
*/
+ − 858
1
+ − 859
function str_hex($string){
+ − 860
$hex='';
+ − 861
for ($i=0; $i < strlen($string); $i++){
+ − 862
$hex .= ' '.dechex(ord($string[$i]));
+ − 863
}
+ − 864
return substr($hex, 1, strlen($hex));
+ − 865
}
+ − 866
76
+ − 867
/**
+ − 868
* Essentially an return code reader for a socket. Don't use this unless you're writing mail code and smtp_send_email doesn't cut it. Ported from phpBB's smtp.php.
+ − 869
* @param socket A socket resource
+ − 870
* @param string The expected response from the server, this needs to be exactly three characters.
+ − 871
*/
+ − 872
+ − 873
function smtp_get_response($socket, $response, $line = __LINE__)
1
+ − 874
{
76
+ − 875
$server_response = '';
+ − 876
while (substr($server_response, 3, 1) != ' ')
+ − 877
{
+ − 878
if (!($server_response = fgets($socket, 256)))
+ − 879
{
1
+ − 880
die_friendly('SMTP Error', "<p>Couldn't get mail server response codes</p>");
76
+ − 881
}
+ − 882
}
1
+ − 883
76
+ − 884
if (!(substr($server_response, 0, 3) == $response))
+ − 885
{
1
+ − 886
die_friendly('SMTP Error', "<p>Ran into problems sending mail. Response: $server_response</p>");
76
+ − 887
}
1
+ − 888
}
+ − 889
76
+ − 890
/**
+ − 891
* Wrapper for smtp_send_email_core that takes the sender as the fourth parameter instead of additional headers.
+ − 892
* @param string E-mail address to send to
+ − 893
* @param string Subject line
+ − 894
* @param string The body of the message
+ − 895
* @param string Address of the sender
+ − 896
*/
+ − 897
1
+ − 898
function smtp_send_email($to, $subject, $message, $from)
+ − 899
{
+ − 900
return smtp_send_email_core($to, $subject, $message, "From: <$from>\n");
+ − 901
}
+ − 902
76
+ − 903
/**
+ − 904
* Replacement or substitute for PHP's mail() builtin function.
+ − 905
* @param string E-mail address to send to
+ − 906
* @param string Subject line
+ − 907
* @param string The body of the message
+ − 908
* @param string Message headers, separated by a single newline ("\n")
+ − 909
* @copyright (C) phpBB Group
+ − 910
* @license GPL
+ − 911
*/
+ − 912
1
+ − 913
function smtp_send_email_core($mail_to, $subject, $message, $headers = '')
+ − 914
{
76
+ − 915
// Fix any bare linefeeds in the message to make it RFC821 Compliant.
+ − 916
$message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
1
+ − 917
76
+ − 918
if ($headers != '')
+ − 919
{
+ − 920
if (is_array($headers))
+ − 921
{
+ − 922
if (sizeof($headers) > 1)
+ − 923
{
+ − 924
$headers = join("\n", $headers);
+ − 925
}
+ − 926
else
+ − 927
{
+ − 928
$headers = $headers[0];
+ − 929
}
+ − 930
}
+ − 931
$headers = chop($headers);
1
+ − 932
76
+ − 933
// Make sure there are no bare linefeeds in the headers
+ − 934
$headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);
1
+ − 935
76
+ − 936
// Ok this is rather confusing all things considered,
+ − 937
// but we have to grab bcc and cc headers and treat them differently
+ − 938
// Something we really didn't take into consideration originally
+ − 939
$header_array = explode("\r\n", $headers);
+ − 940
@reset($header_array);
1
+ − 941
76
+ − 942
$headers = '';
+ − 943
while(list(, $header) = each($header_array))
+ − 944
{
+ − 945
if (preg_match('#^cc:#si', $header))
+ − 946
{
+ − 947
$cc = preg_replace('#^cc:(.*)#si', '\1', $header);
+ − 948
}
+ − 949
else if (preg_match('#^bcc:#si', $header))
+ − 950
{
+ − 951
$bcc = preg_replace('#^bcc:(.*)#si', '\1', $header);
+ − 952
$header = '';
+ − 953
}
+ − 954
$headers .= ($header != '') ? $header . "\r\n" : '';
+ − 955
}
1
+ − 956
76
+ − 957
$headers = chop($headers);
+ − 958
$cc = explode(', ', $cc);
+ − 959
$bcc = explode(', ', $bcc);
+ − 960
}
1
+ − 961
76
+ − 962
if (trim($subject) == '')
+ − 963
{
+ − 964
die_friendly(GENERAL_ERROR, "No email Subject specified");
+ − 965
}
1
+ − 966
76
+ − 967
if (trim($message) == '')
+ − 968
{
+ − 969
die_friendly(GENERAL_ERROR, "Email message was blank");
+ − 970
}
+ − 971
1
+ − 972
// setup SMTP
+ − 973
$host = getConfig('smtp_server');
+ − 974
if ( empty($host) )
+ − 975
return 'No smtp_host in config';
+ − 976
if ( strstr($host, ':' ) )
+ − 977
{
+ − 978
$n = explode(':', $host);
+ − 979
$smtp_host = $n[0];
+ − 980
$port = intval($n[1]);
+ − 981
}
+ − 982
else
+ − 983
{
+ − 984
$smtp_host = $host;
+ − 985
$port = 25;
+ − 986
}
76
+ − 987
1
+ − 988
$smtp_user = getConfig('smtp_user');
+ − 989
$smtp_pass = getConfig('smtp_password');
+ − 990
76
+ − 991
// Ok we have error checked as much as we can to this point let's get on
+ − 992
// it already.
+ − 993
if( !$socket = @fsockopen($smtp_host, $port, $errno, $errstr, 20) )
+ − 994
{
+ − 995
die_friendly(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr");
+ − 996
}
+ − 997
+ − 998
// Wait for reply
+ − 999
smtp_get_response($socket, "220", __LINE__);
1
+ − 1000
76
+ − 1001
// Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
+ − 1002
// This improved as provided by SirSir to accomodate
+ − 1003
if( !empty($smtp_user) && !empty($smtp_pass) )
+ − 1004
{
+ − 1005
enano_fputs($socket, "EHLO " . $smtp_host . "\r\n");
+ − 1006
smtp_get_response($socket, "250", __LINE__);
1
+ − 1007
76
+ − 1008
enano_fputs($socket, "AUTH LOGIN\r\n");
+ − 1009
smtp_get_response($socket, "334", __LINE__);
1
+ − 1010
76
+ − 1011
enano_fputs($socket, base64_encode($smtp_user) . "\r\n");
+ − 1012
smtp_get_response($socket, "334", __LINE__);
1
+ − 1013
76
+ − 1014
enano_fputs($socket, base64_encode($smtp_pass) . "\r\n");
+ − 1015
smtp_get_response($socket, "235", __LINE__);
+ − 1016
}
+ − 1017
else
+ − 1018
{
+ − 1019
enano_fputs($socket, "HELO " . $smtp_host . "\r\n");
+ − 1020
smtp_get_response($socket, "250", __LINE__);
+ − 1021
}
1
+ − 1022
76
+ − 1023
// From this point onward most server response codes should be 250
+ − 1024
// Specify who the mail is from....
+ − 1025
enano_fputs($socket, "MAIL FROM: <" . getConfig('contact_email') . ">\r\n");
+ − 1026
smtp_get_response($socket, "250", __LINE__);
1
+ − 1027
76
+ − 1028
// Specify each user to send to and build to header.
+ − 1029
$to_header = '';
1
+ − 1030
76
+ − 1031
// Add an additional bit of error checking to the To field.
+ − 1032
$mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to);
+ − 1033
if (preg_match('#[^ ]+\@[^ ]+#', $mail_to))
+ − 1034
{
+ − 1035
enano_fputs($socket, "RCPT TO: <$mail_to>\r\n");
+ − 1036
smtp_get_response($socket, "250", __LINE__);
+ − 1037
}
1
+ − 1038
76
+ − 1039
// Ok now do the CC and BCC fields...
+ − 1040
@reset($bcc);
+ − 1041
while(list(, $bcc_address) = each($bcc))
+ − 1042
{
+ − 1043
// Add an additional bit of error checking to bcc header...
+ − 1044
$bcc_address = trim($bcc_address);
+ − 1045
if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address))
+ − 1046
{
+ − 1047
enano_fputs($socket, "RCPT TO: <$bcc_address>\r\n");
+ − 1048
smtp_get_response($socket, "250", __LINE__);
+ − 1049
}
+ − 1050
}
1
+ − 1051
76
+ − 1052
@reset($cc);
+ − 1053
while(list(, $cc_address) = each($cc))
+ − 1054
{
+ − 1055
// Add an additional bit of error checking to cc header
+ − 1056
$cc_address = trim($cc_address);
+ − 1057
if (preg_match('#[^ ]+\@[^ ]+#', $cc_address))
+ − 1058
{
+ − 1059
enano_fputs($socket, "RCPT TO: <$cc_address>\r\n");
+ − 1060
smtp_get_response($socket, "250", __LINE__);
+ − 1061
}
+ − 1062
}
1
+ − 1063
76
+ − 1064
// Ok now we tell the server we are ready to start sending data
+ − 1065
enano_fputs($socket, "DATA\r\n");
1
+ − 1066
76
+ − 1067
// This is the last response code we look for until the end of the message.
+ − 1068
smtp_get_response($socket, "354", __LINE__);
1
+ − 1069
76
+ − 1070
// Send the Subject Line...
+ − 1071
enano_fputs($socket, "Subject: $subject\r\n");
1
+ − 1072
76
+ − 1073
// Now the To Header.
+ − 1074
enano_fputs($socket, "To: $mail_to\r\n");
1
+ − 1075
76
+ − 1076
// Now any custom headers....
+ − 1077
enano_fputs($socket, "$headers\r\n\r\n");
1
+ − 1078
76
+ − 1079
// Ok now we are ready for the message...
+ − 1080
enano_fputs($socket, "$message\r\n");
1
+ − 1081
76
+ − 1082
// Ok the all the ingredients are mixed in let's cook this puppy...
+ − 1083
enano_fputs($socket, ".\r\n");
+ − 1084
smtp_get_response($socket, "250", __LINE__);
1
+ − 1085
76
+ − 1086
// Now tell the server we are done and close the socket...
+ − 1087
enano_fputs($socket, "QUIT\r\n");
+ − 1088
fclose($socket);
1
+ − 1089
76
+ − 1090
return TRUE;
1
+ − 1091
}
+ − 1092
+ − 1093
/**
+ − 1094
* Tell which version of Enano we're running.
+ − 1095
* @param bool $long if true, uses English version names (e.g. alpha, beta, release candidate). If false (default) uses abbreviations (1.0a1, 1.0b3, 1.0RC2, etc.)
+ − 1096
* @return string
+ − 1097
*/
+ − 1098
+ − 1099
function enano_version($long = false, $no_nightly = false)
+ − 1100
{
+ − 1101
$r = getConfig('enano_version');
+ − 1102
$rc = ( $long ) ? ' release candidate ' : 'RC';
+ − 1103
$b = ( $long ) ? ' beta ' : 'b';
+ − 1104
$a = ( $long ) ? ' alpha ' : 'a';
+ − 1105
if($v = getConfig('enano_rc_version')) $r .= $rc.$v;
+ − 1106
if($v = getConfig('enano_beta_version')) $r .= $b.$v;
+ − 1107
if($v = getConfig('enano_alpha_version')) $r .= $a.$v;
+ − 1108
if ( defined('ENANO_NIGHTLY') && !$no_nightly )
+ − 1109
{
+ − 1110
$nightlytag = ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR;
+ − 1111
$nightlylong = ' nightly; build date: ' . ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR;
+ − 1112
$r = ( $long ) ? $r . $nightlylong : $r . '-nightly-' . $nightlytag;
+ − 1113
}
+ − 1114
return $r;
+ − 1115
}
+ − 1116
76
+ − 1117
/**
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1118
* Give the codename of the release of Enano being run.
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1119
* @return string
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1120
*/
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1121
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1122
function enano_codename()
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1123
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1124
$names = array(
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1125
'1.0RC1' => 'Leprechaun',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1126
'1.0RC2' => 'Clurichaun',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1127
'1.0RC3' => 'Druid',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1128
'1.0' => 'Banshee',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1129
'1.0.1' => 'Loch Ness',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1130
'1.0.1.1'=> 'Loch Ness internal bugfix build',
145
+ − 1131
'1.0.2b1'=> 'Coblynau unstable',
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1132
'1.0.2' => 'Coblynau'
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1133
);
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1134
$version = enano_version();
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1135
if ( isset($names[$version]) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1136
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1137
return $names[$version];
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1138
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1139
return 'Anonymous build';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1140
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1141
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1142
/**
76
+ − 1143
* What kinda sh** was I thinking when I wrote this. Deprecated.
+ − 1144
*/
+ − 1145
1
+ − 1146
function _dualurlenc($t) {
+ − 1147
return rawurlencode(rawurlencode($t));
+ − 1148
}
76
+ − 1149
+ − 1150
/**
+ − 1151
* Badly named function to send back eval'able Javascript code with an error message. Deprecated, use JSON instead.
+ − 1152
* @param string Message to send
+ − 1153
*/
+ − 1154
1
+ − 1155
function _die($t) {
+ − 1156
$_ob = 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\'' . rawurlencode('' . $t . '') . '\')';
+ − 1157
die($_ob);
+ − 1158
}
+ − 1159
76
+ − 1160
/**
+ − 1161
* Same as _die(), but sends an SQL backtrace with the error message, and doesn't halt execution.
+ − 1162
* @param string Message to send
+ − 1163
*/
+ − 1164
1
+ − 1165
function jsdie($text) {
+ − 1166
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1167
$text = rawurlencode($text . "\n\nSQL Backtrace:\n" . $db->sql_backtrace());
+ − 1168
echo 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\''.$text.'\');';
+ − 1169
}
+ − 1170
+ − 1171
/**
+ − 1172
* Capitalizes the first letter of a string
+ − 1173
* @param $text string the text to be transformed
+ − 1174
* @return string
+ − 1175
*/
76
+ − 1176
1
+ − 1177
function capitalize_first_letter($text)
+ − 1178
{
+ − 1179
return strtoupper(substr($text, 0, 1)) . substr($text, 1);
+ − 1180
}
+ − 1181
+ − 1182
/**
+ − 1183
* Checks if a value in a bitfield is on or off
+ − 1184
* @param $bitfield int the bit-field value
+ − 1185
* @param $value int the value to switch off
+ − 1186
* @return bool
+ − 1187
*/
76
+ − 1188
1
+ − 1189
function is_bit($bitfield, $value)
+ − 1190
{
+ − 1191
return ( $bitfield & $value ) ? true : false;
+ − 1192
}
+ − 1193
+ − 1194
/**
+ − 1195
* Trims spaces/newlines from the beginning and end of a string
+ − 1196
* @param $text the text to process
+ − 1197
* @return string
+ − 1198
*/
76
+ − 1199
1
+ − 1200
function trim_spaces($text)
+ − 1201
{
+ − 1202
$d = true;
+ − 1203
while($d)
+ − 1204
{
+ − 1205
$c = substr($text, 0, 1);
+ − 1206
$a = substr($text, strlen($text)-1, strlen($text));
+ − 1207
if($c == "\n" || $c == "\r" || $c == "\t" || $c == ' ') $text = substr($text, 1, strlen($text));
+ − 1208
elseif($a == "\n" || $a == "\r" || $a == "\t" || $a == ' ') $text = substr($text, 0, strlen($text)-1);
+ − 1209
else $d = false;
+ − 1210
}
+ − 1211
return $text;
+ − 1212
}
+ − 1213
+ − 1214
/**
+ − 1215
* Enano-ese equivalent of str_split() which is only found in PHP5
+ − 1216
* @param $text string the text to split
+ − 1217
* @param $inc int size of each block
+ − 1218
* @return array
+ − 1219
*/
76
+ − 1220
1
+ − 1221
function enano_str_split($text, $inc = 1)
+ − 1222
{
76
+ − 1223
if($inc < 1)
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1224
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1225
return false;
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1226
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1227
if($inc >= strlen($text))
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1228
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1229
return Array($text);
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1230
}
1
+ − 1231
$len = ceil(strlen($text) / $inc);
+ − 1232
$ret = Array();
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1233
for ( $i = 0; $i < strlen($text); $i = $i + $inc )
1
+ − 1234
{
+ − 1235
$ret[] = substr($text, $i, $inc);
+ − 1236
}
+ − 1237
return $ret;
+ − 1238
}
+ − 1239
+ − 1240
/**
+ − 1241
* Converts a hexadecimal number to a binary string.
+ − 1242
* @param text string hexadecimal number
+ − 1243
* @return string
+ − 1244
*/
+ − 1245
function hex2bin($text)
+ − 1246
{
+ − 1247
$arr = enano_str_split($text, 2);
+ − 1248
$ret = '';
+ − 1249
for ($i=0; $i<sizeof($arr); $i++)
+ − 1250
{
+ − 1251
$ret .= chr(hexdec($arr[$i]));
+ − 1252
}
+ − 1253
return $ret;
+ − 1254
}
+ − 1255
+ − 1256
/**
+ − 1257
* Generates and/or prints a human-readable backtrace
76
+ − 1258
* @param bool $return - if true, this function returns a string, otherwise returns null and prints the backtrace
1
+ − 1259
* @return mixed
+ − 1260
*/
76
+ − 1261
1
+ − 1262
function enano_debug_print_backtrace($return = false)
+ − 1263
{
+ − 1264
ob_start();
+ − 1265
echo '<pre>';
19
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1266
if ( function_exists('debug_print_backtrace') )
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1267
{
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1268
debug_print_backtrace();
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1269
}
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1270
else
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1271
{
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1272
echo '<b>Warning:</b> No debug_print_backtrace() support!';
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1273
}
1
+ − 1274
echo '</pre>';
+ − 1275
$c = ob_get_contents();
+ − 1276
ob_end_clean();
+ − 1277
if($return) return $c;
+ − 1278
else echo $c;
+ − 1279
return null;
+ − 1280
}
+ − 1281
+ − 1282
/**
+ − 1283
* Like rawurlencode(), but encodes all characters
+ − 1284
* @param string $text the text to encode
+ − 1285
* @param optional string $prefix text before each hex character
+ − 1286
* @param optional string $suffix text after each hex character
+ − 1287
* @return string
+ − 1288
*/
76
+ − 1289
1
+ − 1290
function hexencode($text, $prefix = '%', $suffix = '')
+ − 1291
{
+ − 1292
$arr = enano_str_split($text);
+ − 1293
$r = '';
+ − 1294
foreach($arr as $a)
+ − 1295
{
+ − 1296
$nibble = (string)dechex(ord($a));
+ − 1297
if(strlen($nibble) == 1) $nibble = '0' . $nibble;
+ − 1298
$r .= $prefix . $nibble . $suffix;
+ − 1299
}
+ − 1300
return $r;
+ − 1301
}
+ − 1302
+ − 1303
/**
+ − 1304
* Enano-ese equivalent of get_magic_quotes_gpc()
+ − 1305
* @return bool
+ − 1306
*/
76
+ − 1307
1
+ − 1308
function enano_get_magic_quotes_gpc()
+ − 1309
{
+ − 1310
if(function_exists('get_magic_quotes_gpc'))
+ − 1311
{
+ − 1312
return ( get_magic_quotes_gpc() == 1 );
+ − 1313
}
+ − 1314
else
+ − 1315
{
+ − 1316
return ( strtolower(@ini_get('magic_quotes_gpc')) == '1' );
+ − 1317
}
+ − 1318
}
+ − 1319
+ − 1320
/**
+ − 1321
* Recursive stripslashes()
+ − 1322
* @param array
+ − 1323
* @return array
+ − 1324
*/
76
+ − 1325
1
+ − 1326
function stripslashes_recurse($arr)
+ − 1327
{
+ − 1328
foreach($arr as $k => $xxxx)
+ − 1329
{
+ − 1330
$val =& $arr[$k];
+ − 1331
if(is_string($val))
+ − 1332
$val = stripslashes($val);
+ − 1333
elseif(is_array($val))
+ − 1334
$val = stripslashes_recurse($val);
+ − 1335
}
+ − 1336
return $arr;
+ − 1337
}
+ − 1338
+ − 1339
/**
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1340
* Recursive function to remove all NUL bytes from a string
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1341
* @param array
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1342
* @return array
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1343
*/
76
+ − 1344
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1345
function strip_nul_chars($arr)
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1346
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1347
foreach($arr as $k => $xxxx_unused)
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1348
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1349
$val =& $arr[$k];
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1350
if(is_string($val))
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1351
$val = str_replace("\000", '', $val);
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1352
elseif(is_array($val))
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1353
$val = strip_nul_chars($val);
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1354
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1355
return $arr;
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1356
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1357
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1358
/**
76
+ − 1359
* If magic_quotes_gpc is on, calls stripslashes() on everything in $_GET/$_POST/$_COOKIE. Also strips any NUL characters from incoming requests, as these are typically malicious.
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1360
* @ignore - this doesn't work too well in my tests
1
+ − 1361
* @todo port version from the PHP manual
+ − 1362
* @return void
+ − 1363
*/
+ − 1364
function strip_magic_quotes_gpc()
+ − 1365
{
+ − 1366
if(enano_get_magic_quotes_gpc())
+ − 1367
{
40
+ − 1368
$_POST = stripslashes_recurse($_POST);
+ − 1369
$_GET = stripslashes_recurse($_GET);
+ − 1370
$_COOKIE = stripslashes_recurse($_COOKIE);
+ − 1371
$_REQUEST = stripslashes_recurse($_REQUEST);
1
+ − 1372
}
40
+ − 1373
$_POST = strip_nul_chars($_POST);
+ − 1374
$_GET = strip_nul_chars($_GET);
+ − 1375
$_COOKIE = strip_nul_chars($_COOKIE);
+ − 1376
$_REQUEST = strip_nul_chars($_REQUEST);
78
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 1377
$_POST = decode_unicode_array($_POST);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 1378
$_GET = decode_unicode_array($_GET);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 1379
$_COOKIE = decode_unicode_array($_COOKIE);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 1380
$_REQUEST = decode_unicode_array($_REQUEST);
1
+ − 1381
}
+ − 1382
+ − 1383
/**
+ − 1384
* A very basic single-character compression algorithm for binary strings/bitfields
76
+ − 1385
* @param string $bits the text to compress, should be only 1s and 0s
1
+ − 1386
* @return string
+ − 1387
*/
76
+ − 1388
1
+ − 1389
function compress_bitfield($bits)
+ − 1390
{
+ − 1391
$crc32 = crc32($bits);
+ − 1392
$bits .= '0';
+ − 1393
$start_pos = 0;
+ − 1394
$current = substr($bits, 1, 1);
+ − 1395
$last = substr($bits, 0, 1);
+ − 1396
$chunk_size = 1;
+ − 1397
$len = strlen($bits);
+ − 1398
$crc = $len;
+ − 1399
$crcval = 0;
+ − 1400
for ( $i = 1; $i < $len; $i++ )
+ − 1401
{
+ − 1402
$current = substr($bits, $i, 1);
+ − 1403
$last = substr($bits, $i - 1, 1);
+ − 1404
$next = substr($bits, $i + 1, 1);
+ − 1405
// Are we on the last character?
+ − 1406
if($current == $last && $i+1 < $len)
+ − 1407
$chunk_size++;
+ − 1408
else
+ − 1409
{
+ − 1410
if($i+1 == $len && $current == $next)
+ − 1411
{
+ − 1412
// This character completes a chunk
+ − 1413
$chunk_size++;
+ − 1414
$i++;
+ − 1415
$chunk = substr($bits, $start_pos, $chunk_size);
+ − 1416
$chunklen = strlen($chunk);
+ − 1417
$newchunk = $last . '[' . $chunklen . ']';
+ − 1418
$newlen = strlen($newchunk);
+ − 1419
$bits = substr($bits, 0, $start_pos) . $newchunk . substr($bits, $i, $len);
+ − 1420
$chunk_size = 1;
+ − 1421
$i = $start_pos + $newlen;
+ − 1422
$start_pos = $i;
+ − 1423
$len = strlen($bits);
+ − 1424
$crcval = $crcval + $chunklen;
+ − 1425
}
+ − 1426
else
+ − 1427
{
+ − 1428
// Last character completed a chunk
+ − 1429
$chunk = substr($bits, $start_pos, $chunk_size);
+ − 1430
$chunklen = strlen($chunk);
+ − 1431
$newchunk = $last . '[' . $chunklen . '],';
+ − 1432
$newlen = strlen($newchunk);
+ − 1433
$bits = substr($bits, 0, $start_pos) . $newchunk . substr($bits, $i, $len);
+ − 1434
$chunk_size = 1;
+ − 1435
$i = $start_pos + $newlen;
+ − 1436
$start_pos = $i;
+ − 1437
$len = strlen($bits);
+ − 1438
$crcval = $crcval + $chunklen;
+ − 1439
}
+ − 1440
}
+ − 1441
}
+ − 1442
if($crc != $crcval)
+ − 1443
{
+ − 1444
echo __FUNCTION__.'(): ERROR: length check failed, this is a bug in the algorithm<br />Debug info: aiming for a CRC val of '.$crc.', got '.$crcval;
+ − 1445
return false;
+ − 1446
}
+ − 1447
$compressed = 'cbf:len='.$crc.';crc='.dechex($crc32).';data='.$bits.'|end';
+ − 1448
return $compressed;
+ − 1449
}
+ − 1450
+ − 1451
/**
+ − 1452
* Uncompresses a bitfield compressed with compress_bitfield()
+ − 1453
* @param string $bits the compressed bitfield
+ − 1454
* @return string the uncompressed, original (we hope) bitfield OR bool false on error
+ − 1455
*/
76
+ − 1456
1
+ − 1457
function uncompress_bitfield($bits)
+ − 1458
{
+ − 1459
if(substr($bits, 0, 4) != 'cbf:')
+ − 1460
{
+ − 1461
echo __FUNCTION__.'(): ERROR: Invalid stream';
+ − 1462
return false;
+ − 1463
}
+ − 1464
$len = intval(substr($bits, strpos($bits, 'len=')+4, strpos($bits, ';')-strpos($bits, 'len=')-4));
+ − 1465
$crc = substr($bits, strpos($bits, 'crc=')+4, 8);
+ − 1466
$data = substr($bits, strpos($bits, 'data=')+5, strpos($bits, '|end')-strpos($bits, 'data=')-5);
+ − 1467
$data = explode(',', $data);
+ − 1468
foreach($data as $a => $b)
+ − 1469
{
+ − 1470
$d =& $data[$a];
+ − 1471
$char = substr($d, 0, 1);
+ − 1472
$dlen = intval(substr($d, 2, strlen($d)-1));
+ − 1473
$s = '';
+ − 1474
for($i=0;$i<$dlen;$i++,$s.=$char);
+ − 1475
$d = $s;
+ − 1476
unset($s, $dlen, $char);
+ − 1477
}
+ − 1478
$decompressed = implode('', $data);
+ − 1479
$decompressed = substr($decompressed, 0, -1);
+ − 1480
$dcrc = (string)dechex(crc32($decompressed));
+ − 1481
if($dcrc != $crc)
+ − 1482
{
+ − 1483
echo __FUNCTION__.'(): ERROR: CRC check failed<br />debug info:<br />original crc: '.$crc.'<br />decomp\'ed crc: '.$dcrc.'<br />';
+ − 1484
return false;
+ − 1485
}
+ − 1486
return $decompressed;
+ − 1487
}
+ − 1488
+ − 1489
/**
+ − 1490
* Exports a MySQL table into a SQL string.
+ − 1491
* @param string $table The name of the table to export
+ − 1492
* @param bool $structure If true, include a CREATE TABLE command
+ − 1493
* @param bool $data If true, include the contents of the table
+ − 1494
* @param bool $compact If true, omits newlines between parts of SQL statements, use in Enano database exporter
+ − 1495
* @return string
+ − 1496
*/
+ − 1497
+ − 1498
function export_table($table, $structure = true, $data = true, $compact = false)
+ − 1499
{
+ − 1500
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1501
$struct_keys = '';
+ − 1502
$divider = (!$compact) ? "\n" : "\n";
+ − 1503
$spacer1 = (!$compact) ? "\n" : " ";
+ − 1504
$spacer2 = (!$compact) ? " " : " ";
+ − 1505
$rowspacer = (!$compact) ? "\n " : " ";
+ − 1506
$index_list = Array();
+ − 1507
$cols = $db->sql_query('SHOW COLUMNS IN '.$table.';');
+ − 1508
if(!$cols)
+ − 1509
{
+ − 1510
echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />';
+ − 1511
return false;
+ − 1512
}
+ − 1513
$col = Array();
+ − 1514
$sqlcol = Array();
+ − 1515
$collist = Array();
+ − 1516
$pri_keys = Array();
+ − 1517
// Using fetchrow_num() here to compensate for MySQL l10n
+ − 1518
while( $row = $db->fetchrow_num() )
+ − 1519
{
+ − 1520
$field =& $row[0];
+ − 1521
$type =& $row[1];
+ − 1522
$null =& $row[2];
+ − 1523
$key =& $row[3];
+ − 1524
$def =& $row[4];
+ − 1525
$extra =& $row[5];
+ − 1526
$col[] = Array(
+ − 1527
'name'=>$field,
+ − 1528
'type'=>$type,
+ − 1529
'null'=>$null,
+ − 1530
'key'=>$key,
+ − 1531
'default'=>$def,
+ − 1532
'extra'=>$extra,
+ − 1533
);
+ − 1534
$collist[] = $field;
+ − 1535
}
76
+ − 1536
1
+ − 1537
if ( $structure )
+ − 1538
{
+ − 1539
$db->sql_query('SET SQL_QUOTE_SHOW_CREATE = 0;');
+ − 1540
$struct = $db->sql_query('SHOW CREATE TABLE '.$table.';');
+ − 1541
if ( !$struct )
+ − 1542
$db->_die();
+ − 1543
$row = $db->fetchrow_num();
+ − 1544
$db->free_result();
+ − 1545
$struct = $row[1];
+ − 1546
$struct = preg_replace("/\n\) ENGINE=(.+)$/", "\n);", $struct);
+ − 1547
unset($row);
+ − 1548
if ( $compact )
+ − 1549
{
+ − 1550
$struct_arr = explode("\n", $struct);
+ − 1551
foreach ( $struct_arr as $i => $leg )
+ − 1552
{
+ − 1553
if ( $i == 0 )
+ − 1554
continue;
+ − 1555
$test = trim($leg);
+ − 1556
if ( empty($test) )
+ − 1557
{
+ − 1558
unset($struct_arr[$i]);
+ − 1559
continue;
+ − 1560
}
+ − 1561
$struct_arr[$i] = preg_replace('/^([\s]*)/', ' ', $leg);
+ − 1562
}
+ − 1563
$struct = implode("", $struct_arr);
+ − 1564
}
+ − 1565
}
76
+ − 1566
1
+ − 1567
// Structuring complete
+ − 1568
if($data)
+ − 1569
{
+ − 1570
$datq = $db->sql_query('SELECT * FROM '.$table.';');
+ − 1571
if(!$datq)
+ − 1572
{
+ − 1573
echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />';
+ − 1574
return false;
+ − 1575
}
+ − 1576
if($db->numrows() < 1)
+ − 1577
{
+ − 1578
if($structure) return $struct;
+ − 1579
else return '';
+ − 1580
}
+ − 1581
$rowdata = Array();
+ − 1582
$dataqs = Array();
+ − 1583
$insert_strings = Array();
+ − 1584
$z = false;
+ − 1585
while($row = $db->fetchrow_num())
+ − 1586
{
+ − 1587
$z = false;
+ − 1588
foreach($row as $i => $cell)
+ − 1589
{
+ − 1590
$str = mysql_encode_column($cell, $col[$i]['type']);
+ − 1591
$rowdata[] = $str;
+ − 1592
}
+ − 1593
$dataqs2 = implode(",$rowspacer", $dataqs) . ",$rowspacer" . '( ' . implode(', ', $rowdata) . ' )';
+ − 1594
$ins = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . $dataqs2 . ";";
+ − 1595
if ( strlen( $ins ) > MYSQL_MAX_PACKET_SIZE )
+ − 1596
{
+ − 1597
// We've exceeded the maximum allowed packet size for MySQL - separate this into a different query
+ − 1598
$insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";;
+ − 1599
$dataqs = Array('( ' . implode(', ', $rowdata) . ' )');
+ − 1600
$z = true;
+ − 1601
}
+ − 1602
else
+ − 1603
{
+ − 1604
$dataqs[] = '( ' . implode(', ', $rowdata) . ' )';
+ − 1605
}
+ − 1606
$rowdata = Array();
+ − 1607
}
+ − 1608
if ( !$z )
+ − 1609
{
+ − 1610
$insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";;
+ − 1611
$dataqs = Array();
+ − 1612
}
+ − 1613
$datstring = implode($divider, $insert_strings);
+ − 1614
}
+ − 1615
if($structure && !$data) return $struct;
+ − 1616
elseif(!$structure && $data) return $datstring;
+ − 1617
elseif($structure && $data) return $struct . $divider . $datstring;
+ − 1618
elseif(!$structure && !$data) return '';
+ − 1619
}
+ − 1620
+ − 1621
/**
+ − 1622
* Encodes a string value for use in an INSERT statement for given column type $type.
+ − 1623
* @access private
+ − 1624
*/
76
+ − 1625
1
+ − 1626
function mysql_encode_column($input, $type)
+ − 1627
{
+ − 1628
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1629
// Decide whether to quote the string or not
+ − 1630
if(substr($type, 0, 7) == 'varchar' || $type == 'datetime' || $type == 'text' || $type == 'tinytext' || $type == 'smalltext' || $type == 'longtext' || substr($type, 0, 4) == 'char')
+ − 1631
{
+ − 1632
$str = "'" . $db->escape($input) . "'";
+ − 1633
}
+ − 1634
elseif(in_array($type, Array('blob', 'longblob', 'mediumblob', 'smallblob')) || substr($type, 0, 6) == 'binary' || substr($type, 0, 9) == 'varbinary')
+ − 1635
{
+ − 1636
$str = '0x' . hexencode($input, '', '');
+ − 1637
}
+ − 1638
elseif(is_null($input))
+ − 1639
{
+ − 1640
$str = 'NULL';
+ − 1641
}
+ − 1642
else
+ − 1643
{
+ − 1644
$str = (string)$input;
+ − 1645
}
+ − 1646
return $str;
+ − 1647
}
+ − 1648
+ − 1649
/**
+ − 1650
* Creates an associative array defining which file extensions are allowed and which ones aren't
+ − 1651
* @return array keyname will be a file extension, value will be true or false
+ − 1652
*/
+ − 1653
+ − 1654
function fetch_allowed_extensions()
+ − 1655
{
+ − 1656
global $mime_types;
+ − 1657
$bits = getConfig('allowed_mime_types');
+ − 1658
if(!$bits) return Array(false);
+ − 1659
$bits = uncompress_bitfield($bits);
+ − 1660
if(!$bits) return Array(false);
+ − 1661
$bits = enano_str_split($bits, 1);
+ − 1662
$ret = Array();
+ − 1663
$mt = array_keys($mime_types);
+ − 1664
foreach($bits as $i => $b)
+ − 1665
{
+ − 1666
$ret[$mt[$i]] = ( $b == '1' ) ? true : false;
+ − 1667
}
+ − 1668
return $ret;
+ − 1669
}
+ − 1670
+ − 1671
/**
+ − 1672
* Generates a random key suitable for encryption
+ − 1673
* @param int $len the length of the key
+ − 1674
* @return string a BINARY key
+ − 1675
*/
+ − 1676
+ − 1677
function randkey($len = 32)
+ − 1678
{
+ − 1679
$key = '';
+ − 1680
for($i=0;$i<$len;$i++)
+ − 1681
{
+ − 1682
$key .= chr(mt_rand(0, 255));
+ − 1683
}
+ − 1684
return $key;
+ − 1685
}
+ − 1686
+ − 1687
/**
+ − 1688
* Decodes a hex string.
+ − 1689
* @param string $hex The hex code to decode
+ − 1690
* @return string
+ − 1691
*/
+ − 1692
+ − 1693
function hexdecode($hex)
+ − 1694
{
+ − 1695
$hex = enano_str_split($hex, 2);
+ − 1696
$bin_key = '';
+ − 1697
foreach($hex as $nibble)
+ − 1698
{
+ − 1699
$byte = chr(hexdec($nibble));
+ − 1700
$bin_key .= $byte;
+ − 1701
}
+ − 1702
return $bin_key;
+ − 1703
}
+ − 1704
+ − 1705
/**
+ − 1706
* Enano's own (almost) bulletproof HTML sanitizer.
+ − 1707
* @param string $html The input HTML
+ − 1708
* @return string cleaned HTML
+ − 1709
*/
+ − 1710
+ − 1711
function sanitize_html($html, $filter_php = true)
+ − 1712
{
162
+ − 1713
// Random seed for substitution
+ − 1714
$rand_seed = md5( sha1(microtime()) . mt_rand() );
+ − 1715
+ − 1716
// Strip out comments that are already escaped
+ − 1717
preg_match_all('/<!--(.*?)-->/', $html, $comment_match);
+ − 1718
$i = 0;
+ − 1719
foreach ( $comment_match[0] as $comment )
+ − 1720
{
+ − 1721
$html = str_replace_once($comment, "{HTMLCOMMENT:$i:$rand_seed}", $html);
+ − 1722
$i++;
+ − 1723
}
+ − 1724
+ − 1725
// Strip out code sections that will be postprocessed by Text_Wiki
+ − 1726
preg_match_all(';^<code(\s[^>]*)?>((?:(?R)|.)*?)\n</code>(\s|$);msi', $html, $code_match);
+ − 1727
$i = 0;
+ − 1728
foreach ( $code_match[0] as $code )
+ − 1729
{
+ − 1730
$html = str_replace_once($code, "{TW_CODE:$i:$rand_seed}", $html);
+ − 1731
$i++;
+ − 1732
}
76
+ − 1733
1
+ − 1734
$html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>(.*?)</\\1>#is', '<\\1\\2\\3javascript:\\59>\\60</\\1>', $html);
+ − 1735
$html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>#is', '<\\1\\2\\3javascript:\\59>', $html);
76
+ − 1736
1
+ − 1737
if($filter_php)
+ − 1738
$html = str_replace(
+ − 1739
Array('<?php', '<?', '<%', '?>', '%>'),
+ − 1740
Array('<?php', '<?', '<%', '?>', '%>'),
+ − 1741
$html);
76
+ − 1742
1
+ − 1743
$tag_whitelist = array_keys ( setupAttributeWhitelist() );
+ − 1744
if ( !$filter_php )
+ − 1745
$tag_whitelist[] = '?php';
163
+ − 1746
// allow HTML comments
+ − 1747
$tag_whitelist[] = '!--';
1
+ − 1748
$len = strlen($html);
+ − 1749
$in_quote = false;
+ − 1750
$quote_char = '';
+ − 1751
$tag_start = 0;
+ − 1752
$tag_name = '';
+ − 1753
$in_tag = false;
+ − 1754
$trk_name = false;
+ − 1755
for ( $i = 0; $i < $len; $i++ )
+ − 1756
{
+ − 1757
$chr = $html{$i};
+ − 1758
$prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
+ − 1759
$next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
+ − 1760
if ( $in_quote && $in_tag )
+ − 1761
{
+ − 1762
if ( $quote_char == $chr && $prev != '\\' )
+ − 1763
$in_quote = false;
+ − 1764
}
+ − 1765
elseif ( ( $chr == '"' || $chr == "'" ) && $prev != '\\' && $in_tag )
+ − 1766
{
+ − 1767
$in_quote = true;
+ − 1768
$quote_char = $chr;
+ − 1769
}
+ − 1770
if ( $chr == '<' && !$in_tag && $next != '/' )
76
+ − 1771
{
1
+ − 1772
// start of a tag
+ − 1773
$tag_start = $i;
+ − 1774
$in_tag = true;
+ − 1775
$trk_name = true;
+ − 1776
}
+ − 1777
elseif ( !$in_quote && $in_tag && $chr == '>' )
+ − 1778
{
+ − 1779
$full_tag = substr($html, $tag_start, ( $i - $tag_start ) + 1 );
+ − 1780
$l = strlen($tag_name) + 2;
+ − 1781
$attribs_only = trim( substr($full_tag, $l, ( strlen($full_tag) - $l - 1 ) ) );
76
+ − 1782
1
+ − 1783
// Debugging message
+ − 1784
// echo htmlspecialchars($full_tag) . '<br />';
76
+ − 1785
1
+ − 1786
if ( !in_array($tag_name, $tag_whitelist) )
+ − 1787
{
+ − 1788
// Illegal tag
+ − 1789
//echo $tag_name . ' ';
76
+ − 1790
1
+ − 1791
$s = ( empty($attribs_only) ) ? '' : ' ';
76
+ − 1792
1
+ − 1793
$sanitized = '<' . $tag_name . $s . $attribs_only . '>';
76
+ − 1794
1
+ − 1795
$html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1);
+ − 1796
$html = str_replace('</' . $tag_name . '>', '</' . $tag_name . '>', $html);
+ − 1797
$new_i = $tag_start + strlen($sanitized);
76
+ − 1798
1
+ − 1799
$len = strlen($html);
+ − 1800
$i = $new_i;
76
+ − 1801
1
+ − 1802
$in_tag = false;
+ − 1803
$tag_name = '';
+ − 1804
continue;
+ − 1805
}
+ − 1806
else
+ − 1807
{
163
+ − 1808
// If not filtering PHP, don't bother to strip
1
+ − 1809
if ( $tag_name == '?php' && !$filter_php )
+ − 1810
continue;
163
+ − 1811
// If this is a comment, likewise skip this "tag"
+ − 1812
if ( $tag_name == '!--' )
+ − 1813
continue;
1
+ − 1814
$f = fixTagAttributes( $attribs_only, $tag_name );
+ − 1815
$s = ( empty($f) ) ? '' : ' ';
76
+ − 1816
1
+ − 1817
$sanitized = '<' . $tag_name . $f . '>';
+ − 1818
$new_i = $tag_start + strlen($sanitized);
76
+ − 1819
1
+ − 1820
$html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1);
+ − 1821
$len = strlen($html);
+ − 1822
$i = $new_i;
76
+ − 1823
1
+ − 1824
$in_tag = false;
+ − 1825
$tag_name = '';
+ − 1826
continue;
+ − 1827
}
+ − 1828
}
+ − 1829
elseif ( $in_tag && $trk_name )
+ − 1830
{
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 1831
$is_alphabetical = ( strtolower($chr) != strtoupper($chr) || in_array($chr, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) || $chr == '?' || $chr == '!' || $chr == '-' );
1
+ − 1832
if ( $is_alphabetical )
+ − 1833
$tag_name .= $chr;
+ − 1834
else
+ − 1835
{
+ − 1836
$trk_name = false;
+ − 1837
}
+ − 1838
}
76
+ − 1839
1
+ − 1840
}
163
+ − 1841
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
+ − 1842
// Vulnerability from ha.ckers.org/xss.html:
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1843
// <script src="http://foo.com/xss.js"
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1844
// <
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1845
// The rule is so specific because everything else will have been filtered by now
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1846
$html = preg_replace('/<(script|iframe)(.+?)src=([^>]*)</i', '<\\1\\2src=\\3<', $html);
76
+ − 1847
162
+ − 1848
// Restore stripped comments
+ − 1849
$i = 0;
+ − 1850
foreach ( $comment_match[0] as $comment )
+ − 1851
{
+ − 1852
$html = str_replace_once("{HTMLCOMMENT:$i:$rand_seed}", $comment, $html);
+ − 1853
$i++;
+ − 1854
}
+ − 1855
+ − 1856
// Restore stripped code
+ − 1857
$i = 0;
+ − 1858
foreach ( $code_match[0] as $code )
+ − 1859
{
+ − 1860
$html = str_replace_once("{TW_CODE:$i:$rand_seed}", $code, $html);
+ − 1861
$i++;
+ − 1862
}
76
+ − 1863
1
+ − 1864
return $html;
76
+ − 1865
1
+ − 1866
}
+ − 1867
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1868
/**
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1869
* Using the same parsing code as sanitize_html(), this function adds <litewiki> tags around certain block-level elements
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1870
* @param string $html The input HTML
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1871
* @return string formatted HTML
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1872
*/
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1873
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1874
function wikiformat_process_block($html)
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1875
{
76
+ − 1876
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1877
$tok1 = "<litewiki>";
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1878
$tok2 = "</litewiki>";
76
+ − 1879
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1880
$block_tags = array('div', 'p', 'table', 'blockquote', 'pre');
76
+ − 1881
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1882
$len = strlen($html);
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1883
$in_quote = false;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1884
$quote_char = '';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1885
$tag_start = 0;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1886
$tag_name = '';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1887
$in_tag = false;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1888
$trk_name = false;
76
+ − 1889
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1890
$diag = 0;
76
+ − 1891
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1892
$block_tagname = '';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1893
$in_blocksec = 0;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1894
$block_start = 0;
76
+ − 1895
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1896
for ( $i = 0; $i < $len; $i++ )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1897
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1898
$chr = $html{$i};
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1899
$prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1900
$next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
76
+ − 1901
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1902
// Are we inside of a quoted section?
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1903
if ( $in_quote && $in_tag )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1904
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1905
if ( $quote_char == $chr && $prev != '\\' )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1906
$in_quote = false;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1907
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1908
elseif ( ( $chr == '"' || $chr == "'" ) && $prev != '\\' && $in_tag )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1909
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1910
$in_quote = true;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1911
$quote_char = $chr;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1912
}
76
+ − 1913
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1914
if ( $chr == '<' && !$in_tag && $next == '/' )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1915
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1916
// Iterate through until we've got a tag name
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1917
$tag_name = '';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1918
$i++;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1919
while(true)
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1920
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1921
$i++;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1922
// echo $i . ' ';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1923
$chr = $html{$i};
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1924
$prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1925
$next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1926
$tag_name .= $chr;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1927
if ( $next == '>' )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1928
break;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1929
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1930
// echo '<br />';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1931
if ( in_array($tag_name, $block_tags) )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1932
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1933
if ( $block_tagname == $tag_name )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1934
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1935
$in_blocksec -= 1;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1936
if ( $in_blocksec == 0 )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1937
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1938
$block_tagname = '';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1939
$i += 2;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1940
// echo 'Finished wiki litewiki wraparound calc at pos: ' . $i;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1941
$full_litewiki = substr($html, $block_start, ( $i - $block_start ));
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1942
$new_text = "{$tok1}{$full_litewiki}{$tok2}";
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1943
$html = substr($html, 0, $block_start) . $new_text . substr($html, $i);
76
+ − 1944
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1945
$i += ( strlen($tok1) + strlen($tok2) ) - 1;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1946
$len = strlen($html);
76
+ − 1947
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1948
//die('<pre>' . htmlspecialchars($html) . '</pre>');
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1949
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1950
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1951
}
76
+ − 1952
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1953
$in_tag = false;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1954
$in_quote = false;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1955
$tag_name = '';
76
+ − 1956
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1957
continue;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1958
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1959
else if ( $chr == '<' && !$in_tag && $next != '/' )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1960
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1961
// start of a tag
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1962
$tag_start = $i;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1963
$in_tag = true;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1964
$trk_name = true;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1965
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1966
else if ( !$in_quote && $in_tag && $chr == '>' )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1967
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1968
if ( !in_array($tag_name, $block_tags) )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1969
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1970
// Inline tag - reset and go to the next one
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1971
// echo '<inline ' . $tag_name . '> ';
76
+ − 1972
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1973
$in_tag = false;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1974
$tag_name = '';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1975
continue;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1976
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1977
else
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1978
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1979
// echo '<block: ' . $tag_name . ' @ ' . $i . '><br/>';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1980
if ( $in_blocksec == 0 )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1981
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1982
//die('Found a starting tag for a block element: ' . $tag_name . ' at pos ' . $tag_start);
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1983
$block_tagname = $tag_name;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1984
$block_start = $tag_start;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1985
$in_blocksec++;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1986
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1987
else if ( $block_tagname == $tag_name )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1988
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1989
$in_blocksec++;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1990
}
76
+ − 1991
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1992
$in_tag = false;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1993
$tag_name = '';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1994
continue;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1995
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1996
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1997
elseif ( $in_tag && $trk_name )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1998
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 1999
$is_alphabetical = ( strtolower($chr) != strtoupper($chr) || in_array($chr, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) || $chr == '?' || $chr == '!' || $chr == '-' );
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2000
if ( $is_alphabetical )
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2001
$tag_name .= $chr;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2002
else
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2003
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2004
$trk_name = false;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2005
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2006
}
76
+ − 2007
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2008
// Tokenization complete
76
+ − 2009
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2010
}
76
+ − 2011
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2012
$regex = '/' . str_replace('/', '\\/', preg_quote($tok2)) . '([\s]*)' . preg_quote($tok1) . '/is';
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2013
// die(htmlspecialchars($regex));
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2014
$html = preg_replace($regex, '\\1', $html);
76
+ − 2015
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2016
return $html;
76
+ − 2017
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2018
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2019
1
+ − 2020
function htmlalternatives($string)
+ − 2021
{
+ − 2022
$ret = '';
+ − 2023
for ( $i = 0; $i < strlen($string); $i++ )
+ − 2024
{
+ − 2025
$chr = $string{$i};
+ − 2026
$ch1 = ord($chr);
+ − 2027
$ch2 = dechex($ch1);
+ − 2028
$byte = '(&\\#([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch1 . ';|\\\\([0]*){0,7}' . $ch2 . ';|&\\#x([0]*){0,7}' . $ch2 . ';|%([0]*){0,7}' . $ch2 . '|' . preg_quote($chr) . ')';
+ − 2029
$ret .= $byte;
+ − 2030
$ret .= '([\s]){0,2}';
+ − 2031
}
+ − 2032
return $ret;
+ − 2033
}
+ − 2034
+ − 2035
/**
+ − 2036
* Paginates (breaks into multiple pages) a MySQL result resource, which is treated as unbuffered.
+ − 2037
* @param resource The MySQL result resource. This should preferably be an unbuffered query.
+ − 2038
* @param string A template, with variables being named after the column name
+ − 2039
* @param int The number of total results. This should be determined by a second query.
+ − 2040
* @param string sprintf-style formatting string for URLs for result pages. First parameter will be start offset.
+ − 2041
* @param int Optional. Start offset in individual results. Defaults to 0.
+ − 2042
* @param int Optional. The number of results per page. Defualts to 10.
+ − 2043
* @param int Optional. An associative array of functions to call, with key names being column names, and values being function names. Values can also be an array with key 0 being either an object or a string(class name) and key 1 being a [static] method.
+ − 2044
* @param string Optional. The text to be sent before the result list, only if there are any results. Possibly the start of a table.
+ − 2045
* @param string Optional. The text to be sent after the result list, only if there are any results. Possibly the end of a table.
+ − 2046
* @return string
+ − 2047
*/
+ − 2048
+ − 2049
function paginate($q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = '')
+ − 2050
{
+ − 2051
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 2052
$parser = $template->makeParserText($tpl_text);
+ − 2053
$num_pages = ceil ( $num_results / $perpage );
+ − 2054
$out = '';
+ − 2055
$i = 0;
+ − 2056
$this_page = ceil ( $start / $perpage );
76
+ − 2057
1
+ − 2058
// Build paginator
82
+ − 2059
$pg_css = ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ?
+ − 2060
// IE-specific hack
+ − 2061
'display: block; width: 1px;':
+ − 2062
// Other browsers
+ − 2063
'display: table; margin: 10px 0 0 auto;';
+ − 2064
$begin = '<div class="tblholder" style="'. $pg_css . '">
1
+ − 2065
<table border="0" cellspacing="1" cellpadding="4">
+ − 2066
<tr><th>Page:</th>';
+ − 2067
$block = '<td class="row1" style="text-align: center;">{LINK}</td>';
+ − 2068
$end = '</tr></table></div>';
+ − 2069
$blk = $template->makeParserText($block);
+ − 2070
$inner = '';
+ − 2071
$cls = 'row2';
+ − 2072
if ( $num_pages < 5 )
+ − 2073
{
+ − 2074
for ( $i = 0; $i < $num_pages; $i++ )
+ − 2075
{
+ − 2076
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2077
$offset = strval($i * $perpage);
76
+ − 2078
$url = htmlspecialchars(sprintf($result_url, $offset));
1
+ − 2079
$j = $i + 1;
+ − 2080
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2081
$blk->assign_vars(array(
+ − 2082
'CLASS'=>$cls,
+ − 2083
'LINK'=>$link
+ − 2084
));
+ − 2085
$inner .= $blk->run();
+ − 2086
}
+ − 2087
}
+ − 2088
else
+ − 2089
{
+ − 2090
if ( $this_page + 5 > $num_pages )
+ − 2091
{
+ − 2092
$list = Array();
+ − 2093
$tp = $this_page;
+ − 2094
if ( $this_page + 0 == $num_pages ) $tp = $tp - 3;
+ − 2095
if ( $this_page + 1 == $num_pages ) $tp = $tp - 2;
+ − 2096
if ( $this_page + 2 == $num_pages ) $tp = $tp - 1;
+ − 2097
for ( $i = $tp - 1; $i <= $tp + 1; $i++ )
+ − 2098
{
+ − 2099
$list[] = $i;
+ − 2100
}
+ − 2101
}
+ − 2102
else
+ − 2103
{
+ − 2104
$list = Array();
+ − 2105
$current = $this_page;
+ − 2106
$lower = ( $current < 3 ) ? 1 : $current - 1;
+ − 2107
for ( $i = 0; $i < 3; $i++ )
+ − 2108
{
+ − 2109
$list[] = $lower + $i;
+ − 2110
}
+ − 2111
}
+ − 2112
$url = sprintf($result_url, '0');
+ − 2113
$link = ( 0 == $start ) ? "<b>First</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« First</a>";
+ − 2114
$blk->assign_vars(array(
+ − 2115
'CLASS'=>$cls,
+ − 2116
'LINK'=>$link
+ − 2117
));
+ − 2118
$inner .= $blk->run();
76
+ − 2119
1
+ − 2120
// if ( !in_array(1, $list) )
+ − 2121
// {
+ − 2122
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2123
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ − 2124
// $inner .= $blk->run();
+ − 2125
// }
76
+ − 2126
1
+ − 2127
foreach ( $list as $i )
+ − 2128
{
+ − 2129
if ( $i == $num_pages )
+ − 2130
break;
+ − 2131
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2132
$offset = strval($i * $perpage);
+ − 2133
$url = sprintf($result_url, $offset);
+ − 2134
$j = $i + 1;
+ − 2135
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2136
$blk->assign_vars(array(
+ − 2137
'CLASS'=>$cls,
+ − 2138
'LINK'=>$link
+ − 2139
));
+ − 2140
$inner .= $blk->run();
+ − 2141
}
76
+ − 2142
1
+ − 2143
$total = $num_pages * $perpage - $perpage;
76
+ − 2144
1
+ − 2145
if ( $this_page < $num_pages )
+ − 2146
{
+ − 2147
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2148
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ − 2149
// $inner .= $blk->run();
76
+ − 2150
1
+ − 2151
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2152
$offset = strval($total);
+ − 2153
$url = sprintf($result_url, $offset);
+ − 2154
$j = $i + 1;
+ − 2155
$link = ( $offset == strval($start) ) ? "<b>Last</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Last »</a>";
+ − 2156
$blk->assign_vars(array(
+ − 2157
'CLASS'=>$cls,
+ − 2158
'LINK'=>$link
+ − 2159
));
+ − 2160
$inner .= $blk->run();
+ − 2161
}
76
+ − 2162
1
+ − 2163
}
76
+ − 2164
1
+ − 2165
$inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$this_page.', '.$num_pages.', '.$perpage.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>';
76
+ − 2166
1
+ − 2167
$paginator = "\n$begin$inner$end\n";
+ − 2168
$out .= $paginator;
76
+ − 2169
1
+ − 2170
$cls = 'row2';
76
+ − 2171
1
+ − 2172
if ( $row = $db->fetchrow($q) )
+ − 2173
{
+ − 2174
$i = 0;
+ − 2175
$out .= $header;
+ − 2176
do {
+ − 2177
$i++;
+ − 2178
if ( $i <= $start )
+ − 2179
{
+ − 2180
continue;
+ − 2181
}
+ − 2182
if ( ( $i - $start ) > $perpage )
+ − 2183
{
+ − 2184
break;
+ − 2185
}
+ − 2186
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2187
foreach ( $row as $j => $val )
+ − 2188
{
+ − 2189
if ( isset($callers[$j]) )
+ − 2190
{
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 2191
$tmp = ( is_callable($callers[$j]) ) ? @call_user_func($callers[$j], $val, $row) : $val;
76
+ − 2192
1
+ − 2193
if ( $tmp )
+ − 2194
{
+ − 2195
$row[$j] = $tmp;
+ − 2196
}
+ − 2197
}
+ − 2198
}
+ − 2199
$parser->assign_vars($row);
+ − 2200
$parser->assign_vars(array('_css_class' => $cls));
+ − 2201
$out .= $parser->run();
+ − 2202
} while ( $row = $db->fetchrow($q) );
+ − 2203
$out .= $footer;
+ − 2204
}
76
+ − 2205
1
+ − 2206
$out .= $paginator;
76
+ − 2207
1
+ − 2208
return $out;
+ − 2209
}
+ − 2210
+ − 2211
/**
+ − 2212
* This is the same as paginate(), but it processes an array instead of a MySQL result resource.
+ − 2213
* @param array The results. Each value is simply echoed.
+ − 2214
* @param int The number of total results. This should be determined by a second query.
+ − 2215
* @param string sprintf-style formatting string for URLs for result pages. First parameter will be start offset.
+ − 2216
* @param int Optional. Start offset in individual results. Defaults to 0.
+ − 2217
* @param int Optional. The number of results per page. Defualts to 10.
+ − 2218
* @param string Optional. The text to be sent before the result list, only if there are any results. Possibly the start of a table.
+ − 2219
* @param string Optional. The text to be sent after the result list, only if there are any results. Possibly the end of a table.
+ − 2220
* @return string
+ − 2221
*/
+ − 2222
+ − 2223
function paginate_array($q, $num_results, $result_url, $start = 0, $perpage = 10, $header = '', $footer = '')
+ − 2224
{
+ − 2225
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 2226
$num_pages = ceil ( $num_results / $perpage );
+ − 2227
$out = '';
+ − 2228
$i = 0;
+ − 2229
$this_page = ceil ( $start / $perpage );
76
+ − 2230
1
+ − 2231
// Build paginator
+ − 2232
$begin = '<div class="tblholder" style="display: table; margin: 10px 0 0 auto;">
+ − 2233
<table border="0" cellspacing="1" cellpadding="4">
+ − 2234
<tr><th>Page:</th>';
+ − 2235
$block = '<td class="row1" style="text-align: center;">{LINK}</td>';
+ − 2236
$end = '</tr></table></div>';
+ − 2237
$blk = $template->makeParserText($block);
+ − 2238
$inner = '';
+ − 2239
$cls = 'row2';
218
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 2240
$total = $num_pages * $perpage - $perpage;
1
+ − 2241
if ( $start > 0 )
+ − 2242
{
+ − 2243
$url = sprintf($result_url, abs($start - $perpage));
+ − 2244
$link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« Prev</a>";
+ − 2245
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2246
$blk->assign_vars(array(
+ − 2247
'CLASS'=>$cls,
+ − 2248
'LINK'=>$link
+ − 2249
));
+ − 2250
$inner .= $blk->run();
+ − 2251
}
+ − 2252
if ( $num_pages < 5 )
+ − 2253
{
+ − 2254
for ( $i = 0; $i < $num_pages; $i++ )
+ − 2255
{
+ − 2256
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2257
$offset = strval($i * $perpage);
76
+ − 2258
$url = htmlspecialchars(sprintf($result_url, $offset));
1
+ − 2259
$j = $i + 1;
+ − 2260
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2261
$blk->assign_vars(array(
+ − 2262
'CLASS'=>$cls,
+ − 2263
'LINK'=>$link
+ − 2264
));
+ − 2265
$inner .= $blk->run();
+ − 2266
}
+ − 2267
}
+ − 2268
else
+ − 2269
{
+ − 2270
if ( $this_page + 5 > $num_pages )
+ − 2271
{
+ − 2272
$list = Array();
+ − 2273
$tp = $this_page;
+ − 2274
if ( $this_page + 0 == $num_pages ) $tp = $tp - 3;
+ − 2275
if ( $this_page + 1 == $num_pages ) $tp = $tp - 2;
+ − 2276
if ( $this_page + 2 == $num_pages ) $tp = $tp - 1;
+ − 2277
for ( $i = $tp - 1; $i <= $tp + 1; $i++ )
+ − 2278
{
+ − 2279
$list[] = $i;
+ − 2280
}
+ − 2281
}
+ − 2282
else
+ − 2283
{
+ − 2284
$list = Array();
+ − 2285
$current = $this_page;
+ − 2286
$lower = ( $current < 3 ) ? 1 : $current - 1;
+ − 2287
for ( $i = 0; $i < 3; $i++ )
+ − 2288
{
+ − 2289
$list[] = $lower + $i;
+ − 2290
}
+ − 2291
}
+ − 2292
$url = sprintf($result_url, '0');
+ − 2293
$link = ( 0 == $start ) ? "<b>First</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« First</a>";
+ − 2294
$blk->assign_vars(array(
+ − 2295
'CLASS'=>$cls,
+ − 2296
'LINK'=>$link
+ − 2297
));
+ − 2298
$inner .= $blk->run();
76
+ − 2299
1
+ − 2300
// if ( !in_array(1, $list) )
+ − 2301
// {
+ − 2302
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2303
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ − 2304
// $inner .= $blk->run();
+ − 2305
// }
76
+ − 2306
1
+ − 2307
foreach ( $list as $i )
+ − 2308
{
+ − 2309
if ( $i == $num_pages )
+ − 2310
break;
+ − 2311
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2312
$offset = strval($i * $perpage);
+ − 2313
$url = sprintf($result_url, $offset);
+ − 2314
$j = $i + 1;
+ − 2315
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2316
$blk->assign_vars(array(
+ − 2317
'CLASS'=>$cls,
+ − 2318
'LINK'=>$link
+ − 2319
));
+ − 2320
$inner .= $blk->run();
+ − 2321
}
76
+ − 2322
1
+ − 2323
if ( $this_page < $num_pages )
+ − 2324
{
+ − 2325
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2326
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ − 2327
// $inner .= $blk->run();
76
+ − 2328
1
+ − 2329
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2330
$offset = strval($total);
+ − 2331
$url = sprintf($result_url, $offset);
+ − 2332
$j = $i + 1;
+ − 2333
$link = ( $offset == strval($start) ) ? "<b>Last</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Last »</a>";
+ − 2334
$blk->assign_vars(array(
+ − 2335
'CLASS'=>$cls,
+ − 2336
'LINK'=>$link
+ − 2337
));
+ − 2338
$inner .= $blk->run();
+ − 2339
}
76
+ − 2340
1
+ − 2341
}
76
+ − 2342
1
+ − 2343
if ( $start < $total )
+ − 2344
{
218
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 2345
$link_offset = abs($start + $perpage);
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 2346
// i'm tired of debugging a defective sprintf
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 2347
$url = htmlspecialchars(sprintf($result_url, strval($link_offset)));
1
+ − 2348
$link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Next »</a>";
+ − 2349
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2350
$blk->assign_vars(array(
+ − 2351
'CLASS'=>$cls,
+ − 2352
'LINK'=>$link
+ − 2353
));
+ − 2354
$inner .= $blk->run();
+ − 2355
}
76
+ − 2356
1
+ − 2357
$inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$this_page.', '.$num_pages.', '.$perpage.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>';
76
+ − 2358
1
+ − 2359
$paginator = "\n$begin$inner$end\n";
+ − 2360
if ( $total > 1 )
218
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 2361
{
1
+ − 2362
$out .= $paginator;
218
e0ec986c0af3
Searching sucks, and Enano's search algorithm was complete bullcrap. So I rewrote it. No, it does not use Google search technology. Like they have a patent for using the Arial font on search result pages anyway.
Dan
diff
changeset
+ − 2363
}
76
+ − 2364
1
+ − 2365
$cls = 'row2';
76
+ − 2366
1
+ − 2367
if ( sizeof($q) > 0 )
+ − 2368
{
+ − 2369
$i = 0;
+ − 2370
$out .= $header;
+ − 2371
foreach ( $q as $val ) {
+ − 2372
$i++;
+ − 2373
if ( $i <= $start )
+ − 2374
{
+ − 2375
continue;
+ − 2376
}
+ − 2377
if ( ( $i - $start ) > $perpage )
+ − 2378
{
+ − 2379
break;
+ − 2380
}
+ − 2381
$out .= $val;
+ − 2382
}
+ − 2383
$out .= $footer;
+ − 2384
}
76
+ − 2385
1
+ − 2386
if ( $total > 1 )
+ − 2387
$out .= $paginator;
76
+ − 2388
1
+ − 2389
return $out;
+ − 2390
}
+ − 2391
76
+ − 2392
/**
1
+ − 2393
* Enano version of fputs for debugging
+ − 2394
*/
+ − 2395
+ − 2396
function enano_fputs($socket, $data)
+ − 2397
{
+ − 2398
// echo '<pre>' . htmlspecialchars($data) . '</pre>';
+ − 2399
// flush();
+ − 2400
// ob_flush();
+ − 2401
// ob_end_flush();
+ − 2402
return fputs($socket, $data);
+ − 2403
}
+ − 2404
+ − 2405
/**
+ − 2406
* Sanitizes a page URL string so that it can safely be stored in the database.
+ − 2407
* @param string Page ID to sanitize
+ − 2408
* @return string Cleaned text
+ − 2409
*/
+ − 2410
+ − 2411
function sanitize_page_id($page_id)
+ − 2412
{
76
+ − 2413
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
+ − 2414
// Remove character escapes
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2415
$page_id = dirtify_page_id($page_id);
76
+ − 2416
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2417
$pid_clean = preg_replace('/[\w\.\/:;\(\)@\[\]_-]/', 'X', $page_id);
1
+ − 2418
$pid_dirty = enano_str_split($pid_clean, 1);
76
+ − 2419
1
+ − 2420
foreach ( $pid_dirty as $id => $char )
+ − 2421
{
+ − 2422
if ( $char == 'X' )
+ − 2423
continue;
+ − 2424
$cid = ord($char);
+ − 2425
$cid = dechex($cid);
+ − 2426
$cid = strval($cid);
+ − 2427
if ( strlen($cid) < 2 )
+ − 2428
{
+ − 2429
$cid = strtoupper("0$cid");
+ − 2430
}
+ − 2431
$pid_dirty[$id] = ".$cid";
+ − 2432
}
76
+ − 2433
1
+ − 2434
$pid_chars = enano_str_split($page_id, 1);
+ − 2435
$page_id_cleaned = '';
76
+ − 2436
1
+ − 2437
foreach ( $pid_chars as $id => $char )
+ − 2438
{
+ − 2439
if ( $pid_dirty[$id] == 'X' )
+ − 2440
$page_id_cleaned .= $char;
+ − 2441
else
+ − 2442
$page_id_cleaned .= $pid_dirty[$id];
+ − 2443
}
76
+ − 2444
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2445
// global $mime_types;
76
+ − 2446
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2447
// $exts = array_keys($mime_types);
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2448
// $exts = '(' . implode('|', $exts) . ')';
76
+ − 2449
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2450
// $page_id_cleaned = preg_replace('/\.2e' . $exts . '$/', '.\\1', $page_id_cleaned);
76
+ − 2451
1
+ − 2452
return $page_id_cleaned;
+ − 2453
}
+ − 2454
+ − 2455
/**
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
+ − 2456
* Removes character escapes in a page ID string
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2457
* @param string Page ID string to dirty up
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2458
* @return string
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2459
*/
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2460
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2461
function dirtify_page_id($page_id)
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2462
{
38
+ − 2463
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 2464
// First, replace spaces with underscores
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
+ − 2465
$page_id = str_replace(' ', '_', $page_id);
76
+ − 2466
38
+ − 2467
// Exception for userpages for IP addresses
+ − 2468
if ( preg_match('/^' . preg_quote($paths->nslist['User']) . '/', $page_id) )
+ − 2469
{
+ − 2470
$ip = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $page_id);
+ − 2471
if ( is_valid_ip($ip) )
+ − 2472
return $page_id;
+ − 2473
}
76
+ − 2474
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
+ − 2475
preg_match_all('/\.[A-Fa-f0-9][A-Fa-f0-9]/', $page_id, $matches);
76
+ − 2476
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
+ − 2477
foreach ( $matches[0] as $id => $char )
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2478
{
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2479
$char = substr($char, 1);
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2480
$char = strtolower($char);
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2481
$char = intval(hexdec($char));
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2482
$char = chr($char);
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2483
$page_id = str_replace($matches[0][$id], $char, $page_id);
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2484
}
76
+ − 2485
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
+ − 2486
return $page_id;
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2487
}
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2488
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2489
/**
76
+ − 2490
* Inserts commas into a number to make it more human-readable. Floating point-safe and doesn't flirt with the number like number_format() does.
1
+ − 2491
* @param int The number to process
+ − 2492
* @return string Input number with commas added
+ − 2493
*/
+ − 2494
+ − 2495
function commatize($num)
+ − 2496
{
+ − 2497
$num = (string)$num;
+ − 2498
if ( strpos($num, '.') )
+ − 2499
{
+ − 2500
$whole = explode('.', $num);
+ − 2501
$num = $whole[0];
+ − 2502
$dec = $whole[1];
+ − 2503
}
+ − 2504
else
+ − 2505
{
+ − 2506
$whole = $num;
+ − 2507
}
+ − 2508
$offset = ( strlen($num) ) % 3;
+ − 2509
$len = strlen($num);
+ − 2510
$offset = ( $offset == 0 )
+ − 2511
? 3
+ − 2512
: $offset;
+ − 2513
for ( $i = $offset; $i < $len; $i=$i+3 )
+ − 2514
{
+ − 2515
$num = substr($num, 0, $i) . ',' . substr($num, $i, $len);
+ − 2516
$len = strlen($num);
+ − 2517
$i++;
+ − 2518
}
+ − 2519
if ( isset($dec) )
+ − 2520
{
+ − 2521
return $num . '.' . $dec;
+ − 2522
}
+ − 2523
else
+ − 2524
{
+ − 2525
return $num;
+ − 2526
}
+ − 2527
}
+ − 2528
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2529
/**
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2530
* Injects a string into another string at the specified position.
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2531
* @param string The haystack
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2532
* @param string The needle
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2533
* @param int Position at which to insert the needle
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2534
*/
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2535
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2536
function inject_substr($haystack, $needle, $pos)
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2537
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2538
$str1 = substr($haystack, 0, $pos);
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2539
$pos++;
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2540
$str2 = substr($haystack, $pos);
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2541
return "{$str1}{$needle}{$str2}";
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2542
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2543
38
+ − 2544
/**
+ − 2545
* Tells if a given IP address is valid.
+ − 2546
* @param string suspected IP address
+ − 2547
* @return bool true if valid, false otherwise
+ − 2548
*/
76
+ − 2549
38
+ − 2550
function is_valid_ip($ip)
+ − 2551
{
+ − 2552
// These came from phpBB3.
+ − 2553
$ipv4 = '(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])';
+ − 2554
$ipv6 = '(?:(?:(?:[\dA-F]{1,4}:){6}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:::(?:[\dA-F]{1,4}:){5}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:):(?:[\dA-F]{1,4}:){4}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,2}:(?:[\dA-F]{1,4}:){3}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,3}:(?:[\dA-F]{1,4}:){2}(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,4}:(?:[\dA-F]{1,4}:)(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,5}:(?:[\dA-F]{1,4}:[\dA-F]{1,4}|(?:(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])))|(?:(?:[\dA-F]{1,4}:){1,6}:[\dA-F]{1,4})|(?:(?:[\dA-F]{1,4}:){1,7}:))';
76
+ − 2555
38
+ − 2556
if ( preg_match("/^{$ipv4}$/", $ip) || preg_match("/^{$ipv6}$/", $ip) )
+ − 2557
return true;
+ − 2558
else
+ − 2559
return false;
+ − 2560
}
+ − 2561
48
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2562
/**
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2563
* Replaces the FIRST given occurrence of needle within haystack with thread
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2564
* @param string Needle
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2565
* @param string Thread
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2566
* @param string Haystack
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2567
*/
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2568
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2569
function str_replace_once($needle, $thread, $haystack)
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2570
{
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2571
$needle_len = strlen($needle);
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2572
for ( $i = 0; $i < strlen($haystack); $i++ )
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2573
{
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2574
$test = substr($haystack, $i, $needle_len);
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2575
if ( $test == $needle )
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2576
{
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2577
// Got it!
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2578
$upto = substr($haystack, 0, $i);
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2579
$from = substr($haystack, ( $i + $needle_len ));
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2580
$new_haystack = "{$upto}{$thread}{$from}";
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2581
return $new_haystack;
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2582
}
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2583
}
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2584
return $haystack;
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2585
}
fc9762553a3c
E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots
Dan
diff
changeset
+ − 2586
78
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2587
/**
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2588
* From http://us2.php.net/urldecode - decode %uXXXX
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2589
* @param string The urlencoded string
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2590
* @return string
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2591
*/
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2592
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2593
function decode_unicode_url($str)
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2594
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2595
$res = '';
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2596
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2597
$i = 0;
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2598
$max = strlen($str) - 6;
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2599
while ($i <= $max)
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2600
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2601
$character = $str[$i];
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2602
if ($character == '%' && $str[$i + 1] == 'u')
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2603
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2604
$value = hexdec(substr($str, $i + 2, 4));
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2605
$i += 6;
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2606
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2607
if ($value < 0x0080)
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2608
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2609
// 1 byte: 0xxxxxxx
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2610
$character = chr($value);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2611
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2612
else if ($value < 0x0800)
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2613
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2614
// 2 bytes: 110xxxxx 10xxxxxx
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2615
$character =
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2616
chr((($value & 0x07c0) >> 6) | 0xc0)
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2617
. chr(($value & 0x3f) | 0x80);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2618
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2619
else
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2620
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2621
// 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2622
$character =
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2623
chr((($value & 0xf000) >> 12) | 0xe0)
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2624
. chr((($value & 0x0fc0) >> 6) | 0x80)
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2625
. chr(($value & 0x3f) | 0x80);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2626
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2627
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2628
else
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2629
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2630
$i++;
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2631
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2632
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2633
$res .= $character;
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2634
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2635
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2636
return $res . substr($str, $i);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2637
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2638
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2639
/**
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2640
* Recursively decodes an array with UTF-8 characters in its strings
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2641
* @param array Can be multi-depth
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2642
* @return array
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2643
*/
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2644
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2645
function decode_unicode_array($array)
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2646
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2647
foreach ( $array as $i => $val )
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2648
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2649
if ( is_string($val) )
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2650
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2651
$array[$i] = decode_unicode_url($val);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2652
}
217
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2653
else if ( is_array($val) )
78
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2654
{
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2655
$array[$i] = decode_unicode_array($val);
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2656
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2657
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2658
return $array;
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2659
}
4df25dfdde63
Modified Text_Wiki parser to fully support UTF-8 strings; several other UTF-8 fixes, international characters seem to work reasonably well now
Dan
diff
changeset
+ − 2660
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2661
/**
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2662
* Sanitizes a page tag.
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2663
* @param string
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2664
* @return string
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2665
*/
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2666
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2667
function sanitize_tag($tag)
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2668
{
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2669
$tag = strtolower($tag);
254
f49e3c8b638c
Fixed focus of AJAX login form fields in IE; removed stale/unused call to $template->makeParserText() in paginate_array(); added hook page_create_request to possibly help control creation of pages of certain namespaces from plugins; fixed critical bug in user CP that prevented plugins from adding custom CP modules
Dan
diff
changeset
+ − 2670
$tag = preg_replace('/[^\w @\$%\^&-]+/', '', $tag);
f49e3c8b638c
Fixed focus of AJAX login form fields in IE; removed stale/unused call to $template->makeParserText() in paginate_array(); added hook page_create_request to possibly help control creation of pages of certain namespaces from plugins; fixed critical bug in user CP that prevented plugins from adding custom CP modules
Dan
diff
changeset
+ − 2671
$tag = str_replace('_', ' ', $tag);
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2672
$tag = trim($tag);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2673
return $tag;
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2674
}
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2675
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2676
/**
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2677
* Gzips the output buffer.
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2678
*/
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2679
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2680
function gzip_output()
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2681
{
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2682
global $do_gzip;
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2683
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2684
//
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2685
// Compress buffered output if required and send to browser
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2686
//
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2687
if ( $do_gzip && function_exists('ob_gzhandler') )
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2688
{
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2689
$gzip_contents = ob_get_contents();
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2690
ob_end_clean();
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2691
81
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2692
$return = ob_gzhandler($gzip_contents);
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2693
if ( $return )
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2694
{
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2695
header('Content-encoding: gzip');
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2696
echo $gzip_contents;
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2697
}
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2698
else
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2699
{
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2700
echo $gzip_contents;
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2701
}
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2702
}
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2703
}
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2704
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2705
/**
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2706
* Aggressively and hopefully non-destructively optimizes a blob of HTML.
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2707
* @param string HTML to process
237
4ab30e8dd168
Nothing special. ksort()ing list of allowed filetypes in the admin panel to make editing the list marginally easier
Dan
diff
changeset
+ − 2708
* @return string much smaller HTML
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2709
*/
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2710
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2711
function aggressive_optimize_html($html)
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2712
{
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2713
$size_before = strlen($html);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2714
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2715
// kill carriage returns
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2716
$html = str_replace("\r", "", $html);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2717
125
+ − 2718
// Which tags to strip for JAVASCRIPT PROCESSING ONLY - you can change this if needed
+ − 2719
$strip_tags = Array('enano:no-opt');
+ − 2720
$strip_tags = implode('|', $strip_tags);
+ − 2721
+ − 2722
// Strip out the tags and replace with placeholders
173
91127e62f38f
Fixed some regular expressions in HTML optimization algorithm; regex page groups can be edited now (oops)
Dan
diff
changeset
+ − 2723
preg_match_all("#<($strip_tags)([ ]+.*?)?>(.*?)</($strip_tags)>#is", $html, $matches);
125
+ − 2724
$seed = md5(microtime() . mt_rand()); // Random value used for placeholders
+ − 2725
for ($i = 0;$i < sizeof($matches[1]); $i++)
+ − 2726
{
+ − 2727
$html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
+ − 2728
}
+ − 2729
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2730
// Optimize (but don't obfuscate) Javascript
174
+ − 2731
preg_match_all('/<script([ ]+.*?)?>(.*?)(\]\]>)?<\/script>/is', $html, $jscript);
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2732
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2733
// list of Javascript reserved words - from about.com
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2734
$reserved_words = array('abstract', 'as', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'continue', 'const', 'debugger', 'default', 'delete', 'do',
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2735
'double', 'else', 'enum', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import',
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2736
'in', 'instanceof', 'int', 'interface', 'is', 'long', 'namespace', 'native', 'new', 'null', 'package', 'private', 'protected', 'public',
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2737
'return', 'short', 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', 'typeof', 'use', 'var',
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2738
'void', 'volatile', 'while', 'with');
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2739
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2740
$reserved_words = '(' . implode('|', $reserved_words) . ')';
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2741
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2742
for ( $i = 0; $i < count($jscript[0]); $i++ )
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2743
{
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2744
$js =& $jscript[2][$i];
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2745
173
91127e62f38f
Fixed some regular expressions in HTML optimization algorithm; regex page groups can be edited now (oops)
Dan
diff
changeset
+ − 2746
// echo('<pre>' . "-----------------------------------------------------------------------------\n" . htmlspecialchars($js) . '</pre>');
91127e62f38f
Fixed some regular expressions in HTML optimization algorithm; regex page groups can be edited now (oops)
Dan
diff
changeset
+ − 2747
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2748
// for line optimization, explode it
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2749
$particles = explode("\n", $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2750
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2751
foreach ( $particles as $j => $atom )
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2752
{
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2753
// Remove comments
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2754
$atom = preg_replace('#\/\/(.+)#i', '', $atom);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2755
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2756
$atom = trim($atom);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2757
if ( empty($atom) )
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2758
unset($particles[$j]);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2759
else
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2760
$particles[$j] = $atom;
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2761
}
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2762
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2763
$js = implode("\n", $particles);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2764
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2765
$js = preg_replace('#/\*(.*?)\*/#s', '', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2766
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2767
// find all semicolons and then linebreaks, and replace with a single semicolon
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2768
$js = str_replace(";\n", ';', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2769
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2770
// starting braces
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2771
$js = preg_replace('/\{([\s]+)/m', '{', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2772
$js = str_replace(")\n{", '){', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2773
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2774
// ending braces (tricky)
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2775
$js = preg_replace('/\}([^;])/m', '};\\1', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2776
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2777
// other rules
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2778
$js = str_replace("};\n", "};", $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2779
$js = str_replace(",\n", ',', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2780
$js = str_replace("[\n", '[', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2781
$js = str_replace("]\n", ']', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2782
$js = str_replace("\n}", '}', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2783
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2784
// newlines immediately before reserved words
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2785
$js = preg_replace("/(\)|;)\n$reserved_words/is", '\\1\\2', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2786
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2787
// fix for firefox issue
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2788
$js = preg_replace('/\};([\s]*)(else|\))/i', '}\\2', $js);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2789
81
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2790
$replacement = "<script{$jscript[1][$i]}>/* <![CDATA[ */ $js /* ]]> */</script>";
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2791
// apply changes
81
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2792
$html = str_replace($jscript[0][$i], $replacement, $html);
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2793
}
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2794
125
+ − 2795
// Re-insert untouchable tags
+ − 2796
for ($i = 0;$i < sizeof($matches[1]); $i++)
+ − 2797
{
+ − 2798
$html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
+ − 2799
}
+ − 2800
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2801
// Which tags to strip - you can change this if needed
137
+ − 2802
$strip_tags = Array('pre', 'script', 'style', 'enano:no-opt', 'textarea');
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2803
$strip_tags = implode('|', $strip_tags);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2804
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2805
// Strip out the tags and replace with placeholders
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2806
preg_match_all("#<($strip_tags)(.*?)>(.*?)</($strip_tags)>#is", $html, $matches);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2807
$seed = md5(microtime() . mt_rand()); // Random value used for placeholders
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2808
for ($i = 0;$i < sizeof($matches[1]); $i++)
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2809
{
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2810
$html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2811
}
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2812
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2813
// Finally, process the HTML
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2814
$html = preg_replace("#\n([ ]*)#", " ", $html);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2815
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2816
// Remove annoying spaces between tags
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2817
$html = preg_replace("#>([ ][ ]+)<#", "> <", $html);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2818
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2819
// Re-insert untouchable tags
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2820
for ($i = 0;$i < sizeof($matches[1]); $i++)
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2821
{
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2822
$html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2823
}
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2824
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2825
// Remove <enano:no-opt> blocks (can be used by themes that don't want their HTML optimized)
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2826
$html = preg_replace('#<(\/|)enano:no-opt(.*?)>#', '', $html);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2827
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2828
$size_after = strlen($html);
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2829
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2830
// Tell snoopish users what's going on
81
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2831
$html = str_replace('<html', "\n".'<!-- NOTE: Enano has performed an HTML optimization routine on the HTML you see here. This is to enhance page loading speeds.
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2832
To view the uncompressed source of this page, add the "nocompress" parameter to the URI of this page: index.php?title=Main_Page&nocompress or Main_Page?nocompress'."
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2833
Size before compression: $size_before bytes
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2834
Size after compression: $size_after bytes
81
d7fc25acd3f3
Replaced the menu in the admin theme with something much more visually pleasureable; minor fix in Special:UploadFile; finished patching a couple of XSS problems from Banshee; finished Admin:PageGroups; removed unneeded code in flyin.js; finished tag system (except tag cloud); 1.0.1 release candidate
Dan
diff
changeset
+ − 2835
-->\n<html", $html);
80
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2836
return $html;
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2837
}
cb7dde69c301
Improved and enabled HTML optimization algorithm; enabled gzip compression; added but did not test at all the tag cloud class in includes/tagcloud.php, this is still very preliminary and not ready for any type of production use
Dan
diff
changeset
+ − 2838
128
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2839
/**
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2840
* For an input range of numbers (like 25-256) returns an array filled with all numbers in the range, inclusive.
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2841
* @param string
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2842
* @return array
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2843
*/
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2844
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2845
function int_range($range)
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2846
{
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2847
if ( strval(intval($range)) == $range )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2848
return $range;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2849
if ( !preg_match('/^[0-9]+(-[0-9]+)?$/', $range) )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2850
return false;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2851
$ends = explode('-', $range);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2852
if ( count($ends) != 2 )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2853
return $range;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2854
$ret = array();
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2855
if ( $ends[1] < $ends[0] )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2856
$ends = array($ends[1], $ends[0]);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2857
else if ( $ends[0] == $ends[1] )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2858
return array($ends[0]);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2859
for ( $i = $ends[0]; $i <= $ends[1]; $i++ )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2860
{
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2861
$ret[] = $i;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2862
}
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2863
return $ret;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2864
}
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2865
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2866
/**
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2867
* Parses a range or series of IP addresses, and returns the raw addresses. Only parses ranges in the last two octets to prevent DOSing.
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2868
* Syntax for ranges: x.x.x.x; x|y.x.x.x; x.x.x-z.x; x.x.x-z|p.q|y
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2869
* @param string IP address range string
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2870
* @return array
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2871
*/
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2872
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2873
function parse_ip_range($range)
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2874
{
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2875
$octets = explode('.', $range);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2876
if ( count($octets) != 4 )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2877
// invalid range
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2878
return $range;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2879
$i = 0;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2880
$possibilities = array( 0 => array(), 1 => array(), 2 => array(), 3 => array() );
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2881
foreach ( $octets as $octet )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2882
{
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2883
$existing =& $possibilities[$i];
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2884
$inner = explode('|', $octet);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2885
foreach ( $inner as $bit )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2886
{
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2887
if ( $i >= 2 )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2888
{
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2889
$bits = int_range($bit);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2890
if ( $bits === false )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2891
return false;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2892
else if ( !is_array($bits) )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2893
$existing[] = intval($bits);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2894
else
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2895
$existing = array_merge($existing, $bits);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2896
}
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2897
else
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2898
{
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2899
$bit = intval($bit);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2900
$existing[] = $bit;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2901
}
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2902
}
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2903
$existing = array_unique($existing);
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2904
$i++;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2905
}
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2906
$ips = array();
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2907
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2908
// The only way to combine all those possibilities. ;-)
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2909
foreach ( $possibilities[0] as $oc1 )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2910
foreach ( $possibilities[1] as $oc2 )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2911
foreach ( $possibilities[2] as $oc3 )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2912
foreach ( $possibilities[3] as $oc4 )
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2913
$ips[] = "$oc1.$oc2.$oc3.$oc4";
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2914
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2915
return $ips;
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2916
}
01955bf53f96
Improved ban control page and allowed multiple entries/IP ranges; changed some parameters on jBox; user level changes are logged now
Dan
diff
changeset
+ − 2917
217
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2918
/**
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2919
* Parses a valid IP address range into a regular expression.
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2920
* @param string IP range string
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2921
* @return string
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2922
*/
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2923
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2924
function parse_ip_range_regex($range)
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2925
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2926
// Regular expression to test the range string for validity
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2927
$regex = '/^(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2928
. '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2929
. '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)\.'
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2930
. '(([0-9]+(-[0-9]+)?)(\|([0-9]+(-[0-9]+)?))*)$/';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2931
if ( !preg_match($regex, $range) )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2932
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2933
return false;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2934
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2935
$octets = array(0 => array(), 1 => array(), 2 => array(), 3 => array());
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2936
list($octets[0], $octets[1], $octets[2], $octets[3]) = explode('.', $range);
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2937
$return = '^';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2938
foreach ( $octets as $octet )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2939
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2940
// alternatives array
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2941
$alts = array();
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2942
if ( strpos($octet, '|') )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2943
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2944
$particles = explode('|', $octet);
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2945
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2946
else
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2947
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2948
$particles = array($octet);
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2949
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2950
foreach ( $particles as $atom )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2951
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2952
// each $atom will be either
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2953
if ( strval(intval($atom)) == $atom )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2954
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2955
$alts[] = $atom;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2956
continue;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2957
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2958
else
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2959
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2960
// it's a range - parse it out
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2961
$alt2 = int_range($atom);
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2962
if ( !$alt2 )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2963
return false;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2964
foreach ( $alt2 as $neutrino )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2965
$alts[] = $neutrino;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2966
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2967
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2968
$alts = array_unique($alts);
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2969
$alts = '|' . implode('|', $alts) . '|';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2970
// we can further optimize/compress this by weaseling our way into using some character ranges
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2971
for ( $i = 1; $i <= 25; $i++ )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2972
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2973
$alts = str_replace("|{$i}0|{$i}1|{$i}2|{$i}3|{$i}4|{$i}5|{$i}6|{$i}7|{$i}8|{$i}9|", "|{$i}[0-9]|", $alts);
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2974
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2975
$alts = str_replace("|1|2|3|4|5|6|7|8|9|", "|[1-9]|", $alts);
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2976
$alts = '(' . substr($alts, 1, -1) . ')';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2977
$return .= $alts . '\.';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2978
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2979
$return = substr($return, 0, -2);
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2980
$return .= '$';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2981
return $return;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2982
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2983
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2984
function password_score_len($password)
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2985
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2986
if ( !is_string($password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2987
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2988
return -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2989
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2990
$len = strlen($password);
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2991
$score = $len - 7;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2992
return $score;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2993
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2994
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2995
/**
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2996
* Give a numerical score for how strong a password is. This is an open-ended scale based on a score added to or subtracted
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2997
* from based on certain complexity rules. Anything less than about 1 or 0 is weak, 3-4 is strong, and 10 is not to be easily cracked.
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2998
* Based on the Javascript function of the same name.
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 2999
* @param string Password to test
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3000
* @param null Will be filled with an array of debugging info
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3001
* @return int
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3002
*/
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3003
196
+ − 3004
function password_score($password, &$debug)
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3005
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3006
if ( !is_string($password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3007
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3008
return -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3009
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3010
$score = 0;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3011
$debug = array();
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3012
// length check
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3013
$lenscore = password_score_len($password);
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3014
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3015
$debug[] = "<b>How this score was calculated</b>\nYour score was tallied up based on an extensive algorithm which outputted\nthe following scores based on traits of your password. Above you can see the\ncomposite score; your individual scores based on certain tests are below.\n\nThe scale is open-ended, with a minimum score of -10. 10 is very strong, 4\nis strong, 1 is good and -3 is fair. Below -3 scores \"Weak.\"\n";
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3016
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3017
$debug[] = 'Adding '.$lenscore.' points for length';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3018
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3019
$score += $lenscore;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3020
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3021
$has_upper_lower = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3022
$has_symbols = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3023
$has_numbers = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3024
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3025
// contains uppercase and lowercase
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3026
if ( preg_match('/[A-z]+/', $password) && strtolower($password) != $password )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3027
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3028
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3029
$has_upper_lower = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3030
$debug[] = 'Adding 1 point for having uppercase and lowercase';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3031
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3032
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3033
// contains symbols
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3034
if ( preg_match('/[^A-z0-9]+/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3035
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3036
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3037
$has_symbols = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3038
$debug[] = 'Adding 1 point for having nonalphanumeric characters (matching /[^A-z0-9]+/)';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3039
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3040
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3041
// contains numbers
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3042
if ( preg_match('/[0-9]+/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3043
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3044
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3045
$has_numbers = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3046
$debug[] = 'Adding 1 point for having numbers';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3047
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3048
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3049
if ( $has_upper_lower && $has_symbols && $has_numbers && strlen($password) >= 9 )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3050
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3051
// if it has uppercase and lowercase letters, symbols, and numbers, and is of considerable length, add some serious points
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3052
$score += 4;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3053
$debug[] = 'Adding 4 points for having uppercase and lowercase, numbers, and nonalphanumeric and being more than 8 characters';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3054
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3055
else if ( $has_upper_lower && $has_symbols && $has_numbers )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3056
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3057
// still give some points for passing complexity check
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3058
$score += 2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3059
$debug[] = 'Adding 2 points for having uppercase and lowercase, numbers, and nonalphanumeric';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3060
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3061
else if ( ( $has_upper_lower && $has_symbols ) ||
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3062
( $has_upper_lower && $has_numbers ) ||
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3063
( $has_symbols && $has_numbers ) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3064
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3065
// if 2 of the three main complexity checks passed, add a point
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3066
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3067
$debug[] = 'Adding 1 point for having 2 of 3 complexity checks';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3068
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3069
else if ( preg_match('/^[0-9]*?([a-z]+)[0-9]?$/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3070
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3071
// password is something like magnum1 which will be cracked in seconds
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3072
$score += -4;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3073
$debug[] = 'Adding -4 points for being of the form [number][word][number]';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3074
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3075
else if ( ( !$has_upper_lower && !$has_numbers && $has_symbols ) ||
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3076
( !$has_upper_lower && !$has_symbols && $has_numbers ) ||
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3077
( !$has_numbers && !$has_symbols && $has_upper_lower ) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3078
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3079
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3080
$debug[] = 'Adding -2 points for only meeting 1 complexity check';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3081
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3082
else if ( !$has_upper_lower && !$has_numbers && !$has_symbols )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3083
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3084
$debug[] = 'Adding -3 points for not meeting any complexity checks';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3085
$score += -3;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3086
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3087
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3088
//
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3089
// Repetition
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3090
// Example: foobar12345 should be deducted points, where f1o2o3b4a5r should be given points
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3091
//
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3092
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3093
if ( preg_match('/([A-Z][A-Z][A-Z][A-Z]|[a-z][a-z][a-z][a-z])/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3094
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3095
$debug[] = 'Adding -2 points for having more than 4 letters of the same case in a row';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3096
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3097
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3098
else if ( preg_match('/([A-Z][A-Z][A-Z]|[a-z][a-z][a-z])/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3099
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3100
$debug[] = 'Adding -1 points for having more than 3 letters of the same case in a row';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3101
$score += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3102
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3103
else if ( preg_match('/[A-z]/', $password) && !preg_match('/([A-Z][A-Z][A-Z]|[a-z][a-z][a-z])/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3104
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3105
$debug[] = 'Adding 1 point for never having more than 2 letters of the same case in a row';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3106
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3107
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3108
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3109
if ( preg_match('/[0-9][0-9][0-9][0-9]/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3110
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3111
$debug[] = 'Adding -2 points for having 4 or more numbers in a row';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3112
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3113
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3114
else if ( preg_match('/[0-9][0-9][0-9]/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3115
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3116
$debug[] = 'Adding -1 points for having 3 or more numbers in a row';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3117
$score += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3118
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3119
else if ( $has_numbers && !preg_match('/[0-9][0-9][0-9]/', $password) )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3120
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3121
$debug[] = 'Adding 1 point for never more than 2 numbers in a row';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3122
$score += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3123
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3124
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3125
// make passwords like fooooooooooooooooooooooooooooooooooooo totally die by subtracting a point for each character repeated at least 3 times in a row
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3126
$prev_char = '';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3127
$warn = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3128
$loss = 0;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3129
for ( $i = 0; $i < strlen($password); $i++ )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3130
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3131
$chr = $password{$i};
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3132
if ( $chr == $prev_char && $warn )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3133
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3134
$loss += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3135
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3136
else if ( $chr == $prev_char && !$warn )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3137
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3138
$warn = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3139
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3140
else if ( $chr != $prev_char && $warn )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3141
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3142
$warn = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3143
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3144
$prev_char = $chr;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3145
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3146
if ( $loss < 0 )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3147
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3148
$debug[] = 'Adding '.$loss.' points for immediate character repetition';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3149
$score += $loss;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3150
// this can bring the score below -10 sometimes
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3151
if ( $score < -10 )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3152
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3153
$debug[] = 'Setting score to -10 because it went below ('.$score.')';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3154
$score = -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3155
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3156
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3157
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3158
return $score;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3159
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3160
180
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3161
/**
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3162
* Registers a task that will be run every X hours. Scheduled tasks should always be scheduled at runtime - they are not stored in the DB.
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3163
* @param string Function name to call, or array(object, string method)
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3164
* @param int Interval between runs, in hours. Defaults to 24.
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3165
*/
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3166
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3167
function register_cron_task($func, $hour_interval = 24)
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3168
{
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3169
global $cron_tasks;
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3170
if ( !isset($cron_tasks[$hour_interval]) )
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3171
$cron_tasks[$hour_interval] = array();
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3172
$cron_tasks[$hour_interval][] = $func;
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3173
}
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3174
195
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3175
/**
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3176
* Scales an image to the specified width and height, and writes the output to the specified
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3177
* file. Will use ImageMagick if present, but if not will attempt to scale with GD. This will
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3178
* always scale images proportionally.
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3179
* @param string Path to image file
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3180
* @param string Path to output file
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3181
* @param int Image width, in pixels
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3182
* @param int Image height, in pixels
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3183
* @param bool If true, the output file will be deleted if it exists before it is written
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3184
* @return bool True on success, false on failure
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3185
*/
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3186
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3187
function scale_image($in_file, $out_file, $width = 225, $height = 225, $unlink = false)
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3188
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3189
global $db, $session, $paths, $template, $plugins; // Common objects
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3190
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3191
if ( !is_int($width) || !is_int($height) )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3192
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3193
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3194
if ( !file_exists($in_file) )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3195
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3196
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3197
if ( preg_match('/["\'\/\\]/', $in_file) || preg_match('/["\'\/\\]/', $out_file) )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3198
die('SECURITY: scale_image(): infile or outfile path is screwy');
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3199
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3200
if ( file_exists($out_file) && !$unlink )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3201
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3202
else if ( file_exists($out_file) && $unlink )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3203
@unlink($out_file);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3204
if ( file_exists($out_file) )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3205
// couldn't unlink (delete) the output file
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3206
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3207
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3208
$file_ext = substr($in_file, ( strrpos($in_file, '.') + 1));
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3209
switch($file_ext)
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3210
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3211
case 'png':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3212
$func = 'imagecreatefrompng';
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3213
break;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3214
case 'jpg':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3215
case 'jpeg':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3216
$func = 'imagecreatefromjpeg';
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3217
break;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3218
case 'gif':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3219
$func = 'imagecreatefromgif';
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3220
break;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3221
case 'xpm':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3222
$func = 'imagecreatefromxpm';
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3223
break;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3224
default:
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3225
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3226
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3227
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3228
$magick_path = getConfig('imagemagick_path');
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3229
$can_use_magick = (
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3230
getConfig('enable_imagemagick') == '1' &&
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3231
file_exists($magick_path) &&
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3232
is_executable($magick_path)
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3233
);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3234
$can_use_gd = (
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3235
function_exists('getimagesize') &&
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3236
function_exists('imagecreatetruecolor') &&
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3237
function_exists('imagecopyresampled') &&
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3238
function_exists($func)
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3239
);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3240
if ( $can_use_magick )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3241
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3242
if ( !preg_match('/^([\/A-z0-9_-]+)$/', $magick_path) )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3243
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3244
die('SECURITY: ImageMagick path is screwy');
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3245
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3246
$cmdline = "$magick_path \"$in_file\" -resize \"{$width}x{$height}>\" \"$out_file\"";
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3247
system($cmdline, $return);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3248
if ( !file_exists($out_file) )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3249
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3250
return true;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3251
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3252
else if ( $can_use_gd )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3253
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3254
@list($width_orig, $height_orig) = @getimagesize($in_file);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3255
if ( !$width_orig || !$height_orig )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3256
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3257
// calculate new width and height
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3258
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3259
$ratio = $width_orig / $height_orig;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3260
if ( $ratio > 1 )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3261
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3262
// orig. width is greater that height
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3263
$new_width = $width;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3264
$new_height = round( $width / $ratio );
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3265
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3266
else if ( $ratio < 1 )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3267
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3268
// orig. height is greater than width
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3269
$new_width = round( $height / $ratio );
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3270
$new_height = $height;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3271
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3272
else if ( $ratio == 1 )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3273
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3274
$new_width = $width;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3275
$new_height = $width;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3276
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3277
if ( $new_width > $width_orig || $new_height > $height_orig )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3278
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3279
// Too big for our britches here; set it to only convert the file
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3280
$new_width = $width_orig;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3281
$new_height = $height_orig;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3282
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3283
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3284
$newimage = @imagecreatetruecolor($new_width, $new_height);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3285
if ( !$newimage )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3286
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3287
$oldimage = @$func($in_file);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3288
if ( !$oldimage )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3289
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3290
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3291
// Perform scaling
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3292
imagecopyresampled($newimage, $oldimage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3293
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3294
// Get output format
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3295
$out_ext = substr($out_file, ( strrpos($out_file, '.') + 1));
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3296
switch($out_ext)
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3297
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3298
case 'png':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3299
$outfunc = 'imagepng';
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3300
break;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3301
case 'jpg':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3302
case 'jpeg':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3303
$outfunc = 'imagejpeg';
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3304
break;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3305
case 'gif':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3306
$outfunc = 'imagegif';
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3307
break;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3308
case 'xpm':
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3309
$outfunc = 'imagexpm';
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3310
break;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3311
default:
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3312
imagedestroy($newimage);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3313
imagedestroy($oldimage);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3314
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3315
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3316
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3317
// Write output
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3318
$outfunc($newimage, $out_file);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3319
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3320
// clean up
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3321
imagedestroy($newimage);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3322
imagedestroy($oldimage);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3323
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3324
// done!
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3325
return true;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3326
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3327
// Neither scaling method worked; we'll let plugins try to scale it, and then if the file still doesn't exist, die
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3328
$code = $plugins->setHook('scale_image_failure');
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3329
foreach ( $code as $cmd )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3330
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3331
eval($cmd);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3332
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3333
if ( file_exists($out_file) )
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3334
return true;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3335
return false;
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3336
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3337
1
+ − 3338
//die('<pre>Original: 01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>');
+ − 3339
+ − 3340
?>