Plugin Directory

Changeset 596469


Ignore:
Timestamp:
09/09/2012 02:50:12 AM (14 years ago)
Author:
monperrus
Message:

fixed bug, added bibtexbrowser.php and improved documentation

Location:
wp-publications/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • wp-publications/trunk/plugin.php

    r495395 r596469  
    22/*
    33Plugin Name: wp-publications
    4 Description: Integrates bibtexbrowser into wordpress
     4Description: Creates publication lists from Bibtex files by integrating bibtexbrowser into wordpress
    55Plugin URI: http://www.monperrus.net/martin/wp-publications
    66Author: Martin Monperrus
     
    3939    add_shortcode( __WP_PLUGIN__, array( &$this, 'wp_publications_shortcode_handler') );       
    4040    add_action('the_post', array( &$this, 'update_bibtex' ));
     41    register_activation_hook( __FILE__,  array( &$this, 'activation_action'));
    4142  }
    4243
     
    4748    define('BIBTEXBROWSER_URL_BUILDER','wp_bibtexbrowser_url_builder');
    4849   
     50    is_readable(dirname(__FILE__).'/'.'bibtexbrowser.php') or die('bibtexbrowser.php is not readable');
     51
    4952    file_exists(dirname(__FILE__).'/'.'bibtexbrowser.php') or die('the plugin wp-publications requires bibtexbrowser.<br/> Please download it at http://www.monperrus.net/martin/bibtexbrowser.php.txt and copy it into wp-content/plugins/wp-publications. Thanks :)');
    5053    require(dirname(__FILE__).'/'.'bibtexbrowser.php');
     
    6568  function update_bibtex(&$post) {
    6669 
    67    
    6870    if ($post->post_type == __WP_PLUGIN__) {
    6971   
     
    7375      // updating the post
    7476      // we need one refresh to get this into account
    75       $_GET['bib'] = $this->resolve($bibtex);
    76       setDB();
    77       $database = $_GET[Q_DB];
     77      $database = zetDB($this->resolve($bibtex));
    7878      // slugs are case-insensitives
    7979      $bibdb = $database->bibdb;
     
    123123  }
    124124
     125  /** adds a test post for wp-publications and create a sample bibtex file*/
     126  function activation_action() { 
     127      // add a sample.bib
     128      //@file_put_contents(plugin_dir_path(__FILE__).'/sample.bib',
     129      //   "@article{doe2000,title={An article},author={Jane Doe},journal={The Wordpress Journal},year=2000}\n".
     130      //   "@book{doo2001,title={An bok},author={Jane Doe},year=2001}");
     131     
     132      //add_fake_post
     133      $post = array(
     134        'post_content' => "&#91;wp-publications bib=sample.bib all=1&#93; gives:\n[wp-publications bib=sample.bib all=1]", //The full text of the post.
     135        'post_status' => 'publish',
     136        'post_title' => 'wp-publications example', //The title of your post.
     137    ); 
     138    $post_id = wp_insert_post( $post );   
     139  }
     140 
    125141  /** adds a new publication entry if $ID=NULL based on the BibtexEntry $entry
    126142   * from the bibtex file $bibtex_file
     
    148164  /** returns a valid path of the $bibtex */
    149165  function resolve($bibtex) {
     166    $resolvedbibtexfiles = array();
     167   
     168    foreach (explode(';',$bibtex) as $bibtexfile) {
     169      array_push($resolvedbibtexfiles,$this->resolveOneBibTexFile($bibtexfile));
     170    }
     171   
     172    return implode(';',$resolvedbibtexfiles);
     173  }
     174 
     175  function resolveOneBibTexFile($bibtex) {
    150176    // in the plugin directory wp-content/plugins/wp-publications
    151177    $file = dirname(__FILE__).'/'.$bibtex;
     
    153179      return $file;     
    154180    }
    155    
     181
    156182    // in the wordpress directory
    157183    $file = dirname($_SERVER['SCRIPT_FILENAME']).'/'.$bibtex;
    158184    if (is_file($file)) {
    159       return $file;     
    160     }
     185        return $file;     
     186    }
     187
    161188    return $bibtex;
    162189  }
     190
    163191
    164192  /** returns the string associated with a publication list shortcode
     
    166194   */
    167195  function wp_publications_shortcode_handler( $atts, $content=null, $code="" ) {
    168    
    169196    // first we simulate a standard call to bibtexbrowser
    170     $_GET = array_merge($atts, $_GET);
     197    $_GET = array_merge($_GET, $atts);
    171198   
    172199    $_GET['bib'] = $this->resolve($_GET['bib']);
    173 
    174        
    175     setDB();         
    176    
    177     $database = $_GET[Q_DB];
     200    $database = zetDB($this->resolve($_GET['bib']));
    178201   
    179202    foreach($database->getEntries() as $entry) {
     
    193216      }
    194217    }
    195    
    196218    ob_start();
    197219    new Dispatcher();
  • wp-publications/trunk/readme.txt

    r495395 r596469  
    2020Notes:
    2121
     221. The bibtex file is expected in directory at the root of the wordpress installation or in wp-content/plugins/wp-publications
    22231. The short code options exactly correspond to [bibtexbrowser](http://www.monperrus.net/martin/bibtexbrowser) queries.
    23241. The mybibliography.bib should be encoded in UTF-8 if diacritics are not LaTeX-escaped
     251. Please use complete refresh when uploading a new bibtex file (generally Ctrl-F5 or Shift-F5)
    2426
    2527== Installation ==
    2628
    27291. Activate the plugin through the 'Plugins' menu in WordPress
    28 1. Download bibtexbrowser at http://www.monperrus.net/martin/bibtexbrowser.php.txt, copy it into wp-content/plugins/wp-publications/bibtexbrowser.php (without .txt) and chmod it to be readable by PHP
    29301. Create a post or a page with a short code such as  [wp-publications bib="publications.bib" all=true]
     31
     32== Credits ==
     33
     34Sjoerd OP 'T LAND
     35
Note: See TracChangeset for help on using the changeset viewer.