function visitPost(Post $p) { $text = $p->getText(); $title = $p->getTitle(); $author = $p->getAuthor(); $time = $p->getTime(); $tags = $this->tagsToString($p->getTags()); echo '<post>'; echo '<title>' . utf8_encode($title) . '</title>'; echo '<author>' . utf8_encode($author) . '</author>'; echo '<time>' . utf8_encode(date("H:i:s - d/m/Y", $time)) . '</time>'; echo '<tags>' . utf8_encode($tags) . '</tags>'; echo '<text>' . utf8_encode($text) . '</text>'; echo '</post>'; }
function visitPost(Post $p) { $text = $p->getText(); $title = $p->getTitle(); $author = $p->getAuthor(); $time = $p->getTime(); $id = $p->getID(); echo '<item>'; echo '<guid isPermaLink="false">' . utf8_encode("ABBOV_ID_" . $id) . '</guid>'; echo '<title>' . utf8_encode($title) . '</title>'; echo '<description>' . utf8_encode($text) . '</description>'; echo '<pubDate>' . date("D, d M Y G:i:s O", $time) . '</pubDate>'; echo '<dc:creator>' . $author . '</dc:creator>'; echo '</item>'; }
function visitPost(Post $p) { $text = $p->getText(); $title = $p->getTitle(); $author = $p->getAuthor(); $time = $p->getTime(); $tags = $this->tagsToString($p->getTags()); echo '<div id="post">'; echo '<b>' . $title . "</b><br>"; echo $author . ' @ ' . date("H:i:s - d/m/Y", $time) . '<br>'; echo 'Tags: ' . $tags . '<br><br>'; echo $text; echo "<br><br>"; echo '</div>'; }
function visitPost(Post $p) { $text = $p->getText(); $title = $p->getTitle(); $author = $p->getAuthor(); $time = $p->getTime(); $tags = $this->tagsToString($p->getTags()); $id = $p->getID(); echo '<div class="post">'; echo '<b>' . $title . "</b><br>"; echo $author . ' @ ' . date("H:i:s - d/m/Y", $time) . '<br>'; echo 'Tags: ' . $tags . '<br><br>'; echo $text; echo "<br><br>"; echo '<a href="deletepost.php?id=' . $id . '">Delete post</a>'; echo "<br><br>"; echo '</div>'; }
/** * Save post object and populate it with id * * @param Post $post * @return Post */ public function save(Post $post) { $id = $this->persistence->persist(array('author' => $post->getAuthor(), 'created' => $post->getCreated(), 'text' => $post->getText(), 'title' => $post->getTitle())); $post->setId($id); return $post; }
$ijson[] = ["url" => $i->getUrl(), "alt" => $i->getFileName()]; } } $j = ["post_id" => $p->getID(), "liked" => false, "tapped_into" => false, "likes_count" => 0, "comments_count" => 0, "taps_count" => 0, "text" => $p->getText(), "time" => $p->getTime(), "category" => $p->getCategory()->getName(), "user" => $user, "images" => $ijson, "comments" => []]; echo json_encode($j); } else { echo json_encode(["status" => false]); } }); $app->get('/posts', function () use($app) { $posts = App::getPosts(["limit" => 25, "user_id" => 13]); echo json_encode(Utility::formatActivitiesToPosts($posts, $app)); }); $app->delete('/posts/:id', function ($id) use($app) { $p = new Post($id); if ($p->getID() && $app->environment()['testify.user_id'] == $p->getAuthor()->getID()) { $p->delete(); if ($p) { echo json_encode(['status' => true]); } } }); $app->post('/posts/:id/favorites', function ($id) use($app) { if ($uid = $app->environment['testify.user_id']) { $post = new Post($id); if ($post) { $u = new User($uid); $u->favoritePost($post, true); echo json_encode(array("favorites" => $post->countFavorites(), "status" => true)); } }
function addPost(Post $p) { $query = "INSERT INTO `" . $this->_database . "`.`Posts` "; $query .= "(`ID`, `Title`, `Text`, `Author`, `Time`, `Tags`) "; $query .= "VALUES (NULL, '" . $p->getTitle() . "', "; $query .= "'" . $p->getText() . "', "; $query .= "'" . $p->getAuthor() . "', "; $query .= "'" . $p->getTime() . "', "; $query .= "'" . serialize($p->getTags()) . "');"; $added = mysql_query($query, $this->_connection); }
/** * Saves a Post into the database * * @param Post $post The post to be saved * @throws PDOException if a database error occurs * @return void */ public function save(Post $post) { $stmt = $this->db->prepare("INSERT INTO posts(title, content, author) values (?,?,?)"); $stmt->execute(array($post->getTitle(), $post->getContent(), $post->getAuthor()->getUsername())); }