Exemplo n.º 1
0
 static function createDirectory($name, $owner)
 {
     require_once "common.php";
     $name = Filter::filterText($name);
     $dir = new MailDirectory($name, $owner);
     return $dir->save();
 }
Exemplo n.º 2
0
 private static function searchPostsBy($keys, $options, $echo_query = false)
 {
     require_once "query.php";
     require_once "strings/strings.php";
     define_tables();
     definePostColumns();
     $table = Query::getDBSchema()->getTable(TABLE_POST);
     $loadComments = true;
     $wheres = array();
     foreach ($keys as $key => $value) {
         if ($key == "name" || $key == "title") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_TITLE), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "permalink") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_PERMALINK), Operator::EQUAL, intval($value));
         }
         if ($key == "id") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_ID), Operator::EQUAL, intval($value));
         }
         if ($key == "tag") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_TAGS), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "day") {
             if (!is_numeric($value)) {
                 $value = date_timestamp_get(date_create_from_format("Y-m-d", $value));
             }
             $daystart = date("Y-m-d", $value);
             $dayend = date("Y-m-d", $value + 24 * 60 * 60);
             //echo "<br />" . $daystart . "-" . $dayend; //DEBUG
             $wheres[] = new WhereConstraint($table->getColumn(POST_CREATION_DATE), Operator::GREATEROREQUAL, $daystart);
             $wheres[] = new WhereConstraint($table->getColumn(POST_CREATION_DATE), Operator::LESSER, $dayend);
         }
         if ($key == "category") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_CATEGORIES), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "title") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_TITLE), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "content") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_CONTENT), Operator::LIKE, "%" . Filter::filterText($value) . "%");
         }
         if ($key == "author") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_AUTHOR), Operator::EQUAL, intval($value));
         }
         if ($key == "no_id") {
             $wheres[] = new WhereConstraint($table->getColumn(POST_ID), Operator::NOTEQUAL, intval($value));
         }
         if ($key == "loadComments") {
             $loadComments = $value == true;
         }
     }
     $newopt = array();
     foreach ($options as $key => $value) {
         if ($key == "by") {
             if (!is_array($value)) {
                 $value = array($value);
             }
             $newvalue = array();
             foreach ($value as $column) {
                 if (!is_a($column, "Column")) {
                     $column = $table->getColumn($column);
                 }
                 if (!is_null($column)) {
                     $newvalue[] = $column;
                 }
             }
             $value = $newvalue;
         }
         $newopt[$key] = $value;
     }
     $db = new DBManager();
     $db->execute($s = Query::generateSelectStm(array($table), array(), $wheres, $newopt));
     if ($echo_query) {
         echo "<font color='red'>" . $s . "</font>";
     }
     //DEBUG
     $posts = array();
     while ($row = $db->fetch_result()) {
         require_once "post/Post.php";
         $posts[] = Post::createFromDBResult($row, $loadComments);
     }
     return $posts;
 }
Exemplo n.º 3
0
 /**
  * Aggiunge un commento al post selezionato e lo salva nel database.
  *
  * @param author: id dell'autore del commento
  * @param post: variabile di tipo Post
  * @param comment: testo del commento
  * @return post: aggiornato.
  */
 static function commentPost($post, $author, $comment)
 {
     require_once "common.php";
     $comment = Filter::filterText($comment);
     require_once "post/PostCommon.php";
     $c = new Comment(array("author" => $author, "post" => $post->getID(), "comment" => $comment));
     $c->save();
     $post->addComment($c);
     return $post;
 }
Exemplo n.º 4
0
 /**
  * Aggiunge un commento al post selezionato e lo salva nel database.
  *
  * @param author: id dell'autore del commento
  * @param post: variabile di tipo Post
  * @param comment: testo del commento
  * @return post: aggiornato.
  */
 static function commentPost($post, $author, $comment)
 {
     $comment = Filter::filterText($comment);
     require_once "dataobject/Comment.php";
     require_once "dao/CommentDao.php";
     $c = new Comment(array("author" => $author, "post" => $post->getID(), "comment" => $comment));
     $commentdao = new CommentDao();
     $comm = $commentdao->save($c);
     $post->addComment($comm);
     return $post;
 }
Exemplo n.º 5
0
 /**
  * Crea un post;
  * Crea una collezione con il post nel contenuto;
  * Carica la collezione e la confronta con quello salvato in memoria;
  */
 function testSaveCollection()
 {
     require_once "common.php";
     $data = $this->post_data_all;
     $p = PostManager::createPost($data);
     $data1 = $this->collection_data_all;
     //$data1["content"] = array($p);
     $p1 = CollectionManager::addCollection($data1);
     $post = CollectionManager::loadCollection($p1->getID());
     //echo "<p>" . $p1 . "</p><p>" . $post . "</p>"; //DEBUG
     if ($post === false) {
         return "<br />Collection saving test NOT PASSED: not created";
     }
     if ($p1->getTitle() != $post->getTitle()) {
         return "<br />Collection saving test NOT PASSED: title";
     }
     if ($p1->getSubtitle() != $post->getSubtitle()) {
         return "<br />Collection saving test NOT PASSED: subtitle";
     }
     //echo Filter::filterText($p1->getHeadline()) . "-" . Filter::filterText($post->getHeadline()); //DEBUG
     if ($p1->getHeadline() != Filter::filterText($post->getHeadline())) {
         return "<br />Collection saving test NOT PASSED: headline";
     }
     if ($p1->getAuthor() != $post->getAuthor()) {
         return "<br />Collection saving test NOT PASSED: author";
     }
     if (isset($row["tags"])) {
         if ($p1->getTags() != $row["tags"]) {
             return "<br />Post saving test NOT PASSED: tags";
         }
     }
     if (isset($row["categories"])) {
         if ($p1->getCategories() != $row["categories"]) {
             return "<br />Post saving test NOT PASSED: categories";
         }
     }
     //echo serialize($p1->getContent()) . "-" . $post->getContent(); //DEBUG
     if ($p1->getContent() != $post->getContent()) {
         return "<br />Collection saving test NOT PASSED: content";
     }
     if ($p1->isVisible() != $post->isVisible()) {
         return "<br />Collection saving test NOT PASSED: visible";
     }
     $first = false;
     if ($first) {
         return "<br />Collection saving test NOT PASSED: not created";
     }
     return "<br />Save Collection test passed";
 }