<commit_before>
=head1 NAME

CXGN::Page

=head1 DESCRIPTION

Page object which handles headers, footers, simple message pages, and simple error pages. Can also retrieve page arguments and handle redirects.
This is now a subclass of CXGN::Scrap, which handles all of the argument-retrieval.

=cut

package CXGN::Page;
use base qw/CXGN::Scrap/;
use strict;
use Apache2::RequestUtil ();
use Apache2::Cookie;
use HTML::Entities qw/encode_entities/;
use URI::Escape;
use Carp;
use CGI qw/ -compile :html4/;
use CXGN::Page::FormattingHelpers qw(blue_section_html newlines_to_brs);
use CXGN::Apache::Error;
use CXGN::DB::Connection;
use CXGN::Login;
use CXGN::Page::VHost::SGN;
use CXGN::MasonFactory;
use CXGN::Tools::File;
use CXGN::Tools::SVN::Info;

use SGN::Context;


use Data::Dumper;
$Data::Dumper::Varname = 'VAR_DUMP';

## STDERR Capture for the Logger, by Developer Preference ####
our $STDERR_BUFFER  = '';
our $STDERR_CAPTURE = 0;

=head1 OBJECT METHODS

=head2 new

Creates a new page object. This will try to be smart and give you the correct type of header for your virtual host, based on the apache request.  All arguments are optional, but they are ordered.

	#Example
	my $page=CXGN::Page->new( $page_name, $author,
		{jslib => ['CXGN.MyModule','MochiKit.Logging', 'Prototype', 'Scriptaculous.DragDrop']});

The jslib in the final optional hashref is equivalent to using jsan_use() on the page.

=cut

sub new {
    my $class = shift;

    my $self = $class->SUPER::new();

    eval { $self->set_dbh(CXGN::DB::Connection->new());  };
    if ($@) { print STDERR "Oops, database does not seem to be available. ($@). Trying to continue without it...\n"; }

    $self->{mk_log_messages} = [];
    my ( $name, $author, $other ) = @_;
    if ( $other and my $js = $other->{jslib} ) {
        my @libs = ref $js ? @$js : ($js);
        $self->jsan_use(@libs);
    }
    $self->{vhost_object} = SGN::Context->new();
    $self->{project_name} = 'SGN';

    $self->{page_object} = CXGN::Page::VHost::SGN->new($self->get_dbh());
    $self->{page_object}->{page} = $self;

    $name   ||= '';
    $author ||= '';
    $self->{name}         = $name;
    $self->{author}       = $author;
    $self->{embedded_css} = "";

    return $self;
}

=head2 add_style

   Add CSS to the page. Should be called before header() so the style can be output in the <HEAD>.
   (XHTML 1.0 requires that embedded stylesheets be in the <HEAD>.)

   #Example
	$page->add_style(text => "some css text", file => "stylesheet.css");
	

=cut

sub add_style {
    my ( $self, %params ) = @_;
    if ( exists $params{text} ) {
        $self->{embedded_css} .=
          "<style type=\"text/css\">\n$params{text}\n</style>\n";
    }
    if ( exists $params{file} ) {
        $self->{embedded_css} .=
"<link rel=\"stylesheet\" type=\"text/css\" href=\"$params{file}\" />\n";
    }
}

sub get_header {
    my $self           = shift;

    return CXGN::MasonFactory->bare_render(
	'/site/header.mas',
	page_title => $self->{page_title},
	extra_headers => $self->jsan_render_includes
	                 . ( $self->{embedded_css}     || '' )
                         . ( $self->{extra_head_stuff} || '' ),
       );
}

sub get_footer {
    return CXGN::MasonFactory->bare_render('/site/footer.mas');
}

