Example #1
0
        $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']) {
        error_no_permission();
    }
    if ($mybb->request_method != "post") {
Example #2
0
/**
 * 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);
        }
    }
}
 public function alert_comment($user, $commentor, $cid)
 {
     global $mybb, $db, $settings, $cache, $plugins;
     /* if the admin choosed alertbar, or "MyAlerts or Alert bar" but MyAlerts don't exist, notify the user */
     if ($settings["mpcommentsnotification"] == "alertbar" || $settings["mpcommentsnotification"] == "myalertsoralertbar" && !MyProfileUtils::myalerts_exists()) {
         $update_array = array("mpnewcomments" => $user["mpnewcomments"] + 1);
         $db->update_query("users", $update_array, "uid='{$user['uid']}'", "1");
         $user["mpnewcomments"]++;
     } elseif (($settings["mpcommentsnotification"] == "myalerts" || $settings["mpcommentsnotification"] == "myalertsoralertbar") && MyProfileUtils::myalerts_exists()) {
         $myalerts_plugins = $cache->read('mybbstuff_myalerts_alert_types');
         if (isset($myalerts_plugins[MyProfileCommentsMyAlertsFormatter::alert_type_code()]) && $myalerts_plugins[MyProfileCommentsMyAlertsFormatter::alert_type_code()]['enabled'] == 1) {
             $alertType = MybbStuff_MyAlerts_AlertTypeManager::createInstance($db, $cache)->getByCode(MyProfileCommentsMyAlertsFormatter::alert_type_code());
             $alert = MybbStuff_MyAlerts_Entity_Alert::make($user["uid"], $alertType, null, array("cid" => $cid));
             MybbStuff_MyAlerts_AlertManager::createInstance($mybb, $db, $cache, $plugins, $alertType)->addAlert($alert);
         }
     }
 }
Example #4
0
function myalerts_xmlhttp()
{
    global $mybb, $lang, $templates, $db;
    if (!isset($lang->myalerts)) {
        $lang->load('myalerts');
    }
    myalerts_create_instances();
    if ($mybb->get_input('action') == 'getNewAlerts') {
        header('Content-Type: application/json');
        $newAlerts = MybbStuff_MyAlerts_AlertManager::getInstance()->getAlerts(0, $mybb->settings['myalerts_dropdown_limit']);
        $alertsListing = '';
        $alertsToReturn = array();
        if (is_array($newAlerts) && !empty($newAlerts)) {
            $toMarkRead = array();
            foreach ($newAlerts as $alertObject) {
                $altbg = alt_trow();
                $alert = parse_alert($alertObject);
                $alertsToReturn[] = $alert;
                if (isset($mybb->input['from']) && $mybb->input['from'] == 'header') {
                    if ($alert['message']) {
                        $alertsListing .= eval($templates->render('myalerts_alert_row_popup', true, false));
                    }
                } else {
                    if ($alert['message']) {
                        $alertsListing .= eval($templates->render('myalerts_alert_row', true, false));
                    }
                }
                $toMarkRead[] = $alertObject->getId();
            }
            MybbStuff_MyAlerts_AlertManager::getInstance()->markRead($toMarkRead);
        } else {
            $from = $mybb->get_input('from', MyBB::INPUT_STRING);
            $altbg = alt_trow();
            if (!empty($from) && $from == 'header') {
                $alertsListing = eval($templates->render('myalerts_alert_row_popup_no_alerts', true, false));
            } else {
                $alertsListing = eval($templates->render('myalerts_alert_row_no_alerts', true, false));
            }
        }
        echo json_encode(array('alerts' => $alertsToReturn, 'template' => $alertsListing));
    }
    if ($mybb->get_input('action') == 'myalerts_delete') {
        header('Content-Type: application/json');
        $id = $mybb->get_input('id', MyBB::INPUT_INT);
        $userId = (int) $mybb->user['uid'];
        $toReturn = array();
        if ($id > 0) {
            if (!verify_post_check($mybb->get_input('my_post_key'), true)) {
                $toReturn = array('errors' => array($lang->invalid_post_code));
            } else {
                $db->delete_query('alerts', "id = {$id} AND uid = {$userId}");
                $newAlerts = MybbStuff_MyAlerts_AlertManager::getInstance()->getUnreadAlerts();
                $alertsListing = '';
                $alertsToReturn = array();
                if (is_array($newAlerts) && !empty($newAlerts)) {
                    $toMarkRead = array();
                    foreach ($newAlerts as $alertObject) {
                        $altbg = alt_trow();
                        $alert = parse_alert($alertObject);
                        $alertsToReturn[] = $alert;
                        if (isset($mybb->input['from']) && $mybb->input['from'] == 'header') {
                            if ($alert['message']) {
                                $alertsListing .= eval($templates->render('myalerts_alert_row_popup', true, false));
                            }
                        } else {
                            if ($alert['message']) {
                                $alertsListing .= eval($templates->render('myalerts_alert_row', true, false));
                            }
                        }
                        $toMarkRead[] = $alertObject->getId();
                    }
                    MybbStuff_MyAlerts_AlertManager::getInstance()->markRead($toMarkRead);
                } else {
                    $from = $mybb->get_input('from', MyBB::INPUT_STRING);
                    $altbg = alt_trow();
                    if (!empty($from) && $from == 'header') {
                        $alertsListing = eval($templates->render('myalerts_alert_row_popup_no_alerts', true, false));
                    } else {
                        $alertsListing = eval($templates->render('myalerts_alert_row_no_alerts', true, false));
                    }
                }
                $toReturn = array('success' => true, 'template' => $alertsListing);
            }
        } else {
            $toReturn = array('errors' => array($lang->myalerts_error_alert_not_found));
        }
        echo json_encode($toReturn);
    }
    if ($mybb->input['action'] == 'getNumUnreadAlerts') {
        echo MybbStuff_MyAlerts_AlertManager::getInstance()->getNumUnreadAlerts();
    }
}
Example #5
0
/**
 * View all alerts.
 *
 * @param MyBB       $mybb      MyBB core object.
 * @param MyLanguage $lang      Language object.
 * @param templates  $templates Template manager.
 * @param array      $theme     Details about the current theme.
 */
