Пример #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, &$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"]));
 }
Пример #2
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, &$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"]));
  }
Пример #3
0
    /**
     * This does two things:
     * -dynamically creates html form based on parameters (author and menutype)
     * -rebuilds command which is then sent as the bibtex command
     *
     * @param unknown $options The arguments
     * @return multitype:string The output of the bibfilter shortcode
     */
    function bibfilter($options)
    {
        // create form with custom types and authors
        global $post;
        $selected_author = false;
        $selected_type = false;
        $original_authors = Papercite::array_get($options, "author", "");
        $original_allow = Papercite::array_get($options, "allow", "");
        if (isset($_POST) && papercite::array_get($_POST, "papercite_post_id", 0) == $post->ID) {
            if (isset($_POST["papercite_author"]) && !empty($_POST["papercite_author"])) {
                $selected_author = $options["author"] = $_POST["papercite_author"];
            }
            if (isset($_POST["papercite_allow"]) && !empty($_POST["papercite_allow"])) {
                $selected_type = $options["allow"] = $_POST["papercite_allow"];
            }
        }
        $result = $this->getEntries($options);
        ob_start();
        ?>
        <form method="post" accept-charset="UTF-8">
            <input type="hidden" name="papercite_post_id" value="<?php 
        echo $post->ID;
        ?>
">
          <table style="border-top: solid 1px #eee; border-bottom: solid 1px #eee; width: 100%">
            <tr>
              <td>Authors:</td>
              <td><select name="papercite_author" id="papercite_author">
                  <option value="">ALL</option>
                            <?php 
        $authors = preg_split("#\\s*\\|\\s*#", $original_authors);
        if (Papercite::array_get($options, "sortauthors", 0)) {
            sort($authors);
        }
        foreach ($authors as $author) {
            print "<option value=\"" . htmlentities($author, ENT_QUOTES, "UTF-8") . "\"";
            if ($selected_author == $author) {
                print " selected=\"selected\"";
            }
            print ">{$author}</option>";
        }
        ?>
              </select></td>
                    
              <td>Type:</td>
              <td><select name="papercite_allow" id="papercite_type">
                  <option value="">ALL</option>
                            <?php 
        $types = preg_split("#\\s*,\\s*#", $original_allow);
        foreach ($types as $type) {
            print "<option value=\"" . htmlentities($type, ENT_QUOTES, "UTF-8") . "\"";
            if ($selected_type == $type) {
                print " selected=\"selected\"";
            }
            print ">" . papercite_bibtype2string($type) . "</option>";
        }
        ?>
              </select></td>
              <td><input type="submit" value="Filter" /></td>
            </tr>
          </table>
        </form>
        
        <?php 
        return ob_get_clean() . $this->showEntries($result, $options, $this->getBib2TplOptions($options), false, $options["bibtex_template"], $options["format"], "bibtex");
    }