PageRenderTime 33ms CodeModel.GetById 19ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/aoliz/core/admin/controller/system/ctl.appmgr.php

http://phpfor.googlecode.com/
PHP | 300 lines | 262 code | 38 blank | 0 comment | 29 complexity | efaa3696d76802c285cc4bd0402a182b MD5 | raw file
  1<?php
  2require_once('objectPage.php');
  3class ctl_appmgr extends adminPage{
  4
  5    var $workground = 'tools';
  6
  7    function index(){
  8
  9        $appmgr = $this->system->loadModel('system/appmgr');
 10        $apps = $appmgr->getList();
 11        $this->pagedata['install_url'] = constant('APP_INSTALL_URL');
 12        foreach($apps as $k=>$app){
 13            $file = BASE_DIR.'/plugins/app/'.$app['plugin_package'].'/setting.php';
 14            if(file_exists($file)){
 15                if($app['status']=='used'){
 16                    $setting = array();
 17                    require($file);
 18                    foreach($setting as $key=>$value){
 19                        if(!$this->system->getConf('app.'.$app['plugin_ident'].'.'.$key)){
 20                            $app['unset_setting'] = 1;
 21                        }
 22                    }
 23                }
 24                $app['has_setting'] = 1;
 25            }
 26            $app['plugin_struct'] = unserialize($app['plugin_struct']);
 27            $apps[$k] = $app;
 28        }
 29        $this->pagedata['apps'] = &$apps;
 30
 31        $this->page('system/appmgr/index.html');
 32    }
 33
 34    function install_update(){
 35        $this->pagedata['update_url'] = 'index.php?ctl=system/appmgr&act=download_update_app&app_status='.$_GET['app_status'].'&url='.$_GET['url'];
 36        $this->page('system/appmgr/update.html');
 37    }
 38
 39    function download_update_app(){
 40        if(isset($_GET['url'])){
 41            include(CORE_DIR.'/admin/controller/service/ctl.download.php');
 42            $download = new ctl_download();
 43            $_POST = array(
 44                'download_list'=>array($_GET['url']),
 45                'succ_url'=>'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])
 46                .'/index.php?ctl=system/appmgr&act=do_update&app_status='.$_GET['app_status']
 47            );
 48
 49            $download->start();
 50        }
 51        exit;
 52    }
 53
 54    function do_update(){
 55        $task = HOME_DIR.'/tmp/'.$_GET['download'];
 56        $temp_mess = file_get_contents($task.'/task.php');
 57        $down_data = unserialize($temp_mess);
 58        if($url = $down_data['download_list'][0]){
 59            $filename = substr($url,strrpos($url,"/")+1);
 60            $file_path = $task.'/'.$filename;
 61            $dir_name = substr($filename,0,strrpos($filename,"."));
 62            if(file_exists($file_path)){
 63                $appmgr = $this->system->loadModel("system/appmgr");
 64                if(!$appmgr->instal_ol_app($file_path,$dir_name,$msg,true)){
 65                    echo $msg;
 66                    exit;
 67                }else{
 68                    if($_GET['app_status']=='used'){
 69                        $this->install($dir_name,'online','update');
 70                    }else{
 71                        $this->install($dir_name,'online');
 72                    }
 73                };
 74            }
 75        }
 76    }
 77
 78
 79    
 80
 81
 82
 83
 84
 85    function app_onlince(){
 86        $cet_ping = ping_url("http://app.shopex.cn/web/exuser/index.php");
 87        if(!strstr($cet_ping,'HTTP/1.1 200 OK')){
 88            $this->pagedata['cen_error'] = true;
 89            $this->pagedata['error_url'] = $this->system->base_url().'error.html';
 90        }else{
 91            $certi = $this->system->loadModel("service/certificate");
 92            $this->pagedata['cert_id'] =  $certi->getCerti();
 93        }
 94        $this->page('system/appmgr/app_online.html');
 95    }
 96
 97    function view($ident){
 98        $appmgr = $this->system->loadModel('system/appmgr');
 99        $this->pagedata['app'] = $appmgr->info($ident);
100        $this->pagedata['propmap'] = array(
101            'ver'=>'??',
102            'website'=>'??',
103            'author'=>'??',
104            'baseurl'=>'????',
105            'plugin_path'=>'????',
106            );
107        $this->display('system/appmgr/detail.html');
108    }
109
110    function install_online(){
111        if(isset($_GET['url'])){
112            include(CORE_DIR.'/admin/controller/service/ctl.download.php');
113            $download = new ctl_download();
114            $_POST = array(
115                'download_list'=>array($_GET['url']),
116                'succ_url'=>'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])
117                .'/index.php?ctl=system/appmgr&act=do_install_online'
118            );
119
120            $download->start();
121        }
122        exit;
123    }
124
125    function do_install($ident,$type='offline',$is_update=false){
126        $appmgr = $this->system->loadModel('system/appmgr');
127        $this->begin('index.php?ctl=system/appmgr&act=index');
128        if($appmgr->install($ident,$is_update)){
129            $this->clear_all_cache();
130            if($type=='online'){
131                echo "<script>parent.$('dialogContent').getParent('.dialog').retrieve('instance').close(); W.page('index.php?ctl=system/appmgr&act=index');</script>";
132                exit;
133            }
134            $this->end(true,'????','index.php?ctl=system/appmgr&act=index','');
135        }else{
136            $this->end(false,'????');
137        }
138    }
139
140    function install($ident,$type='offline',$is_update=false){
141        $appmgr = $this->system->loadModel('system/appmgr');
142        $app = &$appmgr->load($ident);
143        if($app->depend){
144            if($err_str = $appmgr->getappByident($app->depend)){
145                $this->pagedata['error_msg'] = $err_str;
146            };
147        }
148        
149        $this->pagedata['table_prefix'] = 'sdb_'.$ident.'_';
150
151        include('ctlmap.php');
152        $map = array();
153        $system_ctl_map = &$this->system->getConf('system.ctlmap');
154        foreach($app->ctl_mapper() as $k=>$v){
155            if($system_ctl_map[$k]){
156                list($pkg,$class,$method)= explode(':',$system_ctl_map[$k]);
157                $stopapp[$pkg] = $pkg;
158            }
159            $map[] = isset($ctlmap[$k])?$ctlmap[$k]:$k;
160        }
161
162        foreach($app->listener() as $eventOrg=>$handle){
163            if($eventOrg=='*'){
164                $listen_event[] = '??';
165            }else{
166                list($mdl,$event) = explode(':',$eventOrg);
167                $mdl = &$this->system->loadModel($mdl);
168                if(method_exists($mdl,'events') &&
169                    $events = $mdl->events() && $events[$event]){
170                    $listen_event[] = $mdl->name.$events[$event]['label'];
171                }else{
172                    $listen_event[] = $eventOrg;
173                }
174            }
175        }
176        if($type=='online') $this->pagedata['online'] = true;
177        $this->pagedata['listen_event'] = &$listen_event;
178        $this->pagedata['ctl_mapper'] = $map;
179        $this->pagedata['app_ident'] = $ident;
180        $this->pagedata['stopapp'] = $appmgr->getNameByIdents($stopapp);
181        $this->pagedata['app'] = get_object_vars($app);
182        $this->pagedata['app_tables'] = $app->dbtables();
183
184        if($is_update){
185            $this->pagedata['update'] = 'yes';
186            if($diff_tables = $appmgr->get_app_diff($ident)){
187                $this->pagedata['app_diff_tables'] = $diff_tables;
188            }
189        }
190        $this->page('system/appmgr/install.html');
191    }
192
193
194
195
196    function do_install_online(){      
197        $task = HOME_DIR.'/tmp/'.$_GET['download'];
198        $temp_mess = file_get_contents($task.'/task.php');
199        $down_data = unserialize($temp_mess);
200        if($url = $down_data['download_list'][0]){
201            $filename = substr($url,strrpos($url,"/")+1);
202            $file_path = $task.'/'.$filename;
203            $dir_name = substr($filename,0,strrpos($filename,"."));
204            if(file_exists($file_path)){
205                $appmgr = $this->system->loadModel("system/appmgr");
206                if(!$appmgr->instal_ol_app($file_path,$dir_name,$msg)){
207                    echo $msg;
208                    exit;
209                }else{
210                    $this->install($dir_name,'online');                  
211                };
212            }
213        }
214    }
215
216    function uninstall($ident){
217        $appmgr = $this->system->loadModel('system/appmgr');
218        $this->pagedata['table_prefix'] = 'sdb_'.$ident.'_';
219        $app = &$appmgr->load($ident,'app');
220
221        include('ctlmap.php');
222        $map = array();
223        foreach($app->ctl_mapper() as $k=>$v){
224            $map[] = $ctlmap[$k];
225        }
226        $this->pagedata['ctl_mapper'] = $map;
227
228        $this->pagedata['app'] = get_object_vars($app);
229        $this->pagedata['app_tables'] = $app->dbtables();
230        $this->page('system/appmgr/uninstall.html');
231    }
232
233    function do_uninstall($ident){
234        $appmgr = $this->system->loadModel('system/appmgr');
235        $this->begin('index.php?ctl=system/appmgr&act=index');
236        if($appmgr->uninstall($ident)){
237            $this->clear_all_cache();
238            $this->end(true,'??????','index.php?ctl=system/appmgr&act=index','');
239        }else{
240            $this->end(false,'??????');
241        }
242    }
243
244    function enable($ident){
245        $appmgr = $this->system->loadModel('system/appmgr');
246        $this->begin('index.php?ctl=system/appmgr&act=index');
247        $app_model = $appmgr->load($ident);
248        if(method_exists($app_model,'enable')){
249            $app_model->enable();
250        }
251        $this->clear_all_cache();
252        $this->end($appmgr->enable($ident));
253    }
254
255    function disable($ident){
256        $appmgr = $this->system->loadModel('system/appmgr');
257        $this->begin('index.php?ctl=system/appmgr&act=index');
258        $app_model = $appmgr->load($ident);
259        if(method_exists($app_model,'disable')){
260            $app_model->disable();
261        }
262        $this->clear_all_cache();
263        $this->end($appmgr->disable($ident));
264    }
265    function setting($ident){
266        $appmgr = $this->system->loadModel('system/appmgr');
267        $app_model = &$appmgr->load($ident);
268        $app = $appmgr->info($ident);
269        if(method_exists($app_model,'setting_load')){
270            $app_model->setting_load();
271        }
272        foreach($app['setting'] as $k=>$v){
273            $tmp['app.'.$ident.'.'.$k] = $v;
274        }
275        $app['setting'] = $tmp;
276        $this->pagedata['app'] = $app;
277      
278        $this->display('system/appmgr/setting.html');
279    }
280    function setting_save($ident){
281        $appmgr = $this->system->loadModel('system/appmgr');
282        $app = &$appmgr->load($ident);
283        if(method_exists($app,'setting_save')){
284            $app->setting_save();
285        }else{
286            $setting = $_POST['setting'];
287                foreach($setting as $key=>$val){
288                    $this->system->setConf($key,$val);
289                }
290            }
291        echo "????";
292    }
293    
294    function dofeedback($app_id){
295        $certi = $this->system->loadModel("service/certificate");
296        $certi_id =  $certi->getCerti();
297        echo '<iframe src="http://feedback.ecos.shopex.cn/index.php?certi_id='.$certi_id.'&app_key='.$app_id.'" width=500 height=350/>';
298    }
299       
300}