andreozzi gmail com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ function bib2htmlProcess($data, $filterType, $filter) { $OSBiBPath = dirname(__FILE__) . '/OSBiB/'; include_once($OSBiBPath.'format/bibtexParse/PARSEENTRIES.php'); include_once($OSBiBPath.'format/BIBFORMAT.php'); include_once( dirname(__FILE__) . '/class.TemplatePower.inc.php'); // parse the content of bib string and generate associative array with valid entries $parse = NEW PARSEENTRIES(); $parse->expandMacro = TRUE; $parse->fieldExtract = TRUE; $parse->removeDelimit = TRUE; $parse->loadBibtexString($data); $parse->extractEntries(); list($preamble, $strings, $entries) = $parse->returnArrays(); /* Format the entries array for html output */ $bibformat = NEW BIBFORMAT($OSBiBPath, TRUE); // TRUE implies that the input data is in bibtex format $bibformat->cleanEntry=TRUE; // convert BibTeX (and LaTeX) special characters to UTF-8 list($info, $citation, $styleCommon, $styleTypes) = $bibformat->loadStyle($OSBiBPath."styles/bibliography/", "IEEE"); $bibformat->getStyle($styleCommon, $styleTypes); $i=0; // $citations = '
'; $tpl = new TemplatePower( dirname(__FILE__) . '/bibentry-html.tpl'); $tpl->prepare(); foreach ($entries as $entry) { // Get the resource type ('book', 'article', 'inbook' etc.) $resourceType = $entry['bibtexEntryType']; // adds all the resource elements automatically to the BIBFORMAT::item array $bibformat->preProcess($resourceType, $entry); // apply filters $pos = strpos($filter, $resourceType); $bibkey = $entry['bibtexCitation']; if ( ( (strcmp($filterType, "allow") === 0) && ($pos === false) ) or ( (strcmp($filterType, "deny") === 0) && ($pos !== false) ) or ( (strcmp($filterType, "key") === 0) && (strcmp($filter, $bibkey) != 0) ) ) continue; $i++; $biblogo = 'bibtex"; // get the formatted resource string ready for printing to the web browser // the str_replace is used to remove the { } parentheses possibly present in title // to enforce uppercase, TODO: check if it can be done only on title $tpl->newBlock("bibtex_entry"); $tpl->assign("year", $entry['year']); $tpl->assign("type", $entry['bibtexEntryType']); $tpl->assign("pdf", toDownload($entry)); $tpl->assign("key", $bibkey); $tpl->assign("entry", str_replace(array('{', '}'), '', $bibformat->map())); $tpl->assign("bibtex", formatBibtex($entry['bibtexEntry'])); } return $tpl->getOutputContent(); } function toDownload($entry) { if(array_key_exists('url',$entry)){ $string = " Go to document"; return $string; } return ''; } function bib2html($myContent) { // search for all [bibtex filename] tags and extract the filename preg_match_all("/\[bibtex\s+file=(.*)\s*((allow|deny|key)=([\w,]+))?\s*\]/U", $myContent, $bibItemsSets, PREG_SET_ORDER); if ($bibItemsSets) { foreach ($bibItemsSets as $bibItems) { $bibFile = dirname(__FILE__)."/data/".$bibItems[1]; if (file_exists($bibFile)) { $bib = file_get_contents($bibFile); if (!empty($bib)) { // if bibtex file identified and opened, then convert to html $htmlbib = bib2htmlProcess($bib, $bibItems[3], $bibItems[4]); $myContent = str_replace($bibItems[0], $htmlbib, $myContent); } else { $myContent = str_replace( $bibItems[0], $bibItems[1] . ' bibtex file empty', $myContent); } } else { $myContent = str_replace( $bibItems[0], $bibItems[1] . ' bibtex file not found', $myContent); } } } return $myContent; } // this function formats a bibtex code in order to be readable // when appearing in the modal window function formatBibtex($entry){ $order = array("},"); $replace = "},
\n  "; $entry = preg_replace('/\s\s+/', ' ', trim($entry)); $new_entry = str_replace($order, $replace, $entry); $new_entry = str_replace(", author", ",
\n   author", $new_entry); $new_entry = str_replace(", Author", ",
\n   author", $new_entry); $new_entry = str_replace(", AUTHOR", ",
\n   author", $new_entry); $new_entry = preg_replace('/\},?\s*\}$/', "}\n}", $new_entry); return $new_entry; } function bib2html_head() { echo "\n" . '' . "\n"; echo '' . "\n"; // echo '' . "\n"; // echo '' . "\n"; echo ""; } add_action('wp_head', 'bib2html_head'); add_filter('the_content', 'bib2html',1); ?>