Ignore:
Timestamp:
Dec 24, 2013, 6:23:13 PM (10 years ago)
Author:
mistic100
Message:

update for piwigo 2.6

File:
1 edited

Legend:

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

    r25789 r26180  
    11<?php
    2 if (!defined('FLICKR_PATH')) die('Hacking attempt!');
     2defined('FLICKR_PATH') or die('Hacking attempt!');
    33
    44set_time_limit(600);
     
    77
    88// 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'));
     9if (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');
    1212  $_GET['action'] = 'error';
    1313}
    14 else if ( !test_remote_download() )
    15 {
    16   array_push($page['errors'], l10n('No download method available'));
     14else if (!test_remote_download())
     15{
     16  $page['errors'][] = l10n('No download method available');
    1717  $_GET['action'] = 'error';
    1818}
     
    2323  $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']);
    2424  $flickr->enableCache('fs', FLICKR_FS_CACHE);
    25  
     25
    2626  // must authenticate
    2727  $u = $flickr->test_login();
     
    3030    $_GET['action'] = 'init_login';
    3131  }
    32  
     32
    3333  // generate token after authentication
    3434  if (!empty($_GET['frob']))
    3535  {
    3636    $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
     42if (!isset($_GET['action']))
     43{
     44  $_GET['action'] = 'main';
     45}
    4346
    4447
     
    5154    break;
    5255  }
    53  
     56
    5457  // call flickr login procedure
    5558  case 'login':
     
    5861    break;
    5962  }
    60  
     63
    6164  // message after login
    62   case 'logued':
     65  case 'logged':
    6366  {
    6467    $_SESSION['page_infos'][] = l10n('Successfully logged in to you Flickr account');
     
    6669    break;
    6770  }
    68  
     71
    6972  // logout
    7073  case 'logout':
     
    7578    break;
    7679  }
    77  
     80
    7881  // main menu
    7982  case 'main':
     
    8992    break;
    9093  }
    91  
     94
    9295  // list user albums
    9396  case 'list_albums':
     
    97100    $total_albums = $albums['total'];
    98101    $albums = $albums['photoset'];
    99    
     102
    100103    foreach ($albums as &$album)
    101104    {
     
    103106    }
    104107    unset($album);
    105    
     108
    106109    // not classed
    107110    $wo_albums = $flickr->photos_getNotInSet(NULL, NULL, NULL, NULL, 'photos', NULL, NULL, 1);
    108111    if ($wo_albums['photos']['total'] > 0)
    109112    {
    110       array_push($albums, array(
     113      $albums[] = array(
    111114        'id' => 'not_in_set',
    112115        'title' => l10n('Pictures without album'),
     
    114117        'photos' => $wo_albums['photos']['total'],
    115118        'U_LIST' => FLICKR_ADMIN . '-import&amp;action=list_photos&amp;album=not_in_set',
    116         ));
    117     }
    118    
     119        );
     120    }
     121
    119122    $template->assign(array(
    120123      'total_albums' => $total_albums,
     
    123126    break;
    124127  }
    125  
     128
    126129  // list photos of an album
    127130  case 'list_photos':
     
    130133    $flickr_prefix = 'flickr-'.$u['username'].'-';
    131134    $flickr_root_url = $flickr->urls_getUserPhotos($u['id']);
    132    
     135
    133136    // pagination
    134137    if (isset($_GET['start']))   $page['start'] = intval($_GET['start']);
     
    136139    if (isset($_GET['display'])) $page['display'] = $_GET['display']=='all' ? 500 : intval($_GET['display']);
    137140    else                         $page['display'] = 20;
    138    
     141
    139142    // get photos
    140143    if ($_GET['album'] == 'not_in_set')
     
    148151      $all_photos = $all_photos['photoset']['photo'];
    149152    }
    150    
     153
    151154    // get existing photos
    152155    $query = '
     
    157160    $existing_photos = simple_hash_from_query($query, 'id', 'file');
    158161    $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
    160163    // remove existing photos
    161164    $duplicates = 0;
     
    168171      }
    169172    }
    170    
     173
    171174    if ($duplicates>0)
    172175    {
    173       $page['infos'][] = '<a href="admin.php?page=batch_manager&amp;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&amp;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)
    175181        .'</a>';
    176182    }
    177    
     183
    178184    // displayed photos
    179185    $page_photos = array_slice($all_photos, $page['start'], $page['display']);
    180186    $all_elements = array_map(create_function('$p', 'return  \'"\'.$p["id"].\'"\';'), $all_photos);
    181    
     187
    182188    foreach ($page_photos as &$photo)
    183189    {
     
    187193    }
    188194    unset($photo);
    189    
     195
    190196    $template->assign(array(
    191197      'nb_thumbs_set' => count($all_photos),
     
    197203      'U_DISPLAY' => $self_url,
    198204      ));
    199      
     205
    200206    // get piwigo categories
    201207    $query = '
     
    204210;';
    205211    display_select_cat_wrapper($query, array(), 'category_parent_options');
    206    
     212
    207213    // get navbar
    208214    $nav_bar = create_navigation_bar(
     
    215221    break;
    216222  }
    217  
     223
    218224  // list all photos of the user
    219225  case 'list_all':
    220226  {
    221227    $flickr_prefix = 'flickr-'.$u['username'].'-';
    222    
     228
    223229    // get all photos in all albums
    224230    $all_albums = $flickr->photosets_getList($u['id']);
    225231    $all_albums = $all_albums['photoset'];
    226    
     232
    227233    $all_photos = array();
    228234    foreach ($all_albums as $album)
     
    230236      $album_photos = $flickr->photosets_getPhotos($album['id'], NULL, NULL, 500, NULL, 'photos');
    231237      $album_photos = $album_photos['photoset']['photo'];
    232      
     238
    233239      foreach ($album_photos as $photo)
    234240      {
     
    236242      }
    237243    }
    238    
     244
    239245    // get existing photos
    240246    $query = '
     
    245251    $existing_photos = simple_hash_from_query($query, 'id', 'file');
    246252    $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
    248254    // remove existing photos
    249255    $duplicates = 0;
     
    265271    unset($photo);
    266272    $all_photos = array_values($all_photos);
    267    
     273
    268274    if ($duplicates>0)
    269275    {
    270       $page['infos'][] = '<a href="admin.php?page=batch_manager&amp;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&amp;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)
    272281        .'</a>';
    273282    }
    274    
     283
    275284    $template->assign(array(
    276285      'nb_elements' => count($all_photos),
    277       'all_elements' => json_encode($all_photos),
     286      'all_elements' => $all_photos,
    278287      'F_ACTION' => FLICKR_ADMIN . '-import&amp;action=import_set',
    279288      ));
    280      
     289
    281290    // get piwigo categories
    282291    $query = '
     
    287296    break;
    288297  }
    289  
     298
    290299  // success message after import
    291300  case 'import_set':
     
    293302    if (isset($_POST['done']))
    294303    {
    295       $_SESSION['page_infos'][] = sprintf(l10n('%d pictures imported'), $_POST['done']);
     304      $_SESSION['page_infos'][] = l10n('%d pictures imported', $_POST['done']);
    296305    }
    297306    redirect(FLICKR_ADMIN . '-import');
     
    300309
    301310
    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.