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

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

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


Revision 1.10 - (show annotations) (download) (as text)
Fri Oct 23 20:19:37 2009 UTC (4 weeks, 4 days ago) by rjerome
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.9: +40 -55 lines
File MIME type: text/x-php
merged changes from DRUPAL-6--1 branch
1 <?php
2 // Original File: ./cite/styles/cite_Chicago.php
3 // Original Author(s): Matthias Steffens <mailto:refbase@extracts.de> and
4 // Richard Karnesky <mailto:karnesky@gmail.com>
5 //
6
7 // This is a citation style file (which must reside within the 'cite/styles/' sub-directory of your refbase root directory). It contains a
8 // version of the 'citeRecord()' function that outputs a reference list from selected records according to the citation style documented
9 // in the "Chicago Manual of Style" (2003), and Kate Turabian's "Manual for Writer's of Term Papers, Theses, and Dissertations" (1996)
10
11 // Modified for use in biblio by Ron Jerome
12 //
13 // $Id: biblio_style_chicago.inc,v 1.4.2.12 2009/10/22 18:17:34 rjerome Exp $
14 /**
15 * Get the style information
16 *
17 * @return
18 * The name of the style
19 */
20 function biblio_style_chicago_info() {
21 return array (
22 'chicago' => 'Chicago'
23 );
24 }
25 function biblio_style_chicago_author_options() {
26 $author_options = array(
27 'BetweenAuthorsDelimStandard' =>', ', //4
28 'BetweenAuthorsDelimLastAuthor' => ', and ', //5
29 'AuthorsInitialsDelimFirstAuthor' => ', ', //7
30 'AuthorsInitialsDelimStandard'=> ' ', //8
31 'betweenInitialsDelim' => '. ', //9
32 'initialsBeforeAuthorFirstAuthor' => false, //10
33 'initialsBeforeAuthorStandard' => true, //11
34 'shortenGivenNames' => FALSE, //12
35 'numberOfAuthorsTriggeringEtAl' => 10, //13
36 'includeNumberOfAuthors' => 10, //14
37 'customStringAfterFirstAuthors' => ' et al.',//15
38 'encodeHTML' => true
39 );
40
41 return $author_options;
42 }
43 /**
44 * Apply a bibliographic style to the node
45 *
46 *
47 * @param $node
48 * An object containing the node data to render
49 * @param $base
50 * The base URL of the biblio module (defaults to /biblio)
51 * @param $inline
52 * A logical value indicating if this is being rendered within the
53 * Drupal framwork (false) or we are just passing back the html (true)
54 * @return
55 * The styled biblio entry
56 */
57 function biblio_style_chicago($node, $base = 'biblio', $inline = false) {
58
59 $author_options = biblio_style_chicago_author_options();
60 // $authors = theme('biblio_authors', $node->biblio_contributors[1], 'mla', 1, $inline);
61
62 $authors = theme('biblio_format_authors', $node->biblio_contributors[1], $author_options, $inline);
63 //$editors = theme('biblio_format_authors', $node->biblio_contributors[2], $author_options, $inline);
64 //if (empty($authors)) $authors = theme('biblio_authors', $node->biblio_contributors[5], 'mla', 5, $inline); // if no authors substitute corp author if available
65 //if (empty($authors)) $authors = '[' . t('Anonymous') . ']'; // use anonymous if we still have nothing.
66 //$output .= '<span class="biblio-authors">' . $authors . "</span>.&nbsp; \n";
67 if (!empty ($node->biblio_citekey)&&(variable_get('biblio_display_citation_key',0))) {
68 $output .= '[' . check_plain($node->biblio_citekey) . '] ';
69 }
70
71 switch ($node->biblio_type) {
72 case 102: //Journal Article
73 case 105: //Newspaper Article
74 case 106: //Magazine Article
75 if(!empty($authors)) {
76 if (!preg_match("/\.*$/", $authors))
77 $output .= $authors . ".";
78 else
79 $output .= $authors;
80 }
81
82 if (!empty($node->title)) // title
83 {
84 if (!empty($authors)) $output .= " ";
85 $output .= '"' ;
86 $output .= '<span class="biblio-title-chicago">';
87 $url = biblio_get_title_url_info($node);
88 $output .= l($node->title, $url['link'], $url['options']);
89 $output .= "</span>";
90 if (!preg_match("/[?!.]$/", $node->title)) $output .= ".";
91 $output .= '"';
92 }
93
94 // From here on we'll assume that at least either the 'author' or the 'title' field did contain some contents
95 // 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)
96
97 if (!empty($node->biblio_secondary_title)) // publication (= journal) name
98 $output .= " <i>$node->biblio_secondary_title</i>";
99
100 // if there's no full journal name, we'll use the abbreviated journal name
101 elseif (!empty($node->biblio_alternate_title)) // abbreviated journal name
102 $output .= " <i>$node->biblio_alternate_title</i>";
103
104 if (!empty($node->biblio_volume)) // volume
105 $output .= " " . $node->biblio_volume;
106
107 if (!empty($node->biblio_issue)) // issue
108 $output .= ", no. " . $node->biblio_issue;
109
110 if (!empty($node->biblio_year)) // year
111 $output .= " (" . $node->biblio_year . ")";
112
113 if (!empty($node->biblio_pages)) // pages
114 {
115 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
116 $output .= ": ";
117
118 $output .= theme_biblio_page_number($node->biblio_pages); // function 'formatPageInfo()' is defined in 'cite.inc.php'
119 }
120
121 if ($node->online_publication == "yes") // this record refers to an online article
122 {
123 // append an optional string (given in 'online_citation') plus the current date and the DOI (or URL):
124
125 $today = date("F j, Y");
126
127 if (!empty($node->online_citation)) // online_citation
128 {
129 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
130 {
131 if (empty($node->biblio_pages))
132 $output .= ":"; // print instead of pages
133 else
134 $output .= ","; // append to pages
135 }
136
137 $output .= " " . $node->online_citation;
138 }
139
140 if (!empty($node->doi)) // doi
141 {
142 if (!empty($node->online_citation) OR (empty($node->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
143 $output .= "."; // NOTE: some Chicago examples (e.g. <http://www.lib.berkeley.edu/instruct/guides/chicago-turabianstyle.pdf>) use a comma here (not sure what's correct)
144
145 if ($encodeHTML)
146 $output .= " " . encodeHTML("http://dx.doi.org/" . $node->doi) . " (accessed " . $today . ")";
147 else
148 $output .= " " . "http://dx.doi.org/" . $node->doi . " (accessed " . $today . ")";
149 }
150 elseif (!empty($node->biblio_url)) // url
151 {
152 if (!empty($node->online_citation) OR (empty($node->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
153 $output .= "."; // see note for doi
154
155 if ($encodeHTML)
156 $output .= " " . encodeHTML($node->biblio_url) . " (accessed " . $today . ")";
157 else
158 $output .= " " . $node->biblio_url . " (accessed " . $today . ")";
159 }
160
161 }
162
163 if (!preg_match("/\. *$/", $output)) $output .= ".";
164
165 break;
166 case 101: //Book Chapter
167 case 103: //Conference Paper
168 if(!empty($authors)) {
169 if (!preg_match("/\.*$/", $authors)) {
170 $output .= $authors . ".";
171 }
172 else {
173 $output .= $authors;
174 }
175 }
176 if (!empty($node->title)) // title
177 {
178 if (!empty($authors)) $output .= " ";
179
180 $output .= '"<i>' ;
181 $output .= '<span class="biblio-title-chicago">';
182 $url = biblio_get_title_url_info($node);
183 $output .= l($node->title, $url['link'], $url['options']);
184 $output .= "</span>";
185 $output .= '</i>';
186 if (!preg_match("/[?!.]$/", $node->title)) $output .= ".";
187 $output .= '"';
188 }
189
190 $publication = preg_replace("/[ \r\n]*\(Eds?:[^\)\r\n]*\)/", "", $node->biblio_secondary_title);
191 if (!empty($publication)) // publication
192 $output .= " In <i>$publication</i>";
193
194
195 // From here on we'll assume that at least either the 'author' or the 'title' field did contain some contents
196 // 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)
197
198 if (!empty($node->biblio_contributors[2])) // editor
199 {
200 $editor_options = array(
201 'BetweenAuthorsDelimStandard' => ', ',
202 'BetweenAuthorsDelimLastAuthor' => ' and ',
203 'AuthorsInitialsDelimFirstAuthor' => ' ',
204 'AuthorsInitialsDelimStandard' => ' ',
205 'betweenInitialsDelim' => '. ',
206 'initialsBeforeAuthorFirstAuthor' => TRUE,
207 'initialsBeforeAuthorStandard' => TRUE,
208 'shortenGivenNames' => FALSE,
209 'numberOfAuthorsTriggeringEtAl' => 10,
210 'includeNumberOfAuthors' => 10,
211 'customStringAfterFirstAuthors' => ' et al.',
212 'encodeHTML' => true
213 );
214
215 $editor = theme('biblio_format_authors', $node->biblio_contributors[2], $editor_options, $inline);
216
217 $output .= ", edited by " . $editor;
218 }
219
220 if (!empty($node->biblio_pages)) // pages
221 $output .= ", " . theme_biblio_page_number($node->biblio_pages); // function 'formatPageInfo()' is defined in 'cite.inc.php'
222
223 if (!empty($node->biblio_edition) && !preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $node->biblio_edition)) // edition
224 {
225 if (!preg_match("/[?!.][ \"<i>]*$/", $output)) $output .= ".";
226
227 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.")
228 {
229 if ($node->biblio_edition == "2")
230 $editionSuffix = "nd";
231 elseif ($node->biblio_edition == "3")
232 $editionSuffix = "rd";
233 else
234 $editionSuffix = "th";
235 }
236 else
237 $editionSuffix = "";
238
239 if (!preg_match("/( ed\.?| edition)$/i", $node->biblio_edition))
240 $editionSuffix .= " ed.";
241
242 $output .= " " . $node->biblio_edition . $editionSuffix;
243 }
244
245 if (!empty($node->biblio_volume)) // volume
246 {
247 if (!preg_match("/[?!.][ \"<i>]*$/", $output)) $output .= ".";
248
249 $output .= " Vol. " . $node->biblio_volume;
250 }
251
252 if (!empty($node->biblio_alternate_title) OR !empty($node->biblio_tertiary_title)) // if there's either a full or an abbreviated series title
253 {
254 if (!preg_match("/[?!.][ \"<i>]*$/", $output)) $output .= ".";
255
256 $output .= " ";
257
258 if (!empty($node->biblio_alternate_title))
259 $output .= $node->biblio_alternate_title; // abbreviated series title
260
261 // if there's no abbreviated series title, we'll use the full series title instead:
262 elseif (!empty($node->biblio_tertiary_title))
263 $output .= $node->biblio_tertiary_title; // full series title
264
265 if (!empty($node->biblio_volume)||!empty($node->biblio_issue))
266 $output .= " ";
267
268 if (!empty($node->biblio_volume)) // series volume
269 $output .= $node->biblio_volume;
270
271 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)
272 $output .= ", no. " . $node->biblio_issue; // is it correct to format series issues similar to journal article issues?
273 }
274
275 if (!preg_match("/[?!.][ \"<i>]*$/", $output)) $output .= ".";
276
277 if (!empty($node->biblio_place_published)) // place
278 $output .= " " . $node->biblio_place_published;
279
280 if (!empty($node->biblio_publisher)) // publisher
281 {
282 if (!empty($node->biblio_place_published))
283 $output .= ":";
284
285 $output .= " " . $node->biblio_publisher;
286 }
287
288 if (!empty($node->biblio_year)) // year
289 $output .= ", " . $node->biblio_year;
290
291 if (!preg_match("/\. *$/", $output)) $output .= ".";
292
293 break;
294
295 default : // all other types
296 //TODO
297 // if (preg_match("[ \r\n]*\(ed\)", $node->author)) // single editor
298 // $author = $author . ", ed";
299 // elseif (preg_match("[ \r\n]*\(eds\)", $node->author)) // multiple editors
300 // $author = $author . ", eds";
301
302 if (!empty($authors)) // author
303 {
304 if (!preg_match("/\.*$/", $authors)) {
305 $output .= $authors . ".";
306 }
307 else {
308 $output .= $authors;
309 }
310 }
311
312 if (!empty($node->title)) // title
313 {
314 $url = biblio_get_title_url_info($node);
315 if (!empty($authors))
316 $output .= " ";
317
318 if (!empty($node->thesis)) // thesis
319 {
320 $output .= '<span class="biblio-title-chicago">';
321 $output .= '"' . l($node->title, $url['link'], $url['options']);
322 $output .= "</span>";
323 if (!preg_match("/[?!.]$/", $node->title)) $output .= ".";
324 $output .= '"';
325 }
326 else // not a thesis
327 $output .= '<i>';
328 $output .= '<span class="biblio-title-chicago">';
329 $output .= l($node->title, $url['link'], $url['options']);
330 $output .= "</span>";
331 $output .= '</i>';
332 }
333 $publication = preg_replace("/[ \r\n]*\(Eds?:[^\)\r\n]*\)/", "", $node->biblio_secondary_title);
334 if (!empty($publication)) // publication
335 $output .= " In <i>$publication</i>";
336
337 if (count($node->biblio_contributors[2])) // editor (if different from author, see note above regarding the check for ' (ed)' or ' (eds)')
338 {
339
340 $editor_options = array(
341 'BetweenAuthorsDelimStandard' => ', ',
342 'BetweenAuthorsDelimLastAuthor' => ' and ',
343 'AuthorsInitialsDelimFirstAuthor' => ' ',
344 'AuthorsInitialsDelimStandard' => ' ',
345 'betweenInitialsDelim' => '. ',
346 'initialsBeforeAuthorFirstAuthor' => TRUE,
347 'initialsBeforeAuthorStandard' => TRUE,
348 'shortenGivenNames' => FALSE,
349 'numberOfAuthorsTriggeringEtAl' => 10,
350 'includeNumberOfAuthors' => 10,
351 'customStringAfterFirstAuthors' => ' et al.',
352 'encodeHTML' => true
353 );
354
355 $editor = theme('biblio_format_authors', $node->biblio_contributors[2], $editor_options, $inline);
356 $output .= ", Edited by " . $editor;
357 }
358
359 if (!empty($node->biblio_edition) && !preg_match("/^(1|1st|first|one)( ed\.?| edition)?$/i", $node->biblio_edition)) // edition
360 {
361 if (!preg_match("/[?!.][ \"<i>]*$/", $output)) $output .= ".";
362
363 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.")
364 {
365 if ($node->biblio_edition == "2")
366 $editionSuffix = "nd";
367 elseif ($node->biblio_edition == "3")
368 $editionSuffix = "rd";
369 else
370 $editionSuffix = "th";
371 }
372 else
373 $editionSuffix = "";
374
375 if (!preg_match("/( ed\.?| edition)$/i", $node->biblio_edition)) $editionSuffix .= " ed.";
376
377 $output .= " " . $node->biblio_edition . $editionSuffix;
378 }
379
380 if (!empty($node->biblio_volume)) // volume
381 {
382 if (!preg_match("/[?!.][ \"<i>]*$/", $output)) $output .= ".";
383
384 $output .= " Vol. " . $node->biblio_volume;
385 }
386
387 if (!empty($node->biblio_alternate_title) OR !empty($node->biblio_tertiary_title)) // if there's either a full or an abbreviated series title
388 {
389 if (!preg_match("/[?!.][ \"<i>]*$/", $output)) $output .= ".";
390
391 $output .= " ";
392
393 if (!empty($node->biblio_alternate_title))
394 $output .= $node->biblio_alternate_title; // abbreviated series title
395
396 // if there's no abbreviated series title, we'll use the full series title instead:
397 elseif (!empty($node->biblio_tertiary_title))
398 $output .= $node->biblio_tertiary_title; // full series title
399
400 if (!empty($node->biblio_volume)||!empty($node->biblio_issue))
401 $output .= " ";
402
403 if (!empty($node->biblio_volume)) // series volume
404 $output .= $node->biblio_volume;
405
406 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)
407 $output .= ", no. " . $node->biblio_issue; // is it correct to format series issues similar to journal article issues?
408 }
409
410 if (!empty($node->thesis)) // thesis
411 {
412 if (!preg_match("/[?!.][ \"" . $markupPatternsArray["italic-suffix"] . "]*$/", $output)) $output .= ".";
413
414 $output .= " " . $node->thesis;
415 $output .= ", " . $node->biblio_publisher;
416 }
417 else // not a 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
433 if (!empty($node->biblio_year)) // year
434 $output .= ", ".$node->biblio_year;
435
436 if ($node->online_publication == "yes") // this record refers to an online article
437 {
438 // append an optional string (given in 'online_citation') plus the current date and the DOI (or URL):
439
440 $today = date("F j, Y");
441
442 if (!empty($node->online_citation)) // online_citation
443 {
444 if (!preg_match("/\. *$/", $output)) $output .= ".";
445
446 $output .= " " . $node->online_citation;
447 }
448
449 if (!empty($node->doi)) // doi
450 {
451 if (!preg_match("/\. *$/", $output)) $output .= ".";
452
453 if ($encodeHTML)
454 $output .= " " . encodeHTML("http://dx.doi.org/" . $node->doi) . " (accessed " . $today . ")";
455 else
456 $output .= " " . "http://dx.doi.org/" . $node->doi . " (accessed " . $today . ")";
457 }
458 elseif (!empty($node->biblio_url)) // url
459 {
460 if (!preg_match("/\. *$/", $output)) $output .= ".";
461
462 if ($encodeHTML)
463 $output .= " " . encodeHTML($node->biblio_url) . " (accessed " . $today . ")";
464 else
465 $output .= " " . $node->biblio_url . " (accessed " . $today . ")";
466 }
467
468 }
469
470 if (!preg_match("/\. *$/", $output)) $output .= ".";
471 break;
472 }
473
474 return filter_xss($output, biblio_get_allowed_tags());
475 }
476

  ViewVC Help
Powered by ViewVC 1.1.2