Committer: gprochaev
LJSUP-7052. Add draft version of search. Add Poll Widget. U trunk/cgi-bin/LJ/Browse.pm U trunk/cgi-bin/LJ/Widget/Browse.pm U trunk/cgi-bin/LJ/Widget/Search.pm U trunk/htdocs/browse/index.bml U trunk/templates/Browse/search.tmpl U trunk/templates/Browse/sidebar.tmpl
Modified: trunk/cgi-bin/LJ/Browse.pm =================================================================== --- trunk/cgi-bin/LJ/Browse.pm 2010-11-15 04:39:21 UTC (rev 17680) +++ trunk/cgi-bin/LJ/Browse.pm 2010-11-15 08:04:22 UTC (rev 17681) @@ -355,7 +355,7 @@ $url =~ /^(?:$LJ::SITEROOT)?(\/.+)$/; my $path = $1; - $path =~ s/\/?(?:\?.*)?$//; # remove trailing slash and any get args + $path =~ s/(?:tag)?\/?.*?\/?(?:\?.*)?$//; # remove search string, trailing slash and any get args $path =~ s/\/index\.bml$//; # remove bml page # 4 possibilities: @@ -833,6 +833,25 @@ return $ret; } +sub search_posts { + my $class = shift; + my $search = shift; + my $limit = shift; + + my $dbh = LJ::get_db_reader(); + my $posts = $dbh->selectall_arrayref ("SELECT journalid, jitemid FROM vertical_keywords WHERE keyword = ? AND is_seo = 0", { Slice => {} }, $search); + my @found_posts = (); + foreach my $post (@$posts) { + my $post_ids = $dbh->selectall_arrayref ("SELECT journalid, jitemid FROM category_recent_posts WHERE journalid = ? AND jitemid = ? AND is_deleted = 0 ORDER BY timecreate DESC LIMIT $limit", { Slice => {} }, $post->{journalid}, $post->{jitemid}); + push @found_posts, @$post_ids; + } + my @entries = + map { LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid}) } ## Create LJ::Entry object + grep { $_->{journalid} } ## remove SEO posts + @found_posts; + return @entries; +} + sub recent_posts { my $class = shift; my $comms = shift; Modified: trunk/cgi-bin/LJ/Widget/Browse.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/Browse.pm 2010-11-15 04:39:21 UTC (rev 17680) +++ trunk/cgi-bin/LJ/Widget/Browse.pm 2010-11-15 08:04:22 UTC (rev 17681) @@ -160,6 +160,17 @@ $post_page ||= 1; my $post_skip = ($post_page-1) * $post_page_size; my $post_last = $post_skip + $post_page_size; + + $$title = "$$windowtitle"; + + my $search_str = undef; + if ($opts{'post_vars'}->{'do_search'}) { + $search_str = $opts{'post_vars'}->{'search_text'}; + } else { + ($search_str) = $uri =~ m#.*?tag/(.*)#; + $search_str =~ s#/?\?.*##; + } + if ($cat) { # we're looking at a lower-level category my @cat_title = split(/>/, $cat->title_html()); @@ -184,60 +195,65 @@ $ad = LJ::get_ads({ location => 'bml.explore/novertical', ljadwrapper => 1 }); } - $$title = "$$windowtitle"; + if ($view eq 'communities') { + foreach my $comm (@comms) { + next unless LJ::isu($comm); - my @posts = LJ::Browse->recent_posts ( [ map { $_->{userid} } @comms ], $post_page_size ); + # paging + $count++; + next if $count <= $skip || $count > $last; - foreach my $entry (@posts) { - next unless $entry; + my $secondsold = $comm->timeupdate ? time() - $comm->timeupdate : undef; + my $userpic = $comm->userpic ? + $comm->userpic->imgtag_percentagesize(1) : + LJ::run_hook('no_userpic_html', percentage => 1 ); - next unless 1;## This entry is inappropriate language in the subject or body + push @tmpl_communities, + { + featured => 0, + userpic => $userpic, + journal_name => $comm->ljuser_display(), + journal_user => $comm->{user}, + journal_base => $comm->journal_base(), + journal_title => $comm->{'name'} || '', + journal_subtitle => $comm->prop('comm_theme') || '', + updated_ago => LJ::TimeUtil->ago_text($secondsold), + }; + } + } else { + my @posts = (); + if ($search_str) { + @posts = LJ::Browse->search_posts ( $search_str, $post_page_size ); + } else { + @posts = LJ::Browse->recent_posts ( [ map { $_->{userid} } @comms ], $post_page_size ); + } - $post_count++; - next if $post_count <= $post_skip || $post_count > $post_last; + foreach my $entry (@posts) { + next unless $entry; - my $poster = $entry->poster; - my $userpic = $entry->userpic; - my @tags = $entry->tags; - push @tmpl_posts, { - subject => $entry->subject_text, - userpic => $userpic ? $userpic->url : '', - posted_ago => LJ::TimeUtil->ago_text($entry->logtime_unix), - poster => $poster ? LJ::ljuser($poster) : '?', - tags => scalar @tags ? [ map { { tag => $_ } } @tags ] : '', - mood => $entry->prop('current_mood') || LJ::mood_name($entry->prop('current_moodid')) || '', - music => $entry->prop('current_music'), - location => $entry->prop('current_location'), - post_text => $entry->event_html, - url_to_post => $entry->url, - comments_count => $entry->reply_count, - is_need_more => bytes::length($entry->event_text) > 800 ? 1 : 0, - }; - } + next unless 1;## This entry is inappropriate language in the subject or body - foreach my $comm (@comms) { - next unless LJ::isu($comm); + $post_count++; + next if $post_count <= $post_skip || $post_count > $post_last; - # paging - $count++; - next if $count <= $skip || $count > $last; - - my $secondsold = $comm->timeupdate ? time() - $comm->timeupdate : undef; - my $userpic = $comm->userpic ? - $comm->userpic->imgtag_percentagesize(1) : - LJ::run_hook('no_userpic_html', percentage => 1 ); - - push @tmpl_communities, - { - featured => 0, - userpic => $userpic, - journal_name => $comm->ljuser_display(), - journal_user => $comm->{user}, - journal_base => $comm->journal_base(), - journal_title => $comm->{'name'} || '', - journal_subtitle => $comm->prop('comm_theme') || '', - updated_ago => LJ::TimeUtil->ago_text($secondsold), + my $poster = $entry->poster; + my $userpic = $entry->userpic; + my @tags = $entry->tags; + push @tmpl_posts, { + subject => $entry->subject_text, + userpic => $userpic ? $userpic->url : '', + posted_ago => LJ::TimeUtil->ago_text($entry->logtime_unix), + poster => $poster ? LJ::ljuser($poster) : '?', + tags => scalar @tags ? [ map { { tag => $_ } } @tags ] : '', + mood => $entry->prop('current_mood') || LJ::mood_name($entry->prop('current_moodid')) || '', + music => $entry->prop('current_music'), + location => $entry->prop('current_location'), + post_text => $entry->event_html, + url_to_post => $entry->url, + comments_count => $entry->reply_count, + is_need_more => bytes::length($entry->event_text) > 800 ? 1 : 0, }; + } } # post paging: first, previouse, next, last pages. @@ -344,6 +360,7 @@ top_posts => \@top_posts, top_comms => \@top_comms, view => $view, + poll_of_the_day => LJ::Widget::PollOfTheDay->render(vertical_account => $vertical->journal, vertical_name => $vertical->name), ); return $template->output; Modified: trunk/cgi-bin/LJ/Widget/Search.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/Search.pm 2010-11-15 04:39:21 UTC (rev 17680) +++ trunk/cgi-bin/LJ/Widget/Search.pm 2010-11-15 08:04:22 UTC (rev 17681) @@ -83,7 +83,7 @@ $uri .= "/" if $uri !~ m#/$#; ## add end slash if not exist $template->param ( vertical_name => $vertical->name, - search_url => $uri."tag", + search_url => $uri, view => $opts{'view'}, tags => [ map { { tag => $_->{keyword} } } @{$vertical->load_tags (is_seo => 1)} ], ); Modified: trunk/htdocs/browse/index.bml =================================================================== --- trunk/htdocs/browse/index.bml 2010-11-15 04:39:21 UTC (rev 17680) +++ trunk/htdocs/browse/index.bml 2010-11-15 08:04:22 UTC (rev 17681) @@ -40,6 +40,7 @@ page => $page, post_page => $post_page, view => $view, + post_vars => \%POST, ); } _code?> Modified: trunk/templates/Browse/search.tmpl =================================================================== --- trunk/templates/Browse/search.tmpl 2010-11-15 04:39:21 UTC (rev 17680) +++ trunk/templates/Browse/search.tmpl 2010-11-15 08:04:22 UTC (rev 17681) @@ -9,7 +9,7 @@ <i class="w-head-corner"></i> </div> <div class="w-body"> - <form action=""> + <form action="<tmpl_var search_url>" method="POST"> <fieldset> <p> <label for="search_text" id="search_text_label">Find</label> @@ -18,7 +18,7 @@ </p> <ul class="b-search-tags"> <tmpl_loop tags> - <li<tmpl_if __last__> class="last"</tmpl_if>><a href="<tmpl_var search_url>/<tmpl_var tag><tmpl_if view>?view=<tmpl_var view></tmpl_if>"><tmpl_var tag></a></li> + <li<tmpl_if __last__> class="last"</tmpl_if>><a href="<tmpl_var search_url>tag/<tmpl_var tag><tmpl_if view>?view=<tmpl_var view></tmpl_if>"><tmpl_var tag></a></li> </tmpl_loop> </ul> </fieldset> Modified: trunk/templates/Browse/sidebar.tmpl =================================================================== --- trunk/templates/Browse/sidebar.tmpl 2010-11-15 04:39:21 UTC (rev 17680) +++ trunk/templates/Browse/sidebar.tmpl 2010-11-15 08:04:22 UTC (rev 17681) @@ -8,4 +8,5 @@ <tmpl_include top_posts.tmpl> <tmpl_include featured_communities.tmpl> <TMPL_VAR add_community_widget> +<tmpl_var poll_of_the_day>