Index: extensions/Google2Piwigo/admin.php
===================================================================
--- extensions/Google2Piwigo/admin.php	(revision 28138)
+++ extensions/Google2Piwigo/admin.php	(revision 28832)
@@ -11,6 +11,16 @@
 }
 
+// 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'), PICASA_WA_ADMIN . '-import');
+$tabsheet->add('config', l10n('Configuration'), PICASA_WA_ADMIN . '-config');
+$tabsheet->select($page['tab']);
+$tabsheet->assign();
+
 // include page
-include(PICASA_WA_PATH . 'admin/import.php');
+include(PICASA_WA_PATH . 'admin/' . $page['tab'] . '.php');
 
 // template
Index: extensions/Google2Piwigo/admin/config.php
===================================================================
--- extensions/Google2Piwigo/admin/config.php	(revision 28832)
+++ extensions/Google2Piwigo/admin/config.php	(revision 28832)
@@ -0,0 +1,26 @@
+<?php
+defined('PICASA_WA_PATH') or die('Hacking attempt!');
+
+if (isset($_POST['save_config']))
+{
+  $conf['google2piwigo'] = array(
+    'api_key' => trim($_POST['api_key']),
+    'secret_key' => trim($_POST['secret_key']),
+    'auth_endpoint' => $conf['google2piwigo']['auth_endpoint'],
+    'token_endpoint' => $conf['google2piwigo']['token_endpoint'],
+    );
+  unset($_SESSION['gata_auth_token']);
+
+  conf_update_param('google2piwigo', serialize($conf['google2piwigo']));
+  $page['infos'][] = l10n('Information data registered in database');
+}
+
+
+$template->assign(array(
+  'google2piwigo' => $conf['google2piwigo'],
+  'PICASA_WA_HELP_CONTENT' => load_language('help_api_key.html', PICASA_WA_PATH, array('return'=>true)),
+  'PICASA_WA_CALLBACK' => get_absolute_root_url() . PICASA_WA_ADMIN . '-import',
+  ));
+
+
+$template->set_filename('picasa_web_albums', realpath(PICASA_WA_PATH . 'admin/template/config.tpl'));
Index: extensions/Google2Piwigo/admin/import.php
===================================================================
--- extensions/Google2Piwigo/admin/import.php	(revision 28138)
+++ extensions/Google2Piwigo/admin/import.php	(revision 28832)
@@ -6,5 +6,11 @@
 include_once(PICASA_WA_PATH . 'include/functions.inc.php');
 
-if (!test_remote_download())
+// check API parameters and connect to flickr
+if (empty($conf['google2piwigo']['api_key']) or empty($conf['google2piwigo']['secret_key']))
+{
+  $page['warnings'][] = l10n('Please fill your API keys on the configuration tab');
+  $_GET['action'] = 'error';
+}
+else if (!test_remote_download())
 {
   $page['errors'][] = l10n('No download method available');
@@ -18,22 +24,31 @@
   Zend_Loader::loadClass('Zend_Gdata_AuthSub');
   Zend_Loader::loadClass('Zend_Gdata_Photos');
+  require_once('OAuth2/Client.php');
+  require_once('OAuth2/GrantType/AuthorizationCode.php');
+  
+  $oauth_client = new OAuth2_Client($conf['google2piwigo']['api_key'], $conf['google2piwigo']['secret_key']);
+  $oauth_redirect_url = get_absolute_root_url() . PICASA_WA_ADMIN . '-import';
   
   // generate token after authentication
-  if (!empty($_GET['token']))
-  {
-    $_SESSION['gdata_auth_token'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
+  if (!empty($_GET['code']))
+  {
+    $params = array('code' => $_GET['code'], 'redirect_uri' => $oauth_redirect_url, 'scope' => 'https://picasaweb.google.com/data/');
+    $response = $oauth_client->getAccessToken($conf['google2piwigo']['token_endpoint'], 'authorization_code', $params);
+    $_SESSION['gdata_auth_token'] = $response['result']['access_token'];
     $_GET['action'] = 'logged';
   }
   
-  // authentication
-  if (empty($_SESSION['gdata_auth_token']))
-  {
-    $_GET['action'] = 'login';
-  }
-  else
+  // must authenticate
+  if (!empty($_SESSION['gdata_auth_token']))
   {
     $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['gdata_auth_token']);
     $picasa = new Zend_Gdata_Photos($client, "Piwigo-Google2Piwigo-1.0");
   }
+  else
+  {
+    $params = array('scope' => 'https://picasaweb.google.com/data/');
+    $auth_url = $oauth_client->getAuthenticationUrl($conf['google2piwigo']['auth_endpoint'], $oauth_redirect_url, $params);
+    $_GET['action'] = 'init_login';
+  }
 }
 
@@ -47,16 +62,7 @@
 {
   // button to login page
-  case 'login':
-  {
-    $login_url = Zend_Gdata_AuthSub::getAuthSubTokenUri(
-      get_absolute_root_url() . PICASA_WA_ADMIN . '-import',
-      'https://picasaweb.google.com/data', 
-      false, true
-      );
-        
-    $template->assign(array(
-      'picasa_login' => $login_url,
-      'HELP_CONTENT' => load_language('help.lang.html', PICASA_WA_PATH, array('return'=>true)),
-      ));
+  case 'init_login':
+  {
+    $template->assign('picasa_login', $auth_url);
     break;
   }
@@ -73,10 +79,5 @@
   case 'logout':
   {
-    Zend_Gdata_AuthSub::AuthSubRevokeToken(
-      $_SESSION['gdata_auth_token'],
-      $client
-      );
     unset($_SESSION['gdata_auth_token']);
-    
     $_SESSION['page_infos'][] = l10n('Logged out');
     redirect(PICASA_WA_ADMIN . '-import');
Index: extensions/Google2Piwigo/admin/template/config.tpl
===================================================================
--- extensions/Google2Piwigo/admin/template/config.tpl	(revision 28832)
+++ extensions/Google2Piwigo/admin/template/config.tpl	(revision 28832)
@@ -0,0 +1,37 @@
+{combine_css path=$PICASA_WA_PATH|cat:'admin/template/style.css'}
+
+<div class="titrePage">
+	<h2>Google2Piwigo</h2>
+</div>
+
+<form method="post" action="" class="properties">
+<fieldset>
+  <legend>{'Google project keys'|translate}</legend>
+
+  <ul>
+    <li>
+      <label>
+        <span class="property">Client ID</span>
+        <input type="text" name="api_key" value="{$google2piwigo.api_key}" size="40">
+      </label>
+    </li>
+
+    <li>
+      <label>
+        <span class="property">Client secret</span>
+        <input type="text" name="secret_key" value="{$google2piwigo.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 Google project API key?'|translate}</legend>
+
+  <p><b>{'Callback URL'|translate} :</b> <span style="font-family:monospace;font-size:14px;">{$PICASA_WA_CALLBACK}</span></p>
+  {$PICASA_WA_HELP_CONTENT}
+</fieldset>
+
+</form>
Index: extensions/Google2Piwigo/admin/template/import.tpl
===================================================================
--- extensions/Google2Piwigo/admin/template/import.tpl	(revision 28138)
+++ extensions/Google2Piwigo/admin/template/import.tpl	(revision 28832)
@@ -12,7 +12,4 @@
   window.location.href = "{$picasa_login}";
 });
-$(".login_help").click(function() {
-  $(".infos.tip").slideToggle();
-});
 {/footer_script}
 
@@ -23,11 +20,6 @@
 
 {* <!-- LOGIN --> *}
-{if $ACTION == 'login'}
+{if $ACTION == 'init_login'}
 <p><input type="submit" class="login" value="{'Login'|translate}"></p>
-<p><a href="#" class="login_help">{'Help! I get the error "The site [...] has not been registered."'|translate}</a></p>
-
-<div class="infos tip" style="display:none;">
-{$HELP_CONTENT}
-</div>
 
 {* <!-- MAIN MENU --> *}
Index: extensions/Google2Piwigo/include/OAuth2/Client.php
===================================================================
--- extensions/Google2Piwigo/include/OAuth2/Client.php	(revision 28832)
+++ extensions/Google2Piwigo/include/OAuth2/Client.php	(revision 28832)
@@ -0,0 +1,514 @@
+<?php
+/**
+ * Note : Code is released under the GNU LGPL
+ *
+ * Please do not change the header of this file
+ *
+ * This library is free software; you can redistribute it and/or modify it under the terms of the GNU
+ * Lesser General Public License as published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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 Lesser General Public License for more details.
+ */
+
+/**
+ * Light PHP wrapper for the OAuth 2.0 protocol.
+ *
+ * This client is based on the OAuth2 specification draft v2.15
+ * http://tools.ietf.org/html/draft-ietf-oauth-v2-15
+ *
+ * @author      Pierrick Charron <pierrick@webstart.fr>
+ * @author      Anis Berejeb <anis.berejeb@gmail.com>
+ * @version     1.2-dev
+ */
+
+class OAuth2_Client
+{
+    /**
+     * Different AUTH method
+     */
+    const AUTH_TYPE_URI                 = 0;
+    const AUTH_TYPE_AUTHORIZATION_BASIC = 1;
+    const AUTH_TYPE_FORM                = 2;
+
+    /**
+     * Different Access token type
+     */
+    const ACCESS_TOKEN_URI      = 0;
+    const ACCESS_TOKEN_BEARER   = 1;
+    const ACCESS_TOKEN_OAUTH    = 2;
+    const ACCESS_TOKEN_MAC      = 3;
+
+    /**
+    * Different Grant types
+    */
+    const GRANT_TYPE_AUTH_CODE          = 'authorization_code';
+    const GRANT_TYPE_PASSWORD           = 'password';
+    const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials';
+    const GRANT_TYPE_REFRESH_TOKEN      = 'refresh_token';
+
+    /**
+     * HTTP Methods
+     */
+    const HTTP_METHOD_GET    = 'GET';
+    const HTTP_METHOD_POST   = 'POST';
+    const HTTP_METHOD_PUT    = 'PUT';
+    const HTTP_METHOD_DELETE = 'DELETE';
+    const HTTP_METHOD_HEAD   = 'HEAD';
+    const HTTP_METHOD_PATCH   = 'PATCH';
+
+    /**
+     * HTTP Form content types
+     */
+    const HTTP_FORM_CONTENT_TYPE_APPLICATION = 0;
+    const HTTP_FORM_CONTENT_TYPE_MULTIPART = 1;
+
+    /**
+     * Client ID
+     *
+     * @var string
+     */
+    protected $client_id = null;
+
+    /**
+     * Client Secret
+     *
+     * @var string
+     */
+    protected $client_secret = null;
+
+    /**
+     * Client Authentication method
+     *
+     * @var int
+     */
+    protected $client_auth = self::AUTH_TYPE_URI;
+
+    /**
+     * Access Token
+     *
+     * @var string
+     */
+    protected $access_token = null;
+
+    /**
+     * Access Token Type
+     *
+     * @var int
+     */
+    protected $access_token_type = self::ACCESS_TOKEN_URI;
+
+    /**
+     * Access Token Secret
+     *
+     * @var string
+     */
+    protected $access_token_secret = null;
+
+    /**
+     * Access Token crypt algorithm
+     *
+     * @var string
+     */
+    protected $access_token_algorithm = null;
+
+    /**
+     * Access Token Parameter name
+     *
+     * @var string
+     */
+    protected $access_token_param_name = 'access_token';
+
+    /**
+     * The path to the certificate file to use for https connections
+     *
+     * @var string  Defaults to .
+     */
+    protected $certificate_file = null;
+
+    /**
+     * cURL options
+     *
+     * @var array
+     */
+    protected $curl_options = array();
+
+    /**
+     * Construct
+     *
+     * @param string $client_id Client ID
+     * @param string $client_secret Client Secret
+     * @param int    $client_auth (AUTH_TYPE_URI, AUTH_TYPE_AUTHORIZATION_BASIC, AUTH_TYPE_FORM)
+     * @param string $certificate_file Indicates if we want to use a certificate file to trust the server. Optional, defaults to null.
+     * @return void
+     */
+    public function __construct($client_id, $client_secret, $client_auth = self::AUTH_TYPE_URI, $certificate_file = null)
+    {
+        if (!extension_loaded('curl')) {
+            throw new OAuth2_Exception('The PHP exention curl must be installed to use this library.', OAuth2_Exception::CURL_NOT_FOUND);
+        }
+
+        $this->client_id     = $client_id;
+        $this->client_secret = $client_secret;
+        $this->client_auth   = $client_auth;
+        $this->certificate_file = $certificate_file;
+        if (!empty($this->certificate_file)  && !is_file($this->certificate_file)) {
+            throw new OAuth2_InvalidArgumentException('The certificate file was not found', OAuth2_InvalidArgumentException::CERTIFICATE_NOT_FOUND);
+        }
+    }
+
+    /**
+     * Get the client Id
+     *
+     * @return string Client ID
+     */
+    public function getClientId()
+    {
+        return $this->client_id;
+    }
+
+    /**
+     * Get the client Secret
+     *
+     * @return string Client Secret
+     */
+    public function getClientSecret()
+    {
+        return $this->client_secret;
+    }
+
+    /**
+     * getAuthenticationUrl
+     *
+     * @param string $auth_endpoint Url of the authentication endpoint
+     * @param string $redirect_uri  Redirection URI
+     * @param array  $extra_parameters  Array of extra parameters like scope or state (Ex: array('scope' => null, 'state' => ''))
+     * @return string URL used for authentication
+     */
+    public function getAuthenticationUrl($auth_endpoint, $redirect_uri, array $extra_parameters = array())
+    {
+        $parameters = array_merge(array(
+            'response_type' => 'code',
+            'client_id'     => $this->client_id,
+            'redirect_uri'  => $redirect_uri
+        ), $extra_parameters);
+        return $auth_endpoint . '?' . http_build_query($parameters, null, '&');
+    }
+
+    /**
+     * getAccessToken
+     *
+     * @param string $token_endpoint    Url of the token endpoint
+     * @param int    $grant_type        Grant Type ('authorization_code', 'password', 'client_credentials', 'refresh_token', or a custom code (@see GrantType Classes)
+     * @param array  $parameters        Array sent to the server (depend on which grant type you're using)
+     * @return array Array of parameters required by the grant_type (CF SPEC)
+     */
+    public function getAccessToken($token_endpoint, $grant_type, array $parameters)
+    {
+        if (!$grant_type) {
+            throw new OAuth2_InvalidArgumentException('The grant_type is mandatory.', OAuth2_InvalidArgumentException::INVALID_GRANT_TYPE);
+        }
+        $grantTypeClassName = $this->convertToCamelCase($grant_type);
+        $grantTypeClass =  'OAuth2_GrantType_' . $grantTypeClassName;
+        if (!class_exists($grantTypeClass)) {
+            throw new OAuth2_InvalidArgumentException('Unknown grant type \'' . $grant_type . '\'', OAuth2_InvalidArgumentException::INVALID_GRANT_TYPE);
+        }
+        $grantTypeObject = new $grantTypeClass();
+        $grantTypeObject->validateParameters($parameters);
+        if (!defined($grantTypeClass . '::GRANT_TYPE')) {
+            throw new OAuth2_Exception('Unknown constant GRANT_TYPE for class ' . $grantTypeClassName, OAuth2_Exception::GRANT_TYPE_ERROR);
+        }
+        $parameters['grant_type'] = $grantTypeClass::GRANT_TYPE;
+        $http_headers = array();
+        switch ($this->client_auth) {
+            case self::AUTH_TYPE_URI:
+            case self::AUTH_TYPE_FORM:
+                $parameters['client_id'] = $this->client_id;
+                $parameters['client_secret'] = $this->client_secret;
+                break;
+            case self::AUTH_TYPE_AUTHORIZATION_BASIC:
+                $parameters['client_id'] = $this->client_id;
+                $http_headers['Authorization'] = 'Basic ' . base64_encode($this->client_id .  ':' . $this->client_secret);
+                break;
+            default:
+                throw new OAuth2_Exception('Unknown client auth type.', OAuth2_Exception::INVALID_CLIENT_AUTHENTICATION_TYPE);
+                break;
+        }
+
+        return $this->executeRequest($token_endpoint, $parameters, self::HTTP_METHOD_POST, $http_headers, self::HTTP_FORM_CONTENT_TYPE_APPLICATION);
+    }
+
+    /**
+     * setToken
+     *
+     * @param string $token Set the access token
+     * @return void
+     */
+    public function setAccessToken($token)
+    {
+        $this->access_token = $token;
+    }
+
+    /**
+     * Set the client authentication type
+     *
+     * @param string $client_auth (AUTH_TYPE_URI, AUTH_TYPE_AUTHORIZATION_BASIC, AUTH_TYPE_FORM)
+     * @return void
+     */
+    public function setClientAuthType($client_auth)
+    {
+        $this->client_auth = $client_auth;
+    }
+
+    /**
+     * Set an option for the curl transfer
+     *
+     * @param int   $option The CURLOPT_XXX option to set
+     * @param mixed $value  The value to be set on option
+     * @return void
+     */
+    public function setCurlOption($option, $value)
+    {
+        $this->curl_options[$option] = $value;
+    }
+
+    /**
+     * Set multiple options for a cURL transfer
+     *
+     * @param array $options An array specifying which options to set and their values
+     * @return void
+     */
+    public function setCurlOptions($options) 
+    {
+        $this->curl_options = array_merge($this->curl_options, $options);
+    }
+
+    /**
+     * Set the access token type
+     *
+     * @param int $type Access token type (ACCESS_TOKEN_BEARER, ACCESS_TOKEN_MAC, ACCESS_TOKEN_URI)
+     * @param string $secret The secret key used to encrypt the MAC header
+     * @param string $algorithm Algorithm used to encrypt the signature
+     * @return void
+     */
+    public function setAccessTokenType($type, $secret = null, $algorithm = null)
+    {
+        $this->access_token_type = $type;
+        $this->access_token_secret = $secret;
+        $this->access_token_algorithm = $algorithm;
+    }
+
+    /**
+     * Fetch a protected ressource
+     *
+     * @param string $protected_ressource_url Protected resource URL
+     * @param array  $parameters Array of parameters
+     * @param string $http_method HTTP Method to use (POST, PUT, GET, HEAD, DELETE)
+     * @param array  $http_headers HTTP headers
+     * @param int    $form_content_type HTTP form content type to use
+     * @return array
+     */
+    public function fetch($protected_resource_url, $parameters = array(), $http_method = self::HTTP_METHOD_GET, array $http_headers = array(), $form_content_type = self::HTTP_FORM_CONTENT_TYPE_MULTIPART)
+    {
+        if ($this->access_token) {
+            switch ($this->access_token_type) {
+                case self::ACCESS_TOKEN_URI:
+                    if (is_array($parameters)) {
+                        $parameters[$this->access_token_param_name] = $this->access_token;
+                    } else {
+                        throw new OAuth2_InvalidArgumentException(
+                            'You need to give parameters as array if you want to give the token within the URI.',
+                            OAuth2_InvalidArgumentException::REQUIRE_PARAMS_AS_ARRAY
+                        );
+                    }
+                    break;
+                case self::ACCESS_TOKEN_BEARER:
+                    $http_headers['Authorization'] = 'Bearer ' . $this->access_token;
+                    break;
+                case self::ACCESS_TOKEN_OAUTH:
+                    $http_headers['Authorization'] = 'OAuth ' . $this->access_token;
+                    break;
+                case self::ACCESS_TOKEN_MAC:
+                    $http_headers['Authorization'] = 'MAC ' . $this->generateMACSignature($protected_resource_url, $parameters, $http_method);
+                    break;
+                default:
+                    throw new OAuth2_Exception('Unknown access token type.', OAuth2_Exception::INVALID_ACCESS_TOKEN_TYPE);
+                    break;
+            }
+        }
+        return $this->executeRequest($protected_resource_url, $parameters, $http_method, $http_headers, $form_content_type);
+    }
+
+    /**
+     * Generate the MAC signature
+     *
+     * @param string $url Called URL
+     * @param array  $parameters Parameters
+     * @param string $http_method Http Method
+     * @return string
+     */
+    private function generateMACSignature($url, $parameters, $http_method)
+    {
+        $timestamp = time();
+        $nonce = uniqid();
+        $parsed_url = parse_url($url);
+        if (!isset($parsed_url['port']))
+        {
+            $parsed_url['port'] = ($parsed_url['scheme'] == 'https') ? 443 : 80;
+        }
+        if ($http_method == self::HTTP_METHOD_GET) {
+            if (is_array($parameters)) {
+                $parsed_url['path'] .= '?' . http_build_query($parameters, null, '&');
+            } elseif ($parameters) {
+                $parsed_url['path'] .= '?' . $parameters;
+            }
+        }
+
+        $signature = base64_encode(hash_hmac($this->access_token_algorithm,
+                    $timestamp . "\n"
+                    . $nonce . "\n"
+                    . $http_method . "\n"
+                    . $parsed_url['path'] . "\n"
+                    . $parsed_url['host'] . "\n"
+                    . $parsed_url['port'] . "\n\n"
+                    , $this->access_token_secret, true));
+
+        return 'id="' . $this->access_token . '", ts="' . $timestamp . '", nonce="' . $nonce . '", mac="' . $signature . '"';
+    }
+
+    /**
+     * Execute a request (with curl)
+     *
+     * @param string $url URL
+     * @param mixed  $parameters Array of parameters
+     * @param string $http_method HTTP Method
+     * @param array  $http_headers HTTP Headers
+     * @param int    $form_content_type HTTP form content type to use
+     * @return array
+     */
+    private function executeRequest($url, $parameters = array(), $http_method = self::HTTP_METHOD_GET, array $http_headers = null, $form_content_type = self::HTTP_FORM_CONTENT_TYPE_MULTIPART)
+    {
+        $curl_options = array(
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_SSL_VERIFYPEER => true,
+            CURLOPT_CUSTOMREQUEST  => $http_method
+        );
+
+        switch($http_method) {
+            case self::HTTP_METHOD_POST:
+                $curl_options[CURLOPT_POST] = true;
+                /* No break */
+            case self::HTTP_METHOD_PUT:
+            case self::HTTP_METHOD_PATCH:
+
+                /**
+                 * Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data,
+                 * while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
+                 * http://php.net/manual/en/function.curl-setopt.php
+                 */
+                if(is_array($parameters) && self::HTTP_FORM_CONTENT_TYPE_APPLICATION === $form_content_type) {
+                    $parameters = http_build_query($parameters, null, '&');
+                }
+                $curl_options[CURLOPT_POSTFIELDS] = $parameters;
+                break;
+            case self::HTTP_METHOD_HEAD:
+                $curl_options[CURLOPT_NOBODY] = true;
+                /* No break */
+            case self::HTTP_METHOD_DELETE:
+            case self::HTTP_METHOD_GET:
+                if (is_array($parameters)) {
+                    $url .= '?' . http_build_query($parameters, null, '&');
+                } elseif ($parameters) {
+                    $url .= '?' . $parameters;
+                }
+                break;
+            default:
+                break;
+        }
+
+        $curl_options[CURLOPT_URL] = $url;
+
+        if (is_array($http_headers)) {
+            $header = array();
+            foreach($http_headers as $key => $parsed_urlvalue) {
+                $header[] = "$key: $parsed_urlvalue";
+            }
+            $curl_options[CURLOPT_HTTPHEADER] = $header;
+        }
+
+        $ch = curl_init();
+        curl_setopt_array($ch, $curl_options);
+        // https handling
+        if (!empty($this->certificate_file)) {
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+            curl_setopt($ch, CURLOPT_CAINFO, $this->certificate_file);
+        } else {
+            // bypass ssl verification
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+        }
+        if (!empty($this->curl_options)) {
+            curl_setopt_array($ch, $this->curl_options);
+        }
+        $result = curl_exec($ch);
+        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+        $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
+        if ($curl_error = curl_error($ch)) {
+            throw new OAuth2_Exception($curl_error, OAuth2_Exception::CURL_ERROR);
+        } else {
+            $json_decode = json_decode($result, true);
+        }
+        curl_close($ch);
+
+        return array(
+            'result' => (null === $json_decode) ? $result : $json_decode,
+            'code' => $http_code,
+            'content_type' => $content_type
+        );
+    }
+
+    /**
+     * Set the name of the parameter that carry the access token
+     *
+     * @param string $name Token parameter name
+     * @return void
+     */
+    public function setAccessTokenParamName($name)
+    {
+        $this->access_token_param_name = $name;
+    }
+
+    /**
+     * Converts the class name to camel case
+     *
+     * @param  mixed  $grant_type  the grant type
+     * @return string
+     */
+    private function convertToCamelCase($grant_type)
+    {
+        $parts = explode('_', $grant_type);
+        array_walk($parts, function(&$item) { $item = ucfirst($item);});
+        return implode('', $parts);
+    }
+}
+
+class OAuth2_Exception extends Exception
+{
+    const CURL_NOT_FOUND                     = 0x01;
+    const CURL_ERROR                         = 0x02;
+    const GRANT_TYPE_ERROR                   = 0x03;
+    const INVALID_CLIENT_AUTHENTICATION_TYPE = 0x04;
+    const INVALID_ACCESS_TOKEN_TYPE          = 0x05;
+}
+
+class OAuth2_InvalidArgumentException extends InvalidArgumentException
+{
+    const INVALID_GRANT_TYPE      = 0x01;
+    const CERTIFICATE_NOT_FOUND   = 0x02;
+    const REQUIRE_PARAMS_AS_ARRAY = 0x03;
+    const MISSING_PARAMETER       = 0x04;
+}
Index: extensions/Google2Piwigo/include/OAuth2/GrantType/AuthorizationCode.php
===================================================================
--- extensions/Google2Piwigo/include/OAuth2/GrantType/AuthorizationCode.php	(revision 28832)
+++ extensions/Google2Piwigo/include/OAuth2/GrantType/AuthorizationCode.php	(revision 28832)
@@ -0,0 +1,40 @@
+<?php
+
+require_once('IGrantType.php');
+
+/**
+ * Authorization code  Grant Type Validator
+ */
+class OAuth2_GrantType_AuthorizationCode implements OAuth2_GrantType_IGrantType
+{
+    /**
+     * Defines the Grant Type
+     *
+     * @var string  Defaults to 'authorization_code'.
+     */
+    const GRANT_TYPE = 'authorization_code';
+
+    /**
+     * Adds a specific Handling of the parameters
+     *
+     * @return array of Specific parameters to be sent.
+     * @param  mixed  $parameters the parameters array (passed by reference)
+     */
+    public function validateParameters(&$parameters)
+    {
+        if (!isset($parameters['code']))
+        {
+            throw new OAuth2_InvalidArgumentException(
+                'The \'code\' parameter must be defined for the Authorization Code grant type',
+                OAuth2_InvalidArgumentException::MISSING_PARAMETER
+            );
+        }
+        elseif (!isset($parameters['redirect_uri']))
+        {
+            throw new OAuth2_InvalidArgumentException(
+                'The \'redirect_uri\' parameter must be defined for the Authorization Code grant type',
+                OAuth2_InvalidArgumentException::MISSING_PARAMETER
+            );
+        }
+    }
+}
Index: extensions/Google2Piwigo/include/OAuth2/GrantType/ClientCredentials.php
===================================================================
--- extensions/Google2Piwigo/include/OAuth2/GrantType/ClientCredentials.php	(revision 28832)
+++ extensions/Google2Piwigo/include/OAuth2/GrantType/ClientCredentials.php	(revision 28832)
@@ -0,0 +1,26 @@
+<?php
+
+require_once('IGrantType.php');
+
+/**
+ * Client Credentials Parameters 
+ */
+class OAuth2_GrantType_ClientCredentials implements OAuth2_GrantType_IGrantType
+{
+    /**
+     * Defines the Grant Type
+     * 
+     * @var string  Defaults to 'client_credentials'. 
+     */
+    const GRANT_TYPE = 'client_credentials';
+
+    /**
+     * Adds a specific Handling of the parameters
+     * 
+     * @return array of Specific parameters to be sent.
+     * @param  mixed  $parameters the parameters array (passed by reference)
+     */
+    public function validateParameters(&$parameters)
+    {
+    }
+}
Index: extensions/Google2Piwigo/include/OAuth2/GrantType/IGrantType.php
===================================================================
--- extensions/Google2Piwigo/include/OAuth2/GrantType/IGrantType.php	(revision 28832)
+++ extensions/Google2Piwigo/include/OAuth2/GrantType/IGrantType.php	(revision 28832)
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * Specific GrantType Interface
+ */
+interface OAuth2_GrantType_IGrantType 
+{
+    /**
+     * Adds a specific Handling of the parameters
+     * 
+     * @return array of Specific parameters to be sent.
+     * @param  mixed  $parameters the parameters array (passed by reference)
+     */
+    public function validateParameters(&$parameters);
+}
Index: extensions/Google2Piwigo/include/OAuth2/GrantType/Password.php
===================================================================
--- extensions/Google2Piwigo/include/OAuth2/GrantType/Password.php	(revision 28832)
+++ extensions/Google2Piwigo/include/OAuth2/GrantType/Password.php	(revision 28832)
@@ -0,0 +1,40 @@
+<?php
+
+require_once('IGrantType.php');
+
+/**
+ * Password Parameters
+ */
+class OAuth2_GrantType_Password implements OAuth2_GrantType_IGrantType
+{
+    /**
+     * Defines the Grant Type
+     *
+     * @var string  Defaults to 'password'.
+     */
+    const GRANT_TYPE = 'password';
+
+    /**
+     * Adds a specific Handling of the parameters
+     *
+     * @return array of Specific parameters to be sent.
+     * @param  mixed  $parameters the parameters array (passed by reference)
+     */
+    public function validateParameters(&$parameters)
+    {
+        if (!isset($parameters['username']))
+        {
+            throw new OAuth2_InvalidArgumentException(
+                'The \'username\' parameter must be defined for the Password grant type',
+                OAuth2_InvalidArgumentException::MISSING_PARAMETER
+            );
+        }
+        elseif (!isset($parameters['password']))
+        {
+            throw new OAuth2_InvalidArgumentException(
+                'The \'password\' parameter must be defined for the Password grant type',
+                OAuth2_InvalidArgumentException::MISSING_PARAMETER
+            );
+        }
+    }
+}
Index: extensions/Google2Piwigo/include/OAuth2/GrantType/RefreshToken.php
===================================================================
--- extensions/Google2Piwigo/include/OAuth2/GrantType/RefreshToken.php	(revision 28832)
+++ extensions/Google2Piwigo/include/OAuth2/GrantType/RefreshToken.php	(revision 28832)
@@ -0,0 +1,33 @@
+<?php
+
+require_once('IGrantType.php');
+
+/**
+ * Refresh Token  Parameters
+ */
+class OAuth2_GranType_RefreshToken implements OAuth2_GrantType_IGrantType
+{
+    /**
+     * Defines the Grant Type
+     *
+     * @var string  Defaults to 'refresh_token'.
+     */
+    const GRANT_TYPE = 'refresh_token';
+
+    /**
+     * Adds a specific Handling of the parameters
+     *
+     * @return array of Specific parameters to be sent.
+     * @param  mixed  $parameters the parameters array (passed by reference)
+     */
+    public function validateParameters(&$parameters)
+    {
+        if (!isset($parameters['refresh_token']))
+        {
+            throw new OAuth2_InvalidArgumentException(
+                'The \'refresh_token\' parameter must be defined for the refresh token grant type',
+                OAuth2_InvalidArgumentException::MISSING_PARAMETER
+            );
+        }
+    }
+}
Index: extensions/Google2Piwigo/language/bg_BG/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/bg_BG/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Отиди на <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Напиши си името на домейна без поддомейн в областта (eg: <i>mydomain.com</i>, не <i>gallery.mydomain.com</i>) и кликнете върху <b>Въведи адрес</b>.</li>
-<li>Отиди на <b>Управление [mydomain.com]</b> и се съгласявате с ToS.</li>
-<li>Напиши си името на домейна с поддомейн (дори ако то е <i>www</i>) и <i>http://</i> префикс в първото поле и запази.</li>
-<ol>
Index: extensions/Google2Piwigo/language/da_DK/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/da_DK/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Gå til <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Skriv dit domænenavn uden underdomænet i feltet (fx: <i>mydomain.com</i>, ikke <i>gallery.mydomain.com</i>) og klik på <b>Add domain</b>.</li>
-<li>Klik på <b>Manage [mydomain.com]</b> og accepter ToS'en.</li>
-<li>Skriv dit domænenavn MED underdomænet (selv hvis det er <i>www</i>) og <i>http://</i>-præfikset i det første felt og gem.</li>
-<ol>
Index: extensions/Google2Piwigo/language/de_DE/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/de_DE/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Gehe zu <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Gib deine Domain ohne Sub-Domain ein (Bsp.: <i>meinedomain.com</i>, nichtt <i>gallery.meinedomain.com</i>) und klicke auf <b>Add domain</b>.</li>
-<li>Klicke <b>Manage [mydomain.com]</b> und akzeptiere die Nutzungsbedingungen.</li>
-<li>Schreibe deine Domain INKLUSIVE der Sub-Domain (such wenn diese <i>www</i> seine sollte) mit dem <i>http://</i> Prefix in das erste Feld und dann speichern.</li>
-<ol>
Index: extensions/Google2Piwigo/language/el_GR/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/el_GR/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Πηγαίνετε στο <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Γράψτε το όνομα του domain σας, χωρίς το subdomain στο πεδίο(π.χ.: <i>mydomain.com</i>, not <i>gallery.mydomain.com</i>) και κάντε κλικ στο <b>Add domain</b>.</li>
-<li>Κάντε κλικ στο<b>Manage [mydomain.com]</b> και συμφωνήστε με τους Όροι χρήσης.</li>
-<li>Γράψτε το όνομα τομέα σας ΜΕ το subdomain (ακόμα και αν είναι <i>www</i>) και το πρόθεμα <i>http://</i> στο πρώτο πεδίο και αποθηκεύστε.</li>
-<ol>
Index: extensions/Google2Piwigo/language/en_UK/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/en_UK/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Go to <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Write your domain name without the subdomain in the field (eg: <i>mydomain.com</i>, not <i>gallery.mydomain.com</i>) and click on <b>Add domain</b>.</li>
-<li>Click on <b>Manage [mydomain.com]</b> and agree with the ToS.</li>
-<li>Write your domain name WITH the subdomain (even if it is <i>www</i>) and the <i>http://</i> prefix in the first field and save.</li>
-<ol>
Index: extensions/Google2Piwigo/language/en_UK/help_api_key.html
===================================================================
--- extensions/Google2Piwigo/language/en_UK/help_api_key.html	(revision 28832)
+++ extensions/Google2Piwigo/language/en_UK/help_api_key.html	(revision 28832)
@@ -0,0 +1,10 @@
+<ol>
+  <li>Go to <a href="https://console.developers.google.com/project">Google Developers Console</a> and connect with your Google account</li>
+  <li>Click <b>Create project</b> and give it a name</li>
+  <li>Once the process is finished, click on the newly created project</li>
+  <li>Go to <b>APIS & AUTH</b> / <b>Credentials</b></li>
+  <li>Click <b>Create new Client ID</b></li>
+  <li>Give your domain name as <b>Authorized Javascript origins</b> and the above <b>Callback URL</b> as <b>Authorized redirect URI</b></li>
+  <li>Now copy the <b>Client ID</b> and the <b>Client Secret</b> to Google2Piwigo configuration</li>
+  <li>You're done!</li>
+</ol>
Index: extensions/Google2Piwigo/language/en_UK/plugin.lang.php
===================================================================
--- extensions/Google2Piwigo/language/en_UK/plugin.lang.php	(revision 28138)
+++ extensions/Google2Piwigo/language/en_UK/plugin.lang.php	(revision 28832)
@@ -1,4 +1,5 @@
 <?php
 
+$lang['Please fill your API keys on the configuration tab'] = 'Please fill your API keys on the configuration tab';
 $lang['Successfully logged to you Google account'] = 'Successfully logged to you Google account';
 $lang['One picture is not displayed because already existing in the database.'] = 'One picture is not displayed because already existing in the database.';
@@ -24,5 +25,7 @@
 $lang['Geolocalization'] = 'Geolocalization';
 $lang['Logged in as'] = 'Logged in as';
-$lang['Help! I get the error "The site [...] has not been registered."'] = 'Help! I get the error "The site [...] has not been registered."';
+$lang['Google project keys'] = 'Google project keys';
+$lang['Callback URL'] = 'Callback URL';
+$lang['How do I get my Google project API key?'] = 'How do I get my Google project API key?';
 
 ?>
Index: extensions/Google2Piwigo/language/es_ES/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/es_ES/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Vayan a <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Escribe tu nombre de dominio sin el subdominio en el campo (eg: <i>mydomain.com</i>, no <i>gallery.mydomain.com</i>) y haz clic en <b>Add domain</b>.</li>
-<li> Haz clic en <b>Administrar[mydomain.com]</b> y da tu acuerdo con los Términos de Utilización. </ li>
-<li>Escriba tu nombre de dominio con el subdominio (incluso si es <i>www</i>) y el <i>http://</i> prefijo en el primer campo y guardar.</li>
-<ol>
Index: extensions/Google2Piwigo/language/fr_FR/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/fr_FR/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Allez sur la page <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Écrivez votre nom de domaine sans le sous-domaine dans le champs (ei: <i>mydomain.com</i>, non <i>gallery.mydomain.com</i>) et cliquez sur <b>Add domain</b>.</li>
-<li>Cliquez sur <b>Manage [mydomain.com]</b> et acceptez les conditions d'utilisation (ToS).</li>
-<li>Écrivez votre nom de domaine AVEC le sous-domaine (même si c'est <i>www</i>) et le préfixe <i>http://</i> dans le premier champs, et validez.</li>
-<ol>
Index: extensions/Google2Piwigo/language/fr_FR/help_api_key.html
===================================================================
--- extensions/Google2Piwigo/language/fr_FR/help_api_key.html	(revision 28832)
+++ extensions/Google2Piwigo/language/fr_FR/help_api_key.html	(revision 28832)
@@ -0,0 +1,10 @@
+<ol>
+  <li>Allez sur <a href="https://console.developers.google.com/project">Google Developers Console</a> et connectez-vous avec votre compte Google</li>
+  <li>Cliquez sur <b>Create project</b> et entrez un nom</li>
+  <li>Dès que le processus de création est terminé, cliquez sur l'application nouvellement créée</li>
+  <li>Rendez-vous dans <b>APIS & AUTH</b> / <b>Credentials</b></li>
+  <li>Cliquez sur <b>Create new Client ID</b></li>
+  <li>Entrez votre nom de domaine pour <b>Authorized Javascript origins</b> et le <b>Callback URL</b> ci-dessus pour <b>Authorized redirect URI</b></li>
+  <li>Maintenant copiez le <b>Client ID</b> et le <b>Client Secret</b> dans la configuration de Google2Piwigo</li>
+  <li>Terminé!</li>
+</ol>
Index: extensions/Google2Piwigo/language/hu_HU/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/hu_HU/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Menj ide <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Írd be a domain nevedet aldomain nélkül az mezobe (pl: <i>mydomain.com</i>, ne ezt <i>gallery.mydomain.com</i>) és kattints ide <b>Add domain</b>.</li>
-<li>Kattints ide <b>Manage [mydomain.com]</b> és fogadd el a szolgáltatási feltételeket!</li>
-<li>Írd be a domain neved az aldomainnal EGYÜTT (akkor is, ha az <i>www</i>) és a <i>http://</i> elotagot az elso mezobe és mentsd el.</li>
-<ol> 
Index: extensions/Google2Piwigo/language/it_IT/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/it_IT/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Vai a <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Scrivi il tuo nome di dominio senza il sottodominio nel campo (esempio: <i>mydomain.com</i>, no <i>gallery.mydomain.com</i>) e clicca su <b>Add domain</b>.</li>
-<li>Clicca sù <b>Manage [mydomain.com]</b> ed accetta la ToS.</li>
-<li>Scrivi il tuo nome di dominio CON il sottodominio (anche se c'è <i>www</i>) e il prefisso <i>http://</i> nel primo campo e salvare.</li>
-<ol>
Index: extensions/Google2Piwigo/language/lv_LV/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/lv_LV/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Iet uz <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Ierakstiet savu domēna vārdu bez apakšdomēna šajā laukā (piem: <i>mydomain.com</i>, bet ne <i>gallery.mydomain.com</i>) un klikšķiniet uz <b>Add domain</b>.</li>
-<li>Klikšķiniet uz <b>Pārvaldīt [mydomain.com]</b> un piekrītiet ToS.</li>
-<li>Ierakstiet sava domēna vārdu AR apakšdomēnu (pat, ja tas ir <i>www</i>) un <i>http://</i> prefiksu pirmajā laukā un ieglabāt.</li>
-<ol>
Index: extensions/Google2Piwigo/language/nl_NL/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/nl_NL/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Ga naar <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Voer de naam van uw domein in, in het veld zonder subdomein (bv: <i>mijndomein.nl</i>, en niet <i>fotos.mijndomein.nl</i>) en klik op <b>Toevoegen domein</b>.</li>
-<li>Klik op <b>Beheer [mijndomein.nl]</b> en ga akkoord met de ToS.</li>
-<li>Voer uw domein naam in MET subdomein ervoor (zelfs als het <i>www</i> is) met <i>http://</i> voorvoegsel in het eerste veld en klik op opslaan.</li>
-<ol>
Index: extensions/Google2Piwigo/language/pl_PL/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/pl_PL/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Odwiedź stronę <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Wpisz swoją domenę, bez domeny podrzędnej, w pustym polu (np. <i>mojadomena.pl</i>, ale nie <i>galeria.mojadomena.pl</i>) następnie kliknij przycisk <b>Add domain</b> / <b>Dodaj domenę</b>.</li>
-<li>Kliknij <b>Manage [mojadomena.pl]</b > / <b>Zarządzaj [mojadomena.pl]</b> i zaakceptuj warunki korzystania z usługi (ToS).</li>
-<li>Wpisz swoją domenę wraz z domeną podrzędną (nawet jeśli jest to <i>www</i>), w pierwszym polu wybierz przedrostek <i>http://</i> i zapisz zmiany.</li>
-<ol>
Index: extensions/Google2Piwigo/language/pt_BR/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/pt_BR/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Vá para <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Escreva seu nome de domínio sem o nome do subdomínio no campo (ex: <i>meudominio.com</i>, não <i>gallery.meudominio.com</i>) e clique em <b>Adicionar domínio</b>.</li>
-<li>Clique em <b>Gerenciar/Manage [meudominio.com]</b> e concorde com os termos de serviço (ToS).</li>
-<li>Escreva seu nome de domínio COM o subdomínio  (mesmo se ele seja <i>www</i>) e o prefixo <i>http://</i> no primeiro campo e salve.</li>
-<ol>
Index: extensions/Google2Piwigo/language/pt_PT/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/pt_PT/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Ir para <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Escreva o seu domínio sem o subdomínio (por exemplo: <i>meudominio.com</i>, em vez de <i>galeria.meudominio.com</i>) e clique em <b>Adicionar domínio</b>.</li>
-<li>Clique em <b>Gerir [meudominio.com]</b> e aceite os TdS.</li>
-<li>Escreva o seu domínio COM o subdomínio (mesmo que seja <i>www</i>) e o prefixo <i>http://</i> no primeiro campo e grave.</li>
-<ol>
Index: extensions/Google2Piwigo/language/ru_RU/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/ru_RU/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Пройдите по ссылке<a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Впишите доменное имя без указания поддомена(например: <i>mydomain.com</i>, а не <i>gallery.mydomain.com</i>) и кликните по кнопке <b>Add domain</b>.</li>
-<li>Кликните на <b>Manage [mydomain.com]</b> и ознакомьтесь с правилами использования сервиса.</li>
-<li>Впишите имя Вашего домена ВМЕСТЕ с указанием поддомена (даже если это <i>www</i>) и префикса протокола <i>http://</i> в первом поле. Сохраните настройки.</li>
-<ol>
Index: extensions/Google2Piwigo/language/sk_SK/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/sk_SK/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Choďte na <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Napíšte názov Vašej somény bez poddomény do políčka (napr.: <i>mydomain.com</i>, nie <i>gallery.mydomain.com</i>) a kliknite na <b>Add domain</b>.</li>
-<li>Kliknite na <b>Manage [mydomain.com]</b> a potvrďte s ToS.</li>
-<li>Napíšte názov Vašej domény S poddoménou (rovnakú ak je to <i>www</i>) a <i>http://</i> prefix do prvého políčka a uložte.</li>
-<ol>
Index: extensions/Google2Piwigo/language/tr_TR/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/tr_TR/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li><a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a> adresine gidin.</li>
-<li>Alan adınızı, alt alan adı olmaksızın (<i>gallery.mydomain.com</i> şeklinde değil, <i>mydomain.com</i> gibi) veri giriş alanına yazın ve <b>Add domain</b> kısmına tıklayın.</li>
-<li><b>Manage [mydomain.com]</b> kısa yoluna tıklayın ve ToS uyarısını onaylayın.</li>
-<li>Alan adınızı alt alan adı ile birlikte yazın (Ön kısmında <i>www</i>) ve <i>http://</i> olsa dahi yazın ve kaydedin.</li>
-<ol>
Index: extensions/Google2Piwigo/language/uk_UA/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/uk_UA/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>Перейти до <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>Напишіть своє доменне ім'я без субдомену в полі (наприклад: <i>mydomain.com</i>, не <i>gallery.mydomain.com</i>) і натисніть на <b>Додати домен</b>.</li>
-<li>Натисніть на <b>Керування [mydomain.com]</b> і згоден з ToS.</li>
-<li>Напишіть своє доменне ім'я з субдоменом (навіть якщо це є <i>www</i>) і <i>http://</i> префікс в першому полі і зберегти.</li>
-<ol>
Index: extensions/Google2Piwigo/language/zh_CN/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/zh_CN/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>访问 <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>填写您的域名(不含子域名) (比如: <i>mydomain.com</i>, 而非 <i>gallery.mydomain.com</i>) 并点击 <b>Add domain</b>.</li>
-<li>点击 <b>Manage [mydomain.com]</b> 并同意 ToS.</li>
-<li>填写含子域名的域名 (包括 <i>www</i>) 以及 <i>http://</i> 并保存。</li>
-<ol>
Index: extensions/Google2Piwigo/language/zh_TW/help.lang.html
===================================================================
--- extensions/Google2Piwigo/language/zh_TW/help.lang.html	(revision 28138)
+++ 	(revision )
@@ -1,6 +1,0 @@
-<ol>
-<li>轉到 <a href="https://accounts.google.com/ManageDomains">https://accounts.google.com/ManageDomains</a>.</li>
-<li>輸入您的域名，但不要輸入子域名 (例如: <i>mydomain.com</i>, 而不是 <i>gallery.mydomain.com</i>) 然後點擊 <b>添加域</b>.</li>
-<li>單擊 <b>管理 [mydomain.com]</b> 和同意ToS。</li>
-<li>輸入您域名的子域名 (哪怕是 <i>www</i>) 和 <i>http://</i> 在第一個欄位的前綴並保存。</li>
-<ol>
Index: extensions/Google2Piwigo/main.inc.php
===================================================================
--- extensions/Google2Piwigo/main.inc.php	(revision 28138)
+++ extensions/Google2Piwigo/main.inc.php	(revision 28832)
@@ -17,8 +17,11 @@
 define('PICASA_WA_ADMIN', get_root_url() . 'admin.php?page=plugin-' . PICASA_WA_ID);
 define('PICASA_WA_CACHE', PHPWG_ROOT_PATH . $conf['data_location'] . 'picasa_wa_cache/');
+define('PICASA_WA_VERSION',  'auto');
 
 
 include_once(PICASA_WA_PATH . 'include/ws_functions.inc.php');
 
+
+add_event_handler('init', 'picasa_wa_init');
 add_event_handler('ws_add_methods', 'picasa_wa_add_ws_method');
 
@@ -63,2 +66,12 @@
   }
 }
+
+function picasa_wa_init()
+{
+  global $conf;
+  include_once(PICASA_WA_PATH . 'maintain.inc.php');
+  $maintain = new Google2Piwigo_maintain(PICASA_WA_ID);
+  $maintain->autoUpdate(PICASA_WA_VERSION, 'install');
+
+  $conf['google2piwigo'] = unserialize($conf['google2piwigo']);
+}
Index: extensions/Google2Piwigo/maintain.inc.php
===================================================================
--- extensions/Google2Piwigo/maintain.inc.php	(revision 28832)
+++ extensions/Google2Piwigo/maintain.inc.php	(revision 28832)
@@ -0,0 +1,79 @@
+<?php
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
+
+class Google2Piwigo_maintain extends PluginMaintain
+{
+  private $installed = false;
+
+  private $default_conf = array(
+    'api_key' => null,
+    'secret_key' => null,
+    'auth_endpoint' => 'https://accounts.google.com/o/oauth2/auth',
+    'token_endpoint' => 'https://accounts.google.com/o/oauth2/token'
+    );
+
+  function install($plugin_version, &$errors=array())
+  {
+    global $conf;
+
+    if (empty($conf['google2piwigo']))
+    {
+      $conf['google2piwigo'] = serialize($this->default_conf);
+      conf_update_param('google2piwigo', $conf['google2piwigo']);
+    }
+
+    mkgetdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'picasa_wa_cache/', MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR);
+
+    $this->installed = true;
+  }
+
+  function activate($plugin_version, &$errors=array())
+  {
+    if (!$this->installed)
+    {
+      $this->install($plugin_version, $errors);
+    }
+  }
+
+  function deactivate()
+  {
+  }
+
+  function uninstall()
+  {
+    global $conf;
+
+    conf_delete_param('google2piwigo');
+
+    self::rrmdir(PHPWG_ROOT_PATH . $conf['data_location'] . 'picasa_wa_cache/');
+  }
+
+  static 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 && self::rrmdir($path);
+        }
+        else
+        {
+          $return = $return && @unlink($path);
+        }
+      }
+    }
+
+    return $return && @rmdir($dir);
+  }
+}
