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