<?php include_once 'data/CategoryDAO.php'; include_once 'control/ArticleControls.php'; include_once 'business/Article.php'; $categoryDao = new CategoryDao(); $articleController = new ArticleControls(); $article = new Article(); $article->setName($_POST['title']); $article->setId(intval($_POST['id'])); $article->setContent($_POST['editor']); $article->setSumup($_POST['sumup_editor']); $article->setTags($_POST['tags']); $ret = $articleController->alterArticle($article); if ($ret) { header("location:../news.php?art_id=" . $_POST['id']); } else { echo "Unexpected exception"; }
/** * Delete an instance of an Article entity from the database * * @access public * @param Article $article * @return bool Return status of PDOStatement execute method */ public function delete(Article $article) { // Delete associated tag entries first while the article still exists in the database. // MyISAM does not support transactions. Considering converting tables to InnoDB? $tagDAO = ArticleTagDAO::getInstance(); $oldtags = $article->getTags(); $article->setTags(""); $tagDAO->updateTags($article); $query = "DELETE FROM " . $this->tableName . " WHERE id = ?"; //echo $query; $stmt = self::$dbh->prepare($query); $params = array($article->id); $status = $stmt->execute($params); // If failed, revert tagged entries since MyISAM does not support transactions if (!$status) { $article->setTags($oldtags); $tagDAO->updateTags($article); } return $status; }
header("Location: " . orongoURL("orongo-admin/index.php?msg=2")); exit; } } if (!empty($_POST['title'])) { $article->setTitle($_POST['title']); } if (!empty($_POST['content'])) { $article->setContent($_POST['content']); } if (!empty($_POST['tags'])) { $tags = explode(",", trim($_POST['tags'])); foreach ($tags as &$tag) { trim($tag); } $article->setTags($tags); } header("Location: " . orongoURL("orongo-admin/view.php?msg=1&obj=article&id=" . $article->getID())); exit; break; case "page": if (getUser()->getRank() < RANK_WRITER) { header("Location: " . orongoURL("orongo-admin/index.php?msg=0")); exit; } if (!isset($_POST['title']) || !isset($_POST['content'])) { header("Location: " . orongoURL("orongo-admin/edit.php?page." . $id)); exit; } try { $page = new Page($id);
public function __invoke($args) { if (count($args) < 2) { throw new OrongoScriptParseException("Arguments missing for Articles.SetTags()"); } $article = new Article($args[0]); unset($args[0]); $article->setTags($args); }
/** * Run method with main page logic * * Populate template and display form for creating a new article entry. For POST requests, * validate form data and save information to database. Available to admins only * @access public */ public function run() { $session = Session::getInstance(); $user = $session->getUser(); if (!$user || !$user->isAdmin()) { $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR); header("Location: " . BASE_URL); return; } $form_errors = array(); $form_values = array("title" => "", "content" => "", "postDate" => "", "published" => "", "tags" => ""); $articleDAO = ArticleDAO::getInstance(); $tagDAO = ArticleTagDAO::getInstance(); if (!empty($_POST)) { $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : ""; $form_values["content"] = isset($_POST["content"]) ? trim($_POST["content"]) : ""; $form_values["postDate"] = isset($_POST["postDate"]) ? trim($_POST["postDate"]) : ""; $form_values["published"] = isset($_POST["published"]) ? trim($_POST["published"]) : ""; $form_values["tags"] = isset($_POST["tags"]) ? trim($_POST["tags"]) : ""; if (empty($form_values["title"])) { $form_errors["title"] = "No title specified"; } if (empty($form_values["content"])) { $form_errors["content"] = "No content specified"; } if (empty($form_values["postDate"])) { $form_errors["postDate"] = "No post date specified"; } else { if (strtotime($_POST["postDate"]) == 0) { $form_errors["postDate"] = "An invalid post date was specified"; $form_values["postDate"] = ""; } } if ($form_values["published"] != "true" && $form_values["published"] != "false") { $form_errors["published"] = "Invalid published choice"; } if (empty($form_errors)) { $article = new Article(); $article->setTitle($form_values["title"]); $article->setContent($form_values["content"]); $article->setPostDate(strtotime($form_values["postDate"])); $article->setUpdateDate(0); $published = $form_values["published"] == "true" ? 1 : 0; $article->setPublished($published); $article->setUserId($user->id); //$article->setTags ($form_values["tags"]); $sorted_tag_array = ArticleTag::tagsFromString($form_values["tags"]); $sorted_tags = implode(" ", $sorted_tag_array); $article->setTags($sorted_tags); if ($articleDAO->insert($article)) { $tagDAO->updateTags($article); $session->setMessage("Article details saved"); header("Location: edit_article.php?id={$article->id}"); return; } else { $session->setMessage("Article details could not be saved", Session::MESSAGE_ERROR); } } } $this->template->render(array("title" => "Create Article", "extra_header" => joinPath("headers", "jscal_header_tpl.php"), "main_page" => "create_article_tpl.php", "session" => $session, "form_errors" => $form_errors, "form_values" => $form_values)); }