ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
BibTex.php
Go to the documentation of this file.
1 <?php
2  /* vim: set ts=4 sw=4: */
26 require_once 'PEAR.php' ;
78 {
85  var $data;
92  var $content;
142 
149  function Structures_BibTex($options = array())
150  {
151  $this->_delimiters = array('"'=>'"',
152  '{'=>'}');
153  $this->data = array();
154  $this->content = '';
155  //$this->_stripDelimiter = $stripDel;
156  //$this->_validate = $val;
157  $this->warnings = array();
158  $this->_options = array(
159  'stripDelimiter' => true,
160  'validate' => true,
161  'unwrap' => false,
162  'wordWrapWidth' => false,
163  'wordWrapBreak' => "\n",
164  'wordWrapCut' => 0,
165  'removeCurlyBraces' => false,
166  'extractAuthors' => true,
167  );
168  foreach ($options as $option => $value) {
169  $test = $this->setOption($option, $value);
170  if (PEAR::isError($test)) {
171  //Currently nothing is done here, but it could for example raise an warning
172  }
173  }
174  $this->rtfstring = 'AUTHORS, "{\b TITLE}", {\i JOURNAL}, YEAR';
175  $this->htmlstring = 'AUTHORS, "<strong>TITLE</strong>", <em>JOURNAL</em>, YEAR<br />';
176  $this->allowedEntryTypes = array(
177  'article',
178  'book',
179  'booklet',
180  'confernce',
181  'inbook',
182  'incollection',
183  'inproceedings',
184  'manual',
185  'mastersthesis',
186  'misc',
187  'phdthesis',
188  'proceedings',
189  'techreport',
190  'unpublished'
191  );
192  $this->authorstring = 'VON LAST, JR, FIRST';
193  }
194 
203  function setOption($option, $value)
204  {
205  $ret = true;
206  if (array_key_exists($option, $this->_options)) {
207  $this->_options[$option] = $value;
208  } else {
209  $ret = PEAR::raiseError('Unknown option '.$option);
210  }
211  return $ret;
212  }
213 
221  function loadFile($filename)
222  {
223  if (file_exists($filename)) {
224  if (($this->content = @file_get_contents($filename)) === false) {
225  return PEAR::raiseError('Could not open file '.$filename);
226  } else {
227  $this->_pos = 0;
228  $this->_oldpos = 0;
229  return true;
230  }
231  } else {
232  return PEAR::raiseError('Could not find file '.$filename);
233  }
234  }
235 
242  function parse()
243  {
244  //The amount of opening braces is compared to the amount of closing braces
245  //Braces inside comments are ignored
246  $this->warnings = array();
247  $this->data = array();
248  $valid = true;
249  $open = 0;
250  $entry = false;
251  $char = '';
252  $lastchar = '';
253  $buffer = '';
254  for ($i = 0; $i < strlen($this->content); $i++) {
255  $char = substr($this->content, $i, 1);
256  if ((0 != $open) && ('@' == $char)) {
257  if (!$this->_checkAt($buffer)) {
258  $this->_generateWarning('WARNING_MISSING_END_BRACE', '', $buffer);
259  //To correct the data we need to insert a closing brace
260  $char = '}';
261  $i--;
262  }
263  }
264  if ((0 == $open) && ('@' == $char)) { //The beginning of an entry
265  $entry = true;
266  } elseif ($entry && ('{' == $char) && ('\\' != $lastchar)) { //Inside an entry and non quoted brace is opening
267  $open++;
268  } elseif ($entry && ('}' == $char) && ('\\' != $lastchar)) { //Inside an entry and non quoted brace is closing
269  $open--;
270  if ($open < 0) { //More are closed than opened
271  $valid = false;
272  }
273  if (0 == $open) { //End of entry
274  $entry = false;
275  $entrydata = $this->_parseEntry($buffer);
276  if (!$entrydata) {
283  } else {
284  $this->data[] = $entrydata;
285  }
286  $buffer = '';
287  }
288  }
289  if ($entry) { //Inside entry
290  $buffer .= $char;
291  }
292  $lastchar = $char;
293  }
294  //If open is one it may be possible that the last ending brace is missing
295  if (1 == $open) {
296  $entrydata = $this->_parseEntry($buffer);
297  if (!$entrydata) {
298  $valid = false;
299  } else {
300  $this->data[] = $entrydata;
301  $buffer = '';
302  $open = 0;
303  }
304  }
305  //At this point the open should be zero
306  if (0 != $open) {
307  $valid = false;
308  }
309  //Are there Multiple entries with the same cite?
310  if ($this->_options['validate']) {
311  $cites = array();
312  foreach ($this->data as $entry) {
313  $cites[] = $entry['cite'];
314  }
315  $unique = array_unique($cites);
316  if (sizeof($cites) != sizeof($unique)) { //Some values have not been unique!
317  $notuniques = array();
318  for ($i = 0; $i < sizeof($cites); $i++) {
319  if ('' == $unique[$i]) {
320  $notuniques[] = $cites[$i];
321  }
322  }
323  $this->_generateWarning('WARNING_MULTIPLE_ENTRIES', implode(',',$notuniques));
324  }
325  }
326  if ($valid) {
327  $this->content = '';
328  return true;
329  } else {
330  return PEAR::raiseError('Unbalanced parenthesis');
331  }
332  }
333 
354  function _parseEntry($entry)
355  {
356  $entrycopy = '';
357  if ($this->_options['validate']) {
358  $entrycopy = $entry; //We need a copy for printing the warnings
359  }
360  $ret = array();
361  if ('@string' == strtolower(substr($entry, 0, 7))) {
362  //String are not yet supported!
363  if ($this->_options['validate']) {
364  $this->_generateWarning('STRING_ENTRY_NOT_YET_SUPPORTED', '', $entry.'}');
365  }
366  } elseif ('@preamble' == strtolower(substr($entry, 0, 9))) {
367  //Preamble not yet supported!
368  if ($this->_options['validate']) {
369  $this->_generateWarning('PREAMBLE_ENTRY_NOT_YET_SUPPORTED', '', $entry.'}');
370  }
371  } else {
372  //Parsing all fields
373  while (strrpos($entry,'=') !== false) {
374  $position = strrpos($entry, '=');
375  //Checking that the equal sign is not quoted or is not inside a equation (For example in an abstract)
376  $proceed = true;
377  if (substr($entry, $position-1, 1) == '\\') {
378  $proceed = false;
379  }
380  if ($proceed) {
381  $proceed = $this->_checkEqualSign($entry, $position);
382  }
383  while (!$proceed) {
384  $substring = substr($entry, 0, $position);
385  $position = strrpos($substring,'=');
386  $proceed = true;
387  if (substr($entry, $position-1, 1) == '\\') {
388  $proceed = false;
389  }
390  if ($proceed) {
391  $proceed = $this->_checkEqualSign($entry, $position);
392  }
393  }
394 
395  $value = trim(substr($entry, $position+1));
396  $entry = substr($entry, 0, $position);
397 
398  if (',' == substr($value, strlen($value)-1, 1)) {
399  $value = substr($value, 0, -1);
400  }
401  if ($this->_options['validate']) {
402  $this->_validateValue($value, $entrycopy);
403  }
404  if ($this->_options['stripDelimiter']) {
405  $value = $this->_stripDelimiter($value);
406  }
407  if ($this->_options['unwrap']) {
408  $value = $this->_unwrap($value);
409  }
410  if ($this->_options['removeCurlyBraces']) {
411  $value = $this->_removeCurlyBraces($value);
412  }
413  $position = strrpos($entry, ',');
414  $field = strtolower(trim(substr($entry, $position+1)));
415  $ret[$field] = $value;
416  $entry = substr($entry, 0, $position);
417  }
418  //Parsing cite and entry type
419  $arr = explode('{', $entry);
420  $ret['cite'] = trim($arr[1]);
421  $ret['entryType'] = strtolower(trim($arr[0]));
422  if ('@' == $ret['entryType']{0}) {
423  $ret['entryType'] = substr($ret['entryType'], 1);
424  }
425  if ($this->_options['validate']) {
426  if (!$this->_checkAllowedEntryType($ret['entryType'])) {
427  $this->_generateWarning('WARNING_NOT_ALLOWED_ENTRY_TYPE', $ret['entryType'], $entry.'}');
428  }
429  }
430  //Handling the authors
431  if (in_array('author', array_keys($ret)) && $this->_options['extractAuthors']) {
432  $ret['author'] = $this->_extractAuthors($ret['author']);
433  }
434  }
435  return $ret;
436  }
437 
450  function _checkEqualSign($entry, $position)
451  {
452  $ret = true;
453  //This is getting tricky
454  //We check the string backwards until the position and count the closing an opening braces
455  //If we reach the position the amount of opening and closing braces should be equal
456  $length = strlen($entry);
457  $open = 0;
458  for ($i = $length-1; $i >= $position; $i--) {
459  $precedingchar = substr($entry, $i-1, 1);
460  $char = substr($entry, $i, 1);
461  if (('{' == $char) && ('\\' != $precedingchar)) {
462  $open++;
463  }
464  if (('}' == $char) && ('\\' != $precedingchar)) {
465  $open--;
466  }
467  }
468  if (0 != $open) {
469  $ret = false;
470  }
471  //There is still the posibility that the entry is delimited by double quotes.
472  //Then it is possible that the braces are equal even if the '=' is in an equation.
473  if ($ret) {
474  $entrycopy = trim($entry);
475  $lastchar = $entrycopy{strlen($entrycopy)-1};
476  if (',' == $lastchar) {
477  $lastchar = $entrycopy{strlen($entrycopy)-2};
478  }
479  if ('"' == $lastchar) {
480  //The return value is set to false
481  //If we find the closing " before the '=' it is set to true again.
482  //Remember we begin to search the entry backwards so the " has to show up twice - ending and beginning delimiter
483  $ret = false;
484  $found = 0;
485  for ($i = $length; $i >= $position; $i--) {
486  $precedingchar = substr($entry, $i-1, 1);
487  $char = substr($entry, $i, 1);
488  if (('"' == $char) && ('\\' != $precedingchar)) {
489  $found++;
490  }
491  if (2 == $found) {
492  $ret = true;
493  break;
494  }
495  }
496  }
497  }
498  return $ret;
499  }
500 
508  function _checkAllowedEntryType($entry)
509  {
510  return in_array($entry, $this->allowedEntryTypes);
511  }
512 
524  function _checkAt($entry)
525  {
526  $ret = false;
527  $opening = array_keys($this->_delimiters);
528  $closing = array_values($this->_delimiters);
529  //Getting the value (at is only allowd in values)
530  if (strrpos($entry,'=') !== false) {
531  $position = strrpos($entry, '=');
532  $proceed = true;
533  if (substr($entry, $position-1, 1) == '\\') {
534  $proceed = false;
535  }
536  while (!$proceed) {
537  $substring = substr($entry, 0, $position);
538  $position = strrpos($substring,'=');
539  $proceed = true;
540  if (substr($entry, $position-1, 1) == '\\') {
541  $proceed = false;
542  }
543  }
544  $value = trim(substr($entry, $position+1));
545  $open = 0;
546  $char = '';
547  $lastchar = '';
548  for ($i = 0; $i < strlen($value); $i++) {
549  $char = substr($this->content, $i, 1);
550  if (in_array($char, $opening) && ('\\' != $lastchar)) {
551  $open++;
552  } elseif (in_array($char, $closing) && ('\\' != $lastchar)) {
553  $open--;
554  }
555  $lastchar = $char;
556  }
557  //if open is grater zero were are inside an entry
558  if ($open>0) {
559  $ret = true;
560  }
561  }
562  return $ret;
563  }
564 
572  function _stripDelimiter($entry)
573  {
574  $beginningdels = array_keys($this->_delimiters);
575  $length = strlen($entry);
576  $firstchar = substr($entry, 0, 1);
577  $lastchar = substr($entry, -1, 1);
578  while (in_array($firstchar, $beginningdels)) { //The first character is an opening delimiter
579  if ($lastchar == $this->_delimiters[$firstchar]) { //Matches to closing Delimiter
580  $entry = substr($entry, 1, -1);
581  } else {
582  break;
583  }
584  $firstchar = substr($entry, 0, 1);
585  $lastchar = substr($entry, -1, 1);
586  }
587  return $entry;
588  }
589 
597  function _unwrap($entry)
598  {
599  $entry = preg_replace('/\s+/', ' ', $entry);
600  return trim($entry);
601  }
602 
610  function _wordwrap($entry)
611  {
612  if ( (''!=$entry) && (is_string($entry)) ) {
613  $entry = wordwrap($entry, $this->_options['wordWrapWidth'], $this->_options['wordWrapBreak'], $this->_options['wordWrapCut']);
614  }
615  return $entry;
616  }
617 
625  function _extractAuthors($entry) {
626  $entry = $this->_unwrap($entry);
627  $authorarray = array();
628  $authorarray = explode(' and ', $entry);
629  for ($i = 0; $i < sizeof($authorarray); $i++) {
630  $author = trim($authorarray[$i]);
631  /*The first version of how an author could be written (First von Last)
632  has no commas in it*/
633  $first = '';
634  $von = '';
635  $last = '';
636  $jr = '';
637  if (strpos($author, ',') === false) {
638  $tmparray = array();
639  //$tmparray = explode(' ', $author);
640  $tmparray = explode(' |~', $author);
641  $size = sizeof($tmparray);
642  if (1 == $size) { //There is only a last
643  $last = $tmparray[0];
644  } elseif (2 == $size) { //There is a first and a last
645  $first = $tmparray[0];
646  $last = $tmparray[1];
647  } else {
648  $invon = false;
649  $inlast = false;
650  for ($j=0; $j<($size-1); $j++) {
651  if ($inlast) {
652  $last .= ' '.$tmparray[$j];
653  } elseif ($invon) {
654  $case = $this->_determineCase($tmparray[$j]);
655  if (PEAR::isError($case)) {
656  // IGNORE?
657  } elseif ((0 == $case) || (-1 == $case)) { //Change from von to last
658  //You only change when there is no more lower case there
659  $islast = true;
660  for ($k=($j+1); $k<($size-1); $k++) {
661  $futurecase = $this->_determineCase($tmparray[$k]);
662  if (PEAR::isError($case)) {
663  // IGNORE?
664  } elseif (0 == $futurecase) {
665  $islast = false;
666  }
667  }
668  if ($islast) {
669  $inlast = true;
670  if (-1 == $case) { //Caseless belongs to the last
671  $last .= ' '.$tmparray[$j];
672  } else {
673  $von .= ' '.$tmparray[$j];
674  }
675  } else {
676  $von .= ' '.$tmparray[$j];
677  }
678  } else {
679  $von .= ' '.$tmparray[$j];
680  }
681  } else {
682  $case = $this->_determineCase($tmparray[$j]);
683  if (PEAR::isError($case)) {
684  // IGNORE?
685  } elseif (0 == $case) { //Change from first to von
686  $invon = true;
687  $von .= ' '.$tmparray[$j];
688  } else {
689  $first .= ' '.$tmparray[$j];
690  }
691  }
692  }
693  //The last entry is always the last!
694  $last .= ' '.$tmparray[$size-1];
695  }
696  } else { //Version 2 and 3
697  $tmparray = array();
698  $tmparray = explode(',', $author);
699  //The first entry must contain von and last
700  $vonlastarray = array();
701  $vonlastarray = explode(' ', $tmparray[0]);
702  $size = sizeof($vonlastarray);
703  if (1==$size) { //Only one entry->got to be the last
704  $last = $vonlastarray[0];
705  } else {
706  $inlast = false;
707  for ($j=0; $j<($size-1); $j++) {
708  if ($inlast) {
709  $last .= ' '.$vonlastarray[$j];
710  } else {
711  if (0 != ($this->_determineCase($vonlastarray[$j]))) { //Change from von to last
712  $islast = true;
713  for ($k=($j+1); $k<($size-1); $k++) {
714  $this->_determineCase($vonlastarray[$k]);
715  $case = $this->_determineCase($vonlastarray[$k]);
716  if (PEAR::isError($case)) {
717  // IGNORE?
718  } elseif (0 == $case) {
719  $islast = false;
720  }
721  }
722  if ($islast) {
723  $inlast = true;
724  $last .= ' '.$vonlastarray[$j];
725  } else {
726  $von .= ' '.$vonlastarray[$j];
727  }
728  } else {
729  $von .= ' '.$vonlastarray[$j];
730  }
731  }
732  }
733  $last .= ' '.$vonlastarray[$size-1];
734  }
735  //Now we check if it is version three (three entries in the array (two commas)
736  if (3==sizeof($tmparray)) {
737  $jr = $tmparray[1];
738  }
739  //Everything in the last entry is first
740  $first = $tmparray[sizeof($tmparray)-1];
741  }
742  $authorarray[$i] = array('first'=>trim($first), 'von'=>trim($von), 'last'=>trim($last), 'jr'=>trim($jr));
743  }
744  return $authorarray;
745  }
746 
760  function _determineCase($word) {
761  $ret = -1;
762  $trimmedword = trim ($word);
763  /*We need this variable. Without the next of would not work
764  (trim changes the variable automatically to a string!)*/
765  if (is_string($word) && (strlen($trimmedword) > 0)) {
766  $i = 0;
767  $found = false;
768  $openbrace = 0;
769  while (!$found && ($i <= strlen($word))) {
770  $letter = substr($trimmedword, $i, 1);
771  $ord = ord($letter);
772  if ($ord == 123) { //Open brace
773  $openbrace++;
774  }
775  if ($ord == 125) { //Closing brace
776  $openbrace--;
777  }
778  if (($ord>=65) && ($ord<=90) && (0==$openbrace)) { //The first character is uppercase
779  $ret = 1;
780  $found = true;
781  } elseif ( ($ord>=97) && ($ord<=122) && (0==$openbrace) ) { //The first character is lowercase
782  $ret = 0;
783  $found = true;
784  } else { //Not yet found
785  $i++;
786  }
787  }
788  } else {
789  $ret = PEAR::raiseError('Could not determine case on word: '.(string)$word);
790  }
791  return $ret;
792  }
793 
806  function _validateValue($entry, $wholeentry)
807  {
808  //There is no @ allowed if the entry is enclosed by braces
809  if (preg_match('/^{.*@.*}$/', $entry)) {
810  $this->_generateWarning('WARNING_AT_IN_BRACES', $entry, $wholeentry);
811  }
812  //No escaped " allowed if the entry is enclosed by double quotes
813  if (preg_match('/^\".*\\".*\"$/', $entry)) {
814  $this->_generateWarning('WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES', $entry, $wholeentry);
815  }
816  //Amount of Braces is not correct
817  $open = 0;
818  $lastchar = '';
819  $char = '';
820  for ($i = 0; $i < strlen($entry); $i++) {
821  $char = substr($entry, $i, 1);
822  if (('{' == $char) && ('\\' != $lastchar)) {
823  $open++;
824  }
825  if (('}' == $char) && ('\\' != $lastchar)) {
826  $open--;
827  }
828  $lastchar = $char;
829  }
830  if (0 != $open) {
831  $this->_generateWarning('WARNING_UNBALANCED_AMOUNT_OF_BRACES', $entry, $wholeentry);
832  }
833  }
834 
842  function _removeCurlyBraces($value)
843  {
844  //First we save the delimiters
845  $beginningdels = array_keys($this->_delimiters);
846  $firstchar = substr($entry, 0, 1);
847  $lastchar = substr($entry, -1, 1);
848  $begin = '';
849  $end = '';
850  while (in_array($firstchar, $beginningdels)) { //The first character is an opening delimiter
851  if ($lastchar == $this->_delimiters[$firstchar]) { //Matches to closing Delimiter
852  $begin .= $firstchar;
853  $end .= $lastchar;
854  $value = substr($value, 1, -1);
855  } else {
856  break;
857  }
858  $firstchar = substr($value, 0, 1);
859  $lastchar = substr($value, -1, 1);
860  }
861  //Now we get rid of the curly braces
862  $pattern = '/([^\\\\])\{(.*?[^\\\\])\}/';
863  $replacement = '$1$2';
864  $value = preg_replace($pattern, $replacement, $value);
865  //Reattach delimiters
866  $value = $begin.$value.$end;
867  return $value;
868  }
869 
878  function _generateWarning($type, $entry, $wholeentry='')
879  {
880  $warning['warning'] = $type;
881  $warning['entry'] = $entry;
882  $warning['wholeentry'] = $wholeentry;
883  $this->warnings[] = $warning;
884  }
885 
891  function clearWarnings()
892  {
893  $this->warnings = array();
894  }
895 
902  function hasWarning()
903  {
904  if (sizeof($this->warnings)>0) return true;
905  else return false;
906  }
907 
914  function amount()
915  {
916  return sizeof($this->data);
917  }
918 
928  function _formatAuthor($array)
929  {
930  if (!array_key_exists('von', $array)) {
931  $array['von'] = '';
932  } else {
933  $array['von'] = trim($array['von']);
934  }
935  if (!array_key_exists('last', $array)) {
936  $array['last'] = '';
937  } else {
938  $array['last'] = trim($array['last']);
939  }
940  if (!array_key_exists('jr', $array)) {
941  $array['jr'] = '';
942  } else {
943  $array['jr'] = trim($array['jr']);
944  }
945  if (!array_key_exists('first', $array)) {
946  $array['first'] = '';
947  } else {
948  $array['first'] = trim($array['first']);
949  }
951  $ret = str_replace("VON", $array['von'], $ret);
952  $ret = str_replace("LAST", $array['last'], $ret);
953  $ret = str_replace("JR", $array['jr'], $ret);
954  $ret = str_replace("FIRST", $array['first'], $ret);
955  return trim($ret);
956  }
957 
966  function bibTex()
967  {
968  $bibtex = '';
969  foreach ($this->data as $entry) {
970  //Intro
971  $bibtex .= '@'.strtolower($entry['entryType']).' { '.$entry['cite'].",\n";
972  //Other fields except author
973  foreach ($entry as $key=>$val) {
974  if ($this->_options['wordWrapWidth']>0) {
975  $val = $this->_wordWrap($val);
976  }
977  if (!in_array($key, array('cite','entryType','author'))) {
978  $bibtex .= "\t".$key.' = {'.$val."},\n";
979  }
980  }
981  //Author
982  if (array_key_exists('author', $entry)) {
983  if ($this->_options['extractAuthors']) {
984  $tmparray = array(); //In this array the authors are saved and the joind with an and
985  foreach ($entry['author'] as $authorentry) {
986  $tmparray[] = $this->_formatAuthor($authorentry);
987  }
988  $author = join(' and ', $tmparray);
989  } else {
990  $author = $entry['author'];
991  }
992  } else {
993  $author = '';
994  }
995  $bibtex .= "\tauthor = {".$author."}\n";
996  $bibtex.="}\n\n";
997  }
998  return $bibtex;
999  }
1000 
1008  function addEntry($newentry)
1009  {
1010  $this->data[] = $newentry;
1011  }
1012 
1022  function getStatistic()
1023  {
1024  $ret = array();
1025  foreach ($this->data as $entry) {
1026  if (array_key_exists($entry['entryType'], $ret)) {
1027  $ret[$entry['entryType']]++;
1028  } else {
1029  $ret[$entry['entryType']] = 1;
1030  }
1031  }
1032  return $ret;
1033  }
1034 
1049  function rtf()
1050  {
1051  $ret = "{\\rtf\n";
1052  foreach ($this->data as $entry) {
1053  $line = $this->rtfstring;
1054  $title = '';
1055  $journal = '';
1056  $year = '';
1057  $authors = '';
1058  if (array_key_exists('title', $entry)) {
1059  $title = $this->_unwrap($entry['title']);
1060  }
1061  if (array_key_exists('journal', $entry)) {
1062  $journal = $this->_unwrap($entry['journal']);
1063  }
1064  if (array_key_exists('year', $entry)) {
1065  $year = $this->_unwrap($entry['year']);
1066  }
1067  if (array_key_exists('author', $entry)) {
1068  if ($this->_options['extractAuthors']) {
1069  $tmparray = array(); //In this array the authors are saved and the joind with an and
1070  foreach ($entry['author'] as $authorentry) {
1071  $tmparray[] = $this->_formatAuthor($authorentry);
1072  }
1073  $authors = join(', ', $tmparray);
1074  } else {
1075  $authors = $entry['author'];
1076  }
1077  }
1078  if ((''!=$title) || (''!=$journal) || (''!=$year) || (''!=$authors)) {
1079  $line = str_replace("TITLE", $title, $line);
1080  $line = str_replace("JOURNAL", $journal, $line);
1081  $line = str_replace("YEAR", $year, $line);
1082  $line = str_replace("AUTHORS", $authors, $line);
1083  $line .= "\n\\par\n";
1084  $ret .= $line;
1085  } else {
1086  $this->_generateWarning('WARNING_LINE_WAS_NOT_CONVERTED', '', print_r($entry,1));
1087  }
1088  }
1089  $ret .= '}';
1090  return $ret;
1091  }
1092 
1106  function html()
1107  {
1108  $ret = "<p>\n";
1109  foreach ($this->data as $entry) {
1110  $line = $this->htmlstring;
1111  $title = '';
1112  $journal = '';
1113  $year = '';
1114  $authors = '';
1115  if (array_key_exists('title', $entry)) {
1116  $title = $this->_unwrap($entry['title']);
1117  }
1118  if (array_key_exists('journal', $entry)) {
1119  $journal = $this->_unwrap($entry['journal']);
1120  }
1121  if (array_key_exists('year', $entry)) {
1122  $year = $this->_unwrap($entry['year']);
1123  }
1124  if (array_key_exists('author', $entry)) {
1125  if ($this->_options['extractAuthors']) {
1126  $tmparray = array(); //In this array the authors are saved and the joind with an and
1127  foreach ($entry['author'] as $authorentry) {
1128  $tmparray[] = $this->_formatAuthor($authorentry);
1129  }
1130  $authors = join(', ', $tmparray);
1131  } else {
1132  $authors = $entry['author'];
1133  }
1134  }
1135  if ((''!=$title) || (''!=$journal) || (''!=$year) || (''!=$authors)) {
1136  $line = str_replace("TITLE", $title, $line);
1137  $line = str_replace("JOURNAL", $journal, $line);
1138  $line = str_replace("YEAR", $year, $line);
1139  $line = str_replace("AUTHORS", $authors, $line);
1140  $line .= "\n";
1141  $ret .= $line;
1142  } else {
1143  $this->_generateWarning('WARNING_LINE_WAS_NOT_CONVERTED', '', print_r($entry,1));
1144  }
1145  }
1146  $ret .= "</p>\n";
1147  return $ret;
1148  }
1149 }
1150 ?>