/** * Reformat the array representation of citation into a more useable format - In-text style citations * * @author Mark Grimshaw * @version 1 */ function citationToArrayInTextStyle() { //print_r($this->style); print "<P>"; include_once "PARSESTYLE.php"; $temp = PARSESTYLE::parseStringToArray('citation', trim($this->style['template']), $this->styleMap); // Ensure we have only valid fields. foreach ($temp as $field => $value) { if (array_key_exists($field, $this->styleMap->citation) || $field == 'independent' || $field == 'ultimate' || $field == 'preliminaryText') { $this->template[$field] = $value; } } if (isset($this->template)) { $this->parseIndependent($this->template); } if (trim($this->style['followCreatorTemplate'])) { $temp = PARSESTYLE::parseStringToArray('citation', trim($this->style['followCreatorTemplate']), $this->styleMap); foreach ($temp as $field => $value) { if (array_key_exists($field, $this->styleMap->citation) || $field == 'independent' || $field == 'ultimate' || $field == 'preliminaryText') { $this->followCreatorTemplate[$field] = $value; } } $this->parseIndependent($this->followCreatorTemplate); } if (trim($this->style['consecutiveCreatorTemplate'])) { $temp = PARSESTYLE::parseStringToArray('citation', trim($this->style['consecutiveCreatorTemplate']), $this->styleMap); foreach ($temp as $field => $value) { if (array_key_exists($field, $this->styleMap->citation) || $field == 'independent' || $field == 'ultimate' || $field == 'preliminaryText') { $this->consecutiveCreatorTemplate[$field] = $value; } } $this->parseIndependent($this->consecutiveCreatorTemplate); } if (trim($this->style['subsequentCreatorTemplate'])) { $temp = PARSESTYLE::parseStringToArray('citation', trim($this->style['subsequentCreatorTemplate']), $this->styleMap); foreach ($temp as $field => $value) { if (array_key_exists($field, $this->styleMap->citation) || $field == 'independent' || $field == 'ultimate' || $field == 'preliminaryText') { $this->subsequentCreatorTemplate[$field] = $value; } } $this->parseIndependent($this->subsequentCreatorTemplate); } if (trim($this->style['ambiguousTemplate'])) { $temp = PARSESTYLE::parseStringToArray('citation', trim($this->style['ambiguousTemplate']), $this->styleMap); // Ensure we have only valid fields. foreach ($temp as $field => $value) { if (array_key_exists($field, $this->styleMap->citation) || $field == 'independent' || $field == 'ultimate' || $field == 'preliminaryText') { $this->ambiguousTemplate[$field] = $value; } } $this->parseIndependent($this->ambiguousTemplate); } // replacement citation templates for particular resource types foreach ($this->styleMap->types as $type => $value) { $key = $type . "Template"; if (array_key_exists($key, $this->style) && trim($this->style[$key])) { $temp = PARSESTYLE::parseStringToArray('citation', trim($this->style[$key]), $this->styleMap); foreach ($temp as $field => $value) { if (array_key_exists($field, $this->styleMap->citation) || $field == 'independent' || $field == 'ultimate' || $field == 'preliminaryText') { $this->{$key}[$field] = $value; } } $this->parseIndependent($this->{$key}); } } }
/** * Perform pre-processing on the raw SQL array * * @author Mark Grimshaw * @version 1 * * @param $type The resource type * @param $row Associate array of raw SQL data * @return $row Processed row of raw SQL data */ function preProcess($type, $row) { /** * Ensure that $this->item is empty for each resource!!!!!!!!!! */ $this->item = array(); // Map this system's resource type to OSBib's resource type $this->type = array_search($type, $this->styleMap->types); if ($this->bibtex && array_key_exists('author', $row)) { $row['creator1'] = $row['author']; unset($row['author']); } if ($this->bibtex && array_key_exists('editor', $row)) { $row['creator2'] = $row['editor']; unset($row['editor']); } /** * Set any author/editor re-ordering for book and book_article type. */ if (!$this->preview && ($type == 'book' || $type == 'book_article') && $row['creator2'] && !$row['creator1'] && $this->style['editorSwitch'] && array_key_exists('author', $this->{$type})) { $row['creator1'] = $row['creator2']; $row['creator2'] = FALSE; $editorArray = PARSESTYLE::parseStringToArray($type, $this->style['editorSwitchIfYes'], $this->styleMap); if (!empty($editorArray) && array_key_exists('editor', $editorArray)) { $this->{$type}['author'] = $editorArray['editor']; unset($this->{$type}['editor']); $this->editorSwitch = TRUE; } } if ($this->style['dateMonthNoDay'] && array_key_exists('date', $this->styleMap->{$type}) && array_key_exists('dateMonthNoDayString', $this->style) && $this->style['dateMonthNoDayString']) { $this->dateArray = PARSESTYLE::parseStringToArray($type, $this->style['dateMonthNoDayString'], $this->styleMap, TRUE); $this->dateMonthNoDay = TRUE; } /** * If $row comes in in BibTeX format, process and add items to $this->item */ if ($this->bibtex) { if (!$this->type) { list($type, $row) = $this->preProcessBibtex($row, $type); } else { list($type, $row) = $this->preProcessBibtex($row, $this->type); } } /** * Ensure that for theses types, the first letter of type and label are capitalized (e.g. 'Master's Thesis'). */ if ($type == 'thesis') { if (($key = array_search('type', $this->styleMap->{$type})) !== FALSE) { if (isset($row[$key])) { $row[$key] = ucfirst($row[$key]); } } if (($key = array_search('label', $this->styleMap->{$type})) !== FALSE) { if (isset($row[$key])) { $row[$key] = ucfirst($row[$key]); } } } /** * Set to catch-all generic style. For all keys except named database fields, creator1 and year1, * we only print if the value in $this->styleMap matches the value in * $this->styleMap->generic for each key. */ if ($this->citationFootnote) { // using footnote template $footnoteType = 'footnote_' . $type; if (isset($this->{$footnoteType})) { // footnote template for this resource exists $this->footnoteType = $footnoteType; $this->footnoteTypeArray[$type] = $footnoteType; } else { $footnoteType = 'footnote_' . $this->fallback[$type]; if (isset($this->{$footnoteType})) { // fallback footnote template exists $this->footnoteType = $footnoteType; $this->footnoteTypeArray[$type] = $footnoteType; } else { if (!isset($this->{$type})) { // use fallback bibliography template $fallback = $this->fallback[$type]; $this->footnoteTypeArray[$type] = $fallback; $type = $fallback; } else { $this->footnoteTypeArray[$type] = $type; } } } } else { if (!isset($this->{$type})) { $fallback = $this->fallback[$type]; $type = $fallback; } } $this->type = $type; /** * Add BibTeX entry to $this->item */ if ($this->bibtex) { foreach ($row as $field => $value) { if (array_key_exists($field, $this->styleMap->{$type}) && !array_key_exists($this->styleMap->{$type}[$field], $this->item)) { $this->addItem($row[$field], $field); } } } return $row; }