sub simple_footer { 
    my $self=shift;
 #
    carp "simple_footer() deprecated, please replace this with mason code";<commit_msg>removed CXGN::Page use of masonfactory<commit_after>
=head1 NAME

CXGN::Page

=head1 DESCRIPTION

Page object which handles headers, footers, simple message pages, and simple error pages. Can also retrieve page arguments and handle redirects.
This is now a subclass of CXGN::Scrap, which handles all of the argument-retrieval.

=cut

package CXGN::Page;
use base qw/CXGN::Scrap/;
use strict;
use Apache2::RequestUtil ();
use Apache2::Cookie;
use HTML::Entities qw/encode_entities/;
use URI::Escape;
use Carp;
use CGI qw/ -compile :html4/;
use CXGN::Page::FormattingHelpers qw(blue_section_html newlines_to_brs);
use CXGN::Apache::Error;
use CXGN::DB::Connection;
use CXGN::Login;
use CXGN::Page::VHost::SGN;
use CXGN::Tools::File;
use CXGN::Tools::SVN::Info;

use SGN::Context;


use Data::Dumper;
$Data::Dumper::Varname = 'VAR_DUMP';

## STDERR Capture for the Logger, by Developer Preference ####
our $STDERR_BUFFER  = '';
our $STDERR_CAPTURE = 0;

=head1 OBJECT METHODS

=head2 new

Creates a new page object. This will try to be smart and give you the correct type of header for your virtual host, based on the apache request.  All arguments are optional, but they are ordered.

	#Example
	my $page=CXGN::Page->new( $page_name, $author,
		{jslib => ['CXGN.MyModule','MochiKit.Logging', 'Prototype', 'Scriptaculous.DragDrop']});

The jslib in the final optional hashref is equivalent to using jsan_use() on the page.

=cut

sub new {
    my $class = shift;

    my $self = $class->SUPER::new();

    eval { $self->set_dbh(CXGN::DB::Connection->new());  };
    if ($@) { print STDERR "Oops, database does not seem to be available. ($@). Trying to continue without it...\n"; }

    $self->{mk_log_messages} = [];
    my ( $name, $author, $other ) = @_;
    if ( $other and my $js = $other->{jslib} ) {
        my @libs = ref $js ? @$js : ($js);
        $self->jsan_use(@libs);
    }
    $self->{context} = SGN::Context->new();
    $self->{project_name} = 'SGN';

    $self->{page_object} = CXGN::Page::VHost::SGN->new($self->get_dbh());
    $self->{page_object}->{page} = $self;

    $name   ||= '';
    $author ||= '';
    $self->{name}         = $name;
    $self->{author}       = $author;
    $self->{embedded_css} = "";

    return $self;
}

=head2 add_style

   Add CSS to the page. Should be called before header() so the style can be output in the <HEAD>.
   (XHTML 1.0 requires that embedded stylesheets be in the <HEAD>.)

   #Example
	$page->add_style(text => "some css text", file => "stylesheet.css");
	

=cut

sub add_style {
    my ( $self, %params ) = @_;
    if ( exists $params{text} ) {
        $self->{embedded_css} .=
          "<style type=\"text/css\">\n$params{text}\n</style>\n";
    }
    if ( exists $params{file} ) {
        $self->{embedded_css} .=
"<link rel=\"stylesheet\" type=\"text/css\" href=\"$params{file}\" />\n";
    }
}

sub get_header {
    my $self           = shift;

    return $self->{context}->render_mason(
	'/site/header.mas',
	page_title => $self->{page_title},
	extra_headers => $self->jsan_render_includes
	                 . ( $self->{embedded_css}     || '' )
                         . ( $self->{extra_head_stuff} || '' ),
       );
}

sub get_footer {
    my $self = shift;
    return $self->{context}->render_mason('/site/footer.mas');
}

sub simple_footer { 
    my $self=shift;
 #
    carp "simple_footer() deprecated, please replace this with mason code";
{'fraction_non_alphanumeric': 0.1655901350557839, 'fraction_numerical': 0.0032295948326482677, 'mean_word_length': 3.3869929169349646, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6911958', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2352, 'n_words': 640}