1
+ − 1
<?php
+ − 2
+ − 3
/*
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
801
eb8b23f11744
Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
diff
changeset
+ − 5
* Version 1.1.6 (Caoineag beta 1)
536
+ − 6
* Copyright (C) 2006-2008 Dan Fuhry
1
+ − 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.)
620
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 18
* @param string If specified, this is the "default" value for the configuration entry. Defaults to false.
22
+ − 19
* @return string Configuration value, or bool(false) if the value is not set
+ − 20
*/
+ − 21
620
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 22
function getConfig($n, $default = false)
22
+ − 23
{
1
+ − 24
global $enano_config;
22
+ − 25
if ( isset( $enano_config[ $n ] ) )
+ − 26
{
+ − 27
return $enano_config[$n];
+ − 28
}
+ − 29
else
+ − 30
{
620
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 31
return $default;
22
+ − 32
}
1
+ − 33
}
+ − 34
22
+ − 35
/**
+ − 36
* Update or change a configuration value.
+ − 37
* @param string The identifier of the value ("site_name" etc.)
+ − 38
* @param string The new value
+ − 39
* @return null
+ − 40
*/
+ − 41
+ − 42
function setConfig($n, $v)
+ − 43
{
1
+ − 44
global $enano_config, $db;
620
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 45
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 46
if ( isset($enano_config[$n]) )
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 47
{
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 48
if ( $enano_config[$n] === $v )
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 49
{
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 50
// configuration already matches this value
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 51
return true;
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 52
}
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 53
}
58852672ff12
Added "default" option for getConfig() and made setConfig() only set if the new value is different
Dan
diff
changeset
+ − 54
1
+ − 55
$enano_config[$n] = $v;
842
+ − 56
if ( $v === false )
+ − 57
unset($enano_config[$n]);
+ − 58
1
+ − 59
$v = $db->escape($v);
76
+ − 60
22
+ − 61
$e = $db->sql_query('DELETE FROM '.table_prefix.'config WHERE config_name=\''.$n.'\';');
+ − 62
if ( !$e )
+ − 63
{
+ − 64
$db->_die('Error during generic setConfig() call row deletion.');
+ − 65
}
76
+ − 66
842
+ − 67
if ( $v !== false )
+ − 68
{
+ − 69
$e = $db->sql_query('INSERT INTO '.table_prefix.'config(config_name, config_value) VALUES(\''.$n.'\', \''.$v.'\')');
+ − 70
if ( !$e )
+ − 71
{
+ − 72
$db->_die('Error during generic setConfig() call row insertion.');
+ − 73
}
22
+ − 74
}
1
+ − 75
}
+ − 76
22
+ − 77
/**
+ − 78
* Create a URI for an internal link.
+ − 79
* @param string The full identifier of the page to link to (Special:Administration)
+ − 80
* @param string The GET query string to append
+ − 81
* @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe
+ − 82
* @return string
+ − 83
*/
+ − 84
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 85
if ( !function_exists('makeUrl') )
1
+ − 86
{
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 87
function makeUrl($t, $query = false, $escape = false)
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 88
{
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 89
global $db, $session, $paths, $template, $plugins; // Common objects
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 90
$flags = '';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 91
$sep = urlSeparator;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 92
$t = sanitize_page_id($t);
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 93
if ( isset($_GET['printable'] ) )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 94
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 95
$flags .= $sep . 'printable=yes';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 96
$sep = '&';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 97
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 98
if ( isset($_GET['theme'] ) )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 99
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 100
$flags .= $sep . 'theme='.$session->theme;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 101
$sep = '&';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 102
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 103
if ( isset($_GET['style'] ) )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 104
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 105
$flags .= $sep . 'style='.$session->style;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 106
$sep = '&';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 107
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 108
if ( isset($_GET['lang']) && preg_match('/^[a-z0-9_]+$/', @$_GET['lang']) )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 109
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 110
$flags .= $sep . 'lang=' . urlencode($_GET['lang']);
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 111
$sep = '&';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 112
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 113
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 114
$url = $session->append_sid(contentPath.$t.$flags);
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 115
if($query)
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 116
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 117
$sep = strstr($url, '?') ? '&' : '?';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 118
$url = $url . $sep . $query;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 119
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 120
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 121
return ($escape) ? htmlspecialchars($url) : $url;
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 122
}
1
+ − 123
}
+ − 124
22
+ − 125
/**
+ − 126
* 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.
+ − 127
* @param string The namespace ID
+ − 128
* @param string The page ID
+ − 129
* @param string The GET query string to append
+ − 130
* @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe
+ − 131
* @return string
+ − 132
*/
+ − 133
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 134
if ( !function_exists('makeUrlNS') )
1
+ − 135
{
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 136
function makeUrlNS($n, $t, $query = false, $escape = false)
22
+ − 137
{
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 138
global $db, $session, $paths, $template, $plugins; // Common objects
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 139
$flags = '';
468
+ − 140
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 141
if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
22
+ − 142
{
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 143
$sep = urlSeparator;
22
+ − 144
}
+ − 145
else
+ − 146
{
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 147
$sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 148
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 149
if ( isset( $_GET['printable'] ) ) {
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 150
$flags .= $sep . 'printable';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 151
$sep = '&';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 152
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 153
if ( isset( $_GET['theme'] ) )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 154
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 155
$flags .= $sep . 'theme='.$session->theme;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 156
$sep = '&';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 157
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 158
if ( isset( $_GET['style'] ) )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 159
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 160
$flags .= $sep . 'style='.$session->style;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 161
$sep = '&';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 162
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 163
if ( isset($_GET['lang']) && preg_match('/^[a-z0-9_]+$/', @$_GET['lang']) )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 164
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 165
$flags .= $sep . 'lang=' . urlencode($_GET['lang']);
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 166
$sep = '&';
22
+ − 167
}
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 168
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 169
$ns_prefix = "$n:";
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 170
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 171
if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 172
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 173
$ns_prefix = ( isset($paths->nslist[$n]) ) ? $paths->nslist[$n] : $n . substr($paths->nslist['Special'], -1);
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 174
$url = contentPath . $ns_prefix . $t . $flags;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 175
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 176
else
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 177
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 178
// If the path manager hasn't been initted yet, take an educated guess at what the URI should be
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 179
$url = contentPath . $n . ':' . $t . $flags;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 180
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 181
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 182
if($query)
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 183
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 184
if(strstr($url, '?'))
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 185
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 186
$sep = '&';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 187
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 188
else
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 189
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 190
$sep = '?';
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 191
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 192
$url = $url . $sep . $query . $flags;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 193
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 194
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 195
if(defined('ENANO_BASE_CLASSES_INITIALIZED'))
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 196
{
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 197
$url = $session->append_sid($url);
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 198
}
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 199
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 200
return ($escape) ? htmlspecialchars($url) : $url;
1
+ − 201
}
+ − 202
}
+ − 203
22
+ − 204
/**
+ − 205
* 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.
+ − 206
* @param string The namespace ID
+ − 207
* @param string The page ID
+ − 208
* @param string The GET query string to append
+ − 209
* @param bool If true, perform htmlspecialchars() on the return value to make it HTML-safe
+ − 210
* @return string
+ − 211
*/
+ − 212
1
+ − 213
function makeUrlComplete($n, $t, $query = false, $escape = false)
+ − 214
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 215
return get_server_url() . makeUrlNS($n, $t, $query, $escape);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 216
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 217
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 218
/**
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 219
* Returns an http:// URL for this server.
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 220
* @return string
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 221
*/
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 222
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 223
function get_server_url()
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 224
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 225
return 'http' . ( $GLOBALS['is_https'] ) . '://' . $_SERVER['HTTP_HOST'];
1
+ − 226
}
+ − 227
+ − 228
/**
741
+ − 229
* Returns the full page ID string of the main page.
+ − 230
* @return string
+ − 231
*/
+ − 232
+ − 233
function get_main_page($force_logged_in = false)
+ − 234
{
+ − 235
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 236
+ − 237
$logged_in = false;
+ − 238
if ( is_object($session) && !$force_logged_in )
+ − 239
{
+ − 240
$logged_in = $session->user_logged_in;
+ − 241
}
+ − 242
else if ( $force_logged_in )
+ − 243
{
+ − 244
$logged_in = true;
+ − 245
}
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 246
return $logged_in && getConfig('main_page_alt_enable', '0') == '1' ? getConfig('main_page_alt', getConfig('main_page', 'Main_Page')) : getConfig('main_page', 'Main_Page');
741
+ − 247
}
+ − 248
+ − 249
/**
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 250
* Enano replacement for date(). Accounts for individual users' timezone preferences.
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 251
* @param string Date-formatted string
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 252
* @param int Optional - UNIX timestamp value to use. If omitted, the current time is used.
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 253
* @return string Formatted string
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 254
*/
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 255
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 256
function enano_date($string, $timestamp = false)
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 257
{
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 258
if ( !is_int($timestamp) && !is_double($timestamp) && strval(intval($timestamp)) !== $timestamp )
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 259
$timestamp = time();
406
+ − 260
+ − 261
// perform timestamp offset
+ − 262
global $timezone;
+ − 263
// it's gonna be in minutes, so multiply by 60 to offset the unix timestamp
+ − 264
$timestamp = $timestamp + ( $timezone * 60 );
+ − 265
711
+ − 266
// are we in DST?
+ − 267
global $dst_params;
+ − 268
if ( check_timestamp_dst($timestamp, $dst_params[0], $dst_params[1], $dst_params[2], $dst_params[3]) )
+ − 269
{
+ − 270
// offset for DST
+ − 271
$timestamp += ( $dst_params[4] * 60 );
+ − 272
}
+ − 273
406
+ − 274
// Let PHP do the work for us =)
556
63e131c38876
More work done on effective permissions API, namely reporting of page group and usergroup names
Dan
diff
changeset
+ − 275
return gmdate($string, $timestamp);
345
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 276
}
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 277
4ccdfeee9a11
WiP commit for admin panel localization. All modules up to Admin:UserManager (working down the list) are localized except Admin:ThemeManager, which is due for a rewrite
Dan
diff
changeset
+ − 278
/**
711
+ − 279
* Determine if a timestamp is within DST.
+ − 280
* @param int Timestamp
+ − 281
* @param int Start month (1-12) of DST
+ − 282
* @param int Which Sunday DST starts on (*_SUNDAY constants)
+ − 283
* @param int End month of DST
+ − 284
* @param int Which Sunday DST ends on
+ − 285
* @return bool
+ − 286
*/
+ − 287
+ − 288
function check_timestamp_dst($time, $start_month, $start_sunday, $end_month, $end_sunday)
+ − 289
{
+ − 290
static $sundays = array(FIRST_SUNDAY, SECOND_SUNDAY, THIRD_SUNDAY, LAST_SUNDAY);
+ − 291
+ − 292
// perform timestamp offset
+ − 293
global $timezone;
+ − 294
// it's gonna be in minutes, so multiply by 60 to offset the unix timestamp
+ − 295
$time = $time + ( $timezone * 60 );
+ − 296
$year = intval(gmdate('Y', $time));
+ − 297
+ − 298
// one-pass validation
+ − 299
if ( !in_array($start_sunday, $sundays) || !in_array($end_sunday, $sundays) ||
+ − 300
$start_month < 1 || $start_month > 12 || $end_month < 1 || $end_month > 12 )
+ − 301
return false;
+ − 302
+ − 303
// get timestamp of the selected sunday (start)
+ − 304
$dst_start = get_sunday_timestamp($start_month, $start_sunday, $year);
+ − 305
$dst_end = get_sunday_timestamp($end_month, $end_sunday, $year);
+ − 306
+ − 307
if ( $dst_start > $dst_end )
+ − 308
{
+ − 309
// start time is past the end time, this means we're in the southern hemisphere
+ − 310
// as a result, if we're within the range, DST is NOT in progress.
+ − 311
return !( $time >= $dst_start && $time <= $dst_end );
+ − 312
}
+ − 313
+ − 314
return $time >= $dst_start && $time <= $dst_end;
+ − 315
}
+ − 316
+ − 317
/**
+ − 318
* Returns a timestamp for the given *_SUNDAY index.
+ − 319
* @param int Month
+ − 320
* @param int Which Sunday (FIRST, SECOND, THIRD, or LAST)
+ − 321
* @param int Year that we're doing our calculations in
+ − 322
* @return int
+ − 323
*/
+ − 324
+ − 325
function get_sunday_timestamp($month, $sunday, $year)
+ − 326
{
+ − 327
$days_in_month = array(
+ − 328
1 => 31,
+ − 329
2 => $year % 4 == 0 && ( $year % 100 != 0 || ( $year % 100 == 0 && $year % 400 == 0 ) ) ? 29 : 28,
+ − 330
3 => 31,
+ − 331
4 => 30,
+ − 332
5 => 31,
+ − 333
6 => 30,
+ − 334
7 => 31,
+ − 335
8 => 31,
+ − 336
9 => 30,
+ − 337
10 => 31,
+ − 338
11 => 30,
+ − 339
12 => 31
+ − 340
);
+ − 341
+ − 342
$result = mktime(0, 0, 0, $month, 1, $year);
+ − 343
+ − 344
// hack. allows a specific day of the month to be set instead of a sunday. not a good place to do this.
+ − 345
if ( is_string($sunday) && substr($sunday, -1) === 'd' )
+ − 346
{
+ − 347
$result += 86400 * ( intval($sunday) - 1);
+ − 348
return $result;
+ − 349
}
+ − 350
+ − 351
$tick = 0;
+ − 352
$days_remaining = $days_in_month[$month];
+ − 353
while ( true )
+ − 354
{
+ − 355
if ( date('D', $result) == 'Sun' )
+ − 356
{
+ − 357
$tick++;
+ − 358
if ( ( $tick == 1 && $sunday == FIRST_SUNDAY ) ||
+ − 359
( $tick == 2 && $sunday == SECOND_SUNDAY ) ||
+ − 360
( $tick == 3 && $sunday == THIRD_SUNDAY ) ||
+ − 361
( $sunday == LAST_SUNDAY && $days_remaining < 7 ) )
+ − 362
break;
+ − 363
}
+ − 364
$days_remaining--;
+ − 365
$result += 86400;
+ − 366
}
+ − 367
+ − 368
return $result;
+ − 369
}
+ − 370
+ − 371
/**
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 372
* 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
+ − 373
* @param string Page ID string (ex: Special:Administration)
91
+ − 374
* @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
+ − 375
* @return string
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 376
*/
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 377
91
+ − 378
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
+ − 379
{
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 380
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 381
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 382
$idata = RenderMan::strToPageID($page_id);
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 383
$page_id_key = $paths->nslist[ $idata[1] ] . $idata[0];
91
+ − 384
$page_id_key = sanitize_page_id($page_id_key);
473
518bc2b214f1
Added modal dialog support for page editor; added customizability for breadcrumbs (thanks to Manoj for idea)
Dan
diff
changeset
+ − 385
$page_data = @$paths->pages[$page_id_key];
91
+ − 386
$title = ( isset($page_data['name']) ) ?
+ − 387
( ( $page_data['namespace'] == 'Article' || !$show_ns ) ?
+ − 388
'' :
+ − 389
$paths->nslist[ $idata[1] ] )
+ − 390
. $page_data['name'] :
+ − 391
( $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
+ − 392
return $title;
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 393
}
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 394
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 395
/**
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 396
* 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
+ − 397
* @param string Page ID
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 398
* @param string Namespace
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 399
* @return string
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 400
*/
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 401
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 402
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
+ − 403
{
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 404
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 405
468
+ − 406
$ns_prefix = ( isset($paths->nslist[ $namespace ]) ) ? $paths->nslist[ $namespace ] : $namespace . substr($paths->nslist['Special'], -1);
+ − 407
$page_id_key = $ns_prefix . $page_id;
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 408
if ( isPage($page_id_key) )
320
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
diff
changeset
+ − 409
{
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
diff
changeset
+ − 410
$page_data = $paths->pages[$page_id_key];
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
diff
changeset
+ − 411
}
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
diff
changeset
+ − 412
else
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
diff
changeset
+ − 413
{
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
diff
changeset
+ − 414
$page_data = array();
112debff64bd
SURPRISE! Preliminary PostgreSQL support added. The required schema file is not present in this commit and will be included at a later date. No installer support is implemented. Also in this commit: several fixes including <!-- SYSMSG ... --> was broken in template compiler; set fixed width on included images to prevent the thumbnail box from getting huge; added a much more friendly interface to AJAX responses that are invalid JSON
Dan
diff
changeset
+ − 415
}
468
+ − 416
$title = ( isset($page_data['name']) ) ? $page_data['name'] : $ns_prefix . str_replace('_', ' ', dirtify_page_id( $page_id ) );
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 417
return $title;
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 418
}
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 419
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
diff
changeset
+ − 420
/**
1
+ − 421
* Redirect the user to the specified URL.
+ − 422
* @param string $url The URL, either relative or absolute.
+ − 423
* @param string $title The title of the message
+ − 424
* @param string $message A short message to show to the user
556
63e131c38876
More work done on effective permissions API, namely reporting of page group and usergroup names
Dan
diff
changeset
+ − 425
* @param string $timeout Timeout, in seconds, to delay the redirect. Defaults to 3. If 0, sends a 307 Temporary Redirect.
1
+ − 426
*/
76
+ − 427
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
diff
changeset
+ − 428
function redirect($url, $title = 'etc_redirect_title', $message = 'etc_redirect_body', $timeout = 3)
1
+ − 429
{
+ − 430
global $db, $session, $paths, $template, $plugins; // Common objects
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
diff
changeset
+ − 431
global $lang;
76
+ − 432
343
eefe9ab7fe7c
Localized the first parts of the admin panel. As a consequence, also wrote a brand new Admin:PageManager that doesn't suck like the old one did.
Dan
diff
changeset
+ − 433
// POST check added in 1.1.x because Firefox asks us if we want to "resend the form
eefe9ab7fe7c
Localized the first parts of the admin panel. As a consequence, also wrote a brand new Admin:PageManager that doesn't suck like the old one did.
Dan
diff
changeset
+ − 434
// data to the new location", which can be confusing for some users.
eefe9ab7fe7c
Localized the first parts of the admin panel. As a consequence, also wrote a brand new Admin:PageManager that doesn't suck like the old one did.
Dan
diff
changeset
+ − 435
if ( $timeout == 0 && empty($_POST) )
1
+ − 436
{
+ − 437
header('Location: ' . $url);
391
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
diff
changeset
+ − 438
header('Content-length: 0');
1
+ − 439
header('HTTP/1.1 307 Temporary Redirect');
391
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
diff
changeset
+ − 440
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
diff
changeset
+ − 441
// with 3xx codes HTTP clients expect a response of 0 bytes, so just die here
85f91037cd4f
Localization is FINISHED, DAMN IT HELLAH YEAH! OVER WITH! Man, it feels to get that off my chest. Release is in under 48 hours, folks. And we're ready for it.
Dan
diff
changeset
+ − 442
exit();
1
+ − 443
}
272
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
+ − 444
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
+ − 445
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
+ − 446
{
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
+ − 447
$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
+ − 448
$template->load_theme('oxygen', 'bleu', false);
574
+ − 449
$template->assign_vars(array(
+ − 450
'SITE_NAME' => 'Enano',
+ − 451
'SITE_DESC' => 'This site is experiencing a critical error and cannot load.',
+ − 452
'COPYRIGHT' => 'Powered by Enano CMS - © 2006-2008 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.',
+ − 453
'PAGE_NAME' => htmlspecialchars($title)
+ − 454
));
272
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
+ − 455
}
76
+ − 456
1
+ − 457
$template->add_header('<meta http-equiv="refresh" content="' . $timeout . '; url=' . str_replace('"', '\\"', $url) . '" />');
+ − 458
$template->add_header('<script type="text/javascript">
+ − 459
function __r() {
+ − 460
// FUNCTION AUTOMATICALLY GENERATED
+ − 461
window.location="' . str_replace('"', '\\"', $url) . '";
+ − 462
}
+ − 463
setTimeout(\'__r();\', ' . $timeout . '000);
+ − 464
</script>
+ − 465
');
272
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
+ − 466
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
+ − 467
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
+ − 468
$template->init_vars();
76
+ − 469
574
+ − 470
$template->assign_vars(array('PAGE_NAME' => $title));
1
+ − 471
$template->header(true);
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
diff
changeset
+ − 472
echo '<p>' . $message . '</p>';
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
diff
changeset
+ − 473
$subst = array(
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
diff
changeset
+ − 474
'timeout' => $timeout,
210
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
diff
changeset
+ − 475
'redirect_url' => str_replace('"', '\\"', $url)
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
diff
changeset
+ − 476
);
2b283402e4e4
Added language export to JSON page and localization for Javascript using $lang.get(). Localized AJAX login interface.
Dan
diff
changeset
+ − 477
echo '<p>' . $lang->get('etc_redirect_timeout', $subst) . '</p>';
1
+ − 478
$template->footer(true);
76
+ − 479
1
+ − 480
$db->close();
+ − 481
exit(0);
76
+ − 482
1
+ − 483
}
+ − 484
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 485
/**
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 486
* Generates a confirmation form if a CSRF check fails. Will terminate execution.
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 487
*/
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 488
573
43e7254afdb4
Renamed some functions (that were new in this release anyway) due to compatibility broken with PunBB bridge
Dan
diff
changeset
+ − 489
function csrf_request_confirm()
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 490
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 491
global $db, $session, $paths, $template, $plugins; // Common objects
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 492
global $lang, $output;
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 493
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 494
// If the token was overridden with the correct one, the user confirmed the action using this form. Continue exec.
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 495
if ( isset($_POST['cstok']) || isset($_GET['cstok']) )
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 496
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 497
// using the if() check makes sure that the token isn't in a cookie, since $_REQUEST includes $_COOKIE.
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 498
$token_check =& $_REQUEST['cstok'];
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 499
if ( $token_check === $session->csrf_token )
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 500
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 501
// overridden token matches, continue exec
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 502
return true;
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 503
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 504
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 505
842
+ − 506
ob_end_clean();
+ − 507
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 508
$output->set_title($lang->get('user_csrf_confirm_title'));
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 509
$output->header();
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 510
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 511
// initial info
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 512
echo '<p>' . $lang->get('user_csrf_confirm_body') . '</p>';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 513
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 514
// start form
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 515
$form_method = ( empty($_POST) ) ? 'get' : 'post';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 516
echo '<form action="' . htmlspecialchars($_SERVER['REQUEST_URI']) . '" method="' . $form_method . '" enctype="multipart/form-data">';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 517
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 518
echo '<fieldset enano:expand="closed">';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 519
echo '<legend>' . $lang->get('user_csrf_confirm_btn_viewrequest') . '</legend><div>';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 520
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 521
if ( empty($_POST) )
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 522
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 523
// GET request
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 524
echo csrf_confirm_get_recursive();
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 525
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 526
else
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 527
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 528
// POST request
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 529
echo csrf_confirm_post_recursive();
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 530
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 531
echo '</div></fieldset>';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 532
// insert the right CSRF token
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 533
echo '<input type="hidden" name="cstok" value="' . $session->csrf_token . '" />';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 534
echo '<p><input type="submit" value="' . $lang->get('user_csrf_confirm_btn_continue') . '" /></p>';
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 535
echo '</form><script type="text/javascript">addOnloadHook(function(){load_component(\'expander\');});</script>';
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 536
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 537
$output->footer();
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 538
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 539
exit;
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 540
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 541
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 542
function csrf_confirm_get_recursive($_inner = false, $pfx = false, $data = false)
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 543
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 544
// make posted arrays work right
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 545
if ( !$data )
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 546
( $_inner == 'post' ) ? $data =& $_POST : $data =& $_GET;
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 547
foreach ( $data as $key => $value )
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 548
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 549
$pfx_this = ( empty($pfx) ) ? $key : "{$pfx}[{$key}]";
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 550
if ( is_array($value) )
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 551
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 552
csrf_confirm_get_recursive(true, $pfx_this, $value);
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 553
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 554
else if ( empty($value) )
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 555
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 556
echo htmlspecialchars($pfx_this . " = <nil>") . "<br />\n";
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 557
echo '<input type="hidden" name="' . htmlspecialchars($pfx_this) . '" value="" />';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 558
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 559
else
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 560
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 561
echo htmlspecialchars($pfx_this . " = " . $value) . "<br />\n";
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 562
echo '<input type="hidden" name="' . htmlspecialchars($pfx_this) . '" value="' . htmlspecialchars($value) . '" />';
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 563
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 564
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 565
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 566
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 567
function csrf_confirm_post_recursive()
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 568
{
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 569
csrf_confirm_get_recursive('post');
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 570
}
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 571
1
+ − 572
// Removed wikiFormat() from here, replaced with RenderMan::render
+ − 573
22
+ − 574
/**
+ − 575
* Tell me if the page exists or not.
+ − 576
* @param string the full page ID (Special:Administration) of the page to check for
+ − 577
* @return bool True if the page exists, false otherwise
+ − 578
*/
+ − 579
1
+ − 580
function isPage($p) {
+ − 581
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 582
22
+ − 583
// Try the easy way first ;-)
+ − 584
if ( isset( $paths->pages[ $p ] ) )
+ − 585
{
+ − 586
return true;
+ − 587
}
76
+ − 588
22
+ − 589
// Special case for Special, Template, and Admin pages that can't have slashes in their URIs
+ − 590
$ns_test = RenderMan::strToPageID( $p );
76
+ − 591
22
+ − 592
if($ns_test[1] != 'Special' && $ns_test[1] != 'Template' && $ns_test[1] != 'Admin')
+ − 593
{
+ − 594
return false;
+ − 595
}
76
+ − 596
22
+ − 597
$particles = explode('/', $p);
+ − 598
if ( isset ( $paths->pages[ $particles[ 0 ] ] ) )
+ − 599
{
+ − 600
return true;
+ − 601
}
+ − 602
else
+ − 603
{
+ − 604
return false;
+ − 605
}
1
+ − 606
}
+ − 607
76
+ − 608
/**
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 609
* Returns the appropriate Namespace_* object for a page.
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 610
* @param string Page ID
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 611
* @param string Namespace
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 612
* @param int Revision ID
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 613
*/
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 614
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 615
function namespace_factory($page_id, $namespace, $revision_id = 0)
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 616
{
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 617
if ( !class_exists("Namespace_$namespace") )
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 618
{
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 619
if ( file_exists(ENANO_ROOT . "/includes/namespaces/" . strtolower($namespace) . ".php") )
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 620
{
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 621
require(ENANO_ROOT . "/includes/namespaces/" . strtolower($namespace) . ".php");
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 622
}
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 623
}
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 624
if ( class_exists("Namespace_$namespace") )
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 625
{
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 626
$class = "Namespace_$namespace";
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 627
$ns = new $class($page_id, $namespace, $revision_id);
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 628
return $ns;
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 629
}
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 630
else
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 631
{
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 632
$ns = new Namespace_Default($page_id, $namespace, $revision_id);
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 633
return $ns;
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 634
}
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 635
}
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 636
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 637
/**
76
+ − 638
* These are some old functions that were used with the Midget codebase. They are deprecated and should not be used any more.
+ − 639
*/
+ − 640
1
+ − 641
function arrayItemUp($arr, $keyname) {
+ − 642
$keylist = array_keys($arr);
+ − 643
$keyflop = array_flip($keylist);
+ − 644
$idx = $keyflop[$keyname];
+ − 645
$idxm = $idx - 1;
+ − 646
$temp = $arr[$keylist[$idxm]];
+ − 647
if($arr[$keylist[0]] == $arr[$keyname]) return $arr;
+ − 648
$arr[$keylist[$idxm]] = $arr[$keylist[$idx]];
+ − 649
$arr[$keylist[$idx]] = $temp;
+ − 650
return $arr;
+ − 651
}
+ − 652
+ − 653
function arrayItemDown($arr, $keyname) {
+ − 654
$keylist = array_keys($arr);
+ − 655
$keyflop = array_flip($keylist);
+ − 656
$idx = $keyflop[$keyname];
+ − 657
$idxm = $idx + 1;
+ − 658
$temp = $arr[$keylist[$idxm]];
+ − 659
$sz = sizeof($arr); $sz--;
+ − 660
if($arr[$keylist[$sz]] == $arr[$keyname]) return $arr;
+ − 661
$arr[$keylist[$idxm]] = $arr[$keylist[$idx]];
+ − 662
$arr[$keylist[$idx]] = $temp;
+ − 663
return $arr;
+ − 664
}
+ − 665
+ − 666
function arrayItemTop($arr, $keyname) {
+ − 667
$keylist = array_keys($arr);
+ − 668
$keyflop = array_flip($keylist);
+ − 669
$idx = $keyflop[$keyname];
+ − 670
while( $orig != $arr[$keylist[0]] ) {
+ − 671
// echo 'Keyname: '.$keylist[$idx] . '<br />'; flush(); ob_flush(); // Debugger
+ − 672
if($idx < 0) return $arr;
+ − 673
if($keylist[$idx] == '' || $keylist[$idx] < 0 || !$keylist[$idx]) {
+ − 674
return $arr;
+ − 675
}
+ − 676
$arr = arrayItemUp($arr, $keylist[$idx]);
+ − 677
$idx--;
+ − 678
}
+ − 679
return $arr;
+ − 680
}
+ − 681
+ − 682
function arrayItemBottom($arr, $keyname) {
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 683
$b = $arr[$keyname];
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 684
unset($arr[$keyname]);
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 685
$arr[$keyname] = $b;
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 686
unset($b);
1
+ − 687
return $arr;
+ − 688
}
+ − 689
606
+ − 690
/**
+ − 691
* Implementation of array_merge() that preserves key names. $arr2 takes precedence over $arr1.
+ − 692
* @param array $arr1
+ − 693
* @param array $arr2
+ − 694
* @return array
+ − 695
*/
+ − 696
+ − 697
function enano_safe_array_merge($arr1, $arr2)
+ − 698
{
+ − 699
$arr3 = $arr1;
+ − 700
foreach($arr2 as $k => $v)
+ − 701
{
+ − 702
$arr3[$k] = $v;
+ − 703
}
+ − 704
return $arr3;
+ − 705
}
+ − 706
770
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 707
/**
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 708
* Looks at all values in an array and casts them to integers if they are strings with digits. Recursive.
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 709
* @param array Array to process
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 710
* @return array
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 711
*/
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 712
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 713
function integerize_array($arr)
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 714
{
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 715
if ( !is_array($arr) )
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 716
return $arr;
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 717
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 718
foreach ( $arr as &$val )
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 719
{
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 720
if ( is_string($val) && ctype_digit($val) && strlen($val) < 10 )
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 721
{
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 722
$val = intval($val);
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 723
}
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 724
else if ( is_array($val) )
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 725
{
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 726
$val = integerize_array($val);
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 727
}
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 728
}
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 729
return $arr;
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 730
}
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 731
1
+ − 732
// Convert IP address to hex string
+ − 733
// Input: 127.0.0.1 (string)
+ − 734
// Output: 0x7f000001 (string)
+ − 735
// Updated 12/8/06 to work with PHP4 and not use eval() (blech)
+ − 736
function ip2hex($ip) {
+ − 737
if ( preg_match('/^([0-9a-f:]+)$/', $ip) )
+ − 738
{
+ − 739
// this is an ipv6 address
+ − 740
return str_replace(':', '', $ip);
+ − 741
}
+ − 742
$nums = explode('.', $ip);
+ − 743
if(sizeof($nums) != 4) return false;
+ − 744
$str = '0x';
+ − 745
foreach($nums as $n)
+ − 746
{
221
+ − 747
$byte = (string)dechex($n);
+ − 748
if ( strlen($byte) < 2 )
+ − 749
$byte = '0' . $byte;
1
+ − 750
}
+ − 751
return $str;
+ − 752
}
+ − 753
+ − 754
// Convert DWord to IP address
+ − 755
// Input: 0x7f000001
+ − 756
// Output: 127.0.0.1
+ − 757
// Updated 12/8/06 to work with PHP4 and not use eval() (blech)
+ − 758
function hex2ip($in) {
+ − 759
if(substr($in, 0, 2) == '0x') $ip = substr($in, 2, 8);
+ − 760
else $ip = substr($in, 0, 8);
+ − 761
$octets = enano_str_split($ip, 2);
+ − 762
$str = '';
+ − 763
$newoct = Array();
+ − 764
foreach($octets as $o)
+ − 765
{
+ − 766
$o = (int)hexdec($o);
+ − 767
$newoct[] = $o;
+ − 768
}
+ − 769
return implode('.', $newoct);
+ − 770
}
+ − 771
+ − 772
// Function strip_php moved to RenderMan class
+ − 773
76
+ − 774
/**
+ − 775
* Immediately brings the site to a halt with an error message. Unlike grinding_halt() this can only be called after the config has been
+ − 776
* fetched (plugin developers don't even need to worry since plugins are always loaded after the config) and shows the site name and
+ − 777
* description.
+ − 778
* @param string The title of the error message
+ − 779
* @param string The body of the message, this can be HTML, and should be separated into paragraphs using the <p> tag
479
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 780
* @param bool Added in 1.1.3. If true, only the error is output. Defaults to false.
76
+ − 781
*/
+ − 782
479
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 783
function die_semicritical($t, $p, $no_wrapper = false)
1
+ − 784
{
+ − 785
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 786
$db->close();
533
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 787
1
+ − 788
if ( ob_get_status() )
+ − 789
ob_end_clean();
533
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 790
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 791
// If the config hasn't been fetched yet, call grinding_halt.
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 792
if ( !defined('ENANO_CONFIG_FETCHED') )
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 793
{
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 794
grinding_halt($t, $p);
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 795
}
500
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 796
533
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 797
// also do grinding_halt() if we're in CLI mode
500
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 798
if ( defined('ENANO_CLI') )
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 799
{
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 800
grinding_halt($t, $p);
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 801
}
76
+ − 802
479
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 803
if ( $no_wrapper )
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 804
{
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 805
echo '<h2>' . htmlspecialchars($t) . '</h2>';
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 806
echo "<p>$p</p>";
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 807
exit;
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 808
}
192db6ac195b
Added $no_wrapper parameter to die_semicritical, useful for some upcoming PageProcessor tweaks.
Dan
diff
changeset
+ − 809
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 810
$output = new Output_Safe();
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 811
$output->set_title($t);
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 812
$output->header();
1
+ − 813
echo $p;
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 814
$output->footer();
76
+ − 815
1
+ − 816
exit;
+ − 817
}
+ − 818
76
+ − 819
/**
+ − 820
* 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.
+ − 821
* @param string The title of the message
+ − 822
* @param string The body of the message, this can be HTML, and should be separated into paragraphs using the <p> tag
+ − 823
*/
+ − 824
1
+ − 825
function die_friendly($t, $p)
+ − 826
{
+ − 827
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 828
1
+ − 829
if ( ob_get_status() )
+ − 830
ob_end_clean();
76
+ − 831
1
+ − 832
$paths->cpage['name'] = $t;
+ − 833
$template->tpl_strings['PAGE_NAME'] = $t;
+ − 834
$template->header();
+ − 835
echo $p;
+ − 836
$template->footer();
+ − 837
$db->close();
76
+ − 838
1
+ − 839
exit;
+ − 840
}
+ − 841
76
+ − 842
/**
+ − 843
* 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.
+ − 844
* @param string The title of the error message
+ − 845
* @param string The body of the message, this can be HTML, and should be separated into paragraphs using the <p> tag
+ − 846
*/
+ − 847
1
+ − 848
function grinding_halt($t, $p)
+ − 849
{
+ − 850
global $db, $session, $paths, $template, $plugins; // Common objects
125
+ − 851
+ − 852
if ( !defined('scriptPath') )
+ − 853
require( ENANO_ROOT . '/config.php' );
76
+ − 854
125
+ − 855
if ( is_object($db) )
+ − 856
$db->close();
500
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 857
1
+ − 858
if ( ob_get_status() )
+ − 859
ob_end_clean();
500
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 860
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 861
if ( defined('ENANO_CLI') )
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 862
{
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 863
// set console color
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 864
echo "\x1B[31;1m";
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 865
// error title
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 866
echo "Critical error in Enano runtime: ";
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 867
// unbold
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 868
echo "$t\n";
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 869
// bold
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 870
echo "\x1B[37;1m";
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 871
echo "Error: ";
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 872
// unbold
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 873
echo "\x1B[0m";
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 874
echo "$p\n";
662
fcab604da9a7
Made grinding_halt() exit with status 1 for POSIX compatibility; jscompress.php utility now accepts non-CDN websites
Dan
diff
changeset
+ − 875
exit(1);
500
455277559782
Added basic CLI support for the Enano API. Loads automatically, just include common.php as normal. REVISION 500!!! :-D
Dan
diff
changeset
+ − 876
}
533
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 877
$theme = ( defined('ENANO_CONFIG_FETCHED') ) ? getConfig('theme_default') : 'oxygen';
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 878
$style = ( defined('ENANO_CONFIG_FETCHED') ) ? '__foo__' : 'bleu';
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 879
1
+ − 880
$tpl = new template_nodb();
533
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 881
$tpl->load_theme($theme, $style);
1
+ − 882
$tpl->tpl_strings['SITE_NAME'] = 'Critical error';
+ − 883
$tpl->tpl_strings['SITE_DESC'] = 'This website is experiencing a serious error and cannot load.';
+ − 884
$tpl->tpl_strings['COPYRIGHT'] = 'Unable to retrieve copyright information';
+ − 885
$tpl->tpl_strings['PAGE_NAME'] = $t;
+ − 886
$tpl->header();
+ − 887
echo $p;
+ − 888
$tpl->footer();
533
698a8f04957c
Huge improvements to the template_nodb class and surrounding code; moved template compiler core to its own non-classed function to allow code re-use
Dan
diff
changeset
+ − 889
1
+ − 890
exit;
+ − 891
}
+ − 892
76
+ − 893
/**
+ − 894
* 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.
+ − 895
*/
+ − 896
+ − 897
function show_category_info()
+ − 898
{
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 899
throw new Exception('show_category_info() is deprecated. Use Namespace_*::display_categories().');
76
+ − 900
}
+ − 901
+ − 902
/**
+ − 903
* 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.
+ − 904
*/
1
+ − 905
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 906
function show_file_info($page = false)
1
+ − 907
{
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 908
throw new Exception('show_file_info() is deprecated. Use Namespace_File::show_info().');
1
+ − 909
}
+ − 910
76
+ − 911
/**
+ − 912
* 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.
+ − 913
*/
+ − 914
1
+ − 915
function display_page_headers()
+ − 916
{
+ − 917
global $db, $session, $paths, $template, $plugins; // Common objects
214
+ − 918
global $lang;
1
+ − 919
if($session->get_permissions('vote_reset') && $paths->cpage['delvotes'] > 0)
+ − 920
{
112
+ − 921
$delvote_ips = unserialize($paths->cpage['delvote_ips']);
+ − 922
$hr = htmlspecialchars(implode(', ', $delvote_ips['u']));
214
+ − 923
+ − 924
$string_id = ( $paths->cpage['delvotes'] == 1 ) ? 'delvote_lbl_votes_one' : 'delvote_lbl_votes_plural';
+ − 925
$string = $lang->get($string_id, array('num_users' => $paths->cpage['delvotes']));
+ − 926
1
+ − 927
echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;" id="mdgDeleteVoteNoticeBox">
214
+ − 928
<b>' . $lang->get('etc_lbl_notice') . '</b> ' . $string . '<br />
+ − 929
<b>' . $lang->get('delvote_lbl_users_that_voted') . '</b> ' . $hr . '<br />
+ − 930
<a href="'.makeUrl($paths->page, 'do=deletepage').'" onclick="ajaxDeletePage(); return false;">' . $lang->get('delvote_btn_deletepage') . '</a> | <a href="'.makeUrl($paths->page, 'do=resetvotes').'" onclick="ajaxResetDelVotes(); return false;">' . $lang->get('delvote_btn_resetvotes') . '</a>
1
+ − 931
</div>';
+ − 932
}
+ − 933
}
+ − 934
76
+ − 935
/**
+ − 936
* 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.
+ − 937
*/
+ − 938
1
+ − 939
function display_page_footers()
+ − 940
{
+ − 941
global $db, $session, $paths, $template, $plugins; // Common objects
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 942
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 943
if ( isset($_GET['nofooters']) )
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 944
{
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 945
return;
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 946
}
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 947
1
+ − 948
$code = $plugins->setHook('send_page_footers');
+ − 949
foreach ( $code as $cmd )
+ − 950
{
+ − 951
eval($cmd);
+ − 952
}
+ − 953
}
+ − 954
76
+ − 955
/**
+ − 956
* 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.
+ − 957
* @param socket A socket resource
+ − 958
* @param string The expected response from the server, this needs to be exactly three characters.
+ − 959
*/
+ − 960
+ − 961
function smtp_get_response($socket, $response, $line = __LINE__)
1
+ − 962
{
76
+ − 963
$server_response = '';
+ − 964
while (substr($server_response, 3, 1) != ' ')
+ − 965
{
+ − 966
if (!($server_response = fgets($socket, 256)))
+ − 967
{
1
+ − 968
die_friendly('SMTP Error', "<p>Couldn't get mail server response codes</p>");
76
+ − 969
}
+ − 970
}
1
+ − 971
76
+ − 972
if (!(substr($server_response, 0, 3) == $response))
+ − 973
{
1
+ − 974
die_friendly('SMTP Error', "<p>Ran into problems sending mail. Response: $server_response</p>");
76
+ − 975
}
1
+ − 976
}
+ − 977
76
+ − 978
/**
+ − 979
* Wrapper for smtp_send_email_core that takes the sender as the fourth parameter instead of additional headers.
+ − 980
* @param string E-mail address to send to
+ − 981
* @param string Subject line
+ − 982
* @param string The body of the message
+ − 983
* @param string Address of the sender
+ − 984
*/
+ − 985
1
+ − 986
function smtp_send_email($to, $subject, $message, $from)
+ − 987
{
+ − 988
return smtp_send_email_core($to, $subject, $message, "From: <$from>\n");
+ − 989
}
+ − 990
76
+ − 991
/**
+ − 992
* Replacement or substitute for PHP's mail() builtin function.
+ − 993
* @param string E-mail address to send to
+ − 994
* @param string Subject line
+ − 995
* @param string The body of the message
+ − 996
* @param string Message headers, separated by a single newline ("\n")
+ − 997
* @copyright (C) phpBB Group
+ − 998
* @license GPL
+ − 999
*/
+ − 1000
1
+ − 1001
function smtp_send_email_core($mail_to, $subject, $message, $headers = '')
+ − 1002
{
76
+ − 1003
// Fix any bare linefeeds in the message to make it RFC821 Compliant.
+ − 1004
$message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
1
+ − 1005
76
+ − 1006
if ($headers != '')
+ − 1007
{
+ − 1008
if (is_array($headers))
+ − 1009
{
+ − 1010
if (sizeof($headers) > 1)
+ − 1011
{
+ − 1012
$headers = join("\n", $headers);
+ − 1013
}
+ − 1014
else
+ − 1015
{
+ − 1016
$headers = $headers[0];
+ − 1017
}
+ − 1018
}
+ − 1019
$headers = chop($headers);
1
+ − 1020
76
+ − 1021
// Make sure there are no bare linefeeds in the headers
+ − 1022
$headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers);
1
+ − 1023
76
+ − 1024
// Ok this is rather confusing all things considered,
+ − 1025
// but we have to grab bcc and cc headers and treat them differently
+ − 1026
// Something we really didn't take into consideration originally
+ − 1027
$header_array = explode("\r\n", $headers);
+ − 1028
@reset($header_array);
1
+ − 1029
76
+ − 1030
$headers = '';
472
bc4b58034f4d
Implemented password reset (albeit hackishly) into the new login API; added dummy window.console object to hopefully reduce errors when Firebug isn't around; fixed the longstanding ACL dismiss/close button bug; fixed a couple undefined variables in mailer; fixed PHP error on attempted opening of /dev/(u)random in rijndael.php; clarified documentation for PageProcessor::update_page(); fixed some logic problems in theme ACL code; disabled CAPTCHA debug
Dan
diff
changeset
+ − 1031
$cc = '';
bc4b58034f4d
Implemented password reset (albeit hackishly) into the new login API; added dummy window.console object to hopefully reduce errors when Firebug isn't around; fixed the longstanding ACL dismiss/close button bug; fixed a couple undefined variables in mailer; fixed PHP error on attempted opening of /dev/(u)random in rijndael.php; clarified documentation for PageProcessor::update_page(); fixed some logic problems in theme ACL code; disabled CAPTCHA debug
Dan
diff
changeset
+ − 1032
$bcc = '';
76
+ − 1033
while(list(, $header) = each($header_array))
+ − 1034
{
+ − 1035
if (preg_match('#^cc:#si', $header))
+ − 1036
{
+ − 1037
$cc = preg_replace('#^cc:(.*)#si', '\1', $header);
+ − 1038
}
+ − 1039
else if (preg_match('#^bcc:#si', $header))
+ − 1040
{
+ − 1041
$bcc = preg_replace('#^bcc:(.*)#si', '\1', $header);
+ − 1042
$header = '';
+ − 1043
}
+ − 1044
$headers .= ($header != '') ? $header . "\r\n" : '';
+ − 1045
}
1
+ − 1046
76
+ − 1047
$headers = chop($headers);
+ − 1048
$cc = explode(', ', $cc);
+ − 1049
$bcc = explode(', ', $bcc);
+ − 1050
}
1
+ − 1051
76
+ − 1052
if (trim($subject) == '')
+ − 1053
{
+ − 1054
die_friendly(GENERAL_ERROR, "No email Subject specified");
+ − 1055
}
1
+ − 1056
76
+ − 1057
if (trim($message) == '')
+ − 1058
{
+ − 1059
die_friendly(GENERAL_ERROR, "Email message was blank");
+ − 1060
}
+ − 1061
1
+ − 1062
// setup SMTP
+ − 1063
$host = getConfig('smtp_server');
+ − 1064
if ( empty($host) )
+ − 1065
return 'No smtp_host in config';
+ − 1066
if ( strstr($host, ':' ) )
+ − 1067
{
+ − 1068
$n = explode(':', $host);
+ − 1069
$smtp_host = $n[0];
+ − 1070
$port = intval($n[1]);
+ − 1071
}
+ − 1072
else
+ − 1073
{
+ − 1074
$smtp_host = $host;
+ − 1075
$port = 25;
+ − 1076
}
76
+ − 1077
1
+ − 1078
$smtp_user = getConfig('smtp_user');
+ − 1079
$smtp_pass = getConfig('smtp_password');
+ − 1080
76
+ − 1081
// Ok we have error checked as much as we can to this point let's get on
+ − 1082
// it already.
+ − 1083
if( !$socket = @fsockopen($smtp_host, $port, $errno, $errstr, 20) )
+ − 1084
{
+ − 1085
die_friendly(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr");
+ − 1086
}
+ − 1087
+ − 1088
// Wait for reply
+ − 1089
smtp_get_response($socket, "220", __LINE__);
1
+ − 1090
76
+ − 1091
// Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
+ − 1092
// This improved as provided by SirSir to accomodate
+ − 1093
if( !empty($smtp_user) && !empty($smtp_pass) )
+ − 1094
{
+ − 1095
enano_fputs($socket, "EHLO " . $smtp_host . "\r\n");
+ − 1096
smtp_get_response($socket, "250", __LINE__);
1
+ − 1097
76
+ − 1098
enano_fputs($socket, "AUTH LOGIN\r\n");
+ − 1099
smtp_get_response($socket, "334", __LINE__);
1
+ − 1100
76
+ − 1101
enano_fputs($socket, base64_encode($smtp_user) . "\r\n");
+ − 1102
smtp_get_response($socket, "334", __LINE__);
1
+ − 1103
76
+ − 1104
enano_fputs($socket, base64_encode($smtp_pass) . "\r\n");
+ − 1105
smtp_get_response($socket, "235", __LINE__);
+ − 1106
}
+ − 1107
else
+ − 1108
{
+ − 1109
enano_fputs($socket, "HELO " . $smtp_host . "\r\n");
+ − 1110
smtp_get_response($socket, "250", __LINE__);
+ − 1111
}
1
+ − 1112
76
+ − 1113
// From this point onward most server response codes should be 250
+ − 1114
// Specify who the mail is from....
+ − 1115
enano_fputs($socket, "MAIL FROM: <" . getConfig('contact_email') . ">\r\n");
+ − 1116
smtp_get_response($socket, "250", __LINE__);
1
+ − 1117
76
+ − 1118
// Specify each user to send to and build to header.
+ − 1119
$to_header = '';
1
+ − 1120
76
+ − 1121
// Add an additional bit of error checking to the To field.
+ − 1122
$mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to);
+ − 1123
if (preg_match('#[^ ]+\@[^ ]+#', $mail_to))
+ − 1124
{
+ − 1125
enano_fputs($socket, "RCPT TO: <$mail_to>\r\n");
+ − 1126
smtp_get_response($socket, "250", __LINE__);
+ − 1127
}
1
+ − 1128
76
+ − 1129
// Ok now do the CC and BCC fields...
+ − 1130
@reset($bcc);
+ − 1131
while(list(, $bcc_address) = each($bcc))
+ − 1132
{
+ − 1133
// Add an additional bit of error checking to bcc header...
+ − 1134
$bcc_address = trim($bcc_address);
+ − 1135
if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address))
+ − 1136
{
+ − 1137
enano_fputs($socket, "RCPT TO: <$bcc_address>\r\n");
+ − 1138
smtp_get_response($socket, "250", __LINE__);
+ − 1139
}
+ − 1140
}
1
+ − 1141
76
+ − 1142
@reset($cc);
+ − 1143
while(list(, $cc_address) = each($cc))
+ − 1144
{
+ − 1145
// Add an additional bit of error checking to cc header
+ − 1146
$cc_address = trim($cc_address);
+ − 1147
if (preg_match('#[^ ]+\@[^ ]+#', $cc_address))
+ − 1148
{
+ − 1149
enano_fputs($socket, "RCPT TO: <$cc_address>\r\n");
+ − 1150
smtp_get_response($socket, "250", __LINE__);
+ − 1151
}
+ − 1152
}
1
+ − 1153
76
+ − 1154
// Ok now we tell the server we are ready to start sending data
+ − 1155
enano_fputs($socket, "DATA\r\n");
1
+ − 1156
76
+ − 1157
// This is the last response code we look for until the end of the message.
+ − 1158
smtp_get_response($socket, "354", __LINE__);
1
+ − 1159
76
+ − 1160
// Send the Subject Line...
+ − 1161
enano_fputs($socket, "Subject: $subject\r\n");
1
+ − 1162
76
+ − 1163
// Now the To Header.
+ − 1164
enano_fputs($socket, "To: $mail_to\r\n");
1
+ − 1165
76
+ − 1166
// Now any custom headers....
+ − 1167
enano_fputs($socket, "$headers\r\n\r\n");
1
+ − 1168
76
+ − 1169
// Ok now we are ready for the message...
+ − 1170
enano_fputs($socket, "$message\r\n");
1
+ − 1171
76
+ − 1172
// Ok the all the ingredients are mixed in let's cook this puppy...
+ − 1173
enano_fputs($socket, ".\r\n");
+ − 1174
smtp_get_response($socket, "250", __LINE__);
1
+ − 1175
76
+ − 1176
// Now tell the server we are done and close the socket...
+ − 1177
enano_fputs($socket, "QUIT\r\n");
+ − 1178
fclose($socket);
1
+ − 1179
76
+ − 1180
return TRUE;
1
+ − 1181
}
+ − 1182
+ − 1183
/**
+ − 1184
* Tell which version of Enano we're running.
+ − 1185
* @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.)
685
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
diff
changeset
+ − 1186
* @param bool If true, prevents nightly build information from being appended, useful for upgrade/versioning checks.
1
+ − 1187
* @return string
+ − 1188
*/
+ − 1189
+ − 1190
function enano_version($long = false, $no_nightly = false)
+ − 1191
{
+ − 1192
$r = getConfig('enano_version');
+ − 1193
$rc = ( $long ) ? ' release candidate ' : 'RC';
+ − 1194
$b = ( $long ) ? ' beta ' : 'b';
+ − 1195
$a = ( $long ) ? ' alpha ' : 'a';
+ − 1196
if($v = getConfig('enano_rc_version')) $r .= $rc.$v;
+ − 1197
if($v = getConfig('enano_beta_version')) $r .= $b.$v;
+ − 1198
if($v = getConfig('enano_alpha_version')) $r .= $a.$v;
+ − 1199
if ( defined('ENANO_NIGHTLY') && !$no_nightly )
+ − 1200
{
+ − 1201
$nightlytag = ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR;
+ − 1202
$nightlylong = ' nightly; build date: ' . ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR;
+ − 1203
$r = ( $long ) ? $r . $nightlylong : $r . '-nightly-' . $nightlytag;
+ − 1204
}
+ − 1205
return $r;
+ − 1206
}
+ − 1207
76
+ − 1208
/**
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1209
* 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
+ − 1210
* @return string
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1211
*/
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1212
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1213
function enano_codename()
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1214
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1215
$names = array(
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1216
'1.0RC1' => 'Leprechaun',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1217
'1.0RC2' => 'Clurichaun',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1218
'1.0RC3' => 'Druid',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1219
'1.0' => 'Banshee',
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1220
'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
+ − 1221
'1.0.1.1'=> 'Loch Ness internal bugfix build',
145
+ − 1222
'1.0.2b1'=> 'Coblynau unstable',
317
+ − 1223
'1.0.2' => 'Coblynau',
387
92664d2efab8
Rebranded source code as 1.1.1; added TinyMCE ACL rule as per Vadi's request: http://forum.enanocms.org/viewtopic.php?f=7&t=54
Dan
diff
changeset
+ − 1224
'1.0.3' => 'Dyrad',
92664d2efab8
Rebranded source code as 1.1.1; added TinyMCE ACL rule as per Vadi's request: http://forum.enanocms.org/viewtopic.php?f=7&t=54
Dan
diff
changeset
+ − 1225
'1.1.1' => 'Caoineag alpha 1',
411
+ − 1226
'1.1.2' => 'Caoineag alpha 2',
436
+ − 1227
'1.1.3' => 'Caoineag alpha 3',
536
+ − 1228
'1.1.4' => 'Caoineag alpha 4',
685
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
diff
changeset
+ − 1229
'1.1.5' => 'Caoineag alpha 5',
801
eb8b23f11744
Two big commits in one day I know, but redid password storage to use HMAC-SHA1. Consolidated much AES processing to three core methods in session that should handle everything automagically. Installation works; upgrades should. Rebranded as 1.1.6.
Dan
diff
changeset
+ − 1230
'1.1.6' => 'Caoineag beta 1'
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1231
);
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1232
$version = enano_version();
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1233
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
+ − 1234
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1235
return $names[$version];
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1236
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1237
return 'Anonymous build';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1238
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1239
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 1240
/**
76
+ − 1241
* Badly named function to send back eval'able Javascript code with an error message. Deprecated, use JSON instead.
+ − 1242
* @param string Message to send
+ − 1243
*/
+ − 1244
1
+ − 1245
function _die($t) {
+ − 1246
$_ob = 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\'' . rawurlencode('' . $t . '') . '\')';
+ − 1247
die($_ob);
+ − 1248
}
+ − 1249
76
+ − 1250
/**
+ − 1251
* Same as _die(), but sends an SQL backtrace with the error message, and doesn't halt execution.
+ − 1252
* @param string Message to send
+ − 1253
*/
+ − 1254
1
+ − 1255
function jsdie($text) {
+ − 1256
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1257
$text = rawurlencode($text . "\n\nSQL Backtrace:\n" . $db->sql_backtrace());
+ − 1258
echo 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\''.$text.'\');';
+ − 1259
}
+ − 1260
+ − 1261
/**
+ − 1262
* Capitalizes the first letter of a string
+ − 1263
* @param $text string the text to be transformed
+ − 1264
* @return string
+ − 1265
*/
76
+ − 1266
1
+ − 1267
function capitalize_first_letter($text)
+ − 1268
{
+ − 1269
return strtoupper(substr($text, 0, 1)) . substr($text, 1);
+ − 1270
}
+ − 1271
+ − 1272
/**
+ − 1273
* Checks if a value in a bitfield is on or off
+ − 1274
* @param $bitfield int the bit-field value
+ − 1275
* @param $value int the value to switch off
+ − 1276
* @return bool
+ − 1277
*/
76
+ − 1278
1
+ − 1279
function is_bit($bitfield, $value)
+ − 1280
{
+ − 1281
return ( $bitfield & $value ) ? true : false;
+ − 1282
}
+ − 1283
+ − 1284
/**
+ − 1285
* Trims spaces/newlines from the beginning and end of a string
+ − 1286
* @param $text the text to process
+ − 1287
* @return string
+ − 1288
*/
76
+ − 1289
1
+ − 1290
function trim_spaces($text)
+ − 1291
{
+ − 1292
$d = true;
+ − 1293
while($d)
+ − 1294
{
+ − 1295
$c = substr($text, 0, 1);
+ − 1296
$a = substr($text, strlen($text)-1, strlen($text));
+ − 1297
if($c == "\n" || $c == "\r" || $c == "\t" || $c == ' ') $text = substr($text, 1, strlen($text));
+ − 1298
elseif($a == "\n" || $a == "\r" || $a == "\t" || $a == ' ') $text = substr($text, 0, strlen($text)-1);
+ − 1299
else $d = false;
+ − 1300
}
+ − 1301
return $text;
+ − 1302
}
+ − 1303
+ − 1304
/**
+ − 1305
* Enano-ese equivalent of str_split() which is only found in PHP5
+ − 1306
* @param $text string the text to split
+ − 1307
* @param $inc int size of each block
+ − 1308
* @return array
+ − 1309
*/
76
+ − 1310
1
+ − 1311
function enano_str_split($text, $inc = 1)
+ − 1312
{
76
+ − 1313
if($inc < 1)
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1314
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1315
return false;
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1316
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1317
if($inc >= strlen($text))
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1318
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1319
return Array($text);
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1320
}
1
+ − 1321
$len = ceil(strlen($text) / $inc);
+ − 1322
$ret = Array();
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1323
for ( $i = 0; $i < strlen($text); $i = $i + $inc )
1
+ − 1324
{
+ − 1325
$ret[] = substr($text, $i, $inc);
+ − 1326
}
+ − 1327
return $ret;
+ − 1328
}
+ − 1329
+ − 1330
/**
+ − 1331
* Converts a hexadecimal number to a binary string.
+ − 1332
* @param text string hexadecimal number
+ − 1333
* @return string
+ − 1334
*/
+ − 1335
function hex2bin($text)
+ − 1336
{
+ − 1337
$arr = enano_str_split($text, 2);
+ − 1338
$ret = '';
+ − 1339
for ($i=0; $i<sizeof($arr); $i++)
+ − 1340
{
+ − 1341
$ret .= chr(hexdec($arr[$i]));
+ − 1342
}
+ − 1343
return $ret;
+ − 1344
}
+ − 1345
+ − 1346
/**
+ − 1347
* Generates and/or prints a human-readable backtrace
76
+ − 1348
* @param bool $return - if true, this function returns a string, otherwise returns null and prints the backtrace
1
+ − 1349
* @return mixed
+ − 1350
*/
76
+ − 1351
1
+ − 1352
function enano_debug_print_backtrace($return = false)
+ − 1353
{
+ − 1354
ob_start();
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 1355
if ( !$return )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 1356
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
+ − 1357
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
+ − 1358
{
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1359
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
+ − 1360
}
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1361
else
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1362
{
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
diff
changeset
+ − 1363
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
+ − 1364
}
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 1365
if ( !$return )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 1366
echo '</pre>';
1
+ − 1367
$c = ob_get_contents();
+ − 1368
ob_end_clean();
+ − 1369
if($return) return $c;
+ − 1370
else echo $c;
+ − 1371
return null;
+ − 1372
}
+ − 1373
+ − 1374
/**
+ − 1375
* Like rawurlencode(), but encodes all characters
+ − 1376
* @param string $text the text to encode
+ − 1377
* @param optional string $prefix text before each hex character
+ − 1378
* @param optional string $suffix text after each hex character
+ − 1379
* @return string
+ − 1380
*/
76
+ − 1381
1
+ − 1382
function hexencode($text, $prefix = '%', $suffix = '')
+ − 1383
{
+ − 1384
$arr = enano_str_split($text);
+ − 1385
$r = '';
+ − 1386
foreach($arr as $a)
+ − 1387
{
+ − 1388
$nibble = (string)dechex(ord($a));
+ − 1389
if(strlen($nibble) == 1) $nibble = '0' . $nibble;
+ − 1390
$r .= $prefix . $nibble . $suffix;
+ − 1391
}
+ − 1392
return $r;
+ − 1393
}
+ − 1394
+ − 1395
/**
+ − 1396
* Enano-ese equivalent of get_magic_quotes_gpc()
+ − 1397
* @return bool
+ − 1398
*/
76
+ − 1399
1
+ − 1400
function enano_get_magic_quotes_gpc()
+ − 1401
{
+ − 1402
if(function_exists('get_magic_quotes_gpc'))
+ − 1403
{
+ − 1404
return ( get_magic_quotes_gpc() == 1 );
+ − 1405
}
+ − 1406
else
+ − 1407
{
+ − 1408
return ( strtolower(@ini_get('magic_quotes_gpc')) == '1' );
+ − 1409
}
+ − 1410
}
+ − 1411
+ − 1412
/**
+ − 1413
* Recursive stripslashes()
+ − 1414
* @param array
+ − 1415
* @return array
+ − 1416
*/
76
+ − 1417
1
+ − 1418
function stripslashes_recurse($arr)
+ − 1419
{
+ − 1420
foreach($arr as $k => $xxxx)
+ − 1421
{
+ − 1422
$val =& $arr[$k];
+ − 1423
if(is_string($val))
+ − 1424
$val = stripslashes($val);
+ − 1425
elseif(is_array($val))
+ − 1426
$val = stripslashes_recurse($val);
+ − 1427
}
+ − 1428
return $arr;
+ − 1429
}
+ − 1430
+ − 1431
/**
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1432
* 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
+ − 1433
* @param array
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1434
* @return array
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1435
*/
76
+ − 1436
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1437
function strip_nul_chars($arr)
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1438
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1439
foreach($arr as $k => $xxxx_unused)
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1440
{
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1441
$val =& $arr[$k];
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1442
if(is_string($val))
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1443
$val = str_replace("\000", '', $val);
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1444
elseif(is_array($val))
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1445
$val = strip_nul_chars($val);
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1446
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1447
return $arr;
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1448
}
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1449
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
diff
changeset
+ − 1450
/**
76
+ − 1451
* 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
+ − 1452
* @ignore - this doesn't work too well in my tests
1
+ − 1453
* @todo port version from the PHP manual
+ − 1454
* @return void
+ − 1455
*/
+ − 1456
function strip_magic_quotes_gpc()
+ − 1457
{
+ − 1458
if(enano_get_magic_quotes_gpc())
+ − 1459
{
40
+ − 1460
$_POST = stripslashes_recurse($_POST);
+ − 1461
$_GET = stripslashes_recurse($_GET);
+ − 1462
$_COOKIE = stripslashes_recurse($_COOKIE);
+ − 1463
$_REQUEST = stripslashes_recurse($_REQUEST);
1
+ − 1464
}
40
+ − 1465
$_POST = strip_nul_chars($_POST);
+ − 1466
$_GET = strip_nul_chars($_GET);
+ − 1467
$_COOKIE = strip_nul_chars($_COOKIE);
+ − 1468
$_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
+ − 1469
$_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
+ − 1470
$_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
+ − 1471
$_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
+ − 1472
$_REQUEST = decode_unicode_array($_REQUEST);
1
+ − 1473
}
+ − 1474
+ − 1475
/**
+ − 1476
* A very basic single-character compression algorithm for binary strings/bitfields
76
+ − 1477
* @param string $bits the text to compress, should be only 1s and 0s
1
+ − 1478
* @return string
+ − 1479
*/
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1480
1
+ − 1481
function compress_bitfield($bits)
+ − 1482
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1483
if ( !preg_match('/^[01]+$/', $bits) )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1484
return false;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1485
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1486
$current = intval($bits{0});
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1487
$clen = 0;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1488
$out = '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1489
for ( $i = 0; $i < strlen($bits); $i++ )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1490
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1491
$cbit = intval($bits{$i});
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1492
if ( $cbit !== $current || $clen == 127 || $i == strlen($bits) - 1 )
1
+ − 1493
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1494
if ( $i == strlen($bits) - 1 && $cbit === $current )
1
+ − 1495
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1496
$clen++;
1
+ − 1497
}
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1498
// write chunk
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1499
$byte = $clen;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1500
if ( $current === 1 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1501
$byte |= 0x80;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1502
$out .= chr($byte);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1503
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1504
if ( $i == strlen($bits) - 1 && $cbit !== $current )
1
+ − 1505
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1506
$out .= ( $cbit === 1 ) ? chr(0x81) : chr(0x1);
1
+ − 1507
}
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1508
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1509
// reset
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1510
$current = intval($cbit);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1511
$clen = 0;
1
+ − 1512
}
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1513
$clen++;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1514
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1515
$crc = dechex(crc32($out));
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1516
while ( strlen($crc) < 8 )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1517
$crc = "0$crc";
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1518
return "cbf2:{$crc}" . hexencode($out, '', '');
1
+ − 1519
}
+ − 1520
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1521
// test case
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1522
// $bf = '0111100010000000000000000000000100000000000000001110000000000000000101100000010100001100010000000000000000000000000000111111111111111111111100100001000000000000000000000000000000000000';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1523
// die('<pre>Original: ' . " $bf\nCompressed: " . compress_bitfield($bf) . "\nProcessed: ".uncompress_bitfield(compress_bitfield($bf)).'</pre>');
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1524
1
+ − 1525
/**
+ − 1526
* Uncompresses a bitfield compressed with compress_bitfield()
+ − 1527
* @param string $bits the compressed bitfield
+ − 1528
* @return string the uncompressed, original (we hope) bitfield OR bool false on error
+ − 1529
*/
76
+ − 1530
1
+ − 1531
function uncompress_bitfield($bits)
+ − 1532
{
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1533
if ( substr($bits, 0, 4) == 'cbf:' )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1534
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1535
return uncompress_bitfield_old($bits);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1536
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1537
if ( substr($bits, 0, 5) != 'cbf2:' )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1538
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1539
echo __FUNCTION__.'(): ERROR: Invalid stream';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1540
return false;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1541
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1542
$bits = substr($bits, 5);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1543
$crc = substr($bits, 0, 8);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1544
$bits = substr($bits, 8);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1545
$bits = hexdecode($bits);
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1546
if ( dechex(crc32($bits)) !== $crc )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1547
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1548
echo __FUNCTION__."(): ERROR: CRC failed";
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1549
return false;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1550
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1551
$out = '';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1552
for ( $i = 0; $i < strlen($bits); $i++ )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1553
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1554
$byte = ord($bits{$i});
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1555
$char = $byte & 0x80 ? '1' : '0';
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1556
$byte &= ~0x80;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1557
for ( $j = 0; $j < $byte; $j++ )
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1558
{
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1559
$out .= $char;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1560
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1561
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1562
return $out;
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1563
}
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1564
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1565
/**
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1566
* Decompressor for old-format bitfields.
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1567
* @param string
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1568
* @return string
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1569
* @access private
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1570
*/
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1571
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1572
function uncompress_bitfield_old($bits)
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 1573
{
1
+ − 1574
if(substr($bits, 0, 4) != 'cbf:')
+ − 1575
{
+ − 1576
echo __FUNCTION__.'(): ERROR: Invalid stream';
+ − 1577
return false;
+ − 1578
}
+ − 1579
$len = intval(substr($bits, strpos($bits, 'len=')+4, strpos($bits, ';')-strpos($bits, 'len=')-4));
+ − 1580
$crc = substr($bits, strpos($bits, 'crc=')+4, 8);
+ − 1581
$data = substr($bits, strpos($bits, 'data=')+5, strpos($bits, '|end')-strpos($bits, 'data=')-5);
+ − 1582
$data = explode(',', $data);
+ − 1583
foreach($data as $a => $b)
+ − 1584
{
+ − 1585
$d =& $data[$a];
+ − 1586
$char = substr($d, 0, 1);
+ − 1587
$dlen = intval(substr($d, 2, strlen($d)-1));
+ − 1588
$s = '';
+ − 1589
for($i=0;$i<$dlen;$i++,$s.=$char);
+ − 1590
$d = $s;
+ − 1591
unset($s, $dlen, $char);
+ − 1592
}
+ − 1593
$decompressed = implode('', $data);
+ − 1594
$decompressed = substr($decompressed, 0, -1);
+ − 1595
$dcrc = (string)dechex(crc32($decompressed));
+ − 1596
if($dcrc != $crc)
+ − 1597
{
+ − 1598
echo __FUNCTION__.'(): ERROR: CRC check failed<br />debug info:<br />original crc: '.$crc.'<br />decomp\'ed crc: '.$dcrc.'<br />';
+ − 1599
return false;
+ − 1600
}
+ − 1601
return $decompressed;
+ − 1602
}
+ − 1603
+ − 1604
/**
+ − 1605
* Exports a MySQL table into a SQL string.
+ − 1606
* @param string $table The name of the table to export
+ − 1607
* @param bool $structure If true, include a CREATE TABLE command
+ − 1608
* @param bool $data If true, include the contents of the table
+ − 1609
* @param bool $compact If true, omits newlines between parts of SQL statements, use in Enano database exporter
+ − 1610
* @return string
+ − 1611
*/
+ − 1612
+ − 1613
function export_table($table, $structure = true, $data = true, $compact = false)
+ − 1614
{
+ − 1615
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1616
$struct_keys = '';
+ − 1617
$divider = (!$compact) ? "\n" : "\n";
+ − 1618
$spacer1 = (!$compact) ? "\n" : " ";
+ − 1619
$spacer2 = (!$compact) ? " " : " ";
+ − 1620
$rowspacer = (!$compact) ? "\n " : " ";
+ − 1621
$index_list = Array();
+ − 1622
$cols = $db->sql_query('SHOW COLUMNS IN '.$table.';');
+ − 1623
if(!$cols)
+ − 1624
{
+ − 1625
echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />';
+ − 1626
return false;
+ − 1627
}
+ − 1628
$col = Array();
+ − 1629
$sqlcol = Array();
+ − 1630
$collist = Array();
+ − 1631
$pri_keys = Array();
+ − 1632
// Using fetchrow_num() here to compensate for MySQL l10n
+ − 1633
while( $row = $db->fetchrow_num() )
+ − 1634
{
+ − 1635
$field =& $row[0];
+ − 1636
$type =& $row[1];
+ − 1637
$null =& $row[2];
+ − 1638
$key =& $row[3];
+ − 1639
$def =& $row[4];
+ − 1640
$extra =& $row[5];
+ − 1641
$col[] = Array(
+ − 1642
'name'=>$field,
+ − 1643
'type'=>$type,
+ − 1644
'null'=>$null,
+ − 1645
'key'=>$key,
+ − 1646
'default'=>$def,
+ − 1647
'extra'=>$extra,
+ − 1648
);
+ − 1649
$collist[] = $field;
+ − 1650
}
76
+ − 1651
1
+ − 1652
if ( $structure )
+ − 1653
{
+ − 1654
$db->sql_query('SET SQL_QUOTE_SHOW_CREATE = 0;');
+ − 1655
$struct = $db->sql_query('SHOW CREATE TABLE '.$table.';');
+ − 1656
if ( !$struct )
+ − 1657
$db->_die();
+ − 1658
$row = $db->fetchrow_num();
+ − 1659
$db->free_result();
+ − 1660
$struct = $row[1];
+ − 1661
$struct = preg_replace("/\n\) ENGINE=(.+)$/", "\n);", $struct);
+ − 1662
unset($row);
+ − 1663
if ( $compact )
+ − 1664
{
+ − 1665
$struct_arr = explode("\n", $struct);
+ − 1666
foreach ( $struct_arr as $i => $leg )
+ − 1667
{
+ − 1668
if ( $i == 0 )
+ − 1669
continue;
+ − 1670
$test = trim($leg);
+ − 1671
if ( empty($test) )
+ − 1672
{
+ − 1673
unset($struct_arr[$i]);
+ − 1674
continue;
+ − 1675
}
+ − 1676
$struct_arr[$i] = preg_replace('/^([\s]*)/', ' ', $leg);
+ − 1677
}
+ − 1678
$struct = implode("", $struct_arr);
+ − 1679
}
+ − 1680
}
76
+ − 1681
1
+ − 1682
// Structuring complete
+ − 1683
if($data)
+ − 1684
{
+ − 1685
$datq = $db->sql_query('SELECT * FROM '.$table.';');
+ − 1686
if(!$datq)
+ − 1687
{
+ − 1688
echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />';
+ − 1689
return false;
+ − 1690
}
+ − 1691
if($db->numrows() < 1)
+ − 1692
{
+ − 1693
if($structure) return $struct;
+ − 1694
else return '';
+ − 1695
}
+ − 1696
$rowdata = Array();
+ − 1697
$dataqs = Array();
+ − 1698
$insert_strings = Array();
+ − 1699
$z = false;
+ − 1700
while($row = $db->fetchrow_num())
+ − 1701
{
+ − 1702
$z = false;
+ − 1703
foreach($row as $i => $cell)
+ − 1704
{
+ − 1705
$str = mysql_encode_column($cell, $col[$i]['type']);
+ − 1706
$rowdata[] = $str;
+ − 1707
}
+ − 1708
$dataqs2 = implode(",$rowspacer", $dataqs) . ",$rowspacer" . '( ' . implode(', ', $rowdata) . ' )';
+ − 1709
$ins = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . $dataqs2 . ";";
+ − 1710
if ( strlen( $ins ) > MYSQL_MAX_PACKET_SIZE )
+ − 1711
{
+ − 1712
// We've exceeded the maximum allowed packet size for MySQL - separate this into a different query
+ − 1713
$insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";;
+ − 1714
$dataqs = Array('( ' . implode(', ', $rowdata) . ' )');
+ − 1715
$z = true;
+ − 1716
}
+ − 1717
else
+ − 1718
{
+ − 1719
$dataqs[] = '( ' . implode(', ', $rowdata) . ' )';
+ − 1720
}
+ − 1721
$rowdata = Array();
+ − 1722
}
+ − 1723
if ( !$z )
+ − 1724
{
+ − 1725
$insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";;
+ − 1726
$dataqs = Array();
+ − 1727
}
+ − 1728
$datstring = implode($divider, $insert_strings);
+ − 1729
}
+ − 1730
if($structure && !$data) return $struct;
+ − 1731
elseif(!$structure && $data) return $datstring;
+ − 1732
elseif($structure && $data) return $struct . $divider . $datstring;
+ − 1733
elseif(!$structure && !$data) return '';
+ − 1734
}
+ − 1735
+ − 1736
/**
+ − 1737
* Encodes a string value for use in an INSERT statement for given column type $type.
+ − 1738
* @access private
+ − 1739
*/
76
+ − 1740
1
+ − 1741
function mysql_encode_column($input, $type)
+ − 1742
{
+ − 1743
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 1744
// Decide whether to quote the string or not
+ − 1745
if(substr($type, 0, 7) == 'varchar' || $type == 'datetime' || $type == 'text' || $type == 'tinytext' || $type == 'smalltext' || $type == 'longtext' || substr($type, 0, 4) == 'char')
+ − 1746
{
+ − 1747
$str = "'" . $db->escape($input) . "'";
+ − 1748
}
+ − 1749
elseif(in_array($type, Array('blob', 'longblob', 'mediumblob', 'smallblob')) || substr($type, 0, 6) == 'binary' || substr($type, 0, 9) == 'varbinary')
+ − 1750
{
+ − 1751
$str = '0x' . hexencode($input, '', '');
+ − 1752
}
+ − 1753
elseif(is_null($input))
+ − 1754
{
+ − 1755
$str = 'NULL';
+ − 1756
}
+ − 1757
else
+ − 1758
{
+ − 1759
$str = (string)$input;
+ − 1760
}
+ − 1761
return $str;
+ − 1762
}
+ − 1763
+ − 1764
/**
+ − 1765
* Creates an associative array defining which file extensions are allowed and which ones aren't
+ − 1766
* @return array keyname will be a file extension, value will be true or false
+ − 1767
*/
+ − 1768
+ − 1769
function fetch_allowed_extensions()
+ − 1770
{
+ − 1771
global $mime_types;
+ − 1772
$bits = getConfig('allowed_mime_types');
+ − 1773
if(!$bits) return Array(false);
+ − 1774
$bits = uncompress_bitfield($bits);
+ − 1775
if(!$bits) return Array(false);
+ − 1776
$bits = enano_str_split($bits, 1);
+ − 1777
$ret = Array();
+ − 1778
$mt = array_keys($mime_types);
+ − 1779
foreach($bits as $i => $b)
+ − 1780
{
+ − 1781
$ret[$mt[$i]] = ( $b == '1' ) ? true : false;
+ − 1782
}
+ − 1783
return $ret;
+ − 1784
}
+ − 1785
+ − 1786
/**
+ − 1787
* Generates a random key suitable for encryption
+ − 1788
* @param int $len the length of the key
+ − 1789
* @return string a BINARY key
+ − 1790
*/
+ − 1791
+ − 1792
function randkey($len = 32)
+ − 1793
{
+ − 1794
$key = '';
+ − 1795
for($i=0;$i<$len;$i++)
+ − 1796
{
+ − 1797
$key .= chr(mt_rand(0, 255));
+ − 1798
}
+ − 1799
return $key;
+ − 1800
}
+ − 1801
+ − 1802
/**
+ − 1803
* Decodes a hex string.
+ − 1804
* @param string $hex The hex code to decode
+ − 1805
* @return string
+ − 1806
*/
+ − 1807
+ − 1808
function hexdecode($hex)
+ − 1809
{
+ − 1810
$hex = enano_str_split($hex, 2);
+ − 1811
$bin_key = '';
+ − 1812
foreach($hex as $nibble)
+ − 1813
{
+ − 1814
$byte = chr(hexdec($nibble));
+ − 1815
$bin_key .= $byte;
+ − 1816
}
+ − 1817
return $bin_key;
+ − 1818
}
+ − 1819
+ − 1820
/**
+ − 1821
* Enano's own (almost) bulletproof HTML sanitizer.
+ − 1822
* @param string $html The input HTML
+ − 1823
* @return string cleaned HTML
+ − 1824
*/
+ − 1825
+ − 1826
function sanitize_html($html, $filter_php = true)
+ − 1827
{
163
+ − 1828
// Random seed for substitution
+ − 1829
$rand_seed = md5( sha1(microtime()) . mt_rand() );
+ − 1830
593
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
diff
changeset
+ − 1831
// We need MediaWiki
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
diff
changeset
+ − 1832
require_once(ENANO_ROOT . '/includes/wikiengine/Tables.php');
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
diff
changeset
+ − 1833
163
+ − 1834
// Strip out comments that are already escaped
+ − 1835
preg_match_all('/<!--(.*?)-->/', $html, $comment_match);
+ − 1836
$i = 0;
+ − 1837
foreach ( $comment_match[0] as $comment )
+ − 1838
{
+ − 1839
$html = str_replace_once($comment, "{HTMLCOMMENT:$i:$rand_seed}", $html);
+ − 1840
$i++;
+ − 1841
}
+ − 1842
+ − 1843
// Strip out code sections that will be postprocessed by Text_Wiki
+ − 1844
preg_match_all(';^<code(\s[^>]*)?>((?:(?R)|.)*?)\n</code>(\s|$);msi', $html, $code_match);
+ − 1845
$i = 0;
+ − 1846
foreach ( $code_match[0] as $code )
+ − 1847
{
+ − 1848
$html = str_replace_once($code, "{TW_CODE:$i:$rand_seed}", $html);
+ − 1849
$i++;
+ − 1850
}
76
+ − 1851
1
+ − 1852
$html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>(.*?)</\\1>#is', '<\\1\\2\\3javascript:\\59>\\60</\\1>', $html);
+ − 1853
$html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>#is', '<\\1\\2\\3javascript:\\59>', $html);
76
+ − 1854
1
+ − 1855
if($filter_php)
+ − 1856
$html = str_replace(
+ − 1857
Array('<?php', '<?', '<%', '?>', '%>'),
+ − 1858
Array('<?php', '<?', '<%', '?>', '%>'),
+ − 1859
$html);
76
+ − 1860
1
+ − 1861
$tag_whitelist = array_keys ( setupAttributeWhitelist() );
+ − 1862
if ( !$filter_php )
+ − 1863
$tag_whitelist[] = '?php';
164
+ − 1864
// allow HTML comments
+ − 1865
$tag_whitelist[] = '!--';
1
+ − 1866
$len = strlen($html);
+ − 1867
$in_quote = false;
+ − 1868
$quote_char = '';
+ − 1869
$tag_start = 0;
+ − 1870
$tag_name = '';
+ − 1871
$in_tag = false;
+ − 1872
$trk_name = false;
+ − 1873
for ( $i = 0; $i < $len; $i++ )
+ − 1874
{
+ − 1875
$chr = $html{$i};
+ − 1876
$prev = ( $i == 0 ) ? '' : $html{ $i - 1 };
+ − 1877
$next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
+ − 1878
if ( $in_quote && $in_tag )
+ − 1879
{
+ − 1880
if ( $quote_char == $chr && $prev != '\\' )
+ − 1881
$in_quote = false;
+ − 1882
}
+ − 1883
elseif ( ( $chr == '"' || $chr == "'" ) && $prev != '\\' && $in_tag )
+ − 1884
{
+ − 1885
$in_quote = true;
+ − 1886
$quote_char = $chr;
+ − 1887
}
+ − 1888
if ( $chr == '<' && !$in_tag && $next != '/' )
76
+ − 1889
{
1
+ − 1890
// start of a tag
+ − 1891
$tag_start = $i;
+ − 1892
$in_tag = true;
+ − 1893
$trk_name = true;
+ − 1894
}
+ − 1895
elseif ( !$in_quote && $in_tag && $chr == '>' )
+ − 1896
{
+ − 1897
$full_tag = substr($html, $tag_start, ( $i - $tag_start ) + 1 );
+ − 1898
$l = strlen($tag_name) + 2;
+ − 1899
$attribs_only = trim( substr($full_tag, $l, ( strlen($full_tag) - $l - 1 ) ) );
76
+ − 1900
1
+ − 1901
// Debugging message
+ − 1902
// echo htmlspecialchars($full_tag) . '<br />';
76
+ − 1903
450
35f9d6c93eec
Fixed case where HTML comments were getting stripped when opening tag not followed by whitespace (<!--foo--> was stripped, <!-- foo --> was not, neither is stripped now)
Dan
diff
changeset
+ − 1904
if ( !in_array($tag_name, $tag_whitelist) && substr($tag_name, 0, 3) != '!--' )
1
+ − 1905
{
+ − 1906
// Illegal tag
+ − 1907
//echo $tag_name . ' ';
76
+ − 1908
1
+ − 1909
$s = ( empty($attribs_only) ) ? '' : ' ';
76
+ − 1910
1
+ − 1911
$sanitized = '<' . $tag_name . $s . $attribs_only . '>';
76
+ − 1912
1
+ − 1913
$html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1);
+ − 1914
$html = str_replace('</' . $tag_name . '>', '</' . $tag_name . '>', $html);
+ − 1915
$new_i = $tag_start + strlen($sanitized);
76
+ − 1916
1
+ − 1917
$len = strlen($html);
+ − 1918
$i = $new_i;
76
+ − 1919
1
+ − 1920
$in_tag = false;
+ − 1921
$tag_name = '';
+ − 1922
continue;
+ − 1923
}
+ − 1924
else
+ − 1925
{
164
+ − 1926
// If not filtering PHP, don't bother to strip
1
+ − 1927
if ( $tag_name == '?php' && !$filter_php )
+ − 1928
continue;
164
+ − 1929
// If this is a comment, likewise skip this "tag"
+ − 1930
if ( $tag_name == '!--' )
+ − 1931
continue;
1
+ − 1932
$f = fixTagAttributes( $attribs_only, $tag_name );
+ − 1933
$s = ( empty($f) ) ? '' : ' ';
76
+ − 1934
1
+ − 1935
$sanitized = '<' . $tag_name . $f . '>';
+ − 1936
$new_i = $tag_start + strlen($sanitized);
76
+ − 1937
1
+ − 1938
$html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1);
+ − 1939
$len = strlen($html);
+ − 1940
$i = $new_i;
76
+ − 1941
1
+ − 1942
$in_tag = false;
+ − 1943
$tag_name = '';
+ − 1944
continue;
+ − 1945
}
+ − 1946
}
+ − 1947
elseif ( $in_tag && $trk_name )
+ − 1948
{
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 1949
$is_alphabetical = ( strtolower($chr) != strtoupper($chr) || in_array($chr, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) || $chr == '?' || $chr == '!' || $chr == '-' );
1
+ − 1950
if ( $is_alphabetical )
+ − 1951
$tag_name .= $chr;
+ − 1952
else
+ − 1953
{
+ − 1954
$trk_name = false;
+ − 1955
}
+ − 1956
}
76
+ − 1957
1
+ − 1958
}
164
+ − 1959
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
+ − 1960
// 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
+ − 1961
// <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
+ − 1962
// <
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 1963
// 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
+ − 1964
$html = preg_replace('/<(script|iframe)(.+?)src=([^>]*)</i', '<\\1\\2src=\\3<', $html);
817
+ − 1965
+ − 1966
// Vulnerability reported by fuzion from nukeit.org:
+ − 1967
// XSS in closing HTML tag style attribute
+ − 1968
// Fix: escape all closing tags with non-whitelisted characters
+ − 1969
$html = preg_replace('!</((?:.*)([^a-z0-9-_:]+)(?:.*))>!', '</\\1>', $html);
76
+ − 1970
163
+ − 1971
// Restore stripped comments
+ − 1972
$i = 0;
+ − 1973
foreach ( $comment_match[0] as $comment )
+ − 1974
{
+ − 1975
$html = str_replace_once("{HTMLCOMMENT:$i:$rand_seed}", $comment, $html);
+ − 1976
$i++;
+ − 1977
}
+ − 1978
+ − 1979
// Restore stripped code
+ − 1980
$i = 0;
+ − 1981
foreach ( $code_match[0] as $code )
+ − 1982
{
+ − 1983
$html = str_replace_once("{TW_CODE:$i:$rand_seed}", $code, $html);
+ − 1984
$i++;
+ − 1985
}
76
+ − 1986
1
+ − 1987
return $html;
+ − 1988
}
+ − 1989
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
+ − 1990
/**
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
+ − 1991
* 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
+ − 1992
* @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
+ − 1993
* @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
+ − 1994
*/
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
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
+ − 1997
{
76
+ − 1998
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
+ − 1999
$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
+ − 2000
$tok2 = "</litewiki>";
76
+ − 2001
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
+ − 2002
$block_tags = array('div', 'p', 'table', 'blockquote', 'pre');
76
+ − 2003
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
+ − 2004
$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
+ − 2005
$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
+ − 2006
$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
+ − 2007
$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
+ − 2008
$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
+ − 2009
$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
+ − 2010
$trk_name = false;
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
$diag = 0;
76
+ − 2013
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
+ − 2014
$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
+ − 2015
$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
+ − 2016
$block_start = 0;
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
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
+ − 2019
{
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
+ − 2020
$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
+ − 2021
$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
+ − 2022
$next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 };
76
+ − 2023
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
+ − 2024
// 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
+ − 2025
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
+ − 2026
{
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
+ − 2027
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
+ − 2028
$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
+ − 2029
}
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
+ − 2030
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
+ − 2031
{
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
+ − 2032
$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
+ − 2033
$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
+ − 2034
}
76
+ − 2035
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
+ − 2036
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
+ − 2037
{
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
+ − 2038
// 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
+ − 2039
$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
+ − 2040
$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
+ − 2041
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
+ − 2042
{
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
+ − 2043
$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
+ − 2044
// 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
+ − 2045
$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
+ − 2046
$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
+ − 2047
$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
+ − 2048
$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
+ − 2049
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
+ − 2050
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
+ − 2051
}
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
+ − 2052
// 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
+ − 2053
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
+ − 2054
{
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
+ − 2055
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
+ − 2056
{
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
+ − 2057
$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
+ − 2058
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
+ − 2059
{
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
+ − 2060
$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
+ − 2061
$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
+ − 2062
// 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
+ − 2063
$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
+ − 2064
$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
+ − 2065
$html = substr($html, 0, $block_start) . $new_text . substr($html, $i);
76
+ − 2066
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
+ − 2067
$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
+ − 2068
$len = strlen($html);
76
+ − 2069
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
+ − 2070
//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
+ − 2071
}
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
+ − 2072
}
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
+ − 2073
}
76
+ − 2074
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
+ − 2075
$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
+ − 2076
$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
+ − 2077
$tag_name = '';
76
+ − 2078
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
+ − 2079
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
+ − 2080
}
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
+ − 2081
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
+ − 2082
{
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
+ − 2083
// 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
+ − 2084
$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
+ − 2085
$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
+ − 2086
$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
+ − 2087
}
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
+ − 2088
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
+ − 2089
{
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
+ − 2090
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
+ − 2091
{
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
+ − 2092
// 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
+ − 2093
// echo '<inline ' . $tag_name . '> ';
76
+ − 2094
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
+ − 2095
$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
+ − 2096
$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
+ − 2097
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
+ − 2098
}
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
+ − 2099
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
+ − 2100
{
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
+ − 2101
// 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
+ − 2102
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
+ − 2103
{
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
+ − 2104
//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
+ − 2105
$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
+ − 2106
$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
+ − 2107
$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
+ − 2108
}
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
+ − 2109
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
+ − 2110
{
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
+ − 2111
$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
+ − 2112
}
76
+ − 2113
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
+ − 2114
$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
+ − 2115
$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
+ − 2116
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
+ − 2117
}
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
+ − 2118
}
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
+ − 2119
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
+ − 2120
{
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
+ − 2121
$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
+ − 2122
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
+ − 2123
$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
+ − 2124
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
+ − 2125
{
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
+ − 2126
$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
+ − 2127
}
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
+ − 2128
}
76
+ − 2129
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
+ − 2130
// Tokenization complete
76
+ − 2131
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
+ − 2132
}
76
+ − 2133
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
+ − 2134
$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
+ − 2135
// 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
+ − 2136
$html = preg_replace($regex, '\\1', $html);
76
+ − 2137
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
+ − 2138
return $html;
76
+ − 2139
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
+ − 2140
}
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
+ − 2141
1
+ − 2142
function htmlalternatives($string)
+ − 2143
{
+ − 2144
$ret = '';
+ − 2145
for ( $i = 0; $i < strlen($string); $i++ )
+ − 2146
{
+ − 2147
$chr = $string{$i};
+ − 2148
$ch1 = ord($chr);
+ − 2149
$ch2 = dechex($ch1);
+ − 2150
$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) . ')';
+ − 2151
$ret .= $byte;
+ − 2152
$ret .= '([\s]){0,2}';
+ − 2153
}
+ − 2154
return $ret;
+ − 2155
}
+ − 2156
+ − 2157
/**
825
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2158
* Portal function allowing spam-filtering plugins.
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2159
* Hooking guide:
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2160
* - Attach to spam_check
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2161
* - Return either true or false - true if the message is spam-free, false if it fails your test
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2162
* @example
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2163
<code>
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2164
$plugins->attachHook('spam_check', 'return my_spam_check($string);');
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2165
function my_spam_check($string)
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2166
{
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2167
if ( stristr($string, 'viagra') )
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2168
return false;
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2169
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2170
return true;
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2171
}
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2172
</code>
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2173
* @param string String to check for spam
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2174
* @param string Author name
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2175
* @param string Author e-mail
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2176
* @param string Author website
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2177
* @param string Author IP
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2178
* @return bool
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2179
*/
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2180
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2181
function spamalyze($string, $name = false, $email = false, $url = false, $ip = false)
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2182
{
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2183
global $db, $session, $paths, $template, $plugins; // Common objects
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2184
if ( !$ip )
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2185
$ip =& $_SERVER['REMOTE_ADDR'];
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2186
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2187
$code = $plugins->setHook('spam_check');
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2188
foreach ( $code as $cmd )
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2189
{
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2190
$result = eval($cmd);
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2191
if ( !$result )
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2192
return false;
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2193
}
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2194
return true;
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2195
}
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2196
9d5c04c1414f
Added (very basic) spam filtering plugin support. Plugins can mark a message as spam by hooking into the spam check API, which is documented in functions.php. No spam checking functionality is built-in.
Dan
diff
changeset
+ − 2197
/**
1
+ − 2198
* Paginates (breaks into multiple pages) a MySQL result resource, which is treated as unbuffered.
+ − 2199
* @param resource The MySQL result resource. This should preferably be an unbuffered query.
+ − 2200
* @param string A template, with variables being named after the column name
+ − 2201
* @param int The number of total results. This should be determined by a second query.
+ − 2202
* @param string sprintf-style formatting string for URLs for result pages. First parameter will be start offset.
+ − 2203
* @param int Optional. Start offset in individual results. Defaults to 0.
+ − 2204
* @param int Optional. The number of results per page. Defualts to 10.
+ − 2205
* @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.
+ − 2206
* @param string Optional. The text to be sent before the result list, only if there are any results. Possibly the start of a table.
+ − 2207
* @param string Optional. The text to be sent after the result list, only if there are any results. Possibly the end of a table.
+ − 2208
* @return string
+ − 2209
*/
+ − 2210
+ − 2211
function paginate($q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = '')
+ − 2212
{
+ − 2213
global $db, $session, $paths, $template, $plugins; // Common objects
359
+ − 2214
global $lang;
+ − 2215
1
+ − 2216
$parser = $template->makeParserText($tpl_text);
+ − 2217
$num_pages = ceil ( $num_results / $perpage );
+ − 2218
$out = '';
+ − 2219
$i = 0;
+ − 2220
$this_page = ceil ( $start / $perpage );
76
+ − 2221
1
+ − 2222
// Build paginator
82
+ − 2223
$pg_css = ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ?
+ − 2224
// IE-specific hack
+ − 2225
'display: block; width: 1px;':
+ − 2226
// Other browsers
+ − 2227
'display: table; margin: 10px 0 0 auto;';
+ − 2228
$begin = '<div class="tblholder" style="'. $pg_css . '">
1
+ − 2229
<table border="0" cellspacing="1" cellpadding="4">
359
+ − 2230
<tr><th>' . $lang->get('paginate_lbl_page') . '</th>';
1
+ − 2231
$block = '<td class="row1" style="text-align: center;">{LINK}</td>';
+ − 2232
$end = '</tr></table></div>';
+ − 2233
$blk = $template->makeParserText($block);
+ − 2234
$inner = '';
+ − 2235
$cls = 'row2';
+ − 2236
if ( $num_pages < 5 )
+ − 2237
{
+ − 2238
for ( $i = 0; $i < $num_pages; $i++ )
+ − 2239
{
+ − 2240
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2241
$offset = strval($i * $perpage);
76
+ − 2242
$url = htmlspecialchars(sprintf($result_url, $offset));
1
+ − 2243
$j = $i + 1;
+ − 2244
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2245
$blk->assign_vars(array(
+ − 2246
'CLASS'=>$cls,
+ − 2247
'LINK'=>$link
+ − 2248
));
+ − 2249
$inner .= $blk->run();
+ − 2250
}
+ − 2251
}
+ − 2252
else
+ − 2253
{
+ − 2254
if ( $this_page + 5 > $num_pages )
+ − 2255
{
+ − 2256
$list = Array();
+ − 2257
$tp = $this_page;
+ − 2258
if ( $this_page + 0 == $num_pages ) $tp = $tp - 3;
+ − 2259
if ( $this_page + 1 == $num_pages ) $tp = $tp - 2;
+ − 2260
if ( $this_page + 2 == $num_pages ) $tp = $tp - 1;
+ − 2261
for ( $i = $tp - 1; $i <= $tp + 1; $i++ )
+ − 2262
{
+ − 2263
$list[] = $i;
+ − 2264
}
+ − 2265
}
+ − 2266
else
+ − 2267
{
+ − 2268
$list = Array();
+ − 2269
$current = $this_page;
+ − 2270
$lower = ( $current < 3 ) ? 1 : $current - 1;
+ − 2271
for ( $i = 0; $i < 3; $i++ )
+ − 2272
{
+ − 2273
$list[] = $lower + $i;
+ − 2274
}
+ − 2275
}
+ − 2276
$url = sprintf($result_url, '0');
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2277
$link = ( 0 == $start ) ? "<b>" . $lang->get('paginate_btn_first') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« " . $lang->get('paginate_btn_first') . "</a>";
1
+ − 2278
$blk->assign_vars(array(
+ − 2279
'CLASS'=>$cls,
+ − 2280
'LINK'=>$link
+ − 2281
));
+ − 2282
$inner .= $blk->run();
76
+ − 2283
1
+ − 2284
// if ( !in_array(1, $list) )
+ − 2285
// {
+ − 2286
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2287
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ − 2288
// $inner .= $blk->run();
+ − 2289
// }
76
+ − 2290
1
+ − 2291
foreach ( $list as $i )
+ − 2292
{
+ − 2293
if ( $i == $num_pages )
+ − 2294
break;
+ − 2295
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2296
$offset = strval($i * $perpage);
+ − 2297
$url = sprintf($result_url, $offset);
+ − 2298
$j = $i + 1;
+ − 2299
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2300
$blk->assign_vars(array(
+ − 2301
'CLASS'=>$cls,
+ − 2302
'LINK'=>$link
+ − 2303
));
+ − 2304
$inner .= $blk->run();
+ − 2305
}
76
+ − 2306
1
+ − 2307
$total = $num_pages * $perpage - $perpage;
76
+ − 2308
1
+ − 2309
if ( $this_page < $num_pages )
+ − 2310
{
+ − 2311
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2312
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ − 2313
// $inner .= $blk->run();
76
+ − 2314
1
+ − 2315
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2316
$offset = strval($total);
+ − 2317
$url = sprintf($result_url, $offset);
+ − 2318
$j = $i + 1;
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2319
$link = ( $offset == strval($start) ) ? "<b>" . $lang->get('paginate_btn_last') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('paginate_btn_last') . " »</a>";
1
+ − 2320
$blk->assign_vars(array(
+ − 2321
'CLASS'=>$cls,
+ − 2322
'LINK'=>$link
+ − 2323
));
+ − 2324
$inner .= $blk->run();
+ − 2325
}
76
+ − 2326
1
+ − 2327
}
76
+ − 2328
1
+ − 2329
$inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$this_page.', '.$num_pages.', '.$perpage.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>';
76
+ − 2330
1
+ − 2331
$paginator = "\n$begin$inner$end\n";
+ − 2332
$out .= $paginator;
76
+ − 2333
1
+ − 2334
$cls = 'row2';
76
+ − 2335
1
+ − 2336
if ( $row = $db->fetchrow($q) )
+ − 2337
{
+ − 2338
$i = 0;
+ − 2339
$out .= $header;
+ − 2340
do {
+ − 2341
$i++;
+ − 2342
if ( $i <= $start )
+ − 2343
{
+ − 2344
continue;
+ − 2345
}
+ − 2346
if ( ( $i - $start ) > $perpage )
+ − 2347
{
+ − 2348
break;
+ − 2349
}
+ − 2350
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2351
foreach ( $row as $j => $val )
+ − 2352
{
+ − 2353
if ( isset($callers[$j]) )
+ − 2354
{
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 2355
$tmp = ( is_callable($callers[$j]) ) ? @call_user_func($callers[$j], $val, $row) : $val;
76
+ − 2356
575
9c1ab9c74662
Fixed two bugs in paginator: noisy warning when rows run out and empty strings not being treated as valid from formatting functions
Dan
diff
changeset
+ − 2357
if ( is_string($tmp) )
1
+ − 2358
{
+ − 2359
$row[$j] = $tmp;
+ − 2360
}
+ − 2361
}
+ − 2362
}
+ − 2363
$parser->assign_vars($row);
+ − 2364
$parser->assign_vars(array('_css_class' => $cls));
+ − 2365
$out .= $parser->run();
575
9c1ab9c74662
Fixed two bugs in paginator: noisy warning when rows run out and empty strings not being treated as valid from formatting functions
Dan
diff
changeset
+ − 2366
} while ( $row = @$db->fetchrow($q) );
1
+ − 2367
$out .= $footer;
+ − 2368
}
76
+ − 2369
1
+ − 2370
$out .= $paginator;
76
+ − 2371
1
+ − 2372
return $out;
+ − 2373
}
+ − 2374
+ − 2375
/**
+ − 2376
* This is the same as paginate(), but it processes an array instead of a MySQL result resource.
+ − 2377
* @param array The results. Each value is simply echoed.
+ − 2378
* @param int The number of total results. This should be determined by a second query.
+ − 2379
* @param string sprintf-style formatting string for URLs for result pages. First parameter will be start offset.
+ − 2380
* @param int Optional. Start offset in individual results. Defaults to 0.
+ − 2381
* @param int Optional. The number of results per page. Defualts to 10.
+ − 2382
* @param string Optional. The text to be sent before the result list, only if there are any results. Possibly the start of a table.
+ − 2383
* @param string Optional. The text to be sent after the result list, only if there are any results. Possibly the end of a table.
+ − 2384
* @return string
+ − 2385
*/
+ − 2386
+ − 2387
function paginate_array($q, $num_results, $result_url, $start = 0, $perpage = 10, $header = '', $footer = '')
+ − 2388
{
+ − 2389
global $db, $session, $paths, $template, $plugins; // Common objects
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2390
global $lang;
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2391
1
+ − 2392
$num_pages = ceil ( $num_results / $perpage );
+ − 2393
$out = '';
+ − 2394
$i = 0;
+ − 2395
$this_page = ceil ( $start / $perpage );
76
+ − 2396
1
+ − 2397
// Build paginator
+ − 2398
$begin = '<div class="tblholder" style="display: table; margin: 10px 0 0 auto;">
+ − 2399
<table border="0" cellspacing="1" cellpadding="4">
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2400
<tr><th>' . $lang->get('paginate_lbl_page') . '</th>';
1
+ − 2401
$block = '<td class="row1" style="text-align: center;">{LINK}</td>';
+ − 2402
$end = '</tr></table></div>';
+ − 2403
$blk = $template->makeParserText($block);
+ − 2404
$inner = '';
+ − 2405
$cls = 'row2';
272
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
+ − 2406
$total = $num_pages * $perpage - $perpage;
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2407
/*
1
+ − 2408
if ( $start > 0 )
+ − 2409
{
+ − 2410
$url = sprintf($result_url, abs($start - $perpage));
359
+ − 2411
$link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« " . $lang->get('paginate_btn_prev') . "</a>";
1
+ − 2412
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2413
$blk->assign_vars(array(
+ − 2414
'CLASS'=>$cls,
+ − 2415
'LINK'=>$link
+ − 2416
));
+ − 2417
$inner .= $blk->run();
+ − 2418
}
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2419
*/
1
+ − 2420
if ( $num_pages < 5 )
+ − 2421
{
+ − 2422
for ( $i = 0; $i < $num_pages; $i++ )
+ − 2423
{
+ − 2424
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2425
$offset = strval($i * $perpage);
76
+ − 2426
$url = htmlspecialchars(sprintf($result_url, $offset));
1
+ − 2427
$j = $i + 1;
+ − 2428
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2429
$blk->assign_vars(array(
+ − 2430
'CLASS'=>$cls,
+ − 2431
'LINK'=>$link
+ − 2432
));
+ − 2433
$inner .= $blk->run();
+ − 2434
}
+ − 2435
}
+ − 2436
else
+ − 2437
{
+ − 2438
if ( $this_page + 5 > $num_pages )
+ − 2439
{
+ − 2440
$list = Array();
+ − 2441
$tp = $this_page;
+ − 2442
if ( $this_page + 0 == $num_pages ) $tp = $tp - 3;
+ − 2443
if ( $this_page + 1 == $num_pages ) $tp = $tp - 2;
+ − 2444
if ( $this_page + 2 == $num_pages ) $tp = $tp - 1;
+ − 2445
for ( $i = $tp - 1; $i <= $tp + 1; $i++ )
+ − 2446
{
+ − 2447
$list[] = $i;
+ − 2448
}
+ − 2449
}
+ − 2450
else
+ − 2451
{
+ − 2452
$list = Array();
+ − 2453
$current = $this_page;
+ − 2454
$lower = ( $current < 3 ) ? 1 : $current - 1;
+ − 2455
for ( $i = 0; $i < 3; $i++ )
+ − 2456
{
+ − 2457
$list[] = $lower + $i;
+ − 2458
}
+ − 2459
}
+ − 2460
$url = sprintf($result_url, '0');
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2461
$link = ( 0 == $start ) ? "<b>" . $lang->get('paginate_btn_first') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« " . $lang->get('paginate_btn_first') . "</a>";
1
+ − 2462
$blk->assign_vars(array(
+ − 2463
'CLASS'=>$cls,
+ − 2464
'LINK'=>$link
+ − 2465
));
+ − 2466
$inner .= $blk->run();
76
+ − 2467
1
+ − 2468
// if ( !in_array(1, $list) )
+ − 2469
// {
+ − 2470
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2471
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ − 2472
// $inner .= $blk->run();
+ − 2473
// }
76
+ − 2474
1
+ − 2475
foreach ( $list as $i )
+ − 2476
{
+ − 2477
if ( $i == $num_pages )
+ − 2478
break;
+ − 2479
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2480
$offset = strval($i * $perpage);
+ − 2481
$url = sprintf($result_url, $offset);
+ − 2482
$j = $i + 1;
+ − 2483
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2484
$blk->assign_vars(array(
+ − 2485
'CLASS'=>$cls,
+ − 2486
'LINK'=>$link
+ − 2487
));
+ − 2488
$inner .= $blk->run();
+ − 2489
}
76
+ − 2490
1
+ − 2491
if ( $this_page < $num_pages )
+ − 2492
{
+ − 2493
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2494
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ − 2495
// $inner .= $blk->run();
76
+ − 2496
1
+ − 2497
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2498
$offset = strval($total);
+ − 2499
$url = sprintf($result_url, $offset);
+ − 2500
$j = $i + 1;
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2501
$link = ( $offset == strval($start) ) ? "<b>" . $lang->get('paginate_btn_last') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('paginate_btn_last') . " »</a>";
1
+ − 2502
$blk->assign_vars(array(
+ − 2503
'CLASS'=>$cls,
+ − 2504
'LINK'=>$link
+ − 2505
));
+ − 2506
$inner .= $blk->run();
+ − 2507
}
76
+ − 2508
1
+ − 2509
}
76
+ − 2510
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2511
/*
1
+ − 2512
if ( $start < $total )
+ − 2513
{
272
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
+ − 2514
$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
+ − 2515
$url = htmlspecialchars(sprintf($result_url, strval($link_offset)));
359
+ − 2516
$link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('paginate_btn_next') . " »</a>";
1
+ − 2517
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2518
$blk->assign_vars(array(
+ − 2519
'CLASS'=>$cls,
+ − 2520
'LINK'=>$link
+ − 2521
));
+ − 2522
$inner .= $blk->run();
+ − 2523
}
362
02d315d1cc58
Started localization on User CP. Localized pagination, password strength, and various other small widgets. Fixed bug in path manager causing return of fullpage from get_page_id_from_url() even when namespace is Special.
Dan
diff
changeset
+ − 2524
*/
76
+ − 2525
1
+ − 2526
$inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$this_page.', '.$num_pages.', '.$perpage.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>';
76
+ − 2527
1
+ − 2528
$paginator = "\n$begin$inner$end\n";
+ − 2529
if ( $total > 1 )
272
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
+ − 2530
{
1
+ − 2531
$out .= $paginator;
272
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
+ − 2532
}
76
+ − 2533
1
+ − 2534
$cls = 'row2';
76
+ − 2535
1
+ − 2536
if ( sizeof($q) > 0 )
+ − 2537
{
+ − 2538
$i = 0;
+ − 2539
$out .= $header;
+ − 2540
foreach ( $q as $val ) {
+ − 2541
$i++;
+ − 2542
if ( $i <= $start )
+ − 2543
{
+ − 2544
continue;
+ − 2545
}
+ − 2546
if ( ( $i - $start ) > $perpage )
+ − 2547
{
+ − 2548
break;
+ − 2549
}
+ − 2550
$out .= $val;
+ − 2551
}
+ − 2552
$out .= $footer;
+ − 2553
}
76
+ − 2554
1
+ − 2555
if ( $total > 1 )
+ − 2556
$out .= $paginator;
76
+ − 2557
1
+ − 2558
return $out;
+ − 2559
}
+ − 2560
76
+ − 2561
/**
1
+ − 2562
* Enano version of fputs for debugging
+ − 2563
*/
+ − 2564
+ − 2565
function enano_fputs($socket, $data)
+ − 2566
{
+ − 2567
// echo '<pre>' . htmlspecialchars($data) . '</pre>';
+ − 2568
// flush();
+ − 2569
// ob_flush();
+ − 2570
// ob_end_flush();
+ − 2571
return fputs($socket, $data);
+ − 2572
}
+ − 2573
+ − 2574
/**
+ − 2575
* Sanitizes a page URL string so that it can safely be stored in the database.
+ − 2576
* @param string Page ID to sanitize
+ − 2577
* @return string Cleaned text
+ − 2578
*/
+ − 2579
+ − 2580
function sanitize_page_id($page_id)
+ − 2581
{
325
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2582
global $db, $session, $paths, $template, $plugins; // Common objects
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2583
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2584
if ( isset($paths->nslist['User']) )
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2585
{
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 2586
if ( preg_match('/^' . str_replace('/', '\\/', preg_quote($paths->nslist['User'])) . '/', $page_id) )
325
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2587
{
377
bb3e6c3bd4f4
Removed stray debugging info from ACL editor success notification; added ability for guests to set language on URI (?lang=eng); added html_in_pages ACL type and separated from php_in_pages so HTML can be embedded but not PHP; rewote portions of the path manager to better abstract URL input; added Zend Framework into list of BSD-licensed libraries; localized some remaining strings; got the migration script working, but just barely; fixed display bug in Special:Contributions; localized Main Page button in admin panel
Dan
diff
changeset
+ − 2588
$ip = preg_replace('/^' . str_replace('/', '\\/', preg_quote($paths->nslist['User'])) . '/', '', $page_id);
325
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2589
if ( is_valid_ip($ip) )
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2590
{
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2591
return $page_id;
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2592
}
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2593
}
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2594
}
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2595
685
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
diff
changeset
+ − 2596
if ( empty($page_id) )
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
diff
changeset
+ − 2597
return '';
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
diff
changeset
+ − 2598
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
+ − 2599
// 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
+ − 2600
$page_id = dirtify_page_id($page_id);
76
+ − 2601
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2602
$pid_clean = preg_replace('/[\w\.\/:;\(\)@\[\]_-]/', 'X', $page_id);
1
+ − 2603
$pid_dirty = enano_str_split($pid_clean, 1);
685
17ebe24cdf85
Rebranded as 1.1.5 (Caoineag alpha 5) and fixed a couple bugs related to CDN support in template_nodb and installerUI. Updated readme.
Dan
diff
changeset
+ − 2604
1
+ − 2605
foreach ( $pid_dirty as $id => $char )
+ − 2606
{
+ − 2607
if ( $char == 'X' )
+ − 2608
continue;
+ − 2609
$cid = ord($char);
+ − 2610
$cid = dechex($cid);
+ − 2611
$cid = strval($cid);
+ − 2612
if ( strlen($cid) < 2 )
+ − 2613
{
+ − 2614
$cid = strtoupper("0$cid");
+ − 2615
}
+ − 2616
$pid_dirty[$id] = ".$cid";
+ − 2617
}
76
+ − 2618
1
+ − 2619
$pid_chars = enano_str_split($page_id, 1);
+ − 2620
$page_id_cleaned = '';
76
+ − 2621
1
+ − 2622
foreach ( $pid_chars as $id => $char )
+ − 2623
{
+ − 2624
if ( $pid_dirty[$id] == 'X' )
+ − 2625
$page_id_cleaned .= $char;
+ − 2626
else
+ − 2627
$page_id_cleaned .= $pid_dirty[$id];
+ − 2628
}
325
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2629
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2630
// global $mime_types;
76
+ − 2631
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2632
// $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
+ − 2633
// $exts = '(' . implode('|', $exts) . ')';
76
+ − 2634
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2635
// $page_id_cleaned = preg_replace('/\.2e' . $exts . '$/', '.\\1', $page_id_cleaned);
76
+ − 2636
1
+ − 2637
return $page_id_cleaned;
+ − 2638
}
+ − 2639
+ − 2640
/**
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
+ − 2641
* 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
+ − 2642
* @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
+ − 2643
* @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
+ − 2644
*/
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2645
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2646
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
+ − 2647
{
38
+ − 2648
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 2649
// 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
+ − 2650
$page_id = str_replace(' ', '_', $page_id);
76
+ − 2651
38
+ − 2652
// Exception for userpages for IP addresses
770
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 2653
$pid_ip_check = ( is_object($paths) ) ? preg_replace('+^' . preg_quote($paths->nslist['User']) . '+', '', $page_id) : $page_id;
62fed244fa1c
Fixed timezone preference setting not fully implemented; added ability for users to select their own rank from a list of possible ranks based on group membership and user level
Dan
diff
changeset
+ − 2654
if ( is_valid_ip($pid_ip_check) )
38
+ − 2655
{
325
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2656
return $page_id;
38
+ − 2657
}
76
+ − 2658
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
+ − 2659
preg_match_all('/\.[A-Fa-f0-9][A-Fa-f0-9]/', $page_id, $matches);
76
+ − 2660
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
+ − 2661
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
+ − 2662
{
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2663
$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
+ − 2664
$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
+ − 2665
$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
+ − 2666
$char = chr($char);
800
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 2667
if ( preg_match('/^[\w\.\/:;\(\)@\[\]_-]$/', $char) )
9cdfe82c56cd
Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
diff
changeset
+ − 2668
continue;
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
+ − 2669
$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
+ − 2670
}
325
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2671
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
+ − 2672
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
+ − 2673
}
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2674
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2675
/**
76
+ − 2676
* 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
+ − 2677
* @param int The number to process
+ − 2678
* @return string Input number with commas added
+ − 2679
*/
+ − 2680
+ − 2681
function commatize($num)
+ − 2682
{
+ − 2683
$num = (string)$num;
+ − 2684
if ( strpos($num, '.') )
+ − 2685
{
+ − 2686
$whole = explode('.', $num);
+ − 2687
$num = $whole[0];
+ − 2688
$dec = $whole[1];
+ − 2689
}
+ − 2690
else
+ − 2691
{
+ − 2692
$whole = $num;
+ − 2693
}
+ − 2694
$offset = ( strlen($num) ) % 3;
+ − 2695
$len = strlen($num);
+ − 2696
$offset = ( $offset == 0 )
+ − 2697
? 3
+ − 2698
: $offset;
+ − 2699
for ( $i = $offset; $i < $len; $i=$i+3 )
+ − 2700
{
+ − 2701
$num = substr($num, 0, $i) . ',' . substr($num, $i, $len);
+ − 2702
$len = strlen($num);
+ − 2703
$i++;
+ − 2704
}
+ − 2705
if ( isset($dec) )
+ − 2706
{
+ − 2707
return $num . '.' . $dec;
+ − 2708
}
+ − 2709
else
+ − 2710
{
+ − 2711
return $num;
+ − 2712
}
+ − 2713
}
+ − 2714
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
+ − 2715
/**
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
+ − 2716
* 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
+ − 2717
* @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
+ − 2718
* @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
+ − 2719
* @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
+ − 2720
*/
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
+ − 2721
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
+ − 2722
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
+ − 2723
{
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
+ − 2724
$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
+ − 2725
$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
+ − 2726
$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
+ − 2727
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
+ − 2728
}
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
+ − 2729
38
+ − 2730
/**
+ − 2731
* Tells if a given IP address is valid.
+ − 2732
* @param string suspected IP address
+ − 2733
* @return bool true if valid, false otherwise
+ − 2734
*/
76
+ − 2735
38
+ − 2736
function is_valid_ip($ip)
+ − 2737
{
710
+ − 2738
// This next one came from phpBB3.
38
+ − 2739
$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])';
710
+ − 2740
$ipv6 = '(?:[a-f0-9]{0,4}):(?:[a-f0-9]{0,4}):(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{0,4}:|:)?(?:[a-f0-9]{1,4})';
76
+ − 2741
38
+ − 2742
if ( preg_match("/^{$ipv4}$/", $ip) || preg_match("/^{$ipv6}$/", $ip) )
+ − 2743
return true;
+ − 2744
else
+ − 2745
return false;
+ − 2746
}
+ − 2747
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
+ − 2748
/**
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
+ − 2749
* 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
+ − 2750
* @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
+ − 2751
* @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
+ − 2752
* @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
+ − 2753
*/
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
+ − 2754
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
+ − 2755
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
+ − 2756
{
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
+ − 2757
$needle_len = strlen($needle);
593
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
diff
changeset
+ − 2758
if ( $pos = strstr($haystack, $needle) )
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
+ − 2759
{
593
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
diff
changeset
+ − 2760
$upto = substr($haystack, 0, ( strlen($haystack) - strlen($pos) ));
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
diff
changeset
+ − 2761
$from = substr($pos, $needle_len);
4f9bec0d65c1
More optimization work. Moved special page init functions to common instead of common_post hook. Allowed paths to cache page metadata on filesystem. Phased out the redundancy in $paths->pages that paired a number with every urlname as foreach loops are allowed now (and have been for some time). Fixed missing includes for several functions. Rewrote str_replace_once to be a lot more efficient.
Dan
diff
changeset
+ − 2762
return "{$upto}{$thread}{$from}";
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
+ − 2763
}
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
+ − 2764
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
+ − 2765
}
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
+ − 2766
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
+ − 2767
/**
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2768
* Replaces all given occurences of needle in haystack, case insensitively.
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2769
* @param string Needle
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2770
* @param string Thread
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2771
* @param string Haystack
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2772
* @return string
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2773
*/
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2774
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2775
function str_replace_i($needle, $thread, $haystack)
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2776
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2777
$needle_len = strlen($needle);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2778
$haystack_len = strlen($haystack);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2779
for ( $i = 0; $i < $haystack_len; $i++ )
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2780
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2781
$test = substr($haystack, $i, $needle_len);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2782
if ( strtolower($test) == strtolower($needle) )
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2783
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2784
// Got it!
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2785
$upto = substr($haystack, 0, $i);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2786
$from = substr($haystack, ( $i + $needle_len ));
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2787
$haystack = "{$upto}{$thread}{$from}";
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2788
$haystack_len = strlen($haystack);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2789
$i = $i + strlen($thread);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2790
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2791
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2792
return $haystack;
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2793
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2794
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2795
/**
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2796
* Highlights a term in a string.
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2797
* @param string Needle (term to highlight)
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2798
* @param string Haystack (search string)
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2799
* @param string Starting tag (<b>)
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2800
* @param string Ending tag (</b>)
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2801
* @return string
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2802
*/
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2803
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2804
function highlight_term($needle, $haystack, $start_tag = '<b>', $end_tag = '</b>')
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2805
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2806
$needle_len = strlen($needle);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2807
$haystack_len = strlen($haystack);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2808
for ( $i = 0; $i < $haystack_len; $i++ )
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2809
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2810
$test = substr($haystack, $i, $needle_len);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2811
if ( strtolower($test) == strtolower($needle) )
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2812
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2813
// Got it!
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2814
$upto = substr($haystack, 0, $i);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2815
$from = substr($haystack, ( $i + $needle_len ));
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2816
$haystack = "{$upto}{$start_tag}{$test}{$end_tag}{$from}";
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2817
$haystack_len = strlen($haystack);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2818
$i = $i + strlen($needle) + strlen($start_tag) + strlen($end_tag);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2819
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2820
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2821
return $haystack;
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2822
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2823
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2824
/**
756
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2825
* Registers a new type of search result. Because this is so tricky to do but keep clean, this function takes an associative array as its
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2826
* only parameter. This array configures the function. The required keys are:
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2827
* - table: the database table to search
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2828
* - titlecolumn: the column that will be used as the title of the search result. This will have a weight of 1.5
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2829
* - uniqueid: a TPL-format string, variables being column names, that will be unique for every result. This should contain a string that
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2830
* will be specific to your *type* of search result in addition to a primary key or other unique identifier.
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2831
* - linkformat: an array with the keys page_id and namespace which are where your result will link, plus the following additional options:
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2832
* - append: added to the full generated URL
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2833
* - query: query string without initial "?"
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2834
* Additional options:
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2835
* - datacolumn
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2836
* - additionalcolumns: additional data to select if you want to use a custom formatting callback
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2837
* - formatcallback: a callback or TPL string. If a callback, it will be called with the parameters being the current result row and an
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2838
* array of words in case you want to highlight anything; the callback will be expected to return a string containing
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2839
* a fully formatted and sanitized blob of HTML. If formatcallback is a TPL string, variables will be named after table
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2840
* columns.
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2841
* - additionalwhere: additional SQL to inject into WHERE clause, in the format of "AND foo = bar"
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2842
* @example Working example of adding users to search results:
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2843
<code>
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2844
register_search_handler(array(
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2845
'table' => 'users',
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2846
'titlecolumn' => 'username',
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2847
'uniqueid' => 'ns=User;cid={username}',
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2848
'additionalcolumns' => array('user_id'),
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2849
'resultnote' => '[Member]',
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2850
'linkformat' => array(
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2851
'page_id' => '{username}',
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2852
'namespace' => 'User'
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2853
),
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2854
'formatcallback' => 'format_user_search_result',
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2855
));
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2856
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2857
function format_user_search_result($row)
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2858
{
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2859
global $session, $lang;
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2860
$rankdata = $session->get_user_rank(intval($row['user_id']));
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2861
$rankspan = '<span style="' . $rankdata['rank_style'] . '">' . $lang->get($rankdata['rank_title']) . '</span>';
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2862
if ( empty($rankdata['user_title']) )
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2863
{
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2864
return $rankspan;
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2865
}
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2866
else
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2867
{
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2868
return '"' . htmlspecialchars($rankdata['user_title']) . "\" (<b>$rankspan</b>)";
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2869
}
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2870
}
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2871
</code>
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2872
* @param array Options array - see function documentation
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2873
* @return null
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2874
*/
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2875
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2876
global $search_handlers;
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2877
$search_handlers = array();
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2878
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2879
function register_search_handler($options)
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2880
{
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2881
global $search_handlers;
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2882
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2883
$required = array('table', 'titlecolumn', 'uniqueid', 'linkformat');
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2884
foreach ( $required as $key )
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2885
{
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2886
if ( !isset($options[$key]) )
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2887
{
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2888
throw new Exception("Required search handler option '$key' is missing");
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2889
}
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2890
}
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2891
$search_handlers[] = $options;
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2892
return null;
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2893
}
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2894
e8cf18383425
Added a new search API that allows much easier registration of search results. Basically you give the engine a table, a few columns to look at, and tell it how to format the results and you're done.
Dan
diff
changeset
+ − 2895
/**
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
+ − 2896
* 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
+ − 2897
* @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
+ − 2898
* @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
+ − 2899
*/
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
+ − 2900
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
+ − 2901
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
+ − 2902
{
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
+ − 2903
$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
+ − 2904
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
+ − 2905
$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
+ − 2906
$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
+ − 2907
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
+ − 2908
{
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
+ − 2909
$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
+ − 2910
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
+ − 2911
{
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
+ − 2912
$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
+ − 2913
$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
+ − 2914
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
+ − 2915
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
+ − 2916
{
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
+ − 2917
// 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
+ − 2918
$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
+ − 2919
}
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
+ − 2920
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
+ − 2921
{
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
+ − 2922
// 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
+ − 2923
$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
+ − 2924
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
+ − 2925
. 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
+ − 2926
}
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
+ − 2927
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
+ − 2928
{
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
+ − 2929
// 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
+ − 2930
$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
+ − 2931
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
+ − 2932
. 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
+ − 2933
. 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
+ − 2934
}
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
+ − 2935
}
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
+ − 2936
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
+ − 2937
{
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
+ − 2938
$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
+ − 2939
}
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
+ − 2940
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
+ − 2941
$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
+ − 2942
}
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
+ − 2943
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
+ − 2944
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
+ − 2945
}
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
+ − 2946
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
+ − 2947
/**
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
+ − 2948
* 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
+ − 2949
* @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
+ − 2950
* @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
+ − 2951
*/
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
+ − 2952
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
+ − 2953
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
+ − 2954
{
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
+ − 2955
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
+ − 2956
{
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
+ − 2957
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
+ − 2958
{
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
+ − 2959
$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
+ − 2960
}
270
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2961
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
+ − 2962
{
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
+ − 2963
$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
+ − 2964
}
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
+ − 2965
}
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
+ − 2966
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
+ − 2967
}
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
+ − 2968
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
+ − 2969
/**
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
+ − 2970
* 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
+ − 2971
* @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
+ − 2972
* @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
+ − 2973
*/
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
+ − 2974
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
+ − 2975
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
+ − 2976
{
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
+ − 2977
$tag = strtolower($tag);
315
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
+ − 2978
$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
+ − 2979
$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
+ − 2980
$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
+ − 2981
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
+ − 2982
}
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
+ − 2983
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
+ − 2984
/**
610
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2985
* Replacement for gzencode() which doesn't always work.
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2986
* @param string Data to compress
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2987
* @param int Compression level - 0 (no compression) to 9 (maximum compression)
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2988
* @param string Filename to encode into the compressed data - defaults to blank
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2989
* @param string Comment for archive - defaults to blank
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2990
* @return string Compressed data
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2991
*/
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2992
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2993
function enano_gzencode($data = "", $level = 6, $filename = "", $comments = "")
610
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 2994
{
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2995
$flags = (empty($comment)? 0 : 16) + (empty($filename)? 0 : 8);
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2996
$mtime = time();
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2997
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2998
if ( !function_exists('gzdeflate') )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2999
return false;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 3000
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 3001
return (pack("C1C1C1C1VC1C1", 0x1f, 0x8b, 8, $flags, $mtime, 2, 0xFF) .
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 3002
(empty($filename) ? "" : $filename . "\0") .
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 3003
(empty($comment) ? "" : $comment . "\0") .
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 3004
gzdeflate($data, $level) .
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 3005
pack("VV", crc32($data), strlen($data)));
610
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 3006
}
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 3007
798
+ − 3008
$php_errors = array();
+ − 3009
+ − 3010
/**
+ − 3011
* Enano's PHP error handler.
+ − 3012
* handler ( int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] )
+ − 3013
* @access private
+ − 3014
*/
+ − 3015
+ − 3016
function enano_handle_error($errno, $errstr, $errfile, $errline)
+ − 3017
{
+ − 3018
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 3019
+ − 3020
$er = error_reporting();
+ − 3021
if ( ! $er & $errno || $er == 0 )
+ − 3022
{
+ − 3023
return true;
+ − 3024
}
+ − 3025
global $do_gzip, $php_errors;
+ − 3026
+ − 3027
if ( defined('ENANO_DEBUG') )
+ − 3028
{
+ − 3029
// turn off gzip and echo out error immediately for debug installs
+ − 3030
$do_gzip = false;
+ − 3031
}
+ − 3032
+ − 3033
$error_type = 'error';
+ − 3034
if ( in_array($errno, array(E_WARNING, E_USER_WARNING)) )
+ − 3035
$error_type = 'warning';
+ − 3036
else if ( in_array($errno, array(E_NOTICE, E_USER_NOTICE)) )
+ − 3037
$error_type = 'notice';
+ − 3038
+ − 3039
if ( @is_object(@$plugins) )
+ − 3040
{
+ − 3041
$code = $plugins->setHook('php_error');
+ − 3042
foreach ( $code as $cmd )
+ − 3043
{
+ − 3044
eval($cmd);
+ − 3045
}
+ − 3046
}
+ − 3047
+ − 3048
// bypass errors in date() and mktime() (Enano has its own code for this anyway)
+ − 3049
if ( strstr($errstr, "It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.") )
+ − 3050
{
+ − 3051
return true;
+ − 3052
}
+ − 3053
+ − 3054
if ( $do_gzip )
+ − 3055
{
+ − 3056
$php_errors[] = array(
+ − 3057
'num' => $errno,
+ − 3058
'type' => $error_type,
+ − 3059
'error' => $errstr,
+ − 3060
'file' => $errfile,
+ − 3061
'line' => $errline
+ − 3062
);
+ − 3063
}
+ − 3064
else
+ − 3065
{
+ − 3066
echo "[ <b>PHP $error_type:</b> $errstr in <b>$errfile</b>:<b>$errline</b> ]<br />";
+ − 3067
}
+ − 3068
}
+ − 3069
+ − 3070
set_error_handler('enano_handle_error');
+ − 3071
610
de33b0d26741
Fixed gzip output - no longer depends on ob_gzhandler(), uses gzencode() now with a failsafe available if gzencode() is not available. Public function gzip_output() remains unchanged.
Dan
diff
changeset
+ − 3072
/**
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
+ − 3073
* 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
+ − 3074
*/
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
+ − 3075
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
+ − 3076
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
+ − 3077
{
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
+ − 3078
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
+ − 3079
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
+ − 3080
//
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
+ − 3081
// Compress buffered output if required and send to browser
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 3082
// Sorry, doesn't work in IE. What else is new?
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
+ − 3083
//
720
e2762777b170
Fixed attempt at gzip compression after headers sent; hopefully safely escape args to scale_image() instead of erroring out
Dan
diff
changeset
+ − 3084
if ( $do_gzip && function_exists('gzdeflate') && !strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && !headers_sent() )
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
+ − 3085
{
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
+ − 3086
$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
+ − 3087
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
+ − 3088
798
+ − 3089
global $php_errors;
+ − 3090
if ( !empty($php_errors) )
+ − 3091
{
+ − 3092
$errors = '';
+ − 3093
foreach ( $php_errors as $error )
+ − 3094
{
+ − 3095
$errors .= "[ <b>PHP {$error['type']}:</b> {$error['error']} in <b>{$error['file']}</b>:<b>{$error['line']}</b> ]<br />";
+ − 3096
}
+ − 3097
$gzip_contents = str_replace("</body>", "$errors</body>", $gzip_contents);
+ − 3098
}
+ − 3099
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 3100
$return = @enano_gzencode($gzip_contents);
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
+ − 3101
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
+ − 3102
{
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
+ − 3103
header('Content-encoding: gzip');
542
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3104
echo $return;
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
+ − 3105
}
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
+ − 3106
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
+ − 3107
{
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
+ − 3108
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
+ − 3109
}
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
+ − 3110
}
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
+ − 3111
}
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
+ − 3112
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
+ − 3113
/**
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
+ − 3114
* 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
+ − 3115
* @param string HTML to process
294
4ab30e8dd168
Nothing special. ksort()ing list of allowed filetypes in the admin panel to make editing the list marginally easier
Dan
diff
changeset
+ − 3116
* @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
+ − 3117
*/
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
+ − 3118
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
+ − 3119
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
+ − 3120
{
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
+ − 3121
$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
+ − 3122
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
+ − 3123
// 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
+ − 3124
$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
+ − 3125
125
+ − 3126
// Which tags to strip for JAVASCRIPT PROCESSING ONLY - you can change this if needed
+ − 3127
$strip_tags = Array('enano:no-opt');
+ − 3128
$strip_tags = implode('|', $strip_tags);
+ − 3129
+ − 3130
// Strip out the tags and replace with placeholders
183
91127e62f38f
Fixed some regular expressions in HTML optimization algorithm; regex page groups can be edited now (oops)
Dan
diff
changeset
+ − 3131
preg_match_all("#<($strip_tags)([ ]+.*?)?>(.*?)</($strip_tags)>#is", $html, $matches);
125
+ − 3132
$seed = md5(microtime() . mt_rand()); // Random value used for placeholders
+ − 3133
for ($i = 0;$i < sizeof($matches[1]); $i++)
+ − 3134
{
+ − 3135
$html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
+ − 3136
}
+ − 3137
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
+ − 3138
// Optimize (but don't obfuscate) Javascript
184
+ − 3139
preg_match_all('/<script([ ]+.*?)?>(.*?)(\]\]>)?<\/script>/is', $html, $jscript);
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 3140
require_once(ENANO_ROOT . '/includes/js-compressor.php');
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 3141
$jsc = new JavascriptCompressor();
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
+ − 3142
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
+ − 3143
// 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
+ − 3144
$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
+ − 3145
'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
+ − 3146
'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
+ − 3147
'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
+ − 3148
'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
+ − 3149
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
+ − 3150
$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
+ − 3151
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
+ − 3152
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
+ − 3153
{
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
+ − 3154
$js =& $jscript[2][$i];
582
+ − 3155
if ( empty($js) )
+ − 3156
continue;
183
91127e62f38f
Fixed some regular expressions in HTML optimization algorithm; regex page groups can be edited now (oops)
Dan
diff
changeset
+ − 3157
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 3158
$js = $jsc->getClean($js);
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
+ − 3159
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
+ − 3160
$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
+ − 3161
// 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
+ − 3162
$html = str_replace($jscript[0][$i], $replacement, $html);
562
75df0b2c596c
Got initial CSRF token framework implemented and sample implementation added in Special:Logout; removing Javascript compression engine from aggressive_optimize_html() and instead calling JavascriptCompressor class from js-compressor.php
Dan
diff
changeset
+ − 3163
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
+ − 3164
}
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
+ − 3165
125
+ − 3166
// Re-insert untouchable tags
+ − 3167
for ($i = 0;$i < sizeof($matches[1]); $i++)
+ − 3168
{
+ − 3169
$html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
+ − 3170
}
+ − 3171
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
+ − 3172
// Which tags to strip - you can change this if needed
137
+ − 3173
$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
+ − 3174
$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
+ − 3175
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
+ − 3176
// 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
+ − 3177
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
+ − 3178
$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
+ − 3179
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
+ − 3180
{
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
+ − 3181
$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
+ − 3182
}
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
+ − 3183
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
+ − 3184
// 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
+ − 3185
$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
+ − 3186
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
+ − 3187
// 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
+ − 3188
$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
+ − 3189
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
+ − 3190
// 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
+ − 3191
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
+ − 3192
{
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
+ − 3193
$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
+ − 3194
}
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
+ − 3195
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
+ − 3196
// 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
+ − 3197
$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
+ − 3198
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
+ − 3199
$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
+ − 3200
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
+ − 3201
// 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
+ − 3202
$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
+ − 3203
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
+ − 3204
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
+ − 3205
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
+ − 3206
-->\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
+ − 3207
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
+ − 3208
}
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
+ − 3209
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
+ − 3210
/**
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
+ − 3211
* 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
+ − 3212
* @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
+ − 3213
* @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
+ − 3214
*/
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
+ − 3215
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
+ − 3216
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
+ − 3217
{
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
+ − 3218
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
+ − 3219
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
+ − 3220
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
+ − 3221
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
+ − 3222
$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
+ − 3223
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
+ − 3224
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
+ − 3225
$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
+ − 3226
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
+ − 3227
$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
+ − 3228
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
+ − 3229
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
+ − 3230
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
+ − 3231
{
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
+ − 3232
$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
+ − 3233
}
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
+ − 3234
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
+ − 3235
}
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
+ − 3236
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
+ − 3237
/**
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
+ − 3238
* 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
+ − 3239
* 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
+ − 3240
* @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
+ − 3241
* @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
+ − 3242
*/
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
+ − 3243
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
+ − 3244
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
+ − 3245
{
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
+ − 3246
$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
+ − 3247
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
+ − 3248
// 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
+ − 3249
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
+ − 3250
$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
+ − 3251
$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
+ − 3252
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
+ − 3253
{
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
+ − 3254
$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
+ − 3255
$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
+ − 3256
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
+ − 3257
{
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
+ − 3258
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
+ − 3259
{
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
+ − 3260
$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
+ − 3261
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
+ − 3262
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
+ − 3263
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
+ − 3264
$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
+ − 3265
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
+ − 3266
$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
+ − 3267
}
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
+ − 3268
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
+ − 3269
{
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
+ − 3270
$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
+ − 3271
$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
+ − 3272
}
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
+ − 3273
}
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
+ − 3274
$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
+ − 3275
$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
+ − 3276
}
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
+ − 3277
$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
+ − 3278
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
+ − 3279
// 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
+ − 3280
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
+ − 3281
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
+ − 3282
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
+ − 3283
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
+ − 3284
$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
+ − 3285
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
+ − 3286
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
+ − 3287
}
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
+ − 3288
270
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3289
/**
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3290
* 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
+ − 3291
* @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
+ − 3292
* @return string
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3293
*/
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3294
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3295
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
+ − 3296
{
766
+ − 3297
if ( strstr($range, ':') )
+ − 3298
{
+ − 3299
return parse_ipv6_range_regex($range);
+ − 3300
}
+ − 3301
else
+ − 3302
{
+ − 3303
return parse_ipv4_range_regex($range);
+ − 3304
}
+ − 3305
}
+ − 3306
+ − 3307
/**
+ − 3308
* Parses a valid IPv4 address range into a regular expression.
+ − 3309
* @param string IP range string
+ − 3310
* @return string
+ − 3311
*/
+ − 3312
+ − 3313
function parse_ipv4_range_regex($range)
+ − 3314
{
270
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3315
// 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
+ − 3316
$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
+ − 3317
. '(([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
+ − 3318
. '(([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
+ − 3319
. '(([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
+ − 3320
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
+ − 3321
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3322
return false;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3323
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3324
$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
+ − 3325
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
+ − 3326
$return = '^';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3327
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
+ − 3328
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3329
// alternatives array
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3330
$alts = array();
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3331
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
+ − 3332
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3333
$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
+ − 3334
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3335
else
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3336
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3337
$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
+ − 3338
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3339
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
+ − 3340
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3341
// 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
+ − 3342
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
+ − 3343
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3344
$alts[] = $atom;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3345
continue;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3346
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3347
else
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3348
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3349
// 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
+ − 3350
$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
+ − 3351
if ( !$alt2 )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3352
return false;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3353
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
+ − 3354
$alts[] = $neutrino;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3355
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3356
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3357
$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
+ − 3358
$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
+ − 3359
// 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
+ − 3360
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
+ − 3361
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3362
$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
+ − 3363
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3364
$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
+ − 3365
$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
+ − 3366
$return .= $alts . '\.';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3367
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3368
$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
+ − 3369
$return .= '$';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3370
return $return;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3371
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3372
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3373
/**
766
+ − 3374
* Parses a valid IPv6 address range into a regular expression.
+ − 3375
* @param string IP range string
+ − 3376
* @return string
+ − 3377
*/
+ − 3378
+ − 3379
function parse_ipv6_range_regex($range)
+ − 3380
{
+ − 3381
$range = strtolower(trim($range));
+ − 3382
$valid = '/^';
+ − 3383
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}):';
+ − 3384
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}):';
+ − 3385
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3386
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3387
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3388
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3389
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3390
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4})$/';
+ − 3391
if ( !preg_match($valid, $range) )
+ − 3392
return false;
+ − 3393
+ − 3394
// expand address range.
+ − 3395
// this takes short ranges like:
+ − 3396
// 2001:470-471:054-b02b::5-bb
+ − 3397
// up to:
+ − 3398
// 2001:0470-0471:0054-b02b:0000:0000:0000:0005-00bb
+ − 3399
$range = explode(':', $range);
+ − 3400
$expanded = '';
+ − 3401
$size = count($range);
+ − 3402
foreach ( $range as $byteset )
+ − 3403
{
+ − 3404
if ( empty($byteset) )
+ − 3405
{
+ − 3406
// ::
+ − 3407
while ( $size < 9 )
+ − 3408
{
+ − 3409
$expanded .= '0000:';
+ − 3410
$size++;
+ − 3411
}
+ − 3412
}
+ − 3413
else
+ − 3414
{
+ − 3415
if ( strstr($byteset, '-') )
+ − 3416
{
+ − 3417
// this is a range
+ − 3418
$sides = explode('-', $byteset);
+ − 3419
foreach ( $sides as &$bytepair )
+ − 3420
{
+ − 3421
while ( strlen($bytepair) < 4 )
+ − 3422
{
+ − 3423
$bytepair = "0$bytepair";
+ − 3424
}
+ − 3425
}
+ − 3426
$byteset = implode('-', $sides);
+ − 3427
}
+ − 3428
else
+ − 3429
{
+ − 3430
while ( strlen($byteset) < 4 )
+ − 3431
{
+ − 3432
$byteset = "0$byteset";
+ − 3433
}
+ − 3434
}
+ − 3435
$expanded .= "$byteset:";
+ − 3436
}
+ − 3437
}
+ − 3438
$expanded = explode(':', rtrim($expanded, ':'));
+ − 3439
+ − 3440
// ready to dive in and start generating range regexes.
+ − 3441
// this has to be pretty optimized... we want to end up with regexes like:
+ − 3442
// range: 54-b12b
+ − 3443
/*
+ − 3444
/005[4-9a-f]|
+ − 3445
00[6-9a-f][0-9a-f]|
+ − 3446
0[1-9a-f][0-9a-f][0-9a-f]|
+ − 3447
[1-9a][0-9a-f][0-9a-f][0-9a-f]|
+ − 3448
b[0-0][0-1][0-9a-f]|
+ − 3449
b0[0-1][0-9a-f]|
+ − 3450
b02[0-9a-b]/x
+ − 3451
*/
+ − 3452
foreach ( $expanded as &$word )
+ − 3453
{
+ − 3454
if ( strstr($word, '-') )
+ − 3455
{
+ − 3456
// oh... damn.
+ − 3457
$word = '(?:' . generate_hex_numeral_range($word) . ')';
+ − 3458
}
+ − 3459
}
+ − 3460
+ − 3461
// return print_r($expanded, true);
+ − 3462
return '^' . implode(':', $expanded) . '$';
+ − 3463
}
+ − 3464
+ − 3465
/**
+ − 3466
* Take a hex numeral range and parse it in to a PCRE.
+ − 3467
* @param string
+ − 3468
* @return string
+ − 3469
* @access private
+ − 3470
*/
+ − 3471
+ − 3472
function generate_hex_numeral_range($word)
+ − 3473
{
+ − 3474
list($low, $high) = explode('-', $word);
+ − 3475
+ − 3476
if ( hexdec($low) > hexdec($high) )
+ − 3477
{
+ − 3478
$_ = $low;
+ − 3479
$low = $high;
+ − 3480
$high = $_;
+ − 3481
unset($_);
+ − 3482
}
+ − 3483
+ − 3484
while ( strlen($low) < strlen($high) )
+ − 3485
{
+ − 3486
$low = "0$low";
+ − 3487
}
+ − 3488
+ − 3489
// trim off everything that's the same
+ − 3490
$trimmed = '';
+ − 3491
$len = strlen($low);
+ − 3492
for ( $i = 0; $i < $len; $i++ )
+ − 3493
{
+ − 3494
if ( $low{0} === $high{0} )
+ − 3495
{
+ − 3496
$trimmed .= $low{0};
+ − 3497
$low = substr($low, 1);
+ − 3498
$high = substr($high, 1);
+ − 3499
}
+ − 3500
else
+ − 3501
{
+ − 3502
break;
+ − 3503
}
+ − 3504
}
+ − 3505
+ − 3506
$len = strlen($high);
+ − 3507
if ( $len == 1 )
+ − 3508
{
+ − 3509
// this does happen sometimes, so we can save a bit of CPU power here.
+ − 3510
return $trimmed . __hexdigitrange($low, $high);
+ − 3511
}
+ − 3512
+ − 3513
$return = '';
+ − 3514
// lower half
+ − 3515
for ( $i = $len - 1; $i > 0; $i-- )
+ − 3516
{
+ − 3517
if ( $low{$i} == 'f' )
+ − 3518
continue;
+ − 3519
$return .= $trimmed;
+ − 3520
for ( $j = 0; $j < $len; $j++ )
+ − 3521
{
+ − 3522
if ( $j < $i )
+ − 3523
{
+ − 3524
$return .= $low{$j};
+ − 3525
}
+ − 3526
else if ( $j == $i && ( $i == $len - 1 || $low{$j} == 'f' ) )
+ − 3527
{
+ − 3528
$return .= __hexdigitrange($low{$j}, 'f');
+ − 3529
}
+ − 3530
else if ( $j == $i && $i != $len - 1 )
+ − 3531
{
+ − 3532
$return .= __hexdigitrange(dechex(hexdec($low{$j}) + 1), 'f');
+ − 3533
}
+ − 3534
else
+ − 3535
{
+ − 3536
$return .= __hexdigitrange('0', 'f');
+ − 3537
}
+ − 3538
}
+ − 3539
$return .= '|';
+ − 3540
}
+ − 3541
// middle block
+ − 3542
if ( hexdec($low{0}) + 1 < hexdec($high{0}) )
+ − 3543
{
+ − 3544
if ( hexdec($low{0}) + 1 < hexdec($high{0}) - 1 )
+ − 3545
$return .= $trimmed . __hexdigitrange(dechex(hexdec($low{0}) + 1), dechex(hexdec($high{0}) - 1));
+ − 3546
else
+ − 3547
$return .= $trimmed . __hexdigitrange($low{0}, $high{0});
+ − 3548
if ( $len - 1 > 0 )
+ − 3549
$return .= '[0-9a-f]{' . ( $len - 1 ) . '}|';
+ − 3550
}
+ − 3551
// higher half
+ − 3552
for ( $i = 1; $i < $len; $i++ )
+ − 3553
{
+ − 3554
if ( $high{$i} == '0' )
+ − 3555
continue;
+ − 3556
$return .= $trimmed;
+ − 3557
for ( $j = 0; $j < $len; $j++ )
+ − 3558
{
+ − 3559
if ( $j < $i )
+ − 3560
{
+ − 3561
$return .= $high{$j};
+ − 3562
}
+ − 3563
else if ( $j == $i && ( $i == $len - 1 || $high{$j} == '0' ) )
+ − 3564
{
+ − 3565
$return .= __hexdigitrange('0', $high{$j});
+ − 3566
}
+ − 3567
else if ( $j == $i && $i != $len - 1 )
+ − 3568
{
+ − 3569
$return .= __hexdigitrange('0', dechex(hexdec($high{$j}) - 1));
+ − 3570
}
+ − 3571
else if ( $j > $i )
+ − 3572
{
+ − 3573
$return .= __hexdigitrange('0', 'f');
+ − 3574
}
+ − 3575
else
+ − 3576
{
+ − 3577
die("I don't know what to do! i $i j $j");
+ − 3578
}
+ − 3579
}
+ − 3580
$return .= '|';
+ − 3581
}
+ − 3582
+ − 3583
return rtrim($return, '|');
+ − 3584
}
+ − 3585
+ − 3586
function __hexdigitrange($low, $high)
+ − 3587
{
+ − 3588
if ( $low == $high )
+ − 3589
return $low;
+ − 3590
if ( empty($low) )
+ − 3591
$low = '0';
+ − 3592
+ − 3593
$low_type = ( preg_match('/[0-9]/', $low) ) ? 'num' : 'alph';
+ − 3594
$high_type = ( preg_match('/[0-9]/', $high) ) ? 'num' : 'alph';
+ − 3595
if ( ( $low_type == 'num' && $high_type == 'num') || ( $low_type == 'alph' && $high_type == 'alph' ) )
+ − 3596
{
+ − 3597
return "[$low-$high]";
+ − 3598
}
+ − 3599
else if ( $low_type == 'num' && $high_type == 'alph' )
+ − 3600
{
+ − 3601
$ret = '[';
+ − 3602
+ − 3603
if ( $low == '9' )
+ − 3604
$ret .= '9';
+ − 3605
else
+ − 3606
$ret .= "$low-9";
+ − 3607
if ( $high == 'a' )
+ − 3608
$ret .= 'a';
+ − 3609
else
+ − 3610
$ret .= "a-$high";
+ − 3611
+ − 3612
$ret .= "]";
+ − 3613
return $ret;
+ − 3614
}
+ − 3615
else if ( $low_type == 'alph' && $high_type == 'num' )
+ − 3616
{
+ − 3617
// ???? this should never happen
+ − 3618
return __hexdigitrange($high, $low);
+ − 3619
}
+ − 3620
}
+ − 3621
+ − 3622
/**
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3623
* Validates an e-mail address. Uses a compacted version of the regular expression generated by the scripts at <http://examples.oreilly.com/regex/>.
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3624
* @param string E-mail address
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3625
* @return bool
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3626
*/
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3627
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3628
function check_email_address($email)
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3629
{
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3630
static $regexp = '(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*|(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*(?:(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[^()<>@,;:".\\\[\]\x80-\xff\000-\010\012-\037]*)*<[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*(?:,[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*)*:[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)?(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*@[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:\.[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*)*>)';
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3631
return ( preg_match("/^$regexp$/", $email) ) ? true : false;
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3632
}
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3633
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3634
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
+ − 3635
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3636
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
+ − 3637
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3638
return -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3639
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3640
$len = strlen($password);
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3641
$score = $len - 7;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3642
return $score;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3643
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3644
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3645
/**
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3646
* 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
+ − 3647
* 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
+ − 3648
* 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
+ − 3649
* @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
+ − 3650
* @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
+ − 3651
* @return int
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3652
*/
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3653
472
bc4b58034f4d
Implemented password reset (albeit hackishly) into the new login API; added dummy window.console object to hopefully reduce errors when Firebug isn't around; fixed the longstanding ACL dismiss/close button bug; fixed a couple undefined variables in mailer; fixed PHP error on attempted opening of /dev/(u)random in rijndael.php; clarified documentation for PageProcessor::update_page(); fixed some logic problems in theme ACL code; disabled CAPTCHA debug
Dan
diff
changeset
+ − 3654
function password_score($password, &$debug = false)
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3655
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3656
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
+ − 3657
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3658
return -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3659
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3660
$score = 0;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3661
$debug = array();
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3662
// length check
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3663
$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
+ − 3664
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3665
$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
+ − 3666
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3667
$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
+ − 3668
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3669
$score += $lenscore;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3670
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3671
$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
+ − 3672
$has_symbols = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3673
$has_numbers = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3674
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3675
// 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
+ − 3676
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
+ − 3677
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3678
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3679
$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
+ − 3680
$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
+ − 3681
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3682
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3683
// contains symbols
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3684
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
+ − 3685
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3686
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3687
$has_symbols = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3688
$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
+ − 3689
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3690
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3691
// contains numbers
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3692
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
+ − 3693
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3694
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3695
$has_numbers = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3696
$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
+ − 3697
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3698
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3699
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
+ − 3700
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3701
// 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
+ − 3702
$score += 4;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3703
$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
+ − 3704
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3705
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
+ − 3706
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3707
// 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
+ − 3708
$score += 2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3709
$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
+ − 3710
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3711
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
+ − 3712
( $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
+ − 3713
( $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
+ − 3714
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3715
// 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
+ − 3716
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3717
$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
+ − 3718
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3719
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
+ − 3720
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3721
// 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
+ − 3722
$score += -4;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3723
$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
+ − 3724
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3725
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
+ − 3726
( !$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
+ − 3727
( !$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
+ − 3728
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3729
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3730
$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
+ − 3731
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3732
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
+ − 3733
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3734
$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
+ − 3735
$score += -3;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3736
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3737
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3738
//
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3739
// Repetition
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3740
// 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
+ − 3741
//
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3742
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3743
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
+ − 3744
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3745
$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
+ − 3746
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3747
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3748
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
+ − 3749
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3750
$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
+ − 3751
$score += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3752
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3753
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
+ − 3754
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3755
$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
+ − 3756
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3757
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3758
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3759
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
+ − 3760
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3761
$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
+ − 3762
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3763
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3764
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
+ − 3765
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3766
$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
+ − 3767
$score += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3768
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3769
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
+ − 3770
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3771
$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
+ − 3772
$score += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3773
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3774
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3775
// 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
+ − 3776
$prev_char = '';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3777
$warn = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3778
$loss = 0;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3779
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
+ − 3780
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3781
$chr = $password{$i};
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3782
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
+ − 3783
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3784
$loss += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3785
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3786
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
+ − 3787
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3788
$warn = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3789
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3790
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
+ − 3791
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3792
$warn = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3793
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3794
$prev_char = $chr;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3795
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3796
if ( $loss < 0 )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3797
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3798
$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
+ − 3799
$score += $loss;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3800
// 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
+ − 3801
if ( $score < -10 )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3802
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3803
$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
+ − 3804
$score = -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3805
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3806
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3807
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3808
return $score;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3809
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3810
191
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3811
/**
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3812
* 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
+ − 3813
* @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
+ − 3814
* @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
+ − 3815
*/
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3816
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3817
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
+ − 3818
{
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3819
global $cron_tasks;
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 3820
$hour_interval = strval($hour_interval);
191
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3821
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
+ − 3822
$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
+ − 3823
$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
+ − 3824
}
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3825
230
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
+ − 3826
/**
542
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3827
* Gets the timestamp for the next estimated cron run.
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3828
* @return int
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3829
*/
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3830
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3831
function get_cron_next_run()
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3832
{
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3833
global $cron_tasks;
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3834
$lowest_ivl = min(array_keys($cron_tasks));
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3835
$last_run = intval(getConfig("cron_lastrun_ivl_$lowest_ivl"));
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3836
return intval($last_run + ( 3600 * $lowest_ivl )) - 30;
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3837
}
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3838
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3839
/**
209
+ − 3840
* Installs a language.
+ − 3841
* @param string The ISO-639-3 identifier for the language. Maximum of 6 characters, usually 3.
+ − 3842
* @param string The name of the language in English (Spanish)
+ − 3843
* @param string The name of the language natively (Español)
+ − 3844
* @param string The path to the file containing the language's strings. Optional.
191
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3845
*/
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3846
209
+ − 3847
function install_language($lang_code, $lang_name_neutral, $lang_name_local, $lang_file = false)
191
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3848
{
209
+ − 3849
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 3850
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3851
$q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = \'' . $db->escape($lang_code) . '\';');
209
+ − 3852
if ( !$q )
+ − 3853
$db->_die('functions.php - checking for language existence');
+ − 3854
+ − 3855
if ( $db->numrows() > 0 )
+ − 3856
// Language already exists
+ − 3857
return false;
+ − 3858
+ − 3859
$q = $db->sql_query('INSERT INTO ' . table_prefix . 'language(lang_code, lang_name_default, lang_name_native)
+ − 3860
VALUES(
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3861
\'' . $db->escape($lang_code) . '\',
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3862
\'' . $db->escape($lang_name_neutral) . '\',
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3863
\'' . $db->escape($lang_name_local) . '\'
209
+ − 3864
);');
+ − 3865
if ( !$q )
+ − 3866
$db->_die('functions.php - installing language');
+ − 3867
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3868
if ( ENANO_DBLAYER == 'PGSQL' )
241
c671f3bb8aed
Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
diff
changeset
+ − 3869
{
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3870
// exception for Postgres, which doesn't support insert IDs
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3871
// This will cause the Language class to just load by lang code
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3872
// instead of by numeric ID
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3873
$lang_id = $lang_code;
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3874
}
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3875
else
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3876
{
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3877
$lang_id = $db->insert_id();
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3878
if ( empty($lang_id) || $lang_id == 0 )
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3879
{
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3880
$db->_die('functions.php - invalid returned lang_id');
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3881
}
241
c671f3bb8aed
Trying to get lang import to work in the installer; it's not working ATM - cache file is generated with lang_id = 0. Syncing to Nighthawk.
Dan
diff
changeset
+ − 3882
}
209
+ − 3883
+ − 3884
// Do we also need to install a language file?
+ − 3885
if ( is_string($lang_file) && file_exists($lang_file) )
+ − 3886
{
+ − 3887
$lang = new Language($lang_id);
+ − 3888
$lang->import($lang_file);
+ − 3889
}
+ − 3890
else if ( is_string($lang_file) && !file_exists($lang_file) )
+ − 3891
{
+ − 3892
echo '<b>Notice:</b> Can\'t load language file, so the specified language wasn\'t fully installed.<br />';
+ − 3893
return false;
+ − 3894
}
+ − 3895
return true;
191
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3896
}
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3897
230
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
+ − 3898
/**
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3899
* Lists available languages.
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3900
* @return array Multi-depth. Associative, with children associative containing keys name, name_eng, and dir.
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3901
*/
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3902
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3903
function list_available_languages()
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3904
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3905
// Pulled from install/includes/common.php
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3906
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3907
// Build a list of available languages
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3908
$dir = @opendir( ENANO_ROOT . '/language' );
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3909
if ( !$dir )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3910
die('CRITICAL: could not open language directory');
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3911
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3912
$languages = array();
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3913
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3914
while ( $dh = @readdir($dir) )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3915
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3916
if ( $dh == '.' || $dh == '..' )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3917
continue;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3918
if ( file_exists( ENANO_ROOT . "/language/$dh/meta.json" ) )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3919
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3920
// Found a language directory, determine metadata
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3921
$meta = @file_get_contents( ENANO_ROOT . "/language/$dh/meta.json" );
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3922
if ( empty($meta) )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3923
// Could not read metadata file, continue silently
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3924
continue;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3925
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3926
// Do some syntax correction on the metadata
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3927
$meta = enano_clean_json($meta);
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3928
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3929
$meta = enano_json_decode($meta);
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3930
if ( isset($meta['lang_name_english']) && isset($meta['lang_name_native']) && isset($meta['lang_code']) )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3931
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3932
$languages[$meta['lang_code']] = array(
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3933
'name' => $meta['lang_name_native'],
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3934
'name_eng' => $meta['lang_name_english'],
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3935
'dir' => $dh
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3936
);
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3937
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3938
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3939
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3940
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3941
return $languages;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3942
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3943
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 3944
/**
230
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
+ − 3945
* 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
+ − 3946
* 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
+ − 3947
* 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
+ − 3948
* @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
+ − 3949
* @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
+ − 3950
* @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
+ − 3951
* @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
+ − 3952
* @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
+ − 3953
* @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
+ − 3954
*/
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
+ − 3955
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
+ − 3956
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
+ − 3957
{
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
+ − 3958
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
+ − 3959
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
+ − 3960
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
+ − 3961
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
+ − 3962
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
+ − 3963
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
+ − 3964
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
+ − 3965
720
e2762777b170
Fixed attempt at gzip compression after headers sent; hopefully safely escape args to scale_image() instead of erroring out
Dan
diff
changeset
+ − 3966
$in_file = escapeshellarg($in_file);
e2762777b170
Fixed attempt at gzip compression after headers sent; hopefully safely escape args to scale_image() instead of erroring out
Dan
diff
changeset
+ − 3967
$out_file = escapeshellarg($out_file);
230
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
+ − 3968
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
+ − 3969
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
+ − 3970
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
+ − 3971
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
+ − 3972
@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
+ − 3973
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
+ − 3974
// 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
+ − 3975
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
+ − 3976
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
+ − 3977
$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
+ − 3978
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
+ − 3979
{
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
+ − 3980
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
+ − 3981
$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
+ − 3982
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
+ − 3983
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
+ − 3984
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
+ − 3985
$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
+ − 3986
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
+ − 3987
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
+ − 3988
$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
+ − 3989
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
+ − 3990
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
+ − 3991
$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
+ − 3992
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
+ − 3993
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
+ − 3994
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
+ − 3995
}
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
+ − 3996
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
+ − 3997
$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
+ − 3998
$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
+ − 3999
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
+ − 4000
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
+ − 4001
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
+ − 4002
);
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
+ − 4003
$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
+ − 4004
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
+ − 4005
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
+ − 4006
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
+ − 4007
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
+ − 4008
);
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
+ − 4009
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
+ − 4010
{
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
+ − 4011
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
+ − 4012
{
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
+ − 4013
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
+ − 4014
}
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
+ − 4015
$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
+ − 4016
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
+ − 4017
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
+ − 4018
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
+ − 4019
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
+ − 4020
}
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
+ − 4021
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
+ − 4022
{
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
+ − 4023
@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
+ − 4024
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
+ − 4025
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
+ − 4026
// 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
+ − 4027
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
+ − 4028
$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
+ − 4029
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
+ − 4030
{
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
+ − 4031
// 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
+ − 4032
$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
+ − 4033
$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
+ − 4034
}
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
+ − 4035
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
+ − 4036
{
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
+ − 4037
// 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
+ − 4038
$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
+ − 4039
$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
+ − 4040
}
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
+ − 4041
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
+ − 4042
{
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
+ − 4043
$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
+ − 4044
$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
+ − 4045
}
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
+ − 4046
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
+ − 4047
{
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
+ − 4048
// 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
+ − 4049
$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
+ − 4050
$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
+ − 4051
}
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
+ − 4052
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
+ − 4053
$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
+ − 4054
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
+ − 4055
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
+ − 4056
$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
+ − 4057
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
+ − 4058
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
+ − 4059
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
+ − 4060
// 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
+ − 4061
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
+ − 4062
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
+ − 4063
// 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
+ − 4064
$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
+ − 4065
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
+ − 4066
{
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
+ − 4067
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
+ − 4068
$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
+ − 4069
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
+ − 4070
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
+ − 4071
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
+ − 4072
$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
+ − 4073
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
+ − 4074
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
+ − 4075
$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
+ − 4076
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
+ − 4077
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
+ − 4078
$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
+ − 4079
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
+ − 4080
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
+ − 4081
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
+ − 4082
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
+ − 4083
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
+ − 4084
}
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
+ − 4085
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
+ − 4086
// 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
+ − 4087
$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
+ − 4088
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
+ − 4089
// 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
+ − 4090
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
+ − 4091
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
+ − 4092
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
+ − 4093
// 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
+ − 4094
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
+ − 4095
}
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
+ − 4096
// 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
+ − 4097
$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
+ − 4098
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
+ − 4099
{
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
+ − 4100
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
+ − 4101
}
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
+ − 4102
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
+ − 4103
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
+ − 4104
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
+ − 4105
}
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
+ − 4106
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4107
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4108
* Determines whether a GIF file is animated or not. Credit goes to ZeBadger from <http://www.php.net/imagecreatefromgif>.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4109
* Modified to conform to Enano coding standards.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4110
* @param string Path to GIF file
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4111
* @return bool If animated, returns true
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4112
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4113
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4114
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4115
function is_gif_animated($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4116
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4117
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4118
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4119
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4120
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4121
$str_loc = 0;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4122
$count = 0;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4123
while ( $count < 2 ) // There is no point in continuing after we find a 2nd frame
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4124
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4125
$where1 = strpos($filecontents,"\x00\x21\xF9\x04", $str_loc);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4126
if ( $where1 === false )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4127
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4128
break;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4129
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4130
else
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4131
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4132
$str_loc = $where1 + 1;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4133
$where2 = strpos($filecontents,"\x00\x2C", $str_loc);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4134
if ( $where2 === false )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4135
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4136
break;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4137
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4138
else
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4139
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4140
if ( $where1 + 8 == $where2 )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4141
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4142
$count++;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4143
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4144
$str_loc = $where2 + 1;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4145
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4146
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4147
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4148
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4149
return ( $count > 1 ) ? true : false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4150
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4151
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4152
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4153
* Retrieves the dimensions of a GIF image.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4154
* @param string The path to the GIF file.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4155
* @return array Key 0 is width, key 1 is height
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4156
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4157
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4158
function gif_get_dimensions($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4159
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4160
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4161
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4162
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4163
if ( strlen($filecontents) < 10 )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4164
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4165
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4166
$width = substr($filecontents, 6, 2);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4167
$height = substr($filecontents, 8, 2);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4168
$width = unpack('v', $width);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4169
$height = unpack('v', $height);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4170
return array($width[1], $height[1]);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4171
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4172
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4173
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4174
* Determines whether a PNG image is animated or not. Based on some specification information from <http://wiki.mozilla.org/APNG_Specification>.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4175
* @param string Path to PNG file.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4176
* @return bool If animated, returns true
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4177
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4178
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4179
function is_png_animated($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4180
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4181
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4182
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4183
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4184
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4185
$parsed = parse_png($filecontents);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4186
if ( !$parsed )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4187
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4188
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4189
if ( !isset($parsed['fdAT']) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4190
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4191
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4192
if ( count($parsed['fdAT']) > 1 )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4193
return true;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4194
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4195
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4196
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4197
* Gets the dimensions of a PNG image.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4198
* @param string Path to PNG file
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4199
* @return array Key 0 is width, key 1 is length.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4200
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4201
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4202
function png_get_dimensions($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4203
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4204
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4205
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4206
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4207
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4208
$parsed = parse_png($filecontents);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4209
if ( !$parsed )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4210
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4211
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4212
$ihdr_stream = $parsed['IHDR'][0];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4213
$width = substr($ihdr_stream, 0, 4);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4214
$height = substr($ihdr_stream, 4, 4);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4215
$width = unpack('N', $width);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4216
$height = unpack('N', $height);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4217
$x = $width[1];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4218
$y = $height[1];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4219
return array($x, $y);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4220
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4221
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4222
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4223
* Internal function to parse out the streams of a PNG file. Based on the W3 PNG spec: http://www.w3.org/TR/PNG/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4224
* @param string The contents of the PNG
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4225
* @return array Associative array containing the streams
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4226
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4227
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4228
function parse_png($data)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4229
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4230
// Trim off first 8 bytes to check for PNG header
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4231
$header = substr($data, 0, 8);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4232
if ( $header != "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4233
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4234
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4235
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4236
$return = array();
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4237
$data = substr($data, 8);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4238
while ( strlen($data) > 0 )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4239
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4240
$chunklen_bin = substr($data, 0, 4);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4241
$chunk_type = substr($data, 4, 4);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4242
$chunklen = unpack('N', $chunklen_bin);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4243
$chunklen = $chunklen[1];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4244
$chunk_data = substr($data, 8, $chunklen);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4245
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4246
// If the chunk type is not valid, this may be a malicious PNG with bad offsets. Break out of the loop.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4247
if ( !preg_match('/^[A-z]{4}$/', $chunk_type) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4248
break;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4249
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4250
if ( !isset($return[$chunk_type]) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4251
$return[$chunk_type] = array();
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4252
$return[$chunk_type][] = $chunk_data;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4253
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4254
$offset_next = 4 // Length
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4255
+ 4 // Type
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4256
+ $chunklen // Data
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4257
+ 4; // CRC
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4258
$data = substr($data, $offset_next);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4259
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4260
return $return;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4261
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4262
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4263
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4264
* Retreives information about the intrinsic characteristics of the jpeg image, such as Bits per Component, Height and Width. This function is from the PHP JPEG Metadata Toolkit. Licensed under the GPLv2 or later.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4265
* @param array The JPEG header data, as retrieved from the get_jpeg_header_data function
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4266
* @return array An array containing the intrinsic JPEG values FALSE - if the comment segment couldnt be found
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4267
* @license GNU General Public License
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4268
* @copyright Copyright Evan Hunter 2004
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4269
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4270
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4271
function get_jpeg_intrinsic_values( $jpeg_header_data )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4272
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4273
// Create a blank array for the output
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4274
$Outputarray = array( );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4275
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4276
//Cycle through the header segments until Start Of Frame (SOF) is found or we run out of segments
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4277
$i = 0;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4278
while ( ( $i < count( $jpeg_header_data) ) && ( substr( $jpeg_header_data[$i]['SegName'], 0, 3 ) != "SOF" ) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4279
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4280
$i++;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4281
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4282
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4283
// Check if a SOF segment has been found
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4284
if ( substr( $jpeg_header_data[$i]['SegName'], 0, 3 ) == "SOF" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4285
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4286
// SOF segment was found, extract the information
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4287
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4288
$data = $jpeg_header_data[$i]['SegData'];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4289
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4290
// First byte is Bits per component
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4291
$Outputarray['Bits per Component'] = ord( $data{0} );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4292
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4293
// Second and third bytes are Image Height
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4294
$Outputarray['Image Height'] = ord( $data{ 1 } ) * 256 + ord( $data{ 2 } );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4295
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4296
// Forth and fifth bytes are Image Width
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4297
$Outputarray['Image Width'] = ord( $data{ 3 } ) * 256 + ord( $data{ 4 } );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4298
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4299
// Sixth byte is number of components
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4300
$numcomponents = ord( $data{ 5 } );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4301
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4302
// Following this is a table containing information about the components
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4303
for( $i = 0; $i < $numcomponents; $i++ )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4304
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4305
$Outputarray['Components'][] = array ( 'Component Identifier' => ord( $data{ 6 + $i * 3 } ),
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4306
'Horizontal Sampling Factor' => ( ord( $data{ 7 + $i * 3 } ) & 0xF0 ) / 16,
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4307
'Vertical Sampling Factor' => ( ord( $data{ 7 + $i * 3 } ) & 0x0F ),
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4308
'Quantization table destination selector' => ord( $data{ 8 + $i * 3 } ) );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4309
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4310
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4311
else
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4312
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4313
// Couldn't find Start Of Frame segment, hence can't retrieve info
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4314
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4315
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4316
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4317
return $Outputarray;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4318
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4319
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4320
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4321
* Reads all the JPEG header segments from an JPEG image file into an array. This function is from the PHP JPEG Metadata Toolkit. Licensed under the GPLv2 or later. Modified slightly for Enano coding standards and to remove unneeded capability.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4322
* @param string the filename of the file to JPEG file to read
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4323
* @return string Array of JPEG header segments, or FALSE - if headers could not be read
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4324
* @license GNU General Public License
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4325
* @copyright Copyright Evan Hunter 2004
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4326
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4327
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4328
function get_jpeg_header_data( $filename )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4329
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4330
// Attempt to open the jpeg file - the at symbol supresses the error message about
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4331
// not being able to open files. The file_exists would have been used, but it
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4332
// does not work with files fetched over http or ftp.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4333
$filehnd = @fopen($filename, 'rb');
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4334
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4335
// Check if the file opened successfully
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4336
if ( ! $filehnd )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4337
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4338
// Could't open the file - exit
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4339
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4340
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4341
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4342
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4343
// Read the first two characters
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4344
$data = fread( $filehnd, 2 );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4345
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4346
// Check that the first two characters are 0xFF 0xDA (SOI - Start of image)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4347
if ( $data != "\xFF\xD8" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4348
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4349
// No SOI (FF D8) at start of file - This probably isn't a JPEG file - close file and return;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4350
fclose($filehnd);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4351
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4352
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4353
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4354
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4355
// Read the third character
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4356
$data = fread( $filehnd, 2 );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4357
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4358
// Check that the third character is 0xFF (Start of first segment header)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4359
if ( $data{0} != "\xFF" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4360
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4361
// NO FF found - close file and return - JPEG is probably corrupted
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4362
fclose($filehnd);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4363
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4364
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4365
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4366
// Flag that we havent yet hit the compressed image data
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4367
$hit_compressed_image_data = FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4368
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4369
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4370
// Cycle through the file until, one of: 1) an EOI (End of image) marker is hit,
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4371
// 2) we have hit the compressed image data (no more headers are allowed after data)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4372
// 3) or end of file is hit
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4373
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4374
while ( ( $data{1} != "\xD9" ) && (! $hit_compressed_image_data) && ( ! feof( $filehnd ) ))
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4375
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4376
// Found a segment to look at.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4377
// Check that the segment marker is not a Restart marker - restart markers don't have size or data after them
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4378
if ( ( ord($data{1}) < 0xD0 ) || ( ord($data{1}) > 0xD7 ) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4379
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4380
// Segment isn't a Restart marker
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4381
// Read the next two bytes (size)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4382
$sizestr = fread( $filehnd, 2 );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4383
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4384
// convert the size bytes to an integer
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4385
$decodedsize = unpack ("nsize", $sizestr);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4386
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4387
// Save the start position of the data
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4388
$segdatastart = ftell( $filehnd );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4389
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4390
// Read the segment data with length indicated by the previously read size
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4391
$segdata = fread( $filehnd, $decodedsize['size'] - 2 );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4392
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4393
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4394
// Store the segment information in the output array
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4395
$headerdata[] = array( "SegType" => ord($data{1}),
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4396
"SegName" => $GLOBALS[ "JPEG_Segment_Names" ][ ord($data{1}) ],
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4397
"SegDataStart" => $segdatastart,
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4398
"SegData" => $segdata );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4399
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4400
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4401
// If this is a SOS (Start Of Scan) segment, then there is no more header data - the compressed image data follows
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4402
if ( $data{1} == "\xDA" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4403
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4404
// Flag that we have hit the compressed image data - exit loop as no more headers available.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4405
$hit_compressed_image_data = TRUE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4406
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4407
else
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4408
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4409
// Not an SOS - Read the next two bytes - should be the segment marker for the next segment
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4410
$data = fread( $filehnd, 2 );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4411
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4412
// Check that the first byte of the two is 0xFF as it should be for a marker
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4413
if ( $data{0} != "\xFF" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4414
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4415
// NO FF found - close file and return - JPEG is probably corrupted
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4416
fclose($filehnd);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4417
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4418
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4419
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4420
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4421
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4422
// Close File
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4423
fclose($filehnd);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4424
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4425
// Return the header data retrieved
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4426
return $headerdata;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4427
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4428
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4429
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4430
* Returns the dimensions of a JPEG image in the same format as {php,gif}_get_dimensions().
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4431
* @param string JPEG file to check
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4432
* @return array Key 0 is width, key 1 is height
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4433
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4434
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4435
function jpg_get_dimensions($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4436
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4437
if ( !file_exists($filename) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4438
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4439
echo "Doesn't exist<br />";
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4440
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4441
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4442
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4443
$headers = get_jpeg_header_data($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4444
if ( !$headers )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4445
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4446
echo "Bad headers<br />";
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4447
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4448
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4449
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4450
$metadata = get_jpeg_intrinsic_values($headers);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4451
if ( !$metadata )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4452
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4453
echo "Bad metadata: <pre>" . print_r($metadata, true) . "</pre><br />";
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4454
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4455
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4456
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4457
if ( !isset($metadata['Image Width']) || !isset($metadata['Image Height']) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4458
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4459
echo "No metadata<br />";
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4460
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4461
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4462
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4463
return array($metadata['Image Width'], $metadata['Image Height']);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4464
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4465
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4466
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4467
* Generates a URL for the avatar for the given user ID and avatar type.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4468
* @param int User ID
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4469
* @param string Image type - must be one of jpg, png, or gif.
621
+ − 4470
* @param string User's e-mail address, makes Special:Avatar redirect if not specified
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4471
* @return string
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4472
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4473
621
+ − 4474
function make_avatar_url($user_id, $avi_type, $user_email = false)
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4475
{
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4476
static $img_types = array(
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4477
'png' => IMAGE_TYPE_PNG,
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4478
'gif' => IMAGE_TYPE_GIF,
621
+ − 4479
'jpg' => IMAGE_TYPE_JPG,
+ − 4480
'grv' => IMAGE_TYPE_GRV
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4481
);
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4482
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4483
if ( !is_int($user_id) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4484
return false;
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4485
if ( !isset($img_types[$avi_type]) )
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4486
return false;
621
+ − 4487
+ − 4488
if ( $avi_type == 'grv' )
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4489
{
621
+ − 4490
if ( $user_email )
+ − 4491
{
+ − 4492
return make_gravatar_url($user_email);
+ − 4493
}
+ − 4494
}
+ − 4495
else
+ − 4496
{
+ − 4497
$avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type;
+ − 4498
if ( !file_exists(ENANO_ROOT . $avi_relative_path) )
+ − 4499
{
+ − 4500
return '';
+ − 4501
}
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4502
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4503
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4504
$img_type = $img_types[$avi_type];
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4505
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4506
$dateline = @filemtime(ENANO_ROOT . $avi_relative_path);
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4507
$avi_id = pack('VVv', $dateline, $user_id, $img_type);
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4508
$avi_id = hexencode($avi_id, '', '');
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4509
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4510
// return scriptPath . $avi_relative_path;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4511
return makeUrlNS('Special', "Avatar/$avi_id");
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4512
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4513
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4514
/**
621
+ − 4515
* Generates a URL to the Gravatar for a user based on his/her e-mail address.
+ − 4516
* @param string E-mail address
+ − 4517
* @param int Size - defaults to site-wide limits
+ − 4518
* @return string URL
+ − 4519
*/
+ − 4520
+ − 4521
function make_gravatar_url($email, $size = false)
+ − 4522
{
+ − 4523
$email = md5($email);
+ − 4524
+ − 4525
// gravatar parameters
+ − 4526
if ( $size )
+ − 4527
{
+ − 4528
$max_size = intval($size);
+ − 4529
}
+ − 4530
else
+ − 4531
{
+ − 4532
$max_x = intval(getConfig('avatar_max_width', '150'));
+ − 4533
$max_y = intval(getConfig('avatar_max_height', '150'));
+ − 4534
// ?s=
+ − 4535
$max_size = ( $max_x > $max_y ) ? $max_y : $max_x;
+ − 4536
}
+ − 4537
+ − 4538
// ?r=
+ − 4539
$rating = getConfig('gravatar_rating', 'g');
+ − 4540
+ − 4541
// final URL
+ − 4542
$url = "http://www.gravatar.com/avatar/$email?r=$rating&s=$max_size";
+ − 4543
+ − 4544
return $url;
+ − 4545
}
+ − 4546
+ − 4547
/**
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4548
* Determines an image's filetype based on its signature.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4549
* @param string Path to image file
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4550
* @return string One of gif, png, or jpg, or false if none of these.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4551
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4552
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4553
function get_image_filetype($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4554
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4555
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4556
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4557
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4558
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4559
if ( substr($filecontents, 0, 8) == "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4560
return 'png';
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4561
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4562
if ( substr($filecontents, 0, 6) == 'GIF87a' || substr($filecontents, 0, 6) == 'GIF89a' )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4563
return 'gif';
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4564
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4565
if ( substr($filecontents, 0, 2) == "\xFF\xD8" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4566
return 'jpg';
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4567
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4568
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4569
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4570
334
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4571
/**
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4572
* Generates a JSON encoder/decoder singleton.
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4573
* @return object
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4574
*/
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4575
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4576
function enano_json_singleton()
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4577
{
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4578
static $json_obj;
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4579
if ( !is_object($json_obj) )
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4580
$json_obj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE | SERVICES_JSON_SUPPRESS_ERRORS);
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4581
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4582
return $json_obj;
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4583
}
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4584
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4585
/**
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4586
* Wrapper for JSON encoding.
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4587
* @param mixed Variable to encode
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4588
* @return string JSON-encoded string
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4589
*/
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4590
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4591
function enano_json_encode($data)
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4592
{
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4593
/*
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4594
if ( function_exists('json_encode') )
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4595
{
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4596
// using PHP5 with JSON support
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4597
return json_encode($data);
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4598
}
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4599
*/
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4600
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4601
return Zend_Json::encode($data, true);
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4602
}
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4603
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4604
/**
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4605
* Wrapper for JSON decoding.
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4606
* @param string JSON-encoded string
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4607
* @return mixed Decoded value
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4608
*/
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4609
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4610
function enano_json_decode($data)
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4611
{
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4612
/*
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4613
if ( function_exists('json_decode') )
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4614
{
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4615
// using PHP5 with JSON support
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4616
return json_decode($data);
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4617
}
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4618
*/
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4619
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4620
return Zend_Json::decode($data, Zend_Json::TYPE_ARRAY);
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4621
}
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
diff
changeset
+ − 4622
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4623
/**
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4624
* Cleans a snippet of JSON for closer standards compliance (shuts up the picky Zend parser)
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4625
* @param string Dirty JSON
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4626
* @return string Clean JSON
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4627
*/
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4628
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4629
function enano_clean_json($json)
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4630
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4631
// eliminate comments
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4632
$json = preg_replace(array(
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4633
// eliminate single line comments in '// ...' form
832
7152ca0a0ce9
Major redesign of rendering pipeline that separates pages saved with MCE from pages saved with the plaintext editor (full description in long commit message)
Dan
diff
changeset
+ − 4634
'#^\s*//(.*)$#m',
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4635
// eliminate multi-line comments in '/* ... */' form, at start of string
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4636
'#^\s*/\*(.+)\*/#Us',
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4637
// eliminate multi-line comments in '/* ... */' form, at end of string
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4638
'#/\*(.+)\*/\s*$#Us'
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4639
), '', $json);
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4640
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4641
$json = preg_replace('/([,\{\[])([\s]*?)([a-z0-9_]+)([\s]*?):/', '\\1\\2"\\3" :', $json);
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4642
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4643
return $json;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4644
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4645
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4646
/**
519
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4647
* Trims a snippet of text to the first and last curly braces. Useful for JSON.
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4648
* @param string Text to trim
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4649
* @return string
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4650
*/
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4651
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4652
function enano_trim_json($json)
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4653
{
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4654
return preg_replace('/^([^{]+)\{/', '{', preg_replace('/\}([^}]+)$/', '}', $json));
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4655
}
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4656
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4657
/**
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4658
* Starts the profiler.
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4659
*/
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4660
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4661
function profiler_start()
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4662
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4663
global $_profiler;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4664
$_profiler = array();
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4665
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4666
if ( !defined('ENANO_DEBUG') )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4667
return false;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4668
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4669
$_profiler[] = array(
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4670
'point' => 'Profiling started',
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4671
'time' => microtime_float(),
424
+ − 4672
'backtrace' => false,
+ − 4673
'mem' => false
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4674
);
424
+ − 4675
if ( function_exists('memory_get_usage') )
+ − 4676
{
+ − 4677
$_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
+ − 4678
}
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4679
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4680
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4681
/**
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4682
* Logs something in the profiler.
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4683
* @param string Point name or message
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4684
* @param bool Optional. If true (default), a backtrace will be generated and added to the profiler data. False disables this, often for security reasons.
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4685
*/
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4686
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4687
function profiler_log($point, $allow_backtrace = true)
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4688
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4689
if ( !defined('ENANO_DEBUG') )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4690
return false;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4691
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4692
global $_profiler;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4693
$backtrace = false;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4694
if ( $allow_backtrace && function_exists('debug_print_backtrace') )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4695
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4696
list(, $backtrace) = explode("\n", enano_debug_print_backtrace(true));
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4697
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4698
$_profiler[] = array(
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4699
'point' => $point,
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4700
'time' => microtime_float(),
424
+ − 4701
'backtrace' => $backtrace,
+ − 4702
'mem' => false
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4703
);
424
+ − 4704
if ( function_exists('memory_get_usage') )
+ − 4705
{
+ − 4706
$_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
+ − 4707
}
566
06d241de3151
Made ajaxReset() call the actual requested title instead of effective title; fixed (again) template compiler bug not matching certain tags (probably PCRE bug)
Dan
diff
changeset
+ − 4708
return true;
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4709
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4710
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4711
/**
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4712
* Returns the profiler's data (so far).
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4713
* @return array
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4714
*/
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4715
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4716
function profiler_dump()
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4717
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4718
return $GLOBALS['_profiler'];
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4719
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4720
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4721
/**
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4722
* Generates an HTML version of the performance profile. Not localized because only used as a debugging tool.
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4723
* @return string
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4724
*/
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4725
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4726
function profiler_make_html()
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4727
{
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4728
if ( !defined('ENANO_DEBUG') )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4729
return '';
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4730
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4731
$profile = profiler_dump();
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4732
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4733
$html = '<div class="tblholder">';
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4734
$html .= '<table border="0" cellspacing="1" cellpadding="4">';
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4735
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4736
$time_start = $time_last = $profile[0]['time'];
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4737
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4738
foreach ( $profile as $i => $entry )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4739
{
592
+ − 4740
// $time_since_last = $entry['time'] - $time_last;
+ − 4741
// if ( $time_since_last < 0.01 )
+ − 4742
// continue;
+ − 4743
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4744
$html .= "<!-- ########################################################## -->\n<tr>\n <th colspan=\"2\">Event $i</th>\n</tr>";
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4745
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4746
$html .= '<tr>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4747
$html .= ' <td class="row2">Event:</td>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4748
$html .= ' <td class="row1">' . htmlspecialchars($entry['point']) . '</td>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4749
$html .= '</tr>' . "\n";
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4750
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4751
$time = $entry['time'] - $time_start;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4752
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4753
$html .= '<tr>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4754
$html .= ' <td class="row2">Time since start:</td>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4755
$html .= ' <td class="row1">' . $time . 's</td>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4756
$html .= '</tr>' . "\n";
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4757
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4758
$time = $entry['time'] - $time_last;
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4759
if ( $time < 0.0001 )
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4760
$time = 'Marginal';
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4761
else
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4762
$time = "{$time}s";
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4763
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4764
$html .= '<tr>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4765
$html .= ' <td class="row2">Time since last event:</td>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4766
$html .= ' <td class="row1">' . $time . '</td>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4767
$html .= '</tr>' . "\n";
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4768
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4769
if ( $entry['backtrace'] )
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4770
{
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4771
$html .= '<tr>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4772
$html .= ' <td class="row2">Called from:</td>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4773
$html .= ' <td class="row1">' . htmlspecialchars($entry['backtrace']) . '</td>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4774
$html .= '</tr>' . "\n";
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4775
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4776
424
+ − 4777
if ( $entry['mem'] )
+ − 4778
{
+ − 4779
$html .= '<tr>' . "\n";
+ − 4780
$html .= ' <td class="row2">Total mem usage:</td>' . "\n";
+ − 4781
$html .= ' <td class="row1">' . htmlspecialchars($entry['mem']) . ' (bytes)</td>' . "\n";
+ − 4782
$html .= '</tr>' . "\n";
+ − 4783
}
+ − 4784
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4785
$html .= "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4786
372
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4787
$time_last = $entry['time'];
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4788
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4789
$html .= '</table></div>';
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4790
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4791
return $html;
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4792
}
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4793
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4794
// Might as well start the profiler, it has no external dependencies except from this file.
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4795
profiler_start();
5bd429428101
A number of scattered changes. Profiler added and only enabled in debug mode (currently on), but awfully useful for fixing performance in the future. Started work on Admin:LangManager
Dan
diff
changeset
+ − 4796
376
+ − 4797
/**
+ − 4798
* Returns the number of times a character occurs in a given string.
+ − 4799
* @param string Haystack
+ − 4800
* @param string Needle
+ − 4801
* @return int
+ − 4802
*/
+ − 4803
+ − 4804
function get_char_count($string, $char)
+ − 4805
{
+ − 4806
$char = substr($char, 0, 1);
+ − 4807
$count = 0;
+ − 4808
for ( $i = 0; $i < strlen($string); $i++ )
+ − 4809
{
+ − 4810
if ( $string{$i} == $char )
+ − 4811
$count++;
+ − 4812
}
+ − 4813
return $count;
+ − 4814
}
+ − 4815
+ − 4816
/**
+ − 4817
* Returns the number of lines in a string.
+ − 4818
* @param string String to check
+ − 4819
* @return int
+ − 4820
*/
+ − 4821
+ − 4822
function get_line_count($string)
+ − 4823
{
+ − 4824
return ( get_char_count($string, "\n") ) + 1;
+ − 4825
}
+ − 4826
481
+ − 4827
if ( !function_exists('sys_get_temp_dir') )
+ − 4828
{
+ − 4829
// Based on http://www.phpit.net/
+ − 4830
// article/creating-zip-tar-archives-dynamically-php/2/
+ − 4831
/**
+ − 4832
* Attempt to get the system's temp directory.
+ − 4833
* @return string or bool false on failure
+ − 4834
*/
+ − 4835
+ − 4836
function sys_get_temp_dir()
+ − 4837
{
+ − 4838
// Try to get from environment variable
+ − 4839
if ( !empty($_ENV['TMP']) )
+ − 4840
{
+ − 4841
return realpath( $_ENV['TMP'] );
+ − 4842
}
+ − 4843
else if ( !empty($_ENV['TMPDIR']) )
+ − 4844
{
+ − 4845
return realpath( $_ENV['TMPDIR'] );
+ − 4846
}
+ − 4847
else if ( !empty($_ENV['TEMP']) )
+ − 4848
{
+ − 4849
return realpath( $_ENV['TEMP'] );
+ − 4850
}
+ − 4851
+ − 4852
// Detect by creating a temporary file
+ − 4853
else
+ − 4854
{
+ − 4855
// Try to use system's temporary directory
+ − 4856
// as random name shouldn't exist
+ − 4857
$temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
+ − 4858
if ( $temp_file )
+ − 4859
{
+ − 4860
$temp_dir = realpath( dirname($temp_file) );
+ − 4861
unlink( $temp_file );
+ − 4862
return $temp_dir;
+ − 4863
}
+ − 4864
else
+ − 4865
{
+ − 4866
return FALSE;
+ − 4867
}
+ − 4868
}
+ − 4869
}
+ − 4870
}
+ − 4871
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4872
/**
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4873
* Grabs and processes all rank information directly from the database.
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4874
*/
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4875
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4876
function fetch_rank_data()
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4877
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4878
global $db, $session, $paths, $template, $plugins; // Common objects
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4879
global $lang;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4880
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4881
$sql = $session->generate_rank_sql();
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4882
$q = $db->sql_query($sql);
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4883
if ( !$q )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4884
$db->_die();
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4885
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4886
$GLOBALS['user_ranks'] = array();
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4887
global $user_ranks;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4888
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4889
while ( $row = $db->fetchrow($q) )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4890
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4891
$user_id = $row['user_id'];
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4892
$username = $row['username'];
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4893
$row = $session->calculate_user_rank($row);
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4894
$user_ranks[$username] = $row;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4895
$user_ranks[$user_id] =& $user_ranks[$username];
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4896
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4897
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4898
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4899
/**
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4900
* Caches the computed user rank information.
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4901
*/
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4902
573
43e7254afdb4
Renamed some functions (that were new in this release anyway) due to compatibility broken with PunBB bridge
Dan
diff
changeset
+ − 4903
function generate_cache_userranks()
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4904
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4905
global $db, $session, $paths, $template, $plugins; // Common objects
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4906
global $lang;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4907
global $user_ranks;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4908
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4909
fetch_rank_data();
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4910
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4911
$user_ranks_stripped = array();
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4912
foreach ( $user_ranks as $key => $value )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4913
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4914
if ( is_int($key) )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4915
$user_ranks_stripped[$key] = $value;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4916
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4917
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4918
$ranks_exported = "<?php\n\n// Automatically generated user rank cache.\nglobal \$user_ranks;\n" . '$user_ranks = ' . $lang->var_export_string($user_ranks_stripped) . ';';
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4919
$uid_map = array();
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4920
foreach ( $user_ranks as $id => $row )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4921
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4922
if ( !is_int($id) )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4923
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4924
$username = $id;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4925
continue;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4926
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4927
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4928
$un_san = addslashes($username);
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4929
$ranks_exported .= "\n\$user_ranks['$un_san'] =& \$user_ranks[{$row['user_id']}];";
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4930
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4931
$ranks_exported .= "\n\ndefine('ENANO_RANKS_CACHE_LOADED', 1); \n?>";
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4932
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4933
// open ranks cache file
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4934
$fh = @fopen( ENANO_ROOT . '/cache/cache_ranks.php', 'w' );
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4935
if ( !$fh )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4936
return false;
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4937
fwrite($fh, $ranks_exported);
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4938
fclose($fh);
613
+ − 4939
+ − 4940
return true;
541
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4941
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4942
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4943
/**
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4944
* Loads the rank data, first attempting the cache file and then the database.
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4945
*/
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4946
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4947
function load_rank_data()
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4948
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4949
if ( file_exists( ENANO_ROOT . '/cache/cache_ranks.php' ) )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4950
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4951
@include(ENANO_ROOT . '/cache/cache_ranks.php');
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4952
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4953
if ( !defined('ENANO_RANKS_CACHE_LOADED') )
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4954
{
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4955
fetch_rank_data();
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4956
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4957
}
acb7e23b6ffa
Massive commit with various changes. Added user ranks system (no admin interface yet) and ability for users to have custom user titles. Made cron framework accept fractions of hours through floating-point intervals. Modifed ACL editor to use miniPrompt framework for close confirmation box. Made avatar system use a special page as opposed to fetching the files directly for caching reasons.
Dan
diff
changeset
+ − 4958
599
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4959
/**
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4960
* Function to purge all caches used in Enano. Useful for upgrades, maintenance, backing the site up, etc.
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4961
*/
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4962
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4963
function purge_all_caches()
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4964
{
613
+ − 4965
global $cache;
599
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4966
if ( $dh = opendir(ENANO_ROOT . '/cache') )
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4967
{
613
+ − 4968
$cache->purge('page_meta');
+ − 4969
$cache->purge('anon_sidebar');
+ − 4970
$cache->purge('plugins');
+ − 4971
599
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4972
$data_files = array(
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4973
'aes_decrypt.php',
613
+ − 4974
// ranks cache is stored using a custom engine (not enano's default cache)
599
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4975
'cache_ranks.php'
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4976
);
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4977
while ( $file = @readdir($dh) )
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4978
{
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4979
$fullpath = ENANO_ROOT . "/cache/$file";
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4980
// we don't want to mess with directories
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4981
if ( !is_file($fullpath) )
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4982
continue;
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4983
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4984
// data files
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4985
if ( in_array($file, $data_files) )
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4986
unlink($fullpath);
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4987
// template files
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4988
else if ( preg_match('/\.(?:tpl|css)\.php$/', $file) )
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4989
unlink($fullpath);
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4990
// compressed javascript
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4991
else if ( preg_match('/^jsres_(?:[A-z0-9_-]+)\.js\.json$/', $file) )
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4992
unlink($fullpath);
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4993
// tinymce stuff
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4994
else if ( preg_match('/^tiny_mce_(?:[a-f0-9]+)\.gz$/', $file) )
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4995
unlink($fullpath);
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4996
// language files
613
+ − 4997
else if ( preg_match('/^lang_json_(?:[a-f0-9]+?)\.php$/', $file) || preg_match('/^(?:cache_)?lang_(?:[0-9]+?)\.php$/', $file) )
599
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4998
unlink($fullpath);
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4999
}
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 5000
return true;
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 5001
}
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 5002
return false;
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 5003
}
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 5004
851
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5005
/**
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5006
* Implementation of the "which" command in native PHP.
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5007
* @param string command
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5008
* @return string path to executable, or false on failure
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5009
*/
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5010
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5011
function which($executable)
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5012
{
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5013
$path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false );
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5014
if ( !$path )
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5015
// couldn't get OS's PATH
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5016
return false;
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5017
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5018
$win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' );
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5019
$extensions = $win32 ? array('.exe', '.com', '.bat') : array('');
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5020
$separator = $win32 ? ';' : ':';
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5021
$paths = explode($separator, $path);
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5022
foreach ( $paths as $dir )
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5023
{
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5024
foreach ( $extensions as $ext )
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5025
{
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5026
$fullpath = "$dir/{$executable}{$ext}";
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5027
if ( file_exists($fullpath) && is_executable($fullpath) )
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5028
{
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5029
return $fullpath;
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5030
}
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5031
}
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5032
}
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5033
return false;
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5034
}
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 5035
857
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5036
/**
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5037
* Properly test a file or directory for writability. Used in various places around installer.
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5038
* @param string File or directory to test
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5039
* @return bool
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5040
*/
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5041
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5042
function write_test($filename)
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5043
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5044
// We need to actually _open_ the file to make sure it can be written, because sometimes this fails even when is_writable() returns
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5045
// true on Windows/IIS servers. Don't ask me why.
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5046
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5047
$file = ENANO_ROOT . '/' . $filename;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5048
if ( is_dir($file) )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5049
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5050
$file = rtrim($file, '/') . '/' . 'enanoinstalltest.txt';
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5051
if ( file_exists($file) )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5052
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5053
$fp = @fopen($file, 'a+');
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5054
if ( !$fp )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5055
return false;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5056
fclose($fp);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5057
unlink($file);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5058
return true;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5059
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5060
else
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5061
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5062
$fp = @fopen($file, 'w');
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5063
if ( !$fp )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5064
return false;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5065
fclose($fp);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5066
unlink($file);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5067
return true;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5068
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5069
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5070
else
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5071
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5072
if ( file_exists($file) )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5073
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5074
$fp = @fopen($file, 'a+');
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5075
if ( !$fp )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5076
return false;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5077
fclose($fp);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5078
return true;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5079
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5080
else
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5081
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5082
$fp = @fopen($file, 'w');
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5083
if ( !$fp )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5084
return false;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5085
fclose($fp);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5086
return true;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5087
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5088
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5089
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 5090