Ejemplo n.º 1
0
function qa_question_set_selchildid($userid, $handle, $cookieid, $oldquestion, $selchildid, $answers)
{
    $oldselchildid = $oldquestion['selchildid'];
    qa_db_post_set_selchildid($oldquestion['postid'], isset($selchildid) ? $selchildid : null);
    qa_db_points_update_ifuser($oldquestion['userid'], 'aselects');
    if (isset($oldselchildid)) {
        if (isset($answers[$oldselchildid])) {
            qa_db_points_update_ifuser($answers[$oldselchildid]['userid'], 'aselecteds');
            qa_report_event('a_unselect', $userid, $handle, $cookieid, array('parentid' => $oldquestion['postid'], 'postid' => $oldselchildid));
        }
    }
    if (isset($selchildid)) {
        $answer = $answers[$selchildid];
        qa_db_points_update_ifuser($answer['userid'], 'aselecteds');
        if (isset($answer['notify']) && !qa_post_is_by_user($answer, $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';
            require_once QA_INCLUDE_DIR . 'qa-app-format.php';
            $blockwordspreg = qa_get_block_words_preg();
            $sendtitle = qa_block_words_replace($oldquestion['title'], $blockwordspreg);
            $sendcontent = qa_viewer_text($answer['content'], $answer['format'], array('blockwordspreg' => $blockwordspreg));
            qa_send_notification($answer['userid'], $answer['notify'], @$answer['handle'], qa_lang('emails/a_selected_subject'), qa_lang('emails/a_selected_body'), array('^s_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => $sendtitle, '^a_content' => $sendcontent, '^url' => qa_path(qa_q_request($oldquestion['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor('A', $selchildid))));
        }
        qa_report_event('a_select', $userid, $handle, $cookieid, array('parentid' => $oldquestion['postid'], 'postid' => $selchildid));
    }
}
Ejemplo n.º 2
0
 function process_event($event, $userid, $handle, $cookieid, $params)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
     require_once QA_INCLUDE_DIR . 'qa-app-format.php';
     require_once QA_INCLUDE_DIR . 'qa-util-string.php';
     switch ($event) {
         case 'q_post':
             $followanswer = @$params['followanswer'];
             $sendhandle = isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
             if (isset($followanswer['notify']) && !qa_post_is_by_user($followanswer, $userid, $cookieid)) {
                 $blockwordspreg = qa_get_block_words_preg();
                 $sendtext = qa_viewer_text($followanswer['content'], $followanswer['format'], array('blockwordspreg' => $blockwordspreg));
                 qa_send_notification($followanswer['userid'], $followanswer['notify'], @$followanswer['handle'], qa_lang('emails/a_followed_subject'), qa_lang('emails/a_followed_body'), array('^q_handle' => $sendhandle, '^q_title' => qa_block_words_replace($params['title'], $blockwordspreg), '^a_content' => $sendtext, '^url' => qa_q_path($params['postid'], $params['title'], true)));
             }
             if (qa_opt('notify_admin_q_post')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/q_posted_subject'), qa_lang('emails/q_posted_body'), array('^q_handle' => $sendhandle, '^q_title' => $params['title'], '^q_content' => $params['text'], '^url' => qa_q_path($params['postid'], $params['title'], true)));
             }
             break;
         case 'a_post':
             $question = $params['parent'];
             if (isset($question['notify']) && !qa_post_is_by_user($question, $userid, $cookieid)) {
                 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 : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous')), '^q_title' => $question['title'], '^a_content' => qa_block_words_replace($params['text'], qa_get_block_words_preg()), '^url' => qa_q_path($question['postid'], $question['title'], true, 'A', $params['postid'])));
             }
             break;
         case 'c_post':
             $parent = $params['parent'];
             $question = $params['question'];
             $senttoemail = array();
             // to ensure each user or email gets only one notification about an added comment
             $senttouserid = array();
             switch ($parent['basetype']) {
                 case 'Q':
                     $subject = qa_lang('emails/q_commented_subject');
                     $body = qa_lang('emails/q_commented_body');
                     $context = $parent['title'];
                     break;
                 case 'A':
                     $subject = qa_lang('emails/a_commented_subject');
                     $body = qa_lang('emails/a_commented_body');
                     $context = qa_viewer_text($parent['content'], $parent['format']);
                     break;
             }
             $blockwordspreg = qa_get_block_words_preg();
             $sendhandle = isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : qa_lang('main/anonymous'));
             $sendcontext = qa_block_words_replace($context, $blockwordspreg);
             $sendtext = qa_block_words_replace($params['text'], $blockwordspreg);
             $sendurl = qa_q_path($question['postid'], $question['title'], true, 'C', $params['postid']);
             if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
                 $senduserid = $parent['userid'];
                 $sendemail = @$parent['notify'];
                 if (qa_email_validate($sendemail)) {
                     $senttoemail[$sendemail] = true;
                 } elseif (isset($senduserid)) {
                     $senttouserid[$senduserid] = true;
                 }
                 qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
             }
             foreach ($params['thread'] as $comment) {
                 if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
                     $senduserid = $comment['userid'];
                     $sendemail = @$comment['notify'];
                     if (qa_email_validate($sendemail)) {
                         if (@$senttoemail[$sendemail]) {
                             continue;
                         }
                         $senttoemail[$sendemail] = true;
                     } elseif (isset($senduserid)) {
                         if (@$senttouserid[$senduserid]) {
                             continue;
                         }
                         $senttouserid[$senduserid] = true;
                     }
                     qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
                 }
             }
             break;
         case 'q_queue':
         case 'q_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'q_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'q_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldquestion['name']) ? $oldquestion['name'] : qa_lang('main/anonymous'))), '^p_context' => trim(@$params['title'] . "\n\n" . $params['text']), '^url' => qa_q_path($params['postid'], $params['title'], true), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'a_queue':
         case 'a_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'a_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'a_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous'))), '^p_context' => $params['text'], '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'c_queue':
         case 'c_requeue':
             if (qa_opt('moderate_notify_admin')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, $event == 'c_requeue' ? qa_lang('emails/remoderate_subject') : qa_lang('emails/moderate_subject'), $event == 'c_requeue' ? qa_lang('emails/remoderate_body') : qa_lang('emails/moderate_body'), array('^p_handle' => isset($handle) ? $handle : (strlen($params['name']) ? $params['name'] : (strlen(@$oldcomment['name']) ? $oldcomment['name'] : (strlen(@$oldanswer['name']) ? $oldanswer['name'] : qa_lang('main/anonymous')))), '^p_context' => $params['text'], '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, 'C', $params['postid']), '^a_url' => qa_path_absolute('admin/moderate')));
             }
             break;
         case 'q_flag':
         case 'a_flag':
         case 'c_flag':
             $flagcount = $params['flagcount'];
             $oldpost = $params['oldpost'];
             $notifycount = $flagcount - qa_opt('flagging_notify_first');
             if ($notifycount >= 0 && $notifycount % qa_opt('flagging_notify_every') == 0) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/flagged_subject'), qa_lang('emails/flagged_body'), array('^p_handle' => isset($oldpost['handle']) ? $oldpost['handle'] : (strlen($oldpost['name']) ? $oldpost['name'] : qa_lang('main/anonymous')), '^flags' => $flagcount == 1 ? qa_lang_html_sub('main/1_flag', '1', '1') : qa_lang_html_sub('main/x_flags', $flagcount), '^p_context' => trim(@$oldpost['title'] . "\n\n" . qa_viewer_text($oldpost['content'], $oldpost['format'])), '^url' => qa_q_path($params['questionid'], $params['question']['title'], true, $oldpost['basetype'], $oldpost['postid']), '^a_url' => qa_path_absolute('admin/flagged')));
             }
             break;
         case 'a_select':
             $answer = $params['answer'];
             if (isset($answer['notify']) && !qa_post_is_by_user($answer, $userid, $cookieid)) {
                 $blockwordspreg = qa_get_block_words_preg();
                 $sendcontent = qa_viewer_text($answer['content'], $answer['format'], array('blockwordspreg' => $blockwordspreg));
                 qa_send_notification($answer['userid'], $answer['notify'], @$answer['handle'], qa_lang('emails/a_selected_subject'), qa_lang('emails/a_selected_body'), array('^s_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^q_title' => qa_block_words_replace($params['parent']['title'], $blockwordspreg), '^a_content' => $sendcontent, '^url' => qa_q_path($params['parentid'], $params['parent']['title'], true, 'A', $params['postid'])));
             }
             break;
         case 'u_register':
             if (qa_opt('register_notify_admin')) {
                 qa_send_notification(null, qa_opt('feedback_email'), null, qa_lang('emails/u_registered_subject'), qa_opt('moderate_users') ? qa_lang('emails/u_to_approve_body') : qa_lang('emails/u_registered_body'), array('^u_handle' => $handle, '^url' => qa_path_absolute('user/' . $handle), '^a_url' => qa_path_absolute('admin/approve')));
             }
             break;
         case 'u_level':
             if ($params['level'] >= QA_USER_LEVEL_APPROVED && $params['oldlevel'] < QA_USER_LEVEL_APPROVED) {
                 qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/u_approved_subject'), qa_lang('emails/u_approved_body'), array('^url' => qa_path_absolute('user/' . $params['handle'])));
             }
             break;
         case 'u_wall_post':
             if ($userid != $params['userid']) {
                 $blockwordspreg = qa_get_block_words_preg();
                 qa_send_notification($params['userid'], null, $params['handle'], qa_lang('emails/wall_post_subject'), qa_lang('emails/wall_post_body'), array('^f_handle' => isset($handle) ? $handle : qa_lang('main/anonymous'), '^post' => qa_block_words_replace($params['text'], $blockwordspreg), '^url' => qa_path_absolute('user/' . $params['handle'], null, 'wall')));
             }
             break;
     }
 }
