You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

691 lines
36 KiB

  1. <?php
  2. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  3. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  4. // original author(s).
  5. //
  6. // This code is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  8. // License for more details.
  9. //
  10. // File: ./cite/styles/cite_Harvard_1.php
  11. // Repository: $HeadURL$
  12. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  13. //
  14. // Created: 12-Aug-08, 16:00
  15. // Modified: $Date: 2012-02-27 20:25:30 +0000 (Mon, 27 Feb 2012) $
  16. // $Author$
  17. // $Revision: 1337 $
  18. // This is a citation style file (which must reside within the 'cite/styles/' sub-directory of your refbase root directory). It contains a
  19. // version of the 'citeRecord()' function that outputs a reference list from selected records according to the citation style used by
  20. // the Harvard referencing system
  21. // This is a variant of the Harvard author/date style, modeled after this guide:
  22. // <http://libweb.anglia.ac.uk/referencing/harvard.htm>
  23. // based on 'cite_Harvard_3.php'
  24. // TODO: - abstracts, conference proceedings, magazine articles, patents, reports & software?
  25. // - should we shorten ending page numbers if necessary (e.g. "p. 10-8" or "p. 51-5", but "p. 19-26"), or only if numbers are >=3 digits?
  26. // - where to put (and how to format) series info & editors of whole books that also have an author?
  27. // - see also inline comments labeled with TODO (and NOTE)
  28. // --------------------------------------------------------------------
  29. // --- BEGIN CITATION STYLE ---
  30. function citeRecord($row, $citeStyle, $citeType, $markupPatternsArray, $encodeHTML)
  31. {
  32. $record = ""; // make sure that our buffer variable is empty
  33. // --- BEGIN TYPE = JOURNAL ARTICLE / MAGAZINE ARTICLE / NEWSPAPER ARTICLE --------------------------------------------------------------
  34. if (preg_match("/^(Journal Article|Magazine Article|Newspaper Article)$/", $row['type']))
  35. {
  36. if (!empty($row['author'])) // author
  37. {
  38. // Call the 'reArrangeAuthorContents()' function (defined in 'include.inc.php') in order to re-order contents of the author field. Required Parameters:
  39. // 1. input: contents of the author field
  40. // 2. input: boolean value that specifies whether the author's family name comes first (within one author) in the source string
  41. // ('true' means that the family name is followed by the given name (or initials), 'false' if it's the other way around)
  42. //
  43. // 3. input: pattern describing old delimiter that separates different authors
  44. // 4. output: for all authors except the last author: new delimiter that separates different authors
  45. // 5. output: for the last author: new delimiter that separates the last author from all other authors
  46. //
  47. // 6. input: pattern describing old delimiter that separates author name & initials (within one author)
  48. // 7. output: for the first author: new delimiter that separates author name & initials (within one author)
  49. // 8. output: for all authors except the first author: new delimiter that separates author name & initials (within one author)
  50. // 9. output: new delimiter that separates multiple initials (within one author)
  51. // 10. output: for the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  52. // 11. output: for all authors except the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  53. // 12. output: boolean value that specifies whether an author's full given name(s) shall be shortened to initial(s)
  54. //
  55. // 13. output: if the total number of authors is greater than the given number (integer >= 1), only the number of authors given in (14) will be included in the citation along with the string given in (15); keep empty if all authors shall be returned
  56. // 14. output: number of authors (integer >= 1) that is included in the citation if the total number of authors is greater than the number given in (13); keep empty if not applicable
  57. // 15. output: string that's appended to the number of authors given in (14) if the total number of authors is greater than the number given in (13); the actual number of authors can be printed by including '__NUMBER_OF_AUTHORS__' (without quotes) within the string
  58. //
  59. // 16. output: boolean value that specifies whether the re-ordered string shall be returned with higher ASCII chars HTML encoded
  60. $author = reArrangeAuthorContents($row['author'], // 1.
  61. true, // 2.
  62. "/ *; */", // 3.
  63. ", ", // 4.
  64. " " . $markupPatternsArray["ampersand"] . " ", // 5.
  65. "/ *, */", // 6.
  66. ", ", // 7.
  67. ", ", // 8.
  68. ".", // 9.
  69. false, // 10.
  70. false, // 11.
  71. true, // 12.
  72. "4", // 13.
  73. "1", // 14.
  74. " et al", // 15.
  75. $encodeHTML); // 16.
  76. $record .= $author;
  77. }
  78. if (!empty($row['year'])) // year
  79. {
  80. if (!empty($row['author']))
  81. $record .= ", ";
  82. if (!empty($row['year']))
  83. $record .= $row['year'];
  84. }
  85. if (!empty($row['title'])) // title
  86. {
  87. if (!empty($row['author']) || !empty($row['year']))
  88. $record .= ". ";
  89. $record .= $row['title'];
  90. $record .= ",";
  91. }
  92. // From here on we'll assume that at least one of the fields 'author', 'year' or 'title' did contain some contents
  93. if (!empty($row['publication'])) // publication (= journal) name
  94. $record .= " " . $markupPatternsArray["italic-prefix"] . $row['publication'] . $markupPatternsArray["italic-suffix"];
  95. // if there's no full journal name, we'll use the abbreviated journal name instead:
  96. elseif (!empty($row['abbrev_journal'])) // abbreviated journal name
  97. $record .= " " . $markupPatternsArray["italic-prefix"] . $row['abbrev_journal'] . $markupPatternsArray["italic-suffix"];
  98. if ((!empty($row['abbrev_journal']) || !empty($row['publication'])) && (!empty($row['volume']) || !empty($row['issue'])))
  99. $record .= ","; // NOTE: for newspaper articles, the above mentioned guide uses a dot instead of a comma ("The Times, 3 Sep. p.4-5.") but this seems incorrect/inconsistent to me
  100. if ($row['online_publication'] == "yes") // this record refers to an online publication
  101. $record .= " [Online]";
  102. if ($row['type'] == "Journal Article")
  103. {
  104. if (!empty($row['volume'])) // volume
  105. $record .= " " . $row['volume'];
  106. if (!empty($row['issue'])) // issue
  107. {
  108. if (!empty($row['volume']))
  109. $record .= " ";
  110. $record .= "(" . $row['issue'] . ")";
  111. }
  112. }
  113. elseif (preg_match("/^(Newspaper Article|Magazine Article)$/", $row['type'])) // for newspaper and magazine articles, volume (=month) and issue (=day) information is printed without prefix
  114. {
  115. if (!empty($row['issue'])) // issue (=day)
  116. $record .= " " . $row['issue'];
  117. if (!empty($row['volume'])) // volume (=month)
  118. $record .= " " . $row['volume'];
  119. }
  120. if (!empty($row['pages'])) // pages
  121. {
  122. if (!empty($row['volume']) || !empty($row['issue']) || !empty($row['abbrev_journal']) || !empty($row['publication'])) // only add ", " if either volume, issue, abbrev_journal or publication isn't empty
  123. $record .= ", ";
  124. $record .= formatPageInfo($row['pages'], $markupPatternsArray["endash"], "p. ", "p. "); // function 'formatPageInfo()' is defined in 'cite.inc.php' (NOTE: from the examples in the above mentioned guide it's unclear whether "p." should be followed by a space or not)
  125. }
  126. if ($row['online_publication'] == "yes") // this record refers to an online article
  127. {
  128. // append an optional string (given in 'online_citation') plus the current date and the DOI (or URL):
  129. if (!empty($row['online_citation'])) // online_citation
  130. {
  131. if (!empty($row['volume']) || !empty($row['issue']) || !empty($row['abbrev_journal']) || !empty($row['publication'])) // only add "," if either volume, issue, abbrev_journal or publication isn't empty
  132. $record .= ",";
  133. $record .= " " . $row['online_citation'];
  134. }
  135. if (!empty($row['doi']) || !empty($row['url'])) // doi OR url
  136. {
  137. if (!empty($row['online_citation']) OR (empty($row['online_citation']) AND (!empty($row['volume']) || !empty($row['issue']) || !empty($row['abbrev_journal']) || !empty($row['publication'])))) // only add "." if online_citation isn't empty, or else if either volume, issue, abbrev_journal or publication isn't empty
  138. $record .= ".";
  139. $today = date("j F Y");
  140. $record .= " Available at: " . $markupPatternsArray["underline-prefix"];
  141. if (!empty($row['doi'])) // doi
  142. $uri = "http://dx.doi.org/" . $row['doi'];
  143. else // url
  144. $uri = $row['url'];
  145. if ($encodeHTML)
  146. $record .= encodeHTML($uri);
  147. else
  148. $record .= $uri;
  149. $record .= $markupPatternsArray["underline-suffix"];
  150. $record .= " [accessed " . $today . "]";
  151. }
  152. }
  153. if (!preg_match("/\. *$/", $record)) // if the string doesn't end with a period
  154. $record .= ".";
  155. }
  156. // --- BEGIN TYPE = ABSTRACT / BOOK CHAPTER / CONFERENCE ARTICLE ------------------------------------------------------------------------
  157. elseif (preg_match("/^(Abstract|Book Chapter|Conference Article)$/", $row['type']))
  158. {
  159. if (!empty($row['author'])) // author
  160. {
  161. // Call the 'reArrangeAuthorContents()' function (defined in 'include.inc.php') in order to re-order contents of the author field. Required Parameters:
  162. // 1. input: contents of the author field
  163. // 2. input: boolean value that specifies whether the author's family name comes first (within one author) in the source string
  164. // ('true' means that the family name is followed by the given name (or initials), 'false' if it's the other way around)
  165. //
  166. // 3. input: pattern describing old delimiter that separates different authors
  167. // 4. output: for all authors except the last author: new delimiter that separates different authors
  168. // 5. output: for the last author: new delimiter that separates the last author from all other authors
  169. //
  170. // 6. input: pattern describing old delimiter that separates author name & initials (within one author)
  171. // 7. output: for the first author: new delimiter that separates author name & initials (within one author)
  172. // 8. output: for all authors except the first author: new delimiter that separates author name & initials (within one author)
  173. // 9. output: new delimiter that separates multiple initials (within one author)
  174. // 10. output: for the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  175. // 11. output: for all authors except the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  176. // 12. output: boolean value that specifies whether an author's full given name(s) shall be shortened to initial(s)
  177. //
  178. // 13. output: if the total number of authors is greater than the given number (integer >= 1), only the number of authors given in (14) will be included in the citation along with the string given in (15); keep empty if all authors shall be returned
  179. // 14. output: number of authors (integer >= 1) that is included in the citation if the total number of authors is greater than the number given in (13); keep empty if not applicable
  180. // 15. output: string that's appended to the number of authors given in (14) if the total number of authors is greater than the number given in (13); the actual number of authors can be printed by including '__NUMBER_OF_AUTHORS__' (without quotes) within the string
  181. //
  182. // 16. output: boolean value that specifies whether the re-ordered string shall be returned with higher ASCII chars HTML encoded
  183. $author = reArrangeAuthorContents($row['author'], // 1.
  184. true, // 2.
  185. "/ *; */", // 3.
  186. ", ", // 4.
  187. " " . $markupPatternsArray["ampersand"] . " ", // 5.
  188. "/ *, */", // 6.
  189. ", ", // 7.
  190. ", ", // 8.
  191. ".", // 9.
  192. false, // 10.
  193. false, // 11.
  194. true, // 12.
  195. "4", // 13.
  196. "1", // 14.
  197. " et al", // 15.
  198. $encodeHTML); // 16.
  199. $record .= $author;
  200. }
  201. if (!empty($row['year'])) // year
  202. {
  203. if (!empty($row['author']))
  204. $record .= ", ";
  205. $record .= $row['year'];
  206. }
  207. if (!empty($row['title'])) // title
  208. {
  209. if (!empty($row['author']) || !empty($row['year']))
  210. $record .= ". ";
  211. $record .= $row['title'];
  212. $record .= ".";
  213. }
  214. // From here on we'll assume that at least one of the fields 'author', 'year' or 'title' did contain some contents
  215. // if this is not the case, the output string will begin with a space. However, any preceding/trailing whitespace will be removed at the cleanup stage (see below)
  216. if (!empty($row['editor'])) // editor
  217. {
  218. // Call the 'reArrangeAuthorContents()' function (defined in 'include.inc.php') in order to re-order contents of the author field. Required Parameters:
  219. // 1. input: contents of the author field
  220. // 2. input: boolean value that specifies whether the author's family name comes first (within one author) in the source string
  221. // ('true' means that the family name is followed by the given name (or initials), 'false' if it's the other way around)
  222. //
  223. // 3. input: pattern describing old delimiter that separates different authors
  224. // 4. output: for all authors except the last author: new delimiter that separates different authors
  225. // 5. output: for the last author: new delimiter that separates the last author from all other authors
  226. //
  227. // 6. input: pattern describing old delimiter that separates author name & initials (within one author)
  228. // 7. output: for the first author: new delimiter that separates author name & initials (within one author)
  229. // 8. output: for all authors except the first author: new delimiter that separates author name & initials (within one author)
  230. // 9. output: new delimiter that separates multiple initials (within one author)
  231. // 10. output: for the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  232. // 11. output: for all authors except the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  233. // 12. output: boolean value that specifies whether an author's full given name(s) shall be shortened to initial(s)
  234. //
  235. // 13. output: if the total number of authors is greater than the given number (integer >= 1), only the number of authors given in (14) will be included in the citation along with the string given in (15); keep empty if all authors shall be returned
  236. // 14. output: number of authors (integer >= 1) that is included in the citation if the total number of authors is greater than the number given in (13); keep empty if not applicable
  237. // 15. output: string that's appended to the number of authors given in (14) if the total number of authors is greater than the number given in (13); the actual number of authors can be printed by including '__NUMBER_OF_AUTHORS__' (without quotes) within the string
  238. //
  239. // 16. output: boolean value that specifies whether the re-ordered string shall be returned with higher ASCII chars HTML encoded
  240. $editor = reArrangeAuthorContents($row['editor'], // 1.
  241. true, // 2.
  242. "/ *; */", // 3.
  243. ", ", // 4.
  244. " " . $markupPatternsArray["ampersand"] . " ", // 5.
  245. "/ *, */", // 6.
  246. " ", // 7.
  247. " ", // 8.
  248. ".", // 9.
  249. true, // 10.
  250. true, // 11.
  251. true, // 12.
  252. "4", // 13.
  253. "1", // 14.
  254. " et al", // 15.
  255. $encodeHTML); // 16.
  256. $record .= " In " . $editor . ", ";
  257. if (preg_match("/^[^;\r\n]+(;[^;\r\n]+)+$/", $row['editor'])) // there are at least two editors (separated by ';')
  258. $record .= "eds.";
  259. else // there's only one editor (or the editor field is malformed with multiple editors but missing ';' separator[s])
  260. $record .= "ed.";
  261. }
  262. $publication = preg_replace("/[ \r\n]*\(Eds?:[^\)\r\n]*\)/i", "", $row['publication']);
  263. if (!empty($publication)) // publication
  264. {
  265. if (empty($row['editor']))
  266. $record .= " In";
  267. $record .= " " . $markupPatternsArray["italic-prefix"] . $publication . $markupPatternsArray["italic-suffix"];
  268. }
  269. if (!empty($row['edition']) && !preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $row['edition']) || !empty($row['volume']))
  270. {
  271. $record .= ". ";
  272. if (!empty($row['edition']) && !preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $row['edition'])) // edition
  273. {
  274. if (preg_match("/^\d{1,3}$/", $row['edition'])) // if the edition field contains a number of up to three digits, we assume it's an edition number (such as "2nd ed.")
  275. {
  276. if ($row['edition'] == "2")
  277. $editionSuffix = "nd";
  278. elseif ($row['edition'] == "3")
  279. $editionSuffix = "rd";
  280. else
  281. $editionSuffix = "th";
  282. }
  283. else
  284. $editionSuffix = "";
  285. if (!empty($row['edition']) && !preg_match("/( ed\.?| edition)$/i", $row['edition']))
  286. $editionSuffix .= " ed.";
  287. $record .= $row['edition'] . $editionSuffix;
  288. }
  289. if (!empty($row['volume'])) // volume
  290. {
  291. if (!empty($row['edition']) && !preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $row['edition']))
  292. $record .= ", ";
  293. $record .= "vol. " . $row['volume']; // TODO: not sure whether this is correct
  294. }
  295. }
  296. if (!empty($row['abbrev_series_title']) OR !empty($row['series_title'])) // if there's either a full or an abbreviated series title
  297. {
  298. $record .= ". ";
  299. if (!empty($row['series_title']))
  300. $record .= $row['series_title']; // full series title
  301. // if there's no full series title, we'll use the abbreviated series title instead:
  302. elseif (!empty($row['abbrev_series_title']))
  303. $record .= $row['abbrev_series_title']; // abbreviated series title
  304. if (!empty($row['series_volume'])||!empty($row['series_issue']))
  305. $record .= ", ";
  306. if (!empty($row['series_volume'])) // series volume (I'm not really sure if -- for this cite style -- the series volume & issue should be rather omitted here)
  307. $record .= "vol. " . $row['series_volume']; // TODO: not sure whether this is correct
  308. if (!empty($row['series_issue'])) // series issue (see note for series volume)
  309. {
  310. if (!empty($row['series_volume']))
  311. $record .= ", ";
  312. $record .= "no. " . $row['series_issue']; // TODO: not sure whether this is correct
  313. }
  314. }
  315. if (!preg_match("/\. *$/", $record))
  316. $record .= ".";
  317. if (!empty($row['place'])) // place
  318. $record .= " " . $row['place'];
  319. if (!empty($row['publisher'])) // publisher
  320. {
  321. if (!empty($row['place']))
  322. $record .= ":";
  323. $record .= " " . $row['publisher'];
  324. }
  325. if (!empty($row['pages'])) // pages
  326. {
  327. if (!empty($row['publisher']) || !empty($row['place']))
  328. $record .= ", ";
  329. $record .= formatPageInfo($row['pages'], $markupPatternsArray["endash"], "p. ", "p. "); // function 'formatPageInfo()' is defined in 'cite.inc.php' (NOTE: from the examples in the above mentioned guide it's unclear whether "p." should be followed by a space or not)
  330. }
  331. if (!preg_match("/\. *$/", $record))
  332. $record .= ".";
  333. }
  334. // --- BEGIN TYPE = BOOK WHOLE / CONFERENCE VOLUME / JOURNAL / MANUAL / MANUSCRIPT / MAP / MISCELLANEOUS / PATENT / REPORT / SOFTWARE ---
  335. else // if (preg_match("/Book Whole|Conference Volume|Journal|Manual|Manuscript|Map|Miscellaneous|Patent|Report|Software/", $row['type']))
  336. // note that this also serves as a fallback: unrecognized resource types will be formatted similar to whole books
  337. {
  338. if (!empty($row['author'])) // author
  339. {
  340. $author = preg_replace("/[ \r\n]*\(eds?\)/i", "", $row['author']);
  341. // Call the 'reArrangeAuthorContents()' function (defined in 'include.inc.php') in order to re-order contents of the author field. Required Parameters:
  342. // 1. input: contents of the author field
  343. // 2. input: boolean value that specifies whether the author's family name comes first (within one author) in the source string
  344. // ('true' means that the family name is followed by the given name (or initials), 'false' if it's the other way around)
  345. //
  346. // 3. input: pattern describing old delimiter that separates different authors
  347. // 4. output: for all authors except the last author: new delimiter that separates different authors
  348. // 5. output: for the last author: new delimiter that separates the last author from all other authors
  349. //
  350. // 6. input: pattern describing old delimiter that separates author name & initials (within one author)
  351. // 7. output: for the first author: new delimiter that separates author name & initials (within one author)
  352. // 8. output: for all authors except the first author: new delimiter that separates author name & initials (within one author)
  353. // 9. output: new delimiter that separates multiple initials (within one author)
  354. // 10. output: for the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  355. // 11. output: for all authors except the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  356. // 12. output: boolean value that specifies whether an author's full given name(s) shall be shortened to initial(s)
  357. //
  358. // 13. output: if the total number of authors is greater than the given number (integer >= 1), only the number of authors given in (14) will be included in the citation along with the string given in (15); keep empty if all authors shall be returned
  359. // 14. output: number of authors (integer >= 1) that is included in the citation if the total number of authors is greater than the number given in (13); keep empty if not applicable
  360. // 15. output: string that's appended to the number of authors given in (14) if the total number of authors is greater than the number given in (13); the actual number of authors can be printed by including '__NUMBER_OF_AUTHORS__' (without quotes) within the string
  361. //
  362. // 16. output: boolean value that specifies whether the re-ordered string shall be returned with higher ASCII chars HTML encoded
  363. $author = reArrangeAuthorContents($author, // 1.
  364. true, // 2.
  365. "/ *; */", // 3.
  366. ", ", // 4.
  367. " " . $markupPatternsArray["ampersand"] . " ", // 5.
  368. "/ *, */", // 6.
  369. ", ", // 7.
  370. ", ", // 8.
  371. ".", // 9.
  372. false, // 10.
  373. false, // 11.
  374. true, // 12.
  375. "4", // 13.
  376. "1", // 14.
  377. " et al", // 15.
  378. $encodeHTML); // 16.
  379. // if the author is actually the editor of the resource we'll append ', ed' (or ', eds') to the author string:
  380. // [to distinguish editors from authors in the 'author' field, the 'modify.php' script does append ' (ed)' or ' (eds)' if appropriate,
  381. // so we're just checking for these identifier strings here. Alternatively, we could check whether the editor field matches the author field]
  382. if (preg_match("/[ \r\n]*\(ed\)/", $row['author'])) // single editor
  383. $author = $author . " ed.";
  384. elseif (preg_match("/[ \r\n]*\(eds\)/", $row['author'])) // multiple editors
  385. $author = $author . " eds.";
  386. $record .= $author;
  387. }
  388. if (!empty($row['year'])) // year
  389. {
  390. if (!empty($row['author']))
  391. $record .= ", ";
  392. $record .= $row['year'];
  393. }
  394. if (!empty($row['title'])) // title
  395. {
  396. if (!empty($row['author']) || !empty($row['year']))
  397. $record .= ". ";
  398. $record .= $markupPatternsArray["italic-prefix"] . $row['title'] . $markupPatternsArray["italic-suffix"];
  399. }
  400. if ($row['online_publication'] == "yes") // this record refers to an online publication
  401. $record .= ". [Online]"; // TODO: this may not be entirely correct, since, according to the above mentioned guide, the actual type should be used: e.g. "[e-book]" or "[CD-ROM]"
  402. if (!empty($row['editor']) && !preg_match("/[ \r\n]*\(eds?\)/", $row['author'])) // editor (if different from author, see note above regarding the check for ' (ed)' or ' (eds)')
  403. {
  404. // Call the 'reArrangeAuthorContents()' function (defined in 'include.inc.php') in order to re-order contents of the author field. Required Parameters:
  405. // 1. input: contents of the author field
  406. // 2. input: boolean value that specifies whether the author's family name comes first (within one author) in the source string
  407. // ('true' means that the family name is followed by the given name (or initials), 'false' if it's the other way around)
  408. //
  409. // 3. input: pattern describing old delimiter that separates different authors
  410. // 4. output: for all authors except the last author: new delimiter that separates different authors
  411. // 5. output: for the last author: new delimiter that separates the last author from all other authors
  412. //
  413. // 6. input: pattern describing old delimiter that separates author name & initials (within one author)
  414. // 7. output: for the first author: new delimiter that separates author name & initials (within one author)
  415. // 8. output: for all authors except the first author: new delimiter that separates author name & initials (within one author)
  416. // 9. output: new delimiter that separates multiple initials (within one author)
  417. // 10. output: for the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  418. // 11. output: for all authors except the first author: boolean value that specifies if initials go *before* the author's name ['true'], or *after* the author's name ['false'] (which is the default in the db)
  419. // 12. output: boolean value that specifies whether an author's full given name(s) shall be shortened to initial(s)
  420. //
  421. // 13. output: if the total number of authors is greater than the given number (integer >= 1), only the number of authors given in (14) will be included in the citation along with the string given in (15); keep empty if all authors shall be returned
  422. // 14. output: number of authors (integer >= 1) that is included in the citation if the total number of authors is greater than the number given in (13); keep empty if not applicable
  423. // 15. output: string that's appended to the number of authors given in (14) if the total number of authors is greater than the number given in (13); the actual number of authors can be printed by including '__NUMBER_OF_AUTHORS__' (without quotes) within the string
  424. //
  425. // 16. output: boolean value that specifies whether the re-ordered string shall be returned with higher ASCII chars HTML encoded
  426. $editor = reArrangeAuthorContents($row['editor'], // 1.
  427. true, // 2.
  428. "/ *; */", // 3.
  429. ", ", // 4.
  430. " " . $markupPatternsArray["ampersand"] . " ", // 5.
  431. "/ *, */", // 6.
  432. " ", // 7.
  433. " ", // 8.
  434. ".", // 9.
  435. true, // 10.
  436. true, // 11.
  437. true, // 12.
  438. "4", // 13.
  439. "1", // 14.
  440. " et al", // 15.
  441. $encodeHTML); // 16.
  442. if (!empty($row['author']) || !empty($row['year']) || !empty($row['title']))
  443. $record .= " ";
  444. $record .= " (" . $editor . ", ";
  445. if (preg_match("/^[^;\r\n]+(;[^;\r\n]+)+$/", $row['editor'])) // there are at least two editors (separated by ';')
  446. $record .= "eds.";
  447. else // there's only one editor (or the editor field is malformed with multiple editors but missing ';' separator[s])
  448. $record .= "ed.";
  449. $record .= ")";
  450. }
  451. if (!empty($row['edition']) || !empty($row['volume']))
  452. {
  453. if (!empty($row['author']) || !empty($row['year']) || !empty($row['title']) || (!empty($row['editor']) && !preg_match("/[ \r\n]*\(eds?\)/", $row['author'])))
  454. $record .= ". ";
  455. if ($row['type'] == "Software") // software edition (=version)
  456. {
  457. if (!empty($row['edition']))
  458. {
  459. $record .= "Version " . $row['edition'];
  460. if (!empty($row['volume']) || !empty($row['issue']))
  461. $record .= ", ";
  462. }
  463. if (!empty($row['issue'])) // issue (=day)
  464. $record .= " " . $row['issue'];
  465. if (!empty($row['volume'])) // volume (=month)
  466. $record .= " " . $row['volume'];
  467. }
  468. elseif (!preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $row['edition'])) // regular edition (other than the first)
  469. {
  470. if (preg_match("/^\d{1,3}$/", $row['edition'])) // if the edition field contains a number of up to three digits, we assume it's an edition number (such as "2nd ed.")
  471. {
  472. if ($row['edition'] == "2")
  473. $editionSuffix = "nd";
  474. elseif ($row['edition'] == "3")
  475. $editionSuffix = "rd";
  476. else
  477. $editionSuffix = "th";
  478. }
  479. else
  480. $editionSuffix = "";
  481. if (!empty($row['edition']) && !preg_match("/( ed\.?| edition)$/i", $row['edition']))
  482. $editionSuffix .= " ed.";
  483. $record .= $row['edition'] . $editionSuffix;
  484. if (!empty($row['volume'])) // volume
  485. {
  486. if (!empty($row['edition']) && !preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $row['edition']))
  487. $record .= ", ";
  488. $record .= "vol. " . $row['volume']; // TODO: not sure whether this is correct
  489. }
  490. }
  491. }
  492. if ($row['type'] == "Software") // for software, add software label
  493. {
  494. $record .= ", computer software.";
  495. }
  496. else // add series info
  497. {
  498. if (!preg_match("/\. *$/", $record))
  499. $record .= ".";
  500. if (!empty($row['abbrev_series_title']) OR !empty($row['series_title'])) // if there's either a full or an abbreviated series title
  501. {
  502. $record .= " ";
  503. if (!empty($row['series_title']))
  504. $record .= $row['series_title']; // full series title
  505. // if there's no full series title, we'll use the abbreviated series title instead:
  506. elseif (!empty($row['abbrev_series_title']))
  507. $record .= $row['abbrev_series_title']; // abbreviated series title
  508. if (!empty($row['series_volume'])||!empty($row['series_issue']))
  509. $record .= ", ";
  510. if (!empty($row['series_volume'])) // series volume (I'm not really sure if -- for this cite style -- the series volume & issue should be rather omitted here)
  511. $record .= "vol. " . $row['series_volume']; // TODO: not sure whether this is correct
  512. if (!empty($row['series_issue'])) // series issue (see note for series volume)
  513. {
  514. if (!empty($row['series_volume']))
  515. $record .= ", ";
  516. $record .= "no. " . $row['series_issue']; // TODO: not sure whether this is correct
  517. }
  518. $record .= ".";
  519. }
  520. }
  521. if (!empty($row['thesis'])) // thesis
  522. $record .= " " . $row['thesis'];
  523. if (!empty($row['place']) || !empty($row['publisher']))
  524. {
  525. if (!empty($row['thesis']))
  526. $record .= ".";
  527. if (!empty($row['place'])) // place (NOTE: should we omit the place of publication for theses?)
  528. $record .= " " . $row['place'];
  529. if (!empty($row['publisher'])) // publisher
  530. {
  531. if (!empty($row['place']))
  532. $record .= ":";
  533. $record .= " " . $row['publisher'];
  534. }
  535. }
  536. if ($row['online_publication'] == "yes" || $row['type'] == "Software") // this record refers to an online article, or a computer program/software
  537. {
  538. if (!empty($row['online_citation'])) // online_citation
  539. {
  540. if (!preg_match("/\. *$/", $record))
  541. $record .= ".";
  542. $record .= " " . $row['online_citation'];
  543. }
  544. if (!empty($row['doi']) || !empty($row['url'])) // doi OR url
  545. {
  546. if (!preg_match("/\. *$/", $record))
  547. $record .= ".";
  548. $today = date("j F Y");
  549. $record .= " Available at: " . $markupPatternsArray["underline-prefix"];
  550. if (!empty($row['doi'])) // doi
  551. $uri = "http://dx.doi.org/" . $row['doi'];
  552. else // url
  553. $uri = $row['url'];
  554. if ($encodeHTML)
  555. $record .= encodeHTML($uri);
  556. else
  557. $record .= $uri;
  558. $record .= $markupPatternsArray["underline-suffix"];
  559. $record .= " [accessed " . $today . "]";
  560. }
  561. }
  562. if (!preg_match("/\. *$/", $record)) // if the string doesn't end with a period
  563. $record .= ".";
  564. }
  565. // --- BEGIN POST-PROCESSING -----------------------------------------------------------------------------------------------------------
  566. // do some further cleanup:
  567. $record = trim($record); // remove any preceding or trailing whitespace
  568. return $record;
  569. }
  570. // --- END CITATION STYLE ---
  571. ?>