[vhffs-dev] [1219] Added tag clouds, associated search coming soon.

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


Revision: 1219
Author:   beuss
Date:     2008-06-06 00:42:40 +0200 (Fri, 06 Jun 2008)

Log Message:
-----------
Added tag clouds, associated search coming soon.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Tag.pm
    trunk/vhffs-public/index.pl
    trunk/vhffs-public/templates/index.tmpl
    trunk/vhffs-themes/vhffs/main.css


Modified: trunk/vhffs-api/src/Vhffs/Tag.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Tag.pm	2008-06-05 21:51:10 UTC (rev 1218)
+++ trunk/vhffs-api/src/Vhffs/Tag.pm	2008-06-05 22:42:40 UTC (rev 1219)
@@ -125,6 +125,87 @@
 		FROM vhffs_tag WHERE category_id = ? ORDER BY label}, $category_id);
 }
 
+sub get_most_popular_tags {
+	use POSIX;	# ceil
+	
+	my ($main, $visibility) = @_;
+	$visibility = Vhffs::Constants::TAG_VISIBILITY_PUBLIC unless(defined $visibility);
+	my $tags = [];
+	
+	my $dbh = $main->get_db_object();
+	
+	my $sql = 
+q{SELECT MAX(c) AS max_count FROM 
+(SELECT COUNT(*) AS c
+FROM vhffs_object_tag ot
+INNER JOIN vhffs_tag t ON t.tag_id = ot.tag_id
+INNER JOIN vhffs_tag_category c ON c.tag_category_id = t.category_id
+WHERE c.visibility <= ?
+GROUP BY t.tag_id) AS counts};
+	my $sth = $dbh->prepare($sql);
+	return undef unless($sth->execute($visibility));
+	my $max_count = $sth->fetchrow_hashref()->{max_count};
+	
+	$sql = 
+q{SELECT c.tag_category_id AS category_id, c.label AS category_label, c.description AS category_description,
+t.tag_id AS tag_id, t.label AS tag_label, t.description AS tag_description, COUNT(*) AS object_count
+FROM vhffs_tag t
+INNER JOIN vhffs_tag_category c ON c.tag_category_id = t.category_id
+INNER JOIN vhffs_object_tag ot ON ot.tag_id = t.tag_id
+WHERE c.visibility <= ?
+GROUP BY t.tag_id, t.label, t.description, c.tag_category_id, c.label, c.description
+ORDER BY object_count DESC
+LIMIT 10};
+	$sth = $main->get_db_object->prepare($sql);
+	$sth->execute($visibility) or return undef;
+	while( (my $t = $sth->fetchrow_hashref() )  ) {
+		$t->{weight} = ceil($t->{object_count} * 10 / $max_count);
+		push @$tags, $t;
+	}
+	return $tags; 
+}
+
+sub get_random_tags {
+	use POSIX;	# ceil
+	
+	my ($main, $visibility) = @_;
+	$visibility = Vhffs::Constants::TAG_VISIBILITY_PUBLIC unless(defined $visibility);
+	my $tags = [];
+	
+	my $dbh = $main->get_db_object();
+	
+	my $sql = 
+q{SELECT MAX(c) AS max_count FROM 
+(SELECT COUNT(*) AS c
+FROM vhffs_object_tag ot
+INNER JOIN vhffs_tag t ON t.tag_id = ot.tag_id
+INNER JOIN vhffs_tag_category c ON c.tag_category_id = t.category_id
+WHERE c.visibility <= ?
+GROUP BY t.tag_id) AS counts};
+	my $sth = $dbh->prepare($sql);
+	return undef unless($sth->execute($visibility));
+	my $max_count = $sth->fetchrow_hashref()->{max_count};
+	
+	$sql = 
+q{SELECT c.tag_category_id AS category_id, c.label AS category_label, c.description AS category_description,
+t.tag_id AS tag_id, t.label AS tag_label, t.description AS tag_description, COUNT(*) AS object_count
+FROM vhffs_tag t
+INNER JOIN vhffs_tag_category c ON c.tag_category_id = t.category_id
+INNER JOIN vhffs_object_tag ot ON ot.tag_id = t.tag_id
+WHERE c.visibility <= ?
+GROUP BY t.tag_id, t.label, t.description, c.tag_category_id, c.label, c.description
+ORDER BY RANDOM()
+LIMIT 10};
+	$sth = $main->get_db_object->prepare($sql);
+	$sth->execute($visibility) or return undef;
+	while( (my $t = $sth->fetchrow_hashref() )  ) {
+		$t->{weight} = ceil($t->{object_count} * 10 / $max_count);
+		push @$tags, $t;
+	}
+	return $tags; 
+}
+
+
 =head2
 	Vhffs::Tag::_fetch_tags($main, $sql, @params)
 

