Esempio n. 1
0
 /**
  * Aggiunge un post "collezione" al sistema.
  *
  * @param data: array associativo contenente i dati.
  * Le chiavi ricercate dal sistema per questo array sono:
  * title: titolo della collection (string filtrata)
  * subtitle: sottotitolo della collection (string filtrata)
  * headline: occhiello della collection (string filtrata)
  * author: id dell'autore (long)
  * tags: array di oggetti Tag
  * categories: array di oggetti Category
  * content: array di post "semplici"
  * visibile: indica la visibilità dell'articolo se non visibile è da considerare come una bozza (boolean)
  * @param type: tipo di collection, deve essere incluso in CollectionType
  * 
  * @return: la collection creata o FALSE se c'è un errose
  */
 static function createCollection($data)
 {
     if (isset($data["ID"])) {
         unset($data["ID"]);
     }
     $data = Filter::filterArray($data);
     if (!isset($data[Post::TYPE])) {
         throw new Exception("Il post da creare è di un tipo sconosciuto.");
     }
     $p = false;
     switch ($data[Post::TYPE]) {
         case Post::NEWS:
         case Post::VIDEOREP:
             return PostManager::createPost($data);
             break;
         case Post::COLLECTION:
             if (!$p) {
                 $p = new Collection($data);
             }
         case Post::ALBUM:
             if (!$p) {
                 $p = new Album($data);
             }
         case Post::MAGAZINE:
             if (!$p) {
                 $p = new Magazine($data);
             }
         case Post::PHOTOREP:
             if (!$p) {
                 $p = new PhotoReportage($data);
             }
             $postdao = new PostDao();
             $post = $postdao->save($p);
             return $post;
     }
     throw new Exception("Il post da creare è di un tipo sconosciuto.");
 }
Esempio n. 2
0
    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);
        }
    }
Esempio n. 3
0
 function insertFirstNews()
 {
     $p = PostManager::createPost($this->post_serious);
     echo $p->getFullPermalink();
 }