author | Dan |
Thu, 12 Jul 2007 01:04:01 -0400 | |
changeset 2 | a8a21e1c7afa |
parent 0 | f9ffdbd96607 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/*********************************************************************** |
|
3 |
||
4 |
Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org) |
|
5 |
||
6 |
This file is part of PunBB. |
|
7 |
||
8 |
PunBB is free software; you can redistribute it and/or modify it |
|
9 |
under the terms of the GNU General Public License as published |
|
10 |
by the Free Software Foundation; either version 2 of the License, |
|
11 |
or (at your option) any later version. |
|
12 |
||
13 |
PunBB is distributed in the hope that it will be useful, but |
|
14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
GNU General Public License for more details. |
|
17 |
||
18 |
You should have received a copy of the GNU General Public License |
|
19 |
along with this program; if not, write to the Free Software |
|
20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
|
21 |
MA 02111-1307 USA |
|
22 |
||
23 |
************************************************************************/ |
|
24 |
||
25 |
||
26 |
// Make sure no one attempts to run this script "directly" |
|
27 |
if (!defined('PUN')) |
|
28 |
exit; |
|
29 |
||
30 |
||
31 |
// |
|
32 |
// If we are running pre PHP 4.2.0, we add our own implementation of var_export |
|
33 |
// |
|
34 |
if (!function_exists('var_export')) |
|
35 |
{ |
|
36 |
function var_export() |
|
37 |
{ |
|
38 |
$args = func_get_args(); |
|
39 |
$indent = (isset($args[2])) ? $args[2] : ''; |
|
40 |
||
41 |
if (is_array($args[0])) |
|
42 |
{ |
|
43 |
$output = 'array ('."\n"; |
|
44 |
||
45 |
foreach ($args[0] as $k => $v) |
|
46 |
{ |
|
47 |
if (is_numeric($k)) |
|
48 |
$output .= $indent.' '.$k.' => '; |
|
49 |
else |
|
50 |
$output .= $indent.' \''.str_replace('\'', '\\\'', str_replace('\\', '\\\\', $k)).'\' => '; |
|
51 |
||
52 |
if (is_array($v)) |
|
53 |
$output .= var_export($v, true, $indent.' '); |
|
54 |
else |
|
55 |
{ |
|
56 |
if (gettype($v) != 'string' && !empty($v)) |
|
57 |
$output .= $v.','."\n"; |
|
58 |
else |
|
59 |
$output .= '\''.str_replace('\'', '\\\'', str_replace('\\', '\\\\', $v)).'\','."\n"; |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
$output .= ($indent != '') ? $indent.'),'."\n" : ')'; |
|
64 |
} |
|
65 |
else |
|
66 |
$output = $args[0]; |
|
67 |
||
68 |
if ($args[1] == true) |
|
69 |
return $output; |
|
70 |
else |
|
71 |
echo $output; |
|
72 |
} |
|
73 |
} |
|
74 |
||
75 |
||
76 |
// |
|
77 |
// Generate the config cache PHP script |
|
78 |
// |
|
79 |
function generate_config_cache() |
|
80 |
{ |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
81 |
global $pun_db; |
0 | 82 |
|
83 |
// Get the forum config from the DB |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
84 |
$result = $pun_db->query('SELECT * FROM '.$pun_db->prefix.'config', true) or error('Unable to fetch forum config', __FILE__, __LINE__, $pun_db->error()); |
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
85 |
while ($cur_config_item = $pun_db->fetch_row($result)) |
0 | 86 |
$output[$cur_config_item[0]] = $cur_config_item[1]; |
87 |
||
88 |
// Output config as PHP code |
|
89 |
$fh = @fopen(PUN_ROOT.'cache/cache_config.php', 'wb'); |
|
90 |
if (!$fh) |
|
91 |
error('Unable to write configuration cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__, __LINE__); |
|
92 |
||
93 |
fwrite($fh, '<?php'."\n\n".'define(\'PUN_CONFIG_LOADED\', 1);'."\n\n".'$pun_config = '.var_export($output, true).';'."\n\n".'?>'); |
|
94 |
||
95 |
fclose($fh); |
|
96 |
} |
|
97 |
||
98 |
||
99 |
// |
|
100 |
// Generate the bans cache PHP script |
|
101 |
// |
|
102 |
function generate_bans_cache() |
|
103 |
{ |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
104 |
global $pun_db; |
0 | 105 |
|
106 |
// Get the ban list from the DB |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
107 |
$result = $pun_db->query('SELECT * FROM '.$pun_db->prefix.'bans', true) or error('Unable to fetch ban list', __FILE__, __LINE__, $pun_db->error()); |
0 | 108 |
|
109 |
$output = array(); |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
110 |
while ($cur_ban = $pun_db->fetch_assoc($result)) |
0 | 111 |
$output[] = $cur_ban; |
112 |
||
113 |
// Output ban list as PHP code |
|
114 |
$fh = @fopen(PUN_ROOT.'cache/cache_bans.php', 'wb'); |
|
115 |
if (!$fh) |
|
116 |
error('Unable to write bans cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__, __LINE__); |
|
117 |
||
118 |
fwrite($fh, '<?php'."\n\n".'define(\'PUN_BANS_LOADED\', 1);'."\n\n".'$pun_bans = '.var_export($output, true).';'."\n\n".'?>'); |
|
119 |
||
120 |
fclose($fh); |
|
121 |
} |
|
122 |
||
123 |
||
124 |
// |
|
125 |
// Generate the ranks cache PHP script |
|
126 |
// |
|
127 |
function generate_ranks_cache() |
|
128 |
{ |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
129 |
global $pun_db; |
0 | 130 |
|
131 |
// Get the rank list from the DB |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
132 |
$result = $pun_db->query('SELECT * FROM '.$pun_db->prefix.'ranks ORDER BY min_posts', true) or error('Unable to fetch rank list', __FILE__, __LINE__, $pun_db->error()); |
0 | 133 |
|
134 |
$output = array(); |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
135 |
while ($cur_rank = $pun_db->fetch_assoc($result)) |
0 | 136 |
$output[] = $cur_rank; |
137 |
||
138 |
// Output ranks list as PHP code |
|
139 |
$fh = @fopen(PUN_ROOT.'cache/cache_ranks.php', 'wb'); |
|
140 |
if (!$fh) |
|
141 |
error('Unable to write ranks cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__, __LINE__); |
|
142 |
||
143 |
fwrite($fh, '<?php'."\n\n".'define(\'PUN_RANKS_LOADED\', 1);'."\n\n".'$pun_ranks = '.var_export($output, true).';'."\n\n".'?>'); |
|
144 |
||
145 |
fclose($fh); |
|
146 |
} |
|
147 |
||
148 |
||
149 |
// |
|
150 |
// Generate quickjump cache PHP scripts |
|
151 |
// |
|
152 |
function generate_quickjump_cache($group_id = false) |
|
153 |
{ |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
154 |
global $pun_db, $lang_common, $pun_user; |
0 | 155 |
|
156 |
// If a group_id was supplied, we generate the quickjump cache for that group only |
|
157 |
if ($group_id !== false) |
|
158 |
$groups[0] = $group_id; |
|
159 |
else |
|
160 |
{ |
|
161 |
// A group_id was now supplied, so we generate the quickjump cache for all groups |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
162 |
$result = $pun_db->query('SELECT g_id FROM '.$pun_db->prefix.'groups') or error('Unable to fetch user group list', __FILE__, __LINE__, $pun_db->error()); |
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
163 |
$num_groups = $pun_db->num_rows($result); |
0 | 164 |
|
165 |
for ($i = 0; $i < $num_groups; ++$i) |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
166 |
$groups[] = $pun_db->result($result, $i); |
0 | 167 |
} |
168 |
||
169 |
// Loop through the groups in $groups and output the cache for each of them |
|
170 |
while (list(, $group_id) = @each($groups)) |
|
171 |
{ |
|
172 |
// Output quickjump as PHP code |
|
173 |
$fh = @fopen(PUN_ROOT.'cache/cache_quickjump_'.$group_id.'.php', 'wb'); |
|
174 |
if (!$fh) |
|
175 |
error('Unable to write quickjump cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__, __LINE__); |
|
176 |
||
177 |
$output = '<?php'."\n\n".'if (!defined(\'PUN\')) exit;'."\n".'define(\'PUN_QJ_LOADED\', 1);'."\n\n".'?>'; |
|
178 |
$output .= "\t\t\t\t".'<form id="qjump" method="get" action="viewforum.php">'."\n\t\t\t\t\t".'<div><label><?php echo $lang_common[\'Jump to\'] ?>'."\n\n\t\t\t\t\t".'<br /><select name="id" onchange="window.location=(\'viewforum.php?id=\'+this.options[this.selectedIndex].value)">'."\n"; |
|
179 |
||
180 |
||
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
181 |
$result = $pun_db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url FROM '.$pun_db->prefix.'categories AS c INNER JOIN '.$pun_db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$pun_db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$group_id.') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $pun_db->error()); |
0 | 182 |
|
183 |
$cur_category = 0; |
|
2
a8a21e1c7afa
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents:
0
diff
changeset
|
184 |
while ($cur_forum = $pun_db->fetch_assoc($result)) |
0 | 185 |
{ |
186 |
if ($cur_forum['cid'] != $cur_category) // A new category since last iteration? |
|
187 |
{ |
|
188 |
if ($cur_category) |
|
189 |
$output .= "\t\t\t\t\t\t".'</optgroup>'."\n"; |
|
190 |
||
191 |
$output .= "\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n"; |
|
192 |
$cur_category = $cur_forum['cid']; |
|
193 |
} |
|
194 |
||
195 |
$redirect_tag = ($cur_forum['redirect_url'] != '') ? ' >>>' : ''; |
|
196 |
$output .= "\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'"<?php echo ($forum_id == '.$cur_forum['fid'].') ? \' selected="selected"\' : \'\' ?>>'.pun_htmlspecialchars($cur_forum['forum_name']).$redirect_tag.'</option>'."\n"; |
|
197 |
} |
|
198 |
||
199 |
$output .= "\t\t\t\t\t".'</optgroup>'."\n\t\t\t\t\t".'</select>'."\n\t\t\t\t\t".'<input type="submit" value="<?php echo $lang_common[\'Go\'] ?>" accesskey="g" />'."\n\t\t\t\t\t".'</label></div>'."\n\t\t\t\t".'</form>'."\n"; |
|
200 |
||
201 |
fwrite($fh, $output); |
|
202 |
||
203 |
fclose($fh); |
|
204 |
} |
|
205 |
} |