/**
  * Build a collection manager with collections
  * loaded from config array.
  *
  * Config array structure:
  * .Array
  * (
  *   [collection_name_1] => Array
  *        (
  *            [attribute_1] => 'value'
  *        )
  *
  *   [collection_name_2] => Array
  *        (
  *        )
  * )
  *
  * @param array $config Configuration array with data about collections.
  *
  * @return \Yosymfony\Spress\Core\ContentManager\Collection\CollectionManager
  */
 public function buildFromConfigArray(array $config)
 {
     $cm = new CollectionManager();
     foreach ($config as $collectionName => $attributes) {
         $path = $collectionName;
         if (is_array($attributes) === false) {
             throw new \RuntimeException(sprintf('Expected array at the collection: "%s".', $collectionName));
         }
         $cm->addCollection(new Collection($collectionName, $path, $attributes));
     }
     return $cm;
 }
Exemple #2
0
 /**
  * Aggiunge un post "semplice" al sistema.
  *
  * @param data: array associativo contenente i dati.
  * Le chiavi ricercate dal sistema per questo array sono:
  * title: titolo del post (string filtrata)
  * subtitle: sottotitolo del post (string filtrata)
  * headline: occhiello del post (string filtrata)
  * author: id dell'autore (long)
  * tags: array di oggetti Tag
  * categories: array di oggetti Category
  * content: il testo di un articolo (string filtrata), l'indirizzo del videoreportage o l'elenco di indirizzi delle foto di un fotoreportage
  * visibile: indica la visibilità dell'articolo se non visibile è da considerare come una bozza (boolean)
  * @param type: tipo di post, deve essere incluso in PostType
  * 
  * @return: l'articolo creato.
  */
 static function createPost($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:
             $p = new News($data);
         case Post::VIDEOREP:
             if (!$p) {
                 $p = new VideoReportage($data);
             }
             $postdao = new PostDao();
             $post = $postdao->save($p);
             return $post;
         case Post::COLLECTION:
         case Post::ALBUM:
         case Post::MAGAZINE:
         case Post::PHOTOREP:
             return CollectionManager::createCollection($data);
     }
     throw new Exception("Il post da creare è di un tipo sconosciuto.");
 }
 /**
  * Build a collection manager with collections
  * loaded from config array.
  *
  * Config array structure:
  * .Array
  * (
  *   [collection_name_1] => Array
  *        (
  *            [attribute_1] => 'value'
  *        )
  *
  *   [collection_name_2] => Array
  *        (
  *        )
  * )
  *
  * @param array $config Configuration array with data about collections.
  *
  * @return \Yosymfony\Spress\Core\ContentManager\Collection\CollectionManager
  */
 public function buildFromConfigArray(array $config)
 {
     $cm = new CollectionManager();
     $collectionItemCollection = $cm->getCollectionItemCollection();
     foreach ($config as $collectionName => $attributes) {
         $path = $collectionName;
         if (is_array($attributes) === false) {
             throw new \RuntimeException(sprintf('Expected array at the collection: "%s".', $collectionName));
         }
         if ($collectionItemCollection->has($collectionName) === true) {
             throw new \RuntimeException(sprintf('A previous collection exists with the same name: "%s".', $collectionName));
         }
         $collectionItemCollection->set($collectionName, new Collection($collectionName, $path, $attributes));
     }
     return $cm;
 }
Exemple #4
0
 static function createUser($data, $error = null)
 {
     $data["password"] = Filter::encodePassword($data["passowrd"]);
     $data = Filter::filterArray($data);
     $user = new User($data);
     $u = $user->save();
     //echo "<p>" . $user . "</p>"; //DEBUG
     if ($u !== false) {
         //invia una mail per permettere all'utente di convalidare la sua casella.
         $code = self::generateValidationCode($u);
         mail($u->getMail(), "Iscrizione a IoEsisto", self::generateValidationMailMessage($code));
         //genera una collection di preferiti
         require_once 'post/collection/CollectionManager.php';
         $data = array("title" => "Preferiti", "author" => $u->getID(), "categories" => "favourites", "visible" => false);
         CollectionManager::createCollection($data);
         //genera tre directory email: mailbox, cestino e spam
         require_once "mail/MailManager.php";
         MailManager::createDirectory(MAILBOX, $u->getID());
         MailManager::createDirectory(TRASH, $u->getID());
         MailManager::createDirectory(SPAM, $u->getID());
     }
     return $user;
 }
