wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r19819: LJSUP-9615. Community directory homepage

Committer: gprochaev
LJSUP-9615. Community directory homepage

U   trunk/cgi-bin/LJ/Browse.pm
U   trunk/cgi-bin/LJ/Vertical.pm
U   trunk/cgi-bin/LJ/Widget/Browse.pm
U   trunk/templates/Browse/recent_posts.tmpl
U   trunk/templates/Browse/sidebar.tmpl
Modified: trunk/cgi-bin/LJ/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Browse.pm	2011-08-24 03:31:08 UTC (rev 19818)
+++ trunk/cgi-bin/LJ/Browse.pm	2011-08-24 07:07:25 UTC (rev 19819)
@@ -999,6 +999,12 @@
             push @found_posts, @$post_ids if $post_ids;
         }
         @entries =
+            map {
+                {
+                    entry   => $_,
+                    vert_id => $vertical->vert_id,
+                }
+            }
             grep {
                 ## Filter off suspended entries, deleted communities, suspended posters
                 if ($_ && $_->valid) {
@@ -1023,6 +1029,12 @@
                 { Slice => {} }
             );
             @entries =
+                map {
+                    {
+                        entry   => $_,
+                        vert_id => $vertical ? $vertical->vert_id : 0,
+                    }
+                }
                 grep {
                     ## Filter off suspended entries, deleted communities, suspended posters
                     if ($_ && $_->valid) {

Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2011-08-24 03:31:08 UTC (rev 19818)
+++ trunk/cgi-bin/LJ/Vertical.pm	2011-08-24 07:07:25 UTC (rev 19819)
@@ -386,6 +386,8 @@
 
     my $search = $args{'search'};
 
+    my $vertical = ref $self eq 'LJ::Vertical' ? $self : 'LJ::Vertical';
+
     ## remove trailing spaces
     $search =~ s/^\s+(.*?)$/$1/;
     $search =~ s/(.*?)\s+?$/$1/;
@@ -440,7 +442,7 @@
     }
 
     ## Get subcategories
-    my $cats = $self->get_categories( $args{'category'} );
+    my $cats = $vertical->get_categories( $args{'category'} );
 
     my $cusers = {};
 
@@ -491,11 +493,16 @@
 
     my $dbh = LJ::get_db_reader();
 
-    my $where = $cat ? " AND parentcatid = " . $cat->catid : "";
+    my @where = $cat ? ("parentcatid = " . $cat->catid) : ();
+    my @args = ();
+    if (ref $self eq 'LJ::Vertical') {
+        push @where, " vert_id = ? ";
+        push @args, $self->vert_id;
+    }
 
     my $cats = $dbh->selectall_arrayref(
-        "SELECT * FROM category WHERE vert_id = ? $where", 
-        { Slice => {} }, $self->vert_id
+        "SELECT * FROM category " . (@where ? " WHERE " . join " AND ", @where : ""), 
+        { Slice => {} }, @args
     );
 
     return $cats;

Modified: trunk/cgi-bin/LJ/Widget/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Browse.pm	2011-08-24 03:31:08 UTC (rev 19818)
+++ trunk/cgi-bin/LJ/Widget/Browse.pm	2011-08-24 07:07:25 UTC (rev 19819)
@@ -57,6 +57,22 @@
     return @tree;
 }
 
+sub _get_recent_posts {
+
+    my @all_verticals = LJ::Vertical->load_all ();
+
+    my @posts = map {
+        my $vertical = $_;
+        my @comms = $vertical->get_communities;
+        my @journals = map {
+            $_->{'userid'},
+        } @comms;
+        my @recent_posts = LJ::Browse->search_posts ( comms => \@journals, page_size => 1, vertical => $vertical );
+    } @all_verticals;
+
+    return \@posts;
+}
+
 sub _get_spotlight_communities {    # Load communities saved by spotlight admin
     my @comms = ();
 
@@ -101,6 +117,86 @@
     return @comms;
 }
 
+sub render_posts {
+    my $posts = shift;
+
+    my %args = @_;
+    my $post_skip = $args{'post_skip'};
+    my $post_last = $args{'post_last'};
+
+    my $post_count = 0;
+    my @tmpl_posts = ();
+    foreach my $entry_href (@$posts) {
+        my $entry = $entry_href->{'entry'};
+
+        next unless $entry;
+
+        next unless $entry->valid;
+
+        next unless 1;## This entry is inappropriate language in the subject or body
+
+        next unless $entry->visible_to (undef);
+
+        $post_count++;
+        next if $post_count <= $post_skip || $post_count > $post_last;
+
+        my $logtime = LJ::TimeUtil->mysqldate_to_time($entry->{logtime}, 0);
+        my $secondsold = $logtime ? time() - $logtime : undef;
+        my $poster = $entry->poster;
+        my $userpic = $entry->userpic;
+        my @tags = $entry->tags;
+        my $subject = $entry->subject_text || '***';
+        my $trimmed_subj = LJ::html_trim ($subject, 60);
+        my $event = $entry->event_raw;
+
+        my $parsed = LJ::Browse::Parser->do_parse (
+            text        => $event,
+            remove_tags => [ 'b', 'p', 'div', 'span', 'strong', 'font' ],
+            max_len     => 400,
+            crop_image  => 1,
+            entry       => $entry,
+            need_resize => 0,
+        );
+        $event = $parsed->{'text'};
+        my $images = $parsed->{'images'};
+
+        my $sharing_js = '';
+        if ( LJ::is_enabled('sharing') ) {
+            LJ::Share->request_resources;
+            $sharing_js = LJ::Share->render_js({ 'entry' => $entry });
+        }
+
+        my $vertical = LJ::Vertical->new ( vert_id => $entry_href->{'vert_id'} );
+
+        push @tmpl_posts, {
+            subject         => $trimmed_subj,
+            is_subject_trimmed => $subject ne $trimmed_subj ? 1 : 0,
+            userpic         => $userpic ? $userpic->url : '',
+            posted_ago      => LJ::TimeUtil->ago_text($secondsold),
+            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       => $event,
+            posted_to       => LJ::ljuser(LJ::get_username($entry->journalid)),
+            url_to_post     => $entry->url,
+            photo_for_post  => scalar @$images ? $images->[0] : '',
+            comments_count  => $entry->reply_count,
+            is_need_more    => $parsed->{'is_removed_video'} || $parsed->{'is_text_trimmed'},
+            sharing_js      => $sharing_js,
+            vertical_name   => $vertical->name,
+            vertical_url    => $vertical->url,
+        };
+    }
+
+    return {
+        posts       => \@tmpl_posts,
+        post_count  => $post_count,
+    }
+
+}
+
 sub render_body {
     my $class = shift;
     my %opts = @_;
@@ -117,7 +213,7 @@
     ) or die "Can't open template: $!";
 
     my $vertical = LJ::Vertical->load_by_url($uri);
-    $view = "recent_posts" unless $vertical;
+    $view = "recent_posts" unless $view;
 
     $$windowtitle = $vertical ? $vertical->name : $class->ml('widget.browse.windowtitle');
 
@@ -224,6 +320,11 @@
         $ad = LJ::get_ads({ location => 'bml.explore/vertical', vertical => $cat->display_name, ljadwrapper => 1 });
     } else {
         @comms = _get_spotlight_communities();  # Show spotlight communities by default
+        if (!@comms && $view eq 'communities') {
+            @comms = LJ::Vertical->get_communities(
+                is_need_child   => 1, 
+            );
+        }
         $ad = LJ::get_ads({ location => 'bml.explore/novertical', ljadwrapper => 1 });
     }
 
