Committer: gprochaev
LJSUP-7052. Add recent posts tags. Add community tags.U trunk/bin/worker/category-recent-posts U trunk/cgi-bin/LJ/Browse.pm U trunk/cgi-bin/LJ/Vertical.pm U trunk/cgi-bin/LJ/Widget/Browse.pm U trunk/htdocs/admin/browse/add_community.bml U trunk/htdocs/admin/browse/remove_community.bml
Modified: trunk/bin/worker/category-recent-posts =================================================================== --- trunk/bin/worker/category-recent-posts 2010-11-15 08:04:22 UTC (rev 17681) +++ trunk/bin/worker/category-recent-posts 2010-11-15 09:37:07 UTC (rev 17682) @@ -12,6 +12,8 @@ use lib "$ENV{LJHOME}/cgi-bin"; use base 'LJ::NewWorker::Manual'; +use LJ::Browse; + # how long to wait if we didn't process any at all my $sleep_when_idle; @@ -48,7 +50,7 @@ my $dbh = LJ::get_db_writer(); - my $journals = $dbh->selectall_arrayref ("SELECT * FROM categoryjournals", { Slice => {} }); + my $journals = $dbh->selectall_arrayref ("SELECT catid, journalid 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); @@ -67,7 +69,18 @@ foreach my $entry (@recent) { my $sth = $dbh->prepare ("INSERT INTO category_recent_posts (jitemid, timecreate, journalid) VALUES (?, ?, ?)"); $sth->execute($entry->{itemid}, $entry->{logtime}, $journalid); + + ## Add tags for every entry + my $e_obj = LJ::Entry->new ($u->{userid}, jitemid => $entry->{itemid}); + my @tags = $e_obj->tags; + if (scalar @tags) { + my $cat = LJ::Browse->load_by_id ($rec->{catid}); + next unless $cat; + my $v = $cat->vertical; + $v->save_tags (is_seo => 0, tags => [ map { { tag => $_, journalid => $u->{userid}, jitemid => $entry->{itemid} } } @tags ] ); + } } + } return 0; Modified: trunk/cgi-bin/LJ/Browse.pm =================================================================== --- trunk/cgi-bin/LJ/Browse.pm 2010-11-15 08:04:22 UTC (rev 17681) +++ trunk/cgi-bin/LJ/Browse.pm 2010-11-15 09:37:07 UTC (rev 17682) @@ -355,7 +355,7 @@ $url =~ /^(?:$LJ::SITEROOT)?(\/.+)$/; my $path = $1; - $path =~ s/(?:tag)?\/?.*?\/?(?:\?.*)?$//; # remove search string, trailing slash and any get args + $path =~ s/tag?.*?\/?(?:\?.*)?$//; # remove search string, trailing slash and any get args $path =~ s/\/index\.bml$//; # remove bml page # 4 possibilities: @@ -835,34 +835,29 @@ sub search_posts { my $class = shift; - my $search = shift; - my $limit = shift; - - my $dbh = LJ::get_db_reader(); - my $posts = $dbh->selectall_arrayref ("SELECT journalid, jitemid FROM vertical_keywords WHERE keyword = ? AND is_seo = 0", { Slice => {} }, $search); - my @found_posts = (); - foreach my $post (@$posts) { - my $post_ids = $dbh->selectall_arrayref ("SELECT journalid, jitemid FROM category_recent_posts WHERE journalid = ? AND jitemid = ? AND is_deleted = 0 ORDER BY timecreate DESC LIMIT $limit", { Slice => {} }, $post->{journalid}, $post->{jitemid}); - push @found_posts, @$post_ids; - } - my @entries = - map { LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid}) } ## Create LJ::Entry object - grep { $_->{journalid} } ## remove SEO posts - @found_posts; - return @entries; -} - -sub recent_posts { - my $class = shift; my $comms = shift; my $limit = shift; + my $search = shift; + my @entries = (); my $comm_list = join ",", @$comms; my $dbh = LJ::get_db_reader(); - 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 => {} }); - my @entries = map { LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid}) } @$post_ids; + if (defined $search) { + my $posts = $dbh->selectall_arrayref ("SELECT journalid, jitemid FROM vertical_keywords WHERE keyword like ? AND is_seo = 0", { Slice => {} }, '%'.$search.'%'); + my @found_posts = (); + foreach my $post (@$posts) { + my $post_ids = $dbh->selectall_arrayref ("SELECT journalid, jitemid FROM category_recent_posts WHERE journalid IN ($comm_list) AND journalid = ? AND jitemid = ? AND is_deleted = 0 ORDER BY timecreate DESC LIMIT $limit", { Slice => {} }, $post->{journalid}, $post->{jitemid}); + push @found_posts, @$post_ids; + } + @entries = + map { LJ::Entry->new ($_->{journalid}, jitemid => $_->{jitemid}) } ## Create LJ::Entry object + 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; + } return @entries; - } # Return a list of communities found in a category @@ -906,25 +901,30 @@ } # Takes a list of userids and adds them to a category -sub add_communities { +sub add_community { my $self = shift; - my @uids = @_; + my $uid = shift; + my $tags = shift; my $dbh = LJ::get_db_writer() or die "unable to contact global db master to create category"; - foreach my $uid (@uids) { - $dbh->do("REPLACE INTO categoryjournals VALUES (?,?)", undef, - $self->catid, $uid); - die $dbh->errstr if $dbh->err; + + ## Add community to category + $dbh->do("REPLACE INTO categoryjournals VALUES (?,?)", undef, + $self->catid, $uid); + die $dbh->errstr if $dbh->err; - LJ::Browse->add_approved_community( comm => LJ::want_user($uid), - mod_u => LJ::get_remote(), - catid => $self->catid, ); - } + LJ::Browse->add_approved_community( comm => LJ::want_user($uid), + mod_u => LJ::get_remote(), + catid => $self->catid, ); $self->clear_journals_memcache; + ## Add tags for added community + my $v = $self->vertical; + $v->save_tags (is_seo => 0, tags => [ map { { tag => $_, journalid => $uid } } @$tags ] ); + return 1; } Modified: trunk/cgi-bin/LJ/Vertical.pm =================================================================== --- trunk/cgi-bin/LJ/Vertical.pm 2010-11-15 08:04:22 UTC (rev 17681) +++ trunk/cgi-bin/LJ/Vertical.pm 2010-11-15 09:37:07 UTC (rev 17682) @@ -592,7 +592,6 @@ my $tags = $args{'tags'}; my $dbh = LJ::get_db_writer(); - ## Get the diff between old and new tags list to delete that diff from DB my $old_tags = $self->load_tags(%args); if ($old_tags) { @@ -602,12 +601,12 @@ if (@$to_del_tags) { my @bind = map { '?' } @$to_del_tags; my @bind_vals = map { $_ } @$to_del_tags; - my $del = $dbh->do("DELETE FROM vertical_keywords WHERE vert_id = ? AND keyword IN (".(join ",", @bind).")", undef, $self->vert_id, @bind_vals); + my $del = $dbh->do("DELETE FROM vertical_keywords WHERE vert_id = ? AND keyword IN (".(join ",", @bind).") AND is_seo = ?", undef, $self->vert_id, @bind_vals, $is_seo); } } foreach my $tag (@$tags) { - my $kw_id = $dbh->selectall_arrayref("SELECT * FROM vertical_keywords WHERE keyword = ?", undef, $tag); + my $kw_id = $dbh->selectall_arrayref("SELECT * FROM vertical_keywords WHERE keyword = ? AND is_seo = ?", undef, $tag, $is_seo); next if @$kw_id; my $sth = $dbh->do("INSERT IGNORE INTO vertical_keywords (journalid, keyword, jitemid, vert_id, is_seo) VALUES (?, ?, ?, ?, ?)", undef , $tag->{journalid}, $tag->{tag}, $tag->{jitemid}, $self->vert_id, $is_seo); } Modified: trunk/cgi-bin/LJ/Widget/Browse.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/Browse.pm 2010-11-15 08:04:22 UTC (rev 17681) +++ trunk/cgi-bin/LJ/Widget/Browse.pm 2010-11-15 09:37:07 UTC (rev 17682) @@ -221,12 +221,7 @@ }; } } else { - my @posts = (); - if ($search_str) { - @posts = LJ::Browse->search_posts ( $search_str, $post_page_size ); - } else { - @posts = LJ::Browse->recent_posts ( [ map { $_->{userid} } @comms ], $post_page_size ); - } + my @posts = LJ::Browse->search_posts ( [ map { $_->{userid} } @comms ], $post_page_size, $search_str ); foreach my $entry (@posts) { next unless $entry; Modified: trunk/htdocs/admin/browse/add_community.bml =================================================================== --- trunk/htdocs/admin/browse/add_community.bml 2010-11-15 08:04:22 UTC (rev 17681) +++ trunk/htdocs/admin/browse/add_community.bml 2010-11-15 09:37:07 UTC (rev 17682) @@ -18,7 +18,8 @@ my $ret = ""; my $caturl = $POST{'caturl'}; - my $journals = $POST{'journals'}; + my $journal = $POST{'journal'}; + my $tags = $POST{'tags'}; if (LJ::did_post() and $POST{'add'}) { push @errors, "Invalid form submission" unless LJ::check_form_auth(); @@ -28,7 +29,7 @@ push @errors, "Please select a category"; next; } - unless ($journals) { + unless ($journal) { push @errors, "Please enter journal names to add"; next; } @@ -38,25 +39,16 @@ push @errors, "Invalid category" unless $category; # Extract usernames and get userids - my @usernames = split(/\n/, $journals); + my @tags = split /,\s*/, $tags; my @baduser; - my %users; - foreach my $user (@usernames) { - # trim off extra whitespace characters - $user = LJ::trim($user); - my $uid = LJ::get_userid($user); - if ($uid) { - $users{$user} = $uid; - } else { - push @baduser, $user; - } - } - push @errors, "Invalid users (" . join(',', @baduser) . ")" - if @baduser; + my $uid = LJ::get_userid($journal); + + push @errors, "Invalid user <b>$journal</b>" + unless $uid; next if @errors; - # Add journals to category - if ($category->add_communities(values %users)) { + # Add journal to category + if ($category->add_community($uid, \@tags)) { $ret .= "<span class='super notice'>Communities successfully added to category.</span>"; } else { $ret .= "<span class='super notice'>Communities not added.</span>"; @@ -83,15 +75,20 @@ ); $ret .= "</p>\n"; - $ret .= "<p>the following journals:<br />"; - $ret .= LJ::html_textarea( { - name => 'journals', - cols => 40, - rows => 6, - value => $journals } + $ret .= "<p>the following journal:<br />"; + $ret .= LJ::html_text( { + name => 'journal', + size => 40, + } ); - $ret .= "<br /><i>One username per line.</i></p>\n"; + $ret .= "<p>with tags:<br />"; + $ret .= LJ::html_text( { + name => 'tags', + size => 60, + } + ); + $ret .= "<p>" . LJ::html_submit('add', 'Add') . "</p>"; $ret .= "</form>"; Modified: trunk/htdocs/admin/browse/remove_community.bml =================================================================== --- trunk/htdocs/admin/browse/remove_community.bml 2010-11-15 08:04:22 UTC (rev 17681) +++ trunk/htdocs/admin/browse/remove_community.bml 2010-11-15 09:37:07 UTC (rev 17682) @@ -75,7 +75,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 } } grep { $_->parent } @categories; @caturls = sort { $a cmp $b } @caturls; $ret .= "<p>Remove from Category:<br />";