> * * @author: Lea Viljanen */ class WikiPlugin_CreateBib extends WikiPlugin { function getName() { return _("CreateBib"); } function getDescription() { return _("Automatically create a Bibtex file from linked pages"); } function getDefaultArguments() { return array( 'pagename' => '[pagename]', // The page from which the BibTex file is generated ); } function preg_quote ($heading) { return str_replace(array("/",".","?","*"), array('\/','\.','\?','\*'), $heading); } // Have to include the $starttag and $endtag to the regexps... function extractBibTeX (&$content, $starttag, $endtag) { $bib = array(); $start = false; $stop = false; for ($i=0; $i $thispage->get('mtime'), 'is_ascii' => 1); $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $filename); $zip->addRegularFile( FilenameForPage($thispage->getName()), $mailified, $attrib); $zip->finish(); } function run($dbi, $argstr, $request, $basepage) { extract($this->getArgs($argstr, $request)); if ($pagename) { // Expand relative page names. $page = new WikiPageName($pagename, $basepage); $pagename = $page->name; } if (!$pagename) { return $this->error(_("no page specified")); } // Get the links page contents $page = $dbi->getPage($pagename); $current = $page->getCurrentRevision(); $content = $current->getContent(); // Prepare the button to trigger dumping $dump_url = $request->getURLtoSelf(array("file" => "tube.bib")); global $WikiTheme; $dump_button = $WikiTheme->makeButton("To File", $dump_url , 'foo'); $html = HTML::div(array('class' => 'bib','align' => 'left')); $html->pushContent($dump_button, ' '); $list = HTML::pre(array('id'=>'biblist', 'class' => 'bib')); // Let's find the subpages if ($articles = $this->extractArticles($content)) { foreach ($articles as $h) { // Now let's get the bibtex information from that subpage $subpage = $dbi->getPage($h); $subversion = $subpage->getCurrentRevision(); $subcontent = $subversion->getContent(); $bib = $this->extractBibTeX($subcontent, "@", "}"); // ...and finally just push the bibtex data to page $foo = implode("\n", $bib); $bar = $foo . "\n\n"; $list->pushContent(HTML::raw($bar)); } } $html->pushContent($list); if ($request->getArg('file')) { // Yes, we want to dump this somewhere // Get the contents of this page $p = $dbi->getPage($pagename); $c = $p->getCurrentRevision(); $pagedata = $c->getContent(); $this->dumpFile($pagedata, $request->getArg('file')); } return $html; } }; // Based on CreateTOC // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?>