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

📄 response.pm

📁 codestriker is a develop useful tool to review code on web user interface.
💻 PM
📖 第 1 页 / 共 2 页
字号:
        foreach my $value (@{ $metric_config->{values} }) {            print "    cs_metric_data[$i].values[$j] = '$value';\n";            $j++;        }        if (defined $metric_config->{default_value}) {            print "    cs_metric_data[$i].default_value = '" .              $metric_config->{default_value} . "';\n";        }        $i++;    }    # Output the URL to post to for adding comments.    if (defined $topic) {        my $url_builder = Codestriker::Http::UrlBuilder->new($self->{query});        print "    var cs_add_comment_url = '" .          $url_builder->add_comment_url(topicid => $topic->{topicid}, projectid => $topic->{project_id}) . "';\n";    }    # Check that the external javascript files were loaded, and if not    # output an error message.  This is usually due to a    # misconfiguration.    print "    if ('function' != typeof window.add_comment_html) {\n";    print "        alert('Oh oh... can\\'t find codestriker.js, please check your web-server config.');\n";    print "    }\n";    print "</script>\n";    # Output the comment declarations if the $comments array is defined.    my $comments = $params{comments};    if (defined $comments) {        print generate_comment_declarations($topic, $comments, $query,                                            $fview, $tabwidth);    }    # Write an HTML comment indicating if response was sent compressed or not.    $self->{output_compressed} = $output_compressed;    print "\n<!-- Source was" . (!$output_compressed ? " not" : "") .      " sent compressed. -->\n";}# Return the javascript code necessary to support viewing/modification of# comments.sub generate_comment_declarations  {      my ($topic, $comments, $query, $fview, $tabwidth) = @_;      # The output html to return.      my $html = "";      # Build a hash from filenumber|fileline|new -> comment array, to record      # what comments are associated with what locations.  Also record the      # order of comment_locations found.      my %comment_hash = ();      my @comment_locations = ();      for (my $i = 0; $i <= $#$comments; $i++) {          my $comment = $$comments[$i];          my $key = $comment->{filenumber} . "|" . $comment->{fileline} . "|" .            $comment->{filenew};          if (! exists $comment_hash{$key}) {              push @comment_locations, $key;          }          push @{ $comment_hash{$key} }, $comment;      }      # Precompute the overlib HTML for each comment location.      $html .= "\n<script language=\"JavaScript\" type=\"text/javascript\">\n";      # Add the reviewers for the review here.      $html .= "    var topic_reviewers = '" . $topic->{reviewers} . "';\n";      # Now record all the comments made so far in the topic.      $html .= "    var comment_text = new Array();\n";      $html .= "    var comment_hash = new Array();\n";      $html .= "    var comment_metrics = new Array();\n";      my $index;      for ($index = 0; $index <= $#comment_locations; $index++) {          # Contains the overlib HTML text.          my $overlib_html = "";          # Determine what the previous and next comment locations are.          my $previous = undef;          my $next = undef;          if ($index > 0) {              $previous = $comment_locations[$index-1];          }          if ($index < $#comment_locations) {              $next = $comment_locations[$index+1];          }          # Compute the previous link if required.          my $current_url = $query->self_url();          if (defined $previous && $previous =~ /^(\-?\d+)|\-?\d+|\d+$/o) {              my $previous_fview = $1;              my $previous_index = $index - 1;              my $previous_url = $current_url;              $previous_url =~ s/fview=\d+/fview=$previous_fview/o if $fview != -1;              $previous_url .= '#' . $previous;              $overlib_html .= "<a href=\"javascript:window.location=\\'$previous_url\\'; ";              if ($fview == -1 || $fview == $previous_fview) {                  $overlib_html .= "overlib(comment_text[$previous_index], STICKY, DRAGGABLE, ALTCUT, FIXX, getEltPageLeft(getElt(\\'$previous\\')), FIXY, getEltPageTop(getElt(\\'$previous\\'))); ";              }              $overlib_html .= "void(0);\">Previous</a>";          }          # Compute the next link if required.          if (defined $next && $next =~ /^(\-?\d+)|\-?\d+|\d+$/o) {              my $next_fview = $1;              $overlib_html .= " | " if defined $previous;              my $next_index = $index + 1;              my $next_url = $current_url;              $next_url =~ s/fview=\d+/fview=$next_fview/o if $fview != -1;              $next_url .= '#' . $next;              $overlib_html .= "<a href=\"javascript:window.location=\\'$next_url\\'; ";              if ($fview == -1 || $fview == $next_fview) {                  $overlib_html .= "overlib(comment_text[$next_index], STICKY, DRAGGABLE, ALTCUT, FIXX, getEltPageLeft(getElt(\\'$next\\')), FIXY, getEltPageTop(getElt(\\'$next\\'))); ";              }              $overlib_html .= "void(0);\">Next</a>";          }          if (defined $previous || defined $next) {              $overlib_html .= " | ";          }          # Add an add comment link.          my $key = $comment_locations[$index];          $key =~ /^(\-?\d+)\|(\-?\d+)\|(\d+)$/o;          if (!Codestriker::topic_readonly($topic->{topic_state})) {              $overlib_html .= "<a href=\"javascript:add_comment_tooltip($1,$2,$3)" .                "; void(0);\">Add Comment<\\/a> | ";          }          # Add a close link.          $overlib_html .= "<a href=\"javascript:hideElt(getElt(\\'overDiv\\')); void(0);\">Close<\\/a><p>";          # Create the actual comment text.          my @comments = @{ $comment_hash{$key} };          for (my $i = 0; $i <= $#comments; $i++) {              my $comment = $comments[$i];              # Need to format the data appropriately for HTML display.              my $data = HTML::Entities::encode($comment->{data});              $data =~ s/\\/\\\\/mgo;              $data =~ s/\'/\\\'/mgo;              $data =~ s/\n/<br>/mgo;              $data =~ s/ \s+/'&nbsp;' x (length($&)-1)/emgo;              $data = Codestriker::tabadjust($tabwidth, $data, 1);              # Show each comment with the author and date in bold.              $overlib_html .= "<b>Comment from $comment->{author} ";              $overlib_html .= "on $comment->{date}<\\/b><br>";              $overlib_html .= "$data";              # Add a newline at the end if required.              if ($i < $#comments &&                  substr($overlib_html, length($overlib_html)-4, 4) ne '<br>') {                  $overlib_html .= '<br>';              }          }          $html .= "    comment_text[$index] = '$overlib_html';\n";          $html .= "    comment_hash['" . $comment_locations[$index] .            "'] = $index;\n";          # Store the current metric values for this comment.          $html .= "    comment_metrics[$index] = new Array();\n";          my $comment_metrics = $comments[0]->{metrics};          foreach my $metric_config (@{ $Codestriker::comment_state_metrics }) {              my $value = $comment_metrics->{$metric_config->{name}};              $value = "" unless defined $value;              $html .= "    comment_metrics[${index}]['" .                $metric_config->{name} . "'] = '" . $value . "';\n";          }      }      $html .= "</script>\n";      # Now declare the CSS positional elements for each comment location.      $html .= "<style type=\"text/css\">\n";      for (my $i = 0; $i <= $#$comments; $i++) {          $html .= '#c' . $i . ' { position: absolute; }' . "\n";      }      $html .= "</style>\n";      # Return the generated HTML.      return $html;  }# Close the response, which only requires work if we are dealing with# compressed streams.sub generate_footer($) {    my ($self) = @_;    if ($self->{output_compressed}) {        select(STDOUT);        close(GZIP);        untie *GZIP;    }}# Generate an error page response if bad input was passed in.sub error($$) {    my ($self, $error_message) = @_;    my $query = $self->{query};    # Check if the expected format is XML.    if (defined $self->{format} && $self->{format} eq "xml") {        print $query->header(-content_type=>'text/xml');        print "<?xml version=\"1.0\" encoding=\"UTF-8\" " .          "standalone=\"yes\"?>\n";        print "<response><method>" . $self->{action} . "</method>" .          "<result>" . HTML::Entities::encode($error_message) .            "</result></response>\n";    } else {        if (! $self->{header_generated}) {            print $query->header,              $query->start_html(-title=>'Codestriker error',                                 -bgcolor=>'white');        }        print $query->p, "<FONT COLOR='red'>$error_message</FONT>", $query->p;        print $query->end_html();        $self->generate_footer();    }    exit;}# Implement a gzipped file handle via the Compress:Zlib compression# library.  This code was stolen from CVSweb.sub MAGIC1() { 0x1f }sub MAGIC2() { 0x8b }sub OSCODE() { 3    }sub TIEHANDLE {    my ($class, $out) = @_;    my $level = Compress::Zlib::Z_BEST_COMPRESSION();    my $wbits = -Compress::Zlib::MAX_WBITS();    my ($d) = Compress::Zlib::deflateInit(-Level => $level,                                          -WindowBits => $wbits)      or return undef;    my ($o) = {               handle => $out,               dh => $d,               crc => 0,               len => 0,              };    my ($header) = pack("C10", MAGIC1, MAGIC2,                        Compress::Zlib::Z_DEFLATED(),                        0,0,0,0,0,0, OSCODE);    print {$o->{handle}} $header;    return bless($o, $class);}sub PRINT {    my ($o) = shift;    my ($buf) = join(defined $, ? $, : "",@_);    my ($len) = length($buf);    my ($compressed, $status) = $o->{dh}->deflate($buf);    print {$o->{handle}} $compressed if defined($compressed);    $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});    $o->{len} += $len;    return $len;}sub CLOSE {    my ($o) = @_;    return if !defined( $o->{dh});    my ($buf) = $o->{dh}->flush();    $buf .= pack("V V", $o->{crc}, $o->{len});    print {$o->{handle}} $buf;    undef $o->{dh};}sub DESTROY {    my ($o) = @_;    CLOSE($o);}1;

⌨️ 快捷键说明

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