Index: /extensions/FacebookPlug/Server/cancel.php
===================================================================
--- /extensions/FacebookPlug/Server/cancel.php	(revision 8483)
+++ /extensions/FacebookPlug/Server/cancel.php	(revision 8483)
@@ -0,0 +1,44 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | FacebookPlug - a Piwigo Plugin                                        |
+// | Copyright (C) 2010-2011 Ruben ARNAUD - rub@piwigo.org                 |
+// +-----------------------------------------------------------------------+
+// | 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.                                                                  |
+// +-----------------------------------------------------------------------+
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+</head>
+<body>
+  <script type="text/javascript">
+    window.close();
+  </script>
+<!-- google-analytics -->
+<script type="text/javascript">
+  var _gaq = _gaq || [];
+  _gaq.push(['_setAccount', 'UA-2272624-7']);
+  _gaq.push(['_trackPageview']);
+
+  (function() {
+    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+  })();
+
+</script>
+<!-- google-analytics -->
+</body>
+</html>
Index: /extensions/FacebookPlug/Server/database/database.sql
===================================================================
--- /extensions/FacebookPlug/Server/database/database.sql	(revision 8483)
+++ /extensions/FacebookPlug/Server/database/database.sql	(revision 8483)
@@ -0,0 +1,17 @@
+--
+-- Structure de la table 'FBP_HISTORY'
+--
+
+CREATE TABLE FBP_HISTORY (
+  ID int(10) unsigned NOT NULL auto_increment,
+  `TIMESTAMP` timestamp NOT NULL default CURRENT_TIMESTAMP,
+  VERSION varchar(5) NOT NULL default '',
+  SCRIPT_NAME varchar(15) NOT NULL default '',
+  IP varchar(15) NOT NULL default '',
+  IMAGE_URL text NOT NULL default '',
+  PICTURE_URL text NOT NULL default '',
+  GALLERY_TITLE text NOT NULL default '',
+  PICTURE_TITLE text NOT NULL default '',
+  PRIMARY KEY  (ID),
+  KEY DATETIME_I1 (`TIMESTAMP`)
+) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
Index: /extensions/FacebookPlug/Server/database/index.php
===================================================================
--- /extensions/FacebookPlug/Server/database/index.php	(revision 8483)
+++ /extensions/FacebookPlug/Server/database/index.php	(revision 8483)
@@ -0,0 +1,27 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | FacebookPlug - a Piwigo Plugin                                        |
+// | Copyright (C) 2010-2011 Ruben ARNAUD - rub@piwigo.org                 |
+// +-----------------------------------------------------------------------+
+// | 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 = 'http://www.facebook.com/';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/FacebookPlug/Server/do_upload_photo.php
===================================================================
--- /extensions/FacebookPlug/Server/do_upload_photo.php	(revision 8483)
+++ /extensions/FacebookPlug/Server/do_upload_photo.php	(revision 8483)
@@ -0,0 +1,91 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | FacebookPlug - a Piwigo Plugin                                        |
+// | Copyright (C) 2010-2011 Ruben ARNAUD - rub@piwigo.org                 |
+// +-----------------------------------------------------------------------+
+// | 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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+define('FACEBOOKPLUG_ROOT_PATH','./');
+
+require_once 'include/common.php';
+
+// Check argument
+!empty($_GET['u']) or die('Missing argument!');
+
+fbp_mkdir($conf['local_upload_dir']);
+
+$image_url = $_GET['u'];
+if (! in_array(strtoupper(pathinfo($image_url, PATHINFO_EXTENSION)), $conf['available_upload_ext']))
+{
+  die($image_url.' is not a uploaded file: incorrect type');
+}
+
+$page_url = @$_GET['pu'];
+$page_title = @$_GET['pt'];
+$gallery_title = @$_GET['gt'];
+
+//~ $local_filename = $conf['local_upload_dir'].'/'.basename($image_url);
+$local_filename = $conf['local_upload_dir'].'/'.md5($image_url.$page_url.$page_title.$gallery_title.$_SERVER['REMOTE_ADDR'].print_r(getdate(), true)).'.'.pathinfo($image_url, PATHINFO_EXTENSION);
+
+// Prevent error for local use, IP are not admitted
+//~ $page_url = str_replace('http://127.0.0.1', 'http://localhost', $page_url);
+
+@unlink($local_filename);
+
+@set_time_limit(0);
+
+if ($handle = @fopen($local_filename, 'wb') and fbp_fetchRemote($image_url, $handle))
+{
+  fclose($handle);
+}
+
+if (is_file($local_filename))
+{
+  try
+  {
+    $facebook->setFileUploadSupport(true);
+    $result = $facebook->api(
+      '/me/photos', 'post',
+      array(
+        'source' => '@'.$local_filename,
+        'message' => $page_title.'
+'.$gallery_title.'
+'. $page_url,
+        ));
+    // Send Result
+    if (isset($result['id']))
+    {
+      echo $result['id'];
+    }
+    else
+    {
+      die($image_url.' not uploaded on Facebook');
+    }
+   }
+   catch (FacebookApiException $e)
+   {
+    die($image_url.' not uploaded on Facebook');
+   }
+  unlink($local_filename);
+}
+else
+{
+  die($image_url.' not uploaded locally');
+}
+
+// Mettre des stats
+
+?>
Index: /extensions/FacebookPlug/Server/include/common.php
===================================================================
--- /extensions/FacebookPlug/Server/include/common.php	(revision 8482)
+++ /extensions/FacebookPlug/Server/include/common.php	(revision 8483)
@@ -21,4 +21,34 @@
 defined('FACEBOOKPLUG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
 
+@set_magic_quotes_runtime(false); // Disable magic_quotes_runtime
+
+//
+// addslashes to vars if magic_quotes_gpc is off this is a security
+// precaution to prevent someone trying to break out of a SQL statement.
+//
+if( !@get_magic_quotes_gpc() )
+{
+  function sanitize_mysql_kv(&$v, $k)
+  {
+    $v = addslashes($v);
+  }
+  if( is_array( $_GET ) )
+  {
+    array_walk_recursive( $_GET, 'sanitize_mysql_kv' );
+  }
+  if( is_array( $_POST ) )
+  {
+    array_walk_recursive( $_POST, 'sanitize_mysql_kv' );
+  }
+  if( is_array( $_COOKIE ) )
+  {
+    array_walk_recursive( $_COOKIE, 'sanitize_mysql_kv' );
+  }
+}
+if ( !empty($_SERVER["PATH_INFO"]) )
+{
+  $_SERVER["PATH_INFO"] = addslashes($_SERVER["PATH_INFO"]);
+}
+
 require_once(FACEBOOKPLUG_ROOT_PATH . 'include/constants.php');
 require_once(FACEBOOKPLUG_ROOT_PATH . 'include/constants_secret.php');
@@ -32,4 +62,7 @@
 include(FACEBOOKPLUG_ROOT_PATH . 'include/config_default.php');
 
+// Log on db
+fbp_db_log();
+
 // Init Facebook
 $facebook = new Facebook(array(
@@ -39,15 +72,6 @@
 ));
 
-//~ print_r($_COOKIE);
-
-
-function d($d)
-{
-  echo '<pre>';
-  print_r($d);
-  echo '</pre>';
-}
-
 $session = $facebook->getSession();
+//~ var_dump($session);
 // Session based graph API call.
 if (! $session)
@@ -58,5 +82,8 @@
     (
       //ici on demande les permissions email, publication sur le mur, et changement du status
-      'req_perms' => 'email,publish_stream,status_update',
+      //'req_perms' => 'email,publish_stream,status_update',
+      'req_perms' => 'publish_stream',
+      'display' => 'popup',
+      'cancel_url' => 'http://'.$_SERVER['HTTP_HOST'].'/'.FBP_VERSION.'/cancel.php'
     ));
   header( 'Request-URI: '.$url );
Index: /extensions/FacebookPlug/Server/include/config_default.php
===================================================================
--- /extensions/FacebookPlug/Server/include/config_default.php	(revision 8482)
+++ /extensions/FacebookPlug/Server/include/config_default.php	(revision 8483)
@@ -20,11 +20,10 @@
 
 // Temporay upload directory
-$conf['local_upload_dir'] = dirname(dirname(__FILE__)).'/tmp/_upload';
+//~ $conf['local_upload_dir'] = dirname(dirname(__FILE__)).'/tmp/_upload';
+$conf['local_upload_dir'] = '/web/piwigo/tmp/_upload';
 
-// picture_ext : file extensions for picture file, must be a subset of
-// file_ext
-$conf['picture_ext'] = array('jpg','JPG','jpeg','JPEG',
-                             'png','PNG','gif','GIF');
-
+//From http://developers.facebook.com/docs/reference/rest/photos.upload/
+// *GIF *JPG *PNG *PSD *TIFF *JP2 *IFF *WBMP *XBM
+$conf['available_upload_ext'] = array('GIF', 'JPG', 'PNG', 'PSD', 'TIFF', 'JP2', 'IFF', 'WBMP', 'XBM');
 
 ?>
Index: /extensions/FacebookPlug/Server/include/constants.php
===================================================================
--- /extensions/FacebookPlug/Server/include/constants.php	(revision 8482)
+++ /extensions/FacebookPlug/Server/include/constants.php	(revision 8483)
@@ -19,6 +19,15 @@
 // +-----------------------------------------------------------------------+
 
