]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates/opac/parts/header.tt2
LP#1681095 Browser cache-busting key for longer expires
[Evergreen.git] / Open-ILS / src / templates / opac / parts / header.tt2
1 [%- USE money = format(l('$%.2f'));
2     USE date;
3     USE CGI = CGI_utf8;
4     USE POSIX;
5     USE HTML;
6     SET DATE_FORMAT = l('%m/%d/%Y');
7     PROCESS "opac/parts/config.tt2";
8
9     # Don't wrap in l() here; do that where this format string is actually used.
10     SET HUMAN_NAME_FORMAT = '[_1] [_2] [_3] [_4] [_5]';
11
12     is_advanced = CGI.param("_adv").size;
13     is_special = CGI.param("_special").size;
14
15     # Check if we want to show the detail record view.  Doing this
16     # here because we don't want to repeat logic in multiple other
17     # files, nor do we want to add a new tt2 file just for this.  The
18     # below is currently needed for parts/result/table.tt2,
19     # parts/searchbar.tt2, and results.tt2.
20     show_detail_view = 0;
21     IF CGI.param("detail_record_view").defined;
22         show_detail_view = CGI.param("detail_record_view");
23     ELSIF show_more_details.default == "true" OR
24           show_more_details.default == "hide";
25         show_detail_view = 1;
26     END;
27
28     #variables to use to remove parameters via mkurk
29     expert_search_parms = ['tag','subfield','term','_special'];
30     general_search_parms = ['page','sort','query','bool','contains','pubdate'];
31     browse_search_parms = ['fi:has_browse_entry','bterm','blimit','bpivot'];
32     facet_search_parms = ['facet'];
33
34
35     # -----------------------------------------------------------------------------
36     # mkurl( destination_page, params_to_set, params_to_clear )
37     #
38     # Current page, updated params:
39     # mkurl('', {foo => 'bar', boo => 'baz'});
40     #
41     # New page, one param is a list:
42     # mkurl('http://flarg.baz/squz', {foo => 'bar', boo => ['baz', 'faz']});
43     #
44     # New page, clear all existing params before applying new ones:
45     # mkurl('/fuz/buster', {foo => 'bar', boo => 'baz'}, 1); 
46     #
47     # Current page, clear 'some_param' from the existing params:
48     # mkurl('', {foo => 'bar', boo => 'baz'}, ['some_param']);
49     #
50     # Current page to a named anchor 'copies'
51     # mkurl('', {}, [], 'copies');
52     MACRO mkurl(page, params, clear_params, named_anchor) BLOCK;
53
54         # clone the query string to avoid clobberation
55         cgi = CGI.new(CGI.query_string);
56
57         # remove requested params
58         IF clear_params.0; # array
59             FOR p IN clear_params; cgi.delete(p); END;
60         ELSIF clear_params;
61             cgi.delete_all();
62         END;
63
64         # x and y are artifacts of using <input type="image" /> tags 
65         # instead of true submit buttons, and their values are never used.
66         cgi.delete('x', 'y'); 
67
68         # apply user params
69         FOR k IN params.keys;
70             encoded = [];
71             max = params.$k.max;
72
73             # The following commented-out line can be fooled. Its replacement
74             # below is what you really mean.
75             # list = (params.$k.0 OR max == -1) ? params.$k : [params.$k];
76             list = params.$k.list;
77
78             IF list.size == 0; NEXT; END;
79             # CGI croaks on already-decoded strings.  force-encode to be safe.
80             FOR p IN list; encoded.push(ctx.encode_utf8(p)); END;
81             foo = cgi.param("-name", k, "-values", encoded);
82         END;
83
84         # for url brevity, remove any params that have no value
85         FOR p IN cgi.param;
86             val = cgi.param(p);
87             IF val == ''; cgi.delete(p); END;
88
89             # Delete POST vars unless we asked for them
90             UNLESS CGI.url_param(p).defined OR params.defined(p);
91                 cgi.delete(p);
92             END;
93         END;
94
95         final = named_anchor ? '#' _ named_anchor : '';
96
97         IF page;
98             IF cgi.query_string;
99                 page _ '?' _ cgi.query_string _ final;
100             ELSE;
101                 page _ final;
102             END;
103         ELSE;
104             # staying on the current page
105             cgi.url("-absolute" => 1, "-path" => 1, "-query" => 1) _ final;
106         END;
107     END;
108
109     # Dojo is required for the copy locations advanced search filter
110     IF ctx.page == 'advanced';
111         want_dojo = 1;
112     END;
113
114     # ... and for code that tweaks visibility of types on the added
115     # content tab
116     IF ctx.page == 'record' AND (ctx.expand_addedcontent OR ctx.expand_all);
117         want_dojo = 1;
118     END;
119
120     use_autosuggest = ctx.get_cgf("opac.use_autosuggest");
121
122     IF use_autosuggest.enabled == "t";
123         want_dojo = 1;
124     END;
125
126     IF ENV.OILS_NOVELIST_URL;
127         want_dojo = 1;
128     END;
129
130     IF ebook_api.enabled == 'true';
131         want_dojo = 1;
132     END;
133
134     # Especially useful for image 'alt' tags and link title tags,
135     # where the content may need to be unique (making it longer)
136     # but should not exceed 75 chars for ideal screen reader support.
137     # usage: html_text_attr('title', 'Link to item I Have A Super Long Title')
138     # the full HTML attribute key="value" is produced
139     MACRO html_text_attr(name, value) BLOCK;
140         IF value.length >= 75;
141             value = value.substr(71, value.length, '...');                        
142         END;                                                                   
143         value = value.replace('\s*$', ''); # remove trailing whitespace          
144         HTML.attributes($name => value); 
145     END;
146
147     MACRO img_alt(text) BLOCK;
148         html_text_attr('alt', text);
149     END;
150
151     # Browser cache-busting key
152     # Fall back to the eg_cache_hash (set by autogen) so that we don't have to
153     # add conditionals into the rest of the templates
154     IF ctx.cache_key AND ctx.cache_key != "?" _ ctx.eg_cache_hash;
155         ctx.cache_key = "?v=" _ ctx.cache_key;
156     ELSE;
157         ctx.cache_key = "?" _ ctx.eg_cache_hash;
158     END;
159 %]