// And now the magic begins. $plugins->run_hooks("wiki_edit_commit"); $message = $db->escape_string($mybb->input['message']); $id = (int) $mybb->input['id']; $notes = $db->escape_string($mybb->input['notes']); $notes = str_replace("~~~~", "[signoff:{$mybb->user['uid']}]", $notes); $sql = $db->write_query(sprintf("UPDATE `%swiki`", TABLE_PREFIX) . "SET `content`='{$message}', `authors`='{$authors}', `lastauthor`='{$mybb->user['username']}', `lastauthorid`='{$mybb->user['uid']}', `notepad`='{$notes}'\n\t\t\t\tWHERE `id`='{$id}'"); $sql = $db->write_query(sprintf("INSERT INTO %swiki_edits(`aid`,`author`,`revision`) VALUES('{$id}','{$mybb->user['uid']}','{$message}')", TABLE_PREFIX)); if (class_exists('MybbStuff_MyAlerts_AlertTypeManager')) { $user_array = explode(',', $wiki['watching']); $alertType = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getByCode('mybb_wiki_alert_code'); if ($alertType != null && $alertType->getEnabled()) { $alerts = array(); foreach ($user_array as $user) { $alert = new MybbStuff_MyAlerts_Entity_Alert($user, $alertType, $id); $alert->setExtraDetails(array('title' => $wiki['title'])); $alerts[] = $alert; } MybbStuff_MyAlerts_AlertManager::getInstance()->addAlerts($alerts); } } if (!$sql) { error($lang->notupdated); } else { // All done. :-) $id = (int) $mybb->input['id']; redirect("wiki.php?action=view&id={$id}", $lang->wiki_edited); } } } elseif ($mybb->input['action'] == 'new') { if (!$permissions['can_create']) {
/** * Get a single alert by ID. * * @param int $id The ID of the alert to fetch. * * @return MybbSTuff_MyAlerts_Entity_Alert */ public function getAlert($id = 0) { $id = (int) $id; $alert = null; $this->mybb->user['uid'] = (int) $this->mybb->user['uid']; $prefix = TABLE_PREFIX; $alertsQuery = <<<SQL SELECT a.*, u.uid, u.username, u.avatar, u.usergroup, u.displaygroup, t.code FROM {$prefix}alerts a LEFT JOIN {$prefix}users u ON (a.from_user_id = u.uid) INNER JOIN {$prefix}alert_types t ON (a.alert_type_id = t.id) WHERE a.uid = {$this->mybb->user['uid']} AND a.id = {$id}; SQL; $query = $this->db->write_query($alertsQuery); if ($this->db->num_rows($query) > 0) { while ($alertRow = $this->db->fetch_array($query)) { $alertType = $this->alertTypeManager->getByCode($alertRow['code']); if ($alertType != null) { $alert = new MybbStuff_MyAlerts_Entity_Alert($alertRow['uid'], $alertType, $alertRow['object_id']); $alert->setId($alertRow['id']); $alert->setCreatedAt(new DateTime($alertRow['dateline'])); $alert->setUnread((bool) $alertRow['unread']); $alert->setExtraDetails(json_decode($alertRow['extra_details'], true)); $user = array('uid' => (int) $alertRow['uid'], 'username' => $alertRow['username'], 'avatar' => $alertRow['avatar'], 'usergroup' => $alertRow['usergroup'], 'displaygroup' => $alertRow['displaygroup']); $alert->setFromUser($user); } } } return $alert; }
/** * Alert all attached accounts if one of them receives a new pm. * */ function accountswitcher_pm_sent_alert() { global $mybb, $lang, $pm, $eas; if ($mybb->settings['aj_myalerts'] != 1 || !isset($mybb->settings['myalerts_perpage']) || $pm['saveasdraft'] == 1) { return; } if (!isset($lang->aj_newpm_switch_notice_one)) { $lang->load('accountswitcher'); } // Get recipients if (is_array($pm['bcc'])) { $rec_users = array_merge($pm['to'], $pm['bcc']); } else { $rec_users = $pm['to']; } $pm_users = array_map("trim", $rec_users); // Alert Type $alertType = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getByCode('accountswitcher_pm'); $alerts = array(); foreach ($pm_users as $recipient) { $count = 0; $pmuser = get_user_by_username($recipient); $user = get_user($pmuser['uid']); $accounts = $eas->accountswitcher_cache; if (is_array($accounts)) { // If recipient is master account send alerts to attached users foreach ($accounts as $key => $account) { if ($user['uid'] == $account['as_uid']) { ++$count; if ($count > 0) { $alert = new MybbStuff_MyAlerts_Entity_Alert((int) $account['uid'], $alertType, 0); $alert->setExtraDetails(array('uid' => (int) $user['uid'], 'message' => htmlspecialchars_uni($user['username']))); $alerts[] = $alert; } } } } // If there are no users attached to the current account but the current account is attached to another user if ($count == 0 && $user['as_uid'] != 0) { $master = get_user((int) $user['as_uid']); // Get the masters permission $permission = user_permissions($master['uid']); // If the master has permission to use the Enhanced Account Switcher, get the userlist if ($permission['as_canswitch'] == 1) { // If recipient is attached account, alert master account if ($master['uid'] == $user['as_uid']) { $alert = new MybbStuff_MyAlerts_Entity_Alert((int) $master['uid'], $alertType, 0); $alert->setExtraDetails(array('uid' => (int) $user['uid'], 'message' => htmlspecialchars_uni($user['username']))); $alerts[] = $alert; } if (is_array($accounts)) { // If recipient has the same master account, send alert foreach ($accounts as $key => $account) { // Leave recipient out if ($account['uid'] == $user['uid']) { continue; } if ($master['uid'] == $account['as_uid']) { $alert = new MybbStuff_MyAlerts_Entity_Alert((int) $account['uid'], $alertType, 0); $alert->setExtraDetails(array('message' => htmlspecialchars_uni($user['username']))); $alerts[] = $alert; } } } } } // If there are no users attached to the a recipient and the recipient isn't attached to another user if ($count == 0 && $user['as_uid'] == 0) { $alert = new MybbStuff_MyAlerts_Entity_Alert((int) $user['uid'], $alertType, 0); $alert->setExtraDetails(array('message' => htmlspecialchars_uni($user['username']))); $alerts[] = $alert; } if (!empty($alerts)) { MybbStuff_MyAlerts_AlertManager::getInstance()->addAlerts($alerts); } } }
function myalertsrow_subscribed(&$dataHandler) { global $db, $post; $alertType = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getByCode('subscribed_thread'); if ($alertType != null && $alertType->getEnabled()) { $thread = get_thread($post['tid']); $alerts = array(); $post['tid'] = (int) $post['tid']; $post['uid'] = (int) $post['uid']; $thread['lastpost'] = (int) $thread['lastpost']; $query = $db->query("SELECT s.uid FROM " . TABLE_PREFIX . "threadsubscriptions s\n LEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=s.uid)\n WHERE (s.notification = 0 OR s.notification = 1) AND s.tid='{$post['tid']}'\n AND s.uid != '{$post['uid']}'\n AND u.lastactive>'{$thread['lastpost']}'"); while ($poster = $db->fetch_array($query)) { $forumPerms = forum_permissions($thread['fid'], $poster['uid']); if ($forumPerms['canview'] != 0 || $forumPerms['canviewthreads'] != 0) { $alert = new MybbStuff_MyAlerts_Entity_Alert((int) $poster['uid'], $alertType, $thread['tid']); $alert->setExtraDetails(array('thread_title' => $thread['subject'], 'tid' => (int) $thread['tid'])); $alerts[] = $alert; } } if (!empty($alerts)) { MybbStuff_MyAlerts_AlertManager::getInstance()->addAlerts($alerts); } } }
function tyl_recordAlertThankyou() { global $db, $lang, $mybb, $alert, $post, $codename, $prefix; $codename = basename(__FILE__, ".php"); $prefix = 'g33k_' . $codename . '_'; $lang->load("thankyoulike", false, true); if (!$mybb->settings[$prefix . 'enabled'] == "1") { return false; } $uid = (int) $post['uid']; $tid = (int) $post['tid']; $pid = (int) $post['pid']; $subject = htmlspecialchars_uni($post['subject']); $fid = (int) $post['fid']; $alertType = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getByCode('tyl'); if (isset($alertType) && $alertType->getEnabled()) { //check if already alerted $query = $db->simple_select('alerts', 'id', 'object_id = ' . $pid . ' AND uid = ' . $uid . ' AND unread = 1 AND alert_type_id = ' . $alertType->getId() . ''); if ($db->num_rows($query) == 0) { $alert = new MybbStuff_MyAlerts_Entity_Alert($uid, $alertType, $pid, $mybb->user['uid']); $alert->setExtraDetails(array('tid' => $tid, 'pid' => $pid, 't_subject' => $subject, 'fid' => $fid)); MybbStuff_MyAlerts_AlertManager::getInstance()->addAlert($alert); } } }
/** * Changes the author of the post. * * */ function accountswitcher_author_change() { global $mybb, $db, $eas; // Change action if ($mybb->input['action'] == "do_author" && $mybb->request_method == "post" && ($mybb->settings['aj_changeauthor'] == 1 || $mybb->settings['aj_admin_changeauthor'] == 1)) { // Verify incoming POST request verify_post_check($mybb->get_input('my_post_key')); // Get the current author of the post $pid = $mybb->get_input('pid', MyBB::INPUT_INT); $post = get_post($pid); $tid = (int) $post['tid']; $forum = get_forum($post['fid']); // Get the new user if (is_numeric($mybb->input['authorswitch'])) { // Input is uid from change author $newuid = $mybb->get_input('authorswitch', MyBB::INPUT_INT); $newauthor = get_user($newuid); } else { // Input is username from author moderation $newname = htmlspecialchars_uni($mybb->get_input('authorswitch')); $newauthor = get_user_by_username($newname); $newauthor = get_user((int) $newauthor['uid']); } // New user doesn't exist? Redirect back to the post without changes if ($newauthor['uid'] == 0) { redirect(htmlentities($_POST['p_link'])); return; } // Subtract from the users post count // Update the post count if this forum allows post counts to be tracked if ($forum['usepostcounts'] != 0) { $db->write_query("UPDATE " . TABLE_PREFIX . "users SET postnum=postnum-1 WHERE uid='" . (int) $post['uid'] . "'"); $db->write_query("UPDATE " . TABLE_PREFIX . "users SET postnum=postnum+1 WHERE uid='" . (int) $newauthor['uid'] . "'"); } $updated_record = array("uid" => (int) $newauthor['uid'], "username" => $db->escape_string($newauthor['username'])); if ($db->update_query("posts", $updated_record, "pid='" . (int) $post['pid'] . "'")) { global $lang; if (!isset($lang->aj_author_change_log)) { $lang->load("accountswitcher"); } // Update first/last post info, log moderator action, redirect back to the post update_thread_data($tid); update_forum_lastpost((int) $post['fid']); $lang->aj_author_change_log = $lang->sprintf($lang->aj_author_change_log, (int) $post['pid'], htmlspecialchars_uni($post['username']), htmlspecialchars_uni($newauthor['username'])); log_moderator_action(array("pid" => $post['pid']), $lang->aj_author_change_log); // Send pm to old and new author after moderation if ($post['uid'] != $mybb->user['uid'] && $mybb->settings['aj_admin_changeauthor'] == 1) { if ($mybb->settings['aj_authorpm'] == 1) { // Send PM require_once MYBB_ROOT . "inc/datahandlers/pm.php"; $pmhandler = new PMDataHandler(); $lang->aj_author_change_pm_body = $lang->sprintf($lang->aj_author_change_pm_body, htmlspecialchars_uni($mybb->user['username']), $mybb->settings['bburl'] . '/' . htmlentities($_POST['p_link']), htmlspecialchars_uni($post['subject']), htmlspecialchars_uni($post['username']), htmlspecialchars_uni($newauthor['username'])); $subject = $lang->aj_author_change_pm_subject; $body = $lang->aj_author_change_pm_body; $pm = array('subject' => $subject, 'message' => $body, 'icon' => '', 'toid' => array($post['uid'], $newauthor['uid']), 'fromid' => $mybb->user['uid'], "do" => '', "pmid" => ''); $pm['options'] = array('signature' => '0', 'savecopy' => '0', 'disablesmilies' => '0', 'readreceipt' => '0'); $pmhandler->set_data($pm); $valid_pm = $pmhandler->validate_pm(); if ($valid_pm) { $pmhandler->insert_pm(); } } // Show alert if ($mybb->settings['aj_myalerts'] == 1 && isset($mybb->user['myalerts_disabled_alert_types'])) { $alertType = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getByCode('accountswitcher_author'); $alerts = array(); $subject = htmlspecialchars_uni($post['subject']); $alert_old = new MybbStuff_MyAlerts_Entity_Alert((int) $post['uid'], $alertType, $tid); $alert_old->setExtraDetails(array('thread_title' => $subject, 'pid' => $pid, 'tid' => $tid, 'olduser' => htmlspecialchars_uni($post['username']), 'newuser' => htmlspecialchars_uni($newauthor['username']))); $alerts[] = $alert_old; $alert_new = new MybbStuff_MyAlerts_Entity_Alert((int) $newauthor['uid'], $alertType, $tid); $alert_new->setExtraDetails(array('thread_title' => $subject, 'pid' => $pid, 'tid' => $tid, 'olduser' => htmlspecialchars_uni($post['username']), 'newuser' => htmlspecialchars_uni($newauthor['username']))); $alerts[] = $alert_new; if (!empty($alerts)) { MybbStuff_MyAlerts_AlertManager::getInstance()->addAlerts($alerts); } } } $eas->update_accountswitcher_cache(); redirect(htmlentities($_POST['p_link'])); } } else { return; } }
function trader_myalerts($toid, $fid) { $alertType = MybbStuff_MyAlerts_AlertTypeManager::getInstance()->getByCode('tradefeedback'); $alert = new MybbStuff_MyAlerts_Entity_Alert($toid, $alertType, 0); $alert->setExtraDetails(array('toid' => $toid, 'fid' => $fid)); MybbStuff_MyAlerts_AlertManager::getInstance()->addAlert($alert); }