source: extensions/user_delete_photo/initpicture.php @ 31844

Last change on this file since 31844 was 31464, checked in by ddtddt, 8 years ago

[extensions] - user_delete_photo - 2.8

File size: 3.7 KB
RevLine 
[21964]1<?php
[31464]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
[26879]22//Add prefilter
[21964]23add_event_handler('loc_begin_picture', 'udp', 55 );
[26879]24 function udp()
25  {
26  global $template;
27  $template->set_prefilter('picture', 'udpT');
28  }
[21964]29
[26879]30 function udpT($content, &$smarty)
31  {
32  global $conf;
[21964]33  $search = '#<div id="'.$conf['udp'].'" class="imageInfo">#';
34  $replacement = '
35{if $UDFA}
[26879]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>
[21964]42{/if}
[26879]43 <div id="'.$conf['udp'].'" class="imageInfo">';
[21964]44  return preg_replace($search, $replacement, $content);
[26879]45  }
[21964]46
47add_event_handler('loc_begin_picture', 'udpA');
48
[26879]49 function udpA()
[21964]50{
[26879]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;
[21964]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'];
[26879]64 
[21964]65  $query = '
[26561]66select '.$conf['user_fields']['username'].' AS username
[21964]67  FROM ' . USERS_TABLE . '
[26561]68  WHERE '.$conf['user_fields']['id'].' = \''.$userudp.'\'
[21964]69  ;';
70$result = pwg_query($query);
71$row = pwg_db_fetch_assoc($result);
72$udp=$row['username'];
73
74if (($udp == $user['username']))
75 {
[26879]76 $template->assign(
77 array  (
78 'UDFA' => 'udp',
79 ));
[21964]80 }
81
82if ((isset($_POST['submitudpA']) and ($udp == $user['username'])))
[26879]83 {
84  if (!(isset($_POST['confirm_deletionudp']) and 1 == $_POST['confirm_deletionudp']))
[21964]85  {
[26879]86  array_push($page['errors'], l10n('You need to confirm deletion'));
[21964]87  }
[26879]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 }
[21964]107}
108?>
Note: See TracBrowser for help on using the repository browser.