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

[livejournal] r20406: LJSUP-9645: Community directory (stage 2...

Committer: gprochaev
LJSUP-9645: Community directory (stage 2)
U   branches/landing-page-LJSUP-9645/bin/upgrading/proplists.dat
U   branches/landing-page-LJSUP-9645/bin/upgrading/update-db-general.pl
U   branches/landing-page-LJSUP-9645/bin/worker/category-recent-posts
U   branches/landing-page-LJSUP-9645/cgi-bin/LJ/Browse.pm
U   branches/landing-page-LJSUP-9645/cgi-bin/LJ/Vertical.pm
U   branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community.bml
U   branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community.bml.text
A   branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community_more.bml
U   branches/landing-page-LJSUP-9645/htdocs/admin/browse/index.bml
U   branches/landing-page-LJSUP-9645/htdocs/admin/browse/recent_posts.bml
Modified: branches/landing-page-LJSUP-9645/bin/upgrading/proplists.dat
===================================================================
--- branches/landing-page-LJSUP-9645/bin/upgrading/proplists.dat	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/bin/upgrading/proplists.dat	2011-10-21 15:32:52 UTC (rev 20406)
@@ -1711,6 +1711,14 @@
   multihomed: 0
   cldversion: 8
 
+userproplist.number_delta_posts:
+  datatype: char
+  prettyname: Number of shown and delta time for fetching posts
+  des: Number of shown and delta time for fetching posts
+  indexed: 0
+  multihomed: 0
+  cldversion: 8
+
 userproplist.lastloginid:
   datatype: num
   prettyname: Previous login id

Modified: branches/landing-page-LJSUP-9645/bin/upgrading/update-db-general.pl
===================================================================
--- branches/landing-page-LJSUP-9645/bin/upgrading/update-db-general.pl	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/bin/upgrading/update-db-general.pl	2011-10-21 15:32:52 UTC (rev 20406)
@@ -3270,6 +3270,27 @@
 )
 EOC
 
+register_tablecreate("category_keywords", <<'EOC');
+CREATE TABLE `category_keywords` (
+    `keyword` varchar(80) NOT NULL,
+    `kw_id` int(11) NOT NULL auto_increment,
+    PRIMARY KEY  (`kw_id`),
+    UNIQUE KEY `keyword` (`keyword`)
+)
+EOC
+
+register_tablecreate("category_keymap", <<'EOC');
+CREATE TABLE `category_keymap` (
+    `journalid` int(11) NOT NULL,
+    `jitemid` int(11) NOT NULL,
+    `catid` int(11) NOT NULL,
+    `kw_id` int(11) NOT NULL,
+    PRIMARY KEY  (`journalid`,`jitemid`,`catid`,`kw_id`),
+    KEY `kw_id` (`kw_id`),
+    KEY `catid` (`catid`)
+)
+EOC
+
 # Map journals to categories
 register_tablecreate("categoryjournals", <<'EOC');
 CREATE TABLE categoryjournals (
@@ -3377,6 +3398,7 @@
 CREATE TABLE category_recent_posts (
   jitemid int(11) NOT NULL default '0',
   timecreate datetime NOT NULL,
+  timeadd datetime NOT NULL,
   journalid int(10) unsigned NOT NULL,
   is_deleted tinyint(1) NOT NULL default '0',
   pic_orig_url VARCHAR(255) NOT NULL DEFAULT '',
@@ -4350,6 +4372,13 @@
                 ADD pic_fb_url VARCHAR(255) NOT NULL DEFAULT ''
         ");
     }
+
+    unless (column_type("category_recent_posts", "timeadd")) {
+        do_alter("category_recent_posts",
+            "ALTER TABLE category_recent_posts
+                ADD timeadd DATETIME NOT NULL AFTER timecreate
+        ");
+    }
 });
 
 register_tablecreate("eventrates", <<'EOC'); # clustered

Modified: branches/landing-page-LJSUP-9645/bin/worker/category-recent-posts
===================================================================
--- branches/landing-page-LJSUP-9645/bin/worker/category-recent-posts	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/bin/worker/category-recent-posts	2011-10-21 15:32:52 UTC (rev 20406)
@@ -18,15 +18,16 @@
 # 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;
 
