[vhffs-dev] [1513] You can now use URLs like /tags/type:: development to do simple tag search.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1513
Author:   beuss
Date:     2009-08-05 00:00:37 +0200 (Wed, 05 Aug 2009)

Log Message:
-----------
You can now use URLs like /tags/type::development to do simple tag search. Added sample apache configuration for public part including RewriteRule

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Tag.pm
    trunk/vhffs-public/Makefile.am

Added Paths:
-----------
    trunk/vhffs-doc/config/apache/publicconf
    trunk/vhffs-public/tagsearch.pl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Tag.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Tag.pm	2009-08-04 20:41:57 UTC (rev 1512)
+++ trunk/vhffs-api/src/Vhffs/Panel/Tag.pm	2009-08-04 22:00:37 UTC (rev 1513)
@@ -34,16 +34,9 @@
 
 package Vhffs::Panel::Tag;
 
-use DBI;
 use POSIX qw(locale_h);
-use HTML::Template;
 use locale;
 use Locale::gettext;
-use CGI;
-use CGI::Session;
-use Vhffs::User;
-use Vhffs::Main;
-use Vhffs::Panel::Main;
 use Vhffs::Panel::Group;
 
 =head1 NAME
@@ -56,28 +49,44 @@
 
 =head2 get_groups
 
-	Vhffs::Panel::Tag::get_groups($main, $tag_id, $start, $count)
+	Vhffs::Panel::Tag::get_groups($main, $category_name, $tag_name, $start)
 
-Fetches C<$count> groups associated to tag #C<$tag_id> starting
-at index C<$start>
+Fetches 10 groups associated to tag C<$tag_name> in (optional) category
+C<$category_name> starting at index C<$start>
 
 =cut
 
 sub get_groups {
-    my ($main, $tag_id, $start, $count) = @_;
+	my ($main, $category_name, $tag_name, $start) = @_;
 
-
-	my $select =  'SELECT g.gid, g.groupname, g.realname, o.description ';
-	my $restriction=	'FROM vhffs_groups g INNER JOIN vhffs_object o ON o.object_id=g.object_id '.
+	my $select =  'SELECT g.gid, g.groupname, g.realname, o.description, owner.username AS owner_name ';
+	my $restriction = ' FROM vhffs_groups g INNER JOIN vhffs_object o ON o.object_id=g.object_id '.
 		'INNER JOIN vhffs_object_tag ot ON ot.object_id = o.object_id '.
 		'INNER JOIN vhffs_tag t ON t.tag_id = ot.tag_id '.
-		'WHERE o.state = ? AND ot.tag_id = ?';
-    my @params;
-    push @params, Vhffs::Constants::ACTIVATED;
-    push @params, $tag_id;
+		'INNER JOIN vhffs_tag_category c ON t.category_id = c.tag_category_id '.
+		'INNER JOIN vhffs_users owner ON owner.uid = o.owner_uid '.
+		'WHERE o.state = ? AND t.label = ? ';
+	my @params;
+	push @params, Vhffs::Constants::ACTIVATED;
+	push @params, $tag_name;
+	if(defined $category_name) {
+		$restriction .= ' AND c.label = ?';
+		push @params, $category_name;
+	}
 
-    return Vhffs::Panel::Commons::fetch_slice_and_count($main, $select, $restriction, 
-        ' ORDER BY g.groupname', $start, $count, \@params, \&Vhffs::Panel::Group::fetch_groups_and_users);
+	my $limit = ' LIMIT 10';
+	$limit .= ' OFFSET '.($start * 10) if(defined $start);
+
+	my $groups = Vhffs::Panel::Group::fetch_groups_and_users($main, $select.$restriction.' ORDER BY g.groupname '.$limit, @params);
+
+	my $dbh = $main->get_db_object();
+
+	my $sth = $dbh->prepare('SELECT COUNT(*) '.$restriction);
+	return undef unless ( $sth->execute(@params) );
+
+	my ($count) = $sth->fetchrow_array();
+	
+	return ($groups, $count);
 }
 
 =head2 get_by_tag_ids

