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

[livejournal] r17865: LJSUP-7509. Add "Edit communities" to ad...

Committer: gprochaev
LJSUP-7509. Add "Edit communities" to admin tool

U   trunk/cgi-bin/LJ/Vertical.pm
A   trunk/htdocs/admin/browse/edit_community.bml
A   trunk/htdocs/admin/browse/edit_community.bml.text
U   trunk/htdocs/admin/browse/index.bml
U   trunk/htdocs/admin/browse/recent_posts.bml
U   trunk/htdocs/admin/browse/top_entries_vertical.bml
Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2010-12-06 09:20:01 UTC (rev 17864)
+++ trunk/cgi-bin/LJ/Vertical.pm	2010-12-06 10:54:43 UTC (rev 17865)
@@ -682,6 +682,56 @@
     return $kw_id;
 }
 
+## Remove tags links from vertical_keymap table.
+## Not delete tags from vertical_keywords.
+sub delete_tags_links {
+    my $class = shift;
+    my %args = @_;
+
+    my $comm_id = $args{'comm_id'} || $args{'journalid'};
+    return undef unless $comm_id;
+
+    my $vert_id = $args{'vert_id'} || 0;
+    my $jitemid = $args{'jitemid'} || 0;
+
+    my $v_sql = " AND vert_id = $vert_id ";
+    my $entry_sql = " AND jitemid = $jitemid ";
+
+    my $dbh = LJ::get_db_writer ();
+    my $res = $dbh->do ("
+        DELETE FROM vertical_keymap 
+            WHERE 
+                journalid = ?
+                $v_sql
+                $entry_sql
+    ", undef, $comm_id);
+
+    return 1;
+}
+
+sub get_tags_for_journal {
+    my $class = shift;
+    my %args  = @_;
+
+    my $comm_id = $args{'comm_id'} || $args{'journalid'};
+    return '' unless $comm_id;
+
+    my $vert_id = $args{'vert_id'} || 0;
+    my $jitemid = $args{'jitemid'} || 0;
+
+    my $dbh = LJ::get_db_reader ();
+    my $res = $dbh->selectall_arrayref ("
+        SELECT keyword 
+            FROM vertical_keymap km, vertical_keywords kw
+            WHERE km.kw_id = kw.kw_id
+                AND km.journalid = ?
+                AND km.vert_id = ?
+                AND km.jitemid = ?
+    ", { Slice => {} }, $comm_id, $vert_id, $jitemid);
+
+    return join ", ", map { $_->{keyword} } @$res;
+}
+
 sub save_tags {
     my $self = shift;
     my %args = @_;

Added: trunk/htdocs/admin/browse/edit_community.bml
===================================================================
--- trunk/htdocs/admin/browse/edit_community.bml	                        (rev 0)
+++ trunk/htdocs/admin/browse/edit_community.bml	2010-12-06 10:54:43 UTC (rev 17865)
@@ -0,0 +1,162 @@
+<?page
+title=><?_ml .title _ml?>
+body<=
+<?_code
+{
+    use strict;
+    use vars qw(%GET %POST);
+    use Class::Autouse qw( LJ::Browse );
+
+    return "This page is not available." unless LJ::is_enabled("browse");
+
+    my $ret;
+
+sub get_parent_path {
+    my $cat_path = shift;
+    my $c = shift;
+
+    return undef unless $c;
+
+    my $parent = $c->parent;
+
+    push @$cat_path, $c;
+
+    return 0 unless $parent;
+
+    return get_parent_path ($cat_path, $c->parent);
+}
+
+sub _build_tree {
+    my ($parent, $cats_ref, $selected_cat, $text, $i, $n) = @_;
+
+    $i ||= 0;
+
+    return $text unless $cats_ref;
+
+    my @categories = @$cats_ref;
+    @categories = grep { ($_->parent == $parent) } grep { $_ } @categories;
+
+    return $text unless scalar @categories;
+
+    my @path_ = ();
+    get_parent_path (\@path_, $selected_cat);
+    my %path = map { $_->catid => 1 } @path_;
+    my @sel_cat = grep { $path{$_->catid} } @categories;
+
+    my @caturls = map { { text => $_->{pretty_name}, value => $_->catid } } @categories;
+    @caturls = sort { $a->{text} cmp $b->{text} } @caturls;
+
+    $text .= "<tr><td>Category</td>";
+    $text .= "<td>" . LJ::html_select({
+                name => "catid$i\_$n", style => "width:100%;",
+                selected => $sel_cat[0] ? $sel_cat[0]->catid : '' },
+                { text => $ML{'.add'},
+                value => '' },
+                @caturls
+    ) . "</td>";
+    $text .= "<td>" . LJ::html_submit('select_c', 'Select Category') . "</td>";
+    $text .= "</tr>";
+
+    if ($sel_cat[0]) {
+        my @children = $sel_cat[0]->children;
+        $text = _build_tree($sel_cat[0], \@children, $selected_cat, $text, ++$i, $n);
+    }
+
+    return $text;
+}
+
+    # get remote
+    my $remote = LJ::get_remote();
+    unless ($remote) {
+        $ret .= "<?needlogin?>";
+    }
+
+    my @cat_ = ();
+    my @vert_ = ();
+
+    my $limit = 2; # Max number of categories a community can appear in
+    my @catid_;
+    my @catrem;
+
+    my $i = 1;
+    my $j = $i - 1;
+    ## which category the user wants to add a community?
+    my @ids = sort { $b cmp $a } grep { $_ =~ /^catid\d+\_\Q$i\E$/ } keys %POST;
+    my $cat_id = $POST{$ids[0]};
+    push @catid_, $cat_id if $cat_id;
+    push @catrem, $POST{"catremove_$i"} if $POST{"catremove_$i"};
+    push @cat_, $cat_id ? LJ::Browse->load_by_id ($cat_id) : undef;
+    my $vert_id = $POST{"vert_id_$i"} || $GET{"vert_id"};
+    push @vert_, $vert_id ? LJ::Vertical->load_by_id ($vert_id) : undef;
+
+    if (LJ::did_post && $POST{'action:update'}) {
+        # validate form auth
+        return "<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>"
+            unless LJ::check_form_auth();
+
+        my @new_tags = grep { $_ =~ /^tags_\d+/ } keys %POST;
+        foreach my $tag (@new_tags) {
+            my ($cid) = $tag =~ /^tags_(\d+)/;
+            my @tags = split /,\s*/, $POST{$tag};
+            LJ::Vertical->delete_tags_links (comm_id => $cid, vert_id => $vert_[$j] ? $vert_[$j]->vert_id : 0);
+            $cat_[$j]->add_community ($cid, { tags => \@tags, not_need_approve => 1 });
+        }
+
+    }
+
+    $ret .= "<form method='post' method='post'>";
+    $ret .= LJ::form_auth();
+
+    $ret .= "<table>";
+    my @verticals = LJ::Vertical->load_all();
+    if (!$LJ::DISABLED{'verticals_menu'}) {
+        $ret .= "<tr><td valign='top'><!-- $i.-->Vertical</td>";
+        @verticals = map { { text => $_->{name}, value => $_->{vert_id} } } @verticals;
+
+        $ret .= "<td>".LJ::html_select({
+                    name => "vert_id_$i", style => "",
+                    selected => $vert_[$j] ? $vert_[$j]->vert_id : 0,
+                    },
+                    { text => 'Select Vertical',
+                    value => '',},
+                    @verticals
+                );
+        $ret .= "</td><td>\n";
+
+        $ret .= LJ::html_submit('select_v', 'Select Vertical') . "</td></tr>";
+    }
+
+    if ((LJ::did_post() && $vert_[$j]) || ($LJ::DISABLED{'verticals_menu'})) {
+        my @children = $cat_[$j] ? $cat_[$j]->children : ();
+        # Get the full list of categories
+        my @categories = LJ::Browse->load_all($vert_[$j]);
+
+        $ret .= _build_tree (0, \@categories, $cat_[$j], undef, undef, $i);
+        if ($cat_[$j]) {
+            $ret .= "<tr><td valign='top'>Communities from category:</td><tr><td colspan='3'>";
+            if ($cat_[$j]->communities) {
+                $ret .= "<table width='100%'>";
+                foreach my $comm ($cat_[$j]->communities) {
+                    $ret .= "<tr><td>".LJ::ljuser($comm->user) . "</td><td><input type='text' size='60' name='tags_".$comm->userid."' value='".LJ::Vertical->get_tags_for_journal (vert_id => $vert_[$j] ? $vert_[$j]->vert_id : 0, comm_id => $comm->userid)."'></td></tr>";
+                }
+                $ret .= "</table>";
+            }
+            $ret .= "</td></tr>";
+        }
+    }
+    $ret .= "</table>\n";
+    $ret .= "</p>\n";
+
+    $ret .= "<p>" . LJ::html_submit('action:update', $ML{'.update'}) . "</p>\n"
+        if $cat_[$j];
+    $ret .= "</div></form>\n\n";
+
+    $ret .= "<p><a href='/admin/browse/'>Back to main page</a></p>";
+
+    return $ret;
+
+}
+_code?>
+
+<=body
+page?>

Added: trunk/htdocs/admin/browse/edit_community.bml.text
===================================================================
--- trunk/htdocs/admin/browse/edit_community.bml.text	                        (rev 0)
+++ trunk/htdocs/admin/browse/edit_community.bml.text	2010-12-06 10:54:43 UTC (rev 17865)
@@ -0,0 +1,4 @@
+.title=Edit Community
+.add=Select Category
+.update=Update tags list
+

Modified: trunk/htdocs/admin/browse/index.bml
===================================================================
--- trunk/htdocs/admin/browse/index.bml	2010-12-06 09:20:01 UTC (rev 17864)
+++ trunk/htdocs/admin/browse/index.bml	2010-12-06 10:54:43 UTC (rev 17865)
@@ -36,6 +36,7 @@
     $ret .= "<h2>Manage Communities</h2><ul style='list-style:none;line-height:1.6em;padding:0 0 0 20px;'>";
     $ret .= "<li><a href='./moderate_community.bml'>Moderate Community Submissions</a></li>";
     $ret .= "<li><a href='./add_community.bml'>Add Community to Category</a></li>";
+    $ret .= "<li><a href='./edit_community.bml'>Edit Community</a></li>";
     $ret .= "<li><a href='./remove_community.bml'>Remove Community from Category</a></li>";
     $ret .= "</ul>";
 

Modified: trunk/htdocs/admin/browse/recent_posts.bml
===================================================================
--- trunk/htdocs/admin/browse/recent_posts.bml	2010-12-06 09:20:01 UTC (rev 17864)
+++ trunk/htdocs/admin/browse/recent_posts.bml	2010-12-06 10:54:43 UTC (rev 17865)
@@ -73,6 +73,7 @@
 
         $ret .= "<ul style='list-style:none;line-height:1.6em;padding:0;'>";
         foreach (@posts) {
+            next unless $_->valid;
             my $url = $_->url;
             my $subject = $_->subject_text;
             my $jitemid = $_->jitemid;

Modified: trunk/htdocs/admin/browse/top_entries_vertical.bml
===================================================================
--- trunk/htdocs/admin/browse/top_entries_vertical.bml	2010-12-06 09:20:01 UTC (rev 17864)
+++ trunk/htdocs/admin/browse/top_entries_vertical.bml	2010-12-06 10:54:43 UTC (rev 17865)
@@ -113,6 +113,7 @@
         my @top_posts = ();
         foreach (@$posts) {
             my $entry = LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid});
+            next unless $entry->valid;
             my $url = $entry->url;
             my $subject = $entry->subject_text;
             my $jitemid = $entry->jitemid;
@@ -128,6 +129,7 @@
         my $posts = $vertical->load_vertical_posts( count => $vertical->show_entries, is_random => 1 );
         foreach (@$posts) {
             my $entry = LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid});
+            next unless $entry->valid;
             my $userpic = $entry->userpic;
             my $poster = $entry->poster;
             push @top_posts, {

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