+my $default_count_post_per_comm;
+my $default_delta_time;
+
 sub BEGIN {
-    $sleep_when_idle = 600;
+    $sleep_when_idle = 300;
     $verbose = 0;
-    $max_count_post_per_comm = 30;
+    $default_count_post_per_comm = 1;
+    $default_delta_time = 30;
 }
 
 sub options {
@@ -47,33 +48,56 @@
     my $class = shift;
     my @uids;
 
-    my $verbose = $class->verbose();
+    $verbose = $class->verbose();
 
     my $dbh = LJ::get_db_writer();
 
-    my $journals = $dbh->selectall_arrayref ("SELECT cj.catid, cj.journalid FROM categoryjournals cj, category c WHERE cj.catid = c.catid AND c.vert_id <> 0", { Slice => {} });
+    $class->debug ("Start a new iteration");
+
+    my $journals = $dbh->selectall_arrayref ("SELECT DISTINCT cj.journalid FROM categoryjournals cj, category c WHERE cj.catid = c.catid AND c.vert_id <> 0", { 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 $u = LJ::load_userid($journalid);
+        $class->debug ("Comm: " . $u->username);
+
+        ## Get "number of shown posts" and "time for removing post after"
+        my $number_delta_posts = $u->prop ('number_delta_posts');
+        my $comm_last_update = $u->timeupdate;
+
+        my @last_added = $dbh->selectrow_array ("SELECT max(jitemid), max(unix_timestamp(timeadd)) FROM category_recent_posts WHERE journalid = ?", undef, $journalid);
+        my $last_jitemid = $last_added[0];
+        my $last_added = $last_added[1];
+
+        my ($count_post_per_comm, $delta_time) = split /:/, $number_delta_posts;
+        $count_post_per_comm ||= $default_count_post_per_comm;
+        $delta_time ||= $default_delta_time;
+
+        $class->debug ("Wait for:         " . ($last_added + $delta_time * 60));
+        $class->debug ("Now:              " . time);
+        $class->debug ("Check times:\nComm last update: $comm_last_update\nLast added post:  $last_added\nDelta_time:              ".60 * $delta_time);
+
+        next if $comm_last_update - $last_added < $delta_time * 60;
+
         my @recent = LJ::get_recent_items({
-            itemshow    => $max_count_post_per_comm,
+            itemshow    => $count_post_per_comm,
             err         => undef,
             userid      => $u->{userid},
             clusterid   => $u->{clusterid},
             remote      => undef,
-            afterid     => $last_jitemid[0],
+            afterid     => $last_jitemid,
             order       => 'logtime',
         });
 
+        $class->debug ("\tAdded ".@recent." posts");
+
         foreach my $entry (@recent) {
-            my $sth = $dbh->prepare ("INSERT INTO category_recent_posts (jitemid, timecreate, journalid) VALUES (?, ?, ?)");
-            $sth->execute($entry->{itemid}, $entry->{logtime}, $journalid);
-
             my $e_obj = LJ::Entry->new ($u->{userid}, jitemid => $entry->{itemid});
             my $event = $e_obj->event_raw;
 
+            my $sth = $dbh->prepare ("INSERT INTO category_recent_posts (jitemid, timecreate, timeadd, journalid) VALUES (?, ?, NOW(), ?)");
+            $sth->execute($entry->{itemid}, $entry->{logtime}, $journalid);
+
             my $parsed = LJ::Browse::Parser->do_parse (
                 text        => $event,
                 remove_tags => [ 'b', 'p', 'div', 'span', 'strong', 'font' ],
@@ -126,6 +150,7 @@
 }
 
 sub debug {
+    my $class = shift;
     print STDERR @_, "\n" if $verbose;
 }
 

Modified: branches/landing-page-LJSUP-9645/cgi-bin/LJ/Browse.pm
===================================================================
--- branches/landing-page-LJSUP-9645/cgi-bin/LJ/Browse.pm	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/cgi-bin/LJ/Browse.pm	2011-10-21 15:32:52 UTC (rev 20406)
@@ -138,7 +138,7 @@
     $parent = LJ::Browse->load_by_id($self->{parentcatid})
         if ($self->{parentcatid});
 
-    foreach my $table (qw(categoryprop category)) {
+    foreach my $table (qw(categoryprop category categoryjournals category_keymap)) {
         $dbh->do("DELETE FROM $table WHERE catid=?", undef, $self->{catid});
         die $dbh->errstr if $dbh->err;
     }
@@ -646,7 +646,10 @@
     }
 
     # weird, catids that we couldn't find in memcache or db?
-    $_->{_loaded_row} = 1 foreach values %need;
+    foreach (values %need) {
+        $_->{_loaded_row} = 1;
+        $_->{_not_found} = 1;
+    }
     #warn "unknown category: " . join(",", keys %need) if %need;
 
     # now memcache and request cache are both updated, we're done
@@ -1035,8 +1038,17 @@
                         vert_id => $vertical ? $vertical->vert_id : 0,
                     }
                 }
+                ## Remove posts posted by excluded users
                 grep {
-                    ## Filter off suspended entries, deleted communities, suspended posters
+                    my $posterid = $_->posterid;
+                    if (grep { $posterid == $_->{'userid'} } @{LJ::Browse->get_all_excluded_users()}) {
+                        0;
+                    } else {
+                        1;
+                    }
+                }
+                ## Filter off suspended entries, deleted communities, suspended posters
+                grep {
                     if ($_ && $_->valid) {
                         my $poster = $_->poster;
                         $_->is_suspended || $_->journal->is_deleted || ($poster && $poster->is_suspended) ? 0 : 1;
@@ -1044,6 +1056,7 @@
                         0;
                     }
                 }
+                ## Return a LJ::Entry objects
                 map { LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid}) }
                 @$post_ids;
         }
@@ -1104,7 +1117,7 @@
         or die "unable to contact global db master to create category";
 
     ## Add community to category
-    my $res = $dbh->do("REPLACE INTO categoryjournals VALUES (?,?)", undef,
+    my $res = $dbh->do("REPLACE INTO categoryjournals (catid, journalid) VALUES (?,?)", undef,
              $self->catid, $uid);
     die $dbh->errstr if $dbh->err;
 
@@ -1115,9 +1128,7 @@
 
     $self->clear_journals_memcache;
 
-    ## Add tags for added community if vertical selected
-    my $v = $self->vertical;
-    $v->save_tags (is_seo => 0, tags => [ map { { tag => $_, journalid => $uid } } @$tags ] ) if $v;
+    $self->save_tags (is_seo => 0, tags => [ map { { tag => $_, journalid => $uid } } @$tags ] );
 
     return 1;
 }
@@ -1146,6 +1157,20 @@
     return 1;
 }
 
+sub categories_by_comm {
+    my $class = shift;
+    my $comm  = shift;
+    
+    return unless $comm;
+    
+    my $dbh = LJ::get_db_reader();
+    my $cats = $dbh->selectcol_arrayref("SELECT catid FROM categoryjournals WHERE journalid = ?", undef, $comm->userid);
+
+    return map {
+        LJ::Browse->load_by_id($_);
+    } @$cats;
+}
+
 ## Return "path" for selected category
 ## catobj -> par_catobj -> par_par_catobj -> etc... (array)
 ## Param: arrayref to save "path"
@@ -1162,11 +1187,25 @@
     return $parent->get_parent_path ($cat_path);
 }
 
+sub is_valid {
+    my $self = shift;
+
+    $self->preload_rows unless $self->{'_loaded_row'};
+
+    return 0
+        if defined $self->{'_not_found'} && $self->{'_not_found'} == 1;
+
+    return 1;
+}
+
 sub build_select_tree {
-    my ($class, $parent, $cats_ref, $selected_cat, $text, $i, $n) = @_;
+    my ($class, $parent, $cats_ref, $selected_cat, $text, $i, $n, %opts) = @_;
 
     $i ||= 0;
 
+    my $use_table = defined $opts{'use_table'} ? $opts{'use_table'} : 1;
+    my $use_only_td = $opts{'use_only_td'};
+
     return $text unless $cats_ref;
 
     my @categories = @$cats_ref;
@@ -1182,20 +1221,23 @@
     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%;",
+    $text .= "<tr><td>Category</td>" if $use_table;
+    $text .= "<td>" if $use_table || $use_only_td;
+    $text .= LJ::html_select({
+                name => "catid$i\_$n", style => $use_table ? "width:100%;" : "",
                 selected => $sel_cat[0] ? $sel_cat[0]->catid : '' },
                 { text => LJ::Lang::ml('vertical.admin.add_category.btn'),
                 value => '' },
                 @caturls
-    ) . "</td>";
-    $text .= "<td>" . LJ::html_submit('select_c', 'Select Category') . "</td>";
-    $text .= "</tr>";
+    );
+    $text .= "</td><td>" if $use_table;
+    $text .= LJ::html_submit('select_c', 'Select Category');
+    $text .= "</td></tr>" if $use_table;
+    $text .= "</td>" if $use_only_td;
 
     if ($sel_cat[0]) {
         my @children = $sel_cat[0]->children;
-        $text = $class->build_select_tree($sel_cat[0], \@children, $selected_cat, $text, ++$i, $n);
+        $text = $class->build_select_tree($sel_cat[0], \@children, $selected_cat, $text, ++$i, $n, %opts);
     }
 
     return $text;
