[31444] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[31448] | 3 | // | de_activate all language plugin for piwigo | |
---|
[31444] | 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2016 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 | 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 | |
---|
| 45 | function plugDalPT($content, &$smarty){ |
---|
| 46 | global $template; |
---|
| 47 | $search = '#</h2> |
---|
| 48 | </div>#'; |
---|
| 49 | $replacement = '</h2> |
---|
| 50 | </div> |
---|
| 51 | <p style="text-align: left;padding:10px"> |
---|
[31448] | 52 | <a href="{$U_DAL}" name="submitDal" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');"><span class="icon-check-empty"></span>{\'Deactivate all language\'|@translate}</a> |
---|
| 53 | {if isset ($U_RDAL)} |
---|
| 54 | | <a href="{$U_RDAL}" name="submitrdal" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');"><span class="icon-check"></span>{\'Activate language Deactivate\'|@translate}</a> |
---|
| 55 | {/if} |
---|
[31444] | 56 | | <a href="{$U_DALA}" name="submitDala" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');"><span class="icon-check"></span>{\'Activate all language\'|@translate}</a> |
---|
| 57 | </p> |
---|
| 58 | '; |
---|
| 59 | return preg_replace($search, $replacement, $content); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | function plugDal_action(){ |
---|
[31448] | 63 | load_language('plugin.lang', DAL_PATH); |
---|
| 64 | global $template, $conf; |
---|
| 65 | |
---|
| 66 | if (isset($_GET['deactivatelanguage'])) { |
---|
| 67 | $admin_base_url=explode('&deactivatelanguage', $_SERVER['REQUEST_URI']); |
---|
| 68 | $activelang=array(); |
---|
| 69 | $query = 'SELECT * FROM '.LANGUAGES_TABLE.';'; |
---|
| 70 | $result=pwg_query($query); |
---|
| 71 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 72 | { |
---|
| 73 | $activelang[]=array( |
---|
| 74 | 'id'=>$row['id'], |
---|
| 75 | 'version'=>$row['version'], |
---|
| 76 | 'name'=>$row['name'], |
---|
| 77 | ); |
---|
| 78 | } |
---|
| 79 | if(count($activelang)!=1){ |
---|
| 80 | conf_update_param('de_activate_all_language', $activelang); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | $default_language = get_default_language(); |
---|
[31444] | 84 | $query = 'DELETE FROM '.LANGUAGES_TABLE.' WHERE id!= \''.$default_language.'\';'; |
---|
| 85 | pwg_query($query); |
---|
| 86 | redirect($admin_base_url[0]); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if (isset($_GET['activatelanguage'])) { |
---|
| 90 | $admin_base_url=explode('&activatelanguage', $_SERVER['REQUEST_URI']); |
---|
| 91 | $languages = new languages(); |
---|
| 92 | $languages->get_db_languages(); |
---|
| 93 | |
---|
| 94 | foreach ($languages as $key => $language){ |
---|
| 95 | foreach ($language as $key => $lang){ |
---|
| 96 | //var_dump($lang); |
---|
| 97 | if (isset($lang['code'])){ |
---|
| 98 | $query = 'INSERT INTO '.LANGUAGES_TABLE.'(id, version, name) VALUES(\''.$lang['code'].'\',\''.$lang['version'].'\',\''.$lang['name'].'\');'; |
---|
| 99 | $q = 'SELECT 1 FROM ' . LANGUAGES_TABLE . ' WHERE id= \'' . $lang['code'] . '\';'; |
---|
| 100 | $test = pwg_query($q); |
---|
| 101 | $row = pwg_db_fetch_assoc($test); |
---|
| 102 | if (count($row) == 0) { |
---|
| 103 | $query = 'INSERT INTO '.LANGUAGES_TABLE.'(id, version, name) VALUES(\''.$lang['code'].'\',\''.$lang['version'].'\',\''.$lang['name'].'\');'; |
---|
| 104 | pwg_query($query); |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | redirect($admin_base_url[0]); |
---|
[31448] | 110 | } |
---|
| 111 | |
---|
| 112 | if (isset($_GET['reactivatelanguage'])) { |
---|
| 113 | $admin_base_url=explode('&reactivatelanguage', $_SERVER['REQUEST_URI']); |
---|
| 114 | $reaclang = safe_unserialize($conf['de_activate_all_language']); |
---|
| 115 | foreach ($reaclang as $key => $lang){ |
---|
| 116 | if($lang['id']!=get_default_language()){ |
---|
| 117 | $query = 'INSERT INTO '.LANGUAGES_TABLE.'(id, version, name) VALUES(\''.$lang['id'].'\',\''.$lang['version'].'\',\''.$lang['name'].'\');'; |
---|
| 118 | pwg_query($query); |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | conf_delete_param('de_activate_all_language', $activelang); |
---|
| 122 | redirect($admin_base_url[0]); |
---|
| 123 | } |
---|
[31444] | 124 | |
---|
| 125 | } |
---|