Changeset 26180


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

update for piwigo 2.6

Location:
extensions/flickr2piwigo
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • extensions/flickr2piwigo/admin.php

    r16070 r26180  
    11<?php
    2 if (!defined('FLICKR_PATH')) die('Hacking attempt!');
     2defined('FLICKR_PATH') or die('Hacking attempt!');
    33
    44global $template, $page, $conf;
    55
    6 $conf['flickr2piwigo'] = unserialize($conf['flickr2piwigo']);
    76load_language('plugin.lang', FLICKR_PATH);
    87
     
    1514include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
    1615$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'import';
    17  
     16
    1817$tabsheet = new tabsheet();
    1918$tabsheet->add('import', l10n('Import'), FLICKR_ADMIN . '-import');
     
    3130  'FLICKR_ADMIN' => FLICKR_ADMIN,
    3231  ));
     32
    3333$template->assign_var_from_handle('ADMIN_CONTENT', 'flickr2piwigo');
    34 
    35 ?>
  • extensions/flickr2piwigo/admin/config.php

    r24815 r26180  
    11<?php
    2 if (!defined('FLICKR_PATH')) die('Hacking attempt!');
     2defined('FLICKR_PATH') or die('Hacking attempt!');
    33
    44if (isset($_POST['save_config']))
     
    2121
    2222
    23 $template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/config.tpl');
    24 
    25 ?>
     23$template->set_filename('flickr2piwigo', realpath(FLICKR_PATH . 'admin/template/config.tpl'));
  • 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'));
  • extensions/flickr2piwigo/admin/template/config.tpl

    r16071 r26180  
    1 {combine_css path=$FLICKR_PATH|@cat:"admin/template/style.css"}
     1{combine_css path=$FLICKR_PATH|cat:'admin/template/style.css'}
    22
    33<div class="titrePage">
     
    77<form method="post" action="" class="properties">
    88<fieldset>
    9   <legend>{'Flickr logins'|@translate}</legend>
    10  
     9  <legend>{'Flickr logins'|translate}</legend>
     10
    1111  <ul>
    1212    <li>
    1313      <label>
    14         <span class="property">{'API key'|@translate}</span>
     14        <span class="property">{'API key'|translate}</span>
    1515        <input type="text" name="api_key" value="{$flickr2piwigo.api_key}" size="40">
    1616      </label>
     
    1919    <li>
    2020      <label>
    21         <span class="property">{'API secret'|@translate}</span>
     21        <span class="property">{'API secret'|translate}</span>
    2222        <input type="text" name="secret_key" value="{$flickr2piwigo.secret_key}" size="20">
    2323      </label>
     
    2626</fieldset>
    2727
    28 <p><input type="submit" name="save_config" value="{'Save Settings'|@translate}"></p>
     28<p><input type="submit" name="save_config" value="{'Save Settings'|translate}"></p>
    2929
    3030<fieldset>
    31   <legend>{'How do I get my Flickr API key?'|@translate}</legend>
    32  
    33   <p><b>{'Callback URL'|@translate} :</b> <span style="font-family:monospace;font-size:14px;">{$FLICKR_CALLBACK}</span></p>
     31  <legend>{'How do I get my Flickr API key?'|translate}</legend>
     32
     33  <p><b>{'Callback URL'|translate} :</b> <span style="font-family:monospace;font-size:14px;">{$FLICKR_CALLBACK}</span></p>
    3434  {$FLICKR_HELP_CONTENT}
    3535</fieldset>
    36  
     36
    3737</form>
  • extensions/flickr2piwigo/admin/template/import.list_all.tpl

    r25789 r26180  
    11{footer_script require='jquery.ajaxmanager,jquery.jgrowl'}
    2 /* global vars */
    3 var errorHead   = '{'ERROR'|@translate|@escape:'javascript'}';
    4 var errorMsg    = '{'an error happened'|@translate|@escape:'javascript'}';
    5 var successHead = '{'Success'|@translate|@escape:'javascript'}';
     2(function($){
     3  /* global vars */
     4  var all_elements = [{if !empty($all_elements)}{','|@implode:$all_elements}{/if}];
     5  var import_done = 0;
     6  var import_selected = {$nb_elements};
     7  var queuedManager = $.manageAjax.create('queued', {
     8    queue: true,
     9    maxRequests: 1
     10  });
    611
    7 var import_done = 0;
    8 var import_selected = {$nb_elements};
    9 var queuedManager = jQuery.manageAjax.create('queued', {ldelim}
    10   queue: true, 
    11   maxRequests: 1
    12 });
     12  /* import queue */
     13  function performImport(photo, album, fills) {
     14    queuedManager.add({
     15      type: 'GET',
     16      dataType: 'json',
     17      url: 'ws.php',
     18      data: {
     19        method: 'pwg.images.addFlickr',
     20        id: photo,
     21        category: album,
     22        fills: fills,
     23        format: 'json'
     24      },
     25      success: function(data) {
     26        if (data['stat'] == 'ok') {
     27          $.jGrowl(data['result'], {
     28            theme: 'success', life: 4000, sticky: false,
     29            header: '{'Success'|translate}',
     30          });
     31          $("#photo-"+photo.id).fadeOut(function(){ $(this).remove(); });
     32        }
     33        else {
     34          $.jGrowl(data['result'], {
     35            theme: 'error', sticky: true,
     36            header: '{'ERROR'|translate}'
     37          });
     38        }
    1339
    14 {literal}
    15 /* import queue */
    16 function performImport(photo, album, fills) {
    17   queuedManager.add({
    18     type: 'GET',
    19     dataType: 'json',
    20     url: 'ws.php',
    21     data: { method: 'pwg.images.addFlickr', id: photo, category: album, fills: fills, format: 'json' },
    22     success: function(data) {
    23       if (data['stat'] == 'ok') {
    24         jQuery.jGrowl(data['result'], { theme: 'success', header: successHead, life: 4000, sticky: false });
    25         jQuery("#photo-"+photo.id).fadeOut(function(){ $(this).remove(); });
    26       } else {
    27         jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true });
     40        import_done++;
     41        $("#progress").html(import_done +"/"+ import_selected);
     42
     43        if (import_done == import_selected) {
     44          $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">');
     45          $("#import_form").submit();
     46        }
     47      },
     48      error: function(data) {
     49        $.jGrowl('{'an error happened'|translate|escape:'javascript'}', {
     50          theme: 'error', sticky: true,
     51          header: '{'ERROR'|translate}'
     52        });
    2853      }
    29      
    30       import_done++;
    31       $("#progress").html(import_done +"/"+ import_selected);
    32      
    33       if (import_done == import_selected) {
    34         $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">');
    35         $("#import_form").submit();
    36       }
    37     },
    38     error: function(data) {
    39       jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true });
    40     }
    41   });
    42 }
     54    });
     55  }
    4356
     57  /* begin import */
     58  $('#beginImport').click(function() {
     59    $("#loader_import").fadeIn();
    4460
    45 $(document).ready(function() {
    46   //var all_elements = jQuery.parseJSON('{/literal}{$all_elements}{literal}');
    47   var all_elements = {/literal}{$all_elements}{literal};
    48  
    49   /* begin import */
    50   jQuery('#beginImport').click(function() {
    51     $("#loader_import").fadeIn();
    52    
    5361    if ($("input[name='album_mode']:checked").val() == 'identical') {
    5462      var album = 0;
    55     } else {
     63    }
     64    else {
    5665      var album = $("#albumSelect option:selected").val();
    5766    }
    58    
     67
    5968    var fills = '';
    6069    $("input[name^='fill_']:checked").each(function() {
    6170      fills+= $(this).attr("name") +',';
    62     }); 
    63    
     71    });
     72
    6473    import_selected = all_elements.length;
    6574    $("#progress").html("0/"+ import_selected);
    66    
     75
    6776    for (var i in all_elements) {
    6877      if (album == 0) this_album = all_elements[i]['albums'];
    6978      else            this_album = album;
    70      
     79
    7180      performImport(all_elements[i]['id'], this_album, fills);
    7281    }
    73    
     82
    7483    return false;
    7584  });
    76  
     85
    7786  /* album mode */
    7887  $("input[name='album_mode']").change(function() {
    7988    if ($(this).val() == 'one_album') {
    8089      $("#albumSelectWrapper").slideDown();
    81     } else {
     90    }
     91    else {
    8292      $("#albumSelectWrapper").slideUp();
    8393    }
    8494  });
    85 });
    86 {/literal}
     95}(jQuery));
    8796{/footer_script}
     97
    8898
    8999<form action="{$F_ACTION}" method="post" id="import_form">
    90100
    91101  <fieldset>
    92     <legend>{'Selection'|@translate}</legend>
     102    <legend>{'Selection'|translate}</legend>
    93103
    94104  {if $nb_elements}
    95     {'%d elements ready for importation'|@translate|@sprintf:$nb_elements}
     105    {'%d elements ready for importation'|translate:$nb_elements}
    96106  {else}
    97     <div>{'No photo in the current set.'|@translate}</div>
     107    <div>{'No photo in the current set.'|translate}</div>
    98108  {/if}
    99109  </fieldset>
    100  
     110
    101111  <fieldset>
    102     <legend>{'Import options'|@translate}</legend>
    103    
     112    <legend>{'Import options'|translate}</legend>
     113
    104114    <p>
    105       <label><input type="radio" name="album_mode" value="identical" checked="checked"> {'Reproduce flickr albums'|@translate}</label><br>
    106       <label><input type="radio" name="album_mode" value="one_album"> {'Import all photos in this album'|@translate} :</label>
     115      <label><input type="radio" name="album_mode" value="identical" checked="checked"> {'Reproduce flickr albums'|translate}</label><br>
     116      <label><input type="radio" name="album_mode" value="one_album"> {'Import all photos in this album'|translate} :</label>
    107117    </p>
    108118
     
    111121        {html_options options=$category_parent_options}
    112122      </select>
    113       {'... or '|@translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>
     123      {'... or '|translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|translate}">{'create a new album'|translate}</a>
    114124    </p>
    115    
     125
    116126    <p>
    117       <b>{'Fill these fields from Flickr datas'|@translate}:</b>
    118       <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'|@translate}</label>
    119       <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'|@translate}</label>
    120       <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'|@translate}</label>
    121       <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'|@translate}</label>
    122       <label><input type="checkbox" name="fill_posted"> {'Post date'|@translate}</label>
     127      <b>{'Fill these fields from Flickr datas'|translate}:</b>
     128      <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'|translate}</label>
     129      <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'|translate}</label>
     130      <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'|translate}</label>
     131      <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'|translate}</label>
     132      <label><input type="checkbox" name="fill_posted"> {'Post date'|translate}</label>
    123133      <label><input type="checkbox" name="fill_description" checked="checked"> {'Description'|@translate}</label>
    124       {if $GMAPS_LOADED}<label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label>{/if}
     134      <label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label>
    125135    </p>
    126    
     136
    127137    <p>
    128       <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'|@translate}" {if not $nb_elements}style="display:none;"{/if}>
    129       <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i> <span id="progress"></span></span>
     138      <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'|translate}" {if not $nb_elements}style="display:none;"{/if}>
     139      <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i> <span id="progress"></span></span>
    130140    </p>
    131141  </fieldset>
  • extensions/flickr2piwigo/admin/template/import.list_photos.tpl

    r25789 r26180  
    11{footer_script require='jquery.ajaxmanager,jquery.jgrowl'}
    2 /* global vars */
    3 var nb_thumbs_page = {$nb_thumbs_page};
    4 var nb_thumbs_set = {$nb_thumbs_set};
    5 var all_elements = [{if !empty($all_elements)}{','|@implode:$all_elements}{/if}];
    6 
    7 var errorHead   = '{'ERROR'|@translate|@escape:'javascript'}';
    8 var errorMsg    = '{'an error happened'|@translate|@escape:'javascript'}';
    9 var successHead = '{'Success'|@translate|@escape:'javascript'}';
    10 var selectedMessage_pattern = "{'%d of %d photos selected'|@translate}";
    11 var selectedMessage_none = "{'No photo selected, %d photos in current set'|@translate}";
    12 var selectedMessage_all = "{'All %d photos are selected'|@translate}";
    13 var applyOnDetails_pattern = "{'on the %d selected photos'|@translate}";
    14 
    15 var import_done = 0;
    16 var import_selected = 0;
    17 var queuedManager = jQuery.manageAjax.create('queued', {ldelim}
    18   queue: true, 
    19   maxRequests: 1
    20 });
    21 
    22 {literal}
    23 /* Shift-click: select all photos between the click and the shift+click */
    24 jQuery(document).ready(function() {
     2(function($){
     3  /* global vars */
     4  var nb_thumbs_set = {$nb_thumbs_set};
     5  var all_elements = [{if !empty($all_elements)}{','|@implode:$all_elements}{/if}];
     6  var import_done = 0;
     7  var import_selected = 0;
     8  var queuedManager = $.manageAjax.create('queued', {ldelim}
     9    queue: true,
     10    maxRequests: 1
     11  });
     12
     13  /* Shift-click: select all photos between the click and the shift+click */
    2514  var last_clicked=0;
    2615  var last_clickedstatus=true;
    27   jQuery.fn.enableShiftClick = function() {
     16  $.fn.enableShiftClick = function() {
    2817    var inputs = [];
    2918    var count=0;
     
    4433            input = $(inputs[i]);
    4534            $(input).attr('checked', last_clickedstatus);
    46             if (last_clickedstatus)
    47             {
     35            if (last_clickedstatus) {
    4836              $(input).siblings("span.wrap2").addClass("thumbSelected");
    4937            }
    50             else
    51             {
     38            else {
    5239              $(input).siblings("span.wrap2").removeClass("thumbSelected");
    5340            }
     
    6047        return true;
    6148      });
    62       $(this).click(function(event) {$(this).triggerHandler("shclick",event)});
     49      $(this).click(function(event) { $(this).triggerHandler("shclick",event); });
    6350    });
    6451  }
    65 });
    66 
    67 /* sprintf */
    68 function str_repeat(i, m) {
    69     for (var o = []; m > 0; o[--m] = i);
    70     return o.join('');
    71 }
    72 
    73 function sprintf() {
    74   var i = 0, a, f = arguments[i++], o = [], m, p, c, x, s = '';
    75   while (f) {
    76     if (m = /^[^\x25]+/.exec(f)) {
    77       o.push(m[0]);
    78     }
    79     else if (m = /^\x25{2}/.exec(f)) {
    80       o.push('%');
    81     }
    82     else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
    83       if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) {
    84         throw('Too few arguments.');
    85       }
    86       if (/[^s]/.test(m[7]) && (typeof(a) != 'number')) {
    87         throw('Expecting number but found ' + typeof(a));
    88       }
    89       switch (m[7]) {
    90         case 'b': a = a.toString(2); break;
    91         case 'c': a = String.fromCharCode(a); break;
    92         case 'd': a = parseInt(a); break;
    93         case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
    94         case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
    95         case 'o': a = a.toString(8); break;
    96         case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
    97         case 'u': a = Math.abs(a); break;
    98         case 'x': a = a.toString(16); break;
    99         case 'X': a = a.toString(16).toUpperCase(); break;
    100       }
    101       a = (/[def]/.test(m[7]) && m[2] && a >= 0 ? '+'+ a : a);
    102       c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
    103       x = m[5] - String(a).length - s.length;
    104       p = m[5] ? str_repeat(c, x) : '';
    105       o.push(s + (m[4] ? a + p : p + a));
    106     }
    107     else {
    108       throw('Huh ?!');
    109     }
    110     f = f.substring(m[0].length);
    111   }
    112   return o.join('');
    113 }
    114 
    115 /* update displaying */
    116 function checkPermitAction() {
    117   var nbSelected = 0;
    118   if ($("input[name=setSelected]").is(':checked')) {
    119     nbSelected = nb_thumbs_set;
    120   } else {
    121     $(".thumbnails input[type=checkbox]").each(function() {
    122       if ($(this).is(':checked')) nbSelected++;
    123     });
    124   }
    125 
    126   if (nbSelected == 0) {
    127     $("#beginImport").hide();
    128   } else {
    129     $("#beginImport").show();
    130   }
    131 
    132   $("#applyOnDetails").text(
    133     sprintf(
    134       applyOnDetails_pattern,
    135       nbSelected
    136     )
    137   );
    138 
    139   // display the number of currently selected photos in the "Selection" fieldset
    140   if (nbSelected == 0) {
    141     $("#selectedMessage").text(
     52
     53  /* update displaying */
     54  function checkPermitAction() {
     55    var nbSelected = 0;
     56    if ($("input[name=setSelected]").is(':checked')) {
     57      nbSelected = nb_thumbs_set;
     58    }
     59    else {
     60      $(".thumbnails input[type=checkbox]").each(function() {
     61        if ($(this).is(':checked')) nbSelected++;
     62      });
     63    }
     64
     65    if (nbSelected == 0) {
     66      $("#beginImport").hide();
     67    }
     68    else {
     69      $("#beginImport").show();
     70    }
     71
     72    $("#applyOnDetails").text(
    14273      sprintf(
    143         selectedMessage_none,
    144         nb_thumbs_set
     74        '{'on the %d selected photos'|translate|escape:javascript}',
     75        nbSelected
    14576      )
    14677    );
    147   } else if (nbSelected == nb_thumbs_set) {
    148     $("#selectedMessage").text(
    149       sprintf(
    150         selectedMessage_all,
    151         nb_thumbs_set
    152       )
    153     );
    154   } else {
    155     $("#selectedMessage").text(
    156       sprintf(
    157         selectedMessage_pattern,
    158         nbSelected,
    159         nb_thumbs_set
    160       )
    161     );
     78
     79    // display the number of currently selected photos in the "Selection" fieldset
     80    if (nbSelected == 0) {
     81      $("#selectedMessage").text(
     82        sprintf(
     83          '{'No photo selected, %d photos in current set'|translate|escape:javascript}',
     84          nb_thumbs_set
     85        )
     86      );
     87    }
     88    else if (nbSelected == nb_thumbs_set) {
     89      $("#selectedMessage").text(
     90        sprintf(
     91          '{'All %d photos are selected'|translate|escape:javascript}',
     92          nb_thumbs_set
     93        )
     94      );
     95    }
     96    else {
     97      $("#selectedMessage").text(
     98        sprintf(
     99          '{'%d of %d photos selected'|translate|escape:javascript}',
     100          nbSelected,
     101          nb_thumbs_set
     102        )
     103      );
     104    }
    162105  }
    163 }
    164 
    165 /* import queue */
    166 function performImport(photo, album, fills) {
    167   queuedManager.add({
    168     type: 'GET',
    169     dataType: 'json',
    170     url: 'ws.php',
    171     data: { method: 'pwg.images.addFlickr', id: photo, category: album, fills: fills, format: 'json' },
    172     success: function(data) {
    173       if (data['stat'] == 'ok') {
    174         jQuery.jGrowl(data['result'], { theme: 'success', header: successHead, life: 4000, sticky: false });
    175         jQuery("#photo-"+photo).fadeOut(function(){ $(this).remove(); });
    176       } else {
    177         jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true });
     106
     107  /* import queue */
     108  function performImport(photo, album, fills) {
     109    queuedManager.add({
     110      type: 'GET',
     111      dataType: 'json',
     112      url: 'ws.php',
     113      data: {
     114        method: 'pwg.images.addFlickr',
     115        id: photo,
     116        category: album,
     117        fills: fills,
     118        format: 'json'
     119      },
     120      success: function(data) {
     121        if (data['stat'] == 'ok') {
     122          jQuery.jGrowl(data['result'], {
     123            theme: 'success', life: 4000, sticky: false,
     124            header: '{'Success'|translate}'
     125          });
     126          jQuery("#photo-"+photo).fadeOut(function(){ $(this).remove(); });
     127        }
     128        else {
     129          jQuery.jGrowl(data['result'], {
     130            theme: 'error', sticky: true,
     131            header: '{'ERROR'|translate}'
     132          });
     133        }
     134
     135        import_done++;
     136        $("#progress").html(import_done +"/"+ import_selected);
     137
     138        if (import_done == import_selected) {
     139          $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">');
     140          $("#import_form").submit();
     141        }
     142      },
     143      error: function(data) {
     144        jQuery.jGrowl('{'an error happened'|translate|@escape:'javascript'}', {
     145          theme: 'error', sticky: true,
     146          header: '{'ERROR'|translate}'
     147        });
    178148      }
    179      
    180       import_done++;
    181       $("#progress").html(import_done +"/"+ import_selected);
    182      
    183       if (import_done == import_selected) {
    184         $("#import_form").append('<input type="hidden" name="done" value="' + import_done + '">');
    185         $("#import_form").submit();
    186       }
    187     },
    188     error: function(data) {
    189       jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true });
    190     }
    191   });
    192 }
    193 
    194 
    195 $(document).ready(function() {
     149    });
     150  }
     151
     152
    196153  checkPermitAction();
    197154  $("a.preview-box").colorbox();
     
    206163
    207164  /* thumbnail click */
    208   $(".wrap1 label").click(function (event) {
    209     $("input[name=setSelected]").attr('checked', false);
     165  $(".wrap1 label").click(function(event) {
     166    $("input[name=setSelected]").prop('checked', false);
    210167
    211168    var wrap2 = $(this).children(".wrap2");
     
    215172
    216173    if ($(checkbox).is(':checked')) {
    217       $(wrap2).addClass("thumbSelected"); 
    218     }
    219     else {
    220       $(wrap2).removeClass('thumbSelected'); 
     174      $(wrap2).addClass("thumbSelected");
     175    }
     176    else {
     177      $(wrap2).removeClass('thumbSelected');
    221178    }
    222179
     
    225182
    226183  /* select all */
    227   $("#selectAll").click(function () {
    228     $("input[name=setSelected]").attr('checked', false);
    229    
     184  $("#selectAll").click(function() {
     185    $("input[name=setSelected]").prop('checked', false);
     186
    230187    $(".thumbnails label").each(function() {
    231188      var wrap2 = $(this).children(".wrap2");
    232189      var checkbox = $(this).children("input[type=checkbox]");
    233190
    234       $(checkbox).attr('checked', true);
    235       $(wrap2).addClass("thumbSelected"); 
    236     });
    237    
     191      $(checkbox).prop('checked', true);
     192      $(wrap2).addClass("thumbSelected");
     193    });
     194
    238195    checkPermitAction();
    239196    return false;
     
    241198
    242199  /* select none */
    243   $("#selectNone").click(function () {
    244     $("input[name=setSelected]").attr('checked', false);
    245    
     200  $("#selectNone").click(function() {
     201    $("input[name=setSelected]").prop('checked', false);
     202
    246203    $(".thumbnails label").each(function() {
    247204      var wrap2 = $(this).children(".wrap2");
    248205      var checkbox = $(this).children("input[type=checkbox]");
    249206
    250       $(checkbox).attr('checked', false);
    251       $(wrap2).removeClass("thumbSelected"); 
    252     });
    253    
     207      $(checkbox).prop('checked', false);
     208      $(wrap2).removeClass("thumbSelected");
     209    });
     210
    254211    checkPermitAction();
    255212    return false;
     
    257214
    258215  /* select invert */
    259   $("#selectInvert").click(function () {
    260     $("input[name=setSelected]").attr('checked', false);
    261    
     216  $("#selectInvert").click(function() {
     217    $("input[name=setSelected]").prop('checked', false);
     218
    262219    $(".thumbnails label").each(function() {
    263220      var wrap2 = $(this).children(".wrap2");
    264221      var checkbox = $(this).children("input[type=checkbox]");
    265222
    266       $(checkbox).attr('checked', !$(checkbox).is(':checked'));
     223      $(checkbox).prop('checked', !$(checkbox).is(':checked'));
    267224
    268225      if ($(checkbox).is(':checked')) {
    269         $(wrap2).addClass("thumbSelected");
    270       } else {
    271         $(wrap2).removeClass('thumbSelected');
     226        $(wrap2).addClass("thumbSelected");
    272227      }
    273     });
    274    
    275     checkPermitAction();
    276     return false;
    277   });
    278  
     228      else {
     229        $(wrap2).removeClass('thumbSelected');
     230      }
     231    });
     232
     233    checkPermitAction();
     234    return false;
     235  });
     236
    279237  /* select set */
    280   $("#selectSet").click(function () {
    281     $("input[name=setSelected]").attr('checked', true);
    282    
     238  $("#selectSet").click(function() {
     239    $("input[name=setSelected]").prop('checked', true);
     240
    283241    $(".thumbnails label").each(function() {
    284242      var wrap2 = $(this).children(".wrap2");
    285243      var checkbox = $(this).children("input[type=checkbox]");
    286244
    287       $(checkbox).attr('checked', true);
    288       $(wrap2).addClass("thumbSelected"); 
    289     });
    290    
    291     checkPermitAction();
    292     return false;
    293   });
    294  
     245      $(checkbox).prop('checked', true);
     246      $(wrap2).addClass("thumbSelected");
     247    });
     248
     249    checkPermitAction();
     250    return false;
     251  });
     252
    295253  /* begin import */
    296254  jQuery('#beginImport').click(function() {
    297255    $("#loader_import").fadeIn();
    298256    var album = $("#albumSelect option:selected").val();
    299    
     257
    300258    var fills = '';
    301259    $("input[name^='fill_']:checked").each(function() {
    302260      fills+= $(this).attr("name") +',';
    303     }); 
    304    
     261    });
     262
    305263    if (jQuery('input[name="setSelected"]').attr('checked')) {
    306264      import_selected = all_elements.length;
    307265      $("#progress").html("0/"+ import_selected);
    308      
     266
    309267      for (var i in all_elements) {
    310268        performImport(all_elements[i], album, fills);
    311269      }
    312                 } else {
     270                }
     271    else {
    313272      import_selected = $("input[name='selection[]']:checked").length;
    314273      $("#progress").html("0/"+ import_selected);
    315      
     274
    316275                        jQuery("input[name='selection[]']:checked").each(function() {
    317276        performImport(jQuery(this).attr('value'), album, fills);
    318277      });
    319278    }
    320    
    321     return false;
    322   });
    323  
     279
     280    return false;
     281  });
     282
    324283  /* pagination loader */
    325284  jQuery('#navigation a').click(function() {
    326285    $("#loader_display").fadeIn();
    327286  });
    328 });
    329 {/literal}
     287}(jQuery));
    330288{/footer_script}
     289
    331290
    332291<div id="batchManagerGlobal">
     
    334293
    335294  <fieldset>
    336     <legend>{'Selection'|@translate}</legend>
     295    <legend>{'Selection'|translate}</legend>
    337296
    338297  {if !empty($thumbnails)}
    339298    <p id="checkActions">
    340       {'Select:'|@translate}
     299      {'Select:'|translate}
    341300    {if $nb_thumbs_set > $nb_thumbs_page}
    342       <a href="#" id="selectAll">{'The whole page'|@translate}</a>,
    343       <a href="#" id="selectSet">{'The whole set'|@translate}</a>,
     301      <a href="#" id="selectAll">{'The whole page'|translate}</a>,
     302      <a href="#" id="selectSet">{'The whole set'|translate}</a>,
    344303    {else}
    345       <a href="#" id="selectAll">{'All'|@translate}</a>,
     304      <a href="#" id="selectAll">{'All'|translate}</a>,
    346305    {/if}
    347       <a href="#" id="selectNone">{'None'|@translate}</a>,
    348       <a href="#" id="selectInvert">{'Invert'|@translate}</a>
     306      <a href="#" id="selectNone">{'None'|translate}</a>,
     307      <a href="#" id="selectInvert">{'Invert'|translate}</a>
    349308
    350309      <span id="selectedMessage"></span>
    351310      <input type="checkbox" name="setSelected" style="display:none">
    352       <span id="loader_display" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i></span>
     311      <span id="loader_display" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i></span>
    353312    </p>
    354313
     
    359318                                        <label>
    360319                                                <span class="wrap2">
    361                                                 <div class="actions"><a href="{$thumbnail.src}" class="preview-box">{'Zoom'|@translate}</a> &middot; <a href="{$thumbnail.url}" target="_blank" title="{'Open Flickr page in a new tab'|@translate}">Flickr</a></div>
     320                                                <div class="actions"><a href="{$thumbnail.src}" class="preview-box">{'Zoom'|translate}</a> &middot; <a href="{$thumbnail.url}" target="_blank" title="{'Open Flickr page in a new tab'|translate}">Flickr</a></div>
    362321                                                        <span>
    363                                                                 <img src="{$thumbnail.thumb}" alt="{$thumbnail.title}" title="{$thumbnail.title|@escape:'html'}" class="thumbnail">
     322                                                                <img src="{$thumbnail.thumb}" alt="{$thumbnail.title}" title="{$thumbnail.title|escape:'html'}" class="thumbnail">
    364323                                                        </span>
    365324                                                </span>
     
    370329      {/foreach}
    371330    </ul>
    372    
    373    
     331
     332
    374333    <div style="clear:both;" id="navigation">
    375334    {if !empty($navbar) }
    376335      <div style="float:left">
    377       {include file='navigation_bar.tpl'|@get_extent:'navbar'}
     336      {include file='navigation_bar.tpl'|get_extent:'navbar'}
    378337      </div>
    379338    {/if}
    380    
    381       <div style="float:right;margin-top:10px;">{'display'|@translate}
     339
     340      <div style="float:right;margin-top:10px;">{'display'|translate}
    382341        <a href="{$U_DISPLAY}&amp;display=20">20</a>
    383342        &middot; <a href="{$U_DISPLAY}&amp;display=50">50</a>
    384343        &middot; <a href="{$U_DISPLAY}&amp;display=100">100</a>
    385         &middot; <a href="{$U_DISPLAY}&amp;display=all">{'all'|@translate}</a>
    386         {'photos per page'|@translate}
     344        &middot; <a href="{$U_DISPLAY}&amp;display=all">{'all'|translate}</a>
     345        {'photos per page'|translate}
    387346      </div>
    388347    </div>
    389348
    390349  {else}
    391     <div>{'No photo in the current set.'|@translate}</div>
     350    <div>{'No photo in the current set.'|translate}</div>
    392351  {/if}
    393352  </fieldset>
    394  
     353
    395354  <fieldset>
    396     <legend>{'Import options'|@translate}</legend>
     355    <legend>{'Import options'|translate}</legend>
    397356
    398357    <p>
    399       <label for="albumSelect"><b>{'Album'|@translate}:</b></label>
     358      <label for="albumSelect"><b>{'Album'|translate}:</b></label>
    400359      <select style="width:400px" name="associate" id="albumSelect" size="1">
    401360        {html_options options=$category_parent_options}
    402361      </select>
    403       {'... or '|@translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>
     362      {'... or '|translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|translate}">{'create a new album'|translate}</a>
    404363    </p>
    405    
     364
    406365    <p>
    407       <b>{'Fill these fields from Flickr datas'|@translate}:</b>
    408       <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'|@translate}</label>
    409       <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'|@translate}</label>
    410       <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'|@translate}</label>
    411       <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'|@translate}</label>
    412       <label><input type="checkbox" name="fill_posted"> {'Post date'|@translate}</label>
     366      <b>{'Fill these fields from Flickr datas'|translate}:</b>
     367      <label><input type="checkbox" name="fill_name" checked="checked"> {'Photo name'|translate}</label>
     368      <label><input type="checkbox" name="fill_author" checked="checked"> {'Author'|translate}</label>
     369      <label><input type="checkbox" name="fill_tags" checked="checked"> {'Tags'|translate}</label>
     370      <label><input type="checkbox" name="fill_taken" checked="checked"> {'Creation date'|translate}</label>
     371      <label><input type="checkbox" name="fill_posted"> {'Post date'|translate}</label>
    413372      <label><input type="checkbox" name="fill_description" checked="checked"> {'Description'|@translate}</label>
    414       {if $GMAPS_LOADED}<label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label>{/if}
     373      <label><input type="checkbox" name="fill_geotag" checked="checked"> {'Geolocalization'|@translate}</label>
    415374    </p>
    416375
    417376    <p>
    418377      <input type="hidden" name="album" value="{$album}">
    419       <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'|@translate}" style="display:none;">
    420       <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i> <span id="progress"></span></span>
     378      <input type="submit" name="import_set" id="beginImport" value="{'Begin transfer'|translate}" style="display:none;">
     379      <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i> <span id="progress"></span></span>
    421380    </p>
    422381  </fieldset>
  • extensions/flickr2piwigo/admin/template/import.tpl

    r25789 r26180  
    1 {combine_css path=$FLICKR_PATH|@cat:"admin/template/style.css"}
     1{combine_css path=$FLICKR_PATH|cat:'admin/template/style.css'}
    22
    33{include file='include/colorbox.inc.tpl'}
    44{include file='include/add_album.inc.tpl'}
     5{combine_script id='common' load='footer' path='admin/themes/default/js/common.js'}
    56{combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
    67{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js'}
     
    1314{* <!-- LOGIN --> *}
    1415{if $ACTION == 'init_login'}
    15 <p><input type="submit" onClick="javascript:window.location.href ='{$flickr_login}';" value="{'Login'|@translate}"></p>
     16<p><input type="submit" onclick="javascript:window.location.href ='{$flickr_login}';" value="{'Login'|translate}"></p>
    1617
    1718{* <!-- MAIN MENU --> *}
    18 {elseif $ACTION == 'main'}
    19 {footer_script}{literal}
     19{else if $ACTION == 'main'}
     20
     21{footer_script}
    2022jQuery('input[type="submit"]').click(function() {
    2123  window.location.href = $(this).attr("data");
     
    2426  $("#loader_import").fadeIn();
    2527});
    26 {/literal}{/footer_script}
     28{/footer_script}
    2729
    2830<p>
    29   <b>{'Logged in as'|@translate}</b> : <a href="{$profile_url}" target="_blank">{$username}</a><br><br>
    30   <input type="submit" data="{$logout_url}" value="{'Logout'|@translate}">
     31  <b>{'Logged in as'|translate}</b> : <a href="{$profile_url}" target="_blank">{$username}</a><br><br>
     32  <input type="submit" data="{$logout_url}" value="{'Logout'|translate}">
    3133</p>
    3234<br>
    3335<p>
    34   <input type="submit" data="{$list_albums_url}" class="load" value="{'List my albums'|@translate}">
    35   <input type="submit" data="{$import_all_url}" class="load" value="{'Import all my pictures'|@translate}">
     36  <input type="submit" data="{$list_albums_url}" class="load" value="{'List my albums'|translate}">
     37  <input type="submit" data="{$import_all_url}" class="load" value="{'Import all my pictures'|translate}">
    3638  <br>
    37   <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i></span>
     39  <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i></span>
    3840</p>
    3941
    4042{* <!-- ALBUMS LIST --> *}
    41 {elseif $ACTION == 'list_albums'}
    42 {footer_script}{literal}
     43{else if $ACTION == 'list_albums'}
     44
     45{footer_script}
    4346jQuery('.load').click(function() {
    4447  $("#loader_import").fadeIn();
    4548});
    46 {/literal}{/footer_script}
     49{/footer_script}
    4750
    48 <h3>{'%d albums'|@translate|@sprintf:$total_albums}</h3>
     51<h3>{'%d albums'|translate:$total_albums}</h3>
    4952<ul id="albumsList">
    5053{foreach from=$albums item=album}
    5154  <li {if $album.id == "not_in_set"}class="not_in_set"{/if}>
    52     <b><a href="{$album.U_LIST}" class="load">{$album.title}</a></b> <i>{'(%d photos)'|@translate|@sprintf:$album.photos}</i>
    53     {if $album.description}- {$album.description|@truncate:100}{/if}
     55    <b><a href="{$album.U_LIST}" class="load">{$album.title}</a></b> <i>{'(%d photos)'|translate:$album.photos}</i>
     56    {if $album.description}- {$album.description|truncate:100}{/if}
    5457  </li>
    5558{/foreach}
    5659</ul>
    57 <span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|@translate}</i></span>
     60<span id="loader_import" style="display:none;"><img src="admin/themes/default/images/ajax-loader.gif"> <i>{'Processing...'|translate}</i></span>
    5861
    5962{* <!-- PHOTOS LIST --> *}
    60 {elseif $ACTION == 'list_photos'}
    61 {include file=$FLICKR_ABS_PATH|@cat:'admin/template/import.list_photos.tpl'}
     63{else if $ACTION == 'list_photos'}
     64{include file=$FLICKR_ABS_PATH|cat:'admin/template/import.list_photos.tpl'}
    6265
    6366{* <!-- IMPORT ALL --> *}
    64 {elseif $ACTION == 'list_all'}
    65 {include file=$FLICKR_ABS_PATH|@cat:'admin/template/import.list_all.tpl'}
     67{else if $ACTION == 'list_all'}
     68{include file=$FLICKR_ABS_PATH|cat:'admin/template/import.list_all.tpl'}
    6669
    6770{/if}
  • extensions/flickr2piwigo/include/functions.inc.php

    r21288 r26180  
    11<?php
    2 if (!defined('FLICKR_PATH')) die('Hacking attempt!');
     2defined('FLICKR_PATH') or die('Hacking attempt!');
    33
    44/**
     
    3030      return false;
    3131    }
    32    
     32
    3333    $return = ($dest === true) ? true : false;
    34    
     34
    3535    /* curl */
    3636    if (function_exists('curl_init'))
     
    4141      }
    4242      $ch = curl_init();
    43      
     43
    4444      curl_setopt($ch, CURLOPT_URL, $src);
    4545      curl_setopt($ch, CURLOPT_HEADER, false);
     
    6565        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    6666      }
    67      
     67
    6868      $out = curl_exec($ch);
    6969      curl_close($ch);
    70      
     70
    7171      if ($out === false)
    7272      {
     
    9090        return false;
    9191      }
    92      
     92
    9393      $opts = array(
    9494        'http' => array(
     
    100100
    101101      $context = stream_context_create($opts);
    102      
     102
    103103      if (($file = file_get_contents($src, false, $context)) === false)
    104104      {
    105105        return 'file_error';
    106106      }
    107      
     107
    108108      if (!$return)
    109109      {
     
    116116      }
    117117    }
    118    
     118
    119119    return false;
    120120  }
    121121}
    122 
    123 ?>
  • extensions/flickr2piwigo/include/ws_functions.inc.php

    r25790 r26180  
    11<?php
    2 if (!defined('FLICKR_PATH')) die('Hacking attempt!');
     2defined('FLICKR_PATH') or die('Hacking attempt!');
    33
    44function flickr_add_ws_method($arr)
    55{
    66  $service = &$arr[0];
    7  
     7
    88  $service->addMethod(
    99    'pwg.images.addFlickr',
     
    1414      'fills' => array('default' =>null),
    1515      ),
    16     'Used by Flickr2Piwigo'
     16    'Used by Flickr2Piwigo',
     17    null,
     18    array('hidden'=>true)
    1719    );
    1820}
     
    2426    return new PwgError(403, 'Forbidden');
    2527  }
    26  
     28
    2729  global $conf;
    28   $conf['flickr2piwigo'] = unserialize($conf['flickr2piwigo']);
    29  
    30   if ( empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']) )
     30
     31  if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key']))
    3132  {
    3233    return new PwgError(null, l10n('Please fill your API keys on the configuration tab'));
    3334  }
    34  
     35
    3536  include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
    3637  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
    3738  include_once(FLICKR_PATH . 'include/functions.inc.php');
    38  
     39
    3940  if (test_remote_download() === false)
    4041  {
    4142    return new PwgError(null, l10n('No download method available'));
    4243  }
    43  
     44
    4445  // init flickr API
    4546  include_once(FLICKR_PATH . 'include/phpFlickr/phpFlickr.php');
    4647  $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']);
    4748  $flickr->enableCache('fs', FLICKR_FS_CACHE);
    48  
     49
    4950  // user
    5051  $u = $flickr->test_login();
    51   if ( $u === false or empty($_SESSION['phpFlickr_auth_token']) )
     52  if ($u === false or empty($_SESSION['phpFlickr_auth_token']))
    5253  {
    5354    return new PwgError(403, l10n('API not authenticated'));
    5455  }
    55  
     56
    5657  // photos infos
    5758  $photo_f = $flickr->photos_getInfo($photo['id']);
     
    5960  $photo['url'] = $flickr->get_biggest_size($photo['id'], 'original');
    6061  $photo['path'] = FLICKR_FS_CACHE . 'flickr-'.$u['username'].'-'.$photo['id'].'.'.get_extension($photo['url']);
    61  
     62
    6263  // copy file
    6364  if (download_remote_file($photo['url'], $photo['path']) == false)
     
    6566    return new PwgError(null, l10n('Can\'t download file'));
    6667  }
    67  
     68
    6869  // category
    6970  if (!preg_match('#^[0-9]+$#', $photo['category']))
    7071  {
    7172    $categories_names = explode(',', $photo['category']);
    72    
     73
    7374    $photo['category'] = array();
    7475    foreach ($categories_names as $category_name)
     
    7980;';
    8081      $result = pwg_query($query);
    81      
     82
    8283      if (pwg_db_num_rows($result))
    8384      {
    8485        list($cat_id) = pwg_db_fetch_row($result);
    85         array_push($photo['category'], $cat_id);
     86        $photo['category'][] = $cat_id;
    8687      }
    8788      else
    8889      {
    89        
     90
    9091        $cat = create_virtual_category($category_name);
    91         array_push($photo['category'], $cat['id']);
     92        $photo['category'][] = $cat['id'];
    9293      }
    9394    }
     
    9798    $photo['category'] = array($photo['category']);
    9899  }
    99  
     100
    100101  // add photo
    101102  $photo['image_id'] = add_uploaded_file($photo['path'], basename($photo['path']), $photo['category']);
    102  
     103
    103104  // do some updates
    104105  if (!empty($photo['fills']))
     
    106107    $photo['fills'] = rtrim($photo['fills'], ',');
    107108    $photo['fills'] = explode(',', $photo['fills']);
    108  
     109
    109110    $updates = array();
    110     if (in_array('fill_name', $photo['fills']))   $updates['name'] = pwg_db_real_escape_string($photo['title']); 
     111    if (in_array('fill_name', $photo['fills']))   $updates['name'] = pwg_db_real_escape_string($photo['title']);
    111112    if (in_array('fill_posted', $photo['fills'])) $updates['date_available'] = date('Y-m-d H:i:s', $photo['dates']['posted']);
    112113    if (in_array('fill_taken', $photo['fills']))  $updates['date_creation'] = $photo['dates']['taken'];
     
    115116    if (in_array('fill_geotag', $photo['fills']) and !empty($photo['location']) )
    116117    {
    117       $updates['lat'] = pwg_db_real_escape_string($photo['location']['latitude']);
    118       $updates['lon'] = pwg_db_real_escape_string($photo['location']['longitude']);
     118      $updates['latitude'] = pwg_db_real_escape_string($photo['location']['latitude']);
     119      $updates['longitude'] = pwg_db_real_escape_string($photo['location']['longitude']);
    119120    }
    120    
     121
    121122    if (count($updates))
    122123    {
     
    127128        );
    128129    }
    129    
    130     if ( !empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills']) )
     130
     131    if (!empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills']))
    131132    {
    132133      $raw_tags = array_map(create_function('$t', 'return $t["_content"];'), $photo['tags']['tag']);
     
    135136    }
    136137  }
    137  
    138   return sprintf(l10n('Photo "%s" imported'), $photo['title']);
     138
     139  return l10n('Photo "%s" imported', $photo['title']);
    139140}
    140 
    141 ?>
  • extensions/flickr2piwigo/main.inc.php

    r24815 r26180  
    1 <?php 
     1<?php
    22/*
    33Plugin Name: Flickr2Piwigo
     
    99*/
    1010
    11 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    1212
    1313global $conf;
    1414
    15 define('FLICKR_PATH',     PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
    16 define('FLICKR_ADMIN',    get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
     15define('FLICKR_ID',       basename(dirname(__FILE__)));
     16define('FLICKR_PATH',     PHPWG_PLUGINS_PATH . FLICKR_ID . '/');
     17define('FLICKR_ADMIN',    get_root_url() . 'admin.php?page=plugin-' . FLICKR_ID);
    1718define('FLICKR_FS_CACHE', PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/');
     19define('FLICKR_VERSION',  'auto');
    1820
     21
     22include_once(FLICKR_PATH . 'include/ws_functions.inc.php');
     23
     24
     25add_event_handler('init', 'flickr_init');
     26add_event_handler('ws_add_methods', 'flickr_add_ws_method');
    1927
    2028if (defined('IN_ADMIN'))
    2129{
    2230  add_event_handler('get_admin_plugin_menu_links', 'flickr_admin_menu');
     31
    2332  add_event_handler('get_batch_manager_prefilters', 'flickr_add_batch_manager_prefilters');
    2433  add_event_handler('perform_batch_manager_prefilters', 'flickr_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
    25   add_event_handler('loc_begin_admin_page', 'flickr_prefilter_from_url');
    2634
    27   function flickr_admin_menu($menu) 
     35  function flickr_admin_menu($menu)
    2836  {
    29     array_push($menu, array(
     37    $menu[] = array(
    3038      'NAME' => 'Flickr2Piwigo',
    3139      'URL' => FLICKR_ADMIN,
    32     ));
     40      );
    3341    return $menu;
    3442  }
    35  
     43
    3644  function flickr_add_batch_manager_prefilters($prefilters)
    3745  {
    38     array_push($prefilters, array(
     46    $prefilters[] = array(
    3947      'ID' => 'flickr',
    4048      'NAME' => l10n('Imported from Flickr'),
    41     ));
     49      );
    4250    return $prefilters;
    4351  }
     
    5462      $filter_sets[] = array_from_query($query, 'id');
    5563    }
    56    
     64
    5765    return $filter_sets;
    58   }
    59  
    60   function flickr_prefilter_from_url()
    61   {
    62     global $page;
    63     if ($page['page'] == 'batch_manager' && @$_GET['prefilter'] == 'flickr')
    64     {
    65       $_SESSION['bulk_manager_filter'] = array('prefilter' => 'flickr');
    66       unset($_GET['prefilter']);
    67     }
    6866  }
    6967}
    7068
    7169
    72 include_once(FLICKR_PATH . 'include/ws_functions.inc.php');
     70function flickr_init()
     71{
     72  global $conf;
     73  include_once(FLICKR_PATH . 'maintain.inc.php');
     74  $maintain = new flickr2piwigo_maintain(FLICKR_ID);
     75  $maintain->autoUpdate(FLICKR_VERSION, 'install');
    7376
    74 add_event_handler('ws_add_methods', 'flickr_add_ws_method');
    75 
    76 ?>
     77  $conf['flickr2piwigo'] = unserialize($conf['flickr2piwigo']);
     78}
  • extensions/flickr2piwigo/maintain.inc.php

    r24815 r26180  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    33
    4 define(
    5   'flickr2piwigo_default_config',
    6   serialize(array(
     4class flickr2piwigo_maintain extends PluginMaintain
     5{
     6  private $installed = false;
     7
     8  private $default_conf = array(
    79    'api_key' => null,
    810    'secret_key' => null,
    9     ))
    10   );
     11    );
    1112
     13  function install($plugin_version, &$errors=array())
     14  {
     15    global $conf;
    1216
    13 function plugin_install()
    14 {
    15   global $conf;
    16  
    17   conf_update_param('flickr2piwigo', flickr2piwigo_default_config);
    18  
    19   mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
    20 }
     17    if (empty($conf['flickr2piwigo']))
     18    {
     19      $conf['flickr2piwigo'] = serialize($this->default_conf);
     20      conf_update_param('flickr2piwigo', $conf['flickr2piwigo']);
     21    }
    2122
    22 function plugin_activate()
    23 {
    24   global $conf;
     23    mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
    2524
    26   if (empty($conf['flickr2piwigo']))
     25    $this->installed = true;
     26  }
     27
     28  function activate($plugin_version, &$errors=array())
    2729  {
    28     conf_update_param('flickr2piwigo', flickr2piwigo_default_config);
     30    if (!$this->installed)
     31    {
     32      $this->install($plugin_version, $errors);
     33    }
    2934  }
    30  
    31   if (!file_exists(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/'))
     35
     36  function deactivate()
    3237  {
    33     mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
     38  }
     39
     40  function uninstall()
     41  {
     42    global $conf;
     43
     44    conf_delete_param('flickr2piwigo');
     45
     46    self::rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/');
     47  }
     48
     49  static function rrmdir($dir)
     50  {
     51    if (!is_dir($dir))
     52    {
     53      return false;
     54    }
     55    $dir = rtrim($dir, '/');
     56    $objects = scandir($dir);
     57    $return = true;
     58
     59    foreach ($objects as $object)
     60    {
     61      if ($object !== '.' && $object !== '..')
     62      {
     63        $path = $dir.'/'.$object;
     64        if (filetype($path) == 'dir')
     65        {
     66          $return = $return && self::rrmdir($path);
     67        }
     68        else
     69        {
     70          $return = $return && @unlink($path);
     71        }
     72      }
     73    }
     74
     75    return $return && @rmdir($dir);
    3476  }
    3577}
    36 
    37 function plugin_uninstall()
    38 {
    39   global $conf;
    40  
    41   pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "flickr2piwigo";');
    42   unset($conf['flickr2piwigo']);
    43  
    44   rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'flickr_cache/');
    45 }
    46 
    47 function rrmdir($dir)
    48 {
    49   if (!is_dir($dir))
    50   {
    51     return false;
    52   }
    53   $dir = rtrim($dir, '/');
    54   $objects = scandir($dir);
    55   $return = true;
    56  
    57   foreach ($objects as $object)
    58   {
    59     if ($object !== '.' && $object !== '..')
    60     {
    61       $path = $dir.'/'.$object;
    62       if (filetype($path) == 'dir')
    63       {
    64         $return = $return && rrmdir($path);
    65       }
    66       else
    67       {
    68         $return = $return && @unlink($path);
    69       }
    70     }
    71   }
    72  
    73   return $return && @rmdir($dir);
    74 }
    75 
    76 ?>
Note: See TracChangeset for help on using the changeset viewer.