Changeset 596469
- Timestamp:
- 09/09/2012 02:50:12 AM (14 years ago)
- Location:
- wp-publications/trunk
- Files:
-
- 2 added
- 2 edited
-
bibtexbrowser.php (added)
-
plugin.php (modified) (10 diffs)
-
readme.txt (modified) (1 diff)
-
sample.bib (added)
Legend:
- Unmodified
- Added
- Removed
-
wp-publications/trunk/plugin.php
r495395 r596469 2 2 /* 3 3 Plugin Name: wp-publications 4 Description: Integratesbibtexbrowser into wordpress4 Description: Creates publication lists from Bibtex files by integrating bibtexbrowser into wordpress 5 5 Plugin URI: http://www.monperrus.net/martin/wp-publications 6 6 Author: Martin Monperrus … … 39 39 add_shortcode( __WP_PLUGIN__, array( &$this, 'wp_publications_shortcode_handler') ); 40 40 add_action('the_post', array( &$this, 'update_bibtex' )); 41 register_activation_hook( __FILE__, array( &$this, 'activation_action')); 41 42 } 42 43 … … 47 48 define('BIBTEXBROWSER_URL_BUILDER','wp_bibtexbrowser_url_builder'); 48 49 50 is_readable(dirname(__FILE__).'/'.'bibtexbrowser.php') or die('bibtexbrowser.php is not readable'); 51 49 52 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 :)'); 50 53 require(dirname(__FILE__).'/'.'bibtexbrowser.php'); … … 65 68 function update_bibtex(&$post) { 66 69 67 68 70 if ($post->post_type == __WP_PLUGIN__) { 69 71 … … 73 75 // updating the post 74 76 // 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)); 78 78 // slugs are case-insensitives 79 79 $bibdb = $database->bibdb; … … 123 123 } 124 124 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' => "[wp-publications bib=sample.bib all=1] 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 125 141 /** adds a new publication entry if $ID=NULL based on the BibtexEntry $entry 126 142 * from the bibtex file $bibtex_file … … 148 164 /** returns a valid path of the $bibtex */ 149 165 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) { 150 176 // in the plugin directory wp-content/plugins/wp-publications 151 177 $file = dirname(__FILE__).'/'.$bibtex; … … 153 179 return $file; 154 180 } 155 181 156 182 // in the wordpress directory 157 183 $file = dirname($_SERVER['SCRIPT_FILENAME']).'/'.$bibtex; 158 184 if (is_file($file)) { 159 return $file; 160 } 185 return $file; 186 } 187 161 188 return $bibtex; 162 189 } 190 163 191 164 192 /** returns the string associated with a publication list shortcode … … 166 194 */ 167 195 function wp_publications_shortcode_handler( $atts, $content=null, $code="" ) { 168 169 196 // first we simulate a standard call to bibtexbrowser 170 $_GET = array_merge($ atts, $_GET);197 $_GET = array_merge($_GET, $atts); 171 198 172 199 $_GET['bib'] = $this->resolve($_GET['bib']); 173 174 175 setDB(); 176 177 $database = $_GET[Q_DB]; 200 $database = zetDB($this->resolve($_GET['bib'])); 178 201 179 202 foreach($database->getEntries() as $entry) { … … 193 216 } 194 217 } 195 196 218 ob_start(); 197 219 new Dispatcher(); -
wp-publications/trunk/readme.txt
r495395 r596469 20 20 Notes: 21 21 22 1. The bibtex file is expected in directory at the root of the wordpress installation or in wp-content/plugins/wp-publications 22 23 1. The short code options exactly correspond to [bibtexbrowser](http://www.monperrus.net/martin/bibtexbrowser) queries. 23 24 1. The mybibliography.bib should be encoded in UTF-8 if diacritics are not LaTeX-escaped 25 1. Please use complete refresh when uploading a new bibtex file (generally Ctrl-F5 or Shift-F5) 24 26 25 27 == Installation == 26 28 27 29 1. 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 PHP29 30 1. Create a post or a page with a short code such as [wp-publications bib="publications.bib" all=true] 31 32 == Credits == 33 34 Sjoerd OP 'T LAND 35
Note: See TracChangeset
for help on using the changeset viewer.