1. Go to this page and download the library: Download litemerafrukt/postcomments library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
litemerafrukt / postcomments example snippets
class PostController
/**
* Show a post
*
* @param int $postId
*/
public function showPost($id)
{
$post = $this->posts->fetch($id);
$user = $this->di->get('user');
$user->isUser = $user->isLevel(UserLevels::USER);
$user->isAdmin = $user->isLevel(UserLevels::ADMIN);
$comments = new Comments(new CommentHandler($this->di->get('olddb')));
if ($this->di->request->getPost('new-comment-submitted', false) && $user) {
$authorId = $user->id;
$authorName = $user->name;
$parentId = $this->di->request->getPost('parent-id', 0);
$text = \trim($this->di->request->getPost('comment-text'));
$comments->new($id, $parentId, $authorId, $authorName, $text);
$this->di->get("response")->redirectSelf();
} else if ($this->di->request->getPost('edit-comment-submitted', false) && $user) {
$id = $this->di->request->getPost('comment-id', null);
$text = \trim($this->di->request->getPost('comment-text', ''));
$comments->update($id, $text, function ($comment) use ($user) {
return $comment['id'] === $user->id;
});
$this->di->get("response")->redirectSelf();
}
$commentsHTML = $comments->getHtml($id, $user->isUser, $user->isAdmin, $user->name, $user->id);
$this->renderPage("posts/post", $post->subject, \compact('post', 'user', 'commentsHTML'));
}
..
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.