Exemple #5
0
    static function showNewPostForm($data = null, $error = null)
    {
        $user = Session::getUser();
        require_once 'manager/AuthorizationManager.php';
        if (!isset($_GET["type"])) {
            $_GET["type"] = Post::NEWS;
        }
        if (!AuthorizationManager::canUserDo(AuthorizationManager::CREATE, $_GET["type"])) {
            return;
        }
        //TODO redirect verso pagina di errore.
        $logger = Logger::getLogger();
        $logger->debug("ResourceDao", $_GET["type"]);
        if (isset($_GET["phase"]) && $_GET["phase"] == 3) {
            if ($_GET["type"] == "photoreportage" && isset($_POST["numResources"])) {
                $data = array();
                for ($i = 0; $i < $_POST["numResources"]; $i++) {
                    $resourceID = $_POST["resourceID" . $i];
                    if (isset($_POST[$resourceID]) && $_POST[$resourceID] != '') {
                        //$_POST[$resourceID] is the description
                        $data['description'] = $_POST[$resourceID];
                        $rsUpdated = ResourceManager::editResource($resourceID, $data);
                    }
                }
                Page::redirect("Edit");
            }
        } else {
            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 ($data["type"] == "news") {
                    //carico il testo del post
                    if (isset($_POST["content"]) && trim($_POST["content"]) != "") {
                        $data["content"] = $_POST["content"];
                    } else {
                        $error[] = "Inserire un contenuto.";
                    }
                    //check if ther's not valid files
                    $notvalid = 0;
                    if (trim($_FILES["upfile"]["name"]) != "") {
                        if ($_FILES["upfile"]["type"] == "image/gif" || $_FILES["upfile"]["type"] == "image/jpeg" || $_FILES["upfile"]["type"] == "image/png") {
                        } else {
                            $notvalid++;
                        }
                    }
                    if ($notvalid == 0) {
                        if (trim($_FILES["upfile"]["name"]) != "") {
                            if ($_FILES["upfile"]["type"] == "image/gif" || $_FILES["upfile"]["type"] == "image/jpeg" || $_FILES["upfile"]["type"] == "image/png") {
                                $fname = ResourceManager::editFileName($_FILES["upfile"]["name"]);
                                $newsPhoto = ResourceManager::uploadPhoto($fname, $user->getNickname(), $user->getID(), $_FILES["upfile"]["tmp_name"], $_FILES["upfile"]["type"]);
                                //prelevo l'id della risorsa appena salvata
                                $data["photo"] = $newsPhoto->getID();
                            }
                        }
                    } else {
                        $error[] = "Devi inserire un formato valido: .jpeg .jpg .gif oppure .png";
                    }
                } else {
                    if ($data["type"] == "photoreportage") {
                        $photo = array();
                        //check if ther's not valid files
                        for ($i = 0, $notvalid = 0; $i < 10; $i++) {
                            if (trim($_FILES["upfile{$i}"]["name"]) != "") {
                                if ($_FILES["upfile{$i}"]["type"] == "image/gif" || $_FILES["upfile{$i}"]["type"] == "image/jpeg" || $_FILES["upfile{$i}"]["type"] == "image/png") {
                                } else {
                                    $notvalid++;
                                }
                            }
                        }
                        if ($notvalid == 0) {
                            for ($i = 0, $numphoto = 0; $i < 10; $i++) {
                                if (trim($_FILES["upfile{$i}"]["name"]) != "") {
                                    if ($_FILES["upfile{$i}"]["type"] == "image/gif" || $_FILES["upfile{$i}"]["type"] == "image/jpeg" || $_FILES["upfile{$i}"]["type"] == "image/png") {
                                        $fname = ResourceManager::editFileName($_FILES["upfile{$i}"]["name"]);
                                        $photo[] = ResourceManager::uploadPhoto($fname, $user->getNickname(), $user->getID(), $_FILES["upfile{$i}"]["tmp_name"], $_FILES["upfile{$i}"]["type"]);
                                        $numphoto++;
                                    }
                                }
                            }
                            if ($numphoto > 0) {
                                $data["content"] = $photo;
                            } else {
                                $error[] = "Devi inserire almeno un'immagine";
                            }
                        } else {
                            $error[] = "Devi inserire un formato valido: .jpeg .jpg .gif oppure .png";
                        }
                    } else {
                        if ($data["type"] == "videoreportage") {
                            if (isset($_POST["userUrl"]) && $_POST["userUrl"] != '') {
                                $rs = ResourceManager::createResource($user->getID(), youtubeManager::getVideoID($_POST["userUrl"]), 'video');
                                $data['content'] = youtubeManager::getVideoID($_POST["userUrl"]);
                            }
                        }
                    }
                }
                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();
                    //se photoreportage creo una collection
                    if ($data["type"] == "news") {
                        $post = PostManager::createPost($data);
                        //se vi è una foto aggiorno la tabella PostResource
                        if (isset($data['photo']) && $data['photo'] != "") {
                            PostManager::setPostResource($post->getID(), $data['photo']);
                        }
                    } else {
                        if ($data["type"] == "videoreportage") {
                            $post = PostManager::createPost($data);
                        } else {
                            if ($data["type"] == "photoreportage" && $_GET["phase"] == 2) {
                                //save only the resource ID not the whole object
                                foreach ($data["content"] as &$resource) {
                                    $resource = $resource->getID();
                                }
                                $post = CollectionManager::createCollection($data);
                            } else {
                                $post = false;
                            }
                        }
                    }
                    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
        switch ($_GET["type"]) {
            case Post::COLLECTION:
            case Post::PHOTOREP:
            case Post::VIDEOREP:
            case Post::ALBUM:
            case Post::MAGAZINE:
            case Post::PLAYLIST:
                call_user_func(array("PostPage", "showNew" . $_GET["type"] . "Form"), $data, $error);
                break;
            case "videoreportage3":
                break;
            case Post::NEWS:
            default:
                self::showNewNewsForm($data, $error);
        }
    }
Exemple #6
0
    static function showNewPostForm($data = null, $error = null)
    {
        $user = Session::getUser();
        //TODO controlla sessione
        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"];
                /*DEBUG*/
                echo $data["type"];
            } else {
                $error[] = "Scegliere il tipo di post da pubblicare.";
            }
            if ($data["type"] == "news") {
                if (isset($_POST["content"]) && trim($_POST["content"]) != "") {
                    $data["content"] = $_POST["content"];
                } else {
                    $error[] = "Inserire un contenuto.";
                }
            } else {
                if ($data["type"] == "photoreportage") {
                    /*DEBUG*/
                    echo "</br>caricamento immagini</br>";
                    $photo = array();
                    for ($i = 0, $numphoto = 0, $notvalid = 0; $i < 10; $i++) {
                        if (trim($_FILES["upfile{$i}"]["name"]) != "") {
                            if ($_FILES["upfile{$i}"]["type"] == "image/gif" || $_FILES["upfile{$i}"]["type"] == "image/jpeg" || $_FILES["upfile{$i}"]["type"] == "image/png") {
                                $photo[] = resourceManager::uploadPhoto(trim($_FILES["upfile{$i}"]["name"]), $user->getNickname(), $_FILES["upfile{$i}"]["tmp_name"], $_FILES["upfile{$i}"]["type"]);
                                $numphoto++;
                                /*DEBUG*/
                                echo "caricata immagine upfile" . $i . "</br> numphoto: " . $numphoto;
                            } else {
                                $notvalid++;
                            }
                        }
                    }
                    //se ha caricato file in formato non valido do errore
                    if ($notvalid != 0) {
                        $error[] = "Devi inserire un formato valido: .jpeg .jpg .gif oppure .png";
                    }
                    //se non sono state caricate foto do errore
                    if ($numphoto > 0) {
                        $data["content"] = $photo;
                    } else {
                        $error[] = "Devi inserire almeno un'immagine";
                    }
                    /*DEBUG*/
                    echo "</br>FINE caricamento immagini</br> immagini caricate: " . count($photo);
                } else {
                    if ($data["type"] == "videoreportage") {
                        /*DEBUG*/
                        echo "</br>caricamento video</br>";
                    }
                }
            }
            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"];
            }
            /*DEBUG*/
            echo "</br>controllo errori";
            if (is_null($error) || is_array($error) && count($error) == 0) {
                /*DEBUG*/
                echo "</br>NO errori";
                $data["author"] = $user->getID();
                //se photoreportage creo una collection
                if ($data["type"] == "news" || $data["type"] == "videoreportage") {
                    /*DEBUG*/
                    echo "</br>PostManager::createPost " . $data["type"] . "</br></br>";
                    $post = PostManager::createPost($data);
                } else {
                    if ($data["type"] == "photoreportage") {
                        /*DEBUG*/
                        echo "</br>CollectionManager::createCollection " . $data["type"] . "</br>";
                        $post = CollectionManager::createCollection($data);
                    }
                }
                /*DEBUG*/
                var_dump($post);
                if ($post !== false) {
                    echo '
			<div class="message">
				Notizia salvata: <a href="' . $post->getFullPermalink() . '">Visualizza</a>
			</div>';
                }
            } else {
                /*DEBUG*/
                echo "</br>SI errori</br>";
                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", "showNew" . $_GET["type"] . "Form"), $data, $error);
                    break;
                case "News":
                default:
                    self::showNewNewsForm($data, $error);
            }
        } else {
            self::showNewNewsForm($data, $error);
        }
    }
