Main entry point for spam handling - called from the comment view and
    page processor for ``yacms.forms``, to check if posted content is
    spam. Spam filters are configured via the ``SPAM_FILTERS`` setting.
505771
def is_spam(request, form, url):
    
    for spam_filter_path in settings.SPAM_FILTERS:
        spam_filter = import_dotted_path(spam_filter_path)
        if spam_filter(request, form, url):
            return True
749454
protected function addBasicPurgeFilters() {
        if ($this->purgeFiltersInitialized) {
            return;
        }

        $this->purgeFilters[] = function ($attributeKey) {
            // disallow password confirmation fields
            if (Str::endsWith($attributeKey, '_confirmation')) {
                return false;
            }

            // "_method" is used by Fly\Routing\Router to simulate custom HTTP verbs
            if (strcmp($attributeKey, '_method') === 0) {
                return false;
            }

            // "_token" is used by Fly\Html\FormBuilder to add CSRF protection
            if (strcmp($attributeKey, '_token') === 0) {
                return false;
            }

            return true;
        };

        $this->purgeFiltersInitialized = true;
    }
821338
def process_filters(input)
      keys = input.path.match(@pattern)[0].scan(/(?<=\.)\w+/)

      filters = keys.reverse_each.map do |key|
        @filters[key.to_sym]
      end

      filters.each do |filter|
        input = process_with_filter(input, filter)
      end

      input.read
    end
483955
def moderate(self, comment, entry, request):
        
        if self.auto_moderate_comments:
            return True

        if check_is_spam(comment, entry, request,
                         self.spam_checker_backends):
            return True

        return False
1232520
function checkCommentForSuppress(node) {
      // Skip if types aren't provided or the comment is empty.
      if (!node || !node.value || node.value.length === 0) {
        return;
      }

      const match = node.value.match(/@suppress \{(.*?)\}/);
      if (match && match.length === 2) {
        if (!blacklistedTypes || blacklistedTypes.length === 0) {
          // Array is not present or empty, so block all types.
          context.report(node, '@suppress not allowed for any types');
        } else {
          // Report which matched types are blocked.
          const matched = [];
          const types = match[1].split('|');
          types.forEach(function(type) {
            if (blacklistedTypes.indexOf(type) !== -1 && matched.indexOf(type) === -1) {
              matched.push(type);
            }
          });

          if (matched.length > 0) {
            const typeString = matched.join(', ');
            context.report(node, `@suppress not allowed for: ${typeString}`);
          }
        }
      }
    }
108516
def comment(request, template="generic/comments.html", extra_context=None):
    
    response = initial_validation(request, "comment")
    if isinstance(response, HttpResponse):
        return response
    obj, post_data = response
    form_class = import_dotted_path(settings.COMMENT_FORM_CLASS)
    form = form_class(request, obj, post_data)
    if form.is_valid():
        url = obj.get_absolute_url()
        if is_spam(request, form, url):
            return redirect(url)
        comment = form.save(request)
        response = redirect(add_cache_bypass(comment.get_absolute_url()))
        # Store commenter's details in a cookie for 90 days.
        for field in ThreadedCommentForm.cookie_fields:
            cookie_name = ThreadedCommentForm.cookie_prefix + field
            cookie_value = post_data.get(field, "")
            set_cookie(response, cookie_name, cookie_value)
        return response
    elif request.is_ajax() and form.errors:
        return HttpResponse(dumps({"errors": form.errors}))
    # Show errors with stand-alone comment form.
    context = {"obj": obj, "posted_comment_form": form}
    context.update(extra_context or {})
    return TemplateResponse(request, template, context)
1236272
public function process()
    {
        $form = $this->getForm();
        if ($form !== null && $form->isSubmitted()) {
            $data = $form->getFormData();
            if (isset($data[$this->id])) {
                $this->selected_value = $data[$this->id];

                $view = $this->getFirstAncestor('SwatView');
                if ($view !== null) {
                    $selection = new SwatViewSelection(array(
                        $this->selected_value
                    ));

                    $view->setSelection($selection, $this);
                }
            }
        }
    }
