[1058] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[26461] | 5 | // | Copyright(C) 2008-2014 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 | // +-----------------------------------------------------------------------+ |
---|
[22979] | 34 | |
---|
| 35 | if (!$conf['enable_synchronization']) |
---|
| 36 | { |
---|
| 37 | die('synchronization is disabled'); |
---|
| 38 | } |
---|
| 39 | |
---|
[1072] | 40 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 41 | |
---|
[5195] | 42 | if (!empty($_POST) or isset($_GET['action'])) |
---|
| 43 | { |
---|
| 44 | check_pwg_token(); |
---|
| 45 | } |
---|
| 46 | |
---|
[1058] | 47 | // +-----------------------------------------------------------------------+ |
---|
| 48 | // | template init | |
---|
| 49 | // +-----------------------------------------------------------------------+ |
---|
[2530] | 50 | $template->set_filenames(array('site_manager'=>'site_manager.tpl')); |
---|
[1058] | 51 | |
---|
| 52 | // +-----------------------------------------------------------------------+ |
---|
| 53 | // | new site creation form | |
---|
| 54 | // +-----------------------------------------------------------------------+ |
---|
[8126] | 55 | if (isset($_POST['submit']) and !empty($_POST['galleries_url'])) |
---|
[1058] | 56 | { |
---|
| 57 | $is_remote = url_is_remote( $_POST['galleries_url'] ); |
---|
[13488] | 58 | if ($is_remote) |
---|
| 59 | { |
---|
| 60 | fatal_error('remote sites not supported'); |
---|
| 61 | } |
---|
[1058] | 62 | $url = preg_replace('/[\/]*$/', '', $_POST['galleries_url']); |
---|
| 63 | $url.= '/'; |
---|
[13488] | 64 | if ( ! (strpos($url, '.') === 0 ) ) |
---|
[1058] | 65 | { |
---|
[13488] | 66 | $url = './' . $url; |
---|
[1058] | 67 | } |
---|
| 68 | |
---|
| 69 | // site must not exists |
---|
| 70 | $query = ' |
---|
| 71 | SELECT COUNT(id) AS count |
---|
| 72 | FROM '.SITES_TABLE.' |
---|
| 73 | WHERE galleries_url = \''.$url.'\' |
---|
| 74 | ;'; |
---|
[4325] | 75 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[1058] | 76 | if ($row['count'] > 0) |
---|
| 77 | { |
---|
[25018] | 78 | $page['errors'][] = l10n('This site already exists').' ['.$url.']'; |
---|
[1058] | 79 | } |
---|
| 80 | if (count($page['errors']) == 0) |
---|
| 81 | { |
---|
[13488] | 82 | if ( ! file_exists($url) ) |
---|
[1058] | 83 | { |
---|
[25018] | 84 | $page['errors'][] = l10n('Directory does not exist').' ['.$url.']'; |
---|
[1058] | 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if (count($page['errors']) == 0) |
---|
| 89 | { |
---|
| 90 | $query = ' |
---|
| 91 | INSERT INTO '.SITES_TABLE.' |
---|
| 92 | (galleries_url) |
---|
| 93 | VALUES |
---|
| 94 | (\''.$url.'\') |
---|
| 95 | ;'; |
---|
| 96 | pwg_query($query); |
---|
[25018] | 97 | $page['infos'][] = $url.' '.l10n('created'); |
---|
[1058] | 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | // +-----------------------------------------------------------------------+ |
---|
| 102 | // | actions on site | |
---|
| 103 | // +-----------------------------------------------------------------------+ |
---|
| 104 | if (isset($_GET['site']) and is_numeric($_GET['site'])) |
---|
| 105 | { |
---|
| 106 | $page['site'] = $_GET['site']; |
---|
| 107 | } |
---|
[8126] | 108 | if (isset($_GET['action']) and isset($page['site'])) |
---|
[1058] | 109 | { |
---|
| 110 | $query = ' |
---|
| 111 | SELECT galleries_url |
---|
| 112 | FROM '.SITES_TABLE.' |
---|
| 113 | WHERE id = '.$page['site'].' |
---|
| 114 | ;'; |
---|
[4325] | 115 | list($galleries_url) = pwg_db_fetch_row(pwg_query($query)); |
---|
[1058] | 116 | switch($_GET['action']) |
---|
| 117 | { |
---|
| 118 | case 'delete' : |
---|
| 119 | { |
---|
| 120 | delete_site($page['site']); |
---|
[25018] | 121 | $page['infos'][] = $galleries_url.' '.l10n('deleted'); |
---|
[1058] | 122 | break; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
[5195] | 127 | $template->assign( |
---|
| 128 | array( |
---|
| 129 | 'F_ACTION' => get_root_url().'admin.php'.get_query_string_diff(array('action','site','pwg_token')), |
---|
| 130 | 'PWG_TOKEN' => get_pwg_token(), |
---|
| 131 | ) |
---|
| 132 | ); |
---|
[1058] | 133 | |
---|
| 134 | $query = ' |
---|
[2324] | 135 | SELECT c.site_id, COUNT(DISTINCT c.id) AS nb_categories, COUNT(i.id) AS nb_images |
---|
| 136 | FROM '.CATEGORIES_TABLE.' AS c LEFT JOIN '.IMAGES_TABLE.' AS i |
---|
| 137 | ON c.id=i.storage_category_id |
---|
| 138 | WHERE c.site_id IS NOT NULL |
---|
| 139 | GROUP BY c.site_id |
---|
| 140 | ;'; |
---|
| 141 | $sites_detail = hash_from_query($query, 'site_id'); |
---|
| 142 | |
---|
| 143 | $query = ' |
---|
| 144 | SELECT * |
---|
| 145 | FROM '.SITES_TABLE.' |
---|
| 146 | ;'; |
---|
[1058] | 147 | $result = pwg_query($query); |
---|
| 148 | |
---|
[4325] | 149 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1058] | 150 | { |
---|
| 151 | $is_remote = url_is_remote($row['galleries_url']); |
---|
| 152 | $base_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 153 | $base_url.= '?page=site_manager'; |
---|
| 154 | $base_url.= '&site='.$row['id']; |
---|
[5195] | 155 | $base_url.= '&pwg_token='.get_pwg_token(); |
---|
[1058] | 156 | $base_url.= '&action='; |
---|
| 157 | |
---|
| 158 | $update_url = PHPWG_ROOT_PATH.'admin.php'; |
---|
| 159 | $update_url.= '?page=site_update'; |
---|
| 160 | $update_url.= '&site='.$row['id']; |
---|
[2273] | 161 | |
---|
| 162 | $tpl_var = |
---|
[1058] | 163 | array( |
---|
| 164 | 'NAME' => $row['galleries_url'], |
---|
[5036] | 165 | 'TYPE' => l10n( $is_remote ? 'Remote' : 'Local' ), |
---|
[2324] | 166 | 'CATEGORIES' => (int)@$sites_detail[$row['id']]['nb_categories'], |
---|
| 167 | 'IMAGES' => (int)@$sites_detail[$row['id']]['nb_images'], |
---|
[1058] | 168 | 'U_SYNCHRONIZE' => $update_url |
---|
[2273] | 169 | ); |
---|
| 170 | |
---|
[1107] | 171 | if ($row['id'] != 1) |
---|
| 172 | { |
---|
[2273] | 173 | $tpl_var['U_DELETE'] = $base_url.'delete'; |
---|
[1107] | 174 | } |
---|
| 175 | |
---|
[2273] | 176 | $plugin_links = array(); |
---|
| 177 | //$plugin_links is array of array composed of U_HREF, U_HINT & U_CAPTION |
---|
| 178 | $plugin_links = |
---|
| 179 | trigger_event('get_admins_site_links', |
---|
| 180 | $plugin_links, $row['id'], $is_remote); |
---|
| 181 | $tpl_var['plugin_links'] = $plugin_links; |
---|
| 182 | |
---|
| 183 | $template->append('sites', $tpl_var); |
---|
[1058] | 184 | } |
---|
| 185 | |
---|
| 186 | $template->assign_var_from_handle('ADMIN_CONTENT', 'site_manager'); |
---|
[1775] | 187 | ?> |
---|