+
+ public static function parsePath($path) {
+ // Parse the BookReader path and return the parts
+ // e.g. itemid/some/sub/dir/page/cover.jpg -> array( 'identifier' => 'itemid', 'subPrefix' => 'some/sub/dir',
+ // 'operator' => 'page', 'filename' => 'cover.jpg')
+
+ $parts = array();
+
+ // Pull off query, e.g. ?foo=bar
+ if (preg_match('#(.*?)(\?.*)#', $path, $matches) === 1) {
+ $parts['query'] = $matches[2];
+ $path = $matches[1];
+ }
+
+ // Pull off identifier
+ if (preg_match('#[^/&?]+#', $path, $matches) === 0) {
+ // no match
+ return $parts;
+ }
+ $parts['identifier'] = $matches[0];
+ $path = substr($path, strlen($matches[0]));
+
+ // 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>.*)#';
+ if (preg_match($pattern, $path, $matches) === 1) {
+ $parts['subPrefix'] = substr($matches['subPrefix'], 1); // remove leading '/'
+ $parts['operator'] = $matches['operator'];
+ $parts['operand'] = $matches['operand'];
+ } else {
+ $parts['subPrefix'] = $path;
+ }
+
+ return $parts;
+ }