2 /***********************************************************************
4 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
6 This file is part of PunBB.
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.
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.
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,
23 ************************************************************************/
26 // Make sure no one attempts to run this script "directly"
32 // If we are running pre PHP 4.2.0, we add our own implementation of var_export
34 if (!function_exists('var_export'))
38 $args = func_get_args();
39 $indent = (isset($args[2])) ?
$args[2] : '';
41 if (is_array($args[0]))
43 $output = 'array ('."\n";
45 foreach ($args[0] as $k => $v)
48 $output .= $indent.' '.$k.' => ';
50 $output .= $indent.' \''.str_replace('\'', '\\\'', str_replace('\\', '\\\\', $k)).'\' => ';
53 $output .= var_export($v, true, $indent.' ');
56 if (gettype($v) != 'string' && !empty($v))
57 $output .= $v.','."\n";
59 $output .= '\''.str_replace('\'', '\\\'', str_replace('\\', '\\\\', $v)).'\','."\n";
63 $output .= ($indent != '') ?
$indent.'),'."\n" : ')';
77 // Generate the config cache PHP script
79 function generate_config_cache()
83 // Get the forum config from the DB
84 $result = $db->query('SELECT * FROM '.$db->prefix
.'config', true) or error('Unable to fetch forum config', __FILE__
, __LINE__
, $db->error());
85 while ($cur_config_item = $db->fetch_row($result))
86 $output[$cur_config_item[0]] = $cur_config_item[1];
88 // Output config as PHP code
89 $fh = @fopen
(PUN_ROOT
.'cache/cache_config.php', 'wb');
91 error('Unable to write configuration cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__
, __LINE__
);
93 fwrite($fh, '<?php'."\n\n".'define(\'PUN_CONFIG_LOADED\', 1);'."\n\n".'$pun_config = '.var_export($output, true).';'."\n\n".'?>');
100 // Generate the bans cache PHP script
102 function generate_bans_cache()
106 // Get the ban list from the DB
107 $result = $db->query('SELECT * FROM '.$db->prefix
.'bans', true) or error('Unable to fetch ban list', __FILE__
, __LINE__
, $db->error());
110 while ($cur_ban = $db->fetch_assoc($result))
111 $output[] = $cur_ban;
113 // Output ban list as PHP code
114 $fh = @fopen
(PUN_ROOT
.'cache/cache_bans.php', 'wb');
116 error('Unable to write bans cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__
, __LINE__
);
118 fwrite($fh, '<?php'."\n\n".'define(\'PUN_BANS_LOADED\', 1);'."\n\n".'$pun_bans = '.var_export($output, true).';'."\n\n".'?>');
125 // Generate the ranks cache PHP script
127 function generate_ranks_cache()
131 // Get the rank list from the DB
132 $result = $db->query('SELECT * FROM '.$db->prefix
.'ranks ORDER BY min_posts', true) or error('Unable to fetch rank list', __FILE__
, __LINE__
, $db->error());
135 while ($cur_rank = $db->fetch_assoc($result))
136 $output[] = $cur_rank;
138 // Output ranks list as PHP code
139 $fh = @fopen
(PUN_ROOT
.'cache/cache_ranks.php', 'wb');
141 error('Unable to write ranks cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__
, __LINE__
);
143 fwrite($fh, '<?php'."\n\n".'define(\'PUN_RANKS_LOADED\', 1);'."\n\n".'$pun_ranks = '.var_export($output, true).';'."\n\n".'?>');
150 // Generate quickjump cache PHP scripts
152 function generate_quickjump_cache($group_id = false)
154 global $db, $lang_common, $pun_user;
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;
161 // A group_id was now supplied, so we generate the quickjump cache for all groups
162 $result = $db->query('SELECT g_id FROM '.$db->prefix
.'groups') or error('Unable to fetch user group list', __FILE__
, __LINE__
, $db->error());
163 $num_groups = $db->num_rows($result);
165 for ($i = 0; $i < $num_groups; ++
$i)
166 $groups[] = $db->result($result, $i);
169 // Loop through the groups in $groups and output the cache for each of them
170 while (list(, $group_id) = @each
($groups))
172 // Output quickjump as PHP code
173 $fh = @fopen
(PUN_ROOT
.'cache/cache_quickjump_'.$group_id.'.php', 'wb');
175 error('Unable to write quickjump cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__
, __LINE__
);
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";
181 $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url FROM '.$db->prefix
.'categories AS c INNER JOIN '.$db->prefix
.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$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__
, $db->error());
184 while ($cur_forum = $db->fetch_assoc($result))
186 if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
189 $output .= "\t\t\t\t\t\t".'</optgroup>'."\n";
191 $output .= "\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
192 $cur_category = $cur_forum['cid'];
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";
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";
201 fwrite($fh, $output);