]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2/admin/xs_update.php
660647d815b582d967a529dbc5614bfa7f746fe6
[www.vanrenterghem.biz.git] / phpBB2 / admin / xs_update.php
1 <?php\r
2 \r
3 /***************************************************************************\r
4  *                               xs_update.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_update.'.$phpEx) . '">' . $lang['xs_check_for_updates'] . '</a>'));\r
42 \r
43 $updates = array();\r
44 \r
45 function include_update($filename)\r
46 {\r
47         $update = array();\r
48         @include($filename);\r
49         global $updates;\r
50         $updates = array_merge($updates, $update);\r
51 }\r
52 \r
53 if($dir = @opendir($phpbb_root_path. 'templates/'))\r
54 {\r
55         while($sub_dir = @readdir($dir))\r
56         if(($sub_dir !== '.') && ($sub_dir !== '..') && ($sub_dir !== 'CVS'))\r
57         {\r
58                 $file = $phpbb_root_path . 'templates/' . $sub_dir . '/xs.cfg';\r
59                 if(@file_exists($file))\r
60                 {\r
61                         include_update($file);\r
62                 }\r
63         }\r
64         closedir($dir);\r
65 }\r
66 \r
67 // check for xs files in acp. mask: xs_*.cfg\r
68 if($dir = @opendir('.'))\r
69 {\r
70         while($file = @readdir($dir))\r
71         if(strlen($file) > 6 && substr($file, 0, 3) === 'xs_' && substr($file, strlen($file) - 4) === '.cfg')\r
72         {\r
73                 include_update($file);\r
74         }\r
75         closedir($dir);\r
76 }\r
77 \r
78 \r
79 // nothing to update\r
80 if(!count($updates))\r
81 {\r
82         xs_error($lang['xs_update_nothing']);\r
83 }\r
84 \r
85 // show list of available updates\r
86 if(!isset($HTTP_GET_VARS['doupdate']))\r
87 {\r
88         $template->set_filenames(array('body' => XS_TPL_PATH . 'update.tpl'));\r
89         $template->assign_vars(array(\r
90                 'UPDATE_URL'                    => append_sid('xs_update.'.$phpEx.'?doupdate=1'),\r
91                 'L_XS_UPDATE_TOTAL1'    => str_replace('{NUM}', count($updates), $lang['xs_update_total1']),\r
92                 )\r
93         );\r
94         $counter = 0;\r
95         @reset($updates);\r
96         foreach($updates as $var => $item)\r
97         {\r
98                 $counter ++;\r
99                 $type = isset($lang['xs_update_types'][$item['update_type']]) ? $item['update_type'] : 0;\r
100                 $row_class = $xs_row_class[$counter % 2];\r
101                 $template->assign_block_vars('row',\r
102                                 array(\r
103                                 'ROW_CLASS'     => $row_class,\r
104                                 'NUM'           => $counter,\r
105                                 'VAR'           => 'item_'.$counter.'_',\r
106                                 'ITEM'          => htmlspecialchars($var),\r
107                                 'NAME'          => htmlspecialchars($item['update_name']),\r
108                                 'TYPE'          => $lang['xs_update_types'][$type],\r
109                                 'URL'           => htmlspecialchars($item['update_url']),\r
110                                 'VERSION'       => htmlspecialchars($item['update_version'])\r
111                                 )\r
112                         );\r
113                 $template->assign_block_vars('row.'.(empty($item['update_url']) ? 'nourl' : 'url'), array());\r
114         }\r
115         $template->pparse('body');\r
116         xs_exit();\r
117 }\r
118 \r
119 // check updates.\r
120 \r
121 // getting list of items to update\r
122 @reset($updates);\r
123 $urls = array();\r
124 $items = array();\r
125 $i=0;\r
126 foreach($updates as $var1 => $item)\r
127 {\r
128         $i++;\r
129         $var = 'item_'.$i.'_';\r
130         if(!empty($HTTP_POST_VARS[$var.'item']) && !empty($HTTP_POST_VARS[$var.'checked']) && $HTTP_POST_VARS[$var.'checked'])\r
131         {\r
132                 $item = $HTTP_POST_VARS[$var.'item'];\r
133                 if(!empty($updates[$item]['update_url']))\r
134                 {\r
135                         $items[] = $var1;\r
136                         $found = false;\r
137                         $url = $updates[$item]['update_url'];\r
138                         for($j=0; $j<count($urls) && !$found; $j++)\r
139                         {\r
140                                 if($urls[$j] === $url)\r
141                                 {\r
142                                         $found = true;\r
143                                 }\r
144                         }\r
145                         if(!$found)\r
146                         {\r
147                                 $urls[] = $url;\r
148                         }\r
149                 }\r
150         }\r
151         if(isset($updates[$var1]['data']))\r
152         {\r
153                 unset($updates[$var1]['data']);\r
154         }\r
155 }\r
156 \r
157 // showing error message if there is nothing to update\r
158 if(!count($urls))\r
159 {\r
160         xs_error($lang['xs_update_nothing']);\r
161 }\r
162 \r
163 @set_time_limit(intval($HTTP_POST_VARS['timeout']));\r
164 \r
165 // getting data\r
166 for($i=0; $i<count($urls); $i++)\r
167 {\r
168         $arr = @file($urls[$i]);\r
169         if(empty($arr))\r
170         {\r
171                 // cannot connect. show it as error message\r
172                 @reset($items);\r
173                 for($j=0; $j<count($items); $j++)\r
174                 {\r
175                         $item = $updates[$items[$j]];\r
176                         if($item['update_url'] === $urls[$i])\r
177                         {\r
178                                 $updates[$items[$j]]['data']['error'] = $lang['xs_update_error_noconnect'];\r
179                         }\r
180                 }\r
181         }\r
182         else\r
183         {\r
184                 for($j=0; $j<count($arr); $j++)\r
185                 {       // trim all lines and replace tab with space\r
186                         $arr[$j] = trim(str_replace("\t", ' ', $arr[$j]));\r
187                 }\r
188                 // checking all items to see which ones are for this url\r
189                 for($j=0; $j<count($items); $j++)\r
190                 {\r
191                         $item = $updates[$items[$j]];\r
192                         if($item['update_url'] === $urls[$i])\r
193                         {\r
194                                 // searching for data for this item\r
195                                 $begin_text = '<!-- BEGIN ' . $item['update_item'] . ' -->';\r
196                                 $end_text = '<!-- END ' . $item['update_item'] . ' -->';\r
197                                 $begin_pos = -1;\r
198                                 $end_pos = -1;\r
199                                 // getting begin and end tags for it\r
200                                 for($k=0; ($k<count($arr)-1) && ($begin_pos < 0); $k++)\r
201                                 {\r
202                                         if($arr[$k] === $begin_text)\r
203                                         {\r
204                                                 $begin_pos = $k;\r
205                                                 for(; ($k<count($arr)) && ($end_pos < 0); $k++)\r
206                                                 {\r
207                                                         if($arr[$k] === $end_text)\r
208                                                         {\r
209                                                                 $end_pos = $k;\r
210                                                         }\r
211                                                 }\r
212                                                 if($end_pos < 0)\r
213                                                 {\r
214                                                         $end_pos = count($arr);\r
215                                                 }\r
216                                         }\r
217                                 }\r
218                                 $data = array();\r
219                                 // found item position in text\r
220                                 if($begin_pos >= 0)\r
221                                 {\r
222                                         // getting all data for this item in array\r
223                                         for($k=$begin_pos+1; $k<$end_pos; $k++)\r
224                                         {\r
225                                                 $arr2 = explode(' ', $arr[$k], 2);\r
226                                                 if(count($arr2) == 2)\r
227                                                 {\r
228                                                         $data[trim($arr2[0])] = trim($arr2[1]);\r
229                                                 }\r
230                                         }\r
231                                 }\r
232                                 else\r
233                                 {\r
234                                         $data['error'] = $lang['xs_update_error_noitem'];\r
235                                 }\r
236                                 $updates[$items[$j]]['data'] = $data;\r
237                         }\r
238                 }\r
239         }\r
240 }\r
241 \r
242 $template->set_filenames(array('body' => XS_TPL_PATH . 'update2.tpl'));\r
243 \r
244 @reset($updates);\r
245 $count_total = 0;\r
246 $count_error = 0;\r
247 $count_update = 0;\r
248 foreach($updates as $var => $item)\r
249 {\r
250         if(isset($item['data']) && is_array($item['data']))\r
251         {\r
252                 $count_total++;\r
253                 $type = isset($lang['xs_update_types'][$item['update_type']]) ? $item['update_type'] : 0;\r
254                 $ver1 = htmlspecialchars($item['update_version']);\r
255                 $row_class = $xs_row_class[$count_total % 2];\r
256                 $template->assign_block_vars('row',\r
257                         array(\r
258                                 'ROW_CLASS'             => $row_class,\r
259                                 'ITEM'                  => htmlspecialchars($item['update_name']),\r
260                                 'TYPE'                  => $lang['xs_update_types'][$type],\r
261                                 'VERSION'               => $ver1,\r
262                         )\r
263                 );\r
264                 if(!empty($item['data']['version']))\r
265                 {\r
266                         $ver2 = htmlspecialchars($item['data']['version']);\r
267                         $info = isset($item['data']['info']) ? $item['data']['info'] : '';\r
268                         if($ver2 !== $ver1 && (!empty($item['data']['update']) || !empty($item['data']['autoupdate'])))\r
269                         {\r
270                                 $count_update++;\r
271                                 $u_import = (isset($item['data']['style']) && substr($item['data']['style'], 0, 7) === 'http://') ? append_sid('xs_import.'.$phpEx.'?get_web=' . urlencode($item['data']['style'])) : '';\r
272                                 $template->assign_block_vars('row.update',\r
273                                         array(\r
274                                                 'NUM'                   => $count_total,\r
275                                                 'VERSION'               => $ver2,\r
276                                                 'UPDATE'                => isset($item['data']['update']) ? htmlspecialchars($item['data']['update']) : '',\r
277                                                 'U_IMPORT'              => $u_import,\r
278                                                 'INFO'                  => htmlspecialchars($info),\r
279                                         )\r
280                                 );\r
281                                 $template->assign_block_vars('row.update.' . (empty($item['data']['update']) ? 'noupdate' : 'updated'), array());\r
282                                 $template->assign_block_vars('row.update.' . (empty($item['data']['info']) ? 'noinfo' : 'info'), array());\r
283                                 $template->assign_block_vars('row.update.' . (empty($u_import) ? 'noimport' : 'import'), array());\r
284                         }\r
285                         else\r
286                         {\r
287                                 $template->assign_block_vars('row.noupdate', \r
288                                         array(\r
289                                                 'VERSION'               => $ver2,\r
290                                                 'MESSAGE'               => $lang['xs_update_noupdate'],\r
291                                                 'INFO'                  => empty($info) ? '' : htmlspecialchars($info),\r
292                                         )\r
293                                 );\r
294                                 $template->assign_block_vars('row.noupdate.' . (empty($item['data']['info']) ? 'noinfo' : 'info'), array());\r
295                         }\r
296                 }\r
297                 else\r
298                 {\r
299                         if(empty($item['data']['error']))\r
300                         {\r
301                                 $item['data']['error'] = $lang['xs_update_error_noitem'];\r
302                         }\r
303                         $template->assign_block_vars('row.error', array('ERROR' => htmlspecialchars($item['data']['error'])));\r
304                         $count_error++;\r
305                 }\r
306         }\r
307 }\r
308 \r
309 $template->assign_vars(\r
310         array(\r
311                 'COUNT_TOTAL'           => str_replace('{NUM}', $count_total, $lang['xs_update_total1']),\r
312                 'COUNT_ERROR'           => str_replace('{NUM}', $count_error, $lang['xs_update_total2']),\r
313                 'COUNT_UPDATE'          => str_replace('{NUM}', $count_update, $lang['xs_update_total3'])\r
314         )\r
315 );\r
316 \r
317 $template->pparse('body');\r
318 xs_exit();\r
319 \r
320 ?>