myswap / 1 / code / App / Lib / Action / EmptyAction.class.php

<?php

Class EmptyAction extends Action{ 
    public function _empty()
    {
        $this->goHome();
    }
	public function setSettings(){
		$settings=$this->getUserModel();
		$this->assign('settings',$settings);
	}
	public function getUserModel(){ 
			if (is_numeric(MODULE_NAME)){
				$User=D("User");
				$user=$User->getById(MODULE_NAME);
				return $user[0];
			}else{
				$User=D("User");
				$user=$User->getByUsername(MODULE_NAME);
				return $user[0];
			}
	}
	public function getPublicState(){
		$user=$this->getUserModel();
		return $user["public_state"];
	}
	public function getUserID(){ 
			if (is_numeric(MODULE_NAME)){
				return MODULE_NAME;
			}else{
				$user=$this->getUserModel();
				return $user["user_id"];
			}
	}

    public function swap($pass=0)
	{
		if($_GET["texarea"]=="true"){
			$Swap=M("Swap");
			$Swap->find($_GET["id"]);
			echo '<textarea cols="160"   rows="40" >'.htmlspecialchars($Swap->content).'</textarea>';
		}else if($_GET["id"]){
			$Swap=M("Swap");
			$Swap->find($_GET["id"]);
			echo $Swap->content;
		}
	}
    public function index($pass=0)
    {
		if($this->getPublicState() || $pass){
			$this->setSettings();
			$this->outputSwap($this->getUserID());
		}else{
			$this->auth();
		}
    }
    public function getFriends()
    {
		$settings=$this->getUserModel();
		$friends=preg_split("/\n/", $settings["friends"]);
		return $friends;
    }
    public function goHome()
    {
		header("Location: http://".$_SERVER["HTTP_HOST"]."/".MODULE_NAME."/");
    }
    public function outputSwap($user_id)
    {
    	$Swap=D("Swap");
    	$SWAPS=$Swap->getSwaps($user_id);

		$this->assign('friends',$this->getFriends());
		$this->assign('SWAPS',$SWAPS);
		$this->display('Public/swap');
    }
    public function setting()
	{    	
		if($this->authWithPassword($_POST["password"])){
		//成功修改资料
			$User=M("User");
			$User->find($this->getUserID()); // 查找主键为1的数据
			if($_POST["public_state"]=="on"){
				$User->public_state=1;
			}else{
				$User->public_state=0;
			}
			$User->friends=trim($_POST["friends"]);
			$User->username=$_POST["username"];
			$User->save();
			$this->assign('msg_success',"saved");
		}else if($_POST["password"]){
			$this->assign('msg_error',"wrong password");
		}

		$this->setSettings();
		$this->display('Public/setting');
    }
    public function auth()
	{    	
		$this->setSettings();
		if($this->authWithPassword($_POST["password"])){
			$this->index(1);
		}else if($_POST["password"]){
			$this->assign('msg_error',"wrong password");
			$this->display('Public/auth');
		}else{
			$this->display('Public/auth');
		}
    }
    public function authWithPassword($password)
	{    	
		$settings=$this->getUserModel();
		if($password==$settings["password"]){
			return (1);
		}else{
			return (0);
		}
    }
    public function addSwap()
	{
		if($this->authWithPassword($_POST["password"])){
			$content=$_POST["content"];
			if($content){
				$Swap=D("Swap");
				$Swap->user_id=$this->getUserID();
				$Swap->content=$content;
				// echo $Swap->getLastsql();
				$Swap->add();
				// echo $Swap->getLastsql();
				$this->goHome();
			}
		}else if($_POST["password"]){
			$this->assign("msg_error","wrong password");
			$this->setSettings();
			$this->display('Public/swap');
		}
	}
}

?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.