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