- Migrated from https://github.com/Yetangitu/owncloud-apps
- substantial bit rot accrued in 4 years of non-maintenance which made Reader unusable - Reader now works reliably on public pages - or at least it _Works For Me™_ - Refactored a substantial part of the code to comply to the "current" (ha ha) Nextcloud API - Dropped Owncloud compatibility for lack of a testing installation - Dropped IE (<11) support - Dropped compatibility with older (<20) Nextcloud versions - Dropped app-specific ajax code, now handled by SettingsController - Updated dependencies where applicable
This commit is contained in:
parent
16afbe45fe
commit
b190e180ef
137 changed files with 30984 additions and 2 deletions
48
lib/Db/Bookmark.php
Normal file
48
lib/Db/Bookmark.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2015 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class Bookmark extends ReaderEntity implements \JsonSerializable {
|
||||
|
||||
protected $userId; // user
|
||||
protected $fileId; // book (identified by fileId) for which this mark is valid
|
||||
protected $type; // type, defaults to "bookmark"
|
||||
protected $name; // name, defaults to $location
|
||||
protected $value; // bookmark value (format-specific, eg. page number for PDF, CFI for epub, etc)
|
||||
protected $content; // bookmark content (annotations etc), can be empty
|
||||
protected $lastModified; // modification timestamp
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'userId' => $this->getUserId(),
|
||||
'fileId' => $this->getFileId(),
|
||||
'type' => $this->getType(),
|
||||
'name' => $this->getName(),
|
||||
'value' => static::conditional_json_decode($this->getValue()),
|
||||
'content' => static::conditional_json_decode($this->getContent()),
|
||||
'lastModified' => $this->getLastModified()
|
||||
];
|
||||
}
|
||||
|
||||
public function toService() {
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'type' => $this->getType(),
|
||||
'value' => $this->conditional_json_decode($this->getValue()),
|
||||
'content' => $this->conditional_json_decode($this->getContent()),
|
||||
'lastModified' => $this->getLastModified(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
121
lib/Db/BookmarkMapper.php
Normal file
121
lib/Db/BookmarkMapper.php
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2017 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Db;
|
||||
|
||||
|
||||
use OCP\IDBConnection;
|
||||
|
||||
use OCA\Files_Reader\Utility\Time;
|
||||
|
||||
class BookmarkMapper extends ReaderMapper {
|
||||
|
||||
private $userId;
|
||||
|
||||
/**
|
||||
* @param IDbConnection $db
|
||||
* @param $UserId
|
||||
* @param Time $time
|
||||
*/
|
||||
public function __construct(IDBConnection $db, $UserId, Time $time) {
|
||||
parent::__construct($db, 'reader_bookmarks', Bookmark::class, $time);
|
||||
/** @var int $UserId */
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get bookmarks for $fileId+$userId(+$name)
|
||||
* @param $fileId
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function get($fileId, $name, $type=null) {
|
||||
$sql = "SELECT * FROM `*PREFIX*reader_bookmarks` WHERE file_id=? AND `user_id`=?";
|
||||
$args = [ $fileId, $this->userId ];
|
||||
if (!(null === $type)) {
|
||||
$sql .= " AND `type`=?";
|
||||
$args[] = $type;
|
||||
}
|
||||
if (!(null === $name)) {
|
||||
$sql .= " AND `name`=?";
|
||||
$args[] = $name;
|
||||
}
|
||||
|
||||
return $this->findEntities($sql, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief write bookmark to database
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return Bookmark the newly created or updated bookmark
|
||||
*/
|
||||
public function set($fileId, $name, $value, $type, $content=null) {
|
||||
|
||||
$result = $this->get($fileId, $name);
|
||||
|
||||
if(empty($result)) {
|
||||
|
||||
// anonymous bookmarks are named after their contents
|
||||
if (null === $name) {
|
||||
$name = $value;
|
||||
}
|
||||
|
||||
// default type is "bookmark"
|
||||
if (null === $type) {
|
||||
$type = "bookmark";
|
||||
}
|
||||
|
||||
$bookmark = new Bookmark();
|
||||
$bookmark->setFileId($fileId);
|
||||
$bookmark->setUserId($this->userId);
|
||||
$bookmark->setType($type);
|
||||
$bookmark->setName($name);
|
||||
$bookmark->setValue($value);
|
||||
$bookmark->setContent($content);
|
||||
|
||||
$this->insert($bookmark);
|
||||
} else {
|
||||
$bookmark = $result[0];
|
||||
$bookmark->setValue($value);
|
||||
$bookmark->setContent($content);
|
||||
|
||||
$this->update($bookmark);
|
||||
}
|
||||
|
||||
return $bookmark;
|
||||
}
|
||||
|
||||
/* currently not used */
|
||||
public function deleteForFileId($fileId) {
|
||||
$sql = "SELECT * FROM `*PREFIX*reader_bookmarks` WHERE file_id=?";
|
||||
$args = [ $fileId ];
|
||||
array_map(
|
||||
function($entity) {
|
||||
$this->delete($entity);
|
||||
}, $this->findEntities($sql, $args)
|
||||
);
|
||||
}
|
||||
|
||||
/* currently not used */
|
||||
public function deleteForUserId($userId) {
|
||||
$sql = "SELECT * FROM `*PREFIX*reader_bookmarks` WHERE user_id=?";
|
||||
$args = [ $userId ];
|
||||
array_map(
|
||||
function($entity) {
|
||||
$this->delete($entity);
|
||||
}, $this->findEntities($sql, $args)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
42
lib/Db/Preference.php
Normal file
42
lib/Db/Preference.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2015 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class Preference extends ReaderEntity implements \JsonSerializable {
|
||||
|
||||
protected $userId; // user for whom this preference is valid
|
||||
protected $scope; // scope (default or specific renderer)
|
||||
protected $fileId; // file for which this preference is set
|
||||
protected $name; // preference name
|
||||
protected $value; // preference value
|
||||
protected $lastModified; // modification timestamp
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'scope' => $this->getScope(),
|
||||
'fileId' => $this->getFileId(),
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->conditional_json_decode($this->getValue()),
|
||||
'lastModified' => $this->getLastModified(),
|
||||
];
|
||||
}
|
||||
|
||||
public function toService() {
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->conditional_json_decode($this->getValue()),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
105
lib/Db/PreferenceMapper.php
Normal file
105
lib/Db/PreferenceMapper.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2017 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Db;
|
||||
|
||||
use OCA\Files_Reader\Utility\Time;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class PreferenceMapper extends ReaderMapper {
|
||||
|
||||
public function __construct(IDBConnection $db, $UserId, Time $time) {
|
||||
parent::__construct($db, 'reader_preferences', Preference::class, $time);
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get preferences for $scope+$fileId+$userId(+$name)
|
||||
*
|
||||
* @param string $scope
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function get($scope, $fileId, $name=null) {
|
||||
if(!empty($name)) {
|
||||
$sql = "SELECT * FROM `*PREFIX*reader_preferences` WHERE `scope`=? AND `file_id`=? AND `user_id`=? AND `name`=?";
|
||||
$args = array(
|
||||
$scope,
|
||||
$fileId,
|
||||
$this->userId,
|
||||
$name);
|
||||
} else {
|
||||
$sql = "SELECT * FROM `*PREFIX*reader_preferences` WHERE `scope`=? AND `file_id`=? AND `user_id`=?";
|
||||
$args = array(
|
||||
$scope,
|
||||
$fileId,
|
||||
$this->userId);
|
||||
}
|
||||
|
||||
return $this->findEntities($sql, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief write preference to database
|
||||
*
|
||||
* @param string $scope
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return Preference the newly created or updated preference
|
||||
*/
|
||||
public function set($scope, $fileId, $name, $value) {
|
||||
|
||||
$result = $this->get($scope, $fileId, $name);
|
||||
|
||||
if(empty($result)) {
|
||||
|
||||
$preference = new Preference();
|
||||
$preference->setScope($scope);
|
||||
$preference->setFileId($fileId);
|
||||
$preference->setUserId($this->userId);
|
||||
$preference->setName($name);
|
||||
$preference->setValue($value);
|
||||
|
||||
$this->insert($preference);
|
||||
} else {
|
||||
$preference = $result[0];
|
||||
$preference->setValue($value);
|
||||
|
||||
$this->update($preference);
|
||||
}
|
||||
|
||||
return $preference;
|
||||
}
|
||||
|
||||
/* currently not used*/
|
||||
public function deleteForFileId($fileId) {
|
||||
$sql = "SELECT * FROM `*PREFIX*reader_preferences` WHERE file_id=?";
|
||||
$args = [ $fileId ];
|
||||
array_map(
|
||||
function($entity) {
|
||||
$this->delete($entity);
|
||||
}, $this->findEntities($sql, $args)
|
||||
);
|
||||
}
|
||||
|
||||
/* currently not used*/
|
||||
public function deleteForUserId($userId) {
|
||||
$sql = "SELECT * FROM `*PREFIX*reader_preferences` WHERE user_id=?";
|
||||
$args = [ $userId ];
|
||||
array_map(
|
||||
function($entity) {
|
||||
$this->delete($entity);
|
||||
}, $this->findEntities($sql, $args)
|
||||
);
|
||||
}
|
||||
}
|
39
lib/Db/ReaderEntity.php
Normal file
39
lib/Db/ReaderEntity.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2015 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Db;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class ReaderEntity extends Entity {
|
||||
|
||||
/* returns decoded json if input is json, otherwise returns input */
|
||||
public static function conditional_json_decode($el) {
|
||||
$result = json_decode($el);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
return $result;
|
||||
} else {
|
||||
return $el;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public function toService() {
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'type' => $this->getType(),
|
||||
'value' => $this->conditional_json_decode($this->getValue()),
|
||||
'content' => $this->conditional_json_decode($this->getContent()),
|
||||
'lastModified' => $this->getLastModified(),
|
||||
];
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
40
lib/Db/ReaderMapper.php
Normal file
40
lib/Db/ReaderMapper.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2017 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Db;
|
||||
|
||||
use OCP\IDBConnection;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
use OCA\Files_Reader\Utility\Time;
|
||||
|
||||
abstract class ReaderMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* @var Time
|
||||
*/
|
||||
private $time;
|
||||
|
||||
public function __construct(IDBConnection $db, $table, $entity, Time $time) {
|
||||
parent::__construct($db, $table, $entity);
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
public function update(Entity $entity) {
|
||||
$entity->setLastModified($this->time->getMicroTime());
|
||||
return parent::update($entity);
|
||||
}
|
||||
|
||||
public function insert(Entity $entity) {
|
||||
$entity->setLastModified($this->time->getMicroTime());
|
||||
return parent::insert($entity);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue