Exemplo n.º 1
0
 public static function createEdit($article, $user)
 {
     $edit = new ArticleEdit();
     $edit->article = $article->id;
     $edit->user = $user->id;
     $edit->title = $article->title;
     $edit->text = $article->text;
     $edit->timestamp = Database::now();
     $edit->save();
     return $edit;
 }
Exemplo n.º 2
0
if (!$article) {
    CommonUtil::redirect("admin/contentmanager");
    exit(0);
}
// set info
$article->title = $_POST["title"];
$article->description = $_POST["description"];
$article->text = $_POST["text"];
$article->category = $_POST["category"];
$article->accessLevel = $_POST["accessLevel"];
$article->unlisted = false;
$article->updateDate = Database::now();
// save article
$article->save();
// save history
ArticleEdit::createEdit($article, Session::getUser());
if ($_POST["externalAttachment"]) {
    $url = $_POST["externalAttachment"];
    $parsedUrl = parse_url($url);
    // make sure it's a youtube link.
    if ($parsedUrl["host"] == "www.youtube.com" || $parsedUrl["host"] == "youtube.com") {
        parse_str($parsedUrl["query"], $query);
        if (isset($query["v"])) {
            $attachment = new ArticleAttachment();
            $attachment->data = $query["v"];
            $attachment->article = $article->id;
            $attachment->type = ArticleAttachment::TYPE_VIDEO;
            $attachment->save();
        }
    }
}
<?php

require_once '../config/dbconf.php';
require_once '../model/articles.php';
session_start();
$errors = array();
$updateOk = true;
$errormessage = '';
$isFormGood = true;
$new = new ArticleDisp();
$disp = $new->articleEditDisplay($pdo);
if (isset($_POST['title'])) {
    $new = new ArticleEdit();
    if (empty($_POST["title"]) || strlen($_POST['title']) < 10) {
        $errormessage = "Please put a title or your title is under 10 characters";
        $isFormGood = false;
    }
    if (empty($_POST["content"]) || strlen($_POST['content']) < 100) {
        $errormessage = 'Your article is under 100 characters';
        $isFormGood = false;
    }
    if (empty($_POST["shortContent"]) || strlen($_POST['shortContent']) < 30) {
        $errormessage = 'Your description is under 30 characters';
        $isFormGood = false;
    }
    if (!$isFormGood) {
        http_response_code(400);
        echo json_encode(array('success' => false, "errors" => $errormessage));
    } else {
        $new->updateArticle($pdo);
        echo json_encode(array('success' => true, "user" => $_POST));