1 /***************************************************************************
2 *
3 * gbfwebif.cpp - GBF to HTML filter with hrefs for strongs and morph
4 * tags
5 *
6 * $Id: gbfwebif.cpp 2833 2013-06-29 06:40:28Z chrislit $
7 *
8 * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org)
9 * CrossWire Bible Society
10 * P. O. Box 2528
11 * Tempe, AZ 85280-2528
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation version 2.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 */
23
24
25 #include <gbfwebif.h>
26 #include <ctype.h>
27 #include <url.h>
28
29 SWORD_NAMESPACE_START
30
GBFWEBIF()31 GBFWEBIF::GBFWEBIF() : baseURL(""), passageStudyURL(baseURL + "passagestudy.jsp") {
32 }
33
handleToken(SWBuf & buf,const char * token,BasicFilterUserData * userData)34 bool GBFWEBIF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
35 const char *tok;
36 char val[128];
37 char *valto;
38 const char *num;
39 SWBuf url;
40
41 if (!substituteToken(buf, token)) {
42 if (!strncmp(token, "w", 1)) {
43 // OSIS Word (temporary until OSISRTF is done)
44 valto = val;
45 num = strstr(token, "lemma=\"x-Strongs:");
46 if (num) {
47 for (num+=17; ((*num) && (*num != '\"')); num++)
48 *valto++ = *num;
49 *valto = 0;
50
51 if (atoi((!isdigit(*val))?val+1:val) < 5627) {
52 buf += " <small><em><";
53 url = "";
54 for (tok = val; *tok; tok++) {
55 url += *tok;
56 }
57 if ((url.length() > 1) && strchr("GH", url[0])) {
58 if (isdigit(url[1]))
59 url = url.c_str()+1;
60 }
61 buf.appendFormatted("<a href=\"%s?showStrong=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str());
62
63 for (tok = (!isdigit(*val))?val+1:val; *tok; tok++) {
64 buf += *tok;
65 }
66 buf += "</a>></em></small> ";
67 }
68 }
69 else {
70 num = strstr(token, "lemma=\"strong:");
71 if (num) {
72 for (num+=14; ((*num) && (*num != '\"')); num++)
73 *valto++ = *num;
74 *valto = 0;
75
76 if (atoi((!isdigit(*val))?val+1:val) < 5627) {
77 buf += " <small><em><";
78 url = "";
79 for (tok = val; *tok; tok++) {
80 url += *tok;
81 }
82 if ((url.length() > 1) && strchr("GH", url[0])) {
83 if (isdigit(url[1]))
84 url = url.c_str()+1;
85 }
86 buf.appendFormatted("<a href=\"%s?showStrong=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str());
87
88 for (tok = (!isdigit(*val))?val+1:val; *tok; tok++) {
89 buf += *tok;
90 }
91 buf += "</a>></em></small> ";
92 }
93 }
94 }
95 valto = val;
96 num = strstr(token, "morph=\"x-Robinson:");
97 if (num) {
98 for (num+=18; ((*num) && (*num != '\"')); num++)
99 *valto++ = *num;
100 *valto = 0;
101 buf += " <small><em>(";
102 url = "";
103 for (tok = val; *tok; tok++) {
104 // normal robinsons tense
105 buf += *tok;
106 }
107 buf.appendFormatted("<a href=\"%s?showMorph=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str());
108
109 for (tok = val; *tok; tok++) {
110 buf += *tok;
111 }
112 buf += "</a>)</em></small> ";
113 }
114 }
115
116 else if (!strncmp(token, "WG", 2) || !strncmp(token, "WH", 2)) { // strong's numbers
117 buf += " <small><em><";
118 url = "";
119
120 for (tok = token+1; *tok; tok++) {
121 url += *tok;
122 }
123 if ((url.length() > 1) && strchr("GH", url[0])) {
124 if (isdigit(url[1]))
125 url = url.c_str()+1;
126 }
127 buf.appendFormatted("<a href=\"%s?showStrong=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str());
128
129 for (tok = token + 2; *tok; tok++) {
130 buf += *tok;
131 }
132 buf += "</a>></em></small>";
133 }
134
135 else if (!strncmp(token, "WTG", 3) || !strncmp(token, "WTH", 3)) { // strong's numbers tense
136 buf += " <small><em>(";
137 url = "";
138 for (tok = token + 2; *tok; tok++) {
139 if(*tok != '\"')
140 url += *tok;
141 }
142 if ((url.length() > 1) && strchr("GH", url[0])) {
143 if (isdigit(url[1]))
144 url = url.c_str()+1;
145 }
146 buf.appendFormatted("<a href=\"%s?showStrong=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str());
147
148 for (tok = token + 3; *tok; tok++)
149 if(*tok != '\"')
150 buf += *tok;
151 buf += "</a>)</em></small>";
152 }
153
154 else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags
155 buf += " <small><em>(";
156 for (tok = token + 2; *tok; tok++) {
157 if(*tok != '\"')
158 buf += *tok;
159 }
160 buf.appendFormatted("<a href=\"%s?showMorph=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str());
161
162 for (tok = token + 2; *tok; tok++) {
163 if(*tok != '\"')
164 buf += *tok;
165 }
166 buf += "</a>)</em></small>";
167 }
168
169 else if (!strncmp(token, "RX", 2)) {
170 buf += "<a href=\"";
171 for (tok = token + 3; *tok; tok++) {
172 if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') {
173 buf += *tok;
174 }
175 else {
176 break;
177 }
178 }
179
180 buf.appendFormatted("a href=\"%s?key=%s#cv\">", passageStudyURL.c_str(), URL::encode(url).c_str());
181 }
182 // ok to leave these in
183 else if ((!strncmp(token, "span", 4))
184 || (!strncmp(token, "/span", 5))) {
185 buf.appendFormatted("<%s>", token);
186 }
187
188 else {
189 return GBFXHTML::handleToken(buf, token, userData);
190 }
191 }
192 return true;
193 }
194
195 SWORD_NAMESPACE_END
196