source: extensions/delete_hit_rate/initadmin.php @ 32423

Last change on this file since 32423 was 32386, checked in by ddtddt, 3 years ago

[delete_hit_rate] piwigo 11

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1<?php
2
3// +-----------------------------------------------------------------------+
4// | Delete Hit/Rate plugin for piwigo  by TEMMII                          |
5// +-----------------------------------------------------------------------+
6// | Copyright(C) 2011-2021 ddtddt               http://temmii.com/piwigo/ |
7// +-----------------------------------------------------------------------+
8// | This program is free software; you can redistribute it and/or modify  |
9// | it under the terms of the GNU General Public License as published by  |
10// | the Free Software Foundation                                          |
11// |                                                                       |
12// | This program is distributed in the hope that it will be useful, but   |
13// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
14// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
15// | General Public License for more details.                              |
16// |                                                                       |
17// | You should have received a copy of the GNU General Public License     |
18// | along with this program; if not, write to the Free Software           |
19// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
20// | USA.                                                                  |
21// +-----------------------------------------------------------------------+
22
23if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
24
25define('PDHR_DIR' , basename(dirname(__FILE__)));
26define('PDHR_PATH' , PHPWG_PLUGINS_PATH . PDHR_DIR . '/');
27load_language('plugin.lang', PDHR_PATH);
28define('PDHR_ADMIN',get_root_url().'admin.php?page=plugin-'.PDHR_DIR);
29
30/*add_event_handler('get_admin_plugin_menu_links', 'dphr_admin_menu');
31function dphr_admin_menu($menu){
32  load_language('plugin.lang', PDHR_PATH);
33  $menu[] = array(
34    'NAME' => l10n('Delete Hit/Rate'),
35    'URL' => PDHR_ADMIN,
36  );
37  return $menu;
38}*/
39
40//add prefiltre photo
41add_event_handler('loc_begin_admin', 'plugdphrPf',60);
42add_event_handler('loc_begin_admin', 'plugdphrPf2',60);
43
44function plugdphrPf()
45  {
46  global $template;
47  $admin_base_url = $_SERVER['REQUEST_URI'];
48  $template->set_prefilter('picture_modify', 'plugdphrPT');
49 $template->assign(
50    array(
51                'U_DELETEPHIT' => $admin_base_url . '&amp;deletephit',
52                'U_DELETEPRATE' => $admin_base_url . '&amp;deleteprate',
53  ));
54  }
55
56function plugdphrPT($content, &$smarty)
57        {
58load_language('plugin.lang', PDHR_PATH);
59  $search = "#        </div>
60      </div>
61    </div>
62
63
64    <p>
65      <strong>#";
66 
67  $replacement = '        </div>
68      </div>
69    </div>
70
71
72    <p>
73      <strong>
74        <a class="icon-trash mouse" href="{$U_DELETEPHIT}" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');">{\'Purge hit of the photo\'|@translate}</a><br>
75        <a class="icon-trash mouse" href="{$U_DELETEPRATE}" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');">{\'Purge rate of the photo\'|@translate}</a><br><br>
76  ';
77
78  return preg_replace($search, $replacement, $content);
79        }
80               
81function plugdphrPf2()
82        {
83if (isset($_GET['deletephit'])) {
84  $admin_base_url=explode('&deletephit', $_SERVER['REQUEST_URI']);
85  $photoid = explode('photo-', $_SERVER['REQUEST_URI']);
86  if(strstr($photoid[1], '-properties')){$photoid = explode('-properties', $photoid[1]);}
87  else if(strstr($photoid[1], '&cat')){$photoid = explode('&cat', $photoid[1]);}
88  else{
89  $_SESSION['page_infos'] = array('error');
90  redirect($_SERVER['REQUEST_URI']);
91  }
92  $_SESSION['page_infos'] = $admin_base_url;
93  $query = 'UPDATE ' . IMAGES_TABLE . ' SET hit= \'0\' WHERE id = '.$photoid[0].';';
94  $result = pwg_query($query);
95  redirect($admin_base_url[0]);
96} 
97
98if (isset($_GET['deleteprate'])) {
99  $admin_base_url=explode('&deleteprate', $_SERVER['REQUEST_URI']);
100  $photoid = explode('photo-', $_SERVER['REQUEST_URI']);
101  if(strstr($photoid[1], '-properties')){$photoid = explode('-properties', $photoid[1]);}
102  else if(strstr($photoid[1], '&cat')){$photoid = explode('&cat', $photoid[1]);}
103  else{
104  $_SESSION['page_infos'] = array('error');
105  redirect($_SERVER['REQUEST_URI']);
106  }
107  $query = 'UPDATE ' . IMAGES_TABLE . ' SET rating_score = NULL WHERE id = '.$photoid[0].';';
108  $result = pwg_query($query);
109  $query = 'DELETE FROM ' . RATE_TABLE . ' WHERE element_id = '.$photoid[0].';';
110  $result = pwg_query($query);
111  redirect($admin_base_url[0]);
112}
113
114  }
115 
116//add prefiltre album
117add_event_handler('loc_end_cat_modify', 'plugdphrAf');
118add_event_handler('loc_end_cat_modify', 'plugdphrAf2');
119
120function plugdphrAf()
121 {
122        global $template;
123        $admin_base_url = $_SERVER['REQUEST_URI'];
124        $template->set_prefilter('album_properties', 'plugdphrAT');
125        $template->assign(
126    array(
127                'U_DELETEAHIT' => $admin_base_url . '&amp;deleteahit',
128                'U_DELETEARATE' => $admin_base_url . '&amp;deletearate',
129  ));
130 }
131
132function plugdphrAT($content, &$smarty)
133 {
134load_language('plugin.lang', PDHR_PATH);
135  $search = '#      </div>
136    </div>
137
138    <div class="catLock">#';
139 
140  $replacement = '
141                        <a class="icon-trash mouse" href="{$U_DELETEAHIT}" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');">{\'Purge hits on all pictures album\'|@translate}</a>
142                        <a class="icon-trash mouse" href="{$U_DELETEARATE}" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');">{\'Purge rates on all pictures album\'|@translate}</a>
143                        </div>
144    </div>
145
146    <div class="catLock">
147  ';
148
149  return preg_replace($search, $replacement, $content);
150 }
151 
152 function plugdphrAf2()
153 {
154 
155if (isset($_GET['deleteahit'])) {
156  $admin_base_url=explode('&deleteahit', $_SERVER['REQUEST_URI']);
157  $albumid = explode('album-', $_SERVER['REQUEST_URI']);
158  if(strstr($albumid[1], '-properties')){
159    $albumid = explode('-properties', $albumid[1]);
160        $albumid = $albumid[0];
161  }  else if(strstr($albumid[1], '&deleteahit')){
162    $albumid = explode('&deleteahit', $albumid[1]);
163        $albumid = $albumid[0];
164        }
165  else{
166  $_SESSION['page_infos'] = array('error');
167  redirect($_SERVER['REQUEST_URI']);
168  }
169  $query = 'select image_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = '.$albumid.';';
170  $result = pwg_query($query);
171  $delval = array();
172  while($row = pwg_db_fetch_assoc($result))
173        {
174    array_push($delval, $row['image_id']);
175        }
176  foreach ($delval as $delrate)
177        {
178        $query = 'UPDATE ' . IMAGES_TABLE . ' SET hit= \'0\' WHERE id = \''.$delrate.'\';';
179        $result = pwg_query($query);
180        }
181  redirect($admin_base_url[0]);
182} 
183 
184if (isset($_GET['deletearate'])) {
185  $admin_base_url=explode('&deletearate', $_SERVER['REQUEST_URI']);
186  $albumid = explode('album-', $_SERVER['REQUEST_URI']);
187  if(strstr($albumid[1], '-properties')){
188    $albumid = explode('-properties', $albumid[1]);
189        $albumid = $albumid[0];
190  }  else if(strstr($albumid[1], '&deletearate')){
191    $albumid = explode('&deletearate', $albumid[1]);
192        $albumid = $albumid[0];
193        }
194  else{
195  $_SESSION['page_infos'] = array('error');
196  redirect($_SERVER['REQUEST_URI']);
197  }
198  $query = 'select image_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = '.$albumid.';';
199  $result = pwg_query($query);
200  $delval = array();
201  while($row = pwg_db_fetch_assoc($result))
202        {
203    array_push($delval, $row['image_id']);
204        }
205  foreach ($delval as $delrate)
206        {
207        $query = 'UPDATE ' . IMAGES_TABLE . ' SET rating_score = NULL WHERE id = \''.$delrate.'\';';
208        $result = pwg_query($query);
209       
210        $query = 'DELETE FROM ' . RATE_TABLE . ' WHERE element_id = \''.$delrate.'\';';
211        $result = pwg_query($query);
212        }
213  redirect($admin_base_url[0]);
214} 
215
216}
217?>
Note: See TracBrowser for help on using the repository browser.