1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

Merge pull request #3342 from SimSync/fix_3277_notify

Fixes #3277 Forum notification
This commit is contained in:
Cameron 2018-08-06 13:47:41 -07:00 committed by GitHub
commit f1a3e207db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 351 additions and 48 deletions

View File

@ -10,8 +10,6 @@
*
*/
// TODO - create notify messages + LAN
if (!defined('e107_INIT')) { exit; }
e107::lan('forum','notify',true);
@ -26,80 +24,344 @@ class forum_notify extends notify
$config[] = array(
'name' => LAN_FORUM_NT_NEWTOPIC,
'function' => "forum_nt",
// 'function' => "forum_nt",
'function' => "user_forum_topic_created",
'category' => ''
);
$config[] = array(
'name' => LAN_FORUM_NT_NEWTOPIC_PROB,
'function' => "forum_ntp",
//'function' => "forum_ntp",
'function' => "user_forum_topic_created_probationary",
'category' => ''
);
$config[] = array(
'name' => LAN_FORUM_NT_TOPIC_DELETED,
'function' => "forum_topic_del",
'name' => LAN_FORUM_NT_TOPIC_UPDATED,
'function' => "user_forum_topic_updated",
'category' => ''
);
$config[] = array(
'name' => LAN_FORUM_NT_TOPIC_DELETED,
//'function' => "forum_topic_del",
'function' => "user_forum_topic_deleted",
'category' => ''
);
$config[] = array(
'name' => LAN_FORUM_NT_TOPIC_MOVED,
'function' => "user_forum_topic_moved",
'category' => ''
);
/*
// todo: implement thread split
$config[] = array(
'name' => LAN_FORUM_NT_TOPIC_SPLIT,
'function' => "forum_topic_split",
//'function' => "forum_topic_split",
'function' => "user_forum_topic_split",
'category' => ''
);
*/
$config[] = array(
'name' => LAN_FORUM_NT_POST_CREATED,
'function' => "user_forum_post_created",
'category' => ''
);
$config[] = array(
'name' => LAN_FORUM_NT_POST_UPDATED,
'function' => "user_forum_post_updated",
'category' => ''
);
$config[] = array(
'name' => LAN_FORUM_NT_POST_DELETED,
'function' => "forum_post_del",
//'function' => "forum_post_del",
'function' => "user_forum_post_deleted",
'category' => ''
);
);
$config[] = array(
'name' => LAN_FORUM_NT_POST_REPORTED,
'function' => "forum_post_rep",
//'function' => "forum_post_rep",
'function' => "user_forum_post_report",
'category' => ''
);
return $config;
}
private function getData($type, $id)
{
if (intval($id) < 1) return false;
$qry = '';
switch($type)
{
case 'post':
$qry = 'SELECT f.forum_name, f.forum_sef, t.thread_id, t.thread_name, p.post_entry
FROM `#forum_post` AS p
LEFT JOIN `#forum_thread` AS t ON (t.thread_id = p.post_thread)
LEFT JOIN `#forum` AS f ON (f.forum_id = t.thread_forum_id)
WHERE p.post_id = ' . intval($id);
break;
case 'thread':
$qry = 'SELECT f.forum_name, f.forum_sef, t.thread_id, t.thread_name
FROM `#forum_thread` AS t
LEFT JOIN `#forum` AS f ON (f.forum_id = t.thread_forum_id)
WHERE t.thread_id = ' . intval($id);
break;
default:
return false;
}
$sql = e107::getDb();
if($sql->gen($qry))
{
return $sql->fetch();
}
return false;
}
function forum_nt($data)
//function forum_nt($data)
function user_forum_topic_created($data)
{
$message = 'todo';
$this->send('forum_nt', LAN_PLUGIN_FORUM_NAME, $message);
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: New thread created';
}
else
{
$sef = $data['thread_sef'];
$data = $this->getData('post', vartrue($data['post_id'], 0));
if ($data === false) return false;
$url = e107::url('forum', 'topic', array('thread_id' => $data['thread_id'], 'thread_sef' => $sef, 'forum_sef' => $data['forum_sef']), array('mode' => 'full'));
$message = e107::getParser()->lanVars(nl2br(LAN_FORUM_NT_NEWTOPIC_MSG), array(
'user' => USERNAME,
'forum' => $data['forum_name'],
'thread' => sprintf('<a href="%s">%s</a>', $url, $data['thread_name']),
'post' => e107::getParser()->toHTML($data['post_entry'], true, 'BODY')
));
}
$this->send('user_forum_topic_created', LAN_PLUGIN_FORUM_NAME, $message);
return true;
}
function forum_ntp($data)
//function forum_ntp($data)
function user_forum_topic_created_probationary($data)
{
$message = 'todo';
$this->send('forum_nt', LAN_FORUM_NT_7, $message);
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: New thread (probationary) created';
}
else
{
$sef = $data['thread_sef'];
$data = $this->getData('post', vartrue($data['post_id'], 0));
if ($data === false) return false;
$url = e107::url('forum', 'topic', array('thread_id' => $data['thread_id'], 'thread_sef' => $sef, 'forum_sef' => $data['forum_sef']), array('mode' => 'full'));
$message = e107::getParser()->lanVars(nl2br(LAN_FORUM_NT_NEWTOPIC_PROB_MSG), array(
'user' => USERNAME,
'forum' => $data['forum_name'],
'thread' => sprintf('<a href="%s">%s</a>', $url, $data['thread_name']),
'post' => e107::getParser()->toHTML($data['post_entry'], true, 'BODY')
));
}
$this->send('user_forum_topic_created_probationary', LAN_FORUM_NT_7, $message);
return true;
}
function forum_topic_del($data)
function user_forum_topic_moved($data)
{
$message = 'todo';
$this->send('forum_topic_del', LAN_FORUM_NT_8, $message);
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: Thread moved';
}
else
{
if(!isset($data['old_thread']) || !isset($data['new_thread']))
{
return false;
}
$url = e107::url('forum', 'forum', array('forum_sef' => $data['new_thread']['forum_sef'], 'forum_id' => $data['new_thread']['forum_id']), array('mode' => 'full'));
$message = e107::getParser()->lanVars(nl2br(LAN_FORUM_NT_TOPIC_MOVED_MSG), array(
'user' => USERNAME,
'forum' => $data['old_thread']['forum_name'],
'forum2' => sprintf('<a href="%s">%s</a>', $url, $data['new_thread']['forum_name']),
'thread' => $data['new_thread']['thread_name']
));
}
$this->send('user_forum_topic_moved', LAN_FORUM_NT_13, $message);
return true;
}
function forum_topic_split($data)
//function forum_topic_del($data)
function user_forum_topic_deleted($data)
{
$message = 'todo';
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: Thread deleted';
}
else
{
if(isset($data['thread_id']) && intval($data['thread_id']) < 1)
{
return false;
}
$url = e107::url('forum', 'forum', array('forum_id' => $data['forum_id'], 'forum_sef' => $data['forum_sef']), array('mode' => 'full'));
$message = e107::getParser()->lanVars(nl2br(LAN_FORUM_NT_TOPIC_DELETED_MSG), array(
'user' => USERNAME,
'forum' => sprintf('<a href="%s">%s</a>', $url, $data['forum_name']),
'thread' => $data['thread_name']
));
}
$this->send('user_forum_topic_deleted', LAN_FORUM_NT_8, $message);
return true;
}
function user_forum_topic_updated($data)
{
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: Thread updated';
}
else
{
$data = $this->getData('thread', vartrue($data['thread_id'],0));
if ($data === false) return false;
$sef = eHelper::title2sef($data['thread_name'],'dashl');
$url = e107::url('forum', 'topic', array('thread_id' => $data['thread_id'], 'thread_sef' => $sef, 'forum_sef' => $data['forum_sef']), array('mode' => 'full'));
$message = e107::getParser()->lanVars(nl2br(LAN_FORUM_NT_TOPIC_UPDATED_MSG), array(
'user' => USERNAME,
'forum' => $data['forum_name'],
'thread' => sprintf('<a href="%s">%s</a>', $url, $data['thread_name']),
'post' => e107::getParser()->toHTML($data['post_entry'], true, 'BODY')
));
}
$this->send('user_forum_topic_updated', LAN_FORUM_NT_12, $message);
return true;
}
//function forum_topic_split($data)
function user_forum_topic_split($data)
{
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: Topic splitted';
}
else
{
$message = $data;
}
$this->send('forum_topic_split', LAN_FORUM_NT_9, $message);
}
function forum_post_del($data)
function user_forum_post_created($data)
{
$message = 'todo';
$this->send('forum_post_del', LAN_FORUM_NT_10, $message);
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: Post created';
}
else
{
$data = $this->getData('post', vartrue($data['post_id'], 0));
if ($data === false) return false;
$sef = eHelper::title2sef($data['thread_name'],'dashl');
$url = e107::url('forum', 'topic', array('thread_id' => $data['thread_id'], 'thread_sef' => $sef, 'forum_sef' => $data['forum_sef']), array('mode' => 'full'));
$message = e107::getParser()->lanVars(nl2br(LAN_FORUM_NT_POST_CREATED_MSG), array(
'user' => USERNAME,
'forum' => $data['forum_name'],
'thread' => sprintf('<a href="%s">%s</a>', $url, $data['thread_name']),
'post' => e107::getParser()->toHTML($data['post_entry'], true, 'BODY')
));
}
$this->send('user_forum_post_created', LAN_FORUM_NT_14, $message);
return true;
}
function forum_post_rep($data)
function user_forum_post_updated($data)
{
$message = 'todo';
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: Post updated';
}
else
{
$data = $this->getData('post', vartrue($data['post_id'], 0));
if ($data === false) return false;
$sef = eHelper::title2sef($data['thread_name'],'dashl');
$url = e107::url('forum', 'topic', array('thread_id' => $data['thread_id'], 'thread_sef' => $sef, 'forum_sef' => $data['forum_sef']), array('mode' => 'full'));
$message = e107::getParser()->lanVars(nl2br(LAN_FORUM_NT_POST_UPDATED_MSG), array(
'user' => USERNAME,
'forum' => $data['forum_name'],
'thread' => sprintf('<a href="%s">%s</a>', $url, $data['thread_name']),
'post' => e107::getParser()->toHTML($data['post_entry'], true, 'BODY')
));
}
$this->send('user_forum_post_updated', LAN_FORUM_NT_15, $message);
return true;
}
//function forum_post_del($data)
function user_forum_post_deleted($data)
{
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: Post deleted';
}
else
{
$entry = e107::getParser()->toHTML($data['post_entry'], true, 'BODY');
$postid = $data['post_id'];
$data = $this->getData('thread', vartrue($data['post_thread'], 0));
if ($data === false) return false;
$sef = eHelper::title2sef($data['thread_name'],'dashl');
$url = e107::url('forum', 'topic', array('thread_id' => $data['thread_id'], 'thread_sef' => $sef, 'forum_sef' => $data['forum_sef']), array('mode' => 'full'));
$message = e107::getParser()->lanVars(nl2br(LAN_FORUM_NT_POST_DELETED_MSG), array(
'user' => USERNAME,
'forum' => $data['forum_name'],
'thread' => sprintf('<a href="%s">%s</a>', $url, $data['thread_name']),
'postid' => $postid,
'post' => $entry
));
}
$this->send('user_forum_post_deleted', LAN_FORUM_NT_10, $message);
return true;
}
//function forum_post_rep($data)
function user_forum_post_report($data)
{
if (isset($data['id']) && isset($data['data']))
{
$message = 'Notify test: Post reported';
}
else
{
$message = $data;
}
$this->send('forum_post_rep', LAN_FORUM_NT_11, $message);
}
}
?>
}

