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

📄 user.class.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 2 页
字号:

        return $server;
    }
    /**
    *get upload method:form upload,ftp upload,url upload
    */
    function checkServer()
    {
    global $db,$input;

        if(count($this->servers)==0)
        {
            $this->sendNotify(0,'fatal');
            $this->setting[site_offline] = 1;
        }
        else
        foreach($this->servers as $server)
        {
            if($server[enabled]&&$server[max_webspace]&&$server[webspace]>$server[max_webspace])
            {
                $this->sendNotify(0,'fatal');
                $SET[site_offline] = 1;
                continue;
            }
            if($row[warn_webspace]&&$row[webspace]>$row[warn_webspace])
            {
                $this->sendNotify($row[server_id],'warn');
            }
            if($server[enabled]) $this->upload_servers[$server[server_id]]=$server;
        }
        
        if(count($this->upload_servers)==0)
        {
            $this->sendNotify(0,'fatal');
            $this->setting[site_offline] = 1;
        }
    }
    
    function sendNotify($server_id=0,$type='warn')
    {
    global $db,$email;
        # load the corssponding template
        $email->template->set_filenames(array(
	         'email' => $type=='warn' ? 'server_warning.html':'server_out.html'
        ));
        # assign global vars
        $email->template->assign_vars(array(
            'SITENAME'=>$this->setting[sitename],
            'PASSWORD'=>$result[pass],
            'EMAIL_SIG'=>$user->setting[emailsign],
        ));
        # build server list
        foreach($this->servers as $row)
        {
            $email->template->assign_block_vars('servers', array(
            'name'=>$row[name],
            'server_id'=>$row[server_id],
            'domain'=>$row[domain],
            'webspace'=>convertsize($row[webspace]),
            'warn_webspace'=>convertsize($row[warn_webspace]),
            'max_webspace'=>convertsize($row[max_webspace]),
            'enabled'=>$row[enabled]==1?'Yes':'No',
            ));
            
            if($server_id == $row[server_id])
            {
                $email->template->assign_var('server_name',$row['name']);
            }
        }
        # get emails list to send
        $emails   = split(',',$this->setting[servermoniter_emails]);
        $emails[] = $this->setting[adminemail];

        # sending emails
        foreach($emails as $name)
        {
            $email->to($name,$this->setting[sitename]);
        }
        $email->from($this->setting[adminemail]);
        $email->send('email');
        
        ($hook = YABPlugin::fetch_hook('serverstatus_sent',__FILE__,__LINE__)) ? eval($hook) : '';

    }
    /**
	* check this user is baned by IP
    * @return bool
	*/
	function isBanedByIP()
    {
        global $input;
        $this->setting[banip]=str_replace('*','[0-9]{1}',$this->setting[banip]);
        $banip=split(',',$this->setting[banip]);
        foreach($banip as $ip)
        {
           $ip=trim($ip);
           if($ip=='') continue;
           $ban=preg_match("'$ip'isx",$input[IP_CLIENT]);

           if($ban) return true;
        }
        return false;
	}

    /**
	* update stats for user:uploaded files,used spaces,
	*/
	function updateStats($uid=0) {
    global $db,$input;
        $uid = intval($uid);
        if($uid==0) $uid=$this->uid;
        if($uid==0) return '';
        
        $db->setQuery("select count(f.id) as nums,sum(f.size) as webspace from files as f where f.uid ='$uid' and f.deleted=0");
        $db->query();
        $row=$db->loadRow();
        $db->setQuery("update users set
                       webspace='$row[webspace]',
                       files='$row[nums]'
                       where id='$uid' ");
        $db->query();
        
        return '';
        
        $db->setQuery("select sum(f.downloads) as downloads,count(f.id) as nums,sum(f.size) as webspace,sum(f.bandwidth) as bandwidth from files as f where f.uid ='$uid' and f.deleted=0");
        $db->query();
        $row=$db->loadRow();
        $db->setQuery("update users set last_login='".time()."',
                       webspace='$row[webspace]',
                       bandwidth='$row[bandwidth]',
                       totaldownloads='$row[downloads]',
                       files='$row[nums]'
                       where id='$uid' ");
        $db->query();
	}

    /**
	* load setting from system
    * @return bool
	*/
	function loadSetting()
    {
        global $db,$input,$match_lang,$root_dir,$DATASTORE,$CODE_TO_LANG;

        ## load site setting!
        if(!is_array($DATASTORE[setting]))
        {
            # loading setting table
            $db->setQuery("select * from setting where set_id=1");
            $db->query();
            $SET=$db->loadRow();
        
            # store data
            $DATASTORE[setting]  = $SET;
        }
        else
        {
            $SET=$DATASTORE[setting];
        }
        
        ## load all servers!
        if(!is_array($DATASTORE[servers]))
        {
            # loading server table
            $db->setQuery("SELECT * FROM server");
            $db->query();
            $this->servers=$db->loadRowList('server_id');
            # store data
            $DATASTORE[servers]  = $this->servers;
        }
        else
        {
            $this->servers=$DATASTORE[servers];
        }
       
        ## choose a skin
        $oldskin=$this->getValue('myskin');
        # request from url
        if(isset($input[setskin])&&eregi("[a-z0-9]+",$input[setskin])&&is_dir(ROOT.'/skin/'.$input[setskin]))
        {
            if($this->setValue('myskin',$input[setskin]));
            $SET['skin_dir']=$input[setskin];
        }
        # old skin is valid?
        elseif(eregi("[a-z0-9]+",$oldskin)&&is_dir(ROOT.'/skin/'.$oldskin))
        {
            $SET['skin_dir']=$oldskin;
        }
        ## choose a language
        $oldlang=$this->getValue('mylang');
        if(in_array($input[setlang],array_keys($CODE_TO_LANG))&&is_dir(ROOT.'/language/'.$CODE_TO_LANG[$input[setlang]]))
        {
            $SET[language] = $CODE_TO_LANG[$input[setlang]];
            # record the selected lang
            $this->setValue('mylang',$input[setlang]);
        }
        elseif(in_array($oldlang,array_keys($CODE_TO_LANG))&&is_dir(ROOT.'/language/'.$CODE_TO_LANG[$oldlang]))
        {
            $SET[language] = $CODE_TO_LANG[$oldlang];
        }
        
        ## choose by browser
        if($SET[language]==-1)
        {
            $SET[language] = $this->guess_lang();
            # record the selected lang
            $this->setValue('mylang',array_search($SET[language],$CODE_TO_LANG));
        }

        # if the language is not available, exit ?
        if(!file_exists(ROOT.'/language/'.$SET[language].'/lang.php'))
        {
            $SET[language]='english';
            $this->setValue('mylang','en');
        }
        $this->langcode = array_search($SET[language],$CODE_TO_LANG);
        return $SET;
	}
    function guess_lang()
	{
	global $HTTP_SERVER_VARS,$COUNTRY_CODE_TO_MATCH_LANG;

		// The order here _is_ important, at least for major_minor
		// matches. Don't go moving these around without checking with
		// me first - psoTFX

		if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']))
		{
			$accept_lang_ary = explode(',', $HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']);
			for ($i = 0; $i < sizeof($accept_lang_ary); $i++)
			{
				@reset($COUNTRY_CODE_TO_MATCH_LANG);
				while (list($lang, $match) = each($COUNTRY_CODE_TO_MATCH_LANG))
				{
					if (preg_match('#' . $match . '#i', trim($accept_lang_ary[$i])))
					{
						if (is_file('language/' . $lang . '/lang.php'))
						{
							return $lang;
						}
					}
				}
			}
		}
		return 'english';
    }
    function guess_lang2()
	{
	global $HTTP_SERVER_VARS,$match_lang;

		// The order here _is_ important, at least for major_minor
		// matches. Don't go moving these around without checking with
		// me first - psoTFX

		if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']))
		{
			$accept_lang_ary = explode(',', $HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']);
			for ($i = 0; $i < sizeof($accept_lang_ary); $i++)
			{
				@reset($match_lang);
				while (list($lang, $match) = each($match_lang))
				{
					if (preg_match('#' . $match . '#i', trim($accept_lang_ary[$i])))
					{
						if (is_file('language/' . $lang . '/lang.php'))
						{
							return $lang;
						}
					}
				}
			}
		}
		return 'english.php';
    }
    /**
	* set value for user class:cookie or session
	*/
	function setValue($name,$value)
    {
        $this->$name = $value;
        if($this->running_type=='cookie')
        {
            return setCookies($name,$value);
        }
        else
        {
            $_SESSION[$name]=$value;
        }
	}

    /**
	* get value for user class:cookie or session
	*/
	function getValue($name)
    {
        if($this->running_type=='cookie')
        return getCookies($name);
        else
        return $_SESSION[$name];
	}

    /**
	* user login method
    * @return status of user:1:active,0:unconfirmed,-1:suspended,4:not found
	*/
	function login($username,$password,$autologin=1)
    {
    global $db,$input;

       $db->setQuery("select * from users where user='".$db->getEscaped($username)."' and pass='".$db->getEscaped($password)."'");
       $db->query();
       if($db->getNumRows()==1)
       {
           $row=$db->loadRow();
           if($row[status]==1)
           {
               $this->setValue('logined',1);
               $this->setValue('uid',$row[id]);
               $this->setValue('passhash',md5($password));
               $this->setValue('last_click',time());
               $this->setValue('autologin',$autologin);
           }
           return $row[status];
       }
       else
       {
           $row=$db->loadRowList();
           return 4;
       }
	}
    /**
	* user login method
    * @return status of user:1:active,0:unconfirmed,-1:suspended,4:not found
	*/
	function logout()
    {
    global $db,$input;

         $this->setValue('logined',0);
         $this->setValue('uid',0);
         $this->setValue('passhash','');
         $this->setValue('last_click',time());
         $this->setValue('autologin',0);
	}
    /**
    *check this user with such email available
    */
    function checkAvailable($username,$useremail)
    {
    global $db;
        if($username==''||$useremail=='') return false;
        $db->setQuery("select * from users where user='$username' or email='$useremail'");
        $db->query();
        if($db->getNumRows())
        return false;
        else
        return true;
    }

    /**
    *check password for this user
    */
    function getPassword($username,$useremail)
    {
    global $db;
       if(!empty($username))
       $db->setQuery("select * from users where user='$username'");
       elseif(!empty($useremail))
       $db->setQuery("select * from users where email='$useremail'");
       else return -1;
       $db->query();
       if($db->getNumRows()==0)
       return -1;
       $row=$db->loadRow();
       return $row;
    }
}
?>

⌨️ 快捷键说明

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