Added: trunk/vhffs-doc/config/apache/publicconf
===================================================================
--- trunk/vhffs-doc/config/apache/publicconf	                        (rev 0)
+++ trunk/vhffs-doc/config/apache/publicconf	2009-08-04 22:00:37 UTC (rev 1513)
@@ -0,0 +1,30 @@
+<VirtualHost *:80>
+
+        ServerAdmin adm@xxxxxxxxxx
+        ServerName projects.your.host
+        DocumentRoot /usr/share/vhffs/public
+        DirectoryIndex auth.pl index.pl
+
+        <Directory /usr/share/vhffs/public/>
+                AllowOverride FileInfo
+                Options ExecCGI FollowSymLinks
+                Order allow,deny
+                Allow from all
+                AddHandler cgi-script .pl
+        </Directory>
+
+	# Allows to have /tags/Pouet
+       <IfModule mod_rewrite.c>
+                RewriteEngine On
+                RewriteRule /tags/(.*)$ /tagsearch.pl?search=$1
+        </IfModule>
+
+        ErrorLog /var/log/apache2/projects-error.log
+
+        # Possible values include:
+        #   debug, info, notice, warn, error, crit, alert, emerg
+        LogLevel warn
+
+        CustomLog /var/log/apache2/projects-access.log combined
+        ServerSignature On
+</VirtualHost>

Modified: trunk/vhffs-public/Makefile.am
===================================================================
--- trunk/vhffs-public/Makefile.am	2009-08-04 20:41:57 UTC (rev 1512)
+++ trunk/vhffs-public/Makefile.am	2009-08-04 22:00:37 UTC (rev 1513)
@@ -11,6 +11,7 @@
 	index.pl \
 	lastgroups.pl \
 	lastusers.pl \
+	tagsearch.pl \
 	usersearch.pl \
 	usersearch_form.pl \
 	extern/newgroupsrss.pl \

Added: trunk/vhffs-public/tagsearch.pl
===================================================================
--- trunk/vhffs-public/tagsearch.pl	                        (rev 0)
+++ trunk/vhffs-public/tagsearch.pl	2009-08-04 22:00:37 UTC (rev 1513)
@@ -0,0 +1,80 @@
+#!%PERL%
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions 
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright 
+#   notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in 
+#   the documentation and/or other materials provided with the 
+#   distribution.
+#3. Neither the name of vhffs nor the names of its contributors 
+#   may be used to endorse or promote products derived from this 
+#   software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Tags navigation (/tags/Pouet)
+
+use strict;
+use utf8;
+
+use POSIX qw(locale_h);
+use locale;
+use Locale::gettext;
+
+use lib '%VHFFS_LIB_DIR%';
+
+use Vhffs::Panel::Tag;
+use Vhffs::Panel::Public;
+use Vhffs::Panel::Commons;
+
+my $panel = new Vhffs::Panel::Public();
+
+my $cgi = $panel->{cgi};
+
+
+my $search = Encode::decode_utf8($cgi->param('search'));
+# TODO Handle complicated search patterns
+my ($category, $tag) = split /::/, $search;
+unless(defined $tag) {
+	$tag = $category;
+	$category = undef;
+}
+
+# current page
+my $page = defined($cgi->param('page')) ? int($cgi->param('page')) : 1;
+
+my ($groups, $count) = Vhffs::Panel::Tag::get_groups($panel->{vhffs}, $category, $tag, $page - 1);
+
+if(scalar(@$groups) == 0) {
+	$panel->render('common/error.tt', {
+		message => gettext('No group found')
+	});
+	exit(0);
+}
+
+my $pager = Vhffs::Panel::Commons::get_pager($page, $count, 10, 5, $panel->{url}, { search => $search});
+
+my $vars = {
+	groups => $groups,
+	gs_title => gettext( 'Search results' ),
+	gs_pager => $pager
+};
+
+$panel->render('content/groupsearch-results.tt', $vars);


Property changes on: trunk/vhffs-public/tagsearch.pl
___________________________________________________________________
Name: svn:executable
   + *


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/