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