]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/xs_import.php
b2e621629187131713a110a0efd511aeb653aac1
[www.vanrenterghem.biz.git] / phpBB2_old / admin / xs_import.php
1 <?php
3 /***************************************************************************
4  *                               xs_import.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:48
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_import.'.$phpEx) . '">' . $lang['xs_import_styles'] . '</a>'));
43 $lang['xs_import_back'] = str_replace('{URL}', append_sid('xs_import.'.$phpEx), $lang['xs_import_back']);
45 $return_url = isset($HTTP_POST_VARS['return']) ? stripslashes($HTTP_POST_VARS['return']) : (isset($HTTP_GET_VARS['return']) ? stripslashes($HTTP_GET_VARS['return']) : '');
46 $return = $return_url ? '&return=' . urlencode($return_url) : '';
47 if($return)
48 {
49         $lang['xs_import_back'] = str_replace('{URL}', $return_url, $lang['xs_import_back_download']);
50         $HTTP_POST_VARS['return'] = $HTTP_GET_VARS['return'] = addslashes($return_url);
51 }
53 //
54 // Check required functions
55 //
56 if(!@function_exists('gzcompress'))
57 {
58         xs_error($lang['xs_import_nogzip']);
59 }
61 $tpl_filename = $template->make_filename('_xs_test.tpl');
62 $cache_filename = $template->make_filename_cache($tpl_filename);
63 $str = '';
64 if(!xs_check_cache($cache_filename))
65 {
66         xs_error(str_replace(array('{URL1}', '{URL2}'), array(append_sid('xs_chmod.'.$phpEx), append_sid('xs_import.'.$phpEx)), $lang['xs_import_nowrite_cache']));
67 }
69 //
70 // include all functions
71 //
72 include_once('xs_include_import.'.$phpEx);
74 // remove timeout
75 @set_time_limit(XS_MAX_TIMEOUT);
77 //
78 // check if need to download style
79 //
80 if(!empty($HTTP_GET_VARS['get_remote']))
81 {
82         $HTTP_POST_VARS['action'] = 'web';
83         $HTTP_POST_VARS['source'] = $HTTP_GET_VARS['get_remote'];
84 }
86 //
87 // delete style
88 //
89 if(isset($HTTP_GET_VARS['del']) && !defined('DEMO_MODE'))
90 {
91         $str = xs_tpl_name($HTTP_GET_VARS['del']);
92         @unlink(XS_TEMP_DIR.$str);
93 }
95 //
96 // import style
97 //
98 if(isset($HTTP_GET_VARS['import']) || isset($HTTP_POST_VARS['import']))
99 {
100         $list_only = isset($HTTP_GET_VARS['list']) ? true : false;
101         $get_file = isset($HTTP_GET_VARS['get_file']) ? stripslashes($HTTP_GET_VARS['get_file']) : '';
102         $filename = isset($HTTP_POST_VARS['import']) ? $HTTP_POST_VARS['import'] : $HTTP_GET_VARS['import'];
103         $filename = xs_tpl_name($filename);
104         $write_local = false;
105         if(!$list_only)
106         {
107                 if(defined('DEMO_MODE'))
108                 {
109                         xs_error($lang['xs_permission_denied'] . '<br /><br />' . $lang['xs_import_back']);
110                 }
111                 $params = array('import' => $filename);
112                 $total = intval($HTTP_POST_VARS['total']);
113                 $params['total'] = $total;
114                 for($i=0; $i<$total; $i++)
115                 {
116                         $install = empty($HTTP_POST_VARS['import_install_'.$i]) ? 0 : 1;
117                         $default = $install ? (empty($HTTP_POST_VARS['import_default_'.$i]) ? 0 : 1) : 0;
118                         $params['import_install_'.$i] = $install;
119                         $params['import_default_'.$i] = $default;
120                 }
121                 if($return_url)
122                 {
123                         $params['return'] = $return_url;
124                 }
125                 if(!get_ftp_config(append_sid('xs_import.'.$phpEx), $params, true))
126                 {
127                         xs_exit();
128                 }
129                 xs_ftp_connect(append_sid('xs_import.'.$phpEx), $params, true);
130                 if($ftp === XS_FTP_LOCAL)
131                 {
132                         $write_local = true;
133                         $write_local_dir = '../templates/';
134                 }
135         }
136         include('xs_include_import2.' . $phpEx);        
139 //
140 // Download from web
141 //
142 if(isset($HTTP_GET_VARS['get_web']))
144         $HTTP_POST_VARS['action'] = 'web';
145         $HTTP_POST_VARS['source'] = $HTTP_GET_VARS['get_web'];
147 if(isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'web' && !defined('DEMO_MODE'))
149         $src = stripslashes($HTTP_POST_VARS['source']);
150         $dst = generate_style_name('web');
151         $str = @implode('', @file($src));
152         if(empty($str))
153         {
154                 xs_error(str_replace('{URL}', $src, $lang['xs_import_nodownload']) . '<br /><br />' . $lang['xs_import_back']);
155         }
156         $header = xs_get_style_header('', substr($str, 0, 10240));
157         if($header === false)
158         {
159                 xs_error($lang['xs_style_header_error_reason'] . $xs_header_error . '<br /><br />' . $lang['xs_import_back']);
160         }
161         if($header['filesize'] != strlen($str))
162         {
163                 xs_error($lang['xs_style_header_error_incomplete2'] . '<br /><br />' . $lang['xs_import_back']);
164         }
165         $f = @fopen(XS_TEMP_DIR . $dst, 'wb');
166         if(!$f)
167         {
168                 xs_error(str_replace('{FILE}', $dst, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_import_back']);
169         }
170         fwrite($f, $str);
171         fclose($f);
172         xs_message($lang['Information'], str_replace('{URL}', append_sid('xs_import.'.$phpEx.'?importstyle=' . urlencode($dst) . $return), $lang['xs_import_uploaded2']) . '<br /><br />' . $lang['xs_import_back']);
175 //
176 // Copy from file
177 //
178 if(isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'copy' && !defined('DEMO_MODE'))
180         $src = stripslashes($HTTP_POST_VARS['source']);
181         $dst = generate_style_name('copy');
182         $str = @implode('', @file($src));
183         if(empty($str))
184         {
185                 xs_error(str_replace('{URL}', $src, $lang['xs_import_nodownload2']) . '<br /><br />' . $lang['xs_import_back']);
186         }
187         if(substr($str, 0, strlen(STYLE_HEADER_START)) !== STYLE_HEADER_START)
188         {
189                 xs_error($lang['xs_style_header_error_invalid2'] . '<br /><br />' . $lang['xs_import_back']);
190         }
191         $header = xs_get_style_header('', substr($str, 0, 10240));
192         if($header === false)
193         {
194                 xs_error($lang['xs_style_header_error_reason'] . $xs_header_error . '<br /><br />' . $lang['xs_import_back']);
195         }
196         if($header['filesize'] != strlen($str))
197         {
198                 xs_error($lang['xs_style_header_error_incomplete2'] . '<br /><br />' . $lang['xs_import_back']);
199         }
200         $f = @fopen(XS_TEMP_DIR . $dst, 'wb');
201         if(!$f)
202         {
203                 xs_error(str_replace('{FILE}', $dst, $lang['xs_error_cannot_create_tmp']) . $lang['xs_import_back']);
204         }
205         fwrite($f, $str);
206         fclose($f);
207         xs_message($lang['Information'], str_replace('{URL}', append_sid('xs_import.'.$phpEx.'?importstyle=' . urlencode($dst)), $lang['xs_import_uploaded3']) . '<br /><br />' . $lang['xs_import_back']);
211 //
212 // Upload
213 //
214 if(isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'upload' && !defined('DEMO_MODE'))
216         if(empty($HTTP_POST_FILES['source']['tmp_name']) || !@file_exists($HTTP_POST_FILES['source']['tmp_name']))
217         {
218                 xs_error($lang['xs_import_nodownload3'] . '<br /><br />' . $lang['xs_import_back']);
219         }
220         $src = $HTTP_POST_FILES['source']['tmp_name'];
221         $dst = generate_style_name('upload');
222         $str = @implode('', @file($src));
223         if(empty($str))
224         {
225                 xs_error(str_replace('{URL}', $src, $lang['xs_import_nodownload2']) . '<br /><br />' . $lang['xs_import_back']);
226         }
227         if(substr($str, 0, strlen(STYLE_HEADER_START)) !== STYLE_HEADER_START)
228         {
229                 xs_error($lang['xs_style_header_error_invalid2'] . '<br /><br />' . $lang['xs_import_back']);
230         }
231         $header = xs_get_style_header('', substr($str, 0, 10240));
232         if($header === false)
233         {
234                 xs_error($lang['xs_style_header_error_reason'] . $xs_header_error . '<br /><br />' . $lang['xs_import_back']);
235         }
236         if($header['filesize'] != strlen($str))
237         {
238                 xs_error($lang['xs_style_header_error_incomplete2'] . '<br /><br />' . $lang['xs_import_back']);
239         }
240         $f = @fopen(XS_TEMP_DIR . $dst, 'wb');
241         if(!$f)
242         {
243                 xs_error(str_replace('{FILE}', $dst, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_import_back']);
244         }
245         fwrite($f, $str);
246         fclose($f);
247         xs_error(str_replace('{URL}', append_sid('xs_import.'.$phpEx.'?importstyle=' . urlencode($dst)), $lang['xs_import_uploaded4']) . '<br /><br />' . $lang['xs_import_back']);
251 //
252 // Show import page
253 //
254 if(!empty($HTTP_GET_VARS['importstyle']))
256         $file = xs_tpl_name($HTTP_GET_VARS['importstyle']);
257         $header = xs_get_style_header(XS_TEMP_DIR.$file);
258         if($header === false)
259         {
260                 xs_error($lang['xs_style_header_error_reason'] . $xs_header_error . '<br /><br />' . $lang['xs_import_back']);
261         }
262         if(@filesize(XS_TEMP_DIR.$file) != $header['filesize'])
263         {
264                 xs_error($lang['xs_style_header_error_incomplete2'] . '<br /><br />' . $lang['xs_import_back']);
265         }
266         $template->set_filenames(array('import' => XS_TPL_PATH . 'import2.tpl'));
267         $template->assign_vars(array(
268                 'FORM_ACTION'                   => append_sid('xs_import.'.$phpEx),
269                 'S_RETURN'                              => $return_url ? '<input type="hidden" name="return" value="' . htmlspecialchars($return_url) . '" />' : '',
270                 'IMPORT_FILENAME'               => htmlspecialchars($file),
271                 'STYLE_TEMPLATE'                => htmlspecialchars($header['template']),
272                 'STYLE_FILENAME'                => htmlspecialchars($file),
273                 'STYLE_COMMENT'                 => htmlspecialchars($header['comment']),
274                 'DATE'                                  => create_date($board_config['default_dateformat'], $header['date'], $board_config['board_timezone']),
275                 'STYLE_SIZE'                    => $header['filesize'],
276                 'STYLE_NAME'                    => htmlspecialchars($header['styles'][0]),
277                 'TOTAL'                                 => count($header['styles']),
278                 'L_XS_IMPORT_TPL'               => str_replace('{TPL}', htmlspecialchars($header['template']), $lang['xs_import_tpl'])
279                 ));
280         if(count($header['styles']) > 1)
281         {
282                 $template->assign_block_vars('switch_select_style', array());
283                 for($i=0; $i<count($header['styles']); $i++)
284                 {
285                         $template->assign_block_vars('switch_select_style.style', array(
286                                 'NUM'           => $i,
287                                 'NAME'          => htmlspecialchars($header['styles'][$i]),
288                                 ));
289                 }
290         }
291         else
292         {
293                 $template->assign_block_vars('switch_select_nostyle', array());
294         }
295         $template->pparse('import');
296         xs_exit();
300 $template->set_filenames(array('body' => XS_TPL_PATH . 'import.tpl'));
301 //
302 // Get list of available styles
303 //
304 $dir = @opendir(XS_TEMP_DIR);
305 $files = array();
306 if($dir)
308         while(($file = readdir($dir)) !== false)
309         {
310                 if(substr($file, strlen($file) - strlen(STYLE_EXTENSION)) === STYLE_EXTENSION)
311                 {
312                         $items = xs_get_style_header(XS_TEMP_DIR.$file);
313                         if(is_array($items))
314                         {
315                                 $items['file'] = $file;
316                                 $items['file2'] = substr($file, 0, strlen($file) - strlen(STYLE_EXTENSION));
317                                 if(@filesize(XS_TEMP_DIR.$file) != $items['filesize'])
318                                 {
319                                         $items['error'] = $lang['xs_import_incomplete_file'];
320                                 }
321                                 $files[] = $items;
322                         }
323                         else
324                         {
325                                 $items = array(
326                                         'filename'      => XS_TEMP_DIR.$file,
327                                         'filesize'      => @filesize(XS_TEMP_DIR.$file),
328                                         'date'          => filemtime(XS_TEMP_DIR.$file),
329                                         'file'          => $file,
330                                         'file2'         => substr($file, 0, strlen($file) - strlen(STYLE_EXTENSION)),
331                                         'error'         => $lang['xs_import_invalid_file'],
332                                         'template'      => '-',
333                                         'styles'        => array('-'),
334                                         'comment'       => '',
335                                         'offset'        => 0
336                                         );
337                                 $files[] = $items;
338                         }
339                 }
340         }
341         closedir($dir);
344 if(count($files))
347         for($i=0; $i<count($files); $i++)
348         {
349                 $item = $files[$i];
350                 $row_class = $xs_row_class[$i % 2];
351                 $template->assign_block_vars('styles', array(
352                         'ROW_CLASS'             => $row_class,
353                         'FILE'                  => htmlspecialchars($item['file']),
354                         'FILE2'                 => htmlspecialchars($item['file2']),
355                         'FILENAME'              => htmlspecialchars($item['filename']),
356                         'TEMPLATE'              => htmlspecialchars($item['template']),
357                         'DATE'                  => create_date($board_config['default_dateformat'], $item['date'], $board_config['board_timezone']),
358                         'COMMENT'               => htmlspecialchars($item['comment']),
359                         'U_DELETE'              => append_sid('xs_import.' . $phpEx . '?del=' . urlencode($item['file'])),
360                         'U_IMPORT'              => append_sid('xs_import.' . $phpEx . '?importstyle=' . urlencode($item['file'])),
361                         'U_DOWNLOAD'    => append_sid('xs_download.' . $phpEx),
362                         'U_LIST'                => append_sid('xs_import.' . $phpEx . '?list=1&import=' . urlencode($item['file'])),
363                         ));
364                 if(empty($item['error']))
365                 {
366                         for($j=0; $j<count($item['styles']); $j++)
367                         {
368                                 $template->assign_block_vars('styles.list', array(
369                                         'STYLE'         => $item['styles'][$j]
370                                         ));
371                         }
372                         $template->assign_block_vars('styles.valid', array());
373                 }
374                 else
375                 {
376                         $template->assign_block_vars('styles.error', array('ERROR' => htmlspecialchars($item['error'])));
377                 }
378         }
380 else
382         $template->assign_block_vars('nostyles', array());
384 $template->assign_vars(array(
385         'U_SCRIPT'      => append_sid('xs_import.'.$phpEx),
386         ));
388 $template->pparse('body');
389 xs_exit();
391 ?>