Ejemplo n.º 1
0
 public function canMarkSpam()
 {
     return CMA_Settings::canReportSpam() and !$this->isMarkedAsSpam();
 }
 protected static function _processReportSpam()
 {
     if (self::$query->is_single()) {
         $post = self::$query->post;
         if (!empty($post)) {
             $response = array('success' => 0, 'message' => CMA::__('An error occurred.'));
             if (empty($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], 'cma_report_spam')) {
                 $response['message'] = CMA::__('Invalid nonce.');
             } else {
                 if (CMA_Settings::canReportSpam()) {
                     $thread = CMA_Thread::getInstance($post->ID);
                     $answerId = self::_getParam('answerId');
                     if ($userId = CMA::getPostingUserId()) {
                         $user = apply_filters('cma_filter_author', get_user_by('id', $userId), array('thread' => $thread));
                         $user = $user->display_name;
                     } else {
                         $user = CMA::__('Guest');
                     }
                     if ($answerId and $answer = CMA_Answer::getById($answerId)) {
                         $answer->markAsSpam(true);
                         $url = $answer->getPermalink();
                         $author = $answer->getAuthorLink(true);
                         $content = CMA_Thread::lightContent($answer->getContent());
                         $datetime = $answer->getDate();
                         $trashLink = get_admin_url(null, sprintf('comment.php?c=%d&action=trashcomment', $answerId));
                         $spamLink = get_admin_url(null, sprintf('comment.php?c=%d&action=spamcomment', $answerId));
                     } else {
                         $thread->markAsSpam(true);
                         $url = get_permalink($post->ID);
                         $author = $thread->getAuthorLink(true);
                         $content = $thread->getLightContent();
                         $datetime = $post->post_date;
                         $trashLink = get_admin_url(null, sprintf('post.php?post=%d&action=trash', $post->ID));
                         $spamLink = '--';
                     }
                     $replace = array('[blogname]' => get_bloginfo('name'), '[url]' => $url, '[title]' => strip_tags($thread->getTitle()), '[author]' => strip_tags($author), '[content]' => $content, '[user]' => strip_tags($user), '[datetime]' => $datetime, '[trash]' => $trashLink, '[spam]' => $spamLink);
                     $subject = strtr(CMA_Settings::getOption(CMA_Settings::OPTION_SPAM_REPORTING_EMAIL_SUBJECT), $replace);
                     $template = strtr(CMA_Settings::getOption(CMA_Settings::OPTION_SPAM_REPORTING_EMAIL_TEMPLATE), $replace);
                     $emails = explode(',', CMA_Settings::getOption(CMA_Settings::OPTION_SPAM_REPORTING_EMAIL_ADDR));
                     CMA_Email::send($emails, $subject, $template);
                     /* $headers = array();
                        foreach($emails as $email) {
                        	$email = trim($email);
                        	if (is_email($email)) {
                        		$headers[] = ' Bcc: '. $email;
                        	}
                        }
                        
                        if (!empty($headers)) wp_mail(null, $subject, $template, $headers); */
                     $response['success'] = 1;
                     $response['message'] = CMA_Labels::getLocalized('spam_report_sent');
                 }
             }
             header('Content-type: application/json');
             echo json_encode($response);
             exit;
         }
     }
 }