PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/aoliz/core/updatescripts/50000.php

http://phpfor.googlecode.com/
PHP | 380 lines | 301 code | 53 blank | 26 comment | 56 complexity | d8254634a161dc3382097198d352acda MD5 | raw file
  1. <?php
  2. class UpgradeScript extends Upgrade{
  3. var $left_domain='shopex.cn';
  4. var $workground='setting';
  5. var $max_runtime = 5;
  6. var $safebytes = 10;
  7. var $set;
  8. var $noticeMsg = array();
  9. function upgrade_checkdb(){
  10. $payment = &$this->system->loadModel('trading/payment');
  11. $sql = "SELECT pay_type FROM sdb_payment_cfg";
  12. if($rs = $this->db->select($sql)){
  13. if(is_array($rs)){
  14. foreach($rs as $key=>$val){
  15. if($val['pay_type'] == 'wangyin'){
  16. $val['pay_type'] = 'wangjin';
  17. $this->db->exec("update sdb_payment_cfg set pay_type ='wangjin' where pay_type = 'wangyin'");
  18. }
  19. $type = $val['pay_type'];
  20. $payType = 'pay_'.$val['pay_type'];
  21. $this->install_online($payType,'',1);
  22. }
  23. }
  24. }
  25. }
  26. function install_online($ident,$url,$is_update=false){
  27. if(!$url)
  28. $url = 'http://sds.ecos.shopex.cn/payments/apps/'.$ident.'.tar';
  29. $_POST = array(
  30. 'download_list'=>array($url),
  31. 'succ_url'=>'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])
  32. .'/index.php?ctl=trading/payment&act=do_install_online'
  33. );
  34. $this->start();
  35. if($is_update){
  36. $ident = date("Ymd").substr(md5(time().rand(0,9999)),0,5);
  37. $this->run($this->ident,0);
  38. $_GET['download'] =$this->ident;
  39. $this->do_install_online();
  40. }
  41. }
  42. function start(){
  43. $this->clear_unused_fold();
  44. $ident = date("Ymd").substr(md5(time().rand(0,9999)),0,5);
  45. $this->workdir = HOME_DIR.'/tmp/'.$ident;
  46. // $_POST['succ_url'] = 'http://google.com';
  47. //?????
  48. // $_POST['list'] = array(
  49. // 'http://mirrors.163.com/archlinux/archlinux/iso/latest/archlinux-2009.02-core-i686.img',
  50. // 'http://flaboy.dev.shopex.cn/dbaron-1.wmv',
  51. // 'http://mirror.nus.edu.sg/iso/F-7-i386-rescuecd.iso',
  52. // 'http://flaboy.dev.shopex.cn/fcgi-2.4.0.tar.gz',
  53. // 'http://flaboy.dev.shopex.cn/libtool-1.5.26.tar.gz',
  54. // 'http://flaboy.dev.shopex.cn/flist.php',
  55. // 'http://flaboy.dev.shopex.cn/m4-1.4.11.tar.bz2'
  56. // );
  57. //key_as_name????????????
  58. // $_POST['key_as_name'] = true;
  59. // $_POST['list'] = array(
  60. // 'path/to/img/i686.img'=>'http://mirrors.163.com/archlinux/archlinux/iso/latest/archlinux-2009.02-core-i686.img',
  61. // 'path/to/dbaron-1.wmv'=>'http://flaboy.dev.shopex.cn/dbaron-1.wmv',
  62. // 'fcgi.tgz' => 'http://flaboy.dev.shopex.cn/fcgi-2.4.0.tar.gz',
  63. // 'tools/libtool.tgz' => 'http://flaboy.dev.shopex.cn/libtool-1.5.26.tar.gz',
  64. // 'flist.php' => 'http://flaboy.dev.shopex.cn/flist.php',
  65. // 'm4.tar.bz2' => 'http://flaboy.dev.shopex.cn/m4-1.4.11.tar.bz2'
  66. // );
  67. $this->taskinfo = $_POST;
  68. $this->ident = $ident;
  69. if(!is_dir($this->workdir)){
  70. mkdir_p($this->workdir);
  71. }
  72. file_put_contents($this->workdir.'/task.php',serialize($this->taskinfo));
  73. }
  74. function clear_unused_fold(){
  75. $path=HOME_DIR.'/tmp';
  76. if(($handle = opendir($path))){
  77. while (false !==($file = readdir($handle))){
  78. $file_name=substr($file,0,8);
  79. if(is_int($file_name) && strlen($file_name)==8){
  80. if((strtotime($file_name)+86400)<time()){
  81. remove_floder($path.'/'.$file);
  82. }
  83. }
  84. }
  85. }
  86. }
  87. function run($ident,$file_id){
  88. $this->ident = $ident;
  89. $this->workdir = HOME_DIR.'/tmp/'.$ident;
  90. $this->taskinfo = unserialize(file_get_contents($this->workdir.'/task.php'));
  91. $this->_run($file_id);
  92. }
  93. function _run($file_id){
  94. $this->system->__session_close(false);
  95. $this->cur_file_id = $file_id;
  96. $result=explode("|",$this->taskinfo['download_list'][$file_id]);
  97. $file_url = $result[0];
  98. if($this->taskinfo['key_as_name']){
  99. $file = $this->workdir.'/'.$file_id;
  100. }else{
  101. $file = $this->workdir.'/'.basename($file_url);
  102. }
  103. if(!is_dir($dir = dirname($file))){
  104. mkdir_p($dir);
  105. }
  106. touch($file);
  107. $this->file_rs = fopen($file,'rb+') or exit(__('Error: ??????:').$file);
  108. fseek($this->file_rs,0,SEEK_END);
  109. $cur_size = ftell($this->file_rs);
  110. $header = $cur_size?array('Range'=>'bytes='.$cur_size.'-'):null;
  111. set_time_limit($this->max_runtime + 3);
  112. $this->starttime = time();
  113. register_shutdown_function(array(&$this,'_next_request'));
  114. ob_start();
  115. $this->_next_request();
  116. $netcore = &$this->system->loadModel('utility/http_client');
  117. $netcore->get($file_url,$header, array(&$this,'_runner_handle'));
  118. ob_end_clean();
  119. while(key($this->taskinfo['download_list'])!=$file_id){
  120. next($this->taskinfo['download_list']);
  121. }
  122. if(next($this->taskinfo['download_list'])){
  123. $this->cur_file_id = key($this->taskinfo['download_list']);
  124. }else{
  125. $this->cur_file_id = -1;
  126. }
  127. }
  128. function _runner_handle(&$netcore , &$content){
  129. if($netcore->responseCode{0}==2){
  130. fputs($this->file_rs,$content);
  131. if(time() - $this->starttime > $this->max_runtime){
  132. ob_end_clean();
  133. exit;
  134. }
  135. return true;
  136. }else{
  137. ob_end_clean();
  138. $this->cur_file_id = -1;
  139. $this->_finish = true;
  140. echo $content;
  141. exit;
  142. }
  143. }
  144. function _next_request(){
  145. if(!$this->_finish){
  146. $base_url=$this->system->base_url();
  147. $link="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?ctl=service/download&act=run&p[0]={$this->ident}&p[1]={$this->cur_file_id}";
  148. if($this->cur_file_id!==-1){
  149. echo "<script>download('".$link."');</script>";
  150. }else{
  151. $_GET['download'] = $this->ident;
  152. $this->do_install_online();
  153. }
  154. }
  155. }
  156. function do_install_online(){
  157. $task = HOME_DIR.'/tmp/'.$_GET['download'];
  158. $temp_mess = file_get_contents($task.'/task.php');
  159. $down_data = unserialize($temp_mess);
  160. if($url = $down_data['download_list'][0]){
  161. $filename = substr($url,strrpos($url,"/")+1);
  162. $file_path = $task.'/'.$filename;
  163. $dir_name = substr($filename,0,strrpos($filename,"."));
  164. if(file_exists($file_path)){
  165. $appmgr = $this->system->loadModel("system/appmgr");
  166. $appmgr->instal_ol_app($file_path,$dir_name,$msg,true);
  167. $this->install_app($dir_name);
  168. }
  169. }
  170. }
  171. function install_app($ident){
  172. $appmgr = $this->system->loadModel('system/appmgr');
  173. $refesh = &$this->system->loadModel('system/addons');
  174. if($appmgr->install($ident,'1')){
  175. }else{
  176. $this->end(false,'????');
  177. }
  178. }
  179. function singlepage($view){
  180. $this->pagedata['_PAGE_'] = $view;
  181. $this->pagedata['statusId'] = $this->system->getConf('shopex.wss.enable');
  182. $this->pagedata['session_id'] = $this->system->sess_id;
  183. $this->pagedata['shopadmin_dir'] = dirname($_SERVER['PHP_SELF']).'/';
  184. $this->pagedata['shop_base'] = $this->system->base_url();
  185. $output = $this->fetch('singlepage.html');
  186. $re = '/<script([^>]*)>(.*?)<\/script>/is';
  187. $this->__scripts = '';
  188. /* $sre = array(
  189. '/\/\*.*?\*\//s',
  190. '/\/\/.*$/'
  191. );
  192. $this->__scripts = preg_replace($sre,'',$this->__scripts);*/
  193. echo preg_replace_callback($re,array(&$this,'_singlepage_prepare'),$output)
  194. ,'<script type="text/plain" id="__eval_scripts__" >',$this->__scripts,'</script></body></html>';
  195. }
  196. function &fetch($file, $display = false){
  197. if(defined('CUSTOM_CORE_DIR')){
  198. if($pos = strpos($file,'#')){
  199. }else{
  200. $pos=strlen($file);
  201. }
  202. if(!file_exists(CUSTOM_CORE_DIR.'/'.__ADMIN__.'/view/'.substr($file,0,$pos))){
  203. $this->template_dir = CORE_DIR.'/admin/view/';
  204. }else{
  205. $this->template_dir = CUSTOM_CORE_DIR.'/admin/view/';
  206. }
  207. }
  208. $content = $this->pfetch($file);
  209. if($this->_update_areas){
  210. foreach($this->_update_areas as $k=>$area){
  211. $content.='<!-----'.$k.'-----'.$area.'-----'.$k.'----->';
  212. }
  213. $this->_update_areas = array();
  214. }
  215. $this->system->apply_modifiers($content,'admin');
  216. if($display){
  217. echo $content;
  218. }else{
  219. return $content;
  220. }
  221. }
  222. function &pfetch($file, $display = false){
  223. $this->_files = array($file);
  224. $output = &$this->_fetch_compile($this->_get_resource($file));
  225. array_shift($this->_files);
  226. if ($display){
  227. echo $output;
  228. }else{
  229. return $output;
  230. }
  231. }
  232. function &_fetch_compile($file){
  233. $this->_current_file = $file;
  234. $name = md5((($this->_resource_type == 1) ? $this->template_dir.$file : $this->_resource_type . "_" . $file).$this->lang.$this->__ident);
  235. if($this->force_compile || !$this->__run_compiled($name,$this->_resource_time,$output)){
  236. $file_contents = '';
  237. if($this->_resource_type == 1 || $this->_resource_type == "file"){
  238. if(file_exists($this->template_dir.$file)){
  239. $file_contents = file_get_contents($this->template_dir.$file);
  240. }
  241. }else{
  242. call_user_func_array($this->_plugins['resource'][$this->_resource_type][0],array($file, &$file_contents, &$this));
  243. }
  244. if(file_exists($file)){
  245. $file_contents = file_get_contents($file);
  246. }
  247. $this->_file = $file;
  248. if (!is_object($this->_compile_obj)){
  249. $this->_compile_obj = &$this->system->loadModel('system/tramsy');
  250. $this->_compile_obj->_parent = &$this;
  251. $this->_compile_obj->enable_strip_whitespace = &$this->enable_strip_whitespace;
  252. }
  253. $this->_compile_obj->_require_stack = array();
  254. $this->_compile_obj->_plugins = &$this->_plugins;
  255. $this->_compile_obj->left_delimiter = &$this->left_delimiter;
  256. $this->_compile_obj->right_delimiter = &$this->right_delimiter;
  257. $output = &$this->_compile_obj->_compile_file($file_contents,false);
  258. $this->_compile_obj->post_compile($output);
  259. $this->_set_compile($name,$output);
  260. ob_start();
  261. eval(' ?>' . $output);
  262. $output = ob_get_contents();
  263. ob_end_clean();
  264. }
  265. if(count($this->_plugins['outputfilter'])>0){
  266. foreach($this->_plugins['outputfilter'] as $filter_func){
  267. $output = $filter_func($output);
  268. }
  269. }
  270. return $output;
  271. }
  272. function _get_resource($file){
  273. $this->__ident='';
  274. $_resource_name = explode(':', trim($file));
  275. if($this->default_resource_type!='file' && count($_resource_name) == 1){
  276. $this->_resource_type = $this->default_resource_type;
  277. $exists = isset($this->_plugins['resource'][$this->_resource_type]) && call_user_func_array($this->_plugins['resource'][$this->_resource_type][1], array($file, &$resource_timestamp, &$this));
  278. if (!$exists){
  279. return false;
  280. $this->trigger_error("file '$file' does not exist", E_USER_ERROR);
  281. }
  282. $this->_resource_time = $resource_timestamp;
  283. }elseif (count($_resource_name) == 1 || $_resource_name[0] == "file"){
  284. if($_resource_name[0] == "file"){
  285. $file = substr($file, 5);
  286. }
  287. if($p = strpos($file,'#')){
  288. $this->__ident = substr($file,$p);
  289. $file = substr($file,0,$p);
  290. }
  291. $exists = $this->template_exists($file);
  292. if (!$exists){
  293. return false;
  294. $this->trigger_error("file '$file' does not exist", E_USER_ERROR);
  295. }
  296. }else{
  297. $this->_resource_type = $_resource_name[0];
  298. $file = substr($file, strlen($this->_resource_type) + 1);
  299. $exists = isset($this->_plugins['resource'][$this->_resource_type]) && call_user_func_array($this->_plugins['resource'][$this->_resource_type][1], array($file, &$resource_timestamp, &$this));
  300. if (!$exists){
  301. if(file_exists($file)){
  302. return $file;
  303. }
  304. return false;
  305. $this->trigger_error("file '$file' does not exist", E_USER_ERROR);
  306. }
  307. $this->_resource_time = $resource_timestamp;
  308. }
  309. return $file;
  310. }
  311. function __run_compiled($key,$resource_time,&$output){
  312. $file = $this->compile_dir.$key.'.php';
  313. if(file_exists($file) && !(filemtime($file) < max($resource_time,$this->versionTimeStamp))){
  314. ob_start();
  315. include($file);
  316. $output = ob_get_contents();
  317. ob_end_clean();
  318. return true;
  319. }else{
  320. return false;
  321. }
  322. }
  323. function _set_compile($key,&$content){
  324. return file_put_contents($this->compile_dir.$key.'.php',$content);
  325. }
  326. }
  327. ?>