sunnyman's (sunnyman) wrote in changelog,
sunnyman's
sunnyman
changelog

[livejournal] r20004: OPSC-348: Application promo user head se...

Committer: vtroitsky
OPSC-348: Application promo user head server-side implemented
U   trunk/cgi-bin/LJ/User.pm
U   trunk/htdocs/manage/profile/index.bml
U   trunk/htdocs/manage/profile/index.bml.text
U   trunk/htdocs/tools/endpoints/ctxpopup.bml
U   trunk/htdocs/tools/endpoints/ctxpopup.bml.text
Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2011-09-08 09:23:39 UTC (rev 20003)
+++ trunk/cgi-bin/LJ/User.pm	2011-09-08 09:29:51 UTC (rev 20004)
@@ -6029,10 +6029,21 @@
     return $url;
 }
 
+sub custom_usericon_appid {
+    my ($u) = @_;
+    return $u->prop('custom_usericon_appid') || 0;
+}
+
 sub set_custom_usericon {
-    my ($u, $url) = @_;
+    my ($u, $url, %opts) = @_;
 
     $u->set_prop( 'custom_usericon' => $url );
+
+    if ($opts{application_id}) {
+        $u->set_prop( 'custom_usericon_appid' => $opts{application_id});
+    } else {
+        $u->clear_prop( 'custom_usericon_appid' );
+    }
 }
 
 sub _subscriptions_count {

Modified: trunk/htdocs/manage/profile/index.bml
===================================================================
--- trunk/htdocs/manage/profile/index.bml	2011-09-08 09:23:39 UTC (rev 20003)
+++ trunk/htdocs/manage/profile/index.bml	2011-09-08 09:29:51 UTC (rev 20004)
@@ -244,6 +244,11 @@
                 my $class = LJ::Pay::Payment::PayItem->get_class_for_item('userhead');
                 my $uhs = $class->get_expire_times ($u);
                 if ($uh_prop) {
+                    my $appid = $u->custom_usericon_appid;
+                    if ($appid) {
+                        my $app_obj = LJ::UserApps->get_application(id => $appid);
+                        $ret .= "<img src='".$app_obj->userhead."'>&nbsp;".LJ::Lang::ml('.section.userhead.application', { name => $app_obj->name, href => $app_obj->href}) if ($app_obj);
+                    } else {
                     ## Try to fetch expire date by userhead user's prop
                     ## At first we try to find uh in a shop
                     my $uhs_all = LJ::UserHead->get_all_userheads ();
@@ -262,12 +267,14 @@
                             $ret .= "<img src='$LJ::IMGPREFIX/$uh_prop' class='i-manage-userhead' />";
                         }
                     }
+                    }
                 } else {
                     $ret .= "<img src='$LJ::DEFAULT_USERHEAD' class='i-manage-userhead' />&nbsp;$ML{'.fn.userheads.default_userhead'}";
                 }
                 $ret .= "</td></tr>";
                 $ret .= "<tr><td class='field_name'>$ML{'.fn.userheads.collection'}</td><td>";
-                if (scalar @$uhs) {
+                my $apps = LJ::UserApps->get_apps_with_userhead($remote); # get all installed applications with userheads for specified user
+                if (scalar @$uhs || scalar @$apps) {
                     $ret .= '<p class="b-manage-userheads-desc">' . LJ::Lang::ml('.section.userhead.apply.href', { aopts => "href='$LJ::SITEROOT/shop/userheads.bml'" } ) . '</p>';
                     $ret .= '<ul class="b-manage-userheads">';
                     $ret .= "<li><label for='userhead0'><input type='radio' name='uh_id' value='default' id='userhead0' /><img src='$LJ::DEFAULT_USERHEAD' class='i-manage-userhead' />&nbsp;$ML{'.fn.userheads.default_userhead'}</label></li>";
@@ -276,6 +283,10 @@
                         my $uh_obj = LJ::UserHead->get_userhead ($uh_id);
                         $ret .= "<li><label for='userhead$uh_id'><input type='radio' name='uh_id' value='$uh_id' id='userhead$uh_id' /><img src='".$uh_obj->get_uh_img . "' class='i-manage-userhead' /> " . LJ::Lang::ml('.section.userheads.expire_date', { date => $date_format->($uh->{expdate}) })."</label></li>" if $uh_obj;
                     }
+                    foreach my $app (@$apps) {
+                        my $uh_id = 'appid_'.$app->id;
+                        $ret .= "<li><label for='userhead$uh_id'><input type='radio' name='uh_id' value='$uh_id' id='userhead$uh_id' /><img src='".$app->userhead . "' class='i-manage-userhead' /> " . LJ::Lang::ml('.section.userhead.application', { name => $app->name, href => $app->href })."</label></li>" if $app;
+                    }
                     $ret .= '</ul>';
                 } else {
                     $ret .= LJ::Lang::ml('.section.userhead.no_userheads', { url => $LJ::SITEROOT."/shop/userheads.bml" });
@@ -981,9 +992,14 @@
             if ($POST{'uh_id'} eq 'default') {
                 $u->set_custom_usericon (undef);
             } elsif ($POST{'uh_id'}) {
-                my $uh = LJ::UserHead->get_userhead ($POST{'uh_id'});
-                $u->set_custom_usericon ($uh->get_uh_img)
-                    if $uh;
+                if ($POST{'uh_id'} =~ /^appid_(\d+)$/) {
+                    my $app_obj = LJ::UserApps->get_application(id => $1);
+                    $u->set_custom_usericon ($app_obj->userhead, application_id => $app_obj->id) if ($app_obj);
+                } else {
+                    my $uh = LJ::UserHead->get_userhead ($POST{'uh_id'});
+                    $u->set_custom_usericon ($uh->get_uh_img)
+                        if $uh;
+                }
             }
         }
 

