[9796] | 1 | <?php |
---|
[31436] | 2 | |
---|
| 3 | // +-----------------------------------------------------------------------+ |
---|
| 4 | // | Delete Hit/Rate plugin for piwigo | |
---|
| 5 | // +-----------------------------------------------------------------------+ |
---|
| 6 | // | Copyright(C) 2011-2016 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 | |
---|
[9796] | 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); |
---|
[31436] | 28 | define('PDHR_ADMIN',get_root_url().'admin.php?page=plugin-'.PDHR_DIR); |
---|
[9796] | 29 | |
---|
| 30 | add_event_handler('get_admin_plugin_menu_links', 'dphr_admin_menu'); |
---|
[31436] | 31 | function dphr_admin_menu($menu){ |
---|
| 32 | load_language('plugin.lang', PDHR_PATH); |
---|
| 33 | $menu[] = array( |
---|
[31437] | 34 | 'NAME' => l10n('Delete Hit/Rate'), |
---|
[31436] | 35 | 'URL' => PDHR_ADMIN, |
---|
| 36 | ); |
---|
[9796] | 37 | return $menu; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | //add prefiltre photo |
---|
| 41 | add_event_handler('loc_begin_admin', 'plugdphrPf',60); |
---|
[16548] | 42 | add_event_handler('loc_begin_admin_page', 'plugdphrPf2',60); |
---|
[9796] | 43 | |
---|
| 44 | function plugdphrPf() |
---|
[31436] | 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 | } |
---|
[9796] | 55 | |
---|
| 56 | function plugdphrPT($content, &$smarty) |
---|
| 57 | { |
---|
| 58 | load_language('plugin.lang', PDHR_PATH); |
---|
[31436] | 59 | $search = '# </ul> |
---|
| 60 | </td> |
---|
| 61 | </tr> |
---|
| 62 | </table>#'; |
---|
[9796] | 63 | |
---|
| 64 | $replacement = ' |
---|
[31436] | 65 | <li><a href="{$U_DELETEPHIT}" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');"><span class="icon-trash mouse"></span>{\'Purge hit of the photo\'|@translate}</a></li> |
---|
| 66 | <li><a href="{$U_DELETEPRATE}" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');"><span class="icon-trash mouse"></span>{\'Purge rate of the photo\'|@translate}</a></li> |
---|
[9796] | 67 | |
---|
[31436] | 68 | </ul> |
---|
| 69 | </td> |
---|
| 70 | </tr> |
---|
| 71 | </table>'; |
---|
| 72 | |
---|
[9796] | 73 | return preg_replace($search, $replacement, $content); |
---|
| 74 | } |
---|
[16548] | 75 | |
---|
| 76 | function plugdphrPf2() |
---|
| 77 | { |
---|
[31436] | 78 | if (isset($_GET['deletephit'])) { |
---|
| 79 | $admin_base_url=explode('&deletephit', $_SERVER['REQUEST_URI']); |
---|
| 80 | $photoid = explode('photo-', $_SERVER['REQUEST_URI']); |
---|
| 81 | if(strstr($photoid[1], '-properties')){$photoid = explode('-properties', $photoid[1]);} |
---|
| 82 | else if(strstr($photoid[1], '&cat')){$photoid = explode('&cat', $photoid[1]);} |
---|
| 83 | else{ |
---|
| 84 | $_SESSION['page_infos'] = array('error'); |
---|
| 85 | redirect($_SERVER['REQUEST_URI']); |
---|
[9796] | 86 | } |
---|
[31436] | 87 | $query = 'UPDATE ' . IMAGES_TABLE . ' SET hit= \'0\' WHERE id = '.$photoid[0].';'; |
---|
| 88 | $result = pwg_query($query); |
---|
| 89 | redirect($admin_base_url[0]); |
---|
| 90 | } |
---|
[9796] | 91 | |
---|
[31436] | 92 | if (isset($_GET['deleteprate'])) { |
---|
| 93 | $admin_base_url=explode('&deleteprate', $_SERVER['REQUEST_URI']); |
---|
| 94 | $photoid = explode('photo-', $_SERVER['REQUEST_URI']); |
---|
| 95 | if(strstr($photoid[1], '-properties')){$photoid = explode('-properties', $photoid[1]);} |
---|
| 96 | else if(strstr($photoid[1], '&cat')){$photoid = explode('&cat', $photoid[1]);} |
---|
| 97 | else{ |
---|
| 98 | $_SESSION['page_infos'] = array('error'); |
---|
| 99 | redirect($_SERVER['REQUEST_URI']); |
---|
| 100 | } |
---|
| 101 | $query = 'UPDATE ' . IMAGES_TABLE . ' SET rating_score = \'NULL\' WHERE id = '.$photoid[0].';'; |
---|
| 102 | $result = pwg_query($query); |
---|
| 103 | $query = 'DELETE FROM ' . RATE_TABLE . ' WHERE element_id = '.$photoid[0].';'; |
---|
| 104 | $result = pwg_query($query); |
---|
| 105 | redirect($admin_base_url[0]); |
---|
| 106 | } |
---|
[9796] | 107 | |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | //add prefiltre album |
---|
| 111 | add_event_handler('loc_end_cat_modify', 'plugdphrAf'); |
---|
[16548] | 112 | add_event_handler('loc_end_cat_modify', 'plugdphrAf2'); |
---|
[9796] | 113 | |
---|
| 114 | function plugdphrAf() |
---|
| 115 | { |
---|
| 116 | global $template; |
---|
[31436] | 117 | $admin_base_url = $_SERVER['REQUEST_URI']; |
---|
[16548] | 118 | $template->set_prefilter('album_properties', 'plugdphrAT'); |
---|
[31436] | 119 | $template->assign( |
---|
| 120 | array( |
---|
| 121 | 'U_DELETEAHIT' => $admin_base_url . '&deleteahit', |
---|
| 122 | 'U_DELETEARATE' => $admin_base_url . '&deletearate', |
---|
| 123 | )); |
---|
[9796] | 124 | } |
---|
| 125 | |
---|
| 126 | function plugdphrAT($content, &$smarty) |
---|
| 127 | { |
---|
| 128 | load_language('plugin.lang', PDHR_PATH); |
---|
[31436] | 129 | $search = '#</ul> |
---|
| 130 | </td> |
---|
| 131 | </tr> |
---|
| 132 | </table>#'; |
---|
[9796] | 133 | |
---|
[16548] | 134 | $replacement = ' |
---|
[31436] | 135 | <li><a href="{$U_DELETEAHIT}" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');"><span class="icon-trash mouse"></span>{\'Purge hits on all pictures album\'|@translate}</a></li> |
---|
| 136 | <li><a href="{$U_DELETEARATE}" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');"><span class="icon-trash mouse"></span>{\'Purge rates on all pictures album\'|@translate}</a></li> |
---|
| 137 | </ul> |
---|
| 138 | </td> |
---|
| 139 | </tr> |
---|
| 140 | </table> |
---|
[9796] | 141 | '; |
---|
| 142 | |
---|
| 143 | return preg_replace($search, $replacement, $content); |
---|
| 144 | } |
---|
| 145 | |
---|
[16548] | 146 | function plugdphrAf2() |
---|
| 147 | { |
---|
[31436] | 148 | |
---|
| 149 | if (isset($_GET['deleteahit'])) { |
---|
| 150 | $admin_base_url=explode('&deleteahit', $_SERVER['REQUEST_URI']); |
---|
| 151 | $albumid = explode('album-', $_SERVER['REQUEST_URI']); |
---|
| 152 | if(strstr($albumid[1], '-properties')){ |
---|
| 153 | $albumid = explode('-properties', $albumid[1]); |
---|
| 154 | $albumid = $albumid[0]; |
---|
| 155 | } else if(strstr($albumid[1], '&deleteahit')){ |
---|
| 156 | $albumid = explode('&deleteahit', $albumid[1]); |
---|
| 157 | $albumid = $albumid[0]; |
---|
| 158 | } |
---|
| 159 | else{ |
---|
| 160 | $_SESSION['page_infos'] = array('error'); |
---|
| 161 | redirect($_SERVER['REQUEST_URI']); |
---|
| 162 | } |
---|
| 163 | $query = 'select image_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = '.$albumid.';'; |
---|
| 164 | $result = pwg_query($query); |
---|
| 165 | $delval = array(); |
---|
| 166 | while($row = pwg_db_fetch_assoc($result)) |
---|
[9796] | 167 | { |
---|
| 168 | array_push($delval, $row['image_id']); |
---|
| 169 | } |
---|
[31436] | 170 | foreach ($delval as $delrate) |
---|
[9796] | 171 | { |
---|
[31436] | 172 | $query = 'UPDATE ' . IMAGES_TABLE . ' SET hit= \'0\' WHERE id = \''.$delrate.'\';'; |
---|
| 173 | $result = pwg_query($query); |
---|
[9796] | 174 | } |
---|
[31436] | 175 | redirect($admin_base_url[0]); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | if (isset($_GET['deletearate'])) { |
---|
| 179 | $admin_base_url=explode('&deletearate', $_SERVER['REQUEST_URI']); |
---|
| 180 | $albumid = explode('album-', $_SERVER['REQUEST_URI']); |
---|
| 181 | if(strstr($albumid[1], '-properties')){ |
---|
| 182 | $albumid = explode('-properties', $albumid[1]); |
---|
| 183 | $albumid = $albumid[0]; |
---|
| 184 | } else if(strstr($albumid[1], '&deletearate')){ |
---|
| 185 | $albumid = explode('&deletearate', $albumid[1]); |
---|
| 186 | $albumid = $albumid[0]; |
---|
| 187 | } |
---|
| 188 | else{ |
---|
| 189 | $_SESSION['page_infos'] = array('error'); |
---|
| 190 | redirect($_SERVER['REQUEST_URI']); |
---|
| 191 | } |
---|
| 192 | $query = 'select image_id FROM ' . IMAGE_CATEGORY_TABLE . ' WHERE category_id = '.$albumid.';'; |
---|
| 193 | $result = pwg_query($query); |
---|
| 194 | $delval = array(); |
---|
| 195 | while($row = pwg_db_fetch_assoc($result)) |
---|
[9796] | 196 | { |
---|
| 197 | array_push($delval, $row['image_id']); |
---|
| 198 | } |
---|
[31436] | 199 | foreach ($delval as $delrate) |
---|
[9796] | 200 | { |
---|
[31436] | 201 | $query = 'UPDATE ' . IMAGES_TABLE . ' SET rating_score = \'NULL\' WHERE id = \''.$delrate.'\';'; |
---|
| 202 | $result = pwg_query($query); |
---|
[9796] | 203 | |
---|
[31436] | 204 | $query = 'DELETE FROM ' . RATE_TABLE . ' WHERE element_id = \''.$delrate.'\';'; |
---|
| 205 | $result = pwg_query($query); |
---|
[9796] | 206 | } |
---|
[31436] | 207 | redirect($admin_base_url[0]); |
---|
| 208 | } |
---|
| 209 | |
---|
[16548] | 210 | } |
---|
[9796] | 211 | ?> |
---|