BibtexParserCsv.php
Go to the documentation of this file.00001 <?php
00002
00005
00006
00033 include_once("BibtexItem.php");
00034
00044 class BibtexParserCsv
00045 {
00046 public $items = array();
00047
00049 private $fileContent = "";
00050
00051 function __construct($content)
00052 {
00053 $this->fileContent = $content;
00054
00055
00056 $this->parse();
00057 }
00058
00059 function __destruct() { }
00060
00061 private function parse()
00062 {
00063 $itemsLines = explode("\n", $this->fileContent);
00064
00065 $uniqueID = "";
00066 $item;
00067 $currentType = "";
00068
00069 foreach($itemsLines as $line)
00070 {
00071 $propertyValue = explode("\t", $line);
00072
00073 $propertyValue[0] = strtolower($propertyValue[0]);
00074
00075
00076 if($currentType == "person")
00077 {
00078 switch($propertyValue[0])
00079 {
00080 case "title":
00081 $propertyValue[0] = "name";
00082 break;
00083 }
00084 }
00085
00086 if($currentType == "subject")
00087 {
00088 switch($propertyValue[0])
00089 {
00090 case "title":
00091 $propertyValue[0] = "subjectTitle";
00092 break;
00093 }
00094 }
00095
00096 if($propertyValue[0] == "id_local")
00097 {
00098 if(isset($item) && count($item) > 0)
00099 {
00100 $this->items[$uniqueID] = $item;
00101 }
00102
00103 $item = new BibtexItem();
00104
00105 $uniqueID = $propertyValue[1];
00106 $item->addID($uniqueID);
00107 }
00108 else if($propertyValue[0] == "bibtype")
00109 {
00110 $propertyValue[1] = strtolower($propertyValue[1]);
00111
00112 $item->addType($propertyValue[1]);
00113 $currentType = $propertyValue[1];
00114 }
00115 else if($propertyValue[0] == "author")
00116 {
00117 $authors = "";
00118
00119 preg_match_all("|\"#(.*)\"|U", $propertyValue[1], $matches);
00120
00121 foreach($matches[1] as $author)
00122 {
00123 if($authors != "")
00124 {
00125 $authors .= ",";
00126 }
00127
00128 $authors .= $author;
00129 }
00130
00131 $item->addProperty($propertyValue[0], $authors);
00132 }
00133 else
00134 {
00135 $process = TRUE;
00136
00137
00138 if($propertyValue[0] == "subject")
00139 {
00140 $propertyValue[0] = "subjects";
00141 }
00142
00143 if($propertyValue[0] == "subjects")
00144 {
00145 $propertyValue[1] = str_replace(" ", ",", $propertyValue[1]);
00146 }
00147
00148 if(($propertyValue[0] == "bibliography" || $propertyValue[0] == "honor" || $propertyValue[0] == "image"
00149 || $propertyValue[0] == "biography" || $propertyValue[0] == "memorial") && strlen($propertyValue[1]) > 0)
00150 {
00151 $pos = strpos($propertyValue[1], "href=\"");
00152
00153 if($pos)
00154 {
00155 $pos2 = strpos($propertyValue[1], "\"", $pos + 6);
00156 }
00157
00158 if($pos && $pos2)
00159 {
00160 $propertyValue[1] = substr($propertyValue[1], $pos + 6, $pos2 - 9);
00161 }
00162 }
00163
00164 if($propertyValue[0] == "publisher")
00165 {
00166 $propertyValue[1] = strip_tags($propertyValue[1]);
00167 }
00168
00169 if($propertyValue[0] == "sici")
00170 {
00171 $propertyValue[1] = str_replace(array ("<", ">"), array ("<", ">"), $propertyValue[1]);
00172 }
00173
00174 if($propertyValue[0] == "dates")
00175 {
00176 $dates = explode("--", $propertyValue[1]);
00177
00178 $item->addProperty("born_date", $dates[0]);
00179 $item->addProperty("death_date", $dates[1]);
00180
00181 $process = FALSE;
00182 }
00183
00184
00185 if($process && $propertyValue[0] != "")
00186 {
00187 $item->addProperty($propertyValue[0], $propertyValue[1]);
00188 }
00189 }
00190 }
00191 }
00192 }
00193
00194
00196
00197 ?>
Copyright © 2009.
Structured Dynamics LLC. All rights reserved.