Example #1
0
 /**
  * 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, $goptions, $options, $getKeys, $mainTpl, $formatTpl, $mode)
 {
     // Get the template files
     $main = $this->getContent("{$mainTpl}", "tpl", "tpl", "MIMETYPE", $goptions, true);
     $format = $this->getContent("{$formatTpl}", "tpl", "format", "MIMETYPE", $goptions, true);
     // Fallback to defaults if needed
     if (!$main) {
         $main = $this->getContent(papercite::$default_options["{$mode}_template"], "tpl", "tpl", "MIMETYPE", $goptions, true);
     }
     if (!$format) {
         $format = $this->getContent(papercite::$default_options["format"], "tpl", "format", "MIMETYPE", $goptions, true);
     }
     $bibtexEntryTemplate = new PaperciteBibtexEntryFormat($format);
     // Gives a distinct ID to each publication (i.e. to display the corresponding bibtex)
     // in the reference list
     if ($refs) {
         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);
     $bib2tpl->setGlobal("PAPERCITE_DATA_URL", Papercite::getCustomDataDirectory());
     // Now, check for attached files
     if (!$refs) {
         // No references: return nothing
         return "";
     }
     foreach ($refs as &$ref) {
         // --- Add custom fields
         $this->checkFiles($ref, $goptions);
     }
     // This will set the key of each reference
     $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"];
                 if ($goptions["show_links"]) {
                     $this->keyValues[] = "<a class=\"papercite_bibcite\" href=\"#paperkey_{$ref["papercite_id"]}\">{$ref["key"]}</a>";
                 } else {
                     $this->keyValues[] = $ref["key"];
                 }
             }
         }
     }
     // Process text in order to avoid some unexpected WordPress formatting
     return str_replace("\t", '  ', trim($r["text"]));
 }