From 906d0c347bbee95e5cebcd4277d954076166d3d3 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 Content-Type: text/plain; charset=utf-8 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. Signed-off-by: Hayley Mapley Signed-off-by: Hayley Mapley Signed-off-by: Lisette Scheer --- Koha/Template/Plugin/KohaNews.pm | 7 ++++++- .../bug_22880-move-opacheader-to-news.perl | 18 ++++++++++++++++++ .../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 +++--------- 6 files changed, 39 insertions(+), 26 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 49299f6e3d..bd56f63e2d 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 0000000000..73bd289275 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_22880-move-opacheader-to-news.perl @@ -0,0 +1,18 @@ +$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 7c77af5b30..9c9b2b7f00 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 @@ -251,12 +251,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 6621e0c878..e73e613194 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 @@ -327,7 +327,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 %] [% location = BLOCK %]OPAC news[% END %] 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 8cb9d2f674..d872c73f4d 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 82a1ae6440..f9192e67f4 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') %]
@@ -143,15 +144,8 @@
- [% IF ( opacheader ) %] -
-
-
- [% opacheader | $raw %] -
-
-
- [% END %] + [% PROCESS koha_news_block news => KohaNews.get( location => "opacheader", lang => news_lang, library => branchcode, blocktitle => 0 ) %] +
-- 2.11.0