[1058] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3046] | 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1058] | 23 | |
---|
| 24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 25 | { |
---|
| 26 | die ("Hacking attempt!"); |
---|
| 27 | } |
---|
| 28 | |
---|
[1072] | 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 | |
---|
[4531] | 36 | if (!empty($_POST) or isset($_GET['action'])) |
---|
| 37 | { |
---|
| 38 | check_pwg_token(); |
---|
| 39 | } |
---|
| 40 | |
---|
[1058] | 41 | /** |
---|
| 42 | * requests the given $url (a remote create_listing_file.php) and fills a |
---|
| 43 | * list of lines corresponding to request output |
---|
| 44 | * |
---|
| 45 | * @param string $url |
---|
| 46 | * @return void |
---|
| 47 | */ |
---|
| 48 | function remote_output($url) |
---|
| 49 | { |
---|
| 50 | global $template, $page; |
---|
| 51 | |
---|
[2903] | 52 | if (fetchRemote($url, $result)) |
---|
[1058] | 53 | { |
---|
[2903] | 54 | $lines = explode("\r\n", $result); |
---|
[1058] | 55 | // cleaning lines from HTML tags |
---|
| 56 | foreach ($lines as $line) |
---|
| 57 | { |
---|
| 58 | $line = trim(strip_tags($line)); |
---|
| 59 | if (preg_match('/^PWG-([A-Z]+)-/', $line, $matches)) |
---|
| 60 | { |
---|
[2273] | 61 | $template->append( |
---|
| 62 | 'remote_output', |
---|
[1058] | 63 | array( |
---|
| 64 | 'CLASS' => 'remote'.ucfirst(strtolower($matches[1])), |
---|
| 65 | 'CONTENT' => $line |
---|
| 66 | ) |
---|
| 67 | ); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | else |
---|
| 72 | { |
---|
| 73 | array_push($page['errors'], l10n('site_err_remote_file_not_found')); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | // +-----------------------------------------------------------------------+ |
---|
| 79 | // | template init | |
---|
| 80 | // +-----------------------------------------------------------------------+ |
---|
[2530] | 81 | $template->set_filenames(array('site_manager'=>'site_manager.tpl')); |
---|
[1058] | 82 | |
---|
| 83 | // +-----------------------------------------------------------------------+ |
---|
| 84 | // | new site creation form | |
---|
| 85 | // +-----------------------------------------------------------------------+ |
---|
[1654] | 86 | if (isset($_POST['submit']) and !empty($_POST['galleries_url']) |
---|
| 87 | and !is_adviser() ) |
---|
[1058] | 88 | { |
---|
| 89 | $is_remote = url_is_remote( $_POST['galleries_url'] ); |
---|
| 90 | $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']); |
---|
| 91 | $url.= '/'; |
---|
| 92 | if (! $is_remote) |
---|
| 93 | { |
---|
| 94 | if ( ! (strpos($url, '.') === 0 ) ) |
---|
| 95 | { |
---|
| 96 | $url = './' . $url; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | // site must not exists |
---|
| 101 | $query = ' |
---|
| 102 | SELECT COUNT(id) AS count |
---|
| 103 | FROM '.SITES_TABLE.' |
---|
| 104 | WHERE galleries_url = \''.$url.'\' |
---|
| 105 | ;'; |
---|
| 106 | $row = mysql_fetch_array(pwg_query($query)); |
---|
| 107 | if ($row['count'] > 0) |
---|
| 108 | { |
---|
| 109 | array_push($page['errors'], |
---|
| 110 | l10n('site_already_exists').' ['.$url.']'); |
---|
| 111 | } |
---|
| 112 | if (count($page['errors']) == 0) |
---|
| 113 | { |
---|
| 114 | if ($is_remote) |
---|
| 115 | { |
---|
[1107] | 116 | if ( ! isset($_POST['no_check']) ) |
---|
[1058] | 117 | { |
---|
[1107] | 118 | $clf_url = $url.'create_listing_file.php'; |
---|
| 119 | $clf_url.= '?action=test'; |
---|
| 120 | $clf_url.= '&version='.PHPWG_VERSION; |
---|
[2903] | 121 | if (fetchRemote($clf_url, $result)) |
---|
[1058] | 122 | { |
---|
[2903] | 123 | $lines = explode("\r\n", $result); |
---|
[1107] | 124 | $first_line = strip_tags($lines[0]); |
---|
| 125 | if (!preg_match('/^PWG-INFO-2:/', $first_line)) |
---|
| 126 | { |
---|
| 127 | array_push($page['errors'], |
---|
| 128 | l10n('site_err').' : '.$first_line); |
---|
| 129 | } |
---|
[1058] | 130 | } |
---|
[1107] | 131 | else |
---|
| 132 | { |
---|
| 133 | array_push($page['errors'], l10n('site_err_remote_file_not_found') ); |
---|
| 134 | } |
---|
[1058] | 135 | } |
---|
| 136 | } |
---|
| 137 | else |
---|
| 138 | { // local directory |
---|
| 139 | if ( ! file_exists($url) ) |
---|
| 140 | { |
---|
| 141 | array_push($page['errors'], |
---|
| 142 | l10n('Directory does not exist').' ['.$url.']'); |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | if (count($page['errors']) == 0) |
---|
| 148 | { |
---|
| 149 | $query = ' |
---|
| 150 | INSERT INTO '.SITES_TABLE.' |
---|
| 151 | (galleries_url) |
---|
| 152 | VALUES |
---|
| 153 | (\''.$url.'\') |
---|
| 154 | ;'; |
---|
| 155 | pwg_query($query); |
---|
| 156 | array_push($page['infos'], |
---|
| 157 | $url.' '.l10n('site_created')); |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | // +-----------------------------------------------------------------------+ |
---|
| 162 | // | actions on site | |
---|
| 163 | // +-----------------------------------------------------------------------+ |
---|
| 164 | if (isset($_GET['site']) and is_numeric($_GET['site'])) |
---|
| 165 | { |
---|
| 166 | $page['site'] = $_GET['site']; |
---|
| 167 | } |
---|
[1458] | 168 | if (isset($_GET['action']) and isset($page['site']) and !is_adviser()) |
---|
[1058] | 169 | { |
---|
| 170 | $query = ' |
---|
| 171 | SELECT galleries_url |
---|
| 172 | FROM '.SITES_TABLE.' |
---|
| 173 | WHERE id = '.$page['site'].' |
---|
| 174 | ;'; |
---|
| 175 | list($galleries_url) = mysql_fetch_array(pwg_query($query)); |
---|
| 176 | switch($_GET['action']) |
---|
| 177 | { |
---|
| 178 | case 'generate' : |
---|
| 179 | { |
---|
| 180 | $title = $galleries_url.' : '.l10n('remote_site_generate'); |
---|
| 181 | remote_output($galleries_url.'create_listing_file.php?action=generate'); |
---|
| 182 | break; |
---|
| 183 | } |
---|
| 184 | case 'test' : |
---|
| 185 | { |
---|
| 186 | $title = $galleries_url.' : '.l10n('remote_site_test'); |
---|
| 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 | 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 | |
---|
[4531] | 206 | $template->assign( |
---|
| 207 | array( |
---|
| 208 | 'U_HELP' => get_root_url().'popuphelp.php?page=site_manager', |
---|
| 209 | 'F_ACTION' => get_root_url().'admin.php'.get_query_string_diff(array('action','site','pwg_token')), |
---|
| 210 | 'PWG_TOKEN' => get_pwg_token(), |
---|
| 211 | ) |
---|
| 212 | ); |
---|
[1058] | 213 | |
---|
| 214 | // +-----------------------------------------------------------------------+ |
---|
| 215 | // | remote sites list | |
---|
| 216 | // +-----------------------------------------------------------------------+ |
---|
| 217 | |
---|
[1107] | 218 | if ( is_file(PHPWG_ROOT_PATH.'listing.xml') ) |
---|
| 219 | { |
---|
| 220 | $xml_content = getXmlCode(PHPWG_ROOT_PATH.'listing.xml'); |
---|
| 221 | $local_listing_site_url = getAttribute( |
---|
| 222 | getChild($xml_content, 'informations'), |
---|
| 223 | 'url' |
---|
| 224 | ); |
---|
| 225 | if ( !url_is_remote($local_listing_site_url) ) |
---|
| 226 | { |
---|
| 227 | $local_listing_site_url = null; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
[1058] | 231 | $query = ' |
---|
[2324] | 232 | SELECT c.site_id, COUNT(DISTINCT c.id) AS nb_categories, COUNT(i.id) AS nb_images |
---|
| 233 | FROM '.CATEGORIES_TABLE.' AS c LEFT JOIN '.IMAGES_TABLE.' AS i |
---|
| 234 | ON c.id=i.storage_category_id |
---|
| 235 | WHERE c.site_id IS NOT NULL |
---|
| 236 | GROUP BY c.site_id |
---|
| 237 | ;'; |
---|
| 238 | $sites_detail = hash_from_query($query, 'site_id'); |
---|
| 239 | |
---|
| 240 | $query = ' |
---|
| 241 | SELECT * |
---|
| 242 | FROM '.SITES_TABLE.' |
---|
| 243 | ;'; |
---|
[1058] | 244 | $result = pwg_query($query); |
---|
| 245 | |
---|
| 246 | while ($row = mysql_fetch_array($result)) |
---|
| 247 | { |
---|
| 248 | $is_remote = url_is_remote($row['galleries_url']); |
---|
| 249 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 250 | $base_url.= '?page=site_manager'; |
---|
| 251 | $base_url.= '&site='.$row['id']; |
---|
[4531] | 252 | $base_url.= '&pwg_token='.get_pwg_token(); |
---|
[1058] | 253 | $base_url.= '&action='; |
---|
| 254 | |
---|
| 255 | $update_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 256 | $update_url.= '?page=site_update'; |
---|
| 257 | $update_url.= '&site='.$row['id']; |
---|
[2273] | 258 | |
---|
| 259 | $tpl_var = |
---|
[1058] | 260 | array( |
---|
| 261 | 'NAME' => $row['galleries_url'], |
---|
| 262 | 'TYPE' => l10n( $is_remote ? 'site_remote' : 'site_local' ), |
---|
[2324] | 263 | 'CATEGORIES' => (int)@$sites_detail[$row['id']]['nb_categories'], |
---|
| 264 | 'IMAGES' => (int)@$sites_detail[$row['id']]['nb_images'], |
---|
[1058] | 265 | 'U_SYNCHRONIZE' => $update_url |
---|
[2273] | 266 | ); |
---|
| 267 | |
---|
[1058] | 268 | if ($is_remote) |
---|
| 269 | { |
---|
[2273] | 270 | $tpl_var['remote'] = |
---|
[1058] | 271 | array( |
---|
| 272 | 'U_TEST' => $base_url.'test', |
---|
[1775] | 273 | 'U_GENERATE' => $row['galleries_url'].'create_listing_file.php?action=generate', |
---|
| 274 | 'U_CLEAN' => $base_url.'clean', |
---|
[2273] | 275 | ); |
---|
[1058] | 276 | } |
---|
| 277 | |
---|
[1107] | 278 | if ($row['id'] != 1) |
---|
| 279 | { |
---|
[2273] | 280 | $tpl_var['U_DELETE'] = $base_url.'delete'; |
---|
[1107] | 281 | } |
---|
| 282 | |
---|
[2273] | 283 | $plugin_links = array(); |
---|
| 284 | //$plugin_links is array of array composed of U_HREF, U_HINT & U_CAPTION |
---|
| 285 | $plugin_links = |
---|
| 286 | trigger_event('get_admins_site_links', |
---|
| 287 | $plugin_links, $row['id'], $is_remote); |
---|
| 288 | $tpl_var['plugin_links'] = $plugin_links; |
---|
| 289 | |
---|
| 290 | $template->append('sites', $tpl_var); |
---|
| 291 | |
---|
[1107] | 292 | if ( isset($local_listing_site_url) and |
---|
| 293 | $row['galleries_url']==$local_listing_site_url ) |
---|
| 294 | { |
---|
| 295 | $local_listing_site_id = $row['id']; |
---|
[2273] | 296 | $template->assign( 'local_listing', |
---|
[1107] | 297 | array( |
---|
| 298 | 'URL' => $local_listing_site_url, |
---|
[2273] | 299 | 'U_SYNCHRONIZE' => $update_url.'&local_listing=1' |
---|
[1107] | 300 | ) |
---|
| 301 | ); |
---|
| 302 | } |
---|
[1058] | 303 | } |
---|
| 304 | |
---|
[1107] | 305 | if ( isset($local_listing_site_url) and !isset($local_listing_site_id) ) |
---|
| 306 | { |
---|
[2273] | 307 | $template->assign( 'local_listing', |
---|
[1107] | 308 | array( |
---|
| 309 | 'URL' => $local_listing_site_url, |
---|
[2273] | 310 | 'CREATE' => true |
---|
[1107] | 311 | ) |
---|
| 312 | ); |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | |
---|
[1058] | 316 | $template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager'); |
---|
[1775] | 317 | ?> |
---|