ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
BibTex.php
Go to the documentation of this file.
1<?php
2/* vim: set ts=4 sw=4: */
26require_once 'PEAR.php';
78
85 var $data;
142
143
150 function Structures_BibTex($options = array()) {
151 $this->_delimiters = array(
152 '"' => '"',
153 '{' => '}'
154 );
155 $this->data = array();
156 $this->content = '';
157 //$this->_stripDelimiter = $stripDel;
158 //$this->_validate = $val;
159 $this->warnings = array();
160 $this->_options = array(
161 'stripDelimiter' => true,
162 'validate' => true,
163 'unwrap' => false,
164 'wordWrapWidth' => false,
165 'wordWrapBreak' => "\n",
166 'wordWrapCut' => 0,
167 'removeCurlyBraces' => false,
168 'extractAuthors' => true,
169 );
170 foreach ($options as $option => $value) {
171 $test = $this->setOption($option, $value);
172 if (PEAR::isError($test)) {
173 //Currently nothing is done here, but it could for example raise an warning
174 }
175 }
176 $this->rtfstring = 'AUTHORS, "{\b TITLE}", {\i JOURNAL}, YEAR';
177 $this->htmlstring = 'AUTHORS, "<strong>TITLE</strong>", <em>JOURNAL</em>, YEAR<br />';
178 $this->allowedEntryTypes = array(
179 'article',
180 'book',
181 'booklet',
182 'confernce',
183 'inbook',
184 'incollection',
185 'inproceedings',
186 'manual',
187 'mastersthesis',
188 'misc',
189 'phdthesis',
190 'proceedings',
191 'techreport',
192 'unpublished'
193 );
194 $this->authorstring = 'VON LAST, JR, FIRST';
195 }
196
197
208 function setOption($option, $value) {
209 $ret = true;
210 if (array_key_exists($option, $this->_options)) {
211 $this->_options[$option] = $value;
212 } else {
213 $ret = PEAR::raiseError('Unknown option ' . $option);
214 }
215
216 return $ret;
217 }
218
219
229 function loadFile($filename) {
230 if (file_exists($filename)) {
231 if (($this->content = @file_get_contents($filename)) === false) {
232 return PEAR::raiseError('Could not open file ' . $filename);
233 } else {
234 $this->_pos = 0;
235 $this->_oldpos = 0;
236
237 return true;
238 }
239 } else {
240 return PEAR::raiseError('Could not find file ' . $filename);
241 }
242 }
243
244
251 function parse() {
252 //The amount of opening braces is compared to the amount of closing braces
253 //Braces inside comments are ignored
254 $this->warnings = array();
255 $this->data = array();
256 $valid = true;
257 $open = 0;
258 $entry = false;
259 $char = '';
260 $lastchar = '';
261 $buffer = '';
262 for ($i = 0; $i < strlen($this->content); $i ++) {
263 $char = substr($this->content, $i, 1);
264 if ((0 != $open) && ('@' == $char)) {
265 if (! $this->_checkAt($buffer)) {
266 $this->_generateWarning('WARNING_MISSING_END_BRACE', '', $buffer);
267 //To correct the data we need to insert a closing brace
268 $char = '}';
269 $i --;
270 }
271 }
272 if ((0 == $open) && ('@' == $char)) { //The beginning of an entry
273 $entry = true;
274 } elseif ($entry && ('{' == $char)
275 && ('\\' != $lastchar)
276 ) { //Inside an entry and non quoted brace is opening
277 $open ++;
278 } elseif ($entry && ('}' == $char)
279 && ('\\' != $lastchar)
280 ) { //Inside an entry and non quoted brace is closing
281 $open --;
282 if ($open < 0) { //More are closed than opened
283 $valid = false;
284 }
285 if (0 == $open) { //End of entry
286 $entry = false;
287 $entrydata = $this->_parseEntry($buffer);
288 if (! $entrydata) {
295 } else {
296 $this->data[] = $entrydata;
297 }
298 $buffer = '';
299 }
300 }
301 if ($entry) { //Inside entry
302 $buffer .= $char;
303 }
304 $lastchar = $char;
305 }
306 //If open is one it may be possible that the last ending brace is missing
307 if (1 == $open) {
308 $entrydata = $this->_parseEntry($buffer);
309 if (! $entrydata) {
310 $valid = false;
311 } else {
312 $this->data[] = $entrydata;
313 $buffer = '';
314 $open = 0;
315 }
316 }
317 //At this point the open should be zero
318 if (0 != $open) {
319 $valid = false;
320 }
321 //Are there Multiple entries with the same cite?
322 if ($this->_options['validate']) {
323 $cites = array();
324 foreach ($this->data as $entry) {
325 $cites[] = $entry['cite'];
326 }
327 $unique = array_unique($cites);
328 if (sizeof($cites) != sizeof($unique)) { //Some values have not been unique!
329 $notuniques = array();
330 for ($i = 0; $i < sizeof($cites); $i ++) {
331 if ('' == $unique[$i]) {
332 $notuniques[] = $cites[$i];
333 }
334 }
335 $this->_generateWarning('WARNING_MULTIPLE_ENTRIES', implode(',', $notuniques));
336 }
337 }
338 if ($valid) {
339 $this->content = '';
340
341 return true;
342 } else {
343 return PEAR::raiseError('Unbalanced parenthesis');
344 }
345 }
346
347
370 function _parseEntry($entry) {
371 $entrycopy = '';
372 if ($this->_options['validate']) {
373 $entrycopy = $entry; //We need a copy for printing the warnings
374 }
375 $ret = array();
376 if ('@string' == strtolower(substr($entry, 0, 7))) {
377 //String are not yet supported!
378 if ($this->_options['validate']) {
379 $this->_generateWarning('STRING_ENTRY_NOT_YET_SUPPORTED', '', $entry . '}');
380 }
381 } elseif ('@preamble' == strtolower(substr($entry, 0, 9))) {
382 //Preamble not yet supported!
383 if ($this->_options['validate']) {
384 $this->_generateWarning('PREAMBLE_ENTRY_NOT_YET_SUPPORTED', '', $entry . '}');
385 }
386 } else {
387 //Parsing all fields
388 while (strrpos($entry, '=') !== false) {
389 $position = strrpos($entry, '=');
390 //Checking that the equal sign is not quoted or is not inside a equation (For example in an abstract)
391 $proceed = true;
392 if (substr($entry, $position - 1, 1) == '\\') {
393 $proceed = false;
394 }
395 if ($proceed) {
396 $proceed = $this->_checkEqualSign($entry, $position);
397 }
398 while (! $proceed) {
399 $substring = substr($entry, 0, $position);
400 $position = strrpos($substring, '=');
401 $proceed = true;
402 if (substr($entry, $position - 1, 1) == '\\') {
403 $proceed = false;
404 }
405 if ($proceed) {
406 $proceed = $this->_checkEqualSign($entry, $position);
407 }
408 }
409 $value = trim(substr($entry, $position + 1));
410 $entry = substr($entry, 0, $position);
411 if (',' == substr($value, strlen($value) - 1, 1)) {
412 $value = substr($value, 0, - 1);
413 }
414 if ($this->_options['validate']) {
415 $this->_validateValue($value, $entrycopy);
416 }
417 if ($this->_options['stripDelimiter']) {
418 $value = $this->_stripDelimiter($value);
419 }
420 if ($this->_options['unwrap']) {
421 $value = $this->_unwrap($value);
422 }
423 if ($this->_options['removeCurlyBraces']) {
424 $value = $this->_removeCurlyBraces($value);
425 }
426 $position = strrpos($entry, ',');
427 $field = strtolower(trim(substr($entry, $position + 1)));
428 $ret[$field] = $value;
429 $entry = substr($entry, 0, $position);
430 }
431 //Parsing cite and entry type
432 $arr = explode('{', $entry);
433 $ret['cite'] = trim($arr[1]);
434 $ret['entryType'] = strtolower(trim($arr[0]));
435 if ('@' == $ret['entryType']{0}) {
436 $ret['entryType'] = substr($ret['entryType'], 1);
437 }
438 if ($this->_options['validate']) {
439 if (! $this->_checkAllowedEntryType($ret['entryType'])) {
440 $this->_generateWarning('WARNING_NOT_ALLOWED_ENTRY_TYPE', $ret['entryType'], $entry . '}');
441 }
442 }
443 //Handling the authors
444 if (in_array('author', array_keys($ret)) && $this->_options['extractAuthors']) {
445 $ret['author'] = $this->_extractAuthors($ret['author']);
446 }
447 }
448
449 return $ret;
450 }
451
452
467 function _checkEqualSign($entry, $position) {
468 $ret = true;
469 //This is getting tricky
470 //We check the string backwards until the position and count the closing an opening braces
471 //If we reach the position the amount of opening and closing braces should be equal
472 $length = strlen($entry);
473 $open = 0;
474 for ($i = $length - 1; $i >= $position; $i --) {
475 $precedingchar = substr($entry, $i - 1, 1);
476 $char = substr($entry, $i, 1);
477 if (('{' == $char) && ('\\' != $precedingchar)) {
478 $open ++;
479 }
480 if (('}' == $char) && ('\\' != $precedingchar)) {
481 $open --;
482 }
483 }
484 if (0 != $open) {
485 $ret = false;
486 }
487 //There is still the posibility that the entry is delimited by double quotes.
488 //Then it is possible that the braces are equal even if the '=' is in an equation.
489 if ($ret) {
490 $entrycopy = trim($entry);
491 $lastchar = $entrycopy{strlen($entrycopy) - 1};
492 if (',' == $lastchar) {
493 $lastchar = $entrycopy{strlen($entrycopy) - 2};
494 }
495 if ('"' == $lastchar) {
496 //The return value is set to false
497 //If we find the closing " before the '=' it is set to true again.
498 //Remember we begin to search the entry backwards so the " has to show up twice - ending and beginning delimiter
499 $ret = false;
500 $found = 0;
501 for ($i = $length; $i >= $position; $i --) {
502 $precedingchar = substr($entry, $i - 1, 1);
503 $char = substr($entry, $i, 1);
504 if (('"' == $char) && ('\\' != $precedingchar)) {
505 $found ++;
506 }
507 if (2 == $found) {
508 $ret = true;
509 break;
510 }
511 }
512 }
513 }
514
515 return $ret;
516 }
517
518
528 function _checkAllowedEntryType($entry) {
529 return in_array($entry, $this->allowedEntryTypes);
530 }
531
532
546 function _checkAt($entry) {
547 $ret = false;
548 $opening = array_keys($this->_delimiters);
549 $closing = array_values($this->_delimiters);
550 //Getting the value (at is only allowd in values)
551 if (strrpos($entry, '=') !== false) {
552 $position = strrpos($entry, '=');
553 $proceed = true;
554 if (substr($entry, $position - 1, 1) == '\\') {
555 $proceed = false;
556 }
557 while (! $proceed) {
558 $substring = substr($entry, 0, $position);
559 $position = strrpos($substring, '=');
560 $proceed = true;
561 if (substr($entry, $position - 1, 1) == '\\') {
562 $proceed = false;
563 }
564 }
565 $value = trim(substr($entry, $position + 1));
566 $open = 0;
567 $char = '';
568 $lastchar = '';
569 for ($i = 0; $i < strlen($value); $i ++) {
570 $char = substr($this->content, $i, 1);
571 if (in_array($char, $opening) && ('\\' != $lastchar)) {
572 $open ++;
573 } elseif (in_array($char, $closing) && ('\\' != $lastchar)) {
574 $open --;
575 }
576 $lastchar = $char;
577 }
578 //if open is grater zero were are inside an entry
579 if ($open > 0) {
580 $ret = true;
581 }
582 }
583
584 return $ret;
585 }
586
587
597 function _stripDelimiter($entry) {
598 $beginningdels = array_keys($this->_delimiters);
599 $length = strlen($entry);
600 $firstchar = substr($entry, 0, 1);
601 $lastchar = substr($entry, - 1, 1);
602 while (in_array($firstchar, $beginningdels)) { //The first character is an opening delimiter
603 if ($lastchar == $this->_delimiters[$firstchar]) { //Matches to closing Delimiter
604 $entry = substr($entry, 1, - 1);
605 } else {
606 break;
607 }
608 $firstchar = substr($entry, 0, 1);
609 $lastchar = substr($entry, - 1, 1);
610 }
611
612 return $entry;
613 }
614
615
625 function _unwrap($entry) {
626 $entry = preg_replace('/\s+/', ' ', $entry);
627
628 return trim($entry);
629 }
630
631
641 function _wordwrap($entry) {
642 if (('' != $entry) && (is_string($entry))) {
643 $entry = wordwrap($entry, $this->_options['wordWrapWidth'], $this->_options['wordWrapBreak'], $this->_options['wordWrapCut']);
644 }
645
646 return $entry;
647 }
648
649
659 function _extractAuthors($entry) {
660 $entry = $this->_unwrap($entry);
661 $authorarray = array();
662 $authorarray = explode(' and ', $entry);
663 for ($i = 0; $i < sizeof($authorarray); $i ++) {
664 $author = trim($authorarray[$i]);
665 /*The first version of how an author could be written (First von Last)
666 has no commas in it*/
667 $first = '';
668 $von = '';
669 $last = '';
670 $jr = '';
671 if (strpos($author, ',') === false) {
672 $tmparray = array();
673 //$tmparray = explode(' ', $author);
674 $tmparray = explode(' |~', $author);
675 $size = sizeof($tmparray);
676 if (1 == $size) { //There is only a last
677 $last = $tmparray[0];
678 } elseif (2 == $size) { //There is a first and a last
679 $first = $tmparray[0];
680 $last = $tmparray[1];
681 } else {
682 $invon = false;
683 $inlast = false;
684 for ($j = 0; $j < ($size - 1); $j ++) {
685 if ($inlast) {
686 $last .= ' ' . $tmparray[$j];
687 } elseif ($invon) {
688 $case = $this->_determineCase($tmparray[$j]);
689 if (PEAR::isError($case)) {
690 // IGNORE?
691 } elseif ((0 == $case) || (- 1 == $case)) { //Change from von to last
692 //You only change when there is no more lower case there
693 $islast = true;
694 for ($k = ($j + 1); $k < ($size - 1); $k ++) {
695 $futurecase = $this->_determineCase($tmparray[$k]);
696 if (PEAR::isError($case)) {
697 // IGNORE?
698 } elseif (0 == $futurecase) {
699 $islast = false;
700 }
701 }
702 if ($islast) {
703 $inlast = true;
704 if (- 1 == $case) { //Caseless belongs to the last
705 $last .= ' ' . $tmparray[$j];
706 } else {
707 $von .= ' ' . $tmparray[$j];
708 }
709 } else {
710 $von .= ' ' . $tmparray[$j];
711 }
712 } else {
713 $von .= ' ' . $tmparray[$j];
714 }
715 } else {
716 $case = $this->_determineCase($tmparray[$j]);
717 if (PEAR::isError($case)) {
718 // IGNORE?
719 } elseif (0 == $case) { //Change from first to von
720 $invon = true;
721 $von .= ' ' . $tmparray[$j];
722 } else {
723 $first .= ' ' . $tmparray[$j];
724 }
725 }
726 }
727 //The last entry is always the last!
728 $last .= ' ' . $tmparray[$size - 1];
729 }
730 } else { //Version 2 and 3
731 $tmparray = array();
732 $tmparray = explode(',', $author);
733 //The first entry must contain von and last
734 $vonlastarray = array();
735 $vonlastarray = explode(' ', $tmparray[0]);
736 $size = sizeof($vonlastarray);
737 if (1 == $size) { //Only one entry->got to be the last
738 $last = $vonlastarray[0];
739 } else {
740 $inlast = false;
741 for ($j = 0; $j < ($size - 1); $j ++) {
742 if ($inlast) {
743 $last .= ' ' . $vonlastarray[$j];
744 } else {
745 if (0 != ($this->_determineCase($vonlastarray[$j]))) { //Change from von to last
746 $islast = true;
747 for ($k = ($j + 1); $k < ($size - 1); $k ++) {
748 $this->_determineCase($vonlastarray[$k]);
749 $case = $this->_determineCase($vonlastarray[$k]);
750 if (PEAR::isError($case)) {
751 // IGNORE?
752 } elseif (0 == $case) {
753 $islast = false;
754 }
755 }
756 if ($islast) {
757 $inlast = true;
758 $last .= ' ' . $vonlastarray[$j];
759 } else {
760 $von .= ' ' . $vonlastarray[$j];
761 }
762 } else {
763 $von .= ' ' . $vonlastarray[$j];
764 }
765 }
766 }
767 $last .= ' ' . $vonlastarray[$size - 1];
768 }
769 //Now we check if it is version three (three entries in the array (two commas)
770 if (3 == sizeof($tmparray)) {
771 $jr = $tmparray[1];
772 }
773 //Everything in the last entry is first
774 $first = $tmparray[sizeof($tmparray) - 1];
775 }
776 $authorarray[$i] = array(
777 'first' => trim($first),
778 'von' => trim($von),
779 'last' => trim($last),
780 'jr' => trim($jr)
781 );
782 }
783
784 return $authorarray;
785 }
786
787
803 function _determineCase($word) {
804 $ret = - 1;
805 $trimmedword = trim($word);
806 /*We need this variable. Without the next of would not work
807 (trim changes the variable automatically to a string!)*/
808 if (is_string($word) && (strlen($trimmedword) > 0)) {
809 $i = 0;
810 $found = false;
811 $openbrace = 0;
812 while (! $found && ($i <= strlen($word))) {
813 $letter = substr($trimmedword, $i, 1);
814 $ord = ord($letter);
815 if ($ord == 123) { //Open brace
816 $openbrace ++;
817 }
818 if ($ord == 125) { //Closing brace
819 $openbrace --;
820 }
821 if (($ord >= 65) && ($ord <= 90) && (0 == $openbrace)) { //The first character is uppercase
822 $ret = 1;
823 $found = true;
824 } elseif (($ord >= 97) && ($ord <= 122) && (0 == $openbrace)) { //The first character is lowercase
825 $ret = 0;
826 $found = true;
827 } else { //Not yet found
828 $i ++;
829 }
830 }
831 } else {
832 $ret = PEAR::raiseError('Could not determine case on word: ' . (string)$word);
833 }
834
835 return $ret;
836 }
837
838
853 function _validateValue($entry, $wholeentry) {
854 //There is no @ allowed if the entry is enclosed by braces
855 if (preg_match('/^{.*@.*}$/', $entry)) {
856 $this->_generateWarning('WARNING_AT_IN_BRACES', $entry, $wholeentry);
857 }
858 //No escaped " allowed if the entry is enclosed by double quotes
859 if (preg_match('/^\".*\\".*\"$/', $entry)) {
860 $this->_generateWarning('WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES', $entry, $wholeentry);
861 }
862 //Amount of Braces is not correct
863 $open = 0;
864 $lastchar = '';
865 $char = '';
866 for ($i = 0; $i < strlen($entry); $i ++) {
867 $char = substr($entry, $i, 1);
868 if (('{' == $char) && ('\\' != $lastchar)) {
869 $open ++;
870 }
871 if (('}' == $char) && ('\\' != $lastchar)) {
872 $open --;
873 }
874 $lastchar = $char;
875 }
876 if (0 != $open) {
877 $this->_generateWarning('WARNING_UNBALANCED_AMOUNT_OF_BRACES', $entry, $wholeentry);
878 }
879 }
880
881
890 function _removeCurlyBraces($value) {
891 //First we save the delimiters
892 $beginningdels = array_keys($this->_delimiters);
893 $firstchar = substr($entry, 0, 1);
894 $lastchar = substr($entry, - 1, 1);
895 $begin = '';
896 $end = '';
897 while (in_array($firstchar, $beginningdels)) { //The first character is an opening delimiter
898 if ($lastchar == $this->_delimiters[$firstchar]) { //Matches to closing Delimiter
899 $begin .= $firstchar;
900 $end .= $lastchar;
901 $value = substr($value, 1, - 1);
902 } else {
903 break;
904 }
905 $firstchar = substr($value, 0, 1);
906 $lastchar = substr($value, - 1, 1);
907 }
908 //Now we get rid of the curly braces
909 $pattern = '/([^\\\\])\{(.*?[^\\\\])\}/';
910 $replacement = '$1$2';
911 $value = preg_replace($pattern, $replacement, $value);
912 //Reattach delimiters
913 $value = $begin . $value . $end;
914
915 return $value;
916 }
917
918
928 function _generateWarning($type, $entry, $wholeentry = '') {
929 $warning['warning'] = $type;
930 $warning['entry'] = $entry;
931 $warning['wholeentry'] = $wholeentry;
932 $this->warnings[] = $warning;
933 }
934
935
941 function clearWarnings() {
942 $this->warnings = array();
943 }
944
945
952 function hasWarning() {
953 if (sizeof($this->warnings) > 0) {
954 return true;
955 } else {
956 return false;
957 }
958 }
959
960
967 function amount() {
968 return sizeof($this->data);
969 }
970
971
983 function _formatAuthor($array) {
984 if (! array_key_exists('von', $array)) {
985 $array['von'] = '';
986 } else {
987 $array['von'] = trim($array['von']);
988 }
989 if (! array_key_exists('last', $array)) {
990 $array['last'] = '';
991 } else {
992 $array['last'] = trim($array['last']);
993 }
994 if (! array_key_exists('jr', $array)) {
995 $array['jr'] = '';
996 } else {
997 $array['jr'] = trim($array['jr']);
998 }
999 if (! array_key_exists('first', $array)) {
1000 $array['first'] = '';
1001 } else {
1002 $array['first'] = trim($array['first']);
1003 }
1005 $ret = str_replace("VON", $array['von'], $ret);
1006 $ret = str_replace("LAST", $array['last'], $ret);
1007 $ret = str_replace("JR", $array['jr'], $ret);
1008 $ret = str_replace("FIRST", $array['first'], $ret);
1009
1010 return trim($ret);
1011 }
1012
1013
1022 function bibTex() {
1023 $bibtex = '';
1024 foreach ($this->data as $entry) {
1025 //Intro
1026 $bibtex .= '@' . strtolower($entry['entryType']) . ' { ' . $entry['cite'] . ",\n";
1027 //Other fields except author
1028 foreach ($entry as $key => $val) {
1029 if ($this->_options['wordWrapWidth'] > 0) {
1030 $val = $this->_wordWrap($val);
1031 }
1032 if (! in_array($key, array( 'cite', 'entryType', 'author' ))) {
1033 $bibtex .= "\t" . $key . ' = {' . $val . "},\n";
1034 }
1035 }
1036 //Author
1037 if (array_key_exists('author', $entry)) {
1038 if ($this->_options['extractAuthors']) {
1039 $tmparray = array(); //In this array the authors are saved and the joind with an and
1040 foreach ($entry['author'] as $authorentry) {
1041 $tmparray[] = $this->_formatAuthor($authorentry);
1042 }
1043 $author = join(' and ', $tmparray);
1044 } else {
1045 $author = $entry['author'];
1046 }
1047 } else {
1048 $author = '';
1049 }
1050 $bibtex .= "\tauthor = {" . $author . "}\n";
1051 $bibtex .= "}\n\n";
1052 }
1053
1054 return $bibtex;
1055 }
1056
1057
1067 function addEntry($newentry) {
1068 $this->data[] = $newentry;
1069 }
1070
1071
1081 function getStatistic() {
1082 $ret = array();
1083 foreach ($this->data as $entry) {
1084 if (array_key_exists($entry['entryType'], $ret)) {
1085 $ret[$entry['entryType']] ++;
1086 } else {
1087 $ret[$entry['entryType']] = 1;
1088 }
1089 }
1090
1091 return $ret;
1092 }
1093
1094
1109 function rtf() {
1110 $ret = "{\\rtf\n";
1111 foreach ($this->data as $entry) {
1112 $line = $this->rtfstring;
1113 $title = '';
1114 $journal = '';
1115 $year = '';
1116 $authors = '';
1117 if (array_key_exists('title', $entry)) {
1118 $title = $this->_unwrap($entry['title']);
1119 }
1120 if (array_key_exists('journal', $entry)) {
1121 $journal = $this->_unwrap($entry['journal']);
1122 }
1123 if (array_key_exists('year', $entry)) {
1124 $year = $this->_unwrap($entry['year']);
1125 }
1126 if (array_key_exists('author', $entry)) {
1127 if ($this->_options['extractAuthors']) {
1128 $tmparray = array(); //In this array the authors are saved and the joind with an and
1129 foreach ($entry['author'] as $authorentry) {
1130 $tmparray[] = $this->_formatAuthor($authorentry);
1131 }
1132 $authors = join(', ', $tmparray);
1133 } else {
1134 $authors = $entry['author'];
1135 }
1136 }
1137 if (('' != $title) || ('' != $journal) || ('' != $year) || ('' != $authors)) {
1138 $line = str_replace("TITLE", $title, $line);
1139 $line = str_replace("JOURNAL", $journal, $line);
1140 $line = str_replace("YEAR", $year, $line);
1141 $line = str_replace("AUTHORS", $authors, $line);
1142 $line .= "\n\\par\n";
1143 $ret .= $line;
1144 } else {
1145 $this->_generateWarning('WARNING_LINE_WAS_NOT_CONVERTED', '', print_r($entry, 1));
1146 }
1147 }
1148 $ret .= '}';
1149
1150 return $ret;
1151 }
1152
1153
1167 function html() {
1168 $ret = "<p>\n";
1169 foreach ($this->data as $entry) {
1170 $line = $this->htmlstring;
1171 $title = '';
1172 $journal = '';
1173 $year = '';
1174 $authors = '';
1175 if (array_key_exists('title', $entry)) {
1176 $title = $this->_unwrap($entry['title']);
1177 }
1178 if (array_key_exists('journal', $entry)) {
1179 $journal = $this->_unwrap($entry['journal']);
1180 }
1181 if (array_key_exists('year', $entry)) {
1182 $year = $this->_unwrap($entry['year']);
1183 }
1184 if (array_key_exists('author', $entry)) {
1185 if ($this->_options['extractAuthors']) {
1186 $tmparray = array(); //In this array the authors are saved and the joind with an and
1187 foreach ($entry['author'] as $authorentry) {
1188 $tmparray[] = $this->_formatAuthor($authorentry);
1189 }
1190 $authors = join(', ', $tmparray);
1191 } else {
1192 $authors = $entry['author'];
1193 }
1194 }
1195 if (('' != $title) || ('' != $journal) || ('' != $year) || ('' != $authors)) {
1196 $line = str_replace("TITLE", $title, $line);
1197 $line = str_replace("JOURNAL", $journal, $line);
1198 $line = str_replace("YEAR", $year, $line);
1199 $line = str_replace("AUTHORS", $authors, $line);
1200 $line .= "\n";
1201 $ret .= $line;
1202 } else {
1203 $this->_generateWarning('WARNING_LINE_WAS_NOT_CONVERTED', '', print_r($entry, 1));
1204 }
1205 }
1206 $ret .= "</p>\n";
1207
1208 return $ret;
1209 }
1210}
1211
1212?>
$size
Definition: RandomTest.php:79
$test
Definition: Utf8Test.php:85
$filename
Definition: buildRTE.php:89
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
Definition: PEAR.php:524
rtf()
Returns the stored data in RTF format.
Definition: BibTex.php:1109
getStatistic()
Returns statistic.
Definition: BibTex.php:1081
_formatAuthor($array)
Returns the author formatted.
Definition: BibTex.php:983
clearWarnings()
Cleares all warnings.
Definition: BibTex.php:941
hasWarning()
Is there a warning?
Definition: BibTex.php:952
loadFile($filename)
Reads a give BibTex File.
Definition: BibTex.php:229
_checkAllowedEntryType($entry)
Checking if the entry type is allowed.
Definition: BibTex.php:528
html()
Returns the stored data in HTML format.
Definition: BibTex.php:1167
_removeCurlyBraces($value)
Remove curly braces from entry.
Definition: BibTex.php:890
_validateValue($entry, $wholeentry)
Validation of a value.
Definition: BibTex.php:853
_generateWarning($type, $entry, $wholeentry='')
Generates a warning.
Definition: BibTex.php:928
_determineCase($word)
Case Determination according to the needs of BibTex.
Definition: BibTex.php:803
bibTex()
Converts the stored BibTex entries to a BibTex String.
Definition: BibTex.php:1022
_checkEqualSign($entry, $position)
Checking whether the position of the '=' is correct.
Definition: BibTex.php:467
addEntry($newentry)
Adds a new BibTex entry to the data.
Definition: BibTex.php:1067
setOption($option, $value)
Sets run-time configuration options.
Definition: BibTex.php:208
_stripDelimiter($entry)
Stripping Delimiter.
Definition: BibTex.php:597
amount()
Returns the amount of available BibTex entries.
Definition: BibTex.php:967
Structures_BibTex($options=array())
Constructor.
Definition: BibTex.php:150
_wordwrap($entry)
Wordwrap an entry.
Definition: BibTex.php:641
parse()
Parses what is stored in content and clears the content if the parsing is successfull.
Definition: BibTex.php:251
_extractAuthors($entry)
Extracting the authors.
Definition: BibTex.php:659
_parseEntry($entry)
Extracting the data of one content.
Definition: BibTex.php:370
_unwrap($entry)
Unwrapping entry.
Definition: BibTex.php:625
_checkAt($entry)
Checking whether an at is outside an entry.
Definition: BibTex.php:546
$valid
if(!is_array($argv)) $options