Exemple #7
0
 /**
  * Crea un post;
  * Crea una collezione con il post nel contenuto;
  * Associa alla collezione un voto (lo crea);
  * Carica il voto dal database e lo confronta con quello salvato in memoria;
  */
 function testSaveVoteOnCollection()
 {
     require_once "post/PostManager.php";
     $data = $this->post_data_all;
     $p = PostManager::createPost($data);
     $data1 = $this->collection_data_all;
     $p2 = CollectionManager::addCollection($data1);
     $p1 = CollectionManager::voteCollection($this->author_id, $p2, $this->vote_value);
     if (count($p1->getVotes()) == 0) {
         return "<br />Vote saving test NOT PASSED: not added";
     }
     $votes = $p1->getVotes();
     $vote = PostManager::loadVote($votes[0]->getAuthor(), $votes[0]->getPost());
     $post = CollectionManager::loadCollection($p1->getId());
     if (count($post->getVotes()) == 0) {
         return "<br />Vote saving test NOT PASSED: not added";
     }
     //echo $votes[0] . "<br />" . $vote; //DEBUG
     //echo "<br />" . $p1 . "<br />" . $post; //DEBUG
     if ($vote === false) {
         return "<br />Vote saving test NOT PASSED: not created";
     }
     if ($votes[0]->getAuthor() != $vote->getAuthor()) {
         return "<br />Vote saving test NOT PASSED: author";
     }
     if ($votes[0]->getVote() != $vote->getVote()) {
         return "<br />Vote saving test NOT PASSED: comment";
     }
     if ($votes[0]->getPost() != $vote->getPost()) {
         return "<br />Vote saving test NOT PASSED: post";
     }
     if ($votes[0]->getCreationDate() != $vote->getCreationDate()) {
         return "<br />Vote saving test NOT PASSED: creationDate";
     }
     return "<br />Vote saving test passed";
 }