static function showEditPostForm($post, $data = null, $error = null) { $user = Session::getUser(); if ($user->getID() != $post->getAuthor()) { return; } if (!Page::canUserDo($user)) { return; } //TODO redirect verso pagina di errore. if (is_null($error) && count($_POST) > 0) { $data = array(); if (isset($_POST["title"]) && trim($_POST["title"]) != "") { $data["title"] = $_POST["title"]; } else { $error = array("Inserire un titolo."); } if (isset($_POST["type"])) { $data["type"] = $_POST["type"]; } else { $error[] = "Scegliere il tipo di post da pubblicare."; } if (isset($_POST["content"]) && trim($_POST["content"]) != "") { $data["content"] = $_POST["content"]; } else { $error[] = "Inserire un contenuto."; } if (isset($_POST["cat"]) && is_array($_POST["cat"]) && count($_POST["cat"]) > 0) { $cat = ""; $first = true; foreach ($_POST["cat"] as $k => $c) { if ($first) { $first = false; } else { $cat .= ", "; } $cat .= $c; } $data["categories"] = $cat; } if (isset($_POST["place"]) && trim($_POST["place"]) != "") { $data["place"] = $_POST["place"]; } if (isset($_POST["headline"]) && trim($_POST["headline"]) != "") { $data["headline"] = $_POST["headline"]; } if (isset($_POST["subtitle"]) && trim($_POST["subtitle"]) != "") { $data["subtitle"] = $_POST["subtitle"]; } if (isset($_POST["tags"]) && trim($_POST["tags"]) != "") { $data["tags"] = $_POST["tags"]; } if (is_null($error) || is_array($error) && count($error) == 0) { $data["author"] = $user->getID(); $post = PostManager::createPost($data); if ($post !== false) { echo ' <div class="message"> Notizia salvata: <a href="' . FileManager::appendToRootPath($post->getPermalink()) . '">Visualizza</a> </div>'; } } else { self::showNewPostForm($data, $error); return; } } //echo serialize(isset($_GET["type"])) . "<br/>"; //DEBUG if (isset($_GET["type"])) { switch ($_GET["type"]) { case "Collection": case "PhotoReportage": case "VideoReportage": case "Album": case "Magazine": case "Playlist": call_user_func(array("PostPage", "showEdit" . $_GET["type"] . "Form"), $data, $error); break; case "news": default: self::showEditNewsForm($data, $error); } } else { self::showEditNewsForm($data, $error); } }