All pastes #781396 Raw Edit

Someone

public text v1 · immutable
·published 2007-11-18 21:10 UTC
rendered paste body
<?php
class App{
	public function __construct(){
		include 'home.php';
	}
}
class Posts{
	var $file = 'posts.txt';
	public function __construct(){
	}
	
	public function makePost($sub,$date,$author,$content){
		if(is_writable($this->file)){
			if (!$handle = fopen($this->file, 'a')){
				echo "Cannot open file ($this->file)";
				exit;
			}
			$post = $sub.':'.$date.':'.$author.':'.$content."\n";
			if (fwrite($handle, $post) === FALSE){
				echo "Cannot write to file ($this->file)";
				exit;
			}
			fclose($handle);
			return true;
		} else {
			echo "File ($this->file) was not writable";
			return false;
		}
	}
	public function getPosts($num){
		$handle = fopen($this->file, 'r');
		$posts = array();
		if($handle){
			for($i = 0; ($i <= ($num - 1)) && !feof($handle); $i++){
				if($ipost = fgets($handle)){
					$info = explode(':',$ipost);
					$posts[$i]['sub'] = $info[0];
					$posts[$i]['date'] = $info[1];
					$posts[$i]['author'] = $info[2];
					$posts[$i]['content'] = $info[3];
				}
			}
		}
		return $posts;
	}
}
?>