[31444] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[32389] | 3 | // | de_activate all language plugin for piwigo by TEMMII | |
---|
[31444] | 4 | // +-----------------------------------------------------------------------+ |
---|
[32942] | 5 | // | Copyright(C) 2010-2023 ddtddt http://temmii.com/piwigo/ | |
---|
[31444] | 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 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
| 23 | include_once(PHPWG_ROOT_PATH.'admin/include/languages.class.php'); |
---|
| 24 | |
---|
| 25 | //add prefiltre photo |
---|
| 26 | add_event_handler('loc_begin_admin', 'plugDalPf',60); |
---|
| 27 | add_event_handler('loc_begin_admin_page', 'plugDal_action'); |
---|
| 28 | |
---|
| 29 | function plugDalPf(){ |
---|
[31448] | 30 | global $template, $conf; |
---|
[31444] | 31 | $admin_base_url = $_SERVER['REQUEST_URI']; |
---|
[31448] | 32 | $template->assign( |
---|
| 33 | array( |
---|
| 34 | 'U_DAL' => $admin_base_url . '&deactivatelanguage', |
---|
| 35 | 'U_DALA' => $admin_base_url . '&activatelanguage', |
---|
| 36 | )); |
---|
[31444] | 37 | |
---|
[31448] | 38 | if(isset($conf['de_activate_all_language'])){ |
---|
| 39 | $template->assign('U_RDAL',($admin_base_url . '&reactivatelanguage')); |
---|
| 40 | } |
---|
| 41 | |
---|
[31444] | 42 | $template->set_prefilter('languages', 'plugDalPT'); |
---|
| 43 | } |
---|
| 44 | |
---|
[32705] | 45 | function plugDalPT($content){ |
---|
[31444] | 46 | global $template; |
---|
[32942] | 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} |
---|
| 53 | const confirm_msg = "{"Yes, I am sure"|@translate}"; |
---|
| 54 | const 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> |
---|
[31448] | 83 | {if isset ($U_RDAL)} |
---|
[32942] | 84 | | <a href="{$U_RDAL}" class="purge-search-rdal">{\'Activate language Deactivate\'|@translate}</a> |
---|
[31448] | 85 | {/if} |
---|
[32942] | 86 | | <a href="{$U_DALA}" class="purge-search-ddal">{\'Activate all language\'|@translate}</a> |
---|
[31444] | 87 | </p> |
---|
[32942] | 88 | |
---|
[31444] | 89 | '; |
---|
[32942] | 90 | return str_replace($search,$replacement, $content); |
---|
[31444] | 91 | } |
---|
| 92 | |
---|
| 93 | function plugDal_action(){ |
---|
[31448] | 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(); |
---|
[31444] | 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); |
---|
[32705] | 132 | if (is_null($row)) { |
---|
[31444] | 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]); |
---|
[31448] | 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 | } |
---|
[31444] | 154 | |
---|
| 155 | } |
---|