Hướng dẫn thêm chức năng bình luận (comment) cho module NukeViet

Thứ năm - 14/10/2021 04:53
Bình luận (Comment) là chức năng không thể thiếu trong các hệ thống có chức năng thảo luận. NukeVet đã xây dựng module comment để thực hiện điều này.
Từ phiên bản NukeViet 4.0, NukeViet bổ sung module Comment làm module hệ thống, có chức năng quản lý bình luận chung cho các module. Module comment giúp việc quản lý các bình luận từ thành viên một cách tập trung, giúp việc quản lý đơn giản hơn.
1) Xóa comment ca module cũ đi nếu có
2) Thêm đon sau vào file modules\module_name\funcs\module_op.php
// commentif( isset( $site_mods['comment'] ) and isset( $module_config[$module_name]['activecomm'] ) ){  define( 'NV_COMM_ID', $id ); //ID bài viết    define( 'NV_COMM_AREA', $module_info['funcs'][$op]['func_id'] ); //để đáp ứng comment ở bất cứ đâu không cứ là bài viết     $allowed = $module_config[$module_name]['allowed_comm']; //check allow comemnt  //tuy vào module để lấy cấu hình. Nếu là module news thì có cấu hình theo bài viết       if( $allowed == '-1' )    {                $allowed = $news_contents['allowed_comm'];  }         define( 'NV_PER_PAGE_COMMENT', 5 );         //Số bản ghi hiển thị bình luận    require_once NV_ROOTDIR . '/modules/comment/comment.php';      $area = ( defined( 'NV_COMM_AREA' )) ? NV_COMM_AREA : 0;     $checkss = md5( $module_name . '-' . $area . '-' . NV_COMM_ID . '-' . $allowed . '-' . NV_CACHE_PREFIX );  //get url comment  $url_info = parse_url( $client_info['selfurl'] );   $content_comment = nv_comment_module( $module_name, $checkss, $area, NV_COMM_ID, $allowed, 1 );}else{       $content_comment = '';}
Trong đó, bạn cần lưu ý:
1. define( 'NV_COMM_ID', $id ): $id là ID của bài viết, chủ đề,... (ID xác định trang)
2. Nếu module bạn có cấu hình hiển thị comment theo “từng bài viết cụ thể” thì thêm đoạn này (Xem code mẫu bên trên) để xác định cấu hình từ bài viết. Ngược lại, bỏ đoạn này đi, thì module nhận cấu hình từ Cấu hình module comment
if( $allowed == '-1' ){   $allowed = $news_contents['allowed_comm'];}
$news_contents['allowed_comm'] là ID nhóm được phân quyền comment tại bài viết, thay bằng tham số tương ứng với module của bạn.
3) Truyn biến $content_comment sang file x lý giao din (theme.php, nếu có)
4) Ti function x lý giao din, gi hin th ni dung form bình lun.
if( !empty( $content_comment ) ){  $xtpl->assign( 'CONTENT_COMMENT', $content_comment );        $xtpl->parse( 'main.comment' );}
5) Ti file giao din (*.tpl), thêm html hin th ni dung bình lun.
<!-- BEGIN: comment -->{CONTENT_COMMENT}<!-- END: comment -->
6) Trong file action to CSDL (modules/ten-module/action_mysql.php) ca module cn thêm đon code sau để to d liu cài đặt cho module
Tìm
$sql_create_module = $sql_drop_module;
Thêm lên trên
$result = $db->query( "SHOW TABLE STATUS LIKE '" . $db_config['prefix'] . "\_" . $lang . "\_comment'" );$rows = $result->fetchAll( );if( sizeof( $rows ) ){   $sql_drop_module[] = "DELETE FROM " . $db_config['prefix'] . "_" . $lang . "_comment WHERE module='" . $module_name . "'";}
Thêm xuống cuối file
// Comments$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'auto_postcomm', '1')";$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'allowed_comm', '6')";$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'view_comm', '6')";$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'setcomm', '4')";$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'activecomm', '1')";$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'emailcomm', '0')";$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'adminscomm', '')";$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'sortcomm', '0')";$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . NV_LANG_DATA . "', '" . $module_name . "', 'captcha', '1')";
7) Nếu module bn hat động trước đó và đã có d liu, thc hin bước này để nâng cp CSDL, ngược li, b qua bước này.
Tạo file update-comment.php với nội dung bên dưới, đặt ngang hàng với file index.php
<?php/** * @Project NUKEVIET 4.x * @Author VINADES.,JSC (contact@vinades.vn) * @Copyright (C) 2015 VINADES.,JSC. All rights reserved * @License GNU/GPL version 2 or any later version * @Createdate Wed, 02 Dec 2015 08:26:04 GMT */define( 'NV_SYSTEM', true );// Xac dinh thu muc goc cua sitedefine( 'NV_ROOTDIR', pathinfo( str_replace( DIRECTORY_SEPARATOR, '/', __file__ ), PATHINFO_DIRNAME ) );require NV_ROOTDIR . '/includes/mainfile.php';require NV_ROOTDIR . '/includes/core/user_functions.php';if( defined( 'NV_IS_SPADMIN' ) ){         // Comments      $module_name = 'page';    // Sửa ứng với module     $sql_create_module = array( );       // Comments      $sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'auto_postcomm', '1')";      $sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'allowed_comm', '-1')";       $sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'view_comm', '6')"$sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'setcomm', '4')";     $sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'activecomm', '1')";        $sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'emailcomm', '0')"; $sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'adminscomm', '')"; $sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'sortcomm', '0')"; $sql_create_module[] = "INSERT INTO " . NV_CONFIG_GLOBALTABLE . " (lang, module, config_name, config_value) VALUES ('" . $lang . "', '" . $module_name . "', 'captcha', '1')";   foreach( $sql_create_module as $_sql )      {                 $db->query( $_sql );      }        die( 'Thuc hien nang cap xong, hay xoa file nay ngay' );}else{         die( 'Can thuc hien voi quyen admin toi cao' );}
Trong trường hợp bạn muốn thao tác dữ liệu trên module nhận chức năng comment (Ví dụ: Module news sau khi người dùng bình luân thì cập nhật lại số lượng bình luận ở mỗi bài viết), bạn tạo thêm một file với tên là comment.php đặt vào thư mục modules/ten-module/. Có thể tham khảo nội dung file này ở modules/news/comment.php.
 

Những tin mới hơn

Những tin cũ hơn

Tổng số điểm của bài viết là: 0 trong 0 đánh giá

Click để đánh giá bài viết
Bạn đã không sử dụng Site, Bấm vào đây để duy trì trạng thái đăng nhập. Thời gian chờ: 60 giây