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

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

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


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

  ViewVC Help
Powered by ViewVC 1.1.2