Index: /extensions/most_downloaded/initadmin.php
===================================================================
--- /extensions/most_downloaded/initadmin.php	(revision 31453)
+++ /extensions/most_downloaded/initadmin.php	(revision 31453)
@@ -0,0 +1,31 @@
+<?php
+// +-----------------------------------------------------------------------+
+// |Most Downloaded for piwigo                                             |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2016 ddtddt                    http://temmii.com/piwigo/ |
+// +-----------------------------------------------------------------------+
+// | 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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+	add_event_handler('loc_begin_admin_page', 'most_downloaded_noactif' );
+	
+	function most_downloaded_noactif()
+{
+	global $page,$conf;
+	$page['errors'][] = l10n('Plugin Download Counter must be installe and activate for use Most Downloaded');
+	//add link to desactivate plugin
+}
+
+?>
Index: /extensions/most_downloaded/language/en_UK/description.txt
===================================================================
--- /extensions/most_downloaded/language/en_UK/description.txt	(revision 31453)
+++ /extensions/most_downloaded/language/en_UK/description.txt	(revision 31453)
@@ -0,0 +1,1 @@
+Add a "Most Downloaded" link in "Specials" menu. (Plugin download counter must be activate)
Index: /extensions/most_downloaded/language/en_UK/index.php
===================================================================
--- /extensions/most_downloaded/language/en_UK/index.php	(revision 31453)
+++ /extensions/most_downloaded/language/en_UK/index.php	(revision 31453)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | 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/most_downloaded/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/most_downloaded/language/en_UK/plugin.lang.php	(revision 31453)
+++ /extensions/most_downloaded/language/en_UK/plugin.lang.php	(revision 31453)
@@ -0,0 +1,25 @@
+<?php
+// +-----------------------------------------------------------------------+
+// |Most Downloaded for piwigo                                             |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2016 ddtddt                    http://temmii.com/piwigo/ |
+// +-----------------------------------------------------------------------+
+// | 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.                                                                  |
+// +-----------------------------------------------------------------------+
+$lang['Most downloaded'] = 'Most downloaded';
+$lang['displays most downloaded Photos'] = 'displays most downloaded Photos';
+$lang['Plugin Download Counter must be installe and activate for use Most Downloaded'] = 'Plugin Download Counter must be installe and activate for use Most Downloaded';
+
+?>
Index: /extensions/most_downloaded/language/fr_FR/description.txt
===================================================================
--- /extensions/most_downloaded/language/fr_FR/description.txt	(revision 31453)
+++ /extensions/most_downloaded/language/fr_FR/description.txt	(revision 31453)
@@ -0,0 +1,1 @@
+Ajoute un lien "Plus téléchargés" dans le menu "Spéciales" 'le plugin download counter doit être activé.
Index: /extensions/most_downloaded/language/fr_FR/index.php
===================================================================
--- /extensions/most_downloaded/language/fr_FR/index.php	(revision 31453)
+++ /extensions/most_downloaded/language/fr_FR/index.php	(revision 31453)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | 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/most_downloaded/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/most_downloaded/language/fr_FR/plugin.lang.php	(revision 31453)
+++ /extensions/most_downloaded/language/fr_FR/plugin.lang.php	(revision 31453)
@@ -0,0 +1,25 @@
+<?php
+// +-----------------------------------------------------------------------+
+// |Most Downloaded for piwigo                                             |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2016 ddtddt                    http://temmii.com/piwigo/ |
+// +-----------------------------------------------------------------------+
+// | 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.                                                                  |
+// +-----------------------------------------------------------------------+
+$lang['Most downloaded'] = 'Plus téléchargées';
+$lang['displays most downloaded Photos'] = 'affiché les photos les plus téléchargées';
+$lang['Plugin Download Counter must be installe and activate for use Most Downloaded'] = 'Le plugin Download Counter doit-être installé et activé pour utiliser Most Downloaded';
+
+?>
Index: /extensions/most_downloaded/main.inc.php
===================================================================
--- /extensions/most_downloaded/main.inc.php	(revision 31453)
+++ /extensions/most_downloaded/main.inc.php	(revision 31453)
@@ -0,0 +1,146 @@
+<?php
+/*
+Plugin Name: Most Downloaded
+Version: auto
+Description: Add a "Most Downloaded" link in "Specials" menu. (Plugin download counter must be activate)
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=827
+Author: ddtddt
+Author URI: http://temmii.com/piwigo/
+*/
+
+// +-----------------------------------------------------------------------+
+// |Most Downloaded for piwigo                                             |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2016 ddtddt                    http://temmii.com/piwigo/ |
+// +-----------------------------------------------------------------------+
+// | 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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
+
+define('MOSTDOWNLOADED_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+
+add_event_handler('loading_lang', 'most_downloaded_loading_lang');	  
+function most_downloaded_loading_lang(){
+  load_language('plugin.lang', MOSTDOWNLOADED_PATH);
+}
+
+$desac = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'download_counter';"));
+
+if($desac['state'] != 'active'){
+  if (script_basename() == 'admin'){
+   include_once(dirname(__FILE__).'/initadmin.php');
+  }
+}else{
+
+  
+  add_event_handler('blockmanager_apply' , 'add_link_most_downloaded');
+  add_event_handler('loc_end_section_init', 'section_init_most_downloaded');
+  
+  function add_link_most_downloaded($menu_ref_arr){
+    global $conf;
+    $menu = &$menu_ref_arr[0];
+    $position = (isset($conf['most_downloaded_position']) and is_numeric($conf['most_downloaded_position'])) ? $conf['most_downloaded_position'] : 4;
+    if (($block = $menu->get_block('mbSpecials')) != null){
+     array_splice($block->data, $position-1, 0, array('most_downloaded' =>
+      array(
+        'URL' => make_index_url(array('section' => 'most_downloaded')),
+        'TITLE' => l10n('displays most downloaded Photos'),
+        'NAME' => l10n('Most downloaded')
+        )
+      )
+    );
+   }
+  }
+
+function section_init_most_downloaded()
+{
+  global $tokens, $page, $conf;
+  
+  if (!in_array('most_downloaded', $tokens))
+  {
+    return;
+  }
+  
+  $page['section'] = 'most_downloaded';
+  $page['title'] = '<a href="' . duplicate_index_url() . '">' . l10n('Most downloaded') . '</a>';
+  $page['section_title'] = '<a href="'.get_gallery_home_url().'">' . l10n('Home') . '</a>'
+    . $conf['level_separator'] . $page['title'];
+
+  $query = '
+SELECT DISTINCT image_id
+    FROM ' . IMAGE_CATEGORY_TABLE . '
+    WHERE ' .  
+      get_sql_condition_FandF(
+        array(
+          'forbidden_categories' => 'category_id',
+          'visible_categories' => 'category_id',
+          'visible_images' => 'image_id',
+          ),
+        '', true
+        )
+    . '
+;';
+
+  $img = query2array($query, null, 'image_id');
+
+  if (empty($img))
+  {
+    $page['items'] = array();
+  }
+  else
+  {
+    $query = 'SELECT id, download_counter FROM ' . IMAGES_TABLE . ' AS img WHERE img.id IN (' . implode(',', $img) . ') and download_counter > 0 ORDER BY download_counter DESC, img.hit DESC LIMIT ' . $conf['top_number'] . ';';
+    $page['items'] = query2array($query, null, 'id');
+    
+  add_event_handler('loc_end_index_thumbnails', 'add_nb_most_downloaded');
+}
+
+function add_nb_most_downloaded($tpl_thumbnails_var){
+  global $template, $user, $selection;
+
+  // unsed sort order
+  $template->clear_assign('image_orders');
+
+    $query = 'SELECT id, download_counter FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $selection).');';
+    $nb_download = query2array($query, 'id', 'download_counter');
+    
+    foreach ($tpl_thumbnails_var as &$row)
+    {
+      $row['download_counter'] = $nb_download[$row['id']];
+    }
+    unset($row);
+  
+
+  return $tpl_thumbnails_var;
+}
+
+
+}
+  
+}
+
+
+
+
+
+
+
+   
+
+
+
+
+
Index: /extensions/most_downloaded/maintain.class.php
===================================================================
--- /extensions/most_downloaded/maintain.class.php	(revision 31453)
+++ /extensions/most_downloaded/maintain.class.php	(revision 31453)
@@ -0,0 +1,50 @@
+<?php
+
+// +-----------------------------------------------------------------------+
+// |Most Downloaded for piwigo                                             |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2016 ddtddt                    http://temmii.com/piwigo/ |
+// +-----------------------------------------------------------------------+
+// | 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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+class most_downloaded_maintain extends PluginMaintain
+{
+  function install($plugin_version, &$errors=array())
+  {
+$q = pwg_query('SHOW COLUMNS FROM ' . HISTORY_TABLE . ' LIKE "section"');
+  $section = pwg_db_fetch_array($q);
+  $type = $section['Type'];
+
+  if (substr_count($type, 'most_downloaded') == 0)
+  {
+    $type = strtr($type , array(')' => ',\'most_downloaded\')'));
+  }
+
+  pwg_query('ALTER TABLE ' . HISTORY_TABLE . ' CHANGE section section ' . $type . ' DEFAULT NULL');
+  }
+
+  function update($old_version, $new_version, &$errors=array())
+  {
+	$this->install($new_version, $errors);
+  }
+
+  function uninstall()
+  {
+
+  }
+}
