⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upgrade.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
/*
+--------------------------------------------------------------------------
|   Auto installer v1.0
|   ========================================
|   by Stephen Yabziz
|   (c) 2005 YABSoft Services
|   http://www.yabsoft.com
|   ========================================
|   Web: http://www.yabsoft.com
|   Email: ywyhnchina@163.com
+---------------------------------------------------------------------------
|
|   > Script written by Stephen Yabziz
|   > Date started: 7th Jan 2006
+--------------------------------------------------------------------------
*/
class upgrade {
	var $config = array();
    var $vars   = array();
    var $lang   = array();
    var $_begin = '##';
    var $_end   = '##';
    var $_begin2= '!#';
    var $_end2  = '!#';
    var $step   = 0;
    var $class_hash = '9acb78c4ad37d315f572ed01ac6148b7';
    var $debug  = true;

	function upgrade( $ini='' )
    {
        if(!file_exists($ini)) exit("Fata error:Install config file $ini can not be found!");
        $this->config = parse_ini_file($ini,1);
        $info=$this->getSection('UPGRADE');
        $this->_begin  = $info['var_begin'];
        $this->_end    = $info['var_end'];
        $this->_begin2 = $info['lng_begin'];
        $this->_end2   = $info['lng_end'];
        $this->debug   = $info['debug'];

        $this->install_dir  = dirname(getcwd());//$info[install_dir];
        
        if(!is_file('lang/'.$info['lang'].'.php')) return '';
        include_once( 'lang/'.$info['lang'].'.php' );
        $this->lang    = $lang;
	}
    function setUpgradeIni( $version )
    {
        $ini = 'upgrade_data/upgrade-'.$version.'.ini';
        if(!file_exists($ini)) exit("Fata error:Upgrade config file $ini can not be found!");

        $this->config = parse_ini_file($ini,1);
        $info=$this->getSection('UPGRADE');
        $this->_begin  = $info['var_begin'];
        $this->_end    = $info['var_end'];
        $this->_begin2 = $info['lng_begin'];
        $this->_end2   = $info['lng_end'];
        $this->debug   = $info['debug'];

        $this->upgrade_version = $info['mfhs_version'];
        $this->version         = $info['new_version'];
        
        if(!is_file('lang/'.$info['lang'].'.php')) return '';
        include_once( 'lang/'.$info['lang'].'.php' );
        if(is_array($lang))
        $this->lang    = array_merge($this->lang,$lang);
	}
    /**
    * decide to extract the source file for the install or not
    */
    function checkUpgradeIni()
    {
    global $db;

        $db->setQuery("select * from setting where set_id=1");
        $db->query();
        $SET = $db->loadRow();
        if(LATEST_VERSION==$SET[mfhs_version]) return -1;
        $SET[mfhs_version] = '1.1';
        if($SET[mfhs_version])
        {
            $upgrade_ini = 'upgrade_data/upgrade-'.$SET[mfhs_version].'.ini';
            if(is_file($upgrade_ini))  return $SET[mfhs_version];
        }

        $hdir=opendir('upgrade_data');
        while($file=readdir($hdir)){
            if (($file != ".") && ($file != "..")){
               if(is_file('upgrade_data/'.$file)){
                   if(substr(strtolower(strrchr($file,'.')),1)=='ini')
                   {
                   $config = parse_ini_file('upgrade_data/'.$file,1);
                   $upgrade_inis[$config[UPGRADE][mfhs_version]] = 'upgrade_data/'.$file;
                   }
               }
            }
        }
        closedir($hdir);

        return $upgrade_inis;

    }
    /**
    * dectect the envoiment before the install
    */
    function detectENV()
    {
        $vars=$this->getSection('REQUIRMENT');
        foreach($vars as $var=>$val)
        {
            list($type,$num)=explode('.',$var);
            $pos=strpos($val,':');
            list($name,$okmsg,$warnmsg)=split(':',$val);
            if($type=='module')
            {
                $ok=extension_loaded($name);
            }
            elseif($type=='dir')
            {
                $ok=is_writable($this->install_dir.'/'.$name);
            }
            elseif($type=='function')
            {
                $ok=function_exists($name);
            }
            else
            {
                $ok=0;
            }
            $msg=$ok?$this->evalLang($okmsg):$this->evalLang($warnmsg);
            $this->results[$type][]=array('status'=>$ok,'name'=>($name),'descr'=>ucfirst($msg));
        }
    }
    /**
    * $result=array('status'=>$ok,'name'=>$name,'descr'=>$msg)
    */
    function addENVResult($type,$result)
    {
        if(!empty($type))$this->results[$type][]=$result;
    }
    /**
    * write config file:eval the predefined value of file content
    */
    function writeConfig()
    {
        $vars=$this->getSection('CONFIG');
        foreach($vars as $sfile => $dfile)
        {
            if(file_exists('config/'.$sfile))
            {
                $ok = 1;
                $content=$this->evalValue(file_get_contents ('config/'.$sfile));
                if(!$fp=@fopen($this->install_dir.'/'.$dfile,'wb')) $ok=0;
                if(!@fputs($fp,$content)) $ok=0;
                @fclose($fp);
                $return[$this->install_dir.'/'.$dfile]=array($ok,$content);
            }
            elseif($sfile)
            $this->debug("CONFIG File [config/$sfile] Lost");
        }
        return $return;
    }
    /**
    * form display funtion
    */
    function printFormHeader()
    {
        echo "<form action='?verison=$this->upgrade_version' method=POST><input type=hidden name=version value='$this->upgrade_version'>";
        if($this->step==3) echo "<input type=hidden name=substep value='$this->substep'>";
    }
    function printFormFooter()
    {
        switch($this->step)
        {
        case '-1' :
            $continue = "Continue";
            break;
        case '0' :
            $continue = "Begin";
            break;
        case '1' :
            $continue = "Config";
            break;
        case '2' :
            $continue = "Update DB";
            break;
        case '3' :
            $continue = "Continue";
            break;
        case '4' :
            $continue = "Finish";
            break;
        case '5' :
            $continue = "Continue";
            break;
        }
        echo "<input type=hidden name=step value='$this->step'>";
        if($this->step!=-1)
        {
            echo ($this->step==0?'':"<input type=submit name=back value='back'>");
            echo ($this->step==5?'':"<input type=submit name=".(1?'continue':'refresh')." value='$continue'>");
        }
        echo "</form>";
    }
    function buildForm()
    {
        $this->loadCustom();
        $vars=$this->getSection('SECTION');
        foreach($this->fields as $group=>$fields)
        {
            printHeader($this->evalLang($vars[$group]));
            foreach($fields as $name => $field)
            {
                $data=array('name'=>$this->evalLang($name),'descr'=>$this->evalLang($field[descr]),'value'=>!empty($this->vars[$name])&&$field[type]=='text'?$this->evalValue($this->vars[$name]):$this->evalValue($this->evalLang($field[value])),'type'=>$field[type]);
                printRow($data);
            }
            printFooter();
        }
    }
    function loadCustom()
    {
        $vars=$this->getSection('CUSTOM');
        foreach($vars as $var=>$val)
        {
            list($group,$type,$name)=explode('.',$var);
            $pos=strpos($val,':');
            if($pos===false) $pos=strlen($val);

            $this->fields[$group][$name]=array('value'=>substr($val,$pos+1),'descr'=>substr($val,0,$pos),'type'=>$type);
        }
    }
    function buildHiddenFields()
    {
        $vars=$this->getSection('CUSTOM');
        foreach($vars as $var=>$val)
        {
            list($group,$type,$name)=explode('.',$var);
            if($type=='hidden') echo "<input type=hidden name=$name value=".$this->evalLang($val).">";
        }
    }
    /**
    * assign value from user input to the var defined in ini file
    */
    function assignVars($input)
    {
        $vars=$this->getSection('CUSTOM');
        if($vars)
        foreach($vars as $var=>$val)
        {
            list($group,$type,$name)=explode('.',$var);
            $this->vars[$name]=$input[$name];
        }
        $vars=$this->getSection('MYSQL');
        if($vars)
        foreach($vars as $var=>$val)
        {
            $this->vars[$var]=$input[$var];
        }
        $this->vars=array_intersect($this->vars,$input);

        if(dirname($_SERVER[PHP_SELF])!='/')
        $guessurl=$baseWeb="http://".$_SERVER[HTTP_HOST].dirname($_SERVER[PHP_SELF]);
        else
        $guessurl=$baseWeb="http://".$_SERVER[HTTP_HOST];

        $this->addVar('scriptUrl',dirname($guessurl));
        $this->addVar('scriptDir',dirname(getcwd()));
        $this->addVar('remotesqlhost',$_SERVER[HTTP_HOST]);
        $this->addVar('scriptDomain',substr(dirname($guessurl),7));
        $this->addVar('cgiUrl',substr(dirname($guessurl),7).'/cgi-bin/');
        $this->addVar('downloadDir',dirname(getcwd()).'/data/files/');
        $this->addVar('backupDir',dirname(getcwd()).'/data/backup/');
    }
    /**
    * add single var to $this->vars
    */
    function addVar($name,$value)
    {
        if(!empty($name))$this->vars[$name]=$value;
    }
    /**
    * execute the external sql file in the directory "sql"
    */
    function execSubSQLFile($substep)
    {
        $sqlfiles=$this->getSection($substep);
        $SQL = $return = array();
        $sqlfile = $sqlfiles[sqlfile];
        if(file_exists('upgrade_data/'.$sqlfile)&&strlen($sqlfile))
        $SQL=array_merge($SQL,readSqlFile('upgrade_data/'.$sqlfile));
        elseif($sqlfile)
        $this->debug("SQL File [upgrade_data/$sqlfile] Lost");

        foreach($SQL as $query)
        {
            $return[] = $this->evalValue($query);
        }
        return $return;
    }
    /**
    * execute the custom script located in directory inc
    */
    function execINC($step,$location='start')
    {
        $incs=$this->getSection('INC');
        $file=$incs['inc.'.$step.'.'.$location];
        if(file_exists('inc/'.$file)&&strlen($file))
        require_once('inc/'.$file);
        elseif($file)
        $this->debug("INC File [inc/$file] Lost");

        return true;
        foreach($incs as $inc=>$file)
        {
            list($inc,$step,$location)=explode('.',$var);
            if(file_exists('inc/'.$file)&&strlen($file)&&$step==$install_step)
            require_once('inc/'.$file);
        }
    }
    /**
    * execute the custom script located in directory inc
    */
    function execSubINC($substep,$location='start')
    {
        $incs=$this->getSection($substep);
        $file=$incs['inc'.$location];
        if(file_exists('upgrade_data/'.$file)&&strlen($file))
        require_once('upgrade_data/'.$file);
        elseif($file)
        $this->debug("INC File [upgrade_data/$file] Lost");
    }
    function evalValue($str)
    {
        return preg_replace('/('.$this->_begin.')([a-zA-Z0-9\_]+)('.$this->_end.')/ieU','$this->vars[\\2]',$str);
    }
    function evalLang($str)
    {
        return preg_replace('/('.$this->_begin2.')([a-zA-Z0-9\_]+)('.$this->_end2.')/ieU','$this->lang[\\2]',$str);
    }
    function getSection($name)
    {
        return $this->config[$name];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -