Index: /extensions/pbase2piwigo/admin.php
===================================================================
--- /extensions/pbase2piwigo/admin.php	(revision 17225)
+++ /extensions/pbase2piwigo/admin.php	(revision 17225)
@@ -0,0 +1,35 @@
+<?php
+if (!defined('PBASE_PATH')) die('Hacking attempt!');
+
+global $template, $page, $conf;
+
+// $conf['pbase2piwigo'] = unserialize($conf['pbase2piwigo']);
+load_language('plugin.lang', PBASE_PATH);
+
+if (!file_exists(PBASE_FS_CACHE))
+{
+  mkdir(PBASE_FS_CACHE, 0755);
+}
+
+// tabsheet
+include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
+$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'import';
+  
+$tabsheet = new tabsheet();
+$tabsheet->add('import', l10n('Import'), PBASE_ADMIN . '-import');
+// $tabsheet->add('config', l10n('Configuration'), PBASE_ADMIN . '-config');
+$tabsheet->select($page['tab']);
+$tabsheet->assign();
+
+// include page
+include(PBASE_PATH . 'admin/' . $page['tab'] . '.php');
+
+// template
+$template->assign(array(
+  'PBASE_PATH'=> PBASE_PATH,
+  'PBASE_ABS_PATH'=> dirname(__FILE__).'/',
+  'PBASE_ADMIN' => PBASE_ADMIN,
+  ));
+$template->assign_var_from_handle('ADMIN_CONTENT', 'pbase2piwigo');
+
+?>
Index: /extensions/pbase2piwigo/admin/config.php
===================================================================
--- /extensions/pbase2piwigo/admin/config.php	(revision 17225)
+++ /extensions/pbase2piwigo/admin/config.php	(revision 17225)
@@ -0,0 +1,24 @@
+<?php
+if (!defined('FLICKR_PATH')) die('Hacking attempt!');
+
+if (isset($_POST['save_config']))
+{
+  $conf['flickr2piwigo'] = array(
+    'api_key' => trim($_POST['api_key']),
+    'secret_key' => trim($_POST['secret_key']),
+    );
+  unset($_SESSION['phpFlickr_auth_token']);
+  conf_update_param('flickr2piwigo', serialize($conf['flickr2piwigo']));
+}
+
+
+$template->assign(array(
+  'flickr2piwigo' => $conf['flickr2piwigo'],
+  'FLICKR_HELP_CONTENT' => load_language('help_api_key.html', FLICKR_PATH, array('return'=>true)),
+  'FLICKR_CALLBACK' => get_absolute_root_url() . FLICKR_ADMIN . '-import',
+  ));
+
+
+$template->set_filename('flickr2piwigo', dirname(__FILE__) . '/template/config.tpl');
+
+?>
Index: /extensions/pbase2piwigo/admin/import.php
===================================================================
--- /extensions/pbase2piwigo/admin/import.php	(revision 17225)
+++ /extensions/pbase2piwigo/admin/import.php	(revision 17225)
@@ -0,0 +1,101 @@
+<?php
+if (!defined('PBASE_PATH')) die('Hacking attempt!');
+
+include_once(PBASE_PATH.'include/functions.inc.php');
+
+$step = null;
+
+if (test_remote_download() === false)
+{
+  array_push($page['errors'], l10n('No download method available. PBase2piwigo needs cURL extension or allow_url_fopen=true'));
+}
+else
+{
+  if (isset($_GET['action']))
+  {
+    switch ($_GET['action'])
+    {
+      case 'reset_tree':
+        unlink(PBASE_FS_CACHE.'tree.json');
+        redirect(PBASE_ADMIN.'-import');
+        break;
+    }
+  }
+  else
+  {
+    if (!file_exists(PBASE_FS_CACHE.'tree.json'))
+    {
+      $_GET['action'] = 'analyze';
+    }
+    else
+    {
+      $_GET['action'] = 'config';
+    }
+  }
+  
+  if (file_exists(PBASE_FS_CACHE.'tree.json'))
+  {
+    $tree = json_decode(file_get_contents(PBASE_FS_CACHE.'tree.json'), true);
+  }
+}
+
+
+switch ($_GET['action'])
+{
+  case 'analyze':
+  {
+    break;
+  }
+  
+  case 'config':
+  {
+    $template->assign(array(
+      'F_ACTION' => PBASE_ADMIN.'-import&amp;action=init_import',
+      'RESET_LINK' => PBASE_ADMIN.'-import&amp;action=reset_tree',
+      'TREE' => print_tree($tree, 0, 'select'),
+      ));
+    break;
+  }
+  
+  case 'init_import':
+  {
+    $categories = $_POST['categories'];
+    
+    // remove duplicate categories (in case of recursive mode)
+    if (isset($_POST['recursive']))
+    {
+      foreach ($categories as &$path)
+      {
+        if ( ($matches = array_pos('#'.$path.'/([\w/]+)#', $categories, true, true)) !== false)
+        {
+          foreach ($matches as $i) unset($categories[$i]);
+        }
+      }
+      unset($path);
+    }
+    
+    // count pictures and cats
+    $temp_cats = $categories;
+    $nb_categories = $nb_pictures = 0;
+    foreach ($temp_cats as $path)
+    {
+      count_pictures_cats($tree, $path, $nb_pictures, $nb_categories, isset($_POST['recursive']));
+    }
+    
+    $template->assign(array(
+      'nb_pictures' => $nb_pictures,
+      'nb_categories' => $nb_categories,
+      'categories' => $categories,
+      'RECURSIVE' => boolean_to_string(isset($_POST['recursive'])),
+      'FILLS' => implode(',', @$_POST['fills']),
+      'MANAGE_LINK' => get_root_url().'admin.php?page=batch_manager&amp;cat=recent',
+      ));
+    break;
+  }
+}
+
+$template->assign('STEP', $_GET['action']);
+
+$template->set_filename('pbase2piwigo', dirname(__FILE__) . '/template/import.tpl');
+
+?>
Index: /extensions/pbase2piwigo/admin/index.php
===================================================================
--- /extensions/pbase2piwigo/admin/index.php	(revision 17225)
+++ /extensions/pbase2piwigo/admin/index.php	(revision 17225)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/pbase2piwigo/admin/template/MultiGetSet.js
===================================================================
--- /extensions/pbase2piwigo/admin/template/MultiGetSet.js	(revision 17225)
+++ /extensions/pbase2piwigo/admin/template/MultiGetSet.js	(revision 17225)
@@ -0,0 +1,144 @@
+// https://gist.github.com/2956493
+
+/**
+ July 30th 2012
+ Damien "Mistic"Sorel
+ add increment() and decrement() methods
+ */
+
+var MultiGetSet = function(opt){
+
+    var getType = function(o) {
+      return ({}).toString.call(o).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
+    };
+
+    if(!opt.public || !opt.private)
+        return opt.public;
+
+    if(opt.handler && opt.handler.init)
+        opt.handler.init(opt);
+
+    if(!opt.handler || !opt.handler.setter){
+        opt.public.set = function(paramName, newValue){
+            opt.private[paramName] = newValue;
+        };
+    }else{
+        opt.public.set = function(paramName, newValue){
+            return opt.handler.setter({
+                public: opt.public,
+                private: opt.private,
+                paramName: paramName,
+                newValue: newValue,
+                caller: arguments.callee.caller
+            });
+        };
+    }
+
+    if(!opt.handler || !opt.handler.getter){
+        opt.public.get = function(paramName){
+            return opt.private[paramName];
+        };
+    }else{
+        opt.public.get = function(paramName){
+            return opt.handler.getter({
+                public: opt.public,
+                private: opt.private,
+                paramName: paramName,
+                caller: arguments.callee.caller
+            });
+        };
+    }
+    
+    if(!opt.handler || !opt.handler.adder){
+        opt.public.add = function(paramName, newValue){
+            if(getType(opt.private[paramName])==="array")
+                opt.private[paramName].push(newValue);
+        };
+    }else{
+        opt.public.add = function(paramName, newValue){
+            if(getType(opt.private[paramName])==="array")
+                return opt.handler.adder({
+                    public: opt.public,
+                    private: opt.private,
+                    paramName: paramName,
+                    newValue: newValue,
+                    caller: arguments.callee.caller
+                });
+        };
+    }
+    
+    opt.public.increment = function(paramName, add) {
+      if (add == null) add = 1;
+      opt.public.set(paramName, opt.public.get(paramName)+add);
+    };
+    
+    opt.public.decrement = function(paramName, rem) {
+      if (rem == null) rem = 1;
+      opt.public.increment(paramName, -rem);
+    };
+
+    return opt.public;
+};
+
+var Observable = {
+
+
+    clone: function(o){
+        if(o == null || typeof(o) != 'object')
+            return o;
+
+        var temp = o.constructor(); // changed
+
+        for(var key in o)
+            temp[key] = Observable.clone(o[key]);
+        return temp;
+    },
+
+    init: function(opt){
+        opt.public.listeners = {};
+
+        opt.public.listen = function(paramName, callback){
+            if(Object.prototype.toString.call(paramName) === '[object Array]')
+                for(var p in paramName){
+                    opt.public.listenOne(paramName[p], callback);
+                }
+            else
+                opt.public.listenOne(paramName, callback);
+        };
+
+        opt.public.listenOne = function(paramName, callback){
+            if(!opt.public.listeners[paramName])
+                opt.public.listeners[paramName] = [];
+            opt.public.listeners[paramName].push(callback);
+        };
+    },
+
+    setter: function(opt){
+        if(opt.private[opt.paramName] == opt.newValue)
+            return;
+
+        opt.oldValue = Observable.clone(opt.private[opt.paramName]);
+
+        opt.private[opt.paramName] = opt.newValue;
+
+        for(var listener in opt.public.listeners[opt.paramName]){
+            if(opt.caller != opt.public.listeners[opt.paramName][listener])
+                opt.public.listeners[opt.paramName][listener](opt);
+        }
+    },
+
+    adder: function(opt){
+        if(opt.private[opt.paramName] == opt.newValue || !opt.private[opt.paramName].push)
+            return;
+
+        opt.oldValue = Observable.clone(opt.private[opt.paramName]);
+
+        opt.private[opt.paramName].push(opt.newValue);
+        opt.newValue = opt.private[opt.paramName];
+
+        for(var listener in opt.public.listeners[opt.paramName]){
+            if(opt.caller != opt.public.listeners[opt.paramName][listener])
+                opt.public.listeners[opt.paramName][listener](opt);
+        }
+    }
+};
Index: /extensions/pbase2piwigo/admin/template/config.tpl
===================================================================
--- /extensions/pbase2piwigo/admin/template/config.tpl	(revision 17225)
+++ /extensions/pbase2piwigo/admin/template/config.tpl	(revision 17225)
@@ -0,0 +1,37 @@
+{combine_css path=$FLICKR_PATH|@cat:"admin/template/style.css"}
+
+<div class="titrePage">
+	<h2>Flickr2Piwigo</h2>
+</div>
+
+<form method="post" action="" class="properties">
+<fieldset>
+  <legend>{'Flickr logins'|@translate}</legend>
+  
+  <ul>
+    <li>
+      <label>
+        <span class="property">{'API key'|@translate}</span>
+        <input type="text" name="api_key" value="{$flickr2piwigo.api_key}" size="40">
+      </label>
+    </li>
+
+    <li>
+      <label>
+        <span class="property">{'API secret'|@translate}</span>
+        <input type="text" name="secret_key" value="{$flickr2piwigo.secret_key}" size="20">
+      </label>
+    </li>
+  </ul>
+</fieldset>
+
+<p><input type="submit" name="save_config" value="{'Save Settings'|@translate}"></p>
+
+<fieldset>
+  <legend>{'How do I get my Flickr API key?'|@translate}</legend>
+  
+  <p><b>{'Callback URL'|@translate} :</b> <span style="font-family:monospace;font-size:14px;">{$FLICKR_CALLBACK}</span></p>
+  {$FLICKR_HELP_CONTENT}
+</fieldset>
+  
+</form>
Index: /extensions/pbase2piwigo/admin/template/import.analyze.tpl
===================================================================
--- /extensions/pbase2piwigo/admin/template/import.analyze.tpl	(revision 17225)
+++ /extensions/pbase2piwigo/admin/template/import.analyze.tpl	(revision 17225)
@@ -0,0 +1,70 @@
+{combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
+{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js'}
+{combine_css path="admin/themes/default/uploadify.jGrowl.css"}
+
+{footer_script require='jquery.ajaxmanager,jquery.jgrowl'}
+var errorHead   = '{'ERROR'|@translate|@escape:'javascript'}';
+var errorMsg    = '{'an error happened'|@translate|@escape:'javascript'}';
+var successHead = '{'Success'|@translate|@escape:'javascript'}';
+
+{literal}
+var queue_lenght = 0;
+
+var queuedManager = jQuery.manageAjax.create('queued', {
+  queue: true,  
+  maxRequests: 1
+});
+
+function add_cat_to_parse_queue(url, path) {
+  queuedManager.add({
+    type: 'POST',
+    dataType: 'json',
+    url: 'ws.php?format=json',
+    data: { method: 'pwg.pBase.parse', url: url, path: path },
+    success: function(data) {
+      if (data['stat'] == 'ok') {
+        cats = data['result']['categories'];
+        for (i in cats) {
+          queue_lenght++;
+          add_cat_to_parse_queue(cats[i]['url'], cats[i]['path']);
+        }
+        $('#preview').html($('#preview').html()+data['result']['path']+"\n");
+      } else {
+        jQuery.jGrowl(data['message'], { theme: 'error', header: errorHead, sticky: true });
+        jQuery('.loading').toggle();
+      }
+      
+      queue_lenght--; 
+      if (data['stat'] == 'ok' && queue_lenght == 0) {
+        window.location.reload();
+      }
+    },
+    error: function () {
+      jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true });
+      jQuery('.loading').toggle();
+    }
+  });
+}
+{/literal}
+
+jQuery('#begin_analyse').click(function() {ldelim}
+  login = $('#pbase_login').val();
+  
+  if (login != '') {ldelim}
+    queue_lenght++;
+    add_cat_to_parse_queue('http://www.pbase.com/'+ login +'/root', '/root');
+    jQuery('.loading').toggle();
+  }
+  return false;
+});
+{/footer_script}
+
+
+<form action="{$PBASE_ADMIN}-import" method="post">
+<p><label>{'PBase login'|@translate} <input type="text" id="pbase_login"></label></p>
+<p class="loading"><input type="submit" id="begin_analyse" value="{'Begin analyse'|@translate}"></p>
+<p class="loading" style="display:none;"><img src="{$PBASE_PATH}admin/template/loader-{$themeconf.name}.gif"></p>
+</form>
+
+<pre id="preview">
+</pre>
Index: /extensions/pbase2piwigo/admin/template/import.config.tpl
===================================================================
--- /extensions/pbase2piwigo/admin/template/import.config.tpl	(revision 17225)
+++ /extensions/pbase2piwigo/admin/template/import.config.tpl	(revision 17225)
@@ -0,0 +1,39 @@
+{footer_script require='jquery.ui.resizable'}{literal}
+jQuery(".categoryList").resizable({
+  handles: "s,e,se",
+  animate: true,
+  autoHide: true,
+  ghost: true
+});
+{/literal}{/footer_script}
+
+<form action="{$F_ACTION}" method="post">
+<fieldset>
+  <legend>{'Choose albums to import'|@translate}</legend>
+  
+  <select name="categories[]" class="categoryList" multiple="multiple" size="20">
+    {$TREE}
+  </select>
+  
+  <br>
+  <a href="{$RESET_LINK}" onClick="return confirm('{'Are you sure?'|@translate}');">Reset</a>
+</fieldset>
+
+<fieldset>
+  <legend>{'Configuration'|@translate}</legend>
+  
+  <p><label><input type="checkbox" name="recursive" value="1" checked="checked"> <b>Recursive</b></label></p>
+  <p>
+    <b>{'Fill these fields from pBase datas'|@translate}:</b>
+    <label><input type="checkbox" name="fills[]" value="fill_name" checked="checked"> {'Photo name'|@translate}</label>
+    <label><input type="checkbox" name="fills[]" value="fill_author" checked="checked"> {'Author'|@translate}</label>
+    <label><input type="checkbox" name="fills[]" value="fill_tags" checked="checked"> {'Tags'|@translate}</label>
+    <label><input type="checkbox" name="fills[]" value="fill_taken" checked="checked"> {'Creation date'|@translate}</label>
+    <label><input type="checkbox" name="fills[]" value="fill_comment" checked="checked"> {'Description'|@translate}</label>
+  </p>
+</fieldset>
+
+  <p class="bottomButtons">
+    <input type="submit" value="Begin Transfer">    
+  </p>
+</form>
Index: /extensions/pbase2piwigo/admin/template/import.init_import.tpl
===================================================================
--- /extensions/pbase2piwigo/admin/template/import.init_import.tpl	(revision 17225)
+++ /extensions/pbase2piwigo/admin/template/import.init_import.tpl	(revision 17225)
@@ -0,0 +1,151 @@
+{combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
+{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js'}
+{combine_script id='MultiGetSet' load='header' path=$PBASE_PATH|cat:'admin/template/MultiGetSet.js'}
+{combine_css path="admin/themes/default/uploadify.jGrowl.css"}
+
+{footer_script require='jquery.ajaxmanager,jquery.jgrowl'}
+var errorHead   = '{'ERROR'|@translate|@escape:'javascript'}';
+var errorMsg    = '{'an error happened'|@translate|@escape:'javascript'}';
+var successHead = '{'Success'|@translate|@escape:'javascript'}';
+var errors_final_msg = '{'%1$d errors occured. %2$d albums and %3$d photos added.'|@translate}';
+
+{literal}
+// custom classe for counters listening
+var MyClass = function(){
+  var public = this;
+  var private = {};
+  
+  private.lenght = 0;
+  private.errors = 0;
+  private.categories = 0;
+  private.pictures = 0;
+  
+  MultiGetSet({
+    public: public,
+    private: private,
+    handler: Observable
+  });
+};
+
+var queue = new MyClass();
+
+queue.listen("lenght", function(opt){
+  if (opt.newValue == 0) {
+    $(".loading").css('display', 'none');
+    if (queue.get("errors") == 0) {
+      $(".infos").css('display', 'block');
+    } else {
+      errors_final_msg = errors_final_msg.replace('%1$d', queue.get("errors"));
+      errors_final_msg = errors_final_msg.replace('%2$d', queue.get("categories"));
+      errors_final_msg = errors_final_msg.replace('%3$d', queue.get("pictures"));
+      
+      $(".warnings").css('display', '').html('<ul><li>'+ errors_final_msg +'</li></ul>');
+    }
+  }
+});
+queue.listen("categories", function(opt) {
+  $(".nb_categories").html(opt.newValue);
+});
+queue.listen("pictures", function(opt) {
+  $(".nb_pictures").html(opt.newValue);
+});
+queue.listen("errors", function(opt) {
+  $(".nb_errors").html(opt.newValue);
+});
+
+
+var queuedManager = jQuery.manageAjax.create('queued', {
+  queue: true,  
+  maxRequests: 1
+});
+
+function add_cat_to_add_queue(path, parent_id, recursive, fills) {
+  queuedManager.add({
+    type: 'POST',
+    dataType: 'json',
+    url: 'ws.php?format=json',
+    data: { method: 'pwg.pBase.addCat', path: path, parent_id: parent_id, recursive: recursive },
+    success: function(data) {
+      if (data['stat'] == 'ok') {
+        data = data['result'];
+        
+        for (i in data['pictures']) {
+          queue.increment("lenght");
+          add_picture_to_add_queue(data['pictures'][i], data['category_id'], fills);
+        }
+        if (recursive) {
+          for (i in data['categories']) {
+            queue.increment("lenght");
+            add_cat_to_add_queue(data['categories'][i], data['category_id'], recursive, fills);
+          }
+        }
+        
+        jQuery.jGrowl(data['message'], { theme: 'success', header: successHead, life: 2000, sticky: false });
+        queue.increment("categories");
+      } else {
+        jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true });
+        queue.increment("errors");
+      }
+      
+      queue.decrement("lenght");
+    },
+    error: function () {
+      jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true });
+      queue.increment("errors");
+    }
+  });
+}
+
+function add_picture_to_add_queue(url, cat_id, fills) {
+  queuedManager.add({
+    type: 'POST',
+    dataType: 'json',
+    url: 'ws.php?format=json',
+    data: { method: 'pwg.pBase.addImage', url: url, category: cat_id, fills: fills },
+    success: function(data) {
+      if (data['stat'] == 'ok') {
+        jQuery.jGrowl(data['result'], { theme: 'success', header: successHead, life: 2000, sticky: false });
+        queue.increment("pictures");
+      } else {
+        jQuery.jGrowl(data['result'], { theme: 'error', header: errorHead, sticky: true });
+        queue.increment("errors");
+      }
+      
+      queue.decrement("lenght");
+    },
+    error: function () {
+      jQuery.jGrowl(errorMsg, { theme: 'error', header: errorHead, sticky: true });
+      queue.increment("errors");
+    }
+  });
+}
+{/literal}
+
+{foreach from=$categories item=cat}
+add_cat_to_add_queue('{$cat}', 0, {$RECURSIVE}, '{$FILLS}');
+{/foreach}
+
+queue.set("lenght", {$categories|@count});
+{/footer_script}
+
+
+<div class="infos" style="display:none;">
+  <ul>
+    <li>{'Completed. %1$d albums and %2$d photos added.'|@translate|sprintf:$nb_categories:$nb_pictures}</li>
+  </ul>
+</div>
+<div class="warnings" style="display:none;">
+  <ul>
+    <li>hohiho</li>
+  </ul>
+</div>
+
+<p>
+  <b>Nb albums</b>: <span class="nb_categories">0</span>/{$nb_categories}<br>
+  <b>Nb pictures</b>: <span class="nb_pictures">0</span>/{$nb_pictures}<br>
+  <b>Errors</b>: <span class="nb_errors">0</span><br>
+  <br>
+  <img class="loading" src="{$PBASE_PATH}admin/template/loader-{$themeconf.name}.gif">
+</p>
+
+{* <a href="{$MANAGE_LINK}">{'Manage this set of %d photos'|@translate|sprintf:$nb_pictures}</a> *}
Index: /extensions/pbase2piwigo/admin/template/import.tpl
===================================================================
--- /extensions/pbase2piwigo/admin/template/import.tpl	(revision 17225)
+++ /extensions/pbase2piwigo/admin/template/import.tpl	(revision 17225)
@@ -0,0 +1,18 @@
+{combine_css path=$PBASE_PATH|@cat:"admin/template/style.css"}
+
+
+<div class="titrePage">
+	<h2>PBase2Piwigo</h2>
+</div>
+
+
+{if $STEP == 'analyze'}
+{include file=$PBASE_ABS_PATH|@cat:'admin/template/import.analyze.tpl'}
+
+{elseif $STEP == 'config'}
+{include file=$PBASE_ABS_PATH|@cat:'admin/template/import.config.tpl'}
+
+{elseif $STEP == 'init_import'}
+{include file=$PBASE_ABS_PATH|@cat:'admin/template/import.init_import.tpl'}
+ 
+{/if}
Index: /extensions/pbase2piwigo/admin/template/index.php
===================================================================
--- /extensions/pbase2piwigo/admin/template/index.php	(revision 17225)
+++ /extensions/pbase2piwigo/admin/template/index.php	(revision 17225)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/pbase2piwigo/include/functions.inc.php
===================================================================
--- /extensions/pbase2piwigo/include/functions.inc.php	(revision 17225)
+++ /extensions/pbase2piwigo/include/functions.inc.php	(revision 17225)
@@ -0,0 +1,456 @@
+<?php
+if (!defined('PBASE_PATH')) die('Hacking attempt!');
+
+/**
+ * get the content of web-page, with cache management
+ * @param: string url
+ * @return: string
+ */
+function get_file_cached($url)
+{
+  // html files are cached 10000 seconds
+  $cache_id_prefix = str_replace('http://www.pbase.com/', null, $url);
+  $cache_id_prefix = preg_replace('#([^a-z0-9]+)#i', null, $cache_id_prefix);
+  $cache_id = $cache_id_prefix.'-'.substr(time(), 0, -4);
+  
+  if (!file_exists(PBASE_FS_CACHE.$cache_id))
+  {
+    $files = glob(PBASE_FS_CACHE.$cache_id_prefix.'-*');
+    foreach ($files as $file) unlink($file);
+    
+    if (($result = download_remote_file($url, PBASE_FS_CACHE.$cache_id)) !== true)
+    {
+      return $result;
+    }
+  }
+  
+  $html = file_get_contents(PBASE_FS_CACHE.$cache_id);
+  
+  return utf8_encode($html);
+}
+
+/**
+ * helper to navigate throught the tree
+ * @param: &array tree
+ * @param: string path
+ * @return: reference to a branch of the tree
+ */
+function &get_current_cat(&$tree, $path)
+{
+  if (empty($path)) return $tree;
+  
+  $path = ltrim($path, '/');
+  $path = explode('/', $path);
+  $current = &$tree[ $path[0] ];
+  array_shift($path);
+  
+  foreach ($path as $folder)
+  {
+    $current = &$current['categories'][$folder];
+  }
+  
+  return $current;
+}
+
+/**
+ * check if give account (http://pbase.com/login/root) exists
+ * @param: string url
+ * @return: bool
+ */
+function check_account($url)
+{
+  $html = get_file_cached($url);
+  return !(bool)preg_match('#<h2>Unknown Account</h2>#i', $html);
+}
+
+/**
+ * parse a category page
+ * @param: string category url
+ * @param: bool parse only sub-categories
+ * @param: bool parse only one level
+ * @return: array category
+ */
+function parse_category($url, $path, $cats_only=false, $one_level=false)
+{
+  $url = str_replace('&page=all', null, $url);
+  
+  $current = array(
+    'url' => $url,
+    'path' => null,
+    'id' => null,
+    );
+    
+  // id
+  $temp = parse_url($url);
+  $temp = explode('/', $temp['path']);
+  $current['id'] = $temp[ count($temp)-1 ];
+  $current['path'] = $path.'/'.$current['id'];
+  
+  if ($one_level === 'stop')
+  {
+    return $current;
+  }
+    
+  $current = array_merge($current, array(
+    'title' => null,
+    'description' => null,
+    'pictures' => array(),
+    'categories' => array(),
+    'nb_pictures' => 0,
+    'nb_categories' => 0, 
+    ));
+    
+  
+  $url.= '&page=all'; // seriously... (should be ? not &)
+  
+  
+  $html = get_file_cached($url);
+  if ($html == 'file_error')
+  {
+    return $current;
+  }
+  
+  preg_match('#<body>(.*)</body>#is', $html, $matches);
+  $body = $matches[1];
+  
+  // content
+  // if (preg_match('#<CENTER>(.*)</CENTER>#is', $body, $matches) === 0) return 'null1';
+  if (preg_match_all('#<A HREF="([^">]*)" class="thumbnail">#i', $body, $matches) === 0) return $current;
+  $links = $matches[1];
+  
+  // title
+  if (preg_match('#<h2>(.*?)</h2>#i', $body, $matches))
+  {
+    $current['title'] = trim($matches[1]);
+  }
+  else
+  {
+    $current['title'] = $current['id'];
+  }
+  
+  // description
+  if (preg_match('#<!-- BEGIN user desc -->(.*?)<!-- END user desc -->#s', $body, $matches))
+  {
+    $current['description'] = trim($matches[1]);
+  }
+  
+  // sub-cats and pictures
+  foreach ($links as $link)
+  {
+    if (strpos($link, '/image/') !== false)
+    {
+      if (($image = parse_image($link, $cats_only)) !== null)
+      {
+        $current['pictures'][ $image['id'] ] = $image;
+      }
+      $current['nb_pictures']++;
+    }
+    else
+    {
+      $next_level = ($one_level === true) ? 'stop' : false;
+      if (($category = parse_category($link, $current['path'], $cats_only, $next_level)) !== null)
+      {
+        $current['categories'][ $category['id'] ] = $category;
+      }
+      $current['nb_categories']++;
+    }
+  }
+  
+  return $current;
+}
+
+/**
+ * parse a picture page
+ * @param: string picture url
+ * @param: bool return only url and id
+ * @return: array picture
+ */
+function parse_image($url, $light=false)
+{
+  $url = preg_replace('#/(small|medium|large|original)$#', null, $url);
+  
+  $current = array(
+    'url' => $url,
+    'id' => null,
+    );
+    
+  // id
+  $temp = parse_url($url);
+  $temp = explode('/', $temp['path']);
+  $current['id'] = $temp[ count($temp)-1 ];
+  
+  if ($light)
+  {
+    return $current;
+  }
+  
+  $current = array_merge($current, array(
+    'title' => null,
+    'path' => null,
+    'description' => null,
+    'date' => null,
+    'author' => null,
+    'keywords' => array(),
+    ));
+    
+  $url.= '/original';
+  
+  
+  $html = get_file_cached($url);
+  if ($html == 'file_error')
+  {
+    return $current;
+  }
+  
+  preg_match('#<body>(.*)</body>#is', $html, $matches);
+  $body = $matches[1];
+  
+  // path
+  if (preg_match('#<IMG ([^>]*)class="display" src="([^">]*)"#i', $body, $matches) ===0) return null;
+  $current['path'] = $matches[2];
+  
+  // title
+  preg_match('#<span class="title">(.*?)</span>#i', $body, $matches);
+  if (!empty($matches[1]))
+  {
+    $current['title'] = trim($matches[1]);
+    $current['title'] = get_filename_wo_extension($current['title']);
+  }
+  else
+  {
+    $current['title'] = $current['id'];
+  }
+  
+  // description
+  if (preg_match('#<p class="caption">(.*?)</p>#is', $body, $matches))
+  {
+    $current['description'] = trim($matches[1]);
+  }
+  
+  // date
+  if (preg_match('#<span class=date>(.*?)</span>#i', $body, $matches))
+  {
+    $current['date'] = trim($matches[1]);
+  }
+  
+  // author
+  if (preg_match('#<span class=artist>(.*?)</span>#i', $body, $matches))
+  {
+    $current['author'] = trim($matches[1]);
+  }
+  
+  
+  preg_match('#<head>(.*)</head>#is', $html, $matches);
+  $head = $matches[1];
+  
+  // keywords
+  if (preg_match('#<meta name="keywords" content="([^">]*)">#i', $head, $matches))
+  {
+    $words = explode(',', $matches[1]);
+    foreach ($words as $word)
+    {
+      if (!empty($word)) $current['keywords'][] = trim($word);
+    }
+  }
+  
+  return $current;
+}
+
+/**
+ * print categories tree (list or select)
+ * @param: array tree
+ * @param: int level
+ * @param: string tree type (list|select)
+ * @return: string
+ */
+function print_tree(&$tree, $level=0, $type='list')
+{
+  $out = '';
+  
+  if ($type == 'list')
+  {
+    $out.= '<ul>';
+    foreach ($tree as $item)
+    {
+      $out.= '<li>';
+      $out.= '<a href="'.$item['url'].'">'.$item['title'].'</a> ['.$item['nb_pictures'].']';
+      if (!empty($item['categories']))
+        $out.= print_tree($item['categories'], $level+1, 'list');
+      $out.= '</li>';
+    }
+    $out.= '</ul>';
+  }
+  else if ($type == 'select')
+  {
+    $i=0;
+    foreach ($tree as $item)
+    {
+      $out.= '<option value="'.$item['path'].'"';
+      if ($level==0 and $i==0) $out.= ' selected="selected"';
+      $out.= '>';
+      
+      $out.= str_repeat('&nbsp;', $level*4);
+      $out.= '- '.$item['title'].' ['.$item['nb_pictures'].']';
+      
+      $out.= '</option>';
+      
+      if (!empty($item['categories']))
+        $out.= print_tree($item['categories'], $level+1, 'select');
+        
+      $i++;
+    }
+  }
+  
+  return $out;
+}
+
+/**
+ * test if a download method is available
+ * @return: bool
+ */
+function test_remote_download()
+{
+  return function_exists('curl_init') || ini_get('allow_url_fopen');
+}
+
+/**
+ * download a remote file
+ * @param: string source
+ * @param: string destination
+ * @return: bool
+ */
+function download_remote_file($src, $dest)
+{
+  if (function_exists('curl_init'))
+  {
+    $newf = fopen($dest, "wb");
+    $ch = curl_init();
+    
+    curl_setopt($ch, CURLOPT_URL, $src);
+    curl_setopt($ch, CURLOPT_HEADER, 0);
+    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept-language: en"));
+    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
+    curl_setopt($ch, CURLOPT_FILE, $newf);
+    
+    if (curl_exec($ch) === false)
+    {
+      return 'file_error';
+    }
+    
+    curl_close($ch);
+    fclose($newf);
+    
+    return true;
+  }
+  else if (ini_get('allow_url_fopen'))
+  {
+    $opts = array(
+      'http' => array(
+        'method' => "GET",
+        'user_agent' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)',
+        'header' => "Accept-language: en",
+      )
+    );
+
+    $context = stream_context_create($opts);
+    
+    if (($file = file_get_contents($src, false, $context)) === false)
+    {
+      return 'file_error';
+    }
+    file_put_contents($dest, $file);
+    
+    return true;
+  }
+  
+  return false;
+}
+
+/**
+ * count pictures and cats in the selected cat
+ * @param: &array tree
+ * @param: string $path
+ * @param: &int nb pictures
+ * @param: &int nb categories
+ * @param: bool recursive
+ * @return: void
+ */
+function count_pictures_cats(&$tree, $path, &$nb_pictures, &$nb_categories, $recursive=true)
+{
+  $current = &get_current_cat($tree, $path);
+  $nb_pictures+= $current['nb_pictures'];
+  $nb_categories++;
+  
+  if ( $recursive and !empty($current['categories']) )
+  {
+    foreach ($current['categories'] as $cat)
+    {
+      count_pictures_cats($tree, $cat['path'], $nb_pictures, $nb_categories, $recursive);
+    }
+  }
+}
+
+/**
+ * extract unique values of the specified key in a two dimensional array
+ * @param: array
+ * @param: mixed key name
+ * @return: array
+ */
+function array_unique_deep(&$array, $key)
+{
+  $values = array();
+  foreach ($array as $k1 => $row)
+  {
+    foreach ($row as $k2 => $v)
+    {
+      if ($k2 == $key)
+      {
+        $values[ $k1 ] = $v;
+        continue;
+      }
+    }
+  }
+  return array_unique($values);
+}
+
+/**
+ * search a string in array values
+ * // http://www.strangeplanet.fr/blog/dev/php-une-fonction-pour-rechercher-dans-un-tableau
+ * @param string needle
+ * @param array haystack
+ * @param bool return all instances
+ * @param bool search in PCRE mode
+ * @return key or array of keys
+ */
+function array_pos($needle, &$haystack, $match_all=false, $preg_mode=false)
+{
+  if ($match_all) $matches = array();
+  
+  foreach ($haystack as $i => $row)
+  {
+    if (!is_array($row))
+    {
+      if (!$preg_mode)
+      {
+        if (strpos($row, $needle) !== false)
+        {
+          if (!$match_all) return $i;
+          else array_push($matches, $i);
+        }
+      }
+      else
+      {
+        if (preg_match($needle, $row) === 1)
+        {
+          if (!$match_all) return $i;
+          else array_push($matches, $i);
+        }
+      }
+    }
+  }
+  
+  if ( !$match_all or !count($matches) ) return false;
+  return $matches;
+}
+
+?>
Index: /extensions/pbase2piwigo/include/index.php
===================================================================
--- /extensions/pbase2piwigo/include/index.php	(revision 17225)
+++ /extensions/pbase2piwigo/include/index.php	(revision 17225)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/pbase2piwigo/include/ws_functions.inc.php
===================================================================
--- /extensions/pbase2piwigo/include/ws_functions.inc.php	(revision 17225)
+++ /extensions/pbase2piwigo/include/ws_functions.inc.php	(revision 17225)
@@ -0,0 +1,247 @@
+<?php
+if (!defined('PBASE_PATH')) die('Hacking attempt!');
+
+function pbase_add_ws_method($arr)
+{
+  $service = &$arr[0];
+  
+  $service->addMethod(
+    'pwg.pBase.addImage',
+    'ws_pBase_add_image',
+    array(
+      'url' => array(),
+      'category' => array('default' => null),
+      'fills' => array('default' => 'fill_name,fill_taken,fill_author,fill_comment,fill_tags'),
+      ),
+    'Used by PBase2Piwigo'
+    );
+    
+  $service->addMethod(
+    'pwg.pBase.addCat',
+    'ws_pBase_add_cat',
+    array(
+      'path' => array(),   
+      'parent_id' => array('default' => null),
+      'recursive' => array('default' => true),
+      ),
+    'Used by PBase2Piwigo'
+    );
+    
+  $service->addMethod(
+    'pwg.pBase.parse',
+    'ws_pBase_parse',
+    array(
+      'url' => array(),
+      'path' => array(),
+      ),
+    'Used by PBase2Piwigo'
+    );
+}
+
+/**
+ * pBase parse category
+ */
+function ws_pBase_parse($params, &$service)
+{
+  if (!is_admin())
+  {
+    return new PwgError(401, 'Forbidden');
+  }
+  
+  if (empty($params['path']) or empty($params['url']))
+  {
+    return new PwgError(403, l10n('Missing parameters'));
+  }
+  
+  include_once(PBASE_PATH.'include/functions.inc.php');
+  
+  if (test_remote_download() === false)
+  {
+    return new PwgError(null, l10n('No download method available'));
+  }
+  if ($params['path'] == '/root' and check_account($params['url']) == false)
+  {
+    return new PwgError(null, l10n('Invalid user id'));
+  }
+  
+  // get current tree
+  $tree_file = PBASE_FS_CACHE.'tree.json';
+  if (file_exists($tree_file))
+  {
+    $tree = json_decode(file_get_contents($tree_file), true);
+  }
+  else
+  {
+    $tree = array(
+      'root' => array(),
+      );
+  }
+  // parse sub-tree
+  $current = &get_current_cat($tree, $params['path']);
+  $path = substr($params['path'], 0, strrpos($params['path'], '/'));
+  $current = parse_category($params['url'], $path, true, true);
+  
+  // save tree
+  file_put_contents($tree_file, json_encode($tree));
+  
+  // return datas for AJAX queue
+  return $current;
+}
+
+/**
+ * pBase add category
+ */
+function ws_pBase_add_cat($params, &$service)
+{
+  if (!is_admin())
+  {
+    return new PwgError(401, 'Forbidden');
+  }
+  
+  if (empty($params['path']))
+  {
+    return new PwgError(null, l10n('Missing parameters'));
+  }
+  
+  include_once(PBASE_PATH.'include/functions.inc.php');
+  
+  // get current tree
+  $tree_file = PBASE_FS_CACHE.'tree.json';
+  $tree = json_decode(file_get_contents($tree_file), true);
+  $category = &get_current_cat($tree, $params['path']);
+  
+  if ($category['path'] == '/root')
+  {
+    $category['title'] = 'Import PBase';
+  }
+  
+  // add category
+  $query = '
+SELECT id, name
+  FROM '.CATEGORIES_TABLE.'
+  WHERE name = "'.$category['title'].' <!--pbase-->"
+;';
+  $result = pwg_query($query);
+  
+  if (pwg_db_num_rows($result))
+  {
+    list($category_id) = pwg_db_fetch_row($result);
+  }
+  else
+  {
+    $category_id = ws_categories_add(array(
+      'name' => $category['title'].' <!--pbase-->',
+      'parent' => $params['parent_id'],
+      'comment' => $category['description'],
+      ), $service);
+    $category_id = $category_id['id'];
+  }
+  
+  // return datas for AJAX queue
+  $output = array(
+    'category_id' => $category_id,
+    'pictures' => array(),
+    'categories' => array(),
+    'message' => sprintf(l10n('Album "%s" added'), $category['title']),
+    );
+    
+  foreach ($category['pictures'] as &$pict)
+  {
+    array_push($output['pictures'], $pict['url']);
+  }
+  if ($params['recursive'])
+  {
+    foreach ($category['categories'] as &$cat)
+    {
+      array_push($output['categories'], $cat['path']);
+    }
+  }
+  
+  return $output;
+}
+
+/**
+ * pBase add picture
+ */
+function ws_pBase_add_image($params, &$service)
+{
+  if (!is_admin())
+  {
+    return new PwgError(401, 'Forbidden');
+  }
+  
+  if (empty($params['url']))
+  {
+    return new PwgError(403, l10n('Missing parameters'));
+  }
+  
+  include_once(PBASE_PATH.'include/functions.inc.php');
+  include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
+  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
+    
+  // photo infos
+  $photo = parse_image($params['url'], false);
+  if (empty($photo))
+  {
+    return new PwgError(null, l10n('Invalid picture'));
+  }
+  
+  $photo['local_path'] = PBASE_FS_CACHE . 'pbase-'.$photo['id'].'.'.get_extension($photo['path']);
+  
+  $query = '
+SELECT id
+  FROM '.IMAGES_TABLE.'
+  WHERE file = "'.basename($photo['local_path']).'"
+;';
+  $result = pwg_query($query);
+  
+  if (pwg_db_num_rows($result))
+  {
+    list($photo['image_id']) = pwg_db_fetch_row($result);
+    associate_images_to_categories(array($photo['image_id']), array($params['category']));
+  }
+  else
+  {
+    // copy file
+    if (download_remote_file($photo['path'], $photo['local_path']) === false)
+    {
+      return new PwgError(500, l10n('No download method available'));
+    }
+    
+    // add photo
+    $photo['image_id'] = add_uploaded_file($photo['local_path'], basename($photo['local_path']), array($params['category']));
+  
+    // do some updates
+    if (!empty($params['fills']))
+    {
+      $params['fills'] = rtrim($params['fills'], ',');
+      $params['fills'] = explode(',', $params['fills']);
+    
+      $updates = array();
+      if (in_array('fill_name', $params['fills']))    $updates['name'] = pwg_db_real_escape_string($photo['title']); 
+      if (in_array('fill_posted', $params['fills']))  $updates['date_available'] = date('Y-d-m H:i:s', strtotime($photo['date']));
+      if (in_array('fill_taken', $params['fills']))   $updates['date_creation'] = date('Y-d-m H:i:s', strtotime($photo['date']));
+      if (in_array('fill_author', $params['fills']))  $updates['author'] = pwg_db_real_escape_string($photo['author']);
+      if (in_array('fill_comment', $params['fills'])) $updates['comment'] = pwg_db_real_escape_string($photo['description']);
+      
+      if (count($updates))
+      {
+        single_update(
+          IMAGES_TABLE,
+          $updates,
+          array('id' => $photo['image_id'])
+          );
+      }
+      
+      if ( !empty($photo['keywords']) and in_array('fill_tags', $params['fills']) )
+      {
+        $raw_tags = implode(',', $photo['keywords']);
+        set_tags(get_tag_ids($raw_tags), $photo['image_id']);
+      }
+    }
+  }
+  
+  return sprintf(l10n('Photo "%s" imported'), $photo['title']);
+}
+
+?>
Index: /extensions/pbase2piwigo/index.php
===================================================================
--- /extensions/pbase2piwigo/index.php	(revision 17225)
+++ /extensions/pbase2piwigo/index.php	(revision 17225)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/pbase2piwigo/language/en_UK/description.txt
===================================================================
--- /extensions/pbase2piwigo/language/en_UK/description.txt	(revision 17225)
+++ /extensions/pbase2piwigo/language/en_UK/description.txt	(revision 17225)
@@ -0,0 +1,1 @@
+Extension for importing pictures from PBase
Index: /extensions/pbase2piwigo/language/en_UK/index.php
===================================================================
--- /extensions/pbase2piwigo/language/en_UK/index.php	(revision 17225)
+++ /extensions/pbase2piwigo/language/en_UK/index.php	(revision 17225)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/pbase2piwigo/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/pbase2piwigo/language/en_UK/plugin.lang.php	(revision 17225)
+++ /extensions/pbase2piwigo/language/en_UK/plugin.lang.php	(revision 17225)
@@ -0,0 +1,5 @@
+<?php
+
+
+
+?>
Index: /extensions/pbase2piwigo/language/fr_FR/description.txt
===================================================================
--- /extensions/pbase2piwigo/language/fr_FR/description.txt	(revision 17225)
+++ /extensions/pbase2piwigo/language/fr_FR/description.txt	(revision 17225)
@@ -0,0 +1,1 @@
+Extension pour importer des photos depuis PBase
Index: /extensions/pbase2piwigo/language/fr_FR/index.php
===================================================================
--- /extensions/pbase2piwigo/language/fr_FR/index.php	(revision 17225)
+++ /extensions/pbase2piwigo/language/fr_FR/index.php	(revision 17225)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/pbase2piwigo/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/pbase2piwigo/language/fr_FR/plugin.lang.php	(revision 17225)
+++ /extensions/pbase2piwigo/language/fr_FR/plugin.lang.php	(revision 17225)
@@ -0,0 +1,5 @@
+<?php
+
+
+
+?>
Index: /extensions/pbase2piwigo/language/index.php
===================================================================
--- /extensions/pbase2piwigo/language/index.php	(revision 17225)
+++ /extensions/pbase2piwigo/language/index.php	(revision 17225)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/pbase2piwigo/main.inc.php
===================================================================
--- /extensions/pbase2piwigo/main.inc.php	(revision 17225)
+++ /extensions/pbase2piwigo/main.inc.php	(revision 17225)
@@ -0,0 +1,37 @@
+<?php 
+/*
+Plugin Name: PBase2Piwigo
+Version: auto
+Description: Extension for importing pictures from PBase
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
+Author: Mistic
+Author URI: http://www.strangeplanet.fr
+*/
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $conf;
+
+define('PBASE_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+define('PBASE_ADMIN', get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
+define('PBASE_FS_CACHE', $conf['data_location'].'pbase_cache/');
+
+if (defined('IN_ADMIN'))
+{
+  add_event_handler('get_admin_plugin_menu_links', 'pbase_admin_menu');
+
+  function pbase_admin_menu($menu) 
+  {
+    array_push($menu, array(
+      'NAME' => 'PBase2Piwigo',
+      'URL' => PBASE_ADMIN,
+    ));
+    return $menu;
+  }
+}
+
+include_once(PBASE_PATH . 'include/ws_functions.inc.php');
+
+add_event_handler('ws_add_methods', 'pbase_add_ws_method');
+
+?>
Index: /extensions/pbase2piwigo/maintain.inc.php
===================================================================
--- /extensions/pbase2piwigo/maintain.inc.php	(revision 17225)
+++ /extensions/pbase2piwigo/maintain.inc.php	(revision 17225)
@@ -0,0 +1,71 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+define(
+  'pbase2piwigo_default_config', 
+  serialize(array(
+    ))
+  );
+
+
+function plugin_install() 
+{
+  global $conf;
+  
+  // conf_update_param('pbase2piwigo', pbase2piwigo_default_config);
+  
+  mkdir($conf['data_location'].'pbase_cache/', 0755);
+}
+
+function plugin_activate()
+{
+  global $conf;
+
+  // if (empty($conf['pbase2piwigo']))
+  // {
+    // conf_update_param('pbase2piwigo', pbase2piwigo_default_config);
+  // }
+  
+  if (!file_exists($conf['data_location'].'pbase_cache/'))
+  {
+    mkdir($conf['data_location'].'pbase_cache/', 0755);
+  }
+}
+
+function plugin_uninstall() 
+{
+  // pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "pbase2piwigo" LIMIT 1;');
+  
+  rrmdir($conf['data_location'].'pbase_cache/');
+}
+
+function rrmdir($dir)
+{
+  if (!is_dir($dir))
+  {
+    return false;
+  }
+  $dir = rtrim($dir, '/');
+  $objects = scandir($dir);
+  $return = true;
+  
+  foreach ($objects as $object)
+  {
+    if ($object !== '.' && $object !== '..')
+    {
+      $path = $dir.'/'.$object;
+      if (filetype($path) == 'dir') 
+      {
+        $return = $return && rrmdir($path); 
+      }
+      else 
+      {
+        $return = $return && @unlink($path);
+      }
+    }
+  }
+  
+  return $return && @rmdir($dir);
+} 
+
+?>
