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