@@ -1495,4 +1537,197 @@
     return 0;
 }
 
+sub add_excluded_comm {
+    my $class = shift;
+    my $userid = shift;
+
+    my $dbh = LJ::get_db_writer();
+    my $res = $dbh->do ("INSERT INTO category_exclude_comms (userid) VALUES (?)", undef, $userid);
+
+    return $res;
+}
+
+sub is_comm_excluded {
+    my $class = shift;
+    my $userid = shift;
+
+    my $dbh = LJ::get_db_reader();
+    my $flag = $dbh->selectcol_arrayref ("SELECT 1 FROM category_exclude_comms WHERE userid = ?", undef, $userid);
+
+    return ref $flag eq 'ARRAY' && @$flag ? $flag->[0] : 0;
+}
+
+sub remove_comm_from_exclude {
+    my $class  = shift;
+    my $userid = shift;
+
+    my $dbh = LJ::get_db_writer();
+    my $res = $dbh->do ("DELETE FROM category_exclude_comms WHERE userid = ?", undef, $userid);
+
+    return $res;
+}
+
+sub get_all_excluded_comms {
+    my $class = shift;
+
+    my $dbh = LJ::get_db_reader();
+    my $res = $dbh->selectall_arrayref ("SELECT userid FROM category_exclude_comms ORDER BY addition_date DESC", { Slice => {} });
+
+    return $res;
+}
+
+sub add_excluded_user {
+    my $class = shift;
+    my $userid = shift;
+
+    my $dbh = LJ::get_db_writer();
+    my $res = $dbh->do ("INSERT INTO category_exclude_users (userid) VALUES (?)", undef, $userid);
+
+    return $res;
+}
+
+sub is_user_excluded {
+    my $class = shift;
+    my $userid = shift;
+
+    my $dbh = LJ::get_db_reader();
+    my $flag = $dbh->selectcol_arrayref ("SELECT 1 FROM category_exclude_users WHERE userid = ?", undef, $userid);
+
+    return ref $flag eq 'ARRAY' && @$flag ? $flag->[0] : 0;
+}
+
+sub remove_user_from_exclude {
+    my $class  = shift;
+    my $userid = shift;
+
+    my $dbh = LJ::get_db_writer();
+    my $res = $dbh->do ("DELETE FROM category_exclude_users WHERE userid = ?", undef, $userid);
+
+    return $res;
+}
+
+sub get_all_excluded_users {
+    my $class = shift;
+
+    my $dbh = LJ::get_db_reader();
+    my $res = $dbh->selectall_arrayref ("SELECT userid FROM category_exclude_users ORDER BY addition_date DESC", { Slice => {} });
+
+    return $res;
+}
+
+sub create_tag {
+    my $self = shift;
+    my $keyword = shift;
+
+    return undef unless $keyword;
+
+    my $dbh = LJ::get_db_writer();
+    my $res = $dbh->do("INSERT INTO category_keywords (keyword) values (?)", undef, $keyword);
+    my $kw_id = $dbh->selectrow_array("SELECT LAST_INSERT_ID()");
+    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 $catid   = $args{'catid'}   || 0;
+    my $jitemid = $args{'jitemid'} || 0;
+
+    my $cat_sql   = " AND catid   = $catid ";
+    my $entry_sql = " AND jitemid = $jitemid ";
+
+    my $dbh = LJ::get_db_writer ();
+    my $res = $dbh->do ("
+        DELETE FROM category_keymap 
+            WHERE 
+                journalid = ?
+                $cat_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 $catid   = $args{'catid'} || 0;
+    my $jitemid = $args{'jitemid'} || 0;
+
+    my $dbh = LJ::get_db_reader ();
+    my $res = $dbh->selectall_arrayref ("
+        SELECT keyword 
+            FROM category_keymap km, category_keywords kw
+            WHERE km.kw_id = kw.kw_id
+                AND km.journalid = ?
+                AND km.catid = ?
+                AND km.jitemid = ?
+    ", { Slice => {} }, $comm_id, $catid, $jitemid);
+
+    return join ", ", map { $_->{keyword} } @$res;
+}
+
+sub save_tags {
+    my $self = shift;
+    my %args = @_;
+
+    my $tags = $args{'tags'};
+
+    my $dbh = LJ::get_db_writer();
+
+    foreach my $tag (@$tags) {
+        my $res = $dbh->selectall_arrayref(
+            "SELECT m.kw_id 
+                FROM category_keymap m, category_keywords w 
+                WHERE m.kw_id = w.kw_id 
+                    AND w.keyword = ? 
+                    AND m.catid = ?", 
+            undef, $tag, $self->catid
+        ) || [];
+        next if @$res;
+        my $kw_id = $dbh->selectrow_array(
+            "SELECT kw_id 
+                FROM category_keywords 
+                WHERE keyword = ?",
+            undef, $tag->{tag}
+        );
+        $kw_id = $self->create_tag ($tag->{tag}) unless $kw_id;
+        my $sth = $dbh->do(
+            "INSERT IGNORE INTO category_keymap 
+            (journalid, kw_id, jitemid, catid) 
+            VALUES (?, ?, ?, ?)",
+            undef , $tag->{journalid}, $kw_id, $tag->{jitemid}, $self->catid
+        );
+    }
+
+    return 1;
+}
+
+sub load_tags {
+    my $self = shift;
+    my %args = @_;
+
+    my $dbh = LJ::get_db_writer();
+    my $tags = $dbh->selectall_arrayref(
+        "SELECT journalid, keyword, jitemid, m.kw_id 
+            FROM category_keymap m, category_keywords w 
+            WHERE m.kw_id = w.kw_id 
+                AND m.catid = ?", 
+        { Slice => {} }, $self->catid
+    );
+
+    return $tags ? $tags : [];
+}
+
+
 1;

Modified: branches/landing-page-LJSUP-9645/cgi-bin/LJ/Vertical.pm
===================================================================
--- branches/landing-page-LJSUP-9645/cgi-bin/LJ/Vertical.pm	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/cgi-bin/LJ/Vertical.pm	2011-10-21 15:32:52 UTC (rev 20406)
@@ -726,6 +726,7 @@
 #
 
 sub create_tag {
+die "Do not run this!";
     my $self = shift;
     my $keyword = shift;
 
@@ -740,6 +741,7 @@
 ## Remove tags links from vertical_keymap table.
 ## Not delete tags from vertical_keywords.
 sub delete_tags_links {
+    die "Do not run this!";
     my $class = shift;
     my %args = @_;
 
@@ -765,6 +767,7 @@
 }
 
 sub get_tags_for_journal {
+    die "Do not run this!";
     my $class = shift;
     my %args  = @_;
 
@@ -788,6 +791,7 @@
 }
 
 sub save_tags {
+    die "Do not run this!";
     my $self = shift;
     my %args = @_;
 
@@ -824,6 +828,7 @@
 }
 
 sub load_tags {
+    die "Do not run this!";
     my $self = shift;
     my %args = @_;
 

Modified: branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community.bml
===================================================================
--- branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community.bml	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community.bml	2011-10-21 15:32:52 UTC (rev 20406)
@@ -32,8 +32,8 @@
     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]} ? $POST{$ids[0]} : $POST{$ids[1]};
+    my @ids = sort { $b cmp $a } grep { $_ =~ /^catid\d+\_\Q$i\E$/ } (keys %POST, keys %GET);
+    my $cat_id = $POST{$ids[0]} || $GET{$ids[0]} ? $POST{$ids[0]} || $GET{$ids[0]} : $POST{$ids[1]} || $GET{$ids[1]};
     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;
@@ -53,10 +53,21 @@
         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);
+            LJ::Browse->delete_tags_links (comm_id => $cid, catid => $cat_[$j] ? $cat_[$j]->catid : 0);
             $cat_[$j]->add_community ($cid, { tags => \@tags, not_need_approve => 1 });
         }
