Exemple #1
0
 static function createMail($data)
 {
     require_once "common.php";
     $data = Filter::filterArray($data);
     $mail = new Mail($data);
     return $mail->save();
 }
 /**
  * Modifica un post "collezione".
  * 
  * @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)
  * tags: array di oggetti Tag
  * categories: array di oggetti Category
  * content: array di id di Post "semplici".
  * visibile: indica la visibilità dell'articolo se non visibile è da considerare come una bozza (boolean)
  *
  * @return: la collection modificata.
  */
 static function editCollection($collection, $data)
 {
     require_once "common.php";
     $data = Filter::filterArray($data);
     if (isset($data["title"])) {
         $collection->setTitle($data["title"]);
     }
     if (isset($data["subtitle"])) {
         $collection->setSubtitle($data["subtitle"]);
     }
     if (isset($data["headline"])) {
         $collection->setHeadline($data["headline"]);
     }
     if (isset($data["tags"])) {
         $collection->setTags($data["tags"]);
     }
     if (isset($data["categories"])) {
         $collection->setCategories($data["categories"]);
     }
     if (isset($data["content"])) {
         $collection->setContent($data["content"]);
     }
     if (isset($data["visible"])) {
         $collection->setVisible($data["visible"]);
     }
     $collection->update();
     return $collection;
 }
Exemple #3
0
 static function editContest($contest, $data)
 {
     require_once "common.php";
     $data = Filter::filterArray($data);
     if (isset($data["title"])) {
         $contest->setTitle($data["title"]);
     }
     if (isset($data["description"])) {
         $contest->setDescription($data["description"]);
     }
     if (isset($data["rules"])) {
         $contest->setRules($data["rules"]);
     }
     if (isset($data["prizes"])) {
         $contest->setPrizes($data["prizes"]);
     }
     if (isset($data["start"])) {
         $contest->setStart($data["start"]);
     }
     if (isset($data["end"])) {
         $contest->setEnd($data["end"]);
     }
     $contest->update();
     return $contest;
 }
Exemple #4
0
 static function editContest($contest, $data)
 {
     $data = Filter::filterArray($data);
     $contest->edit($data);
     $contestdao = new ContestDao();
     return $contestdao->update($contest, Session::getUser());
 }
Exemple #5
0
 /**
  * Modifica un post "semplice".
  * 
  * @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)
  * tags: array di oggetti Tag
  * categories: array di oggetti Category
  * content: il testo di un articolo (filtrato), l'indirizzo del videoreportage o l'elenco di indirizzi di foto di un fotoreportage
  * visibile: indica la visibilità dell'articolo se non visibile è da considerare come una bozza (boolean)
  *
  * @return: l'articolo modificato.
  */
 static function editPost($post, $data)
 {
     require_once "common.php";
     if (isset($data["ID"])) {
         unset($data["ID"]);
     }
     $data = Filter::filterArray($data);
     if (isset($data["title"])) {
         $post->setTitle($data["title"]);
     }
     if (isset($data["subtitle"])) {
         $post->setSubtitle($data["subtitle"]);
     }
     if (isset($data["headline"])) {
         $post->setHeadline($data["headline"]);
     }
     if (isset($data["tags"])) {
         $post->setTags($data["tags"]);
     }
     if (isset($data["categories"])) {
         $post->setCategories($data["categories"]);
     }
     if (isset($data["content"])) {
         $post->setContent($data["content"]);
     }
     if (isset($data["visible"])) {
         $post->setVisible($data["visible"]);
     }
     $post->update();
     return $post;
 }
