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