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