. * */ class ClassTeX_Parser { var $count; var $items; var $sortedItems; var $types; var $filename; var $inputdata; var $yearData; var $lastType; var $resultedHtml; /** * BibTeX_Parser( $file, $data ) * * Constructor * @param String $file if filename is used * @param String $data if input is a string */ function parser( $file = null, $data = null ) { $this->items = array( 'title' => array(), 'year' => array(), 'code' => array(), 'description' => array(), 'outline' => array(), 'type' => array(), 'link' => array(), 'abstract' => array(), 'location' => array(), 'url' => array(), ); if( $file ) $this->filename = $file; elseif( $data ) $this->inputdata = $data; $this->parse(); $this->types = array_unique($this->items['type']); $this->types = array_values($this->types); //print_r($this->sortedItems['type']); global $sortby; $this->sortedItems = $this->items; return $this->printPublications(); } /** * parse() * * Main method that parses the data. */ function parse() { $value = array(); $var = array(); $this->count = -1; $lineindex = 0; $fieldcount = -1; if( $this->filename ) $lines = file($this->filename); else $lines = preg_split( '/\n/', $this->inputdata ); if (!$lines) return; foreach($lines as $line) { $lineindex++; if ($this->count > -1) { $this->items['lineend'][$this->count] = $lineindex; } $line = trim($line); $raw_line = $line + '\n'; $line=str_replace("'","`",$line); $seg=str_replace("\"","`",$line); $ps=strpos($seg,'='); $segtest=strtolower($seg); // some funny comment string if (strpos($segtest,'@string')!==false) continue; // pybliographer comments if (strpos($segtest,'@comment')!==false) continue; // normal TeX style comment if (strpos($seg,'%%')!==false) continue; /* ok when there is nothing to see, skip it! */ if (!strlen($seg)) continue; if ("@" == $seg[0]) { $this->count++; $this->items['raw'][$this->count] = $line . "\r\n"; $ps=strpos($seg,'@'); $pe=strpos($seg,'{'); $this->types[$this->count]=trim(substr($seg, 1,$pe-1)); $fieldcount=-1; $this->items['linebegin'][$this->count] = $lineindex; } // #of item increase elseif ($ps!==false ) { // one field begins $this->items['raw'][$this->count] .= $line . "\r\n"; $ps=strpos($seg,'='); $fieldcount++; $var[$fieldcount]=strtolower(trim(substr($seg,0,$ps))); if ($var[$fieldcount]=='pages') { $ps=strpos($seg,'='); $pm=strpos($seg,'--'); $pe=strpos($seg,'},'); $pagefrom[$this->count] = substr($seg,$ps,$pm-$ps); $pageto[$this->count]=substr($seg,$pm,$pe-$pm); $bp=str_replace('=','',$pagefrom[$this->count]); $bp=str_replace('{','',$bp);$bp=str_replace('}','',$bp);$bp=trim(str_replace('-','',$bp)); $ep=str_replace('=','',$pageto[$this->count]); $bp=str_replace('{','',$bp);$bp=str_replace('}','',$bp);;$ep=trim(str_replace('-','',$ep)); } $pe=strpos($seg,'},'); if ($pe===false) $value[$fieldcount]=strstr($seg,'='); else $value[$fieldcount]=substr($seg,$ps,$pe); } else { if ($this->count > -1 ) { $this->items['raw'][$this->count] .= $line . "\r\n"; $pe=strpos($seg,'},'); } if ($fieldcount > -1) { if ($pe===false) $value[$fieldcount].=' '.strstr($seg,' '); else $value[$fieldcount] .=' '.substr($seg,$ps,$pe); } } if ($fieldcount > -1) { $v = $value[$fieldcount]; $v=str_replace('=','',$v); $v=str_replace('{','',$v); $v=str_replace('}','',$v); if ($var[$fieldcount]=='author' || $var[$fieldcount]=='location' ) $v=$this->str_last_replace(',',' ',$v); else $v=$this->str_last_replace(',',' ',$v); $v=str_replace('\'',' ',$v); $v=str_replace('\"',' ',$v); // test! $v=str_replace('`',' \'',$v); $v=trim($v); $this->items["$var[$fieldcount]"][$this->count]="$v"; } } } function printPublications() { global $sortby; global $sortbyTitle; //Print filters echo '
'.$this->sortedItems['abstract'][$element].'