<?php
namespace App;
/* This class is handling all the ajax requests */
class ajaxController{
function __construct() {
// Verify CSFR
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if(! app('csfr')->verifyToken(SECRET_KEY) ){
header('HTTP/1.0 403 Forbidden');
exit();
}
}
}
// Saving received messages
public function save_message(){
$post_data = app('request')->body;
$profanity_found = false;
if (in_array($post_data['message_type'], array(2,6,7))) {
$message_content = app('purify')->xss_clean($post_data['message_content']);
}elseif ($post_data['message_type'] == 8) {
$content = json_decode($post_data['message_content'], true);
if (in_array($content['new_message']['new_type'], array(2,6,7))) {
$content['new_message']['new_content'] = app('purify')->xss_clean($content['new_message']['new_content']);
$message_content = json_encode($content);
}else if ($content['new_message']['new_type'] == 1) {
preg_match('/\b(?:(?:https?):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $content['new_message']['new_content'], $message_links);
if (!empty($message_links[0])) {
$url_data = get_url_data($message_links[0]);
$url_data['url'] = $message_links[0];
$link_message_content = array();
$link_message_content['message'] = app('purify')->xss_clean($content['new_message']['new_content']);
$content['new_message']['new_content'] = array_merge($link_message_content,$url_data);
$content['new_message']['new_type'] = 5;
$message_content = json_encode($content,JSON_UNESCAPED_UNICODE);
}else{
// Check profanity
if (isset(SETTINGS['profanity_filter']) && SETTINGS['profanity_filter'] == true) {
$message_content_filtered = profanity_filter($content['new_message']['new_content']);
if ($message_content_filtered != $content['new_message']['new_content']) {
$content['new_message']['new_content'] = $message_content_filtered;
$profanity_found = true;
}
}
$content['new_message']['new_content'] = app('purify')->xss_clean(clean($content['new_message']['new_content']));
$message_content = json_encode($content);
}
}else{
$content['new_message']['new_content'] = app('purify')->xss_clean(clean($content['new_message']['new_content']));
$message_content = json_encode($content);
}
}else{
$message_content = app('purify')->xss_clean(clean($post_data['message_content']));
}
// Check profanity
if(!in_array($post_data['message_type'], array(2,6,7,8))){
if (isset(SETTINGS['profanity_filter']) && SETTINGS['profanity_filter'] == true) {
$message_content_filtered = profanity_filter($message_content);
if ($message_content_filtered != $message_content) {
$message_content = $message_content_filtered;
$profanity_found = true;
}
}
}
// get links inside message
if ($post_data['message_type'] == 1) {
preg_match('/\b(?:(?:https?):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $post_data['message_content'], $message_links);
if (!empty($message_links[0])) {
$url_data = get_url_data($message_links[0]);
$url_data['url'] = $message_links[0];
$link_message_content = array();
$link_message_content['message'] = app('purify')->xss_clean($post_data['message_content']);
$link_message_content = array_merge($link_message_content,$url_data);
$message_content = json_encode($link_message_content,JSON_UNESCAPED_UNICODE);
$post_data['message_type'] = 5; // message with links
}
}
$chat_save = app('chat')->saveNewMessage(
app('auth')->user()['id'],
$message_content,
app('purify')->xss_clean(clean($post_data['active_user'])),
app('purify')->xss_clean(clean($post_data['active_group'])),
app('purify')->xss_clean(clean($post_data['active_room'])),
app('purify')->xss_clean(clean($post_data['message_type'])),
app('purify')->xss_clean(clean($post_data['chat_meta_id']))
);
$chat_save['random_id'] = $post_data['random_id'];
if ($profanity_found) {
if ($post_data['message_type'] == 8){
$chat_save['profanity_filtered'] = json_decode($message_content, true)['new_message']['new_content'];
}else{
$chat_save['profanity_filtered'] = $message_content;
}
}else{
$chat_save['profanity_filtered'] = null;
}
return json_response($chat_save);
}
// main heartbeat function to keep the chat alive.
public function heartbeat(){
$last_seen_data = Array ( 'last_seen' => app('db')->now());
app('db')->where ('id', app('auth')->user()['id']);
app('db')->update ('users', $last_seen_data);
$post_data = app('request')->body;
$data = array();
if($post_data['active_user']) {
if($post_data['active_user'] > app('auth')->user()['id']) {
$user_1 = app('auth')->user()['id'];
$user_2 = $post_data['active_user'];
}else{
$user_1 = $post_data['active_user'];
$user_2 = app('auth')->user()['id'];
}
$data['chat_type'] = "user";
// get new messages
app('db')->join("users u", "c.sender_id=u.id", "LEFT");
app('db')->where ('c.id', $post_data['last_chat_id'], ">");
app('db')->where ('c.user_1', $user_1);
app('db')->where ('c.user_2', $user_2);
app('db')->where ('c.room_id', $post_data['active_room']);
app('db')->where ("c.sender_id != " . app('auth')->user()['id']);
$chats = app('db')->get('private_chats c', null, 'c.*, u.user_name, u.first_name, u.avatar, "private" as chat_type');
$update_meta = array();
$update_meta['chat_meta_id'] = $post_data['chat_meta_id'];
$update_meta['is_typing'] = $post_data['is_typing'];
app('chat')->updateChatMetaData($update_meta);
$active_user = app('auth')->user($post_data['active_user']);
$last_seen = strtotime($active_user['last_seen']);
$seconds10 = strtotime("-10 seconds");
//active user chat meta
$active_user_chat_meta_data = app('chat')->getChatMetaData($post_data['active_user'], app('auth')->user()['id'], $post_data['active_room']);
$data['last_seen'] = date('Y-m-d H:i:s', $last_seen);
$data['seconds10'] = date('Y-m-d H:i:s', $seconds10);
if($active_user_chat_meta_data['is_typing']){
$active_user = app('auth')->user($post_data['active_user']);
if($last_seen > $seconds10){
$data['typing_user'] = "typing...";
}else{
$data['typing_user'] = 0;
}
}else{
$data['typing_user'] = 0;
}
$from_user_chat_meta_data = app('chat')->getChatMetaData(app('auth')->user()['
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
软件开发设计:应用软件开发、系统软件开发、移动应用开发、网站开发Node.js、C++、Java、python、web、C#等语言的项目开发与学习资料 硬件与设备:单片机、EDA、proteus、RTOS、包括计算机硬件、服务器、网络设备、存储设备、移动设备等 操作系统:LInux、Android树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信是一个非常广泛的领域,它涉及到计算机科学、电子工程、数学等多个学科的知识。 云计算与大数据:包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。
资源推荐
资源详情
资源评论
收起资源包目录
PHP 多端同步聊天系统.zip (44个子文件)
cm
mysql
mysql 1B
sm2_20210718_212054.sql 104KB
404.html 479B
html
register.html 8KB
terms.html 625B
forgot_password.html 3KB
reset_password.html 4KB
chat_room_update.html 14KB
chat_room_loop_large.html 5KB
chat_room_list_modal.html 2KB
base.min.html 3KB
privacy.html 609B
profile_modal.html 6KB
login.html 12KB
html 1B
join_chatroom.html 7KB
base.html 7KB
index.html 4KB
contact.html 3KB
about.html 591B
base.index.html 16KB
settings.html 49KB
chat_room_loop_small.html 5KB
chat_room.html 37KB
index.php 9KB
index.html 917B
php
cronController.php 996B
installController.php 769B
template_functions.php 2KB
homeController.php 32KB
Auth.php 12KB
adminController.php 16KB
utils.php 21KB
Admin.php 10KB
Resize.php 24KB
index.php 25B
init.php 5KB
ajaxController.php 45KB
Csrf.php 5KB
Upload.php 13KB
php 1B
Chat.php 26KB
countries.php 6KB
settings.php 211B
共 44 条
- 1
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- uniapp中tab切换,底部内容跟着移动,相反,底部移动,tab也跟着切换-组件
- 基于JS+TS实现跨平台3D相机控制器-附项目源码-优质项目分享.zip
- 跨相机-基于Rust实现的跨平台相机捕获-附项目源码-优质项目分享.zip
- odise 14离线安装包 大众斯柯达奥迪 5054 6153
- 网页设计期末作业-纯html加css+少量js-盗墓笔记旅游导航网站.rar
- 算法笔记模拟退火.rar
- MATLAB大数据仿真案例-蚁群算法(ACO)用于求解旅行商(TSP)问题.rar
- 基于yolov5的吸烟行为检测源码+模型.zip
- MySQL基础知识-个人笔记.rar
- Project8.ipynb
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功