承接 litemerafrukt/postcomments 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

litemerafrukt/postcomments

Composer 安装命令:

composer require litemerafrukt/postcomments

包简介

litemerafrukt postcomments module.

README 文档

README

Latest Stable Version Build Status CircleCI Build Status Scrutinizer Code Quality Code Coverage

Reddit-like comments to posts.

Uses view-files recursively to achieve nested comments. There are default view files. If you want to define your own views then look at the included view files for examples. The Comments class takes a top level view file as optional parameter.

CommentsHandler class needs a simple database class with a query-method. Look at the supplied Database class for the interface if you want to build your own (which you should). The database needs to be setup with a comments table, se src/extras folder for schema. Table name can optionally be supplied to CommentsHandler constructor, defaults to r1_comments.

This module is built to fit in an Anax project but should fit in to any project with a little work. At the same time, this is not a fit all package, this is written for a specific project.

Install

PHP version > 7.0.

$ composer require litemerafrukt/postcomments

Setup your database with a table for the commments, see vendor/litemerafrukt/postcomments/src/extras.

Use database class with namespace litemerafrukt\Database or supply your own class with a query-metod, see vendor/litemerafrukt/postcomments/src/Database/Database.php for interface.

Usage

Set up your forum post controller to handle both get and post requests. The postcomments module will supply the view with html for the comments.

Example from an Anax project.

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'));
    }

    ..

License

This software carries a MIT license.

 .
..:  Copyright (c) 2017 Anders Nygren (litemerafrukt@gmail.com)

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固