Saltar al contenido
Underc0de /foro

Simple PHP Blog Script v2

🌐 Esta é uma tradução automática de um tópico do Underc0de, a maior comunidade de hacking e TI em espanhol. Ler o original (espanhol) e responder →
fleshworm ·
Saudações, bem, comento que ando um pouco distraído, já que estou começando os estudos, então tenho passado um pouco mais afastado do PC e mais inclinado à leitura e a alguns manuais. Desta vez compartilho com vocês um Script em PHP para um app de Blog composto por um Index, Config e nosso objeto ou classe Blog.class, o qual vocês são livres para implementar, redistribuir ou questionar. Ele conta com um sistema NO-SQL ou MonoDB como camada de abstração de dados (DAL) sob as diferentes configurações de codificação, desta vez UTF-8 (ANSI ou UNICODE), para armazenar os posts ou publicações, além de ser implementado com Bootstrap como padrão de design.<br /><br />Filename (index.php)<br />
Código: php
<br /><?php<br />/*** Mini Blog Script v2 By Nickhere Under Creative Commons Atribution 4 ***/<br />error_reporting(E_ALL);<br />date_default_timezone_set("America/Los_Angeles");<br />header("Content-type: text/html; charset=UTF-8;");<br /><br />include("config.php");<br /><br />$blog = new miniblog();<br /><br />$blog->display_posts($postspath);<br /><br />if(isset($_POST["submit_entry"])){<br /> $blog->saveposts($postspath, true);<br />}<br /><br />$blog->saveposts($postspath, 0);<br /><br /><br />?><br />
<br /><br />Filename (config.php)<br />
Código: php
<br /><?php<br />/*** Mini Blog Script v2 By Nickhere Under Creative Commons Atribution 4 ***/<br /><br />include("blog.class.php"); //Include our blog class object for further reference<br /><br />$postspath = "posts_path_here/"; //Desired posts directory with trailing slash(/)<br /><br />?><br />
<br /><br />Filename (blog.class.php)<br />
Código: php
<br /><?php<br />/*** Mini Blog Script v2 By Nickhere Under Creative Commons Atribution 4 ***/<br /> <br />class miniblog{<br /> <br /> public $username;<br /> public $email;<br /> public $title;<br /> public $message;<br /> public $date;<br /> public $post;<br /> <br /> public function __construct(){<br />  $this->username = (!empty($_POST["username"]))? $_POST["username"]: "Anonimo";<br />  $this->email = (!empty($_POST["contact"]))? $_POST["contact"]: "mail@domain";<br />  $this->title = (!empty($_POST["title"]))? $_POST["title"]: "Post title fillin";<br />  $this->message = (!empty($_POST["message"]))? $_POST["message"]: "Lipsum post fillin dummy text";<br />  $this->date = date("M d,Y h:i a");<br /> }<br /> <br /> public function saveposts($path, $attr){<br />  $this->post = $path.date("Ymdhis")."-".rand(00, 99).".data";<br />  if($attr === true){<br />   $handle = fopen($this->post, "a") ;<br />   fwrite($handle, $this->username."\n".$this->email."\n".$this->title."\n".$this->message."\n".$this->date);<br />   fclose($handle);<br />   echo("Your post has been successfully stored, Please wait while we redirect you to your entry");<br />   header("Refresh: 6; url=index.php");<br />  }elseif(isset($path) && $attr === 0){<br />   $form = "<form method=\"post\" action=\"\" id=\"post_form\">";<br />   $form .= "Username<br/><input type=\"text\" name=\"username\" value=\"\" /><br/>";<br />   $form .= "Email<br/><input type=\"text\" name=\"contact\" value=\"\" /><br/>";<br />   $form .= "Title<br/><input type=\"text\" name=\"title\" value=\"\" /><br/>";<br />   $form .= "Message<br/><textarea cols=\"45\" rows=\"6\" name=\"message\"></textarea><br/>";<br />   $form .= "<input type=\"submit\" name=\"submit_entry\" value=\"Submit\" /></form>";<br />   echo($form);<br />  }<br /> }<br /> <br /> public function display_posts($path){<br />  if(is_dir($path) && ($dir = opendir($path))){<br />   while(false != ($data = readdir($dir))){<br />    if($data != "." && $data != ".."){<br />     $posts[] = $data;<br />     foreach($posts as $element){<br />      $post = file($path.$element);<br />      echo("By ".$post[0]." Email ".$post[1]." Date ".$post[4]."<br/><h3>".$post[2]."</h3><p>".$post[3]."</p>");<br />      unset($post);<br />     }<br />    }<br />   }<br />   closedir($dir);<br />  }<br /> }<br /> <br />}<br /> <br />?><br />
<br /><br />Para finalizar, vocês precisam criar o diretório onde seus posts serão armazenados (ie. post_path_here/). Comento que a versão publicada está implementada para PHP 5+ e ela inclui utilitários como índice de recursos da próxima publicação. Boa sorte
DuendeSlayeR ·
Muito bom, obrigado.<br /><br /><br />Saudações
Grupo de WhatsApp