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-12-13 01:38:47 +0000 (Wed, 13 Dec 2006) $ |
---|
10 | // | last modifier : $Author: rvelices $ |
---|
11 | // | revision : $Revision: 1654 $ |
---|
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']) and !empty($_POST['galleries_url']) |
---|
86 | and !is_adviser() ) |
---|
87 | { |
---|
88 | $is_remote = url_is_remote( $_POST['galleries_url'] ); |
---|
89 | $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']); |
---|
90 | $url.= '/'; |
---|
91 | if (! $is_remote) |
---|
92 | { |
---|
93 | if ( ! (strpos($url, '.') === 0 ) ) |
---|
94 | { |
---|
95 | $url = './' . $url; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | // site must not exists |
---|
100 | $query = ' |
---|
101 | SELECT COUNT(id) AS count |
---|
102 | FROM '.SITES_TABLE.' |
---|
103 | WHERE galleries_url = \''.$url.'\' |
---|
104 | ;'; |
---|
105 | $row = mysql_fetch_array(pwg_query($query)); |
---|
106 | if ($row['count'] > 0) |
---|
107 | { |
---|
108 | array_push($page['errors'], |
---|
109 | l10n('site_already_exists').' ['.$url.']'); |
---|
110 | } |
---|
111 | if (count($page['errors']) == 0) |
---|
112 | { |
---|
113 | if ($is_remote) |
---|
114 | { |
---|
115 | if ( ! isset($_POST['no_check']) ) |
---|
116 | { |
---|
117 | $clf_url = $url.'create_listing_file.php'; |
---|
118 | $clf_url.= '?action=test'; |
---|
119 | $clf_url.= '&version='.PHPWG_VERSION; |
---|
120 | if ($lines = @file($clf_url)) |
---|
121 | { |
---|
122 | $first_line = strip_tags($lines[0]); |
---|
123 | if (!preg_match('/^PWG-INFO-2:/', $first_line)) |
---|
124 | { |
---|
125 | array_push($page['errors'], |
---|
126 | l10n('site_err').' : '.$first_line); |
---|
127 | } |
---|
128 | } |
---|
129 | else |
---|
130 | { |
---|
131 | array_push($page['errors'], l10n('site_err_remote_file_not_found') ); |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | else |
---|
136 | { // local directory |
---|
137 | if ( ! file_exists($url) ) |
---|
138 | { |
---|
139 | array_push($page['errors'], |
---|
140 | l10n('Directory does not exist').' ['.$url.']'); |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | if (count($page['errors']) == 0) |
---|
146 | { |
---|
147 | $query = ' |
---|
148 | INSERT INTO '.SITES_TABLE.' |
---|
149 | (galleries_url) |
---|
150 | VALUES |
---|
151 | (\''.$url.'\') |
---|
152 | ;'; |
---|
153 | pwg_query($query); |
---|
154 | array_push($page['infos'], |
---|
155 | $url.' '.l10n('site_created')); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | // +-----------------------------------------------------------------------+ |
---|
160 | // | actions on site | |
---|
161 | // +-----------------------------------------------------------------------+ |
---|
162 | if (isset($_GET['site']) and is_numeric($_GET['site'])) |
---|
163 | { |
---|
164 | $page['site'] = $_GET['site']; |
---|
165 | } |
---|
166 | if (isset($_GET['action']) and isset($page['site']) and !is_adviser()) |
---|
167 | { |
---|
168 | $query = ' |
---|
169 | SELECT galleries_url |
---|
170 | FROM '.SITES_TABLE.' |
---|
171 | WHERE id = '.$page['site'].' |
---|
172 | ;'; |
---|
173 | list($galleries_url) = mysql_fetch_array(pwg_query($query)); |
---|
174 | switch($_GET['action']) |
---|
175 | { |
---|
176 | case 'generate' : |
---|
177 | { |
---|
178 | $title = $galleries_url.' : '.l10n('remote_site_generate'); |
---|
179 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
180 | remote_output($galleries_url.'create_listing_file.php?action=generate'); |
---|
181 | break; |
---|
182 | } |
---|
183 | case 'test' : |
---|
184 | { |
---|
185 | $title = $galleries_url.' : '.l10n('remote_site_test'); |
---|
186 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
187 | remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION); |
---|
188 | break; |
---|
189 | } |
---|
190 | case 'clean' : |
---|
191 | { |
---|
192 | $title = $galleries_url.' : '.l10n('remote_site_clean'); |
---|
193 | $template->assign_vars(array('REMOTE_SITE_TITLE'=>$title)); |
---|
194 | remote_output($galleries_url.'create_listing_file.php?action=clean'); |
---|
195 | break; |
---|
196 | } |
---|
197 | case 'delete' : |
---|
198 | { |
---|
199 | delete_site($page['site']); |
---|
200 | array_push($page['infos'], |
---|
201 | $galleries_url.' '.l10n('site_deleted')); |
---|
202 | break; |
---|
203 | } |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | $template->assign_vars( array( |
---|
208 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=remote_site', |
---|
209 | 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php' |
---|
210 | .get_query_string_diff( array('action','site') ) |
---|
211 | ) ); |
---|
212 | |
---|
213 | // +-----------------------------------------------------------------------+ |
---|
214 | // | remote sites list | |
---|
215 | // +-----------------------------------------------------------------------+ |
---|
216 | |
---|
217 | if ( is_file(PHPWG_ROOT_PATH.'listing.xml') ) |
---|
218 | { |
---|
219 | $xml_content = getXmlCode(PHPWG_ROOT_PATH.'listing.xml'); |
---|
220 | $local_listing_site_url = getAttribute( |
---|
221 | getChild($xml_content, 'informations'), |
---|
222 | 'url' |
---|
223 | ); |
---|
224 | if ( !url_is_remote($local_listing_site_url) ) |
---|
225 | { |
---|
226 | $local_listing_site_url = null; |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | $query = ' |
---|
231 | SELECT s.*, COUNT(c.id) AS nb_categories, SUM(c.nb_images) AS nb_images |
---|
232 | FROM '.SITES_TABLE.' AS s LEFT JOIN '.CATEGORIES_TABLE.' AS c |
---|
233 | ON s.id=c.site_id |
---|
234 | GROUP BY s.id'. |
---|
235 | ';'; |
---|
236 | $result = pwg_query($query); |
---|
237 | |
---|
238 | if (mysql_num_rows($result) > 0) |
---|
239 | { |
---|
240 | $template->assign_block_vars('sites', array()); |
---|
241 | } |
---|
242 | while ($row = mysql_fetch_array($result)) |
---|
243 | { |
---|
244 | $is_remote = url_is_remote($row['galleries_url']); |
---|
245 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
246 | $base_url.= '?page=site_manager'; |
---|
247 | $base_url.= '&site='.$row['id']; |
---|
248 | $base_url.= '&action='; |
---|
249 | |
---|
250 | $update_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
251 | $update_url.= '?page=site_update'; |
---|
252 | $update_url.= '&site='.$row['id']; |
---|
253 | $template->assign_block_vars( |
---|
254 | 'sites.site', |
---|
255 | array( |
---|
256 | 'NAME' => $row['galleries_url'], |
---|
257 | 'TYPE' => l10n( $is_remote ? 'site_remote' : 'site_local' ), |
---|
258 | 'CATEGORIES' => $row['nb_categories'], |
---|
259 | 'IMAGES' => isset($row['nb_images']) ? $row['nb_images'] : 0, |
---|
260 | 'U_SYNCHRONIZE' => $update_url |
---|
261 | ) |
---|
262 | ); |
---|
263 | if ($is_remote) |
---|
264 | { |
---|
265 | $template->assign_block_vars('sites.site.remote', |
---|
266 | array( |
---|
267 | 'U_TEST' => $base_url.'test', |
---|
268 | 'U_GENERATE' => $base_url.'generate', |
---|
269 | 'U_CLEAN' => $base_url.'clean' |
---|
270 | ) |
---|
271 | ); |
---|
272 | } |
---|
273 | |
---|
274 | if ($row['id'] != 1) |
---|
275 | { |
---|
276 | $template->assign_block_vars( 'sites.site.delete', |
---|
277 | array('U_DELETE' => $base_url.'delete') ); |
---|
278 | } |
---|
279 | |
---|
280 | if ( isset($local_listing_site_url) and |
---|
281 | $row['galleries_url']==$local_listing_site_url ) |
---|
282 | { |
---|
283 | $local_listing_site_id = $row['id']; |
---|
284 | $template->assign_block_vars( 'local_listing', |
---|
285 | array( |
---|
286 | 'URL' => $local_listing_site_url, |
---|
287 | ) |
---|
288 | ); |
---|
289 | |
---|
290 | $template->assign_block_vars( 'local_listing.update', |
---|
291 | array( |
---|
292 | 'U_SYNCHRONIZE' => $update_url.'&local_listing=1' |
---|
293 | ) |
---|
294 | ); |
---|
295 | } |
---|
296 | } |
---|
297 | |
---|
298 | if ( isset($local_listing_site_url) and !isset($local_listing_site_id) ) |
---|
299 | { |
---|
300 | $template->assign_block_vars( 'local_listing', |
---|
301 | array( |
---|
302 | 'URL' => $local_listing_site_url, |
---|
303 | ) |
---|
304 | ); |
---|
305 | |
---|
306 | $template->assign_block_vars( 'local_listing.create', |
---|
307 | array('NAME' => $local_listing_site_url) |
---|
308 | ); |
---|
309 | } |
---|
310 | |
---|
311 | |
---|
312 | $template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager'); |
---|
313 | ?> |
---|