/** * Sends emails to moderators configured in admincp */ protected function sendModeratorNotification($nodeid) { // This is the list of ALL mods who have either the newpostemail or the newthreademail option enabled // We'll go through this list and figure out which ones are moderators of the ancestor channels of $nodeid $notify = vB_Cache::instance(vB_Cache::CACHE_STD)->read('vB_Mod_PostNotify'); if ($notify === false) { $library = vB_Library::instance('usergroup'); $smodgroups = $library->getSuperModGroups(); //force to have a non empty array or the query will be unhappy. It's unlikely that a site will //not have any usergroups with the superadmin flag set, but its possible if (!$smodgroups) { $smodgroups = array(0); } $notify = array(); $bitFields = vb::getDatastore()->getValue('bf_misc_moderatorpermissions'); $modQry = $this->assertor->assertQuery('vBForum:modPostNotify', array('bfPost' => $bitFields['newpostemail'], 'bfTopic' => $bitFields['newthreademail'], 'smodgroups' => $smodgroups)); $events = array(); if ($modQry->valid()) { foreach ($modQry as $mod) { $events[$mod['userid']] = 'userChg_' . $mod['userid']; //Every time a moderator changes emails, is deleted, etc, we have to invalidate it. if (!isset($notify[$mod['nodeid']])) { $notify[$mod['nodeid']] = array("posts" => array(), "topics" => array()); } if ($mod['notifypost'] > 0) { $notify[$mod['nodeid']]['posts'][] = $mod['email']; } if ($mod['notifytopic'] > 0) { $notify[$mod['nodeid']]['topics'][] = $mod['email']; } } } // all these user change events could be a lot... $events['vB_ModPostNotifyChg'] = 'vB_ModPostNotifyChg'; vB_Cache::instance(vB_Cache::CACHE_STD)->write('vB_Mod_PostNotify', $notify, 1440, $events); } // grab parents of the added node, and see if we have any moderators on the channel $parents = vB::getDbAssertor()->getRows('vBForum:closure', array('child' => $nodeid)); $notifyList = array(); // the actual list of emails that are associated with this node. $node = vB_Library::instance('node')->getNodeFullContent($nodeid); $node = $node[$nodeid]; if ($node['starter'] == $node['nodeid']) { $notifyKey = "topics"; } else { $notifyKey = "posts"; } foreach ($parents as $closure) { $parentid = $closure['parent']; if (array_key_exists($parentid, $notify)) { // each found list is an array of emails, so we have to merge $notifyList = array_merge($notifyList, $notify[$parentid][$notifyKey]); } } // Global moderators case. At the moment, the global mods in the moderator table has nodeid = 0 so the // closure check above leaves them out. if (!empty($notify[0])) { $notifyList = array_merge($notifyList, $notify[0][$notifyKey]); } $notifyList = array_unique($notifyList); if (empty($notifyList)) { return; } // grab some data for the message $userinfo = vB::getCurrentsession()->fetch_userinfo(); $forumName = vB::getDatastore()->getOption('bbtitle'); $starter = vB_Library::instance('node')->getNodeFullContent($node['starter']); $starter = $starter[$node['starter']]; $threadTitle = $starter['title']; // Below is the call to fetch the url to the thread starter // $threadLink = vB5_Route::buildUrl($starter['routeid'] . '|fullurl', $starter); // If we want the direct link to the post, below is what's needed $routeInfo = array('nodeid' => $nodeid); // Using the normal vB5_Route::buildURL can throw an exception, because it'll likely use the // conversation route which checks permissions on the *current* user in the constructor and // throw an exception. // So we'll use vB5_Route_Node $nodeLink = vB5_Route::buildUrl('node|fullurl', $routeInfo); $message = vB_Phrase::fetchSinglePhrase('new_post_notification_a_b_c_d_e_f', array($userinfo['username'], $node['channeltitle'], $forumName, $threadTitle, $nodeLink, $node['rawtext'])); $subject = vB_Phrase::fetchSinglePhrase('new_post_in_forum_x', $node['channeltitle']); // send emails foreach ($notifyList as $email) { if ($email != $userinfo['email']) { vB_Mail::vbmail($email, $subject, $message, true, '', '', '', TRUE); } } }