Hi, Khách!
![]() | ![]() ![]() ![]() ![]() |

[imghttp://i.imgur.com/Y1YhJ54.png?1[/img
Hôm nai mới rãnh nên hướng dẫn mod Thông Báo bằng systems mail có sẵn của johncms. Johncms gốc thì cái sys mail chỉ thông báo khi đăng kí mới.
đầu tiên các bạn vào data nhập sql
và
vào panel > index.php tại cái mảng $array thêm vào 1 cái 'notification' nữa
tìm
thêm lên trước
rồi vào incfiles > classes > functions.php thêm function này vào
<?php
public static function get_forum($id)
{
$req = mysql_query("SELECT * FROM `forum` WHERE `id` = '$id'");
$res = mysql_fetch_assoc($req);
return $res;
}
public static function new_notify(array $prm)
{
$set_notify = unserialize(core::$system_set['mod_notify');
$user = self::get_user($prm['id');
$user = $user['name';
$post = self::get_forum($prm['post');
$text = bbcode::notags($post['text');
$text = preg_replace('#\[c\(.+?)\#si', '', $text);
$text = substr($text,0, 50);
$text = '.core::$system_set['homeurl'.'/forum/index.php?id='.$post['id'.''.$text.'...';
switch ($prm['type'):
case 'like': $prm['text' = $set_notify['like_msg'; break;
case 'say' : $prm['text' = $set_notify['say_msg'; break;
case 'quote':$prm['text' = $set_notify['quote_msg';break;
default: break;
endswitch;
$matchs = array('{USER}','{POST}');
$replace = array($user, $text);
$prm['text' = str_replace($matchs, $replace, $prm['text');
mysql_query("INSERT INTO `cms_mail` SET `user_id`='{$prm['id'}', `from_id`='{$prm['from'}', `text`='{$prm['text'}', `time`='".time()."', `sys`='1', `them`='{$prm['type'}', `postid`='{$prm['post'}'");
}
?>
Copy code
public static function get_forum($id)
{
$req = mysql_query("SELECT * FROM `forum` WHERE `id` = '$id'");
$res = mysql_fetch_assoc($req);
return $res;
}
public static function new_notify(array $prm)
{
$set_notify = unserialize(core::$system_set['mod_notify');
$user = self::get_user($prm['id');
$user = $user['name';
$post = self::get_forum($prm['post');
$text = bbcode::notags($post['text');
$text = preg_replace('#\[c\(.+?)\#si', '', $text);
$text = substr($text,0, 50);
$text = '.core::$system_set['homeurl'.'/forum/index.php?id='.$post['id'.''.$text.'...';
switch ($prm['type'):
case 'like': $prm['text' = $set_notify['like_msg'; break;
case 'say' : $prm['text' = $set_notify['say_msg'; break;
case 'quote':$prm['text' = $set_notify['quote_msg';break;
default: break;
endswitch;
$matchs = array('{USER}','{POST}');
$replace = array($user, $text);
$prm['text' = str_replace($matchs, $replace, $prm['text');
mysql_query("INSERT INTO `cms_mail` SET `user_id`='{$prm['id'}', `from_id`='{$prm['from'}', `text`='{$prm['text'}', `time`='".time()."', `sys`='1', `them`='{$prm['type'}', `postid`='{$prm['post'}'");
}
?>
Copy code
bạn đã có functions tạo thông báo. là functions::new_notify() bây giờ bạn mún 1 hành động nào xảy ra sẽ có thông báo thì vào file xử lí hành động đó add thông báo vào. ở đây mình chỉ hướng dẫn 3 hành động reply, like và quote thôi nha.
Reply và quote thì cùng 1 file forum > includes > say.php các bạn mở ra và tìm
$fadd = mysql_insert_id(); bạn sẽ thấy 2 kết quả, cái thứ nhất là reply cái thứ hai là quote.
ở kết quả thứ nhất thêm sau đoạn dưới đây
<?php
functions::new_notify(array(
'type' => 'say',
'id' => $user_id,
'from' => $type1['user_id',
'post' => $fadd
));
?>
Copy code
functions::new_notify(array(
'type' => 'say',
'id' => $user_id,
'from' => $type1['user_id',
'post' => $fadd
));
?>
Copy code
tương tự kết quả thứ hai cũng là đoạn trên nhưng thay 'say' thành 'quote' nha các bạn
hd dùng functions::new_notify lun.
<?php
$options = array (
'type' => 'xxx', // có 3 loại là like | quote | say. các bạn có thể tùy biến thêm nhiều hành động khác
'id' => 'xxx', // là id của người thực hiện hành động trên. trong thông báo sẽ ghi tên ng này. hình như lúc nào cũng là $user_id
'from' => 'xxx', // là id của người nhận thông báo, là người post bài viết đó
'post' => 'xxx' // id bài viết
);
functions::new_notify($options);
?>
Copy code
$options = array (
'type' => 'xxx', // có 3 loại là like | quote | say. các bạn có thể tùy biến thêm nhiều hành động khác
'id' => 'xxx', // là id của người thực hiện hành động trên. trong thông báo sẽ ghi tên ng này. hình như lúc nào cũng là $user_id
'from' => 'xxx', // là id của người nhận thông báo, là người post bài viết đó
'post' => 'xxx' // id bài viết
);
functions::new_notify($options);
?>
Copy code
Riêng like thì mỗi code mỗi khác nên các bạn tìm dòng nào mà có dòng query INSERT INTO cái bảng chứa dữ liệu like í. thêm thông báo vs functions::new_notify trên và để type là like.
Cái biến thông báo ra ngoài index hình như johncms gốc có sẵn rồi. bạn nào lỡ xóa thì nó là cái này đây.
<?php
$notifications = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` WHERE `from_id`='$user_id' AND `read`='0' AND `sys`='1' AND `delete`!='$user_id';"), 0);
?>
Copy code
$notifications = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_mail` WHERE `from_id`='$user_id' AND `read`='0' AND `sys`='1' AND `delete`!='$user_id';"), 0);
?>
Copy code
nó sẽ in ra bao nhiêu thông báo, còn bố trí sao thì tùy bạn
nếu bạn không thích url mail/index.php?act=systems thì dùng .htaccess rewrite lại thôi
mấy cái icon như demo trên mình dùng fonticon của google bạn thích thì nhập nó vào head còn k thì vào mail > includes > systems.php sửa lại.
Tải zip này lên root và giải nén. nó có notification.php trong panel và systems.php trong mail đó
Tải Về Thông Báo
các bạn vào url panel/?act=notification để cài đặt mod thông báo nha
Nguồn: nhanhnao.xyz

Trực Tuyến:
Khách: 1