along with BookReader. If not, see <http://www.gnu.org/licenses/>.
*/
+require_once("BookReaderMeta.inc.php");
+
class BookReaderImages
{
public $MIMES = array('gif' => 'image/gif',
// Index of image to return
$imageIndex = null;
- // XXX deal with subPrefix
- $pageInfo = $this->parsePageRequest($page);
-
- // Parse requested page for page type, size and format options
- if (preg_match('#^([^_]+)#', $page, $matches) === 0) {
- // Unrecognized page specifier
- $this->BRfatal('Unrecognized page specifier');
+ // deal with subPrefix
+ if ($_REQUEST['subPrefix']) {
+ $parts = split('/', $_REQUEST['subPrefix']);
+ $bookId = $parts[count($parts) - 1 ];
+ } else {
+ $bookId = $_REQUEST['id'];
}
- $basePage = $matches[1];
+
+ $pageInfo = $this->parsePageRequest($page, $bookId);
+
+ $basePage = $pageInfo['type'];
switch ($basePage) {
case 'title':
$imageIndex = 0;
break;
+ case 'n':
+ // Accessible index page
+ $imageIndex = intval($pageInfo['value']);
+ break;
+
+ case 'page':
+ // Named page
+ $index = array_search($pageInfo['value'], $metadata['pageNums']);
+ if ($index === FALSE) {
+ // Not found
+ $this->BRfatal("Page not found");
+ break;
+ }
+
+ $imageIndex = $index;
+ break;
+
default:
// Shouldn't be possible
- $this->BRfatal("Couldn't find page");
+ $this->BRfatal("Unrecognized page type requested");
break;
}
// Serve request
$bri = new BookReaderImages();
try {
- $bri->serveRequest($_REQUEST);
+ if ($_REQUEST['page']) {
+ // Need to lookup metadata
+ $bri->serveLookupRequest($_REQUEST);
+ } else {
+ // Request should be fully qualified - no lookup needed
+ $bri->serveRequest($_REQUEST);
+ }
} catch (Exception $e) {
header("HTTP/1.0 404 Not Found");
header("Content-type: text/plain");
$parts = array();
- // Pull off query
+ // Pull off query, e.g. ?foo=bar
if (preg_match('#(.*?)(\?.*)#', $path, $matches) === 1) {
$parts['query'] = $matches[2];
$path = $matches[1];
// Look for operators
// The sub-prefix can be arbitrary, so we match up until the first operator
$operators = '(' . join('|', self::$downloadOperators) . ')';
- $pattern = '#/(?P<subPrefix>.*?)/(?P<operator>' . $operators . ')/(?P<operand>.*)#';
+ $pattern = '#(?P<subPrefix>.*?)/(?P<operator>' . $operators . ')/(?P<operand>.*)#';
if (preg_match($pattern, $path, $matches) === 1) {
- $parts['subPrefix'] = $matches['subPrefix'];
+ $parts['subPrefix'] = substr($matches['subPrefix'], 1); // remove leading '/'
$parts['operator'] = $matches['operator'];
$parts['operand'] = $matches['operand'];
} else {