1
0
Fork 0
mirror of https://github.com/Yetangitu/owncloud-apps.git synced 2025-10-02 14:49:17 +02:00

files_opds: yet another 9.0 compatibility fix, change $id-handling to explicitly handle command strings

This commit is contained in:
frankdelange 2016-04-04 22:06:49 +02:00
parent 980502c412
commit 6559dd5528
4 changed files with 34 additions and 15 deletions

View file

@ -10,7 +10,7 @@
The feed is in compliance with the OPDS 1.1 specification according to the online OPDS validator (http://opds-validator.appspot.com/).
</description>
<licence>AGPL</licence>
<version>0.6.14</version>
<version>0.6.15</version>
<author>Frank de Lange</author>
<shipped>false</shipped>
<default_enable/>

View file

@ -31,6 +31,7 @@ if (Config::get('enable', 'false') === 'false') {
exit;
}
/* id defaults to 'root' (meaning 'serve root feed') */
$id = isset($_GET['id']) ? $_GET['id'] : 'root';
@ -45,6 +46,14 @@ if (isset($_GET['tid'])) {
$type = 'thumbnail';
}
# this is a bit ugly: $id either contains a numerical ID or a command string. If it contains the latter,
# move the content to $type for the Feed to interpret and switch in the library root numerical ID
if (ctype_alpha($id)) {
$type = $id;
$rootFolder = \OC::$server->getUserFolder(\OC::$server->getUserSession()->getUser()->getUID());
$id = $rootFolder->getId();
}
$dir = \OC\Files\Filesystem::normalizePath(\OC\Files\Filesystem::getPath($id));
$root = Config::get('root_path', '/Library');
@ -65,7 +74,7 @@ switch ($dirInfo->getType()) {
}
break;
case 'dir':
Feed::serveFeed($dir, $id);
Feed::serveFeed($dir, $id, $type);
break;
default:
Util::logWarn("I don't know how to handle files of type " . $dirInfo->getType());

View file

@ -47,8 +47,9 @@ class Feed
*
* @param string $dir full path to directory
* @param int $id requested id
* @param string $type request type (root, bookshelf, directory)
*/
public static function serveFeed($dir, $id) {
public static function serveFeed($dir, $id, $type) {
if (isset($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'], 'application/atom+xml')) {
header('Content-Type: application/atom+xml');
} else {
@ -63,6 +64,7 @@ class Feed
$tmpl->assign('bookshelf-count', Bookshelf::count());
$tmpl->assign('feed_id', self::getFeedId());
$tmpl->assign('id', $id);
$tmpl->assign('type', $type);
$tmpl->assign('dir', $dir);
$tmpl->assign('user', \OCP\User::getDisplayName());
$tmpl->assign('feed_title', Config::get('feed_title',\OCP\User::getDisplayName() . "'s Library"));

View file

@ -41,20 +41,28 @@ echo '<?xml version="1.0" encoding="UTF-8"?>';
<?php
if ($_['id'] == 'root') {
print_unescaped($this->inc('part.feed.root'));
} elseif (($_['id'] == 'bookshelf')) {
foreach ($_['bookshelf'] as $file) {
print_unescaped($this->inc('part.feed.acquisition', [ 'file' => $file ]));
}
} else {
foreach ($_['files'] as $file) {
if ($file['type'] == 'dir') {
print_unescaped($this->inc('part.feed.navigation', [ 'file' => $file ]));
} else {
switch ($_['type']) {
case 'root':
print_unescaped($this->inc('part.feed.root'));
break;
case 'bookshelf':
foreach ($_['bookshelf'] as $file) {
print_unescaped($this->inc('part.feed.acquisition', [ 'file' => $file ]));
}
}
break;
/* intentional fall-through for 'directory' */
case 'directory':
default:
foreach ($_['files'] as $file) {
if ($file['type'] == 'dir') {
print_unescaped($this->inc('part.feed.navigation', [ 'file' => $file ]));
} else {
print_unescaped($this->inc('part.feed.acquisition', [ 'file' => $file ]));
}
}
break;
}
?>
</feed>