746242
def flag(request, comment_id, next=None):
    
    comment = get_object_or_404(comments.get_model(), pk=comment_id, site__pk=settings.SITE_ID)

    # Flag on POST
    if request.method == 'POST':
        perform_flag(request, comment)
        return next_redirect(request, fallback=next or 'comments-flag-done',
            c=comment.pk)

    # Render a form on GET
    else:
        return render_to_response('comments/flag.html',
            {'comment': comment, "next": next},
            template.RequestContext(request)
        )
673490
def allow(self, comment, content_object, request):
        
        # Parent class check
        if not super(FluentCommentsModerator, self).allow(comment, content_object, request):
            return False

        # Akismet check
        if self.akismet_check:
            akismet_result = akismet_check(comment, content_object, request)
            if self.akismet_check_action == 'delete' and akismet_result in (SpamStatus.ProbableSpam, SpamStatus.DefiniteSpam):
                return False  # Akismet marked the comment as spam.
            elif self.akismet_check_action == 'auto' and akismet_result == SpamStatus.DefiniteSpam:
                return False  # Clearly spam

        return True
872376
def get(self):
        
        spam_check = {}
        if self.enable is not None:
            spam_check["enable"] = self.enable

        if self.threshold is not None:
            spam_check["threshold"] = self.threshold.get()

        if self.post_to_url is not None:
            spam_check["post_to_url"] = self.post_to_url.get()
        return spam_check
552744
function process_form($form, &$preferences){
        if (isset($form->jabber_jabberid) && !empty($form->jabber_jabberid)) {
            $preferences['message_processor_jabber_jabberid'] = $form->jabber_jabberid;
        }
    }
1212332
def form_invalid(self, form):
        
        messages.error(self.request, form.errors[NON_FIELD_ERRORS])
        return redirect(
            reverse(
                'forum_conversation:topic',
                kwargs={
                    'forum_slug': self.object.topic.forum.slug,
                    'forum_pk': self.object.topic.forum.pk,
                    'slug': self.object.topic.slug,
                    'pk': self.object.topic.pk
                },
            ),
        )
854152
public function formSubmit() {

		if ( empty( $this->isFormSubmission() ) || empty( current_user_can( 'edit_others_posts' ) ) ) {
			// Don't do anything in this function, bail.
			return;
		}

		// Process form
		if ( isset( $_GET['custom_styles'] ) && $_GET['custom_styles'] === 'yes' && isset( $_POST['your_styles'] ) && check_admin_referer( 'pb-custom-styles' ) ) {
			$slug = isset( $_POST['slug'] ) ? $_POST['slug'] : 'web';
			$redirect_url = get_admin_url( get_current_blog_id(), '/themes.php?page=' . $this::PAGE . '&slug=' . $slug );

			if ( ! isset( $_POST['post_id'], $_POST['post_id_integrity'] ) ) {
				debug_error_log( __METHOD__ . ' error: Missing post ID' );
				\Pressbooks\Redirect\location( $redirect_url . '&custom_styles_error=true' );
			}
			if ( md5( NONCE_KEY . $_POST['post_id'] ) !== $_POST['post_id_integrity'] ) {
				// A hacker trying to overwrite posts?.
				debug_error_log( __METHOD__ . ' error: unexpected value for post_id_integrity' );
				\Pressbooks\Redirect\location( $redirect_url . '&custom_styles_error=true' );
			}

			// Remove wp_filter_post_kses, this causes CSS escaping issues
			remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
			remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
			remove_all_filters( 'content_save_pre' );

			// Write to database
			$my_post = [
				'ID' => absint( $_POST['post_id'] ),
				'post_content' => \Pressbooks\Sanitize\cleanup_css( $_POST['your_styles'] ),
			];
			$response = wp_update_post( $my_post, true );

			if ( is_wp_error( $response ) ) {
				// Something went wrong?
				debug_error_log( __METHOD__ . ' error, wp_update_post(): ' . $response->get_error_message() );
				\Pressbooks\Redirect\location( $redirect_url . '&custom_styles_error=true' );
			}

			if ( $slug === 'web' ) {
				// a recompile will be triggered whenever the user saves custom styles targeting web
				$this->updateWebBookStyleSheet();
			}

			// Ok!
			\Pressbooks\Redirect\location( $redirect_url );
		}

	}
