Ignore:
Timestamp:
Jun 27, 2012, 1:53:21 AM (12 years ago)
Author:
mistic100
Message:

code cleanup, don't ask username anymore (prohibit importing photos from another account)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/flickr2piwigo/admin/import.php

    r16070 r16071  
    33
    44// check API parameters and connect to flickr
    5 if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']) or empty($conf['flickr2piwigo']['username']))
     5if ( empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']) )
    66{
    77  array_push($page['warnings'], l10n('Please fill your API keys on the configuration tab'));
     
    1616 
    1717  // must authenticate
    18   if (empty($_SESSION['phpFlickr_auth_token']) and @$_GET['action']!='login')
     18  $u = $flickr->test_login();
     19  if ( ($u === false or empty($_SESSION['phpFlickr_auth_token'])) and @$_GET['action']!='login' )
    1920  {
    2021    $_GET['action'] = 'init_login';
    2122  }
    22   else
    23   {
    24     // get user id
    25     $u = $flickr->people_findByUsername($conf['flickr2piwigo']['username']);
    26     if ($u === false)
    27     {
    28       array_push($page['errors'], l10n('Unknown username, please verify your configuration'));
    29       $_GET['action'] = 'error';
    30     }
    31   }
    32  
    3323 
    3424  // generate token after authentication
     
    4838  case 'init_login':
    4939  {
    50     $template->assign('flickr_login', FLICKR_ADMIN.'-import&action=login');
     40    $template->assign('flickr_login', FLICKR_ADMIN . '-import&action=login');
    5141    break;
    5242  }
     
    6353  {
    6454    $_SESSION['page_infos'][] = l10n('Successfully logued to you Flickr account');
    65     redirect(FLICKR_ADMIN.'-import');
     55    redirect(FLICKR_ADMIN . '-import');
    6656    break;
    6757  }
     
    7262    unset($_SESSION['phpFlickr_auth_token']);
    7363    $_SESSION['page_infos'][] = l10n('Logued out');
    74     redirect(FLICKR_ADMIN.'-import');
     64    redirect(FLICKR_ADMIN . '-import');
    7565    break;
    7666  }
     
    8171    $u = $flickr->people_getInfo($u['id']);
    8272    $template->assign(array(
    83       'username' => $conf['flickr2piwigo']['username'],
    84       'profile_url' => $u['photosurl'],
    85       'logout_url' => FLICKR_ADMIN.'-import&action=logout',
    86       'list_albums_url' => FLICKR_ADMIN.'-import&action=list_albums',
    87       'import_all_url' => FLICKR_ADMIN.'-import&action=list_all',
     73      'username' => $u['username'],
     74      'profile_url' => $u['profileurl'],
     75      'logout_url' => FLICKR_ADMIN . '-import&action=logout',
     76      'list_albums_url' => FLICKR_ADMIN . '-import&action=list_albums',
     77      'import_all_url' => FLICKR_ADMIN . '-import&action=list_all',
    8878      ));
    8979    break;
     
    10090    foreach ($albums as &$album)
    10191    {
    102       //$album['U_IMPORT_ALL'] = FLICKR_ADMIN.'-import&action=import_album&album='.$album['id'];
    103       $album['U_LIST'] = FLICKR_ADMIN.'-import&action=list_photos&album='.$album['id'];
     92      $album['U_LIST'] = FLICKR_ADMIN . '-import&action=list_photos&album='.$album['id'];
    10493    }
    10594    unset($album);
     
    114103        'description' => null,
    115104        'photos' => $wo_albums['photos']['total'],
    116         //'U_IMPORT_ALL' => FLICKR_ADMIN.'-import&action=import_album&album='.$album['id'],
    117         'U_LIST' => FLICKR_ADMIN.'-import&action=list_photos&album=not_in_set',
     105        'U_LIST' => FLICKR_ADMIN . '-import&action=list_photos&album=not_in_set',
    118106        ));
    119107    }
     
    129117  case 'list_photos':
    130118  {
     119    $self_url = FLICKR_ADMIN . '-import&action=list_photos&album='.$_GET['album'];
     120    $flickr_prefix = 'flickr-'.$u['username'].'-';
     121    $flickr_root_url = $flickr->urls_getUserPhotos($u['id']);
     122   
     123    // pagination
    131124    if (isset($_GET['start']))   $page['start'] = intval($_GET['start']);
    132125    else                         $page['start'] = 0;
     
    134127    else                         $page['display'] = 20;
    135128   
    136     $self_url = FLICKR_ADMIN.'-import&action=list_photos&album='.$_GET['album'];
    137     $flickr_prefix = 'flickr-'.$conf['flickr2piwigo']['username'].'-';
    138     $flickr_root_url = $flickr->urls_getUserPhotos($u['id']);
     129    // get photos
     130    if ($_GET['album'] == 'not_in_set')
     131    {
     132      $all_photos = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 500);
     133      $all_photos = $all_photos['photos']['photo'];
     134    }
     135    else
     136    {
     137      $all_photos = $flickr->photosets_getPhotos($_GET['album'], NULL, NULL, 500, NULL, 'photos');
     138      $all_photos = $all_photos['photoset']['photo'];
     139    }
    139140   
    140141    // get existing photos
     
    147148    $existing_photos = array_map(create_function('$p', '$p=preg_replace("#^'.$flickr_prefix.'([0-9]+)\.([a-z]{3,4})$#i", "$1", $p); return $p;'), $existing_photos);
    148149   
    149     // get photos
    150     if ($_GET['album'] == 'not_in_set')
    151     {
    152       $all_photos = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 500);
    153       $all_photos = $all_photos['photos']['photo'];
    154     }
    155     else
    156     {
    157       $all_photos = $flickr->photosets_getPhotos($_GET['album'], NULL, NULL, 500, NULL, 'photos');
    158       $all_photos = $all_photos['photoset']['photo'];
    159     }
    160    
    161     // remove existing
     150    // remove existing photos
    162151    $duplicates = 0;
    163152    foreach ($all_photos as $i => $photo)
     
    169158      }
    170159    }
     160   
    171161    if ($duplicates>0)
    172162    {
     
    214204    break;
    215205  }
    216    
     206 
     207  // list all photos of the user
    217208  case 'list_all':
    218209  {
    219     $flickr_prefix = 'flickr-'.$conf['flickr2piwigo']['username'].'-';
     210    $flickr_prefix = 'flickr-'.$u['username'].'-';
    220211   
    221212    // get all photos in all albums
     
    246237    $existing_photos = array_map(create_function('$p', '$p=preg_replace("#^'.$flickr_prefix.'([0-9]+)\.([a-z]{3,4})$#i", "$1", $p); return $p;'), $existing_photos);
    247238   
    248     // remove duplicates
     239    // remove existing photos
    249240    $duplicates = 0;
    250241    foreach ($all_photos as $id => &$photo)
     
    264255    }
    265256    unset($photo);
     257    $all_photos = array_values($all_photos);
     258   
    266259    if ($duplicates>0)
    267260    {
    268261      array_push($page['infos'], 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));
    269262    }
    270     $all_photos = array_values($all_photos);
    271263   
    272264    $template->assign(array(
    273265      'nb_elements' => count($all_photos),
    274266      'all_elements' => json_encode($all_photos),
    275       'F_ACTION' => FLICKR_ADMIN.'-import&action=import_set',
     267      'F_ACTION' => FLICKR_ADMIN . '-import&action=import_set',
    276268      ));
    277269     
     
    293285      $_SESSION['page_infos'][] = sprintf(l10n('%d pictures imported'), $_POST['done']);
    294286    }
    295     redirect(FLICKR_ADMIN.'-import');
     287    redirect(FLICKR_ADMIN . '-import');
    296288  }
    297289}
    298290
     291
    299292$template->assign('ACTION', $_GET['action']);
    300293
    301 $template->set_filename('flickr2piwigo', dirname(__FILE__).'/template/import.tpl');
     294$template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/import.tpl');
    302295
    303296?>
Note: See TracChangeset for help on using the changeset viewer.