AxKit-App-TABOO

 view release on metacpan or  search on metacpan

lib/AxKit/App/TABOO/XSP/Story.pm  view on Meta::CPAN

session object, it will throw an exception with an C<AUTH_REQUIRED>
code. If asked to store certain priviliged fields, it will check the
authorization level and throw an exception with a C<FORBIDDEN> code if
not satisfied. If timestamps do not exist, they will be created based
on the system clock.

If TABOOAkismetKey is set (and spammers will make you want this really
fast), it will check the Akismet anti-spam system if article has not
been approved by an editor and the user has an authlevel less than 2,
and return a C<FORBIDDEN> if it is deemed to be spam. Once the article
has been approved by an editor, it is fed to Akismet to teach it what
is ham.

Finally, the Data object is instructed to save itself.

If successful, it will return a C<store> element in the output
namespace with the number 1.

=cut


sub store : node({http://www.kjetil.kjernsmo.net/software/TABOO/NS/Story/Output}store) {
    return << 'EOC'
        my %args;
    foreach my $name ($cgi->param) {
      $args{$name} = $cgi->param($name);
    }

    my $session = AxKit::App::TABOO::session($r);
    $args{'username'} = AxKit::App::TABOO::loggedin($session);

    my $authlevel = AxKit::App::TABOO::authlevel($session); 
    AxKit::Debug(4, "Logged in as $args{'username'} at level $authlevel");
    unless (defined($authlevel)) {
	throw Apache::AxKit::Exception::Retval(
					       return_code => AUTH_REQUIRED,
					       -text => "Not authenticated and authorized with an authlevel");
    }
    unless ($args{'storyname'}) {
	$args{'storyname'} = AxKit::App::TABOO::XSP::Story::_create_storyname($args{'title'});
    } 
    if ($args{'sectionid'} ne 'subqueue') {
	if ($authlevel < AxKit::App::TABOO::XSP::Story::EDITOR) {
	    throw Apache::AxKit::Exception::Retval(
						   return_code => FORBIDDEN,
						   -text => "Editor Priviliges are needed to store non-subqueue section. Your level: " . $authlevel);
	}
    }
    if (($args{'editorok'}) && ($authlevel < AxKit::App::TABOO::XSP::Story::EDITOR)) {
	throw Apache::AxKit::Exception::Retval(
					       return_code => FORBIDDEN,
					       -text => "Editor Priviliges are needed to OK an article. Your level: " . $authlevel);
    }
    
    if ($r->dir_config('TABOOAkismetKey')) {
      AxKit::Debug(4, "Using Akismet");
      my $akismet = Net::Akismet->new(
                        KEY => $r->dir_config('TABOOAkismetKey'),
                        URL => 'http://'.$r->header_in('X-Forwarded-Host'),
                ) or throw Apache::AxKit::Exception::Error(-text => "Akismet key verification failed.");
      my %akismetstuff = (USER_IP => $r->header_in('X-Forwarded-For'),
			  COMMENT_CONTENT => $args{'minicontent'} ."\n". $args{'content'},
			  REFERRER => $r->header_in('Referer'),
			  COMMENT_TYPE => 'comment',
			 );
      if ($args{'editorok'}) { # Surely ham
	$akismet->ham(%akismetstuff);
      } elsif ($authlevel < 2) { # Above 2 is probably ham
	AxKit::Debug(10, "Akismet check on: ".join("    ",values(%akismetstuff)));
	if ($akismet->check(%akismetstuff) eq 'true') {
	  throw Apache::AxKit::Exception::Retval(
						 return_code => FORBIDDEN,
						 -text => "Akismet check says that your comment is spam. Please contact webmaster if you received this message in error.");
	}
      }
    }


    if (! $args{'submitterid'}) {
	# If the submitterid is not set, we set it to the current username
	$args{'submitterid'} = $args{'username'}
    }

    my $story = AxKit::App::TABOO::Data::Story->new();

    my $timestamp = localtime;
    unless ($args{'timestamp'}) {
	$args{'timestamp'} = $timestamp->datetime;
    }
    unless ($args{'lasttimestamp'}) {
	$args{'lasttimestamp'} = $timestamp->datetime;
    }

    $story->populate(\%args);
    $story->save;
    1;
EOC
}


=head2 C<E<lt>this-story/E<gt>>

Will return an XML representation of the data submitted in the last
request, enclosed in a C<story-submission> element. Particularly
useful for previewing a submission.

=cut

sub this_story : struct {
    return << 'EOC'
    my %args = map { $_ => $cgi->param($_) } $cgi->param;

    $args{'username'} = AxKit::App::TABOO::loggedin(AxKit::App::TABOO::session($r));

    unless ($args{'submitterid'}) {
      # If the submitterid is not set, we set it to the current username
	$args{'submitterid'} = $args{'username'}
    }
    
    my $timestamp = localtime;
    unless ($args{'timestamp'}) {



( run in 2.124 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )