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

[livejournal] r17708: LJSUP-7358. If user clicks on category w...

Committer: gprochaev
LJSUP-7358. If user clicks on category we should display all communities and recent posts from this category

U   trunk/bin/worker/category-recent-posts
U   trunk/cgi-bin/LJ/Browse.pm
U   trunk/cgi-bin/LJ/Vertical.pm
U   trunk/cgi-bin/LJ/Widget/Browse.pm
U   trunk/htdocs/browse/index.bml
U   trunk/templates/Browse/featured_communities.tmpl
U   trunk/templates/Browse/index.tmpl
U   trunk/templates/Browse/top_posts.tmpl
Modified: trunk/bin/worker/category-recent-posts
===================================================================
--- trunk/bin/worker/category-recent-posts	2010-11-17 07:29:45 UTC (rev 17707)
+++ trunk/bin/worker/category-recent-posts	2010-11-18 02:54:05 UTC (rev 17708)
@@ -77,7 +77,8 @@
                 my $cat = LJ::Browse->load_by_id ($rec->{catid});
                 next unless $cat;
                 my $v = $cat->vertical;
-                $v->save_tags (is_seo => 0, tags => [ map { { tag => $_, journalid => $u->{userid}, jitemid => $entry->{itemid} } } @tags ] );
+                $v->save_tags (is_seo => 0, tags => [ map { { tag => $_, journalid => $u->{userid}, jitemid => $entry->{itemid} } } @tags ] )
+                    if $v;
             }
         }
 

Modified: trunk/cgi-bin/LJ/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Browse.pm	2010-11-17 07:29:45 UTC (rev 17707)
+++ trunk/cgi-bin/LJ/Browse.pm	2010-11-18 02:54:05 UTC (rev 17708)
@@ -244,9 +244,8 @@
     my $dbh = LJ::get_db_reader()
         or die "unable to contact global db slave to load categories";
 
-    my $vert_id = $vertical ? $vertical->vert_id : undef;
-    my $where = '';
-    $where = " WHERE vert_id = $vert_id " if $vert_id;
+    my $vert_id = $vertical ? $vertical->vert_id : 0;
+    my $where = " WHERE vert_id = $vert_id ";
 
     my $sth = $dbh->prepare("SELECT * FROM category" . $where);
     $sth->execute();