Modified: trunk/htdocs/manage/profile/index.bml.text
===================================================================
--- trunk/htdocs/manage/profile/index.bml.text	2011-09-08 09:23:39 UTC (rev 20003)
+++ trunk/htdocs/manage/profile/index.bml.text	2011-09-08 09:29:51 UTC (rev 20004)
@@ -384,6 +384,8 @@
 
 .section.userheads.expire_date=Expire [[date]]
 
+.section.userhead.application=&laquo;<a href="[[href]]">[[name]]</a>&raquo; promo userhead
+
 .section.userhead.apply.href=Click userhead to apply (or <a [[aopts]]>buy more userheads</a>):
 
 .section.vernum.button=Verify

Modified: trunk/htdocs/tools/endpoints/ctxpopup.bml
===================================================================
--- trunk/htdocs/tools/endpoints/ctxpopup.bml	2011-09-08 09:23:39 UTC (rev 20003)
+++ trunk/htdocs/tools/endpoints/ctxpopup.bml	2011-09-08 09:29:51 UTC (rev 20004)
@@ -191,6 +191,26 @@
             }
         }
     }
+
+    if ($remote && $u && $ret{is_custom_userhead} && $u->custom_usericon_appid) {
+        $ret{is_app_userhead} = 1;
+        my $app = LJ::UserApps->get_application(id => $u->custom_usericon_appid);
+        if($app && $app->can_show_restricted) {
+            $ret{is_app_userhead} = 1;
+            if ($app->is_authorized(user => $remote)) {
+                if($remote->custom_usericon_appid == $app->id) {
+                    $ret{url_userhead_install} = $app->href;    # default view !!! TODO: pass referer parameters
+                    $ret{ml_userhead_install} = BML::ml('.app_use');
+                } else {
+                    $ret{url_userhead_install} = "$LJ::SITEROOT/manage/profile/#userheads";   # Edit profile
+                    $ret{ml_userhead_install} = BML::ml('.app_change_userhead');
+                }
+            } else {    # Not installed
+                $ret{url_userhead_install} = $app->href;    # INSTALL view !!!
+                $ret{ml_userhead_install} = BML::ml('.app_install', { name => $app->name });
+            }
+        }
+    }
     
     $ret{success} = 1;
     return LJ::JSON->to_json(\%ret);

Modified: trunk/htdocs/tools/endpoints/ctxpopup.bml.text
===================================================================
--- trunk/htdocs/tools/endpoints/ctxpopup.bml.text	2011-09-08 09:23:39 UTC (rev 20003)
+++ trunk/htdocs/tools/endpoints/ctxpopup.bml.text	2011-09-08 09:29:51 UTC (rev 20004)
@@ -4,6 +4,10 @@
 
 .add_friend=Add friend
 
+.app_change_userhead=Install the same user head for free
+.app_install=Install &laquo;[[name]]&raquo; to have the same user head
+.app_use=Use that user head application
+
 .ban_everywhere.title|staleness=1
 .ban_everywhere.title=Ban user everywhere
 

Tags: bml, livejournal, pm, sunnyman, text
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