1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Personal Favicon plugin for Piwigo by TEMMII | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2010-2021 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 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
22 | |
---|
23 | global $template, $conf, $user, $page; |
---|
24 | include_once(PHPWG_ROOT_PATH .'admin/include/tabsheet.class.php'); |
---|
25 | $my_base_url = get_admin_plugin_menu_link(__FILE__); |
---|
26 | |
---|
27 | // +-----------------------------------------------------------------------+ |
---|
28 | // | Check Access and exit when user status is not ok | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | check_status(ACCESS_ADMINISTRATOR); |
---|
31 | |
---|
32 | //-------------------------------------------------------- sections definitions |
---|
33 | |
---|
34 | if (!is_webmaster()) |
---|
35 | { |
---|
36 | array_push($page['errors'], l10n('This section is reserved for the webmaster')); |
---|
37 | } |
---|
38 | else |
---|
39 | { |
---|
40 | // Gest Tab |
---|
41 | if (!isset($_GET['tab'])) |
---|
42 | $page['tab'] = 'pfi'; |
---|
43 | else |
---|
44 | $page['tab'] = $_GET['tab']; |
---|
45 | $tabsheet = new tabsheet(); |
---|
46 | $tabsheet->add('pfi',l10n('pfi_ajout'),PFI_ADMIN.'-pfi'); |
---|
47 | $tabsheet->add('help',l10n('help'),PFI_ADMIN.'-help'); |
---|
48 | $tabsheet->select($page['tab']); |
---|
49 | $tabsheet->assign(); |
---|
50 | |
---|
51 | switch ($page['tab']) |
---|
52 | { |
---|
53 | // Onglet gestion de onglet ajout icône |
---|
54 | case 'pfi': |
---|
55 | $blockdesc = 'pfi'; |
---|
56 | $template->assign( |
---|
57 | $blockdesc, |
---|
58 | array( |
---|
59 | 'meta'=>l10n('pfi_name'), |
---|
60 | )); |
---|
61 | |
---|
62 | $filename = PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'favicon.ico'; |
---|
63 | if (file_exists($filename)) {$template->assign('ICO',$filename);} |
---|
64 | |
---|
65 | if (isset($_POST['submitpfi'])) |
---|
66 | { |
---|
67 | |
---|
68 | $content_dir = PHPWG_ROOT_PATH.PWG_LOCAL_DIR; |
---|
69 | $tmp_file = $_FILES['pfi']['tmp_name']; |
---|
70 | |
---|
71 | if ($_FILES['pfi']['error'] !== UPLOAD_ERR_OK){ |
---|
72 | include_once(PHPWG_ROOT_PATH .'admin/include/functions_upload.inc.php'); |
---|
73 | $error_message = file_upload_error_message($_FILES['pfi']['error']); |
---|
74 | array_push( $page['errors'], $error_message); |
---|
75 | break; |
---|
76 | } |
---|
77 | |
---|
78 | if( !is_uploaded_file($tmp_file) ){ |
---|
79 | array_push( $page['errors'], l10n('pfi_erreur_vide') ); |
---|
80 | break; |
---|
81 | } |
---|
82 | |
---|
83 | $type_file = strrchr($_FILES['pfi']['name'], '.'); |
---|
84 | if( !strstr($type_file, 'ico')){ |
---|
85 | array_push( $page['errors'], l10n('pfi_erreur_ext')); |
---|
86 | break; |
---|
87 | } |
---|
88 | |
---|
89 | $taille_maxi = 5120; |
---|
90 | $taille = filesize($_FILES['pfi']['tmp_name']); |
---|
91 | if($taille>$taille_maxi){ |
---|
92 | array_push($page['errors'], l10n('pfi_erreur_taille')); |
---|
93 | break; |
---|
94 | } |
---|
95 | |
---|
96 | $filename = PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'favicon.ico'; |
---|
97 | if (file_exists($filename)){ |
---|
98 | array_push($page['infos'], l10n('pfi_erreur_exist')); |
---|
99 | } |
---|
100 | |
---|
101 | $name_file = $_FILES['pfi']['name']; |
---|
102 | if( preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $name_file) ){ |
---|
103 | array_push( $page['infos'], l10n('pfi_erreur_nom') ); |
---|
104 | break; |
---|
105 | } |
---|
106 | else if( |
---|
107 | !move_uploaded_file($tmp_file, $content_dir . 'favicon.ico') ) |
---|
108 | { |
---|
109 | array_push( $page['errors'], l10n('pfi_erreur_mouve') ); |
---|
110 | break; |
---|
111 | } |
---|
112 | array_push( $page['infos'], l10n('pfi_ok') ); |
---|
113 | } |
---|
114 | break; |
---|
115 | |
---|
116 | case 'help': |
---|
117 | $blockdesc = 'help'; |
---|
118 | $template->assign( |
---|
119 | $blockdesc, |
---|
120 | array( |
---|
121 | 'meta'=>l10n('pfi_name'), |
---|
122 | )); |
---|
123 | |
---|
124 | break; |
---|
125 | |
---|
126 | } |
---|
127 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); |
---|
128 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
129 | } |
---|
130 | ?> |
---|