Exemple #6
0
 /**
  * Modifica un post "semplice".
  * 
  * @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)
  * tags: array di oggetti Tag
  * categories: array di oggetti Category
  * content: il testo di un articolo (filtrato), l'indirizzo del videoreportage o l'elenco di indirizzi di foto di un fotoreportage
  * visibile: indica la visibilità dell'articolo se non visibile è da considerare come una bozza (boolean)
  *
  * @return: l'articolo modificato.
  */
 static function editPost($post, $data)
 {
     if (isset($data["ID"])) {
         unset($data["ID"]);
     }
     $data = Filter::filterArray($data);
     $p->edit($data);
     $postdao = new PostDao();
     $post = $postdao->update($p, Session::getUser());
     return $post;
 }
 /**
  * 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.");
 }
Exemple #8
0
    static function showEditProfileForm($user, $error = null)
    {
        if ($error == null && count($_POST) > 0) {
            /* information already insered  */
            $data = array();
            $error = array();
            if (isset($_POST["avatar"]) && $_POST["avatar"] != "") {
                $data["avatar"] = $_POST["avatar"];
            }
            if (isset($_POST["nickname"]) && $_POST["nickname"] != "") {
                $data["nickname"] = $_POST["nickname"];
            } else {
                $error[] = "non c'è il nickname";
            }
            if (isset($_POST["current_password"]) && $_POST["current_password"] != "") {
                if ($user->getPassword() == Filter::encodePassword($_POST["current_password"])) {
                    if (isset($_POST["check_password"]) && $_POST["check_password"] != "" && isset($_POST["new_password"]) && $_POST["new_password"] != "") {
                        if ($_POST["new_password"] == $_POST["check_password"]) {
                            $data["password"] = $_POST["new_password"];
                        } else {
                            $error[] = "le password non corrispondono";
                        }
                    }
                } else {
                    $error[] = "password non corretta";
                }
            } else {
                $error[] = "E' necessaria la password per modificare i tuoi dati";
            }
            if (isset($_POST["name"]) && $_POST["name"] != "") {
                $data["name"] = $_POST["name"];
            }
            if (isset($_POST["surname"]) && $_POST["surname"] != "") {
                $data["surname"] = $_POST["surname"];
            }
            if (isset($_POST["email"]) && $_POST["email"] != "") {
                $data["email"] = $_POST["email"];
            } else {
                $error[] = "non c'è l'email";
            }
            if (isset($_POST["gender"])) {
                if ($_POST["gender"] == "male") {
                    $data["gender"] = "m";
                } else {
                    $data["gender"] = "f";
                }
            }
            if (isset($_POST["job"]) && $_POST["job"] != "") {
                $data["job"] = $_POST["job"];
            }
            if (isset($_POST["birthday_year"]) && $_POST["birthday_year"] != "" && isset($_POST["birthday_month"]) && $_POST["birthday_month"] != "" && isset($_POST["birthday_day"]) && $_POST["birthday_day"] != "") {
                $birthday_timestamp = mktime(0, 0, 0, $_POST["birthday_month"], $_POST["birthday_day"], $_POST["birthday_year"]);
                $data["birthday"] = $birthday_timestamp;
            } else {
                $error[] = "inserisci una data completa di giorno, mese e anno";
            }
            if (isset($_POST["birthplace"]) && $_POST["birthplace"] != "") {
                $data["birthplace"] = $_POST["birthplace"];
            }
            if (isset($_POST["livingPlace"]) && $_POST["livingPlace"] != "") {
                $data["livingPlace"] = $_POST["livingPlace"];
            }
            if (isset($_POST["hobbies"]) && $_POST["hobbies"] != "") {
                $data["hobbies"] = $_POST["hobbies"];
            }
            /* show error message or apply changes and show the profile page updated*/
            if (count($error) > 0) {
                self::showEditProfileForm($user, $error);
                return;
            } else {
                $dataFiltered = Filter::filterArray($data);
                UserManager::editUser($user, $dataFiltered);
                self::showProfile($user);
            }
        } else {
            /*show form with user's information
            	 POST_data == true  -> user insered information in the form with error, the form will be reloaded with these information
            	 POST_data == false -> first time user view the page, the form will be loaded with db information */
            $POST_data = count($_POST) > 0;
            ?>
<form name="editProfile" action="" method="post">
		<?php 
            if ($error != null) {
                ?>
			<div class="error">
			<?php 
                foreach ($error as $err) {
                    ?>
			<p><?php 
                    echo $err;
                    ?>
</p>
			<?php 
                }
                ?>
</div>
		<?php 
            }
            ?>
<div class="userProfile" id="<?php 
            echo $user->getID();
            ?>
">
Avatar: <input type="text" name="avatar" value="<?php 
            if (!$POST_data) {
                echo Filter::decodeFilteredText($user->getAvatar());
            } else {
                echo $_POST["avatar"];
            }
            ?>
" /> <br>
Nickname*: <input type="text" name="nickname" value="<?php 
            if (!$POST_data) {
                echo Filter::decodeFilteredText($user->getNickname());
            } else {
                echo $_POST["nickname"];
            }
            ?>
" /> <br>
Current Password*: <input type="password" name="current_password" value="" /> <br>
New Password: <input type="password" name="new_password" value="" /> <br>
Check Password: <input type="password" name="check_password" value="" />
<br>
Name: <input type="text" name="name" value="<?php 
            if (!$POST_data) {
                echo Filter::decodeFilteredText($user->getName());
            } else {
                echo $_POST["name"];
            }
            ?>
" /> <br>
Surname: <input type="text" name="surname" value="<?php 
            if (!$POST_data) {
                echo Filter::decodeFilteredText($user->getSurname());
            } else {
                echo $_POST["surname"];
            }
            ?>
" /> <br>
email: <input type="text" name="email" value="<?php 
            if (!$POST_data) {
                echo Filter::decodeFilteredText($user->getEMail());
            } else {
                echo $_POST["email"];
            }
            ?>
" /> <br>
Gender: <label for="male">Male</label><input type="radio" name="gender" value="male" <?php 
            if ($user->getGender() == "m") {
                echo 'checked="checked"';
            }
            ?>
 />
		<label for="female">Female</label>
		<input type="radio" name="gender" value="female" <?php 
            if ($user->getGender() == "f") {
                echo 'checked="checked"';
            }
            ?>
 /><br>
Job: <input type="text" name="job" value="<?php 
            if (!$POST_data) {
                echo Filter::decodeFilteredText($user->getJob());
            } else {
                echo $_POST["job"];
            }
            ?>
" /> <br>
<p>Birthday: <br><?php 
            if ($POST_data == false) {
                $birthday_year = date('Y', $user->getBirthday());
                $birthday_month = date('m', $user->getBirthday());
                $birthday_day = date('d', $user->getBirthday());
            } else {
                $birthday_year = $_POST["birthday_year"];
                $birthday_month = $_POST["birthday_month"];
                $birthday_day = $_POST["birthday_day"];
            }
            ?>
Year: <input type="text" name="birthday_year" value="<?php 
            echo $birthday_year;
            ?>
" /><br>
Month: <input type="text" name="birthday_month" value="<?php 
            echo $birthday_month;
            ?>
" /><br>
Day: <input type="text" name="birthday_day" value="<?php 
            echo $birthday_day;
            ?>
" /><br></p>
Birthplace: <input type="text" name="birthplace" value="<?php 
            if (!$POST_data) {
                echo Filter::decodeFilteredText($user->getBirthplace());
            } else {
                echo $_POST["birthplace"];
            }
            ?>
" />
<br>
<!-- TODO: geolocate -->
Living Place: <input type="text" name="livingPlace" value="<?php 
            if (!$POST_data) {
                echo Filter::decodeFilteredText($user->getLivingPlace());
            } else {
                echo $_POST["livingPlace"];
            }
            ?>
" /> <br>
<br>
<!-- TODO: geolocate-->
<?php 
            if (!$POST_data) {
                $hobbies = $user->getHobbies();
            } else {
                $hobbies = $_POST["hobbies"];
            }
            ?>
 Hobbies: <br><textarea cols="50" rows="4" name="hobbies"><?php 
            echo $hobbies;
            ?>
</textarea><br>
<input type="submit" value="Edit"></div>
</form>
<?php 
        }
    }
