1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-07-11 20:56:51 +0000 (Tue, 11 Jul 2006) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1459 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | if (!defined('PHPWG_ROOT_PATH')) |
---|
29 | { |
---|
30 | die ("Hacking attempt!"); |
---|
31 | } |
---|
32 | |
---|
33 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | check_status(ACCESS_ADMINISTRATOR); |
---|
39 | |
---|
40 | /** |
---|
41 | * requests the given $url (a remote create_listing_file.php) and fills a |
---|
42 | * list of lines corresponding to request output |
---|
43 | * |
---|
44 | * @param string $url |
---|
45 | * @return void |
---|
46 | */ |
---|
47 | function remote_output($url) |
---|
48 | { |
---|
49 | global $template, $page; |
---|
50 | |
---|
51 | if($lines = @file($url)) |
---|
52 | { |
---|
53 | $template->assign_block_vars('remote_output', array()); |
---|
54 | // cleaning lines from HTML tags |
---|
55 | foreach ($lines as $line) |
---|
56 | { |
---|
57 | $line = trim(strip_tags($line)); |
---|
58 | if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches)) |
---|
59 | { |
---|
60 | $template->assign_block_vars( |
---|
61 | 'remote_output.remote_line', |
---|
62 | array( |
---|
63 | 'CLASS' => 'remote'.ucfirst(strtolower($matches[1])), |
---|
64 | 'CONTENT' => $line |
---|
65 | ) |
---|
66 | ); |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | array_push($page['errors'], l10n('site_err_remote_file_not_found')); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | // +-----------------------------------------------------------------------+ |
---|
78 | // | template init | |
---|
79 | // +-----------------------------------------------------------------------+ |
---|
80 | $template->set_filenames(array('site_manager'=>'admin/site_manager.tpl')); |
---|
81 | |
---|
82 | // +-----------------------------------------------------------------------+ |
---|
83 | // | new site creation form | |
---|
84 | // +-----------------------------------------------------------------------+ |
---|
85 | if (isset($_POST['submit'])) |
---|
86 | { |
---|
87 | $is_remote = url_is_remote( $_POST['galleries_url'] ); |
---|
88 | $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']); |
---|
89 | $url.= '/'; |
---|
90 | if (! $is_remote) |
---|
91 | { |
---|
92 | if ( ! (strpos($url, '.') === 0 ) ) |
---|
93 | { |
---|
94 | $url = './' . $url; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | // site must not exists |
---|
99 | $query = ' |
---|
100 | SELECT COUNT(id) AS count |
---|
101 | FROM '.SITES_TABLE.' |
---|
102 | WHERE galleries_url = \''.$url.'\' |
---|
103 | ;'; |
---|
104 | $row = mysql_fetch_array(pwg_query($query)); |
---|
105 | if ($row['count'] > 0) |
---|
106 | { |
---|
107 | array_push($page['errors'], |
---|
108 | l10n('site_already_exists').' ['.$url.']'); |
---|
109 | } |
---|
110 | if (count($page['errors']) == 0) |
---|
111 | { |
---|
112 | if ($is_remote) |
---|
113 | { |
---|
114 | if ( ! isset($_POST['no_check']) ) |
---|
115 | { |
---|
116 | $clf_url = $url.'create_listing_file.php'; |
---|
117 | $clf_url.= '?action=test'; |
---|
118 | $clf_url.= '&version='.PHPWG_VERSION; |
---|
119 | if ($lines = @file($clf_url)) |
---|
120 | { |
---|
121 | $first_line = strip_tags($lines[0]); |
---|
122 | if (!preg_match('/^PWG-INFO-2:/', $first_line)) |
---|
123 | { |
---|
124 | array_push($page['errors'], |
---|
125 | l10n('site_err').' : '.$first_line); |
---|
126 | } |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | array_push($page['errors'], l10n('site_err_remote_file_not_found') ); |
---|
131 | } |
---|
132 | } |
---|
133 | } |
---|
134 | else |
---|
135 | { // local directory |
---|
136 | if ( ! file_exists($url) ) |
---|
137 | { |
---|
138 | array_push($page['errors'], |
---|
139 | l10n('Directory does not exist').' ['.$url.']'); |
---|
140 | } |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | if (count($page['errors']) == 0) |
---|
145 | { |
---|
146 | $query = ' |
---|
147 | INSERT INTO '.SITES_TABLE.' |
---|
148 | (galleries_url) |
---|
149 | VALUES |
---|
150 | (\''.$url.'\') |
---|
151 | ;'; |
---|
152 | pwg_query($query); |
---|
153 | array_push($page['infos'], |
---|
154 | $url.' '.l10n('site_created')); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | // +-----------------------------------------------------------------------+ |
---|
159 | // | actions on site | |
---|
160 | // +-----------------------------------------------------------------------+ |
---|
161 | if (isset($_GET['site']) and is_numeric($_GET['site'])) |
---|
162 | { |
---|
163 | $page['site'] = $_GET['site']; |
---|
164 | } |
---|
165 | if (isset($_GET['action']) and isset($page['site']) and !is_adviser()) |
---|
166 | { |
---|
167 | $query = ' |
---|
168 | SELECT galleries_url |
---|
169 | FROM '.SITES_TABLE.' |
---|
170 | WHERE id = '.$page['site'].' |
---|
171 | ;'; |
---|
172 | list($galleries_url) = mysql_fetch_array(pwg_query($query)); |
---|
173 | switch($_GET['action']) |
---|
174 | { |
---|
175 | case 'generate' : |
---|
176 | { |
---|
177 | $title = $galleries_url.' : '.l10n('remote_site_generate'); |
---|
178 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
179 | remote_output($galleries_url.'create_listing_file.php?action=generate'); |
---|
180 | break; |
---|
181 | } |
---|
182 | case 'test' : |
---|
183 | { |
---|
184 | $title = $galleries_url.' : '.l10n('remote_site_test'); |
---|
185 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
186 | remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION); |
---|
187 | break; |
---|
188 | } |
---|
189 | case 'clean' : |
---|
190 | { |
---|
191 | $title = $galleries_url.' : '.l10n('remote_site_clean'); |
---|
192 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
193 | remote_output($galleries_url.'create_listing_file.php?action=clean'); |
---|
194 | break; |
---|
195 | } |
---|
196 | case 'delete' : |
---|
197 | { |
---|
198 | delete_site($page['site']); |
---|
199 | array_push($page['infos'], |
---|
200 | $galleries_url.' '.l10n('site_deleted')); |
---|
201 | break; |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | $template->assign_vars( array( |
---|
207 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=remote_site', |
---|
208 | 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php' |
---|
209 | .get_query_string_diff( array('action','site') ) |
---|
210 | ) ); |
---|
211 | |
---|
212 | // +-----------------------------------------------------------------------+ |
---|
213 | // | remote sites list | |
---|
214 | // +-----------------------------------------------------------------------+ |
---|
215 | |
---|
216 | if ( is_file(PHPWG_ROOT_PATH.'listing.xml') ) |
---|
217 | { |
---|
218 | $xml_content = getXmlCode(PHPWG_ROOT_PATH.'listing.xml'); |
---|
219 | $local_listing_site_url = getAttribute( |
---|
220 | getChild($xml_content, 'informations'), |
---|
221 | 'url' |
---|
222 | ); |
---|
223 | if ( !url_is_remote($local_listing_site_url) ) |
---|
224 | { |
---|
225 | $local_listing_site_url = null; |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | $query = ' |
---|
230 | SELECT s.*, COUNT(c.id) AS nb_categories, SUM(c.nb_images) AS nb_images |
---|
231 | FROM '.SITES_TABLE.' AS s LEFT JOIN '.CATEGORIES_TABLE.' AS c |
---|
232 | ON s.id=c.site_id |
---|
233 | GROUP BY s.id'. |
---|
234 | ';'; |
---|
235 | $result = pwg_query($query); |
---|
236 | |
---|
237 | if (mysql_num_rows($result) > 0) |
---|
238 | { |
---|
239 | $template->assign_block_vars('sites', array()); |
---|
240 | } |
---|
241 | while ($row = mysql_fetch_array($result)) |
---|
242 | { |
---|
243 | $is_remote = url_is_remote($row['galleries_url']); |
---|
244 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
245 | $base_url.= '?page=site_manager'; |
---|
246 | $base_url.= '&site='.$row['id']; |
---|
247 | $base_url.= '&action='; |
---|
248 | |
---|
249 | $update_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
250 | $update_url.= '?page=site_update'; |
---|
251 | $update_url.= '&site='.$row['id']; |
---|
252 | $template->assign_block_vars( |
---|
253 | 'sites.site', |
---|
254 | array( |
---|
255 | 'NAME' => $row['galleries_url'], |
---|
256 | 'TYPE' => l10n( $is_remote ? 'site_remote' : 'site_local' ), |
---|
257 | 'CATEGORIES' => $row['nb_categories'], |
---|
258 | 'IMAGES' => isset($row['nb_images']) ? $row['nb_images'] : 0, |
---|
259 | 'U_SYNCHRONIZE' => $update_url |
---|
260 | ) |
---|
261 | ); |
---|
262 | if ($is_remote) |
---|
263 | { |
---|
264 | $template->assign_block_vars('sites.site.remote', |
---|
265 | array( |
---|
266 | 'U_TEST' => $base_url.'test', |
---|
267 | 'U_GENERATE' => $base_url.'generate', |
---|
268 | 'U_CLEAN' => $base_url.'clean' |
---|
269 | ) |
---|
270 | ); |
---|
271 | } |
---|
272 | |
---|
273 | if ($row['id'] != 1) |
---|
274 | { |
---|
275 | $template->assign_block_vars( 'sites.site.delete', |
---|
276 | array('U_DELETE' => $base_url.'delete') ); |
---|
277 | } |
---|
278 | |
---|
279 | if ( isset($local_listing_site_url) and |
---|
280 | $row['galleries_url']==$local_listing_site_url ) |
---|
281 | { |
---|
282 | $local_listing_site_id = $row['id']; |
---|
283 | $template->assign_block_vars( 'local_listing', |
---|
284 | array( |
---|
285 | 'URL' => $local_listing_site_url, |
---|
286 | ) |
---|
287 | ); |
---|
288 | |
---|
289 | $template->assign_block_vars( 'local_listing.update', |
---|
290 | array( |
---|
291 | 'U_SYNCHRONIZE' => $update_url.'&local_listing=1' |
---|
292 | ) |
---|
293 | ); |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | if ( isset($local_listing_site_url) and !isset($local_listing_site_id) ) |
---|
298 | { |
---|
299 | $template->assign_block_vars( 'local_listing', |
---|
300 | array( |
---|
301 | 'URL' => $local_listing_site_url, |
---|
302 | ) |
---|
303 | ); |
---|
304 | |
---|
305 | $template->assign_block_vars( 'local_listing.create', |
---|
306 | array('NAME' => $local_listing_site_url) |
---|
307 | ); |
---|
308 | } |
---|
309 | |
---|
310 | |
---|
311 | $template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager'); |
---|
312 | ?> |
---|