View File

@ -870,7 +870,15 @@ class e107forum
$triggerData['thread_sef'] = $threadInfo['thread_sef'];
$triggerData['post_id'] = $newPostId;
e107::getEvent()->trigger('user_forum_topic_created', $triggerData);
if (e107::getDb()->count('forum_post', '(post_id)', 'WHERE post_user = "'.USERID.'"') > 0)
{
e107::getEvent()->trigger('user_forum_topic_created', $triggerData);
}
else
{
e107::getEvent()->trigger('user_forum_topic_created_probationary', $triggerData);
}
return array('postid' => $newPostId, 'threadid' => $newThreadId, 'threadsef'=>$threadInfo['thread_sef']);
}
@ -922,6 +930,11 @@ class e107forum
$this->forumUpdateLastpost('forum', $oldForumId, false);
$this->forumUpdateLastpost('forum', $newForumId, false);
e107::getEvent()->trigger('user_forum_topic_moved', array(
'old_thread' => $threadInfo,
'new_thread' => $this->threadGet($threadId)
));
}
@ -944,9 +957,9 @@ class e107forum
e107::getEvent()->trigger('user_forum_topic_updated', $triggerData);
}
function postUpdate($postId, $postInfo)
function postUpdate($postId, $postInfo)
{
$info = array();
$info['data'] = $postInfo;
@ -960,11 +973,11 @@ class e107forum
$triggerData = $postInfo;
$triggerData['post_id'] = intval($postId);
e107::getEvent()->trigger('user_forum_post_updated', $info);
e107::getEvent()->trigger('user_forum_post_updated', $triggerData);
}
function threadGet($id, $joinForum = true, $uid = USERID)
{
$id = (int)$id;
@ -1103,7 +1116,7 @@ class e107forum
$threadId = $sql->retrieve('forum_post', 'post_thread', 'post_id = '.$postId);
if($rows = $sql->retrieve('forum_post', 'post_id', 'post_thread = '.$threadId, TRUE))
{
{
$postids = array();
foreach($rows as $row)
@ -1114,7 +1127,7 @@ class e107forum
if($postId == min($postids))
{
return true;
}
}
}
return false;
}
@ -1499,6 +1512,7 @@ class e107forum
{
$sql = e107::getDb();
$where = '';
if(!empty($this->permList['view_list']))
{
$where = ($all ? '' : " WHERE forum_id IN ({$this->permList['view_list']}) ");
@ -2047,8 +2061,11 @@ class e107forum
if ($sql->select('forum_thread', 'thread_id', "thread_lastpost < {$prunedate} AND thread_sticky != 1 AND thread_forum_id IN ({$forumList})"))
{
$threadList = $sql->db_getList();
$thread_count = count($threadList);
$reply_count = 0;
foreach($threadList as $thread)
{
$reply_count += (int)$sql->count('forum_post', '(*)', 'WHERE post_thread = '.$thread['thread_id']);
$this->threadDelete($thread['thread_id'], false);
}
foreach($forumArray as $fid)
@ -2057,6 +2074,7 @@ class e107forum
$this->forumUpdateCounts($fid);
}
return FORLAN_8." ( ".$thread_count." ".FORLAN_92.", ".$reply_count." ".FORLAN_93." )";
return FORLAN_8." ( ".count($threadList)." ".FORLAN_92.", ".$reply_count." ".FORLAN_93." )";
}
else
{
@ -2344,7 +2362,7 @@ class e107forum
if($sql->delete('forum_thread', 'thread_id='.$threadId))
{
$status = true;
e107::getEvent()->trigger('user_forum_topic_deleted', $threadId);
e107::getEvent()->trigger('user_forum_topic_deleted', $threadInfo);
}
//Delete any thread tracking
@ -2376,9 +2394,11 @@ class e107forum
$postId = (int)$postId;
$e107 = e107::getInstance();
$sql = e107::getDb();
$deleted = false;
if(!$sql->select('forum_post', '*', 'post_id = '.$postId))
$deleted = false;
$postInfo = $sql->retrieve('forum_post', '*', 'post_id = '.$postId);
//if(!$sql->select('forum_post', '*', 'post_id = '.$postId))
if(!is_array($postInfo) || empty($postInfo))
{
echo 'NOT FOUND!'; return;
}
@ -2396,7 +2416,7 @@ class e107forum
if($sql->delete('forum_post', 'post_id='.$postId))
{
$deleted = true;
e107::getEvent()->trigger('user_forum_post_deleted', $postId);
e107::getEvent()->trigger('user_forum_post_deleted', $postInfo);
}
// update statistics

View File

@ -309,10 +309,13 @@ class forum_post_handler
$link = "{e_PLUGIN}forum/forum_admin.php?mode=post&action=list&id=".intval($result);
$report = LAN_FORUM_2018." ".SITENAME." : ".$link . "\n
".LAN_FORUM_2019.": ".USERNAME. "\n" . $report_add;
$subject = LAN_FORUM_2020." ". SITENAME;
e107::getNotify()->send('forum_post_rep', $subject, $report);
//$subject = LAN_FORUM_2020." ". SITENAME;
//e107::getNotify()->send('forum_post_rep', $subject, $report);
e107::getEvent()->trigger('user_forum_post_report', $report);
e107::getRender()->tablerender(LAN_FORUM_2023, $text, 'forum-post-report');
}

View File

@ -7,11 +7,29 @@ define("LAN_FORUM_NT_8", "Forum - Thread deleted");
define("LAN_FORUM_NT_9", "Forum - Thread split");
define("LAN_FORUM_NT_10", "Forum - Post deleted");
define("LAN_FORUM_NT_11", "Forum - Post reported");
define("LAN_FORUM_NT_12", "Forum - Thread updated");
define("LAN_FORUM_NT_13", "Forum - Thread moved");
define("LAN_FORUM_NT_14", "Forum - Post created");
define("LAN_FORUM_NT_15", "Forum - Post updated");
define("LAN_FORUM_NT_NEWTOPIC", "New topic created");
define("LAN_FORUM_NT_NEWTOPIC_PROB", "New topic created by probationary member");
define("LAN_FORUM_NT_TOPIC_DELETED", "Topic deleted");
define("LAN_FORUM_NT_TOPIC_SPLIT", "Topic split");
define("LAN_FORUM_NT_TOPIC_UPDATED", "Topic updated");
define("LAN_FORUM_NT_TOPIC_DELETED", "Topic deleted");
define("LAN_FORUM_NT_TOPIC_MOVED", "Topic moved");
define("LAN_FORUM_NT_POST_CREATED", "Post created");
define("LAN_FORUM_NT_POST_UPDATED", "Post updated");
define("LAN_FORUM_NT_POST_DELETED", "Post deleted");
define("LAN_FORUM_NT_POST_REPORTED", "Post reported");
define("LAN_FORUM_NT_NEWTOPIC_MSG", "New thread in forum [forum] created by: [user]\nSubject: [thread]\n\nMessage:\n[post]");
define("LAN_FORUM_NT_NEWTOPIC_PROB_MSG", "New thread in forum [forum] created by new user: [user]\nSubject: [thread]\n\nMessage:\n[post]");
define("LAN_FORUM_NT_TOPIC_UPDATED_MSG", "Thread [thread] (Forum name: [forum]) has been updated by: [user]");
define("LAN_FORUM_NT_TOPIC_DELETED_MSG", "Thread [thread] in forum [forum] deleted by: [user]");
define("LAN_FORUM_NT_TOPIC_MOVED_MSG", "Thread [thread] has been moved from [forum] to forum [forum2] by: [user]");
define("LAN_FORUM_NT_POST_CREATED_MSG", "New message in thread [thread] (Forum name: [forum]) created by: [user]\nMessage:\n[post]");
define("LAN_FORUM_NT_POST_UPDATED_MSG", "Message in thread [thread] (Forum name: [forum]) updated by: [user]\nMessage:\n[post]");
define("LAN_FORUM_NT_POST_DELETED_MSG", "Message #[postid] of thread [thread] in forum [forum] deleted by: [user]\n\nMessage:\n[post]");