source: extensions/delete_hit_rate/initadmin.php

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

[delete_hit_rate] check php8.3 and Piwigo14

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1<?php
2
3// +-----------------------------------------------------------------------+
4// | Delete Hit/Rate plugin for piwigo  by TEMMII                          |
5// +-----------------------------------------------------------------------+
6// | Copyright(C) 2011-2023 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 prefiltre photo
31add_event_handler('loc_begin_admin', 'plugdphrPf',60);
32add_event_handler('loc_begin_admin', 'plugdphrPf2',60);
33
34function plugdphrPf()
35  {
36  global $template;
37  $admin_base_url = $_SERVER['REQUEST_URI'];
38  $template->set_prefilter('picture_modify', 'plugdphrPT');
39 $template->assign(
40    array(
41                'U_DELETEPHIT' => $admin_base_url . '&amp;deletephit',
42                'U_DELETEPRATE' => $admin_base_url . '&amp;deleteprate',
43  ));
44  }
45
46function plugdphrPT($content)
47        {
48load_language('plugin.lang', PDHR_PATH);
49  $search = "#        </div>
50      </div>
51    </div>
52
53
54    <p>
55      <strong>#";
56 
57  $replacement = '        </div>
58      </div>
59    </div>
60
61
62    <p>
63      <strong>
64        <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>
65        <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>
66  ';
67
68  return preg_replace($search, $replacement, $content);
69        }
70               
71function plugdphrPf2()
72        {
73if (isset($_GET['deletephit'])) {
74  $admin_base_url=explode('&deletephit', $_SERVER['REQUEST_URI']);
75  $photoid = explode('photo-', $_SERVER['REQUEST_URI']);
76  if(strstr($photoid[1], '-properties')){$photoid = explode('-properties', $photoid[1]);}
77  else if(strstr($photoid[1], '&cat')){$photoid = explode('&cat', $photoid[1]);}
78  else{
79  $_SESSION['page_infos'] = array('error');
80  redirect($_SERVER['REQUEST_URI']);
81  }
82  $_SESSION['page_infos'] = $admin_base_url;
83  $query = 'UPDATE ' . IMAGES_TABLE . ' SET hit= \'0\' WHERE id = '.$photoid[0].';';
84  $result = pwg_query($query);
85  redirect($admin_base_url[0]);
86} 
87
88if (isset($_GET['deleteprate'])) {
89  $admin_base_url=explode('&deleteprate', $_SERVER['REQUEST_URI']);
90  $photoid = explode('photo-', $_SERVER['REQUEST_URI']);
91  if(strstr($photoid[1], '-properties')){$photoid = explode('-properties', $photoid[1]);}
92  else if(strstr($photoid[1], '&cat')){$photoid = explode('&cat', $photoid[1]);}
93  else{
94  $_SESSION['page_infos'] = array('error');
95  redirect($_SERVER['REQUEST_URI']);
96  }
97  $query = 'UPDATE ' . IMAGES_TABLE . ' SET rating_score = NULL WHERE id = '.$photoid[0].';';
98  $result = pwg_query($query);
99  $query = 'DELETE FROM ' . RATE_TABLE . ' WHERE element_id = '.$photoid[0].';';
100  $result = pwg_query($query);
101  redirect($admin_base_url[0]);
102}
103
104  }
105 
106//add prefiltre album
107add_event_handler('loc_end_cat_modify', 'plugdphrAf');
108add_event_handler('loc_end_cat_modify', 'plugdphrAf2');
109
110function plugdphrAf()
111 {
112        global $template;
113        $admin_base_url = $_SERVER['REQUEST_URI'];
114        $template->set_prefilter('album_properties', 'plugdphrAT');
115        $template->assign(
116    array(
117                'U_DELETEAHIT' => $admin_base_url . '&amp;deleteahit',
118                'U_DELETEARATE' => $admin_base_url . '&amp;deletearate',
119  ));
120 }
121
122function plugdphrAT($content)
123 {
124load_language('plugin.lang', PDHR_PATH);
125  $search = '#<div class="cat-modify-form">#';
126 
127  $replacement = '
128  <div class="cat-modify-form">
129    <div class="cat-modify-input-container">
130                <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>
131                <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>
132        </div>
133';
134
135  return preg_replace($search, $replacement, $content);
136 }
137 
138 function plugdphrAf2()
139 {
140   $admin_base_url = $_SERVER['REQUEST_URI'];
141if (isset($_GET['deleteahit'])) {
142  $admin_base_url=explode('&deleteahit', $_SERVER['REQUEST_URI']);
143  $albumid = explode('album-', $_SERVER['REQUEST_URI']);
144  if(strstr($albumid[1], '-properties')){
145    $albumid = explode('-properties', $albumid[1]);
146        $albumid = $albumid[0];
147  }  else if(strstr($albumid[1], '&deleteahit')){
148    $albumid = explode('&deleteahit', $albumid[1]);
149        $albumid = $albumid[0];
150        }
151  else{
152  $_SESSION['page_infos'] = array('error');
153  redirect($_SERVER['REQUEST_URI']);
154  }
155  $query = 'select image_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = '.$albumid.';';
156  $result = pwg_query($query);
157  $delval = array();
158  while($row = pwg_db_fetch_assoc($result))
159        {
160    array_push($delval, $row['image_id']);
161        }
162  foreach ($delval as $delrate)
163        {
164        $query = 'UPDATE ' . IMAGES_TABLE . ' SET hit= \'0\' WHERE id = \''.$delrate.'\';';
165        $result = pwg_query($query);
166        }
167  redirect($admin_base_url[0]);
168} 
169 
170if (isset($_GET['deletearate'])) {
171  $admin_base_url=explode('&deletearate', $_SERVER['REQUEST_URI']);
172  $albumid = explode('album-', $_SERVER['REQUEST_URI']);
173  if(strstr($albumid[1], '-properties')){
174    $albumid = explode('-properties', $albumid[1]);
175        $albumid = $albumid[0];
176  }  else if(strstr($albumid[1], '&deletearate')){
177    $albumid = explode('&deletearate', $albumid[1]);
178        $albumid = $albumid[0];
179        }
180  else{
181  $_SESSION['page_infos'] = array('error');
182  redirect($_SERVER['REQUEST_URI']);
183  }
184  $query = 'select image_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = '.$albumid.';';
185  $result = pwg_query($query);
186  $delval = array();
187  while($row = pwg_db_fetch_assoc($result))
188        {
189    array_push($delval, $row['image_id']);
190        }
191  foreach ($delval as $delrate)
192        {
193        $query = 'UPDATE ' . IMAGES_TABLE . ' SET rating_score = NULL WHERE id = \''.$delrate.'\';';
194        $result = pwg_query($query);
195       
196        $query = 'DELETE FROM ' . RATE_TABLE . ' WHERE element_id = \''.$delrate.'\';';
197        $result = pwg_query($query);
198        }
199  redirect($admin_base_url[0]);
200} 
201
202}
203
204//add prefiltre maintenance
205add_event_handler('loc_begin_admin_page', 'plugdphrPa');
206
207function plugdphrPa()
208  {
209  global $template;
210  $admin_base_url = $_SERVER['REQUEST_URI'];
211  $template->set_prefilter('maintenance', 'plugdphrPaT');
212  $template->assign(
213    array(
214                'U_DELETEHIT' => $admin_base_url . '&amp;deletehit',
215                'U_DELETERATE' => $admin_base_url . '&amp;deleterate',
216   ));
217  }
218
219function plugdphrPaT($content){
220 $search = '<a href="{$U_MAINT_SEARCH}" class="icon-search maintenance-action purge-search-history-button">{\'Purge search history\'|@translate}</a>';
221 
222 $replacement = '<a href="{$U_DELETEHIT}" class="icon-trash mouse maintenance-action purge-search-hits">{\'Purge all hits on all pictures gallery\'|@translate}</a>
223 <a href="{$U_DELETERATE}" class="icon-trash-1 maintenance-action purge-search-rates">{\'Purge all rate on all pictures gallery\'|@translate}</a>';
224
225  return str_replace($search, $search.$replacement, $content);
226}
227
228add_event_handler('loc_begin_admin_page', 'plugdphrPa5');
229
230function plugdphrPa5(){
231 global $template;
232 $template->set_prefilter('maintenance', 'plugdphrPaT5');
233}
234
235function plugdphrPaT5($content){
236 $search = '{/footer_script}';
237 
238 $replacement = '
239 $(".purge-search-hits").each(function() {
240  const title = \'{"Purge all hits on all pictures gallery"|@translate|@escape:\'javascript\'}\';
241  $(this).pwg_jconfirm_follow_href({
242    alert_title: title,
243    alert_confirm: confirm_msg,
244    alert_cancel: cancel_msg
245  });
246 });
247  $(".purge-search-rates").each(function() {
248  const title = \'{"Purge all rate on all pictures gallery"|@translate|@escape:\'javascript\'}\';
249  $(this).pwg_jconfirm_follow_href({
250    alert_title: title,
251    alert_confirm: confirm_msg,
252    alert_cancel: cancel_msg
253  });
254 });
255 ';
256
257  return str_replace($search, $replacement.$search, $content);
258}
259
260
261add_event_handler('loc_begin_admin_page', 'plugdphrPaA');
262
263function plugdphrPaA(){
264 $admin_base_url = $_SERVER['REQUEST_URI'];
265 if (isset($_GET['deletehit'])){
266        $query = 'UPDATE ' . IMAGES_TABLE . ' SET hit= \'0\';';
267    pwg_query($query);
268        $_SESSION['page_infos'] = array(l10n('Hit purge completed successfully'));
269        redirect(get_root_url().'admin.php?page=maintenance');
270 }
271
272 if (isset($_GET['deleterate'])){
273        $query = 'UPDATE ' . IMAGES_TABLE . ' SET rating_score=NULL ;';
274        $result = pwg_query($query);
275
276        $query = 'TRUNCATE ' . RATE_TABLE . ';';
277        $result = pwg_query($query);
278    pwg_query($query);
279        $_SESSION['page_infos'] = array(l10n('Rate purge completed successfully'));
280        redirect(get_root_url().'admin.php?page=maintenance');
281 } 
282}
283
284
285?>
Note: See TracBrowser for help on using the repository browser.