Changeset 17314


Ignore:
Timestamp:
Aug 2, 2012, 6:38:10 PM (9 years ago)
Author:
mistic100
Message:
  • many small improvements
  • protect "generic" functions
  • complete localization
Location:
extensions/pbase2piwigo
Files:
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • extensions/pbase2piwigo/admin.php

    r17225 r17314  
    1212}
    1313
    14 // tabsheet
    15 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
    16 $page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'import';
    17  
    18 $tabsheet = new tabsheet();
    19 $tabsheet->add('import', l10n('Import'), PBASE_ADMIN . '-import');
    20 // $tabsheet->add('config', l10n('Configuration'), PBASE_ADMIN . '-config');
    21 $tabsheet->select($page['tab']);
    22 $tabsheet->assign();
    23 
    2414// include page
    25 include(PBASE_PATH . 'admin/' . $page['tab'] . '.php');
     15include(PBASE_PATH . 'admin/import.php');
    2616
    2717// template
  • extensions/pbase2piwigo/admin/import.php

    r17225 r17314  
    5050  case 'config':
    5151  {
     52    if (isset($_SESSION['pbase_empty_error']))
     53    {
     54      array_push($page['errors'], l10n('Import queue is empty'));
     55      unset($_SESSION['pbase_empty_error']);
     56    }
     57   
     58    // counters
     59    $nb_categories = $nb_pictures = 0;
     60    count_pictures_cats($tree, '/root', $nb_pictures, $nb_categories, true);
     61   
     62    // get piwigo categories
     63    $query = '
     64SELECT id, name, uppercats, global_rank
     65  FROM '.CATEGORIES_TABLE.'
     66;';
     67    display_select_cat_wrapper($query, array(), 'associate_options');
     68    display_select_cat_wrapper($query, array(), 'category_parent_options');
     69   
    5270    $template->assign(array(
     71      'nb_categories' => $nb_categories-1, // don't count root
     72      'nb_pictures' => $nb_pictures,
    5373      'F_ACTION' => PBASE_ADMIN.'-import&action=init_import',
    5474      'RESET_LINK' => PBASE_ADMIN.'-import&action=reset_tree',
     
    6181  {
    6282    $categories = $_POST['categories'];
     83    $nb_categories = $nb_pictures = 0;
    6384   
    64     // remove duplicate categories (in case of recursive mode)
    6585    if (isset($_POST['recursive']))
    6686    {
     87      // we don't add "root", only it's children
     88      if (@$categories[0] == '/root')
     89      {
     90        $temp = &get_current_cat($tree, '/root');
     91        $categories = array_merge($categories, array_values(array_unique_deep($temp['categories'], 'path')));
     92        $categories = array_unique($categories);
     93        unset($categories[0]);
     94      }
     95     
     96      // remove duplicate categories (in case of recursive mode)
    6797      foreach ($categories as &$path)
    6898      {
     
    77107    // count pictures and cats
    78108    $temp_cats = $categories;
    79     $nb_categories = $nb_pictures = 0;
    80109    foreach ($temp_cats as $path)
    81110    {
    82111      count_pictures_cats($tree, $path, $nb_pictures, $nb_categories, isset($_POST['recursive']));
     112    }
     113   
     114    if ($nb_pictures == 0)
     115    {
     116      $_SESSION['pbase_empty_error'] = true;
     117      redirect(PBASE_ADMIN.'-import');
    83118    }
    84119   
     
    87122      'nb_categories' => $nb_categories,
    88123      'categories' => $categories,
     124      'PARENT_CATEGORY' => $_POST['parent_category'],
    89125      'RECURSIVE' => boolean_to_string(isset($_POST['recursive'])),
    90126      'FILLS' => implode(',', @$_POST['fills']),
  • extensions/pbase2piwigo/admin/template/import.config.tpl

    r17225 r17314  
     1{include file='include/colorbox.inc.tpl'}
     2{include file='include/add_album.inc.tpl'}
     3
    14{footer_script require='jquery.ui.resizable'}{literal}
    25jQuery(".categoryList").resizable({
     
    1013<form action="{$F_ACTION}" method="post">
    1114<fieldset>
    12   <legend>{'Choose albums to import'|@translate}</legend>
     15  <legend>{'Select albums to import'|@translate}</legend>
    1316 
    1417  <select name="categories[]" class="categoryList" multiple="multiple" size="20">
     
    1619  </select>
    1720 
     21  <b>{'Nb albums'|@translate}</b>: {$nb_categories}<br>
     22  <b>{'Nb photos'|@translate}</b>: {$nb_pictures}<br>
     23 
    1824  <br>
    19   <a href="{$RESET_LINK}" onClick="return confirm('{'Are you sure?'|@translate}');">Reset</a>
     25  <a href="{$RESET_LINK}" onClick="return confirm('{'Are you sure?'|@translate}');">{'Reset'|@translate}</a>
    2026</fieldset>
    2127
     
    2329  <legend>{'Configuration'|@translate}</legend>
    2430 
    25   <p><label><input type="checkbox" name="recursive" value="1" checked="checked"> <b>Recursive</b></label></p>
     31  <p><label><input type="checkbox" name="recursive" value="1" checked="checked"> <b>{'Recursive'|@translate}</b></label></p>
     32 
     33  <p id="albumSelectWrapper">
     34    <b>{'Import in this album'|@translate}:</b>
     35    <select style="width:400px" name="parent_category" id="albumSelect" size="1">
     36      <option value="0">------------</option>
     37      {html_options options=$associate_options}
     38    </select>
     39    {'... or '|@translate}<a href="#" class="addAlbumOpen" title="{'create a new album'|@translate}">{'create a new album'|@translate}</a>
     40  </p>
     41   
    2642  <p>
    2743    <b>{'Fill these fields from pBase datas'|@translate}:</b>
     
    3551
    3652  <p class="bottomButtons">
    37     <input type="submit" value="Begin Transfer">   
     53    <input type="submit" value="{'Begin transfer'|@translate}">   
    3854  </p>
    3955</form>
  • extensions/pbase2piwigo/admin/template/import.init_import.tpl

    r17225 r17314  
    123123
    124124{foreach from=$categories item=cat}
    125 add_cat_to_add_queue('{$cat}', 0, {$RECURSIVE}, '{$FILLS}');
     125add_cat_to_add_queue('{$cat}', {$PARENT_CATEGORY}, {$RECURSIVE}, '{$FILLS}');
    126126{/foreach}
    127127
     
    137137<div class="warnings" style="display:none;">
    138138  <ul>
    139     <li>hohiho</li>
     139    <li>null</li>
    140140  </ul>
    141141</div>
    142142
    143143<p>
    144   <b>Nb albums</b>: <span class="nb_categories">0</span>/{$nb_categories}<br>
    145   <b>Nb pictures</b>: <span class="nb_pictures">0</span>/{$nb_pictures}<br>
    146   <b>Errors</b>: <span class="nb_errors">0</span><br>
     144  <b>{'Nb albums'|@translate}</b>: <span class="nb_categories">0</span>/{$nb_categories}<br>
     145  <b>{'Nb photos'|@translate}</b>: <span class="nb_pictures">0</span>/{$nb_pictures}<br>
     146  <b>{'Errors'|@translate}</b>: <span class="nb_errors">0</span><br>
    147147  <br>
    148148  <img class="loading" src="{$PBASE_PATH}admin/template/loader-{$themeconf.name}.gif">
  • extensions/pbase2piwigo/include/functions.inc.php

    r17225 r17314  
    309309 * @return: bool
    310310 */
    311 function test_remote_download()
    312 {
    313   return function_exists('curl_init') || ini_get('allow_url_fopen');
     311if (!function_exists('test_remote_download'))
     312{
     313  function test_remote_download()
     314  {
     315    return function_exists('curl_init') || ini_get('allow_url_fopen');
     316  }
    314317}
    315318
    316319/**
    317320 * download a remote file
    318  * @param: string source
    319  * @param: string destination
    320  * @return: bool
    321  */
    322 function download_remote_file($src, $dest)
    323 {
    324   if (function_exists('curl_init'))
    325   {
    326     $newf = fopen($dest, "wb");
    327     $ch = curl_init();
    328    
    329     curl_setopt($ch, CURLOPT_URL, $src);
    330     curl_setopt($ch, CURLOPT_HEADER, 0);
    331     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-language: en"));
    332     curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
    333     curl_setopt($ch, CURLOPT_FILE, $newf);
    334    
    335     if (curl_exec($ch) === false)
    336     {
    337       return 'file_error';
    338     }
    339    
    340     curl_close($ch);
    341     fclose($newf);
    342    
    343     return true;
    344   }
    345   else if (ini_get('allow_url_fopen'))
    346   {
    347     $opts = array(
    348       'http' => array(
    349         'method' => "GET",
    350         'user_agent' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
    351         'header' => "Accept-language: en",
    352       )
    353     );
    354 
    355     $context = stream_context_create($opts);
    356    
    357     if (($file = file_get_contents($src, false, $context)) === false)
    358     {
    359       return 'file_error';
    360     }
    361     file_put_contents($dest, $file);
    362    
    363     return true;
    364   }
    365  
    366   return false;
     321 *  - needs cURL or allow_url_fopen
     322 *  - take care of SSL urls
     323 *
     324 * @param: string source url
     325 * @param: mixed destination file (if true, file content is returned)
     326 */
     327if (!function_exists('download_remote_file'))
     328{
     329  function download_remote_file($src, $dest)
     330  {
     331    if (empty($src))
     332    {
     333      return false;
     334    }
     335   
     336    $return = ($dest === true) ? true : false;
     337   
     338    /* curl */
     339    if (function_exists('curl_init'))
     340    {
     341      if (!$return)
     342      {
     343        $newf = fopen($dest, "wb");
     344      }
     345      $ch = curl_init();
     346     
     347      curl_setopt($ch, CURLOPT_URL, $src);
     348      curl_setopt($ch, CURLOPT_HEADER, 0);
     349      curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-language: en"));
     350      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
     351      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     352      curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
     353      if (strpos($src, 'https://') !== false)
     354      {
     355        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     356        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     357      }
     358      if (!$return)
     359      {
     360        curl_setopt($ch, CURLOPT_FILE, $newf);
     361      }
     362      else
     363      {
     364        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     365      }
     366     
     367      if (($out = curl_exec($ch)) === false)
     368      {
     369        return 'file_error';
     370      }
     371     
     372      curl_close($ch);
     373     
     374      if (!$return)
     375      {
     376        fclose($newf);
     377        return true;
     378      }
     379      else
     380      {
     381        return $out;
     382      }
     383    }
     384    /* file get content */
     385    else if (ini_get('allow_url_fopen'))
     386    {
     387      if (strpos($src, 'https://') !== false and !extension_loaded('openssl'))
     388      {
     389        return false;
     390      }
     391     
     392      $opts = array(
     393        'http' => array(
     394          'method' => "GET",
     395          'user_agent' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
     396          'header' => "Accept-language: en",
     397        )
     398      );
     399
     400      $context = stream_context_create($opts);
     401     
     402      if (($file = file_get_contents($src, false, $context)) === false)
     403      {
     404        return 'file_error';
     405      }
     406     
     407      if (!$return)
     408      {
     409        file_put_contents($dest, $file);
     410        return true;
     411      }
     412      else
     413      {
     414        return $file;
     415      }
     416    }
     417   
     418    return false;
     419  }
    367420}
    368421
     
    397450 * @return: array
    398451 */
    399 function array_unique_deep(&$array, $key)
    400 {
    401   $values = array();
    402   foreach ($array as $k1 => $row)
    403   {
    404     foreach ($row as $k2 => $v)
    405     {
    406       if ($k2 == $key)
    407       {
    408         $values[ $k1 ] = $v;
    409         continue;
    410       }
    411     }
    412   }
    413   return array_unique($values);
     452if (!function_exists('array_unique_deep'))
     453{
     454  function array_unique_deep(&$array, $key)
     455  {
     456    $values = array();
     457    foreach ($array as $k1 => $row)
     458    {
     459      foreach ($row as $k2 => $v)
     460      {
     461        if ($k2 == $key)
     462        {
     463          $values[ $k1 ] = $v;
     464          continue;
     465        }
     466      }
     467    }
     468    return array_unique($values);
     469  }
    414470}
    415471
     
    423479 * @return key or array of keys
    424480 */
    425 function array_pos($needle, &$haystack, $match_all=false, $preg_mode=false)
    426 {
    427   if ($match_all) $matches = array();
    428  
    429   foreach ($haystack as $i => $row)
    430   {
    431     if (!is_array($row))
    432     {
    433       if (!$preg_mode)
    434       {
    435         if (strpos($row, $needle) !== false)
     481if (!function_exists('array_pos'))
     482{
     483  function array_pos($needle, &$haystack, $match_all=false, $preg_mode=false)
     484  {
     485    if ($match_all) $matches = array();
     486   
     487    foreach ($haystack as $i => $row)
     488    {
     489      if (!is_array($row))
     490      {
     491        if (!$preg_mode)
    436492        {
    437           if (!$match_all) return $i;
    438           else array_push($matches, $i);
     493          if (strpos($row, $needle) !== false)
     494          {
     495            if (!$match_all) return $i;
     496            else array_push($matches, $i);
     497          }
    439498        }
    440       }
    441       else
    442       {
    443         if (preg_match($needle, $row) === 1)
     499        else
    444500        {
    445           if (!$match_all) return $i;
    446           else array_push($matches, $i);
     501          if (preg_match($needle, $row) === 1)
     502          {
     503            if (!$match_all) return $i;
     504            else array_push($matches, $i);
     505          }
    447506        }
    448507      }
    449508    }
    450   }
    451  
    452   if ( !$match_all or !count($matches) ) return false;
    453   return $matches;
     509   
     510    if ( !$match_all or !count($matches) ) return false;
     511    return $matches;
     512  }
    454513}
    455514
  • extensions/pbase2piwigo/include/ws_functions.inc.php

    r17225 r17314  
    111111  $category = &get_current_cat($tree, $params['path']);
    112112 
    113   if ($category['path'] == '/root')
    114   {
    115     $category['title'] = 'Import PBase';
    116   }
    117  
    118113  // add category
    119114  $query = '
     
    143138    'pictures' => array(),
    144139    'categories' => array(),
    145     'message' => sprintf(l10n('Album "%s" added'), $category['title']),
     140    'message' => sprintf(l10n('Album "%s" created'), $category['title']),
    146141    );
    147142   
  • extensions/pbase2piwigo/language/en_UK/description.txt

    r17225 r17314  
    1 Extension for importing pictures from PBase
     1Import photos from PBase
  • extensions/pbase2piwigo/language/en_UK/plugin.lang.php

    r17225 r17314  
    11<?php
    22
    3 
     3$lang['No download method available. PBase2piwigo needs cURL extension or allow_url_fopen=true'] = 'No download method available. PBase2piwigo needs cURL extension or allow_url_fopen=true';
     4$lang['Import queue is empty'] = 'Import queue is empty';
     5$lang['Invalid user id'] = 'Invalid user id';
     6$lang['Album "%s" created'] = 'Album "%s" created';
     7$lang['Photo "%s" imported'] = 'Photo "%s" imported';
     8$lang['PBase login'] = 'PBase login';
     9$lang['Begin analyse'] = 'Begin analyse';
     10$lang['Select albums to import'] = 'Select albums to import';
     11$lang['Nb albums'] = 'Nb albums';
     12$lang['Nb photos'] = 'Nb photos';
     13$lang['Import in this album'] = 'Import in this album';
     14$lang['Fill these fields from pBase datas'] = 'Fill these fields from pBase datas';
     15$lang['%1$d errors occured. %2$d albums and %3$d photos added.'] = '%1$d errors occured. %2$d albums and %3$d photos added.';
     16$lang['Completed. %1$d albums and %2$d photos added.'] = 'Completed. %1$d albums and %2$d photos added.';
     17$lang['Errors'] = 'Errors';
     18$lang['Recursive'] = 'Recursive';
     19$lang['Begin transfer'] = 'Begin transfer';
    420
    521?>
  • extensions/pbase2piwigo/language/fr_FR/description.txt

    r17225 r17314  
    1 Extension pour importer des photos depuis PBase
     1Importez des photos depuis PBase
  • extensions/pbase2piwigo/language/fr_FR/plugin.lang.php

    r17225 r17314  
    11<?php
    22
     3$lang['No download method available. PBase2piwigo needs cURL extension or allow_url_fopen=true'] = 'Aucune fonction de téléchargement disponible. PBase2Piwigo a besoin de l\'extension cURL ou du réglage allow_url_fopen=true';
     4$lang['Import queue is empty'] = 'File d\'attente vide';
     5$lang['Invalid user id'] = 'Identifiant invdalie';
     6$lang['Album "%s" created'] = 'Album "%s" créé';
     7$lang['Photo "%s" imported'] = 'Photo "%s" importée';
     8$lang['PBase login'] = 'Identifiant PBase';
     9$lang['Begin analyse'] = 'Démarre l\'analyse';
     10$lang['Select albums to import'] = 'Selectionnez les albums à importer';
     11$lang['Nb albums'] = 'Nb d\'albums';
     12$lang['Nb photos'] = 'Nb de photos';
     13$lang['Import in this album'] = 'Importer dans cet album';
     14$lang['Fill these fields from pBase datas'] = 'Remplir ces champs à partir des données de PBase';
     15$lang['%1$d errors occured. %2$d albums and %3$d photos added.'] = '%1$d erreurs. %2$d albums et %3$d photos ajoutés.';
     16$lang['Completed. %1$d albums and %2$d photos added.'] = 'Terminé. %1$d albums et %2$d photos ajoutés.';
     17$lang['Errors'] = 'Erreurs';
     18$lang['Recursive'] = 'Recursif';
     19$lang['Begin transfer'] = 'Démarrer le transfert';
    320
    421
  • extensions/pbase2piwigo/main.inc.php

    r17225 r17314  
    33Plugin Name: PBase2Piwigo
    44Version: auto
    5 Description: Extension for importing pictures from PBase
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
     5Description: Import photos from PBase
     6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=627
    77Author: Mistic
    88Author URI: http://www.strangeplanet.fr
Note: See TracChangeset for help on using the changeset viewer.