@@ -717,7 +716,9 @@
     my @cats = ( $self->catid );
     if ($args{'is_need_child'}) {
         ## get communities from child category too. need for Info (Admin Page), for example
-        my $sth = $dbh->prepare("SELECT catid FROM category WHERE parentcatid = ?");
+        my $vertical = $args{'vertical'};
+        my $where = $vertical ? " AND vert_id = " . $vertical->vert_id : '';
+        my $sth = $dbh->prepare("SELECT catid FROM category WHERE parentcatid = ? $where");
         $sth->execute($self->catid);
         while (my $row = $sth->fetchrow_hashref) {
             push @cats, $row->{'catid'};
@@ -744,6 +745,8 @@
 sub vertical {
     my $self = shift;
 
+    return undef unless $self->vert_id;
+
     return LJ::Vertical->load_by_id ($self->vert_id);
 }
 

Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2010-11-17 07:29:45 UTC (rev 17707)
+++ trunk/cgi-bin/LJ/Vertical.pm	2010-11-18 02:54:05 UTC (rev 17708)
@@ -344,6 +344,37 @@
     return $class->new( vert_id => $dbh->{mysql_insertid} );
 }
 
+# Return a list of communities found in vertical's categories
+# Returns User objects
+sub get_communities {
+    my $self = shift;
+    my %args = @_;
+
+    my $cats = $self->get_categories();
+
+    my $cusers = {};
+    foreach my $c (@$cats) {
+        my $cat = LJ::Browse->load_by_id ( $c->{catid} );
+
+        $cat->load_communities ( %args ) unless ($args{'is_need_child'} && $cat->{_loaded_journals});
+
+        my $comms = $cat->{communities};
+        my $temp_users = LJ::load_userids(@$comms);
+
+        foreach my $userid (keys %$temp_users) {
+            $cusers->{$userid} = $temp_users->{$userid};
+        }
+
+    }
+
+    return                                  # 6. return result
+        map {$_->[1]}                       # 5. get a cargo from temporary containers
+            sort {$a->[0] cmp $b->[0]}      # 4. sort it by a sort-keys
+                map {[lc $_->username, $_]} # 3. create list of [ sort-key, cargo-to-sort ]
+                    grep { $_ }             # 2. remove empties from it, we don't want to die() on $_->username
+                        (values %$cusers);  # 1. get communities list
+}
+
 sub get_categories {
     my $self = shift;
     my $cat  = shift;

Modified: trunk/cgi-bin/LJ/Widget/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Browse.pm	2010-11-17 07:29:45 UTC (rev 17707)
+++ trunk/cgi-bin/LJ/Widget/Browse.pm	2010-11-18 02:54:05 UTC (rev 17708)
@@ -97,7 +97,7 @@
 
     my $vertical = LJ::Vertical->load_by_url($uri);
     
-    $$windowtitle = $vertical->name; #$class->ml('widget.browse.windowtitle');
+    $$windowtitle = $vertical ? $vertical->name : $class->ml('widget.browse.windowtitle');
 
     my $cat = LJ::Browse->load_by_url($uri); # Currently selected category
 
@@ -171,7 +171,13 @@
         $search_str =~ s#/?\?.*##;
     }
 
-    if ($cat) { # we're looking at a lower-level category
+    if ($cat && $vertical) {
+        @comms = $cat->communities( is_need_child => 1 );
+        $ad = LJ::get_ads({ location => 'bml.explore/vertical', vertical => $vertical->name, ljadwrapper => 1 });
+    } elsif ($vertical) {
+        @comms = $vertical->get_communities( is_need_child => 1 );
+        $ad = LJ::get_ads({ location => 'bml.explore/vertical', vertical => $vertical->name, ljadwrapper => 1 });
+    } elsif ($cat) { # we're looking at a lower-level category
 
         my @cat_title = split(/>/, $cat->title_html());
         shift @cat_title;
@@ -181,14 +187,14 @@
                     (pop(@cat_title) || '');
 
         # show actual communities
-        #if ($cat->parent) {
+        if ($cat->parent) {
             if ($cat->{'pretty_name'} eq 'lj_spotlight_community') {
                 # Load communities saved by spotlight admin
                 @comms = _get_spotlight_communities();  # Load communities saved by spotlight admin
             } else {
-                @comms = $cat->communities();
+                @comms = $cat->communities;
             }
-        #}
+        }
         $ad = LJ::get_ads({ location => 'bml.explore/vertical', vertical => $cat->display_name, ljadwrapper => 1 });
     } else {
         @comms = _get_spotlight_communities();  # Show spotlight communities by default
@@ -300,33 +306,39 @@
     $uri .= '?' . $args if $args;
 
     ## Prepare DATA for Featured Communities Widget
-    my $comms = $vertical->load_communities( count => $vertical->show_entries, is_random => 1 );
+    my $comms = undef;
     my @top_comms = ();
-    foreach my $comm (@$comms) {
-        my $c = LJ::load_userid($comm->{journalid});
-        next unless $c;
-        my $userpic = $c->userpic;
-        push @top_comms, {
-            username        => $c->display_name,
-            userpic         => $userpic ? $userpic->url : '',
-            community       => $c->user,
-            bio             => $c->bio,
-        };
+    if ($vertical) {
+        $comms = $vertical->load_communities( count => $vertical->show_entries, is_random => 1 );
+        foreach my $comm (@$comms) {
+            my $c = LJ::load_userid($comm->{journalid});
+            next unless $c;
+            my $userpic = $c->userpic;
+            push @top_comms, {
+                username        => $c->display_name,
+                userpic         => $userpic ? $userpic->url : '',
+                community       => $c->user,
+                bio             => $c->bio,
+            };
+        }
     }
 
     ## Prepare DATA for Featured Posts Widget
-    my $posts = $vertical->load_vertical_posts( count => $vertical->show_entries, is_random => 1 );
+    my $posts = undef;
     my @top_posts = ();
-    foreach my $post (@$posts) {
-        my $entry = LJ::Entry->new ($post->{journalid}, jitemid => $post->{jitemid});
-        my $userpic = $entry->userpic;
-        push @top_posts, {
-            subject         => $entry->subject_text,
-            userpic         => $userpic ? $userpic->url : '',
-            updated_ago     => LJ::TimeUtil->ago_text($entry->logtime_unix),
-            comments_count  => $entry->reply_count,
-            ljuser          => $entry->journal->ljuser_display,
-        };
+    if ($vertical) {
+        $posts = $vertical->load_vertical_posts( count => $vertical->show_entries, is_random => 1 );
+        foreach my $post (@$posts) {
+            my $entry = LJ::Entry->new ($post->{journalid}, jitemid => $post->{jitemid});
+            my $userpic = $entry->userpic;
+            push @top_posts, {
+                subject         => $entry->subject_text,
+                userpic         => $userpic ? $userpic->url : '',
+                updated_ago     => LJ::TimeUtil->ago_text($entry->logtime_unix),
+                comments_count  => $entry->reply_count,
+                ljuser          => $entry->journal->ljuser_display,
+            };
+        }
     }
 
     $template->param(
@@ -351,11 +363,15 @@
         nav_line                => $nav_line,
         popular_interests_widget=> LJ::Widget::PopularInterests->render(),
         add_community_widget    => LJ::Widget::AddCommunity->render(),
-        search_widget           => LJ::Widget::Search->render(type => "tags", view => $view),
+        search_widget           => LJ::Widget::Search->render(type => $vertical ? "tags" : "yandex", view => $view),
         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),
+        poll_of_the_day         => LJ::Widget::PollOfTheDay->render(
+                                        vertical_account => $vertical ? $vertical->journal : undef,
+                                        vertical_name => $vertical ? $vertical->name : undef
+                                    ),
+        is_vertical_view        => $vertical ? 1 : 0,
     );
 
     return $template->output;

Modified: trunk/htdocs/browse/index.bml
===================================================================
--- trunk/htdocs/browse/index.bml	2010-11-17 07:29:45 UTC (rev 17707)
+++ trunk/htdocs/browse/index.bml	2010-11-18 02:54:05 UTC (rev 17708)
@@ -24,12 +24,14 @@
     my $view = defined $GET{'view'} ? $GET{'view'} : 'recent_posts';
 
     my $vertical = LJ::Vertical->load_by_url($uri);
+=head
     unless ($vertical) {
         LJ::Request->pnotes ('error'  => 'e404');
         LJ::Request->pnotes ('remote' => LJ::get_remote());
         BML::return_error_status(LJ::Request::NOT_FOUND());
         return;
     }
+=cut
 
     return LJ::Widget::Browse->render(
         browse      => 'new',

Modified: trunk/templates/Browse/featured_communities.tmpl
===================================================================
--- trunk/templates/Browse/featured_communities.tmpl	2010-11-17 07:29:45 UTC (rev 17707)
+++ trunk/templates/Browse/featured_communities.tmpl	2010-11-18 02:54:05 UTC (rev 17708)
@@ -1,3 +1,4 @@
+<tmpl_if is_vertical_view>
 <div class="appwidget appwidget-featuredcomms">
 <div class="right-mod">
 <div class="mod-tl">
@@ -35,4 +36,4 @@
 </div>
 </div>
 </div>
-
+</tmpl_if>

Modified: trunk/templates/Browse/index.tmpl
===================================================================
--- trunk/templates/Browse/index.tmpl	2010-11-17 07:29:45 UTC (rev 17707)
+++ trunk/templates/Browse/index.tmpl	2010-11-18 02:54:05 UTC (rev 17708)
@@ -1,6 +1,4 @@
 <div class="l-body">
-	<div>Vertical name</div>
-	<div>AD Block</div>
 	<div class="b-catalogue">
 		<div class="l-aside">	
 			<TMPL_INCLUDE browse.tmpl>

Modified: trunk/templates/Browse/top_posts.tmpl
===================================================================
--- trunk/templates/Browse/top_posts.tmpl	2010-11-17 07:29:45 UTC (rev 17707)
+++ trunk/templates/Browse/top_posts.tmpl	2010-11-18 02:54:05 UTC (rev 17708)
@@ -1,3 +1,4 @@
+<tmpl_if is_vertical_view>
 <div class="appwidget appwidget-featuredposts">
 <div class="right-mod">
 <div class="mod-tl">
@@ -29,4 +30,4 @@
 </div>
 </div>
 </div>
-
+</tmpl_if>

Tags: bml, 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