+    }
 
+    if (LJ::did_post && $POST{'action:remove'}) {
+        # validate form auth
+        return "<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>"
+            unless LJ::check_form_auth();
+
+        my @remove_ids = grep { $_ =~ /^remove_\d+/ } keys %POST;
+        foreach my $comm (@remove_ids) {
+            my ($cid) = $comm =~ /^remove_(\d+)/;
+            $cat_[$j]->remove_communities ($cid);
+        }
     }
 
     $ret .= "<form method='post' method='post'>";
@@ -81,7 +92,12 @@
         $ret .= LJ::html_submit('select_v', 'Select Vertical') . "</td></tr>";
     }
 
-    if ((LJ::did_post() && $vert_[$j]) || ($LJ::DISABLED{'verticals_menu'})) {
+    if (
+        (LJ::did_post() && $vert_[$j])
+        ## Need for return from edit_community_more.bml
+        || (LJ::Request->header_in('Referer') =~ m#^$LJ::SITEROOT/admin/browse/edit_community_more.bml# && $vert_[$j])
+        || ($LJ::DISABLED{'verticals_menu'})
+    ) {
         my @children = $cat_[$j] ? $cat_[$j]->children : ();
         # Get the full list of categories
         my @categories = $vert_[$j] ? LJ::Browse->load_all($vert_[$j]) : ();
@@ -90,9 +106,15 @@
         if ($cat_[$j]) {
             $ret .= "<tr><td valign='top'>Communities from category:</td><tr><td colspan='3'>";
             if ($cat_[$j]->communities) {
+                my $excl_list = LJ::Browse->get_all_excluded_comms ();
                 $ret .= "<table width='100%'>";
+                $ret .= "<tr><td colspan='4' align='right'></td><td>".LJ::html_submit('action:remove', $ML{'.remove'})."</td></tr>";
                 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 .= "<tr><td>\n";
+                    $ret .= "FLAG" if grep { $_->{userid} == $comm->userid } @$excl_list;
+                    $ret .= "</td><td>".LJ::ljuser($comm->user) . "</td><td><input type='text' size='60' name='tags_".$comm->userid."' value='".LJ::Browse->get_tags_for_journal (catid => $cat_[$j] ? $cat_[$j]->catid : 0, comm_id => $comm->userid)."'></td><td>\n<button type=\"button\" onclick='window.location=\"/admin/browse/edit_community_more.bml?return_to=";
+                    $ret .= $vert_[$j]->vert_id."-".$cat_[$j]->catid."&comm_user=".$comm->username;
+                    $ret .= "\"'>Edit</button>\n</td><td align='center'><input type='checkbox' name='remove_".$comm->userid."'></td></tr>";
                 }
                 $ret .= "</table>";
             }

Modified: branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community.bml.text
===================================================================
--- branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community.bml.text	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community.bml.text	2011-10-21 15:32:52 UTC (rev 20406)
@@ -1,4 +1,5 @@
 .title=Edit Community
 .add=Select Category
-.update=Update tags list
+.update=Save
+.remove=Remove
 

Added: branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community_more.bml
===================================================================
--- branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community_more.bml	                        (rev 0)
+++ branches/landing-page-LJSUP-9645/htdocs/admin/browse/edit_community_more.bml	2011-10-21 15:32:52 UTC (rev 20406)
@@ -0,0 +1,181 @@
+<?page
+title=><?_ml .title _ml?>
+body<=
+<?_code
+{
+#line 6
+    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 = '';
+
+    # get remote
+    my $remote = LJ::get_remote();
+    unless ($remote) {
+        $ret .= "<?needlogin?>";
+    }
+
+    return "You are not allowed to view this page"
+        unless LJ::check_priv($remote, 'siteadmin', 'community_directory') || $LJ::IS_DEV_SERVER;
+
+    ## Check form is valid
+    if (LJ::did_post()) {
+        return "<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>"
+            unless LJ::check_form_auth();
+    }
+
+    $LJ::VERTICALS_FORCE_USE_MASTER = 1;
+
+    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]} ? $POST{$ids[0]} : $POST{$ids[1]};
+    push @catid_, $cat_id if $cat_id;
+    my $comm_id_remove = $POST{"commremove"} ? $POST{"commremove"} : undef;
+    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;
+
+    ## delete-catid-commid
+    my @delete_ids = grep { $_ =~ /^delete-\d+-\d+/ } keys %POST;
+
+    if (LJ::did_post() && $POST{'select_v'}) {
+        $cat_[$j] = undef;
+    }
+
+    my $comm_user = $GET{'comm_user'} || $POST{'comm_user'};
+    my $c = LJ::load_user ($comm_user);
+
+    return "Error community name"
+        unless $c;
+
+    if (LJ::did_post() && $POST{'add_category'}) {
+        $cat_[$j]->add_community($c->userid, { tags => [], not_need_approve => 1 });
+        @catid_ = ();
+        @catrem = ();
+        @cat_ = ();
+        @vert_ = ();
+    }
+
+    if (LJ::did_post() && @delete_ids) {
+        foreach my $delete (@delete_ids) {
+            my ($catid, $commid) = $delete =~ /^delete-(\d+)-(\d+)/;
+            my $cat = LJ::Browse->load_by_id ($catid);
+            $cat->remove_communities($commid);
+        }
+    }
+
+    my @end_cats = LJ::Browse->categories_by_comm ($c);
+
+    if (LJ::did_post() && $comm_id_remove) {
+        $_->remove_communities($c->userid)
+            foreach @end_cats;
+        my $return_to = $GET{'return_to'} || $POST{'return_to'};
+        my ($vert_id, $catid) = $return_to =~ m#^(\d+)-(\d+)$#; ##
+        BML::redirect($LJ::SITEROOT."/admin/browse/edit_community.bml?vert_id=$vert_id&catid0_1=$catid&select_c=1")
+    }
+
+    $ret .= "<form method='post'>\n";
+    $ret .= "<input type='hidden' name='return_to' value='".($GET{'return_to'} || $POST{'return_to'})."'>\n";
+    $ret .= LJ::form_auth();
+    $ret .= "<table width='100%' border='0'>";
+    $ret .= "<tr><td>Vertical</td><td>Category</td><td>Sub-Category</td><td></td><td></td></tr>";
+    foreach my $e_cat (@end_cats) {
+        next unless $e_cat->is_valid;
+        # $ret .= "<form method='post'>";
+        $ret .= "<tr>";
+        my @path = ();
+        $e_cat->get_parent_path(\@path);
+        if (@path < 2) {
+            push @path, "" foreach (1 .. 2-@path);
+        }
+        my $v = LJ::Vertical->load_by_id ($path[0]->{'vert_id'});
+        $ret .= "<td>".$v->display_name."</td>";
+        foreach my $cat (@path) {
+            $ret .= "<td>".(ref $cat eq "LJ::Browse" ? $cat->display_name : $cat)."</td>";
+        }
+        $ret .= "<td><button>show tags</button></td>";
+        $ret .= "<td><input type='submit' name='delete-".$e_cat->catid."-".$c->userid."' value='delete'></td>";
+        $ret .= "</tr>";
+        $ret .= "<tr><td colspan='5'>";
+        my @tags = split /,\s+?/, $e_cat->get_tags_for_journal (catid => $e_cat->catid, comm_id => $c->userid);
+        foreach my $tag (@tags) {
+            $ret .= "<input type='text' name='tag-".$e_cat->catid."' value='$tag'>&nbsp;<input type='submit' name='remove-tag-".$e_cat->catid."' value='Remove'><br/>";
+        }
+        $ret .= "<input type='submit' name='add-tag-".$e_cat->catid."' value='Add new tag'><br/>";
+        $ret .= "</td></tr>";
+        # $ret .= "</form>";
+    }
+    $ret .= "</table>";
+
+    $ret .= '<hr>';
+
+    # $ret .= "<form method='post'>";
+    $ret .= "<input type='hidden' name='comm_user' value='".$c->user."'>";
+    $ret .= "<table width='100%' border='0'>";
+    my @verticals = LJ::Vertical->load_all();
+    $ret .= "<tr><td valign='top'><!-- $i.-->";
+    @verticals = map { { text => $_->{name}, value => $_->{vert_id} } } @verticals;
+
+    $ret .= LJ::html_select({
+                name => "vert_id_$i", style => "",
+                selected => $vert_[$j] ? $vert_[$j]->vert_id : 0,
+                },
+                { text => 'Community Directory',
+                value => '',},
+                @verticals
+            );
+    # $ret .= "</td><td>\n";
+
+    $ret .= LJ::html_submit('select_v', 'Select Vertical') . "</td>";
+    
+    my $category = $cat_[$j];
+    my $vertical = $vert_[$j] ? $vert_[$j] : 0;
+    my @categories = $vertical ? LJ::Browse->load_all($vertical) : ();
+    $ret .= LJ::Browse->build_select_tree (0, \@categories, $category, undef, undef, $i, use_table => 0, use_only_td => 1);
+
+    $ret .= "<td>";
+    if ($vertical) {
+        $ret .= "<input type='submit' name='add_category' value='Add to ";
+        $ret .= $category ? $category->display_name : $vertical->display_name;
+        $ret .= "'>";
+    }
+    $ret .= "</td>";
+    
+    $ret .= "</tr>";
+    $ret .= "</table>";
+
+    # $ret .= "</form>";
+
+    $ret .= "<hr>";
+    
+    # $ret .= "<form method='post'>";
+    $ret .= "<input type='hidden' name='comm_user' value='".$c->user."'>";
+    $ret .= "<table border='0'>";
+    $ret .= "<tr>
+        <td width='300'>Number of shown posts <input type='text' size='3' name='shown_posts' value='1'></td>
+        <td width='400'>Time for removing posts <input type='text' size='4' name='remove_after' value='30'></td>
+    </tr>";
+    $ret .= "</table>";
+
+    $ret .= "<div align='right'><table border='0'><tr><td><input type='submit' name='commremove' value='Remove community'></td><td><input type='button' value='Save'></td></tr></table></div>";
+    $ret .= "</form>";
+
+    return $ret;
+
+}
+_code?>
+
+<=body
+page?>

Modified: branches/landing-page-LJSUP-9645/htdocs/admin/browse/index.bml
===================================================================
--- branches/landing-page-LJSUP-9645/htdocs/admin/browse/index.bml	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/htdocs/admin/browse/index.bml	2011-10-21 15:32:52 UTC (rev 20406)
@@ -17,6 +17,11 @@
     $title = "Verticals And Community Directory Admin";
     my $ret = "";
 
+    $ret .= "<h2>Excludes</h2><ul style='list-style:none;line-height:1.6em;padding:0 0 0 20px;'>";
+    $ret .= "<li><a href='./exclude_users.bml'>Exclude users</a></li>";
+    $ret .= "<li><a href='./exclude_comms.bml'>Exclude communities</a></li>";
+    $ret .= "</ul>";
+
     $ret .= "<h2>Manage Verticals</h2><ul style='list-style:none;line-height:1.6em;padding:0 0 0 20px;'>";
     $ret .= "<li><a href='./add_verticals.bml'>Add Verticals</a></li>";
     $ret .= "<li><a href='./edit_verticals.bml'>Edit Verticals</a></li>";

Modified: branches/landing-page-LJSUP-9645/htdocs/admin/browse/recent_posts.bml
===================================================================
--- branches/landing-page-LJSUP-9645/htdocs/admin/browse/recent_posts.bml	2011-10-21 15:10:06 UTC (rev 20405)
+++ branches/landing-page-LJSUP-9645/htdocs/admin/browse/recent_posts.bml	2011-10-21 15:32:52 UTC (rev 20406)
@@ -2,6 +2,7 @@
 body<=
 <?_code
 {
+#line 5
     use strict;
     use vars qw(%GET %POST $title $headextra @errors @warnings);
     use Class::Autouse qw( LJ::Browse );
@@ -73,11 +74,12 @@
 
         $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;
-            my $commid = $_->journalid;
+            my $entry = $_->{'entry'};
+            next unless $entry->valid;
+            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' style='display:inline;padding:0 0 0 10px;'>\n";
             $ret .= LJ::form_auth();

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