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