⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 response.pm

📁 codestriker is a develop useful tool to review code on web user interface.
💻 PM
📖 第 1 页 / 共 2 页
字号:
################################################################################ Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.# sits@users.sourceforge.net## This program is free software; you can redistribute it and modify it under# the terms of the GPL.# Collection of routines for creating HTTP responses, including headers and# error indications.package Codestriker::Http::Response;use strict;use Codestriker::Http::Cookie;use Codestriker::Http::UrlBuilder;use HTML::Entities ();# Constructor for this class.  Indicate that the response header hasn't been# generated yet.sub new($$) {    my ($type, $query) = @_;    my $self = {};    $self->{header_generated} = 0;    $self->{query} = $query;    $self->{format} = $query->param('format');    $self->{action} = $query->param('action');    return bless $self, $type;}# Return the query object associated with the response.sub get_query($) {    my ($self) = @_;    return $self->{query};}# Generate the initial HTTP response header, with the initial HTML header.# Most of the input parameters are used for storage into the user's cookie.sub generate_header {    my ($self, %params) = @_;    my $topic = undef;    my $topic_title = "";    my $email = "";    my $reviewers = "";    my $cc = "";    my $mode = "";    my $tabwidth = "";    my $repository = "";    my $projectid = "";    my $load_anchor = "";    my $topicsort = "";    my $password_hash = "";    my $fview = -1;    my $reload = $params{reload};    my $cache = $params{cache};    $load_anchor = $params{load_anchor};    $load_anchor = "" if ! defined $load_anchor;    # If the header has already been generated, do nothing.    return if ($self->{header_generated});    $self->{header_generated} = 1;    my $query = $self->{query};    # Set the topic and title parameters.    $topic = $params{topic};    $topic_title = $params{topic_title};    # Set the fview parameter if defined.    $fview = $params{fview} if defined $params{fview};    # Set the cookie in the HTTP header for the $email, $cc, $reviewers and    # $tabwidth parameters.    my %cookie = ();    if (! defined $params{email} || $params{email} eq "") {        $email = Codestriker::Http::Cookie->get_property($query, 'email');    } else {        $email = $params{email};    }    if (! defined $params{reviewers} || $params{reviewers} eq "") {        $reviewers = Codestriker::Http::Cookie->get_property($query,                                                             'reviewers');    } else {        $reviewers = $params{reviewers};    }    if (! defined $params{cc} || $params{cc} eq "") {        $cc = Codestriker::Http::Cookie->get_property($query, 'cc');    } else {        $cc = $params{cc};    }    if (! defined $params{tabwidth} || $params{tabwidth} eq "") {        $tabwidth = Codestriker::Http::Cookie->get_property($query,                                                            'tabwidth');    } else {        $tabwidth = $params{tabwidth};    }    if (! defined $params{mode} || $params{mode} eq "") {        $mode = Codestriker::Http::Cookie->get_property($query, 'mode');    } else {        $mode = $params{mode};    }    if (! defined $params{repository} || $params{repository} eq "") {        $repository = Codestriker::Http::Cookie->get_property($query,                                                              'repository');    } else {        $repository = $params{repository};    }    if (! defined $params{projectid} || $params{projectid} eq "") {        $projectid = Codestriker::Http::Cookie->get_property($query,                                                             'projectid');    } else {        $projectid = $params{projectid};    }    if (! defined $params{topicsort} || $params{topicsort} eq "") {        $topicsort = Codestriker::Http::Cookie->get_property($query,                                                             'topicsort');    } else {        $topicsort = $params{topicsort};    }    if (! defined $params{password_hash} || $params{password_hash} eq "") {        $password_hash = Codestriker::Http::Cookie->get_property($query,                                                                 'password_hash');    } else {        $password_hash = $params{password_hash};    }    $cookie{'email'} = $email if $email ne "";    $cookie{'reviewers'} = $reviewers if $reviewers ne "";    $cookie{'cc'} = $cc if $cc ne "";    $cookie{'tabwidth'} = $tabwidth if $tabwidth ne "";    $cookie{'mode'} = $mode if $mode ne "";    $cookie{'repository'} = $repository if $repository ne "";    $cookie{'projectid'} = $projectid if $projectid ne "";    $cookie{'topicsort'} = $topicsort if $topicsort ne "";    $cookie{'password_hash'} = $password_hash if $password_hash ne "";    my $cookie_obj = Codestriker::Http::Cookie->make($query, \%cookie);    # This logic is taken from cvsweb.  There is _reason_ behind this logic...    # Basically mozilla supports gzip regardless even though some versions    # don't state this.  IE claims it does, but doesn't support it.  Using    # the gzip binary technique doesn't work apparently under mod_perl.    # Determine if the client browser is capable of handled compressed HTML.    eval {        require Compress::Zlib;    };    my $output_compressed = 0;    my $has_zlib = !$@;    my $browser = $ENV{'HTTP_USER_AGENT'};    my $can_compress = ($Codestriker::use_compression &&                        ((defined($ENV{'HTTP_ACCEPT_ENCODING'})                          && $ENV{'HTTP_ACCEPT_ENCODING'} =~ m|gzip|)                         || $browser =~ m%^Mozilla/3%)                        && ($browser !~ m/MSIE/)                        && !(defined($ENV{'MOD_PERL'}) && !$has_zlib));    # Output the appropriate header if compression is allowed to the client.    if ($can_compress &&        ($has_zlib || ($Codestriker::gzip ne "" &&                       open(GZIP, "| $Codestriker::gzip -1 -c")))) {        if ($cache) {            print $query->header(-cookie=>$cookie_obj,                                 -content_encoding=>'x-gzip',                                 -charset=>"UTF-8",                                 -vary=>'Accept-Encoding');        } else {            print $query->header(-cookie=>$cookie_obj,                                 -expires=>'+1d',                                 -charset=>"UTF-8",                                 -cache_control=>'no-store',                                 -pragma=>'no-cache',                                 -content_encoding=>'x-gzip',                                 -vary=>'Accept-Encoding');        }        # Flush header output, and switch STDOUT to GZIP.        $| = 1; $| = 0;        if ($has_zlib) {            tie *GZIP, __PACKAGE__, \*STDOUT;        }        select(GZIP);        $output_compressed = 1;    } else {        # Make sure the STDOUT encoding is set to UTF8.  Not needed        # when the data is being sent as compressed bytes.        binmode STDOUT, ':utf8';        if ($cache) {            print $query->header(-cookie=>$cookie_obj,                                 -charset=>"UTF-8");        } else {            print $query->header(-cookie=>$cookie_obj,                                 -expires=>'+1d',                                 -charset=>"UTF-8",                                 -cache_control=>'no-store',                                 -pragma=>'no-cache');        }    }    my $title = "Codestriker";    if (defined $topic_title && $topic_title ne "") {        $title .= ": \"$topic_title\"";    }    $title = HTML::Entities::encode($title);    # Generate the URL to the codestriker CSS file.    my $codestriker_css;    if (defined $Codestriker::codestriker_css &&        $Codestriker::codestriker_css ne "") {        if ($Codestriker::codestriker_css =~ /[\/\\]/o) {            # Assume CSS file is specified with absolute path.            $codestriker_css = $Codestriker::codestriker_css;        } else {            # Assume CSS file is in case html directory, just under            # a different name.            $codestriker_css = $query->url();            $codestriker_css =~ s#/[^/]+?/codestriker\.pl#/codestrikerhtml/$Codestriker::codestriker_css#;        }    } else {        # Use the default CSS file.        $codestriker_css = $query->url();        if ($query->url() =~ /codestriker.pl$/) {            $codestriker_css =~ s#/[^/]+?/codestriker\.pl#/codestrikerhtml/codestriker.css#;        } else {            $codestriker_css = $query->url() . "html/codestriker.css";        }    }    my $codestrikerhtml_path = $codestriker_css;    $codestrikerhtml_path =~ s/\/[\w\-]*.css/\//;    my $overlib_js = $codestrikerhtml_path . "overlib.js";    my $overlib_centerpopup_js = $codestrikerhtml_path . "overlib_centerpopup.js";    my $overlib_draggable_js = $codestrikerhtml_path . "overlib_draggable.js";    my $xbdhtml_js = $codestrikerhtml_path . "xbdhtml.js";    my $codestriker_js = $codestrikerhtml_path . "codestriker.js";    # Print the basic HTML header header, with the inclusion of the scripts.    # Make sure a DOCTYPE is used which will put IE 6 and above into    # "standards-compliant mode": http://msdn.microsoft.com/en-us/library/ms535242(VS.85).aspx.    print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">';    print "\n";    print '<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">';    print "\n";    print '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';    print "\n";    print "<head><title>$title</title>\n";    print "<link rel=\"stylesheet\" type=\"text/css\" href=\"$codestriker_css\" />\n";    print "<script src=\"$overlib_js\" type=\"text/javascript\"></script>\n";    print "<script src=\"$overlib_centerpopup_js\" type=\"text/javascript\"></script>\n";    print "<script src=\"$overlib_draggable_js\" type=\"text/javascript\"></script>\n";    print "<script src=\"$xbdhtml_js\" type=\"text/javascript\"></script>\n";    print "<script src=\"$codestriker_js\" type=\"text/javascript\"></script>\n";    print "<script type=\"text/javascript\">\n";    print "    var cs_load_anchor = '$load_anchor';\n";    print "    var cs_reload = $reload;\n";    print "    var cs_topicid = $topic->{topicid};\n" if defined $topic;    print "    var cs_projectid = $topic->{project_id};\n" if defined $topic;    print "    var cs_email = '$email';\n" if defined $email;    print "    var cs_css = '$codestriker_css';\n";    print "    var cs_xbdhtml_js = '$xbdhtml_js';\n";    # Now output all of the comment metric information.    print "    var cs_metric_data = new Array();\n";    my $i = 0;    foreach my $metric_config (@{ $Codestriker::comment_state_metrics }) {        print "    cs_metric_data[$i] = new Object();\n";        print "    cs_metric_data[$i].name = '" .          $metric_config->{name} . "';\n";        print "    cs_metric_data[$i].values = new Array();\n";        my $j = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -