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

[livejournal] r17636: LJSUP-7052. Add SEO-tags and search widg...

Committer: gprochaev
LJSUP-7052. Add SEO-tags and search widget.

U   trunk/bin/upgrading/update-db-general.pl
U   trunk/cgi-bin/LJ/Vertical.pm
U   trunk/cgi-bin/LJ/Widget/Browse.pm
U   trunk/cgi-bin/LJ/Widget/Search.pm
U   trunk/htdocs/admin/browse/index.bml
Modified: trunk/bin/upgrading/update-db-general.pl
===================================================================
--- trunk/bin/upgrading/update-db-general.pl	2010-11-03 08:30:23 UTC (rev 17635)
+++ trunk/bin/upgrading/update-db-general.pl	2010-11-03 10:14:43 UTC (rev 17636)
@@ -3141,6 +3141,19 @@
 )
 EOC
 
+register_tablecreate("vertical_keywords", <<'EOC');
+CREATE TABLE vertical_keywords (
+  journalid int(11) NOT NULL,
+  jitemid int(11) NOT NULL,
+  vert_id int(11) NOT NULL,
+  keyword varchar(80) NOT NULL,
+  is_seo tinyint(1) NOT NULL,
+  PRIMARY KEY  (journalid,jitemid,vert_id,keyword),
+  KEY vert_id (vert_id),
+  KEY keyword (keyword)
+)
+EOC
+
 ## --
 ## -- embedconten previews
 ## --

Modified: trunk/cgi-bin/LJ/Vertical.pm
===================================================================
--- trunk/cgi-bin/LJ/Vertical.pm	2010-11-03 08:30:23 UTC (rev 17635)
+++ trunk/cgi-bin/LJ/Vertical.pm	2010-11-03 10:14:43 UTC (rev 17636)
@@ -586,6 +586,50 @@
 # Loaders
 #
 
+sub save_tags {
+    my $self = shift;
+    my %args = @_;
+
+    my $is_seo = $args{'is_seo'};
+    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) {
+        my %new_tags = map { $_->{'tag'} => 1 } @$tags;
+        my $to_del_tags = [ grep { !$new_tags{$_} } map { $_->{keyword} } @$old_tags ];
+        ## Need to delete some tags?
+        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);
+        }
+    }
+
+    foreach my $tag (@$tags) {
+        my $kw_id = $dbh->selectall_arrayref("SELECT * FROM vertical_keywords WHERE keyword = ?", undef, $tag);
+        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);
+    }
+
+    return 1;
+}
+
+sub load_tags {
+    my $self = shift;
+    my %args = @_;
+
+    my $is_seo = $args{'is_seo'};
+
+    my $dbh = LJ::get_db_writer();
+    my $where = $is_seo ? " AND is_seo = 1 " : "";
+    my $tags = $dbh->selectall_arrayref("SELECT journalid, keyword, jitemid FROM vertical_keywords WHERE vert_id = ? $where", { Slice => {} }, $self->vert_id);
+
+    return $tags ? $tags : [];
+}
+
 sub load_communities {
     my $self = shift;
     my %args = @_;

Modified: trunk/cgi-bin/LJ/Widget/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Browse.pm	2010-11-03 08:30:23 UTC (rev 17635)
+++ trunk/cgi-bin/LJ/Widget/Browse.pm	2010-11-03 10:14:43 UTC (rev 17636)
@@ -339,7 +339,7 @@
         nav_line                => $nav_line,
         popular_interests_widget=> LJ::Widget::PopularInterests->render(),
         add_community_widget    => LJ::Widget::AddCommunity->render(),
-        search_widget           => LJ::Widget::Search->render(type => 'yandex'),
+        search_widget           => LJ::Widget::Search->render(type => "tags", view => $view),
         top_posts               => \@top_posts,
         top_comms               => \@top_comms,
         view                    => $view,

Modified: trunk/cgi-bin/LJ/Widget/Search.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/Search.pm	2010-11-03 08:30:23 UTC (rev 17635)
+++ trunk/cgi-bin/LJ/Widget/Search.pm	2010-11-03 10:14:43 UTC (rev 17636)
@@ -68,6 +68,28 @@
 EOF
     }
 
+    if ($opts{type} eq 'tags') {
+        my $template = LJ::HTML::Template->new(
+            { use_expr => 1 }, # force HTML::Template::Pro with Expr support
+            filename => "$ENV{'LJHOME'}/templates/Browse/search.tmpl",
+            die_on_bad_params => 0,
+            strict => 0,
+        ) or die "Can't open template: $!";
+
+        my $uri = BML::get_uri();
+        my $vertical = LJ::Vertical->load_by_url ($uri);
+
+        $uri .= "/" if $uri !~ m#/$#; ## add end slash if not exist
+        $template->param (
+            vertical_name   => $vertical->name,
+            search_url      => $uri."tag",
+            view            => $opts{'view'},
+            tags            => [ map { { tag => $_->{keyword} } } @{$vertical->load_tags (is_seo => 1)} ],
+        );
+
+        return $template->output;
+    }
+
     my $ret;
 
     my $single_search = $opts{single_search};

Modified: trunk/htdocs/admin/browse/index.bml
===================================================================
--- trunk/htdocs/admin/browse/index.bml	2010-11-03 08:30:23 UTC (rev 17635)
+++ trunk/htdocs/admin/browse/index.bml	2010-11-03 10:14:43 UTC (rev 17636)
@@ -25,6 +25,7 @@
     $ret .= "<p><a href='./recent_posts.bml'>Manage Recent Posts</a></p>";
     $ret .= "<p><a href='./top_entries_vertical.bml'>Top Entries in communities</a></p>";
     $ret .= "<p><a href='./featured_communities.bml'>Featured Communities</a></p>";
+    $ret .= "<p><a href='./search_tags.bml'>Editing Search Tags</a></p>";
     $ret .= "</blockquote>";
 
     $ret .= "<h2>Manage Communities</h2><blockquote>";

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