Committer: janineSupport for sponsored styles.
Moved the customize page-related hooks into Hooks/Customize.pm, and created two new hooks.
http://rt.livejournal.org/Ticket/Display.html?id=3798 A branches/r6/cgi-bin/LJ/Hooks/Customize.pm
U branches/r6/cgi-bin/ljcom.pl
U branches/r6/htdocs/customize/preview.bml.text.local
Added: branches/r6/cgi-bin/LJ/Hooks/Customize.pm
===================================================================
--- branches/r6/cgi-bin/LJ/Hooks/Customize.pm 2007-04-23 16:58:10 UTC (rev 4808)
+++ branches/r6/cgi-bin/LJ/Hooks/Customize.pm 2007-04-23 17:10:39 UTC (rev 4809)
@@ -0,0 +1,121 @@
+#!/usr/bin/perl
+
+package LJ::LJcom;
+use strict;
+
+LJ::register_hook('customize_style_upsell', sub {
+ my ($u, $remote) = @_;
+ my $same_u = $remote ? LJ::u_equals($u, $remote) : 1;
+ my $username = $u->user;
+
+ my $ret = "";
+ return $ret unless $u;
+
+ my $plus_url = $same_u ? "$LJ::SITEROOT/manage/payments/modify.bml" : "$LJ::SITEROOT/shop/view.bml?item=paidaccount&gift=1&for=$username";
+ my $basic_url = $same_u ? "$LJ::SITEROOT/manage/payments/" : "$LJ::SITEROOT/community/account.bml?authas=$username";
+
+ if ($u->in_class('paid') || $u->in_class('perm') || $u->in_class('early')) {
+ return $ret;
+ }
+ else {
+ $ret .= "*Account Limit";
+ if ($u->in_class('plus')) {
+ $ret .= "Paid account. p?>";
+ }
+ else {
+ $ret .= "Plus account for free. p?>";
+ }
+ $ret .= " standout?>";
+ }
+
+ return $ret;
+});
+
+LJ::register_hook('customize_advanced_upsell', sub {
+ my ($u, $remote) = @_;
+ my $same_u = $remote ? LJ::u_equals($u, $remote) : 1;
+ my $username = $u->user;
+
+ my $ret;
+ my $button = $same_u ?
+ "" :
+ "";
+
+ unless (LJ::get_cap($u, "styles")) {
+ $ret .= "
Please Note:";
+ $ret .= "
Only users with
Paid Accounts may create and use custom styles.
";
+ $ret .= $button;
+ $ret .= " standout?>";
+ }
+ return $ret;
+});
+
+LJ::register_hook("extra_sidebar_content", sub {
+ my $u = shift;
+
+ # don't show to paid users
+ return "" unless $u && (!$u->in_class('paid') || $u->in_class('force_ads'));
+
+ my $ret = "New Styles...More Styles p?>";
+ $ret .= "";
+ $ret .= " standout?>";
+
+ return $ret;
+});
+
+# Given an arrayref of layouts, figures out which are sponsored and moves them
+# to the front of the array. Returns an array of sponsored layouts as well.
+LJ::register_hook("modify_layout_list", sub {
+ my $layouts = shift;
+ my %opts = @_;
+
+ return unless ref $layouts;
+
+ # don't modify if the user is paid
+ my $u = $opts{user};
+ return unless !$u || !$u->in_class('paid') || $u->in_class('force_ads');
+
+ # find sponsored layouts in the list, remove them, and add them to a separate list
+ my @sponsored_layouts = ();
+ for (my $i = 0; $i < @$layouts; $i++) {
+ next unless ref $layouts->[$i];
+
+ # uniq is either in the element or must be looked up in the public layers
+ my $uniq = $layouts->[$i]->{uniq};
+ if (!$uniq) {
+ my $pub = $opts{pub};
+ $uniq = ref $pub ? $pub->{$layouts->[$i]->{value}}->{uniq} : "";
+ }
+
+ if ($LJ::SPONSORED_LAYERS{$uniq}) {
+ my $el = splice(@$layouts, $i, 1);
+ push @sponsored_layouts, $el;
+ $i--; # we just removed an element from @layouts
+ }
+ }
+
+ # sort the sponsored layouts alphabetically
+ @sponsored_layouts = sort { $a->{text} cmp $b->{text} } @sponsored_layouts;
+
+ # add separators to the list of sponsored layouts
+ if ($opts{add_seps} && @sponsored_layouts) {
+ unshift @sponsored_layouts,
+ { value => "",
+ text => "--- Sponsored Layouts: ---",
+ disabled => 1 };
+ push @sponsored_layouts,
+ { value => "",
+ text => "--- System Layouts: ---",
+ disabled => 1 };
+ }
+
+ # add the list of sponsored layouts to the front of the list of other layouts
+ unshift @$layouts, @sponsored_layouts;
+
+ return @sponsored_layouts;
+});
+
+1;
Modified: branches/r6/cgi-bin/ljcom.pl
===================================================================
--- branches/r6/cgi-bin/ljcom.pl 2007-04-23 16:58:10 UTC (rev 4808)
+++ branches/r6/cgi-bin/ljcom.pl 2007-04-23 17:10:39 UTC (rev 4809)
@@ -1954,56 +1954,6 @@
}
});
-LJ::register_hook('customize_style_upsell', sub {
- my ($u, $remote) = @_;
- my $same_u = $remote ? LJ::u_equals($u, $remote) : 1;
- my $username = $u->user;
-
- my $ret = "";
- return $ret unless $u;
-
- my $plus_url = $same_u ? "$LJ::SITEROOT/manage/payments/modify.bml" : "$LJ::SITEROOT/shop/view.bml?item=paidaccount&gift=1&for=$username";
- my $basic_url = $same_u ? "$LJ::SITEROOT/manage/payments/" : "$LJ::SITEROOT/community/account.bml?authas=$username";
-
- if ($u->in_class('paid') || $u->in_class('perm') || $u->in_class('early')) {
- return $ret;
- }
- else {
- $ret .= "
*Account Limit";
- if ($u->in_class('plus')) {
- $ret .= "Paid account. p?>";
- }
- else {
- $ret .= "Plus account for free. p?>";
- }
- $ret .= " standout?>";
- }
-
- return $ret;
-});
-
-LJ::register_hook('customize_advanced_upsell', sub {
- my ($u, $remote) = @_;
- my $same_u = $remote ? LJ::u_equals($u, $remote) : 1;
- my $username = $u->user;
-
- my $ret;
- my $button = $same_u ?
- "" :
- "";
-
- unless (LJ::get_cap($u, "styles")) {
- $ret .= "
Please Note:";
- $ret .= "
Only users with
Paid Accounts may create and use custom styles.
";
- $ret .= $button;
- $ret .= " standout?>";
- }
- return $ret;
-});
-
-
LJ::register_hook('userlog_rows', sub {
my $row = shift;
return "Deleted virtual gift #" . $row->{actiontarget}
Modified: branches/r6/htdocs/customize/preview.bml.text.local
===================================================================
--- branches/r6/htdocs/customize/preview.bml.text.local 2007-04-23 16:58:10 UTC (rev 4808)
+++ branches/r6/htdocs/customize/preview.bml.text.local 2007-04-23 17:10:39 UTC (rev 4809)
@@ -1,3 +1,6 @@
;; -*- coding: utf-8 -*-
+
+.specialstyles.header=Sponsored Styles
+
.unavailable=This layout is only available to
Plus and Paid Accounts