Merge the results for communities and users, add ability to filter by
account type (communities only, personal journals only, openid journals only)
Patch by kareila.
diffs (290 lines):
diff -r 0c3f9b7f8c34 -r 684da270b0c6 bin/upgrading/en.dat
--- a/bin/upgrading/en.dat Tue Mar 01 14:45:13 2011 +0800
+++ b/bin/upgrading/en.dat Tue Mar 01 15:18:23 2011 +0800
@@ -2558,7 +2558,11 @@ s2theme.themename.default=(Unnamed - [[t
s2theme.themename.notheme=(Layout Default)
+search.user.commdesc=Community Description:
+
search.user.journal=Journal:
+
+search.user.journaltitle=Journal Title:
search.user.name=Name:
diff -r 0c3f9b7f8c34 -r 684da270b0c6 cgi-bin/DW/Controller/Search/Interests.pm
--- a/cgi-bin/DW/Controller/Search/Interests.pm Tue Mar 01 14:45:13 2011 +0800
+++ b/cgi-bin/DW/Controller/Search/Interests.pm Tue Mar 01 15:18:23 2011 +0800
@@ -303,49 +303,81 @@ sub interest_handler {
# can't trust LJ::load_userids to maintain sort order
};
+ # filtering by account type
+ $rv->{type_list} = [ 'none', 'P', 'C', 'I' ];
+
+ my $type = $args->{type};
+ $type = 'none' unless $type && $type =~ /^[PCI]$/;
+ my $typefilter = sub { return $type eq 'none' ? 1 :
+ $_[0]->journaltype eq $type };
+
+ # get top 500 user and/or community results
+ my $us = {};
+
+ unless ( $type eq 'C' ) { # unless no users needed
+ $us = $int_query->( "userinterests" );
+ $rv->{comm_count} = 1; # reset later if comms loaded
+ }
+
+ unless ( $type =~ /^[PI]$/ ) { # unless no comms needed
+ my $cus = $int_query->( "comminterests" );
+ $rv->{comm_count} = scalar values %$cus;
+
+ # combine the two sets of results
+ @{ $us }{ keys %$cus } = values %$cus;
+ }
+
my $should_show = sub {
return $_[0]->should_show_in_search_results( for => $remote );
};
- # community results
- if ( LJ::is_enabled( 'interests-community' ) ) {
- my $us = $int_query->( "comminterests" );
- my $updated = LJ::get_timeupdate_multi( keys %$us );
- my $def_upd = sub { $updated->{$_[0]->userid} || 0 };
- # let undefined values be zero for sorting purposes
- my @cl = sort { $def_upd->($b) <=> $def_upd->($a) || $a->user cmp
$b->user }
- grep { $_ && $should_show->( $_ ) } values %$us;
- $rv->{int_comms} = { count => scalar @cl, data => [] };
- foreach ( @cl ) {
- my $updated = $updated->{$_->id}
- ? LJ::diff_ago_text( $updated->{$_->id} )
+ my $updated = LJ::get_timeupdate_multi( keys %$us );
+ my $def_upd = sub { $updated->{$_[0]->userid} || 0 };
+ # let undefined values be zero for sorting purposes
+
+ my @ul = sort { $def_upd->($b) <=> $def_upd->($a) || $a->user cmp
$b->user }
+ grep { $_ && $typefilter->( $_ ) && $should_show->( $_ ) }
+ values %$us;
+ $rv->{type_count} = scalar @ul if $intcount != scalar @ul;
+
+ # construct filter links
+ $rv->{type_link} = sub {
+ return '' if $type eq $_[0]; # no link for active selection
+ my $typearg = $_[0] eq 'none' ? '' : $_[0];
+ return LJ::page_change_getargs( type => $typearg );
+ };
+
+ if ( @ul ) {
+ # pagination
+ my $curpage = $args->{page} || 1;
+ my %items = LJ::paging( \@ul, $curpage, 30 );
+ my @data;
+
+ # subset of users to display on this page
+ foreach my $u ( @{ $items{items} } ) {
+ my $desc = LJ::ehtml( $u->prop( 'journaltitle' ) );
+ my $label = LJ::Lang::ml( 'search.user.journaltitle' );
+
+ # community promo desc overrides journal title
+ if ( $u->is_comm && LJ::is_enabled( 'community_themes' ) &&
+ ( my $prop_theme = $u->prop( "comm_theme" ) ) ) {
+ $label = LJ::Lang::ml( 'search.user.commdesc' );
+ $desc = LJ::ehtml( $prop_theme );
+ }
+
+ my $userpic = $u->userpic;
+ $userpic = $userpic ? $userpic->imgtag_lite : '';
+
+ my $updated = $updated->{$u->id}
+ ? LJ::diff_ago_text( $updated->{$u->id} )
: undef;
- my $prop_theme = $_->prop("comm_theme");
- my $theme = LJ::is_enabled('community_themes') && $prop_theme
- ? LJ::ehtml( $prop_theme )
- : undef;
- push @{ $rv->{int_comms}->{data} },
- { u => $_, updated => $updated, theme => $theme };
+ push @data, { u => $u, updated => $updated, icon => $userpic,
+ desc => $desc, desclabel => $label };
}
+
+ $rv->{navbar} = LJ::paging_bar( $items{page}, $items{pages} );
+ $rv->{data} = \@data;
}
-
- # user results
- my $us = $int_query->( "userinterests" );
- my @ul = grep { $_
- && ! $_->is_community # not communities
- && $should_show->( $_ ) # and should show to
the remote user
- } values %$us;
- my $navbar;
- my $results =
- LJ::user_search_display( users => \@ul,
- timesort => 1,
- perpage => 50,
- curpage => exists $args->{page} ?
- $args->{page} : 1,
- navbar => \$navbar );
-
- $rv->{int_users} = { count => scalar( @ul ), navbar => $navbar,
- results => $results };
# check to see if the remote user already has the interest
$rv->{not_interested} = ! $remote->interests->{$interest}
diff -r 0c3f9b7f8c34 -r 684da270b0c6 views/interests/int.tt
--- a/views/interests/int.tt Tue Mar 01 14:45:13 2011 +0800
+++ b/views/interests/int.tt Tue Mar 01 15:18:23 2011 +0800
@@ -14,7 +14,13 @@
[%- sections.head = BLOCK %]
<style type='text/css'>
div.tagcloud a { text-decoration: none; }
- ul.contentlist li { padding-bottom: 3px; }
+ ul.contentlist { list-style-type: none; }
+ ul.contentlist li { padding-bottom: 1em; font-size: 125%; clear: both; }
+ ul.contentlist .userpic-img { border: 1px solid #000; }
+ .imgpos { float: left; width: 100px; min-height: 4em; text-align: right;
+ margin: 0 .5em .5em 0; }
+ .navbar { text-align: center; clear: both; }
+ .typefilter { font-weight: bold; font-size: 125%; margin: 1em 0; }
</style>
[% END -%]
@@ -37,44 +43,62 @@
<input type="text" name="fromuser" size="20" />
<input type='submit' value='[% "interests.enmasse.btn" | ml %]' />
</form></td></tr></table>
+<h1>[% ".header" | ml(interest = e_int) %]</h1>
+<div class='typefilter'>[% '.filterlink.label' | ml %]
+[%- FOREACH type = type_list -%]
+ [%- link = type_link(type) -%]
+ [%- IF type != 'none' ; ' | ' ; END -%]
+ [%- IF link %]<a href="[% link | html %]">[% END -%]
+ [%- ".filterlink.$type" | ml -%]
+ [%- IF link ; '</a>' ; END -%]
+[%- END -%]
+</div>
[%- IF intcount -%]
- [%- IF int_comms.count -%]
- <h1>[% ".communities.header" | ml(interest = e_int) %]</h1>
- <p class='matches'><b>[% '.matches2' | ml(num = int_comms.count) %]</b>
- <ul class='contentlist'>
- [%- FOREACH int_comms.data -%]
- <li class='commname'>[% u.ljuser_display %] - [% u.name_html %]
- <small class='lastupdated'>(
- [%- IF updated; '.lastupdated.true' | ml(time = updated) -%]
- [%- ELSE; '.lastupdated.false' | ml; END -%]
- )</small>
- [%- IF theme -%]
- <br /> <em>[% theme %]</em>
- [%- END -%]
- </li>
- [%- END -%]
- </ul></p>
- [%- ELSE -%]
- <h1>[% '.nocomms.header' | ml %]</h1><p>
- [%- '.nocomms.text' | ml(aopts = "href='$site.root/community/create'",
- int = interest) %]</p>
- [%- END -%]
- <h1>[% ".users.header" | ml(interest = e_int) %]</h1>
<p class='interestinfo'>
[%- IF not_interested -%]
[%- '.addint2' | ml(aopts =
"href='$site.root/interests?mode=add&intid=$intid'") -%]
[%- END -%]
[% '.morestuff2' | ml(aopts = "href='$site.root/interests'") %]</p>
- <p class='matches'><b>[% '.matches2' | ml(num = int_users.count) %]</b></p>
- <div style='text-align: center'>[% int_users.navbar %]</div><br />
- [% int_users.results %]
- <div style='text-align: center; clear: both'>[% int_users.navbar
%]</div><br />
+ [%- UNLESS comm_count -%]
+ <p class='interestinfo'>
+ [%- '.nocomms' | ml(aopts = "href='$site.root/community/create'",
+ int = e_int) %]</p>
+ [%- END -%]
+ <p class='matches'><b>
+ [%- IF type_count -%]
+ [% '.filtered' | ml(num = intcount, count = type_count) %]</p>
+ [%- ELSE -%]
+ [% '.matches2' | ml(num = intcount) %]
+ [%- END -%]
+ </b></p>
+ [%- IF data -%]
+ <div class='navbar'>[% navbar %]</div><br />
+
+ <ul class='contentlist'>
+ [%- FOREACH data -%]
+ <li><span class="imgpos">
+ <a href='[% u.allpics_base %]'>[% icon %]</a></span>
+ [% u.ljuser_display %] - [% u.name_html %]
+ [%- IF desc -%]
+ <br /> <i>[% desclabel %]</i> [% desc %]
+ [%- END -%]
+ <br /> <small class='lastupdated'>(
+ [%- IF updated; '.lastupdated.true' | ml(time = updated) -%]
+ [%- ELSE; '.lastupdated.false' | ml; END -%]
+ )</small></li>
+ [%- END -%]
+ </ul>
+
+ <div class='navbar'>[% navbar %]</div>
+ [%- ELSE -%]
+ <p>[% '.nomatch' | ml(link = type_link('none')) %]</p>
+ [%- END -%]
[%- ELSE -%]
- <h1>[% '.nocomms.header' | ml %]</h1><p>
- [%- '.nocomms.text' | ml(aopts = "href='$site.root/community/create'",
- int = e_int) %]</p>
- <h1>[% '.nousers.header' | ml %]</h1><p>
- [%- '.nousers.text2' | ml(int = e_int,
+ <p class='interestinfo'>
+ [%- '.nocomms' | ml(aopts = "href='$site.root/community/create'",
+ int = e_int) %]</p>
+ <p class='interestinfo'>
+ [%- '.nousers' | ml(int = e_int,
aopts_add =
"href='$site.root/interests?mode=addnew&keyword=$e_int'",
aopts_int = "href='$site.root/interests'") %]</p>
[%- END -%]
diff -r 0c3f9b7f8c34 -r 684da270b0c6 views/interests/int.tt.text
--- a/views/interests/int.tt.text Tue Mar 01 14:45:13 2011 +0800
+++ b/views/interests/int.tt.text Tue Mar 01 15:18:23 2011 +0800
@@ -1,7 +1,19 @@
;; -*- coding: utf-8 -*-
.addint2=If you're also interested in this, would you like to be <a
[[aopts]]>added to this list</a>?
-.communities.header=Results for communities listing an interest in
"[[interest]]"
+.filtered=[[num]] [[?num|match|matches]], showing [[count]]
[[?count|result|results]]:
+
+.filterlink.C=Communities Only
+
+.filterlink.I=OpenIDs Only
+
+.filterlink.label=Show:
+
+.filterlink.none=All Account Types
+
+.filterlink.P=Users Only
+
+.header=Search results for "[[interest]]"
.lastupdated.false=Never updated
@@ -11,14 +23,10 @@
.morestuff2=You can find more fun stuff on the <a [[aopts]]>interests page</a>.
-.nocomms.header=Relevant communities
+.nocomms=There are no communities interested in "<b>[[int]]</b>." You can <a
[[aopts]]>create one</a>!
-.nocomms.text=There are no communities interested in "<b>[[int]]</b>." You can
<a [[aopts]]>create one</a>!
+.nomatch=No matching users for the specified account type. <a
href="[[link]]">View all accounts with this interest.</a>
-.nousers.header=Interested users
-
-.nousers.text2=There are no users interested in "<b>[[int]]</b>". If you are
interested in this, <a [[aopts_add]]>click here to add the interest to your
profile</a>. More fun stuff can be found on the <a [[aopts_int]]>interests
page</a>.
+.nousers=There are no users interested in "<b>[[int]]</b>". If you are
interested in this, <a [[aopts_add]]>click here to add the interest to your
profile</a>. More fun stuff can be found on the <a [[aopts_int]]>interests
page</a>.
.title=Interests
-
-.users.header=Results for people interested in "[[interest]]"
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog