ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Structures_BibTex Class Reference
+ Collaboration diagram for Structures_BibTex:

Public Member Functions

 Structures_BibTex ($options=array())
 Constructor.
 setOption ($option, $value)
 Sets run-time configuration options.
 loadFile ($filename)
 Reads a give BibTex File.
 parse ()
 Parses what is stored in content and clears the content if the parsing is successfull.
 _parseEntry ($entry)
 Extracting the data of one content.
 _checkEqualSign ($entry, $position)
 Checking whether the position of the '=' is correct.
 _checkAllowedEntryType ($entry)
 Checking if the entry type is allowed.
 _checkAt ($entry)
 Checking whether an at is outside an entry.
 _stripDelimiter ($entry)
 Stripping Delimiter.
 _unwrap ($entry)
 Unwrapping entry.
 _wordwrap ($entry)
 Wordwrap an entry.
 _extractAuthors ($entry)
 Extracting the authors.
 _determineCase ($word)
 Case Determination according to the needs of BibTex.
 _validateValue ($entry, $wholeentry)
 Validation of a value.
 _removeCurlyBraces ($value)
 Remove curly braces from entry.
 _generateWarning ($type, $entry, $wholeentry= '')
 Generates a warning.
 clearWarnings ()
 Cleares all warnings.
 hasWarning ()
 Is there a warning?
 amount ()
 Returns the amount of available BibTex entries.
 _formatAuthor ($array)
 Returns the author formatted.
 bibTex ()
 Converts the stored BibTex entries to a BibTex String.
 addEntry ($newentry)
 Adds a new BibTex entry to the data.
 getStatistic ()
 Returns statistic.
 rtf ()
 Returns the stored data in RTF format.
 html ()
 Returns the stored data in HTML format.

Data Fields

 $data
 $content
 $_delimiters
 $warnings
 $_options
 $rtfstring
 $htmlstring
 $allowedEntryTypes
 $authorstring

Detailed Description

Definition at line 77 of file BibTex.php.

Member Function Documentation

Structures_BibTex::_checkAllowedEntryType (   $entry)

Checking if the entry type is allowed.

private

Parameters
string$entryThe entry to check
Returns
bool true if allowed, false otherwise

Definition at line 528 of file BibTex.php.

Referenced by _parseEntry().

{
return in_array($entry, $this->allowedEntryTypes);
}

+ Here is the caller graph for this function:

Structures_BibTex::_checkAt (   $entry)

Checking whether an at is outside an entry.

Sometimes an entry misses an entry brace. Then the at of the next entry seems to be inside an entry. This is checked here. When it is most likely that the at is an opening at of the next entry this method returns true.

private

Parameters
string$entryThe text of the entry until the at
Returns
bool true if the at is correct, false if the at is likely to begin the next entry.

Definition at line 546 of file BibTex.php.

References $ret.

Referenced by parse().

{
$ret = false;
$opening = array_keys($this->_delimiters);
$closing = array_values($this->_delimiters);
//Getting the value (at is only allowd in values)
if (strrpos($entry, '=') !== false) {
$position = strrpos($entry, '=');
$proceed = true;
if (substr($entry, $position - 1, 1) == '\\') {
$proceed = false;
}
while (! $proceed) {
$substring = substr($entry, 0, $position);
$position = strrpos($substring, '=');
$proceed = true;
if (substr($entry, $position - 1, 1) == '\\') {
$proceed = false;
}
}
$value = trim(substr($entry, $position + 1));
$open = 0;
$char = '';
$lastchar = '';
for ($i = 0; $i < strlen($value); $i ++) {
$char = substr($this->content, $i, 1);
if (in_array($char, $opening) && ('\\' != $lastchar)) {
$open ++;
} elseif (in_array($char, $closing) && ('\\' != $lastchar)) {
$open --;
}
$lastchar = $char;
}
//if open is grater zero were are inside an entry
if ($open > 0) {
$ret = true;
}
}
return $ret;
}

+ Here is the caller graph for this function:

Structures_BibTex::_checkEqualSign (   $entry,
  $position 
)

Checking whether the position of the '=' is correct.

Sometimes there is a problem if a '=' is used inside an entry (for example abstract). This method checks if the '=' is outside braces then the '=' is correct and true is returned. If the '=' is inside braces it contains to a equation and therefore false is returned.

private

