Move customizelib.pl to LJ::Customize module.
Patch by szabgab.
diffs (299 lines):
diff -r f1430708e8b4 -r e40ef9654536 cgi-bin/LJ/Customize.pm
--- a/cgi-bin/LJ/Customize.pm Wed Oct 21 18:04:43 2009 +0000
+++ b/cgi-bin/LJ/Customize.pm Wed Oct 21 18:20:50 2009 +0000
@@ -1,10 +1,6 @@ package LJ::Customize;
package LJ::Customize;
use strict;
use Carp qw(croak);
-
-use lib "$LJ::HOME/cgi-bin";
-
-require "customizelib.pl";
# returns the S2Theme object of the given user's current theme
sub get_current_theme {
@@ -170,11 +166,10 @@ sub real_themeid_for_uniq {
return scalar @s2lids_for_uniq ? $s2lids_for_uniq[0] : 0;
}
-# wrapper around LJ::cmize::s2_implicit_style_create
sub implicit_style_create {
my $class = shift;
- return LJ::cmize::s2_implicit_style_create(@_);
+ return s2_implicit_style_create(@_);
}
# passing the opt "reset" will revert the language layers to default
@@ -635,19 +630,7 @@ sub s2_upsell {
return $ret;
}
-# wrapper around LJ::cmize::validate_moodthemeid
-sub validate_moodthemeid {
- my $class = shift;
- return LJ::cmize::validate_moodthemeid(@_);
-}
-
-# wrapper around LJ::cmize::get_moodtheme_select_list
-sub get_moodtheme_select_list {
- my $class = shift;
-
- return LJ::cmize::get_moodtheme_select_list(@_);
-}
sub get_cats {
my $class = shift;
@@ -732,4 +715,116 @@ sub get_propgroup_subheaders_order {
);
}
+# <LJFUNC>
+# name: LJ::Customize::s2_implicit_style_create
+# des: Common "create s2 style" skeleton.
+# args: opts?, user, style*
+# des-opts: Hash of options
+# - force: forces creation of a new style even if one already exists
+# des-user: User to get layers of
+# des-style: Hash of style information
+# - theme: theme id of style theme
+# - layout: layout id of style layout
+# Other keys as used by LJ::S2::set_style_layers
+# returns: 1 if successful
+# </LJFUNC>
+sub s2_implicit_style_create
+{
+ my ($opts, $u, %style);
+
+ # this is because the arguments aren't static
+ # old callers don't pass in an options hashref, so we create a blank one
+ if (ref $_[0] && ref $_[1]) {
+ ($opts, $u) = (shift, shift);
+ } else {
+ ($opts, $u) = ({}, shift);
+ }
+
+ # everything else is part of the style hash
+ %style = ( @_ );
+
+ my $pub = LJ::S2::get_public_layers();
+ my $userlay = LJ::S2::get_layers_of_user($u);
+
+ # Create new style if necessary
+ my $s2style = LJ::S2::load_style($u->prop('s2_style'));
+ if (! ($s2style && $s2style->{'userid'} eq $u->{'userid'}) ||
$opts->{'force'}) {
+ my $themeid = $style{theme};
+ my $layoutid = $style{layout};
+ my $layer = $pub->{$themeid} || $userlay->{$themeid} ||
$userlay->{$layoutid};
+ my $uniq = $layer->{uniq} || $layer->{s2lid};
+
+ my $s2_style;
+ unless ($s2_style = LJ::S2::create_style($u, "wizard-$uniq")) {
+ die "Can't create style";
+ }
+ $u->set_prop("s2_style", $s2_style);
+ }
+ # save values in %style to db
+ LJ::S2::set_style_layers($u, $u->prop('s2_style'), %style);
+
+ return 1;
+}
+
+# <LJFUNC>
+# name: LJ::Customize::validate_moodthemeid
+# des: Spoof checking for mood theme ids
+# args: user, themeid
+# des-user: user attempting to use the mood theme
+# des-themeid: mood theme user wants to use
+# returns: themeid if public or owned by user, false otherwise
+# </LJFUNC>
+sub validate_moodthemeid {
+ my $class = shift;
+ my ($u, $themeid) = @_;
+ my $dbr = LJ::get_db_reader();
+ if ($themeid) {
+ my ($mownerid, $mpublic) = $dbr->selectrow_array("SELECT ownerid,
is_public FROM moodthemes ".
+ "WHERE
moodthemeid=?", undef, $themeid);
+ $themeid = 0 unless $mpublic eq 'Y' || $mownerid == $u->{'userid'};
+ }
+ return $themeid
+}
+
+# <LJFUNC>
+# name: LJ::Customize::get_moodtheme_select_list
+# des: Gets mood theme list.
+# args: user
+# des-user: users whose private mood themes should be returned
+# returns: Returns a list of mood themes that the user can select from,
+# suitable for [func[LJ::html_select]].
+# </LJFUNC>
+sub get_moodtheme_select_list
+{
+ my $class = shift;
+ my $u = shift;
+
+ my $dbr = LJ::get_db_reader();
+ my $sth = $dbr->prepare("SELECT moodthemeid, name FROM moodthemes WHERE
is_public='Y' ORDER BY name");
+ $sth->execute;
+
+ my @themes;
+ while (my $moodtheme = $sth->fetchrow_hashref) {
+ my $is_active = LJ::run_hook("mood_theme_is_active",
$moodtheme->{moodthemeid});
+ next unless !defined $is_active || $is_active;
+ push @themes, $moodtheme;
+ }
+ LJ::run_hook('modify_mood_theme_list', \...@themes, user => $u, add_seps
=> 1);
+ unshift @themes, { 'moodthemeid' => 0, 'name' => '(None)' };
+
+ ### user's private themes
+ {
+ my @theme_user;
+ $sth = $dbr->prepare("SELECT moodthemeid, name FROM moodthemes WHERE
ownerid=? AND is_public='N'");
+ $sth->execute($u->{'userid'});
+ push @theme_user, $_ while ($_ = $sth->fetchrow_hashref);
+ if (@theme_user) {
+ push @themes, { 'moodthemeid' => 0, 'name' => "--- " .
BML::ml('/modify_do.bml.moodicons.personal'). " ---", disabled => 1 };
+ push @themes, @theme_user;
+ }
+ }
+
+ return @themes;
+}
+
1;
diff -r f1430708e8b4 -r e40ef9654536 cgi-bin/customizelib.pl
--- a/cgi-bin/customizelib.pl Wed Oct 21 18:04:43 2009 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-#!/usr/bin/perl
-#
-
-package LJ::cmize;
-use strict;
-
-use Carp qw/ confess /;
-
-# <LJFUNC>
-# name: LJ::cmize::s2_implicit_style_create
-# des: Common "create s2 style" skeleton.
-# args: opts?, user, style*
-# des-opts: Hash of options
-# - force: forces creation of a new style even if one already exists
-# des-user: User to get layers of
-# des-style: Hash of style information
-# - theme: theme id of style theme
-# - layout: layout id of style layout
-# Other keys as used by LJ::S2::set_style_layers
-# returns: 1 if successful
-# </LJFUNC>
-sub s2_implicit_style_create
-{
- my ($opts, $u, %style);
-
- # this is because the arguments aren't static
- # old callers don't pass in an options hashref, so we create a blank one
- if (ref $_[0] && ref $_[1]) {
- ($opts, $u) = (shift, shift);
- } else {
- ($opts, $u) = ({}, shift);
- }
-
- # everything else is part of the style hash
- %style = ( @_ );
-
- my $pub = LJ::S2::get_public_layers();
- my $userlay = LJ::S2::get_layers_of_user($u);
-
- # Create new style if necessary
- my $s2style = LJ::S2::load_style($u->prop('s2_style'));
- if (! ($s2style && $s2style->{'userid'} eq $u->{'userid'}) ||
$opts->{'force'}) {
- my $themeid = $style{theme};
- my $layoutid = $style{layout};
- my $layer = $pub->{$themeid} || $userlay->{$themeid} ||
$userlay->{$layoutid};
- my $uniq = $layer->{uniq} || $layer->{s2lid};
-
- my $s2_style;
- unless ($s2_style = LJ::S2::create_style($u, "wizard-$uniq")) {
- die "Can't create style";
- }
- $u->set_prop("s2_style", $s2_style);
- }
- # save values in %style to db
- LJ::S2::set_style_layers($u, $u->prop('s2_style'), %style);
-
- return 1;
-}
-
-# <LJFUNC>
-# name: LJ::cmize::validate_moodthemeid
-# des: Spoof checking for mood theme ids
-# args: user, themeid
-# des-user: user attempting to use the mood theme
-# des-themeid: mood theme user wants to use
-# returns: themeid if public or owned by user, false otherwise
-# </LJFUNC>
-sub validate_moodthemeid {
- my ($u, $themeid) = @_;
- my $dbr = LJ::get_db_reader();
- if ($themeid) {
- my ($mownerid, $mpublic) = $dbr->selectrow_array("SELECT ownerid,
is_public FROM moodthemes ".
- "WHERE
moodthemeid=?", undef, $themeid);
- $themeid = 0 unless $mpublic eq 'Y' || $mownerid == $u->{'userid'};
- }
- return $themeid
-}
-
-# <LJFUNC>
-# name: LJ::cmize::get_moodtheme_select_list
-# des: Gets mood theme list.
-# args: user
-# des-user: users whose private mood themes should be returned
-# returns: Returns a list of mood themes that the user can select from,
-# suitable for [func[LJ::html_select]].
-# </LJFUNC>
-sub get_moodtheme_select_list
-{
- my $u = shift;
-
- my $dbr = LJ::get_db_reader();
- my $sth = $dbr->prepare("SELECT moodthemeid, name FROM moodthemes WHERE
is_public='Y' ORDER BY name");
- $sth->execute;
-
- my @themes;
- while (my $moodtheme = $sth->fetchrow_hashref) {
- my $is_active = LJ::run_hook("mood_theme_is_active",
$moodtheme->{moodthemeid});
- next unless !defined $is_active || $is_active;
- push @themes, $moodtheme;
- }
- LJ::run_hook('modify_mood_theme_list', \...@themes, user => $u, add_seps
=> 1);
- unshift @themes, { 'moodthemeid' => 0, 'name' => '(None)' };
-
- ### user's private themes
- {
- my @theme_user;
- $sth = $dbr->prepare("SELECT moodthemeid, name FROM moodthemes WHERE
ownerid=? AND is_public='N'");
- $sth->execute($u->{'userid'});
- push @theme_user, $_ while ($_ = $sth->fetchrow_hashref);
- if (@theme_user) {
- push @themes, { 'moodthemeid' => 0, 'name' => "--- " .
BML::ml('/modify_do.bml.moodicons.personal'). " ---", disabled => 1 };
- push @themes, @theme_user;
- }
- }
-
- return @themes;
-}
-
-1;
diff -r f1430708e8b4 -r e40ef9654536 cgi-bin/modperl_subs.pl
--- a/cgi-bin/modperl_subs.pl Wed Oct 21 18:04:43 2009 +0000
+++ b/cgi-bin/modperl_subs.pl Wed Oct 21 18:20:50 2009 +0000
@@ -81,7 +81,7 @@ use LJ::Tags;
use LJ::Tags;
require "schoollib.pl";
require "ljemailgateway-web.pl";
-require "customizelib.pl";
+use LJ::Customize;
# preload site-local libraries, if present:
require "$LJ::HOME/cgi-bin/modperl_subs-local.pl"
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog