From a101cd2d8232c57ccb47b6f89547bf684d49f91c Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 28 May 2008 20:31:28 -0500 Subject: [PATCH] Tags AJAX integration on OPAC details page, so it behaves like results. Also, prevent duplicate tags (same user, biblio and term). Strip leading/trailing whitespace from term. Block whitespace terms. The CSS for details could be enhanced to emphasize tagstatus more. Signed-off-by: Joshua Ferraro --- C4/Tags.pm | 32 ++++++++++++++----- koha-tmpl/opac-tmpl/prog/en/js/tags.js | 2 +- .../prog/en/modules/opac-detail.tmpl | 7 ++-- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/C4/Tags.pm b/C4/Tags.pm index f706ffccba..09e59934b4 100644 --- a/C4/Tags.pm +++ b/C4/Tags.pm @@ -531,18 +531,25 @@ sub add_tag ($$;$$) { # biblionumber,term,[borrowernumber,approvernumber] my $biblionumber = shift or return undef; my $term = shift or return undef; my $borrowernumber = (@_) ? shift : 0; # the user, default to kohaadmin - - # first, add to tags regardless of approaval + $term =~ s/^\s+//; + $term =~ s/\s+$//; + ($term) or return undef; # must be more than whitespace + my $rows = get_tag_rows({biblionumber=>$biblionumber, borrowernumber=>$borrowernumber, term=>$term, limit=>1}); my $query = "INSERT INTO tags_all (borrowernumber,biblionumber,term,date_created) VALUES (?,?,?,NOW())"; $debug and print STDERR "add_tag query:\n $query\n", "add_tag query args: ($borrowernumber,$biblionumber,$term)\n"; + if (scalar @$rows) { + $debug and carp "Duplicate tag detected. Tag not added."; + return undef; + } + # add to tags_all regardless of approaval my $sth = C4::Context->dbh->prepare($query); $sth->execute($borrowernumber,$biblionumber,$term); # then - if (@_) { # if an arg remains, it is the borrowernumber of the approver: tag is pre-approved. + if (@_) { # if an arg remains, it is the borrowernumber of the approver: tag is pre-approved. Note, whitelist unaffected. my $approver = shift; add_tag_approval($term,$approver); add_tag_index($term,$biblionumber,$approver); @@ -620,12 +627,19 @@ trying to calculate that and the "weight" (number of times a tag appears) on the biblionumber - book record it is attached to weight - number of times tag applied by any user -tags_blacklist - TODO +tags_blacklist - A set of regular expression filters. Unsurprisingly, these should be perl- +compatible (PCRE) for your version of perl. Since this is a blacklist, a term will be +blocked if it matches any of the given patterns. WARNING: do not add blacklist regexps +if you do not understand their operation and interaction. It is quite easy to define too +simple or too complex a regexp and effectively block all terms. The blacklist operation is +fairly resource intensive, since every line of tags_blacklist will need to be read and compared. +It is recommended that tags_blacklist be used minimally, and only by an administrator with an +understanding of regular expression syntax and performance. -So the best way to think about the different tabes is that they are each tailored to a certain +So the best way to think about the different tables is that they are each tailored to a certain use. Note that tags_approval and tags_index do not rely on the user's borrower mapping, so -the tag population can continue to grow even if a user is removed, along with the corresponding -rows in tags_all. +the tag population can continue to grow even if a user (along with their corresponding +rows in tags_all) is removed. =head2 Tricks @@ -664,8 +678,10 @@ mysql> select biblionumber from biblio where title LIKE "%Health%"; +--------------+ 26 rows in set (0.00 sec) -Then, take those numbers and type them into this perl command line: +Then, take those numbers and type/pipe them into this perl command line: perl -ne 'use C4::Tags qw(get_tags add_tag); use Data::Dumper;chomp; add_tag($_,"health",51,1); print Dumper get_tags({limit=>5,term=>"health",});' +Note, the borrowernumber in this example is 51. Use your own or any arbitrary valid borrowernumber. + =cut diff --git a/koha-tmpl/opac-tmpl/prog/en/js/tags.js b/koha-tmpl/opac-tmpl/prog/en/js/tags.js index 62c66b2fdb..95f3d19537 100644 --- a/koha-tmpl/opac-tmpl/prog/en/js/tags.js +++ b/koha-tmpl/opac-tmpl/prog/en/js/tags.js @@ -69,7 +69,7 @@ KOHA.Tags = { scrubbed_all_bad : function(arg) {return ("Error! Your tag was entirely markup code. It was NOT added. Please try again with plain text.");}, badparam : function(arg) {return ("Error! Illegal parameter '" +arg+ "'.");}, scrubbed : function(arg) {return ("Note: your tag contained markup code that was removed. The tag was added as '" +arg+ "'.");}, - failed_add_tag : function(arg) {return ("Error! The add_tag operation failed on '" +arg+ "'.");}, + failed_add_tag : function(arg) {return ("Error! The add_tag operation failed on '" +arg+ "'. Note: you can only tag an item with a given term once. Check 'My Tags' to see your current tags.");}, failed_delete : function(arg) {return ("Error! You cannot delete the tag '" +arg+ "'. Note: you can only delete your own tags.");}, }, }; diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl index 83c4309478..540263de5e 100755 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tmpl @@ -18,6 +18,7 @@ }); KOHA.Google.GetCoverFromIsbn(); + $(".tagbutton").click(KOHA.Tags.add_tag_button); }); //]]> @@ -193,13 +194,13 @@ Add
" method="post" action="/cgi-bin/koha/opac-tags.pl" id="tagform"> " id="newtag" maxlength="100" /> - + " type="submit" value="Add" /> Cancel
-
- " class="tagstatus" style="display:none;"> + _status" class="tagstatus" style="display:none;"> Tag status here. +