Parameters
string$entryThe text of the whole remaining entry
intthe current used place of the '='
Returns
bool true if the '=' is correct, false if it contains to an equation

Definition at line 467 of file BibTex.php.

References $ret.

Referenced by _parseEntry().

{
$ret = true;
//This is getting tricky
//We check the string backwards until the position and count the closing an opening braces
//If we reach the position the amount of opening and closing braces should be equal
$length = strlen($entry);
$open = 0;
for ($i = $length - 1; $i >= $position; $i --) {
$precedingchar = substr($entry, $i - 1, 1);
$char = substr($entry, $i, 1);
if (('{' == $char) && ('\\' != $precedingchar)) {
$open ++;
}
if (('}' == $char) && ('\\' != $precedingchar)) {
$open --;
}
}
if (0 != $open) {
$ret = false;
}
//There is still the posibility that the entry is delimited by double quotes.
//Then it is possible that the braces are equal even if the '=' is in an equation.
if ($ret) {
$entrycopy = trim($entry);
$lastchar = $entrycopy{strlen($entrycopy) - 1};
if (',' == $lastchar) {
$lastchar = $entrycopy{strlen($entrycopy) - 2};
}
if ('"' == $lastchar) {
//The return value is set to false
//If we find the closing " before the '=' it is set to true again.
//Remember we begin to search the entry backwards so the " has to show up twice - ending and beginning delimiter
$ret = false;
$found = 0;
for ($i = $length; $i >= $position; $i --) {
$precedingchar = substr($entry, $i - 1, 1);
$char = substr($entry, $i, 1);
if (('"' == $char) && ('\\' != $precedingchar)) {
$found ++;
}
if (2 == $found) {
$ret = true;
break;
}
}
}
}
return $ret;
}

+ Here is the caller graph for this function:

Structures_BibTex::_determineCase (   $word)

Case Determination according to the needs of BibTex.

To parse the Author(s) correctly a determination is needed to get the Case of a word. There are three possible values:

  • Upper Case (return value 1)
  • Lower Case (return value 0)
  • Caseless (return value -1)

private

Parameters
string$word
Returns
int The Case or PEAR_Error if there was a problem

Definition at line 803 of file BibTex.php.

References $ret, and PEAR\raiseError().

Referenced by _extractAuthors().

