[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() { |
---|
[12081] | 17 | global $erreur_message,$liste_des_plugins_actifs,$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'); |
---|
[12081] | 24 | $liste_des_plugins_actifs = array(); |
---|
[11499] | 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") |
---|
[12081] | 29 | array_push($liste_des_plugins_actifs,$plugin_id); |
---|
[11499] | 30 | } |
---|
| 31 | } //foreach |
---|
| 32 | if (isset($_GET['set'])){ |
---|
| 33 | $ret['config']=$_GET; |
---|
[12081] | 34 | $ret['liste_plugins']=$liste_des_plugins_actifs; |
---|
| 35 | // array_push($ret,$liste_des_plugins_actifs); |
---|
[11499] | 36 | if($_GET['config']['liste_visible']) |
---|
| 37 | set_plugins::save_config(); |
---|
| 38 | echo json_encode($ret); |
---|
| 39 | |
---|
| 40 | exit; |
---|
| 41 | } |
---|
[12081] | 42 | $liste_active_plugins=$liste_des_plugins_actifs; |
---|
[11499] | 43 | } |
---|
[11484] | 44 | } |
---|
| 45 | //============================================================================ |
---|
[11385] | 46 | function set_plugins_add() { |
---|
[11484] | 47 | global $user, $template, $val,$page,$conf,$erreur_message,$infos_message; |
---|
[12081] | 48 | global $liste_des_plugins_actifs,$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 | |
---|
[12404] | 70 | if ( (isset($_GET['page']) AND ($_GET['page'] == 'plugins' || $_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(){ |
---|
[12081] | 140 | global $infos_message,$liste_des_plugins_actifs,$erreur_message ; |
---|
[11484] | 141 | |
---|
[11386] | 142 | include_once(SET_PLUGINS_PATH."include/constants.php"); |
---|
[11484] | 143 | include(SET_PLUGINS_PATH.'include/affiche.php'); |
---|
| 144 | |
---|
[12404] | 145 | $all_tpl_vars = $template->get_template_vars('ADMIN_CONTENT'); |
---|
| 146 | |
---|
[11497] | 147 | if( isset($_POST['submit'])){ |
---|
[11386] | 148 | $state=""; |
---|
[11497] | 149 | if($_POST['submit']==l10n("Deactivate") ) |
---|
[11386] | 150 | $state='inactive'; |
---|
[11497] | 151 | elseif($_POST['submit']==l10n("Activate") ) |
---|
[11386] | 152 | $state='active'; |
---|
| 153 | if($state!=""){ |
---|
[11385] | 154 | if($state=="inactive") |
---|
| 155 | $sens ="DESC"; |
---|
| 156 | else |
---|
| 157 | $sens="ASC"; |
---|
[11497] | 158 | |
---|
[11385] | 159 | //============================ |
---|
| 160 | $query = 'SELECT * |
---|
[11386] | 161 | FROM ' . PLUGINS_TABLE . ' |
---|
[11385] | 162 | WHERE `state` NOT LIKE "'.$state. '" AND id!="' . "set_plugins" . '" |
---|
| 163 | ORDER BY `id` '.$sens.' |
---|
| 164 | LIMIT '.$nb.' |
---|
| 165 | '; |
---|
[11386] | 166 | $result = pwg_query($query); |
---|
[12404] | 167 | //======= mise a jour ========= |
---|
[11385] | 168 | if($result){ |
---|
| 169 | $query = ' |
---|
| 170 | UPDATE '.PLUGINS_TABLE.' |
---|
[11386] | 171 | SET state="'.$state.'" |
---|
[11385] | 172 | WHERE `state` NOT LIKE "'.$state. '" AND id!="' . "set_plugins" . '" |
---|
| 173 | ORDER BY `id` '.$sens.' |
---|
| 174 | LIMIT '.$nb.';'; |
---|
[11386] | 175 | pwg_query($query); |
---|
[11385] | 176 | } |
---|
| 177 | //===================================== |
---|
| 178 | if(isset($result) && $result==true){ |
---|
| 179 | $liste= array_unique($liste); |
---|
[11386] | 180 | if(!array_search($add_plugins, $liste)){ |
---|
[11385] | 181 | array_push($liste, $add_plugins ); |
---|
| 182 | } |
---|
[11386] | 183 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
[11385] | 184 | $url = $row['id'] ; |
---|
[11386] | 185 | array_push($liste, $url); |
---|
| 186 | } |
---|
[11385] | 187 | } |
---|
[11497] | 188 | }else if ($_POST['submit']==l10n('store') ){ |
---|
[11386] | 189 | $liste = array(); |
---|
[11385] | 190 | $state="active"; |
---|
| 191 | $query = 'SELECT * |
---|
[11386] | 192 | FROM ' . PLUGINS_TABLE . ' |
---|
| 193 | WHERE `state` LIKE "active" AND id!="' . "set_plugins" . '" |
---|
[11385] | 194 | '; |
---|
| 195 | $result = pwg_query($query); |
---|
| 196 | if(isset($result) && $result==true){ |
---|
[11386] | 197 | $liste_plugins = array(); |
---|
| 198 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
[11385] | 199 | $url = $row['id'] ; |
---|
| 200 | //array_push($liste_plugins, array('plugin' => $url ) ); |
---|
[11386] | 201 | array_push($liste, $url ); |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | $nb=count($liste_plugins); |
---|
[11462] | 205 | |
---|
| 206 | } |
---|
[11385] | 207 | if(isset($result) && $result==true){ |
---|
[11484] | 208 | $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; |
---|
[11462] | 209 | set_plugins::save_config(); |
---|
[11385] | 210 | $_POST['set']=""; |
---|
| 211 | $set=""; |
---|
[11386] | 212 | include(SET_PLUGINS_PATH.'include/affiche.php'); |
---|
[11385] | 213 | // redirect($redirect_url); |
---|
| 214 | } |
---|
[11484] | 215 | |
---|
[11385] | 216 | } |
---|
| 217 | $template->set_filenames( |
---|
[11462] | 218 | array( 'cl_plugin' => SET_PLUGINS_PATH_ABS.'template/admin.tpl' ) |
---|
[11499] | 219 | ); |
---|
[11484] | 220 | |
---|
[11385] | 221 | //=========================================================== |
---|
[11386] | 222 | $header_1='<div id="titrePage"> |
---|
| 223 | <h2>'.l10n("set_plugins").l10n("Version").": ".$cl_set_plugins_plugin['version'] .'</h2> |
---|
[11385] | 224 | </div>'; |
---|
[12404] | 225 | |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | $bpplus=$header_1."<div>".$template->parse('cl_plugin', true)."</div>"; |
---|
| 229 | |
---|
| 230 | |
---|
[11497] | 231 | $template-> assign('ADMIN_CONTENT',$bpplus); |
---|
| 232 | $template-> concat('ADMIN_CONTENT',$all_tpl_vars); |
---|
[11385] | 233 | } |
---|
| 234 | |
---|
[11484] | 235 | //======================================== |
---|
| 236 | function save_to_file($liste){ |
---|
| 237 | global $infos_message; |
---|
| 238 | $edited_file=set_plugins::get_file_name(); |
---|
[11499] | 239 | if (file_exists($edited_file)){ |
---|
| 240 | copy($edited_file, substr_replace($edited_file, '.bak', strrpos($edited_file , '.'), 0) ); |
---|
| 241 | } |
---|
| 242 | if ($file = @fopen($edited_file , "w")) { |
---|
| 243 | $liste= array_unique($liste); |
---|
| 244 | @fwrite($file , serialize($liste)); |
---|
| 245 | @fclose($file); |
---|
| 246 | $infos_message.=l10n("save config").set_plugins::memo_var($edited_file); |
---|
| 247 | unset($_POST['submit']); |
---|
[11484] | 248 | } |
---|
| 249 | } |
---|
| 250 | //============================================== |
---|
| 251 | function restore_from_file(){ |
---|
[11497] | 252 | global $infos_message,$edited_file; |
---|
[11499] | 253 | $content_file = file_get_contents($edited_file); |
---|
[11497] | 254 | return unserialize($content_file) ; |
---|
[11484] | 255 | } |
---|
| 256 | //=============================================== |
---|
| 257 | function get_file_name(){ |
---|
[11497] | 258 | global $edited_file,$infos_message; |
---|
[11499] | 259 | $dir=realpath('./local/plugins/set_plugins'); |
---|
[11497] | 260 | if (!is_dir($dir)){ |
---|
[11499] | 261 | $dir=realpath('./local/plugins'); |
---|
| 262 | if (!is_dir($dir)){ |
---|
| 263 | $dir=str_replace("\\","/",realpath('./local').'/plugins'); |
---|
| 264 | $umask = umask(0); |
---|
| 265 | $mkd = @mkdir($dir, 0755, true ); |
---|
| 266 | umask($umask); |
---|
| 267 | if ($mkd==false){ |
---|
| 268 | fatal_error( "1°) $dir ".l10n('no write access')); |
---|
| 269 | } |
---|
| 270 | } |
---|
| 271 | //===================================================== |
---|
| 272 | $dir=realpath('./local/plugins/set_plugins'); |
---|
| 273 | if (!is_dir($dir)){ |
---|
| 274 | |
---|
| 275 | $dir=str_replace("\\","/",realpath('./local/plugins').'/set_plugins'); |
---|
| 276 | $umask = umask(0); |
---|
| 277 | $mkd = @mkdir($dir, 0755, true ); |
---|
| 278 | umask($umask); |
---|
| 279 | if ($mkd==false){ |
---|
| 280 | fatal_error( "2°) $dir ".l10n('no write access')); |
---|
| 281 | } |
---|
| 282 | //$file = $dir.'\\.htaccess'; |
---|
| 283 | //@file_put_contents( $file, 'allow from all' ); |
---|
| 284 | } |
---|
| 285 | $dir=realpath('./local/plugins/set_plugins'); |
---|
| 286 | } |
---|
| 287 | |
---|
[11484] | 288 | if(!isset($edited_file) || $edited_file=="") |
---|
| 289 | $edited_file=$dir."/config.txt"; |
---|
| 290 | $edited_file=str_replace("\\","/", $edited_file); |
---|
[11499] | 291 | |
---|
| 292 | |
---|
[11484] | 293 | return $edited_file ; |
---|
| 294 | } |
---|
[11385] | 295 | |
---|
| 296 | }// fin classe |
---|
| 297 | ?> |
---|