The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gbfhtmlhref.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * gbfhtmlhref.cpp - GBF to HTML filter with hrefs
4  *
5  * $Id: gbfhtmlhref.cpp 3547 2017-12-10 05:06:48Z scribe $
6  *
7  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 
24 #include <stdlib.h>
25 #include <gbfhtmlhref.h>
26 #include <swmodule.h>
27 #include <utilxml.h>
28 #include <versekey.h>
29 #include <ctype.h>
30 #include <url.h>
31 
33 
35  if (module) {
36  version = module->getName();
37  }
38 }
39 
41  setTokenStart("<");
42  setTokenEnd(">");
43 
45 
46  //addTokenSubstitute("Rf", ")</small></font>");
47  addTokenSubstitute("FA", "<font color=\"#800000\">"); // for ASV footnotes to mark text
48  addTokenSubstitute("Rx", "</a>");
49  addTokenSubstitute("FI", "<i>"); // italics begin
50  addTokenSubstitute("Fi", "</i>");
51  addTokenSubstitute("FB", "<b>"); // bold begin
52  addTokenSubstitute("Fb", "</b>");
53  addTokenSubstitute("FR", "<font color=\"#FF0000\">"); // words of Jesus begin
54  addTokenSubstitute("Fr", "</font>");
55  addTokenSubstitute("FU", "<u>"); // underline begin
56  addTokenSubstitute("Fu", "</u>");
57  addTokenSubstitute("FO", "<cite>"); // Old Testament quote begin
58  addTokenSubstitute("Fo", "</cite>");
59  addTokenSubstitute("FS", "<sup>"); // Superscript begin// Subscript begin
60  addTokenSubstitute("Fs", "</sup>");
61  addTokenSubstitute("FV", "<sub>"); // Subscript begin
62  addTokenSubstitute("Fv", "</sub>");
63  addTokenSubstitute("TT", "<big>"); // Book title begin
64  addTokenSubstitute("Tt", "</big>");
65  addTokenSubstitute("PP", "<cite>"); // poetry begin
66  addTokenSubstitute("Pp", "</cite>");
67  addTokenSubstitute("Fn", "</font>"); // font end
68  addTokenSubstitute("CL", "<br />"); // new line
69  addTokenSubstitute("CM", "<!P><br />"); // paragraph <!P> is a non showing comment that can be changed in the front end to <P> if desired
70  addTokenSubstitute("CG", ""); // ???
71  addTokenSubstitute("CT", ""); // ???
72  addTokenSubstitute("JR", "<div align=\"right\">"); // right align begin
73  addTokenSubstitute("JC", "<div align=\"center\">"); // center align begin
74  addTokenSubstitute("JL", "</div>"); // align end
75 
76  renderNoteNumbers = false;
77 }
78 
79 
80 bool GBFHTMLHREF::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
81  const char *tok;
82  MyUserData *u = (MyUserData *)userData;
83 
84  if (!substituteToken(buf, token)) {
85  XMLTag tag(token);
86  /*if (!strncmp(token, "w", 1)) {
87  // OSIS Word (temporary until OSISRTF is done)
88  valto = val;
89  num = strstr(token, "lemma=\"x-Strongs:");
90  if (num) {
91  for (num+=17; ((*num) && (*num != '\"')); num++)
92  *valto++ = *num;
93  *valto = 0;
94  if (atoi((!isdigit(*val))?val+1:val) < 5627) {
95  buf += " <small><em>&lt;<a href=\"type=Strongs value=";
96  for (tok = val; *tok; tok++)
97  buf += *tok;
98  buf += "\">";
99  for (tok = (!isdigit(*val))?val+1:val; *tok; tok++)
100  buf += *tok;
101  buf += "</a>&gt;</em></small> ";
102  //cout << buf;
103 
104  }
105  // forget these for now
106  //else {
107  // verb morph
108  //sprintf(wordstr, "%03d", word-1);
109  //module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
110  //}
111  }
112  else {
113  num = strstr(token, "lemma=\"strong:");
114  if (num) {
115  for (num+=14; ((*num) && (*num != '\"')); num++)
116  *valto++ = *num;
117  *valto = 0;
118  if (atoi((!isdigit(*val))?val+1:val) < 5627) {
119  buf += " <small><em>&lt;<a href=\"type=Strongs value=";
120  for (tok = val; *tok; tok++)
121  buf += *tok;
122  buf += "\">";
123  for (tok = (!isdigit(*val))?val+1:val; *tok; tok++)
124  buf += *tok;
125  buf += "</a>&gt;</em></small> ";
126  //cout << buf;
127 
128  }
129  // forget these for now
130  //else {
131  // verb morph
132  //sprintf(wordstr, "%03d", word-1);
133  //module->getEntryAttributes()["Word"][wordstr]["Morph"] = val;
134  //}
135  }
136  }
137  valto = val;
138  num = strstr(token, "morph=\"x-Robinson:");
139  if (num) {
140  for (num+=18; ((*num) && (*num != '\"')); num++)
141  *valto++ = *num;
142  *valto = 0;
143  buf += " <small><em>(<a href=\"type=morph class=Robinson value=";
144  for (tok = val; *tok; tok++)
145  // normal robinsons tense
146  buf += *tok;
147  buf += "\">";
148  for (tok = val; *tok; tok++)
149  //if(*tok != '\"')
150  buf += *tok;
151  buf += "</a>)</em></small> ";
152  }
153  }*/
154 
155  // else
156  if (!strncmp(token, "WG", 2)) { // strong's numbers
157  //buf += " <small><em>&lt;<a href=\"type=Strongs value=";
158  buf += " <small><em class=\"strongs\">&lt;<a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value=";
159  for (tok = token+2; *tok; tok++)
160  //if(token[i] != '\"')
161  buf += *tok;
162  buf += "\" class=\"strongs\">";
163  for (tok = token + 2; *tok; tok++)
164  //if(token[i] != '\"')
165  buf += *tok;
166  buf += "</a>&gt;</em></small>";
167  }
168  else if (!strncmp(token, "WH", 2)) { // strong's numbers
169  //buf += " <small><em>&lt;<a href=\"type=Strongs value=";
170  buf += " <small><em class=\"strongs\">&lt;<a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value=";
171  for (tok = token+2; *tok; tok++)
172  //if(token[i] != '\"')
173  buf += *tok;
174  buf += "\" class=\"strongs\">";
175  for (tok = token + 2; *tok; tok++)
176  //if(token[i] != '\"')
177  buf += *tok;
178  buf += "</a>&gt;</em></small>";
179  }
180  else if (!strncmp(token, "WTG", 3)) { // strong's numbers tense
181  //buf += " <small><em>(<a href=\"type=Strongs value=";
182  buf += " <small><em class=\"strongs\">(<a href=\"passagestudy.jsp?action=showStrongs&type=Greek&value=";
183  for (tok = token + 3; *tok; tok++)
184  if(*tok != '\"')
185  buf += *tok;
186  buf += "\" class=\"strongs\">";
187  for (tok = token + 3; *tok; tok++)
188  if(*tok != '\"')
189  buf += *tok;
190  buf += "</a>)</em></small>";
191  }
192  else if (!strncmp(token, "WTH", 3)) { // strong's numbers tense
193  //buf += " <small><em>(<a href=\"type=Strongs value=";
194  buf += " <small><em class=\"strongs\">(<a href=\"passagestudy.jsp?action=showStrongs&type=Hebrew&value=";
195  for (tok = token + 3; *tok; tok++)
196  if(*tok != '\"')
197  buf += *tok;
198  buf += "\" class=\"strongs\">";
199  for (tok = token + 3; *tok; tok++)
200  if(*tok != '\"')
201  buf += *tok;
202  buf += "</a>)</em></small>";
203  }
204 
205  else if (!strncmp(token, "WT", 2) && strncmp(token, "WTH", 3) && strncmp(token, "WTG", 3)) { // morph tags
206  //buf += " <small><em>(<a href=\"type=morph class=none value=";
207  buf += " <small><em class=\"morph\">(<a href=\"passagestudy.jsp?action=showMorph&type=Greek&value=";
208 
209  for (tok = token + 2; *tok; tok++)
210  if(*tok != '\"')
211  buf += *tok;
212  buf += "\" class=\"morph\">";
213  for (tok = token + 2; *tok; tok++)
214  if(*tok != '\"')
215  buf += *tok;
216  buf += "</a>)</em></small>";
217  }
218 
219  else if (!strcmp(tag.getName(), "RX")) {
220  buf += "<a href=\"";
221  for (tok = token + 3; *tok; tok++) {
222  if(*tok != '<' && *tok+1 != 'R' && *tok+2 != 'x') {
223  buf += *tok;
224  }
225  else {
226  break;
227  }
228  }
229  buf += "\">";
230  }
231  else if (!strcmp(tag.getName(), "RF")) {
232  SWBuf type = tag.getAttribute("type");
233  SWBuf footnoteNumber = tag.getAttribute("swordFootnote");
234  SWBuf noteName = tag.getAttribute("n");
235  if (u->vkey) {
236  // leave this special osis type in for crossReference notes types? Might thml use this some day? Doesn't hurt.
237  //char ch = ((tag.getAttribute("type") && ((!strcmp(tag.getAttribute("type"), "crossReference")) || (!strcmp(tag.getAttribute("type"), "x-cross-ref")))) ? 'x':'n');
238  buf.appendFormatted("<a href=\"passagestudy.jsp?action=showNote&type=n&value=%s&module=%s&passage=%s\"><small><sup class=\"n\">*n%s</sup></small></a> ",
239  URL::encode(footnoteNumber.c_str()).c_str(),
240  URL::encode(u->version.c_str()).c_str(),
241  URL::encode(u->vkey->getText()).c_str(),
242  (renderNoteNumbers ? URL::encode(noteName.c_str()).c_str(): ""));
243  }
244  u->suspendTextPassThru = true;
245  }
246  else if (!strcmp(tag.getName(), "Rf")) {
247  u->suspendTextPassThru = false;
248  }
249 /*
250  else if (!strncmp(token, "RB", 2)) {
251  buf += "<i> ";
252  u->hasFootnotePreTag = true;
253  }
254 
255  else if (!strncmp(token, "Rf", 2)) {
256  buf += "&nbsp<a href=\"note=";
257  buf += u->lastTextNode.c_str();
258  buf += "\">";
259  buf += "<small><sup>*n</sup></small></a>&nbsp";
260  // let's let text resume to output again
261  u->suspendTextPassThru = false;
262  }
263 
264  else if (!strncmp(token, "RF", 2)) {
265  if (u->hasFootnotePreTag) {
266  u->hasFootnotePreTag = false;
267  buf += "</i> ";
268  }
269  u->suspendTextPassThru = true;
270  }
271 */
272  else if (!strncmp(token, "FN", 2)) {
273  buf += "<font face=\"";
274  for (tok = token + 2; *tok; tok++)
275  if(*tok != '\"')
276  buf += *tok;
277  buf += "\">";
278  }
279 
280  else if (!strncmp(token, "CA", 2)) { // ASCII value
281  buf += (char)atoi(&token[2]);
282  }
283 
284  else {
285  return false;
286  }
287  }
288  return true;
289 }
290 
const char * getName() const
Definition: swmodule.cpp:204
#define SWORD_NAMESPACE_START
Definition: defs.h:39
SWBuf & appendFormatted(const char *format,...)
Definition: swbuf.cpp:81
void setTokenEnd(const char *tokenEnd)
Definition: swbuf.h:47
const char * getName() const
Definition: utilxml.h:58
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
void setTokenCaseSensitive(bool val)
bool substituteToken(SWBuf &buf, const char *token)
const VerseKey * vkey
Definition: swbasicfilter.h:44
virtual const char * getText() const
Definition: versekey.cpp:1242
void setTokenStart(const char *tokenStart)
const char * c_str() const
Definition: swbuf.h:158
bool renderNoteNumbers
Definition: gbfhtmlhref.h:34
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: gbfhtmlhref.cpp:80
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
MyUserData(const SWModule *module, const SWKey *key)
Definition: gbfhtmlhref.cpp:34
void addTokenSubstitute(const char *findString, const char *replaceString)
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
static const SWBuf encode(const char *urlText)
Definition: url.cpp:231