root/trunk/cgi-bin/LJ/Widget/QotDResponses.pm

Revision 16287, 4.3 KB (checked in by mchernyshev, 6 months ago)

LJSUP-5539: There is no question preview

  • show question preview when there is no answers;
  • remove 'answer' link below block so there is such button inside block.
Line 
1package LJ::Widget::QotDResponses;
2
3use strict;
4use base qw(LJ::Widget);
5use Carp qw(croak);
6use Class::Autouse qw( LJ::QotD );
7
8sub need_res {
9    return qw( js/widgets/qotd.js stc/widgets/qotd.css stc/widgets/qotdresponses.css );
10}
11
12# how many individual
13sub responses_per_page { 30 }
14
15# how much of each entry should we show?
16sub entry_show_length { 200 }
17
18sub load_responses {
19    my $class = shift;
20    my %opts = @_;
21
22}
23
24sub render_body {
25    my $class = shift;
26    my %opts = @_;
27
28    my $hide_question = $opts{hide_question};
29
30    my $remote = LJ::get_remote();
31
32    my $get = $class->get_args;
33
34    my $qid  = $get->{qid}+0;
35    my $skip = $get->{skip}+0;
36
37    my ($q) = $qid ? LJ::QotD->get_single_question($qid) : LJ::QotD->get_questions;
38    $qid = $q->{qid} if $q;
39    return $class->ml('widget.qotdresponses.no.entries.to.display') unless $qid;
40
41    # get responses
42    my $show_size = $class->responses_per_page;
43    my $queue = LJ::queue("latest_qotd_$qid");
44    my @responses = $queue->get($skip, $show_size+1, reverse => 1);
45
46    # we'll try to fetch 1 more than we need... if it came back then
47    # we know we need a 'more' link below.
48    my $need_more = @responses >= $show_size + 1 ? 1 : 0;
49
50    # now truncate the list back down to $show_size
51    @responses = @responses[0..($show_size-1)] if @responses > $show_size;
52
53    my $ret = "";
54
55    unless ($hide_question) {
56        my $widget_html = LJ::Widget::QotD->render(question => $q, nocontrols => 1);
57        $ret .= "<div class='qotd-container'>$widget_html</div>";
58    }
59
60    unless (@responses) {
61        $ret .= "<?p " . $class->ml('widget.qotdresponses.there.are.no.answers') . " p?>";
62        $ret .= "<ul>";
63        $ret .= "<li><a href='" . $remote->journal_base . "/friends'>" . $class->ml('widget.qotdresponses.read.your.friends.page') . "</a></li>"
64            if $remote;
65        $ret .= "<li><a href='$LJ::SITEROOT/site/search.bml'>" . $class->ml('widget.qotdresponses.explore') . " $LJ::SITENAMEABBREV</a></li>";
66        $ret .= "</ul>";
67        return $ret;
68    }
69
70    $ret .= $class->render_responses(@responses);
71
72    # did we have more to display?
73    if ($need_more) {
74        my $newskip = $skip + $show_size;
75        $ret .= "<div><a href='$LJ::SITEROOT/misc/latestqotd.bml?qid=$qid&skip=$newskip'>" . $class->ml('widget.qotdresponses.previous') . " $show_size</a></div>";
76    }
77
78    return $ret;
79}
80
81sub render_responses {
82    my $class = shift;
83    my @responses = @_;
84
85    my $remote = LJ::get_remote();
86
87    my $ret = "";
88   
89  RESPONSE:
90    foreach my $resp (@responses) {
91        my ($userid, $jitemid) = split(',', $resp);
92
93        if (! $userid || ! $jitemid) {
94            warn "invalid qotd queue item: '$resp'";
95            next;
96        }
97
98        my $journal = LJ::load_userid($userid);
99        my $entry = LJ::Entry->new($journal, jitemid => $jitemid);
100        next unless $journal && $entry && $entry->valid;
101        next unless $entry->visible_to($remote);
102
103        foreach my $u (($entry->journal, $entry->poster)) {
104            next RESPONSE unless $u->is_visible;
105            next RESPONSE if $u->prop("exclude_from_verticals");
106            next RESPONSE if $u->prop("latest_optout");
107        }
108
109        my $userpic = $entry->userpic;
110        my $userpic_html = '';
111
112        if ($userpic) {
113            my $img = $userpic->imgtag(width => 75);
114            $userpic_html = qq { <div class="lj_qotd_entry_userpic">$img</div> };
115        }
116
117        my $entry_html = LJ::trim($entry->event_html_summary($class->entry_show_length, { noexpandembedded => 1 }));
118        my $entry_author = $journal->ljuser_display();
119        my $entry_subject = $entry->subject_html;
120        my $entry_url = $entry->url;
121        my $entry_cmt_link = $entry->reply_url;
122        my $comments = $entry->comment_text;
123
124        $ret .= qq {
125            <div class="lj_qotd_entry_container">
126                $userpic_html
127                <div class="lj_qotd_entry_subject">$entry_author $entry_subject</div>
128                <div class="lj_qotd_entry_body">$entry_html</div>
129                <div>
130        };   
131               
132        $ret .= "<a href=\"$entry_url\">" . $class->ml('widget.qotdresponses.read.more') . "</a> | <a href=\"$entry_cmt_link\">$comments</a>";
133        $ret .= '</div><div class="clear">&nbsp;</div></div>';
134       
135    }
136
137    return $ret;
138}
139
1401;
Note: See TracBrowser for help on using the browser.