@@ -255,63 +356,17 @@
                 };
         }
     } else {
-        my @posts = LJ::Browse->search_posts ( comms => [ map { $_->{userid} } @comms ], page_size => 300, search_str => $search_str );
+        unless (@comms) {
+            my $posts = _get_recent_posts ();
+            my $result = render_posts ( $posts, post_skip => $post_skip, post_last => $post_last );
+            @tmpl_posts = @{$result->{'posts'}};
+            $post_count = $result->{'post_count'};
+        } else {
+            my @posts = LJ::Browse->search_posts ( comms => [ map { $_->{userid} } @comms ], page_size => 300, search_str => $search_str );
 
-        foreach my $entry (@posts) {
-            next unless $entry;
-            next unless $entry->valid;
-
-            next unless 1;## This entry is inappropriate language in the subject or body
-
-            next unless $entry->visible_to (undef);
-
-            $post_count++;
-            next if $post_count <= $post_skip || $post_count > $post_last;
-
-            my $logtime = LJ::TimeUtil->mysqldate_to_time($entry->{logtime}, 0);
-            my $secondsold = $logtime ? time() - $logtime : undef;
-            my $poster = $entry->poster;
-            my $userpic = $entry->userpic;
-            my @tags = $entry->tags;
-            my $subject = $entry->subject_text || '***';
-            my $trimmed_subj = LJ::html_trim ($subject, 60);
-            my $event = $entry->event_raw;
-
-            my $parsed = LJ::Browse::Parser->do_parse (
-                text        => $event,
-                remove_tags => [ 'b', 'p', 'div', 'span', 'strong', 'font' ],
-                max_len     => 400,
-                crop_image  => 1,
-                entry       => $entry,
-                need_resize => 0,
-            );
-            $event = $parsed->{'text'};
-            my $images = $parsed->{'images'};
-
-            my $sharing_js = '';
-            if ( LJ::is_enabled('sharing') ) {
-                LJ::Share->request_resources;
-                $sharing_js = LJ::Share->render_js({ 'entry' => $entry });
-            }
-
-            push @tmpl_posts, {
-                subject         => $trimmed_subj,
-                is_subject_trimmed => $subject ne $trimmed_subj ? 1 : 0,
-                userpic         => $userpic ? $userpic->url : '',
-                posted_ago      => LJ::TimeUtil->ago_text($secondsold),
-                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       => $event,
-                posted_to       => LJ::ljuser(LJ::get_username($entry->journalid)),
-                url_to_post     => $entry->url,
-                photo_for_post  => scalar @$images ? $images->[0] : '',
-                comments_count  => $entry->reply_count,
-                is_need_more    => $parsed->{'is_removed_video'} || $parsed->{'is_text_trimmed'},
-                sharing_js      => $sharing_js,
-            };
+            my $result = render_posts ( \@posts, post_skip => $post_skip, post_last => $post_last );
+            @tmpl_posts = @{$result->{'posts'}};
+            $post_count = $result->{'post_count'};
         }
     }
 
@@ -449,7 +504,8 @@
                                         vertical_account => $vertical ? $vertical->journal : undef,
                                         vertical_name    => $vertical ? $vertical->name : undef,
                                     ),