Modified: trunk/vhffs-public/index.pl
===================================================================
--- trunk/vhffs-public/index.pl	2008-06-05 21:51:10 UTC (rev 1218)
+++ trunk/vhffs-public/index.pl	2008-06-05 22:42:40 UTC (rev 1219)
@@ -45,6 +45,7 @@
 use Vhffs::Constants;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Template;
+use Vhffs::Tag;
 
 my $panel = new Vhffs::Panel::Main();
 exit 0 unless $panel;
@@ -59,8 +60,10 @@
 my $template;
 my $subtemplate;
 
-$template = new Vhffs::Panel::Template( filename => $templatedir."/public/index.tmpl" );
+$template = new Vhffs::Panel::Template( filename => $templatedir.'/public/index.tmpl', die_on_bad_params => 0 );
 
+$template->param( TOP_TAGS => Vhffs::Tag::get_most_popular_tags($vhffs) );
+$template->param( RANDOM_TAGS => Vhffs::Tag::get_random_tags($vhffs) );
 
 $template->param( TEXT_TITLE => sprintf( gettext("%s public area") , $vhffs->get_config->get_host_name)  );
 

Modified: trunk/vhffs-public/templates/index.tmpl
===================================================================
--- trunk/vhffs-public/templates/index.tmpl	2008-06-05 21:51:10 UTC (rev 1218)
+++ trunk/vhffs-public/templates/index.tmpl	2008-06-05 22:42:40 UTC (rev 1219)
@@ -20,6 +20,7 @@
     </fieldset>
 
     <h2><TMPL_I18N KEY="Groups/Projects"></h2>
+    <h3><TMPL_I18N KEY="Project search"></h3>
     <ul>
         <li><a href="/lastgroups.pl"><TMPL_I18N KEY="Last Groups"></a></li>
         <li><a href="/allgroups.pl"><TMPL_I18N KEY="All Groups"></a></li>
@@ -34,7 +35,22 @@
             <p><input type="submit" name="search_group_submit" value="<TMPL_I18N KEY="Search">"/></p>
         </form>
    </fieldset>
-
+	<TMPL_IF NAME="TOP_TAGS">
+	<h3><TMPL_I18N KEY="Most popular tags"></h3>
+	<TMPL_LOOP NAME="TOP_TAGS">
+		<span class="tag-<TMPL_VAR NAME="WEIGHT">">
+			<a href="#" title="<TMPL_VAR ESCAPE=1 NAME="CATEGORY_DESCRIPTION">"><TMPL_VAR NAME="CATEGORY_LABEL"></a>::<a href="#" title="<TMPL_VAR ESCAPE=1 NAME="TAG_DESCRIPTION">"><TMPL_VAR NAME="TAG_LABEL"></a>
+		</span>
+	</TMPL_LOOP>
+	</TMPL_IF>
+	<TMPL_IF NAME="RANDOM_TAGS">
+	<h3><TMPL_I18N KEY="Random tags"></h3>
+	<TMPL_LOOP NAME="RANDOM_TAGS">
+		<span class="tag-<TMPL_VAR NAME="WEIGHT">">
+			<a href="#" title="<TMPL_VAR ESCAPE=1 NAME="CATEGORY_DESCRIPTION">"><TMPL_VAR NAME="CATEGORY_LABEL"></a>::<a href="#" title="<TMPL_VAR ESCAPE=1 NAME="TAG_DESCRIPTION">"><TMPL_VAR NAME="TAG_LABEL"></a>
+		</span>
+	</TMPL_LOOP>
+	</TMPL_IF>
     <h2><TMPL_I18N KEY="Websites"></h2>
     <ul>
         <li><a href="/allwebsites.pl"><TMPL_I18N KEY="All Websites"></a></li>

Modified: trunk/vhffs-themes/vhffs/main.css
===================================================================
--- trunk/vhffs-themes/vhffs/main.css	2008-06-05 21:51:10 UTC (rev 1218)
+++ trunk/vhffs-themes/vhffs/main.css	2008-06-05 22:42:40 UTC (rev 1219)
@@ -818,3 +818,49 @@
 	display: inline;
 	float:none;
 }
+
+/* Tags */
+span.tag-10 {
+	font-weight: bold;
+	font-size: 15pt;
+}
+
+span.tag-9 {
+	font-weight: bold;
+	font-size: 14.5pt;
+}
+
+span.tag-8 {
+	font-weight: bold;
+	font-size: 14pt;
+}
+
+span.tag-7 {
+	font-weight: bold;
+	font-size: 13.5pt;
+}
+
+span.tag-6 {
+	font-weight: bold;
+	font-size: 13pt;
+}
+
+span.tag-5 {
+	font-size: 12.5pt;
+}
+
+span.tag-4 {
+	font-size: 12pt;
+}
+
+span.tag-3 {
+	font-size: 11.5pt;
+}
+
+span.tag-2 {
+	font-size: 11pt;
+}
+
+span.tag-1 {
+	font-size: 10.5pt;
+}


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