source: extensions/user_delete_photo/initpicture.php @ 26879

Last change on this file since 26879 was 26879, checked in by ddtddt, 10 years ago

[extensions] - user_delete_photo - redirection in the right section if the user isn't in album

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