source: extensions/user_delete_photo/initpicture.php @ 31844

Revision 31464, 3.7 KB checked in by ddtddt, 4 years ago (diff)

[extensions] - user_delete_photo - 2.8

Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | user delete photo plugin for piwigo                                   |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2013 - 2016 ddtddt             http://temmii.com/piwigo/ |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22//Add prefilter
23add_event_handler('loc_begin_picture', 'udp', 55 );
24 function udp()
25  {
26  global $template;
27  $template->set_prefilter('picture', 'udpT');
28  }
29
30 function udpT($content, &$smarty)
31  {
32  global $conf;
33  $search = '#<div id="'.$conf['udp'].'" class="imageInfo">#';
34  $replacement = '
35{if $UDFA}
36 <div id="udp" class="imageInfo">
37  <form method="post">
38   <input class="submit" name="submitudpA" type="submit" value="{\'delete photo\'|@translate}">
39   <label><input type="checkbox" name="confirm_deletionudp" value="1"> {\'Are you sure?\'|@translate}</label>
40  </form>
41 </div>
42{/if}
43 <div id="'.$conf['udp'].'" class="imageInfo">';
44  return preg_replace($search, $replacement, $content);
45  }
46
47add_event_handler('loc_begin_picture', 'udpA');
48
49 function udpA()
50{
51  global $conf, $page, $template  ;
52  load_language('plugin.lang', UDP_PATH);
53  load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
54  global $conf, $user, $page;
55
56  $query = '
57select added_by
58  FROM ' . IMAGES_TABLE . '
59  WHERE id = \''.$page['image_id'].'\'
60  ;';
61$result = pwg_query($query);
62$row = pwg_db_fetch_assoc($result);
63$userudp=$row['added_by'];
64 
65  $query = '
66select '.$conf['user_fields']['username'].' AS username
67  FROM ' . USERS_TABLE . '
68  WHERE '.$conf['user_fields']['id'].' = \''.$userudp.'\'
69  ;';
70$result = pwg_query($query);
71$row = pwg_db_fetch_assoc($result);
72$udp=$row['username'];
73
74if (($udp == $user['username']))
75 {
76 $template->assign(
77 array  (
78 'UDFA' => 'udp',
79 ));
80 }
81
82if ((isset($_POST['submitudpA']) and ($udp == $user['username'])))
83 {
84  if (!(isset($_POST['confirm_deletionudp']) and 1 == $_POST['confirm_deletionudp']))
85  {
86  array_push($page['errors'], l10n('You need to confirm deletion'));
87  }
88  else
89  {
90  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
91  global $page;
92  $deletephotoudp =array($page['image_id']);
93  delete_elements($deletephotoudp, true);
94  invalidate_user_cache();
95   if (isset($page['category']['id']))
96   {
97   $redirect_url = get_root_url().'index.php?/category/'.($page['category']['id']);
98   }
99   else
100   {
101   $redirect_url = get_root_url().'index.php?/'.($page['section']);
102   }
103   $_SESSION['page_infos'] = array(l10n('Photo deleted'));
104   redirect($redirect_url);
105  }
106 }
107}
108?>
Note: See TracBrowser for help on using the repository browser.