Use a controller, instead of a BML page. (Better future-proofing, no 
user-facing functional changes)

        Patch by exor674. 

diffs (135 lines):

diff -r 15097b759f54 -r 697554d09cd1 cgi-bin/DW/Controller/CommentCount.pm
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Controller/CommentCount.pm     Mon Apr 05 07:45:39 2010 -0700
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+#
+# DW::Controller::CommentCount
+#
+# Creates an image that shows the current number of comments on 
+# the given post.
+#
+# Authors:
+#      Allen Petersen
+#      Andrea Nall <[email protected]>
+#
+# Copyright (c) 2009-2010 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+#
+
+package DW::Controller::CommentCount;
+
+use strict;
+use warnings;
+use DW::Routing;
+use Image::Magick;
+
+DW::Routing->register_string("/tools/commentcount", \&commentcount_handler, 
app => 1);
+
+sub commentcount_handler {
+    my $r = DW::Request->get;
+    my $args = $r->get_args;
+
+    my $count = $args->{samplecount} || 0;
+
+    my $entry = undef;
+
+    if ( $args->{ditemid} && $args->{user} ) {
+        my $ditemid = $args->{ditemid};
+        my $uid = LJ::get_userid( $args->{user} );
+        $entry = LJ::Entry->new( $uid, ditemid => $ditemid ) if $uid;
+    }
+
+    $count = $entry->reply_count if $entry;
+
+    # create an image
+    my $image = Image::Magick->new;
+    $image->Set(pen => 'black');
+    $image->Set(font => 'Generic.ttf');
+    $image->Set(pointsize => 12);
+    $image->Set(size => '30x12');
+    $image->Read("label:$count");
+
+    # return the image
+    $r->content_type("image/png");
+    $r->print( $image->ImageToBlob( magick => "png" ) );
+
+    return $r->OK;
+}
+
+1;
diff -r 15097b759f54 -r 697554d09cd1 cgi-bin/modperl.pl
--- a/cgi-bin/modperl.pl        Mon Apr 05 00:16:35 2010 -0700
+++ b/cgi-bin/modperl.pl        Mon Apr 05 07:45:39 2010 -0700
@@ -44,21 +44,8 @@ use lib "$ENV{LJHOME}/cgi-bin";
 #    return Apache2::Const::OK;
 #}
 
-# Image::Size wants to pull in Image::Magick.  Let's not let it during
-# the init process.
-my $still_loading = 1;
-unshift @INC, sub {
-    my $f = $_[1];
-    return undef unless $still_loading;
-    return undef unless $f eq "Image/Magick.pm";
-    die "Will not start with Image/Magick.pm"; # makes the require fail, which 
Image::Size traps
-};
-
 # pull in libraries and do per-start initialization once.
 require "modperl_subs.pl";
-
-# now we're done loading
-$still_loading = 0;
 
 # do per-restart initialization
 LJ::ModPerl::setup_restart();
diff -r 15097b759f54 -r 697554d09cd1 htdocs/tools/commentcount.bml
--- a/htdocs/tools/commentcount.bml     Mon Apr 05 00:16:35 2010 -0700
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-<?_c
-# This code was forked from the LiveJournal project owned and operated
-# by Live Journal, Inc. The code has been modified and expanded by
-# Dreamwidth Studios, LLC. These files were originally licensed under
-# the terms of the license supplied by Live Journal, Inc, which can
-# currently be found at:
-#
-# 
http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt
-#
-# In accordance with the original license, this code and all its
-# modifications are provided under the GNU General Public License.
-# A copy of that license can be found in the LICENSE file included as
-# part of this distribution.
-_c?><?_code # -*-bml-*-
-{
-    use strict;
-    use vars qw(%GET);
-    use Image::Magick;
-
-    # creates an image that shows the current number of comments on 
-    # the given post.
-
-    my $ditemid = $GET{ditemid};
-    my $uid = LJ::get_userid( $GET{user} );
-
-    # get the value to display
-    my $count = $GET{samplecount} || eval { LJ::Entry->new( $uid, ditemid => 
$ditemid )->reply_count } || 0;
-
-    # create an image
-    my $image = Image::Magick->new;
-    $image->Set(pen => 'black');
-    $image->Set(font => 'Generic.ttf');
-    $image->Set(pointsize => 12);
-    $image->Set(size => '30x12');
-    $image->Read("label:$count");
-
-    # return the image
-    BML::set_content_type("image/png");
-    BML::noparse();
-
-    return $image->ImageToBlob( magick => "png" );
-}
-_code?>
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to