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