source: extensions/most_downloaded/main.inc.php @ 32418

Last change on this file since 32418 was 32418, checked in by ddtddt, 3 years ago

[most_downloaded] piwigo 11

File size: 4.7 KB
Line 
1<?php
2/*
3Plugin Name: Most Downloaded
4Version: auto
5Description: Add a "Most Downloaded" link in "Specials" menu. (Plugin download counter must be activate)
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=827
7Author: ddtddt
8Author URI: http://temmii.com/piwigo/
9*/
10
11// +-----------------------------------------------------------------------+
12// |Most Downloaded for piwigo by TEMMII                                   |
13// +-----------------------------------------------------------------------+
14// | Copyright(C) 2016 - 2021 ddtddt             http://temmii.com/piwigo/ |
15// +-----------------------------------------------------------------------+
16// | This program is free software; you can redistribute it and/or modify  |
17// | it under the terms of the GNU General Public License as published by  |
18// | the Free Software Foundation                                          |
19// |                                                                       |
20// | This program is distributed in the hope that it will be useful, but   |
21// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
22// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
23// | General Public License for more details.                              |
24// |                                                                       |
25// | You should have received a copy of the GNU General Public License     |
26// | along with this program; if not, write to the Free Software           |
27// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
28// | USA.                                                                  |
29// +-----------------------------------------------------------------------+
30
31defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
32
33define('MOSTDOWNLOADED_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
34
35add_event_handler('loading_lang', 'most_downloaded_loading_lang');       
36function most_downloaded_loading_lang(){
37  load_language('plugin.lang', MOSTDOWNLOADED_PATH);
38}
39
40global $pwg_loaded_plugins;
41
42if (!isset($pwg_loaded_plugins['download_counter'])){
43  if (script_basename() == 'admin'){
44   include_once(dirname(__FILE__).'/initadmin.php');
45  }
46}else{
47 
48  add_event_handler('blockmanager_apply' , 'add_link_most_downloaded');
49  add_event_handler('loc_end_section_init', 'section_init_most_downloaded');
50 
51  function add_link_most_downloaded($menu_ref_arr){
52    global $conf;
53    $menu = &$menu_ref_arr[0];
54    $position = (isset($conf['most_downloaded_position']) and is_numeric($conf['most_downloaded_position'])) ? $conf['most_downloaded_position'] : 4;
55    if (($block = $menu->get_block('mbSpecials')) != null){
56     array_splice($block->data, $position-1, 0, array('most_downloaded' =>
57      array(
58        'URL' => make_index_url(array('section' => 'most_downloaded')),
59        'TITLE' => l10n('displays most downloaded Photos'),
60        'NAME' => l10n('Most downloaded')
61        )
62      )
63    );
64   }
65  }
66
67function section_init_most_downloaded()
68{
69  global $tokens, $page, $conf;
70 
71  if (!in_array('most_downloaded', $tokens))
72  {
73    return;
74  }
75 
76  $page['section'] = 'most_downloaded';
77  $page['title'] = '<a href="' . duplicate_index_url() . '">' . l10n('Most downloaded') . '</a>';
78  $page['section_title'] = '<a href="'.get_gallery_home_url().'">' . l10n('Home') . '</a>'
79    . $conf['level_separator'] . $page['title'];
80
81  $query = '
82SELECT DISTINCT image_id
83    FROM ' . IMAGE_CATEGORY_TABLE . '
84    WHERE ' . 
85      get_sql_condition_FandF(
86        array(
87          'forbidden_categories' => 'category_id',
88          'visible_categories' => 'category_id',
89          'visible_images' => 'image_id',
90          ),
91        '', true
92        )
93    . '
94;';
95
96  $img = query2array($query, null, 'image_id');
97
98  if (empty($img))
99  {
100    $page['items'] = array();
101  }
102  else
103  {
104    $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'] . ';';
105    $page['items'] = query2array($query, null, 'id');
106   
107  add_event_handler('loc_end_index_thumbnails', 'add_nb_most_downloaded');
108}
109
110function add_nb_most_downloaded($tpl_thumbnails_var){
111  global $template, $user, $selection;
112
113  // unsed sort order
114  $template->clear_assign('image_orders');
115
116    $query = 'SELECT id, download_counter FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $selection).');';
117    $nb_download = query2array($query, 'id', 'download_counter');
118   
119    foreach ($tpl_thumbnails_var as &$row)
120    {
121      $row['download_counter'] = $nb_download[$row['id']];
122    }
123    unset($row);
124 
125
126  return $tpl_thumbnails_var;
127}
128
129
130}
131 
132}
133
134
135
136
137
138
139
140   
141
142
143
144
145
Note: See TracBrowser for help on using the repository browser.