Exemple #9
0
 function testDeleteMailFromDirectory()
 {
     require_once "common.php";
     $data = Filter::filterArray($this->mail_data);
     $mail = MailManager::createMail($data);
     //echo "<hr style='height:3px;background-color:blue;' />";
     $dir = MailManager::loadDirectoryFromName(MAILBOX, $this->author_id);
     //echo "<hr style='height:3px;background-color:blue;' />";
     $oldmailboxcount = count($dir->getMails());
     $dir2 = MailManager::loadDirectoryFromName(TRASH, $dir->getOwner());
     $oldtrashcount = count($dir2->getMails());
     //echo "<p>" . $mail . "<br />" . $dir . "</p>"; //DEBUG
     if ($mail == null || $mail === false) {
         return "<br />Mail test NOT PASSED: not created";
     }
     MailManager::moveToTrash($mail, $dir);
     $dir = MailManager::loadDirectoryFromName(MAILBOX, $this->author_id);
     $mail2 = MailManager::loadMail($mail->getID());
     $dir2 = MailManager::loadDirectoryFromName(TRASH, $dir->getOwner());
     if ($mail === false) {
         return "<br />Mail test NOT PASSED: deleted";
     }
     //echo "<p>" . $dir . "<br />" . $dir2 . "</p>"; //DEBUG
     if ($mail != $mail2) {
         return "<br />Mail test NOT PASSED: mail duplicated";
     }
     if (count($dir->getMails()) == $oldmailboxcount) {
         return "<br />Mail test NOT PASSED: mailbox not updated";
     }
     if (count($dir2->getMails()) == $oldtrashcount) {
         return "<br />Mail test NOT PASSED: trash not updated";
     }
     return "<br />Mail deleting test passed";
 }
Exemple #10
0
 /**
  * Tests creating, saving, editing, Contact objects.
  */
 function testContacts()
 {
     $u = UserManager::loadUserByNickname($this->user_data[NICKNAME]);
     if ($u === false) {
         $u = UserManager::loadUserByNickname($this->user_data2[NICKNAME]);
     }
     if ($u === false) {
         $u = UserManager::createUser($this->user_data);
     }
     $data = $this->contact_data;
     $data[USER] = $u->getID();
     $utente = UserManager::addContactToUser($data, $u);
     //echo "<p>" . $u . "</p>"; //DEBUG
     $data = Filter::filterArray($this->contact_data);
     if (count($utente->getContacts()) == 0) {
         return "Test Contact NOT PASSED: not added.";
     }
     $cs = $utente->getContacts();
     $c = $cs[0];
     if (isset($this->contact_data[NAME])) {
         if ($this->contact_data[NAME] != $c->getName()) {
             return "Test Contact NOT PASSED: contact name.";
         }
     }
     if (isset($this->contact_data[CONTACT])) {
         if ($this->contact_data[CONTACT] != $c->getContact()) {
             return "Test Contact NOT PASSED: contact.";
         }
     }
     if (isset($this->contact_data[TYPE])) {
         if ($this->contact_data[TYPE] != $c->getType()) {
             return "Test Contact NOT PASSED: contact type.";
         }
     }
     if ($utente->getID() != $c->getUser()) {
         return "Test Contact NOT PASSED: user.";
     }
     return "Test Contact passed.";
 }
Exemple #11
0
 /**
  * 过滤$_GET $_POST $_REQUEST $_COOKIE
  */
 static function request()
 {
     self::$origin_get = $_GET;
     self::$origin_post = $_POST;
     self::$origin_request = $_REQUEST;
     self::$origin_cookie = $_COOKIE;
     $_POST = Filter::filterArray($_POST);
     $_GET = Filter::filterArray($_GET);
     $_REQUEST = Filter::filterArray($_REQUEST);
     $_COOKIE = Filter::filterArray($_COOKIE);
 }
Exemple #12
0
 static function editUser($user, $data)
 {
     if (isset($data[User::PASSWORD]) && $data[User::PASSWORD] != "") {
         $data[User::PASSWORD] = Filter::encodePassword($data[User::PASSWORD]);
     }
     $data = Filter::filterArray($data);
     $user->edit($data);
     $userdao = new UserDao();
     return $userdao->update($user, $editor);
 }
Exemple #13
0
 static function editUser($user, $data, $error = null)
 {
     require_once "common.php";
     $data["password"] = Filter::encodePassword($data["password"]);
     $data = Filter::filterArray($data);
     return $user->edit($data);
 }
Exemple #14
0
 function testPermalink()
 {
     $data = Filter::filterArray($this->post_data_all);
     $p = PostManager::createPost($data);
     echo $p->getPermalink();
     echo "<br />" . $p->getFullPermalink();
 }