Changeset 26180 for extensions/flickr2piwigo/admin/import.php
- Timestamp:
- Dec 24, 2013, 6:23:13 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/flickr2piwigo/admin/import.php
r25789 r26180 1 1 <?php 2 if (!defined('FLICKR_PATH'))die('Hacking attempt!');2 defined('FLICKR_PATH') or die('Hacking attempt!'); 3 3 4 4 set_time_limit(600); … … 7 7 8 8 // check API parameters and connect to flickr 9 if ( empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']))10 { 11 array_push($page['warnings'], l10n('Please fill your API keys on the configuration tab'));9 if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key'])) 10 { 11 $page['warnings'][] = l10n('Please fill your API keys on the configuration tab'); 12 12 $_GET['action'] = 'error'; 13 13 } 14 else if ( !test_remote_download())15 { 16 array_push($page['errors'], l10n('No download method available'));14 else if (!test_remote_download()) 15 { 16 $page['errors'][] = l10n('No download method available'); 17 17 $_GET['action'] = 'error'; 18 18 } … … 23 23 $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']); 24 24 $flickr->enableCache('fs', FLICKR_FS_CACHE); 25 25 26 26 // must authenticate 27 27 $u = $flickr->test_login(); … … 30 30 $_GET['action'] = 'init_login'; 31 31 } 32 32 33 33 // generate token after authentication 34 34 if (!empty($_GET['frob'])) 35 35 { 36 36 $flickr->auth_getToken($_GET['frob']); 37 $_GET['action'] = 'logued'; 38 } 39 } 40 41 42 if (!isset($_GET['action'])) $_GET['action'] = 'main'; 37 $_GET['action'] = 'logged'; 38 } 39 } 40 41 42 if (!isset($_GET['action'])) 43 { 44 $_GET['action'] = 'main'; 45 } 43 46 44 47 … … 51 54 break; 52 55 } 53 56 54 57 // call flickr login procedure 55 58 case 'login': … … 58 61 break; 59 62 } 60 63 61 64 // message after login 62 case 'log ued':65 case 'logged': 63 66 { 64 67 $_SESSION['page_infos'][] = l10n('Successfully logged in to you Flickr account'); … … 66 69 break; 67 70 } 68 71 69 72 // logout 70 73 case 'logout': … … 75 78 break; 76 79 } 77 80 78 81 // main menu 79 82 case 'main': … … 89 92 break; 90 93 } 91 94 92 95 // list user albums 93 96 case 'list_albums': … … 97 100 $total_albums = $albums['total']; 98 101 $albums = $albums['photoset']; 99 102 100 103 foreach ($albums as &$album) 101 104 { … … 103 106 } 104 107 unset($album); 105 108 106 109 // not classed 107 110 $wo_albums = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 1); 108 111 if ($wo_albums['photos']['total'] > 0) 109 112 { 110 array_push($albums,array(113 $albums[] = array( 111 114 'id' => 'not_in_set', 112 115 'title' => l10n('Pictures without album'), … … 114 117 'photos' => $wo_albums['photos']['total'], 115 118 'U_LIST' => FLICKR_ADMIN . '-import&action=list_photos&album=not_in_set', 116 ) );117 } 118 119 ); 120 } 121 119 122 $template->assign(array( 120 123 'total_albums' => $total_albums, … … 123 126 break; 124 127 } 125 128 126 129 // list photos of an album 127 130 case 'list_photos': … … 130 133 $flickr_prefix = 'flickr-'.$u['username'].'-'; 131 134 $flickr_root_url = $flickr->urls_getUserPhotos($u['id']); 132 135 133 136 // pagination 134 137 if (isset($_GET['start'])) $page['start'] = intval($_GET['start']); … … 136 139 if (isset($_GET['display'])) $page['display'] = $_GET['display']=='all' ? 500 : intval($_GET['display']); 137 140 else $page['display'] = 20; 138 141 139 142 // get photos 140 143 if ($_GET['album'] == 'not_in_set') … … 148 151 $all_photos = $all_photos['photoset']['photo']; 149 152 } 150 153 151 154 // get existing photos 152 155 $query = ' … … 157 160 $existing_photos = simple_hash_from_query($query, 'id', 'file'); 158 161 $existing_photos = array_map(create_function('$p', 'return preg_replace("#^'.$flickr_prefix.'([0-9]+)\.([a-z]{3,4})$#i", "$1", $p);'), $existing_photos); 159 162 160 163 // remove existing photos 161 164 $duplicates = 0; … … 168 171 } 169 172 } 170 173 171 174 if ($duplicates>0) 172 175 { 173 $page['infos'][] = '<a href="admin.php?page=batch_manager&prefilter=flickr">' 174 .l10n_dec('One picture is not displayed because already existing in the database.', '%d pictures are not displayed because already existing in the database.', $duplicates) 176 $page['infos'][] = '<a href="admin.php?page=batch_manager&filter=prefilter-flickr">' 177 .l10n_dec( 178 'One picture is not displayed because already existing in the database.', 179 '%d pictures are not displayed because already existing in the database.', 180 $duplicates) 175 181 .'</a>'; 176 182 } 177 183 178 184 // displayed photos 179 185 $page_photos = array_slice($all_photos, $page['start'], $page['display']); 180 186 $all_elements = array_map(create_function('$p', 'return \'"\'.$p["id"].\'"\';'), $all_photos); 181 187 182 188 foreach ($page_photos as &$photo) 183 189 { … … 187 193 } 188 194 unset($photo); 189 195 190 196 $template->assign(array( 191 197 'nb_thumbs_set' => count($all_photos), … … 197 203 'U_DISPLAY' => $self_url, 198 204 )); 199 205 200 206 // get piwigo categories 201 207 $query = ' … … 204 210 ;'; 205 211 display_select_cat_wrapper($query, array(), 'category_parent_options'); 206 212 207 213 // get navbar 208 214 $nav_bar = create_navigation_bar( … … 215 221 break; 216 222 } 217 223 218 224 // list all photos of the user 219 225 case 'list_all': 220 226 { 221 227 $flickr_prefix = 'flickr-'.$u['username'].'-'; 222 228 223 229 // get all photos in all albums 224 230 $all_albums = $flickr->photosets_getList($u['id']); 225 231 $all_albums = $all_albums['photoset']; 226 232 227 233 $all_photos = array(); 228 234 foreach ($all_albums as $album) … … 230 236 $album_photos = $flickr->photosets_getPhotos($album['id'], NULL, NULL, 500, NULL, 'photos'); 231 237 $album_photos = $album_photos['photoset']['photo']; 232 238 233 239 foreach ($album_photos as $photo) 234 240 { … … 236 242 } 237 243 } 238 244 239 245 // get existing photos 240 246 $query = ' … … 245 251 $existing_photos = simple_hash_from_query($query, 'id', 'file'); 246 252 $existing_photos = array_map(create_function('$p', 'return preg_replace("#^'.$flickr_prefix.'([0-9]+)\.([a-z]{3,4})$#i", "$1", $p);'), $existing_photos); 247 253 248 254 // remove existing photos 249 255 $duplicates = 0; … … 265 271 unset($photo); 266 272 $all_photos = array_values($all_photos); 267 273 268 274 if ($duplicates>0) 269 275 { 270 $page['infos'][] = '<a href="admin.php?page=batch_manager&prefilter=flickr">' 271 .l10n_dec('%d picture is not displayed because already existing in the database.', '%d pictures are not displayed because already existing in the database.', $duplicates) 276 $page['infos'][] = '<a href="admin.php?page=batch_manager&filter=prefilter-flickr">' 277 .l10n_dec( 278 'One picture is not displayed because already existing in the database.', 279 '%d pictures are not displayed because already existing in the database.', 280 $duplicates) 272 281 .'</a>'; 273 282 } 274 283 275 284 $template->assign(array( 276 285 'nb_elements' => count($all_photos), 277 'all_elements' => json_encode($all_photos),286 'all_elements' => $all_photos, 278 287 'F_ACTION' => FLICKR_ADMIN . '-import&action=import_set', 279 288 )); 280 289 281 290 // get piwigo categories 282 291 $query = ' … … 287 296 break; 288 297 } 289 298 290 299 // success message after import 291 300 case 'import_set': … … 293 302 if (isset($_POST['done'])) 294 303 { 295 $_SESSION['page_infos'][] = sprintf(l10n('%d pictures imported'), $_POST['done']);304 $_SESSION['page_infos'][] = l10n('%d pictures imported', $_POST['done']); 296 305 } 297 306 redirect(FLICKR_ADMIN . '-import'); … … 300 309 301 310 302 $template->assign(array( 303 'ACTION' => $_GET['action'], 304 'GMAPS_LOADED' => !empty($pwg_loaded_plugins['rv_gmaps']) || !empty($pwg_loaded_plugins['piwigo-openstreetmap']), 305 )); 306 307 $template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/import.tpl'); 308 309 ?> 311 $template->assign('ACTION', $_GET['action']); 312 313 $template->set_filename('flickr2piwigo', realpath(FLICKR_PATH . 'admin/template/import.tpl'));
Note: See TracChangeset
for help on using the changeset viewer.