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
/**
875
+ − 2198
* Generates the HTML of a pagination control.
+ − 2199
* @param int Current page
+ − 2200
* @param int Number of pages
+ − 2201
* @param string sprintf()-style formatting URL for pages
+ − 2202
* @param int Multiplier for start offset, defaults to 1
+ − 2203
* @param int Add to each $i for addition to result urls, usually either 0 or 1 (depends on whether you want your ?page= to start with 0 ro 1)
+ − 2204
* @return string HTML
+ − 2205
*/
+ − 2206
+ − 2207
function generate_paginator($current_page, $num_pages, $result_url, $start_mult = 1, $start_add = 1)
+ − 2208
{
+ − 2209
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 2210
global $lang;
+ − 2211
+ − 2212
$out = '';
+ − 2213
$i = 0;
+ − 2214
+ − 2215
// Build paginator
+ − 2216
$pg_css = ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) ?
+ − 2217
// IE-specific hack
+ − 2218
'display: block; width: 1px;':
+ − 2219
// Other browsers
+ − 2220
'display: table; margin: 10px 0 0 auto;';
+ − 2221
+ − 2222
$begin = '<div class="tblholder" style="'. $pg_css . '">
+ − 2223
<table border="0" cellspacing="1" cellpadding="4">
+ − 2224
<tr><th>' . $lang->get('paginate_lbl_page') . '</th>';
+ − 2225
$block = '<td class="row1" style="text-align: center;">{LINK}</td>';
+ − 2226
$end = '</tr></table></div>';
+ − 2227
$blk = $template->makeParserText($block);
+ − 2228
$inner = '';
+ − 2229
$cls = 'row2';
+ − 2230
if ( $num_pages < 5 )
+ − 2231
{
+ − 2232
for ( $i = 0; $i < $num_pages; $i++ )
+ − 2233
{
+ − 2234
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2235
$offset = strval(($i * $start_mult) + $start_add);
+ − 2236
$url = htmlspecialchars(sprintf($result_url, $offset));
+ − 2237
$j = $i + 1;
+ − 2238
$link = ( $i == $current_page ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2239
$blk->assign_vars(array(
+ − 2240
'CLASS'=>$cls,
+ − 2241
'LINK'=>$link
+ − 2242
));
+ − 2243
$inner .= $blk->run();
+ − 2244
}
+ − 2245
}
+ − 2246
else
+ − 2247
{
+ − 2248
if ( $current_page + 5 > $num_pages )
+ − 2249
{
+ − 2250
$list = Array();
+ − 2251
$tp = $current_page;
+ − 2252
if ( $current_page + 0 == $num_pages ) $tp = $tp - 3;
+ − 2253
if ( $current_page + 1 == $num_pages ) $tp = $tp - 2;
+ − 2254
if ( $current_page + 2 == $num_pages ) $tp = $tp - 1;
+ − 2255
for ( $i = $tp - 1; $i <= $tp + 1; $i++ )
+ − 2256
{
+ − 2257
$list[] = $i;
+ − 2258
}
+ − 2259
}
+ − 2260
else
+ − 2261
{
+ − 2262
$list = Array();
+ − 2263
$current = $current_page;
+ − 2264
$lower = ( $current < 3 ) ? 1 : $current - 1;
+ − 2265
for ( $i = 0; $i < 3; $i++ )
+ − 2266
{
+ − 2267
$list[] = $lower + $i;
+ − 2268
}
+ − 2269
}
+ − 2270
$url = sprintf($result_url, '0');
+ − 2271
$link = ( 0 == $current_page ) ? "<b>" . $lang->get('paginate_btn_first') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« " . $lang->get('paginate_btn_first') . "</a>";
+ − 2272
$blk->assign_vars(array(
+ − 2273
'CLASS'=>$cls,
+ − 2274
'LINK'=>$link
+ − 2275
));
+ − 2276
$inner .= $blk->run();
+ − 2277
+ − 2278
foreach ( $list as $i )
+ − 2279
{
+ − 2280
if ( $i == $num_pages )
+ − 2281
break;
+ − 2282
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2283
$offset = strval(($i * $start_mult) + $start_add);
+ − 2284
$url = sprintf($result_url, $offset);
+ − 2285
$j = $i + 1;
+ − 2286
$link = ( $i == $current_page ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>";
+ − 2287
$blk->assign_vars(array(
+ − 2288
'CLASS'=>$cls,
+ − 2289
'LINK'=>$link
+ − 2290
));
+ − 2291
$inner .= $blk->run();
+ − 2292
}
+ − 2293
+ − 2294
// "Last" button
+ − 2295
$total = (($num_pages - 1) * $start_mult) + $start_add;
+ − 2296
+ − 2297
if ( $current_page < $num_pages )
+ − 2298
{
+ − 2299
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2300
$offset = strval($total);
+ − 2301
$url = sprintf($result_url, $offset);
+ − 2302
$link = ( $num_pages - 1 == $current_page ) ? "<b>" . $lang->get('paginate_btn_last') . "</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>" . $lang->get('paginate_btn_last') . " »</a>";
+ − 2303
$blk->assign_vars(array(
+ − 2304
'CLASS'=>$cls,
+ − 2305
'LINK'=>$link
+ − 2306
));
+ − 2307
$inner .= $blk->run();
+ − 2308
}
+ − 2309
+ − 2310
}
+ − 2311
+ − 2312
$inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$current_page.', '.$num_pages.', '.$start_mult.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>';
+ − 2313
+ − 2314
$paginator = "\n$begin$inner$end\n";
+ − 2315
return $paginator;
+ − 2316
}
+ − 2317
+ − 2318
/**
1
+ − 2319
* Paginates (breaks into multiple pages) a MySQL result resource, which is treated as unbuffered.
+ − 2320
* @param resource The MySQL result resource. This should preferably be an unbuffered query.
+ − 2321
* @param string A template, with variables being named after the column name
+ − 2322
* @param int The number of total results. This should be determined by a second query.
+ − 2323
* @param string sprintf-style formatting string for URLs for result pages. First parameter will be start offset.
+ − 2324
* @param int Optional. Start offset in individual results. Defaults to 0.
+ − 2325
* @param int Optional. The number of results per page. Defualts to 10.
+ − 2326
* @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.
+ − 2327
* @param string Optional. The text to be sent before the result list, only if there are any results. Possibly the start of a table.
+ − 2328
* @param string Optional. The text to be sent after the result list, only if there are any results. Possibly the end of a table.
+ − 2329
* @return string
+ − 2330
*/
+ − 2331
+ − 2332
function paginate($q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = '')
+ − 2333
{
+ − 2334
global $db, $session, $paths, $template, $plugins; // Common objects
359
+ − 2335
1
+ − 2336
$parser = $template->makeParserText($tpl_text);
875
+ − 2337
1
+ − 2338
$num_pages = ceil ( $num_results / $perpage );
+ − 2339
$out = '';
875
+ − 2340
$this_page = ceil ( $start / $perpage );
1
+ − 2341
$i = 0;
875
+ − 2342
+ − 2343
$paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0);
1
+ − 2344
$out .= $paginator;
76
+ − 2345
1
+ − 2346
$cls = 'row2';
76
+ − 2347
1
+ − 2348
if ( $row = $db->fetchrow($q) )
+ − 2349
{
+ − 2350
$i = 0;
+ − 2351
$out .= $header;
+ − 2352
do {
+ − 2353
$i++;
+ − 2354
if ( $i <= $start )
+ − 2355
{
+ − 2356
continue;
+ − 2357
}
+ − 2358
if ( ( $i - $start ) > $perpage )
+ − 2359
{
+ − 2360
break;
+ − 2361
}
+ − 2362
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ − 2363
foreach ( $row as $j => $val )
+ − 2364
{
+ − 2365
if ( isset($callers[$j]) )
+ − 2366
{
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
diff
changeset
+ − 2367
$tmp = ( is_callable($callers[$j]) ) ? @call_user_func($callers[$j], $val, $row) : $val;
76
+ − 2368
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
+ − 2369
if ( is_string($tmp) )
1
+ − 2370
{
+ − 2371
$row[$j] = $tmp;
+ − 2372
}
+ − 2373
}
+ − 2374
}
+ − 2375
$parser->assign_vars($row);
+ − 2376
$parser->assign_vars(array('_css_class' => $cls));
+ − 2377
$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
+ − 2378
} while ( $row = @$db->fetchrow($q) );
1
+ − 2379
$out .= $footer;
+ − 2380
}
76
+ − 2381
1
+ − 2382
$out .= $paginator;
76
+ − 2383
1
+ − 2384
return $out;
+ − 2385
}
+ − 2386
+ − 2387
/**
+ − 2388
* This is the same as paginate(), but it processes an array instead of a MySQL result resource.
+ − 2389
* @param array The results. Each value is simply echoed.
+ − 2390
* @param int The number of total results. This should be determined by a second query.
+ − 2391
* @param string sprintf-style formatting string for URLs for result pages. First parameter will be start offset.
+ − 2392
* @param int Optional. Start offset in individual results. Defaults to 0.
+ − 2393
* @param int Optional. The number of results per page. Defualts to 10.
+ − 2394
* @param string Optional. The text to be sent before the result list, only if there are any results. Possibly the start of a table.
+ − 2395
* @param string Optional. The text to be sent after the result list, only if there are any results. Possibly the end of a table.
+ − 2396
* @return string
+ − 2397
*/
+ − 2398
+ − 2399
function paginate_array($q, $num_results, $result_url, $start = 0, $perpage = 10, $header = '', $footer = '')
+ − 2400
{
+ − 2401
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
+ − 2402
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
+ − 2403
1
+ − 2404
$num_pages = ceil ( $num_results / $perpage );
+ − 2405
$out = '';
+ − 2406
$i = 0;
+ − 2407
$this_page = ceil ( $start / $perpage );
76
+ − 2408
875
+ − 2409
$paginator = generate_paginator($this_page, $num_pages, $result_url, $perpage, 0);
+ − 2410
$out .= $paginator;
+ − 2411
1
+ − 2412
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
+ − 2413
{
1
+ − 2414
$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
+ − 2415
}
76
+ − 2416
1
+ − 2417
$cls = 'row2';
76
+ − 2418
1
+ − 2419
if ( sizeof($q) > 0 )
+ − 2420
{
+ − 2421
$i = 0;
+ − 2422
$out .= $header;
+ − 2423
foreach ( $q as $val ) {
+ − 2424
$i++;
+ − 2425
if ( $i <= $start )
+ − 2426
{
+ − 2427
continue;
+ − 2428
}
+ − 2429
if ( ( $i - $start ) > $perpage )
+ − 2430
{
+ − 2431
break;
+ − 2432
}
+ − 2433
$out .= $val;
+ − 2434
}
+ − 2435
$out .= $footer;
+ − 2436
}
76
+ − 2437
1
+ − 2438
if ( $total > 1 )
+ − 2439
$out .= $paginator;
76
+ − 2440
1
+ − 2441
return $out;
+ − 2442
}
+ − 2443
76
+ − 2444
/**
1
+ − 2445
* Enano version of fputs for debugging
+ − 2446
*/
+ − 2447
+ − 2448
function enano_fputs($socket, $data)
+ − 2449
{
+ − 2450
// echo '<pre>' . htmlspecialchars($data) . '</pre>';
+ − 2451
// flush();
+ − 2452
// ob_flush();
+ − 2453
// ob_end_flush();
+ − 2454
return fputs($socket, $data);
+ − 2455
}
+ − 2456
+ − 2457
/**
+ − 2458
* Sanitizes a page URL string so that it can safely be stored in the database.
+ − 2459
* @param string Page ID to sanitize
+ − 2460
* @return string Cleaned text
+ − 2461
*/
+ − 2462
+ − 2463
function sanitize_page_id($page_id)
+ − 2464
{
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
+ − 2465
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
+ − 2466
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2467
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
+ − 2468
{
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
+ − 2469
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
+ − 2470
{
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
+ − 2471
$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
+ − 2472
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
+ − 2473
{
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2474
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
+ − 2475
}
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2476
}
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2477
}
e17cc42d77cf
Fixed: $paths->page_id not set when the page doesn't exist; finally fixed garbled page names for IP addresses
Dan
diff
changeset
+ − 2478
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
+ − 2479
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
+ − 2480
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
+ − 2481
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
+ − 2482
// 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
+ − 2483
$page_id = dirtify_page_id($page_id);
76
+ − 2484
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2485
$pid_clean = preg_replace('/[\w\.\/:;\(\)@\[\]_-]/', 'X', $page_id);
1
+ − 2486
$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
+ − 2487
1
+ − 2488
foreach ( $pid_dirty as $id => $char )
+ − 2489
{
+ − 2490
if ( $char == 'X' )
+ − 2491
continue;
+ − 2492
$cid = ord($char);
+ − 2493
$cid = dechex($cid);
+ − 2494
$cid = strval($cid);
+ − 2495
if ( strlen($cid) < 2 )
+ − 2496
{
+ − 2497
$cid = strtoupper("0$cid");
+ − 2498
}
+ − 2499
$pid_dirty[$id] = ".$cid";
+ − 2500
}
76
+ − 2501
1
+ − 2502
$pid_chars = enano_str_split($page_id, 1);
+ − 2503
$page_id_cleaned = '';
76
+ − 2504
1
+ − 2505
foreach ( $pid_chars as $id => $char )
+ − 2506
{
+ − 2507
if ( $pid_dirty[$id] == 'X' )
+ − 2508
$page_id_cleaned .= $char;
+ − 2509
else
+ − 2510
$page_id_cleaned .= $pid_dirty[$id];
+ − 2511
}
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
+ − 2512
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2513
// global $mime_types;
76
+ − 2514
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2515
// $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
+ − 2516
// $exts = '(' . implode('|', $exts) . ')';
76
+ − 2517
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
diff
changeset
+ − 2518
// $page_id_cleaned = preg_replace('/\.2e' . $exts . '$/', '.\\1', $page_id_cleaned);
76
+ − 2519
1
+ − 2520
return $page_id_cleaned;
+ − 2521
}
+ − 2522
+ − 2523
/**
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
+ − 2524
* 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
+ − 2525
* @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
+ − 2526
* @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
+ − 2527
*/
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2528
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2529
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
+ − 2530
{
38
+ − 2531
global $db, $session, $paths, $template, $plugins; // Common objects
76
+ − 2532
// 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
+ − 2533
$page_id = str_replace(' ', '_', $page_id);
76
+ − 2534
38
+ − 2535
// 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
+ − 2536
$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
+ − 2537
if ( is_valid_ip($pid_ip_check) )
38
+ − 2538
{
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
+ − 2539
return $page_id;
38
+ − 2540
}
76
+ − 2541
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
+ − 2542
preg_match_all('/\.[A-Fa-f0-9][A-Fa-f0-9]/', $page_id, $matches);
76
+ − 2543
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
+ − 2544
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
+ − 2545
{
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2546
$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
+ − 2547
$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
+ − 2548
$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
+ − 2549
$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
+ − 2550
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
+ − 2551
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
+ − 2552
$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
+ − 2553
}
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
+ − 2554
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
+ − 2555
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
+ − 2556
}
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2557
ad5986a53197
Fixed complicated SQL injection vulnerability in URL handler, updated license info for Tigra Tree Menu, and killed one XSS vulnerability
Dan
diff
changeset
+ − 2558
/**
76
+ − 2559
* 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
+ − 2560
* @param int The number to process
+ − 2561
* @return string Input number with commas added
+ − 2562
*/
+ − 2563
+ − 2564
function commatize($num)
+ − 2565
{
+ − 2566
$num = (string)$num;
+ − 2567
if ( strpos($num, '.') )
+ − 2568
{
+ − 2569
$whole = explode('.', $num);
+ − 2570
$num = $whole[0];
+ − 2571
$dec = $whole[1];
+ − 2572
}
+ − 2573
else
+ − 2574
{
+ − 2575
$whole = $num;
+ − 2576
}
+ − 2577
$offset = ( strlen($num) ) % 3;
+ − 2578
$len = strlen($num);
+ − 2579
$offset = ( $offset == 0 )
+ − 2580
? 3
+ − 2581
: $offset;
+ − 2582
for ( $i = $offset; $i < $len; $i=$i+3 )
+ − 2583
{
+ − 2584
$num = substr($num, 0, $i) . ',' . substr($num, $i, $len);
+ − 2585
$len = strlen($num);
+ − 2586
$i++;
+ − 2587
}
+ − 2588
if ( isset($dec) )
+ − 2589
{
+ − 2590
return $num . '.' . $dec;
+ − 2591
}
+ − 2592
else
+ − 2593
{
+ − 2594
return $num;
+ − 2595
}
+ − 2596
}
+ − 2597
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
+ − 2598
/**
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2599
* 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
+ − 2600
* @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
+ − 2601
* @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
+ − 2602
* @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
+ − 2603
*/
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2604
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2605
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
+ − 2606
{
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2607
$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
+ − 2608
$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
+ − 2609
$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
+ − 2610
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
+ − 2611
}
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
diff
changeset
+ − 2612
38
+ − 2613
/**
+ − 2614
* Tells if a given IP address is valid.
+ − 2615
* @param string suspected IP address
+ − 2616
* @return bool true if valid, false otherwise
+ − 2617
*/
76
+ − 2618
38
+ − 2619
function is_valid_ip($ip)
+ − 2620
{
710
+ − 2621
// This next one came from phpBB3.
38
+ − 2622
$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
+ − 2623
$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
+ − 2624
38
+ − 2625
if ( preg_match("/^{$ipv4}$/", $ip) || preg_match("/^{$ipv6}$/", $ip) )
+ − 2626
return true;
+ − 2627
else
+ − 2628
return false;
+ − 2629
}
+ − 2630
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
+ − 2631
/**
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
+ − 2632
* 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
+ − 2633
* @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
+ − 2634
* @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
+ − 2635
* @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
+ − 2636
*/
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
+ − 2637
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
+ − 2638
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
+ − 2639
{
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
+ − 2640
$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
+ − 2641
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
+ − 2642
{
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
+ − 2643
$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
+ − 2644
$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
+ − 2645
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
+ − 2646
}
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
+ − 2647
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
+ − 2648
}
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
+ − 2649
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
+ − 2650
/**
581
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2651
* 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
+ − 2652
* @param string Needle
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2653
* @param string Thread
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2654
* @param string Haystack
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2655
* @return string
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2656
*/
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2657
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2658
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
+ − 2659
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2660
$needle_len = strlen($needle);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2661
$haystack_len = strlen($haystack);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2662
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
+ − 2663
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2664
$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
+ − 2665
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
+ − 2666
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2667
// Got it!
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2668
$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
+ − 2669
$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
+ − 2670
$haystack = "{$upto}{$thread}{$from}";
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2671
$haystack_len = strlen($haystack);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2672
$i = $i + strlen($thread);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2673
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2674
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2675
return $haystack;
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2676
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2677
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2678
/**
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2679
* 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
+ − 2680
* @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
+ − 2681
* @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
+ − 2682
* @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
+ − 2683
* @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
+ − 2684
* @return string
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2685
*/
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2686
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2687
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
+ − 2688
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2689
$needle_len = strlen($needle);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2690
$haystack_len = strlen($haystack);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2691
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
+ − 2692
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2693
$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
+ − 2694
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
+ − 2695
{
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2696
// Got it!
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2697
$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
+ − 2698
$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
+ − 2699
$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
+ − 2700
$haystack_len = strlen($haystack);
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2701
$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
+ − 2702
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2703
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2704
return $haystack;
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2705
}
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2706
5e8fd89c02ea
Initial progress towards converting auto-completion framework to Spry. Not currently in a very working state.
Dan
diff
changeset
+ − 2707
/**
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
+ − 2708
* 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
+ − 2709
* 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
+ − 2710
* - 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
+ − 2711
* - 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
+ − 2712
* - 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
+ − 2713
* 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
+ − 2714
* - 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
+ − 2715
* - 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
+ − 2716
* - 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
+ − 2717
* 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
+ − 2718
* - 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
+ − 2719
* - 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
+ − 2720
* - 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
+ − 2721
* 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
+ − 2722
* 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
+ − 2723
* 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
+ − 2724
* - 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
+ − 2725
* @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
+ − 2726
<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
+ − 2727
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
+ − 2728
'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
+ − 2729
'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
+ − 2730
'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
+ − 2731
'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
+ − 2732
'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
+ − 2733
'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
+ − 2734
'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
+ − 2735
'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
+ − 2736
),
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
+ − 2737
'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
+ − 2738
));
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
+ − 2739
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
+ − 2740
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
+ − 2741
{
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
+ − 2742
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
+ − 2743
$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
+ − 2744
$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
+ − 2745
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
+ − 2746
{
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
+ − 2747
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
+ − 2748
}
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
+ − 2749
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
+ − 2750
{
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
+ − 2751
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
+ − 2752
}
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
+ − 2753
}
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
+ − 2754
</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
+ − 2755
* @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
+ − 2756
* @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
+ − 2757
*/
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
+ − 2758
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
+ − 2759
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
+ − 2760
$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
+ − 2761
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
+ − 2762
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
+ − 2763
{
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
+ − 2764
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
+ − 2765
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
+ − 2766
$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
+ − 2767
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
+ − 2768
{
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
+ − 2769
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
+ − 2770
{
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
+ − 2771
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
+ − 2772
}
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
+ − 2773
}
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
+ − 2774
$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
+ − 2775
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
+ − 2776
}
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
+ − 2777
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
+ − 2778
/**
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
+ − 2779
* 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
+ − 2780
* @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
+ − 2781
* @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
+ − 2782
*/
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
+ − 2783
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
+ − 2784
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
+ − 2785
{
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
+ − 2786
$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
+ − 2787
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
+ − 2788
$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
+ − 2789
$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
+ − 2790
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
+ − 2791
{
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
+ − 2792
$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
+ − 2793
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
+ − 2794
{
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
+ − 2795
$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
+ − 2796
$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
+ − 2797
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
+ − 2798
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
+ − 2799
{
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
+ − 2800
// 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
+ − 2801
$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
+ − 2802
}
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
+ − 2803
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
+ − 2804
{
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
+ − 2805
// 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
+ − 2806
$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
+ − 2807
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
+ − 2808
. 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
+ − 2809
}
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
+ − 2810
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
+ − 2811
{
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
+ − 2812
// 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
+ − 2813
$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
+ − 2814
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
+ − 2815
. 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
+ − 2816
. 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
+ − 2817
}
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
+ − 2818
}
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
+ − 2819
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
+ − 2820
{
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
+ − 2821
$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
+ − 2822
}
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
+ − 2823
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
+ − 2824
$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
+ − 2825
}
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
+ − 2826
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
+ − 2827
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
+ − 2828
}
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
+ − 2829
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
+ − 2830
/**
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
+ − 2831
* 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
+ − 2832
* @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
+ − 2833
* @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
+ − 2834
*/
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
+ − 2835
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
+ − 2836
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
+ − 2837
{
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
+ − 2838
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
+ − 2839
{
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
+ − 2840
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
+ − 2841
{
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
+ − 2842
$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
+ − 2843
}
270
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 2844
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
+ − 2845
{
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
+ − 2846
$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
+ − 2847
}
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
+ − 2848
}
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
+ − 2849
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
+ − 2850
}
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
+ − 2851
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
+ − 2852
/**
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
+ − 2853
* 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
+ − 2854
* @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
+ − 2855
* @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
+ − 2856
*/
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
+ − 2857
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
+ − 2858
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
+ − 2859
{
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
+ − 2860
$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
+ − 2861
$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
+ − 2862
$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
+ − 2863
$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
+ − 2864
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
+ − 2865
}
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
+ − 2866
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
+ − 2867
/**
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
+ − 2868
* 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
+ − 2869
* @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
+ − 2870
* @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
+ − 2871
* @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
+ − 2872
* @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
+ − 2873
* @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
+ − 2874
*/
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
+ − 2875
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2876
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
+ − 2877
{
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2878
$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
+ − 2879
$mtime = time();
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2880
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2881
if ( !function_exists('gzdeflate') )
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2882
return false;
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2883
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2884
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
+ − 2885
(empty($filename) ? "" : $filename . "\0") .
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2886
(empty($comment) ? "" : $comment . "\0") .
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2887
gzdeflate($data, $level) .
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2888
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
+ − 2889
}
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
+ − 2890
798
+ − 2891
$php_errors = array();
+ − 2892
+ − 2893
/**
+ − 2894
* Enano's PHP error handler.
+ − 2895
* handler ( int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] )
+ − 2896
* @access private
+ − 2897
*/
+ − 2898
+ − 2899
function enano_handle_error($errno, $errstr, $errfile, $errline)
+ − 2900
{
+ − 2901
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 2902
+ − 2903
$er = error_reporting();
+ − 2904
if ( ! $er & $errno || $er == 0 )
+ − 2905
{
+ − 2906
return true;
+ − 2907
}
+ − 2908
global $do_gzip, $php_errors;
+ − 2909
+ − 2910
if ( defined('ENANO_DEBUG') )
+ − 2911
{
+ − 2912
// turn off gzip and echo out error immediately for debug installs
+ − 2913
$do_gzip = false;
+ − 2914
}
+ − 2915
+ − 2916
$error_type = 'error';
+ − 2917
if ( in_array($errno, array(E_WARNING, E_USER_WARNING)) )
+ − 2918
$error_type = 'warning';
+ − 2919
else if ( in_array($errno, array(E_NOTICE, E_USER_NOTICE)) )
+ − 2920
$error_type = 'notice';
+ − 2921
+ − 2922
if ( @is_object(@$plugins) )
+ − 2923
{
+ − 2924
$code = $plugins->setHook('php_error');
+ − 2925
foreach ( $code as $cmd )
+ − 2926
{
+ − 2927
eval($cmd);
+ − 2928
}
+ − 2929
}
+ − 2930
+ − 2931
// bypass errors in date() and mktime() (Enano has its own code for this anyway)
+ − 2932
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.") )
+ − 2933
{
+ − 2934
return true;
+ − 2935
}
+ − 2936
+ − 2937
if ( $do_gzip )
+ − 2938
{
+ − 2939
$php_errors[] = array(
+ − 2940
'num' => $errno,
+ − 2941
'type' => $error_type,
+ − 2942
'error' => $errstr,
+ − 2943
'file' => $errfile,
+ − 2944
'line' => $errline
+ − 2945
);
+ − 2946
}
+ − 2947
else
+ − 2948
{
+ − 2949
echo "[ <b>PHP $error_type:</b> $errstr in <b>$errfile</b>:<b>$errline</b> ]<br />";
+ − 2950
}
+ − 2951
}
+ − 2952
+ − 2953
set_error_handler('enano_handle_error');
+ − 2954
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
+ − 2955
/**
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
+ − 2956
* 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
+ − 2957
*/
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
+ − 2958
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
+ − 2959
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
+ − 2960
{
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
+ − 2961
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
+ − 2962
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
+ − 2963
//
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
+ − 2964
// 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
+ − 2965
// 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
+ − 2966
//
720
e2762777b170
Fixed attempt at gzip compression after headers sent; hopefully safely escape args to scale_image() instead of erroring out
Dan
diff
changeset
+ − 2967
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
+ − 2968
{
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
$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
+ − 2970
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
+ − 2971
798
+ − 2972
global $php_errors;
+ − 2973
if ( !empty($php_errors) )
+ − 2974
{
+ − 2975
$errors = '';
+ − 2976
foreach ( $php_errors as $error )
+ − 2977
{
+ − 2978
$errors .= "[ <b>PHP {$error['type']}:</b> {$error['error']} in <b>{$error['file']}</b>:<b>{$error['line']}</b> ]<br />";
+ − 2979
}
+ − 2980
$gzip_contents = str_replace("</body>", "$errors</body>", $gzip_contents);
+ − 2981
}
+ − 2982
667
72818d2bf336
Fixed improperly set up gzencode() replacement; fixed bad regexp in scale_image() security check
Dan
diff
changeset
+ − 2983
$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
+ − 2984
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
+ − 2985
{
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
+ − 2986
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
+ − 2987
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
+ − 2988
}
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
+ − 2989
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
+ − 2990
{
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
+ − 2991
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
+ − 2992
}
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
+ − 2993
}
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
+ − 2994
}
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
+ − 2995
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
+ − 2996
/**
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
+ − 2997
* 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
+ − 2998
* @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
+ − 2999
* @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
+ − 3000
*/
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
+ − 3001
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
+ − 3002
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
+ − 3003
{
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
+ − 3004
$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
+ − 3005
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
+ − 3006
// 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
+ − 3007
$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
+ − 3008
125
+ − 3009
// Which tags to strip for JAVASCRIPT PROCESSING ONLY - you can change this if needed
+ − 3010
$strip_tags = Array('enano:no-opt');
+ − 3011
$strip_tags = implode('|', $strip_tags);
+ − 3012
+ − 3013
// 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
+ − 3014
preg_match_all("#<($strip_tags)([ ]+.*?)?>(.*?)</($strip_tags)>#is", $html, $matches);
125
+ − 3015
$seed = md5(microtime() . mt_rand()); // Random value used for placeholders
+ − 3016
for ($i = 0;$i < sizeof($matches[1]); $i++)
+ − 3017
{
+ − 3018
$html = str_replace($matches[0][$i], "{DONT_STRIP_ME_NAKED:$seed:$i}", $html);
+ − 3019
}
+ − 3020
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
+ − 3021
// Optimize (but don't obfuscate) Javascript
184
+ − 3022
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
+ − 3023
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
+ − 3024
$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
+ − 3025
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
+ − 3026
// 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
+ − 3027
$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
+ − 3028
'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
+ − 3029
'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
+ − 3030
'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
+ − 3031
'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
+ − 3032
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
+ − 3033
$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
+ − 3034
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
+ − 3035
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
+ − 3036
{
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
+ − 3037
$js =& $jscript[2][$i];
582
+ − 3038
if ( empty($js) )
+ − 3039
continue;
183
91127e62f38f
Fixed some regular expressions in HTML optimization algorithm; regex page groups can be edited now (oops)
Dan
diff
changeset
+ − 3040
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
+ − 3041
$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
+ − 3042
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
+ − 3043
$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
+ − 3044
// 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
+ − 3045
$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
+ − 3046
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
+ − 3047
}
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
+ − 3048
125
+ − 3049
// Re-insert untouchable tags
+ − 3050
for ($i = 0;$i < sizeof($matches[1]); $i++)
+ − 3051
{
+ − 3052
$html = str_replace("{DONT_STRIP_ME_NAKED:$seed:$i}", "<{$matches[1][$i]}{$matches[2][$i]}>{$matches[3][$i]}</{$matches[4][$i]}>", $html);
+ − 3053
}
+ − 3054
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
+ − 3055
// Which tags to strip - you can change this if needed
137
+ − 3056
$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
+ − 3057
$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
+ − 3058
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
+ − 3059
// 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
+ − 3060
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
+ − 3061
$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
+ − 3062
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
+ − 3063
{
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
+ − 3064
$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
+ − 3065
}
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
+ − 3066
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
+ − 3067
// 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
+ − 3068
$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
+ − 3069
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
+ − 3070
// 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
+ − 3071
$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
+ − 3072
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
// 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
+ − 3074
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
+ − 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
$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
+ − 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
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
// 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
+ − 3080
$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
+ − 3081
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
+ − 3082
$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
+ − 3083
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
+ − 3084
// 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
+ − 3085
$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
+ − 3086
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
+ − 3087
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
+ − 3088
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
+ − 3089
-->\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
+ − 3090
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
+ − 3091
}
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
+ − 3092
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
+ − 3093
/**
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
+ − 3094
* 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
+ − 3095
* @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
+ − 3096
* @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
+ − 3097
*/
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
+ − 3098
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
+ − 3099
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
+ − 3100
{
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
+ − 3101
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
+ − 3102
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
+ − 3103
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
+ − 3104
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
+ − 3105
$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
+ − 3106
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
+ − 3107
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
+ − 3108
$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
+ − 3109
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
+ − 3110
$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
+ − 3111
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
+ − 3112
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
+ − 3113
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
+ − 3114
{
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
+ − 3115
$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
+ − 3116
}
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
+ − 3117
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
+ − 3118
}
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
+ − 3119
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
+ − 3120
/**
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
+ − 3121
* 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
+ − 3122
* 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
+ − 3123
* @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
+ − 3124
* @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
+ − 3125
*/
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
+ − 3126
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
+ − 3127
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
+ − 3128
{
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
+ − 3129
$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
+ − 3130
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
+ − 3131
// 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
+ − 3132
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
+ − 3133
$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
+ − 3134
$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
+ − 3135
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
+ − 3136
{
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
+ − 3137
$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
+ − 3138
$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
+ − 3139
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
+ − 3140
{
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
+ − 3141
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
+ − 3142
{
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
+ − 3143
$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
+ − 3144
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
+ − 3145
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
+ − 3146
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
+ − 3147
$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
+ − 3148
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
+ − 3149
$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
+ − 3150
}
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
+ − 3151
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
+ − 3152
{
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
+ − 3153
$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
+ − 3154
$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
+ − 3155
}
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
+ − 3156
}
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
+ − 3157
$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
+ − 3158
$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
+ − 3159
}
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
+ − 3160
$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
+ − 3161
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
+ − 3162
// 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
+ − 3163
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
+ − 3164
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
+ − 3165
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
+ − 3166
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
+ − 3167
$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
+ − 3168
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
+ − 3169
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
+ − 3170
}
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
+ − 3171
270
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3172
/**
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3173
* 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
+ − 3174
* @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
+ − 3175
* @return string
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3176
*/
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3177
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3178
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
+ − 3179
{
766
+ − 3180
if ( strstr($range, ':') )
+ − 3181
{
+ − 3182
return parse_ipv6_range_regex($range);
+ − 3183
}
+ − 3184
else
+ − 3185
{
+ − 3186
return parse_ipv4_range_regex($range);
+ − 3187
}
+ − 3188
}
+ − 3189
+ − 3190
/**
+ − 3191
* Parses a valid IPv4 address range into a regular expression.
+ − 3192
* @param string IP range string
+ − 3193
* @return string
+ − 3194
*/
+ − 3195
+ − 3196
function parse_ipv4_range_regex($range)
+ − 3197
{
270
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3198
// 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
+ − 3199
$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
+ − 3200
. '(([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
+ − 3201
. '(([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
+ − 3202
. '(([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
+ − 3203
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
+ − 3204
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3205
return false;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3206
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3207
$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
+ − 3208
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
+ − 3209
$return = '^';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3210
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
+ − 3211
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3212
// alternatives array
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3213
$alts = array();
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3214
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
+ − 3215
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3216
$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
+ − 3217
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3218
else
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3219
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3220
$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
+ − 3221
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3222
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
+ − 3223
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3224
// 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
+ − 3225
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
+ − 3226
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3227
$alts[] = $atom;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3228
continue;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3229
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3230
else
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3231
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3232
// 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
+ − 3233
$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
+ − 3234
if ( !$alt2 )
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3235
return false;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3236
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
+ − 3237
$alts[] = $neutrino;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3238
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3239
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3240
$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
+ − 3241
$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
+ − 3242
// 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
+ − 3243
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
+ − 3244
{
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3245
$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
+ − 3246
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3247
$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
+ − 3248
$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
+ − 3249
$return .= $alts . '\.';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3250
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3251
$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
+ − 3252
$return .= '$';
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3253
return $return;
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3254
}
5bcdee999015
Major fixes to the ban system - large IP match lists don't slow down the server miserably anymore.
Dan
diff
changeset
+ − 3255
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3256
/**
766
+ − 3257
* Parses a valid IPv6 address range into a regular expression.
+ − 3258
* @param string IP range string
+ − 3259
* @return string
+ − 3260
*/
+ − 3261
+ − 3262
function parse_ipv6_range_regex($range)
+ − 3263
{
+ − 3264
$range = strtolower(trim($range));
+ − 3265
$valid = '/^';
+ − 3266
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}):';
+ − 3267
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}):';
+ − 3268
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3269
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3270
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3271
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3272
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4}:|:)?';
+ − 3273
$valid .= '(?:[0-9a-f]{0,4}|[0-9a-f]{1,4}-[0-9a-f]{1,4})$/';
+ − 3274
if ( !preg_match($valid, $range) )
+ − 3275
return false;
+ − 3276
+ − 3277
// expand address range.
+ − 3278
// this takes short ranges like:
+ − 3279
// 2001:470-471:054-b02b::5-bb
+ − 3280
// up to:
+ − 3281
// 2001:0470-0471:0054-b02b:0000:0000:0000:0005-00bb
+ − 3282
$range = explode(':', $range);
+ − 3283
$expanded = '';
+ − 3284
$size = count($range);
+ − 3285
foreach ( $range as $byteset )
+ − 3286
{
+ − 3287
if ( empty($byteset) )
+ − 3288
{
+ − 3289
// ::
+ − 3290
while ( $size < 9 )
+ − 3291
{
+ − 3292
$expanded .= '0000:';
+ − 3293
$size++;
+ − 3294
}
+ − 3295
}
+ − 3296
else
+ − 3297
{
+ − 3298
if ( strstr($byteset, '-') )
+ − 3299
{
+ − 3300
// this is a range
+ − 3301
$sides = explode('-', $byteset);
+ − 3302
foreach ( $sides as &$bytepair )
+ − 3303
{
+ − 3304
while ( strlen($bytepair) < 4 )
+ − 3305
{
+ − 3306
$bytepair = "0$bytepair";
+ − 3307
}
+ − 3308
}
+ − 3309
$byteset = implode('-', $sides);
+ − 3310
}
+ − 3311
else
+ − 3312
{
+ − 3313
while ( strlen($byteset) < 4 )
+ − 3314
{
+ − 3315
$byteset = "0$byteset";
+ − 3316
}
+ − 3317
}
+ − 3318
$expanded .= "$byteset:";
+ − 3319
}
+ − 3320
}
+ − 3321
$expanded = explode(':', rtrim($expanded, ':'));
+ − 3322
+ − 3323
// ready to dive in and start generating range regexes.
+ − 3324
// this has to be pretty optimized... we want to end up with regexes like:
+ − 3325
// range: 54-b12b
+ − 3326
/*
+ − 3327
/005[4-9a-f]|
+ − 3328
00[6-9a-f][0-9a-f]|
+ − 3329
0[1-9a-f][0-9a-f][0-9a-f]|
+ − 3330
[1-9a][0-9a-f][0-9a-f][0-9a-f]|
+ − 3331
b[0-0][0-1][0-9a-f]|
+ − 3332
b0[0-1][0-9a-f]|
+ − 3333
b02[0-9a-b]/x
+ − 3334
*/
+ − 3335
foreach ( $expanded as &$word )
+ − 3336
{
+ − 3337
if ( strstr($word, '-') )
+ − 3338
{
+ − 3339
// oh... damn.
+ − 3340
$word = '(?:' . generate_hex_numeral_range($word) . ')';
+ − 3341
}
+ − 3342
}
+ − 3343
+ − 3344
// return print_r($expanded, true);
+ − 3345
return '^' . implode(':', $expanded) . '$';
+ − 3346
}
+ − 3347
+ − 3348
/**
+ − 3349
* Take a hex numeral range and parse it in to a PCRE.
+ − 3350
* @param string
+ − 3351
* @return string
+ − 3352
* @access private
+ − 3353
*/
+ − 3354
+ − 3355
function generate_hex_numeral_range($word)
+ − 3356
{
+ − 3357
list($low, $high) = explode('-', $word);
+ − 3358
+ − 3359
if ( hexdec($low) > hexdec($high) )
+ − 3360
{
+ − 3361
$_ = $low;
+ − 3362
$low = $high;
+ − 3363
$high = $_;
+ − 3364
unset($_);
+ − 3365
}
+ − 3366
+ − 3367
while ( strlen($low) < strlen($high) )
+ − 3368
{
+ − 3369
$low = "0$low";
+ − 3370
}
+ − 3371
+ − 3372
// trim off everything that's the same
+ − 3373
$trimmed = '';
+ − 3374
$len = strlen($low);
+ − 3375
for ( $i = 0; $i < $len; $i++ )
+ − 3376
{
+ − 3377
if ( $low{0} === $high{0} )
+ − 3378
{
+ − 3379
$trimmed .= $low{0};
+ − 3380
$low = substr($low, 1);
+ − 3381
$high = substr($high, 1);
+ − 3382
}
+ − 3383
else
+ − 3384
{
+ − 3385
break;
+ − 3386
}
+ − 3387
}
+ − 3388
+ − 3389
$len = strlen($high);
+ − 3390
if ( $len == 1 )
+ − 3391
{
+ − 3392
// this does happen sometimes, so we can save a bit of CPU power here.
+ − 3393
return $trimmed . __hexdigitrange($low, $high);
+ − 3394
}
+ − 3395
+ − 3396
$return = '';
+ − 3397
// lower half
+ − 3398
for ( $i = $len - 1; $i > 0; $i-- )
+ − 3399
{
+ − 3400
if ( $low{$i} == 'f' )
+ − 3401
continue;
+ − 3402
$return .= $trimmed;
+ − 3403
for ( $j = 0; $j < $len; $j++ )
+ − 3404
{
+ − 3405
if ( $j < $i )
+ − 3406
{
+ − 3407
$return .= $low{$j};
+ − 3408
}
+ − 3409
else if ( $j == $i && ( $i == $len - 1 || $low{$j} == 'f' ) )
+ − 3410
{
+ − 3411
$return .= __hexdigitrange($low{$j}, 'f');
+ − 3412
}
+ − 3413
else if ( $j == $i && $i != $len - 1 )
+ − 3414
{
+ − 3415
$return .= __hexdigitrange(dechex(hexdec($low{$j}) + 1), 'f');
+ − 3416
}
+ − 3417
else
+ − 3418
{
+ − 3419
$return .= __hexdigitrange('0', 'f');
+ − 3420
}
+ − 3421
}
+ − 3422
$return .= '|';
+ − 3423
}
+ − 3424
// middle block
+ − 3425
if ( hexdec($low{0}) + 1 < hexdec($high{0}) )
+ − 3426
{
+ − 3427
if ( hexdec($low{0}) + 1 < hexdec($high{0}) - 1 )
+ − 3428
$return .= $trimmed . __hexdigitrange(dechex(hexdec($low{0}) + 1), dechex(hexdec($high{0}) - 1));
+ − 3429
else
+ − 3430
$return .= $trimmed . __hexdigitrange($low{0}, $high{0});
+ − 3431
if ( $len - 1 > 0 )
+ − 3432
$return .= '[0-9a-f]{' . ( $len - 1 ) . '}|';
+ − 3433
}
+ − 3434
// higher half
+ − 3435
for ( $i = 1; $i < $len; $i++ )
+ − 3436
{
+ − 3437
if ( $high{$i} == '0' )
+ − 3438
continue;
+ − 3439
$return .= $trimmed;
+ − 3440
for ( $j = 0; $j < $len; $j++ )
+ − 3441
{
+ − 3442
if ( $j < $i )
+ − 3443
{
+ − 3444
$return .= $high{$j};
+ − 3445
}
+ − 3446
else if ( $j == $i && ( $i == $len - 1 || $high{$j} == '0' ) )
+ − 3447
{
+ − 3448
$return .= __hexdigitrange('0', $high{$j});
+ − 3449
}
+ − 3450
else if ( $j == $i && $i != $len - 1 )
+ − 3451
{
+ − 3452
$return .= __hexdigitrange('0', dechex(hexdec($high{$j}) - 1));
+ − 3453
}
+ − 3454
else if ( $j > $i )
+ − 3455
{
+ − 3456
$return .= __hexdigitrange('0', 'f');
+ − 3457
}
+ − 3458
else
+ − 3459
{
+ − 3460
die("I don't know what to do! i $i j $j");
+ − 3461
}
+ − 3462
}
+ − 3463
$return .= '|';
+ − 3464
}
+ − 3465
+ − 3466
return rtrim($return, '|');
+ − 3467
}
+ − 3468
+ − 3469
function __hexdigitrange($low, $high)
+ − 3470
{
+ − 3471
if ( $low == $high )
+ − 3472
return $low;
+ − 3473
if ( empty($low) )
+ − 3474
$low = '0';
+ − 3475
+ − 3476
$low_type = ( preg_match('/[0-9]/', $low) ) ? 'num' : 'alph';
+ − 3477
$high_type = ( preg_match('/[0-9]/', $high) ) ? 'num' : 'alph';
+ − 3478
if ( ( $low_type == 'num' && $high_type == 'num') || ( $low_type == 'alph' && $high_type == 'alph' ) )
+ − 3479
{
+ − 3480
return "[$low-$high]";
+ − 3481
}
+ − 3482
else if ( $low_type == 'num' && $high_type == 'alph' )
+ − 3483
{
+ − 3484
$ret = '[';
+ − 3485
+ − 3486
if ( $low == '9' )
+ − 3487
$ret .= '9';
+ − 3488
else
+ − 3489
$ret .= "$low-9";
+ − 3490
if ( $high == 'a' )
+ − 3491
$ret .= 'a';
+ − 3492
else
+ − 3493
$ret .= "a-$high";
+ − 3494
+ − 3495
$ret .= "]";
+ − 3496
return $ret;
+ − 3497
}
+ − 3498
else if ( $low_type == 'alph' && $high_type == 'num' )
+ − 3499
{
+ − 3500
// ???? this should never happen
+ − 3501
return __hexdigitrange($high, $low);
+ − 3502
}
+ − 3503
}
+ − 3504
+ − 3505
/**
504
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3506
* 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
+ − 3507
* @param string E-mail address
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3508
* @return bool
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3509
*/
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3510
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3511
function check_email_address($email)
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3512
{
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3513
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
+ − 3514
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
+ − 3515
}
bc8e0e9ee01d
Added support for embedding language data into plugins; updated all version numbers on plugin files
Dan
diff
changeset
+ − 3516
132
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3517
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
+ − 3518
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3519
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
+ − 3520
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3521
return -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3522
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3523
$len = strlen($password);
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3524
$score = $len - 7;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3525
return $score;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3526
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3527
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3528
/**
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3529
* 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
+ − 3530
* 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
+ − 3531
* 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
+ − 3532
* @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
+ − 3533
* @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
+ − 3534
* @return int
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3535
*/
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3536
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
+ − 3537
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
+ − 3538
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3539
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
+ − 3540
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3541
return -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3542
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3543
$score = 0;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3544
$debug = array();
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3545
// length check
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3546
$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
+ − 3547
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3548
$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
+ − 3549
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3550
$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
+ − 3551
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3552
$score += $lenscore;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3553
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3554
$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
+ − 3555
$has_symbols = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3556
$has_numbers = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3557
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3558
// 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
+ − 3559
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
+ − 3560
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3561
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3562
$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
+ − 3563
$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
+ − 3564
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3565
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3566
// contains symbols
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3567
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
+ − 3568
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3569
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3570
$has_symbols = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3571
$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
+ − 3572
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3573
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3574
// contains numbers
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3575
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
+ − 3576
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3577
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3578
$has_numbers = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3579
$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
+ − 3580
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3581
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3582
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
+ − 3583
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3584
// 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
+ − 3585
$score += 4;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3586
$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
+ − 3587
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3588
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
+ − 3589
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3590
// 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
+ − 3591
$score += 2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3592
$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
+ − 3593
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3594
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
+ − 3595
( $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
+ − 3596
( $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
+ − 3597
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3598
// 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
+ − 3599
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3600
$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
+ − 3601
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3602
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
+ − 3603
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3604
// 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
+ − 3605
$score += -4;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3606
$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
+ − 3607
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3608
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
+ − 3609
( !$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
+ − 3610
( !$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
+ − 3611
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3612
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3613
$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
+ − 3614
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3615
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
+ − 3616
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3617
$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
+ − 3618
$score += -3;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3619
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3620
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3621
//
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3622
// Repetition
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3623
// 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
+ − 3624
//
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3625
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3626
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
+ − 3627
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3628
$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
+ − 3629
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3630
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3631
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
+ − 3632
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3633
$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
+ − 3634
$score += -1;
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
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
+ − 3637
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3638
$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
+ − 3639
$score += 1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3640
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3641
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3642
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
+ − 3643
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3644
$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
+ − 3645
$score += -2;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3646
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3647
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
+ − 3648
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3649
$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
+ − 3650
$score += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3651
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3652
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
+ − 3653
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3654
$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
+ − 3655
$score += -1;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3656
}
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
// 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
+ − 3659
$prev_char = '';
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3660
$warn = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3661
$loss = 0;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3662
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
+ − 3663
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3664
$chr = $password{$i};
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3665
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
+ − 3666
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3667
$loss += -1;
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
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
+ − 3670
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3671
$warn = true;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3672
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3673
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
+ − 3674
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3675
$warn = false;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3676
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3677
$prev_char = $chr;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3678
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3679
if ( $loss < 0 )
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3680
{
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3681
$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
+ − 3682
$score += $loss;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3683
// 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
+ − 3684
if ( $score < -10 )
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
$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
+ − 3687
$score = -10;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3688
}
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
return $score;
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3692
}
0ae1b281a884
[sync only] Minor display change in Special:About_Enano; added initial PHP function for password strength testing
Dan
diff
changeset
+ − 3693
191
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3694
/**
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3695
* 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
+ − 3696
* @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
+ − 3697
* @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
+ − 3698
*/
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3699
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3700
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
+ − 3701
{
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3702
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
+ − 3703
$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
+ − 3704
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
+ − 3705
$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
+ − 3706
$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
+ − 3707
}
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3708
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
+ − 3709
/**
542
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3710
* 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
+ − 3711
* @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
+ − 3712
*/
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3713
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3714
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
+ − 3715
{
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3716
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
+ − 3717
$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
+ − 3718
$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
+ − 3719
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
+ − 3720
}
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3721
5841df0ab575
Added ETag support and increased caching settings to try and speed the system up. Result of a YSlow audit.
Dan
diff
changeset
+ − 3722
/**
209
+ − 3723
* Installs a language.
+ − 3724
* @param string The ISO-639-3 identifier for the language. Maximum of 6 characters, usually 3.
+ − 3725
* @param string The name of the language in English (Spanish)
+ − 3726
* @param string The name of the language natively (Español)
+ − 3727
* @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
+ − 3728
*/
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3729
209
+ − 3730
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
+ − 3731
{
209
+ − 3732
global $db, $session, $paths, $template, $plugins; // Common objects
+ − 3733
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3734
$q = $db->sql_query('SELECT 1 FROM '.table_prefix.'language WHERE lang_code = \'' . $db->escape($lang_code) . '\';');
209
+ − 3735
if ( !$q )
+ − 3736
$db->_die('functions.php - checking for language existence');
+ − 3737
+ − 3738
if ( $db->numrows() > 0 )
+ − 3739
// Language already exists
+ − 3740
return false;
+ − 3741
+ − 3742
$q = $db->sql_query('INSERT INTO ' . table_prefix . 'language(lang_code, lang_name_default, lang_name_native)
+ − 3743
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
+ − 3744
\'' . $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
+ − 3745
\'' . $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
+ − 3746
\'' . $db->escape($lang_name_local) . '\'
209
+ − 3747
);');
+ − 3748
if ( !$q )
+ − 3749
$db->_die('functions.php - installing language');
+ − 3750
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3751
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
+ − 3752
{
371
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3753
// 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
+ − 3754
// 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
+ − 3755
// 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
+ − 3756
$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
+ − 3757
}
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3758
else
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3759
{
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3760
$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
+ − 3761
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
+ − 3762
{
dc6026376919
Improved compatibility with PostgreSQL and fixed a number of installer bugs; fixed missing "meta" category declaration in language files
Dan
diff
changeset
+ − 3763
$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
+ − 3764
}
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
+ − 3765
}
209
+ − 3766
+ − 3767
// Do we also need to install a language file?
+ − 3768
if ( is_string($lang_file) && file_exists($lang_file) )
+ − 3769
{
+ − 3770
$lang = new Language($lang_id);
+ − 3771
$lang->import($lang_file);
+ − 3772
}
+ − 3773
else if ( is_string($lang_file) && !file_exists($lang_file) )
+ − 3774
{
+ − 3775
echo '<b>Notice:</b> Can\'t load language file, so the specified language wasn\'t fully installed.<br />';
+ − 3776
return false;
+ − 3777
}
+ − 3778
return true;
191
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3779
}
3dbe848431b0
Added a cron framework. Currently tasks will not be run; will implement into templates in next commit
Dan
diff
changeset
+ − 3780
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
+ − 3781
/**
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
+ − 3782
* 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
+ − 3783
* @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
+ − 3784
*/
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
+ − 3785
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
+ − 3786
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
+ − 3787
{
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
+ − 3788
// 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
+ − 3789
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
+ − 3790
// 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
+ − 3791
$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
+ − 3792
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
+ − 3793
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
+ − 3794
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
+ − 3795
$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
+ − 3796
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
+ − 3797
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
+ − 3798
{
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
+ − 3799
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
+ − 3800
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
+ − 3801
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
+ − 3802
{
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
+ − 3803
// 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
+ − 3804
$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
+ − 3805
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
+ − 3806
// 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
+ − 3807
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
+ − 3808
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
+ − 3809
// 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
+ − 3810
$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
+ − 3811
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
+ − 3812
$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
+ − 3813
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
+ − 3814
{
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
+ − 3815
$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
+ − 3816
'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
+ − 3817
'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
+ − 3818
'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
+ − 3819
);
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
+ − 3820
}
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
+ − 3821
}
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
+ − 3822
}
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
+ − 3823
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
+ − 3824
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
+ − 3825
}
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
+ − 3826
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
+ − 3827
/**
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
+ − 3828
* 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
+ − 3829
* 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
+ − 3830
* 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
+ − 3831
* @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
+ − 3832
* @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
+ − 3833
* @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
+ − 3834
* @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
+ − 3835
* @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
+ − 3836
* @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
+ − 3837
*/
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3838
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3839
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
+ − 3840
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3841
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
+ − 3842
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3843
if ( !is_int($width) || !is_int($height) )
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3844
throw new Exception('Invalid height or width.');
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
+ − 3845
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3846
if ( !file_exists($in_file) )
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3847
throw new Exception('Input file does not exist');
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
+ − 3848
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3849
$in_file_sh = escapeshellarg($in_file);
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3850
$out_file_sh = 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
+ − 3851
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3852
if ( file_exists($out_file) && !$unlink )
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3853
throw new Exception('Refusing to write output file as it already exists and $unlink was not specified.');
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
+ − 3854
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
+ − 3855
@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
+ − 3856
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
+ − 3857
// couldn't unlink (delete) the output file
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3858
throw new Exception('Failed to delete existing output 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
+ − 3859
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3860
$file_ext = strtolower(substr($in_file, ( strrpos($in_file, '.') + 1)));
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
+ − 3861
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
+ − 3862
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3863
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
+ − 3864
$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
+ − 3865
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
+ − 3866
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
+ − 3867
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
+ − 3868
$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
+ − 3869
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
+ − 3870
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
+ − 3871
$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
+ − 3872
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
+ − 3873
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
+ − 3874
$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
+ − 3875
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
+ − 3876
default:
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3877
throw new Exception('Invalid extension of input 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
+ − 3878
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3879
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3880
$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
+ − 3881
$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
+ − 3882
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
+ − 3883
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
+ − 3884
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
+ − 3885
);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3886
$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
+ − 3887
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
+ − 3888
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
+ − 3889
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
+ − 3890
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
+ − 3891
);
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3892
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
+ − 3893
{
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3894
if ( !preg_match('/^([\/A-z0-9:\. _-]+)$/', $magick_path) )
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
+ − 3895
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3896
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
+ − 3897
}
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3898
$cmdline = "$magick_path $in_file_sh -resize \"{$width}x{$height}>\" $out_file_sh";
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
+ − 3899
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
+ − 3900
if ( !file_exists($out_file) )
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3901
throw new Exception('ImageMagick: did not produce output image 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
+ − 3902
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
+ − 3903
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3904
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
+ − 3905
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3906
@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
+ − 3907
if ( !$width_orig || !$height_orig )
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3908
throw new Exception('GD: Could not get height and width of input 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
+ − 3909
// 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
+ − 3910
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3911
$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
+ − 3912
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
+ − 3913
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3914
// 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
+ − 3915
$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
+ − 3916
$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
+ − 3917
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3918
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
+ − 3919
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3920
// 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
+ − 3921
$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
+ − 3922
$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
+ − 3923
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3924
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
+ − 3925
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3926
$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
+ − 3927
$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
+ − 3928
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3929
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
+ − 3930
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3931
// 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
+ − 3932
$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
+ − 3933
$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
+ − 3934
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3935
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3936
$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
+ − 3937
if ( !$newimage )
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3938
throw new Exception('GD: Request to create new truecolor image refused.');
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
+ − 3939
$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
+ − 3940
if ( !$oldimage )
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3941
throw new Exception('GD: Request to load input image file failed.');
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
+ − 3942
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will be used. No UI changes to speak of, but a check in the installer will be added in a later commit
Dan
diff
changeset
+ − 3943
// 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
+ − 3944
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
+ − 3945
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
// Get output format
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3947
$out_ext = strtolower(substr($out_file, ( strrpos($out_file, '.') + 1)));
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
+ − 3948
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
+ − 3949
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
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
+ − 3951
$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
+ − 3952
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
+ − 3953
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
+ − 3954
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
+ − 3955
$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
+ − 3956
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
+ − 3957
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
+ − 3958
$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
+ − 3959
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
+ − 3960
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
+ − 3961
$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
+ − 3962
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
+ − 3963
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
+ − 3964
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
+ − 3965
imagedestroy($oldimage);
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3966
throw new Exception('GD: Invalid extension of output 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
+ − 3967
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
// 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
+ − 3970
$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
+ − 3971
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
// 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
+ − 3973
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
+ − 3974
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
+ − 3975
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
// 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
+ − 3977
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
+ − 3978
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
// 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
+ − 3980
$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
+ − 3981
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
+ − 3982
{
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
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
+ − 3984
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
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
+ − 3986
return true;
898
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3987
c75754f5b1da
When changing namespace of a File: page, associated files are now deleted. Also fixed some issues with image scaling.
Dan
diff
changeset
+ − 3988
throw new Exception('Failed to find an appropriate method for scaling.');
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
+ − 3989
}
3daa715e0f69
Alternate scaling using GD is implemented now; images will be scaled with ImageMagick if enabled and working; else, GD will 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
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 3991
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 3992
* 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
+ − 3993
* 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
+ − 3994
* @param string Path to GIF file
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 3995
* @return bool If animated, returns true
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 3996
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 3997
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 3998
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 3999
function is_gif_animated($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4000
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4001
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4002
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4003
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4004
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4005
$str_loc = 0;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4006
$count = 0;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4007
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
+ − 4008
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4009
$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
+ − 4010
if ( $where1 === false )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4011
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4012
break;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4013
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4014
else
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4015
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4016
$str_loc = $where1 + 1;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4017
$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
+ − 4018
if ( $where2 === false )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4019
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4020
break;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4021
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4022
else
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4023
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4024
if ( $where1 + 8 == $where2 )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4025
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4026
$count++;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4027
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4028
$str_loc = $where2 + 1;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4029
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4030
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4031
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4032
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4033
return ( $count > 1 ) ? true : false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4034
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4035
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4036
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4037
* 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
+ − 4038
* @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
+ − 4039
* @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
+ − 4040
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4041
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4042
function gif_get_dimensions($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4043
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4044
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4045
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4046
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4047
if ( strlen($filecontents) < 10 )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4048
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4049
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4050
$width = substr($filecontents, 6, 2);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4051
$height = substr($filecontents, 8, 2);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4052
$width = unpack('v', $width);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4053
$height = unpack('v', $height);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4054
return array($width[1], $height[1]);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4055
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4056
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4057
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4058
* 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
+ − 4059
* @param string Path to PNG file.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4060
* @return bool If animated, returns true
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4061
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4062
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4063
function is_png_animated($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4064
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4065
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4066
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4067
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4068
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4069
$parsed = parse_png($filecontents);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4070
if ( !$parsed )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4071
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4072
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4073
if ( !isset($parsed['fdAT']) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4074
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4075
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4076
if ( count($parsed['fdAT']) > 1 )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4077
return true;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4078
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4079
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4080
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4081
* 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
+ − 4082
* @param string Path to PNG file
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4083
* @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
+ − 4084
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4085
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4086
function png_get_dimensions($filename)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4087
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4088
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4089
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4090
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4091
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4092
$parsed = parse_png($filecontents);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4093
if ( !$parsed )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4094
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4095
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4096
$ihdr_stream = $parsed['IHDR'][0];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4097
$width = substr($ihdr_stream, 0, 4);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4098
$height = substr($ihdr_stream, 4, 4);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4099
$width = unpack('N', $width);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4100
$height = unpack('N', $height);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4101
$x = $width[1];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4102
$y = $height[1];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4103
return array($x, $y);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4104
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4105
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4106
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4107
* 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
+ − 4108
* @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
+ − 4109
* @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
+ − 4110
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4111
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4112
function parse_png($data)
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
// 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
+ − 4115
$header = substr($data, 0, 8);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4116
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
+ − 4117
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4118
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4119
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4120
$return = array();
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4121
$data = substr($data, 8);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4122
while ( strlen($data) > 0 )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4123
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4124
$chunklen_bin = substr($data, 0, 4);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4125
$chunk_type = substr($data, 4, 4);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4126
$chunklen = unpack('N', $chunklen_bin);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4127
$chunklen = $chunklen[1];
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4128
$chunk_data = substr($data, 8, $chunklen);
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
// 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
+ − 4131
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
+ − 4132
break;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4133
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4134
if ( !isset($return[$chunk_type]) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4135
$return[$chunk_type] = array();
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4136
$return[$chunk_type][] = $chunk_data;
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
$offset_next = 4 // Length
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4139
+ 4 // Type
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4140
+ $chunklen // Data
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4141
+ 4; // CRC
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4142
$data = substr($data, $offset_next);
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
return $return;
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
* 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
+ − 4149
* @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
+ − 4150
* @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
+ − 4151
* @license GNU General Public License
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4152
* @copyright Copyright Evan Hunter 2004
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4153
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4154
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4155
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
+ − 4156
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4157
// 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
+ − 4158
$Outputarray = array( );
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
//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
+ − 4161
$i = 0;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4162
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
+ − 4163
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4164
$i++;
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
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4167
// 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
+ − 4168
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
+ − 4169
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4170
// 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
+ − 4171
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4172
$data = $jpeg_header_data[$i]['SegData'];
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
// First byte is Bits per component
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4175
$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
+ − 4176
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4177
// 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
+ − 4178
$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
+ − 4179
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4180
// 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
+ − 4181
$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
+ − 4182
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4183
// Sixth byte is number of components
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4184
$numcomponents = ord( $data{ 5 } );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4185
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4186
// 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
+ − 4187
for( $i = 0; $i < $numcomponents; $i++ )
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
$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
+ − 4190
'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
+ − 4191
'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
+ − 4192
'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
+ − 4193
}
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
else
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
// 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
+ − 4198
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4199
}
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
return $Outputarray;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4202
}
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
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4205
* 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
+ − 4206
* @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
+ − 4207
* @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
+ − 4208
* @license GNU General Public License
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4209
* @copyright Copyright Evan Hunter 2004
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4210
*/
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
function get_jpeg_header_data( $filename )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4213
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4214
// 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
+ − 4215
// 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
+ − 4216
// 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
+ − 4217
$filehnd = @fopen($filename, 'rb');
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4218
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4219
// Check if the file opened successfully
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4220
if ( ! $filehnd )
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
// Could't open the file - exit
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4223
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4224
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4225
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
// Read the first two characters
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4228
$data = fread( $filehnd, 2 );
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
// 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
+ − 4231
if ( $data != "\xFF\xD8" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4232
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4233
// 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
+ − 4234
fclose($filehnd);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4235
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4236
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4237
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4238
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4239
// Read the third character
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4240
$data = fread( $filehnd, 2 );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4241
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4242
// 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
+ − 4243
if ( $data{0} != "\xFF" )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4244
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4245
// 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
+ − 4246
fclose($filehnd);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4247
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4248
}
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
// 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
+ − 4251
$hit_compressed_image_data = FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4252
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
// 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
+ − 4255
// 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
+ − 4256
// 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
+ − 4257
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4258
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
+ − 4259
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4260
// Found a segment to look at.
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4261
// 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
+ − 4262
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
+ − 4263
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4264
// Segment isn't a Restart marker
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4265
// Read the next two bytes (size)
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4266
$sizestr = fread( $filehnd, 2 );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4267
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4268
// 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
+ − 4269
$decodedsize = unpack ("nsize", $sizestr);
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
// 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
+ − 4272
$segdatastart = ftell( $filehnd );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4273
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4274
// 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
+ − 4275
$segdata = fread( $filehnd, $decodedsize['size'] - 2 );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4276
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4277
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4278
// 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
+ − 4279
$headerdata[] = array( "SegType" => ord($data{1}),
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4280
"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
+ − 4281
"SegDataStart" => $segdatastart,
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4282
"SegData" => $segdata );
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4283
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4284
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4285
// 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
+ − 4286
if ( $data{1} == "\xDA" )
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
// 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
+ − 4289
$hit_compressed_image_data = TRUE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4290
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4291
else
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
// 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
+ − 4294
$data = fread( $filehnd, 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
// 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
+ − 4297
if ( $data{0} != "\xFF" )
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
// 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
+ − 4300
fclose($filehnd);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4301
return FALSE;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4302
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4303
}
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
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4306
// Close File
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4307
fclose($filehnd);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4308
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4309
// Return the header data retrieved
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4310
return $headerdata;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4311
}
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
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4314
* 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
+ − 4315
* @param string JPEG file to check
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4316
* @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
+ − 4317
*/
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
function jpg_get_dimensions($filename)
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
if ( !file_exists($filename) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4322
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4323
echo "Doesn't exist<br />";
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4324
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4325
}
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
$headers = get_jpeg_header_data($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4328
if ( !$headers )
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
echo "Bad headers<br />";
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4331
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4332
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4333
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4334
$metadata = get_jpeg_intrinsic_values($headers);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4335
if ( !$metadata )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4336
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4337
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
+ − 4338
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4339
}
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
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
+ − 4342
{
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4343
echo "No metadata<br />";
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4344
return false;
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
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4347
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
+ − 4348
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4349
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4350
/**
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4351
* 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
+ − 4352
* @param int User ID
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4353
* @param string Image type - must be one of jpg, png, or gif.
621
+ − 4354
* @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
+ − 4355
* @return string
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4356
*/
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4357
621
+ − 4358
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
+ − 4359
{
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
+ − 4360
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
+ − 4361
'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
+ − 4362
'gif' => IMAGE_TYPE_GIF,
621
+ − 4363
'jpg' => IMAGE_TYPE_JPG,
+ − 4364
'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
+ − 4365
);
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
+ − 4366
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4367
if ( !is_int($user_id) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4368
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
+ − 4369
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
+ − 4370
return false;
621
+ − 4371
+ − 4372
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
+ − 4373
{
621
+ − 4374
if ( $user_email )
+ − 4375
{
+ − 4376
return make_gravatar_url($user_email);
+ − 4377
}
+ − 4378
}
+ − 4379
else
+ − 4380
{
+ − 4381
$avi_relative_path = '/' . getConfig('avatar_directory') . '/' . $user_id . '.' . $avi_type;
+ − 4382
if ( !file_exists(ENANO_ROOT . $avi_relative_path) )
+ − 4383
{
+ − 4384
return '';
+ − 4385
}
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
+ − 4386
}
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
+ − 4387
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
+ − 4388
$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
+ − 4389
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
+ − 4390
$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
+ − 4391
$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
+ − 4392
$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
+ − 4393
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
+ − 4394
// 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
+ − 4395
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
+ − 4396
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4397
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4398
/**
621
+ − 4399
* Generates a URL to the Gravatar for a user based on his/her e-mail address.
+ − 4400
* @param string E-mail address
+ − 4401
* @param int Size - defaults to site-wide limits
+ − 4402
* @return string URL
+ − 4403
*/
+ − 4404
+ − 4405
function make_gravatar_url($email, $size = false)
+ − 4406
{
+ − 4407
$email = md5($email);
+ − 4408
+ − 4409
// gravatar parameters
+ − 4410
if ( $size )
+ − 4411
{
+ − 4412
$max_size = intval($size);
+ − 4413
}
+ − 4414
else
+ − 4415
{
+ − 4416
$max_x = intval(getConfig('avatar_max_width', '150'));
+ − 4417
$max_y = intval(getConfig('avatar_max_height', '150'));
+ − 4418
// ?s=
+ − 4419
$max_size = ( $max_x > $max_y ) ? $max_y : $max_x;
+ − 4420
}
+ − 4421
+ − 4422
// ?r=
+ − 4423
$rating = getConfig('gravatar_rating', 'g');
+ − 4424
+ − 4425
// final URL
+ − 4426
$url = "http://www.gravatar.com/avatar/$email?r=$rating&s=$max_size";
+ − 4427
+ − 4428
return $url;
+ − 4429
}
+ − 4430
+ − 4431
/**
328
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4432
* 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
+ − 4433
* @param string Path to image file
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4434
* @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
+ − 4435
*/
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
function get_image_filetype($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
$filecontents = @file_get_contents($filename);
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4440
if ( empty($filecontents) )
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4441
return false;
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
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
+ − 4444
return 'png';
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
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
+ − 4447
return 'gif';
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
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
+ − 4450
return 'jpg';
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4451
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4452
return false;
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4453
}
dc838fd61a06
Added initial avatar support. Currently rather feature complete except for admin controls for avatar.
Dan
diff
changeset
+ − 4454
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
+ − 4455
/**
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
+ − 4456
* 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
+ − 4457
* @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
+ − 4458
*/
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
+ − 4459
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
+ − 4460
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
+ − 4461
{
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
+ − 4462
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
+ − 4463
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
+ − 4464
$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
+ − 4465
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
+ − 4466
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
+ − 4467
}
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
+ − 4468
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
+ − 4469
/**
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
+ − 4470
* 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
+ − 4471
* @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
+ − 4472
* @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
+ − 4473
*/
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
+ − 4474
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
+ − 4475
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
+ − 4476
{
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
+ − 4477
/*
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
+ − 4478
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
+ − 4479
{
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
+ − 4480
// 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
+ − 4481
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
+ − 4482
}
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
+ − 4483
*/
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
+ − 4484
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
+ − 4485
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
+ − 4486
}
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
+ − 4487
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
+ − 4488
/**
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
+ − 4489
* 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
+ − 4490
* @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
+ − 4491
* @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
+ − 4492
*/
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
+ − 4493
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
+ − 4494
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
+ − 4495
{
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
+ − 4496
/*
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
+ − 4497
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
+ − 4498
{
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
+ − 4499
// 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
+ − 4500
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
+ − 4501
}
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
+ − 4502
*/
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
+ − 4503
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
+ − 4504
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
+ − 4505
}
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
+ − 4506
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
+ − 4507
/**
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
+ − 4508
* 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
+ − 4509
* @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
+ − 4510
* @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
+ − 4511
*/
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
+ − 4512
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
+ − 4513
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
+ − 4514
{
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
+ − 4515
// 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
+ − 4516
$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
+ − 4517
// 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
+ − 4518
'#^\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
+ − 4519
// 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
+ − 4520
'#^\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
+ − 4521
// 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
+ − 4522
'#/\*(.+)\*/\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
+ − 4523
), '', $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
+ − 4524
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
+ − 4525
$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
+ − 4526
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
+ − 4527
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
+ − 4528
}
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
+ − 4529
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
+ − 4530
/**
519
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4531
* 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
+ − 4532
* @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
+ − 4533
* @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
+ − 4534
*/
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4535
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4536
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
+ − 4537
{
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4538
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
+ − 4539
}
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4540
94214ec0871c
Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
diff
changeset
+ − 4541
/**
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
+ − 4542
* 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
+ − 4543
*/
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
+ − 4544
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
+ − 4545
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
+ − 4546
{
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
+ − 4547
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
+ − 4548
$_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
+ − 4549
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
+ − 4550
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
+ − 4551
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
+ − 4552
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
+ − 4553
$_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
+ − 4554
'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
+ − 4555
'time' => microtime_float(),
424
+ − 4556
'backtrace' => false,
+ − 4557
'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
+ − 4558
);
424
+ − 4559
if ( function_exists('memory_get_usage') )
+ − 4560
{
+ − 4561
$_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
+ − 4562
}
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
+ − 4563
}
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
+ − 4564
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
+ − 4565
/**
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
+ − 4566
* 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
+ − 4567
* @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
+ − 4568
* @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
+ − 4569
*/
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
+ − 4570
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
+ − 4571
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
+ − 4572
{
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
+ − 4573
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
+ − 4574
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
+ − 4575
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
+ − 4576
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
+ − 4577
$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
+ − 4578
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
+ − 4579
{
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
+ − 4580
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
+ − 4581
}
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
+ − 4582
$_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
+ − 4583
'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
+ − 4584
'time' => microtime_float(),
424
+ − 4585
'backtrace' => $backtrace,
+ − 4586
'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
+ − 4587
);
424
+ − 4588
if ( function_exists('memory_get_usage') )
+ − 4589
{
+ − 4590
$_profiler[ count($_profiler) - 1 ]['mem'] = memory_get_usage();
+ − 4591
}
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
+ − 4592
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
+ − 4593
}
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
+ − 4594
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
+ − 4595
/**
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
+ − 4596
* 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
+ − 4597
* @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
+ − 4598
*/
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
+ − 4599
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
+ − 4600
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
+ − 4601
{
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
+ − 4602
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
+ − 4603
}
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
+ − 4604
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
+ − 4605
/**
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
+ − 4606
* 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
+ − 4607
* @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
+ − 4608
*/
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
+ − 4609
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
+ − 4610
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
+ − 4611
{
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
+ − 4612
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
+ − 4613
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
+ − 4614
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
+ − 4615
$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
+ − 4616
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
+ − 4617
$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
+ − 4618
$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
+ − 4619
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
+ − 4620
$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
+ − 4621
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
+ − 4622
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
+ − 4623
{
592
+ − 4624
// $time_since_last = $entry['time'] - $time_last;
+ − 4625
// if ( $time_since_last < 0.01 )
+ − 4626
// continue;
+ − 4627
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4628
$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
+ − 4629
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4630
$html .= '<tr>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4631
$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
+ − 4632
$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
+ − 4633
$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
+ − 4634
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
$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
+ − 4636
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4637
$html .= '<tr>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4638
$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
+ − 4639
$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
+ − 4640
$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
+ − 4641
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
$time = $entry['time'] - $time_last;
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4643
if ( $time < 0.0001 )
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4644
$time = 'Marginal';
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4645
else
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4646
$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
+ − 4647
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4648
$html .= '<tr>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4649
$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
+ − 4650
$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
+ − 4651
$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
+ − 4652
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
+ − 4653
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
+ − 4654
{
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4655
$html .= '<tr>' . "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4656
$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
+ − 4657
$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
+ − 4658
$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
+ − 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
424
+ − 4661
if ( $entry['mem'] )
+ − 4662
{
+ − 4663
$html .= '<tr>' . "\n";
+ − 4664
$html .= ' <td class="row2">Total mem usage:</td>' . "\n";
+ − 4665
$html .= ' <td class="row1">' . htmlspecialchars($entry['mem']) . ' (bytes)</td>' . "\n";
+ − 4666
$html .= '</tr>' . "\n";
+ − 4667
}
+ − 4668
382
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4669
$html .= "\n";
2ccb55995aef
Profiling enabled for RenderMan's wikiformat routine; [minor] made HTML from profiler more pretty
Dan
diff
changeset
+ − 4670
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
+ − 4671
$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
+ − 4672
}
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
+ − 4673
$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
+ − 4674
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
+ − 4675
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
+ − 4676
}
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
+ − 4677
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
+ − 4678
// 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
+ − 4679
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
+ − 4680
376
+ − 4681
/**
+ − 4682
* Returns the number of times a character occurs in a given string.
+ − 4683
* @param string Haystack
+ − 4684
* @param string Needle
+ − 4685
* @return int
+ − 4686
*/
+ − 4687
+ − 4688
function get_char_count($string, $char)
+ − 4689
{
+ − 4690
$char = substr($char, 0, 1);
+ − 4691
$count = 0;
+ − 4692
for ( $i = 0; $i < strlen($string); $i++ )
+ − 4693
{
+ − 4694
if ( $string{$i} == $char )
+ − 4695
$count++;
+ − 4696
}
+ − 4697
return $count;
+ − 4698
}
+ − 4699
+ − 4700
/**
+ − 4701
* Returns the number of lines in a string.
+ − 4702
* @param string String to check
+ − 4703
* @return int
+ − 4704
*/
+ − 4705
+ − 4706
function get_line_count($string)
+ − 4707
{
+ − 4708
return ( get_char_count($string, "\n") ) + 1;
+ − 4709
}
+ − 4710
481
+ − 4711
if ( !function_exists('sys_get_temp_dir') )
+ − 4712
{
+ − 4713
// Based on http://www.phpit.net/
+ − 4714
// article/creating-zip-tar-archives-dynamically-php/2/
+ − 4715
/**
+ − 4716
* Attempt to get the system's temp directory.
+ − 4717
* @return string or bool false on failure
+ − 4718
*/
+ − 4719
+ − 4720
function sys_get_temp_dir()
+ − 4721
{
+ − 4722
// Try to get from environment variable
+ − 4723
if ( !empty($_ENV['TMP']) )
+ − 4724
{
+ − 4725
return realpath( $_ENV['TMP'] );
+ − 4726
}
+ − 4727
else if ( !empty($_ENV['TMPDIR']) )
+ − 4728
{
+ − 4729
return realpath( $_ENV['TMPDIR'] );
+ − 4730
}
+ − 4731
else if ( !empty($_ENV['TEMP']) )
+ − 4732
{
+ − 4733
return realpath( $_ENV['TEMP'] );
+ − 4734
}
+ − 4735
+ − 4736
// Detect by creating a temporary file
+ − 4737
else
+ − 4738
{
+ − 4739
// Try to use system's temporary directory
+ − 4740
// as random name shouldn't exist
+ − 4741
$temp_file = tempnam( md5(uniqid(rand(), TRUE)), '' );
+ − 4742
if ( $temp_file )
+ − 4743
{
+ − 4744
$temp_dir = realpath( dirname($temp_file) );
+ − 4745
unlink( $temp_file );
+ − 4746
return $temp_dir;
+ − 4747
}
+ − 4748
else
+ − 4749
{
+ − 4750
return FALSE;
+ − 4751
}
+ − 4752
}
+ − 4753
}
+ − 4754
}
+ − 4755
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
+ − 4756
/**
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
+ − 4757
* 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
+ − 4758
*/
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
+ − 4759
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
+ − 4760
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
+ − 4761
{
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
+ − 4762
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
+ − 4763
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
+ − 4764
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
+ − 4765
$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
+ − 4766
$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
+ − 4767
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
+ − 4768
$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
+ − 4769
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
+ − 4770
$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
+ − 4771
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
+ − 4772
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
+ − 4773
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
+ − 4774
{
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
+ − 4775
$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
+ − 4776
$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
+ − 4777
$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
+ − 4778
$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
+ − 4779
$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
+ − 4780
}
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
+ − 4781
}
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
+ − 4782
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
+ − 4783
/**
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
+ − 4784
* 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
+ − 4785
*/
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
+ − 4786
573
43e7254afdb4
Renamed some functions (that were new in this release anyway) due to compatibility broken with PunBB bridge
Dan
diff
changeset
+ − 4787
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
+ − 4788
{
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
+ − 4789
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
+ − 4790
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
+ − 4791
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
+ − 4792
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
+ − 4793
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
+ − 4794
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
+ − 4795
$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
+ − 4796
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
+ − 4797
{
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
+ − 4798
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
+ − 4799
$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
+ − 4800
}
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
+ − 4801
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
+ − 4802
$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
+ − 4803
$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
+ − 4804
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
+ − 4805
{
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
+ − 4806
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
+ − 4807
{
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
+ − 4808
$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
+ − 4809
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
+ − 4810
}
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
+ − 4811
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
+ − 4812
$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
+ − 4813
$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
+ − 4814
}
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
+ − 4815
$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
+ − 4816
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
+ − 4817
// 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
+ − 4818
$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
+ − 4819
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
+ − 4820
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
+ − 4821
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
+ − 4822
fclose($fh);
613
+ − 4823
+ − 4824
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
+ − 4825
}
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
+ − 4826
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
+ − 4827
/**
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
+ − 4828
* 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
+ − 4829
*/
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
+ − 4830
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
+ − 4831
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
+ − 4832
{
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
+ − 4833
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
+ − 4834
{
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
+ − 4835
@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
+ − 4836
}
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
+ − 4837
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
+ − 4838
{
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
+ − 4839
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
+ − 4840
}
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
+ − 4841
}
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
+ − 4842
599
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4843
/**
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4844
* 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
+ − 4845
*/
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4846
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4847
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
+ − 4848
{
613
+ − 4849
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
+ − 4850
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
+ − 4851
{
613
+ − 4852
$cache->purge('page_meta');
+ − 4853
$cache->purge('anon_sidebar');
+ − 4854
$cache->purge('plugins');
+ − 4855
599
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4856
$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
+ − 4857
'aes_decrypt.php',
613
+ − 4858
// 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
+ − 4859
'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
+ − 4860
);
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4861
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
+ − 4862
{
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4863
$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
+ − 4864
// 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
+ − 4865
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
+ − 4866
continue;
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4867
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4868
// 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
+ − 4869
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
+ − 4870
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
+ − 4871
// 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
+ − 4872
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
+ − 4873
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
+ − 4874
// 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
+ − 4875
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
+ − 4876
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
+ − 4877
// 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
+ − 4878
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
+ − 4879
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
+ − 4880
// language files
613
+ − 4881
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
+ − 4882
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
+ − 4883
}
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4884
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
+ − 4885
}
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4886
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
+ − 4887
}
52bffa6c499f
Added purge_all_caches() routine to functions.php. Temporary, will be discarded once the new cache code is implemented
Dan
diff
changeset
+ − 4888
851
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4889
/**
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4890
* 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
+ − 4891
* @param string command
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4892
* @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
+ − 4893
*/
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4894
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4895
function which($executable)
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4896
{
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4897
$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
+ − 4898
if ( !$path )
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4899
// couldn't get OS's PATH
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4900
return false;
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4901
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4902
$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
+ − 4903
$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
+ − 4904
$separator = $win32 ? ';' : ':';
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4905
$paths = explode($separator, $path);
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4906
foreach ( $paths as $dir )
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4907
{
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4908
foreach ( $extensions as $ext )
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4909
{
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4910
$fullpath = "$dir/{$executable}{$ext}";
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4911
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
+ − 4912
{
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4913
return $fullpath;
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4914
}
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4915
}
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4916
}
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4917
return false;
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4918
}
b98798f6572d
Redesigned installer sysreqs page to cover more features, be more comprehensive, and look better
Dan
diff
changeset
+ − 4919
857
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4920
/**
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4921
* 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
+ − 4922
* @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
+ − 4923
* @return bool
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4924
*/
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4925
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4926
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
+ − 4927
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4928
// 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
+ − 4929
// 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
+ − 4930
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4931
$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
+ − 4932
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
+ − 4933
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4934
$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
+ − 4935
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
+ − 4936
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4937
$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
+ − 4938
if ( !$fp )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4939
return false;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4940
fclose($fp);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4941
unlink($file);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4942
return true;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4943
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4944
else
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4945
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4946
$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
+ − 4947
if ( !$fp )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4948
return false;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4949
fclose($fp);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4950
unlink($file);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4951
return true;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4952
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4953
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4954
else
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4955
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4956
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
+ − 4957
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4958
$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
+ − 4959
if ( !$fp )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4960
return false;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4961
fclose($fp);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4962
return true;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4963
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4964
else
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4965
{
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4966
$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
+ − 4967
if ( !$fp )
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4968
return false;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4969
fclose($fp);
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4970
return true;
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4971
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4972
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4973
}
f3a5a276208c
Added support for alternate port numbers on database servers. Also in install-cli, merged in new sysreqs functionality.
Dan
diff
changeset
+ − 4974