示例#1
0
            }
        } else {
            foreach ($categorias as $categoria) {
                $arr = array("idCategoria" => $categoria, "idPost" => $_POST['id']);
                PostController::insertPostCategoria($arr);
            }
        }
        if ($res) {
            header("Location: blog-posts");
            exit;
        } else {
            die("ERRO");
        }
    }
} elseif ($_POST['action'] == "del") {
    if (PostController::delete($_POST)) {
        die("OK");
    } else {
        die("ERRO");
    }
} elseif ($_POST['action'] == "listaAvaliacoes") {
    $html = "";
    $i = 0;
    $soma = 0;
    foreach (AvaliacaoController::getAllByPost($_POST['idPost'], "a.DataCriacao DESC") as $avaliacao) {
        if (!empty($avaliacao->Id)) {
            $i++;
            $soma += $avaliacao->Nota;
            $html .= "\t<tr>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t" . DefaultHelper::converterData($avaliacao->DataCriacao) . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t" . $avaliacao->IP . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<div class='nota rateit' data-rateit-min='0' data-rateit-max='5' data-rateit-readonly='true' data-rateit-value='" . $avaliacao->Nota . "'></div>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t<a href='#' class='btn btn-danger del-avaliacao' onclick='delAvaliacao(" . $avaliacao->Id . ");'><i class='fa fa-fw fa-close'></i></button>\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>";
        }
    }
示例#2
0
    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']));
}