source: extensions/user_delete_photo/initpicture.php

Last change on this file was 32998, checked in by ddtddt, 4 months ago

[user_delete_photo] bug thanks to OpenPicture /check Php8.3 and Piwigo14

File size: 3.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | user delete photo plugin for piwigo by TEMMII                         |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2013 - 2023 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 );
24function udp(){
25  global $template;
26  $template->set_prefilter('picture', 'udpT');
27}
28function udpT($content){
29  global $conf;
30  $search = '#<div id="'.$conf['udp'].'" class="imageInfo">#';
31  $replacement = '
32{if isset ($UDFA)}
33 <div id="udp" class="imageInfo">
34  <form method="post">
35   <input class="submit" name="submitudpA" type="submit" value="{\'delete photo\'|@translate}">
36   <label><input type="checkbox" name="confirm_deletionudp" value="1"> {\'Are you sure?\'|@translate}</label>
37  </form>
38 </div>
39{/if}
40 <div id="'.$conf['udp'].'" class="imageInfo">';
41  return preg_replace($search, $replacement, $content);
42}
43
44add_event_handler('loc_begin_picture', 'udpA');
45function udpA(){
46  global $conf, $page, $template  ;
47  load_language('plugin.lang', UDP_PATH);
48  load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
49  global $conf, $user, $page;
50
51  $query = '
52select added_by
53  FROM ' . IMAGES_TABLE . '
54  WHERE id = \''.$page['image_id'].'\'
55  ;';
56$result = pwg_query($query);
57$row = pwg_db_fetch_assoc($result);
58$userudp=$row['added_by'];
59 
60  $query = '
61select '.$conf['user_fields']['username'].' AS username
62  FROM ' . USERS_TABLE . '
63  WHERE '.$conf['user_fields']['id'].' = \''.$userudp.'\'
64  ;';
65$result = pwg_query($query);
66$row = pwg_db_fetch_assoc($result);
67$udp=$row['username'];
68
69if (($udp == $user['username'])){
70 $template->assign(
71 array(
72 'UDFA' => 'udp',
73 ));
74}
75
76if ((isset($_POST['submitudpA']) and ($udp == $user['username'])))
77 {
78  if (!(isset($_POST['confirm_deletionudp']) and 1 == $_POST['confirm_deletionudp']))
79  {
80  array_push($page['errors'], l10n('You need to confirm deletion'));
81  }
82  else
83  {
84  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
85  global $page;
86  $deletephotoudp =array($page['image_id']);
87  delete_elements($deletephotoudp, true);
88  invalidate_user_cache();
89   if (isset($page['category']['id']))
90   {
91   $redirect_url = get_root_url().'index.php?/category/'.($page['category']['id']);
92   }
93   else
94   {
95   $redirect_url = get_root_url().'index.php?/'.($page['section']);
96   }
97   $_SESSION['page_infos'] = array(l10n('Photo deleted'));
98   redirect($redirect_url);
99  }
100 }
101}
102?>
Note: See TracBrowser for help on using the repository browser.