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