2)&&(!strpos($aa[$j],".")))
$aa[$j]=substr($aa[$j],0,1).".";
}
$authArr[$i]=implode(" ",$aa);
//end abbreviate fornames
if((!strpos($authArr[$i],","))&&(strpos($authArr[$i]," ")))
$authArr[$i]=strrchr($authArr[$i]," ")."$sepName ".substr($authArr[$i],0,strrpos($authArr[$i]," "));
$i++;
// }else $i=9999;
}
$tempdat=implode(" and ",$authArr);
//end this is the surname / given name exchange
$temppos=0;
$lastpos=$temppos;
while($lastpos=strpos($tempdat," and ",$temppos)){
$temppos=$lastpos+1;
}
if($temppos>0)
$tempdat[$temppos]="#";
$tempdat=str_replace(" and ",", ",$tempdat);
$tempdat=str_replace(" #nd "," and ",$tempdat);
return $tempdat.$suffix;
}
function searchIt($keywordphrase){
return " (amazon: .co.uk .com .de)";
}
//this will take bibtex data (one entry a time) and return a fairly standard citation representation in html
function bibtex2html($texEntry,$internalNumber,$addlinks=true){
$ret=extractBib("text",$texEntry);
if(trim($ret)==""){
//begin there is no predefined text to show, we create some
$author=extractBib("author",$texEntry);
if($author==""){
$author=extractBib("editor",$texEntry);
$author=$author.", ed.";
}
$shortAuth=shortenAuthors($author);
$ret=$ret.$shortAuth;
$year=extractBib("year",$texEntry);
if($ret[strlen($ret)-1]!=".")
$ret=$ret.".";
$ret=$ret." ";
$title=extractBib("title",$texEntry);
if((trim($author)=="")||(trim($title)==""))
return "";
$texType=strtolower(extractBibType($texEntry));
if(($texType!="article")&&($texType!="inproceedings"))
$ret=$ret."$title";
else
$ret=$ret.$title;
if($title[strlen($title)-1]!=".")
$ret=$ret.".";
if($texType=="phdthesis"){
$ret=$ret." Ph.D. Thesis";
$school=extractBib("school",$texEntry);
if(trim($school)!="")
$ret=$ret.", ".$school;
$addrs=extractBib("address",$texEntry);
if(trim($addrs)!="")
$ret=$ret.", ".$addrs;
if(trim(strtolower($year))!="")
$ret=$ret.", ".$year;
$ret=$ret.".";
}
if($texType=="article"){
$journ=extractBib("journal",$texEntry);
if($journ=="") //might be a book chapter...
$journ=extractBib("book",$texEntry);
if(trim(strtolower($journ))!=""){
$ret=$ret." In ".$journ."";
$vol=extractBib("volume",$texEntry);
if(trim(strtolower($vol))!="")
$ret=$ret.", ".$vol;
$numb=extractBib("number",$texEntry);
if(trim(strtolower($numb))!="")
$ret=$ret." (".str_replace("--","-",$numb).")";
$pages=extractBib("pages",$texEntry);
if(trim(strtolower($pages))!="")
$ret=$ret.": ".str_replace("--","-",$pages);
if(trim(strtolower($year))!="")
$ret=$ret.", ".$year;
$ret=$ret.".";
}
}
if($texType=="inproceedings"){
$booktitle=extractBib("booktitle",$texEntry);
if(trim(strtolower($booktitle))!=""){
$ret=$ret." In ".$booktitle."";
$pages=extractBib("pages",$texEntry);
if(trim(strtolower($pages))!="")
$ret=$ret.", pages ".str_replace("--","-",$pages);
$publisher=extractBib("publisher",$texEntry);
if(trim(strtolower($publisher))!="")
$ret=$ret.", ".$publisher;
if(trim(strtolower($year))!="")
$ret=$ret.", ".$year;
$ret=$ret.".";
}
}
if($texType=="book"){
$publisher=extractBib("publisher",$texEntry);
if(trim(strtolower($publisher))!="")
$ret=$ret." ".$publisher;
$pubaddress=extractBib("address",$texEntry);
if(trim(strtolower($pubaddress))!="")
$ret=$ret.", ".$pubaddress;
if(trim(strtolower($year))!="")
$ret=$ret.", ".$year;
$ret=$ret.".";
}
}//end there is no predefined text to show, we create some
if($addlinks){
global $createJumpMarks;
global $addBreaksBeforeLinks;
if($createJumpMarks){//KNSQbioClockGRNs
$bibName=extractBibName($texEntry);
$ret="".$ret;
}
$tempdat=extractBib("url",$texEntry);
if($addBreaksBeforeLinks)
$ret=$ret."
";
if($tempdat!="")
$ret=$ret." (link) ";
$tempdat=extractBib("EE",$texEntry);
if($tempdat!="")
$ret=$ret." (file) ";
//link to show complete bibtex entry - specific to this script
global $SCRNAME;
global $sep;
global $args;
$ret=$ret." (bibtex)";
if($texType=="book"){
$authSplit=split(",",$shortAuth);
$authorOne=trim($authSplit[0]);
$keywordphrase=str_replace(" ","%20",$title)."%20$authorOne";
$ret=$ret.searchIt($keywordphrase);
}
}
return "".$ret."
";
}
function sel($i,$j){
if($i==$j)
return "selected";
return "";
}
//we are the upper part of frame
if($args[0]=="head"){
echo "";
echo "\r\n";
echo "\r\n";
echo "\r\n";
echo "\r\n";
die;
}
//begin read xml data file
function trustedFile($file)
{
// only trust local files owned by ourselves
if (!eregi("^([a-z]+)://", $file)
&& fileowner($file) == getmyuid()) {
return true;
}
return false;
}
function startElement($parser, $name, $attribs) //opening, i.e.
{
global $titleData;
global $authorData;
global $acquiredData;
global $ratingData;
global $commentData;
global $topicData;
global $languageData;
global $typeData;
global $bibtexData;
if($name=="TEXT"){
$topicData="";
$titleData="";
$authorData="";
$acquiredData="";
$ratingData="";
$commentData="";
$languageData="";
$typeData="";
$bibtexData="";
}
else{
global $current;
$$current=trim($$current);
$current=strtolower($name)."Data";
}
//no attributes used, ignore $attribs...
}
function endElement($parser, $name) //closing, i.e.
{
if($name=="TEXT"){
global $titleData;
global $authorData;
global $acquiredData;
$acquiredData=trim($acquiredData);
global $ratingData;
global $commentData;
global $bibtexData;
$bibtexData=trim($bibtexData);
global $textsArray;
global $topicData;
global $languageData;
global $typeData;
global $args;
global $bibTexCnt;
if(($args[0]=="edit")&&($args[2]=="d")&&(intval($args[1])==sizeof($textsArray))){
//delete entry by ignoring it, but only one entry!
$args[1]="-1";
}
else{
if($bibtexData!="")
$bibTexCnt++;
$textsArray[]=array( //create text entry in our array
'Language' => $languageData,
'Type' => $typeData,
'Title' => $titleData,
'Author' => $authorData,
'Acquired' => $acquiredData,
'Topic' => $topicData,
'Rating' => $ratingData,
'Comment' => $commentData,
'BibTex' => $bibtexData);
}
}
}
function characterData($parser, $data) //plain text like this
{
global $current;
global $titleData;
global $authorData;
global $acquiredData;
global $ratingData;
global $commentData;
global $bibtexData;
global $topicData;
global $languageData;
global $typeData;
$$current=$$current.$data;
}
function PIHandler($parser, $target, $data)
{
switch (strtolower($target)) {
case "php":
global $parser_file;
// If the parsed document is "trusted", we say it is safe
// to execute PHP code inside it. If not, display the code
// instead.
if (trustedFile($parser_file[$parser])) {
eval($data);
} else {
printf("Untrusted PHP code: %s",
htmlspecialchars($data));
}
break;
}
}
function defaultHandler($parser, $data)
{
return;
}
function externalEntityRefHandler($parser, $openEntityNames, $base, $systemId,
$publicId) {
if ($systemId) {
if (!list($parser, $fp) = new_xml_parser($systemId)) {
printf("Could not open entity %s at %s\r\n", $openEntityNames,
$systemId);
return false;
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($parser, $data, feof($fp))) {
printf("XML error: %s at line %d while parsing entity %s\r\n",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser), $openEntityNames);
xml_parser_free($parser);
return false;
}
}
xml_parser_free($parser);
return true;
}
return false;
}
function new_xml_parser($file)
{
global $parser_file;
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_set_processing_instruction_handler($xml_parser, "PIHandler");
xml_set_default_handler($xml_parser, "defaultHandler");
xml_set_external_entity_ref_handler($xml_parser, "externalEntityRefHandler");
if (!($fp = @fopen($file, "r"))) {
return false;
}
if (!is_array($parser_file)) {
settype($parser_file, "array");
}
$parser_file[$xml_parser] = $file;
return array($xml_parser, $fp);
}
if (!(list($xml_parser, $fp) = new_xml_parser($filename))) {
echo "";
echo "Could not open XML input.
Maybe the database file ".$filename." is missing?
It should be placed in the same directory as the script and contain at least:
".str_replace(">",">",str_replace("<","<",$libStart."