Underc0de

Programación Web => Back-end => Mensaje iniciado por: fleshworm en Julio 08, 2016, 05:47:46 AM

Título: Simple PHP Blog Script v2
Publicado por: fleshworm en Julio 08, 2016, 05:47:46 AM
Saludos, bueno les comento algo distraido ya que comienzo estudios pues la he pasado algo mas separado del Pc y mas inclinado en la lectura y algunos manuales. En esta ocasion les comparto un Script en PHP para un Blog app compuesto por un Index, Config y nuestro objeto o clase Blog.class el cual son libres de implementar, redistribuir u objetar. El mismo cuenta con un systema NO-SQL o MonoDB como capa de abstraccion de datos (DAL) bajo las diferentes configuraciones de codificacion en esta ocacion UTF-8 (ANSI o UNICODE) para almacenar los posts o publicaciones ademas de ser implementado bajo Boostrap como patron de diseño.

Filename (index.php)
Código (php) [Seleccionar]

<?php
/*** Mini Blog Script v2 By Nickhere Under Creative Commons Atribution 4 ***/
error_reporting(E_ALL);
date_default_timezone_set("America/Los_Angeles");
header("Content-type: text/html; charset=UTF-8;");

include(
"config.php");

$blog = new miniblog();

$blog->display_posts($postspath);

if(isset(
$_POST["submit_entry"])){
 
$blog->saveposts($postspathtrue);
}

$blog->saveposts($postspath0);


?>



Filename (config.php)
Código (php) [Seleccionar]

<?php
/*** Mini Blog Script v2 By Nickhere Under Creative Commons Atribution 4 ***/

include("blog.class.php"); //Include our blog class object for further reference

$postspath "posts_path_here/"//Desired posts directory with trailing slash(/)

?>



Filename (blog.class.php)
Código (php) [Seleccionar]

<?php
/*** Mini Blog Script v2 By Nickhere Under Creative Commons Atribution 4 ***/
 
class miniblog{
 
 public 
$username;
 public 
$email;
 public 
$title;
 public 
$message;
 public 
$date;
 public 
$post;
 
 public function 
__construct(){
  
$this->username = (!empty($_POST["username"]))? $_POST["username"]: "Anonimo";
  
$this->email = (!empty($_POST["contact"]))? $_POST["contact"]: "mail@domain";
  
$this->title = (!empty($_POST["title"]))? $_POST["title"]: "Post title fillin";
  
$this->message = (!empty($_POST["message"]))? $_POST["message"]: "Lipsum post fillin dummy text";
  
$this->date date("M d,Y h:i a");
 }
 
 public function 
saveposts($path$attr){
  
$this->post $path.date("Ymdhis")."-".rand(0099).".data";
  if(
$attr === true){
   
$handle fopen($this->post"a") ;
   
fwrite($handle$this->username."\n".$this->email."\n".$this->title."\n".$this->message."\n".$this->date);
   
fclose($handle);
   echo(
"Your post has been successfully stored, Please wait while we redirect you to your entry");
   
header("Refresh: 6; url=index.php");
  }elseif(isset(
$path) && $attr === 0){
   
$form "<form method=\"post\" action=\"\" id=\"post_form\">";
   
$form .= "Username<br/><input type=\"text\" name=\"username\" value=\"\" /><br/>";
   
$form .= "Email<br/><input type=\"text\" name=\"contact\" value=\"\" /><br/>";
   
$form .= "Title<br/><input type=\"text\" name=\"title\" value=\"\" /><br/>";
   
$form .= "Message<br/><textarea cols=\"45\" rows=\"6\" name=\"message\"></textarea><br/>";
   
$form .= "<input type=\"submit\" name=\"submit_entry\" value=\"Submit\" /></form>";
   echo(
$form);
  }
 }
 
 public function 
display_posts($path){
  if(
is_dir($path) && ($dir opendir($path))){
   while(
false != ($data readdir($dir))){
    if(
$data != "." && $data != ".."){
     
$posts[] = $data;
     foreach(
$posts as $element){
      
$post file($path.$element);
      echo(
"By ".$post[0]." Email ".$post[1]." Date ".$post[4]."<br/><h3>".$post[2]."</h3><p>".$post[3]."</p>");
      unset(
$post);
     }
    }
   }
   
closedir($dir);
  }
 }
 
}
 
?>



Para culminar necesitan crear el directorio donde estaran almacenados sus posts (ie. post_path_here/), comento la version publicada esta implementada bajo PHP 5+ y la misma conforma utilidades como indice de recursos de la publicacion siguiente. Suerte
Título: Re:Simple PHP Blog Script v2
Publicado por: DuendeSlayeR en Febrero 22, 2018, 03:44:27 AM
Muy bueno, gracias.


Saludos