839683
public static function _init()
	{
		static::$csrf_token_key = \Config::get('security.csrf_token_key', 'fuel_csrf_token');
		static::$csrf_old_token = \Input::cookie(static::$csrf_token_key, false);

		// if csrf automatic checking is enabled, and it fails validation, bail out!
		if (\Config::get('security.csrf_autoload', true))
		{
			$check_token_methods = \Config::get('security.csrf_autoload_methods', array('post', 'put', 'delete'));
			if (in_array(strtolower(\Input::method()), $check_token_methods) and ! static::check_token())
			{
				throw new \SecurityException('CSRF validation failed, Possible hacking attempt detected!');
			}
		}

		// throw an exception if the output filter setting is missing from the app config
		if (\Config::get('security.output_filter', null) === null)
		{
			throw new \FuelException('There is no security.output_filter defined in your application config file');
		}

		// deal with duplicate filters, no need to slow the framework down
		foreach (array('output_filter', 'uri_filter', 'input_filter') as $setting)
		{
			$config = \Config::get('security.'.$setting, array());
			is_array($config) and \Config::set('security.'.$setting, \Arr::unique($config));
		}
	}
760078
public function run()
    {
        $post = $this->findPost('lorem-ipsum-post');
        if (!$post->exists) {
            $post->fill([
                'title'            => 'Lorem Ipsum Post',
                'author_id'        => 0,
                'seo_title'        => null,
                'excerpt'          => 'This is the excerpt for the Lorem Ipsum Post',
                'body'             => '<p>This is the body of the lorem ipsum post</p>',
                'image'            => 'posts/nlje9NZQ7bTMYOUG4lF1.jpg',
                'slug'             => 'lorem-ipsum-post',
                'meta_description' => 'This is the meta description',
                'meta_keywords'    => 'keyword1, keyword2, keyword3',
                'status'           => 'PUBLISHED',
                'featured'         => 0,
            ])->save();
        }

        $post = $this->findPost('my-sample-post');
        if (!$post->exists) {
            $post->fill([
                'title'     => 'My Sample Post',
                'author_id' => 0,
                'seo_title' => null,
                'excerpt'   => 'This is the excerpt for the sample Post',
                'body'      => '<p>This is the body for the sample post, which includes the body.</p>
                <h2>We can use all kinds of format!</h2>
                <p>And include a bunch of other stuff.</p>',
                'image'            => 'posts/7uelXHi85YOfZKsoS6Tq.jpg',
                'slug'             => 'my-sample-post',
                'meta_description' => 'Meta Description for sample post',
                'meta_keywords'    => 'keyword1, keyword2, keyword3',
                'status'           => 'PUBLISHED',
                'featured'         => 0,
            ])->save();
        }

        $post = $this->findPost('latest-post');
        if (!$post->exists) {
            $post->fill([
                'title'            => 'Latest Post',
                'author_id'        => 0,
                'seo_title'        => null,
                'excerpt'          => 'This is the excerpt for the latest post',
                'body'             => '<p>This is the body for the latest post</p>',
                'image'            => 'posts/9txUSY6wb7LTBSbDPrD9.jpg',
                'slug'             => 'latest-post',
                'meta_description' => 'This is the meta description',
                'meta_keywords'    => 'keyword1, keyword2, keyword3',
                'status'           => 'PUBLISHED',
                'featured'         => 0,
            ])->save();
        }

        $post = $this->findPost('yarr-post');
        if (!$post->exists) {
            $post->fill([
                'title'     => 'Yarr Post',
                'author_id' => 0,
                'seo_title' => null,
                'excerpt'   => 'Reef sails nipperkin bring a spring upon her cable coffer jury mast spike marooned Pieces of Eight poop deck pillage. Clipper driver coxswain galleon hempen halter come about pressgang gangplank boatswain swing the lead. Nipperkin yard skysail swab lanyard Blimey bilge water ho quarter Buccaneer.',
                'body'      => '<p>Swab deadlights Buccaneer fire ship square-rigged dance the hempen jig weigh anchor cackle fruit grog furl. Crack Jennys tea cup chase guns pressgang hearties spirits hogshead Gold Road six pounders fathom measured fer yer chains. Main sheet provost come about trysail barkadeer crimp scuttle mizzenmast brig plunder.</p>
<p>Mizzen league keelhaul galleon tender cog chase Barbary Coast doubloon crack Jennys tea cup. Blow the man down lugsail fire ship pinnace cackle fruit line warp Admiral of the Black strike colors doubloon. Tackle Jack Ketch come about crimp rum draft scuppers run a shot across the bow haul wind maroon.</p>
<p>Interloper heave down list driver pressgang holystone scuppers tackle scallywag bilged on her anchor. Jack Tar interloper draught grapple mizzenmast hulk knave cable transom hogshead. Gaff pillage to go on account grog aft chase guns piracy yardarm knave clap of thunder.</p>',
                'image'            => 'posts/yuk1fBwmKKZdY2qR1ZKM.jpg',
                'slug'             => 'yarr-post',
                'meta_description' => 'this be a meta descript',
                'meta_keywords'    => 'keyword1, keyword2, keyword3',
                'status'           => 'PUBLISHED',
                'featured'         => 0,
            ])->save();
        }
    }
