Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[ljcom] r10223: LJSUP-8025: variables with numbers of jo...

Committer: gariev
LJSUP-8025: variables with numbers of journals and posts

U   trunk/cgi-bin/LJ/PublicStats.pm
U   trunk/cgi-bin/LJ/Widget/PublicStats.pm
Modified: trunk/cgi-bin/LJ/PublicStats.pm
===================================================================
--- trunk/cgi-bin/LJ/PublicStats.pm	2011-03-11 03:31:55 UTC (rev 10222)
+++ trunk/cgi-bin/LJ/PublicStats.pm	2011-03-11 04:44:35 UTC (rev 10223)
@@ -5,41 +5,19 @@
 # Get stats from DB if not cached
 sub load_stats {
     if (!defined $LJ::CACHE_STAT_ACCTS || !defined $LJ::CACHE_STAT_POSTS_DAY) {
-        my $dbr = LJ::get_db_reader();
-
-        if (!defined $LJ::CACHE_STAT_ACCTS) {
-            $LJ::CACHE_STAT_ACCTS = $dbr->selectrow_array("SELECT statval FROM stats WHERE statcat='size' AND statkey='accounts'")+0;
+        if ($LJ::IS_DEV_SERVER) {
+            $LJ::CACHE_STAT_ACCTS = 31_234_567;
+            $LJ::CACHE_STAT_POSTS_DAY = 987_654;
+        } else {
+            my $dbr = LJ::get_db_reader();
+            if (!defined $LJ::CACHE_STAT_ACCTS) {
+                $LJ::CACHE_STAT_ACCTS = $dbr->selectrow_array("SELECT statval FROM stats WHERE statcat='size' AND statkey='accounts'")+0;
+            }
+            if (!defined $LJ::CACHE_STAT_POSTS_DAY) {
+                $LJ::CACHE_STAT_POSTS_DAY = $dbr->selectrow_array("SELECT statval FROM stats WHERE statcat='userinfo' AND statkey='updated_last1'")+0;
+            }
         }
-
-        if (!defined $LJ::CACHE_STAT_POSTS_DAY) {
-            $LJ::CACHE_STAT_POSTS_DAY = $dbr->selectrow_array("SELECT statval FROM stats WHERE statcat='userinfo' AND statkey='updated_last1'")+0;
-        }
     }
 }
 
-# renders and commafies the stats
-sub make_stats_table {
-    my $number = shift;
-    my %opts = @_;
-
-    my $short_numbers = defined $opts{short_numbers} ? $opts{short_numbers} : 0;
-
-    my $final_number;
-    if ($short_numbers) {
-        if ($number >= 1_000_000) {
-            $final_number = sprintf(LJ::Lang::ml('number.million', { number => "%0.1f" }), $number / 1_000_000);
-        } elsif ($number >= 1_000) {
-            $final_number = sprintf(LJ::Lang::ml('number.thousand', { number => "%0.1f" }), $number / 1_000);
-        }
-    } else {
-        $final_number = LJ::commafy($number);
-    }
-
-    my $ret = "<div class='publicstats-wrapper'>";
-    $ret .= $final_number;
-    $ret .= "</div>";
-
-    return $ret;
-}
-
 1;

Modified: trunk/cgi-bin/LJ/Widget/PublicStats.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/PublicStats.pm	2011-03-11 03:31:55 UTC (rev 10222)
+++ trunk/cgi-bin/LJ/Widget/PublicStats.pm	2011-03-11 04:44:35 UTC (rev 10223)
@@ -2,8 +2,7 @@
 
 use strict;
 use base qw(LJ::Widget);
-use Carp qw(croak);
-use Class::Autouse qw( LJ::PublicStats );
+use LJ::PublicStats;
 
 sub need_res { qw( stc/widgets/publicstats.css ) }
 
@@ -11,51 +10,71 @@
     my $class = shift;
     my %opts = @_;
 
-    my $show_total_accts = defined $opts{show_total_accts} ? $opts{show_total_accts} : 1;
-    my $show_posts_day = defined $opts{show_posts_day} ? $opts{show_posts_day} : 1;
-    my $show_latest_posts = defined $opts{show_latest_posts} ? $opts{show_latest_posts} : 1;
-    my $total_accts = "";
-    my $posts_day = "";
-
     # Make sure stats are loaded
     LJ::PublicStats::load_stats();
 
-    if ($LJ::CACHE_STAT_ACCTS && $show_total_accts) {
-        $total_accts = LJ::PublicStats::make_stats_table($LJ::CACHE_STAT_ACCTS, short_numbers => $opts{short_numbers} );
-        if ($total_accts) {
-            $total_accts = "<div class='statmeter stats-total pkg'>$total_accts<p class='detail'>" . $class->ml('.widget.publicstats.sincestart') . "</p></div>";
+    if ($opts{'show_developers_widget'}) {
+        my $total_accts = format_stats_number($LJ::CACHE_STAT_ACCTS,      short_numbers => 1, number_format => "<strong>%0.1f</strong>" );
+        my $posts_day   = format_stats_number($LJ::CACHE_STAT_POSTS_DAY,  short_numbers => 1, number_format => "<strong>%0.1f</strong>" );
+        my $text_sincestart = $class->ml('.widget.publicstats.sincestart');
+        my $text_day        = $class->ml('.widget.publicstats.day');
+        return <<"END"
+<dl class="b-promo-stat">
+    <dt>$text_sincestart</dt><dd>$total_accts</dd>
+    <dt>$text_day</dt><dd>$posts_day</dd>
+</dl> 
+END
+    } else {
+        my $total_accts = format_stats_number($LJ::CACHE_STAT_ACCTS,      short_numbers => $opts{short_numbers} );
+        my $posts_day   = format_stats_number($LJ::CACHE_STAT_POSTS_DAY,  short_numbers => $opts{short_numbers} );
+        my $show_total_accts    = defined $opts{show_total_accts}   ? $opts{show_total_accts}   : 1;
+        my $show_posts_day      = defined $opts{show_posts_day}     ? $opts{show_posts_day}     : 1;
+        my $show_latest_posts   = defined $opts{show_latest_posts}  ? $opts{show_latest_posts}  : 1;
+
+        my $ret;
+        $ret .= "<table cellspacing='0' cellpadding='0'><tr valign='top'>";
+
+        if ($show_total_accts) {
+            my $text_sincestart = $class->ml('.widget.publicstats.sincestart');
+            $ret .=     "<td width='50%' style='padding-right: 10px;'>" . 
+                        "<div class='statmeter stats-total pkg'><div class='publicstats-wrapper'>$total_accts</div>" . 
+                        "<p class='detail'>$text_sincestart</p></div>" .
+                        "</td>";
         }
-    }
 
-    if ($LJ::CACHE_STAT_POSTS_DAY && $show_posts_day) {
-        $posts_day = LJ::PublicStats::make_stats_table($LJ::CACHE_STAT_POSTS_DAY, short_numbers => $opts{short_numbers} );
-        if ($posts_day) {
-            $posts_day = "<div class='statmeter stats-daily pkg'>$posts_day<p class='detail'>" . $class->ml('.widget.publicstats.day') . "</p></div>";
+        if ($show_posts_day) {
+            $ret .= "<td><div class='statmeter stats-daily pkg'><div class='publicstats-wrapper'>$posts_day</div></td>" .
+                    "<p class='detail'>" . $class->ml('.widget.publicstats.day') . "</p></div>";
+
+            if ($show_latest_posts) {
+                my $text_latestposts = $class->ml('.widget.publicstats.latestposts');
+                my $text_rssalt = $class->ml('.widget.publicstats.rssalt');
+                $ret .= "</tr><tr><td colspan='2'><a href='$LJ::SITEROOT/stats/latest.bml'>$text_latestposts</a>" . 
+                        "<a href='$LJ::SITEROOT/stats/latest-rss.bml'>" . 
+                        "<img src='$LJ::IMGPREFIX/xml.gif' alt='$text_rssalt' align='absmiddle' height='14' width='36' border='0'></a></td>";
+            }
         }
-    }
 
-    if ($LJ::IS_DEV_SERVER) {
-        $total_accts = 100;
-        $posts_day = 200;
+        $ret .= "</tr></table>";
+        return $ret;
     }
+}
 
-    return "" if $total_accts eq "" && $posts_day eq "";
+sub format_stats_number {
+    my $number = shift;
+    my %opts = @_;
 
-    my $ret;
-
-    $ret .= "<table cellspacing='0' cellpadding='0'><tr valign='top'>";
-    if ($show_total_accts) {
-        $ret .= "<td width='50%' style='padding-right: 10px;'>$total_accts</td>";
-    }
-    if ($show_posts_day) {
-        $ret .= "<td>$posts_day</td>";
-        if ($show_latest_posts) {
-            $ret .= "</tr><tr><td colspan='2'><a href='$LJ::SITEROOT/stats/latest.bml'>" . $class->ml('.widget.publicstats.latestposts') . "</a> <a href='$LJ::SITEROOT/stats/latest-rss.bml'><img src='$LJ::IMGPREFIX/xml.gif' alt='" . $class->ml('.widget.publicstats.rssalt') . "' align='absmiddle' height='14' width='36' border='0'></a></td>";
+    if ($opts{short_numbers}) {
+        my $number_format   = $opts{number_format} || "%0.1f"; 
+        if ($number >= 1_000_000) {
+            return LJ::Lang::ml('number.million',  { number => sprintf($number_format, $number / 1_000_000)});
+        } elsif ($number >= 1_000) {
+            return LJ::Lang::ml('number.thousand', { number => sprintf($number_format, $number / 1_000)});
         }
+    } else {
+        return LJ::commafy($number);
     }
-    $ret .= "</tr></table>";
-
-    return $ret;
 }
 
+
 1;

Tags: gariev, ljcom, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments