[Cpan-forum-commit] rev 26 - in trunk: lib/CPAN lib/CPAN/Forum templates

svn at pti.co.il svn at pti.co.il
Mon Jan 17 02:26:48 IST 2005


Author: gabor
Date: 2005-01-17 02:26:47 +0200 (Mon, 17 Jan 2005)
New Revision: 26

Added:
   trunk/templates/module_select_form.tmpl
Modified:
   trunk/lib/CPAN/Forum.pm
   trunk/lib/CPAN/Forum/Groups.pm
   trunk/templates/module_search_form.tmpl
Log:
search for module name before selecting one to write something

Modified: trunk/lib/CPAN/Forum/Groups.pm
===================================================================
--- trunk/lib/CPAN/Forum/Groups.pm	2005-01-16 23:05:00 UTC (rev 25)
+++ trunk/lib/CPAN/Forum/Groups.pm	2005-01-17 00:26:47 UTC (rev 26)
@@ -4,9 +4,12 @@
 use Carp;
 use base 'CPAN::Forum::DBI';
 __PACKAGE__->table('groups');
-__PACKAGE__->columns(All => qw/id name gtype status/);
-__PACKAGE__->has_many(posts => "CPAN::Forum::Posts");
+__PACKAGE__->columns(All     => qw/id name gtype status/);
+#__PACKAGE__->columns(Primary => qw/id name/);
+__PACKAGE__->has_many(posts  => "CPAN::Forum::Posts");
 __PACKAGE__->has_many(subscriptions => "CPAN::Forum::Subscriptions");
 
+__PACKAGE__->set_sql(count_like   => "SELECT count(*) FROM __TABLE__ WHERE %s LIKE '%s'");
+__PACKAGE__->set_sql(count   => "SELECT count(*) FROM __TABLE__ WHERE %s = '%s'");
 1;
 

Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm	2005-01-16 23:05:00 UTC (rev 25)
+++ trunk/lib/CPAN/Forum.pm	2005-01-17 00:26:47 UTC (rev 26)
@@ -486,6 +486,7 @@
 			new_post process_post
 			mypan 
 			response_form 
+			module_search
 			selfconfig change_password update_subscription); 
 			
 my @urls = qw(
@@ -563,11 +564,6 @@
 		$self->header_props(-url => "http://$ENV{HTTP_HOST}/login/");
 		return;
 	}
-
-
-	#my ($field) = CPAN::Forum::Configure->search({field => "from"});
-	#$FROM = $field->value;
-	#$self->log->debug("FROM field set to be $FROM");
 }
 
 
@@ -946,13 +942,15 @@
 	my @group_ids;
 	
 	if ($group_id) {
-		@group_ids = ($group_id);
-		$group_labels{$group_id} = $group_name;
+		if (ref $group_id eq "ARRAY") {
+			@group_ids = @$group_id;
+			@group_labels{@$group_id} = @$group_name;
+		} else {
+			@group_ids = ($group_id);
+			$group_labels{$group_id} = $group_name;
+		}
 	}
 
-	if ($q->param('q')) {
-		# TODO
-	}
 
 	my $cache = $self->param("ROOT") . "/db/modules.txt";
 	if (not @group_ids and open my $fh, $cache) {
@@ -1001,9 +999,10 @@
 }
 
 
-sub _module_serach_form {
-	my ($self) = @_;
+sub module_serach_form {
+	my ($self, $errors) = @_;
 	my $t = $self->load_tmpl("module_search_form.tmpl");
+	$t->param($_=>1) foreach @$errors;
 	$t->output;
 }
 
@@ -1030,6 +1029,7 @@
 	
 	if ($rm eq "new_post") {
 		$new_group = ${$self->param("path_parameters")}[0] || "";
+		$new_group_id = $q->param('new_group') if $q->param('new_group');
 		
 		if ($new_group) {
 			if ($new_group =~ /^([\w-]+)$/) {
@@ -1045,11 +1045,19 @@
 				cluck "Bad regex for '$new_group' ? Accessed PATH_INFO: '$ENV{PATH_INFO}'";
 				return $self->internal_error;
 			}
+		} elsif ($new_group_id) {
+			my ($gr) = CPAN::Forum::Groups->retrieve($new_group_id);
+			if ($gr) {
+				$new_group = $gr->name;
+			} else {
+				cluck "Group '$new_group_id' was not in database when accessed PATH_INFO: '$ENV{PATH_INFO}'";
+				return $self->internal_error;
+			}
 		} elsif ($q->param('q')) {
 			# process search later	
 		} else {
-			# TODO should be called whent the _module_search is ready
-			#return $self->_module_serach_form();
+			# TODO should be called whent the module_search is ready
+			return $self->module_serach_form();
 		}
 	}
 	if ($rm eq "process_post") {
@@ -1570,23 +1578,43 @@
 
 
 # partially written code to select a module name
-sub _module_search {
+sub module_search {
 	my ($self) = @_;
 
 	my $q = $self->query;
 	my $txt = $q->param("q");
 
-	# kill the taint checking (why do I use taint checking if I kill it then ?)
-	if ($txt =~ /(.*)/) {
+	# remove taint if there is
+	if ($txt =~ /^([\w:.%-]+)$/) {
 		$txt = $1;
+	} else {
+		$self->log->debug("Tained search: $txt");
 	}
 
-	if ($txt) {
-		if ($txt =~ /%/) {
-			my $it =  CPAN::Forum::Groups->search_like(name => $txt);
-			my $cnt = CPAN::Forum::Groups->sql_count_like("name", $txt)->select_val;
-		}
+	if (not $txt) {
+		return $self->module_serach_form(['invalid_search_term']);
 	}
+	$self->log->debug("group name search term: $txt");
+	$txt = '%' . $txt . '%';
+	
+	my $it =  CPAN::Forum::Groups->search_like(name => $txt);
+	my $cnt = CPAN::Forum::Groups->sql_count_like("name", $txt)->select_val;
+	my @group_names;
+	my @group_ids;
+	while (my $group  = $it->next) {
+		push @group_names, $group->name;
+		push @group_ids, $group->id;
+	}
+	if (not @group_names) {
+		return $self->module_serach_form(['no_module_found']);
+	}
+	
+	#$self->log->debug("GROUP NAMES: @group_names");
+
+	my $t = $self->load_tmpl("module_select_form.tmpl",
+	);
+	$t->param("group_selector" => $self->_group_selector(\@group_names, \@group_ids));
+	$t->output;
 }
 
 =head2 search

Modified: trunk/templates/module_search_form.tmpl
===================================================================
--- trunk/templates/module_search_form.tmpl	2005-01-16 23:05:00 UTC (rev 25)
+++ trunk/templates/module_search_form.tmpl	2005-01-17 00:26:47 UTC (rev 26)
@@ -2,14 +2,17 @@
 <p id="pageTitle">Search for module name</p>
 
 <TMPL_INCLUDE NAME="navigation.tmpl">
+<p class="error">
+<TMPL_IF invalid_search_term>Invalid or missing search term</TMPL_IF><br />
+<TMPL_IF no_module_found>No module found</TMPL_IF><br />
+</p>
 <p>
-Please type in the name of a module.
-You can use '%' signs as wide cards.
+Please search for the name of a module.
 </p>
 
 <form method="post" action="/module_search/">
 <p>
-<input type="hidden" name="rm" value="search" />
+<input type="hidden" name="rm" value="module_search" />
 <input name="q" value="<TMPL_VAR q>" />
 <input type="submit" value="Search" />
 </p>

Added: trunk/templates/module_select_form.tmpl
===================================================================
--- trunk/templates/module_select_form.tmpl	2005-01-16 23:05:00 UTC (rev 25)
+++ trunk/templates/module_select_form.tmpl	2005-01-17 00:26:47 UTC (rev 26)
@@ -0,0 +1,20 @@
+<TMPL_INCLUDE NAME="head.tmpl">
+<p id="pageTitle">Select the module name to write about</p>
+
+<TMPL_INCLUDE NAME="navigation.tmpl">
+<p class="error">
+<TMPL_IF invalid_search_term>Invalid or missing search term</TMPL_IF>
+</p>
+<p>
+</p>
+
+<form method="post" action="/new_post/">
+<p>
+<input type="hidden" name="rm" value="new_post" />
+<TMPL_VAR group_selector>
+<input type="submit" value="Select" />
+</p>
+</form>
+
+<TMPL_INCLUDE NAME="footer.tmpl">
+



More information about the Cpan-forum-commit mailing list