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

[livejournal] r17622: LJSUP-7052. Add Vertical top posts

Committer: gprochaev
LJSUP-7052. Add Vertical top posts

U   trunk/cgi-bin/LJ/Browse.pm
U   trunk/cgi-bin/LJ/Vertical.pm
U   trunk/cgi-bin/LJ/VerticalEditorials.pm
U   trunk/cgi-bin/LJ/Widget/AddVerticalEditorials.pm
U   trunk/cgi-bin/LJ/Widget/Browse.pm
U   trunk/cgi-bin/LJ/Widget/VerticalContentControl.pm
U   trunk/htdocs/admin/browse/add_community.bml
U   trunk/htdocs/admin/browse/index.bml
U   trunk/htdocs/admin/browse/manage_category.bml
U   trunk/htdocs/admin/browse/recent_posts.bml
A   trunk/htdocs/admin/browse/top_entries_vertical.bml
U   trunk/htdocs/browse/index.bml
U   trunk/templates/Browse/sidebar.tmpl
A   trunk/templates/Browse/top_posts.tmpl
Modified: trunk/cgi-bin/LJ/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Browse.pm	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/cgi-bin/LJ/Browse.pm	2010-11-01 06:13:08 UTC (rev 17622)
@@ -246,10 +246,10 @@
 
     my $vert_id = $vertical ? $vertical->vert_id : undef;
     my $where = '';
-    $where = ' WHERE vert_id = ? ' if $vert_id;
+    $where = " WHERE vert_id = $vert_id " if $vert_id;
 
     my $sth = $dbh->prepare("SELECT * FROM category" . $where);
-    $sth->execute($vert_id);
+    $sth->execute();
     die $dbh->errstr if $dbh->err;
 
     my @categories;
@@ -373,7 +373,7 @@
         ## Vertical is not set
         return undef unless $v_uri;
 
-        my $vertical = LJ::Vertical->load_by_url ($v_uri);
+        #my $vertical = LJ::Vertical->load_by_url ($v_uri);
         #return $vertical;
 
         # check cache now for full URI
@@ -701,6 +701,7 @@
 
 sub load_communities {
     my $self = shift;
+    my %args = @_;
 
     # check memcache for data
     my $memval = LJ::MemCache::get($self->memkey_catid_journals());
@@ -712,8 +713,19 @@
     my $dbh = LJ::get_db_reader()
         or die "unable to contact global db slave to load category";
 
-    my $sth = $dbh->prepare("SELECT * FROM categoryjournals WHERE catid=?");
-    $sth->execute($self->catid);
+    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 = ?");
+        $sth->execute($self->catid);
+        while (my $row = $sth->fetchrow_hashref) {
+            push @cats, $row->{'catid'};
+        }
+    }
+
+    my @ph = map { '?' } @cats;
+    my $sth = $dbh->prepare("SELECT * FROM categoryjournals WHERE catid IN (".(join ",", @ph).")");
+    $sth->execute(@cats);
     my $jrow;
     while (my $row = $sth->fetchrow_hashref) {
         push @{$jrow->{communities}}, $row->{journalid};
@@ -727,6 +739,13 @@
 # Accessors
 #
 #
+
+sub vertical {
+    my $self = shift;
+
+    return LJ::Vertical->load_by_id ($self->vert_id);
+}
+
 sub children {
     my $self = shift;
     my %opts = @_;
@@ -769,11 +788,14 @@
 sub path {
     my $c = shift;
     my $p = '';
+    my $v = undef;
     if ($c->parent) {
         $p = $c->parent->url_path . $p;
         $p = path($c->parent) . $p;
+    } else {
+        $v = LJ::Vertical->load_by_id ($c->vert_id);
     }
-    return $p;
+    return $v ? $v->uri . $p : $p;
 }
 
 # returns full URL for a category
@@ -783,7 +805,7 @@
 
     return undef unless $vertical;
 
-    my $base = "$LJ::SITEROOT/browse".$vertical->uri;
+    my $base = "$LJ::SITEROOT/browse";
 
     return $base . $self->uri . "/";
 }
@@ -828,8 +850,10 @@
 # Returns User objects
 sub communities {
     my $self = shift;
-    $self->load_communities unless $self->{_loaded_journals};
+    my %args = @_;
 
+    $self->load_communities ( %args ) unless ($args{'is_need_child'} && $self->{_loaded_journals});
+
     my $comms = $self->{communities};
     my $cusers = LJ::load_userids(@$comms);
 
@@ -950,6 +974,7 @@
 sub display_name   { shift->_get_set('pretty_name')        }
 sub url_path       { shift->_get_set('url_path')           }
 sub parentid       { shift->_get_set('parentcatid')        }
+sub vert_id        { shift->_get_set('vert_id')            }
 
 
 # Community Moderation

Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/cgi-bin/LJ/Vertical.pm	2010-11-01 06:13:08 UTC (rev 17622)
@@ -42,7 +42,7 @@
 #
 
 my %singletons = (); # vertid => singleton
-my @vert_cols = qw( vert_id url journal name createtime lastfetch );
+my @vert_cols = qw( vert_id url journal name createtime lastfetch show_entries not_deleted remove_after );
 
 sub min_age_of_poster_account {
     my $class = shift;
@@ -373,7 +373,7 @@
 
     my $reqcache = $LJ::REQ_GLOBAL{vertname}->{$name};
     if ($reqcache) {
-        my $v = $class->new( vertid => $reqcache->{vertid} );
+        my $v = $class->new( vert_id => $reqcache->{vert_id} );
         $v->absorb_row($reqcache);
 
         return $v;
@@ -382,7 +382,7 @@
     # check memcache for data
     my $memval = LJ::MemCache::get($class->memkey_vertname($name));
     if ($memval) {
-        my $v = $class->new( vertid => $memval->{vertid} );
+        my $v = $class->new( vert_id => $memval->{vert_id} );
         $v->absorb_row($memval);
         $LJ::REQ_GLOBAL{vertname}->{$name} = $memval;
 
@@ -393,12 +393,12 @@
         or die "unable to contact global db master to load vertical";
 
     # not in memcache; load from db
-    my $sth = $dbh->prepare("SELECT * FROM vertical WHERE name = ?");
+    my $sth = $dbh->prepare("SELECT * FROM vertical2 WHERE name = ?");
     $sth->execute($name);
     die $dbh->errstr if $dbh->err;
 
     if (my $row = $sth->fetchrow_hashref) {
-        my $v = $class->new( vertid => $row->{vertid} );
+        my $v = $class->new( vert_id => $row->{vert_id} );
         $v->absorb_row($row);
         $v->set_memcache;
         $LJ::REQ_GLOBAL{vertname}->{$name} = $row;
@@ -540,13 +540,25 @@
     my $class = shift;
 
     my @verticals;
-    foreach my $vertname (keys %LJ::VERTICAL_TREE) {
-        next unless $LJ::VERTICAL_TREE{$vertname}->{has_editorials};
 
-        my $v = $class->load_by_name($vertname);
-        push @verticals, $v if $v;
+    my $dbh = LJ::get_db_writer()
+        or die "unable to contact global db master to load vertical";
+
+    my $sth = $dbh->prepare("SELECT * FROM vertical2");
+    $sth->execute;
+    die $dbh->errstr if $dbh->err;
+
+    my @verticals;
+    while (my $row = $sth->fetchrow_hashref) {
+        my $v = $class->new( vert_id => $row->{vert_id} );
+        $v->absorb_row($row);
+        $v->set_memcache;
+
+        push @verticals, $v;
     }
 
+        #next unless $LJ::VERTICAL_TREE{$vertname}->{has_editorials};
+
     return sort { lc $a->display_name cmp lc $b->display_name } @verticals;
 }
 
@@ -574,6 +586,30 @@
 # Loaders
 #
 
+## Return a list of Top Entries in communities
+## Arg:
+##     - count     - for admin page - all (Inf), for widget - 5, for example
+##     - is_random - need to shuffle?
+sub load_vertical_posts {
+    my $self = shift;
+    my %args = @_;
+
+    my $is_random = $args{'is_random'};
+
+    my $dbh = LJ::get_db_writer();
+    my $posts = $dbh->selectall_arrayref("SELECT * FROM vertical_posts WHERE vert_id = ?", { Slice => {} }, $self->vert_id);
+    my $max_num = scalar @$posts;
+    my $count   = $args{'count'};
+    $count = $max_num if $count > $max_num;
+    my @result = ();
+    while ($count--) {
+        my $post = $posts->[int(rand($max_num))];
+        push @result, $post if $post;
+    }
+
+    return \@result;
+}
+
 sub memkey_vertid {
     my $self = shift;
     my $id = shift;
@@ -722,7 +758,7 @@
 
     my @vals = keys %need;
     my $bind = LJ::bindstr(@vals);
-    my $sth = $dbh->prepare("SELECT * FROM vertical WHERE vert_id IN ($bind)");
+    my $sth = $dbh->prepare("SELECT * FROM vertical2 WHERE vert_id IN ($bind)");
     $sth->execute(@vals);
 
     while (my $row = $sth->fetchrow_hashref) {
@@ -847,7 +883,7 @@
 
     # db contains storable object
     my $rules = $dbh->selectrow_array("SELECT rules FROM vertical_rules WHERE vertid=?",
-                                      undef, $self->vertid);
+                                      undef, $self->vert_id);
     die $dbh->errstr if $dbh->err;
 
     # if we got something, deserialize it
@@ -989,6 +1025,37 @@
 # Accessors
 #
 
+sub delete_post {
+    my $self = shift;
+    my %args = @_;
+
+    my $post_id = $args{'post_id'};
+
+    my ($jitemid, $journalid) = $post_id =~ m#^(\d+)-(\d+)$#; ## Parse key
+
+    return undef unless $journalid && $jitemid;
+
+    my $dbh = LJ::get_db_writer();
+    my $res = $dbh->do("DELETE FROM vertical_posts WHERE vert_id = ? AND journalid = ? AND jitemid = ?", undef, $self->vert_id, $journalid, $jitemid);
+    return $res;
+}
+
+sub add_post {
+    my $self = shift;
+    my $url  = shift;
+
+    my $entry = LJ::Entry->new_from_url ($url);
+
+    return undef unless $entry;
+
+    my $dbh = LJ::get_db_writer();
+    my $res = $dbh->do("INSERT INTO vertical_posts (vert_id, journalid, jitemid, timecreate, timeadded) VALUES
+        (?, ?, ?, ?, UNIX_TIMESTAMP())", undef, $self->vert_id, $entry->journalid, $entry->jitemid, $entry->logtime_unix);
+
+    return $res;
+
+}
+
 sub add_entry {
     my $self = shift;
     my @entries = @_;
@@ -1251,7 +1318,8 @@
 sub display_name {
     my $self = shift;
 
-    return $LJ::VERTICAL_TREE{$self->name}->{display_name};
+    return $self->name;
+    #return $LJ::VERTICAL_TREE{$self->name}->{display_name};
 }
 
 sub url {
@@ -1390,16 +1458,22 @@
     return $self->{$key};
 }
 
-sub vert_id         { shift->_get_set('vert_id')                }
-sub name            { shift->_get_set('name')                   }
-sub set_name        { shift->_get_set('name' => $_[0])          }
-sub uri             { shift->_get_set('url')                    }
-sub set_uri         { shift->_get_set('url' => $_[0])           }
-sub journal         { shift->_get_set('journal')                }
-sub set_journal     { shift->_get_set('journal' => $_[0])       }
-sub createtime      { shift->_get_set('createtime')             }
-sub set_createtime  { shift->_get_set('createtime' => $_[0])    }
-sub lastfetch       { shift->_get_set('lastfetch')              }
-sub set_lastfetch   { shift->_get_set('lastfetch' => $_[0])     }
+sub vert_id          { shift->_get_set('vert_id')                }
+sub name             { shift->_get_set('name')                   }
+sub set_name         { shift->_get_set('name' => $_[0])          }
+sub uri              { shift->_get_set('url')                    }
+sub set_uri          { shift->_get_set('url' => $_[0])           }
+sub journal          { shift->_get_set('journal')                }
+sub set_journal      { shift->_get_set('journal' => $_[0])       }
+sub createtime       { shift->_get_set('createtime')             }
+sub set_createtime   { shift->_get_set('createtime' => $_[0])    }
+sub lastfetch        { shift->_get_set('lastfetch')              }
+sub set_lastfetch    { shift->_get_set('lastfetch' => $_[0])     }
+sub show_entries     { shift->_get_set('show_entries')           }
+sub set_show_entries { shift->_get_set('show_entries' => $_[0])  }
+sub not_deleted      { shift->_get_set('not_deleted')            }
+sub set_not_deleted  { shift->_get_set('not_deleted' => $_[0])   }
+sub remove_after     { shift->_get_set('remove_after')           }
+sub set_remove_after { shift->_get_set('remove_after' => $_[0])  }
 
 1;

Modified: trunk/cgi-bin/LJ/VerticalEditorials.pm
===================================================================
--- trunk/cgi-bin/LJ/VerticalEditorials.pm	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/cgi-bin/LJ/VerticalEditorials.pm	2010-11-01 06:13:08 UTC (rev 17622)
@@ -79,7 +79,7 @@
     my $sth = $dbh->prepare(
         "SELECT * FROM vertical_editorials WHERE time_start <= UNIX_TIMESTAMP() AND time_end >= UNIX_TIMESTAMP() AND vertid = ?"
     );
-    $sth->execute($vertical->vertid);
+    $sth->execute($vertical->vert_id);
 
     my @rows = ();
     while (my $row = $sth->fetchrow_hashref) {
@@ -207,7 +207,7 @@
         "(time_start <= ? AND time_end >= ?))"
     );
     $sth->execute(
-        $vertical->vertid, $time_start_epoch, $time_start_epoch, $time_end_epoch, $time_end_epoch,
+        $vertical->vert_id, $time_start_epoch, $time_start_epoch, $time_end_epoch, $time_end_epoch,
         $time_start_epoch, $time_end_epoch, $time_start_epoch, $time_end_epoch
     )
         or die "Error getting this month's editorials: " . $dbh->errstr;

Modified: trunk/cgi-bin/LJ/Widget/AddVerticalEditorials.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/AddVerticalEditorials.pm	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/cgi-bin/LJ/Widget/AddVerticalEditorials.pm	2010-11-01 06:13:08 UTC (rev 17622)
@@ -91,7 +91,7 @@
         name => 'vertid',
         id => 'vertid',
         selected => $vertid || 0,
-        list => [ "0", "(Choose one)", map { $_->vertid, $_->display_name } LJ::Vertical->load_for_editorials ],
+        list => [ "0", "(Choose one)", map { $_->vert_id, $_->display_name } LJ::Vertical->load_for_editorials ],
     ) . "</td></tr>";
 
     $ret .= "<tr><td>Start Date:</td><td>";

Modified: trunk/cgi-bin/LJ/Widget/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Browse.pm	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/cgi-bin/LJ/Widget/Browse.pm	2010-11-01 06:13:08 UTC (rev 17622)
@@ -86,7 +86,7 @@
 
     return $class->render_body_old(%opts) unless exists $opts{browse};
 
-    my ($title, $windowtitle, $remote, $uri, $page, $post_page) = @opts{qw(title windowtitle remote uri page post_page)};
+    my ($title, $windowtitle, $remote, $uri, $page, $post_page, $view) = @opts{qw(title windowtitle remote uri page post_page view)};
 
     my $template = LJ::HTML::Template->new(
         { use_expr => 1 }, # force HTML::Template::Pro with Expr support
@@ -170,14 +170,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();
             }
-        }
+        #}
         $ad = LJ::get_ads({ location => 'bml.explore/vertical', vertical => $cat->display_name, ljadwrapper => 1 });
     } else {
         @comms = _get_spotlight_communities();  # Show spotlight communities by default
@@ -288,6 +288,20 @@
     # merge args to uri.
     $uri .= '?' . $args if $args;
 
+    ## Prepare DATA for Featured Posts Widget
+    my $posts = $vertical->load_vertical_posts( count => $vertical->show_entries, is_random => 1 );
+    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,
+        };
+    }
+
     $template->param(
         communities             => \@tmpl_communities,
         posts                   => \@tmpl_posts,
@@ -311,6 +325,8 @@
         popular_interests_widget=> LJ::Widget::PopularInterests->render(),
         add_community_widget    => LJ::Widget::AddCommunity->render(),
         search_widget           => LJ::Widget::Search->render(type => 'yandex'),
+        top_posts               => \@top_posts,
+        view                    => $view,
     );
 
     return $template->output;

Modified: trunk/cgi-bin/LJ/Widget/VerticalContentControl.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/VerticalContentControl.pm	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/cgi-bin/LJ/Widget/VerticalContentControl.pm	2010-11-01 06:13:08 UTC (rev 17622)
@@ -32,13 +32,13 @@
         if (@verticals > 1) {
             $ret .= $class->html_select(
                 name => 'verticals',
-                list => [ map { $_->vertid, $_->display_name } @verticals ],
+                list => [ map { $_->vert_id, $_->display_name } @verticals ],
                 multiple => 'multiple',
                 size => 5,
             );
         } else {
             $ret .= "<strong>" . $verticals[0]->display_name . "</strong>";
-            $ret .= $class->html_hidden( verticals => $verticals[0]->vertid );
+            $ret .= $class->html_hidden( verticals => $verticals[0]->vert_id );
         }
         $ret .= "</td></tr>";
 
@@ -147,7 +147,7 @@
         $ret .= "<form method='GET'>";
         $ret .= "Define rules for vertical: ";
         if (@verticals > 1) {
-            $ret .= LJ::html_select({ name => 'vertical_name' }, map { $_->name, $_->display_name } @verticals);
+            $ret .= LJ::html_select({ name => 'vertical_name' }, map { { text => $_->name, value => $_->display_name } } @verticals);
         } else {
             $ret .= "<strong>" . $verticals[0]->display_name . "</strong>";
             $ret .= LJ::html_hidden( vertical_name => $verticals[0]->name );
@@ -231,8 +231,8 @@
 
         my @verticals = split('\0', $post->{verticals});
         my @vert_names;
-        foreach my $vertid (@verticals) {
-            my $v = LJ::Vertical->load_by_id($vertid);
+        foreach my $vert_id (@verticals) {
+            my $v = LJ::Vertical->load_by_id($vert_id);
             die "You cannot perform this action." if $action eq "add" && !$v->remote_is_moderator;
             die "You cannot perform this action." if $action eq "remove" && !$v->remote_can_remove_entry($entry);
 

Modified: trunk/htdocs/admin/browse/add_community.bml
===================================================================
--- trunk/htdocs/admin/browse/add_community.bml	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/htdocs/admin/browse/add_community.bml	2010-11-01 06:13:08 UTC (rev 17622)
@@ -70,7 +70,7 @@
     # Get the full list of categories
     my @categories = LJ::Browse->load_all;
     # Don't include the top level categories and get the unique URI for each
-    my @caturls = map { $_->uri, $_->uri } grep { $_->parent } @categories;
+    my @caturls = map { { text => $_->{pretty_name}, value => $_->uri } } @categories;
     @caturls = sort { $a cmp $b } @caturls;
 
     $ret .= "<p>Add to Category:<br />";

Modified: trunk/htdocs/admin/browse/index.bml
===================================================================
--- trunk/htdocs/admin/browse/index.bml	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/htdocs/admin/browse/index.bml	2010-11-01 06:13:08 UTC (rev 17622)
@@ -23,6 +23,7 @@
     $ret .= "<p><a href='./remove_verticals.bml'>Remove Verticals</a></p>";
     $ret .= "<p><a href='./upload_verticals.bml'>Upload Verticals</a></p>";
     $ret .= "<p><a href='./recent_posts.bml'>Manage Recent Posts</a></p>";
+    $ret .= "<p><a href='./top_entries_vertical.bml'>Top Entries in communities</a></p>";
     $ret .= "</blockquote>";
 
     $ret .= "<h2>Manage Communities</h2><blockquote>";

Modified: trunk/htdocs/admin/browse/manage_category.bml
===================================================================
--- trunk/htdocs/admin/browse/manage_category.bml	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/htdocs/admin/browse/manage_category.bml	2010-11-01 06:13:08 UTC (rev 17622)
@@ -17,38 +17,67 @@
     $title = "Move Category To Vertical";
     my $ret = "";
 
-    my ($vertid, $caturl) = ();
+    my ($vert_url, $cat_url) = ();
 
+    if (LJ::did_post() and $POST{'show'}) {
+        $cat_url = $POST{'cat_url'};
+
+        {
+            # Check for required data
+            unless ($cat_url) {
+                push @errors, "Please select a category for source";
+                next;
+            }
+
+            my $category = LJ::Browse->load_by_url("/browse" . $cat_url);
+            ## Category till is not in vertical?
+            $category = LJ::Browse->load_by_url("/browse" . "/notset" . $cat_url)
+                unless $category;
+            unless ($category) {
+                push @errors, "Invalid category" unless $category;
+                next;
+            }
+
+            $ret .= "Category '".$category->{pretty_name}."' belongs '".$category->vertical->name."' vertical<br/>";
+            $ret .= "Category contains the following communities:<br/>";
+            foreach my $comm ($category->communities( is_need_child => 1 )) {
+                $ret .= $comm->ljuser_display() . "<br/>";
+            }
+        }
+
+    }
+
     if (LJ::did_post() and $POST{'move'}) {
-        $caturl = $POST{'caturl'};
-        $vertid = $POST{'vertid'};
+        $cat_url = $POST{'cat_url'};
+        $vert_url = $POST{'vert_url'};
 
         push @errors, "Invalid form submission" unless LJ::check_form_auth();
         {
             # Check for required data
-            unless ($caturl) {
+            unless ($cat_url) {
                 push @errors, "Please select a category for source";
                 next;
             }
-            unless ($vertid) {
+            unless ($vert_url) {
                 push @errors, "Please select a vertical for destination";
                 next;
             }
 
+            # Has a valid vertical been chosen
+            my $vertical = LJ::Vertical->load_by_url("/browse" . $vert_url);
+            push @errors, "Invalid vertical" unless $vertical;
+
             # Has a valid category been chosen
-            my $category = LJ::Browse->load_by_url("/browse" . $caturl);
+            my $category = LJ::Browse->load_by_url("/browse" . $vert_url . $cat_url);
             push @errors, "Invalid category" unless $category;
 
-            # Has a valid vertical been chosen
-            my $vertical = LJ::Vertical->load_by_id($vertid);
-            push @errors, "Invalid vertical" unless $vertical;
-
             next if @errors;
 
             # Move category
             my $dbh = LJ::get_db_writer();
-            my $res = $dbh->do("UPDATE category SET vert_id = ? WHERE catid = ?", undef, $vertical->vert_id, $category->catid);
-            if ($res) {
+            my $res     = $dbh->do("UPDATE category SET vert_id = ? WHERE catid = ?", undef, $vertical->vert_id, $category->catid);
+            my $res_sub = $dbh->do("UPDATE category SET vert_id = ? WHERE parentcatid = ?", undef, $vertical->vert_id, $category->catid);
+            if ($res && $res_sub) {
                 $ret .= "<span class='super notice'>Category moved.</span>";
             } else {
                 $ret .= "<span class='super notice'>Category not moved.</span>";
@@ -64,16 +93,17 @@
     # Get the full list of categories
     my @categories = LJ::Browse->load_all;
     # Get the unique URI for each
-    my @caturls = map { { text => $_->{pretty_name}, value => $_->uri } } grep { $_->{parentcatid} } @categories;
+    my @caturls = map { { text => $_->{pretty_name}, value => $_->uri } } grep { !$_->{parentcatid} } @categories;
     #@caturls = sort { $a cmp $b } @caturls;
 
     my @verticals = LJ::Vertical->load_all();
-    @verticals = map { { text => $_->{name}, value => $_->{vert_id} } } @verticals;
+    @verticals = map { { text => $_->{name}, value => $_->{url} } } @verticals;
 
     $ret .= "<table border='0'>";
     $ret .= "<tr><td>Category</td><td>=></td><td>Vertical</td>";
     $ret .= "<tr><td>".LJ::html_select({
-                name => 'caturl',
+                name => 'cat_url',
+                selected => $cat_url,
                 },
                 { text => 'Select Top Category',
                 value => '',},
@@ -82,7 +112,8 @@
     $ret .= "</td>\n";
     $ret .= "<td>&nbsp;</td>";
     $ret .= "<td>".LJ::html_select({
-                name => 'vertid',
+                name => 'vert_url',
+                selected => $vert_url,
                 },
                 { text => 'Select Vertical',
                 value => '',},
@@ -93,6 +124,7 @@
     $ret .= "</table></p>\n";
 
     $ret .= "<p>" . LJ::html_submit('move', 'Move') . "</p>";
+    $ret .= "<p>" . LJ::html_submit('show', 'Show Info') . "</p>";
 
     $ret .= "</form>";
 

Modified: trunk/htdocs/admin/browse/recent_posts.bml
===================================================================
--- trunk/htdocs/admin/browse/recent_posts.bml	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/htdocs/admin/browse/recent_posts.bml	2010-11-01 06:13:08 UTC (rev 17622)
@@ -43,7 +43,6 @@
     $ret .= "</form>";
 
     if (LJ::did_post()) {
-use Data::Dumper;
         my $vertical = LJ::Vertical->load_by_id($POST{'vert_id'});
         my $cats = $vertical->get_categories;
         $ret .= "<b><div>Recent Posts</div></p>";
@@ -54,9 +53,9 @@
             push @communities, @{$c->{communities}}
                 if $c->{communities};
         };
-warn Dumper \@communities;
+
         my @posts = LJ::Browse->recent_posts(\@communities, 5);
-warn Dumper \@posts;
+
         foreach (@posts) {
             my $url = $_->url;
             my $subject = $_->subject_text;

Added: trunk/htdocs/admin/browse/top_entries_vertical.bml
===================================================================
--- trunk/htdocs/admin/browse/top_entries_vertical.bml	                        (rev 0)
+++ trunk/htdocs/admin/browse/top_entries_vertical.bml	2010-11-01 06:13:08 UTC (rev 17622)
@@ -0,0 +1,131 @@
+<?page
+body<=
+<?_code
+{
+    use strict;
+    use vars qw(%GET %POST $title $headextra @errors @warnings);
+    use Class::Autouse qw( LJ::Browse );
+
+    my $remote = LJ::get_remote();
+
+    return "<?needlogin?>"
+        unless $remote;
+
+    return "You are not allowed to view this page"
+        unless LJ::check_priv($remote, 'siteadmin', 'community_directory') || $LJ::IS_DEV_SERVER;
+
+    $title = "Top Entries in communities";
+    my $ret = "";
+
+    my $vert_id = $POST{'vert_id'};
+    my $journals = $POST{'journals'};
+
+    $ret .= "<form method='POST'>\n";
+    $ret .= LJ::form_auth();
+
+    # Get the full list of categories
+    my @verticals = LJ::Vertical->load_all;
+    # Don't include the top level categories and get the unique URI for each
+
+    my @vert_ids = map { { value => $_->vert_id, text => $_->name } } @verticals;
+    @vert_ids = sort { $a cmp $b } @vert_ids;
+
+    $ret .= "<p>Select vertical:";
+    $ret .= LJ::html_select({
+                name => 'vert_id',
+                selected => $vert_id },
+                { text => 'Select Category',
+                value => '' },
+                @vert_ids
+            );
+    $ret .= "&nbsp;" . LJ::html_submit('go', 'Go') . "</p>";
+
+    $ret .= "</form>";
+
+    my $vertical = undef;
+    if ($vert_id) {
+        $vertical = LJ::Vertical->load_by_id($vert_id);
+    }
+
+    if (LJ::did_post() && $POST{'store'}) {
+        $vertical->set_show_entries ($POST{'show_entries'});
+        $vertical->set_not_deleted ($POST{'not_deleted'});
+        $vertical->set_remove_after ($POST{'remove_after'});
+    }
+
+    if ($vert_id) {
+        my ($show_entries, $not_deleted, $remove_after) = ();
+        if ($vertical) {
+            $show_entries = $vertical->show_entries;
+            $not_deleted  = $vertical->not_deleted;
+            $remove_after = $vertical->remove_after;
+        }
+        $ret .= <<ADDPOST;
+<form method="post">
+<input type="hidden" name="vert_id" value="$vert_id">
+<table>
+    <caption>Enter URL for adding featured post:</caption>
+    <tr>
+        <td>URL:</td><td colspan="2"><input type="text" size="50" name="url"></td>
+        <td colspan="2"><input type="submit" name="add" value="Add"></td>
+    </tr>
+</table>
+</form>
+<br/>
+<br/>
+<form method="post">
+<input type="hidden" name="vert_id" value="$vert_id">
+<table>
+    <tr>
+        <td>Number of shown entries: <input type="text" size="3" name="show_entries" value="$show_entries"></td>
+    </tr>
+    <tr>
+        <td>Number of entries, that can not be deleted: <input type="text" size="3" name="not_deleted" value="$not_deleted"> <input type="submit" name="store" value="Store"></td>
+    </tr>
+    <tr>
+        <td>Remove post from widget after: <input type="text" size="3" name="remove_after" value="$remove_after"></td>
+    </tr>
+</table>
+</form><br/><br/>
+ADDPOST
+
+    }
+
+    if (LJ::did_post() && $POST{'add'}) {
+        $vertical->add_post ($POST{'url'});
+    }
+
+    if (LJ::did_post() && $POST{'delete_post'}) {
+        $vertical->delete_post (post_id => $POST{'rec_id'});
+    }
+
+    if (LJ::did_post()) {
+        $ret .= "<b><div>Added Posts</div></p>";
+        my $posts = $vertical->load_vertical_posts( count => '100', is_random => 0 );
+
+        foreach (@$posts) {
+            my $entry = LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid});
+            my $url = $entry->url;
+            my $subject = $entry->subject_text;
+            my $jitemid = $entry->jitemid;
+            my $commid = $entry->journalid;
+            $ret .= "<li><a href='".$url."'>".($subject ? $subject : '...')."</a>";
+            $ret .= "<form method='POST'>\n";
+            $ret .= LJ::form_auth();
+            $ret .= "<input type='hidden' name='rec_id' value='$jitemid-$commid'>";
+            $ret .= "<input type='hidden' name='vert_id' value='".$vertical->vert_id."'>";
+            $ret .= "<input type='submit' name='delete_post' value='Remove post'>" if scalar @$posts > $vertical->not_deleted;
+            $ret .= "</form>";
+        }
+    }
+
+
+    return "<body>$ret</body>";
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>

Modified: trunk/htdocs/browse/index.bml
===================================================================
--- trunk/htdocs/browse/index.bml	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/htdocs/browse/index.bml	2010-11-01 06:13:08 UTC (rev 17622)
@@ -20,6 +20,7 @@
 
     my $page = defined $GET{page} ? $GET{page} : 1;
     my $post_page = defined $GET{post_page} ? $GET{post_page} : 1;
+    my $view = defined $GET{'view'} ? $GET{'view'} : 'recent_posts';
 
     my $vertical = LJ::Vertical->load_by_url($uri);
     unless ($vertical) {
@@ -37,6 +38,7 @@
         uri         => $uri,
         page        => $page,
         post_page   => $post_page,
+        view        => $view,
     );
 }
 _code?>

Modified: trunk/templates/Browse/sidebar.tmpl
===================================================================
--- trunk/templates/Browse/sidebar.tmpl	2010-10-29 11:05:00 UTC (rev 17621)
+++ trunk/templates/Browse/sidebar.tmpl	2010-11-01 06:13:08 UTC (rev 17622)
@@ -7,3 +7,5 @@
 <TMPL_IF 0><TMPL_VAR popular_interests_widget></TMPL_IF>
 <TMPL_VAR add_community_widget>
 
+<tmpl_include top_posts.tmpl>
+

Added: trunk/templates/Browse/top_posts.tmpl
===================================================================
--- trunk/templates/Browse/top_posts.tmpl	                        (rev 0)
+++ trunk/templates/Browse/top_posts.tmpl	2010-11-01 06:13:08 UTC (rev 17622)
@@ -0,0 +1,8 @@
+<tmpl_loop top_posts>
+<tmpl_var subject><br/>
+<tmpl_var userpic><br/>
+<tmpl_var updated_ago><br/>
+<tmpl_var comments_count><br/>
+<hr/>
+</tmpl_loop>
+

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