]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2/admin/xs_export.php
Baseline
[www.vanrenterghem.biz.git] / phpBB2 / admin / xs_export.php
1 <?php\r
2 \r
3 /***************************************************************************\r
4  *                               xs_export.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_export.'.$phpEx) . '">' . $lang['xs_export_styles'] . '</a>'));\r
42 \r
43 $lang['xs_export_back'] = str_replace('{URL}', append_sid('xs_export.'.$phpEx), $lang['xs_export_back']);\r
44 \r
45 //\r
46 // Check required functions\r
47 //\r
48 if(!@function_exists('gzcompress'))\r
49 {\r
50         xs_error($lang['xs_import_nogzip']);\r
51 }\r
52 \r
53 \r
54 //\r
55 // Export page\r
56 //\r
57 $export = isset($HTTP_GET_VARS['export']) ? $HTTP_GET_VARS['export'] : '';\r
58 $export = xs_tpl_name($export);\r
59 if(!empty($export) && @file_exists($phpbb_root_path . $template_dir . $export . '/theme_info.cfg'))\r
60 {\r
61         // Get list of styles\r
62         $sql = "SELECT themes_id, style_name FROM " . THEMES_TABLE . " WHERE template_name = '$export' ORDER BY style_name ASC";\r
63         if(!$result = $db->sql_query($sql))\r
64         {\r
65                 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_export_back']);\r
66         }\r
67         $theme_rowset = $db->sql_fetchrowset($result);\r
68         if(count($theme_rowset) == 0)\r
69         {\r
70                 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_export_back']);\r
71         }\r
72         $template->set_filenames(array('body' => XS_TPL_PATH . 'export2.tpl'));\r
73         $xs_send_method = isset($board_config['xs_export_data']) ? $board_config['xs_export_data'] : '';\r
74         $xs_send = @unserialize($xs_send_method);\r
75         $xs_send_method = $xs_send['method'] == 'ftp' ? 'ftp' : ($xs_send['method'] == 'file' ? 'file' : 'save');\r
76         $template->assign_vars(array(\r
77                         'FORM_ACTION'           => append_sid('xs_export.'.$phpEx),\r
78                         'EXPORT_TEMPLATE'       => htmlspecialchars($export),\r
79                         'STYLE_ID'                      => $theme_rowset[0]['themes_id'],\r
80                         'STYLE_NAME'            => htmlspecialchars($theme_rowset[0]['style_name']),\r
81                         'TOTAL'                         => count($theme_rowset),\r
82                         'SEND_METHOD_'.strtoupper($xs_send_method)      => ' checked="checked"',\r
83                         'SEND_DATA_DIR'         => isset($xs_send['dir']) ? htmlspecialchars($xs_send['dir']) : '',\r
84                         'SEND_DATA_HOST'        => isset($xs_send['host']) ? htmlspecialchars($xs_send['host']) : '',\r
85                         'SEND_DATA_LOGIN'       => isset($xs_send['login']) ? htmlspecialchars($xs_send['login']) : '',\r
86                         'SEND_DATA_FTPDIR'      => isset($xs_send['ftpdir']) ? htmlspecialchars($xs_send['ftpdir']) : '',\r
87                         'L_TITLE'                       => str_replace('{TPL}', $export, $lang['xs_export_style_title']),\r
88                         ));\r
89         if(count($theme_rowset) == 1)\r
90         {\r
91                 $template->assign_block_vars('switch_select_nostyle', array());\r
92         }\r
93         else\r
94         {\r
95                 $template->assign_block_vars('switch_select_style', array());\r
96                 for($i=0; $i<count($theme_rowset); $i++)\r
97                 {\r
98                         $template->assign_block_vars('switch_select_style.style', array(\r
99                                 'NUM'           => $i,\r
100                                 'ID'            => $theme_rowset[$i]['themes_id'],\r
101                                 'NAME'          => htmlspecialchars($theme_rowset[$i]['style_name'])\r
102                                 ));\r
103                 }\r
104         }\r
105         $template->pparse('body');\r
106         xs_exit();\r
107 }\r
108 \r
109 //\r
110 // Export style\r
111 //\r
112 $export = isset($HTTP_POST_VARS['export']) ? $HTTP_POST_VARS['export'] : '';\r
113 $export = xs_tpl_name($export);\r
114 if(!empty($export) && @file_exists($phpbb_root_path . $template_dir . $export . '/theme_info.cfg') && !defined('DEMO_MODE'))\r
115 {\r
116         $total = intval($HTTP_POST_VARS['total']);\r
117         $comment = substr(stripslashes($HTTP_POST_VARS['export_comment']), 0, 255);\r
118         $list = array();\r
119         for($i=0; $i<$total; $i++)\r
120         {\r
121                 if(!empty($HTTP_POST_VARS['export_style_'.$i]))\r
122                 {\r
123                         $list[] = intval($HTTP_POST_VARS['export_style_id_'.$i]);\r
124                 }\r
125         }\r
126         if(!count($list))\r
127         {\r
128                 xs_error($lang['xs_export_noselect_themes'] . '<br /><br /> ' . $lang['xs_export_back']);\r
129         }\r
130         // Export as...\r
131         $exportas = empty($HTTP_POST_VARS['export_template']) ? $export : $HTTP_POST_VARS['export_template'];\r
132         $exportas = xs_tpl_name($exportas);\r
133         // Generate theme_info.cfg\r
134         $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE template_name = '$export' AND themes_id IN (" . implode(', ', $list) . ")";\r
135         if(!$result = $db->sql_query($sql))\r
136         {\r
137                 xs_error($lang['xs_no_theme_data'] . $lang['xs_export_back']);\r
138         }\r
139         $theme_rowset = $db->sql_fetchrowset($result);\r
140         if(count($theme_rowset) == 0)\r
141         {\r
142                 xs_error($lang['xs_no_themes']  . '<br /><br />' . $lang['xs_export_back']);\r
143         }\r
144         $theme_data = xs_generate_themeinfo($theme_rowset, $export, $exportas, $total);\r
145 \r
146         // prepare to pack      \r
147         $pack_error = '';\r
148         $pack_list = array();\r
149         $pack_replace = array('./theme_info.cfg' => $theme_data);\r
150 \r
151         // pack style\r
152         for($i=0; $i<count($theme_rowset); $i++)\r
153         {\r
154                 $id = $theme_rowset[$i]['themes_id'];\r
155                 $theme_name = $theme_rowset[$i]['style_name'];\r
156                 for($j=0; $j<$total; $j++)\r
157                 {\r
158                         if(!empty($HTTP_POST_VARS['export_style_name_'.$j]) && $HTTP_POST_VARS['export_style_id_'.$j] == $id)\r
159                         {\r
160                                 $theme_name = stripslashes($HTTP_POST_VARS['export_style_name_'.$j]);\r
161                         }\r
162                 }\r
163                 $theme_rowset[$i]['style_name'] = $theme_name;\r
164         }\r
165         $data = pack_style($export, $exportas, $theme_rowset, $comment);\r
166 \r
167         // check errors\r
168         if($pack_error)\r
169         {\r
170                 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error']) . $pack_error  . '<br /><br />' . $lang['xs_export_back']);\r
171         }\r
172         if(!$data)\r
173         {\r
174                 xs_error(str_replace('{TPL}', $export, $lang['xs_export_error2']) . '<br /><br />' . $lang['xs_export_back']);\r
175         }\r
176 \r
177         //\r
178         // Got file. Sending it.\r
179         //\r
180         $send_method = isset($HTTP_POST_VARS['export_to']) ? $HTTP_POST_VARS['export_to'] : '';\r
181         $export_filename = empty($HTTP_POST_VARS['export_filename']) ? $exportas . STYLE_EXTENSION : $HTTP_POST_VARS['export_filename'];\r
182         if($send_method === 'file')\r
183         {\r
184                 // store on local server\r
185                 $send_dir = isset($HTTP_POST_VARS['export_to_dir']) ? $HTTP_POST_VARS['export_to_dir'] : '';\r
186                 $send_dir = str_replace('\\', '/', stripslashes($send_dir));\r
187                 if(empty($send_dir))\r
188                 {\r
189                         $send_dir = XS_TEMP_DIR;\r
190                 }\r
191                 if(substr($send_dir, strlen($send_dir) - 1) !== '/')\r
192                 {\r
193                         $send_dir .= '/';\r
194                 }\r
195                 $filename = $send_dir . $export_filename;\r
196                 $f = @fopen($filename, 'wb');\r
197                 if(!$f)\r
198                 {\r
199                         xs_error(str_replace('{FILE}', $filename, $lang['xs_error_cannot_create_file']) . '<br /><br />' . $lang['xs_export_back']);\r
200                 }\r
201                 @fwrite($f, $data);\r
202                 @fclose($f);\r
203                 set_export_method('file', array('dir' => $send_dir));\r
204                 xs_message($lang['Information'], str_replace('{FILE}', $filename, $lang['xs_export_saved']) . '<br /><br />' . $lang['xs_export_back']);\r
205         }\r
206         elseif($send_method === 'ftp')\r
207         {\r
208                 // upload via ftp\r
209                 $ftp_host = $HTTP_POST_VARS['export_to_ftp_host'];\r
210                 $ftp_login = $HTTP_POST_VARS['export_to_ftp_login'];\r
211                 $ftp_pass = $HTTP_POST_VARS['export_to_ftp_pass'];\r
212                 $ftp_dir = str_replace('\\', '/', $HTTP_POST_VARS['export_to_ftp_dir']);\r
213                 if($ftp_dir && substr($ftp_dir, strlen($ftp_dir) - 1) !== '/')\r
214                 {\r
215                         $ftp_dir .= '/';\r
216                 }\r
217                 // save as temporary file\r
218                 $filename = XS_TEMP_DIR.'tmp_' . time() . '.tmp';\r
219                 $f = @fopen($filename, 'wb');\r
220                 if(!$f)\r
221                 {\r
222                         xs_error(str_replace('{FILE}', $filename, $lang['xs_error_cannot_create_tmp']) . '<br /><br />' . $lang['xs_export_back']);\r
223                 }\r
224                 @fwrite($f, $data);\r
225                 @fclose($f);\r
226                 // connect to ftp\r
227                 $ftp = @ftp_connect($ftp_host);\r
228                 if(!$ftp)\r
229                 {\r
230                         @unlink($filename);\r
231                         xs_error($lang['xs_ftp_error_noconnect'] . '<br /><br />' . $lang['xs_export_back']);\r
232                 }\r
233                 $res = @ftp_login($ftp, $ftp_login, $ftp_pass);\r
234                 if(!$res)\r
235                 {\r
236                         @unlink($filename);\r
237                         xs_error($lang['xs_ftp_error_login2'] . '<br /><br />' . $lang['xs_export_back']);\r
238                 }\r
239                 if($ftp_dir)\r
240                 {\r
241                         @ftp_chdir($ftp, $ftp_dir);\r
242                 }\r
243                 $res = @ftp_put($ftp, $ftp_dir . $export_filename, $filename, FTP_BINARY);\r
244                 @unlink($filename);\r
245                 if(!$res)\r
246                 {\r
247                         xs_error($lang['xs_export_error_uploading'] . '<br /><br />' . $lang['xs_export_back']);\r
248                 }\r
249                 set_export_method('ftp', array('host' => $ftp_host, 'login' => $ftp_login, 'ftpdir' => $ftp_dir));\r
250                 xs_message($lang['Information'], $lang['xs_export_uploaded'] . '<br /><br />' . $lang['xs_export_back']);\r
251         }\r
252         // send file\r
253         xs_download_file($export_filename, $data, 'application/phpbbstyle');\r
254         xs_exit();\r
255 }\r
256 \r
257 $template->set_filenames(array('body' => XS_TPL_PATH . 'export.tpl'));\r
258 \r
259 //\r
260 // get list of installed styles\r
261 //\r
262 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY template_name';\r
263 if(!$result = $db->sql_query($sql))\r
264 {\r
265         xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);\r
266 }\r
267 $style_rowset = $db->sql_fetchrowset($result);\r
268 \r
269 $prev_id = -1;\r
270 $prev_tpl = '';\r
271 $style_names = array();\r
272 $j = 0;\r
273 for($i=0; $i<count($style_rowset); $i++)\r
274 {\r
275         $item = $style_rowset[$i];\r
276         if($item['template_name'] === $prev_tpl)\r
277         {\r
278                 $style_names[] = htmlspecialchars($item['style_name']);\r
279         }\r
280         else\r
281         {\r
282                 if($prev_id > 0)\r
283                 {\r
284                         $str = implode('<br />', $style_names);\r
285                         $str2 = urlencode($prev_tpl);\r
286                         $row_class = $xs_row_class[$j % 2];\r
287                         $j++;\r
288                         $template->assign_block_vars('styles', array(\r
289                                         'ROW_CLASS'     => $row_class,\r
290                                         'TPL'           => $prev_tpl,\r
291                                         'STYLES'        => $str,\r
292                                         'U_EXPORT'      => "xs_export.{$phpEx}?export={$str2}&sid={$userdata['session_id']}",\r
293                                 )\r
294                         );\r
295                 }\r
296                 $prev_id = $item['themes_id'];\r
297                 $prev_tpl = $item['template_name'];\r
298                 $style_names = array(htmlspecialchars($item['style_name']));\r
299         }\r
300 }\r
301 \r
302 if($prev_id > 0)\r
303 {\r
304         $str = implode('<br />', $style_names);\r
305         $str2 = urlencode($prev_tpl);\r
306         $row_class = $xs_row_class[$j % 2];\r
307         $j++;\r
308         $template->assign_block_vars('styles', array(\r
309                         'ROW_CLASS'     => $row_class,\r
310                         'TPL'           => $prev_tpl,\r
311                         'STYLES'        => $str,\r
312                         'U_EXPORT'      => "xs_export.{$phpEx}?export={$str2}&sid={$userdata['session_id']}",\r
313                 )\r
314         );\r
315 }\r
316 \r
317 $template->pparse('body');\r
318 xs_exit();\r
319 \r
320 ?>