/** * Show a set of entries * @param refs An array of references * @param options The options to pass to bib2tpl * @param getKeys Keep track of the keys for a final substitution */ function showEntries(&$refs, &$options, $getKeys, $mainTpl, $formatTpl, $mode) { // Get the template files $mainFile = papercite::getDataFile("/tpl/{$mainTpl}.tpl"); $formatFile = papercite::getDataFile("/format/{$formatTpl}.tpl"); // Fallback to defaults if needed if (!$mainFile) { $mainFile = papercite::getDataFile("/tpl/" . papercite::$default_options["{$mode}_template"] . ".tpl"); } if (!$formatFile) { $formatFile = papercite::getDataFile("/format/" . papercite::$default_options["format"] . ".tpl"); } $main = file_get_contents($mainFile[0]); $format = file_get_contents($formatFile[0]); $bibtexEntryTemplate = new BibtexEntryFormat($format); // Gives a distinct ID to each publication (i.e. to display the corresponding bibtex) // in the reference list foreach ($refs as &$entry) { $entry["papercite_id"] = $this->counter++; } // Convert (also set the citation key) $bib2tpl = new BibtexConverter($options, $main, $bibtexEntryTemplate); $bib2tpl->setGlobal("WP_PLUGIN_URL", WP_PLUGIN_URL); $r = $bib2tpl->display($refs); // If we need to get the citation key back if ($getKeys) { foreach ($refs as &$group) { foreach ($group as &$ref) { $this->keys[] = $ref["pKey"]; $this->keyValues[] = $ref["key"]; } } } // Process text in order to avoid some unexpected WordPress formatting return str_replace("\t", ' ', trim($r["text"])); }
/** * Show a set of entries * @param refs An array of references * @param options The options to pass to bib2tpl * @param getKeys Keep track of the keys for a final substitution */ function showEntries(&$refs, &$options, $getKeys, $mainTpl, $formatTpl, $mode) { $mainFile = papercite::getDataFile("/tpl/$mainTpl.tpl"); $formatFile = papercite::getDataFile("/format/$formatTpl.tpl"); // Fallback to defaults if (!$mainFile) $mainFile = papercite::getDataFile("/tpl/" .papercite::$default_options["${mode}_template"] .".tpl"); if (!$formatFile) $formatFile = papercite::getDataFile("/format/" .papercite::$default_options["format"] . ".tpl"); $main = file_get_contents($mainFile[0]); $format = file_get_contents($formatFile[0]); $bibtexEntryTemplate = new BibtexEntryFormat($format); foreach($refs as &$entry) { $entry["papercite_id"] = $this->counter++; } // Convert $bib2tpl = new BibtexConverter($options, $main, $bibtexEntryTemplate); $bib2tpl->setGlobal("WP_PLUGIN_URL", WP_PLUGIN_URL); $r = $bib2tpl->display($refs); if ($getKeys) { foreach($refs as &$group) foreach($group as &$ref) { $this->keys[] = $ref["pKey"]; $this->keyValues[] = $ref["key"]; } } // Process text in order to avoid some unexpected WordPress formatting return str_replace("\t", ' ', trim($r["text"])); }
/** * Returns the content of a file (disk or post data) * * @see papercite::getDataFile */ static function getContent($relfile, $ext, $folder, $mimetype, $options, $use_files = false) { // Handles custom:// $custom_prefix = "custom://"; if (papercite::startsWith($relfile, $custom_prefix)) { $key = substr($relfile, strlen($custom_prefix)); $data = get_post_custom_values("papercite_{$key}"); if ($data) { return $data[0]; } } // Normal behavior $data = papercite::getDataFile($relfile, $ext, $folder, $mimetype, $options, $use_files); if ($data) { return file_get_contents($data[0]); } return false; }