Committer: ssafronova
LJSUP-7052: Landing page - LJSUP-7343: Poll widget for community catalogU trunk/cgi-bin/LJ/Widget/PollOfTheDay.pm
Modified: trunk/cgi-bin/LJ/Widget/PollOfTheDay.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/PollOfTheDay.pm 2010-11-15 04:56:31 UTC (rev 9709) +++ trunk/cgi-bin/LJ/Widget/PollOfTheDay.pm 2010-11-15 05:32:29 UTC (rev 9710) @@ -12,14 +12,13 @@ my $MAX_POLLS = 15; # scroll depth sub load_last_posts { - my $class = shift; + my ($class, $lj_poll, $memkey) = @_; - my $data = LJ::MemCache::get([1, "lj_poll_posts:1"]); + my $data = LJ::MemCache::get($memkey); if ($data and ref $data eq 'ARRAY') { return @$data; } - my $lj_poll = LJ::load_user('daily_poll'); return unless $lj_poll; my @itemids; @@ -56,18 +55,32 @@ push @good, [$e->journalid, $e->ditemid]; } - LJ::MemCache::set([1, "lj_poll_posts:1"], \@good, 60); # 1 min + LJ::MemCache::set($memkey, \@good, 60); # 1 min return @good; } +# call in vertical with two parameters: +# vertical_account => journal name of vertical hosting account +# vertical_name => already translated title of the widget +# call in homepage as 'poll of the day' - without paratemers sub render_body { my $class = shift; my %opts = @_; - return if $LJ::DISABLED{'poll_of_the_day'}; + my ($poll_hoster, $memkey); + if ($opts{vertical_account}) { + return if $LJ::DISABLED{'poll_in_vertical'}; + $poll_hoster = LJ::load_user($opts{vertical_account}); + return unless $poll_hoster; + $memkey = [$poll_hoster->userid, 'lj_poll_posts:' . $poll_hoster->userid]; + } else { + return if $LJ::DISABLED{'poll_of_the_day'}; + $poll_hoster = LJ::load_user('daily_poll'); + $memkey = [1, "lj_poll_posts:1"]; + } - my @last_posts = LJ::Widget::PollOfTheDay->load_last_posts; + my @last_posts = LJ::Widget::PollOfTheDay->load_last_posts($poll_hoster, $memkey); return unless @last_posts; @@ -108,7 +121,8 @@ my $pollpic; $pollpic = '<img src="' . $img . '" alt="' . $entry->subject_text . '" class="i-potd-pic" />' if $img; - my $ret = "<div><div class='w-head'><h2><span class='w-head-in'>" . $class->ml('widget.polloftheday.title'); + my $ret = "<div><div class='w-head'><h2><span class='w-head-in'>"; + $ret .= $opts{vertical_name} ? $opts{vertical_name}: $class->ml('widget.polloftheday.title'); $ret .= "</span></h2> <i class='w-head-corner'></i></div>"; $ret .= "<div class='w-body'>"; $ret .= "<input type='hidden' value='$skip' name='skip' />";