[ljcom] r4059: -- hook 'construct_adcall' was redesigne...

Dec 22, 2006 16:54


Committer: sup-- hook 'construct_adcall' was redesigned in order to fit to SixApart-SUP agreement on advertisement area splitting

U trunk/cgi-bin/ljcom.pl

Modified: trunk/cgi-bin/ljcom.pl
===================================================================
--- trunk/cgi-bin/ljcom.pl 2006-12-21 11:12:59 UTC (rev 4058)
+++ trunk/cgi-bin/ljcom.pl 2006-12-22 16:54:47 UTC (rev 4059)
@@ -3671,26 +3671,88 @@
my $u = LJ::load_user($username);
my $remote = LJ::get_remote();

- my $sup_u;
+ # it's much eaiser to define when we SHOULD not show SUP advs
+ # there are 4 cases (out of 12):
+ # 1. user - defined, non-SUP
+ # remote - defined, non-SUP
+ # ip address - any
+ # 2. user - defined, non-SUP
+ # remote - undefined
+ # ip address - non ex-USSR
+ # 3. user - undefined (app pages)
+ # remote - defined, non-SUP
+ # ip address - any
+ # 4. user - undefined (app pages)
+ # remote - undefined
+ # ip address - non ex-USSR
+

- if ($u && $u->get_cap("sup_user")) {
- # If we're viewing a journal page of a sup_user, then use that userid for the ip class check.
- $sup_u = $u;
- } elsif ($remote && $remote->get_cap("sup_user")) {
- # Otherwise see if the remote is a sup_user, using that if they are.
- $sup_u = $remote;
- } else {
- # Otherwise bail out, we're not dealing with sup users at all.
- return;
- }
+ my $is_sup_user;
+ my $is_sup_remote;
+
+ $is_sup_user = $u->get_cap("sup_user") if ($u); # whether user is SUP or not
+ $is_sup_remote = $remote->get_cap("sup_user") if ($remote); # whether remote is SUP or not

my $ip = LJ::get_remote_ip();
my $ip_class = ip_class($ip);
+ my $exUSSR_ip = $ip_class eq 'sup' || $ip_class eq 'russia';

- my $sup_userid = $sup_u->id;
+ if ($u) {
+ unless ($is_sup_user) {
+ if ($remote) {
+ # case 1:
+ # user - defined, non-SUP
+ # remote - defined, non-SUP
+ # ip address - any
+ return unless $is_sup_remote;
+ }
+ else {
+ # case 2:
+ # user - defined, non-SUP
+ # remote - undefined
+ # ip address - non ex-USSR
+ return unless $exUSSR_ip;
+ }
+ }
+ }
+ else {
+ if ($remote) {
+ # case 3:
+ # user - undefined (app pages)
+ # remote - defined, non-SUP
+ # ip address - any
+ return unless $is_sup_remote;
+ }
+ else {
+ # case 4
+ # user - undefined (app pages)
+ # remote - undefined
+ # ip address - non ex-USSR
+ return unless $exUSSR_ip;
+ }
+ }

- my $match_all = LJ::Knob->instance("adv-sup-all")->check($sup_userid);
- my $match_class = $ip_class && LJ::Knob->instance("adv-sup-$ip_class")->check($sup_userid);
+ # if we got here we SHOULD TRY to show SUP adv
+ # trying depends on value of percentage (from 0 to 100%)
+
+ my $trying_userid;
+ if ($is_sup_user) {
+ $trying_userid = $u->id;
+ }
+ elsif ($is_sup_remote) {
+ $trying_userid = $remote->id;
+ } elsif ($u) {
+ $trying_userid = $u->id;
+ } elsif ($remote) {
+ $trying_userid = $remote->id;
+ } else {
+ # anonymous user => let's use ip address as $trying_userid
+
+ $trying_userid = $ip;
+ }
+
+ my $match_all = LJ::Knob->instance("adv-sup-all")->check($trying_userid);
+ my $match_class = $ip_class && LJ::Knob->instance("adv-sup-$ip_class")->check($trying_userid);

return unless $match_all || $match_class;

Previous post Next post
Up