1137387
public static function is_spam( array $values = [] ){
		$query_string = self::make_request( $values );
		// If Akismet is not active, always return error
		if( !class_exists('Akismet') || ! \Akismet::get_api_key() ){
			return new \WP_Error(500, 'Akismet is not active.');
		}
		// Make request
		add_filter('akismet_ua', [static::class, 'get_ua'], 9);
		$response = \Akismet::http_post($query_string, 'comment-check');
		remove_filter('akismet_ua', [static::class, 'get_ua'], 9);
		// Parse result
		switch( $response[1] ){
			case 'true':
				return true; // This is spam.
				break;
			case 'false':
				return false; // This is not spam.
				break;
			default:
				// Something is wrong
				if( isset( $response[0]['x-akismet-debug-help'] ) && !empty($response[0]['x-akismet-debug-help']) ){
					$message = $response[0]['x-akismet-debug-help'];
				}else{
					$message = 'Akismet return the invalid result. Something is wrong.';
				}
				return new \WP_Error(500, $message);
				break;
		}
	}
346946
def post_submission(self):
        
        # Check that the subreddit can be submitted to
        name = self.content.name
        if '+' in name or name in ('/r/all', '/r/front', '/r/me', '/u/saved'):
            self.term.show_notification("Can't post to {0}".format(name))
            return

        submission_info = docs.SUBMISSION_FILE.format(name=name)
        with self.term.open_editor(submission_info) as text:
            if not text:
                self.term.show_notification('Canceled')
                return
            elif '\n' not in text:
                self.term.show_notification('Missing body')
                return

            title, content = text.split('\n', 1)
            with self.term.loader('Posting', delay=0):
                submission = self.reddit.submit(name, title, text=content,
                                                raise_captcha_exception=True)
                # Give reddit time to process the submission
                time.sleep(2.0)
            if self.term.loader.exception:
                raise TemporaryFileError()

        if not self.term.loader.exception:
            # Open the newly created submission
            self.selected_page = self.open_submission_page(submission=submission)