function myalerts_view_alerts($mybb, $lang, $templates, $theme)
{
    if (MybbStuff_MyAlerts_AlertManager::getInstance() === false) {
        myalerts_create_instances();
    }
    $alerts = MybbStuff_MyAlerts_AlertManager::getInstance()->getAlerts(0, 10);
    if (!isset($lang->myalerts)) {
        $lang->load('myalerts');
    }
    add_breadcrumb($lang->myalerts_page_title, 'alerts.php?action=alerts');
    require_once __DIR__ . '/inc/functions_user.php';
    usercp_menu();
    $numAlerts = MybbStuff_MyAlerts_AlertManager::getInstance()->getNumAlerts();
    $page = (int) $mybb->input['page'];
    $pages = ceil($numAlerts / $mybb->settings['myalerts_perpage']);
    if ($page > $pages or $page <= 0) {
        $page = 1;
    }
    if ($page) {
        $start = ($page - 1) * $mybb->settings['myalerts_perpage'];
    } else {
        $start = 0;
        $page = 1;
    }
    $multipage = multipage($numAlerts, $mybb->settings['myalerts_perpage'], $page, "alerts.php");
    $alertsList = MybbStuff_MyAlerts_AlertManager::getInstance()->getAlerts($start);
    $readAlerts = array();
    if (is_array($alertsList) && !empty($alertsList)) {
        foreach ($alertsList as $alertObject) {
            $altbg = alt_trow();
            $alert = parse_alert($alertObject);
            if ($alert['message']) {
                eval("\$alertsListing .= \"" . $templates->get('myalerts_alert_row') . "\";");
            }
            $readAlerts[] = $alert['id'];
        }
    } else {
        $altbg = 'trow1';
        eval("\$alertsListing = \"" . $templates->get('myalerts_alert_row_no_alerts') . "\";");
    }
    MybbStuff_MyAlerts_AlertManager::getInstance()->markRead($readAlerts);
    global $headerinclude, $header, $footer, $usercpnav;
    $content = '';
    eval("\$content = \"" . $templates->get('myalerts_page') . "\";");
    output_page($content);
}
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);
        }
    }
}
Example #7
0
/**
 * 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;
    }
}
Example #8
0
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);
}