Code modernization: move mood theme logic out of package LJ and into
its own package (DW::Mood). Also involves the creation of a mood theme object
and using that, where applicable, instead of relying purely on class methods.
Patch by kareila.
diffs (875 lines):
diff -r b97315fc8d4b -r 29f13c2dc059
cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm
--- a/cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm Wed Jun 16 13:48:22
2010 +0800
+++ b/cgi-bin/DW/External/XPostProtocol/LJXMLRPC.pm Thu Jun 17 15:02:55
2010 +0800
@@ -361,23 +361,23 @@ sub entry_to_req {
# 1. use the mood icon that matches the given mood id
# 2. use the mood icon that matches the given mood text
# 3. don't use an icon
- $external_moodid = LJ::get_external_site_moodid( siteid => $siteid,
moodid => $moodid );
+ $external_moodid = DW::Mood->get_external_moodid( siteid => $siteid,
moodid => $moodid );
unless ( $external_moodid ) {
- $external_moodid = LJ::get_external_site_moodid( siteid =>
$siteid, mood => $mood );
+ $external_moodid = DW::Mood->get_external_moodid( siteid =>
$siteid, mood => $mood );
}
} elsif ( $moodid ) {
# try these in order:
# 1. use the mood icon that matches the given mood id
# 2. use the mood text that matches the given mood id (no icon)
- $external_moodid = LJ::get_external_site_moodid( siteid => $siteid,
moodid => $moodid );
+ $external_moodid = DW::Mood->get_external_moodid( siteid => $siteid,
moodid => $moodid );
unless ( $external_moodid ) {
- $req->{props}->{current_mood} = LJ::mood_name( $moodid );
+ $req->{props}->{current_mood} = DW::Mood->mood_name( $moodid );
}
} elsif ( $mood ) {
# try these in order:
# 1. use the mood icon that matches the given mood text
# 2. use the mood text that was given (no icon)
- $external_moodid = LJ::get_external_site_moodid( siteid => $siteid,
mood => $mood );
+ $external_moodid = DW::Mood->get_external_moodid( siteid => $siteid,
mood => $mood );
unless ( $external_moodid ) {
$req->{props}->{current_mood} = $mood;
}
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/DW/Mood.pm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/DW/Mood.pm Thu Jun 17 15:02:55 2010 +0800
@@ -0,0 +1,211 @@
+#!/usr/bin/perl
+#
+# DW::Mood - Provide mood theme support. Replaces ljmood.pl from LJ.
+#
+# Authors:
+# Jen Griffin <[email protected]>
+#
+# Copyright (c) 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::Mood;
+
+use strict;
+use warnings;
+
+# basic object construction: requires theme id
+# arguments: theme id (required)
+# returns: object reference, undef on failure
+sub new {
+ my ( $class, $id ) = @_;
+ return undef unless $id;
+ my $self = {}; # id set via object method below
+ bless $self, ( ref $class ? ref $class : $class );
+ return undef unless $self->id( $id );
+ $self->load_moods; # not necessary but saves effort later
+ return $self->load_theme;
+}
+
+# basic get/set for theme id
+# arguments: set if theme id given, get if no args
+# returns: value of theme id, undef on failure
+sub id {
+ my ( $self, $id ) = @_;
+ return undef if $id && $id !~ /^\d+$/; # invalid id
+ return $id unless ref $self; # class method
+ return $self->{id} unless $id; # get only
+ return $self->{id} = $id; # set and return
+}
+
+# load theme data from DB (adapted from LJ::load_mood_theme)
+# arguments: theme id (only required if called as class method)
+# returns: object reference, undef on failure
+sub load_theme {
+ my ( $self, $themeid ) = @_;
+
+ # force object path if called as class
+ return $self->new( $themeid ) unless ref $self;
+
+ # check themeid and assign it to the object
+ return undef unless $themeid = $self->id( $themeid );
+
+ # check global memory cache
+ return $self if $LJ::CACHE_MOOD_THEME{$themeid};
+
+ # check memcache
+ my $memkey = [$themeid, "moodthemedata:$themeid"];
+ $LJ::CACHE_MOOD_THEME{$themeid} = LJ::MemCache::get( $memkey );
+ return $self if %{ $LJ::CACHE_MOOD_THEME{$themeid} || {} };
+
+ # fall back to db
+ $LJ::CACHE_MOOD_THEME{$themeid} = {};
+ my $dbr = LJ::get_db_reader();
+
+ # load picture rows from moodthemedata
+ my $data = $dbr->selectall_arrayref(
+ "SELECT moodid, picurl, width, height FROM moodthemedata " .
+ "WHERE moodthemeid=?", undef, $themeid );
+ die $dbr->errstr if $dbr->err;
+
+ # load metadata from moodthemes
+ my ( $name, $des ) = $dbr->selectrow_array(
+ "SELECT name, des FROM moodthemes WHERE moodthemeid=?",
+ undef, $themeid );
+ die $dbr->errstr if $dbr->err;
+
+ $LJ::CACHE_MOOD_THEME{$themeid}->{name} = $name;
+ $LJ::CACHE_MOOD_THEME{$themeid}->{des} = $des;
+
+ foreach my $d ( @$data ) {
+ my ( $id, $pic, $w, $h ) = @$d;
+ $LJ::CACHE_MOOD_THEME{$themeid}->{$id} =
+ { pic => $pic, w => $w, h => $h };
+ }
+
+ # set in memcache
+ LJ::MemCache::set( $memkey, $LJ::CACHE_MOOD_THEME{$themeid}, 3600 )
+ if %{ $LJ::CACHE_MOOD_THEME{$themeid} || {} };
+
+ return $self;
+}
+
+# class method to load list of moods from DB (adapted from LJ::load_moods)
+# arguments: none
+# returns: true
+sub load_moods {
+ return 1 if $LJ::CACHED_MOODS;
+
+ $LJ::CACHED_MOOD_MAX ||= 0;
+
+ my $dbr = LJ::get_db_reader();
+ my $data = $dbr->selectall_arrayref(
+ "SELECT moodid, mood, parentmood, weight FROM moods" );
+ die $dbr->errstr if $dbr->err;
+ foreach my $row ( @$data ) {
+ my ( $id, $mood, $parent, $weight ) = @$row;
+ $LJ::CACHE_MOODS{$id} =
+ { name => $mood, parent => $parent, id => $id, weight => $weight };
+ $LJ::CACHED_MOOD_MAX = $id if $id > $LJ::CACHED_MOOD_MAX;
+ }
+ return $LJ::CACHED_MOODS = 1;
+}
+
+# class method to get list of moods from cache (adapted from LJ::get_moods)
+# arguments: class
+# returns: hashref
+sub get_moods {
+ my ( $self ) = @_;
+ $self->load_moods;
+ return \%LJ::CACHE_MOODS;
+}
+
+# object method to load a mood icon (adapted from LJ::get_mood_picture)
+# arguments: moodid; hashref to assign with mood icon data
+# returns: 1 on success, 0 otherwise.
+sub get_picture {
+ my ( $self, $moodid, $ref ) = @_;
+ return 0 unless $ref && ref $ref;
+ my $themeid = $self->id or return 0;
+
+ while ( $moodid ) {
+ # inheritance check
+ unless ( $LJ::CACHE_MOOD_THEME{$themeid} &&
+ $LJ::CACHE_MOOD_THEME{$themeid}->{$moodid} ) {
+ $moodid = defined $LJ::CACHE_MOODS{$moodid} ?
+ $LJ::CACHE_MOODS{$moodid}->{parent} : 0;
+ next;
+ }
+ # load the data
+ %{ $ref } = %{ $LJ::CACHE_MOOD_THEME{$themeid}->{$moodid} };
+ $ref->{moodid} = $moodid;
+ # sanitize the value of pic
+ if ($ref->{pic} =~ m!^/!) {
+ $ref->{pic} =~ s!^/img!!;
+ $ref->{pic} = $LJ::IMGPREFIX . $ref->{pic};
+ }
+ # must be a good url
+ $ref->{pic} = "#invalid" unless
+ $ref->{pic} =~ m!^https?://[^\'\"\0\s]+$!;
+ return 1;
+ }
+ return 0; # couldn't find a picture anywhere in the parent chain
+}
+
+# class method: mood name to id (or undef) (adapted from LJ::mood_id)
+sub mood_id {
+ my ( $self, $mood ) = @_;
+ return undef unless $mood;
+ $self->load_moods;
+ foreach my $m ( values %LJ::CACHE_MOODS ) {
+ return $m->{id} if $mood eq $m->{name};
+ }
+ return undef;
+}
+
+# class method: mood id to name (or undef) (adapted from LJ::mood_name)
+sub mood_name {
+ my ( $self, $moodid ) = @_;
+ return undef unless $moodid;
+
+ $self->load_moods;
+ my $m = $LJ::CACHE_MOODS{$moodid};
+ return $m ? $m->{name} : undef;
+}
+
+# object method: get theme description (adapted from LJ::mood_theme_des)
+sub des {
+ my ( $self ) = @_;
+ my $themeid = $self->id or return undef;
+ my $m = $LJ::CACHE_MOOD_THEME{$themeid};
+ return $m ? $m->{des} : undef;
+}
+
+# class method: associate local moods with moodids on other sites
+# arguments: local moodid or mood; external siteid
+# returns: id of mood on the remote site, or 0 on failure
+sub get_external_moodid {
+ my ( $self, %opts ) = @_;
+
+ my $siteid = $opts{siteid};
+ my $moodid = $opts{moodid};
+ my $mood = $opts{mood};
+
+ return 0 unless $siteid;
+ return 0 unless $moodid || $mood;
+
+ my $mood_text = $mood ? $mood : $self->mood_name( $moodid );
+
+ # determine which moodid on the external site
+ # corresponds to the given $mood_text
+ my $dbr = LJ::get_db_reader();
+ my ( $external_moodid ) = $dbr->selectrow_array(
+ "SELECT moodid FROM external_site_moods WHERE siteid = ?" .
+ " AND LOWER( mood ) = ?", undef, $siteid, lc $mood_text );
+
+ return $external_moodid ? $external_moodid : 0;
+}
+
+1;
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm Wed Jun 16 13:48:22 2010 +0800
+++ b/cgi-bin/LJ/Entry.pm Thu Jun 17 15:02:55 2010 +0800
@@ -868,7 +868,7 @@ sub userpic {
# mood, then their standard mood
my $key = $self->prop('picture_keyword') ||
$self->prop('current_mood') ||
- LJ::mood_name($self->prop('current_moodid'));
+ DW::Mood->mood_name( $self->prop('current_moodid') );
# return the picture from keyword, if defined
my $picid = LJ::get_picid_from_keyword($up, $key);
@@ -883,7 +883,7 @@ sub userpic_kw_from_props {
return $props->{'picture_keyword'} ||
$props->{'current_mood'} ||
- LJ::mood_name($props->{'current_moodid'});
+ DW::Mood->mood_name( $props->{'current_moodid'} );
}
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Wed Jun 16 13:48:22 2010 +0800
+++ b/cgi-bin/LJ/S2.pm Thu Jun 17 15:02:55 2010 +0800
@@ -1866,9 +1866,10 @@ sub Entry
if (my $mid = $p->{'current_moodid'}) {
my $theme = defined $arg->{'moodthemeid'} ? $arg->{'moodthemeid'} :
$u->{'moodthemeid'};
my %pic;
- $e->{'mood_icon'} = Image($pic{'pic'}, $pic{'w'}, $pic{'h'})
- if LJ::get_mood_picture($theme, $mid, \%pic);
- if (my $mood = LJ::mood_name($mid)) {
+ my $mobj = DW::Mood->new( $theme );
+ $e->{mood_icon} = Image( $pic{pic}, $pic{w}, $pic{h} )
+ if $mobj && $mobj->get_picture( $mid, \%pic );
+ if ( my $mood = DW::Mood->mood_name( $mid ) ) {
my $extra = LJ::Hooks::run_hook("current_mood_extra", $theme) ||
"";
$e->{'metadata'}->{'mood'} = "$mood$extra";
}
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/LJ/Widget/MoodThemeChooser.pm
--- a/cgi-bin/LJ/Widget/MoodThemeChooser.pm Wed Jun 16 13:48:22 2010 +0800
+++ b/cgi-bin/LJ/Widget/MoodThemeChooser.pm Thu Jun 17 15:02:55 2010 +0800
@@ -66,10 +66,10 @@ sub render_body {
my $moodtheme_extra = LJ::Hooks::run_hook("mood_theme_extra_content", $u,
\...@themes);
my $show_special = $moodtheme_extra ? "special" : "nospecial";
- LJ::load_mood_theme($preview_moodthemeid);
- my @show_moods = ('happy', 'sad', 'angry', 'tired');
+ my $mobj = DW::Mood->new( $preview_moodthemeid );
+ my @show_moods = qw( happy sad angry tired );
- if ($preview_moodthemeid) {
+ if ( $mobj) {
my $count = 0;
$ret .= "<div class='moodtheme-preview
moodtheme-preview-$show_special'>";
@@ -77,23 +77,24 @@ sub render_body {
$ret .= "<tr>" unless $moodtheme_extra;
foreach my $mood (@show_moods) {
my %pic;
- if (LJ::get_mood_picture($preview_moodthemeid, LJ::mood_id($mood),
\%pic)) {
+ if ( $mobj->get_picture( $mobj->mood_id( $mood ), \%pic ) ) {
$ret .= "<tr>" if $moodtheme_extra && $count % 2 == 0;
$ret .= "<td><img class='moodtheme-img' align='absmiddle'
alt='$mood' src=\"$pic{pic}\" width='$pic{w}' height='$pic{h}' /><br
/>$mood</td>";
$ret .= "</tr>" if $moodtheme_extra && $count % 2 != 0;
$count++;
}
}
- if ($moodtheme_extra) {
+ if ( $moodtheme_extra ) {
$ret .= "<tr><td colspan='2'>";
} else {
$ret .= "<td>";
}
- $ret .= "<p><a
href='$LJ::SITEROOT/moodlist?moodtheme=$preview_moodthemeid'>" .
$class->ml('widget.moodthemechooser.viewtheme') . "</a></p>";
+ $ret .= "<p><a
href='$LJ::SITEROOT/moodlist?moodtheme=$preview_moodthemeid'>";
+ $ret .= $class->ml( 'widget.moodthemechooser.viewtheme' ) . "</a></p>";
$ret .= "</td></tr></table>";
- my $mood_des = LJ::mood_theme_des($preview_moodthemeid);
- LJ::CleanHTML::clean (\$mood_des);
- $ret .= "<p>".$mood_des."</p>";
+ my $mood_des = $mobj->des;
+ LJ::CleanHTML::clean( \$mood_des );
+ $ret .= "<p>$mood_des</p>";
$ret .= "</div>";
}
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/ljemailgateway.pl
--- a/cgi-bin/ljemailgateway.pl Wed Jun 16 13:48:22 2010 +0800
+++ b/cgi-bin/ljemailgateway.pl Thu Jun 17 15:02:55 2010 +0800
@@ -432,7 +432,7 @@ sub process {
$props->{picture_keyword} = $post_headers{'userpic'} ||
$post_headers{'icon'} ||
$u->{'emailpost_userpic'};
- if (my $id = LJ::mood_id($post_headers{'mood'})) {
+ if ( my $id = DW::Mood->mood_id( $post_headers{'mood'} ) ) {
$props->{current_moodid} = $id;
} else {
$props->{current_mood} = $post_headers{'mood'};
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/ljfeed.pl
--- a/cgi-bin/ljfeed.pl Wed Jun 16 13:48:22 2010 +0800
+++ b/cgi-bin/ljfeed.pl Thu Jun 17 15:02:55 2010 +0800
@@ -265,7 +265,7 @@ sub make_feed
if ($logprops{$itemid}->{'current_mood'}) {
$mood = $logprops{$itemid}->{'current_mood'};
} elsif ($logprops{$itemid}->{'current_moodid'}) {
- $mood = LJ::mood_name($logprops{$itemid}->{'current_moodid'}+0);
+ $mood = DW::Mood->mood_name(
$logprops{$itemid}->{'current_moodid'}+0 );
}
my $createtime = $LJ::EndOfTime - $it->{rlogtime};
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl Wed Jun 16 13:48:22 2010 +0800
+++ b/cgi-bin/ljlib.pl Thu Jun 17 15:02:55 2010 +0800
@@ -136,7 +136,7 @@ require "ljtextutil.pl";
require "ljtextutil.pl";
require "ljtimeutil.pl";
require "ljcapabilities.pl";
-require "ljmood.pl";
+use DW::Mood;
require "ljrelation.pl";
require "ljuserpics.pl";
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/ljmood.pl
--- a/cgi-bin/ljmood.pl Wed Jun 16 13:48:22 2010 +0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +0,0 @@
-# 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.
-
-package LJ;
-use strict;
-
-# <LJFUNC>
-# name: LJ::load_mood_theme
-# des: Loads and caches a mood theme, or returns immediately if already loaded.
-# args: dbarg?, themeid
-# des-themeid: the mood theme ID to load.
-# </LJFUNC>
-sub load_mood_theme {
- my $themeid = shift;
- return if $LJ::CACHE_MOOD_THEME{$themeid};
- return unless $themeid;
-
- # check memcache
- my $memkey = [$themeid, "moodthemedata:$themeid"];
- return if $LJ::CACHE_MOOD_THEME{$themeid} = LJ::MemCache::get($memkey) and
- %{$LJ::CACHE_MOOD_THEME{$themeid} || {}};
-
- # fall back to db
- my $dbh = LJ::get_db_writer()
- or return 0;
-
- $LJ::CACHE_MOOD_THEME{$themeid} = {};
-
- my $sth = $dbh->prepare("SELECT moodid, picurl, width, height FROM
moodthemedata WHERE moodthemeid=?");
- $sth->execute($themeid);
- return 0 if $dbh->err;
-
- while (my ($id, $pic, $w, $h) = $sth->fetchrow_array) {
- $LJ::CACHE_MOOD_THEME{$themeid}->{$id} = { 'pic' => $pic, 'w' => $w,
'h' => $h };
- }
-
- my $des_sth = $dbh->prepare("SELECT name, des FROM moodthemes WHERE
moodthemeid=?");
- $des_sth->execute($themeid);
- return 0 if $dbh->err;
-
- my ($name, $des) = $des_sth->fetchrow_array;
- $LJ::CACHE_MOOD_THEME{$themeid}->{name} = $name;
- $LJ::CACHE_MOOD_THEME{$themeid}->{des} = $des;
-
- # set in memcache
- LJ::MemCache::set($memkey, $LJ::CACHE_MOOD_THEME{$themeid}, 3600)
- if %{$LJ::CACHE_MOOD_THEME{$themeid} || {}};
-
- return 1;
-}
-
-# <LJFUNC>
-# name: LJ::load_moods
-# class:
-# des:
-# info:
-# args:
-# des-:
-# returns:
-# </LJFUNC>
-sub load_moods
-{
- return if $LJ::CACHED_MOODS;
- my $dbr = LJ::get_db_reader();
- my $sth = $dbr->prepare("SELECT moodid, mood, parentmood, weight FROM
moods");
- $sth->execute;
- while (my ($id, $mood, $parent, $weight) = $sth->fetchrow_array) {
- $LJ::CACHE_MOODS{$id} = { name => $mood, parent => $parent, id => $id,
weight => $weight };
- if ($id > $LJ::CACHED_MOOD_MAX) { $LJ::CACHED_MOOD_MAX = $id; }
- }
- $LJ::CACHED_MOODS = 1;
-}
-
-# <LJFUNC>
-# name: LJ::get_mood_picture
-# des: Loads a mood icon hashref given a themeid and moodid.
-# args: themeid, moodid, ref
-# des-themeid: Integer; mood themeid.
-# des-moodid: Integer; mood id.
-# des-ref: Hashref to load mood icon data into.
-# returns: Boolean; 1 on success, 0 otherwise.
-# </LJFUNC>
-sub get_mood_picture
-{
- my ($themeid, $moodid, $ref) = @_;
- LJ::load_mood_theme($themeid) unless $LJ::CACHE_MOOD_THEME{$themeid};
- LJ::load_moods() unless $LJ::CACHED_MOODS;
- do
- {
- if ($LJ::CACHE_MOOD_THEME{$themeid} &&
- $LJ::CACHE_MOOD_THEME{$themeid}->{$moodid}) {
- %{$ref} = %{$LJ::CACHE_MOOD_THEME{$themeid}->{$moodid}};
- if ($ref->{'pic'} =~ m!^/!) {
- $ref->{'pic'} =~ s!^/img!!;
- $ref->{'pic'} = $LJ::IMGPREFIX . $ref->{'pic'};
- }
- $ref->{'pic'} = "#invalid" unless
- $ref->{'pic'} =~ m!^https?://[^\'\"\0\s]+$!;
- $ref->{'moodid'} = $moodid;
- return 1;
- } else {
- $moodid = (defined $LJ::CACHE_MOODS{$moodid} ?
- $LJ::CACHE_MOODS{$moodid}->{'parent'} : 0);
- }
- }
- while ($moodid);
- return 0;
-}
-
-# mood id to name (or undef)
-sub mood_name
-{
- my ($moodid) = @_;
- LJ::load_moods() unless $LJ::CACHED_MOODS;
- my $m = $LJ::CACHE_MOODS{$moodid};
- return $m ? $m->{'name'} : undef;
-}
-
-# mood id to desc
-sub mood_theme_des
-{
- my ($themeid) = @_;
- LJ::load_mood_theme($themeid);
- my $m = $LJ::CACHE_MOOD_THEME{$themeid};
- return $m ? $m->{'des'} : undef;
-}
-
-# mood name to id (or undef)
-sub mood_id
-{
- my ($mood) = @_;
- return undef unless $mood;
- LJ::load_moods() unless $LJ::CACHED_MOODS;
- foreach my $m (values %LJ::CACHE_MOODS) {
- return $m->{'id'} if $mood eq $m->{'name'};
- }
- return undef;
-}
-
-sub get_moods
-{
- LJ::load_moods() unless $LJ::CACHED_MOODS;
- return \%LJ::CACHE_MOODS;
-}
-
-# given a local moodid or mood and an external siteid, return that mood's id
on that site
-sub get_external_site_moodid {
- my %opts = @_;
-
- my $siteid = $opts{siteid};
- my $moodid = $opts{moodid};
- my $mood = $opts{mood};
-
- return 0 unless $siteid;
- return 0 unless $moodid || $mood;
-
- my $mood_text = $mood ? $mood : LJ::mood_name( $moodid );
-
- # determine which moodid on the external site corresponds to the given
$mood_text
- my $dbr = LJ::get_db_reader();
- my ( $external_moodid ) = $dbr->selectrow_array( "SELECT moodid FROM
external_site_moods WHERE siteid = ? AND LOWER( mood ) = ?", undef, $siteid, lc
$mood_text );
-
- return $external_moodid ? $external_moodid : 0;
-}
-
-1;
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/ljprotocol.pl
--- a/cgi-bin/ljprotocol.pl Wed Jun 16 13:48:22 2010 +0800
+++ b/cgi-bin/ljprotocol.pl Thu Jun 17 15:02:55 2010 +0800
@@ -2788,7 +2788,7 @@ sub list_moods
sub list_moods
{
my $mood_max = int(shift);
- LJ::load_moods();
+ DW::Mood->load_moods;
my $res = [];
return $res if $mood_max >= $LJ::CACHED_MOOD_MAX;
diff -r b97315fc8d4b -r 29f13c2dc059 cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl Wed Jun 16 13:48:22 2010 +0800
+++ b/cgi-bin/weblib.pl Thu Jun 17 15:02:55 2010 +0800
@@ -1457,7 +1457,7 @@ RTE
my @moodlist = ('', BML::ml('entryform.mood.noneother'));
my $sel;
- my $moods = LJ::get_moods();
+ my $moods = DW::Mood->get_moods;
foreach (sort { $moods->{$a}->{'name'} cmp
$moods->{$b}->{'name'} } keys %$moods) {
push @moodlist, ($_, $moods->{$_}->{'name'});
@@ -1468,15 +1468,21 @@ RTE
}
}
- if ($remote) {
- LJ::load_mood_theme($remote->{'moodthemeid'});
- foreach my $mood (keys %$moods) {
- if (LJ::get_mood_picture($remote->{'moodthemeid'},
$moods->{$mood}->{id}, \ my %pic)) {
- $moodlist .= " moods[" .
$moods->{$mood}->{id} . "] = \"" . $moods->{$mood}->{name} . "\";\n";
- $moodpics .= " moodpics[" .
$moods->{$mood}->{id} . "] = \"" . $pic{pic} . "\";\n";
- }
- }
- $$onload .= " mood_preview();";
+ if ( $remote ) {
+ my $r_theme = DW::Mood->new( $remote->{'moodthemeid'} );
+ foreach my $mood ( keys %$moods ) {
+ my $moodid = $moods->{$mood}->{id};
+ if ( $r_theme && $r_theme->get_picture(
+ $moodid, \ my %pic ) ) {
+ $moodlist .= " moods[" . $moodid;
+ $moodlist .= "] = \"";
+ $moodlist .= $moods->{$mood}->{name} . "\";\n";
+ $moodpics .= " moodpics[" . $moodid;
+ $moodpics .= "] = \"";
+ $moodpics .= $pic{pic} . "\";\n";
+ }
+ }
+ $$onload .= " mood_preview();";
$$head .= <<MOODS;
<script type="text/javascript" language="JavaScript"><!--
if (document.getElementById) {
@@ -2238,7 +2244,7 @@ sub entry_form_decode
## see if an "other" mood they typed in has an equivalent moodid
if ($POST->{'prop_current_mood'}) {
- if (my $id = LJ::mood_id($POST->{'prop_current_mood'})) {
+ if ( my $id = DW::Mood->mood_id( $POST->{'prop_current_mood'} ) ) {
$req->{'prop_current_moodid'} = $id;
delete $req->{'prop_current_mood'};
}
diff -r b97315fc8d4b -r 29f13c2dc059 htdocs/community/moderate.bml
--- a/htdocs/community/moderate.bml Wed Jun 16 13:48:22 2010 +0800
+++ b/htdocs/community/moderate.bml Thu Jun 17 15:02:55 2010 +0800
@@ -450,15 +450,16 @@ body<=
if ($props->{'current_mood'} || $props->{'current_moodid'}) {
$current{'Mood'} = $props->{'current_mood'};
LJ::CleanHTML::clean_subject(\$current{'Mood'});
- my $mid = $props->{'current_moodid'};
- if ($mid) {
- my $theme = $up->{'moodthemeid'};
+ if ( my $mid = $props->{current_moodid} ) {
+ my $theme = DW::Mood->new( $up->{moodthemeid} );
my %pic;
- my $name = LJ::mood_name($mid);
- if (LJ::get_mood_picture($theme, $mid, \%pic)) {
- $current{'Mood'} = "<img src='$pic{'pic'}'
align='absmiddle' width='$pic{'w'}' height='$pic{'h'}' vspace='1'> $name";
+ my $name = DW::Mood->mood_name( $mid );
+ if ( $theme && $theme->get_picture( $mid, \%pic ) ) {
+ $current{Mood} =
+ "<img src='$pic{pic}' align='absmiddle' "
+ . "width='$pic{w}' height='$pic{h}' vspace='1'> $name";
} else {
- $current{'Mood'} = $name;
+ $current{Mood} = $name;
}
}
}
diff -r b97315fc8d4b -r 29f13c2dc059 htdocs/export_do.bml
--- a/htdocs/export_do.bml Wed Jun 16 13:48:22 2010 +0800
+++ b/htdocs/export_do.bml Thu Jun 17 15:02:55 2010 +0800
@@ -151,11 +151,9 @@ _c?>
if ($opts->{'currents'}) {
$e->{'current_music'} = $eprops->{'current_music'};
$e->{'current_mood'} = $eprops->{'current_mood'};
- if ($eprops->{'current_moodid'}) {
- my $mood;
- $mood = LJ::mood_name($eprops->{'current_moodid'})
- if $eprops->{'current_moodid'};
- $e->{'current_mood'} = $mood if $mood;
+ if ( $eprops->{current_moodid} ) {
+ my $mood = DW::Mood->mood_name(
$eprops->{current_moodid} );
+ $e->{current_mood} = $mood if $mood;
}
}
diff -r b97315fc8d4b -r 29f13c2dc059 htdocs/manage/moodthemes.bml
--- a/htdocs/manage/moodthemes.bml Wed Jun 16 13:48:22 2010 +0800
+++ b/htdocs/manage/moodthemes.bml Thu Jun 17 15:02:55 2010 +0800
@@ -186,15 +186,18 @@ body<=
$make_tree = sub {
my ($num, $tid) = @_;
return unless $lists{$num};
+ my $theme = DW::Mood->new( $tid );
$ret .= "<ul>\n";
foreach my $mood (@{$lists{$num}}) {
$ret .= "<li><b>$mood->{'name'}</b>";
my %pic;
- LJ::get_mood_picture($tid, $mood->{'id'}, \%pic);
+ $theme->get_picture( $mood->{id}, \%pic ) if $theme;
if (%pic) {
- $ret .= "<img id='$mood->{'id'}img' align='absmiddle'
src=\"$pic{'pic'}\" width='$pic{'w'}' height='$pic{'h'}' hspace='2' vspace='2'
/></li>\n";
+ $ret .= "<img id='$mood->{id}img' align='absmiddle'";
+ $ret .= " src=\"$pic{pic}\" width='$pic{w}' height='$pic{h}'";
+ $ret .= " hspace='2' vspace='2' /></li>\n";
}
# Figure out if this picture is really just inherited from a parent
@@ -206,12 +209,16 @@ body<=
}
$ret .= "<table>";
- if ($mood->{'parent'}) {
- $ret .= "<tr><td colspan='2'><label for='$mood->{id}inherit'>"
. BML::ml('.mood.label.inherit', {'mood' => LJ::mood_name($mood->{'parent'})})
. "</label>";
- $ret .= " " . LJ::html_check({ type => 'check', name =>
"$mood->{id}inherit",
- id => "$mood->{id}inherit",
- onclick =>
"enable($mood->{id}, $mood->{parent})",
- selected => $inherited });
+ if ( $mood->{parent} ) {
+ $ret .= "<tr><td colspan='2'><label for='$mood->{id}inherit'>";
+ $ret .= BML::ml( '.mood.label.inherit',
+ { mood => DW::Mood->mood_name( $mood->{parent} ) }
);
+ $ret .= "</label> ";
+ $ret .= LJ::html_check( { type => 'check',
+ id => "$mood->{id}inherit",
+ name => "$mood->{id}inherit",
+ onclick => "enable($mood->{id},
$mood->{parent})",
+ selected => $inherited } );
$ret .= "</td></tr>\n";
}
$ret .= "<tr><td>$ML{'.mood.label.url'} </td><td>";
@@ -235,7 +242,7 @@ body<=
my $id = shift;
# Get a list of all possible moods
- my $moods = LJ::get_moods();
+ my $moods = DW::Mood->get_moods;
foreach (sort { $moods->{$a}->{'name'} cmp $moods->{$b}->{'name'} }
keys %$moods) {
my $m = $moods->{$_};
@@ -346,7 +353,7 @@ body<=
my $width = $POST{$mid.'w'};
my $height = $POST{$mid.'h'};
my $picurl = $POST{$key};
- my $mname = LJ::mood_name($mid);
+ my $mname = DW::Mood->mood_name( $mid );
# inherited, don't represent in db
if ($POST{$mid.'check'} eq 'checked') {
@@ -440,9 +447,10 @@ body<=
'themeids' => join(",", map {
$_->{moodthemeid} } @user_themes));
$ret .= "<table>";
$ret .=
"<tr><th></th><th>$ML{'.yourthemes.example.happy'}</th><th>$ML{'.yourthemes.example.sad'}</th><th>$ML{'.yourthemes.example.angry'}</th><th></th></tr>";
- foreach my $theme (@user_themes) {
- my $ename = LJ::ehtml($theme->{'name'});
- my $tid = $theme->{'moodthemeid'};
+ foreach my $theme ( @user_themes ) {
+ my $ename = LJ::ehtml( $theme->{name} );
+ my $tid = $theme->{moodthemeid};
+ my $tobj = DW::Mood->new( $tid );
my $use_dis = 0;
if ($tid == $u->{'moodthemeid'}) {
@@ -455,7 +463,7 @@ body<=
my @head_moods = (15, 25, 2); # happy, sad, angry
foreach my $moodid (@head_moods) {
my %pic = ();
- LJ::get_mood_picture($tid, $moodid, \%pic);
+ $tobj->get_picture( $moodid, \%pic ) if $tobj;
$ret .= "<td>";
if (%pic) {
$ret .= "<img align='absmiddle'
src=\"$pic{'pic'}\" width='$pic{'w'}' height='$pic{'h'}' hspace='2' vspace='2'
/>";
diff -r b97315fc8d4b -r 29f13c2dc059 htdocs/moodlist.bml
--- a/htdocs/moodlist.bml Wed Jun 16 13:48:22 2010 +0800
+++ b/htdocs/moodlist.bml Thu Jun 17 15:02:55 2010 +0800
@@ -54,7 +54,7 @@ body<=
};
# Get a list of all possible moods
- my $moods = LJ::get_moods();
+ my $moods = DW::Mood->get_moods;
my @mlist = ();
my %lists = {};
foreach (sort { $moods->{$a}->{'name'} cmp $moods->{$b}->{'name'} } keys
%$moods) {
@@ -112,11 +112,11 @@ body<=
$ret .= "<tr><td>$theme->{'name'}</td>\n";
}
- LJ::load_mood_theme($theme->{'moodthemeid'});
+ my $tobj = DW::Mood->new( $theme->{moodthemeid} );
# Output each of the displayed moods
- foreach my $mood (@show_moods) {
- if (LJ::get_mood_picture($theme->{'moodthemeid'},
LJ::mood_id($mood), \ my %pic)) {
+ foreach my $mood ( @show_moods ) {
+ if ( $tobj && $tobj->get_picture( $tobj->mood_id( $mood ), \
my %pic ) ) {
$ret .= "<td align='center'><img align='absmiddle' alt='" .
LJ::ehtml( $theme->{name} . ": " . $mood ) .
"' src=\"$pic{'pic'}\" width='$pic{'w'}'
height='$pic{'h'}' hspace='2' vspace='2' />" .
@@ -198,7 +198,8 @@ body<=
@user_themes = sort { lc($a->{name}) cmp lc($b->{name}) } @user_themes;
my $do_theme_detail = sub {
- my ($themeid) = @_;
+ my ( $themeid ) = @_;
+ my $tobj = DW::Mood->new( $themeid );
$ret .= "<br /><table width='100%'><tr><td colspan='5'
align='center'>";
@@ -228,7 +229,7 @@ body<=
my $m = shift @mlist;
my $mood = $m->{name};
my %pic;
- if (LJ::get_mood_picture($themeid, $m->{id}, \%pic)) {
+ if ( $tobj && $tobj->get_picture( $m->{id}, \%pic ) ) {
$ret .= "<td style='text-align:center;
vertical-align:bottom'>" .
"<img align='absmiddle' style='margin-top:25px'
alt='$m->{name}' src=\"$pic{'pic'}\" width='$pic{'w'}' height='$pic{'h'}'
hspace='2' vspace='2' />" .
"<br /><a class='lj_moodlist_link'
href='http://dictionary.reference.com/search?q=$mood'>$mood</a><br /></td>";
@@ -247,11 +248,12 @@ body<=
my $self = shift;
my $num = shift;
return unless $lists{$num};
+ my $tobj = DW::Mood->new( $GET{moodtheme} );
$ret .= "<ul>\n";
foreach my $mood (@{$lists{$num}}) {
$ret .= "<li>" . BML::ml('.moodname', {'name' => "<b><a
href=\"http://dictionary.reference.com/search?q=$mood->{'name'}\"
target='dict'>$mood->{'name'}</a></b>", 'id' => $mood->{'id'}}) . "</li>\n";
my %pic;
- if (LJ::get_mood_picture($GET{moodtheme}, $mood->{'id'},
\%pic)) {
+ if ( $tobj && $tobj->get_picture( $mood->{id}, \%pic ) ) {
unless ($GET{'hidederived'} && $pic{'moodid'} !=
$mood->{'id'}) {
$ret .= "<img align='absmiddle' src=\"$pic{'pic'}\"
width='$pic{'w'}' height='$pic{'h'}' hspace='2' vspace='2' />\n";
}
diff -r b97315fc8d4b -r 29f13c2dc059 htdocs/preview/entry.bml
--- a/htdocs/preview/entry.bml Wed Jun 16 13:48:22 2010 +0800
+++ b/htdocs/preview/entry.bml Thu Jun 17 15:02:55 2010 +0800
@@ -163,12 +163,13 @@ _c?>
$moodname = $val;
}
- if (my $val = $moodid) {
- $moodname ||= LJ::mood_name($val);
+ if ( my $val = $moodid ) {
+ $moodname ||= DW::Mood->mood_name( $val );
+ my $theme = DW::Mood->new( $themeid );
my %pic;
- if (LJ::get_mood_picture($themeid, $val, \%pic)) {
- $moodpic = "<img src=\"$pic{'pic'}\" align='absmiddle'
width='$pic{'w'}' " .
- "height='$pic{'h'}' vspace='1' alt='' /> ";
+ if ( $theme && $theme->get_picture( $val, \%pic ) ) {
+ $moodpic = "<img class='moodpic' src=\"$pic{pic}\"
align='absmiddle' " .
+ "width='$pic{w}' height='$pic{h}' vspace='1'
alt='' /> ";
}
}
diff -r b97315fc8d4b -r 29f13c2dc059 htdocs/talkpost.bml
--- a/htdocs/talkpost.bml Wed Jun 16 13:48:22 2010 +0800
+++ b/htdocs/talkpost.bml Thu Jun 17 15:02:55 2010 +0800
@@ -291,12 +291,13 @@ body<=
$moodname = $val;
}
- if (my $val = $moodid) {
- $moodname ||= LJ::mood_name($val);
+ if ( my $val = $moodid ) {
+ $moodname ||= DW::Mood->mood_name( $val );
+ my $theme = DW::Mood->new( $themeid );
my %pic;
- if (LJ::get_mood_picture($themeid, $val, \%pic)) {
- $moodpic = "<img src=\"$pic{'pic'}\" align='absmiddle'
width='$pic{'w'}' " .
- "height='$pic{'h'}' vspace='1' alt='' /> ";
+ if ( $theme && $theme->get_picture( $val, \%pic ) ) {
+ $moodpic = "<img class='moodpic' src=\"$pic{pic}\"
align='absmiddle' " .
+ "width='$pic{w}' height='$pic{h}' vspace='1' alt=''
/> ";
}
}
diff -r b97315fc8d4b -r 29f13c2dc059 htdocs/talkread.bml
--- a/htdocs/talkread.bml Wed Jun 16 13:48:22 2010 +0800
+++ b/htdocs/talkread.bml Thu Jun 17 15:02:55 2010 +0800
@@ -321,13 +321,14 @@ body<=
$moodname = $val;
}
- if (my $val = $moodid) {
- $moodname ||= LJ::mood_name($val);
- my %pic;
- if (LJ::get_mood_picture($themeid, $val, \%pic)) {
- $moodpic = "<img class='moodpic' src=\"$pic{'pic'}\"
align='absmiddle' width='$pic{'w'}' " .
- "height='$pic{'h'}' vspace='1' alt='' /> ";
- }
+ if ( my $val = $moodid ) {
+ $moodname ||= DW::Mood->mood_name( $val );
+ my $theme = DW::Mood->new( $themeid );
+ my %pic;
+ if ( $theme && $theme->get_picture( $val, \%pic ) ) {
+ $moodpic = "<img class='moodpic' src=\"$pic{pic}\"
align='absmiddle' " .
+ "width='$pic{w}' height='$pic{h}' vspace='1' alt=''
/> ";
+ }
}
$current{'Mood'} = "$moodpic$moodname";
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog