Index: /extensions/hotlink_compatibility/admin.php
===================================================================
--- /extensions/hotlink_compatibility/admin.php	(revision 16274)
+++ /extensions/hotlink_compatibility/admin.php	(revision 16274)
@@ -0,0 +1,108 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $template, $page;
+load_language('plugin.lang', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
+
+// file contents
+if (!isset($conf['prefix_thumbnail'])) $conf['prefix_thumbnail'] = 'TN-';
+if (!isset($conf['dir_thumbnail']))    $conf['dir_thumbnail'] = 'thumbnail';
+
+$htaccess = PHPWG_ROOT_PATH.'/.htaccess';
+$htaccess_content = '
+<IfModule mod_rewrite.c>
+RewriteEngine on
+## redirect <2.4 thumbnails hotlinks to i.php
+RewriteRule ^upload/(.*)/'.preg_quote($conf['dir_thumbnail']).'/'.preg_quote($conf['prefix_thumbnail']).'(.*)\.(jpg|jpeg|png|gif)$ i.php?/upload/$1/$2-th.$3 [NC,L]
+RewriteRule ^galleries/(.*)/'.preg_quote($conf['dir_thumbnail']).'/'.preg_quote($conf['prefix_thumbnail']).'(.*)\.(jpg|jpeg|png|gif)$ i.php?/galleries/$1/$2-th.$3 [NC,L]
+
+## redirect <2.4 high-def hotlinks to original file
+RewriteRule ^upload/(.*)/pwg_high/(.*)\.(jpg|jpeg|png|gif)$ upload/$1/$2.$3 [NC,L]
+RewriteRule ^galleries/(.*)/pwg_high/(.*)\.(jpg|jpeg|png|gif)$ galleries/$1/$2.$3 [NC,L]
+
+## redirect <2.4 low-def hotlinks to i.php
+RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC]
+RewriteRule ^upload/(.*)/(.*)\.(jpg|jpeg|png|gif)$ i.php?/upload/$1/$2-me.$3 [NC,L]
+RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?'.preg_quote($_SERVER['SERVER_NAME']).'/.*$ [NC]
+RewriteRule ^galleries(.*)/(.*)\.(jpg|jpeg|png|gif)$ i.php?/galleries/$1/$2-me.$3 [NC,L]
+</IfModule>';
+
+
+// check if the file is writable
+$writable = true;
+if (file_exists($htaccess))
+{
+  if (!is_readable($htaccess) || !is_writable($htaccess))
+  {
+    $writable = false;
+  }
+}
+else
+{
+  $writable = is_writable(PHPWG_ROOT_PATH);
+}
+
+if (!$writable)
+{
+  array_push($page['errors'], l10n('.htaccess file is not writable'));
+  $template->assign('FILE_ERROR', true);
+  $template->assign('FILE_CONTENT', $htaccess_content);
+  $template->assign('DISPLAY_DESC', true);
+}
+else
+{
+  $continue = true;
+  $content = file_exists($htaccess) ? file_get_contents($htaccess) : null;
+
+  // check if RewriteEngine off
+  if (preg_match('#RewriteEngine\s+off#', $content))
+  {
+    array_push($page['errors'], l10n('Unable to activate RewriteEngine'));
+    $template->assign('REWRITE_ERROR', true);
+    $template->assign('DISPLAY_DESC', true);
+    $continue = false;
+  }
+  
+  // check if already updated
+  if (strpos($content, '## redirect <2.4') !== false)
+  {
+    array_push($page['infos'], l10n('Upgrade already applied, please remove this plugin'));
+    $template->assign('ALREADY_UPDATED', true);
+    $continue = false;
+  }
+
+  if ($continue)
+  {
+    if (isset($_GET['init_migration']))
+    {
+      if (strpos($content, 'RewriteEngine on') !== false)
+      {
+        $htaccess_content = str_replace('RewriteEngine on', null, $htaccess_content);
+      }
+      
+      file_put_contents($htaccess, "\n".$htaccess_content, FILE_APPEND);
+      
+      array_push($page['infos'], l10n('Upgrade successfully applied, please remove this plugin'));
+    }
+    else
+    {
+      // check if the host is incompatible
+      if (preg_match('#free\.fr/?$#', $_SERVER['SERVER_NAME']))
+      {
+        array_push($page['warnings'], l10n('Your host may be incompatible with URL rewriting'));
+        $template->assign('HOST_WARNING', true);
+      }
+      
+      $template->assign('DISPLAY_DESC', true);
+      $template->assign('NO_ERROR', true);
+    }
+  }
+}
+
+$template->assign('DESC_CONTENT', load_language('desc_content.html', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/', array('return'=>true)));
+$template->assign('URL_INIT', get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)).'&amp;init_migration');
+
+$template->set_filename('addht_content', dirname(__FILE__).'/admin.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'addht_content');
+
+?>  
Index: /extensions/hotlink_compatibility/admin.tpl
===================================================================
--- /extensions/hotlink_compatibility/admin.tpl	(revision 16274)
+++ /extensions/hotlink_compatibility/admin.tpl	(revision 16274)
@@ -0,0 +1,49 @@
+{html_head}{literal}
+<style type="text/css">
+  .warning { margin-top:20px; border:1px solid #a00;padding:5px;border-radius:3px; }
+  .addht { max-width:750px;margin:0 auto;text-align:justify; }
+  textarea { font-size:12px;width:730px; }
+</style>
+{/literal}{/html_head}
+
+<div class="titrePage">
+  <h2>{'Hotlink Compatibility'|@translate}</h2>
+</div>
+
+<div class="addht">
+{if $DISPLAY_DESC}
+<p>
+{$DESC_CONTENT}
+</p>
+{/if}
+
+{if $FILE_ERROR}
+<p class="warning">
+{'Piwigo can\'t create or modify the .htaccess, you would have to do it manually if you want to apply this upgrade. Here is what you must put in the file:'|@translate}
+</p>
+<p><textarea rows="17">{$FILE_CONTENT}</textarea></p>
+{/if}
+
+{if $REWRITE_ERROR}
+<p class="warning">
+{'You already have a .htaccess file but it blocks the rewrite engine (line <i>RewriteEngine off</i>), please remove this line to allow Piwigo to apply the upgrade.'|@translate}
+</p>
+{/if}
+
+{if $HOST_WARNING}
+<p class="warning">
+{'Your gallery is hosted by a service known to have issues with URL Rewriting, you apply this upgrade at your own risk.'|@translate}
+</p>
+{/if}
+
+
+{if $NO_ERROR}
+<p>
+{if $HOST_WARNING}
+  <a href="{$URL_INIT}" onClick="return confirm('{'Are you sure?'|@translate}');">{'Apply upgrade anyway'|@translate}</a>
+{else}
+  <br><a href="{$URL_INIT}" onClick="return confirm('{'Are you sure?'|@translate}');">{'Apply upgrade'|@translate}</a>
+{/if}
+</p>
+{/if}
+</div>
Index: /extensions/hotlink_compatibility/index.php
===================================================================
--- /extensions/hotlink_compatibility/index.php	(revision 16274)
+++ /extensions/hotlink_compatibility/index.php	(revision 16274)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/hotlink_compatibility/language/en_UK/desc_content.html
===================================================================
--- /extensions/hotlink_compatibility/language/en_UK/desc_content.html	(revision 16274)
+++ /extensions/hotlink_compatibility/language/en_UK/desc_content.html	(revision 16274)
@@ -0,0 +1,8 @@
+Piwigo 2.4 introduces the Multisize feature which includes many technical changes, especially int the filesystem : instead of 2 or 3 version of each photo (websize, thumbnail, high-def), we now only keep on version (original) on <i>upload</i> and <i>galleries</i> directories. The consequences are :
+<ul>
+  <li>hotlinks on "web size" becomes hotlinks on originals</li>
+  <li>hotlinks on HD no longer works</li>
+  <li>hotlinks on thumbnails no longer works</li>
+</ul>
+To solve this, we created this plugin which tries to create or modify the .htaccess file on the root of your installation. This file contains some url rewrite rules informing your host that links to pictures had changed.<br>
+<b>If your don't use hotlinks to your gallery you might not apply the following upgrade and remove this plugin.</b>
Index: /extensions/hotlink_compatibility/language/en_UK/description.txt
===================================================================
--- /extensions/hotlink_compatibility/language/en_UK/description.txt	(revision 16274)
+++ /extensions/hotlink_compatibility/language/en_UK/description.txt	(revision 16274)
@@ -0,0 +1,1 @@
+Update your .htaccess file to resolve your old hotlinks, useless for new users in Piwigo 2.4 or above.
Index: /extensions/hotlink_compatibility/language/en_UK/index.php
===================================================================
--- /extensions/hotlink_compatibility/language/en_UK/index.php	(revision 16274)
+++ /extensions/hotlink_compatibility/language/en_UK/index.php	(revision 16274)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/hotlink_compatibility/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/hotlink_compatibility/language/en_UK/plugin.lang.php	(revision 16274)
+++ /extensions/hotlink_compatibility/language/en_UK/plugin.lang.php	(revision 16274)
@@ -0,0 +1,14 @@
+<?php
+
+$lang['.htaccess file is not writable'] = '.htaccess file is not writable';
+$lang['Unable to activate RewriteEngine'] = 'Unable to activate RewriteEngine';
+$lang['Upgrade already applied, please remove this plugin'] = 'Upgrade already applied, please remove this plugin';
+$lang['Upgrade successfully applied, please remove this plugin'] = 'Upgrade successfully applied, please remove this plugin';
+$lang['Your host may be incompatible with URL rewriting'] = 'Your host may be incompatible with URL rewriting';
+$lang['Piwigo can\'t create or modify the .htaccess, you would have to do it manually if you want to apply this upgrade. Here is what you must put in the file:'] = 'Piwigo can\'t create or modify the .htaccess, you would have to do it manually if you want to apply this upgrade. Here is what you must put in the file:';
+$lang['You already have a .htaccess file but it blocks the rewrite engine (line <i>RewriteEngine off</i>), please remove this line to allow Piwigo to apply the upgrade.'] = 'You already have a .htaccess file but it blocks the rewrite engine (line <i>RewriteEngine off</i>), please remove this line to allow Piwigo to apply the upgrade.';
+$lang['Your gallery is hosted by a service known to have issues with URL Rewriting, you apply this upgrade at your own risk.'] = 'Your gallery is hosted by a service known to have issues with URL Rewriting, you apply this upgrade at your own risk.';
+$lang['Apply upgrade anyway'] = 'Apply upgrade anyway';
+$lang['Apply upgrade'] = 'Apply upgrade';
+
+?>
Index: /extensions/hotlink_compatibility/language/fr_FR/desc_content.html
===================================================================
--- /extensions/hotlink_compatibility/language/fr_FR/desc_content.html	(revision 16274)
+++ /extensions/hotlink_compatibility/language/fr_FR/desc_content.html	(revision 16274)
@@ -0,0 +1,8 @@
+Piwigo 2.4 a ajouté l'option de tailles multiple, cette option implique de nombreux changements techniques, en particulier dans le système de fichiers : au lieu d'avoir 2 ou 3 versions de chaque photo (taille web, miniature, haute-définition), nous ne stockons qu'une seule version (l'originale) dans les dossiers <i>upload</i> et <i>galleries</i>. Les conséquences sont :
+<ul>
+  <li>les hotlinks vers les tailles web deviennent des hotlinks vers les originaux</li>
+  <li>les hotlinks vers les versions haute-définition ne fonctionnent plus</li>
+  <li>les hotlinks vers les miniatures ne fonctionnent plus</li>
+</ul>
+Piur résoudre ceci, nous avons créé ce plugin, qui essaye de créer ou modifier le fichier .htaccess à la racine de votre installation. Ce fichier contient des règles de réécriture d'URL (URL Rewriting) informant le serveur que l'emplacement des photos a changé.<br>
+<b>Si vous n'utilisiez pas de hotlinks vers votre galerie, vous ne devriez pas appliquer cette mise à jour, et déssintaller le plugin.</b>
Index: /extensions/hotlink_compatibility/language/fr_FR/description.txt
===================================================================
--- /extensions/hotlink_compatibility/language/fr_FR/description.txt	(revision 16274)
+++ /extensions/hotlink_compatibility/language/fr_FR/description.txt	(revision 16274)
@@ -0,0 +1,1 @@
+Met à jour le fichier .htaccess pour résoudre les vieux hotlinks, inutile pour les nouveaux utilisateurs de Piwigo 2.4 ou supérieur.
Index: /extensions/hotlink_compatibility/language/fr_FR/index.php
===================================================================
--- /extensions/hotlink_compatibility/language/fr_FR/index.php	(revision 16274)
+++ /extensions/hotlink_compatibility/language/fr_FR/index.php	(revision 16274)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/hotlink_compatibility/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/hotlink_compatibility/language/fr_FR/plugin.lang.php	(revision 16274)
+++ /extensions/hotlink_compatibility/language/fr_FR/plugin.lang.php	(revision 16274)
@@ -0,0 +1,14 @@
+<?php
+
+$lang['.htaccess file is not writable'] = 'Le fichier .htaccess n\'est pas accessible en écriture';
+$lang['Unable to activate RewriteEngine'] = 'Impossible d\'activer RewriteEngine';
+$lang['Upgrade already applied, please remove this plugin'] = 'La mise à jour est déjà appliquée, veuillez désactiver le plugin';
+$lang['Upgrade successfully applied, please remove this plugin'] = 'Mise à jour appliquée avec succès, veuillez désactiver le plugin';
+$lang['Your host may be incompatible with URL rewriting'] = 'Votre hébergeur n\'est peut-être pas compatible avec l\'URL Rewriting';
+$lang['Piwigo can\'t create or modify the .htaccess, you would have to do it manually if you want to apply this upgrade. Here is what you must put in the file:'] = 'Piwigo ne peut pas créer le fichier .htaccess, vous devrez le faire manuellement si vous voulez appliquer la mise à jour. Voici le contenu que vous devrez ajouter au fichier :';
+$lang['You already have a .htaccess file but it blocks the rewrite engine (line <i>RewriteEngine off</i>), please remove this line to allow Piwigo to apply the upgrade.'] = 'Vous avez déjà un fichier .htaccess mais il bloque le processus de réécriture (ligne <i>RewriteEngine off</i>), veuillez supprimer cette ligne pour permettre à Piwigo de continuer la mise à jour.';
+$lang['Your gallery is hosted by a service known to have issues with URL Rewriting, you apply this upgrade at your own risk.'] = 'Votre gallerie est hébergée par un service connu pour présenter des problèmes avec l\'URL Rewriting, vous appliquez cette mis eà jour à vos risques et périls.';
+$lang['Apply upgrade anyway'] = 'Quand même appliquer la mise à jour';
+$lang['Apply upgrade'] = 'Appliquer la mise à jour';
+
+?>
Index: /extensions/hotlink_compatibility/language/index.php
===================================================================
--- /extensions/hotlink_compatibility/language/index.php	(revision 16274)
+++ /extensions/hotlink_compatibility/language/index.php	(revision 16274)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/hotlink_compatibility/main.inc.php
===================================================================
--- /extensions/hotlink_compatibility/main.inc.php	(revision 16274)
+++ /extensions/hotlink_compatibility/main.inc.php	(revision 16274)
@@ -0,0 +1,27 @@
+<?php
+/*
+Plugin Name: Hotlink Compatibility
+Version: auto
+Description: Update your .htaccess file to resolve your old hotlinks, useless for new users in Piwigo 2.4 or above.
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=613
+Author: Piwigo Team
+Author URI: http://www.piwigo.org
+*/
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+if (script_basename() == 'admin')
+{
+  add_event_handler('get_admin_plugin_menu_links', 'addht_plugin_admin_menu');
+
+  function addht_plugin_admin_menu($menu)
+  {
+    array_push($menu, array(
+      'NAME' => 'Hotlink Compatibility',
+      'URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__))
+      ));
+    return $menu;
+  }
+}
+
+?>
