function the_qa_flag_form($id)
{
    global $qa_general_settings;
    $f = '';
    $f .= '<div id="qa_flag_form_' . $id . '" style="display:none" >';
    $f .= '<form method="post" action="' . admin_url("admin-ajax.php") . '" >';
    $f .= '<input type="hidden" name="action" value="qa_flag" />';
    $f .= '<input type="hidden" name="ID" value="' . $id . '" />';
    if (isset($qa_general_settings["report_reasons"]) && '' != trim($qa_general_settings["report_reasons"])) {
        $reasons = explode(",", $qa_general_settings["report_reasons"]);
        if (is_array($reasons)) {
            $f .= '<div class="qa_report_reason">';
            $f .= __('Select a reason for reporting:', QA_TEXTDOMAIN);
            $f .= '<br />';
            foreach ($reasons as $reason) {
                $f .= '<input type="radio" name="report_reason" value="' . stripslashes(trim($reason)) . '" /> ' . stripslashes(trim($reason));
                $f .= '<br />';
            }
            $f .= '</div>';
        }
    }
    if (isset($qa_general_settings["captcha"]) && $qa_general_settings["captcha"] && qa_is_captcha_usable()) {
        $f .= '<div class="qa_captcha"> 
		<label class="description" >' . __('Type the letters you see in the image below:', QA_TEXTDOMAIN) . '</label>
		<div class="qa_captcha_inner">
		<img class="captcha_image" id="captcha_' . $id . '" src="' . plugins_url("/qa/securimage/securimage_show.php") . '" alt="CAPTCHA Image" />
		</div>
		<div>
		<input type="text" id="captcha_code_' . $id . '" name="captcha_code" size="10" maxlength="6" />
		<a href="javascript:void(0)" onclick="document.getElementsByClassName(\'captcha_image\').src=\'' . plugins_url("/qa/securimage/images/blank.png") . '\';document.getElementById(\'captcha_' . $id . '\').src = \'' . plugins_url("/qa/securimage/securimage_show.php") . '?\' + Math.random(); document.getElementById(\'captcha_code_' . $id . '\').value=\'\'; return false;">' . __('[ Different Image ]', QA_TEXTDOMAIN) . '</a>
		</div>
		</div>';
    }
    $f .= '<input type="submit" value="' . __('Send Report', QA_TEXTDOMAIN) . '" />';
    $f .= '</form>';
    $f .= '<br />';
    $f .= '<input type="submit" value="' . __('Cancel', QA_TEXTDOMAIN) . '" onClick="javascript:document.getElementById(\'qa_flag_form_' . $id . '\').style.display=\'none\';" />';
    $f .= '</div>';
    return $f;
}
</label>
				</th>
				<td>
				<input type="checkbox" name="captcha" value="1" <?php 
if (isset($options["captcha"]) && $options["captcha"]) {
    echo 'checked="checked"';
}
?>
 />
				&nbsp;
				<span class="description">
				<?php 
_e('Whether to use Captcha verification while submitting report.', QA_TEXTDOMAIN);
?>
				<?php 
if (!qa_is_captcha_usable()) {
    _e('Note: Your php installation does not let Captcha usage.', QA_TEXTDOMAIN);
}
?>
				</span>
				</td>
			</tr>
			
			<tr>
				<th>
					<label for="report"><?php 
_e('Email address on report', QA_TEXTDOMAIN);
?>
</label>
				</th>
				<td>
Exemple #3
0
 /**
  * Handles report request
  * Since V1.3.1
  */
 function qa_flag()
 {
     $id = $_POST['ID'];
     $post = get_post($id);
     // Don't add anchor for answers, as they already have
     if ('answer' != $post->post_type) {
         $anchor = '#"question-body';
     } else {
         $anchor = '';
     }
     // Check report reason
     if (isset($this->g_settings["report_reasons"]) && '' != trim($this->g_settings["report_reasons"]) && !isset($_POST["report_reason"])) {
         $url = add_query_arg(array('no_reason' => '1' . $anchor), get_permalink($id));
         wp_redirect($url);
         die;
     }
     // Check Captcha
     if (isset($this->g_settings["captcha"]) && $this->g_settings["captcha"] && qa_is_captcha_usable()) {
         if (!session_id()) {
             @session_start();
         }
         include_once WP_PLUGIN_DIR . '/qa/securimage/securimage.php';
         $securimage = new Securimage();
         if ($securimage->check($_POST['captcha_code']) == false) {
             $url = add_query_arg(array('flag_error' => '1' . $anchor), get_permalink($id));
             wp_redirect($url);
             die;
         }
     }
     $meta = get_post_meta($id, '_qa_report', true);
     $new_meta = array();
     $new_meta["count"] = 1;
     if ($meta && isset($meta["count"])) {
         $new_meta["count"] = $meta["count"] + 1;
     }
     if (is_user_logged_in()) {
         global $current_user;
         $user_info = get_userdata($current_user->ID);
         $new_meta["user"] = $user_info->user_login;
     } else {
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $new_meta["user"] = $_SERVER['REMOTE_ADDR'];
         } else {
             $new_meta["user"] = __('Unknown', QA_TEXTDOMAIN);
         }
     }
     if (isset($_POST["report_reason"])) {
         $new_meta["reason"] = $_POST["report_reason"];
     } else {
         $new_meta["reason"] = __('None', QA_TEXTDOMAIN);
     }
     update_post_meta($id, '_qa_report', $new_meta);
     do_action('qa_reported', $id, $new_meta);
     // Only send email for the first report
     if (isset($this->g_settings["report_email"]) && is_email($this->g_settings["report_email"]) && $new_meta["count"] == 1) {
         $to = $this->g_settings["report_email"];
         $subject = __('A question or answer has been reported', QA_TEXTDOMAIN);
         $message = __('Reported by:', QA_TEXTDOMAIN);
         $message .= $new_meta["user"];
         $message .= "\n";
         $message .= __('Report reason:', QA_TEXTDOMAIN);
         $message .= stripslashes($new_meta["reason"]);
         $message .= "\n\n";
         $message .= __('You can edit it by clicking this link:', QA_TEXTDOMAIN);
         $message .= "\n\n";
         $message .= admin_url("post.php?post=" . $id . "&action=edit");
         wp_mail($to, $subject, $message);
     }
     $url = add_query_arg(array('flag_received' => '1' . $anchor), get_permalink($id));
     wp_redirect($url);
     die;
 }
Exemple #4
0
 /**
  * Save admin options.
  *
  * @return void die() if _wpnonce is not verified
  */
 function ajax_save()
 {
     check_admin_referer('qa-verify');
     if (!current_user_can('manage_options')) {
         die(-1);
     }
     // add/remove capabilities
     global $wp_roles;
     $qa_capabilities_set = get_option('qa_capabilties_set', array());
     $role = $_POST['roles'];
     $all_caps = array_keys($this->capability_map);
     if (isset($_POST['capabilities'])) {
         $to_add = array_keys($_POST['capabilities']);
     } else {
         $to_add = array();
     }
     $to_remove = array_diff($all_caps, $to_add);
     foreach ($to_remove as $capability) {
         $wp_roles->remove_cap($role, $capability);
     }
     foreach ($to_add as $capability) {
         $wp_roles->add_cap($role, $capability);
     }
     if (qa_is_captcha_usable() && isset($_POST['captcha'])) {
         $captcha = true;
     } else {
         $captcha = false;
     }
     $options = array('general_settings' => array('moderation' => isset($_POST['moderation']), 'bp_comment_hide' => isset($_POST['bp_comment_hide']), 'page_layout' => @$_POST['qa_page_layout'], 'page_width' => trim(@$_POST['page_width']), 'content_width' => trim(@$_POST['content_width']), 'content_alignment' => @$_POST['content_alignment'], 'sidebar_width' => trim(@$_POST['sidebar_width']), 'search_input_width' => trim(@$_POST['search_input_width']), 'additional_css' => esc_attr(@$_POST['additional_css']), 'full_width' => isset($_POST['full_width']), 'answers_per_page' => trim(@$_POST['answers_per_page']), 'questions_per_page' => trim(@$_POST['questions_per_page']), 'disable_editor' => isset($_POST['disable_editor']), 'selected_role' => @$_POST['roles'], 'default_category' => @$_POST['default_category'], 'thank_you' => @$_POST['thank_you'], 'unauthorized' => @$_POST['unauthorized'], 'assigned_to' => @$_POST['assigned_to'], 'method' => @$_POST['method'], 'captcha' => $captcha, 'report_reasons' => trim(@$_POST['report_reasons']), 'report_email' => trim(@$_POST['report_email'])));
     $qa_capabilities_set[$role] = true;
     update_option('qa_capabilties_set', array_unique($qa_capabilities_set));
     update_option(QA_OPTIONS_NAME, $options);
     update_option('qa_email_notification_subject', $_POST['qa_email_notification_subject']);
     update_option('qa_email_notification_content', $_POST['qa_email_notification_content']);
     die(1);
 }