author | Dan |
Wed, 11 Jul 2007 13:00:19 -0400 | |
changeset 62 | 9dc4fded30e6 |
parent 48 | fc9762553a3c |
child 73 | 0a74676a2f2f |
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 |
|
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
|
5 |
* Version 1.0 (Banshee) |
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 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
43 |
|
1 | 44 |
global $enano_config, $db; |
45 |
$enano_config[$n] = $v; |
|
46 |
$v = $db->escape($v); |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
47 |
|
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 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
53 |
|
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; |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
74 |
if ( isset($_GET['printable'] ) ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
75 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
76 |
$flags .= $sep . 'printable=yes'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
77 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
78 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
79 |
if ( isset($_GET['theme'] ) ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
80 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
81 |
$flags .= $sep . 'theme='.$session->theme; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
82 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
83 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
84 |
if ( isset($_GET['style'] ) ) { |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
85 |
$flags .= $sep . 'style='.$session->style; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
86 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
87 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
88 |
|
1 | 89 |
$url = $session->append_sid(contentPath.$t.$flags); |
90 |
if($query) |
|
91 |
{ |
|
92 |
$sep = strstr($url, '?') ? '&' : '?'; |
|
93 |
$url = $url . $sep . $query; |
|
94 |
} |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
95 |
|
1 | 96 |
return ($escape) ? htmlspecialchars($url) : $url; |
97 |
} |
|
98 |
||
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
99 |
/** |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
100 |
* 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
|
101 |
* @param string The namespace ID |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
102 |
* @param string The page ID |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
103 |
* @param string The GET query string to append |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
104 |
* @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
|
105 |
* @return string |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
106 |
*/ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
107 |
|
1 | 108 |
function makeUrlNS($n, $t, $query = false, $escape = false) |
109 |
{ |
|
110 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
111 |
$flags = ''; |
|
112 |
||
113 |
if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
|
114 |
{ |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
115 |
$sep = urlSeparator; |
1 | 116 |
} |
117 |
else |
|
118 |
{ |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
119 |
$sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
120 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
121 |
if ( isset( $_GET['printable'] ) ) { |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
122 |
$flags .= $sep . 'printable'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
123 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
124 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
125 |
if ( isset( $_GET['theme'] ) ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
126 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
127 |
$flags .= $sep . 'theme='.$session->theme; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
128 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
129 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
130 |
if ( isset( $_GET['style'] ) ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
131 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
132 |
$flags .= $sep . 'style='.$session->style; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
133 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
134 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
135 |
|
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
136 |
if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
137 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
138 |
$url = contentPath . $paths->nslist[$n] . $t . $flags; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
139 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
140 |
else |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
141 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
142 |
// 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
|
143 |
$url = contentPath . $n . ':' . $t . $flags; |
1 | 144 |
} |
145 |
||
146 |
if($query) |
|
147 |
{ |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
148 |
if(strstr($url, '?')) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
149 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
150 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
151 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
152 |
else |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
153 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
154 |
$sep = '?'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
155 |
} |
1 | 156 |
$url = $url . $sep . $query . $flags; |
157 |
} |
|
158 |
||
159 |
if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
|
160 |
{ |
|
161 |
$url = $session->append_sid($url); |
|
162 |
} |
|
163 |
||
164 |
return ($escape) ? htmlspecialchars($url) : $url; |
|
165 |
} |
|
166 |
||
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
167 |
/** |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
168 |
* 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
|
169 |
* @param string The namespace ID |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
170 |
* @param string The page ID |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
171 |
* @param string The GET query string to append |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
172 |
* @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
|
173 |
* @return string |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
174 |
*/ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
175 |
|
1 | 176 |
function makeUrlComplete($n, $t, $query = false, $escape = false) |
177 |
{ |
|
178 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
179 |
$flags = ''; |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
180 |
|
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
181 |
if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
182 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
183 |
$sep = urlSeparator; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
184 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
185 |
else |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
186 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
187 |
$sep = (strstr($_SERVER['REQUEST_URI'], '?')) ? '&' : '?'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
188 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
189 |
if ( isset( $_GET['printable'] ) ) { |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
190 |
$flags .= $sep . 'printable'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
191 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
192 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
193 |
if ( isset( $_GET['theme'] ) ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
194 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
195 |
$flags .= $sep . 'theme='.$session->theme; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
196 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
197 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
198 |
if ( isset( $_GET['style'] ) ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
199 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
200 |
$flags .= $sep . 'style='.$session->style; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
201 |
$sep = '&'; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
202 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
203 |
|
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
204 |
if(defined('ENANO_BASE_CLASSES_INITIALIZED')) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
205 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
206 |
$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
|
207 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
208 |
else |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
209 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
210 |
// 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
|
211 |
$url = contentPath . $n . ':' . $t . $flags; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
212 |
} |
1 | 213 |
if($query) |
214 |
{ |
|
215 |
if(strstr($url, '?')) $sep = '&'; |
|
216 |
else $sep = '?'; |
|
217 |
$url = $url . $sep . $query . $flags; |
|
218 |
} |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
219 |
|
1 | 220 |
$baseprot = 'http' . ( isset($_SERVER['HTTPS']) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST']; |
221 |
$url = $baseprot . $url; |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
222 |
|
1 | 223 |
return ($escape) ? htmlspecialchars($url) : $url; |
224 |
} |
|
225 |
||
226 |
/** |
|
62
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
227 |
* 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
|
228 |
* @param string Page ID string (ex: Special:Administration) |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
229 |
* @return string |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
230 |
*/ |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
231 |
|
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
232 |
function get_page_title($page_id) |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
233 |
{ |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
234 |
global $db, $session, $paths, $template, $plugins; // Common objects |
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 |
$idata = RenderMan::strToPageID($page_id); |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
237 |
$page_id_key = $paths->nslist[ $idata[1] ] . $idata[0]; |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
238 |
$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
|
239 |
$title = ( isset($page_data['name']) ) ? $page_data['name'] : $paths->nslist[$idata[1]] . str_replace('_', ' ', dirtify_page_id( $idata[0] ) ); |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
240 |
return $title; |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
241 |
} |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
242 |
|
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
243 |
/** |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
244 |
* 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
|
245 |
* @param string Page ID |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
246 |
* @param string Namespace |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
247 |
* @return string |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
248 |
*/ |
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 |
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
|
251 |
{ |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
252 |
global $db, $session, $paths, $template, $plugins; // Common objects |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
253 |
|
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
254 |
$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
|
255 |
$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
|
256 |
$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
|
257 |
return $title; |
9dc4fded30e6
Redirect pages actually work stable-ish now; critical extraneous debug message removed (oops!)
Dan
parents:
48
diff
changeset
|
258 |
} |
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 |
/** |
1 | 261 |
* Redirect the user to the specified URL. |
262 |
* @param string $url The URL, either relative or absolute. |
|
263 |
* @param string $title The title of the message |
|
264 |
* @param string $message A short message to show to the user |
|
265 |
* @param string $timeout Timeout, in seconds, to delay the redirect. Defaults to 3. |
|
266 |
*/ |
|
267 |
||
268 |
function redirect($url, $title = 'Redirecting...', $message = 'Please wait while you are redirected.', $timeout = 3) |
|
269 |
{ |
|
270 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
271 |
||
272 |
if ( $timeout == 0 ) |
|
273 |
{ |
|
274 |
header('Location: ' . $url); |
|
275 |
header('HTTP/1.1 307 Temporary Redirect'); |
|
276 |
} |
|
277 |
||
278 |
$template->add_header('<meta http-equiv="refresh" content="' . $timeout . '; url=' . str_replace('"', '\\"', $url) . '" />'); |
|
279 |
$template->add_header('<script type="text/javascript"> |
|
280 |
function __r() { |
|
281 |
// FUNCTION AUTOMATICALLY GENERATED |
|
282 |
window.location="' . str_replace('"', '\\"', $url) . '"; |
|
283 |
} |
|
284 |
setTimeout(\'__r();\', ' . $timeout . '000); |
|
285 |
</script> |
|
286 |
'); |
|
287 |
||
288 |
$template->tpl_strings['PAGE_NAME'] = $title; |
|
289 |
$template->header(true); |
|
290 |
echo '<p>' . $message . '</p><p>If you are not redirected within ' . ( $timeout + 1 ) . ' seconds, <a href="' . str_replace('"', '\\"', $url) . '">please click here</a>.</p>'; |
|
291 |
$template->footer(true); |
|
292 |
||
293 |
$db->close(); |
|
294 |
exit(0); |
|
295 |
||
296 |
} |
|
297 |
||
298 |
// Removed wikiFormat() from here, replaced with RenderMan::render |
|
299 |
||
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
300 |
/** |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
301 |
* Tell me if the page exists or not. |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
302 |
* @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
|
303 |
* @return bool True if the page exists, false otherwise |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
304 |
*/ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
305 |
|
1 | 306 |
function isPage($p) { |
307 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
308 |
|
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
309 |
// Try the easy way first ;-) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
310 |
if ( isset( $paths->pages[ $p ] ) ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
311 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
312 |
return true; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
313 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
314 |
|
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
315 |
// 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
|
316 |
$ns_test = RenderMan::strToPageID( $p ); |
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 |
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
|
319 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
320 |
return false; |
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 |
|
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
323 |
$particles = explode('/', $p); |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
324 |
if ( isset ( $paths->pages[ $particles[ 0 ] ] ) ) |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
325 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
326 |
return true; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
327 |
} |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
328 |
else |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
329 |
{ |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
330 |
return false; |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
331 |
} |
1 | 332 |
} |
333 |
||
334 |
function arrayItemUp($arr, $keyname) { |
|
335 |
$keylist = array_keys($arr); |
|
336 |
$keyflop = array_flip($keylist); |
|
337 |
$idx = $keyflop[$keyname]; |
|
338 |
$idxm = $idx - 1; |
|
339 |
$temp = $arr[$keylist[$idxm]]; |
|
340 |
if($arr[$keylist[0]] == $arr[$keyname]) return $arr; |
|
341 |
$arr[$keylist[$idxm]] = $arr[$keylist[$idx]]; |
|
342 |
$arr[$keylist[$idx]] = $temp; |
|
343 |
return $arr; |
|
344 |
} |
|
345 |
||
346 |
function arrayItemDown($arr, $keyname) { |
|
347 |
$keylist = array_keys($arr); |
|
348 |
$keyflop = array_flip($keylist); |
|
349 |
$idx = $keyflop[$keyname]; |
|
350 |
$idxm = $idx + 1; |
|
351 |
$temp = $arr[$keylist[$idxm]]; |
|
352 |
$sz = sizeof($arr); $sz--; |
|
353 |
if($arr[$keylist[$sz]] == $arr[$keyname]) return $arr; |
|
354 |
$arr[$keylist[$idxm]] = $arr[$keylist[$idx]]; |
|
355 |
$arr[$keylist[$idx]] = $temp; |
|
356 |
return $arr; |
|
357 |
} |
|
358 |
||
359 |
function arrayItemTop($arr, $keyname) { |
|
360 |
$keylist = array_keys($arr); |
|
361 |
$keyflop = array_flip($keylist); |
|
362 |
$idx = $keyflop[$keyname]; |
|
363 |
while( $orig != $arr[$keylist[0]] ) { |
|
364 |
// echo 'Keyname: '.$keylist[$idx] . '<br />'; flush(); ob_flush(); // Debugger |
|
365 |
if($idx < 0) return $arr; |
|
366 |
if($keylist[$idx] == '' || $keylist[$idx] < 0 || !$keylist[$idx]) { |
|
367 |
/* echo 'Infinite loop caught in arrayItemTop(<br /><pre>'; |
|
368 |
print_r($arr); |
|
369 |
echo '</pre><br />, '.$keyname.');<br /><br />EnanoCMS: Critical error during function call, exiting to prevent excessive server load.'; |
|
370 |
exit; */ |
|
371 |
return $arr; |
|
372 |
} |
|
373 |
$arr = arrayItemUp($arr, $keylist[$idx]); |
|
374 |
$idx--; |
|
375 |
} |
|
376 |
return $arr; |
|
377 |
} |
|
378 |
||
379 |
function arrayItemBottom($arr, $keyname) { |
|
380 |
$keylist = array_keys($arr); |
|
381 |
$keyflop = array_flip($keylist); |
|
382 |
$idx = $keyflop[$keyname]; |
|
383 |
$sz = sizeof($arr); $sz--; |
|
384 |
while( $orig != $arr[$keylist[$sz]] ) { |
|
385 |
// echo 'Keyname: '.$keylist[$idx] . '<br />'; flush(); ob_flush(); // Debugger |
|
386 |
if($idx > $sz) return $arr; |
|
387 |
if($keylist[$idx] == '' || $keylist[$idx] < 0 || !$keylist[$idx]) { |
|
388 |
echo 'Infinite loop caught in arrayItemBottom(<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 |
} |
|
393 |
$arr = arrayItemDown($arr, $keylist[$idx]); |
|
394 |
$idx++; |
|
395 |
} |
|
396 |
return $arr; |
|
397 |
} |
|
398 |
||
399 |
// Convert IP address to hex string |
|
400 |
// Input: 127.0.0.1 (string) |
|
401 |
// Output: 0x7f000001 (string) |
|
402 |
// Updated 12/8/06 to work with PHP4 and not use eval() (blech) |
|
403 |
function ip2hex($ip) { |
|
404 |
if ( preg_match('/^([0-9a-f:]+)$/', $ip) ) |
|
405 |
{ |
|
406 |
// this is an ipv6 address |
|
407 |
return str_replace(':', '', $ip); |
|
408 |
} |
|
409 |
$nums = explode('.', $ip); |
|
410 |
if(sizeof($nums) != 4) return false; |
|
411 |
$str = '0x'; |
|
412 |
foreach($nums as $n) |
|
413 |
{ |
|
414 |
$str .= (string)dechex($n); |
|
415 |
} |
|
416 |
return $str; |
|
417 |
} |
|
418 |
||
419 |
// Convert DWord to IP address |
|
420 |
// Input: 0x7f000001 |
|
421 |
// Output: 127.0.0.1 |
|
422 |
// Updated 12/8/06 to work with PHP4 and not use eval() (blech) |
|
423 |
function hex2ip($in) { |
|
424 |
if(substr($in, 0, 2) == '0x') $ip = substr($in, 2, 8); |
|
425 |
else $ip = substr($in, 0, 8); |
|
426 |
$octets = enano_str_split($ip, 2); |
|
427 |
$str = ''; |
|
428 |
$newoct = Array(); |
|
429 |
foreach($octets as $o) |
|
430 |
{ |
|
431 |
$o = (int)hexdec($o); |
|
432 |
$newoct[] = $o; |
|
433 |
} |
|
434 |
return implode('.', $newoct); |
|
435 |
} |
|
436 |
||
437 |
// Function strip_php moved to RenderMan class |
|
438 |
||
439 |
function die_semicritical($t, $p) |
|
440 |
{ |
|
441 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
442 |
$db->close(); |
|
443 |
||
444 |
if ( ob_get_status() ) |
|
445 |
ob_end_clean(); |
|
446 |
||
447 |
dc_here('functions: <span style="color: red">calling die_semicritical</span>'); |
|
448 |
||
449 |
$tpl = new template_nodb(); |
|
450 |
$tpl->load_theme('oxygen', 'bleu'); |
|
451 |
$tpl->tpl_strings['SITE_NAME'] = getConfig('site_name'); |
|
452 |
$tpl->tpl_strings['SITE_DESC'] = getConfig('site_desc'); |
|
453 |
$tpl->tpl_strings['COPYRIGHT'] = getConfig('copyright_notice'); |
|
454 |
$tpl->tpl_strings['PAGE_NAME'] = $t; |
|
455 |
$tpl->header(); |
|
456 |
echo $p; |
|
457 |
$tpl->footer(); |
|
458 |
||
459 |
exit; |
|
460 |
} |
|
461 |
||
462 |
function die_friendly($t, $p) |
|
463 |
{ |
|
464 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
465 |
||
466 |
if ( ob_get_status() ) |
|
467 |
ob_end_clean(); |
|
468 |
||
469 |
dc_here('functions: <span style="color: red">calling die_friendly</span>'); |
|
470 |
$paths->cpage['name'] = $t; |
|
471 |
$template->tpl_strings['PAGE_NAME'] = $t; |
|
472 |
$template->header(); |
|
473 |
echo $p; |
|
474 |
$template->footer(); |
|
475 |
$db->close(); |
|
476 |
||
477 |
exit; |
|
478 |
} |
|
479 |
||
480 |
function grinding_halt($t, $p) |
|
481 |
{ |
|
482 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
483 |
||
484 |
$db->close(); |
|
485 |
||
486 |
if ( ob_get_status() ) |
|
487 |
ob_end_clean(); |
|
488 |
||
489 |
dc_here('functions: <span style="color: red">calling grinding_halt</span>'); |
|
490 |
$tpl = new template_nodb(); |
|
491 |
$tpl->load_theme('oxygen', 'bleu'); |
|
492 |
$tpl->tpl_strings['SITE_NAME'] = 'Critical error'; |
|
493 |
$tpl->tpl_strings['SITE_DESC'] = 'This website is experiencing a serious error and cannot load.'; |
|
494 |
$tpl->tpl_strings['COPYRIGHT'] = 'Unable to retrieve copyright information'; |
|
495 |
$tpl->tpl_strings['PAGE_NAME'] = $t; |
|
496 |
$tpl->header(); |
|
497 |
echo $p; |
|
498 |
$tpl->footer(); |
|
499 |
exit; |
|
500 |
} |
|
501 |
||
502 |
function show_category_info() { |
|
503 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
504 |
dc_here('functions: showing category info'); |
|
505 |
if($template->no_headers && !strpos($_SERVER['REQUEST_URI'], 'ajax.php')) return ''; |
|
506 |
if($paths->namespace=='Category') |
|
507 |
{ |
|
508 |
$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;'); |
|
509 |
if(!$q) $db->_die('The category information could not be selected.'); |
|
510 |
$ticker = -1; |
|
511 |
echo '<h3>Subcategories</h3>'; |
|
512 |
if($db->numrows() < 1) echo '<p>There are no subcategories in this category.</p>'; |
|
513 |
echo '<table border="0" cellspacing="1" cellpadding="4">'; |
|
514 |
while($row = $db->fetchrow()) |
|
515 |
{ |
|
516 |
$ticker++;if($ticker==3) $ticker=0; |
|
517 |
if($ticker==0) echo '<tr>'; |
|
518 |
echo '<td style="width: 200px;"><a href="'.makeUrlNS($row['namespace'], $row['page_id']).'">'.$paths->pages[$paths->nslist[$row['namespace']].$row['page_id']]['name'].'</a></td>'; |
|
519 |
if($ticker==2) echo '</tr>'; |
|
520 |
} |
|
521 |
$db->free_result(); |
|
522 |
if($ticker) echo '</tr>'; |
|
523 |
echo '</table>'; |
|
524 |
||
525 |
$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;'); |
|
526 |
if(!$q) $db->_die('The category information could not be selected.'); |
|
527 |
$ticker = -1; |
|
528 |
echo '<h3>Pages</h3>'; |
|
529 |
if($db->numrows() < 1) echo '<p>There are no pages in this category.</p>'; |
|
530 |
echo '<table border="0" cellspacing="1" cellpadding="4">'; |
|
531 |
while($row = $db->fetchrow()) |
|
532 |
{ |
|
533 |
$ticker++;if($ticker==3) $ticker=0; |
|
534 |
if($ticker==0) echo '<tr>'; |
|
535 |
echo '<td style="width: 200px;"><a href="'.makeUrlNS($row['namespace'], $row['page_id']).'">'.$paths->pages[$paths->nslist[$row['namespace']].$row['page_id']]['name'].'</a></td>'; |
|
536 |
if($ticker==2) echo '</tr>'; |
|
537 |
} |
|
538 |
$db->free_result(); |
|
539 |
if($ticker) echo '</tr>'; |
|
540 |
echo '</table><br /><br />'; |
|
541 |
} |
|
542 |
$q = $db->sql_query('SELECT category_id FROM '.table_prefix.'categories WHERE page_id=\''.$paths->cpage['urlname_nons'].'\' AND namespace=\''.$paths->namespace.'\''); |
|
543 |
if(!$q) $db->_die('The error seems to have occurred during selection of category data.'); |
|
544 |
if($db->numrows() > 0) { |
|
545 |
echo '<div class="mdg-comment" style="margin-left: 0;">Categories: '; |
|
546 |
$i=0; |
|
547 |
while($r = $db->fetchrow()) |
|
548 |
{ |
|
549 |
if($i>0) echo ', '; |
|
550 |
$i++; |
|
551 |
echo '<a href="'.makeUrlNS('Category', $r['category_id']).'">'.$paths->pages[$paths->nslist['Category'].$r['category_id']]['name'].'</a>'; |
|
552 |
} |
|
553 |
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>'; |
|
554 |
} else { |
|
555 |
echo '<div class="mdg-comment" style="margin-left: 0;">Categories: '; |
|
556 |
echo '(Uncategorized)'; |
|
557 |
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>'; |
|
558 |
else echo '</div>'; |
|
559 |
} |
|
560 |
$db->free_result(); |
|
561 |
} |
|
562 |
||
563 |
function show_file_info() |
|
564 |
{ |
|
565 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
566 |
if($paths->namespace != 'File') return null; // Prevent unnecessary work |
|
567 |
$selfn = $paths->cpage['urlname_nons']; // substr($paths->page, strlen($paths->nslist['File']), strlen($paths->cpage)); |
|
568 |
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'])); |
|
569 |
$q = $db->sql_query('SELECT mimetype,time_id,size FROM '.table_prefix.'files WHERE page_id=\''.$selfn.'\' ORDER BY time_id DESC;'); |
|
570 |
if(!$q) $db->_die('The file type could not be fetched.'); |
|
571 |
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; } |
|
572 |
$r = $db->fetchrow(); |
|
573 |
$mimetype = $r['mimetype']; |
|
574 |
$datestring = date('F d, Y h:i a', (int)$r['time_id']); |
|
575 |
echo '<div class="mdg-comment" style="margin-left: 0;"><p><h3>Uploaded file</h3></p><p>Type: '.$r['mimetype'].'<br />Size: '; |
|
576 |
$fs = $r['size']; |
|
577 |
echo $fs.' bytes'; |
|
578 |
$fs = (int)$fs; |
|
579 |
if($fs >= 1048576) |
|
580 |
{ |
|
581 |
$fs = round($fs / 1048576, 1); |
|
582 |
echo ' ('.$fs.' MB)'; |
|
583 |
} elseif($fs >= 1024) { |
|
584 |
$fs = round($fs / 1024, 1); |
|
585 |
echo ' ('.$fs.' KB)'; |
|
586 |
} |
|
587 |
echo '<br />Uploaded: '.$datestring.'</p>'; |
|
588 |
if(substr($mimetype, 0, 6)!='image/' && ( substr($mimetype, 0, 5) != 'text/' || $mimetype == 'text/html' || $mimetype == 'text/javascript' )) |
|
589 |
{ |
|
590 |
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>'; |
|
591 |
} |
|
592 |
if(substr($mimetype, 0, 6)=='image/') |
|
593 |
{ |
|
594 |
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>'; |
|
595 |
} |
|
596 |
echo '<p><a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">Download this file</a>'; |
|
597 |
if(!$paths->page_protected && ( $paths->wiki_mode || $session->get_permissions('upload_new_version') )) |
|
598 |
{ |
|
599 |
echo ' | <a href="'.makeUrlNS('Special', 'UploadFile'.'/'.$selfn).'">Upload new version</a>'; |
|
600 |
} |
|
601 |
echo '</p>'; |
|
602 |
if($db->numrows() > 1) |
|
603 |
{ |
|
604 |
echo '<h3>File history</h3><p>'; |
|
605 |
while($r = $db->fetchrow()) |
|
606 |
{ |
|
607 |
echo '(<a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">this ver</a>) '; |
|
608 |
if($session->get_permissions('history_rollback')) |
|
609 |
echo ' (<a href="#" onclick="ajaxRollback(\''.$r['time_id'].'\'); return false;">revert</a>) '; |
|
610 |
$mimetype = $r['mimetype']; |
|
611 |
$datestring = date('F d, Y h:i a', (int)$r['time_id']); |
|
612 |
echo $datestring.': '.$r['mimetype'].', '; |
|
613 |
$fs = $r['size']; |
|
614 |
$fs = (int)$fs; |
|
615 |
if($fs >= 1048576) |
|
616 |
{ |
|
617 |
$fs = round($fs / 1048576, 1); |
|
618 |
echo ' '.$fs.' MB'; |
|
619 |
} elseif($fs >= 1024) { |
|
620 |
$fs = round($fs / 1024, 1); |
|
621 |
echo ' '.$fs.' KB'; |
|
622 |
} else { |
|
623 |
echo ' '.$fs.' bytes'; |
|
624 |
} |
|
625 |
echo '<br />'; |
|
626 |
} |
|
627 |
echo '</p>'; |
|
628 |
} |
|
629 |
$db->free_result(); |
|
630 |
echo '</div><br />'; |
|
631 |
} |
|
632 |
||
633 |
function display_page_headers() |
|
634 |
{ |
|
635 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
636 |
if($session->get_permissions('vote_reset') && $paths->cpage['delvotes'] > 0) |
|
637 |
{ |
|
638 |
$hr = implode(', ', explode('|', $paths->cpage['delvote_ips'])); |
|
639 |
$is = 'is'; |
|
640 |
$s = ''; |
|
641 |
$s2 = 's'; |
|
642 |
if ( $paths->cpage['delvotes'] > 1) |
|
643 |
{ |
|
644 |
$is = 'are'; |
|
645 |
$s = 's'; |
|
646 |
$s2 = ''; |
|
647 |
} |
|
648 |
echo '<div class="info-box" style="margin-left: 0; margin-top: 5px;" id="mdgDeleteVoteNoticeBox"> |
|
649 |
<b>Notice:</b> There '.$is.' '.$paths->cpage['delvotes'].' user'.$s.' that think'.$s2.' this page should be deleted.<br /> |
|
650 |
<b>Users that voted:</b> ' . $hr . '<br /> |
|
651 |
<a href="'.makeUrl($paths->page, 'do=deletepage').'" onclick="ajaxDeletePage(); return false;">Delete page</a> | <a href="'.makeUrl($paths->page, 'do=resetvotes').'" onclick="ajaxResetDelVotes(); return false;">Reset votes</a> |
|
652 |
</div>'; |
|
653 |
} |
|
654 |
} |
|
655 |
||
656 |
function display_page_footers() |
|
657 |
{ |
|
658 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
659 |
if(isset($_GET['nofooters'])) return; |
|
660 |
$code = $plugins->setHook('send_page_footers'); |
|
661 |
foreach ( $code as $cmd ) |
|
662 |
{ |
|
663 |
eval($cmd); |
|
664 |
} |
|
665 |
show_file_info(); |
|
666 |
show_category_info(); |
|
667 |
} |
|
668 |
||
669 |
function password_prompt($id = false) |
|
670 |
{ |
|
671 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
672 |
if(!$id) $id = $paths->page; |
|
673 |
if(isset($paths->pages[$id]['password']) && strlen($paths->pages[$id]['password']) == 40 && !isset($_REQUEST['pagepass'])) |
|
674 |
{ |
|
675 |
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>'); |
|
676 |
} elseif(isset($_REQUEST['pagepass'])) { |
|
677 |
$p = (preg_match('#^([a-f0-9]*){40}$#', $_REQUEST['pagepass'])) ? $_REQUEST['pagepass'] : sha1($_REQUEST['pagepass']); |
|
678 |
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>'); |
|
679 |
} |
|
680 |
} |
|
681 |
||
682 |
function str_hex($string){ |
|
683 |
$hex=''; |
|
684 |
for ($i=0; $i < strlen($string); $i++){ |
|
685 |
$hex .= ' '.dechex(ord($string[$i])); |
|
686 |
} |
|
687 |
return substr($hex, 1, strlen($hex)); |
|
688 |
} |
|
689 |
||
690 |
// Function pulled from phpBB's smtp.php |
|
691 |
function smtp_get_response($socket, $response, $line = __LINE__) |
|
692 |
{ |
|
693 |
$server_response = ''; |
|
694 |
while (substr($server_response, 3, 1) != ' ') |
|
695 |
{ |
|
696 |
if (!($server_response = fgets($socket, 256))) |
|
697 |
{ |
|
698 |
die_friendly('SMTP Error', "<p>Couldn't get mail server response codes</p>"); |
|
699 |
} |
|
700 |
} |
|
701 |
||
702 |
if (!(substr($server_response, 0, 3) == $response)) |
|
703 |
{ |
|
704 |
die_friendly('SMTP Error', "<p>Ran into problems sending mail. Response: $server_response</p>"); |
|
705 |
} |
|
706 |
} |
|
707 |
||
708 |
function smtp_send_email($to, $subject, $message, $from) |
|
709 |
{ |
|
710 |
return smtp_send_email_core($to, $subject, $message, "From: <$from>\n"); |
|
711 |
} |
|
712 |
||
713 |
// Replacement or substitute for PHP's mail command |
|
714 |
// Ported from phpBB - copyright (C) phpBB group, GPL. |
|
715 |
function smtp_send_email_core($mail_to, $subject, $message, $headers = '') |
|
716 |
{ |
|
717 |
global $board_config; |
|
718 |
||
719 |
// Fix any bare linefeeds in the message to make it RFC821 Compliant. |
|
720 |
$message = preg_replace("#(?<!\r)\n#si", "\r\n", $message); |
|
721 |
||
722 |
if ($headers != '') |
|
723 |
{ |
|
724 |
if (is_array($headers)) |
|
725 |
{ |
|
726 |
if (sizeof($headers) > 1) |
|
727 |
{ |
|
728 |
$headers = join("\n", $headers); |
|
729 |
} |
|
730 |
else |
|
731 |
{ |
|
732 |
$headers = $headers[0]; |
|
733 |
} |
|
734 |
} |
|
735 |
$headers = chop($headers); |
|
736 |
||
737 |
// Make sure there are no bare linefeeds in the headers |
|
738 |
$headers = preg_replace('#(?<!\r)\n#si', "\r\n", $headers); |
|
739 |
||
740 |
// Ok this is rather confusing all things considered, |
|
741 |
// but we have to grab bcc and cc headers and treat them differently |
|
742 |
// Something we really didn't take into consideration originally |
|
743 |
$header_array = explode("\r\n", $headers); |
|
744 |
@reset($header_array); |
|
745 |
||
746 |
$headers = ''; |
|
747 |
while(list(, $header) = each($header_array)) |
|
748 |
{ |
|
749 |
if (preg_match('#^cc:#si', $header)) |
|
750 |
{ |
|
751 |
$cc = preg_replace('#^cc:(.*)#si', '\1', $header); |
|
752 |
} |
|
753 |
else if (preg_match('#^bcc:#si', $header)) |
|
754 |
{ |
|
755 |
$bcc = preg_replace('#^bcc:(.*)#si', '\1', $header); |
|
756 |
$header = ''; |
|
757 |
} |
|
758 |
$headers .= ($header != '') ? $header . "\r\n" : ''; |
|
759 |
} |
|
760 |
||
761 |
$headers = chop($headers); |
|
762 |
$cc = explode(', ', $cc); |
|
763 |
$bcc = explode(', ', $bcc); |
|
764 |
} |
|
765 |
||
766 |
if (trim($subject) == '') |
|
767 |
{ |
|
768 |
die_friendly(GENERAL_ERROR, "No email Subject specified"); |
|
769 |
} |
|
770 |
||
771 |
if (trim($message) == '') |
|
772 |
{ |
|
773 |
die_friendly(GENERAL_ERROR, "Email message was blank"); |
|
774 |
} |
|
775 |
||
776 |
// setup SMTP |
|
777 |
$host = getConfig('smtp_server'); |
|
778 |
if ( empty($host) ) |
|
779 |
return 'No smtp_host in config'; |
|
780 |
if ( strstr($host, ':' ) ) |
|
781 |
{ |
|
782 |
$n = explode(':', $host); |
|
783 |
$smtp_host = $n[0]; |
|
784 |
$port = intval($n[1]); |
|
785 |
} |
|
786 |
else |
|
787 |
{ |
|
788 |
$smtp_host = $host; |
|
789 |
$port = 25; |
|
790 |
} |
|
791 |
||
792 |
$smtp_user = getConfig('smtp_user'); |
|
793 |
$smtp_pass = getConfig('smtp_password'); |
|
794 |
||
795 |
// Ok we have error checked as much as we can to this point let's get on |
|
796 |
// it already. |
|
797 |
if( !$socket = @fsockopen($smtp_host, $port, $errno, $errstr, 20) ) |
|
798 |
{ |
|
799 |
die_friendly(GENERAL_ERROR, "Could not connect to smtp host : $errno : $errstr"); |
|
800 |
} |
|
801 |
||
802 |
// Wait for reply |
|
803 |
smtp_get_response($socket, "220", __LINE__); |
|
804 |
||
805 |
// Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO |
|
806 |
// This improved as provided by SirSir to accomodate |
|
807 |
if( !empty($smtp_user) && !empty($smtp_pass) ) |
|
808 |
{ |
|
809 |
enano_fputs($socket, "EHLO " . $smtp_host . "\r\n"); |
|
810 |
smtp_get_response($socket, "250", __LINE__); |
|
811 |
||
812 |
enano_fputs($socket, "AUTH LOGIN\r\n"); |
|
813 |
smtp_get_response($socket, "334", __LINE__); |
|
814 |
||
815 |
enano_fputs($socket, base64_encode($smtp_user) . "\r\n"); |
|
816 |
smtp_get_response($socket, "334", __LINE__); |
|
817 |
||
818 |
enano_fputs($socket, base64_encode($smtp_pass) . "\r\n"); |
|
819 |
smtp_get_response($socket, "235", __LINE__); |
|
820 |
} |
|
821 |
else |
|
822 |
{ |
|
823 |
enano_fputs($socket, "HELO " . $smtp_host . "\r\n"); |
|
824 |
smtp_get_response($socket, "250", __LINE__); |
|
825 |
} |
|
826 |
||
827 |
// From this point onward most server response codes should be 250 |
|
828 |
// Specify who the mail is from.... |
|
829 |
enano_fputs($socket, "MAIL FROM: <" . getConfig('contact_email') . ">\r\n"); |
|
830 |
smtp_get_response($socket, "250", __LINE__); |
|
831 |
||
832 |
// Specify each user to send to and build to header. |
|
833 |
$to_header = ''; |
|
834 |
||
835 |
// Add an additional bit of error checking to the To field. |
|
836 |
$mail_to = (trim($mail_to) == '') ? 'Undisclosed-recipients:;' : trim($mail_to); |
|
837 |
if (preg_match('#[^ ]+\@[^ ]+#', $mail_to)) |
|
838 |
{ |
|
839 |
enano_fputs($socket, "RCPT TO: <$mail_to>\r\n"); |
|
840 |
smtp_get_response($socket, "250", __LINE__); |
|
841 |
} |
|
842 |
||
843 |
// Ok now do the CC and BCC fields... |
|
844 |
@reset($bcc); |
|
845 |
while(list(, $bcc_address) = each($bcc)) |
|
846 |
{ |
|
847 |
// Add an additional bit of error checking to bcc header... |
|
848 |
$bcc_address = trim($bcc_address); |
|
849 |
if (preg_match('#[^ ]+\@[^ ]+#', $bcc_address)) |
|
850 |
{ |
|
851 |
enano_fputs($socket, "RCPT TO: <$bcc_address>\r\n"); |
|
852 |
smtp_get_response($socket, "250", __LINE__); |
|
853 |
} |
|
854 |
} |
|
855 |
||
856 |
@reset($cc); |
|
857 |
while(list(, $cc_address) = each($cc)) |
|
858 |
{ |
|
859 |
// Add an additional bit of error checking to cc header |
|
860 |
$cc_address = trim($cc_address); |
|
861 |
if (preg_match('#[^ ]+\@[^ ]+#', $cc_address)) |
|
862 |
{ |
|
863 |
enano_fputs($socket, "RCPT TO: <$cc_address>\r\n"); |
|
864 |
smtp_get_response($socket, "250", __LINE__); |
|
865 |
} |
|
866 |
} |
|
867 |
||
868 |
// Ok now we tell the server we are ready to start sending data |
|
869 |
enano_fputs($socket, "DATA\r\n"); |
|
870 |
||
871 |
// This is the last response code we look for until the end of the message. |
|
872 |
smtp_get_response($socket, "354", __LINE__); |
|
873 |
||
874 |
// Send the Subject Line... |
|
875 |
enano_fputs($socket, "Subject: $subject\r\n"); |
|
876 |
||
877 |
// Now the To Header. |
|
878 |
enano_fputs($socket, "To: $mail_to\r\n"); |
|
879 |
||
880 |
// Now any custom headers.... |
|
881 |
enano_fputs($socket, "$headers\r\n\r\n"); |
|
882 |
||
883 |
// Ok now we are ready for the message... |
|
884 |
enano_fputs($socket, "$message\r\n"); |
|
885 |
||
886 |
// Ok the all the ingredients are mixed in let's cook this puppy... |
|
887 |
enano_fputs($socket, ".\r\n"); |
|
888 |
smtp_get_response($socket, "250", __LINE__); |
|
889 |
||
890 |
// Now tell the server we are done and close the socket... |
|
891 |
enano_fputs($socket, "QUIT\r\n"); |
|
892 |
fclose($socket); |
|
893 |
||
894 |
return TRUE; |
|
895 |
} |
|
896 |
||
897 |
/** |
|
898 |
* Tell which version of Enano we're running. |
|
899 |
* @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.) |
|
900 |
* @return string |
|
901 |
*/ |
|
902 |
||
903 |
function enano_version($long = false, $no_nightly = false) |
|
904 |
{ |
|
905 |
$r = getConfig('enano_version'); |
|
906 |
$rc = ( $long ) ? ' release candidate ' : 'RC'; |
|
907 |
$b = ( $long ) ? ' beta ' : 'b'; |
|
908 |
$a = ( $long ) ? ' alpha ' : 'a'; |
|
909 |
if($v = getConfig('enano_rc_version')) $r .= $rc.$v; |
|
910 |
if($v = getConfig('enano_beta_version')) $r .= $b.$v; |
|
911 |
if($v = getConfig('enano_alpha_version')) $r .= $a.$v; |
|
912 |
if ( defined('ENANO_NIGHTLY') && !$no_nightly ) |
|
913 |
{ |
|
914 |
$nightlytag = ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR; |
|
915 |
$nightlylong = ' nightly; build date: ' . ENANO_NIGHTLY_MONTH . '-' . ENANO_NIGHTLY_DAY . '-' . ENANO_NIGHTLY_YEAR; |
|
916 |
$r = ( $long ) ? $r . $nightlylong : $r . '-nightly-' . $nightlytag; |
|
917 |
} |
|
918 |
return $r; |
|
919 |
} |
|
920 |
||
921 |
function _dualurlenc($t) { |
|
922 |
return rawurlencode(rawurlencode($t)); |
|
923 |
} |
|
924 |
||
925 |
function _die($t) { |
|
926 |
$_ob = 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\'' . rawurlencode('' . $t . '') . '\')'; |
|
927 |
die($_ob); |
|
928 |
} |
|
929 |
||
930 |
function jsdie($text) { |
|
931 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
932 |
$text = rawurlencode($text . "\n\nSQL Backtrace:\n" . $db->sql_backtrace()); |
|
933 |
echo 'document.getElementById("ajaxEditContainer").innerHTML = unescape(\''.$text.'\');'; |
|
934 |
} |
|
935 |
||
936 |
// HTML sanitizing function - written by Kallahar |
|
937 |
// Original function at: http://quickwired.com/kallahar/smallprojects/php_xss_filter_function.php |
|
938 |
||
939 |
// UNUSED - todo: remove this in gold or put it to use |
|
940 |
||
941 |
function RemoveXSS($val) { |
|
942 |
// remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed |
|
943 |
// this prevents some character re-spacing such as <java\0script> |
|
944 |
// note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs |
|
945 |
$val = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $val); |
|
946 |
||
947 |
// straight replacements, the user should never need these since they're normal characters |
|
948 |
// this prevents like <IMG SRC=@avascript:alert('XSS')> |
|
949 |
$search = 'abcdefghijklmnopqrstuvwxyz'; |
|
950 |
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
951 |
$search .= '1234567890!@#$%^&*()'; |
|
952 |
$search .= '~`";:?+/={}[]-_|\'\\'; |
|
953 |
for ($i = 0; $i < strlen($search); $i++) { |
|
954 |
// ;? matches the ;, which is optional |
|
955 |
// 0{0,7} matches any padded zeros, which are optional and go up to 8 chars |
|
956 |
||
957 |
// @ @ search for the hex values |
|
958 |
$val = preg_replace('/(&#[x|X]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val); // with a ; |
|
959 |
// @ @ 0{0,7} matches '0' zero to seven times |
|
960 |
$val = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ; |
|
961 |
} |
|
962 |
||
963 |
// now the only remaining whitespace attacks are \t, \n, and \r |
|
964 |
$ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base'); |
|
965 |
$ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); |
|
966 |
$ra = array_merge($ra1, $ra2); |
|
967 |
||
968 |
$found = true; // keep replacing as long as the previous round replaced something |
|
969 |
while ($found == true) { |
|
970 |
$val_before = $val; |
|
971 |
for ($i = 0; $i < sizeof($ra); $i++) { |
|
972 |
$pattern = '/'; |
|
973 |
for ($j = 0; $j < strlen($ra[$i]); $j++) { |
|
974 |
if ($j > 0) { |
|
975 |
$pattern .= '('; |
|
976 |
$pattern .= '(&#[x|X]0{0,8}([9][a][b]);?)?'; |
|
977 |
$pattern .= '|(�{0,8}([9][10][13]);?)?'; |
|
978 |
$pattern .= ')?'; |
|
979 |
} |
|
980 |
$pattern .= $ra[$i][$j]; |
|
981 |
} |
|
982 |
$pattern .= '/i'; |
|
983 |
$replacement = substr($ra[$i], 0, 2).'<b></b>'.substr($ra[$i], 2); // add in <> to nerf the tag |
|
984 |
$val = preg_replace($pattern, $replacement, $val); // filter out the hex tags |
|
985 |
if ($val_before == $val) { |
|
986 |
// no replacements were made, so exit the loop |
|
987 |
$found = false; |
|
988 |
} |
|
989 |
} |
|
990 |
} |
|
991 |
return $val; |
|
992 |
} |
|
993 |
||
994 |
/** |
|
995 |
* Capitalizes the first letter of a string |
|
996 |
* @param $text string the text to be transformed |
|
997 |
* @return string |
|
998 |
*/ |
|
999 |
||
1000 |
function capitalize_first_letter($text) |
|
1001 |
{ |
|
1002 |
return strtoupper(substr($text, 0, 1)) . substr($text, 1); |
|
1003 |
} |
|
1004 |
||
1005 |
/** |
|
1006 |
* Checks if a value in a bitfield is on or off |
|
1007 |
* @param $bitfield int the bit-field value |
|
1008 |
* @param $value int the value to switch off |
|
1009 |
* @return bool |
|
1010 |
*/ |
|
1011 |
||
1012 |
function is_bit($bitfield, $value) |
|
1013 |
{ |
|
1014 |
return ( $bitfield & $value ) ? true : false; |
|
1015 |
} |
|
1016 |
||
1017 |
/** |
|
1018 |
* Trims spaces/newlines from the beginning and end of a string |
|
1019 |
* @param $text the text to process |
|
1020 |
* @return string |
|
1021 |
*/ |
|
1022 |
||
1023 |
function trim_spaces($text) |
|
1024 |
{ |
|
1025 |
$d = true; |
|
1026 |
while($d) |
|
1027 |
{ |
|
1028 |
$c = substr($text, 0, 1); |
|
1029 |
$a = substr($text, strlen($text)-1, strlen($text)); |
|
1030 |
if($c == "\n" || $c == "\r" || $c == "\t" || $c == ' ') $text = substr($text, 1, strlen($text)); |
|
1031 |
elseif($a == "\n" || $a == "\r" || $a == "\t" || $a == ' ') $text = substr($text, 0, strlen($text)-1); |
|
1032 |
else $d = false; |
|
1033 |
} |
|
1034 |
return $text; |
|
1035 |
} |
|
1036 |
||
1037 |
/** |
|
1038 |
* Enano-ese equivalent of str_split() which is only found in PHP5 |
|
1039 |
* @param $text string the text to split |
|
1040 |
* @param $inc int size of each block |
|
1041 |
* @return array |
|
1042 |
*/ |
|
1043 |
||
1044 |
function enano_str_split($text, $inc = 1) |
|
1045 |
{ |
|
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1046 |
if($inc < 1) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1047 |
{ |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1048 |
return false; |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1049 |
} |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1050 |
if($inc >= strlen($text)) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1051 |
{ |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1052 |
return Array($text); |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1053 |
} |
1 | 1054 |
$len = ceil(strlen($text) / $inc); |
1055 |
$ret = Array(); |
|
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1056 |
for ( $i = 0; $i < strlen($text); $i = $i + $inc ) |
1 | 1057 |
{ |
1058 |
$ret[] = substr($text, $i, $inc); |
|
1059 |
} |
|
1060 |
return $ret; |
|
1061 |
} |
|
1062 |
||
1063 |
/** |
|
1064 |
* Converts a hexadecimal number to a binary string. |
|
1065 |
* @param text string hexadecimal number |
|
1066 |
* @return string |
|
1067 |
*/ |
|
1068 |
function hex2bin($text) |
|
1069 |
{ |
|
1070 |
$arr = enano_str_split($text, 2); |
|
1071 |
$ret = ''; |
|
1072 |
for ($i=0; $i<sizeof($arr); $i++) |
|
1073 |
{ |
|
1074 |
$ret .= chr(hexdec($arr[$i])); |
|
1075 |
} |
|
1076 |
return $ret; |
|
1077 |
} |
|
1078 |
||
1079 |
/** |
|
1080 |
* Generates and/or prints a human-readable backtrace |
|
1081 |
* @param bool $return - if true, this function returns a string, otherwise returns null |
|
1082 |
* @return mixed |
|
1083 |
*/ |
|
1084 |
||
1085 |
function enano_debug_print_backtrace($return = false) |
|
1086 |
{ |
|
1087 |
ob_start(); |
|
1088 |
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
|
1089 |
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
|
1090 |
{ |
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
parents:
16
diff
changeset
|
1091 |
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
|
1092 |
} |
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
parents:
16
diff
changeset
|
1093 |
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
|
1094 |
{ |
5d003b6c9e89
Added demo mode functionality to various parts of Enano (unlocked only with a plugin) and fixed groups table
Dan
parents:
16
diff
changeset
|
1095 |
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
|
1096 |
} |
1 | 1097 |
echo '</pre>'; |
1098 |
$c = ob_get_contents(); |
|
1099 |
ob_end_clean(); |
|
1100 |
if($return) return $c; |
|
1101 |
else echo $c; |
|
1102 |
return null; |
|
1103 |
} |
|
1104 |
||
1105 |
/** |
|
1106 |
* Like rawurlencode(), but encodes all characters |
|
1107 |
* @param string $text the text to encode |
|
1108 |
* @param optional string $prefix text before each hex character |
|
1109 |
* @param optional string $suffix text after each hex character |
|
1110 |
* @return string |
|
1111 |
*/ |
|
1112 |
||
1113 |
function hexencode($text, $prefix = '%', $suffix = '') |
|
1114 |
{ |
|
1115 |
$arr = enano_str_split($text); |
|
1116 |
$r = ''; |
|
1117 |
foreach($arr as $a) |
|
1118 |
{ |
|
1119 |
$nibble = (string)dechex(ord($a)); |
|
1120 |
if(strlen($nibble) == 1) $nibble = '0' . $nibble; |
|
1121 |
$r .= $prefix . $nibble . $suffix; |
|
1122 |
} |
|
1123 |
return $r; |
|
1124 |
} |
|
1125 |
||
1126 |
/** |
|
1127 |
* Enano-ese equivalent of get_magic_quotes_gpc() |
|
1128 |
* @return bool |
|
1129 |
*/ |
|
1130 |
||
1131 |
function enano_get_magic_quotes_gpc() |
|
1132 |
{ |
|
1133 |
if(function_exists('get_magic_quotes_gpc')) |
|
1134 |
{ |
|
1135 |
return ( get_magic_quotes_gpc() == 1 ); |
|
1136 |
} |
|
1137 |
else |
|
1138 |
{ |
|
1139 |
return ( strtolower(@ini_get('magic_quotes_gpc')) == '1' ); |
|
1140 |
} |
|
1141 |
} |
|
1142 |
||
1143 |
/** |
|
1144 |
* Recursive stripslashes() |
|
1145 |
* @param array |
|
1146 |
* @return array |
|
1147 |
*/ |
|
1148 |
||
1149 |
function stripslashes_recurse($arr) |
|
1150 |
{ |
|
1151 |
foreach($arr as $k => $xxxx) |
|
1152 |
{ |
|
1153 |
$val =& $arr[$k]; |
|
1154 |
if(is_string($val)) |
|
1155 |
$val = stripslashes($val); |
|
1156 |
elseif(is_array($val)) |
|
1157 |
$val = stripslashes_recurse($val); |
|
1158 |
} |
|
1159 |
return $arr; |
|
1160 |
} |
|
1161 |
||
1162 |
/** |
|
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1163 |
* 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
|
1164 |
* @param array |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1165 |
* @return array |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1166 |
*/ |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1167 |
|
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1168 |
function strip_nul_chars($arr) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1169 |
{ |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1170 |
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
|
1171 |
{ |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1172 |
$val =& $arr[$k]; |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1173 |
if(is_string($val)) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1174 |
$val = str_replace("\000", '', $val); |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1175 |
elseif(is_array($val)) |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1176 |
$val = strip_nul_chars($val); |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1177 |
} |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1178 |
return $arr; |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1179 |
} |
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1180 |
|
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1181 |
/** |
1 | 1182 |
* If magic_quotes_gpc is on, calls stripslashes() on everything in $_GET/$_POST/$_COOKIE |
14
ce6053bb48d8
Security: NUL characters are now stripped from GPC; several code readability standards changes
Dan
parents:
1
diff
changeset
|
1183 |
* @ignore - this doesn't work too well in my tests |
1 | 1184 |
* @todo port version from the PHP manual |
1185 |
* @return void |
|
1186 |
*/ |
|
1187 |
function strip_magic_quotes_gpc() |
|
1188 |
{ |
|
1189 |
if(enano_get_magic_quotes_gpc()) |
|
1190 |
{ |
|
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
38
diff
changeset
|
1191 |
$_POST = stripslashes_recurse($_POST); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
38
diff
changeset
|
1192 |
$_GET = stripslashes_recurse($_GET); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
38
diff
changeset
|
1193 |
$_COOKIE = stripslashes_recurse($_COOKIE); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
38
diff
changeset
|
1194 |
$_REQUEST = stripslashes_recurse($_REQUEST); |
1 | 1195 |
} |
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
38
diff
changeset
|
1196 |
$_POST = strip_nul_chars($_POST); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
38
diff
changeset
|
1197 |
$_GET = strip_nul_chars($_GET); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
38
diff
changeset
|
1198 |
$_COOKIE = strip_nul_chars($_COOKIE); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
38
diff
changeset
|
1199 |
$_REQUEST = strip_nul_chars($_REQUEST); |
1 | 1200 |
} |
1201 |
||
1202 |
/** |
|
1203 |
* A very basic single-character compression algorithm for binary strings/bitfields |
|
1204 |
* @param string $bits the text to compress |
|
1205 |
* @return string |
|
1206 |
*/ |
|
1207 |
||
1208 |
function compress_bitfield($bits) |
|
1209 |
{ |
|
1210 |
$crc32 = crc32($bits); |
|
1211 |
$bits .= '0'; |
|
1212 |
$start_pos = 0; |
|
1213 |
$current = substr($bits, 1, 1); |
|
1214 |
$last = substr($bits, 0, 1); |
|
1215 |
$chunk_size = 1; |
|
1216 |
$len = strlen($bits); |
|
1217 |
$crc = $len; |
|
1218 |
$crcval = 0; |
|
1219 |
for ( $i = 1; $i < $len; $i++ ) |
|
1220 |
{ |
|
1221 |
$current = substr($bits, $i, 1); |
|
1222 |
$last = substr($bits, $i - 1, 1); |
|
1223 |
$next = substr($bits, $i + 1, 1); |
|
1224 |
// Are we on the last character? |
|
1225 |
if($current == $last && $i+1 < $len) |
|
1226 |
$chunk_size++; |
|
1227 |
else |
|
1228 |
{ |
|
1229 |
if($i+1 == $len && $current == $next) |
|
1230 |
{ |
|
1231 |
// This character completes a chunk |
|
1232 |
$chunk_size++; |
|
1233 |
$i++; |
|
1234 |
$chunk = substr($bits, $start_pos, $chunk_size); |
|
1235 |
$chunklen = strlen($chunk); |
|
1236 |
$newchunk = $last . '[' . $chunklen . ']'; |
|
1237 |
$newlen = strlen($newchunk); |
|
1238 |
$bits = substr($bits, 0, $start_pos) . $newchunk . substr($bits, $i, $len); |
|
1239 |
$chunk_size = 1; |
|
1240 |
$i = $start_pos + $newlen; |
|
1241 |
$start_pos = $i; |
|
1242 |
$len = strlen($bits); |
|
1243 |
$crcval = $crcval + $chunklen; |
|
1244 |
} |
|
1245 |
else |
|
1246 |
{ |
|
1247 |
// Last character completed a chunk |
|
1248 |
$chunk = substr($bits, $start_pos, $chunk_size); |
|
1249 |
$chunklen = strlen($chunk); |
|
1250 |
$newchunk = $last . '[' . $chunklen . '],'; |
|
1251 |
$newlen = strlen($newchunk); |
|
1252 |
$bits = substr($bits, 0, $start_pos) . $newchunk . substr($bits, $i, $len); |
|
1253 |
$chunk_size = 1; |
|
1254 |
$i = $start_pos + $newlen; |
|
1255 |
$start_pos = $i; |
|
1256 |
$len = strlen($bits); |
|
1257 |
$crcval = $crcval + $chunklen; |
|
1258 |
} |
|
1259 |
} |
|
1260 |
} |
|
1261 |
if($crc != $crcval) |
|
1262 |
{ |
|
1263 |
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; |
|
1264 |
return false; |
|
1265 |
} |
|
1266 |
$compressed = 'cbf:len='.$crc.';crc='.dechex($crc32).';data='.$bits.'|end'; |
|
1267 |
return $compressed; |
|
1268 |
} |
|
1269 |
||
1270 |
/** |
|
1271 |
* Uncompresses a bitfield compressed with compress_bitfield() |
|
1272 |
* @param string $bits the compressed bitfield |
|
1273 |
* @return string the uncompressed, original (we hope) bitfield OR bool false on error |
|
1274 |
*/ |
|
1275 |
||
1276 |
function uncompress_bitfield($bits) |
|
1277 |
{ |
|
1278 |
if(substr($bits, 0, 4) != 'cbf:') |
|
1279 |
{ |
|
1280 |
echo __FUNCTION__.'(): ERROR: Invalid stream'; |
|
1281 |
return false; |
|
1282 |
} |
|
1283 |
$len = intval(substr($bits, strpos($bits, 'len=')+4, strpos($bits, ';')-strpos($bits, 'len=')-4)); |
|
1284 |
$crc = substr($bits, strpos($bits, 'crc=')+4, 8); |
|
1285 |
$data = substr($bits, strpos($bits, 'data=')+5, strpos($bits, '|end')-strpos($bits, 'data=')-5); |
|
1286 |
$data = explode(',', $data); |
|
1287 |
foreach($data as $a => $b) |
|
1288 |
{ |
|
1289 |
$d =& $data[$a]; |
|
1290 |
$char = substr($d, 0, 1); |
|
1291 |
$dlen = intval(substr($d, 2, strlen($d)-1)); |
|
1292 |
$s = ''; |
|
1293 |
for($i=0;$i<$dlen;$i++,$s.=$char); |
|
1294 |
$d = $s; |
|
1295 |
unset($s, $dlen, $char); |
|
1296 |
} |
|
1297 |
$decompressed = implode('', $data); |
|
1298 |
$decompressed = substr($decompressed, 0, -1); |
|
1299 |
$dcrc = (string)dechex(crc32($decompressed)); |
|
1300 |
if($dcrc != $crc) |
|
1301 |
{ |
|
1302 |
echo __FUNCTION__.'(): ERROR: CRC check failed<br />debug info:<br />original crc: '.$crc.'<br />decomp\'ed crc: '.$dcrc.'<br />'; |
|
1303 |
return false; |
|
1304 |
} |
|
1305 |
return $decompressed; |
|
1306 |
} |
|
1307 |
||
1308 |
/** |
|
1309 |
* Exports a MySQL table into a SQL string. |
|
1310 |
* @param string $table The name of the table to export |
|
1311 |
* @param bool $structure If true, include a CREATE TABLE command |
|
1312 |
* @param bool $data If true, include the contents of the table |
|
1313 |
* @param bool $compact If true, omits newlines between parts of SQL statements, use in Enano database exporter |
|
1314 |
* @return string |
|
1315 |
*/ |
|
1316 |
||
1317 |
function export_table($table, $structure = true, $data = true, $compact = false) |
|
1318 |
{ |
|
1319 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
1320 |
$struct_keys = ''; |
|
1321 |
$divider = (!$compact) ? "\n" : "\n"; |
|
1322 |
$spacer1 = (!$compact) ? "\n" : " "; |
|
1323 |
$spacer2 = (!$compact) ? " " : " "; |
|
1324 |
$rowspacer = (!$compact) ? "\n " : " "; |
|
1325 |
$index_list = Array(); |
|
1326 |
$cols = $db->sql_query('SHOW COLUMNS IN '.$table.';'); |
|
1327 |
if(!$cols) |
|
1328 |
{ |
|
1329 |
echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />'; |
|
1330 |
return false; |
|
1331 |
} |
|
1332 |
$col = Array(); |
|
1333 |
$sqlcol = Array(); |
|
1334 |
$collist = Array(); |
|
1335 |
$pri_keys = Array(); |
|
1336 |
// Using fetchrow_num() here to compensate for MySQL l10n |
|
1337 |
while( $row = $db->fetchrow_num() ) |
|
1338 |
{ |
|
1339 |
$field =& $row[0]; |
|
1340 |
$type =& $row[1]; |
|
1341 |
$null =& $row[2]; |
|
1342 |
$key =& $row[3]; |
|
1343 |
$def =& $row[4]; |
|
1344 |
$extra =& $row[5]; |
|
1345 |
$col[] = Array( |
|
1346 |
'name'=>$field, |
|
1347 |
'type'=>$type, |
|
1348 |
'null'=>$null, |
|
1349 |
'key'=>$key, |
|
1350 |
'default'=>$def, |
|
1351 |
'extra'=>$extra, |
|
1352 |
); |
|
1353 |
$collist[] = $field; |
|
1354 |
} |
|
1355 |
||
1356 |
if ( $structure ) |
|
1357 |
{ |
|
1358 |
$db->sql_query('SET SQL_QUOTE_SHOW_CREATE = 0;'); |
|
1359 |
$struct = $db->sql_query('SHOW CREATE TABLE '.$table.';'); |
|
1360 |
if ( !$struct ) |
|
1361 |
$db->_die(); |
|
1362 |
$row = $db->fetchrow_num(); |
|
1363 |
$db->free_result(); |
|
1364 |
$struct = $row[1]; |
|
1365 |
$struct = preg_replace("/\n\) ENGINE=(.+)$/", "\n);", $struct); |
|
1366 |
unset($row); |
|
1367 |
if ( $compact ) |
|
1368 |
{ |
|
1369 |
$struct_arr = explode("\n", $struct); |
|
1370 |
foreach ( $struct_arr as $i => $leg ) |
|
1371 |
{ |
|
1372 |
if ( $i == 0 ) |
|
1373 |
continue; |
|
1374 |
$test = trim($leg); |
|
1375 |
if ( empty($test) ) |
|
1376 |
{ |
|
1377 |
unset($struct_arr[$i]); |
|
1378 |
continue; |
|
1379 |
} |
|
1380 |
$struct_arr[$i] = preg_replace('/^([\s]*)/', ' ', $leg); |
|
1381 |
} |
|
1382 |
$struct = implode("", $struct_arr); |
|
1383 |
} |
|
1384 |
} |
|
1385 |
||
1386 |
// Structuring complete |
|
1387 |
if($data) |
|
1388 |
{ |
|
1389 |
$datq = $db->sql_query('SELECT * FROM '.$table.';'); |
|
1390 |
if(!$datq) |
|
1391 |
{ |
|
1392 |
echo 'export_table(): Error getting column list: '.$db->get_error_text().'<br />'; |
|
1393 |
return false; |
|
1394 |
} |
|
1395 |
if($db->numrows() < 1) |
|
1396 |
{ |
|
1397 |
if($structure) return $struct; |
|
1398 |
else return ''; |
|
1399 |
} |
|
1400 |
$rowdata = Array(); |
|
1401 |
$dataqs = Array(); |
|
1402 |
$insert_strings = Array(); |
|
1403 |
$z = false; |
|
1404 |
while($row = $db->fetchrow_num()) |
|
1405 |
{ |
|
1406 |
$z = false; |
|
1407 |
foreach($row as $i => $cell) |
|
1408 |
{ |
|
1409 |
$str = mysql_encode_column($cell, $col[$i]['type']); |
|
1410 |
$rowdata[] = $str; |
|
1411 |
} |
|
1412 |
$dataqs2 = implode(",$rowspacer", $dataqs) . ",$rowspacer" . '( ' . implode(', ', $rowdata) . ' )'; |
|
1413 |
$ins = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . $dataqs2 . ";"; |
|
1414 |
if ( strlen( $ins ) > MYSQL_MAX_PACKET_SIZE ) |
|
1415 |
{ |
|
1416 |
// We've exceeded the maximum allowed packet size for MySQL - separate this into a different query |
|
1417 |
$insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";; |
|
1418 |
$dataqs = Array('( ' . implode(', ', $rowdata) . ' )'); |
|
1419 |
$z = true; |
|
1420 |
} |
|
1421 |
else |
|
1422 |
{ |
|
1423 |
$dataqs[] = '( ' . implode(', ', $rowdata) . ' )'; |
|
1424 |
} |
|
1425 |
$rowdata = Array(); |
|
1426 |
} |
|
1427 |
if ( !$z ) |
|
1428 |
{ |
|
1429 |
$insert_strings[] = 'INSERT INTO '.$table.'( '.implode(',', $collist).' ) VALUES' . implode(",$rowspacer", $dataqs) . ";";; |
|
1430 |
$dataqs = Array(); |
|
1431 |
} |
|
1432 |
$datstring = implode($divider, $insert_strings); |
|
1433 |
} |
|
1434 |
if($structure && !$data) return $struct; |
|
1435 |
elseif(!$structure && $data) return $datstring; |
|
1436 |
elseif($structure && $data) return $struct . $divider . $datstring; |
|
1437 |
elseif(!$structure && !$data) return ''; |
|
1438 |
} |
|
1439 |
||
1440 |
/** |
|
1441 |
* Encodes a string value for use in an INSERT statement for given column type $type. |
|
1442 |
* @access private |
|
1443 |
*/ |
|
1444 |
||
1445 |
function mysql_encode_column($input, $type) |
|
1446 |
{ |
|
1447 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
1448 |
// Decide whether to quote the string or not |
|
1449 |
if(substr($type, 0, 7) == 'varchar' || $type == 'datetime' || $type == 'text' || $type == 'tinytext' || $type == 'smalltext' || $type == 'longtext' || substr($type, 0, 4) == 'char') |
|
1450 |
{ |
|
1451 |
$str = "'" . $db->escape($input) . "'"; |
|
1452 |
} |
|
1453 |
elseif(in_array($type, Array('blob', 'longblob', 'mediumblob', 'smallblob')) || substr($type, 0, 6) == 'binary' || substr($type, 0, 9) == 'varbinary') |
|
1454 |
{ |
|
1455 |
$str = '0x' . hexencode($input, '', ''); |
|
1456 |
} |
|
1457 |
elseif(is_null($input)) |
|
1458 |
{ |
|
1459 |
$str = 'NULL'; |
|
1460 |
} |
|
1461 |
else |
|
1462 |
{ |
|
1463 |
$str = (string)$input; |
|
1464 |
} |
|
1465 |
return $str; |
|
1466 |
} |
|
1467 |
||
1468 |
/** |
|
1469 |
* Creates an associative array defining which file extensions are allowed and which ones aren't |
|
1470 |
* @return array keyname will be a file extension, value will be true or false |
|
1471 |
*/ |
|
1472 |
||
1473 |
function fetch_allowed_extensions() |
|
1474 |
{ |
|
1475 |
global $mime_types; |
|
1476 |
$bits = getConfig('allowed_mime_types'); |
|
1477 |
if(!$bits) return Array(false); |
|
1478 |
$bits = uncompress_bitfield($bits); |
|
1479 |
if(!$bits) return Array(false); |
|
1480 |
$bits = enano_str_split($bits, 1); |
|
1481 |
$ret = Array(); |
|
1482 |
$mt = array_keys($mime_types); |
|
1483 |
foreach($bits as $i => $b) |
|
1484 |
{ |
|
1485 |
$ret[$mt[$i]] = ( $b == '1' ) ? true : false; |
|
1486 |
} |
|
1487 |
return $ret; |
|
1488 |
} |
|
1489 |
||
1490 |
/** |
|
1491 |
* Generates a random key suitable for encryption |
|
1492 |
* @param int $len the length of the key |
|
1493 |
* @return string a BINARY key |
|
1494 |
*/ |
|
1495 |
||
1496 |
function randkey($len = 32) |
|
1497 |
{ |
|
1498 |
$key = ''; |
|
1499 |
for($i=0;$i<$len;$i++) |
|
1500 |
{ |
|
1501 |
$key .= chr(mt_rand(0, 255)); |
|
1502 |
} |
|
1503 |
return $key; |
|
1504 |
} |
|
1505 |
||
1506 |
/** |
|
1507 |
* Decodes a hex string. |
|
1508 |
* @param string $hex The hex code to decode |
|
1509 |
* @return string |
|
1510 |
*/ |
|
1511 |
||
1512 |
function hexdecode($hex) |
|
1513 |
{ |
|
1514 |
$hex = enano_str_split($hex, 2); |
|
1515 |
$bin_key = ''; |
|
1516 |
foreach($hex as $nibble) |
|
1517 |
{ |
|
1518 |
$byte = chr(hexdec($nibble)); |
|
1519 |
$bin_key .= $byte; |
|
1520 |
} |
|
1521 |
return $bin_key; |
|
1522 |
} |
|
1523 |
||
1524 |
/** |
|
1525 |
* Enano's own (almost) bulletproof HTML sanitizer. |
|
1526 |
* @param string $html The input HTML |
|
1527 |
* @return string cleaned HTML |
|
1528 |
*/ |
|
1529 |
||
1530 |
function sanitize_html($html, $filter_php = true) |
|
1531 |
{ |
|
1532 |
||
1533 |
$html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>(.*?)</\\1>#is', '<\\1\\2\\3javascript:\\59>\\60</\\1>', $html); |
|
1534 |
$html = preg_replace('#<([a-z]+)([\s]+)([^>]+?)'.htmlalternatives('javascript:').'(.+?)>#is', '<\\1\\2\\3javascript:\\59>', $html); |
|
1535 |
||
1536 |
if($filter_php) |
|
1537 |
$html = str_replace( |
|
1538 |
Array('<?php', '<?', '<%', '?>', '%>'), |
|
1539 |
Array('<?php', '<?', '<%', '?>', '%>'), |
|
1540 |
$html); |
|
1541 |
||
1542 |
$tag_whitelist = array_keys ( setupAttributeWhitelist() ); |
|
1543 |
if ( !$filter_php ) |
|
1544 |
$tag_whitelist[] = '?php'; |
|
1545 |
$len = strlen($html); |
|
1546 |
$in_quote = false; |
|
1547 |
$quote_char = ''; |
|
1548 |
$tag_start = 0; |
|
1549 |
$tag_name = ''; |
|
1550 |
$in_tag = false; |
|
1551 |
$trk_name = false; |
|
1552 |
for ( $i = 0; $i < $len; $i++ ) |
|
1553 |
{ |
|
1554 |
$chr = $html{$i}; |
|
1555 |
$prev = ( $i == 0 ) ? '' : $html{ $i - 1 }; |
|
1556 |
$next = ( ( $i + 1 ) == $len ) ? '' : $html { $i + 1 }; |
|
1557 |
if ( $in_quote && $in_tag ) |
|
1558 |
{ |
|
1559 |
if ( $quote_char == $chr && $prev != '\\' ) |
|
1560 |
$in_quote = false; |
|
1561 |
} |
|
1562 |
elseif ( ( $chr == '"' || $chr == "'" ) && $prev != '\\' && $in_tag ) |
|
1563 |
{ |
|
1564 |
$in_quote = true; |
|
1565 |
$quote_char = $chr; |
|
1566 |
} |
|
1567 |
if ( $chr == '<' && !$in_tag && $next != '/' ) |
|
1568 |
{ |
|
1569 |
// start of a tag |
|
1570 |
$tag_start = $i; |
|
1571 |
$in_tag = true; |
|
1572 |
$trk_name = true; |
|
1573 |
} |
|
1574 |
elseif ( !$in_quote && $in_tag && $chr == '>' ) |
|
1575 |
{ |
|
1576 |
$full_tag = substr($html, $tag_start, ( $i - $tag_start ) + 1 ); |
|
1577 |
$l = strlen($tag_name) + 2; |
|
1578 |
$attribs_only = trim( substr($full_tag, $l, ( strlen($full_tag) - $l - 1 ) ) ); |
|
1579 |
||
1580 |
// Debugging message |
|
1581 |
// echo htmlspecialchars($full_tag) . '<br />'; |
|
1582 |
||
1583 |
if ( !in_array($tag_name, $tag_whitelist) ) |
|
1584 |
{ |
|
1585 |
// Illegal tag |
|
1586 |
//echo $tag_name . ' '; |
|
1587 |
||
1588 |
$s = ( empty($attribs_only) ) ? '' : ' '; |
|
1589 |
||
1590 |
$sanitized = '<' . $tag_name . $s . $attribs_only . '>'; |
|
1591 |
||
1592 |
$html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1); |
|
1593 |
$html = str_replace('</' . $tag_name . '>', '</' . $tag_name . '>', $html); |
|
1594 |
$new_i = $tag_start + strlen($sanitized); |
|
1595 |
||
1596 |
$len = strlen($html); |
|
1597 |
$i = $new_i; |
|
1598 |
||
1599 |
$in_tag = false; |
|
1600 |
$tag_name = ''; |
|
1601 |
continue; |
|
1602 |
} |
|
1603 |
else |
|
1604 |
{ |
|
1605 |
if ( $tag_name == '?php' && !$filter_php ) |
|
1606 |
continue; |
|
1607 |
$f = fixTagAttributes( $attribs_only, $tag_name ); |
|
1608 |
$s = ( empty($f) ) ? '' : ' '; |
|
1609 |
||
1610 |
$sanitized = '<' . $tag_name . $f . '>'; |
|
1611 |
$new_i = $tag_start + strlen($sanitized); |
|
1612 |
||
1613 |
$html = substr($html, 0, $tag_start) . $sanitized . substr($html, $i + 1); |
|
1614 |
$len = strlen($html); |
|
1615 |
$i = $new_i; |
|
1616 |
||
1617 |
$in_tag = false; |
|
1618 |
$tag_name = ''; |
|
1619 |
continue; |
|
1620 |
} |
|
1621 |
} |
|
1622 |
elseif ( $in_tag && $trk_name ) |
|
1623 |
{ |
|
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
|
1624 |
$is_alphabetical = ( strtolower($chr) != strtoupper($chr) || in_array($chr, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) || $chr == '?' || $chr == '!' || $chr == '-' ); |
1 | 1625 |
if ( $is_alphabetical ) |
1626 |
$tag_name .= $chr; |
|
1627 |
else |
|
1628 |
{ |
|
1629 |
$trk_name = false; |
|
1630 |
} |
|
1631 |
} |
|
1632 |
||
1633 |
} |
|
1634 |
||
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
|
1635 |
// 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
|
1636 |
// <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
|
1637 |
// < |
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
|
1638 |
// 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
|
1639 |
$html = preg_replace('/<(script|iframe)(.+?)src=([^>]*)</i', '<\\1\\2src=\\3<', $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
|
1640 |
|
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
|
1641 |
// Unstrip comments |
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
|
1642 |
$html = preg_replace('/<!--([^>]*?)-->/i', '', $html); |
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
|
1643 |
|
1 | 1644 |
return $html; |
1645 |
||
1646 |
} |
|
1647 |
||
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
|
1648 |
/** |
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
|
1649 |
* 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
|
1650 |
* @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
|
1651 |
* @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
|
1652 |
*/ |
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
|
1653 |
|
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
|
1654 |
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
|
1655 |
{ |
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
|
1656 |
|
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
|
1657 |
$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
|
1658 |
$tok2 = "</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
|
1659 |
|
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
|
1660 |
$block_tags = array('div', 'p', 'table', 'blockquote', '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
|
1661 |
|
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
|
1662 |
$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
|
1663 |
$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
|
1664 |
$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
|
1665 |
$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
|
1666 |
$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
|
1667 |
$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
|
1668 |
$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
|
1669 |
|
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
|
1670 |
$diag = 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
|
1671 |
|
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
|
1672 |
$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
|
1673 |
$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
|
1674 |
$block_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
|
1675 |
|
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
|
1676 |
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
|
1677 |
{ |
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
|
1678 |
$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
|
1679 |
$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
|
1680 |
$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
|
1681 |
|
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
|
1682 |
// 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
|
1683 |
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
|
1684 |
{ |
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
|
1685 |
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
|
1686 |
$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
|
1687 |
} |
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
|
1688 |
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
|
1689 |
{ |
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
|
1690 |
$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
|
1691 |
$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
|
1692 |
} |
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
|
1693 |
|
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
|
1694 |
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
|
1695 |
{ |
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
|
1696 |
// 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
|
1697 |
$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
|
1698 |
$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
|
1699 |
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
|
1700 |
{ |
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
|
1701 |
$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
|
1702 |
// 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
|
1703 |
$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
|
1704 |
$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
|
1705 |
$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
|
1706 |
$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
|
1707 |
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
|
1708 |
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
|
1709 |
} |
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
|
1710 |
// 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
|
1711 |
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
|
1712 |
{ |
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
|
1713 |
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
|
1714 |
{ |
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
|
1715 |
$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
|
1716 |
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
|
1717 |
{ |
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
|
1718 |
$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
|
1719 |
$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
|
1720 |
// 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
|
1721 |
$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
|
1722 |
$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
|
1723 |
$html = substr($html, 0, $block_start) . $new_text . substr($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
|
1724 |
|
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
|
1725 |
$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
|
1726 |
$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
|
1727 |
|
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
|
1728 |
//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
|
1729 |
} |
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
|
1730 |
} |
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
|
1731 |
} |
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
|
1732 |
|
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
|
1733 |
$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
|
1734 |
$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
|
1735 |
$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
|
1736 |
|
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
|
1737 |
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
|
1738 |
} |
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
|
1739 |
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
|
1740 |
{ |
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
|
1741 |
// 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
|
1742 |
$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
|
1743 |
$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
|
1744 |
$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
|
1745 |
} |
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
|
1746 |
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
|
1747 |
{ |
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
|
1748 |
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
|
1749 |
{ |
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
|
1750 |
// 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
|
1751 |
// echo '<inline ' . $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
|
1752 |
|
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
|
1753 |
$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
|
1754 |
$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
|
1755 |
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
|
1756 |
} |
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
|
1757 |
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
|
1758 |
{ |
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
|
1759 |
// 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
|
1760 |
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
|
1761 |
{ |
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
|
1762 |
//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
|
1763 |
$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
|
1764 |
$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
|
1765 |
$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
|
1766 |
} |
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
|
1767 |
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
|
1768 |
{ |
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
|
1769 |
$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
|
1770 |
} |
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
|
1771 |
|
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
|
1772 |
$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
|
1773 |
$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
|
1774 |
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
|
1775 |
} |
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
|
1776 |
} |
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
|
1777 |
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
|
1778 |
{ |
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
|
1779 |
$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
|
1780 |
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
|
1781 |
$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
|
1782 |
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
|
1783 |
{ |
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
|
1784 |
$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
|
1785 |
} |
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
|
1786 |
} |
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
|
1787 |
|
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
|
1788 |
// Tokenization complete |
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
|
1789 |
|
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
|
1790 |
} |
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
|
1791 |
|
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
|
1792 |
$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
|
1793 |
// 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
|
1794 |
$html = preg_replace($regex, '\\1', $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
|
1795 |
|
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
|
1796 |
return $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
|
1797 |
|
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
|
1798 |
} |
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
|
1799 |
|
1 | 1800 |
function htmlalternatives($string) |
1801 |
{ |
|
1802 |
$ret = ''; |
|
1803 |
for ( $i = 0; $i < strlen($string); $i++ ) |
|
1804 |
{ |
|
1805 |
$chr = $string{$i}; |
|
1806 |
$ch1 = ord($chr); |
|
1807 |
$ch2 = dechex($ch1); |
|
1808 |
$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) . ')'; |
|
1809 |
$ret .= $byte; |
|
1810 |
$ret .= '([\s]){0,2}'; |
|
1811 |
} |
|
1812 |
return $ret; |
|
1813 |
} |
|
1814 |
||
1815 |
/** |
|
1816 |
* Paginates (breaks into multiple pages) a MySQL result resource, which is treated as unbuffered. |
|
1817 |
* @param resource The MySQL result resource. This should preferably be an unbuffered query. |
|
1818 |
* @param string A template, with variables being named after the column name |
|
1819 |
* @param int The number of total results. This should be determined by a second query. |
|
1820 |
* @param string sprintf-style formatting string for URLs for result pages. First parameter will be start offset. |
|
1821 |
* @param int Optional. Start offset in individual results. Defaults to 0. |
|
1822 |
* @param int Optional. The number of results per page. Defualts to 10. |
|
1823 |
* @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. |
|
1824 |
* @param string Optional. The text to be sent before the result list, only if there are any results. Possibly the start of a table. |
|
1825 |
* @param string Optional. The text to be sent after the result list, only if there are any results. Possibly the end of a table. |
|
1826 |
* @return string |
|
1827 |
*/ |
|
1828 |
||
1829 |
function paginate($q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = '') |
|
1830 |
{ |
|
1831 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
1832 |
$parser = $template->makeParserText($tpl_text); |
|
1833 |
$num_pages = ceil ( $num_results / $perpage ); |
|
1834 |
$out = ''; |
|
1835 |
$i = 0; |
|
1836 |
$this_page = ceil ( $start / $perpage ); |
|
1837 |
||
1838 |
// Build paginator |
|
1839 |
$begin = '<div class="tblholder" style="display: table; margin: 10px 0 0 auto;"> |
|
1840 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
1841 |
<tr><th>Page:</th>'; |
|
1842 |
$block = '<td class="row1" style="text-align: center;">{LINK}</td>'; |
|
1843 |
$end = '</tr></table></div>'; |
|
1844 |
$blk = $template->makeParserText($block); |
|
1845 |
$inner = ''; |
|
1846 |
$cls = 'row2'; |
|
1847 |
if ( $num_pages < 5 ) |
|
1848 |
{ |
|
1849 |
for ( $i = 0; $i < $num_pages; $i++ ) |
|
1850 |
{ |
|
1851 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
1852 |
$offset = strval($i * $perpage); |
|
1853 |
$url = sprintf($result_url, $offset); |
|
1854 |
$j = $i + 1; |
|
1855 |
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>"; |
|
1856 |
$blk->assign_vars(array( |
|
1857 |
'CLASS'=>$cls, |
|
1858 |
'LINK'=>$link |
|
1859 |
)); |
|
1860 |
$inner .= $blk->run(); |
|
1861 |
} |
|
1862 |
} |
|
1863 |
else |
|
1864 |
{ |
|
1865 |
if ( $this_page + 5 > $num_pages ) |
|
1866 |
{ |
|
1867 |
$list = Array(); |
|
1868 |
$tp = $this_page; |
|
1869 |
if ( $this_page + 0 == $num_pages ) $tp = $tp - 3; |
|
1870 |
if ( $this_page + 1 == $num_pages ) $tp = $tp - 2; |
|
1871 |
if ( $this_page + 2 == $num_pages ) $tp = $tp - 1; |
|
1872 |
for ( $i = $tp - 1; $i <= $tp + 1; $i++ ) |
|
1873 |
{ |
|
1874 |
$list[] = $i; |
|
1875 |
} |
|
1876 |
} |
|
1877 |
else |
|
1878 |
{ |
|
1879 |
$list = Array(); |
|
1880 |
$current = $this_page; |
|
1881 |
$lower = ( $current < 3 ) ? 1 : $current - 1; |
|
1882 |
for ( $i = 0; $i < 3; $i++ ) |
|
1883 |
{ |
|
1884 |
$list[] = $lower + $i; |
|
1885 |
} |
|
1886 |
} |
|
1887 |
$url = sprintf($result_url, '0'); |
|
1888 |
$link = ( 0 == $start ) ? "<b>First</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« First</a>"; |
|
1889 |
$blk->assign_vars(array( |
|
1890 |
'CLASS'=>$cls, |
|
1891 |
'LINK'=>$link |
|
1892 |
)); |
|
1893 |
$inner .= $blk->run(); |
|
1894 |
||
1895 |
// if ( !in_array(1, $list) ) |
|
1896 |
// { |
|
1897 |
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
1898 |
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...')); |
|
1899 |
// $inner .= $blk->run(); |
|
1900 |
// } |
|
1901 |
||
1902 |
foreach ( $list as $i ) |
|
1903 |
{ |
|
1904 |
if ( $i == $num_pages ) |
|
1905 |
break; |
|
1906 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
1907 |
$offset = strval($i * $perpage); |
|
1908 |
$url = sprintf($result_url, $offset); |
|
1909 |
$j = $i + 1; |
|
1910 |
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>"; |
|
1911 |
$blk->assign_vars(array( |
|
1912 |
'CLASS'=>$cls, |
|
1913 |
'LINK'=>$link |
|
1914 |
)); |
|
1915 |
$inner .= $blk->run(); |
|
1916 |
} |
|
1917 |
||
1918 |
$total = $num_pages * $perpage - $perpage; |
|
1919 |
||
1920 |
if ( $this_page < $num_pages ) |
|
1921 |
{ |
|
1922 |
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
1923 |
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...')); |
|
1924 |
// $inner .= $blk->run(); |
|
1925 |
||
1926 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
1927 |
$offset = strval($total); |
|
1928 |
$url = sprintf($result_url, $offset); |
|
1929 |
$j = $i + 1; |
|
1930 |
$link = ( $offset == strval($start) ) ? "<b>Last</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Last »</a>"; |
|
1931 |
$blk->assign_vars(array( |
|
1932 |
'CLASS'=>$cls, |
|
1933 |
'LINK'=>$link |
|
1934 |
)); |
|
1935 |
$inner .= $blk->run(); |
|
1936 |
} |
|
1937 |
||
1938 |
} |
|
1939 |
||
1940 |
$inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$this_page.', '.$num_pages.', '.$perpage.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>'; |
|
1941 |
||
1942 |
$paginator = "\n$begin$inner$end\n"; |
|
1943 |
$out .= $paginator; |
|
1944 |
||
1945 |
$cls = 'row2'; |
|
1946 |
||
1947 |
if ( $row = $db->fetchrow($q) ) |
|
1948 |
{ |
|
1949 |
$i = 0; |
|
1950 |
$out .= $header; |
|
1951 |
do { |
|
1952 |
$i++; |
|
1953 |
if ( $i <= $start ) |
|
1954 |
{ |
|
1955 |
continue; |
|
1956 |
} |
|
1957 |
if ( ( $i - $start ) > $perpage ) |
|
1958 |
{ |
|
1959 |
break; |
|
1960 |
} |
|
1961 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
1962 |
foreach ( $row as $j => $val ) |
|
1963 |
{ |
|
1964 |
if ( isset($callers[$j]) ) |
|
1965 |
{ |
|
1966 |
$tmp = ( is_callable($callers[$j]) ) ? @call_user_func($callers[$j], $val, $row) : $v; |
|
1967 |
||
1968 |
if ( $tmp ) |
|
1969 |
{ |
|
1970 |
$row[$j] = $tmp; |
|
1971 |
} |
|
1972 |
} |
|
1973 |
} |
|
1974 |
$parser->assign_vars($row); |
|
1975 |
$parser->assign_vars(array('_css_class' => $cls)); |
|
1976 |
$out .= $parser->run(); |
|
1977 |
} while ( $row = $db->fetchrow($q) ); |
|
1978 |
$out .= $footer; |
|
1979 |
} |
|
1980 |
||
1981 |
$out .= $paginator; |
|
1982 |
||
1983 |
return $out; |
|
1984 |
} |
|
1985 |
||
1986 |
/** |
|
1987 |
* This is the same as paginate(), but it processes an array instead of a MySQL result resource. |
|
1988 |
* @param array The results. Each value is simply echoed. |
|
1989 |
* @param int The number of total results. This should be determined by a second query. |
|
1990 |
* @param string sprintf-style formatting string for URLs for result pages. First parameter will be start offset. |
|
1991 |
* @param int Optional. Start offset in individual results. Defaults to 0. |
|
1992 |
* @param int Optional. The number of results per page. Defualts to 10. |
|
1993 |
* @param string Optional. The text to be sent before the result list, only if there are any results. Possibly the start of a table. |
|
1994 |
* @param string Optional. The text to be sent after the result list, only if there are any results. Possibly the end of a table. |
|
1995 |
* @return string |
|
1996 |
*/ |
|
1997 |
||
1998 |
function paginate_array($q, $num_results, $result_url, $start = 0, $perpage = 10, $header = '', $footer = '') |
|
1999 |
{ |
|
2000 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
2001 |
$parser = $template->makeParserText($tpl_text); |
|
2002 |
$num_pages = ceil ( $num_results / $perpage ); |
|
2003 |
$out = ''; |
|
2004 |
$i = 0; |
|
2005 |
$this_page = ceil ( $start / $perpage ); |
|
2006 |
||
2007 |
// Build paginator |
|
2008 |
$begin = '<div class="tblholder" style="display: table; margin: 10px 0 0 auto;"> |
|
2009 |
<table border="0" cellspacing="1" cellpadding="4"> |
|
2010 |
<tr><th>Page:</th>'; |
|
2011 |
$block = '<td class="row1" style="text-align: center;">{LINK}</td>'; |
|
2012 |
$end = '</tr></table></div>'; |
|
2013 |
$blk = $template->makeParserText($block); |
|
2014 |
$inner = ''; |
|
2015 |
$cls = 'row2'; |
|
2016 |
if ( $start > 0 ) |
|
2017 |
{ |
|
2018 |
$url = sprintf($result_url, abs($start - $perpage)); |
|
2019 |
$link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« Prev</a>"; |
|
2020 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
2021 |
$blk->assign_vars(array( |
|
2022 |
'CLASS'=>$cls, |
|
2023 |
'LINK'=>$link |
|
2024 |
)); |
|
2025 |
$inner .= $blk->run(); |
|
2026 |
} |
|
2027 |
if ( $num_pages < 5 ) |
|
2028 |
{ |
|
2029 |
for ( $i = 0; $i < $num_pages; $i++ ) |
|
2030 |
{ |
|
2031 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
2032 |
$offset = strval($i * $perpage); |
|
2033 |
$url = sprintf($result_url, $offset); |
|
2034 |
$j = $i + 1; |
|
2035 |
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>"; |
|
2036 |
$blk->assign_vars(array( |
|
2037 |
'CLASS'=>$cls, |
|
2038 |
'LINK'=>$link |
|
2039 |
)); |
|
2040 |
$inner .= $blk->run(); |
|
2041 |
} |
|
2042 |
} |
|
2043 |
else |
|
2044 |
{ |
|
2045 |
if ( $this_page + 5 > $num_pages ) |
|
2046 |
{ |
|
2047 |
$list = Array(); |
|
2048 |
$tp = $this_page; |
|
2049 |
if ( $this_page + 0 == $num_pages ) $tp = $tp - 3; |
|
2050 |
if ( $this_page + 1 == $num_pages ) $tp = $tp - 2; |
|
2051 |
if ( $this_page + 2 == $num_pages ) $tp = $tp - 1; |
|
2052 |
for ( $i = $tp - 1; $i <= $tp + 1; $i++ ) |
|
2053 |
{ |
|
2054 |
$list[] = $i; |
|
2055 |
} |
|
2056 |
} |
|
2057 |
else |
|
2058 |
{ |
|
2059 |
$list = Array(); |
|
2060 |
$current = $this_page; |
|
2061 |
$lower = ( $current < 3 ) ? 1 : $current - 1; |
|
2062 |
for ( $i = 0; $i < 3; $i++ ) |
|
2063 |
{ |
|
2064 |
$list[] = $lower + $i; |
|
2065 |
} |
|
2066 |
} |
|
2067 |
$url = sprintf($result_url, '0'); |
|
2068 |
$link = ( 0 == $start ) ? "<b>First</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>« First</a>"; |
|
2069 |
$blk->assign_vars(array( |
|
2070 |
'CLASS'=>$cls, |
|
2071 |
'LINK'=>$link |
|
2072 |
)); |
|
2073 |
$inner .= $blk->run(); |
|
2074 |
||
2075 |
// if ( !in_array(1, $list) ) |
|
2076 |
// { |
|
2077 |
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
2078 |
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...')); |
|
2079 |
// $inner .= $blk->run(); |
|
2080 |
// } |
|
2081 |
||
2082 |
foreach ( $list as $i ) |
|
2083 |
{ |
|
2084 |
if ( $i == $num_pages ) |
|
2085 |
break; |
|
2086 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
2087 |
$offset = strval($i * $perpage); |
|
2088 |
$url = sprintf($result_url, $offset); |
|
2089 |
$j = $i + 1; |
|
2090 |
$link = ( $offset == strval($start) ) ? "<b>$j</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>$j</a>"; |
|
2091 |
$blk->assign_vars(array( |
|
2092 |
'CLASS'=>$cls, |
|
2093 |
'LINK'=>$link |
|
2094 |
)); |
|
2095 |
$inner .= $blk->run(); |
|
2096 |
} |
|
2097 |
||
2098 |
$total = $num_pages * $perpage - $perpage; |
|
2099 |
||
2100 |
if ( $this_page < $num_pages ) |
|
2101 |
{ |
|
2102 |
// $cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
2103 |
// $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...')); |
|
2104 |
// $inner .= $blk->run(); |
|
2105 |
||
2106 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
2107 |
$offset = strval($total); |
|
2108 |
$url = sprintf($result_url, $offset); |
|
2109 |
$j = $i + 1; |
|
2110 |
$link = ( $offset == strval($start) ) ? "<b>Last</b>" : "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Last »</a>"; |
|
2111 |
$blk->assign_vars(array( |
|
2112 |
'CLASS'=>$cls, |
|
2113 |
'LINK'=>$link |
|
2114 |
)); |
|
2115 |
$inner .= $blk->run(); |
|
2116 |
} |
|
2117 |
||
2118 |
} |
|
2119 |
||
2120 |
if ( $start < $total ) |
|
2121 |
{ |
|
2122 |
$url = sprintf($result_url, abs($start + $perpage)); |
|
2123 |
$link = "<a href=".'"'."$url".'"'." style='text-decoration: none;'>Next »</a>"; |
|
2124 |
$cls = ( $cls == 'row1' ) ? 'row2' : 'row1'; |
|
2125 |
$blk->assign_vars(array( |
|
2126 |
'CLASS'=>$cls, |
|
2127 |
'LINK'=>$link |
|
2128 |
)); |
|
2129 |
$inner .= $blk->run(); |
|
2130 |
} |
|
2131 |
||
2132 |
$inner .= '<td class="row2" style="cursor: pointer;" onclick="paginator_goto(this, '.$this_page.', '.$num_pages.', '.$perpage.', unescape(\'' . rawurlencode($result_url) . '\'));">↓</td>'; |
|
2133 |
||
2134 |
$paginator = "\n$begin$inner$end\n"; |
|
2135 |
if ( $total > 1 ) |
|
2136 |
$out .= $paginator; |
|
2137 |
||
2138 |
$cls = 'row2'; |
|
2139 |
||
2140 |
if ( sizeof($q) > 0 ) |
|
2141 |
{ |
|
2142 |
$i = 0; |
|
2143 |
$out .= $header; |
|
2144 |
foreach ( $q as $val ) { |
|
2145 |
$i++; |
|
2146 |
if ( $i <= $start ) |
|
2147 |
{ |
|
2148 |
continue; |
|
2149 |
} |
|
2150 |
if ( ( $i - $start ) > $perpage ) |
|
2151 |
{ |
|
2152 |
break; |
|
2153 |
} |
|
2154 |
$out .= $val; |
|
2155 |
} |
|
2156 |
$out .= $footer; |
|
2157 |
} |
|
2158 |
||
2159 |
if ( $total > 1 ) |
|
2160 |
$out .= $paginator; |
|
2161 |
||
2162 |
return $out; |
|
2163 |
} |
|
2164 |
||
2165 |
/** |
|
2166 |
* Enano version of fputs for debugging |
|
2167 |
*/ |
|
2168 |
||
2169 |
function enano_fputs($socket, $data) |
|
2170 |
{ |
|
2171 |
// echo '<pre>' . htmlspecialchars($data) . '</pre>'; |
|
2172 |
// flush(); |
|
2173 |
// ob_flush(); |
|
2174 |
// ob_end_flush(); |
|
2175 |
return fputs($socket, $data); |
|
2176 |
} |
|
2177 |
||
2178 |
/** |
|
2179 |
* Sanitizes a page URL string so that it can safely be stored in the database. |
|
2180 |
* @param string Page ID to sanitize |
|
2181 |
* @return string Cleaned text |
|
2182 |
*/ |
|
2183 |
||
2184 |
function sanitize_page_id($page_id) |
|
2185 |
{ |
|
2186 |
||
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
|
2187 |
// 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
|
2188 |
$page_id = dirtify_page_id($page_id); |
1 | 2189 |
|
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
|
2190 |
$pid_clean = preg_replace('/[\w\.\/:;\(\)@\[\]_-]/', 'X', $page_id); |
1 | 2191 |
$pid_dirty = enano_str_split($pid_clean, 1); |
2192 |
||
2193 |
foreach ( $pid_dirty as $id => $char ) |
|
2194 |
{ |
|
2195 |
if ( $char == 'X' ) |
|
2196 |
continue; |
|
2197 |
$cid = ord($char); |
|
2198 |
$cid = dechex($cid); |
|
2199 |
$cid = strval($cid); |
|
2200 |
if ( strlen($cid) < 2 ) |
|
2201 |
{ |
|
2202 |
$cid = strtoupper("0$cid"); |
|
2203 |
} |
|
2204 |
$pid_dirty[$id] = ".$cid"; |
|
2205 |
} |
|
2206 |
||
2207 |
$pid_chars = enano_str_split($page_id, 1); |
|
2208 |
$page_id_cleaned = ''; |
|
2209 |
||
2210 |
foreach ( $pid_chars as $id => $char ) |
|
2211 |
{ |
|
2212 |
if ( $pid_dirty[$id] == 'X' ) |
|
2213 |
$page_id_cleaned .= $char; |
|
2214 |
else |
|
2215 |
$page_id_cleaned .= $pid_dirty[$id]; |
|
2216 |
} |
|
2217 |
||
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
|
2218 |
// global $mime_types; |
1 | 2219 |
|
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
|
2220 |
// $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
|
2221 |
// $exts = '(' . implode('|', $exts) . ')'; |
1 | 2222 |
|
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
|
2223 |
// $page_id_cleaned = preg_replace('/\.2e' . $exts . '$/', '.\\1', $page_id_cleaned); |
1 | 2224 |
|
2225 |
return $page_id_cleaned; |
|
2226 |
} |
|
2227 |
||
2228 |
/** |
|
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
|
2229 |
* 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
|
2230 |
* @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
|
2231 |
* @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
|
2232 |
*/ |
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
|
2233 |
|
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
|
2234 |
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
|
2235 |
{ |
38 | 2236 |
global $db, $session, $paths, $template, $plugins; // Common objects |
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
|
2237 |
// First, replace spaces with underscores |
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
|
2238 |
$page_id = str_replace(' ', '_', $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
|
2239 |
|
38 | 2240 |
// Exception for userpages for IP addresses |
2241 |
if ( preg_match('/^' . preg_quote($paths->nslist['User']) . '/', $page_id) ) |
|
2242 |
{ |
|
2243 |
$ip = preg_replace('/^' . preg_quote($paths->nslist['User']) . '/', '', $page_id); |
|
2244 |
if ( is_valid_ip($ip) ) |
|
2245 |
return $page_id; |
|
2246 |
} |
|
2247 |
||
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
|
2248 |
preg_match_all('/\.[A-Fa-f0-9][A-Fa-f0-9]/', $page_id, $matches); |
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
|
2249 |
|
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
|
2250 |
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
|
2251 |
{ |
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
|
2252 |
$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
|
2253 |
$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
|
2254 |
$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
|
2255 |
$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
|
2256 |
$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
|
2257 |
} |
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
|
2258 |
|
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
|
2259 |
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
|
2260 |
} |
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
|
2261 |
|
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
|
2262 |
/** |
1 | 2263 |
* Inserts commas into a number to make it more human-readable. Floating point-safe. |
2264 |
* @param int The number to process |
|
2265 |
* @return string Input number with commas added |
|
2266 |
*/ |
|
2267 |
||
2268 |
function commatize($num) |
|
2269 |
{ |
|
2270 |
$num = (string)$num; |
|
2271 |
if ( strpos($num, '.') ) |
|
2272 |
{ |
|
2273 |
$whole = explode('.', $num); |
|
2274 |
$num = $whole[0]; |
|
2275 |
$dec = $whole[1]; |
|
2276 |
} |
|
2277 |
else |
|
2278 |
{ |
|
2279 |
$whole = $num; |
|
2280 |
} |
|
2281 |
$offset = ( strlen($num) ) % 3; |
|
2282 |
$len = strlen($num); |
|
2283 |
$offset = ( $offset == 0 ) |
|
2284 |
? 3 |
|
2285 |
: $offset; |
|
2286 |
for ( $i = $offset; $i < $len; $i=$i+3 ) |
|
2287 |
{ |
|
2288 |
$num = substr($num, 0, $i) . ',' . substr($num, $i, $len); |
|
2289 |
$len = strlen($num); |
|
2290 |
$i++; |
|
2291 |
} |
|
2292 |
if ( isset($dec) ) |
|
2293 |
{ |
|
2294 |
return $num . '.' . $dec; |
|
2295 |
} |
|
2296 |
else |
|
2297 |
{ |
|
2298 |
return $num; |
|
2299 |
} |
|
2300 |
} |
|
2301 |
||
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
|
2302 |
/** |
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
|
2303 |
* 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
|
2304 |
* @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
|
2305 |
* @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
|
2306 |
* @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
|
2307 |
*/ |
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
|
2308 |
|
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
|
2309 |
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
|
2310 |
{ |
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
|
2311 |
$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
|
2312 |
$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
|
2313 |
$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
|
2314 |
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
|
2315 |
} |
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
|
2316 |
|
38 | 2317 |
/** |
2318 |
* Tells if a given IP address is valid. |
|
2319 |
* @param string suspected IP address |
|
2320 |
* @return bool true if valid, false otherwise |
|
2321 |
*/ |
|
2322 |
||
2323 |
function is_valid_ip($ip) |
|
2324 |
{ |
|
2325 |
// These came from phpBB3. |
|
2326 |
$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])'; |
|
2327 |
$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}:))'; |
|
2328 |
||
2329 |
if ( preg_match("/^{$ipv4}$/", $ip) || preg_match("/^{$ipv6}$/", $ip) ) |
|
2330 |
return true; |
|
2331 |
else |
|
2332 |
return false; |
|
2333 |
} |
|
2334 |
||
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
|
2335 |
/** |
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
|
2336 |
* 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
|
2337 |
* @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
|
2338 |
* @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
|
2339 |
* @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
|
2340 |
*/ |
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
|
2341 |
|
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
|
2342 |
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
|
2343 |
{ |
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
|
2344 |
$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
|
2345 |
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
|
2346 |
{ |
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
|
2347 |
$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
|
2348 |
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
|
2349 |
{ |
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
|
2350 |
// 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
|
2351 |
$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
|
2352 |
$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
|
2353 |
$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
|
2354 |
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
|
2355 |
} |
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
|
2356 |
} |
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
|
2357 |
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
|
2358 |
} |
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
|
2359 |
|
1 | 2360 |
//die('<pre>Original: 01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'</pre>'); |
2361 |
||
2362 |
?> |