+//This defines ares on constants_secret.php
 //define('FACEBOOK_APP_ID', '***');
 //define('FACEBOOK_SECRET', '***');
+
+//~ define('FBP_BASE', '***');
+//~ define('FBP_USER', '***');
+//~ define('FBP_PASSWORD', '***');
+//~ define('FBP_HOST', '***');
 //This defines ares on constants_secret.php
+
+define('FBP_VERSION', basename(dirname(dirname(__FILE__))));
+
 ?>
Index: /extensions/FacebookPlug/Server/include/functions.php
===================================================================
--- /extensions/FacebookPlug/Server/include/functions.php	(revision 8482)
+++ /extensions/FacebookPlug/Server/include/functions.php	(revision 8483)
@@ -19,4 +19,6 @@
 // +-----------------------------------------------------------------------+
 
+defined('FACEBOOKPLUG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
+
 function fbp_mkdir($dir)
 {
@@ -179,3 +181,80 @@
 }
 
+/**
+ * Return basename of the current script
+ * Copy from Piwigo application
+ * Lower case convertion is applied on return value
+ * Return value is without file extention ".php"
+ *
+ * @param void
+ *
+ * @return script basename
+ */
+function fbp_script_basename()
+{
+  global $conf;
+
+  foreach (array('SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF') as $value)
+  {
+    if (!empty($_SERVER[$value]))
+    {
+      $filename = strtolower($_SERVER[$value]);
+      $basename = basename($filename, '.php');
+      if (!empty($basename))
+      {
+        return $basename;
+      }
+    }
+  }
+  return '';
+}
+
+function  fbp_db_query($query)
+{
+  $result = mysql_query($query);
+  if (!$result)
+  {
+    die('Invalid query: [mysql error '.mysql_errno().'] '.mysql_error()."\n".$query);
+  }
+}
+
+function fbp_db_log()
+{  
+  $link = @mysql_connect(FBP_HOST, FBP_USER, FBP_PASSWORD);
+  if (!$link)
+  {
+    die("Can't connect to server");
+  }
+  if (!mysql_select_db(FBP_BASE, $link))
+  {
+    die('Connection to server succeed, but it was impossible to connect to database');
+  }
+
+  fbp_db_query('set names "utf8"');
+
+  fbp_db_query("
+insert into
+  FBP_HISTORY
+(
+  VERSION,
+  SCRIPT_NAME,
+  IP,
+  IMAGE_URL,
+  PICTURE_URL,
+  GALLERY_TITLE,
+  PICTURE_TITLE
+)
+values
+(
+  '".mysql_real_escape_string(FBP_VERSION)."',
+  '".mysql_real_escape_string(fbp_script_basename())."',
+  '".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."',
+  '".mysql_real_escape_string(@$_GET['u'])."',
+  '".mysql_real_escape_string(@$_GET['pu'])."',
+  '".mysql_real_escape_string(@$_GET['gt'])."',
+  '".mysql_real_escape_string(@$_GET['pt'])."'
+);
+");
+}
+
 ?>
Index: /extensions/FacebookPlug/Server/upload_photo.php
===================================================================
--- /extensions/FacebookPlug/Server/upload_photo.php	(revision 8482)
+++ /extensions/FacebookPlug/Server/upload_photo.php	(revision 8483)
@@ -23,81 +23,69 @@
 require_once 'include/common.php';
 
-// Check argument
-!empty($_GET['filename']) or trigger_error('Missing argument!', E_USER_ERROR);
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+  <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
+</head>
+<body>
+  <center>
+    <div id="loading"><img src="./image/image_85486.gif" alt="Loading"></div>
+    <div id="infos">
+      <img src="./image/infos.png" alt="Infos">
+      <a id ="info_a" href="" onclick="window.open(this.href); return false;">
+        <img src="<?php echo addslashes($_GET['u']) ?>" alt="Image" style="height:50px">
+      </a>
+    </div>
+    <div id="errors">
+        <img src="./image/errors.png" alt="Error">
+        <textearea id="error_result"></textearea>
+    </div>
+  </center>
+ 
+  <script type="text/javascript">
+    $(document).ready(function () {
+      $("#errors").hide();
+      $("#infos").hide();
+      $.get(
+      './do_upload_photo.php',
+      {u:"<?php echo addslashes($_GET['u']) ?>", pu: "<?php echo addslashes($_GET['pu']) ?>", pt: "<?php echo addslashes($_GET['pt']) ?>", gt: "<?php echo addslashes($_GET['gt']) ?>"},
+      function(data) {
+        $("#loading").hide();
+        is_ok = ! isNaN(data);
+        if (is_ok)
+        {
+          div_id = "#infos";
+          fb_photo_page = 'http://www.facebook.com/photo.php?fbid='+data;
+          $('#info_a').attr('href', fb_photo_page);
+        }
+        else
+        {
+          div_id = "#errors";
+          $('#error_result').html(data);
+        }
+        $(div_id).show();
+        $(div_id).fadeOut(3000, function ()
+          {
+            if (is_ok) { window.open(fb_photo_page); }
+            window.close();
+          });
+      });
+  });
+  </script>
+<!-- google-analytics -->
+<script type="text/javascript">
+  var _gaq = _gaq || [];
+  _gaq.push(['_setAccount', 'UA-2272624-7']);
+  _gaq.push(['_trackPageview']);
 
-/*try
-{
-  //~ $fbme = null;
-  $uid = $facebook->getUser();
-  $fbme = $facebook->api('/me');
+  (function() {
+    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+  })();
 
-  $param  =   array(
-     'method'  => 'users.getinfo',
-     //~ 'uids'       => $fbme['id'],
-     'uids'       => $uid,
-     'fields'     => 'name,current_location,profile_url',
-     'callback'  => ''
-  );
-  $userInfo   =   $facebook->api($param);
-  d($userInfo);
-}
-catch (FacebookApiException $e)
-{
-  d($e);
-}*/
-
-fbp_mkdir($conf['local_upload_dir']);
-
-  //~ try {
-        //~ $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> $fbme['name'].' a mis à jour son status par Piwigo en test sur FB', 'cb' => ''));
-        //~ echo "Status mis à jour";
-  //~ } catch (FacebookApiException $e) {
-        //~ d($e);
-  //~ }
-
-  //~ try {
-        //~ $result = $facebook->api('/me/albums', 'post', array('name' => 'Piwigo', 'message'=> 'Test'));
-        //~ d($result);
-        //~ echo "Album créé";
-  //~ } catch (FacebookApiException $e) {
-        //~ d($e);
-  //~ }
-
-  $filename = $_GET['filename'];
-  $local_filename = $conf['local_upload_dir'].'/'.basename($filename);
-
-  @unlink($local_filename);
-
-  @set_time_limit(0);
-
-  //~ copy($filename, $local_filename);
-  if ($handle = @fopen($local_filename, 'wb') and fbp_fetchRemote($filename, $handle))
-  {
-    fclose($handle);
-  }
-
-  if (is_file($local_filename))
-  {
-    try
-    {
-      $facebook->setFileUploadSupport(true);
-      //~ $result = $facebook->api('/me/photos', 'post', array('source' => '@./tmp/_upload/'.basename($local_filename)));
-      $result = $facebook->api('/me/photos', 'post', array('source' => '@'.$local_filename));
-      //~ d($result);
-      unlink($local_filename);
-     } 
-     catch (FacebookApiException $e)
-     {
-      d($e);
-     }
-
-  }
-  else
-  {
-    trigger_error('$filename not uploaded', E_USER_ERROR);
-  }
-
-  // check extension
-  // changer le nom de l'image
-
-?>
+</script>
+<!-- google-analytics -->
+</body>
+</html>
