Skip to content

Commit 4bfa49d

Browse files
momijizukamoriCocoa
andauthored
Convert misc widgets to TT (#3500)
* Convert Search widget * Convert PaidAccountStatus widget to use TT * Convert NewlyCreatedComms and RecentlyActiveComms to TT --------- Co-authored-by: Cocoa <momijizukamori@gmail.com>
1 parent 8531320 commit 4bfa49d

File tree

7 files changed

+45
-70
lines changed

7 files changed

+45
-70
lines changed

cgi-bin/DW/Widget/NewlyCreatedComms.pm

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ sub render_body {
3535

3636
my $dbr = LJ::get_db_reader();
3737
my $sth;
38-
my $ret;
3938

4039
# prep the stats we're interested in using here
4140

@@ -44,24 +43,16 @@ sub render_body {
4443
);
4544
$sth->execute;
4645

47-
$ret .= "<h2>" . $class->ml('widget.comms.recentcreate') . "</h2>";
48-
$ret .= "<ul>";
49-
50-
# build the list
51-
52-
my $ct;
5346
my $targetu;
47+
my @rowdata;
5448

5549
while ( my ( $iuser, $iname, $itime ) = $sth->fetchrow_array ) {
5650
$targetu = LJ::load_user($iuser);
57-
$ret .= "<li>" . $targetu->ljuser_display . ": " . $iname . ", " . $itime . "</li>\n";
58-
$ct++;
51+
push @rowdata, { user => $targetu, name => $iname, time => $itime };
5952
}
6053

61-
$ret .= "<li><em> " . BML::ml('widget.comms.notavailable') . "</em></li>" unless $ct;
62-
$ret .= "</ul>\n";
63-
64-
return $ret;
54+
return DW::Template->template_string( 'widget/comms.tt',
55+
{ title => 'widget.comms.recentcreate', rowdata => \@rowdata } );
6556
}
6657

6758
1;

cgi-bin/DW/Widget/PaidAccountStatus.pm

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ sub render_body {
4141
. LJ::mysql_time($expires_at)
4242
: '';
4343

44-
my $ret = "<div class='shop-item-highlight shop-account-status border'>";
45-
$ret .= $class->ml('widget.paidaccountstatus.accounttype') . " ";
46-
$ret .= "<strong>$account_type</strong>$expires_on";
47-
$ret .= "</div>";
48-
49-
return $ret;
44+
return DW::Template->template_string( 'widget/paidaccountstatus.tt',
45+
{ account_type => $account_type, expires_on => $expires_on } );
5046
}
5147

5248
1;

cgi-bin/DW/Widget/RecentlyActiveComms.pm

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ sub render_body {
3535

3636
my $dbr = LJ::get_db_reader();
3737
my $sth;
38-
my $ret;
3938

4039
# prep the stats we're interested in using here
4140

@@ -45,25 +44,16 @@ sub render_body {
4544
. " AND u.journaltype = 'C' ORDER BY uu.timeupdate_public DESC LIMIT 10" );
4645
$sth->execute;
4746

48-
$ret .= "<h2>" . $class->ml('widget.comms.recentactive') . "</h2>";
49-
$ret .= "<ul>";
50-
51-
# build the list
52-
53-
my $ct;
5447
my $targetu;
48+
my @rowdata;
5549

5650
while ( my ( $iuser, $iname, $itime ) = $sth->fetchrow_array ) {
5751
$targetu = LJ::load_user($iuser);
58-
$ret .= "<li>" . $targetu->ljuser_display . ": " . $iname . ", " . $itime . "</li>\n";
59-
$ct++;
52+
push @rowdata, { user => $targetu, name => $iname, time => $itime };
6053
}
6154

62-
$ret .= "<li><em> " . BML::ml('widget.comms.notavailable') . "</em></li>" unless $ct;
63-
$ret .= "</ul>\n";
64-
65-
LJ::warn_for_perl_utf8($ret);
66-
return $ret;
55+
return DW::Template->template_string( 'widget/comms.tt',
56+
{ title => 'widget.comms.recentactive', rowdata => \@rowdata } );
6757
}
6858

6959
1;

cgi-bin/LJ/Widget/Search.pm

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,7 @@ use Carp qw(croak);
2020
sub need_res { qw( stc/widgets/search.css ) }
2121

2222
sub render_body {
23-
my $class = shift;
24-
my %opts = @_;
25-
my $ret;
26-
27-
my ( $select_box, $search_btn );
28-
29-
my @search_opts = (
30-
int => $class->ml('widget.search.interest'),
31-
region => $class->ml('widget.search.region'),
32-
nav_and_user => $class->ml('widget.search.siteuser'),
33-
faq => $class->ml('widget.search.faq'),
34-
email => $class->ml('widget.search.email'),
35-
);
36-
37-
{
38-
$select_box =
39-
LJ::html_select( { name => 'type', selected => 'int', class => 'select' },
40-
@search_opts )
41-
. " ";
42-
$search_btn = LJ::html_submit( $class->ml('widget.search.btn.go') );
43-
}
44-
45-
$ret .= "<form action='$LJ::SITEROOT/multisearch' method='post'>\n";
46-
$ret .= LJ::html_text(
47-
{
48-
name => 'q',
49-
id => 'search',
50-
class => 'text',
51-
title => $class->ml('widget.search.title'),
52-
size => 20
53-
}
54-
) . " ";
55-
$ret .= $select_box;
56-
$ret .= $search_btn;
57-
$ret .= "</form>";
58-
59-
return $ret;
23+
return DW::Template->template_string('widget/search.tt');
6024
}
6125

6226
1;

views/widget/comms.tt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h2>[% dw.ml(title) %]</h2>
2+
<ul>
3+
[% IF rowdata.length > 0 %]
4+
[% FOREACH row IN rowdata %]
5+
<li>[% row.user.ljuser_display %]: [% row.name %], [% row.time %]</li>
6+
[% END %]
7+
[% ELSE %]
8+
<li><em>[% dw.ml('widget.comms.notavailable') %]</em></li>
9+
[% END %]
10+
</ul>

views/widget/paidaccountstatus.tt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class='shop-item-highlight shop-account-status border'>
2+
[% dw.ml('widget.paidaccountstatus.accounttype') %] <strong>[% account_type %]</strong>[% expires_on %]
3+
</div>

views/widget/search.tt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<form action='[% site.root %]/multisearch' method='post'>
2+
[% form.textbox (
3+
name => 'q',
4+
id => 'search',
5+
class => 'text',
6+
title => dw.ml('widget.search.title'),
7+
size => 20)
8+
%]
9+
[% form.select(
10+
name => 'type',
11+
selected => 'int',
12+
class => 'select',
13+
items => [
14+
'int', dw.ml('widget.search.interest'),
15+
'region', dw.ml('widget.search.region'),
16+
'nav_and_user', dw.ml('widget.search.siteuser'),
17+
'faq', dw.ml('widget.search.faq'),
18+
'email', dw.ml('widget.search.email'),
19+
] ) %]
20+
[% form.submit( value = dw.ml('widget.search.btn.go') )%]
21+
</form>

0 commit comments

Comments
 (0)