1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | global $template, $conf, $user, $page; |
---|
6 | |
---|
7 | load_language('plugin.lang', ICONSET_PATH); |
---|
8 | // +-------------------------------------------------------+ |
---|
9 | // | envoi de la config | |
---|
10 | // +-------------------------------------------------------+ |
---|
11 | if (isset($_POST['envoi_config']) and $_POST['envoi_config']=='iconset') |
---|
12 | { |
---|
13 | check_pwg_token(); |
---|
14 | $conf_iconset = @unserialize($conf['iconset']); |
---|
15 | $conf_themes=$conf_iconset['themes']; |
---|
16 | $conf_icons=$conf_iconset['icons']; |
---|
17 | $conf_icons=$conf_iconset['icons']; |
---|
18 | $error_update=''; |
---|
19 | $update_ok=''; |
---|
20 | foreach ($conf_themes as $theme_id => $iconset) // theme supprimé |
---|
21 | { |
---|
22 | if (isset($_POST[$theme_id]) and isset($conf_themes[$theme_id]) and $conf_themes[$theme_id]!=$_POST[$theme_id] and in_array($_POST[$theme_id], $conf_icons)) |
---|
23 | { |
---|
24 | $conf_themes[$theme_id]=$_POST[$theme_id]; |
---|
25 | $update_ok.=$theme_id.' / '; |
---|
26 | } |
---|
27 | elseif (empty($_POST[$theme_id]) and $conf_themes[$theme_id]!=$_POST[$theme_id]) |
---|
28 | { |
---|
29 | $conf_themes[$theme_id]=''; |
---|
30 | $update_ok.=$theme_id.' / '; |
---|
31 | } |
---|
32 | elseif (!isset($_POST[$theme_id]) or !isset($conf_themes[$theme_id]) or (!in_array($_POST[$theme_id], $conf_icons) and !empty($_POST[$theme_id])) ) |
---|
33 | { |
---|
34 | $error_update.=$theme_id.' / '; |
---|
35 | } |
---|
36 | } |
---|
37 | $conf['iconset']=array( |
---|
38 | 'themes'=>$conf_themes, |
---|
39 | 'icons'=>$conf_icons |
---|
40 | ); |
---|
41 | $query = ' |
---|
42 | UPDATE '.CONFIG_TABLE.' |
---|
43 | SET value="'.pwg_db_real_escape_string(serialize($conf['iconset'])).'" |
---|
44 | WHERE param="iconset" |
---|
45 | LIMIT 1'; |
---|
46 | pwg_query($query); |
---|
47 | if (!empty($error_update)) { array_push($page['errors'], l10n('iconset_error_update').$error_update ); } |
---|
48 | if (!empty($update_ok)) { array_push($page['infos'], l10n('iconset_update_ok').$update_ok ); } |
---|
49 | load_conf_from_db(); |
---|
50 | } |
---|
51 | |
---|
52 | // +-------------------------------------------------------+ |
---|
53 | // | liste les icones dispo | |
---|
54 | // +-------------------------------------------------------+ |
---|
55 | |
---|
56 | // RQ : un set d'icone = chemin vers le *.conf.php ; on associe (ou pas) un fichier *.conf.php par thème |
---|
57 | |
---|
58 | function get_list_iconconf_path ($dir) { |
---|
59 | static $list_iconconf_path=array(); |
---|
60 | $dh = opendir ($dir); |
---|
61 | while (($file = readdir ($dh)) !== false ) { |
---|
62 | if ($file !== '.' && $file !== '..') { |
---|
63 | $path =$dir.'/'.$file; |
---|
64 | if (is_dir ($path)) { |
---|
65 | get_list_iconconf_path ($path); |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | $page = explode('.', $file); |
---|
70 | $nb = count($page); |
---|
71 | $nom_fichier = $page[0]; |
---|
72 | for ($i = 1; $i < $nb-1; $i++){ |
---|
73 | $nom_fichier .= '.'.$page[$i]; |
---|
74 | } |
---|
75 | if(isset($page[1])){ |
---|
76 | $ext_fichier = $page[$nb-2].'.'.$page[$nb-1]; |
---|
77 | } |
---|
78 | else { |
---|
79 | $ext_fichier = ''; |
---|
80 | } |
---|
81 | |
---|
82 | if($ext_fichier == 'conf.php') { //On ne prend que les .conf.php |
---|
83 | $path = str_replace("./plugins/Icons_Set/icons/", "", $path); |
---|
84 | $list_iconconf_path[]=$path; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | closedir ($dh); |
---|
90 | return $list_iconconf_path; |
---|
91 | } |
---|
92 | // +-------------------------------------------------------+ |
---|
93 | // | Vérifie l'intégrité de la config | |
---|
94 | // +-------------------------------------------------------+ |
---|
95 | function check_config() |
---|
96 | { |
---|
97 | global $conf, $prefixeTable, $page; |
---|
98 | $conf_iconset = @unserialize($conf['iconset']);//pwg_db_real_escape_string(serialize($conf_iconset)) |
---|
99 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
---|
100 | $themes = new themes(); |
---|
101 | $all_icons=get_list_iconconf_path ('./plugins/Icons_Set/icons'); |
---|
102 | if ( !isset($conf_iconset) or empty($conf_iconset) or !is_array($conf_iconset) ) |
---|
103 | { |
---|
104 | $conf['iconset']=array( |
---|
105 | 'themes'=>array(), |
---|
106 | 'icons'=>array() |
---|
107 | ); |
---|
108 | } |
---|
109 | $themes->sort_fs_themes(); |
---|
110 | $conf_themes=$conf_iconset['themes']; |
---|
111 | $conf_icons=$conf_iconset['icons']; |
---|
112 | $list_theme_id=array(); |
---|
113 | $info_new_theme=''; |
---|
114 | $info_new_icon=''; |
---|
115 | $info_deleted_theme=''; |
---|
116 | $info_deleted_icon=''; |
---|
117 | foreach ($themes->fs_themes as $theme_id => $fs_theme) |
---|
118 | { |
---|
119 | if ((isset($fs_theme['activable']) and !$fs_theme['activable']) or $theme_id == 'default' ) |
---|
120 | { |
---|
121 | continue; |
---|
122 | } |
---|
123 | if (!is_array($conf_themes)) // theme ajouté |
---|
124 | { |
---|
125 | $info_new_theme.=$theme_id.'<br>'; |
---|
126 | $conf_themes[$theme_id]=''; // RAZ |
---|
127 | } |
---|
128 | elseif (!array_key_exists($fs_theme['id'], $conf_themes)) // theme ajouté |
---|
129 | { |
---|
130 | $info_new_theme.=$theme_id.'<br>'; |
---|
131 | $conf_themes[$theme_id]=''; // RAZ |
---|
132 | } |
---|
133 | if (!empty($conf_themes[$theme_id]) and !in_array($conf_themes[$theme_id], $all_icons)) // association thème/icon supprimée |
---|
134 | { |
---|
135 | $info_deleted_icon.=$conf_themes[$theme_id].'<br>'; |
---|
136 | $conf_themes[$theme_id]=''; // RAZ |
---|
137 | } |
---|
138 | $list_theme_id[]=$theme_id; |
---|
139 | } |
---|
140 | foreach ($conf_themes as $theme_id => $iconset) // theme supprimé |
---|
141 | { |
---|
142 | if (!in_array($theme_id, $list_theme_id)) |
---|
143 | { |
---|
144 | $info_deleted_theme.=$theme_id.'<br>'; |
---|
145 | unset($conf_themes[$theme_id]);// suppression de sa config |
---|
146 | } |
---|
147 | } |
---|
148 | foreach ($all_icons as $iconset) // icones ajoutées |
---|
149 | { |
---|
150 | if (is_array($conf_icons)) |
---|
151 | { |
---|
152 | if (!in_array($iconset, $conf_icons)) |
---|
153 | { |
---|
154 | $info_new_icon.=$iconset.'<br>'; |
---|
155 | } |
---|
156 | } |
---|
157 | else |
---|
158 | { |
---|
159 | $info_new_icon.=$iconset.'<br>'; |
---|
160 | } |
---|
161 | } |
---|
162 | $conf['iconset']=array( |
---|
163 | 'themes'=>$conf_themes, |
---|
164 | 'icons'=>$all_icons |
---|
165 | ); |
---|
166 | $query = ' |
---|
167 | UPDATE '.CONFIG_TABLE.' |
---|
168 | SET value="'.pwg_db_real_escape_string(serialize($conf['iconset'])).'" |
---|
169 | WHERE param="iconset" |
---|
170 | LIMIT 1'; |
---|
171 | pwg_query($query); |
---|
172 | load_conf_from_db(); |
---|
173 | if (!empty($info_new_theme)) { array_push($page['infos'], l10n('iconset_info_new_theme').$info_new_theme ); } |
---|
174 | if (!empty($info_new_icon)) { array_push($page['infos'], l10n('iconset_info_new_icon').$info_new_icon ); } |
---|
175 | if (!empty($info_deleted_theme)) { array_push($page['infos'], l10n('iconset_info_deleted_theme').$info_deleted_theme ); } |
---|
176 | if (!empty($info_deleted_icon)) { array_push($page['infos'], l10n('iconset_info_deleted_icon').$info_deleted_icon ); } |
---|
177 | } |
---|
178 | |
---|
179 | // +-------------------------------------------------------+ |
---|
180 | // | début réel | |
---|
181 | // +-------------------------------------------------------+ |
---|
182 | |
---|
183 | if (!isset($_POST['envoi_config']))// on économise du temps |
---|
184 | { |
---|
185 | check_config(); |
---|
186 | load_conf_from_db(); |
---|
187 | } |
---|
188 | $conf_iconset = @unserialize($conf['iconset']);//pwg_db_real_escape_string(serialize($conf_iconset)) |
---|
189 | $conf_themes=$conf_iconset['themes']; |
---|
190 | $conf_icons=$conf_iconset['icons']; |
---|
191 | include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php'); |
---|
192 | $themes = new themes(); |
---|
193 | $themes->sort_fs_themes(); |
---|
194 | $all_themes=array(); |
---|
195 | |
---|
196 | // affichage des themes |
---|
197 | foreach ($conf_themes as $theme_id => $iconset) |
---|
198 | { |
---|
199 | $all_themes[$theme_id]=array( |
---|
200 | 'name'=>$themes->fs_themes[$theme_id]['name'], |
---|
201 | 'id'=>$themes->fs_themes[$theme_id]['id'], |
---|
202 | 'screenshot'=>$themes->fs_themes[$theme_id]['screenshot'], |
---|
203 | 'icon'=>$iconset, |
---|
204 | ); |
---|
205 | } |
---|
206 | |
---|
207 | $all_icons=array(); |
---|
208 | $values=array(); |
---|
209 | $output=array(); |
---|
210 | $template->func_combine_css(array( |
---|
211 | 'path' => 'themes/default/iconset.css', |
---|
212 | ) |
---|
213 | ); |
---|
214 | |
---|
215 | // affichage des icônes |
---|
216 | foreach ($conf_icons as $iconset) |
---|
217 | { |
---|
218 | @include_once('icons/'.$iconset); |
---|
219 | $all_icons[]=array( |
---|
220 | 'path'=>$iconset, |
---|
221 | 'name' => $iconsetconf['name'], |
---|
222 | 'id' => $iconsetconf['id'], |
---|
223 | 'icon_file' => $iconsetconf['icon_file'], |
---|
224 | 'css_file' => $iconsetconf['css_file'], |
---|
225 | 'css_file_admin' => $iconsetconf['css_file_admin'], |
---|
226 | ); |
---|
227 | $values[]=$iconset; |
---|
228 | $output[]=$iconsetconf['name']; |
---|
229 | $template->func_combine_css(array( |
---|
230 | 'path' => $iconsetconf['css_file_admin'], |
---|
231 | ) |
---|
232 | ); |
---|
233 | } |
---|
234 | $template->assign(array( |
---|
235 | 'all_themes' => $all_themes, |
---|
236 | 'all_icons' => $all_icons, |
---|
237 | 'values' => $values, |
---|
238 | 'output' => $output, |
---|
239 | )); |
---|
240 | |
---|
241 | $template->assign(array( |
---|
242 | 'PWG_TOKEN' => get_pwg_token() |
---|
243 | )); |
---|
244 | |
---|
245 | $template->func_combine_css(array( |
---|
246 | 'path' => 'plugins/'.ICONSET_DIR.'/template/admin.css', |
---|
247 | ) |
---|
248 | ); |
---|
249 | |
---|
250 | $template->set_filename('plugin_admin_content', dirname(__FILE__) .'/template/admin.tpl'); |
---|
251 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
252 | |
---|
253 | ?> |
---|