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

[livejournal] r17602: LJSUP-7052. Landing Page.

Committer: gprochaev
LJSUP-7052. Landing Page.

A   trunk/bin/worker/category-recent-posts
A   trunk/htdocs/admin/browse/add_verticals.bml
A   trunk/htdocs/admin/browse/manage_category.bml
A   trunk/htdocs/admin/browse/recent_posts.bml
A   trunk/htdocs/admin/browse/remove_verticals.bml
Added: trunk/bin/worker/category-recent-posts
===================================================================
--- trunk/bin/worker/category-recent-posts	                        (rev 0)
+++ trunk/bin/worker/category-recent-posts	2010-10-26 05:28:29 UTC (rev 17602)
@@ -0,0 +1,84 @@
+#!/usr/bin/perl
+use strict;
+use lib "$ENV{LJHOME}/cgi-bin";
+use LJ::NewWorker::Manual;
+LJ::NewWorker::Manual::CategoryRecentPosts->start();
+
+################################################################################
+
+package LJ::NewWorker::Manual::CategoryRecentPosts;
+
+use strict;
+use lib "$ENV{LJHOME}/cgi-bin";
+use base 'LJ::NewWorker::Manual';
+
+# how long to wait if we didn't process any at all
+my $sleep_when_idle;
+
+## how much entries are to fetch from each community
+my $max_count_post_per_comm;
+
+my $verbose;
+
+sub BEGIN {
+    $sleep_when_idle = 10;
+    $verbose = 0;
+    $max_count_post_per_comm = 30;
+}
+
+sub options {
+    my $self = shift;
+    return (
+        $self->SUPER::options(),
+    );
+}
+
+sub help {
+    my $self = shift;
+    return
+        $self->SUPER::help() .
+        "-u | --user login  work on one specific user\n";
+}
+
+sub work {
+    my $class = shift;
+    my @uids;
+
+    my $verbose = $class->verbose();
+
+    my $dbh = LJ::get_db_writer();
+
+    my $journals = $dbh->selectall_arrayref ("SELECT * FROM categoryjournals", { Slice => {} });
+    foreach my $rec (@$journals) {
+        my $journalid = $rec->{journalid};
+        my @last_jitemid = $dbh->selectrow_array ("SELECT max(jitemid) FROM category_recent_posts WHERE journalid = ?", undef, $journalid);
+
+        my $u = LJ::load_userid($journalid);
+        my @recent = LJ::get_recent_items({
+            itemshow    => $max_count_post_per_comm,
+            err         => undef,
+            userid      => $u->{userid},
+            clusterid   => $u->{clusterid},
+            remote      => undef,
+            afterid     => $last_jitemid[0],
+            order       => 'logtime',
+        });
+
+        foreach my $entry (@recent) {
+            my $sth = $dbh->prepare ("INSERT INTO category_recent_posts (jitemid, timecreate, journalid) VALUES (?, ?, ?)");
+            $sth->execute($entry->{itemid}, $entry->{logtime}, $journalid);
+        }
+    }
+
+    return 0;
+}
+
+sub on_idle {
+    return sleep $sleep_when_idle;
+}
+
+sub debug {
+    print STDERR @_, "\n" if $verbose;
+}
+
+1;


Property changes on: trunk/bin/worker/category-recent-posts
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/htdocs/admin/browse/add_verticals.bml
===================================================================
--- trunk/htdocs/admin/browse/add_verticals.bml	                        (rev 0)
+++ trunk/htdocs/admin/browse/add_verticals.bml	2010-10-26 05:28:29 UTC (rev 17602)
@@ -0,0 +1,52 @@
+<?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 = "Add verticals";
+    my $ret = "";
+
+    if (LJ::did_post()) {
+        my $vert_url  = $POST{'vert_url'};
+        my $vert_name = $POST{'vert_name'};
+        if ($vert_url && $vert_name) {
+            my $vert = LJ::Vertical->create (name => $vert_name, url => $vert_url);
+            $ret .= "Vertical $vert_name added" if $vert;
+        } else {
+            $ret .= "<?h1 $ML{'Error'} h1?><?p Not set url or name p?>";
+        } 
+    }
+
+    $ret .= "<form method='POST'>\n";
+    $ret .= LJ::form_auth();
+
+    $ret .= "<table border='0'>";
+    $ret .= "<tr><td>Vertical name</td><td>Vertical Url</td></tr>";
+    $ret .= "<tr><td><input type='text' name='vert_name'></td><td><input type='text' name='vert_url'></td></tr>";
+    $ret .= "</table>";
+
+    $ret .= "&nbsp;" . LJ::html_submit('go', 'Go') . "</p>";
+
+    $ret .= "</form>";
+
+
+    return "<body>$ret</body>";
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>

Added: trunk/htdocs/admin/browse/manage_category.bml
===================================================================
--- trunk/htdocs/admin/browse/manage_category.bml	                        (rev 0)
+++ trunk/htdocs/admin/browse/manage_category.bml	2010-10-26 05:28:29 UTC (rev 17602)
@@ -0,0 +1,107 @@
+<?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', 'category_admin') || $LJ::IS_DEV_SERVER;
+
+    $title = "Move Category To Vertical";
+    my $ret = "";
+
+    my ($vertid, $caturl) = ();
+
+    if (LJ::did_post() and $POST{'move'}) {
+        $caturl = $POST{'caturl'};
+        $vertid = $POST{'vertid'};
+
+        push @errors, "Invalid form submission" unless LJ::check_form_auth();
+        {
+            # Check for required data
+            unless ($caturl) {
+                push @errors, "Please select a category for source";
+                next;
+            }
+            unless ($vertid) {
+                push @errors, "Please select a vertical for destination";
+                next;
+            }
+
+            # Has a valid category been chosen
+            my $category = LJ::Browse->load_by_url("/browse" . $caturl);
+            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) {
+                $ret .= "<span class='super notice'>Category moved.</span>";
+            } else {
+                $ret .= "<span class='super notice'>Category not moved.</span>";
+            }
+        }
+    }
+
+    $headextra = "<style>table td.label { text-align: right; vertical-align: top;}</style>";
+
+    $ret .= "<form method='POST'>\n";
+    $ret .= LJ::form_auth();
+
+    # 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;
+    #@caturls = sort { $a cmp $b } @caturls;
+
+    my @verticals = LJ::Vertical->load_all();
+    @verticals = map { { text => $_->{name}, value => $_->{vert_id} } } @verticals;
+
+    $ret .= "<table border='0'>";
+    $ret .= "<tr><td>Category</td><td>=></td><td>Vertical</td>";
+    $ret .= "<tr><td>".LJ::html_select({
+                name => 'caturl',
+                },
+                { text => 'Select Top Category',
+                value => '',},
+                @caturls
+            );
+    $ret .= "</td>\n";
+    $ret .= "<td>&nbsp;</td>";
+    $ret .= "<td>".LJ::html_select({
+                name => 'vertid',
+                },
+                { text => 'Select Vertical',
+                value => '',},
+                @verticals
+            );
+    $ret .= "</td></tr>\n";
+
+    $ret .= "</table></p>\n";
+
+    $ret .= "<p>" . LJ::html_submit('move', 'Move') . "</p>";
+
+    $ret .= "</form>";
+
+    return "<body>$ret</body>";
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>

Added: trunk/htdocs/admin/browse/recent_posts.bml
===================================================================
--- trunk/htdocs/admin/browse/recent_posts.bml	                        (rev 0)
+++ trunk/htdocs/admin/browse/recent_posts.bml	2010-10-26 05:28:29 UTC (rev 17602)
@@ -0,0 +1,83 @@
+<?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 = "Recent Entries in verticals";
+    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>";
+
+    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>";
+        my @communities = ();
+        foreach my $cat (@$cats) {
+            my $c = LJ::Browse->load_by_id($cat->{catid});
+            $c->load_communities;
+            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;
+            my $jitemid = $_->jitemid;
+            my $commid = $_->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='submit' name='delete_post' value='Remove post'>";
+            $ret .= "</form>";
+        }
+    }
+
+
+    return "<body>$ret</body>";
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>

Added: trunk/htdocs/admin/browse/remove_verticals.bml
===================================================================
--- trunk/htdocs/admin/browse/remove_verticals.bml	                        (rev 0)
+++ trunk/htdocs/admin/browse/remove_verticals.bml	2010-10-26 05:28:29 UTC (rev 17602)
@@ -0,0 +1,56 @@
+<?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 = "Remove verticals";
+    my $ret = "";
+
+    if (LJ::did_post()) {
+        my @keys = keys %POST;
+        foreach (@keys) {
+            next unless $_ =~ /delete_vert_(\d+)/;
+            my $vert = LJ::Vertical->load_by_id ($1);
+            return "Vertical is not empty"
+                if $vert->delete_and_purge();
+        }
+    }
+
+    my @verticals = LJ::Vertical->load_all();
+
+    $ret .= "<form method='POST'>\n";
+    $ret .= LJ::form_auth();
+
+    $ret .= "<table border='1'>";
+    $ret .= "<tr><td>Vertical name</td><td>Vertical Url</td></tr>";
+    foreach my $vert (@verticals) {
+        my $vert_name = $vert->{name};
+        my $vert_url  = $vert->{url};
+        my $vert_id   = $vert->{vert_id};
+        $ret .= "<tr><td>$vert_name</td><td>$vert_url</td><td><input type='submit' name='delete_vert_$vert_id' value='Delete'></tr>";
+    }
+    $ret .= "</table>";
+
+    $ret .= "</form>";
+
+
+    return "<body>$ret</body>";
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>

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