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 | |
---|
23 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
24 | |
---|
25 | define('PDHR_DIR' , basename(dirname(__FILE__))); |
---|
26 | define('PDHR_PATH' , PHPWG_PLUGINS_PATH . PDHR_DIR . '/'); |
---|
27 | load_language('plugin.lang', PDHR_PATH); |
---|
28 | define('PDHR_ADMIN',get_root_url().'admin.php?page=plugin-'.PDHR_DIR); |
---|
29 | |
---|
30 | /*add_event_handler('get_admin_plugin_menu_links', 'dphr_admin_menu'); |
---|
31 | function 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 |
---|
41 | add_event_handler('loc_begin_admin', 'plugdphrPf',60); |
---|
42 | add_event_handler('loc_begin_admin', 'plugdphrPf2',60); |
---|
43 | |
---|
44 | function 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 . '&deletephit', |
---|
52 | 'U_DELETEPRATE' => $admin_base_url . '&deleteprate', |
---|
53 | )); |
---|
54 | } |
---|
55 | |
---|
56 | function plugdphrPT($content, &$smarty) |
---|
57 | { |
---|
58 | load_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 | |
---|
81 | function plugdphrPf2() |
---|
82 | { |
---|
83 | if (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 | |
---|
98 | if (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 |
---|
117 | add_event_handler('loc_end_cat_modify', 'plugdphrAf'); |
---|
118 | add_event_handler('loc_end_cat_modify', 'plugdphrAf2'); |
---|
119 | |
---|
120 | function 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 . '&deleteahit', |
---|
128 | 'U_DELETEARATE' => $admin_base_url . '&deletearate', |
---|
129 | )); |
---|
130 | } |
---|
131 | |
---|
132 | function plugdphrAT($content, &$smarty) |
---|
133 | { |
---|
134 | load_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 | |
---|
155 | if (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 | |
---|
184 | if (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 | ?> |
---|