]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/xs_export_data.php
Baseline
[www.vanrenterghem.biz.git] / phpBB2_old / admin / xs_export_data.php
1 <?php
3 /***************************************************************************
4  *                             xs_export_data.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_export_data.'.$phpEx) . '">' . $lang['xs_edit_styles_data'] . '</a>'));
43 $lang['xs_export_data_back'] = str_replace('{URL}', append_sid('xs_export_data.'.$phpEx), $lang['xs_export_data_back']);
45 //
46 // export style
47 //
48 if(isset($HTTP_GET_VARS['export']))
49 {
50         $export = str_replace(array('\\', '/'), array('',''), stripslashes($HTTP_GET_VARS['export']));
51         // get list of themes for style
52         $sql = "SELECT themes_id, style_name FROM " . THEMES_TABLE . " WHERE template_name = '$export' ORDER BY style_name ASC";
53         if(!$result = $db->sql_query($sql))
54         {
55                 xs_error($lang['xs_no_theme_data'] . '<br /><br />' . $lang['xs_export_data_back']);
56         }
57         $theme_rowset = $db->sql_fetchrowset($result);
58         if(count($theme_rowset) == 0)
59         {
60                 xs_error($lang['xs_no_themes'] . '<br /><br />' . $lang['xs_export_data_back']);
61         }
62         if(count($theme_rowset) == 1)
63         {
64                 $HTTP_POST_VARS['export'] = $HTTP_GET_VARS['export'];
65                 $HTTP_POST_VARS['export_total'] = '1';
66                 $HTTP_POST_VARS['export_id_0'] = $theme_rowset[0]['themes_id'];
67                 $HTTP_POST_VARS['export_check_0'] = 'checked';
68         }
69         else
70         {
71                 $template->set_filenames(array('body' => XS_TPL_PATH . 'export_data2.tpl'));
72                 $template->assign_vars(array(
73                         'TOTAL'         => count($theme_rowset),
74                         'EXPORT'        => htmlspecialchars($export),
75                         'U_ACTION'      => append_sid("xs_export_data.{$phpEx}")
76                         )
77                 );
78                 for($i=0; $i<count($theme_rowset); $i++)
79                 {
80                         $row_class = $xs_row_class[$i % 2];
81                         $template->assign_block_vars('styles', array(
82                                 'ROW_CLASS'             => $row_class,
83                                 'NUM'                   => $i,
84                                 'ID'                    => $theme_rowset[$i]['themes_id'],
85                                 'STYLE'                 => htmlspecialchars($theme_rowset[$i]['style_name'])
86                                 )
87                         );
88                 }
89                 $template->pparse('body');
90                 xs_exit();
91         }
92 }
94 if(!empty($HTTP_POST_VARS['export']) && !defined('DEMO_MODE'))
95 {
96         $export = xs_tpl_name($HTTP_POST_VARS['export']);
97         // get ftp configuration
98         $params = array('export' => $export);
99         $total = intval($HTTP_POST_VARS['export_total']);
100         $count = 0;
101         for($i=0; $i<$total; $i++)
102         {
103                 if(!empty($HTTP_POST_VARS['export_check_'.$i]))
104                 {
105                         $params['export_id_'.$count] = intval($HTTP_POST_VARS['export_id_'.$i]);
106                         $params['export_check_'.$count] = 'checked';
107                         $count ++;
108                 }
109         }
110         $params['export_total'] = $count;
111         if(!$count)
112         {
113                 xs_error($lang['xs_export_noselect_themes'] . '<br /><br />' . $lang['xs_export_data_back']);
114         }
115         $write_local = false;
116         if(!get_ftp_config(append_sid('xs_export_data.'.$phpEx), $params, true))
117         {
118                 xs_exit();
119         }
120         xs_ftp_connect(append_sid('xs_export_data.'.$phpEx), $params, true);
121         if($ftp === XS_FTP_LOCAL)
122         {
123                 $write_local = true;
124                 $local_filename = '../templates/'. $export . '/theme_info.cfg';
125         }
126         else
127         {
128                 $local_filename = XS_TEMP_DIR . 'export_' . time() . '.tmp';
129         }
130         // get all themes for style
131         $export_list = array();
132         for($i=0; $i<$total; $i++)
133         {
134                 if(!empty($HTTP_POST_VARS['export_check_'.$i]))
135                 {
136                         $export_list[] = intval($HTTP_POST_VARS['export_id_'.$i]);
137                 }
138         }
139         $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id IN (" . implode(', ', $export_list) . ") ORDER BY style_name ASC";
140         if(!$result = $db->sql_query($sql))
141         {
142                 xs_error($lang['xs_no_style_info'] . '<br /><br />' . $lang['xs_export_data_back'], __LINE__, __FILE__);
143         }
144         $style_rowset = $db->sql_fetchrowset($result);
145         if(!count($style_rowset))
146         {
147                 xs_error($lang['xs_no_style_info'] . '<br /><br />' . $lang['xs_export_data_back'], __LINE__, __FILE__);
148         }
149         $data = xs_generate_themeinfo($style_rowset, $export, $export, 0);
150         $f = @fopen($local_filename, 'wb');
151         if(!$f)
152         {
153                 xs_error(str_replace('{FILE}', $local_filename, $lang['xs_error_cannot_create_file']) . '<br /><br />' . $lang['xs_export_data_back']);
154         }
155         fwrite($f, $data);
156         fclose($f);
157         if($write_local)
158         {
159                 xs_message($lang['Information'], $lang['xs_export_data_saved'] . '<br /><br />' . $lang['xs_export_data_back']);
160         }
161         // generate ftp actions
162         $actions = array();
163         // chdir to template directory
164         $actions[] = array(
165                         'command'       => 'chdir',
166                         'dir'           => 'templates'
167                 );
168         $actions[] = array(
169                         'command'       => 'chdir',
170                         'dir'           => $export
171                 );
172         $actions[] = array(
173                         'command'       => 'upload',
174                         'local'         => $local_filename,
175                         'remote'        => 'templates/' . $export . '/theme_info.cfg'
176                         );
177         $ftp_log = array();
178         $ftp_error = '';
179         $res = ftp_myexec($actions);
180 /*      echo "<!--\n\n";
181         echo "\$actions dump:\n\n";
182         print_r($actions);
183         echo "\n\n\$ftp_log dump:\n\n";
184         print_r($ftp_log);
185         echo "\n\n -->"; */
186         @unlink($local_filename);
187         if($res)
188         {
189                 xs_message($lang['Information'], $lang['xs_export_data_saved'] . '<br /><br />' . $lang['xs_export_data_back']);
190         }
191         xs_error($ftp_error . '<br /><br />' . $lang['xs_export_data_back']);
197 $template->set_filenames(array('body' => XS_TPL_PATH . 'export_data.tpl'));
198 //
199 // get list of installed styles
200 //
201 $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY template_name';
202 if(!$result = $db->sql_query($sql))
204         xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
206 $style_rowset = $db->sql_fetchrowset($result);
208 $prev_id = -1;
209 $prev_tpl = '';
210 $style_names = array();
211 $j = 0;
212 for($i=0; $i<count($style_rowset); $i++)
214         $item = $style_rowset[$i];
215         if($item['template_name'] === $prev_tpl)
216         {
217                 $style_names[] = htmlspecialchars($item['style_name']);
218         }
219         else
220         {
221                 if($prev_id > 0)
222                 {
223                         $str = implode('<br />', $style_names);
224                         $str2 = urlencode($prev_tpl);
225                         $row_class = $xs_row_class[$j % 2];
226                         $j++;
227                         $template->assign_block_vars('styles', array(
228                                         'ROW_CLASS'     => $row_class,
229                                         'TPL'           => $prev_tpl,
230                                         'STYLES'        => $str,
231                                         'U_EXPORT'      => "xs_export_data.{$phpEx}?export={$str2}&sid={$userdata['session_id']}",
232                                 )
233                         );
234                 }
235                 $prev_id = $item['themes_id'];
236                 $prev_tpl = $item['template_name'];
237                 $style_names = array(htmlspecialchars($item['style_name']));
238         }
241 if($prev_id > 0)
243         $str = implode('<br />', $style_names);
244         $str2 = urlencode($prev_tpl);
245         $row_class = $xs_row_class[$j % 2];
246         $j++;
247         $template->assign_block_vars('styles', array(
248                         'ROW_CLASS'     => $row_class,
249                         'TPL'           => $prev_tpl,
250                         'STYLES'        => $str,
251                         'U_EXPORT'      => "xs_export_data.{$phpEx}?export={$str2}&sid={$userdata['session_id']}",
252                 )
253         );
256 $template->pparse('body');
257 xs_exit();
259 ?>