AxKit-App-TABOO

 view release on metacpan or  search on metacpan

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

	  push(@errors, 'nosave');
      }
  }
      
  unless (@errors) { # Actually, everything went fine here, so we redirect to continue
    $cgi->status($attr_retval || 302);
    $cgi->err_headers_out->add("Location" => $attr_redirect || '/');
    Apache::exit($attr_retval || 302);
  } else { 
    AxKit::Debug(9, "Things that went wrong: " . join(' ', @errors));
  }
  @errors;
EOC
}

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

  my $lookupurl = AxKit::App::TABOO::XSP::Article::_write_file($upload, $attr_primcat, $r->document_root);
  $args{'format'} = $upload->type;
  # TODO: Security sanity checks.

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

  $args{'authorids'} = [$args{'authorid'}]; # Has to change to support more authors
  my $article = AxKit::App::TABOO::Data::Article->new();
  $article->populate(\%args);
  $article->adduserinfo();
  $article->addcatinfo();
  $article->addformatinfo();
    
  my $doc = XML::LibXML::Document->new();
  my $addel = $doc->createElementNS('http://www.kjetil.kjernsmo.net/software/TABOO/NS/Article/Output', 'art:article-submission');
  $addel->setAttribute('contenturl', $lookupurl);
  $doc->setDocumentElement($addel);
  $article->write_xml($doc, $addel); # Return an XML representation
EOC
}


=head2 C<E<lt>get-article filename="foo" primcat="bar"/E<gt>>

This tag will get an XML representation of the article identified with
C<filename> and C<primcat>. The parameters may be given as attributes
or child elements.

=cut


sub get_article : struct attribOrChild(filename,primcat) {
    return << 'EOC'
    AxKit::Debug(8, "We look for article with filename: '" . $attr_filename . "'");
    my $article = AxKit::App::TABOO::Data::Article->new();
    unless ($article->load(limit => { filename => $attr_filename })) {
	throw Apache::AxKit::Exception::Retval(
					       return_code => 404,
					       -text => "Article with identifier $attr_filename not found");
    }	
    unless ($article->editorok && $article->authorok) {
        my $session = AxKit::App::TABOO::session($r);
	my $authlevel = AxKit::App::TABOO::authlevel($session);
	if (!$authlevel) {
	    throw Apache::AxKit::Exception::Retval(
						   return_code => 401,
						   -text => "Not authorised with an authlevel");
	}
	my $editinguser = AxKit::App::TABOO::loggedin($session);
	unless (grep(/$editinguser/, @{$article->authorids}) || ($authlevel >= 5)) {
	    throw Apache::AxKit::Exception::Retval(
						   return_code => 403,
						   -text => "Authentication and higher priviliges required to load article");
      }
    }
	    
    $article->adduserinfo;
    $article->addcatinfo;
    $article->addformatinfo();

    my $lookupurl;
    foreach my $ext ($article->mimetype->extensions) {
	my $lookupfile = "/articles/content/$attr_primcat/$attr_filename/$attr_filename.$ext";
	warn $r->document_root . $lookupfile;
	if (-r $r->document_root . $lookupfile) {
	    $lookupurl = 'http://' . $r->get_server_name . ':' . $r->get_server_port . $lookupfile;
	}
	last if $lookupurl;
    }
    AxKit::Debug(8, "Content really at: " . $lookupurl);

    unless ($lookupurl) {
	throw Apache::AxKit::Exception::Retval(
					       return_code => 404,
					       -text => "Content $lookupurl not found");
    }

    my $doc = XML::LibXML::Document->new();
    my $rootel = $doc->createElement('taboo');
    $rootel->setAttribute('contenturl', $lookupurl);
    #  $rootel->setAttribute('type', 'article');
    #  $rootel->setAttribute('origin', 'Article');
    $doc->setDocumentElement($rootel);
    $article->write_xml($doc, $rootel);
EOC
}




1;




=head1 FORMALITIES

See L<AxKit::App::TABOO>.

=cut



( run in 1.957 second using v1.01-cache-2.11-cpan-39bf76dae61 )