source: extensions/DownloadFromThumbnail/main.inc.php @ 32504

Last change on this file since 32504 was 31410, checked in by ddtddt, 9 years ago

[extensions] - DownloadFromThumbnail

File size: 3.5 KB
Line 
1<?php
2/*
3Plugin Name: Download From Thumbnail
4Version: 2.7.0
5Description:
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
7Author: ddtddt
8Author URI: http://temmii.com/piwigo/
9*/
10// +-----------------------------------------------------------------------+
11// | Download From Thumbnail plugin for piwigo                             |
12// +-----------------------------------------------------------------------+
13// | Copyright(C) 2015-2016 ddtddt               http://temmii.com/piwigo/ |
14// +-----------------------------------------------------------------------+
15// | This program is free software; you can redistribute it and/or modify  |
16// | it under the terms of the GNU General Public License as published by  |
17// | the Free Software Foundation                                          |
18// |                                                                       |
19// | This program is distributed in the hope that it will be useful, but   |
20// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
21// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
22// | General Public License for more details.                              |
23// |                                                                       |
24// | You should have received a copy of the GNU General Public License     |
25// | along with this program; if not, write to the Free Software           |
26// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
27// | USA.                                                                  |
28// +-----------------------------------------------------------------------+
29
30defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
31
32global $conf, $prefixeTable;
33
34define('DST_ID',          basename(dirname(__FILE__)));
35define('DST_PATH',        PHPWG_PLUGINS_PATH . DST_ID . '/');
36
37add_event_handler('init', 'DST_init');
38add_event_handler('loc_end_index_thumbnails', 'DST_thumbnails_list', EVENT_HANDLER_PRIORITY_NEUTRAL-10, 2);
39
40
41function DST_init()
42{
43  if (mobile_theme())
44  {
45    return;
46  }
47  load_language('plugin.lang', DST_PATH);
48   
49}
50
51function DST_thumbnails_list($tpl_thumbnails_var, $pictures)
52{
53  if (is_a_guest()) return $tpl_thumbnails_var;
54
55  global $page, $template,$conf, $user;
56
57  $template->set_prefilter('index_thumbnails', 'DST_prefilter_thumbnails');
58  $template->set_filename('DST', realpath(DST_PATH.'dst.tpl'));
59  $template->append('head_elements',$template->parse('DST',true));
60
61 
62  // the content is different on collection edition page and no button on batch downloader set edition page
63  if (empty($pictures))
64  {
65    return $tpl_thumbnails_var;
66  }
67
68  $query = '
69  SELECT enabled_high
70  FROM '.USER_INFOS_TABLE.'
71  WHERE user_id = \''.$user['id'].'\'
72  ;';
73  $result = pwg_query($query);
74  $row = pwg_db_fetch_assoc($result);
75  if($row['enabled_high']=='true'){
76        $template->assign('PLUG_DST', 'ok');
77  }
78  foreach ($tpl_thumbnails_var as &$thumbnail)
79  {
80    $thumbnail['dowpic']=DST_PATH.'save.png';
81  }
82 
83  $template->func_combine_css(array('id'=>'dst','path'=>DST_PATH.'dst.css'));
84 
85  return $tpl_thumbnails_var;
86}
87
88function DST_prefilter_thumbnails($content, &$smarty) {
89        global $template;
90
91       
92 $search = '#(<span class="wrap2">)#';
93 $replace = '$1
94  {strip}{if isset($PLUG_DST)}
95  <form method="post" >
96  <a href="{$thumbnail.path}" class="dowpica" data-id="{$thumbnail.id}" download="{$thumbnail.name}" title="{\'Download this file\'|@translate}" rel="nofollow">
97  <img class="dowpic" src="{$thumbnail.dowpic}" /></a>
98  </form>
99  {/if}{/strip}
100';
101
102  return preg_replace($search, $replace, $content);
103       
104}
105
Note: See TracBrowser for help on using the repository browser.