source: extensions/Des_activate_all_languages/initadmin.php @ 31444

Revision 31444, 3.8 KB checked in by ddtddt, 4 years ago (diff)

[extensions] - Des_activate_all_languages - Beta

Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Des_activate all language plugin for piwigo                           |
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
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;
31  $admin_base_url = $_SERVER['REQUEST_URI'];
32  $template->assign('U_DAL',($admin_base_url . '&amp;desactivatelanguage'));
33  $template->assign('U_DALA',($admin_base_url . '&amp;activatelanguage'));
34 
35  $template->set_prefilter('languages', 'plugDalPT');
36}
37
38function plugDalPT($content, &$smarty){
39  global $template;
40  $search = '#</h2>
41</div>#';
42  $replacement = '</h2>
43</div>
44<p style="text-align: left;padding:10px">
45<a href="{$U_DAL}" name="submitDal" onclick="return confirm(\'{\'Are you sure?\'|@translate|@escape:javascript}\');"><span class="icon-check-empty"></span>{\'Desactivate all language\'|@translate}</a>
46| <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>
47</p>
48 ';
49  return preg_replace($search, $replacement, $content);
50}
51 
52function plugDal_action(){
53  load_language('plugin.lang', DAL_PATH);       
54  if (isset($_GET['desactivatelanguage'])) {
55        $admin_base_url=explode('&desactivatelanguage', $_SERVER['REQUEST_URI']);
56    $default_language = get_default_language();
57    $query = 'DELETE FROM '.LANGUAGES_TABLE.' WHERE id!= \''.$default_language.'\';';
58        pwg_query($query);
59        redirect($admin_base_url[0]);
60          }
61         
62  if (isset($_GET['activatelanguage'])) {
63        $admin_base_url=explode('&activatelanguage', $_SERVER['REQUEST_URI']);
64        $languages = new languages();
65        $languages->get_db_languages();
66       
67        foreach ($languages as $key => $language){
68                foreach ($language as $key => $lang){
69                //var_dump($lang);
70                  if (isset($lang['code'])){
71                        $query = 'INSERT INTO '.LANGUAGES_TABLE.'(id, version, name) VALUES(\''.$lang['code'].'\',\''.$lang['version'].'\',\''.$lang['name'].'\');';
72                        $q = 'SELECT 1 FROM ' . LANGUAGES_TABLE . ' WHERE id= \'' . $lang['code'] . '\';';
73                        $test = pwg_query($q);
74                        $row = pwg_db_fetch_assoc($test);
75                        if (count($row) == 0) {
76              $query = 'INSERT INTO '.LANGUAGES_TABLE.'(id, version, name) VALUES(\''.$lang['code'].'\',\''.$lang['version'].'\',\''.$lang['name'].'\');';
77                          pwg_query($query);
78                        }
79                  }
80                }
81        }
82        redirect($admin_base_url[0]);
83  }       
84         
85}
Note: See TracBrowser for help on using the repository browser.