1<?php
2/********************************
3OSBib:
4A collection of PHP classes to create and manage bibliographic formatting for OS bibliography software
5using the OSBib standard.
6
7Released through http://bibliophile.sourceforge.net under the GPL licence.
8Do whatever you like with this -- some credit to the author(s) would be appreciated.
9
10If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net
11so that your improvements can be added to the release package.
12
13Adapted from WIKINDX: http://wikindx.sourceforge.net
14
15Mark Grimshaw 2005
16http://bibliophile.sourceforge.net
17********************************/
18/*****
19*	TEMPLATE PREVIEW class.
20*
21*	Preview bibliographic style templates.
22*
23*	$Header: /cvsroot/bibliophile/OSBib/create/PREVIEWSTYLE.php,v 1.1 2005/06/25 02:57:34 sirfragalot Exp $
24*****/
25class PREVIEWSTYLE
26{
27	function PREVIEWSTYLE($vars)
28	{
29		$this->vars = $vars;
30		include_once("../format/BIBFORMAT.php");
31		include_once("MISC.php");
32		include_once("MESSAGES.php");
33		$this->messages = new MESSAGES();
34		include_once("ERRORS.php");
35		$this->errors = new ERRORS();
36		$this->bibformat = new BIBFORMAT(FALSE, FALSE, TRUE);
37	}
38/**
39* display
40*
41* @author Mark Grimshaw
42*/
43	function display()
44	{
45		include_once("ADMINSTYLE.php");
46		include_once("../STYLEMAP.php");
47		$map = new STYLEMAP();
48		$templateNameArray = split("_", stripslashes($this->vars['templateName']), 2);
49		$type = $templateNameArray[1];
50		$templateString = stripslashes($this->vars['templateString']);
51		if(!$templateString)
52			return $this->errors->text("inputError", "missing");
53		$templateArray = ADMINSTYLE::parseStringToArray($type, $templateString, $map, TRUE);
54		if(!$templateArray)
55			return $this->errors->text("inputError", "invalid");
56		$style = unserialize(stripslashes($this->vars['style']));
57		foreach($style as $key => $value)
58			$this->bibformat->style[str_replace("style_", "", $key)] = $value;
59		if(array_key_exists('independent', $templateArray))
60		{
61			$temp = $templateArray['independent'];
62			foreach($temp as $key => $value)
63			{
64				$split = split("_", $key);
65				$independent[$split[1]] = $value;
66			}
67			$templateArray['independent'] = $independent;
68		}
69		$this->bibformat->$type = $templateArray;
70//		print_r($this->bibformat->$type); print "<P>";
71//		print_r($this->bibformat->style); print "<P>";
72		$this->loadArrays($type);
73		$pString = $this->process($type);
74		return MISC::b($this->messages->text("resourceType", $type) . ":") . MISC::br() . $pString;
75	}
76// Process the example.
77	function process($type)
78	{
79// For WIKINDX, if type == book or book article and there exists both 'year1' and 'year2' in $row (entered as
80// publication year and reprint year respectively), then switch these around as 'year1' is
81// entered in the style template as 'originalPublicationYear' and 'year2' should be 'publicationYear'.
82		if(($type == 'book') || ($type == 'book_article'))
83		{
84			$year2 = stripslashes($this->row['year2']);
85			if($year2 && !$this->row['year1'])
86			{
87				$this->row['year1'] = $year2;
88				unset($this->row['year2']);
89			}
90			else if($year2 && $this->row['year1'])
91			{
92				$this->row['year2'] = stripslashes($this->row['year1']);
93				$this->row['year1'] = $year2;
94			}
95		}
96		$this->row = $this->bibformat->preProcess($type, $this->row);
97// Return $type is the OSBib resource type ($this->book, $this->web_article etc.) as used in STYLEMAP
98		$type = $this->bibformat->type;
99// Various types of creator
100		for($index = 1; $index <= 5; $index++)
101		{
102			$nameType = 'creator' . $index;
103			if(array_key_exists($nameType, $this->bibformat->styleMap->$type))
104				$this->bibformat->formatNames($this->$nameType, 'creator' . $index);
105		}
106// The title of the resource
107		$this->createTitle();
108// edition
109		if($editionKey = array_search('edition', $this->bibformat->styleMap->$type))
110			$this->createEdition($editionKey);
111// pageStart and pageEnd
112		$this->pages = FALSE; // indicates not yet created pages for articles
113		if(array_key_exists('pages', $this->bibformat->styleMap->$type))
114			$this->createPages();
115// Date
116		if(array_key_exists('date', $this->bibformat->styleMap->$type))
117			$this->createDate();
118// runningTime for film/broadcast
119		if(array_key_exists('runningTime', $this->bibformat->styleMap->$type))
120			$this->createRunningTime();
121// web_article URL
122		if(array_key_exists('URL', $this->bibformat->styleMap->$type) &&
123			($itemElement = $this->createUrl()))
124			$this->bibformat->addItem($itemElement, 'URL', FALSE);
125// the rest...  All other database resource fields that do not require special formatting/conversion.
126		$this->bibformat->addAllOtherItems($this->row);
127// We now have an array for this item where the keys match the key names of $this->styleMap->$type
128// where $type is book, journal_article, thesis etc. and are now ready to map this against the defined
129// bibliographic style for each resource ($this->book, $this->book_article etc.).
130// This bibliographic style array not only provides the formatting and punctuation for each field but also
131// provides the order. If a field name does not exist in this style array, we print nothing.
132		$pString = $this->bibformat->map();
133// ordinals such as 5$^{th}$
134		$pString = preg_replace_callback("/(\d+)\\$\^\{(.*)\}\\$/", array($this, "ordinals"), $pString);
135// remove extraneous {...}
136		return preg_replace("/{(.*)}/U", "$1", $pString);
137	}
138// callback for ordinals above
139	function ordinals($matches)
140	{
141		return $matches[1] . "<sup>" . $matches[2] . "</sup>";
142	}
143// Create the resource title
144	function createTitle()
145	{
146		$pString = stripslashes($this->row['noSort']) . ' ' .
147			stripslashes($this->row['title']);
148		if($this->row['subtitle'])
149			$pString .= ': ' . stripslashes($this->row['subtitle']);
150// anything enclosed in {...} is to be left as is
151		$this->bibformat->formatTitle($pString, "{", "}");
152	}
153// Create the URL
154	function createUrl()
155	{
156		if(!$this->row['url'])
157			return FALSE;
158		$url = htmlspecialchars(stripslashes($this->row['url']));
159		unset($this->row['url']);
160		return MISC::a('rLink', $url, $url, "_blank");
161	}
162// Create date
163	function createDate()
164	{
165		$startDay = isset($this->row['miscField2']) ? stripslashes($this->row['miscField2']) : FALSE;
166		$startMonth = isset($this->row['miscField3']) ? stripslashes($this->row['miscField3']) : FALSE;
167		unset($this->row['miscField2']);
168		unset($this->row['miscField3']);
169		$endDay = isset($this->row['miscField5']) ? stripslashes($this->row['miscField5']) : FALSE;
170		$endMonth = isset($this->row['miscField6']) ? stripslashes($this->row['miscField6']) : FALSE;
171		unset($this->row['miscField5']);
172		unset($this->row['miscField6']);
173		$startDay = ($startDay == 0) ? FALSE : $startDay;
174		$startMonth = ($startMonth == 0) ? FALSE : $startMonth;
175		if(!$startMonth)
176			return;
177		$endDay = ($endDay == 0) ? FALSE : $endDay;
178		$endMonth = ($endMonth == 0) ? FALSE : $endMonth;
179		$this->bibformat->formatDate($startDay, $startMonth, $endDay, $endMonth);
180	}
181// Create runningTime for film/broadcast
182	function createRunningTime()
183	{
184		$minutes = stripslashes($this->row['miscField1']);
185		$hours = stripslashes($this->row['miscField4']);
186		if(!$hours && !$minutes)
187			return;
188		if(!$hours)
189			$hours = 0;
190		$this->bibformat->formatRunningTime($minutes, $hours);
191	}
192// Create the edition number
193	function createEdition($editionKey)
194	{
195		if(!$this->row[$editionKey])
196			return FALSE;
197		$edition = stripslashes($this->row[$editionKey]);
198		$this->bibformat->formatEdition($edition);
199	}
200// Create page start and page end
201	function createPages()
202	{
203		if(!$this->row['pageStart'] || $this->pages) // empty field or page format already done
204		{
205			$this->pages = TRUE;
206			return;
207		}
208		$this->pages = TRUE;
209		$start = trim(stripslashes($this->row['pageStart']));
210		$end = $this->row['pageEnd'] ? trim(stripslashes($this->row['pageEnd'])) : FALSE;
211		$this->bibformat->formatPages($start, $end);
212	}
213/**
214* Example values for  resources and creators
215*/
216	function loadArrays($type)
217	{
218// Some of these default values may be overridden depending on the resource type.
219// The values here are the keys of resource type arrays in STYLEMAP.php
220		$this->row = array(
221					'noSort'			=>				"The",
222					'title' 			=>				"{OSBib System}",
223					'subtitle'			=>				"Bibliographic formatting as it should be",
224					'year1'				=>				"2003", // publicationYear
225					'year2'				=>				"2004", // reprintYear
226					'year3'				=>				"2001-2003", // volume set publication year(s)
227					'pageStart'			=>				"109",
228					'pageEnd'			=>				"122",
229					'miscField2'		=>				'21', // start day
230					'miscField3'		=>				'8', // start month
231					'miscField4'		=>				'12', // numberOfVolumes
232					'field1'			=>				'The Software Series', // seriesTitle
233					'field2'			=>				'3', // edition
234					'field3'			=>				'9', // seriesNumber
235					'field4'			=>				'III', // volumeNumber
236					'field5'			=>				'35', // umber
237					'url'				=>				'http://bibliophile.sourceforge.net',
238					'isbn'				=>				'0-9876-123456',
239					'publisherName'		=>				'Botswana Books',
240					'publisherLocation'	=>				'Selebi Phikwe',
241					'collectionTitle'	=>				'The Best of Open Source Software',
242					'collectionTitleShort'	=>			'Best_OSS',
243					);
244		$authors = array(
245					0	=>	array(
246							'surname'		=>			'Grimshaw',
247							'firstname'		=>			'Mark',
248							'initials'		=>			'N',
249							'prefix'		=>			'',
250							),
251					1	=>	array(
252							'surname'		=>			'Boulanger',
253							'firstname'		=>			'Christian',
254							'initials'		=>			'',
255							'prefix'		=>			'',
256							),
257					2	=>	array(
258							'surname'		=>			'Rossato',
259							'firstname'		=>			'Andrea',
260							'initials'		=>			'',
261							'prefix'		=>			'',
262							),
263					4	=>	array(
264							'surname'		=>			'Guillaume',
265							'firstname'		=>			'Gardey',
266							'initials'		=>			'',
267							'prefix'		=>			'',
268							),
269					);
270		$editors = array(
271					0	=>	array(
272							'surname'		=>			'Mouse',
273							'firstname'		=>			'Mickey',
274							'initials'		=>			'',
275							'prefix'		=>			'',
276							),
277					1	=>	array(
278							'surname'		=>			'Duck',
279							'firstname'		=>			'Donald',
280							'initials'		=>			'D D',
281							'prefix'		=>			'de',
282							),
283					);
284		$revisers = array(
285					0	=>	array(
286							'surname'		=>			'Bush',
287							'firstname'		=>			'George',
288							'initials'		=>			'W',
289							'prefix'		=>			'',
290							),
291					);
292		$translators = array(
293					0	=>	array(
294							'surname'		=>			'Lenin',
295							'firstname'		=>			'V I',
296							'initials'		=>			'',
297							'prefix'		=>			'',
298							),
299					);
300		$seriesEditors = array(
301					0	=>	array(
302							'surname'		=>			'Freud',
303							'firstname'		=>			'S',
304							'initials'		=>			'',
305							'prefix'		=>			'',
306							),
307					);
308		$composers = array(
309					0	=>	array(
310							'surname'		=>			'Mozart',
311							'firstname'		=>			'Wolfgang Amadeus',
312							'initials'		=>			'',
313							'prefix'		=>			'',
314							),
315					);
316		$performers = array(
317					0	=>	array(
318							'surname'		=>			'Led Zeppelin',
319							'firstname'		=>			'',
320							'initials'		=>			'',
321							'prefix'		=>			'',
322							),
323					);
324		$artists = array(
325					0	=>	array(
326							'surname'		=>			'Vinci',
327							'firstname'		=>			'Leonardo',
328							'initials'		=>			'',
329							'prefix'		=>			'da',
330							),
331					);
332		$this->creator1 = $authors;
333		$this->creator2 = $editors;
334		$this->creator3 = $revisers;
335		$this->creator4 = $translators;
336		$this->creator5 = $seriesEditors;
337// For various types, override default settings above
338		if($type == 'genericMisc')
339		{
340			$this->row['field2'] = 'software';
341			$this->row['subtitle'] = '';
342			$this->row['miscField2'] = '';
343			$this->row['publisherName'] = 'Kalahari Soft';
344		}
345		else if ($type == 'magazine_article')
346		{
347			$this->row['noSort'] = '';
348			$this->row['subtitle'] = '';
349			$this->row['title'] = '{OSS} Between the Sheets';
350			$this->row['collectionTitle'] = 'The Scandal Rag';
351			$this->row['collectionTitleShort'] = 'RAG';
352			$this->row['field2'] = 'interview';
353			$this->row['field4'] = 'Winter';
354			$this->row['miscField5'] = '27'; // end day
355			$this->row['miscField6'] = '8'; // end month
356		}
357		else if ($type == 'journal_article')
358		{
359			$this->row['field1'] = '23'; // volume number
360			$this->row['miscField2'] = '';
361			$this->row['miscField6'] = '9'; // end month
362		}
363		else if ($type == 'newspaper_article')
364		{
365			$this->row['field1'] = 'G2'; // section
366			$this->row['field2'] = 'Gabarone';
367			$this->row['collectionTitle'] = 'TseTswana Times';
368			$this->row['collectionTitleShort'] = 'TsTimes';
369		}
370		else if ($type == 'proceedings')
371		{
372			$this->row['publisherName'] = 'International Association of Open Source Software';
373			$this->row['publisherLocation'] = 'Serowe';
374			$this->row['miscField5'] = '3'; // end day
375			$this->row['miscField6'] = '9'; // end month
376		}
377		else if ($type == 'conference_paper')
378		{
379			$this->row['publisherName'] = 'International Association of Open Source Software';
380			$this->row['publisherLocation'] = 'Serowe';
381		}
382		else if ($type == 'proceedings_article')
383		{
384			$this->row['publisherName'] = 'International Association of Open Source Software';
385			$this->row['publisherLocation'] = 'Serowe';
386			$this->row['miscField5'] = '3'; // end day
387			$this->row['miscField6'] = '9'; // end month
388			$this->row['collectionTitle'] = '7th. International OSS Conference';
389			$this->row['collectionTitleShort'] = '7_IntOSS';
390		}
391		else if ($type == 'thesis')
392		{
393			$this->row['field1'] = 'PhD';
394			$this->row['field2'] = 'thesis';
395			$this->row['field5'] = 'Pie in the Sky'; // Dept.
396			$this->row['publisherName'] = 'University of Bums on Seats';
397			$this->row['publisherLocation'] = 'Laputia';
398		}
399		else if ($type == 'web_article')
400		{
401			$this->row['field1'] = '23';
402		}
403		else if ($type == 'film')
404		{
405			$this->row['noSort'] = '';
406			$this->row['subtitle'] = '';
407			$this->row['title'] = 'Kill Will Vol. 3';
408			$this->row['publisherName'] = 'Totally Brain Dead Films';
409			$this->row['publisherLocation'] = '';
410			$this->row['field1'] = 'USA';
411			$this->row['miscField1'] = '59'; // minutes
412			$this->row['miscField4'] = '5'; // hours
413		}
414		else if ($type == 'broadcast')
415		{
416			$this->row['noSort'] = '';
417			$this->row['subtitle'] = '';
418			$this->row['title'] = 'We put people on TV and humiliate them';
419			$this->row['publisherName'] = 'Lowest Common Denominator Productions';
420			$this->row['publisherLocation'] = 'USA';
421			$this->row['miscField1'] = '45'; // minutes
422			$this->row['miscField4'] = ''; // hours
423		}
424		else if ($type == 'music_album')
425		{
426			$this->row['noSort'] = '';
427			$this->row['subtitle'] = 'Canon & Gigue';
428			$this->row['title'] = 'Pachelbel';
429			$this->row['isbn'] = '447-285-2';
430			$this->row['publisherName'] = 'Archiv';
431			$this->row['field2'] = 'CD'; // medium
432			$this->row['year1'] = '1982-1983';
433		}
434		else if ($type == 'music_track')
435		{
436			$this->row['noSort'] = '';
437			$this->row['subtitle'] = '';
438			$this->row['title'] = 'Dazed and Confused';
439			$this->row['collectionTitle'] = 'Led Zeppelin 1';
440			$this->row['collectionTitleShort'] = 'LZ1';
441			$this->row['isbn'] = '7567826322';
442			$this->row['publisherName'] = 'Atlantic';
443			$this->row['field2'] = 'CD'; // medium
444			$this->row['year1'] = '1994';
445		}
446		else if ($type == 'music_score')
447		{
448			$this->row['noSort'] = '';
449			$this->row['subtitle'] = '';
450			$this->row['title'] = 'Sonata in A Minor';
451			$this->row['isbn'] = '3801 05945';
452			$this->row['publisherName'] = 'Alfred Publishing';
453			$this->row['publisherLocation'] = 'New York';
454			$this->row['year1'] = '1994';
455		}
456		else if ($type == 'artwork')
457		{
458			$this->row['noSort'] = '';
459			$this->row['subtitle'] = '';
460			$this->row['title'] = 'Art? What Art?';
461			$this->row['publisherName'] = 'More Money than Sense';
462			$this->row['publisherLocation'] = 'New York';
463			$this->row['field2'] = 'Movement in protoplasma';
464			$this->creator1 = $artists;
465		}
466		else if ($type == 'software')
467		{
468			$this->row['field2'] = 'PHP source code'; // type
469			$this->row['field4'] = '1.3'; // version
470			$this->row['publisherName'] = 'Kalahari Soft';
471			$this->row['publisherLocation'] = 'Maun';
472		}
473		else if ($type == 'audiovisual')
474		{
475			$this->row['noSort'] = '';
476			$this->row['subtitle'] = '';
477			$this->row['title'] = 'Whispering Sands';
478			$this->row['field1'] = 'Chobe ArtWorks Series'; // series title
479			$this->row['field2'] = 'video installation'; //medium
480			$this->row['field4'] = 'IV'; // series number
481			$this->row['publisherName'] = 'Ephemera';
482			$this->row['publisherLocation'] = 'Maun';
483			$this->creator1 = $artists;
484		}
485		else if ($type == 'database')
486		{
487			$this->row['noSort'] = 'The';
488			$this->row['subtitle'] = 'Sotware Listings';
489			$this->row['title'] = 'Blue Pages';
490			$this->row['publisherName'] = 'Kalahari Soft';
491			$this->row['publisherLocation'] = 'Maun';
492		}
493		else if ($type == 'government_report')
494		{
495			$this->row['noSort'] = 'The';
496			$this->row['subtitle'] = '';
497			$this->row['title'] = 'State of Things to Come';
498			$this->row['field1'] = 'Prognostications'; // section
499			$this->row['field2'] = 'Pie in the Sky'; // department
500			$this->row['publisherName'] = 'United Nations';
501		}
502		else if ($type == 'hearing')
503		{
504			$this->row['field1'] = 'Committee on Unworldly Activities'; // committee
505			$this->row['field2'] = 'United Nations'; // legislative body
506			$this->row['field3'] = 'Summer'; //session
507			$this->row['field4'] = '113'; // document number
508			$this->row['miscField4'] = '27'; // no. of volumes
509		}
510		else if ($type == 'statute')
511		{
512			$this->row['field1'] = '101.43a'; // public law no.
513			$this->row['field2'] = 'Lex Hammurabi'; // code
514			$this->row['field3'] = 'Autumn'; //session
515			$this->row['field4'] = '34-A'; // section
516			$this->row['year1'] = '1563 BC';
517		}
518		else if ($type == 'legal_ruling')
519		{
520			$this->row['noSort'] = 'The';
521			$this->row['subtitle'] = '';
522			$this->row['title'] = 'People v. George';
523			$this->row['field1'] = 'Court of Public Law'; // section
524			$this->row['field2'] = 'Appellate Decision'; // type
525			$this->row['publisherName'] = 'Legal Pulp';
526			$this->row['publisherLocation'] = 'Gabarone';
527		}
528		else if ($type == 'case')
529		{
530			$this->row['noSort'] = 'The';
531			$this->row['subtitle'] = '';
532			$this->row['title'] = 'People v. George';
533			$this->row['field1'] = 'Public Law'; // reporter
534			$this->row['field4'] = 'XIV'; // reporter volume
535			$this->row['publisherName'] = 'Supreme Court';
536		}
537		else if ($type == 'bill')
538		{
539			$this->row['noSort'] = 'The';
540			$this->row['subtitle'] = '';
541			$this->row['title'] = 'People v. George';
542			$this->row['field1'] = 'Court of Public Law'; // section
543			$this->row['field2'] = 'Lex Hammurabi'; // code
544			$this->row['field4'] = 'Spring'; // session
545			$this->row['publisherName'] = 'United Nations';
546			$this->row['publisherLocation'] = 'New York';
547		}
548		else if ($type == 'patent')
549		{
550			$this->row['field1'] = 'Journal of Patents'; // publishedSource
551			$this->row['field3'] = '289763[e].x-233'; // application no.
552			$this->row['field4'] = 'bibliographic software'; // type
553			$this->row['field5'] = '5564763[E].X-233'; // int. pat. no.
554			$this->row['field6'] = 'OSBib'; // int. title
555			$this->row['field7'] = 'software'; // int. class
556			$this->row['field8'] = '0-84784-AAH.z'; // pat. no.
557			$this->row['field9'] = 'not awarded'; // legal status
558			$this->row['publisherName'] = 'Lawyers Inc.'; // assignee
559			$this->row['publisherLocation'] = 'New Zealand';
560		}
561		else if ($type == 'personal')
562		{
563			$this->row['noSort'] = '';
564			$this->row['subtitle'] = '';
565			$this->row['title'] = 'Save up to 80% on Microsoft Products!';
566			$this->row['field2'] = 'email'; // type
567		}
568		else if ($type == 'unpublished')
569		{
570			$this->row['field2'] = 'manuscript'; // type
571			$this->row['publisherName'] = 'University of Bums on Seats';
572			$this->row['publisherLocation'] = 'Laputia';
573		}
574		else if ($type == 'classical')
575		{
576			$this->row['noSort'] = '';
577			$this->row['subtitle'] = '';
578			$this->row['title'] = 'Sed quis custodiet ipsos custodes?';
579			$this->row['field4'] = 'Codex XIX'; // volume
580			$this->row['year1'] = '114 BC'; // volume
581		}
582		else if ($type == 'manuscript')
583		{
584			$this->row['field2'] = 'manuscript'; // type
585			$this->row['publisherName'] = 'University of Bums on Seats';
586			$this->row['publisherLocation'] = 'Laputia';
587		}
588		else if ($type == 'map')
589		{
590			$this->row['noSort'] = '';
591			$this->row['subtitle'] = '';
592			$this->row['title'] = 'Mappa Mundi';
593			$this->row['field1'] = 'Maps of the World'; // series title
594			$this->row['field2'] = 'isomorphic projection'; // type
595		}
596		else if ($type == 'chart')
597		{
598			$this->row['noSort'] = '';
599			$this->row['subtitle'] = '';
600			$this->row['title'] = 'Incidence of Sniffles in the New York Area';
601			$this->row['field1'] = 'sniff_1.gif'; // filename
602			$this->row['field2'] = 'The GIMP'; // program
603			$this->row['field3'] = '800*600'; // size
604			$this->row['field4'] = 'GIF'; // type
605			$this->row['field5'] = '1.1a'; // version
606			$this->row['field6'] = '11'; // number
607			$this->row['publisherName'] = 'University of Bums on Seats';
608			$this->row['publisherLocation'] = 'Laputia';
609		}
610		else if ($type == 'miscellaneous')
611		{
612			$this->row['noSort'] = '';
613			$this->row['subtitle'] = '';
614			$this->row['title'] = 'Making Sunlight from Cucumbers';
615			$this->row['field2'] = 'thin air'; // medium
616			$this->row['publisherName'] = 'University of Bums on Seats';
617			$this->row['publisherLocation'] = 'Laputia';
618		}
619	}
620}
621?>
622