Ejemplo n.º 3
0
function qa_page_q_add_a_submit($question, $answers, $usecaptcha, &$in, &$errors)
{
    $in = array('name' => qa_post_text('a_name'), 'notify' => qa_post_text('a_notify') !== null, 'email' => qa_post_text('a_email'), 'queued' => qa_user_moderation_reason(qa_user_level_for_post($question)) !== false);
    qa_get_post_content('a_editor', 'a_content', $in['editor'], $in['content'], $in['format'], $in['text']);
    $errors = array();
    if (!qa_check_form_security_code('answer-' . $question['postid'], qa_post_text('code'))) {
        $errors['content'] = qa_lang_html('misc/form_security_again');
    } else {
        // call any filter plugins
        $filtermodules = qa_load_modules_with('filter', 'filter_answer');
        foreach ($filtermodules as $filtermodule) {
            $oldin = $in;
            $filtermodule->filter_answer($in, $errors, $question, null);
            qa_update_post_text($in, $oldin);
        }
        // check CAPTCHA
        if ($usecaptcha) {
            qa_captcha_validate_post($errors);
        }
        // check for duplicate posts
        if (empty($errors)) {
            $testwords = implode(' ', qa_string_to_words($in['content']));
            foreach ($answers as $answer) {
                if (!$answer['hidden']) {
                    if (implode(' ', qa_string_to_words($answer['content'])) == $testwords) {
                        $errors['content'] = qa_lang_html('question/duplicate_content');
                    }
                }
            }
        }
        $userid = qa_get_logged_in_userid();
        // if this is an additional answer, check we can add it
        if (empty($errors) && !qa_opt('allow_multi_answers')) {
            foreach ($answers as $answer) {
                if (qa_post_is_by_user($answer, $userid, qa_cookie_get())) {
                    $errors[] = '';
                    break;
                }
            }
        }
        // create the answer
        if (empty($errors)) {
            $handle = qa_get_logged_in_handle();
            $cookieid = isset($userid) ? qa_cookie_get() : qa_cookie_get_create();
            // create a new cookie if necessary
            $answerid = qa_answer_create($userid, $handle, $cookieid, $in['content'], $in['format'], $in['text'], $in['notify'], $in['email'], $question, $in['queued'], $in['name']);
            return $answerid;
        }
    }
    return null;
}
Ejemplo n.º 4
0
function qa_page_q_post_rules($post, $parentpost = null, $siblingposts = null, $childposts = null)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    $userid = qa_get_logged_in_userid();
    $cookieid = qa_cookie_get();
    $rules['isbyuser'] = qa_post_is_by_user($post, $userid, $cookieid);
    $rules['queued'] = substr($post['type'], 1) == '_QUEUED';
    $rules['closed'] = $post['basetype'] == 'Q' && (isset($post['closedbyid']) || isset($post['selchildid']) && qa_opt('do_close_on_select'));
    //	Cache some responses to the user permission checks
    $permiterror_post_q = qa_user_permit_error('permit_post_q');
    $permiterror_post_a = qa_user_permit_error('permit_post_a');
    $permiterror_post_c = qa_user_permit_error('permit_post_c');
    $permiterror_edit = qa_user_permit_error($post['basetype'] == 'Q' ? 'permit_edit_q' : ($post['basetype'] == 'A' ? 'permit_edit_a' : 'permit_edit_c'));
    $permiterror_retagcat = qa_user_permit_error('permit_retag_cat');
    $permiterror_hide_show = qa_user_permit_error($rules['isbyuser'] ? null : 'permit_hide_show');
    $permiterror_close_open = qa_user_permit_error($rules['isbyuser'] ? null : 'permit_close_q');
    $permiterror_moderate = qa_user_permit_error('permit_moderate');
    //	General permissions
    $rules['authorlast'] = !isset($post['lastuserid']) || $post['lastuserid'] === $post['userid'];
    $rules['viewable'] = $post['hidden'] ? !$permiterror_hide_show : ($rules['queued'] ? $rules['isbyuser'] || !$permiterror_moderate : true);
    //	Answer, comment and edit might show the button even if the user still needs to do something (e.g. log in)
    $rules['answerbutton'] = $post['type'] == 'Q' && $permiterror_post_a != 'level' && !$rules['closed'] && (qa_opt('allow_self_answer') || !$rules['isbyuser']);
    $rules['commentbutton'] = ($post['type'] == 'Q' || $post['type'] == 'A') && $permiterror_post_c != 'level' && qa_opt($post['type'] == 'Q' ? 'comment_on_qs' : 'comment_on_as');
    $rules['commentable'] = $rules['commentbutton'] && !$permiterror_post_c;
    $rules['editbutton'] = !$post['hidden'] && ($rules['isbyuser'] || $permiterror_edit != 'level' && !$rules['queued']) && !$rules['closed'];
    $rules['editable'] = $rules['editbutton'] && ($rules['isbyuser'] || !$permiterror_edit);
    $rules['retagcatbutton'] = $post['basetype'] == 'Q' && (qa_using_tags() || qa_using_categories()) && !$post['hidden'] && ($rules['isbyuser'] || $permiterror_retagcat != 'level');
    $rules['retagcatable'] = $rules['retagcatbutton'] && ($rules['isbyuser'] || !$permiterror_retagcat);
    if ($rules['editbutton'] && $rules['retagcatbutton']) {
        // only show one button since they lead to the same form
        if ($rules['retagcatable'] && !$rules['editable']) {
            $rules['editbutton'] = false;
        } else {
            $rules['retagcatbutton'] = false;
        }
    }
    $rules['aselectable'] = $post['type'] == 'Q' && !qa_user_permit_error($rules['isbyuser'] ? null : 'permit_select_a');
    $rules['flagbutton'] = qa_opt('flagging_of_posts') && !$rules['isbyuser'] && !$post['hidden'] && !$rules['queued'] && !@$post['userflag'] && qa_user_permit_error('permit_flag') != 'level';
    $rules['flagtohide'] = $rules['flagbutton'] && !qa_user_permit_error('permit_flag') && $post['flagcount'] + 1 >= qa_opt('flagging_hide_after');
    $rules['unflaggable'] = @$post['userflag'] && !$post['hidden'];
    $rules['clearflaggable'] = $post['flagcount'] >= (@$post['userflag'] ? 2 : 1) && !qa_user_permit_error('permit_hide_show');
    //	Other actions only show the button if it's immediately possible
    $notclosedbyother = !($rules['closed'] && isset($post['closedbyid']) && !$rules['authorlast']);
    $nothiddenbyother = !($post['hidden'] && !$rules['authorlast']);
    $rules['closeable'] = qa_opt('allow_close_questions') && $post['type'] == 'Q' && !$rules['closed'] && !$permiterror_close_open;
    $rules['reopenable'] = $rules['closed'] && isset($post['closedbyid']) && !$permiterror_close_open && !$post['hidden'] && ($notclosedbyother || !qa_user_permit_error('permit_close_q'));
    // cannot reopen a question if it's been hidden, or if it was closed by someone else and you don't have global closing permissions
    $rules['moderatable'] = $rules['queued'] && !$permiterror_moderate;
    $rules['hideable'] = !$post['hidden'] && ($rules['isbyuser'] || !$rules['queued']) && !$permiterror_hide_show && ($notclosedbyother || !qa_user_permit_error('permit_hide_show'));
    // cannot hide a question if it was closed by someone else and you don't have global hiding permissions
    $rules['reshowable'] = $post['hidden'] && !$permiterror_hide_show && !qa_user_moderation_reason() && ($nothiddenbyother && !$post['flagcount'] || !qa_user_permit_error('permit_hide_show'));
    // cannot reshow a question if it was hidden by someone else, or if it has flags - unless you have global hiding permissions
    $rules['deleteable'] = $post['hidden'] && !qa_user_permit_error('permit_delete_hidden');
    $rules['claimable'] = !isset($post['userid']) && isset($userid) && strlen(@$post['cookieid']) && strcmp(@$post['cookieid'], $cookieid) == 0 && !($post['basetype'] == 'Q' ? $permiterror_post_q : ($post['basetype'] == 'A' ? $permiterror_post_a : $permiterror_post_c));
    $rules['followable'] = $post['type'] == 'A' ? qa_opt('follow_on_as') : false;
    //	Check for claims that could break rules about self answering and mulltiple answers
    if ($rules['claimable'] && $post['basetype'] == 'A') {
        if (!qa_opt('allow_self_answer') && isset($parentpost) && qa_post_is_by_user($parentpost, $userid, $cookieid)) {
            $rules['claimable'] = false;
        }
        if (isset($siblingposts) && !qa_opt('allow_multi_answers')) {
            foreach ($siblingposts as $siblingpost) {
                if ($siblingpost['parentid'] == $post['parentid'] && $siblingpost['basetype'] == 'A' && qa_post_is_by_user($siblingpost, $userid, $cookieid)) {
                    $rules['claimable'] = false;
                }
            }
        }
    }
    //	Now make any changes based on the child posts
    if (isset($childposts)) {
        foreach ($childposts as $childpost) {
            if ($childpost['parentid'] == $post['postid'] && ($childpost['basetype'] == 'A' || $childpost['basetype'] == 'C')) {
                $rules['deleteable'] = false;
                if ($childpost['basetype'] == 'A' && qa_post_is_by_user($childpost, $userid, $cookieid)) {
                    if (!qa_opt('allow_multi_answers')) {
                        $rules['answerbutton'] = false;
                    }
                    if (!qa_opt('allow_self_answer')) {
                        $rules['claimable'] = false;
                    }
                }
            }
        }
    }
    //	Return the resulting rules
    return $rules;
}
Ejemplo n.º 5
0
function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $dummy, $options)
{
    if (qa_to_override(__FUNCTION__)) {
        $args = func_get_args();
        return qa_call_override(__FUNCTION__, $args);
    }
    require_once QA_INCLUDE_DIR . 'app/updates.php';
    $fields = qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, $options);
    switch ($question['obasetype'] . '-' . @$question['oupdatetype']) {
        case 'Q-':
            $langstring = 'main/asked';
            break;
        case 'Q-' . QA_UPDATE_VISIBLE:
            if (@$question['opersonal']) {
                $langstring = $question['hidden'] ? 'misc/your_q_hidden' : 'misc/your_q_reshown';
            } else {
                $langstring = $question['hidden'] ? 'main/hidden' : 'main/reshown';
            }
            break;
        case 'Q-' . QA_UPDATE_CLOSED:
            if (@$question['opersonal']) {
                $langstring = isset($question['closedbyid']) ? 'misc/your_q_closed' : 'misc/your_q_reopened';
            } else {
                $langstring = isset($question['closedbyid']) ? 'main/closed' : 'main/reopened';
            }
            break;
        case 'Q-' . QA_UPDATE_TAGS:
            $langstring = @$question['opersonal'] ? 'misc/your_q_retagged' : 'main/retagged';
            break;
        case 'Q-' . QA_UPDATE_CATEGORY:
            $langstring = @$question['opersonal'] ? 'misc/your_q_recategorized' : 'main/recategorized';
            break;
        case 'A-':
            $langstring = @$question['opersonal'] ? 'misc/your_q_answered' : 'main/answered';
            break;
        case 'A-' . QA_UPDATE_SELECTED:
            $langstring = @$question['opersonal'] ? 'misc/your_a_selected' : 'main/answer_selected';
            break;
        case 'A-' . QA_UPDATE_VISIBLE:
            if (@$question['opersonal']) {
                $langstring = $question['ohidden'] ? 'misc/your_a_hidden' : 'misc/your_a_reshown';
            } else {
                $langstring = $question['ohidden'] ? 'main/hidden' : 'main/answer_reshown';
            }
            break;
        case 'A-' . QA_UPDATE_CONTENT:
            $langstring = @$question['opersonal'] ? 'misc/your_a_edited' : 'main/answer_edited';
            break;
        case 'Q-' . QA_UPDATE_FOLLOWS:
            $langstring = @$question['opersonal'] ? 'misc/your_a_questioned' : 'main/asked_related_q';
            break;
        case 'C-':
            $langstring = 'main/commented';
            break;
        case 'C-' . QA_UPDATE_C_FOR_Q:
            $langstring = @$question['opersonal'] ? 'misc/your_q_commented' : 'main/commented';
            break;
        case 'C-' . QA_UPDATE_C_FOR_A:
            $langstring = @$question['opersonal'] ? 'misc/your_a_commented' : 'main/commented';
            break;
        case 'C-' . QA_UPDATE_FOLLOWS:
            $langstring = @$question['opersonal'] ? 'misc/your_c_followed' : 'main/commented';
            break;
        case 'C-' . QA_UPDATE_TYPE:
            $langstring = @$question['opersonal'] ? 'misc/your_c_moved' : 'main/comment_moved';
            break;
        case 'C-' . QA_UPDATE_VISIBLE:
            if (@$question['opersonal']) {
                $langstring = $question['ohidden'] ? 'misc/your_c_hidden' : 'misc/your_c_reshown';
            } else {
                $langstring = $question['ohidden'] ? 'main/hidden' : 'main/comment_reshown';
            }
            break;
        case 'C-' . QA_UPDATE_CONTENT:
            $langstring = @$question['opersonal'] ? 'misc/your_c_edited' : 'main/comment_edited';
            break;
        case 'Q-' . QA_UPDATE_CONTENT:
        default:
            $langstring = @$question['opersonal'] ? 'misc/your_q_edited' : 'main/edited';
            break;
    }
    $fields['what'] = qa_lang_html($langstring);
    if (@$question['opersonal']) {
        $fields['what_your'] = true;
    }
    if ($question['obasetype'] != 'Q' || @$question['oupdatetype'] == QA_UPDATE_FOLLOWS) {
        $fields['what_url'] = qa_q_path_html($question['postid'], $question['title'], false, $question['obasetype'], $question['opostid']);
    }
    if (@$options['contentview'] && !empty($question['ocontent'])) {
        $viewer = qa_load_viewer($question['ocontent'], $question['oformat']);
        $fields['content'] = $viewer->get_html($question['ocontent'], $question['oformat'], array('blockwordspreg' => @$options['blockwordspreg'], 'showurllinks' => @$options['showurllinks'], 'linksnewwindow' => @$options['linksnewwindow']));
    }
    if (@$options['whenview']) {
        $fields['when'] = qa_when_to_html($question['otime'], @$options['fulldatedays']);
    }
    if (@$options['whoview']) {
        $isbyuser = qa_post_is_by_user(array('userid' => $question['ouserid'], 'cookieid' => @$question['ocookieid']), $userid, $cookieid);
        $fields['who'] = qa_who_to_html($isbyuser, $question['ouserid'], $usershtml, @$options['ipview'] ? @$question['oip'] : null, false, @$question['oname']);
        if (isset($question['opoints'])) {
            if (@$options['pointsview']) {
                $fields['who']['points'] = $question['opoints'] == 1 ? qa_lang_html_sub_split('main/1_point', '1', '1') : qa_lang_html_sub_split('main/x_points', qa_html(number_format($question['opoints'])));
            }
            if (isset($options['pointstitle'])) {
                $fields['who']['title'] = qa_get_points_title_html($question['opoints'], $options['pointstitle']);
            }
        }
        if (isset($question['olevel'])) {
            $fields['who']['level'] = qa_html(qa_user_level_string($question['olevel']));
        }
    }
    unset($fields['flags']);
    if (@$options['flagsview'] && @$question['oflagcount']) {
        $fields['flags'] = $question['oflagcount'] == 1 ? qa_lang_html_sub_split('main/1_flag', '1', '1') : qa_lang_html_sub_split('main/x_flags', $question['oflagcount']);
    }
    unset($fields['avatar']);
    if (@$options['avatarsize'] > 0) {
        if (QA_FINAL_EXTERNAL_USERS) {
            $fields['avatar'] = qa_get_external_avatar_html($question['ouserid'], $options['avatarsize'], false);
        } else {
            $fields['avatar'] = qa_get_user_avatar_html($question['oflags'], $question['oemail'], $question['ohandle'], $question['oavatarblobid'], $question['oavatarwidth'], $question['oavatarheight'], $options['avatarsize']);
        }
    }
    return $fields;
}
Ejemplo n.º 6
0
 function do_hide($data, $post)
 {
     $userid = qa_get_logged_in_userid();
     $cookieid = qa_cookie_get();
     $userlevel = qa_user_level_for_post($post);
     $postid = (int) @$data['action_id'];
     $rules['closed'] = $post['basetype'] == 'Q' && (isset($post['closedbyid']) || isset($post['selchildid']) && qa_opt('do_close_on_select'));
     $rules['isbyuser'] = qa_post_is_by_user($post, $userid, $cookieid);
     $rules['queued'] = substr($post['type'], 1) == '_QUEUED';
     $rules['authorlast'] = !isset($post['lastuserid']) || $post['lastuserid'] === $post['userid'];
     $notclosedbyother = !($rules['closed'] && isset($post['closedbyid']) && !$rules['authorlast']);
     $nothiddenbyother = !($post['hidden'] && !$rules['authorlast']);
     $permiterror_hide_show = qa_user_permit_error($rules['isbyuser'] ? null : 'permit_hide_show', null, $userlevel);
     $rules['reshowimmed'] = $post['hidden'] && !qa_user_permit_error('permit_hide_show', null, $userlevel);
     // means post can be reshown immediately without checking whether it needs moderation
     $hideable = !$post['hidden'] && ($rules['isbyuser'] || !$rules['queued']) && !$permiterror_hide_show && ($notclosedbyother || !qa_user_permit_error('permit_hide_show', null, $userlevel));
     $showable = $post['hidden'] && !$permiterror_hide_show && ($rules['reshowimmed'] || $nothiddenbyother && !$post['flagcount']);
     // cannot reshow a question if it was hidden by someone else, or if it has flags - unless you have global hide/show permissions
     require_once QA_INCLUDE_DIR . 'qa-app-posts.php';
     if ($hideable && isset($data['action_data']['hide'])) {
         // hide allowed
         qa_post_set_hidden($postid, true, $userid);
     } else {
         if ($showable && !isset($data['action_data']['hide'])) {
             // reshow allowed
             qa_post_set_hidden($postid, false, $userid);
         } else {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 7
0
function qa_comment_create($userid, $handle, $cookieid, $content, $format, $text, $notify, $email, $question, $answer, $commentsfollows)
{
    require_once QA_INCLUDE_DIR . 'qa-app-emails.php';
    require_once QA_INCLUDE_DIR . 'qa-app-options.php';
    require_once QA_INCLUDE_DIR . 'qa-app-format.php';
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    $parent = isset($answer) ? $answer : $question;
    $postid = qa_db_post_create('C', $parent['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'] || @$answer['hidden'])) {
        // don't index comment if parent or parent of parent is hidden
        qa_post_index($postid, 'C', $question['postid'], null, $text, null);
    }
    qa_db_points_update_ifuser($userid, 'cposts');
    qa_db_ccount_update();
    //	$senttoemail and $senttouserid ensure each user or email gets only one notification about an added comment,
    //	even if they have several previous comments in the same thread and asked for notifications for the parent.
    //	Still, if a person posted some comments as a registered user and some others anonymously,
    //	they could get two emails about a subsequent comment. Shouldn't be much of a problem in practice.
    $senttoemail = array();
    $senttouserid = array();
    switch ($parent['basetype']) {
        case 'Q':
            $subject = qa_lang('emails/q_commented_subject');
            $body = qa_lang('emails/q_commented_body');
            $context = $parent['title'];
            break;
        case 'A':
            $subject = qa_lang('emails/a_commented_subject');
            $body = qa_lang('emails/a_commented_body');
            $context = qa_viewer_text($parent['content'], $parent['format']);
            break;
    }
    $blockwordspreg = qa_get_block_words_preg();
    $sendhandle = isset($handle) ? $handle : qa_lang('main/anonymous');
    $sendcontext = qa_block_words_replace($context, $blockwordspreg);
    $sendtext = qa_block_words_replace($text, $blockwordspreg);
    $sendtitle = qa_block_words_replace($question['title'], $blockwordspreg);
    $sendurl = qa_path(qa_q_request($question['postid'], $sendtitle), null, qa_opt('site_url'), null, qa_anchor($parent['basetype'], $parent['postid']));
    if (isset($parent['notify']) && !qa_post_is_by_user($parent, $userid, $cookieid)) {
        $senduserid = $parent['userid'];
        $sendemail = @$parent['notify'];
        if (qa_email_validate($sendemail)) {
            $senttoemail[$sendemail] = true;
        } elseif (isset($senduserid)) {
            $senttouserid[$senduserid] = true;
        }
        qa_send_notification($senduserid, $sendemail, @$parent['handle'], $subject, $body, array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
    }
    foreach ($commentsfollows as $comment) {
        if ($comment['basetype'] == 'C' && $comment['parentid'] == $parent['postid'] && !$comment['hidden']) {
            // find just those for this parent
            if (isset($comment['notify']) && !qa_post_is_by_user($comment, $userid, $cookieid)) {
                $senduserid = $comment['userid'];
                $sendemail = @$comment['notify'];
                if (qa_email_validate($sendemail)) {
                    if (@$senttoemail[$sendemail]) {
                        continue;
                    }
                    $senttoemail[$sendemail] = true;
                } elseif (isset($senduserid)) {
                    if (@$senttouserid[$senduserid]) {
                        continue;
                    }
                    $senttouserid[$senduserid] = true;
                }
                qa_send_notification($senduserid, $sendemail, @$comment['handle'], qa_lang('emails/c_commented_subject'), qa_lang('emails/c_commented_body'), array('^c_handle' => $sendhandle, '^c_context' => $sendcontext, '^c_content' => $sendtext, '^url' => $sendurl));
            }
        }
    }
    qa_report_event('c_post', $userid, $handle, $cookieid, array('postid' => $postid, 'parentid' => $parent['postid'], 'parenttype' => $parent['basetype'], 'questionid' => $question['postid'], 'content' => $content, 'format' => $format, 'text' => $text, 'categoryid' => $question['categoryid'], 'notify' => $notify, 'email' => $email));
    return $postid;
}
Ejemplo n.º 8
0
function qa_page_q_post_rules(&$post)
{
    global $qa_login_userid, $qa_cookieid;
    $post['isbyuser'] = qa_post_is_by_user($post, $qa_login_userid, $qa_cookieid);
    //	Cache some responses to the user permission checks
    $permiterror_post_q = qa_user_permit_error('permit_post_q');
    $permiterror_post_a = qa_user_permit_error('permit_post_a');
    $permiterror_post_c = qa_user_permit_error('permit_post_c');
    $permiterror_edit = qa_user_permit_error($post['basetype'] == 'Q' ? 'permit_edit_q' : ($post['basetype'] == 'A' ? 'permit_edit_a' : 'permit_edit_c'));
    $permiterror_hide_show = qa_user_permit_error($post['isbyuser'] ? null : 'permit_hide_show');
    //	General permissions
    $post['authorlast'] = $post['lastuserid'] === $post['userid'] || !isset($post['lastuserid']);
    $post['viewable'] = !$post['hidden'] || !$permiterror_hide_show;
    //	Answer, comment and edit might show the button even if the user still needs to do something (e.g. log in)
    $post['answerbutton'] = $post['type'] == 'Q' && $permiterror_post_a != 'level';
    $post['commentbutton'] = ($post['type'] == 'Q' || $post['type'] == 'A') && $permiterror_post_c != 'level' && qa_opt($post['type'] == 'Q' ? 'comment_on_qs' : 'comment_on_as');
    $post['commentable'] = $post['commentbutton'] && !$permiterror_post_c;
    $post['editbutton'] = !$post['hidden'] && ($post['isbyuser'] || $permiterror_edit != 'level');
    $post['aselectable'] = $post['type'] == 'Q' && !qa_user_permit_error($post['isbyuser'] ? null : 'permit_select_a');
    $post['flagbutton'] = qa_opt('flagging_of_posts') && !$post['isbyuser'] && !$post['hidden'] && !@$post['userflag'] && qa_user_permit_error('permit_flag') != 'level';
    $post['flagtohide'] = $post['flagbutton'] && !qa_user_permit_error('permit_flag') && $post['flagcount'] + 1 >= qa_opt('flagging_hide_after');
    $post['unflaggable'] = @$post['userflag'] && !$post['hidden'];
    $post['clearflaggable'] = $post['flagcount'] >= (@$post['userflag'] ? 2 : 1) && !qa_user_permit_error('permit_hide_show');
    //	Other actions only show the button if it's immediately possible
    $post['hideable'] = !$post['hidden'] && !$permiterror_hide_show;
    $post['reshowable'] = $post['hidden'] && !$permiterror_hide_show && ($post['authorlast'] && !$post['flagcount'] || !$post['isbyuser'] || !qa_user_permit_error('permit_hide_show'));
    // can only reshow a question if you're the one who hid it and it hasn't been flagged, or of course if you have general showing permissions
    $post['deleteable'] = $post['hidden'] && !qa_user_permit_error('permit_delete_hidden');
    // this does not check the post has no children - that check is performed in qa_page_q_load_q()
    $post['claimable'] = !isset($post['userid']) && isset($qa_login_userid) && strcmp(@$post['cookieid'], $qa_cookieid) == 0 && !($post['basetype'] == 'Q' ? $permiterror_post_q : ($post['basetype'] == 'A' ? $permiterror_post_a : $permiterror_post_c));
    $post['followable'] = $post['type'] == 'A' ? qa_opt('follow_on_as') : false;
}
Ejemplo n.º 9
0
function qa_other_to_q_html_fields($question, $userid, $cookieid, $usershtml, $dummy, $options)
{
    $fields = qa_post_html_fields($question, $userid, $cookieid, $usershtml, null, $options);
    switch ($question['obasetype']) {
        case 'Q':
            $fields['what'] = @$question['oedited'] ? qa_lang_html('main/edited') : null;
            break;
        case 'A':
            $fields['what'] = @$question['oedited'] ? qa_lang_html('main/answer_edited') : qa_lang_html('main/answered');
            break;
        case 'C':
            $fields['what'] = @$question['oedited'] ? qa_lang_html('main/comment_edited') : qa_lang_html('main/commented');
            break;
    }
    if ($question['obasetype'] != 'Q') {
        $fields['what_url'] = $fields['url'] . '#' . qa_html(urlencode(qa_anchor($question['obasetype'], $question['opostid'])));
    }
    if (@$options['whenview']) {
        $fields['when'] = qa_lang_html_sub_split('main/x_ago', qa_html(qa_time_to_string(qa_opt('db_time') - $question['otime'])));
    }
    if (@$options['whoview']) {
        $isbyuser = qa_post_is_by_user(array('userid' => $question['ouserid'], 'cookieid' => $question['ocookieid']), $userid, $cookieid);
        $fields['who'] = qa_who_to_html($isbyuser, $question['ouserid'], $usershtml, @$options['ipview'] ? $question['oip'] : null, false);
        if (isset($question['opoints'])) {
            if (@$options['pointsview']) {
                $fields['who']['points'] = $question['opoints'] == 1 ? qa_lang_html_sub_split('main/1_point', '1', '1') : qa_lang_html_sub_split('main/x_points', qa_html(number_format($question['opoints'])));
            }
            if (isset($options['pointstitle'])) {
                $fields['who']['title'] = qa_get_points_title_html($question['opoints'], $options['pointstitle']);
            }
        }
        if (isset($question['olevel'])) {
            $fields['who']['level'] = qa_html(qa_user_level_string($question['olevel']));
        }
    }
    unset($fields['flags']);
    if (@$options['flagsview'] && @$post['oflagcount']) {
        $fields['flags'] = $post['oflagcount'] == 1 ? qa_lang_html_sub_split('main/1_flag', '1', '1') : qa_lang_html_sub_split('main/x_flags', $post['oflagcount']);
    }
    unset($fields['avatar']);
    if (!QA_FINAL_EXTERNAL_USERS && @$options['avatarsize'] > 0) {
        $fields['avatar'] = qa_get_user_avatar_html($question['oflags'], $question['oemail'], $question['ohandle'], $question['oavatarblobid'], $question['oavatarwidth'], $question['oavatarheight'], $options['avatarsize']);
    }
    return $fields;
}