source: trunk/gsdl/src/recpt/tipaction.cpp@ 5967

Last change on this file since 5967 was 5967, checked in by jrm21, 20 years ago

don't fill up the error log file if tips aren't defined in the macro files

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1/**********************************************************************
2 *
3 * tipaction.cpp -- define random tip macros
4 * Copyright (C) 1999 DigiLib Systems Limited, New Zealand
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#include "tipaction.h"
27#include <stdlib.h>
28
29
30tipaction::tipaction () {
31 // "st" show tips - "0"=no, "1"=yes
32 cgiarginfo arg_ainfo;
33 arg_ainfo.shortname = "st";
34 arg_ainfo.longname = "show tips";
35 arg_ainfo.multiplechar = true;
36 arg_ainfo.defaultstatus = cgiarginfo::weak;
37 arg_ainfo.argdefault = "1";
38 arg_ainfo.savedarginfo = cgiarginfo::must;
39 argsinfo.addarginfo (NULL, arg_ainfo);
40}
41
42void tipaction::define_external_macros (displayclass &disp, cgiargsclass &args,
43 recptprotolistclass * /*protos*/, ostream &logout) {
44
45 // define_external_macros sets the following macros:
46
47 // _tip:thistip_ - a random tip (defined if st == "1")
48
49 if (args["st"].getint()) {
50 // get the maximum tip number (_tip:tipmax_)
51 text_t tipmax_str;
52 disp.expandstring ("tip", "_tipmax_", tipmax_str);
53 if (tipmax_str.empty()) {
54 // don't bother filling up the logs if tip.dm isn't loaded!
55 // logout << "Warning: _tip:tipmax_ not set. This macro is needed for displaying tips.\n";
56 return;
57 }
58
59 int tipmax = tipmax_str.getint();
60 if (tipmax < 1) {
61 // don't bother filling up the logs if tip.dm isn't loaded!
62 // logout << "Warning: _tip:tipmax_ was less than 1. No tips were set.\n";
63 return;
64 }
65
66 disp.setmacro("thistip", "tip", "_tip" + text_t((rand()%tipmax) + 1) + "_");
67 }
68}
Note: See TracBrowser for help on using the repository browser.