{
$ret = - 1;
$trimmedword = trim($word);
/*We need this variable. Without the next of would not work
(trim changes the variable automatically to a string!)*/
if (is_string($word) && (strlen($trimmedword) > 0)) {
$i = 0;
$found = false;
$openbrace = 0;
while (! $found && ($i <= strlen($word))) {
$letter = substr($trimmedword, $i, 1);
$ord = ord($letter);
if ($ord == 123) { //Open brace
$openbrace ++;
}
if ($ord == 125) { //Closing brace
$openbrace --;
}
if (($ord >= 65) && ($ord <= 90) && (0 == $openbrace)) { //The first character is uppercase
$ret = 1;
$found = true;
} elseif (($ord >= 97) && ($ord <= 122) && (0 == $openbrace)) { //The first character is lowercase
$ret = 0;
$found = true;
} else { //Not yet found
$i ++;
}
}
} else {
$ret = PEAR::raiseError('Could not determine case on word: ' . (string)$word);
}
return $ret;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Structures_BibTex::_extractAuthors (   $entry)

Extracting the authors.

private

Parameters
string$entryThe entry with the authors
Returns
array the extracted authors

Definition at line 659 of file BibTex.php.

References $size, _determineCase(), _unwrap(), and PEAR\isError().

Referenced by _parseEntry().

{
$entry = $this->_unwrap($entry);
$authorarray = array();
$authorarray = explode(' and ', $entry);
for ($i = 0; $i < sizeof($authorarray); $i ++) {
$author = trim($authorarray[$i]);
/*The first version of how an author could be written (First von Last)
has no commas in it*/
$first = '';
$von = '';
$last = '';
$jr = '';
if (strpos($author, ',') === false) {
$tmparray = array();
//$tmparray = explode(' ', $author);
$tmparray = explode(' |~', $author);
$size = sizeof($tmparray);
if (1 == $size) { //There is only a last
$last = $tmparray[0];
} elseif (2 == $size) { //There is a first and a last
$first = $tmparray[0];
$last = $tmparray[1];
} else {
$invon = false;
$inlast = false;
for ($j = 0; $j < ($size - 1); $j ++) {
if ($inlast) {
$last .= ' ' . $tmparray[$j];
} elseif ($invon) {
$case = $this->_determineCase($tmparray[$j]);
if (PEAR::isError($case)) {
// IGNORE?
} elseif ((0 == $case) || (- 1 == $case)) { //Change from von to last
//You only change when there is no more lower case there
$islast = true;
for ($k = ($j + 1); $k < ($size - 1); $k ++) {
$futurecase = $this->_determineCase($tmparray[$k]);
if (PEAR::isError($case)) {
// IGNORE?
} elseif (0 == $futurecase) {
$islast = false;
}
}
if ($islast) {
$inlast = true;
if (- 1 == $case) { //Caseless belongs to the last
$last .= ' ' . $tmparray[$j];
} else {
$von .= ' ' . $tmparray[$j];
}
} else {
$von .= ' ' . $tmparray[$j];
}
} else {
$von .= ' ' . $tmparray[$j];
}
} else {
$case = $this->_determineCase($tmparray[$j]);
if (PEAR::isError($case)) {
// IGNORE?
} elseif (0 == $case) { //Change from first to von
$invon = true;
$von .= ' ' . $tmparray[$j];
} else {
$first .= ' ' . $tmparray[$j];
}
}
}
//The last entry is always the last!
$last .= ' ' . $tmparray[$size - 1];
}
} else { //Version 2 and 3
$tmparray = array();
$tmparray = explode(',', $author);
//The first entry must contain von and last
$vonlastarray = array();
$vonlastarray = explode(' ', $tmparray[0]);
$size = sizeof($vonlastarray);
if (1 == $size) { //Only one entry->got to be the last
$last = $vonlastarray[0];
} else {
$inlast = false;
for ($j = 0; $j < ($size - 1); $j ++) {
if ($inlast) {
$last .= ' ' . $vonlastarray[$j];
} else {
if (0 != ($this->_determineCase($vonlastarray[$j]))) { //Change from von to last
$islast = true;
for ($k = ($j + 1); $k < ($size - 1); $k ++) {
$this->_determineCase($vonlastarray[$k]);
$case = $this->_determineCase($vonlastarray[$k]);
if (PEAR::isError($case)) {
// IGNORE?
} elseif (0 == $case) {
$islast = false;
}
}
if ($islast) {
$inlast = true;
$last .= ' ' . $vonlastarray[$j];
} else {
$von .= ' ' . $vonlastarray[$j];
}
} else {
$von .= ' ' . $vonlastarray[$j];
}
}
}
$last .= ' ' . $vonlastarray[$size - 1];
}
//Now we check if it is version three (three entries in the array (two commas)
if (3 == sizeof($tmparray)) {
$jr = $tmparray[1];
}
//Everything in the last entry is first
$first = $tmparray[sizeof($tmparray) - 1];
}
$authorarray[$i] = array(
'first' => trim($first),
'von' => trim($von),
'last' => trim($last),
'jr' => trim($jr)
);
}
return $authorarray;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Structures_BibTex::_formatAuthor (   $array)

Returns the author formatted.

The Author is formatted as setted in the authorstring

private

Parameters
array$arrayAuthor array
Returns
string the formatted author string

Definition at line 983 of file BibTex.php.

References $authorstring, and $ret.

Referenced by bibTex(), html(), and rtf().

{
if (! array_key_exists('von', $array)) {
$array['von'] = '';
} else {
$array['von'] = trim($array['von']);
}
if (! array_key_exists('last', $array)) {
$array['last'] = '';
} else {
$array['last'] = trim($array['last']);
}
if (! array_key_exists('jr', $array)) {
$array['jr'] = '';
} else {
$array['jr'] = trim($array['jr']);
}
if (! array_key_exists('first', $array)) {
$array['first'] = '';
} else {
$array['first'] = trim($array['first']);
}
$ret = str_replace("VON", $array['von'], $ret);
$ret = str_replace("LAST", $array['last'], $ret);
$ret = str_replace("JR", $array['jr'], $ret);
$ret = str_replace("FIRST", $array['first'], $ret);
return trim($ret);
}

+ Here is the caller graph for this function:

Structures_BibTex::_generateWarning (   $type,
  $entry,
  $wholeentry = '' 
)

Generates a warning.

private

Parameters
string$typeThe type of the warning
string$entryThe line of the entry where the warning occurred
string$wholeentryOPTIONAL The whole entry where the warning occurred

Definition at line 928 of file BibTex.php.

Referenced by _parseEntry(), _validateValue(), html(), parse(), and rtf().

{
$warning['warning'] = $type;
$warning['entry'] = $entry;
$warning['wholeentry'] = $wholeentry;
$this->warnings[] = $warning;
}

+ Here is the caller graph for this function:

Structures_BibTex::_parseEntry (   $entry)

Extracting the data of one content.

The parse function splits the content into its entries. Then every entry is parsed by this function. It parses the entry backwards. First the last '=' is searched and the value extracted from that. A copy is made of the entry if warnings should be generated. This takes quite some memory but it is needed to get good warnings. If nor warnings are generated then you don have to worry about memory. Then the last ',' is searched and the field extracted from that. Again the entry is shortened. Finally after all field=>value pairs the cite and type is extraced and the authors are splitted. If there is a problem false is returned.

private

Parameters
string$entryThe entry
Returns
array The representation of the entry or false if there is a problem

Definition at line 370 of file BibTex.php.

References $ret, _checkAllowedEntryType(), _checkEqualSign(), _extractAuthors(), _generateWarning(), _removeCurlyBraces(), _stripDelimiter(), _unwrap(), and _validateValue().

Referenced by parse().

{
$entrycopy = '';
if ($this->_options['validate']) {
$entrycopy = $entry; //We need a copy for printing the warnings
}
$ret = array();
if ('@string' == strtolower(substr($entry, 0, 7))) {
//String are not yet supported!
if ($this->_options['validate']) {
$this->_generateWarning('STRING_ENTRY_NOT_YET_SUPPORTED', '', $entry . '}');
}
} elseif ('@preamble' == strtolower(substr($entry, 0, 9))) {
//Preamble not yet supported!
if ($this->_options['validate']) {
$this->_generateWarning('PREAMBLE_ENTRY_NOT_YET_SUPPORTED', '', $entry . '}');
}
} else {
//Parsing all fields
while (strrpos($entry, '=') !== false) {
$position = strrpos($entry, '=');
//Checking that the equal sign is not quoted or is not inside a equation (For example in an abstract)
$proceed = true;
if (substr($entry, $position - 1, 1) == '\\') {
$proceed = false;
}
if ($proceed) {
$proceed = $this->_checkEqualSign($entry, $position);
}
while (! $proceed) {
$substring = substr($entry, 0, $position);
$position = strrpos($substring, '=');
$proceed = true;
if (substr($entry, $position - 1, 1) == '\\') {
$proceed = false;
}
if ($proceed) {
$proceed = $this->_checkEqualSign($entry, $position);
}
}
$value = trim(substr($entry, $position + 1));
$entry = substr($entry, 0, $position);
if (',' == substr($value, strlen($value) - 1, 1)) {
$value = substr($value, 0, - 1);
}
if ($this->_options['validate']) {
$this->_validateValue($value, $entrycopy);
}
if ($this->_options['stripDelimiter']) {
$value = $this->_stripDelimiter($value);
}
if ($this->_options['unwrap']) {
$value = $this->_unwrap($value);
}
if ($this->_options['removeCurlyBraces']) {
$value = $this->_removeCurlyBraces($value);
}
$position = strrpos($entry, ',');
$field = strtolower(trim(substr($entry, $position + 1)));
$ret[$field] = $value;
$entry = substr($entry, 0, $position);
}
//Parsing cite and entry type
$arr = explode('{', $entry);
$ret['cite'] = trim($arr[1]);
$ret['entryType'] = strtolower(trim($arr[0]));
if ('@' == $ret['entryType']{0}) {
$ret['entryType'] = substr($ret['entryType'], 1);
}
if ($this->_options['validate']) {
if (! $this->_checkAllowedEntryType($ret['entryType'])) {
$this->_generateWarning('WARNING_NOT_ALLOWED_ENTRY_TYPE', $ret['entryType'], $entry . '}');
}
}
//Handling the authors
if (in_array('author', array_keys($ret)) && $this->_options['extractAuthors']) {
$ret['author'] = $this->_extractAuthors($ret['author']);
}
}
return $ret;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Structures_BibTex::_removeCurlyBraces (   $value)

Remove curly braces from entry.

private

Parameters
string$valueThe value in which curly braces to be removed
stringValue with removed curly braces

Definition at line 890 of file BibTex.php.

Referenced by _parseEntry().

{
//First we save the delimiters
$beginningdels = array_keys($this->_delimiters);
$firstchar = substr($entry, 0, 1);
$lastchar = substr($entry, - 1, 1);
$begin = '';
$end = '';
while (in_array($firstchar, $beginningdels)) { //The first character is an opening delimiter
if ($lastchar == $this->_delimiters[$firstchar]) { //Matches to closing Delimiter
$begin .= $firstchar;
$end .= $lastchar;
$value = substr($value, 1, - 1);
} else {
break;
}
$firstchar = substr($value, 0, 1);
$lastchar = substr($value, - 1, 1);
}
//Now we get rid of the curly braces
$pattern = '/([^\\\\])\{(.*?[^\\\\])\}/';
$replacement = '$1$2';
$value = preg_replace($pattern, $replacement, $value);
//Reattach delimiters
$value = $begin . $value . $end;
return $value;
}

+ Here is the caller graph for this function:

Structures_BibTex::_stripDelimiter (   $entry)

Stripping Delimiter.

private

Parameters
string$entryThe entry where the Delimiter should be stripped from
Returns
string Stripped entry

Definition at line 597 of file BibTex.php.

Referenced by _parseEntry().

{
$beginningdels = array_keys($this->_delimiters);
$length = strlen($entry);
$firstchar = substr($entry, 0, 1);
$lastchar = substr($entry, - 1, 1);
while (in_array($firstchar, $beginningdels)) { //The first character is an opening delimiter
if ($lastchar == $this->_delimiters[$firstchar]) { //Matches to closing Delimiter
$entry = substr($entry, 1, - 1);
} else {
break;
}
$firstchar = substr($entry, 0, 1);
$lastchar = substr($entry, - 1, 1);
}
return $entry;
}

+ Here is the caller graph for this function:

Structures_BibTex::_unwrap (   $entry)

Unwrapping entry.

private

Parameters
string$entryThe entry to unwrap
Returns
string unwrapped entry

Definition at line 625 of file BibTex.php.

Referenced by _extractAuthors(), _parseEntry(), html(), and rtf().

{
$entry = preg_replace('/\s+/', ' ', $entry);
return trim($entry);
}

+ Here is the caller graph for this function:

Structures_BibTex::_validateValue (   $entry,
  $wholeentry 
)

Validation of a value.

There may be several problems with the value of a field. These problems exist but do not break the parsing. If a problem is detected a warning is appended to the array warnings.

private

Parameters
string$entryThe entry aka one line which which should be validated
string$wholeentryThe whole BibTex Entry which the one line is part of
Returns
void

Definition at line 853 of file BibTex.php.

References _generateWarning().

Referenced by _parseEntry().

{
//There is no @ allowed if the entry is enclosed by braces
if (preg_match('/^{.*@.*}$/', $entry)) {
$this->_generateWarning('WARNING_AT_IN_BRACES', $entry, $wholeentry);
}
//No escaped " allowed if the entry is enclosed by double quotes
if (preg_match('/^\".*\\".*\"$/', $entry)) {
$this->_generateWarning('WARNING_ESCAPED_DOUBLE_QUOTE_INSIDE_DOUBLE_QUOTES', $entry, $wholeentry);
}
//Amount of Braces is not correct
$open = 0;
$lastchar = '';
$char = '';
for ($i = 0; $i < strlen($entry); $i ++) {
$char = substr($entry, $i, 1);
if (('{' == $char) && ('\\' != $lastchar)) {
$open ++;
}
if (('}' == $char) && ('\\' != $lastchar)) {
$open --;
}
$lastchar = $char;
}
if (0 != $open) {
$this->_generateWarning('WARNING_UNBALANCED_AMOUNT_OF_BRACES', $entry, $wholeentry);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Structures_BibTex::_wordwrap (   $entry)

Wordwrap an entry.

private

Parameters
string$entryThe entry to wrap
Returns
string wrapped entry

Definition at line 641 of file BibTex.php.

{
if (('' != $entry) && (is_string($entry))) {
$entry = wordwrap($entry, $this->_options['wordWrapWidth'], $this->_options['wordWrapBreak'], $this->_options['wordWrapCut']);
}
return $entry;
}
Structures_BibTex::addEntry (   $newentry)

Adds a new BibTex entry to the data.

public

Parameters
array$newentryThe new data to add
Returns
void

Definition at line 1067 of file BibTex.php.

{
$this->data[] = $newentry;
}
Structures_BibTex::amount ( )

Returns the amount of available BibTex entries.

public

Returns
int The amount of available BibTex entries

Definition at line 967 of file BibTex.php.

References $data.

{
return sizeof($this->data);
}
Structures_BibTex::bibTex ( )

Converts the stored BibTex entries to a BibTex String.

In the field list, the author is the last field.

public

Returns
string The BibTex string

Definition at line 1022 of file BibTex.php.

References $bibtex, and _formatAuthor().

{
$bibtex = '';
foreach ($this->data as $entry) {
//Intro
$bibtex .= '@' . strtolower($entry['entryType']) . ' { ' . $entry['cite'] . ",\n";
//Other fields except author
foreach ($entry as $key => $val) {
if ($this->_options['wordWrapWidth'] > 0) {
$val = $this->_wordWrap($val);
}
if (! in_array($key, array( 'cite', 'entryType', 'author' ))) {
$bibtex .= "\t" . $key . ' = {' . $val . "},\n";
}
}
//Author
if (array_key_exists('author', $entry)) {
if ($this->_options['extractAuthors']) {
$tmparray = array(); //In this array the authors are saved and the joind with an and
foreach ($entry['author'] as $authorentry) {
$tmparray[] = $this->_formatAuthor($authorentry);
}
$author = join(' and ', $tmparray);
} else {
$author = $entry['author'];
}
} else {
$author = '';
}
$bibtex .= "\tauthor = {" . $author . "}\n";
$bibtex .= "}\n\n";
}
return $bibtex;
}

+ Here is the call graph for this function:

Structures_BibTex::clearWarnings ( )

Cleares all warnings.

public

Definition at line 941 of file BibTex.php.

{
$this->warnings = array();
}
Structures_BibTex::getStatistic ( )

Returns statistic.

This functions returns a hash table. The keys are the different entry types and the values are the amount of these entries.

public

Returns
array Hash Table with the data

Definition at line 1081 of file BibTex.php.

References $ret.

{
$ret = array();
foreach ($this->data as $entry) {
if (array_key_exists($entry['entryType'], $ret)) {
$ret[$entry['entryType']] ++;
} else {
$ret[$entry['entryType']] = 1;
}
}
return $ret;
}
Structures_BibTex::hasWarning ( )

Is there a warning?

public

Returns
true if there is, false otherwise

Definition at line 952 of file BibTex.php.

{
if (sizeof($this->warnings) > 0) {
return true;
} else {
return false;
}
}
Structures_BibTex::html ( )

Returns the stored data in HTML format.

This method simply returns a HTML formatted string. This is done very simple and is not intended for heavy using and fine formatting. This should be done by BibTex! It is intended to give some kind of quick preview. If you want to change the default format you have to override the class variable "htmlstring". This variable is used and the placeholders simply replaced. Lines with no data cause an warning!

Returns
string the HTML Strings

Definition at line 1167 of file BibTex.php.

References $htmlstring, $ret, _formatAuthor(), _generateWarning(), and _unwrap().

{
$ret = "<p>\n";
foreach ($this->data as $entry) {
$title = '';
$journal = '';
$year = '';
$authors = '';
if (array_key_exists('title', $entry)) {
$title = $this->_unwrap($entry['title']);
}
if (array_key_exists('journal', $entry)) {
$journal = $this->_unwrap($entry['journal']);
}
if (array_key_exists('year', $entry)) {
$year = $this->_unwrap($entry['year']);
}
if (array_key_exists('author', $entry)) {
if ($this->_options['extractAuthors']) {
$tmparray = array(); //In this array the authors are saved and the joind with an and
foreach ($entry['author'] as $authorentry) {
$tmparray[] = $this->_formatAuthor($authorentry);
}
$authors = join(', ', $tmparray);
} else {
$authors = $entry['author'];
}
}
if (('' != $title) || ('' != $journal) || ('' != $year) || ('' != $authors)) {
$line = str_replace("TITLE", $title, $line);
$line = str_replace("JOURNAL", $journal, $line);
$line = str_replace("YEAR", $year, $line);
$line = str_replace("AUTHORS", $authors, $line);
$line .= "\n";
$ret .= $line;
} else {
$this->_generateWarning('WARNING_LINE_WAS_NOT_CONVERTED', '', print_r($entry, 1));
}
}
$ret .= "</p>\n";
return $ret;
}

+ Here is the call graph for this function:

Structures_BibTex::loadFile (   $filename)

Reads a give BibTex File.

public

Parameters
string$filenameName of the file
Returns
mixed true on success PEAR_Error on failure

Definition at line 229 of file BibTex.php.

References $filename, and PEAR\raiseError().

{
if (file_exists($filename)) {
if (($this->content = @file_get_contents($filename)) === false) {
return PEAR::raiseError('Could not open file ' . $filename);
} else {
$this->_pos = 0;
$this->_oldpos = 0;
return true;
}
} else {
return PEAR::raiseError('Could not find file ' . $filename);
}
}

+ Here is the call graph for this function:

Structures_BibTex::parse ( )

Parses what is stored in content and clears the content if the parsing is successfull.

public

Returns
boolean true on success and PEAR_Error if there was a problem

This is not yet used. We are here if the Entry is either not correct or not supported. But this should already generate a warning. Therefore it should not be necessary to do anything here

Definition at line 251 of file BibTex.php.

References $valid, _checkAt(), _generateWarning(), _parseEntry(), and PEAR\raiseError().

{
//The amount of opening braces is compared to the amount of closing braces
//Braces inside comments are ignored
$this->warnings = array();
$this->data = array();
$valid = true;
$open = 0;
$entry = false;
$char = '';
$lastchar = '';
$buffer = '';
for ($i = 0; $i < strlen($this->content); $i ++) {
$char = substr($this->content, $i, 1);
if ((0 != $open) && ('@' == $char)) {
if (! $this->_checkAt($buffer)) {
$this->_generateWarning('WARNING_MISSING_END_BRACE', '', $buffer);
//To correct the data we need to insert a closing brace
$char = '}';
$i --;
}
}
if ((0 == $open) && ('@' == $char)) { //The beginning of an entry
$entry = true;
} elseif ($entry && ('{' == $char)
&& ('\\' != $lastchar)
) { //Inside an entry and non quoted brace is opening
$open ++;
} elseif ($entry && ('}' == $char)
&& ('\\' != $lastchar)
) { //Inside an entry and non quoted brace is closing
$open --;
if ($open < 0) { //More are closed than opened
$valid = false;
}
if (0 == $open) { //End of entry
$entry = false;
$entrydata = $this->_parseEntry($buffer);
if (! $entrydata) {
} else {
$this->data[] = $entrydata;
}
$buffer = '';
}
}
if ($entry) { //Inside entry
$buffer .= $char;
}
$lastchar = $char;
}
//If open is one it may be possible that the last ending brace is missing
if (1 == $open) {
$entrydata = $this->_parseEntry($buffer);
if (! $entrydata) {
$valid = false;
} else {
$this->data[] = $entrydata;
$buffer = '';
$open = 0;
}
}
//At this point the open should be zero
if (0 != $open) {
$valid = false;
}
//Are there Multiple entries with the same cite?
if ($this->_options['validate']) {
$cites = array();
foreach ($this->data as $entry) {
$cites[] = $entry['cite'];
}
$unique = array_unique($cites);
if (sizeof($cites) != sizeof($unique)) { //Some values have not been unique!
$notuniques = array();
for ($i = 0; $i < sizeof($cites); $i ++) {
if ('' == $unique[$i]) {
$notuniques[] = $cites[$i];
}
}
$this->_generateWarning('WARNING_MULTIPLE_ENTRIES', implode(',', $notuniques));
}
}
if ($valid) {
$this->content = '';
return true;
} else {
return PEAR::raiseError('Unbalanced parenthesis');
}
}

+ Here is the call graph for this function:

Structures_BibTex::rtf ( )

Returns the stored data in RTF format.

This method simply returns a RTF formatted string. This is done very simple and is not intended for heavy using and fine formatting. This should be done by BibTex! It is intended to give some kind of quick preview or to send someone a reference list as word/rtf format (even some people in the scientific field still use word). If you want to change the default format you have to override the class variable "rtfstring". This variable is used and the placeholders simply replaced. Lines with no data cause an warning!

Returns
string the RTF Strings

Definition at line 1109 of file BibTex.php.

References $ret, $rtfstring, _formatAuthor(), _generateWarning(), and _unwrap().

{
$ret = "{\\rtf\n";
foreach ($this->data as $entry) {
$title = '';
$journal = '';
$year = '';
$authors = '';
if (array_key_exists('title', $entry)) {
$title = $this->_unwrap($entry['title']);
}
if (array_key_exists('journal', $entry)) {
$journal = $this->_unwrap($entry['journal']);
}
if (array_key_exists('year', $entry)) {
$year = $this->_unwrap($entry['year']);
}
if (array_key_exists('author', $entry)) {
if ($this->_options['extractAuthors']) {
$tmparray = array(); //In this array the authors are saved and the joind with an and
foreach ($entry['author'] as $authorentry) {
$tmparray[] = $this->_formatAuthor($authorentry);
}
$authors = join(', ', $tmparray);
} else {
$authors = $entry['author'];
}
}
if (('' != $title) || ('' != $journal) || ('' != $year) || ('' != $authors)) {
$line = str_replace("TITLE", $title, $line);
$line = str_replace("JOURNAL", $journal, $line);
$line = str_replace("YEAR", $year, $line);
$line = str_replace("AUTHORS", $authors, $line);
$line .= "\n\\par\n";
$ret .= $line;
} else {
$this->_generateWarning('WARNING_LINE_WAS_NOT_CONVERTED', '', print_r($entry, 1));
}
}
$ret .= '}';
return $ret;
}

+ Here is the call graph for this function:

Structures_BibTex::setOption (   $option,
  $value 
)

Sets run-time configuration options.

public

Parameters
string$optionoption name
mixed$valuevalue for the option
Returns
mixed true on success PEAR_Error on failure

Definition at line 208 of file BibTex.php.

References $ret, and PEAR\raiseError().

Referenced by Structures_BibTex().

{
$ret = true;
if (array_key_exists($option, $this->_options)) {
$this->_options[$option] = $value;
} else {
$ret = PEAR::raiseError('Unknown option ' . $option);
}
return $ret;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Structures_BibTex::Structures_BibTex (   $options = array())

Constructor.

public

Returns
void

Definition at line 150 of file BibTex.php.

References $options, $test, PEAR\isError(), and setOption().

{
$this->_delimiters = array(
'"' => '"',
'{' => '}'
);
$this->data = array();
$this->content = '';
//$this->_stripDelimiter = $stripDel;
//$this->_validate = $val;
$this->warnings = array();
$this->_options = array(
'stripDelimiter' => true,
'validate' => true,
'unwrap' => false,
'wordWrapWidth' => false,
'wordWrapBreak' => "\n",
'wordWrapCut' => 0,
'removeCurlyBraces' => false,
'extractAuthors' => true,
);
foreach ($options as $option => $value) {
$test = $this->setOption($option, $value);
//Currently nothing is done here, but it could for example raise an warning
}
}
$this->rtfstring = 'AUTHORS, "{\b TITLE}", {\i JOURNAL}, YEAR';
$this->htmlstring = 'AUTHORS, "<strong>TITLE</strong>", <em>JOURNAL</em>, YEAR<br />';
$this->allowedEntryTypes = array(
'article',
'book',
'booklet',
'confernce',
'inbook',
'incollection',
'inproceedings',
'manual',
'mastersthesis',
'misc',
'phdthesis',
'proceedings',
'techreport',
'unpublished'
);
$this->authorstring = 'VON LAST, JR, FIRST';
}

+ Here is the call graph for this function:

Field Documentation

Structures_BibTex::$_delimiters

Definition at line 99 of file BibTex.php.

Structures_BibTex::$_options

Definition at line 113 of file BibTex.php.

Structures_BibTex::$allowedEntryTypes

Definition at line 134 of file BibTex.php.

Structures_BibTex::$authorstring

Definition at line 141 of file BibTex.php.

Referenced by _formatAuthor().

Structures_BibTex::$content

Definition at line 92 of file BibTex.php.

Structures_BibTex::$data

Definition at line 85 of file BibTex.php.

Referenced by amount().

Structures_BibTex::$htmlstring

Definition at line 127 of file BibTex.php.

Referenced by html().

Structures_BibTex::$rtfstring

Definition at line 120 of file BibTex.php.

Referenced by rtf().

Structures_BibTex::$warnings

Definition at line 106 of file BibTex.php.


The documentation for this class was generated from the following file: