source: extensions/de_activate_all_languages/initadmin.php

Last change on this file was 32942, checked in by ddtddt, 15 months ago

[de_activate_all_languages] check php8 and Piwigo13

File size: 5.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | de_activate all language plugin for piwigo by TEMMII                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2010-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
22include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
23include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php');
24
25//add prefiltre photo
26add_event_handler('loc_begin_admin', 'plugDalPf',60);
27add_event_handler('loc_begin_admin_page', 'plugDal_action');
28
29function plugDalPf(){
30  global $template, $conf;
31  $admin_base_url = $_SERVER['REQUEST_URI'];
32   $template->assign(
33    array(
34                'U_DAL' => $admin_base_url . '&amp;deactivatelanguage',
35                'U_DALA' => $admin_base_url . '&amp;activatelanguage',
36  ));
37 
38  if(isset($conf['de_activate_all_language'])){
39  $template->assign('U_RDAL',($admin_base_url . '&amp;reactivatelanguage'));
40  }
41 
42  $template->set_prefilter('languages', 'plugDalPT');
43}
44
45function plugDalPT($content){
46  global $template;
47  $search = '{/footer_script}';
48  $replacement = '
49{/footer_script} 
50{combine_script id=\'jquery.confirm\' load=\'footer\' require=\'jquery\' path=\'themes/default/js/plugins/jquery-confirm.min.js\'}
51{combine_css path="themes/default/js/plugins/jquery-confirm.min.css"}
52{footer_script}
53const confirm_msg = "{"Yes, I am sure"|@translate}";
54const cancel_msg = "{"No, I have changed my mind"|@translate}";
55$(".purge-search-dal").each(function() {
56  const title = \'{"Are you sure?"|@translate|@escape:\'javascript\'}\';
57  $(this).pwg_jconfirm_follow_href({
58    alert_title: title,
59    alert_confirm: confirm_msg,
60    alert_cancel: cancel_msg
61  });
62});
63$(".purge-search-rdal").each(function() {
64  const title = \'{"Are you sure?"|@translate|@escape:\'javascript\'}\';
65  $(this).pwg_jconfirm_follow_href({
66    alert_title: title,
67    alert_confirm: confirm_msg,
68    alert_cancel: cancel_msg
69  });
70});
71$(".purge-search-ddal").each(function() {
72  const title = \'{"Are you sure?"|@translate|@escape:\'javascript\'}\';
73  $(this).pwg_jconfirm_follow_href({
74    alert_title: title,
75    alert_confirm: confirm_msg,
76    alert_cancel: cancel_msg
77  });
78});
79
80{/footer_script}
81<p style="text-align:left; padding:10px;">
82<a href="{$U_DAL}" class="purge-search-dal">{\'Deactivate all language\'|@translate}</a>
83{if isset ($U_RDAL)}
84| <a href="{$U_RDAL}" class="purge-search-rdal">{\'Activate language Deactivate\'|@translate}</a>
85{/if}
86| <a href="{$U_DALA}" class="purge-search-ddal">{\'Activate all language\'|@translate}</a>
87</p>
88
89 ';
90  return str_replace($search,$replacement, $content);
91}
92 
93function plugDal_action(){
94  load_language('plugin.lang', DAL_PATH);
95  global $template, $conf;
96 
97  if (isset($_GET['deactivatelanguage'])) {
98        $admin_base_url=explode('&deactivatelanguage', $_SERVER['REQUEST_URI']);
99    $activelang=array();
100        $query = 'SELECT * FROM '.LANGUAGES_TABLE.';';
101        $result=pwg_query($query);
102        while ($row = pwg_db_fetch_assoc($result))
103          {
104        $activelang[]=array(
105                  'id'=>$row['id'],
106                  'version'=>$row['version'],
107                  'name'=>$row['name'],           
108                );
109      }
110        if(count($activelang)!=1){
111        conf_update_param('de_activate_all_language', $activelang);
112        }
113       
114        $default_language = get_default_language();
115    $query = 'DELETE FROM '.LANGUAGES_TABLE.' WHERE id!= \''.$default_language.'\';';
116        pwg_query($query);
117        redirect($admin_base_url[0]);
118          }
119         
120  if (isset($_GET['activatelanguage'])) {
121        $admin_base_url=explode('&activatelanguage', $_SERVER['REQUEST_URI']);
122        $languages = new languages();
123        $languages->get_db_languages();
124       
125        foreach ($languages as $key => $language){
126                foreach ($language as $key => $lang){
127                  if (isset($lang['code'])){
128                        $query = 'INSERT INTO '.LANGUAGES_TABLE.'(id, version, name) VALUES(\''.$lang['code'].'\',\''.$lang['version'].'\',\''.$lang['name'].'\');';
129                        $q = 'SELECT 1 FROM ' . LANGUAGES_TABLE . ' WHERE id= \'' . $lang['code'] . '\';';
130                        $test = pwg_query($q);
131                        $row = pwg_db_fetch_assoc($test);
132                        if (is_null($row)) {
133              $query = 'INSERT INTO '.LANGUAGES_TABLE.'(id, version, name) VALUES(\''.$lang['code'].'\',\''.$lang['version'].'\',\''.$lang['name'].'\');';
134                          pwg_query($query);
135                        }
136                  }
137                }
138        }
139        redirect($admin_base_url[0]);
140  }
141
142  if (isset($_GET['reactivatelanguage'])) {
143        $admin_base_url=explode('&reactivatelanguage', $_SERVER['REQUEST_URI']);
144        $reaclang = safe_unserialize($conf['de_activate_all_language']);
145        foreach ($reaclang as $key => $lang){
146          if($lang['id']!=get_default_language()){
147                $query = 'INSERT INTO '.LANGUAGES_TABLE.'(id, version, name) VALUES(\''.$lang['id'].'\',\''.$lang['version'].'\',\''.$lang['name'].'\');';
148                pwg_query($query);
149          }
150        }
151        conf_delete_param('de_activate_all_language', $activelang);
152        redirect($admin_base_url[0]);
153  }         
154         
155}
Note: See TracBrowser for help on using the repository browser.