1
0
Fork 0
mirror of https://github.com/Yetangitu/owncloud-apps.git synced 2025-10-02 14:49:17 +02:00
nextcloud-apps/files_opds/lib/bookshelf.php
frankdelange 77143932b8 files_reader: new version of epub.js, using JSZip.
files_opds: empty bookshelf seems to cause problems for some, now fixed.
2015-01-02 02:24:51 +01:00

67 lines
1.5 KiB
PHP

<?php
/**
* ownCloud - Files_Opds App
*
* @author Frank de Lange
* @copyright 2014 Frank de Lange
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Files_Opds;
/**
* Bookshelf class for publishing as OPDS
*
* This implements a 'personal bookshelf', listing books
* which have been downloaded from the OPDS feed.
*/
class Bookshelf
{
/**
* @brief add book to personal bookshelf
*
* @param int $id book to add to bookshelf
*/
public static function add($id) {
$bookshelf = json_decode(Config::get('bookshelf', ''), true);
if(!isset($bookshelf[$id])) {
$bookshelf[$id]=time();
}
Config::set('bookshelf', json_encode($bookshelf));
}
/**
* @brief clear personal bookshelf
*/
public static function clear() {
Config::set('bookshelf', '');
}
/**
* @brief return number of books on personal bookshelf
* @return int number of books
*/
public static function count() {
return substr_count(Config::get('bookshelf', ''), ':');
}
/**
* @brief list bookshelf contents
*
* @return array of FileInfo[], sorted by time added
*/
public static function get() {
$files = array();
if($bookshelf = json_decode(Config::get('bookshelf', ''), true)) {
arsort($bookshelf);
while (list($id, $time) = each($bookshelf)) {
array_push($files, \OC\Files\Filesystem::getFileInfo(\OC\Files\Filesystem::normalizePath(\OC\Files\Filesystem::getPath($id))));
}
}
return $files;
}
}