1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | reset level plugin for piwigo by TEMMII | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2011-2023 ddtddt http://temmii.com/piwigo/ | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | This program is free software; you can redistribute it and/or modify | |
---|
8 | // | it under the terms of the GNU General Public License as published by | |
---|
9 | // | the Free Software Foundation | |
---|
10 | // | | |
---|
11 | // | This program is distributed in the hope that it will be useful, but | |
---|
12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
14 | // | General Public License for more details. | |
---|
15 | // | | |
---|
16 | // | You should have received a copy of the GNU General Public License | |
---|
17 | // | along with this program; if not, write to the Free Software | |
---|
18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
19 | // | USA. | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | |
---|
23 | add_event_handler('loading_lang', 'reset_level_loading_lang'); |
---|
24 | function reset_level_loading_lang(){ |
---|
25 | load_language('plugin.lang', DELLE_PATH); |
---|
26 | } |
---|
27 | |
---|
28 | add_event_handler('loc_begin_admin', 'plugrlPf'); |
---|
29 | add_event_handler('loc_begin_admin_page', 'plugrlaction'); |
---|
30 | |
---|
31 | function plugrlPf(){ |
---|
32 | global $template; |
---|
33 | $admin_base_url = $_SERVER['REQUEST_URI']; |
---|
34 | $template->set_prefilter('maintenance', 'plugrlPT'); |
---|
35 | $template->assign( |
---|
36 | array( |
---|
37 | 'U_RESETLEVEL' => $admin_base_url . '&resetlevel&pwg_token='.get_pwg_token(), |
---|
38 | )); |
---|
39 | } |
---|
40 | |
---|
41 | function plugrlPT($content){ |
---|
42 | // add js link |
---|
43 | $search = '{/footer_script}'; |
---|
44 | $replace = ' |
---|
45 | $(".reset-level-button").each(function() { |
---|
46 | const title = \'{"Discount level of confidentiality for all photos in the gallery: for all"|@translate|@escape:\'javascript\'}\'; |
---|
47 | $(this).pwg_jconfirm_follow_href({ |
---|
48 | alert_title: title, |
---|
49 | alert_confirm: confirm_msg, |
---|
50 | alert_cancel: cancel_msg |
---|
51 | }); |
---|
52 | }); |
---|
53 | '; |
---|
54 | $content = str_replace($search, $replace.$search, $content); |
---|
55 | |
---|
56 | //add action |
---|
57 | $search = '<a href="{$U_MAINT_C13Y}" class="icon-ok maintenance-action">{\'Reinitialize check integrity\'|@translate}</a>'; |
---|
58 | $replacement = '<a href="{$U_RESETLEVEL}" class="maintenance-action reset-level-button" title="{\'Discount level of confidentiality for all photos in the gallery: for all\'|@translate}"><span class="icon-arrows-cw"></span>{\'Reset levels of privacy\'|@translate}</a>'; |
---|
59 | return str_replace($search, $search.$replacement, $content); |
---|
60 | } |
---|
61 | |
---|
62 | function plugrlaction(){ |
---|
63 | if (isset($_GET['resetlevel'])){ |
---|
64 | if (is_webmaster()){ |
---|
65 | $query = 'UPDATE ' . IMAGES_TABLE . ' SET level= \'0\';'; |
---|
66 | $result = pwg_query($query); |
---|
67 | invalidate_user_cache(); |
---|
68 | $_SESSION['page_infos'] = array(l10n('All Photos now have a level of confidentiality "for all "')); |
---|
69 | }else{ |
---|
70 | $_SESSION['page_errors'] = array(l10n('Only webmaster can be reset privacy level')); |
---|
71 | } |
---|
72 | redirect(get_root_url().'admin.php?page=maintenance'); |
---|
73 | } |
---|
74 | } |
---|