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