[11386] | 1 | <?php |
---|
[11385] | 2 | /***************************************************************************/ |
---|
[11462] | 3 | class set_plugins { |
---|
[11385] | 4 | //============================================================================= |
---|
| 5 | function set_plugins_admin_menu($menu) { |
---|
| 6 | array_push( |
---|
| 7 | $menu, |
---|
| 8 | array( |
---|
| 9 | 'NAME' => 'Set_plugins', |
---|
| 10 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php' |
---|
| 11 | ) |
---|
| 12 | ); |
---|
| 13 | return $menu; |
---|
| 14 | } |
---|
| 15 | //============================================================================ |
---|
[11484] | 16 | function begin_admin() { |
---|
[11497] | 17 | global $erreur_message,$liste_des_plugins_activés,$liste_active_plugins,$page; |
---|
[11499] | 18 | //========= Liste des plugins actifs ================= |
---|
| 19 | if (!isset($page['body_id'])) return; |
---|
| 20 | if($page['body_id']!='theAdminPage' ) return ; |
---|
| 21 | if($page['page']=='plugins_list' || $page['page']=='plugins'){ |
---|
[11484] | 22 | $plugins = new plugins(); |
---|
[11499] | 23 | $plugins->sort_fs_plugins('name'); |
---|
| 24 | $liste_des_plugins_activés = array(); |
---|
| 25 | foreach ($plugins->fs_plugins as $plugin_id => $fs_plugin){ |
---|
| 26 | if(isset( $plugins->db_plugins_by_id[$plugin_id])){ |
---|
| 27 | $State_id=$plugins->db_plugins_by_id[$plugin_id]['state'] ; |
---|
| 28 | if($State_id=="active" && $plugin_id!="set_plugins") |
---|
| 29 | array_push($liste_des_plugins_activés,$plugin_id); |
---|
| 30 | } |
---|
| 31 | } //foreach |
---|
| 32 | if (isset($_GET['set'])){ |
---|
| 33 | $ret['config']=$_GET; |
---|
| 34 | $ret['liste_plugins']=$liste_des_plugins_activés; |
---|
| 35 | // array_push($ret,$liste_des_plugins_activés); |
---|
| 36 | if($_GET['config']['liste_visible']) |
---|
| 37 | set_plugins::save_config(); |
---|
| 38 | echo json_encode($ret); |
---|
| 39 | |
---|
| 40 | exit; |
---|
| 41 | } |
---|
[11497] | 42 | $liste_active_plugins=$liste_des_plugins_activés; |
---|
[11499] | 43 | } |
---|
[11484] | 44 | } |
---|
| 45 | //============================================================================ |
---|
[11385] | 46 | function set_plugins_add() { |
---|
[11484] | 47 | global $user, $template, $val,$page,$conf,$erreur_message,$infos_message; |
---|
[11497] | 48 | global $liste_des_plugins_activés,$liste_active_plugins; |
---|
[11385] | 49 | if (!isset($page['body_id'])) return; |
---|
[11484] | 50 | |
---|
[11385] | 51 | switch($page['body_id']){ |
---|
[11386] | 52 | case 'theAdminPage': |
---|
[11385] | 53 | switch($page['page']){ |
---|
[11484] | 54 | case 'plugins_list': |
---|
[11386] | 55 | if(!isset($template)) return ; |
---|
[11462] | 56 | set_plugins::Affiche_set_plugins(); |
---|
[11385] | 57 | break; |
---|
[11386] | 58 | case 'plugins': |
---|
[11385] | 59 | if (!isset($page['tab'])) return; |
---|
[11386] | 60 | if ($page['tab']!="installed") return ; |
---|
[11462] | 61 | set_plugins::Affiche_set_plugins(); |
---|
[11386] | 62 | break; |
---|
| 63 | } |
---|
| 64 | } |
---|
[11385] | 65 | } |
---|
| 66 | //============================================================================ |
---|
[11484] | 67 | function messages_admin(){ |
---|
[11386] | 68 | global $template,$page, $template, $pwg_loaded_plugins,$infos_message,$erreur_message,$infos_warning; |
---|
[11462] | 69 | |
---|
[11386] | 70 | if ( (isset($_GET['page']) AND $_GET['page'] == 'plugins_list') ) { |
---|
[11462] | 71 | if (!isset($page['infos'])) $page['infos']=array(); |
---|
[11385] | 72 | if ($infos_message != "") { |
---|
[11386] | 73 | array_push($page['infos'], $infos_message); |
---|
| 74 | $infos_message=""; |
---|
[11462] | 75 | |
---|
| 76 | } |
---|
| 77 | if (count($page['infos']) != 0){ |
---|
| 78 | $template->assign('infos', $page['infos']); |
---|
[11385] | 79 | } |
---|
[11462] | 80 | if (!isset($page['errors'])) $page['errors']=array(); |
---|
[11386] | 81 | if ($erreur_message != "") { |
---|
| 82 | array_push($page['errors'], $erreur_message); |
---|
| 83 | $erreur_message=""; |
---|
[11462] | 84 | } |
---|
| 85 | if (count($page['errors']) != 0){ |
---|
| 86 | $template->assign('errors', $page['errors']); |
---|
[11386] | 87 | } |
---|
[11462] | 88 | |
---|
| 89 | if (!isset($page['warnings'])) $page['warnings']=array(); |
---|
[11386] | 90 | if ($infos_warning!= "") { |
---|
| 91 | array_push($page['warnings'], $infos_warning); |
---|
| 92 | $infos_warning= ""; |
---|
[11462] | 93 | } |
---|
[11386] | 94 | if (count($page['warnings']) != 0){ |
---|
| 95 | $template->assign('warnings', $page['warnings']); |
---|
| 96 | } |
---|
| 97 | } |
---|
[11385] | 98 | } |
---|
| 99 | //========================================================================================== |
---|
| 100 | function set_var($key,$defaut){ |
---|
| 101 | global $set_plugins_parametres; |
---|
[11386] | 102 | global $infos_message; |
---|
[11385] | 103 | |
---|
| 104 | if(isset($set_plugins_parametres) && isset($set_plugins_parametres[$key])) |
---|
| 105 | $ret=$set_plugins_parametres[$key]; |
---|
| 106 | |
---|
| 107 | $ret= (isset($ret))?$ret:$defaut; |
---|
[11386] | 108 | $ret=isset($_POST[$key])?$_POST[$key]:$ret; |
---|
[11385] | 109 | return $ret ; |
---|
[11386] | 110 | } |
---|
[11385] | 111 | //================================================================ |
---|
| 112 | function save_config(){ |
---|
[11386] | 113 | global $list_visible, $state,$liste,$nb,$page,$conf ; |
---|
| 114 | global $infos_message,$infos_warning,$erreur_message ; |
---|
[11385] | 115 | $config=array(); |
---|
| 116 | $config = array( |
---|
| 117 | 'list_visible' => $list_visible, |
---|
| 118 | 'state' => $state, |
---|
[11484] | 119 | 'liste'=>$liste, |
---|
[11385] | 120 | 'nb' =>$nb |
---|
[11386] | 121 | ); |
---|
[11462] | 122 | // $infos_warning .="save_config" . set_plugins::memo_var($conf['set_plugins'] ); |
---|
[11385] | 123 | $conf['set_plugins']= (serialize($config)); |
---|
| 124 | conf_update_param('set_plugins', $conf['set_plugins']); |
---|
[11462] | 125 | |
---|
[11385] | 126 | |
---|
| 127 | } |
---|
| 128 | //================================================================= |
---|
| 129 | function memo_var($variables){ |
---|
| 130 | ob_start(); |
---|
| 131 | echo '<pre>'; |
---|
| 132 | print_r($variables); |
---|
| 133 | echo '</pre>'; |
---|
| 134 | $m= ob_get_contents(); |
---|
| 135 | ob_end_clean(); |
---|
[11386] | 136 | return $m; |
---|
| 137 | } |
---|
[11385] | 138 | //=================================================================== |
---|
[11462] | 139 | function Affiche_set_plugins(){ |
---|
[11497] | 140 | global $infos_message,$liste_des_plugins_activés,$erreur_message ; |
---|
[11484] | 141 | |
---|
[11386] | 142 | include_once(SET_PLUGINS_PATH."include/constants.php"); |
---|
[11484] | 143 | include(SET_PLUGINS_PATH.'include/affiche.php'); |
---|
| 144 | |
---|
[11497] | 145 | if( isset($_POST['submit'])){ |
---|
[11386] | 146 | $state=""; |
---|
[11497] | 147 | if($_POST['submit']==l10n("Deactivate") ) |
---|
[11386] | 148 | $state='inactive'; |
---|
[11497] | 149 | elseif($_POST['submit']==l10n("Activate") ) |
---|
[11386] | 150 | $state='active'; |
---|
| 151 | if($state!=""){ |
---|
[11385] | 152 | if($state=="inactive") |
---|
| 153 | $sens ="DESC"; |
---|
| 154 | else |
---|
| 155 | $sens="ASC"; |
---|
[11497] | 156 | |
---|
[11385] | 157 | //============================ |
---|
| 158 | $query = 'SELECT * |
---|
[11386] | 159 | FROM ' . PLUGINS_TABLE . ' |
---|
[11385] | 160 | WHERE `state` NOT LIKE "'.$state. '" AND id!="' . "set_plugins" . '" |
---|
| 161 | ORDER BY `id` '.$sens.' |
---|
| 162 | LIMIT '.$nb.' |
---|
| 163 | '; |
---|
[11386] | 164 | $result = pwg_query($query); |
---|
| 165 | //======= mise à jour ========= |
---|
[11385] | 166 | if($result){ |
---|
| 167 | $query = ' |
---|
| 168 | UPDATE '.PLUGINS_TABLE.' |
---|
[11386] | 169 | SET state="'.$state.'" |
---|
[11385] | 170 | WHERE `state` NOT LIKE "'.$state. '" AND id!="' . "set_plugins" . '" |
---|
| 171 | ORDER BY `id` '.$sens.' |
---|
| 172 | LIMIT '.$nb.';'; |
---|
[11386] | 173 | pwg_query($query); |
---|
[11385] | 174 | } |
---|
| 175 | //===================================== |
---|
| 176 | if(isset($result) && $result==true){ |
---|
| 177 | $liste= array_unique($liste); |
---|
[11386] | 178 | if(!array_search($add_plugins, $liste)){ |
---|
[11385] | 179 | array_push($liste, $add_plugins ); |
---|
| 180 | } |
---|
[11386] | 181 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
[11385] | 182 | $url = $row['id'] ; |
---|
[11386] | 183 | array_push($liste, $url); |
---|
| 184 | } |
---|
[11385] | 185 | } |
---|
[11497] | 186 | }else if ($_POST['submit']==l10n('store') ){ |
---|
[11386] | 187 | $liste = array(); |
---|
[11385] | 188 | $state="active"; |
---|
| 189 | $query = 'SELECT * |
---|
[11386] | 190 | FROM ' . PLUGINS_TABLE . ' |
---|
| 191 | WHERE `state` LIKE "active" AND id!="' . "set_plugins" . '" |
---|
[11385] | 192 | '; |
---|
| 193 | $result = pwg_query($query); |
---|
| 194 | if(isset($result) && $result==true){ |
---|
[11386] | 195 | $liste_plugins = array(); |
---|
| 196 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
[11385] | 197 | $url = $row['id'] ; |
---|
| 198 | //array_push($liste_plugins, array('plugin' => $url ) ); |
---|
[11386] | 199 | array_push($liste, $url ); |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | $nb=count($liste_plugins); |
---|
[11462] | 203 | |
---|
| 204 | } |
---|
[11385] | 205 | if(isset($result) && $result==true){ |
---|
[11484] | 206 | $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; |
---|
[11462] | 207 | set_plugins::save_config(); |
---|
[11385] | 208 | $_POST['set']=""; |
---|
| 209 | $set=""; |
---|
[11386] | 210 | include(SET_PLUGINS_PATH.'include/affiche.php'); |
---|
[11385] | 211 | // redirect($redirect_url); |
---|
| 212 | } |
---|
[11484] | 213 | |
---|
[11385] | 214 | } |
---|
| 215 | $template->set_filenames( |
---|
[11462] | 216 | array( 'cl_plugin' => SET_PLUGINS_PATH_ABS.'template/admin.tpl' ) |
---|
[11499] | 217 | ); |
---|
[11484] | 218 | |
---|
[11385] | 219 | //=========================================================== |
---|
[11386] | 220 | $header_1='<div id="titrePage"> |
---|
| 221 | <h2>'.l10n("set_plugins").l10n("Version").": ".$cl_set_plugins_plugin['version'] .'</h2> |
---|
[11385] | 222 | </div>'; |
---|
[11497] | 223 | $bpplus=$header_1.$template->parse('cl_plugin', true); |
---|
| 224 | $all_tpl_vars = $template->get_template_vars('ADMIN_CONTENT'); |
---|
| 225 | $template-> assign('ADMIN_CONTENT',$bpplus); |
---|
| 226 | $template-> concat('ADMIN_CONTENT',$all_tpl_vars); |
---|
[11385] | 227 | } |
---|
| 228 | |
---|
[11484] | 229 | //======================================== |
---|
| 230 | function save_to_file($liste){ |
---|
| 231 | global $infos_message; |
---|
| 232 | $edited_file=set_plugins::get_file_name(); |
---|
[11499] | 233 | if (file_exists($edited_file)){ |
---|
| 234 | copy($edited_file, substr_replace($edited_file, '.bak', strrpos($edited_file , '.'), 0) ); |
---|
| 235 | } |
---|
| 236 | if ($file = @fopen($edited_file , "w")) { |
---|
| 237 | $liste= array_unique($liste); |
---|
| 238 | @fwrite($file , serialize($liste)); |
---|
| 239 | @fclose($file); |
---|
| 240 | $infos_message.=l10n("save config").set_plugins::memo_var($edited_file); |
---|
| 241 | unset($_POST['submit']); |
---|
[11484] | 242 | } |
---|
| 243 | } |
---|
| 244 | //============================================== |
---|
| 245 | function restore_from_file(){ |
---|
[11497] | 246 | global $infos_message,$edited_file; |
---|
[11499] | 247 | $content_file = file_get_contents($edited_file); |
---|
[11497] | 248 | return unserialize($content_file) ; |
---|
[11484] | 249 | } |
---|
| 250 | //=============================================== |
---|
| 251 | function get_file_name(){ |
---|
[11497] | 252 | global $edited_file,$infos_message; |
---|
[11499] | 253 | $dir=realpath('./local/plugins/set_plugins'); |
---|
[11497] | 254 | if (!is_dir($dir)){ |
---|
[11499] | 255 | $dir=realpath('./local/plugins'); |
---|
| 256 | if (!is_dir($dir)){ |
---|
| 257 | $dir=str_replace("\\","/",realpath('./local').'/plugins'); |
---|
| 258 | $umask = umask(0); |
---|
| 259 | $mkd = @mkdir($dir, 0755, true ); |
---|
| 260 | umask($umask); |
---|
| 261 | if ($mkd==false){ |
---|
| 262 | fatal_error( "1°) $dir ".l10n('no write access')); |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | //===================================================== |
---|
| 266 | $dir=realpath('./local/plugins/set_plugins'); |
---|
| 267 | if (!is_dir($dir)){ |
---|
| 268 | |
---|
| 269 | $dir=str_replace("\\","/",realpath('./local/plugins').'/set_plugins'); |
---|
| 270 | $umask = umask(0); |
---|
| 271 | $mkd = @mkdir($dir, 0755, true ); |
---|
| 272 | umask($umask); |
---|
| 273 | if ($mkd==false){ |
---|
| 274 | fatal_error( "2°) $dir ".l10n('no write access')); |
---|
| 275 | } |
---|
| 276 | //$file = $dir.'\\.htaccess'; |
---|
| 277 | //@file_put_contents( $file, 'allow from all' ); |
---|
| 278 | } |
---|
| 279 | $dir=realpath('./local/plugins/set_plugins'); |
---|
| 280 | } |
---|
| 281 | |
---|
[11484] | 282 | if(!isset($edited_file) || $edited_file=="") |
---|
| 283 | $edited_file=$dir."/config.txt"; |
---|
| 284 | $edited_file=str_replace("\\","/", $edited_file); |
---|
[11499] | 285 | |
---|
| 286 | |
---|
[11484] | 287 | return $edited_file ; |
---|
| 288 | } |
---|
[11385] | 289 | |
---|
| 290 | }// fin classe |
---|
| 291 | ?> |
---|