Browse Source

figured out how to ensure correct html wrapper used when script is required from outside its cwd

pull/81/head
Chris 8 years ago
parent
commit
a0daf5c44c
  1. 2
      composer.json
  2. 25
      public/embed.php
  3. 29
      public/index.php
  4. 11
      src/bibtexbrowser.php

2
composer.json

@ -19,7 +19,7 @@
} }
}, },
"scripts": { "scripts": {
"serve": "@php -S localhost:8080 -t public/"
"serve": "@php -S localhost:29896 -t public/"
}, },
"require-dev": { "require-dev": {
"monolog/monolog": "^1.23", "monolog/monolog": "^1.23",

25
public/embed.php

@ -0,0 +1,25 @@
<?PHP
print <<<HTML
<!doctype html>
<html>
<head></head>
<body>
HTML;
$_GET['library']=1;
require_once('../src/bibtexbrowser.php');
$db = new BibDataBase();
$db->load('bibacid-utf8.bib');
$query = array('year'=>'1997');
$entries=$db->multisearch($query);
uasort($entries, 'compare_bib_entries');
foreach ($entries as $bibentry) {
print $bibentry->toHTML()."<br/>";
}
print <<<HTML
</body>
</html>
HTML;
exit;

29
public/index.php

@ -1,27 +1,16 @@
<?PHP <?PHP
// have this assume same directory as thing
$_GET['bib'] = "bibacid-utf8.bib"; $_GET['bib'] = "bibacid-utf8.bib";
// first step is to get relative reference correct
require_once "../src/bibtexbrowser.php";
//require_once "../vendor/autoload.php";
// use Monperrus\BibtexBrowser\Bibliography;
require_once "../vendor/autoload.php";
use Monperrus\BibtexBrowser\Bibliography;
// $config = array("bib" => "bibacid-utf8.bib",
// "all" => 1,
// "author" => "",
// "academic" => 1
// );
$config = array("bib" => "bibacid-utf8.bib",
"all" => 1,
"author" => "",
"academic" => 1
);
// $_GET['menu']=1;
// $browser = new Monperrus\BibtexBrowser\Bibliography($config);
// $browser->print();
//s($_SERVER);
$browser = new Bibliography($config);
$browser->print();

11
src/bibtexbrowser.php

@ -328,7 +328,7 @@ function _zetDB($bibtex_filenames) {
// to automate dectection of faulty links with tools such as webcheck // to automate dectection of faulty links with tools such as webcheck
header('HTTP/1.1 404 Not found'); header('HTTP/1.1 404 Not found');
// escape $bib to prevent XSS // escape $bib to prevent XSS
$escapedBib = htmlEntities($bib, ENT_QUOTES);
htmlEntities($bib, ENT_QUOTES);
die('<b>the bib file '.$escapedBib.' does not exist !</b>'); die('<b>the bib file '.$escapedBib.' does not exist !</b>');
} }
} // end for each } // end for each
@ -4531,7 +4531,7 @@ class Dispatcher {
} }
// should call method display() on $x // should call method display() on $x
$fun = $this->wrapper;
$fun = BIBTEXBROWSER_DEFAULT_TEMPLATE;//$this->wrapper;
$fun($x); $fun($x);
$this->clearQuery(); $this->clearQuery();
@ -4541,7 +4541,7 @@ class Dispatcher {
// if some contents have already been sent, for instance if we are included // if some contents have already been sent, for instance if we are included
// this means doing nothing // this means doing nothing
if ( headers_sent() == false ) { /* to avoid sending an unnecessary frameset */ if ( headers_sent() == false ) { /* to avoid sending an unnecessary frameset */
header("Location: ".$_SERVER['SCRIPT_NAME']."?frameset&bib=".$_GET[Q_FILE]);
header("Location: ".$_SERVER['SCRIPT_NAME']."?frameset&bib=".$_GET[Q_FILE]);
} }
} }
} }
@ -4668,7 +4668,8 @@ class Dispatcher {
function menu() { function menu() {
$menu = createMenuManager(); $menu = createMenuManager();
$menu->setDB($this->getDB()); $menu->setDB($this->getDB());
$fun = $this->wrapper;
// why does //$this->wrapper; = no wrapper?
$fun = BIBTEXBROWSER_DEFAULT_TEMPLATE;
$fun($menu); $fun($menu);
return 'END_DISPATCH'; return 'END_DISPATCH';
} }
@ -4759,7 +4760,7 @@ class Dispatcher {
</html> </html>
<?php <?php
return 'END_DISPATCH';
return 'END_DISPATCH';
} }
} // end class Dispatcher } // end class Dispatcher

Loading…
Cancel
Save