PHP Classes

File: blog.class.php

Recommend this page to a friend!
  Classes of Jonathan Alexey   Blog Criptkiller   blog.class.php   Download  
File: blog.class.php
Role: Class source
Content type: text/plain
Description: A classe to generated a blog class
Class: Blog Criptkiller
Create blog posts stored in text files
Author: By
Last change: added getProps methods to get propreties from line post
added Blog(), __construct() and init() to give compatibilite for PHP4 and PHP5
bugfixed time save now in numeric and not in date format , to give some extra flexibilite.
remove some methods.
more fast and ease to use.
Date: 12 years ago
Size: 2,763 bytes
 

Contents

Class file image Download
<?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");
            }
        }
    }

}
?>