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

[livejournal] r17828: LJSUP-7434. Add widget preview to admin ...

Committer: gprochaev
LJSUP-7434. Add widget preview to admin tool

U   trunk/cgi-bin/LJ/Browse.pm
U   trunk/cgi-bin/LJ/Vertical.pm
U   trunk/htdocs/admin/browse/featured_communities.bml
U   trunk/htdocs/admin/browse/top_entries_vertical.bml
Modified: trunk/cgi-bin/LJ/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Browse.pm	2010-11-30 08:57:15 UTC (rev 17827)
+++ trunk/cgi-bin/LJ/Browse.pm	2010-11-30 09:18:54 UTC (rev 17828)
@@ -866,6 +866,31 @@
     return 1;
 }
 
+sub count_posts {
+    my $class  = shift;
+    my %args   = @_;
+
+    my $comms    = $args{'comms'};
+    my $limit    = $args{'page_size'};
+    my $search   = $args{'search_str'};
+    my $vertical = $args{'vertical'};
+
+    my $comm_list = join ",", @$comms;
+    my $dbh = LJ::get_db_reader();
+    if ($comm_list) {
+        my $count = $dbh->selectrow_arrayref (
+            "SELECT count(journalid) FROM category_recent_posts 
+                WHERE journalid IN ($comm_list) 
+                    AND is_deleted = 0 
+                ORDER BY timecreate DESC",
+            { Slice => {} }
+        );
+        return $count->[0];
+    }
+
+    return 0;
+}
+
 sub search_posts {
     my $class  = shift;
     my %args   = @_;
@@ -904,15 +929,17 @@
             grep { $_->{journalid} }                                                ## remove SEO posts
             @found_posts;
     } else {
-        my $post_ids = $dbh->selectall_arrayref (
-            "SELECT * FROM category_recent_posts 
-                WHERE journalid IN ($comm_list) 
-                    AND is_deleted = 0 
-                ORDER BY timecreate DESC 
-                LIMIT $limit", 
-            { Slice => {} }
-        );
-        @entries = map { LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid}) } @$post_ids;
+        if ($comm_list) {
+            my $post_ids = $dbh->selectall_arrayref (
+                "SELECT * FROM category_recent_posts 
+                    WHERE journalid IN ($comm_list) 
+                        AND is_deleted = 0 
+                    ORDER BY timecreate DESC 
+                    LIMIT $limit", 
+                { Slice => {} }
+            );
+            @entries = map { LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid}) } @$post_ids;
+        }
     }
     return @entries;
 }

Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2010-11-30 08:57:15 UTC (rev 17827)
+++ trunk/cgi-bin/LJ/Vertical.pm	2010-11-30 09:18:54 UTC (rev 17828)
@@ -682,7 +682,7 @@
             "SELECT m.kw_id 
                 FROM vertical_keymap m, vertical_keywords w 
                 WHERE m.kw_id = w.kw_id 
-                    AND w.keywords = ? 
+                    AND w.keyword = ? 
                     AND m.vert_id = ?", 
             undef, $tag, $self->vert_id
         ) || [];
@@ -736,15 +736,19 @@
     );
     return [] unless $comms;
     my $max_num = scalar @$comms;
-    my $count   = $args{'count'};
-    if ($count > $max_num) {
-        $count = $max_num;
-        $is_random = 0;
-    }
+    my $count   = $args{'count'} || $max_num;
+    $count = $max_num if $count > $max_num;
     my @result = ();
