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)

Location:
extensions/flickr2piwigo/admin
Files:
5 edited

Legend:

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

    r16063 r16071  
    77    'api_key' => trim($_POST['api_key']),
    88    'secret_key' => trim($_POST['secret_key']),
    9     'username' => trim($_POST['username']),
    109    );
    1110  unset($_SESSION['phpFlickr_auth_token']);
     
    1413
    1514
    16 $template->assign('flickr2piwigo', $conf['flickr2piwigo']);
    17 
    1815$template->assign(array(
     16  'flickr2piwigo' => $conf['flickr2piwigo'],
    1917  'FLICKR_HELP_CONTENT' => load_language('help_api_key.html', FLICKR_PATH, array('return'=>true)),
    20   'FLICKR_CALLBACK' => get_absolute_root_url().FLICKR_ADMIN.'-import',
     18  'FLICKR_CALLBACK' => get_absolute_root_url() . FLICKR_ADMIN . '-import',
    2119  ));
    2220
    2321
    24 $template->set_filename('flickr2piwigo', dirname(__FILE__).'/template/config.tpl');
    25 
     22$template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/config.tpl');
    2623
    2724?>
  • 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?>
  • extensions/flickr2piwigo/admin/template/config.tpl

    r16063 r16071  
    2323      </label>
    2424    </li>
    25 
    26     <li>
    27       <label>
    28         <span class="property">{'Username'|@translate}</span>
    29         <input type="text" name="username" value="{$flickr2piwigo.username}" size="20"></label>
    30       </label>
    31     </li>
    3225  </ul>
    3326</fieldset>
  • extensions/flickr2piwigo/admin/template/import.list_photos.tpl

    r16063 r16071  
    330330  /* pagination loader */
    331331  jQuery('#navigation a').click(function() {
    332     $("#loader_display").fadeIn()
     332    $("#loader_display").fadeIn();
    333333  });
    334334});
  • extensions/flickr2piwigo/admin/template/import.tpl

    r16064 r16071  
    55</div>
    66
     7{* <!-- LOGIN --> *}
    78{if $ACTION == 'init_login'}
    89<p><input type="submit" onClick="javascript:window.location.href ='{$flickr_login}';" value="{'Login'|@translate}"></p>
    910
     11{* <!-- MAIN MENU --> *}
    1012{elseif $ACTION == 'main'}
     13{footer_script}{literal}
     14jQuery('input[type="submit"]').click(function() {
     15  window.location.href = $(this).attr("data");
     16});
     17jQuery('.load').click(function() {
     18  $("#loader_import").fadeIn();
     19});
     20{/literal}{/footer_script}
     21
    1122<p>
    1223  <b>{'Logued as'|@translate}</b> : <a href="{$profile_url}" target="_blank">{$username}</a><br><br>
    13   <input type="submit" onClick="javascript:window.location.href ='{$logout_url}';" value="{'Logout'|@translate}">
     24  <input type="submit" data="{$logout_url}" value="{'Logout'|@translate}">
    1425</p>
    1526<br>
    1627<p>
    17   <input type="submit" onClick="javascript:window.location.href ='{$list_albums_url}';" value="{'List my albums'|@translate}">
    18   <input type="submit" onClick="javascript:window.location.href ='{$import_all_url}';" value="{'Import all my pictures'|@translate}">
     28  <input type="submit" data="{$list_albums_url}" class="load" value="{'List my albums'|@translate}">
     29  <input type="submit" data="{$import_all_url}" class="load" value="{'Import all my pictures'|@translate}">
     30  <br>
     31  <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i></span>
    1932</p>
    2033
     34{* <!-- ALBUMS LIST --> *}
    2135{elseif $ACTION == 'list_albums'}
     36{footer_script}{literal}
     37jQuery('.load').click(function() {
     38  $("#loader_import").fadeIn();
     39});
     40{/literal}{/footer_script}
     41
    2242<h3>{'%d albums'|@translate|@sprintf:$total_albums}</h3>
    2343<ul id="albumsList">
    2444{foreach from=$albums item=album}
    2545  <li {if $album.id == "not_in_set"}class="not_in_set"{/if}>
    26     <b><a href="{$album.U_LIST}">{$album.title}</a></b> <i>{'(%d photos)'|@translate|@sprintf:$album.photos}</i> {if $album.description}- {$album.description|@truncate:100}{/if}
    27     {*- <a href="{$album.U_IMPORT_ALL}">{'Import all pictures of this album'|@translate}</a>*}
     46    <b><a href="{$album.U_LIST}" class="load">{$album.title}</a></b> <i>{'(%d photos)'|@translate|@sprintf:$album.photos}</i>
     47    {if $album.description}- {$album.description|@truncate:100}{/if}
    2848  </li>
    2949{/foreach}
    3050</ul>
     51<span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i></span>
    3152
     53{* <!-- PHOTOS LIST --> *}
    3254{elseif $ACTION == 'list_photos'}
    3355{include file=$FLICKR_ABS_PATH|@cat:'admin/template/import.list_photos.tpl'}
    3456
     57{* <!-- IMPORT ALL --> *}
    3558{elseif $ACTION == 'list_all'}
    3659{include file=$FLICKR_ABS_PATH|@cat:'admin/template/import.list_all.tpl'}
Note: See TracChangeset for help on using the changeset viewer.