From f3ea54e2f1e0e89b58f74689ab539f06dde93372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick?= Date: Wed, 19 Mar 2014 13:52:02 -0400 Subject: [PATCH] Add an URL validation plugin for authority and biblio frameworks. http://bugs.koha-community.org/show_bug.cgi?id=8609 --- C4/Installer/PerlDependencies.pm | 5 + cataloguing/value_builder/url.pl | 103 +++++++++++++++++++++ .../prog/en/modules/authorities/authorities.tt | 4 + .../prog/en/modules/cataloguing/addbiblio.tt | 4 + .../prog/en/modules/cataloguing/additem.tt | 5 + .../prog/en/modules/tools/batchMod-edit.tt | 5 + 6 files changed, 126 insertions(+) create mode 100644 cataloguing/value_builder/url.pl diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index ad1f5a6..0f0b3e4 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -742,6 +742,11 @@ our $PERL_DEPS = { 'required' => '0', 'min_ver' => '5.836', }, + 'Regexp::Common::URI' => { + 'usage' => 'URL validation value_builder', + 'required' => '0', + 'min_ver' => '2010010201', + }, }; 1; diff --git a/cataloguing/value_builder/url.pl b/cataloguing/value_builder/url.pl new file mode 100644 index 0000000..6402c53 --- /dev/null +++ b/cataloguing/value_builder/url.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl + + +# Copyright 2010 Frédérick Capovilla - Libéo +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use strict; +use warnings; +no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings + +use C4::Context; +use Regexp::Common qw( URI ); + +=head1 + +plugin_parameters : other parameters added when the plugin is called by the dopop function + +=cut + +sub plugin_parameters { + return ""; +} + +=head1 + +plugin_javascript : the javascript function called when the user enters the subfield. +contain 3 javascript functions : +* one called when the field is entered (OnFocus). Named FocusXXX +* one called when the field is leaved (onBlur). Named BlurXXX +* one called when the ... link is clicked () named ClicXXX + +returns : +* XXX +* a variable containing the 3 scripts. +the 3 scripts are inserted after the in the html code + +=cut + +sub plugin_javascript { + my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_; + my $function_name = $field_number; + my @split_field_name = split(/_/, $field_number); + my $field_name = $split_field_name[1] . '$' . $split_field_name[3]; + my $regex = $RE{URI}; + $regex =~ s/\//\\\//g; + + my $res = < +// + +END_OF_JS +return ($function_name,$res); +} + +=head1 + +plugin : the true value_builded. The screen that is open in the popup window. + +=cut + +sub plugin { + return ""; +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt index ea47100..1bb2724 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt @@ -122,6 +122,10 @@ function confirmnotdup(redirect){ $("#confirm_not_duplicate").attr("value","1"); Check(); } +// For the url.pl value_builder validation +function invalid_url_alert(field_name) { + alert(_("The field ") + field_name + _(" must contain a valid URL!\nex : http://www.google.com")); +} //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt index 790a57b..e3634bb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -362,6 +362,10 @@ function Changefwk(FwkList) { f.submit(); } +// For the url.pl value_builder validation +function invalid_url_alert(field_name) { + alert(_("The field ") + field_name + _(" must contain a valid URL!\nex : http://www.google.com")); +} //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 85a4486..066ea2b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -99,6 +99,11 @@ $(document).ready(function() { function () {$(this).removeClass("highlight");} ); }); + +// For the url.pl value_builder validation +function invalid_url_alert(field_name) { + alert(_("The field ") + field_name + _(" must contain a valid URL!\nex : http://www.google.com")); +} //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt index ab9c2de..e7d0ddb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt @@ -33,6 +33,11 @@ $(document).ready(function(){ }); }); + +// For the url.pl value_builder validation +function invalid_url_alert(field_name) { + alert(_("The field ") + field_name + _(" must contain a valid URL!\nex : http://www.google.com")); +} //]]>