[1058] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 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 | |
---|
[5195] | 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 | |
---|
[2902] | 52 | if (fetchRemote($url, $result)) |
---|
[1058] | 53 | { |
---|
[2902] | 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 | { |
---|
[5021] | 73 | array_push($page['errors'], l10n('file create_listing_file.php on remote site was not found')); |
---|
[1058] | 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 | // +-----------------------------------------------------------------------+ |
---|
[8126] | 86 | if (isset($_POST['submit']) and !empty($_POST['galleries_url'])) |
---|
[1058] | 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 | ;'; |
---|
[4325] | 105 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[1058] | 106 | if ($row['count'] > 0) |
---|
| 107 | { |
---|
| 108 | array_push($page['errors'], |
---|
[5021] | 109 | l10n('This site already exists').' ['.$url.']'); |
---|
[1058] | 110 | } |
---|
| 111 | if (count($page['errors']) == 0) |
---|
| 112 | { |
---|
| 113 | if ($is_remote) |
---|
| 114 | { |
---|
[1107] | 115 | if ( ! isset($_POST['no_check']) ) |
---|
[1058] | 116 | { |
---|
[1107] | 117 | $clf_url = $url.'create_listing_file.php'; |
---|
[8083] | 118 | $get_data = array( |
---|
| 119 | 'action' => 'test', |
---|
| 120 | 'version' => PHPWG_VERSION, |
---|
| 121 | ); |
---|
| 122 | if (fetchRemote($clf_url, $result, $get_data)) |
---|
[1058] | 123 | { |
---|
[2902] | 124 | $lines = explode("\r\n", $result); |
---|
[1107] | 125 | $first_line = strip_tags($lines[0]); |
---|
| 126 | if (!preg_match('/^PWG-INFO-2:/', $first_line)) |
---|
| 127 | { |
---|
| 128 | array_push($page['errors'], |
---|
[5021] | 129 | l10n('an error happened').' : '.$first_line); |
---|
[1107] | 130 | } |
---|
[1058] | 131 | } |
---|
[1107] | 132 | else |
---|
| 133 | { |
---|
[5021] | 134 | array_push($page['errors'], l10n('file create_listing_file.php on remote site was not found') ); |
---|
[1107] | 135 | } |
---|
[1058] | 136 | } |
---|
| 137 | } |
---|
| 138 | else |
---|
| 139 | { // local directory |
---|
| 140 | if ( ! file_exists($url) ) |
---|
| 141 | { |
---|
| 142 | array_push($page['errors'], |
---|
| 143 | l10n('Directory does not exist').' ['.$url.']'); |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | if (count($page['errors']) == 0) |
---|
| 149 | { |
---|
| 150 | $query = ' |
---|
| 151 | INSERT INTO '.SITES_TABLE.' |
---|
| 152 | (galleries_url) |
---|
| 153 | VALUES |
---|
| 154 | (\''.$url.'\') |
---|
| 155 | ;'; |
---|
| 156 | pwg_query($query); |
---|
| 157 | array_push($page['infos'], |
---|
[5021] | 158 | $url.' '.l10n('created')); |
---|
[1058] | 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | // +-----------------------------------------------------------------------+ |
---|
| 163 | // | actions on site | |
---|
| 164 | // +-----------------------------------------------------------------------+ |
---|
| 165 | if (isset($_GET['site']) and is_numeric($_GET['site'])) |
---|
| 166 | { |
---|
| 167 | $page['site'] = $_GET['site']; |
---|
| 168 | } |
---|
[8126] | 169 | if (isset($_GET['action']) and isset($page['site'])) |
---|
[1058] | 170 | { |
---|
| 171 | $query = ' |
---|
| 172 | SELECT galleries_url |
---|
| 173 | FROM '.SITES_TABLE.' |
---|
| 174 | WHERE id = '.$page['site'].' |
---|
| 175 | ;'; |
---|
[4325] | 176 | list($galleries_url) = pwg_db_fetch_row(pwg_query($query)); |
---|
[1058] | 177 | switch($_GET['action']) |
---|
| 178 | { |
---|
| 179 | case 'generate' : |
---|
| 180 | { |
---|
[5021] | 181 | $title = $galleries_url.' : '.l10n('generate listing'); |
---|
[1058] | 182 | remote_output($galleries_url.'create_listing_file.php?action=generate'); |
---|
| 183 | break; |
---|
| 184 | } |
---|
| 185 | case 'test' : |
---|
| 186 | { |
---|
[5021] | 187 | $title = $galleries_url.' : '.l10n('test'); |
---|
[1058] | 188 | remote_output($galleries_url.'create_listing_file.php?action=test&version='.PHPWG_VERSION); |
---|
| 189 | break; |
---|
| 190 | } |
---|
| 191 | case 'clean' : |
---|
| 192 | { |
---|
[5021] | 193 | $title = $galleries_url.' : '.l10n('clean'); |
---|
[1058] | 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'], |
---|
[5021] | 201 | $galleries_url.' '.l10n('deleted')); |
---|
[1058] | 202 | break; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
[5195] | 207 | $template->assign( |
---|
| 208 | array( |
---|
[5920] | 209 | 'U_HELP' => get_root_url().'admin/popuphelp.php?page=site_manager', |
---|
[5195] | 210 | 'F_ACTION' => get_root_url().'admin.php'.get_query_string_diff(array('action','site','pwg_token')), |
---|
| 211 | 'PWG_TOKEN' => get_pwg_token(), |
---|
| 212 | ) |
---|
| 213 | ); |
---|
[1058] | 214 | |
---|
| 215 | // +-----------------------------------------------------------------------+ |
---|
| 216 | // | remote sites list | |
---|
| 217 | // +-----------------------------------------------------------------------+ |
---|
| 218 | |
---|
[1107] | 219 | if ( is_file(PHPWG_ROOT_PATH.'listing.xml') ) |
---|
| 220 | { |
---|
| 221 | $xml_content = getXmlCode(PHPWG_ROOT_PATH.'listing.xml'); |
---|
| 222 | $local_listing_site_url = getAttribute( |
---|
| 223 | getChild($xml_content, 'informations'), |
---|
| 224 | 'url' |
---|
| 225 | ); |
---|
| 226 | if ( !url_is_remote($local_listing_site_url) ) |
---|
| 227 | { |
---|
| 228 | $local_listing_site_url = null; |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
[1058] | 232 | $query = ' |
---|
[2324] | 233 | SELECT c.site_id, COUNT(DISTINCT c.id) AS nb_categories, COUNT(i.id) AS nb_images |
---|
| 234 | FROM '.CATEGORIES_TABLE.' AS c LEFT JOIN '.IMAGES_TABLE.' AS i |
---|
| 235 | ON c.id=i.storage_category_id |
---|
| 236 | WHERE c.site_id IS NOT NULL |
---|
| 237 | GROUP BY c.site_id |
---|
| 238 | ;'; |
---|
| 239 | $sites_detail = hash_from_query($query, 'site_id'); |
---|
| 240 | |
---|
| 241 | $query = ' |
---|
| 242 | SELECT * |
---|
| 243 | FROM '.SITES_TABLE.' |
---|
| 244 | ;'; |
---|
[1058] | 245 | $result = pwg_query($query); |
---|
| 246 | |
---|
[4325] | 247 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1058] | 248 | { |
---|
| 249 | $is_remote = url_is_remote($row['galleries_url']); |
---|
| 250 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 251 | $base_url.= '?page=site_manager'; |
---|
| 252 | $base_url.= '&site='.$row['id']; |
---|
[5195] | 253 | $base_url.= '&pwg_token='.get_pwg_token(); |
---|
[1058] | 254 | $base_url.= '&action='; |
---|
| 255 | |
---|
| 256 | $update_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 257 | $update_url.= '?page=site_update'; |
---|
| 258 | $update_url.= '&site='.$row['id']; |
---|
[2273] | 259 | |
---|
| 260 | $tpl_var = |
---|
[1058] | 261 | array( |
---|
| 262 | 'NAME' => $row['galleries_url'], |
---|
[5036] | 263 | 'TYPE' => l10n( $is_remote ? 'Remote' : 'Local' ), |
---|
[2324] | 264 | 'CATEGORIES' => (int)@$sites_detail[$row['id']]['nb_categories'], |
---|
| 265 | 'IMAGES' => (int)@$sites_detail[$row['id']]['nb_images'], |
---|
[1058] | 266 | 'U_SYNCHRONIZE' => $update_url |
---|
[2273] | 267 | ); |
---|
| 268 | |
---|
[1058] | 269 | if ($is_remote) |
---|
| 270 | { |
---|
[2273] | 271 | $tpl_var['remote'] = |
---|
[1058] | 272 | array( |
---|
| 273 | 'U_TEST' => $base_url.'test', |
---|
[1775] | 274 | 'U_GENERATE' => $row['galleries_url'].'create_listing_file.php?action=generate', |
---|
| 275 | 'U_CLEAN' => $base_url.'clean', |
---|
[2273] | 276 | ); |
---|
[1058] | 277 | } |
---|
| 278 | |
---|
[1107] | 279 | if ($row['id'] != 1) |
---|
| 280 | { |
---|
[2273] | 281 | $tpl_var['U_DELETE'] = $base_url.'delete'; |
---|
[1107] | 282 | } |
---|
| 283 | |
---|
[2273] | 284 | $plugin_links = array(); |
---|
| 285 | //$plugin_links is array of array composed of U_HREF, U_HINT & U_CAPTION |
---|
| 286 | $plugin_links = |
---|
| 287 | trigger_event('get_admins_site_links', |
---|
| 288 | $plugin_links, $row['id'], $is_remote); |
---|
| 289 | $tpl_var['plugin_links'] = $plugin_links; |
---|
| 290 | |
---|
| 291 | $template->append('sites', $tpl_var); |
---|
| 292 | |
---|
[1107] | 293 | if ( isset($local_listing_site_url) and |
---|
| 294 | $row['galleries_url']==$local_listing_site_url ) |
---|
| 295 | { |
---|
| 296 | $local_listing_site_id = $row['id']; |
---|
[2273] | 297 | $template->assign( 'local_listing', |
---|
[1107] | 298 | array( |
---|
| 299 | 'URL' => $local_listing_site_url, |
---|
[2273] | 300 | 'U_SYNCHRONIZE' => $update_url.'&local_listing=1' |
---|
[1107] | 301 | ) |
---|
| 302 | ); |
---|
| 303 | } |
---|
[1058] | 304 | } |
---|
| 305 | |
---|
[1107] | 306 | if ( isset($local_listing_site_url) and !isset($local_listing_site_id) ) |
---|
| 307 | { |
---|
[2273] | 308 | $template->assign( 'local_listing', |
---|
[1107] | 309 | array( |
---|
| 310 | 'URL' => $local_listing_site_url, |
---|
[2273] | 311 | 'CREATE' => true |
---|
[1107] | 312 | ) |
---|
| 313 | ); |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | |
---|
[1058] | 317 | $template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager'); |
---|
[1775] | 318 | ?> |
---|