-    while ($count--) {
-        my $comm = $is_random ? $comms->[int(rand($max_num))] : $comms->[$count];
-        push @result, $comm if $comm;
+    my %used = ();
+    my $i = 0;
+    while (scalar @result < $count) {
+        my $comm_id = $is_random ? int(rand($max_num)) : $i++;
+        next if $used{$comm_id};
+        my $comm = $comms->[$comm_id];
+        if ($comm) {
+            $used{$comm_id} = 1;
+            push @result, $comm;
+        }
     }
 
     return \@result;
@@ -761,15 +765,28 @@
     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 $posts = $dbh->selectall_arrayref(
+        "SELECT * 
+            FROM vertical_posts 
+            WHERE vert_id = ? 
+            ORDER BY timeadded DESC", 
+        { Slice => {} }, $self->vert_id
+    );
     return [] unless $posts;
     my $max_num = scalar @$posts;
-    my $count   = $args{'count'};
+    my $count   = $args{'count'} || $max_num;
     $count = $max_num if $count > $max_num;
     my @result = ();
-    while ($count--) {
-        my $post = $posts->[int(rand($max_num))];
-        push @result, $post if $post;
+    my %used = ();
+    my $i = 0;
+    while (scalar @result < $count) {
+        my $post_id = $is_random ? int(rand($max_num)) : $i++;
+        next if $used{$post_id};
+        my $post = $posts->[$post_id];
+        if ($post) {
+            $used{$post_id} = 1;
+            push @result, $post;
+        }
     }
 
     return \@result;
@@ -1247,7 +1264,7 @@
 
     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);
+        (?, ?, ?, ?, UNIX_TIMESTAMP(NOW()))", undef, $self->vert_id, $entry->journalid, $entry->jitemid, $entry->logtime_unix);
 
     return $res;
 

Modified: trunk/htdocs/admin/browse/featured_communities.bml
===================================================================
--- trunk/htdocs/admin/browse/featured_communities.bml	2010-11-30 08:57:15 UTC (rev 17827)
+++ trunk/htdocs/admin/browse/featured_communities.bml	2010-11-30 09:18:54 UTC (rev 17828)
@@ -6,6 +6,8 @@
     use vars qw(%GET %POST $title $headextra @errors @warnings);
     use Class::Autouse qw( LJ::Browse );
 
+    LJ::need_res ( qw( stc/widgets/widgets-layout.css stc/widgets/search.css stc/widgets/add-community.css stc/widgets/featuredposts.css stc/widgets/featuredcomms.css ) );
+
     my $remote = LJ::get_remote();
 
     return "<?needlogin?>"
@@ -28,7 +30,7 @@
     # 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;
+    @vert_ids = sort { $a->{'text'} cmp $b->{'text'} } @vert_ids;
 
     $ret .= "<p>";
     $ret .= LJ::html_select({
@@ -73,7 +75,8 @@
         $ret .= "<h2>Added Communities</h2>";
         my $comms = $vertical->load_communities( count => '100', is_random => 0 );
 
-        $ret .= "<ul style='list-style:none;line-height:1.6em;padding:0;'>";
+        $ret .= "<ul style='list-style:none;line-height:1.6em;padding:0;float:left;width:500px;'>";
+        my @top_comms = ();
         foreach (@$comms) {
             my $comm = LJ::load_userid($_->{journalid});
             my $url = $comm->journal_base;
@@ -85,7 +88,32 @@
             $ret .= "<input type='submit' name='delete_comm' value='Remove post' style='font-size:.8em;text-transform:lowercase;'>";
             $ret .= "</form>";
         }
+        my $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;
+            my $descr = $c->prop('comm_theme') || '';
+            my $descr_trimmed = LJ::html_trim($descr, 50);
+            push @top_comms, {
+                username        => $c->display_name,
+                userpic         => $userpic ? $userpic->url : '',
+                community       => $c->user,
+                bio             => $descr_trimmed,
+                is_subtitle_trimmed => $descr ne $descr_trimmed ? 1 : 0,
+            };
+        }
         $ret .= "</ul>";
+        my $template = LJ::HTML::Template->new(
+            { use_expr => 1 }, # force HTML::Template::Pro with Expr support
+            filename => "$ENV{'LJHOME'}/templates/Browse/featured_communities.tmpl",
+            die_on_bad_params => 0,
+            strict => 0,
+        ) or die "Can't open template: $!";
+        $template->param(
+            top_comms => \@top_comms,
+        );
+        $ret .= "<div style=\"padding:0 0 0 500px\">".$template->output."</div>";
     }
     $ret .= "<p><a href='/admin/browse/'>Back to main page</a></p>";
 

Modified: trunk/htdocs/admin/browse/top_entries_vertical.bml
===================================================================
--- trunk/htdocs/admin/browse/top_entries_vertical.bml	2010-11-30 08:57:15 UTC (rev 17827)
+++ trunk/htdocs/admin/browse/top_entries_vertical.bml	2010-11-30 09:18:54 UTC (rev 17828)
@@ -6,6 +6,8 @@
     use vars qw(%GET %POST $title $headextra @errors @warnings);
     use Class::Autouse qw( LJ::Browse );
 
+    LJ::need_res ( qw( stc/widgets/widgets-layout.css stc/widgets/search.css stc/widgets/add-community.css stc/widgets/featuredposts.css stc/widgets/featuredcomms.css ) );
+
     my $remote = LJ::get_remote();
 
     return "<?needlogin?>"
@@ -28,7 +30,7 @@
     # 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;
+    @vert_ids = sort { $a->{'text'} cmp $b->{'text'} } @vert_ids;
 
     $ret .= "<p>";
     $ret .= LJ::html_select({
@@ -60,6 +62,7 @@
             $not_deleted  = $vertical->not_deleted;
             $remove_after = $vertical->remove_after;
         }
+
         $ret .= <<ADDPOST;
 <form method="post">
 <input type="hidden" name="vert_id" value="$vert_id">
@@ -103,9 +106,10 @@
 
     if (LJ::did_post() && $vertical) {
         $ret .= "<h2>Added Posts</h2>";
-        my $posts = $vertical->load_vertical_posts( count => '100', is_random => 0 );
+        my $posts = $vertical->load_vertical_posts( count => 100, is_random => 0 );
 
-        $ret .= "<ul style='list-style:none;line-height:1.6em;padding:0;'>";
+        $ret .= "<ul style='list-style:none;line-height:1.6em;padding:0;float:left;width:500px'>";
+        my @top_posts = ();
         foreach (@$posts) {
             my $entry = LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid});
             my $url = $entry->url;
@@ -120,7 +124,32 @@
             $ret .= "<input type='submit' name='delete_post' value='Remove post' style='font-size:.8em;text-transform:lowercase;'>" if scalar @$posts > $vertical->not_deleted;
             $ret .= "</form>";
         }
+        my $posts = $vertical->load_vertical_posts( count => $vertical->show_entries, is_random => 1 );
+        foreach (@$posts) {
+            my $entry = LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid});
+            my $userpic = $entry->userpic;
+            my $poster = $entry->poster;
+            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          => $poster ? LJ::ljuser($poster) : '?',
+                url_to_post     => $entry->url,
+            };
+        }
         $ret .= "</ul>";
+        my $template = LJ::HTML::Template->new(
+            { use_expr => 1 }, # force HTML::Template::Pro with Expr support
+            filename => "$ENV{'LJHOME'}/templates/Browse/top_posts.tmpl",
+            die_on_bad_params => 0,
+            strict => 0,
+        ) or die "Can't open template: $!";
+        $template->param(
+            top_posts => \@top_posts,
+        );
+        $ret .= "<div style=\"padding:0 0 0 500px\">".$template->output."</div>";
+
     }
     $ret .= "<p><a href='/admin/browse/'>Back to main page</a></p>";
 

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