monperrus / bibtexbrowser

Beautiful publication lists with bibtex and PHP (standalone or in Wordpress)
http://www.monperrus.net/martin/bibtexbrowser/
84 stars 54 forks source link

Hide some bibtex fields from showing up in the bibtex code #41

Closed i2000s closed 9 years ago

i2000s commented 9 years ago

When the bibtex code was extracted and shown on the webpage, it would be great if some fields can be hidden. For example, owner, timestamp and other customized fields should not be seen in public.

I tried to modify the totoEntryUnformatted() to implement this function, but seems nothing gets hidden. See the code I modified below.

function toEntryUnformatted() {
    $result = "";
    $result .= '<pre class="purebibtex">'; // pre is nice when it is embedded with no CSS available

    // Duplicate the input bibtex object and remove the hidden properties.
    $tempobj = Clone $this; // Note: the tempobj lines are added by Qi for removing hidden fields from showing up in the html bibtex code.
    $hidden_bibtex_entries = array('owner' => 'owner', 'timestamp' => 'timestamp', 'grant' => 'grant','grouptag' => 'grouptag');
    foreach ($hidden_bibtex_entries as $field => $hiddenentry) {
        if ($tempobj->hasField($field)){
          unset($tempobj -> $field);
          // $tempobj -> $field = null;
          // print is_object($tempobj)? 't. ' : 'f. ';
          // print($field.'='.$tempobj->getField($field));
        }
    }

    // Parse the bibtex object to html text.
    $entry = htmlspecialchars($tempobj->getFullText());

    // Fields that should be hyperlinks. Has been reordered to fix the url bug, and arxiv links are added in.
    $hyperlinks = array('doi' => 'http://dx.doi.org/%O', 'arxiv' => 'http://arxiv.org/abs/%O', 'url' => '%O', 'file' => '%O', 'pdf' => '%O', 'gsid' => 'http://scholar.google.com/scholar?cites=%O');

    foreach ($hyperlinks as $field => $url) {
      if ($tempobj->hasField($field)) {
        $href = str_replace('%O', $tempobj->getField($field), $url);
        // this is not a parsing but a simple replacement
        $entry = str_replace($tempobj->getField($field), '<a'.(BIBTEXBROWSER_LINKS_IN_NEW_WINDOW?' target="_blank" ':'').' href="'.$href.'">'.$tempobj->getField($field).'</a>', $entry);
      }
    }

    $result .=  $entry;
    $result .=  '</pre>';
    unset($tempobj);
    return $result;
   }

Hope you can shadow a light on how to implement it. Thanks.

monperrus commented 9 years ago

When the bibtex code was extracted and shown on the webpage, it would be great if some fields can be hidden.

That would be a nice feature, I'll see how to implement it when I'll have time.

monperrus commented 9 years ago

done in 60bdd459eee548ca9731d3bd365afe54b70402ec. Does it work for you?

i2000s commented 9 years ago

It works here! Thank you very much!