-        is_vertical_view        => $vertical ? 1 : 0,
+        is_vertical_view        => 1,
+        is_vertical_selected    => $vertical ? 1 : 0,
     );
 
     return $template->output;

Modified: trunk/templates/Browse/recent_posts.tmpl
===================================================================
--- trunk/templates/Browse/recent_posts.tmpl	2011-08-24 03:31:08 UTC (rev 19818)
+++ trunk/templates/Browse/recent_posts.tmpl	2011-08-24 07:07:25 UTC (rev 19819)
@@ -10,6 +10,7 @@
 
 <ul class="b-catalogue-list b-recent-posts">
 <tmpl_loop posts>
+    <tmpl_unless is_vertical_selected><tmpl_var vertical_name>:<tmpl_var vertical_url></tmpl_unless>
 	<li class="b-catalogue-item">
 		<dl class="b-catalogue-item-header">
 			<dt class="b-catalogue-item-subject"><a href="<tmpl_var url_to_post>"><tmpl_var subject><tmpl_if is_subject_trimmed>&hellip;</tmpl_if></a></dt>

Modified: trunk/templates/Browse/sidebar.tmpl
===================================================================
--- trunk/templates/Browse/sidebar.tmpl	2011-08-24 03:31:08 UTC (rev 19818)
+++ trunk/templates/Browse/sidebar.tmpl	2011-08-24 07:07:25 UTC (rev 19819)
@@ -2,14 +2,14 @@
 <TMPL_VAR search_widget>
 <TMPL_IF ad><div class="b-catalogue-ads"><TMPL_VAR ad></div></TMPL_IF>
 <TMPL_IF 0><TMPL_VAR popular_interests_widget></TMPL_IF>
-<tmpl_if is_vertical_view><tmpl_include top_posts.tmpl></tmpl_if>
-<tmpl_if is_vertical_view>
+<tmpl_if is_vertical_selected><tmpl_include top_posts.tmpl></tmpl_if>
+<tmpl_if is_vertical_selected>
 	<tmpl_if poll_of_the_day>
 	<div class="appwidget-polloftheday-wrapper"><div class="right-mod"><div class="mod-tl"><div class="mod-tr"><div class="mod-br"><div class="mod-bl">
 	<tmpl_var poll_of_the_day>
 	</div></div></div></div></div></div>
     </tmpl_if>
 </tmpl_if>
-<tmpl_if is_vertical_view><tmpl_include featured_communities.tmpl></tmpl_if>
+<tmpl_if is_vertical_selected><tmpl_include featured_communities.tmpl></tmpl_if>
 <TMPL_VAR add_community_widget>
 

Tags: livejournal, pm, tmpl, wisest-owl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments