/[drupal]/contributions/modules/biblio/biblio_style_ama.inc
ViewVC logotype

Contents of /contributions/modules/biblio/biblio_style_ama.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Fri Oct 23 20:19:37 2009 UTC (5 weeks, 1 day ago) by rjerome
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.7: +36 -46 lines
File MIME type: text/x-php
merged changes from DRUPAL-6--1 branch
1 <?php
2 // Original File: ./cite/styles/cite_AMA.php
3 // Original Author(s): Matthias Steffens <mailto:refbase@extracts.de> and
4 // Richard Karnesky <mailto:karnesky@gmail.com>
5
6 // This is a citation style file (which must reside within the 'cite/styles/' sub-directory of your refbase root directory). It contains a
7 // version of the 'citeRecord()' function that outputs a reference list from selected records according to the citation style used by
8 // the American Medical Association (AMA)
9
10 // based on 'cite_Chicago.php'
11
12 // TODO: - abstracts, conference proceedings, patents, reports
13 // - book/volume/report/etc titles should be formatted in heading caps
14 // - don't add a dot if the abbreviated journal (or series title) ends with a dot!
15
16 // Modified for use in biblio by Ron Jerome
17 //
18 // $Id: biblio_style_ama.inc,v 1.1.2.12 2009/10/22 18:17:34 rjerome Exp $
19 /**
20 * Get the style information
21 *
22 * @return
23 * The name of the style
24 */
25 function biblio_style_ama_info() {
26 return array (
27 'ama' => 'American Medical Association (AMA)'
28 );
29 }
30 function biblio_style_ama_author_options() {
31 $author_options = array(
32 'BetweenAuthorsDelimStandard' => ', ',
33 'BetweenAuthorsDelimLastAuthor' => ', ',
34 'AuthorsInitialsDelimFirstAuthor' => ' ',
35 'AuthorsInitialsDelimStandard' => ' ',
36 'betweenInitialsDelim' => '',
37 'initialsBeforeAuthorFirstAuthor' => FALSE,
38 'initialsBeforeAuthorStandard' => FALSE,
39 'shortenGivenNames' => TRUE,
40 'numberOfAuthorsTriggeringEtAl' => 6,
41 'includeNumberOfAuthors' => 3,
42 'customStringAfterFirstAuthors' => ', et al.',
43 'encodeHTML' => true
44 );
45
46 return $author_options;
47 }
48
49 function biblio_style_ama($node, $base = 'biblio', $inline = false) {
50 $markupPatternsArray = array("italic-prefix" => "<i>",
51 "italic-suffix" => "<\/i>",
52 "endash" => '-');
53 $author_options = biblio_style_ama_author_options();
54 $authors = theme('biblio_format_authors', $node->biblio_contributors[1], $author_options, $inline);
55 //$editors = theme('biblio_format_authors', $node->biblio_contributors[2], $author_options, $inline);
56 //if (empty($authors)) $authors = theme('biblio_authors', $node->biblio_contributors[5], 'mla', 5, $inline); // if no authors substitute corp author if available
57 //if (empty($authors)) $authors = '[' . t('Anonymous') . ']'; // use anonymous if we still have nothing.
58 //$output .= '<span class="biblio-authors">' . $authors . "</span>.&nbsp; \n";
59 if (!empty ($node->biblio_citekey)&&(variable_get('biblio_display_citation_key',0))) {
60 $output .= '[' . check_plain($node->biblio_citekey) . '] ';
61 }
62
63 switch ($node->biblio_type) {
64 case 102: //Journal Article
65 case 105: //Newspaper Article
66 case 106: //Magazine Article
67 if(!empty($authors)) {
68 if (!preg_match("/\.*$/", $authors)) {
69 $output .= $authors . ".";
70 }
71 else {
72 $output .= $authors;
73 }
74 }
75
76 if (!empty($node->title)) // title
77 {
78 if (!empty($authors)) $output .= " ";
79 $output .= '"' ;
80 $output .= '<span class="biblio-title-ama">';
81 $url = biblio_get_title_url_info($node);
82 $output .= l($node->title, $url['link'], $url['options']);
83 $output .= "</span>";
84 if (!preg_match("/[?!.]$/", $node->title)) $output .= ".";
85 $output .= '"';
86 }
87
88 // From here on we'll assume that at least either the 'author' or the 'title' field did contain some contents
89 // 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)
90
91 if (!empty($node->biblio_alternate_title)) // abbreviated journal name
92 $output .= " " . $markupPatternsArray["italic-prefix"] . $node->biblio_alternate_title . $markupPatternsArray["italic-suffix"];
93
94 // if there's no abbreviated journal name, we'll use the full journal name
95 elseif (!empty($node->biblio_secondary_title)) // publication (= journal) name
96 $output .= " " . $markupPatternsArray["italic-prefix"] . $node->biblio_secondary_title . $markupPatternsArray["italic-suffix"];
97
98 if ($node->biblio_type == 105 || $node->biblio_type == 106 AND !preg_match("/^\d+$/", $node->biblio_volume)) // for newspaper articles (and magazine articles if w/o volume number), volume (=month) and issue (=day) information is printed before the year
99 {
100 if (!empty($node->biblio_volume)) // volume (=month)
101 $output .= ". " . $node->biblio_volume;
102
103 if (!empty($node->biblio_issue)) // issue (=day)
104 $output .= " " . $node->biblio_issue;
105
106 if (!empty($node->biblio_year)) // year
107 $output .= ", " . $node->biblio_year;
108 }
109 else // journal article (or a magazine article with volume numbers)
110 {
111 if (!empty($node->biblio_year)) // year
112 $output .= ". " . $node->biblio_year;
113
114 if (!empty($node->biblio_volume) || !empty($node->biblio_issue))
115 $output .= ";";
116
117 if (!empty($node->biblio_volume)) // volume
118 $output .= $node->biblio_volume;
119
120 if (!empty($node->biblio_issue)) // issue
121 $output .= "(" . $node->biblio_issue . ")";
122 }
123
124 if (!empty($node->biblio_pages)) // pages
125 {
126 if (!empty($node->biblio_year) || !empty($node->biblio_volume) || !empty($node->biblio_issue) || !empty($node->biblio_alternate_title) || !empty($node->biblio_secondary_title)) // only add ": " if either year, volume, issue, abbrev_journal or publication isn't empty
127 $output .= ":";
128
129 $output .= theme_biblio_page_number($node->biblio_pages, $markupPatternsArray["endash"]); // function 'formatPageInfo()' is defined in 'cite.inc.php'
130 }
131
132 if ($row['online_publication'] == "yes") // this record refers to an online article
133 {
134 // append an optional string (given in 'online_citation') plus the current date and the DOI (or URL):
135
136 $today = date("F j, Y");
137
138 if (!empty($row['online_citation'])) // online_citation
139 {
140 if (!empty($node->biblio_year) || !empty($node->biblio_volume) || !empty($node->biblio_issue) || !empty($node->biblio_alternate_title) || !empty($node->biblio_secondary_title)) // only add ":" or "," if either year, volume, issue, abbrev_journal or publication isn't empty
141 {
142 if (empty($node->biblio_pages))
143 $output .= ":"; // print instead of pages
144 else
145 $output .= ","; // append to pages
146 }
147
148 $output .= $row['online_citation'];
149 }
150
151 if (!empty($row['doi'])) // doi
152 {
153 if (!empty($row['online_citation']) OR (empty($row['online_citation']) AND (!empty($node->biblio_year) || !empty($node->biblio_volume) || !empty($node->biblio_issue) || !empty($node->biblio_alternate_title) || !empty($node->biblio_secondary_title)))) // only add "." if online_citation isn't empty, or else if either year, volume, issue, abbrev_journal or publication isn't empty
154 $output .= ".";
155
156 if ($encodeHTML)
157 $output .= " " . encodeHTML("http://dx.doi.org/" . $row['doi']) . ". Accessed " . $today;
158 else
159 $output .= " " . "http://dx.doi.org/" . $row['doi'] . ". Accessed " . $today;
160 }
161 elseif (!empty($row['url'])) // url
162 {
163 if (!empty($row['online_citation']) OR (empty($row['online_citation']) AND (!empty($node->biblio_year) || !empty($node->biblio_volume) || !empty($node->biblio_issue) || !empty($node->biblio_alternate_title) || !empty($node->biblio_secondary_title)))) // only add "." if online_citation isn't empty, or else if either year, volume, issue, abbrev_journal or publication isn't empty
164 $output .= ".";
165
166 if ($encodeHTML)
167 $output .= " " . encodeHTML($row['url']) . ". Accessed " . $today;
168 else
169 $output .= " " . $row['url'] . ". Accessed " . $today;
170 }
171
172 }
173
174 if (!preg_match("/\. *$/", $output)) $output .= ".";
175
176 break;
177 case 101: //Book Chapter
178 case 103: //Conference Paper
179 if(!empty($authors)) {
180 if (!preg_match("/\.*$/", $authors)) {
181 $output .= $authors . ".";
182 }
183 else {
184 $output .= $authors;
185 }
186 }
187 if (!empty($node->title)) // title
188 {
189 if (!empty($authors)) $output .= " ";
190
191 $output .= '"<i>' ;
192 $output .= '<span class="biblio-title-ama">';
193 $url = biblio_get_title_url_info($node);
194 $output .= l($node->title, $url['link'], $url['options']);
195 $output .= "</span>";
196 $output .= '</i>';
197 if (!preg_match("/[?!.]$/", $node->title)) $output .= ".";
198 $output .= '"';
199 }
200
201
202 if (!empty($node->biblio_contributors[2])) // editor
203 {
204 $editor_options = array(
205 'BetweenAuthorsDelimStandard' => ', ',
206 'BetweenAuthorsDelimLastAuthor' => ', ',
207 'AuthorsInitialsDelimFirstAuthor' => ' ',
208 'AuthorsInitialsDelimStandard' => ' ',
209 'betweenInitialsDelim' => '',
210 'initialsBeforeAuthorFirstAuthor' => FALSE,
211 'initialsBeforeAuthorStandard' => FALSE,
212 'shortenGivenNames' => TRUE,
213 'numberOfAuthorsTriggeringEtAl' => 6,
214 'includeNumberOfAuthors' => 3,
215 'customStringAfterFirstAuthors' => ' et al.',
216 'encodeHTML' => true
217 );
218
219 $editor = theme('biblio_format_authors', $node->biblio_contributors[2], $editor_options, $inline);
220
221 $output .= " In: " . $editor . ", ";
222 if (count ($node->biblio_contributors[2]) > 1) // there are at least two editors (separated by ';')
223 $output .= "eds";
224 else // there's only one editor (or the editor field is malformed with multiple editors but missing ';' separator[s])
225 $output .= "ed";
226 }
227
228 $publication = preg_replace("/[ \r\n]*\(Eds?:[^\)\r\n]*\)/", "", $node->biblio_secondary_title);
229 if (!empty($publication)) // publication
230 {
231 if (!preg_match("/[?!.] *$/", $output)) $output .= ".";
232
233 if (empty($editor))
234 $output .= " In:";
235
236 // TODO: container titles should be formatted in heading caps, however, this doesn't yet work correctly if the publication title contains HTML entities
237 $output .= " " . $markupPatternsArray["italic-prefix"] . $publication . $markupPatternsArray["italic-suffix"];
238 // $output .= " " . $markupPatternsArray["italic-prefix"] . changeCase("heading", $publication) . $markupPatternsArray["italic-suffix"]; // function 'changeCase()' is defined in 'include.inc.php'
239 }
240
241 if (!empty($node->biblio_volume)) // volume
242 {
243 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output)) $output .= ".";
244
245 $output .= " Vol. " . $node->biblio_volume;
246 }
247
248 if (!empty($node->biblio_edition) && !preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $node->biblio_edition)) // edition
249 {
250 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output))
251 $output .= ".";
252
253 if (preg_match("/^\d{1,3}$/", $node->biblio_edition)) // if the edition field contains a number of up to three digits, we assume it's an edition number (such as "2nd ed.")
254 {
255 if ($node->biblio_edition == "2")
256 $editionSuffix = "nd";
257 elseif ($node->biblio_edition == "3")
258 $editionSuffix = "rd";
259 else
260 $editionSuffix = "th";
261 }
262 else
263 $editionSuffix = "";
264
265 if (!preg_match("/( ed\.?| edition)$/i", $node->biblio_edition))
266 $editionSuffix .= " ed.";
267
268 $output .= " " . $node->biblio_edition . $editionSuffix;
269 }
270
271 if (!preg_match("[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$", $output)) $output .= ".";
272
273 if (!empty($node->biblio_place_published)) // place
274 $output .= " " . $node->biblio_place_published;
275
276 if (!empty($node->biblio_publisher)) // publisher
277 {
278 if (!empty($node->biblio_place_published))
279 $output .= ":";
280
281 $output .= " " . $node->biblio_publisher;
282 }
283
284 if (!empty($node->biblio_year)) // year
285 $output .= "; " . $node->biblio_year;
286
287 if (!empty($node->biblio_pages)) // pages
288 $output .= ":" . theme('biblio_page_number', $node->biblio_pages, $markupPatternsArray["endash"]); // function 'formatPageInfo()' is defined in 'cite.inc.php'
289
290 if (!empty($node->biblio_alternate_title) OR !empty($node->biblio_tertiary_title)) // if there's either a full or an abbreviated series title
291 {
292 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output)) $output .= ".";
293
294 $output .= " ";
295
296 if (!empty($node->biblio_alternate_title))
297 $output .= $node->biblio_alternate_title; // abbreviated series title
298
299 // if there's no abbreviated series title, we'll use the full series title instead:
300 elseif (!empty($node->biblio_tertiary_title))
301 $output .= $node->biblio_tertiary_title; // full series title
302
303 if (!empty($node->biblio_volume)||!empty($node->biblio_issue))
304 $output .= " ";
305
306 if (!empty($node->biblio_volume)) // series volume
307 $output .= $node->biblio_volume;
308
309 if (!empty($node->biblio_issue)) // series issue (I'm not really sure if -- for this cite style -- the series issue should be rather omitted here)
310 $output .= "(" . $node->biblio_issue . ")"; // is it correct to format series issues similar to journal article issues?
311 }
312
313 if (!preg_match("/\. *$/", $output))
314 $output .= ".";
315
316 break;
317
318 default : // all other types
319 //TODO
320 // if (ereg("[ \r\n]*\(ed\)", $node->author)) // single editor
321 // $author = $author . ", ed";
322 // elseif (ereg("[ \r\n]*\(eds\)", $node->author)) // multiple editors
323 // $author = $author . ", eds";
324
325 if (!empty($authors)) // author
326 {
327 if (!preg_match("/\. *$/", $authors))
328 $output .= $authors . ".";
329 else
330 $output .= $authors;
331 }
332
333 if (!empty($node->title)) // title
334 {
335 if (!empty($authors))
336 $output .= " ";
337
338 $output .= '<i>';
339 // TODO: book/volume/report/etc titles should be formatted in heading caps, however, this doesn't yet work correctly if the publication title contains HTML entities
340 $output .= '<span class="biblio-title-ama">';
341 $url = biblio_get_title_url_info($node);
342 $output .= l($node->title, $url['link'], $url['options']);
343 $output .= "</span>";
344 $output .= '</i>';
345 }
346 if ($node->biblio_type == "Software") // for software, add software label
347 $output .= " [computer program]";
348
349 if (!empty($node->biblio_volume) AND ($node->biblio_type != "Software")) // volume
350 {
351 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output))
352 $output .= ".";
353
354 $output .= " Vol. " . $node->biblio_volume;
355 }
356
357 if (!empty($node->biblio_edition)) // edition
358 {
359 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output))
360 $output .= ".";
361
362 if ($row['type'] == "Software") // software edition (=version)
363 {
364 $output .= " Version " . $node->biblio_edition;
365 }
366 elseif (!preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $node->biblio_edition)) // edition
367 {
368 if (preg_match("/^\d{1,3}$/", $node->biblio_edition)) // if the edition field contains a number of up to three digits, we assume it's an edition number (such as "2nd ed.")
369 {
370 if ($node->biblio_edition == "2")
371 $editionSuffix = "nd";
372 elseif ($node->biblio_edition == "3")
373 $editionSuffix = "rd";
374 else
375 $editionSuffix = "th";
376 }
377 else
378 $editionSuffix = "";
379
380 if (!preg_match("/( ed\.?| edition)$/i", $node->biblio_edition))
381 $editionSuffix .= " ed.";
382
383 $output .= " " . $node->biblio_edition . $editionSuffix;
384 }
385 }
386
387 if (count($node->biblio_contributors[2])) // editor (if different from author, see note above regarding the check for ' (ed)' or ' (eds)')
388 {
389
390 $editor_options = array(
391 'BetweenAuthorsDelimStandard' => ', ',
392 'BetweenAuthorsDelimLastAuthor' => ', ',
393 'AuthorsInitialsDelimFirstAuthor' => ' ',
394 'AuthorsInitialsDelimStandard' => ' ',
395 'betweenInitialsDelim' => '',
396 'initialsBeforeAuthorFirstAuthor' => FALSE,
397 'initialsBeforeAuthorStandard' => FALSE,
398 'shortenGivenNames' => TRUE,
399 'numberOfAuthorsTriggeringEtAl' => 6,
400 'includeNumberOfAuthors' => 3,
401 'customStringAfterFirstAuthors' => ' et al.',
402 'encodeHTML' => true
403 );
404
405 $editor = theme('biblio_format_authors', $node->biblio_contributors[2], $editor_options, $inline);
406 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output)) $output .= ".";
407
408 $output .= " " . $editor;
409 if (count ($node->biblio_contributors[2]) > 1) // there are at least two editors (separated by ';')
410 $output .= ", eds";
411 else // there's only one editor (or the editor field is malformed with multiple editors but missing ';' separator[s])
412 $output .= ", ed";
413 }
414
415 if (!empty($row['thesis'])) // thesis
416 // TODO: do we need to use the term "[dissertation]" instead of "[Ph.D. thesis]", etc? What about other thesis types then?
417 $output .= " [" . $row['thesis'] . "]";
418
419 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output)) $output .= ".";
420
421 if (!empty($node->biblio_place_published)) // place
422 $output .= " " . $node->biblio_place_published;
423
424 if (!empty($node->biblio_publisher)) // publisher
425 {
426 if (!empty($node->biblio_place_published))
427 $output .= ":";
428
429 $output .= " " . $node->biblio_publisher;
430 }
431
432 $output .= ";";
433
434 if ($row['type'] == "Software") // for software, volume (=month) and issue (=day) information is printed before the year (similar to newspaper articles)
435 {
436 if (!empty($node->biblio_volume)) // volume (=month)
437 $output .= " " . $node->biblio_volume;
438
439 if (!empty($node->biblio_issue)) // issue (=day)
440 $output .= " " . $node->biblio_issue;
441
442 $output .= ",";
443 }
444
445 if (!empty($node->biblio_year)) // year
446 $output .= " " . $node->biblio_year;
447
448 if (!empty($node->biblio_alternate_title) OR !empty($node->biblio_tertiary_title)) // if there's either a full or an abbreviated series title
449 {
450 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output)) $output .= ".";
451
452 $output .= " ";
453
454 if (!empty($node->biblio_alternate_title))
455 $output .= $node->biblio_alternate_title; // abbreviated series title
456
457 // if there's no abbreviated series title, we'll use the full series title instead:
458 elseif (!empty($node->biblio_tertiary_title))
459 $output .= $node->biblio_tertiary_title; // full series title
460
461 if (!empty($node->biblio_volume)||!empty($node->biblio_issue))
462 $output .= " ";
463
464 if (!empty($node->biblio_volume)) // series volume
465 $output .= $node->biblio_volume;
466
467 if (!empty($node->biblio_issue)) // series issue (I'm not really sure if -- for this cite style -- the series issue should be rather omitted here)
468 $output .= "(" . $node->biblio_issue . ")"; // is it correct to format series issues similar to journal article issues?
469 }
470
471 if ($row['online_publication'] == "yes" || $row['type'] == "Software") // this record refers to an online article, or a computer program/software
472 {
473 // append an optional string (given in 'online_citation') plus the current date and the DOI (or URL):
474
475 $today = date("F j, Y");
476
477 if (!empty($row['online_citation'])) // online_citation
478 {
479 if (!preg_match("/\. *$/", $output)) $output .= ".";
480
481 $output .= $row['online_citation'];
482 }
483
484 if (!empty($row['doi'])) // doi
485 {
486 if (!preg_match("/\. *$/", $output)) $output .= ".";
487
488 if ($encodeHTML)
489 $output .= " " . encodeHTML("http://dx.doi.org/" . $row['doi']) . ". Accessed " . $today;
490 else
491 $output .= " " . "http://dx.doi.org/" . $row['doi'] . ". Accessed " . $today;
492 }
493 elseif (!empty($row['url'])) // url
494 {
495 if (!preg_match("/\. *$/", $output)) $output .= ".";
496
497 if ($encodeHTML)
498 $output .= " " . encodeHTML($row['url']) . ". Accessed " . $today;
499 else
500 $output .= " " . $row['url'] . ". Accessed " . $today;
501 }
502
503 }
504
505 if (!preg_match("/\. *$/", $output)) $output .= ".";
506 break;
507 }
508
509 return filter_xss($output, biblio_get_allowed_tags());
510 }
511

  ViewVC Help
Powered by ViewVC 1.1.2