| 
<?php 
/*
 * Portugal | PT-pt
 *
 * Direitos reservados a Jonathan Fontes
 * Por favor não utilize codigo sem fazer publicidade dele ;)
 *
 * All right reserver to Jonathan Fontes
 * www.jonathanfontes.com
 * 2010/2011
 */
 class Blog {
 
 protected $nome;
 var $file = false;
 var $handle = false;
 var $versao = '1.3';
 
 function Blog($file) {
 $this->init($file);
 }
 
 function __construct($file){
 $this->init($file);
 }
 
 
 function init ( $file ){
 $this->handle = fopen($file, 'a+');
 $this->file = file($file);
 $this->nome = $file;
 }
 
 function nova_entrada($titulo, $conteudo) {
 $data = strtotime(date('j-m-Y h:i:s'));
 $escreve =   $titulo . '|' . $this->xss_protection($conteudo) . '|' . $data  . "\n";
 fputs($this->handle, $escreve);
 return true;
 }
 
 function ler_entrada($inicio=null, $limite=null) {//return array com/sem limites de linhas = sql limit inicio e fim
 $this->blog($this->nome);//Para refrescar no caso de houver uma entrada depois de ler o ficheiro
 if ($inicio != null && $limite != null) {
 if ($inicio <= $limite && $limite <= $this->numero_entradas()) {
 $f_contents =$this->file;
 $sua_linha = array();
 for ($n = $inicio; $n <= $limite; $n++) {
 $sua_linha[] = $f_contents[$n];
 }
 return $sua_linha;
 } else {
 throw new Exception("Inicio ({$inicio}) < Limite ({$limite}) &&  Limite < numero de entrada ({$this->numero_entradas()})");
 }
 } else {
 return $this->file;//Começa sempre do 0!
 }
 }
 
 function getProps ( $props , $data ){
 $data = explode("|",$data);
 
 switch ($props) {
 case 'titulo':
 return $data[1];
 break;
 case 'corpo':
 return $data[2];
 break;
 case 'data':
 return $data[3];
 break;
 }
 
 
 }
 
 function numero_entradas() {
 return count($this->file) - 1;
 }
 
 function ler_linha($linha) {
 
 $explode_1 = explode('**', $linha);
 for ($n = 0; $n <= $this->numero_entradas(); $n++) {
 $explode = explode('|', $explode_1[$n]);
 if (count($explode) > 0 && count($explode) == 4) {
 $array = array('tipo' => $explode[0], 'titulo'=>$explode[1] ,'conteudo' => $explode[2], 'data' => $explode[3]);
 return $array;
 } else {
 throw new Exception("Ocorreu um erro ao ler uma linha do seu blog");
 }
 }
 }
 
 }
 ?>
 
 |