From f5499079ab58c66525c5cdcbbd63ff85486e5317 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 9 May 2019 13:52:30 +0000 Subject: [PATCH] Bug 22880: Convert opacheader system preference to news block This patch builds on Bug 22318 to move the opacheader system preference into the Koha news system, making it possible to have language- and library-specific content. It extends the original patch by adding an option to the template plugin specifying whether the content title should be shown (probably should be a flag in opac_news). It also adds a wrapper div with the content location as the ID (e.g. 'opacheader'). This will make it slightly more backwards-compatible with CSS customizations. To test you should have some content in the opacheader system preference. Apply the patch and run the database update process. - Go to the OPAC and confirm that the content which was previously in the opacheader system preference now displays correctly where it was before. - In the staff client, go to Tools -> News and verify that the content from opacheader is now stored in a news item with the location 'opacheader_en.' - Go to Administration -> System preferences and confirm that the opacheader preference has been removed. --- Koha/Template/Plugin/KohaNews.pm | 7 ++++++- .../bug_22880-move-opacheader-to-news.perl | 19 +++++++++++++++++++ .../prog/en/modules/admin/preferences/opac.pref | 6 ------ .../intranet-tmpl/prog/en/modules/tools/koha-news.tt | 2 +- .../opac-tmpl/bootstrap/en/includes/html_helpers.inc | 20 +++++++++++--------- .../opac-tmpl/bootstrap/en/includes/masthead.inc | 12 +++--------- .../opac-tmpl/bootstrap/en/modules/opac-main.tt | 2 +- 7 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_22880-move-opacheader-to-news.perl diff --git a/Koha/Template/Plugin/KohaNews.pm b/Koha/Template/Plugin/KohaNews.pm index 49299f6..bd56f63 100644 --- a/Koha/Template/Plugin/KohaNews.pm +++ b/Koha/Template/Plugin/KohaNews.pm @@ -32,6 +32,7 @@ sub get { my ( $self, $params ) = @_; my $display_location = $params->{location}; + my $blocktitle = $params->{blocktitle}; my $lang = $params->{lang}; my $library = $params->{library} || ""; my $news_lang; @@ -44,7 +45,11 @@ sub get { my $content = &GetNewsToDisplay( $news_lang, $library ); - return $content; + return { + content => $content, + location => $display_location, + blocktitle => $blocktitle + }; } 1; diff --git a/installer/data/mysql/atomicupdate/bug_22880-move-opacheader-to-news.perl b/installer/data/mysql/atomicupdate/bug_22880-move-opacheader-to-news.perl new file mode 100644 index 0000000..d525836 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_22880-move-opacheader-to-news.perl @@ -0,0 +1,19 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + my $opaclang = C4::Context->preference("opaclanguages"); + my @langs; + push @langs, split ( '\,', $opaclang ); + # Get any existing value from the opacheader system preference + my ($opacheader) = $dbh->selectrow_array( q| + SELECT value FROM systempreferences WHERE variable='opacheader'; + |); + if( $opacheader ){ + # If there is a value in the opacheader preference, insert it into opac_news + $dbh->do("INSERT INTO opac_news (branchcode, lang, title, content ) VALUES (NULL, 'opacheader_$langs[0]', '', '$opacheader')"); + } + # Remove the opacheader system preference + $dbh->do("DELETE FROM systempreferences WHERE variable='opacheader'"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (Bug 22880: Move contents of opacheader preference to Koha news system)\n"; +} + 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 8300553..e9dcfe3 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 @@ -237,12 +237,6 @@ OPAC: syntax: text/html class: code - - - "Include the following HTML in the header of all pages in the OPAC:" - - pref: opacheader - type: textarea - syntax: text/html - class: code - - - "Include the following HTML in the footer of all pages in the OPAC:" - pref: opaccredits type: textarea diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt index 1d36f44..d6051ce 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt @@ -278,7 +278,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %] [% END %] [% FOREACH lang_lis IN lang_list %] - [% FOREACH location IN [ '', 'OpacNavRight' ] %] + [% FOREACH location IN [ '', 'OpacNavRight', 'opacheader' ] %] [% IF ( location == '' ) %] [% SET location_lang = lang_lis.language %] [% SET location = "OPAC news" %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/html_helpers.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/html_helpers.inc index 8cb9d2f..d872c73 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/html_helpers.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/html_helpers.inc @@ -9,14 +9,16 @@ [% END %] [% BLOCK koha_news_block %] - [% IF ( news.size > 0 ) %] - [% FOREACH n IN news %] -
- [% IF ( n.title ) %] -

[% n.title | html %]

- [% END %] -
[% n.content | $raw %]
-
- [% END %] + [% IF ( news.content.size > 0 ) %] +
+ [% FOREACH n IN news.content %] +
+ [% IF ( n.title && news.blocktitle ) %] +

[% n.title | html %]

+ [% END %] +
[% n.content | $raw %]
+
+ [% END %] +
[% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc index 91f908e..9ac7320 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/masthead.inc @@ -2,6 +2,7 @@ [% USE Koha %] [% USE Branches %] [% USE Categories %] +[% USE KohaNews %] [% SET OpacLangSelectorMode = Koha.Preference('OpacLangSelectorMode') %]
@@ -122,15 +123,8 @@
- [% IF ( opacheader ) %] -
-
-
- [% opacheader | $raw %] -
-
-
- [% END %] + [% PROCESS koha_news_block news => KohaNews.get( location => "opacheader", lang => news_lang, library => branchcode, blocktitle => 0 ) %] +
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt index b48e922..eabe889 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -213,7 +213,7 @@ [% END %] [% END # /loggedinusername %] [% END # /opacuserlogin %] - [% PROCESS koha_news_block news => KohaNews.get( location => "OpacNavRight", lang => news_lang, library => branchcode ) %] + [% PROCESS koha_news_block news => KohaNews.get( location => "OpacNavRight", lang => news_lang, library => branchcode, blocktitle => 1 ) %]
[% END # /opacuserlogin || OpacNavRight %] -- 2.1.4