/** * Event callback after triggering "user_forum_post_created". * * @param array $info * Details about forum post. */ function nodejs_forum_event_user_forum_post_created_callback($info) { $postID = intval(vartrue($info['data']['post_id'], 0)); $postUserID = intval(vartrue($info['data']['post_user'], 0)); $postThreadID = intval(vartrue($info['data']['post_thread'], 0)); if ($postID === 0 || $postThreadID === 0) { return; } // Get forum plugin preferences. $plugForumPrefs = e107::getPlugConfig('forum')->getPref(); $db = e107::getDb(); // Load thread. $thread = $db->retrieve('forum_thread', '*', 'thread_id = ' . $postThreadID); $threadUser = intval(vartrue($thread['thread_user'], 0)); // Load forum to check (read) permission. $forum = $db->retrieve('forum', '*', 'forum_id = ' . intval(vartrue($thread['thread_forum_id'], 0))); // Author of the forum post. $authorPost = e107::user($postUserID); // Author of the forum topic. $authorThread = e107::user($threadUser); e107_require_once(e_PLUGIN . 'nodejs/nodejs.main.php'); $template = e107::getTemplate('nodejs_forum'); $sc = e107::getScBatch('nodejs_forum', true); $tp = e107::getParser(); // Get topic page number. $postNum = $db->count('forum_post', '(*)', "WHERE post_id <= " . $postID . " AND post_thread = " . $postThreadID . " ORDER BY post_id ASC"); $postPage = ceil($postNum / vartrue($plugForumPrefs['postspage'], 10)); // Push rendered row item into Latest Forum Posts menu. $sc_vars = array('author' => $authorPost, 'post' => $info['data'], 'thread' => $thread, 'topicPage' => $postPage); $sc->setVars($sc_vars); $markup = $tp->parseTemplate($template['MENU']['RECENT']['ITEM'], true, $sc); $message = (object) array('broadcast' => true, 'channel' => 'nodejs_notify', 'callback' => 'nodejsForumMenu', 'type' => 'latestForumPosts', 'markup' => $markup); nodejs_enqueue_message($message); // Broadcast logged in users to inform about new forum post created. if ($authorPost) { $sc->setVars($sc_vars); $markup = $tp->parseTemplate($template['NOTIFICATION']['POST_ALL'], true, $sc); // It's a public forum, so broadcast every online user. if (intval(vartrue($forum['forum_class'], 0)) === 0) { $message = (object) array('broadcast' => true, 'channel' => 'nodejs_notify', 'callback' => 'nodejsForum', 'type' => 'newForumPostAny', 'markup' => $markup, 'exclude' => $postUserID); nodejs_enqueue_message($message); } else { $forumClass = vartrue($forum['forum_class'], 0); $db->select('nodejs_presence'); while ($row = $db->fetch()) { if (isset($row['uid']) && check_class($forumClass, null, $row['uid'])) { $message = (object) array('channel' => 'nodejs_user_' . $row['uid'], 'callback' => 'nodejsForum', 'type' => 'newForumPostAny', 'markup' => $markup, 'exclude' => $postUserID); nodejs_enqueue_message($message); } } } } // Broadcast logged in (thread-author) user to inform about new forum post created in his/her topic. if (isset($authorThread['user_id'])) { $sc->setVars($sc_vars); $markup = $tp->parseTemplate($template['NOTIFICATION']['POST_OWN'], true, $sc); $message = (object) array('channel' => 'nodejs_user_' . $authorThread['user_id'], 'callback' => 'nodejsForum', 'type' => 'newForumPostOwn', 'markup' => $markup, 'exclude' => $postUserID); nodejs_enqueue_message($message); } }
/** * Send messages to clients for updating online menu. */ public function nodejs_update_online_menu() { e107_require_once(e_PLUGIN . 'nodejs/nodejs.main.php'); e107_require_once(e_PLUGIN . 'nodejs_online/includes/nodejs_online.php'); $template = e107::getTemplate('nodejs_online'); $sc = e107::getScBatch('nodejs_online', true); $tp = e107::getParser(); $users = nodejs_online_get_online_users(); $message = (object) array('broadcast' => true, 'callback' => 'nodejsOnlineMenu', 'type' => 'nodejsOnlineMenuBadge', 'markup' => count($users)); nodejs_enqueue_message($message); $list = '<li role="presentation" class="nav-header dropdown-header">' . LAN_NODEJS_ONLINE_MENU_01 . '</li>'; foreach ($users as $uinfo => $row) { $sc->setVars(array('user' => $row)); $list .= $tp->parseTemplate($template['MENU']['ITEM'], true, $sc); } $message = (object) array('broadcast' => true, 'callback' => 'nodejsOnlineMenu', 'type' => 'nodejsOnlineMenuList', 'markup' => $list); nodejs_enqueue_message($message); }
/** * Event callback after triggering "postcomment". * * @param array $comment * Comment item. * * $comment contains: * - comment_pid * - comment_item_id * - comment_subject * - comment_author_id * - comment_author_name * - comment_author_email * - comment_datestamp * - comment_comment * - comment_blocked * - comment_ip * - comment_type * - comment_lock * - comment_share * - comment_nick * - comment_time * - comment_id * * getCommentData() returns with array, which contains: * - comment_datestamp * - comment_author_id * - comment_author * - comment_comment * - comment_subject * - comment_type * - comment_title * - comment_url */ function nodejs_comment_event_postcomment_callback($comment) { e107_require_once(e_PLUGIN . 'nodejs/nodejs.main.php'); $tpl = e107::getTemplate('nodejs_comment'); $sc = e107::getScBatch('nodejs_comment', true); $tp = e107::getParser(); $cm = e107::getComment(); $cid = (int) vartrue($comment['comment_id'], 0); $pid = (int) vartrue($comment['comment_pid'], 0); $uid = (int) vartrue($comment['comment_author_id'], 0); $commentData = $cm->getCommentData(1, 0, 'comment_id=' . $cid); if (!isset($commentData[0])) { return; } $authorData = e107::user($uid); // Send notification to everyone for updating latest comments menu. $sc->setVars($commentData[0]); $markup = $tp->parseTemplate($tpl['MENU']['LATEST']['ITEM'], true, $sc); $message = (object) array('broadcast' => true, 'channel' => 'nodejs_notify', 'callback' => 'nodejsCommentMenu', 'type' => 'latestComments', 'markup' => $markup); nodejs_enqueue_message($message); // Send notification to everyone for notifying about new comment. $sc->setVars(array('account' => $authorData, 'comment' => $commentData[0])); $markup = $tp->parseTemplate($tpl['NOTIFICATION']['POST_ALL'], true, $sc); $message = (object) array('broadcast' => true, 'channel' => 'nodejs_notify', 'callback' => 'nodejsComments', 'type' => 'newCommentAny', 'markup' => $markup, 'exclude' => $authorData['user_id']); nodejs_enqueue_message($message); // Reply on comment. if ($pid > 0) { $commentParentData = $cm->getCommentData(1, 0, 'comment_id=' . $pid); array_pop($commentParentData); $authorParentData = e107::user(); // Send notification to author of parent comment for notifying about new reply. $sc->setVars(array('account' => $authorData, 'comment' => $commentData[0])); $markup = $tp->parseTemplate($tpl['NOTIFICATION']['POST_OWN'], true, $sc); $message = (object) array('channel' => 'nodejs_user_' . $authorParentData['user_id'], 'callback' => 'nodejsComments', 'type' => 'newCommentOwn', 'markup' => $markup, 'exclude' => $authorData['user_id']); nodejs_enqueue_message($message); } }