Example #1
0
function mp_announcement_create($userid, $handle, $cookieid, $title, $content, $format, $text, $notify, $categoryid)
{
    /* 
     * Proceeds to create an announcement
     *
     */
    require_once QA_INCLUDE_DIR . 'qa-db-post-create.php';
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'mp-app-users.php';
    // persist data to database
    $postid = qa_db_post_create('AN', null, $userid, $cookieid, qa_remote_ip_address(), $title, $content, $format, null, $notify, $categoryid);
    qa_user_report_action(qa_get_logged_in_userid(), null, null, null, null);
    // update new post with category path hierarchy
    qa_db_posts_calc_category_path($postid);
    // send notifications
    if ($notify && isset($postid)) {
        $category = mp_get_categoryinfo($categoryid);
        $recipients = mp_get_category_userids($categoryid);
        foreach ($recipients as $recipient) {
            // retrieve the user flags
            $userflags = mp_get_user_flags($recipient['userid']);
            // check user flags to determine whether user should be notified or not
            // of the new answer post
            if (!($userflags & QA_USER_FLAGS_NOTIFY_ANNOUNCEMENTS)) {
                qa_send_notification($recipient['userid'], null, null, qa_lang('emails/an_posted_subject'), qa_lang('emails/an_posted_body'), array('^an_handle' => $handle, '^category_title' => $category['title'], '^an_title' => $title, '^an_url' => qa_path('mp-announcements-page', null, qa_opt('site_url'), null, null)));
            }
        }
    }
    // report announcement create event
    qa_report_event('an_post', $userid, $handle, $cookieid, array('postid' => $postid, 'title' => $title, 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $categoryid, 'notify' => $notify));
    return $postid;
}
function qa_answer_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question)
{
    $postid = qa_db_post_create('A', $question['postid'], $userid, isset($userid) ? null : $cookieid, qa_remote_ip_address(), null, $content, $format, null, qa_combine_notify_email($userid, $notify, $email), $question['categoryid']);
    qa_db_posts_calc_category_path($postid);
    if (!$question['hidden']) {
        // don't index answer if parent question is hidden
        qa_post_index($postid, 'A', $question['postid'], null, $text, null);
    }
    qa_db_post_acount_update($question['postid']);
    qa_db_hotness_update($question['postid']);
    qa_db_points_update_ifuser($userid, 'aposts');
    qa_db_acount_update();
    qa_db_unaqcount_update();
    if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid)) {
        require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
        require_once QA_INCLUDE_DIR . 'qa-app-options.php';
        require_once QA_INCLUDE_DIR . 'qa-util-string.php';
        $blockwordspreg = qa_get_block_words_preg();
        $sendtitle = qa_block_words_replace($question['title'], $blockwordspreg);
        $sendtext = qa_block_words_replace($text, $blockwordspreg);
        qa_send_notification($question['userid'], $question['notify'], @$question['handle'], qa_lang('emails/q_answered_subject'), qa_lang('emails/q_answered_body'), array('^a_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $sendtitle, '^a_content' => $sendtext, '^url' => qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $postid))));
    }
    // notify all members of the category about the new post
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'mp-db-users.php';
    require_once QA_INCLUDE_DIR . 'mp-app-users.php';
    // find list of members of the category
    $recipients = mp_get_category_userids(mp_get_categoryid());
    // remove the current user from the list of recipients
    unset($recipients[$userid]);
    // get details for current category
    $currentcategory = mp_get_categoryinfo(mp_get_categoryid());
    foreach ($recipients as $recipient) {
        // retrieve the user flags
        $userflags = mp_get_user_flags($recipient['userid']);
        // check user flags to determine whether user should be notified or not
        // of the new answer post
        if (!($userflags & QA_USER_FLAGS_NOTIFY_ANSWERS)) {
            // for each member, send notification
            qa_send_notification($recipient['userid'], null, null, qa_lang('emails/q_answered_with_category_subject'), qa_lang('emails/q_answered_with_category_body'), array('^a_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $question['title'], '^a_content' => $text, '^url' => qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $postid)), '^category_title' => $currentcategory['title'] . $userflags));
        }
    }
    qa_report_event('a_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email));
    return $postid;
}