Apache-Wyrd
view release on metacpan or search on metacpan
Wyrd/Site/Page.pm view on Meta::CPAN
sub _check_auth {
my ($self) = @_;
#warn 'here, authorizing with an allow of ' . $self->{'allow'};
if ($self->{'allow'}) {
return undef if($self->_override_auth_conditions);
unless ($self->dbl->user->username) {
#warn 'here, about to ask for a redirect';
my $hash = $self->_auth_hash;
while (my ($key, $value) = each %$hash) {
$self->dbl->req->dir_config->add($key, $value);
}
#$self->dbl->req->dir_config->add('AuthLevel', $self->{'allow'});
$self->abort('request authorization');
die "abort failed.";
}
if ($self->dbl->user->auth($self->{'allow'}, $self->{'deny'})) {
return;
}
my $redirect = $self->dbl->req->dir_config('UnauthURL');
if ($redirect) {
$self->abort($redirect);
die "abort failed.";
}
$self->_data($self->_unauthorized_text);
}
#warn 'here about tor return from check_auth';
return;
}
=item (scalar) C<_override_auth_conditions> (void)
Override the default authorization behavior. The default behavior is to check
the id against the dir_config values for "trusted_ipaddrs", a
whitespace-separated list.
=cut
sub _override_auth_conditions {
my ($self) = @_;
my $addrs = $self->dbl->req->dir_config('trusted_ipaddrs');
return 0 unless ($addrs);
my @trusted_ips = split /\s+/, $addrs;
my $ip = $self->dbl->req->connection->remote_addr;
return 1 if (grep {$_ eq $ip} @trusted_ips);
return 0;
}
=item (scalar) C<_unauthorized_text> (void)
The error message to be returned when no UnauthURL is set.
=cut
sub _unauthorized_text {
my ($self) = @_;
return '<h1>Unauthorized</h1><hr>You are not authorized to view this document';
}
=item (void) C<_page_edit> (void)
A hook method for pages which interact with some sort of content management editing facility.
=cut
sub _page_edit {
my ($self) = @_;
return;
}
=item (void) C<_process_template> (void)
A hook method for how to assemble the body section of the page from the
template. Defaults to replacing the string _INSERT_TEXT_HERE_ with the
enclosed text.
=cut
sub _process_template {
my ($self, $template) = @_;
$template =~ s/_INSERT_TEXT_HERE_/$$self{_data}/;
$self->{_data} = $template;
}
=item (array) C<_attribute_list> (void)
=item (array) C<_map_list> (void)
List of those attributes supported by this Page object that are tracked in
the the attributes of the Index object that supports it. The default is to
use the Index object's attribute and map lists, respectively. See
C<qw(Apache::Wyrd::Site::Index)> and C<qw(Apache::Wyrd::Services::Index)>.
=cut
#index-dependent attribute list
sub _attribute_list {
my ($self) = @_;
return ($self->index->attribute_list);
}
sub _map_list {
my ($self) = @_;
return $self->index->map_list;
}
#overloads Indexable
=item (scalar) C<index_digest> (void)
As in C<Apache::Wyrd::Interfaces::Indexable>, provides the raw data to be
considered in generating the "fingerprint" that is used to determine if this
page has been changed, and consequently requires re-indexing.
=cut
sub index_digest {
my ($self, $extra) = @_;
$extra ||= '';
return $self->SUPER::index_digest(
$self->index_parent
. $self->index_published
. $self->index_section
. $self->index_allow
. $self->index_deny
. $self->index_tags
Wyrd/Site/Page.pm view on Meta::CPAN
my ($self) = @_;
return $self->{'deny'};
}
sub index_tags {
my ($self) = @_;
return $self->{'tags'};
}
sub index_children {
my ($self) = @_;
return $self->{'parent'};
}
sub handle_children {
my ($self, $id, $parent) = @_;
my @parents = token_parse($parent);
my %score = ();
foreach $parent (@parents) {
($parent, my $score) = split(':', $parent);
$score{$parent} = $score;
}
$self->index->index_map('children', $id, \%score);
}
#The list goes on and on
sub index_doctype {
my ($self) = @_;
return ($self->{'doctype'} || 'HTML');
}
sub index_expires {
my ($self) = @_;
return $self->{'expires'};
}
sub index_longdescription {
my ($self) = @_;
return ($self->{'longdescription'} || $self->{'description'});
}
sub index_shorttitle {
my ($self) = @_;
return ($self->{'shorttitle'} || $self->{'title'});
}
=back
=head1 BUGS/CAVEATS
Reserves the _format_output and _generate_output methods.
=cut
sub _setup {
my ($self) = @_;
$self->_init_state;
$self->_check_auth;
$self->_init_index;
$self->_page_edit;
unless ($self->_flags->nofail) {
my $name = $self->index_name;
if ($name eq $self->{'original'}) {
if ($name =~ m/^\//) {
unless (-f $self->dbl->req->document_root . $name) {
$self->_raise_exception("Original file doesn't exist ($name). Use the nofail flag to override this error.");
}
}
}
}
}
sub _format_output {
my ($self) = @_;
my $response = $self->index->update_entry($self);
$self->_info($response);
$self->_set_state;
my $head = join ('/', $self->dbl->req->document_root, 'lib/head.html');
my $file = join ('/', $self->dbl->req->document_root, 'lib/body.html');
my $template = $self->get_cached($head);
my $title = $self->{'title'};
my $keywords = $self->{'keywords'};
my $description = $self->{'description'};
my $meta = $self->{'meta'};
$template =~ s/<\/head>/\n$meta\n<\/head>/ if ($meta);
my $lib = $self->{'lib'};
if ($lib) {
my @inserts = token_parse($lib);
foreach my $lib (@inserts) {
$lib = join ('/', $self->dbl->req->document_root, 'lib', $lib);
$lib = $self->get_cached($lib);
$template =~ s/<\/head>/$lib\n<\/head>/;
}
}
$title =~ s/\s+/ /g;
$keywords =~ s/\s+/ /g;
$description =~ s/\s+/ /g;
$template = $self->_set({title => strip_html($title), keywords => strip_html($keywords), description => strip_html($description)}, $template);
$template .= $self->get_cached($file);
$self->_process_template($template);
return;
}
sub _generate_output {
my ($self) = @_;
$self->_dispose_index;
return $self->SUPER::_generate_output;
}
=pod
=head1 AUTHOR
Barry King E<lt>wyrd@nospam.wyrdwright.comE<gt>
=head1 SEE ALSO
=over
( run in 0.727 second using v1.01-cache-2.11-cpan-d8267643d1d )