<?php /** * @author Harri Bell-Thomas <*****@*****.**> * @created January, 2014 * @version 1.0.0 * @license Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) * @license url : http://creativecommons.org/licenses/by-sa/3.0/ */ /* INCLUDE WRAPPER */ require_once 'class.postcontroller.php'; /* USAGE */ $Poster = new PostController(); $Poster->set_title("My Post's Title"); $Poster->add_category(array(1, 2, 8)); $Poster->set_type("post"); $Poster->set_content("This my awesome content"); $Poster->set_author_id(1); $Poster->set_post_slug('updated_post'); //$Poster->set_page_template( "login-infusion-page.php" ); $Poster->set_post_state("publish"); $Poster->search('title', 'Old Post'); $Poster->update(); //$Poster->create(); //$Poster->PrettyPrintAll(); $Poster->get_var('slug');
$categorias = array(); if (count($_POST["categorias"]) > 0) { $categorias = explode(",", $_POST["categorias"]); } foreach ($categorias as $categoria) { $arr = array("idCategoria" => $categoria, "idPost" => $res); PostController::insertPostCategoria($arr); } if ($res) { header("Location: blog-posts"); exit; } else { die("ERRO"); } } else { $res = PostController::update($_POST); //Tags $tags = array(); if (count($_POST["tags"]) > 0) { $tags = explode(",", $_POST["tags"]); } $newTags = array(); if (count($_POST["newTags"]) > 0 && !empty($_POST["newTags"])) { $newTags = explode(",", $_POST["newTags"]); } if (!empty($newTags) && count($newTags) > 0) { foreach ($newTags as $newTag) { $arr = array("nome" => $newTag, "seo" => ""); $tags[] = TagController::insert($arr); } }
return strip_tags($title); } // Format content accordingly function format_content($content) { // Convert all \n into <br/> for proper content display return str_replace("\n", '<br />', $content); } $post_controller = new PostController($db); // Initialize Post Controller // HTTP Requests if (isset($_POST['add'])) { // Publish a post $post_controller->publish($_SESSION['userid'], format_title($_POST['title']), format_content($_POST['content'])); } if (isset($_GET['delete'])) { // Delete a post $post = $post_controller->search_by_id($_GET['id']); // Ensure that only authors can delete their own posts if ($_SESSION['userid'] == $post['author_id']) { // Authorized $post_controller->delete($post['id']); } else { // Not Authorized header('Location: index.php'); } } if (isset($_POST['update'])) { // Update an existing post $post_controller->update($_POST['id'], format_title($_POST['title']), format_content($_POST['content'])); }