]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2/admin/xs_cache.php
4f01b4f733b39e532a601ccdaa91d768a8672caa
[www.vanrenterghem.biz.git] / phpBB2 / admin / xs_cache.php
1 <?php\r
2 \r
3 /***************************************************************************\r
4  *                                xs_cache.php\r
5  *                                ------------\r
6  *   copyright            : (C) 2003 - 2005 CyberAlien\r
7  *   support              : http://www.phpbbstyles.com\r
8  *\r
9  *   version              : 2.3.1\r
10  *\r
11  *   file revision        : 72\r
12  *   project revision     : 78\r
13  *   last modified        : 05 Dec 2005  13:54:54\r
14  *\r
15  ***************************************************************************/\r
16 \r
17 /***************************************************************************\r
18  *\r
19  *   This program is free software; you can redistribute it and/or modify\r
20  *   it under the terms of the GNU General Public License as published by\r
21  *   the Free Software Foundation; either version 2 of the License, or\r
22  *   (at your option) any later version.\r
23  *\r
24  ***************************************************************************/\r
25 \r
26 define('IN_PHPBB', 1);\r
27 $phpbb_root_path = "./../";\r
28 $no_page_header = true;\r
29 require($phpbb_root_path . 'extension.inc');\r
30 require('./pagestart.' . $phpEx);\r
31 \r
32 // check if mod is installed\r
33 if(empty($template->xs_version) || $template->xs_version !== 8)\r
34 {\r
35         message_die(GENERAL_ERROR, isset($lang['xs_error_not_installed']) ? $lang['xs_error_not_installed'] : 'eXtreme Styles mod is not installed. You forgot to upload includes/template.php');\r
36 }\r
37 \r
38 define('IN_XS', true);\r
39 include_once('xs_include.' . $phpEx);\r
40 \r
41 $template->assign_block_vars('nav_left',array('ITEM' => '&raquo; <a href="' . append_sid('xs_cache.'.$phpEx) . '">' . $lang['xs_manage_cache'] . '</a>'));\r
42 \r
43 $data = '';\r
44 \r
45 $skip_files = array(\r
46         '.',\r
47         '..',\r
48         '.htaccess',\r
49         'index.htm',\r
50         'index.html',\r
51         'index.php',\r
52         'attach_config.php',\r
53         );\r
54 \r
55 //\r
56 // clear cache\r
57 //\r
58 if(isset($HTTP_GET_VARS['clear']) && !defined('DEMO_MODE'))\r
59 {\r
60         @set_time_limit(XS_MAX_TIMEOUT);\r
61         $clear = $HTTP_GET_VARS['clear'];\r
62         if(!$clear)\r
63         {\r
64                 // clear all cache\r
65                 $match = '';\r
66         }\r
67         else\r
68         {\r
69                 $match = XS_TPL_PREFIX . $clear . XS_SEPARATOR;\r
70         }\r
71         $match_len = strlen($match);\r
72         $style_len = strlen(STYLE_EXTENSION);\r
73         $backup_len = strlen(XS_BACKUP_EXT);\r
74         $dir = $template->cachedir;\r
75         $res = @opendir($dir);\r
76         if(!$res)\r
77         {\r
78                 $data = $lang['xs_cache_nowrite'];\r
79         }\r
80         else\r
81         {\r
82                 $num = 0;\r
83                 $num_error = 0;\r
84                 while(($file = readdir($res)) !== false)\r
85                 {\r
86                         $len = strlen($file);\r
87                         // delete only files that match pattern, that aren't in exclusion list and that aren't downloaded styles.\r
88                         if(substr($file, 0, $match_len) === $match && !xs_in_array($file, $skip_files))\r
89                         if(substr($file, $len - $style_len) !== STYLE_EXTENSION && substr($file, $len - $backup_len) !== XS_BACKUP_EXT)\r
90                         {\r
91                                 $res2 = @unlink($dir . $file);\r
92                                 if($res2)\r
93                                 {\r
94                                         $data .= str_replace('{FILE}', $file, $lang['xs_cache_log_deleted']) . "<br />\n";\r
95                                         $num ++;\r
96                                 }\r
97                                 elseif(@is_file($dir . $file))\r
98                                 {\r
99                                         $data .= str_replace('{FILE}', $file, $lang['xs_cache_log_nodelete']) . "<br />\n";\r
100                                         $num_error ++;\r
101                                 }\r
102                         }\r
103                 }\r
104                 closedir($res);\r
105                 if(!$num && !$num_error)\r
106                 {\r
107                         if($clear)\r
108                         {\r
109                                 $data .= str_replace('{TPL}', $clear, $lang['xs_cache_log_nothing']) . "<br />\n";\r
110                         }\r
111                         else\r
112                         {\r
113                                 $data .= $lang['xs_cache_log_nothing2'] . "<br />\n";\r
114                         }\r
115                 }\r
116                 else\r
117                 {\r
118                         $data .= str_replace('{NUM}', $num, $lang['xs_cache_log_count']) . "<br />\n";\r
119                         if($num_error)\r
120                         {\r
121                                 $data .= str_replace('{NUM}', $num_error, $lang['xs_cache_log_count2']) . "<br />\n";\r
122                         }\r
123                 }\r
124         }\r
125 }\r
126 \r
127 \r
128 //\r
129 // compile cache\r
130 //\r
131 if(isset($HTTP_GET_VARS['compile']) && !defined('DEMO_MODE'))\r
132 {\r
133         $tpl = $HTTP_GET_VARS['compile'];\r
134         @set_time_limit(XS_MAX_TIMEOUT);\r
135         $num_errors = 0;\r
136         $num_compiled = 0;\r
137         if($tpl)\r
138         {\r
139                 $dir = $template->tpldir . $tpl . '/';\r
140                 compile_cache($dir, '', $tpl);\r
141         }\r
142         else\r
143         {\r
144                 $res = opendir('../templates');\r
145                 while(($file = readdir($res)) !== false)\r
146                 {\r
147                         if($file !== '.' && $file !== '..' && is_dir('../templates/'.$file) && @file_exists('../templates/'.$file.'/overall_header.tpl'))\r
148                         {\r
149                                 compile_cache('../templates/'.$file.'/', '', $file);\r
150                         }\r
151                 }\r
152                 closedir($res);\r
153         }\r
154         $data .= str_replace('{NUM}', $num_compiled, $lang['xs_cache_log_compiled']) . "<br />\n";\r
155         $data .= str_replace('{NUM}', $num_errors, $lang['xs_cache_log_errors']) . "<br />\n";\r
156 }\r
157 \r
158 function compile_cache($dir, $subdir, $tpl)\r
159 {\r
160         global $data, $template, $num_errors, $num_compiled, $lang;\r
161         $str = $dir . $subdir;\r
162         $res = @opendir($dir . $subdir);\r
163         if(!$res)\r
164         {\r
165                 $data .= str_replace('{DIR}', $dir.$subdir, $lang['xs_cache_log_noaccess']) . "<br />\n";\r
166                 $num_errors ++;\r
167                 return;\r
168         }\r
169         while(($file = readdir($res)) !== false)\r
170         {\r
171                 if(@is_dir($str . $file) && $file !== '.' && $file !== '..' && $file !== 'CVS')\r
172                 {\r
173                         compile_cache($dir, $subdir . $file . '/', $tpl);\r
174                 }\r
175                 elseif(substr($file, strlen($file) - 4) === '.tpl')\r
176                 {\r
177                         $res2 = $template->precompile($tpl, $subdir . $file);\r
178                         if($res2)\r
179                         {\r
180                                 $data .= str_replace('{FILE}', $dir.$subdir.$file, $lang['xs_cache_log_compiled2']) . "<br />\n";\r
181                                 $num_compiled ++;\r
182                         }\r
183                         else\r
184                         {\r
185                                 $data .= str_replace('{FILE}', $dir.$subdir.$file, $lang['xs_cache_log_nocompile']) . "<br />\n";\r
186                                 $num_errors ++;\r
187                         }\r
188                 }\r
189         }\r
190         closedir($res);\r
191 }\r
192 \r
193 //\r
194 // get list of installed styles\r
195 //\r
196 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY template_name';\r
197 if(!$result = $db->sql_query($sql))\r
198 {\r
199         xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);\r
200 }\r
201 $style_rowset = $db->sql_fetchrowset($result);\r
202 \r
203 $template->set_filenames(array('body' => XS_TPL_PATH . 'cache.tpl'));\r
204 \r
205 $prev_id = -1;\r
206 $prev_tpl = '';\r
207 $style_names = array();\r
208 $j = 0;\r
209 for($i=0; $i<count($style_rowset); $i++)\r
210 {\r
211         $item = $style_rowset[$i];\r
212         if($item['template_name'] === $prev_tpl)\r
213         {\r
214                 $style_names[] = htmlspecialchars($item['style_name']);\r
215         }\r
216         else\r
217         {\r
218                 if($prev_id > 0)\r
219                 {\r
220                         $str = implode('<br />', $style_names);\r
221                         $str2 = urlencode($prev_tpl);\r
222                         $row_class = $xs_row_class[$j % 2];\r
223                         $j++;\r
224                         $template->assign_block_vars('styles', array(\r
225                                         'ROW_CLASS'     => $row_class,\r
226                                         'TPL'           => $prev_tpl,\r
227                                         'STYLES'        => $str,\r
228                                         'U_CLEAR'       => "xs_cache.{$phpEx}?clear={$str2}&sid={$userdata['session_id']}",\r
229                                         'U_COMPILE'     => "xs_cache.{$phpEx}?compile={$str2}&sid={$userdata['session_id']}",\r
230                                 )\r
231                         );\r
232                 }\r
233                 $prev_id = $item['themes_id'];\r
234                 $prev_tpl = $item['template_name'];\r
235                 $style_names = array(htmlspecialchars($item['style_name']));\r
236         }\r
237 }\r
238 if($prev_id > 0)\r
239 {\r
240         $str = implode('<br />', $style_names);\r
241         $str2 = urlencode($prev_tpl);\r
242         $row_class = $xs_row_class[$j % 2];\r
243         $j++;\r
244         $template->assign_block_vars('styles', array(\r
245                         'ROW_CLASS'     => $row_class,\r
246                         'TPL'           => $prev_tpl,\r
247                         'STYLES'        => $str,\r
248                         'U_CLEAR'       => "xs_cache.{$phpEx}?clear={$str2}&sid={$userdata['session_id']}",\r
249                         'U_COMPILE'     => "xs_cache.{$phpEx}?compile={$str2}&sid={$userdata['session_id']}",\r
250                 )\r
251         );\r
252 }\r
253 \r
254 $template->assign_vars(array(\r
255         'U_CLEAR_ALL'   => "xs_cache.{$phpEx}?clear=&sid={$userdata['session_id']}",\r
256         'U_COMPILE_ALL' => "xs_cache.{$phpEx}?compile=&sid={$userdata['session_id']}",\r
257         'RESULT'                => '<br /><br />' . $data\r
258         )\r
259 );\r
260 \r
261 $template->pparse('body');\r
262 xs_exit();\r
263 \r
264 ?>