From 3d3d0a2adf1c5bfee45e9c72e349bc4ab65b3af0 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Fri, 19 Sep 2014 00:37:17 -0400 Subject: [PATCH] Bug 5010 - Fix OPACBaseURL to include protocol First, it is strongly recommended to set the OPACBaseURL. But this patch allows the inclusion of the protocol and not just a site. Next, C4/Auth now puts OPACBaseURL into the template parameters regardless of OPAC or Staff clients. In the staff client, once the OPACBaseURL is set, you get a nice OPAC View link when viewing a biblio's detail. It should reflect the protocol used now. Hard coded 'http://' strings were removed from the sample_notices.sql files. This is what required also updating the letters table in the updatedatabase.pl script. The explanation text in the sysprefs.sql needed updating too to reflect the inclusion of the protocol. And this was the other update done in the updatedatabase.pl script. The opac.pref file was similarly changed as well. catalogue/detail.pl had no need to pass a custom OpacUrl value, since C4/Auth passes the required OPACBaseURL, so it and the corresponding template were modified. Both the MARC21 and NORMARC intranet details files had 'http://' hard coded in them. This was removed. Both the bootstrap and prog theme opac-detail template had a protocol parameter that was used. The logic for the parameter was not removed, because it is used extensively in one template. Perhaps it should be used to simplify the other. However, the calculated current_url parameter had references to the protocol removed, because of the changes to OPACBaseURL. opac/opac-shareshelf.pl had a hard coded 'http://' which was removed. t/db_dependent/Auth_with_cas.t had 'http://' added to the value set for OPACBaseURL. In virtualshelves/sendshelf.pl explicit code which sent the OPACBaseURL preference was removed, since C4/Auth sends it all the time now. C4::Context::set_preference was tweaked to ensure that OPACBaseURL would always start with http. TEST PLAN --------- Not done yet --- C4/Auth.pm | 7 +----- C4/Context.pm | 5 +++++ catalogue/detail.pl | 6 ----- .../data/mysql/de-DE/mandatory/sample_notices.sql | 2 +- .../data/mysql/en/mandatory/sample_notices.sql | 2 +- .../mysql/nb-NO/1-Obligatorisk/sample_notices.sql | 2 +- installer/data/mysql/sysprefs.sql | 2 +- installer/data/mysql/updatedatabase.pl | 23 +++++++++++++++++++- .../prog/en/modules/admin/preferences/opac.pref | 4 ++-- .../prog/en/modules/catalogue/detail.tt | 4 ++-- .../prog/en/xslt/MARC21slim2intranetDetail.xsl | 2 +- .../prog/en/xslt/NORMARCslim2intranetDetail.xsl | 2 +- .../opac-tmpl/bootstrap/en/modules/opac-detail.tt | 10 ++++----- koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 10 ++++----- opac/opac-shareshelf.pl | 3 +-- t/db_dependent/Auth_with_cas.t | 2 +- virtualshelves/sendshelf.pl | 4 ---- 17 files changed, 50 insertions(+), 40 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 2b8a036..181bc48 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -339,6 +339,7 @@ sub get_template_and_user { noItemTypeImages => C4::Context->preference("noItemTypeImages"), marcflavour => C4::Context->preference("marcflavour"), persona => C4::Context->preference("persona"), + OPACBaseURL => C4::Context->preference('OPACBaseURL'), ); if ( $in->{'type'} eq "intranet" ) { $template->param( @@ -405,11 +406,6 @@ sub get_template_and_user { } elsif (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv && C4::Context->userenv->{'branch'}) { $opac_name = C4::Context->userenv->{'branch'}; } - # FIXME Under Plack the CGI->https method always returns 'OFF' ($using_https will be set to 0 in this case) - my $opac_base_url = C4::Context->preference("OPACBaseURL"); #FIXME uses $using_https below as well - if (!$opac_base_url){ - $opac_base_url = $ENV{'SERVER_NAME'} . ($ENV{'SERVER_PORT'} eq ($using_https ? "443" : "80") ? '' : ":$ENV{'SERVER_PORT'}"); - } $template->param( opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"), AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"), @@ -430,7 +426,6 @@ sub get_template_and_user { OPACMobileUserCSS => "". C4::Context->preference("OPACMobileUserCSS"), OPACViewOthersSuggestions => "" . C4::Context->preference("OPACViewOthersSuggestions"), OpacAuthorities => C4::Context->preference("OpacAuthorities"), - OPACBaseURL => ($using_https ? "https://" : "http://") . $opac_base_url, opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'}, opac_search_limit => $opac_search_limit, opac_limit_override => $opac_limit_override, diff --git a/C4/Context.pm b/C4/Context.pm index 63e8ebe..88d289c 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -637,6 +637,11 @@ sub set_preference { $value = 0 if ( $type && $type eq 'YesNo' && $value eq '' ); + // force explicit protocol on OPACBaseURL + if ($var eq 'opacbaseurl' && substr($value,0,4) !~ /http/) { + $value = 'http://' . $value; + } + my $sth = $dbh->prepare( " INSERT INTO systempreferences ( variable, value ) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 967d71d..134100b 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -396,12 +396,6 @@ if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->p $template->param( C4::HTML5Media->gethtml5media($record)); } - -# Get OPAC URL -if (C4::Context->preference('OPACBaseURL')){ - $template->param( OpacUrl => C4::Context->preference('OPACBaseURL') ); -} - # Displaying tags my $tag_quantity; diff --git a/installer/data/mysql/de-DE/mandatory/sample_notices.sql b/installer/data/mysql/de-DE/mandatory/sample_notices.sql index 01ae5d4..2b45bcc 100644 --- a/installer/data/mysql/de-DE/mandatory/sample_notices.sql +++ b/installer/data/mysql/de-DE/mandatory/sample_notices.sql @@ -100,7 +100,7 @@ VALUES ( Ihr Bibliothekskonto wurde angelegt. Bitte bestätigen Sie Ihre E-Mail-Adresse indem Sie auf folgenden Link klicken: -http://<>/cgi-bin/koha/opac-registration-verify.pl?token=<> +<>/cgi-bin/koha/opac-registration-verify.pl?token=<> Wenn Sie keine Kontoanmeldung durchgeführt haben, können Sie diese Benachrichtigung ignorieren. Sie wird in Kürze ungültig. diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql index 2281739..0361f99 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ b/installer/data/mysql/en/mandatory/sample_notices.sql @@ -113,7 +113,7 @@ VALUES ( Your library account has been created. Please verify your email address by clicking this link to complete the signup process: -http://<>/cgi-bin/koha/opac-registration-verify.pl?token=<> +<>/cgi-bin/koha/opac-registration-verify.pl?token=<> If you did not initiate this request, you may safely ignore this one-time message. The request will expire shortly.' ); diff --git a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql b/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql index f1e8fb0..bbd9049 100644 --- a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql +++ b/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql @@ -134,7 +134,7 @@ VALUES ( D har blitt registrert som bruker av biblioteket. Verifiser epostadressen din ved å klikke på lenka nedenfor: -http://<>/cgi-bin/koha/opac-registration-verify.pl?token=<> +<>/cgi-bin/koha/opac-registration-verify.pl?token=<> Dersom du ikke har bedt om å bli registret som bruker av biblioteket kan du se bort fra denne engangsmeldingen. Forespørselen vil snart gå ut på dato.' ); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index b06b163..8e0ee9d 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -222,7 +222,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OPACAllowUserToChooseBranch','1','1','Allow the user to choose the branch they want to pickup their hold from','YesNo'), ('OPACAmazonCoverImages','0','','Display cover images on OPAC from Amazon Web Services','YesNo'), ('OpacAuthorities','1',NULL,'If ON, enables the search authorities link on OPAC','YesNo'), -('OPACBaseURL',NULL,NULL,'Specify the Base URL of the OPAC, e.g., opac.mylibrary.com, the http:// will be added automatically by Koha.','Free'), +('OPACBaseURL',NULL,NULL,'Specify the Base URL of the OPAC, e.g., http://opac.mylibrary.com, including the protocol (http:// or https://). Otherwise, the http:// will be added automatically by Koha upon saving.','Free'), ('opacbookbag','1','','If ON, enables display of Cart feature','YesNo'), ('OpacBrowser','0',NULL,'If ON, enables subject authorities browser on OPAC (needs to set misc/cronjob/sbuild_browser_and_cloud.pl)','YesNo'), ('OpacBrowseResults','1',NULL,'Disable/enable browsing and paging search results from the OPAC detail page.','YesNo'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index aae80f1..ad5bab5 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8766,7 +8766,6 @@ if(CheckVersion($DBversion)) { SetVersion($DBversion); } - $DBversion = '3.17.00.025'; if ( CheckVersion($DBversion) ) { $dbh->do(qq{ @@ -8776,6 +8775,28 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = '3.17.00.XXX'; +if ( CheckVersion($DBversion) ) { + my $OPACBaseURL = C4::Context->preference('OPACBaseURL'); + if (defined($OPACBaseURL) && substr($OPACBaseURL,0,4) ne "http") { + my $explanation = q{Specify the Base URL of the OPAC, e.g., http://opac.mylibrary.com, including the protocol (http:// or https://). Otherwise, the http:// will be added automatically by Koha upon saving.}; + $OPACBaseURL = 'http://' . $OPACBaseURL; + my $sth_OPACBaseURL = $dbh->prepare( q{ + UPDATE systempreferences SET value=?,explanation=? + WHERE variable='OPACBaseURL'; } ); + $sth->execute($OPACBaseURL,$explanation); + $dbh->do( q{ UPDATE letter + SET content=replace(content, + 'http://<>', + '<>') + WHERE content LIKE "%http://<>%"; } ); + } + + print "Upgrade to $DBversion done (Bug 5010: Fix OPACBaseURL to include protocol)\n"; + SetVersion($DBversion); +} + + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 2770e53..8091e2b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -6,10 +6,10 @@ OPAC: choices: opac-templates - theme on the OPAC. - - - "The OPAC is located at http://" + - "The OPAC is located at " - pref: OPACBaseURL class: url - - . Do not include a trailing slash in the URL. (This must be filled in correctly for RSS, unAPI, and search plugins to work.) + - . This should be a complete URL, starting with http:// or https://. Do not include a trailing slash in the URL. (This must be filled in correctly for RSS, unAPI, and search plugins to work.) - - Show - pref: LibraryName diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index e10d95f..59bcb31 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -418,9 +418,9 @@ function verify_images() { [% END %] - [% IF ( OpacUrl ) %] + [% IF ( OPACBaseURL ) %]
  • OPAC view: - Open in new window + Open in new window
  • [% END %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl index 003f528..58fa87a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl +++ b/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2intranetDetail.xsl @@ -828,7 +828,7 @@ OPAC view: - http:///cgi-bin/koha/opac-detail.pl?biblionumber=_blankOpen in new window. + /cgi-bin/koha/opac-detail.pl?biblionumber=_blankOpen in new window. diff --git a/koha-tmpl/intranet-tmpl/prog/en/xslt/NORMARCslim2intranetDetail.xsl b/koha-tmpl/intranet-tmpl/prog/en/xslt/NORMARCslim2intranetDetail.xsl index 3271e5b..6c51add 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/xslt/NORMARCslim2intranetDetail.xsl +++ b/koha-tmpl/intranet-tmpl/prog/en/xslt/NORMARCslim2intranetDetail.xsl @@ -569,7 +569,7 @@

    OPAC View: - http:///cgi-bin/koha/opac-detail.pl?biblionumber= + /cgi-bin/koha/opac-detail.pl?biblionumber= _blank Open in new window

    diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt index 8545b4e..b3e2e41 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-detail.tt @@ -1097,12 +1097,12 @@ [% IF ( SocialNetworks ) %] [% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index c7afcf2..5f6b17b 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -1471,12 +1471,12 @@ YAHOO.util.Event.onContentReady("furtherm", function () { [% IF ( SocialNetworks ) %] [% END %] diff --git a/opac/opac-shareshelf.pl b/opac/opac-shareshelf.pl index 669629b..275d1c3 100755 --- a/opac/opac-shareshelf.pl +++ b/opac/opac-shareshelf.pl @@ -179,8 +179,7 @@ sub send_invitekey { my ($param) = @_; my $fromaddr = C4::Context->preference('KohaAdminEmailAddress'); my $url = - 'http://' - . C4::Context->preference('OPACBaseURL') + C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-shareshelf.pl?shelfnumber=" . $param->{shelfnumber} . "&op=accept&key="; diff --git a/t/db_dependent/Auth_with_cas.t b/t/db_dependent/Auth_with_cas.t index 8e0f783..cb86413 100755 --- a/t/db_dependent/Auth_with_cas.t +++ b/t/db_dependent/Auth_with_cas.t @@ -38,7 +38,7 @@ my $dbh = C4::Context->dbh; $dbh->{ AutoCommit } = 0; $dbh->{ RaiseError } = 1; -C4::Context->set_preference('OPACBaseURL','localhost'); +C4::Context->set_preference('OPACBaseURL','http://localhost'); my $opac_base_url = C4::Context->preference('OpacBaseURL'); my $query_string = 'ticket=foo&bar=baz'; diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl index 9439609..193f7ac 100755 --- a/virtualshelves/sendshelf.pl +++ b/virtualshelves/sendshelf.pl @@ -100,10 +100,6 @@ if ( $email ) { push( @results, $dat ); } - if (C4::Context->preference('OPACBaseURL')){ - $template2->param( OPACBaseURL => C4::Context->preference('OPACBaseURL') ); - } - $template2->param( BIBLIO_RESULTS => \@results, email_sender => $email_from, -- 1.7.9.5