/** * Get the bibtex data from an URI */ function &getData($biburis, $timeout = 3600) { // Loop over the different given URIs $array = explode(",", $biburis); $result = array(); foreach($array as $biburi) { // (1) Get the context if (!$this->cache[$biburi]) { if (strpos($biburi, "http://") === 0) $bibFile = $this->getCached($biburi, $timeout); else { $bibFile = $this->getDataFile("bib/$biburi"); } if (!$bibFile || !file_exists($bibFile[0])) continue; $bibFile = $bibFile[0]; // (2) Parse the BibTeX if (file_exists($bibFile)) { $data = file_get_contents($bibFile); if (!empty($data)) { switch($this->options["bibtex_parser"]) { case "papercite": $parser = new BibTexEntries(); if (!$parser->parse($data)) { $this->cache[$biburi] = false; continue; } else { $this->cache[$biburi] = &$parser->data; } break; default: $this->_parser = new Structures_BibTex(array('removeCurlyBraces' => true, 'extractAuthors' => true)); $this->_parser->loadString($data); $stat = $this->_parser->parse(); if ( !$stat ) return $this->cache[$biburi] = false; $this->cache[$biburi] = &$this->_parser->data; } // --- Add custom fields foreach($this->cache[$biburi] as &$entry) { $this->checkFiles($entry, array(array("pdf", "pdf"))); } } } } // Add to the list if ($this->cache[$biburi]) $result[] = $this->cache[$biburi]; } if (sizeof($result) == 0) return false; return $result; }
/** * Get the bibtex data from an URI */ function &getData($biburis, $timeout = 3600) { global $wpdb, $papercite_table_name; // Loop over the different given URIs $array = explode(",", $biburis); $result = array(); foreach ($array as $biburi) { // (1) Get the context $data = FALSE; if (!$this->cache[$biburi]) { if (strpos($biburi, "custom://") === 0) { $data = get_post_custom_values("papercite_" . substr($biburi, 9)); if ($data) { $data = $data[0]; } } else { if (strpos($biburi, "http://") === 0) { $bibFile = $this->getCached($biburi, $timeout); } else { $bibFile = $this->getDataFile("bib/{$biburi}"); } } if ($data === FALSE && !($bibFile && file_exists($bibFile[0]))) { continue; } // (2) Parse the BibTeX if ($data || file_exists($bibFile[0])) { if (!$data) { $fileTS = filemtime($bibFile[0]); // Check if we don't have the data in cache if ($this->useDb()) { // We use entrytype as a timestamp $dbTS = intval($wpdb->get_var($wpdb->prepare("SELECT entrytype FROM {$papercite_table_name} WHERE url=%s and bibtexid=''", "ts://" . $biburi))); if ($dbTS >= $fileTS) { $result[$biburi] = $this->cache[$biburi] = "__DB__"; continue; } } $data = file_get_contents($bibFile[0]); } if (!empty($data)) { switch ($this->options["bibtex_parser"]) { case "pear": // Pear parser $this->_parser = new Structures_BibTex(array('removeCurlyBraces' => true, 'extractAuthors' => true)); $this->_parser->loadString($data); $stat = $this->_parser->parse(); if (!$stat) { return $this->cache[$biburi] = false; } $this->cache[$biburi] =& $this->_parser->data; break; default: // OSBiB parser $parser = new BibTexEntries(); if (!$parser->parse($data)) { $this->cache[$biburi] = false; continue; } else { $this->cache[$biburi] =& $parser->data; } break; } // --- Add custom fields foreach ($this->cache[$biburi] as &$entry) { $this->checkFiles($entry, array(array("pdf", "pdf"))); } // Save to DB if (!$stringedFile && $this->useDb()) { // First delete everything $wpdb->query($wpdb->prepare("DELETE FROM {$papercite_table_name} WHERE url=%s", $biburi)); $code = true; foreach ($this->cache[$biburi] as &$value) { $statement = $wpdb->prepare("INSERT INTO {$papercite_table_name}(url, bibtexid, entrytype, year, data) VALUES (%s,%s,%s,%s,%s)", $biburi, $value["cite"], $value["entrytype"], $value["year"], maybe_serialize($value)); $code = $wpdb->query($statement); if ($code === FALSE) { break; } } if ($code !== FALSE) { $statement = $wpdb->prepare("INSERT INTO {$papercite_table_name}(url, bibtexid, entrytype) VALUES(%s,%s,%s)", "ts://" . $biburi, "", $fileTS); $code = $wpdb->query($statement); } } } } } // Add to the list if ($this->cache[$biburi]) { $result[$biburi] = $this->cache[$biburi]; } } if (sizeof($result) == 0) { return false; } return $result; }