use JSON rather than Storable for the OPAC search history cookie
[koha.git] / opac / opac-search.pl
index dfe651e..ced8ae4 100755 (executable)
@@ -54,7 +54,7 @@ use C4::Ratings;
 
 use POSIX qw(ceil floor strftime);
 use URI::Escape;
-use Storable qw(thaw freeze);
+use JSON qw/decode_json encode_json/;
 use Business::ISBN;
 
 my $DisplayMultiPlaceHold = C4::Context->preference("DisplayMultiPlaceHold");
@@ -193,7 +193,7 @@ if (C4::Context->preference('TagsEnabled')) {
 
 my $branches = GetBranches();   # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established
 $template->param(
-    searchdomainloop => GetBranchCategories(undef,'searchdomain'),
+    searchdomainloop => GetBranchCategories('searchdomain'),
 );
 
 # load the language limits (for search)
@@ -625,8 +625,8 @@ for (my $i=0;$i<@servers;$i++) {
             my $searchcookie = $cgi->cookie('KohaOpacRecentSearches');
             if ($searchcookie){
                 $searchcookie = uri_unescape($searchcookie);
-                if (thaw($searchcookie)) {
-                    @recentSearches = @{thaw($searchcookie)};
+                if (decode_json($searchcookie)) {
+                    @recentSearches = @{decode_json($searchcookie)};
                 }
             }
 
@@ -641,8 +641,8 @@ for (my $i=0;$i<@servers;$i++) {
                 # To a cookie (the user is not logged in)
                 if (!$offset) {
                     push @recentSearches, {
-                                "query_desc" => $query_desc_history || "unknown",
-                                "query_cgi"  => $query_cgi_history  || "unknown",
+                                "query_desc" => Encode::decode_utf8($query_desc_history) || "unknown",
+                                "query_cgi"  => Encode::decode_utf8($query_cgi_history)  || "unknown",
                                 "time"       => time(),
                                 "total"      => $total
                               };
@@ -653,8 +653,8 @@ for (my $i=0;$i<@servers;$i++) {
                 # Pushing the cookie back
                 $newsearchcookie = $cgi->cookie(
                             -name => 'KohaOpacRecentSearches',
-                            # We uri_escape the whole freezed structure so we're sure we won't have any encoding problems
-                            -value =>freeze(\@recentSearches),
+                            # We uri_escape the whole serialized structure so we're sure we won't have any encoding problems
+                            -value => uri_escape( encode_json(\@recentSearches) ),
                             -expires => ''
                 );
                 $cookie = [$cookie, $newsearchcookie];