Refacto all project

This commit is contained in:
Michel Roux 2023-06-16 16:58:23 +02:00
parent ba42ac92af
commit e896016ff9
33 changed files with 1518 additions and 1165 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.idea
*.iml
/vendor/
/build/
node_modules/
/.php-cs-fixer.cache
js/*hot-update.*

18
.php-cs-fixer.dist.php Normal file
View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
require_once './vendor/autoload.php';
use Nextcloud\CodingStandard\Config;
$config = new Config();
$config
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
return $config;

View File

@ -12,7 +12,6 @@
namespace OCA\Epubreader\AppInfo;
use OCP\AppFramework\App;
use OCP\Util;
$l = \OC::$server->getL10N('epubreader');

View File

@ -29,7 +29,7 @@ See [README] for more exhaustive information on features and potential misfeatur
[README]: https://github.com/e-alfred/epubreader/blob/master/epubreader/README.md
]]>
</description>
<version>1.4.7</version>
<version>1.4.8</version>
<licence>agpl</licence>
<author>Frank de Lange</author>
<author>e-alfred</author>
@ -46,7 +46,7 @@ See [README] for more exhaustive information on features and potential misfeatur
<screenshot>https://github.com/e-alfred/epubreader/blob/master/screenshots/photo_2017-03-15_17-22-00.jpg?raw=true</screenshot>
<screenshot>https://github.com/e-alfred/epubreader/blob/master/screenshots/photo_2017-03-15_17-22-02.jpg?raw=true</screenshot>
<dependencies>
<nextcloud min-version="21" max-version="23"/>
<nextcloud min-version="21" max-version="27"/>
</dependencies>
<settings>
<personal>OCA\Epubreader\Settings\Personal</personal>

View File

@ -38,4 +38,3 @@ return ['routes' => [
// User Settings
['name' => 'settings#setPreference', 'url' => '/settings/set', 'verb' => 'POST'],
]];

30
composer.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "nextcloud/epubreader",
"description": "EPUB/CBZ/PDF ebook reader",
"version": "1.4.8",
"type": "project",
"license": "AGPL-3.0-or-later",
"require-dev": {
"nextcloud/ocp": "^21.0.0",
"psalm/phar": "^5.12.0",
"nextcloud/coding-standard": "^1.1.1"
},
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar --threads=1 --no-cache",
"psalm:fix": "psalm.phar --no-cache --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType"
},
"autoload": {
"psr-4": {
"OCA\\Epubreader\\": "lib/",
"OC\\": "stubs/oc/"
}
},
"config": {
"platform": {
"php": "7.4"
}
}
}

189
composer.lock generated Normal file
View File

@ -0,0 +1,189 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6684feffdd51c1ea6c0f31066f3e5560",
"packages": [],
"packages-dev": [
{
"name": "nextcloud/coding-standard",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/nextcloud/coding-standard.git",
"reference": "55def702fb9a37a219511e1d8c6fe8e37164c1fb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/55def702fb9a37a219511e1d8c6fe8e37164c1fb",
"reference": "55def702fb9a37a219511e1d8c6fe8e37164c1fb",
"shasum": ""
},
"require": {
"php": "^7.3|^8.0",
"php-cs-fixer/shim": "^3.17"
},
"type": "library",
"autoload": {
"psr-4": {
"Nextcloud\\CodingStandard\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Christoph Wurst",
"email": "christoph@winzerhof-wurst.at"
}
],
"description": "Nextcloud coding standards for the php cs fixer",
"support": {
"issues": "https://github.com/nextcloud/coding-standard/issues",
"source": "https://github.com/nextcloud/coding-standard/tree/v1.1.1"
},
"time": "2023-06-01T12:05:01+00:00"
},
{
"name": "nextcloud/ocp",
"version": "v21.0.0",
"source": {
"type": "git",
"url": "https://github.com/nextcloud-deps/ocp.git",
"reference": "41e1476b4aed5bce7371895054049eca353729c5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/41e1476b4aed5bce7371895054049eca353729c5",
"reference": "41e1476b4aed5bce7371895054049eca353729c5",
"shasum": ""
},
"require": {
"php": "^7.3 || ~8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "21.0.0-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"AGPL-3.0-or-later"
],
"authors": [
{
"name": "Christoph Wurst",
"email": "christoph@winzerhof-wurst.at"
}
],
"description": "Composer package containing Nextcloud's public API (classes, interfaces)",
"support": {
"source": "https://github.com/nextcloud-deps/ocp/tree/v21.0.0"
},
"time": "2021-03-01T08:42:25+00:00"
},
{
"name": "php-cs-fixer/shim",
"version": "v3.17.0",
"source": {
"type": "git",
"url": "https://github.com/PHP-CS-Fixer/shim.git",
"reference": "f51b4aed90565c447136f1d015798f6f7c82490f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/f51b4aed90565c447136f1d015798f6f7c82490f",
"reference": "f51b4aed90565c447136f1d015798f6f7c82490f",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-tokenizer": "*",
"php": "^7.4 || ^8.0"
},
"replace": {
"friendsofphp/php-cs-fixer": "self.version"
},
"suggest": {
"ext-dom": "For handling output formats in XML",
"ext-mbstring": "For handling non-UTF8 characters."
},
"bin": [
"php-cs-fixer",
"php-cs-fixer.phar"
],
"type": "application",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Dariusz Rumiński",
"email": "dariusz.ruminski@gmail.com"
}
],
"description": "A tool to automatically fix PHP code style",
"support": {
"issues": "https://github.com/PHP-CS-Fixer/shim/issues",
"source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.17.0"
},
"time": "2023-05-22T20:00:38+00:00"
},
{
"name": "psalm/phar",
"version": "5.12.0",
"source": {
"type": "git",
"url": "https://github.com/psalm/phar.git",
"reference": "e7f9306ec83c706b4dba451f6adfb865ce4688e4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/psalm/phar/zipball/e7f9306ec83c706b4dba451f6adfb865ce4688e4",
"reference": "e7f9306ec83c706b4dba451f6adfb865ce4688e4",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"vimeo/psalm": "*"
},
"bin": [
"psalm.phar"
],
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Composer-based Psalm Phar",
"support": {
"issues": "https://github.com/psalm/phar/issues",
"source": "https://github.com/psalm/phar/tree/5.12.0"
},
"time": "2023-05-22T21:30:41+00:00"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"platform-overrides": {
"php": "7.4"
},
"plugin-api-version": "2.3.0"
}

View File

@ -10,12 +10,11 @@
namespace OCA\Epubreader\Controller;
use OCP\IRequest;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCA\Epubreader\Service\BookmarkService;
use OCP\AppFramework\Controller;
use OCP\IRequest;
class BookmarkController extends Controller {
@ -28,7 +27,7 @@ class BookmarkController extends Controller {
*/
public function __construct($AppName,
IRequest $request,
BookmarkService $bookmarkService ) {
BookmarkService $bookmarkService) {
parent::__construct($AppName, $request);
$this->bookmarkService = $bookmarkService;
@ -45,7 +44,7 @@ class BookmarkController extends Controller {
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function get($fileId, $name, $type=null) {
public function get($fileId, $name, $type = null) {
return $this->bookmarkService->get($fileId, $name, $type);
}
@ -61,7 +60,7 @@ class BookmarkController extends Controller {
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function set($fileId, $name, $value, $type=null, $content=null) {
public function set($fileId, $name, $value, $type = null, $content = null) {
return $this->bookmarkService->set($fileId, $name, $value, $type, $content);
}

View File

@ -10,10 +10,10 @@
namespace OCA\Epubreader\Controller;
use OCP\IRequest;
use OCA\Epubreader\Service\MetadataService;
use OCP\AppFramework\Controller;
use OCA\Epubreader\Service\MetadataService;
use OCP\IRequest;
class MetadataController extends Controller {
@ -26,7 +26,7 @@ class MetadataController extends Controller {
*/
public function __construct($AppName,
IRequest $request,
MetadataService $metadataService ) {
MetadataService $metadataService) {
parent::__construct($AppName, $request);
$this->metadataService = $metadataService;

View File

@ -10,19 +10,18 @@
namespace OCA\Epubreader\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Files\IRootFolder;
use OCP\Share\IManager;
use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCA\Epubreader\Service\BookmarkService;
use OCA\Epubreader\Service\MetadataService;
use OCA\Epubreader\Service\PreferenceService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Share\IManager;
class PageController extends Controller {
@ -74,7 +73,7 @@ class PageController extends Controller {
* @return TemplateResponse
*/
public function showReader() {
$templates= [
$templates = [
'application/epub+zip' => 'epubreader',
'application/x-cbr' => 'cbreader',
'application/pdf' => 'pdfreader'
@ -87,14 +86,14 @@ class PageController extends Controller {
* fileType => null
* ];
*/
$fileInfo = $this->getFileInfo($this->request->get['file']);
$fileInfo = $this->getFileInfo($this->request->getParam('file'));
$fileId = $fileInfo['fileId'];
$type = $this->request->get["type"];
$type = $this->request->getParam('type');
$scope = $template = $templates[$type];
$params = [
'urlGenerator' => $this->urlGenerator,
'downloadLink' => $this->request->get['file'],
'downloadLink' => $this->request->getParam('file'),
'scope' => $scope,
'fileId' => $fileInfo['fileId'],
'fileName' => $fileInfo['fileName'],
@ -102,7 +101,6 @@ class PageController extends Controller {
'cursor' => $this->toJson($this->bookmarkService->getCursor($fileId)),
'defaults' => $this->toJson($this->preferenceService->getDefault($scope)),
'preferences' => $this->toJson($this->preferenceService->get($scope, $fileId)),
'defaults' => $this->toJson($this->preferenceService->getDefault($scope)),
'metadata' => $this->toJson($this->metadataService->get($fileId)),
'annotations' => $this->toJson($this->bookmarkService->get($fileId))
];
@ -136,7 +134,7 @@ class PageController extends Controller {
*/
private function getFileInfo($path) {
$count = 0;
$shareToken = preg_replace("/(?:\/index\.php)?\/s\/([A-Za-z0-9]{15,32})\/download.*/", "$1", $path, 1,$count);
$shareToken = preg_replace("/(?:\/index\.php)?\/s\/([A-Za-z0-9]{15,32})\/download.*/", "$1", $path, 1, $count);
if ($count === 1) {
@ -159,8 +157,7 @@ class PageController extends Controller {
} else {
$filePath = $path;
$fileId = $this->rootFolder->getUserFolder($this->userId)
->get(preg_replace("/.*\/remote.php\/webdav(.*)/", "$1", rawurldecode($this->request->get['file'])))
->getFileInfo()
->get(preg_replace("/.*\/remote.php\/webdav(.*)/", "$1", rawurldecode($this->request->getParam('file'))))
->getId();
}

View File

@ -10,12 +10,11 @@
namespace OCA\Epubreader\Controller;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\AppFramework\Http;
use OCP\AppFramework\Controller;
use OCA\Epubreader\Service\PreferenceService;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\IURLGenerator;
class PreferenceController extends Controller {
@ -31,7 +30,7 @@ class PreferenceController extends Controller {
public function __construct($AppName,
IRequest $request,
IURLGenerator $urlGenerator,
PreferenceService $preferenceService ) {
PreferenceService $preferenceService) {
parent::__construct($AppName, $request);
$this->urlGenerator = $urlGenerator;

View File

@ -11,13 +11,13 @@
*/
namespace OCA\Epubreader\Controller;
use OCA\Epubreader\Config;
use OCA\Epubreader\Service\PreferenceService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\AppFramework\Http;
use OCP\AppFramework\Controller;
use OCA\Epubreader\Service\PreferenceService;
use OCA\Epubreader\Config;
use OCP\AppFramework\Http\JSONResponse;
class SettingsController extends Controller {
@ -33,7 +33,7 @@ class SettingsController extends Controller {
public function __construct($AppName,
IRequest $request,
IURLGenerator $urlGenerator,
PreferenceService $preferenceService ) {
PreferenceService $preferenceService) {
parent::__construct($AppName, $request);
$this->urlGenerator = $urlGenerator;
@ -46,12 +46,12 @@ class SettingsController extends Controller {
* @NoAdminRequired
*
* @param int $EpubEnable
* @param int $EpubEnable
* @param int $PdfEnable
* @param int $CbxEnable
*
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function setPreference(string $EpubEnable, string $PdfEnable, string $CbxEnable) {
public function setPreference(int $EpubEnable, int $PdfEnable, int $CbxEnable) {
$l = \OC::$server->getL10N('epubreader');
@ -60,7 +60,7 @@ class SettingsController extends Controller {
Config::set('cbx_enable', $CbxEnable);
$response = array(
'data' => array('message'=> $l->t('Settings updated successfully.')),
'data' => array('message' => $l->t('Settings updated successfully.')),
'status' => 'success'
);

View File

@ -10,8 +10,6 @@
namespace OCA\Epubreader\Db;
use OCP\AppFramework\Db\Entity;
class Bookmark extends ReaderEntity implements \JsonSerializable {
protected $userId; // user
@ -22,7 +20,7 @@ class Bookmark extends ReaderEntity implements \JsonSerializable {
protected $content; // bookmark content (annotations etc), can be empty
protected $lastModified; // modification timestamp
public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'userId' => $this->getUserId(),
@ -44,5 +42,60 @@ class Bookmark extends ReaderEntity implements \JsonSerializable {
'lastModified' => $this->getLastModified(),
];
}
}
public function getUserId() {
return $this->userId;
}
public function setUserId($userId) {
$this->userId = $userId;
}
public function getFileId() {
return $this->fileId;
}
public function setFileId($fileId) {
$this->fileId = $fileId;
}
public function getType() {
return $this->type;
}
public function setType($type) {
$this->type = $type;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getValue() {
return $this->value;
}
public function setValue($value) {
$this->value = $value;
}
public function getContent() {
return $this->content;
}
public function setContent($content) {
$this->content = $content;
}
public function getLastModified() {
return $this->lastModified;
}
public function setLastModified($lastModified) {
$this->lastModified = $lastModified;
}
}

View File

@ -10,11 +10,10 @@
namespace OCA\Epubreader\Db;
use OCA\Epubreader\Utility\Time;
use OCP\IDBConnection;
use OCA\Epubreader\Utility\Time;
class BookmarkMapper extends ReaderMapper {
private $userId;
@ -36,7 +35,7 @@ class BookmarkMapper extends ReaderMapper {
* @param string $name
* @return array
*/
public function get($fileId, $name, $type = null) {
public function get(int $fileId, $name, $type = null) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
@ -63,7 +62,7 @@ class BookmarkMapper extends ReaderMapper {
*
* @return Bookmark the newly created or updated bookmark
*/
public function set($fileId, $name, $value, $type, $content=null) {
public function set($fileId, $name, $value, $type, $content = null) {
$result = $this->get($fileId, $name);
@ -98,27 +97,4 @@ class BookmarkMapper extends ReaderMapper {
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)
);
}
}

View File

@ -10,8 +10,6 @@
namespace OCA\Epubreader\Db;
use OCP\AppFramework\Db\Entity;
class Preference extends ReaderEntity implements \JsonSerializable {
protected $userId; // user for whom this preference is valid
@ -21,7 +19,7 @@ class Preference extends ReaderEntity implements \JsonSerializable {
protected $value; // preference value
protected $lastModified; // modification timestamp
public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'scope' => $this->getScope(),
@ -38,5 +36,52 @@ class Preference extends ReaderEntity implements \JsonSerializable {
'value' => $this->conditional_json_decode($this->getValue()),
];
}
}
public function getUserId() {
return $this->userId;
}
public function setUserId($userId) {
$this->userId = $userId;
}
public function getScope() {
return $this->scope;
}
public function setScope($scope) {
$this->scope = $scope;
}
public function getFileId() {
return $this->fileId;
}
public function setFileId($fileId) {
$this->fileId = $fileId;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
}
public function getValue() {
return $this->value;
}
public function setValue($value) {
$this->value = $value;
}
public function getLastModified() {
return $this->lastModified;
}
public function setLastModified($lastModified) {
$this->lastModified = $lastModified;
}
}

View File

@ -10,12 +10,13 @@
namespace OCA\Epubreader\Db;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCA\Epubreader\Utility\Time;
use OCP\IDBConnection;
class PreferenceMapper extends ReaderMapper {
private $userId;
public function __construct(IDBConnection $db, $UserId, Time $time) {
parent::__construct($db, 'reader_prefs', Preference::class, $time);
$this->userId = $UserId;
@ -29,7 +30,7 @@ class PreferenceMapper extends ReaderMapper {
* @param string $name
* @return array
*/
public function get($scope, $fileId, $name=null) {
public function get($scope, $fileId, $name = null) {
$query = $this->db->getQueryBuilder();
$query->select('*')
->from($this->getTableName())
@ -77,26 +78,4 @@ class PreferenceMapper extends ReaderMapper {
return $preference;
}
/* currently not used*/
public function deleteForFileId($fileId) {
$sql = "SELECT * FROM `*PREFIX*reader_prefs` 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_prefs` WHERE user_id=?";
$args = [ $userId ];
array_map(
function($entity) {
$this->delete($entity);
}, $this->findEntities($sql, $args)
);
}
}

View File

@ -14,6 +14,8 @@ use OCP\AppFramework\Db\Entity;
class ReaderEntity extends Entity {
private $lastModified;
/* returns decoded json if input is json, otherwise returns input */
public static function conditional_json_decode($el) {
$result = json_decode($el);
@ -24,16 +26,12 @@ class ReaderEntity extends Entity {
}
}
/*
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(),
];
public function getLastModified() {
return $this->lastModified;
}
*/
}
public function setLastModified($lastModified) {
$this->lastModified = $lastModified;
}
}

View File

@ -10,12 +10,15 @@
namespace OCA\Epubreader\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Db\Entity;
use OCA\Epubreader\Utility\Time;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;
/**
* @template-extends QBMapper<ReaderEntity>
*/
abstract class ReaderMapper extends QBMapper {
/**

View File

@ -10,11 +10,10 @@
namespace OCA\Epubreader;
use OCP\IDBConnection;
use OCP\Files\Node;
use OCP\IUser;
use OCP\Util;
use \OC\User\User as User;
use OCP\Files\Node;
use OCP\IDBConnection;
use OCP\Util;
class Hooks {

View File

@ -10,14 +10,13 @@
namespace OCA\Epubreader\Service;
use OCA\Epubreader\Db\BookmarkMapper;
class BookmarkService extends Service {
// "bookmark" name to use for the cursor (current reading position)
const CURSOR = '__CURSOR__';
const bookmark_type = 'bookmark';
public const CURSOR = '__CURSOR__';
public const bookmark_type = 'bookmark';
private $bookmarkMapper;
private $userId;
@ -38,10 +37,10 @@ class BookmarkService extends Service {
*
* @return array
*/
public function get($fileId, $name=null, $type=null) {
public function get($fileId, $name = null, $type = null) {
$result = $this->bookmarkMapper->get($fileId, $name, $type);
return array_map(
function($entity) {
function ($entity) {
return $entity->toService();
}, $result);
}
@ -57,7 +56,7 @@ class BookmarkService extends Service {
*
* @return array
*/
public function set($fileId, $name, $value, $type=null, $content=null) {
public function set($fileId, $name, $value, $type = null, $content = null) {
return $this->bookmarkMapper->set($fileId, $name, $value, $type, $content);
}
@ -94,7 +93,7 @@ class BookmarkService extends Service {
* @param string $name
*
*/
public function delete($fileId, $name, $type=null) {
public function delete($fileId, $name, $type = null) {
foreach ($this->bookmarkMapper->get($fileId, $name, $type) as $bookmark) {
$this->bookmarkMapper->delete($bookmark);
}
@ -110,4 +109,3 @@ class BookmarkService extends Service {
$this->delete($fileId, static::CURSOR, static::bookmark_type);
}
}

View File

@ -31,17 +31,7 @@ class MetadataService {
*
* @return array
*/
public function get($fileId, $name=null) {
if ($this->appManager->isInstalled('files_opds')) {
if ($meta = \OCA\Files_Opds\Meta::get($fileId)) {
if (!empty($name) && array_key_exists($name, $meta)) {
return [$item => $meta[$name]];
} else {
return $meta;
}
}
}
public function get($fileId, $name = null) {
return [];
}
@ -72,4 +62,3 @@ class MetadataService {
return [];
}
}

View File

@ -16,7 +16,7 @@ class PreferenceService extends Service {
// (ab)use the fact that $fileId never goes below 1 by using the
// value 0 to indicate a default preference
const DEFAULTS = 0;
public const DEFAULTS = 0;
private $preferenceMapper;
@ -40,10 +40,10 @@ class PreferenceService extends Service {
*
* @return array
*/
public function get($scope, $fileId, $name=null) {
public function get($scope, $fileId, $name = null) {
$result = $this->preferenceMapper->get($scope, $fileId, $name);
return array_map(
function($entity) {
function ($entity) {
return $entity->toService();
}, $result);
}
@ -73,7 +73,7 @@ class PreferenceService extends Service {
*
* @return array
*/
public function getDefault($scope, $name=null) {
public function getDefault($scope, $name = null) {
return $this->get($scope, static::DEFAULTS, $name);
}

View File

@ -16,10 +16,7 @@ abstract class Service {
protected $mapper;
public function __construct(ReaderMapper $mapper){
public function __construct(ReaderMapper $mapper) {
$this->mapper = $mapper;
}
}

View File

@ -12,11 +12,10 @@
namespace OCA\Epubreader\Settings;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;
use OCP\IConfig;
use OCP\Settings\ISettings;
class Personal implements ISettings
{
class Personal implements ISettings {
private $userId;
private $configManager;
@ -24,8 +23,7 @@ class Personal implements ISettings
public function __construct(
$userId,
IConfig $configManager
)
{
) {
$this->userId = $userId;
$this->configManager = $configManager;
}
@ -34,8 +32,7 @@ class Personal implements ISettings
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
* @since 9.1
*/
public function getForm()
{
public function getForm() {
$parameters = [
'EpubEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'epub_enable'),
@ -50,8 +47,7 @@ class Personal implements ISettings
*
* @return TemplateResponse
*/
public function getPanel()
{
public function getPanel() {
return $this->getForm();
}
@ -59,8 +55,7 @@ class Personal implements ISettings
* @return string the section ID, e.g. 'sharing'
* @since 9.1
*/
public function getSection()
{
public function getSection() {
return 'epubreader';
}
@ -69,8 +64,7 @@ class Personal implements ISettings
*
* @return string
*/
public function getSectionID()
{
public function getSectionID() {
return 'epubreader';
}
@ -82,8 +76,7 @@ class Personal implements ISettings
* E.g.: 70
* @since 9.1
*/
public function getPriority()
{
public function getPriority() {
return 10;
}
}

View File

@ -15,15 +15,13 @@ use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
class PersonalSection implements IIconSection
{
class PersonalSection implements IIconSection {
/** @var IURLGenerator */
private $urlGenerator;
/** @var IL10N */
private $l;
public function __construct(IURLGenerator $urlGenerator, IL10N $l)
{
public function __construct(IURLGenerator $urlGenerator, IL10N $l) {
$this->urlGenerator = $urlGenerator;
$this->l = $l;
}
@ -33,8 +31,7 @@ class PersonalSection implements IIconSection
*
* @returns string
*/
public function getIcon()
{
public function getIcon() {
return $this->urlGenerator->imagePath('epubreader', 'app.svg');
}
@ -43,8 +40,7 @@ class PersonalSection implements IIconSection
*
* @returns string
*/
public function getID()
{
public function getID() {
return 'epubreader';
}
@ -53,8 +49,7 @@ class PersonalSection implements IIconSection
*
* @return string
*/
public function getName()
{
public function getName() {
return $this->l->t('EPUB/CBZ/PDF ebook reader');
}
@ -63,8 +58,7 @@ class PersonalSection implements IIconSection
*
* @return int
*/
public function getPriority()
{
public function getPriority() {
return 20;
}
}

View File

@ -16,10 +16,9 @@ class Time {
}
/**
*
* @return int the current unix time in miliseconds
* @return string the current unix time in miliseconds
*/
public function getMicroTime() {
public function getMicroTime(): string {
list($millisecs, $secs) = explode(" ", microtime());
return $secs . substr($millisecs, 2, 6);
}

View File

@ -15,8 +15,7 @@ namespace OCA\Epubreader;
/**
* Config class for Reader
*/
class Config
{
class Config {
/**
* @brief get user config value
*

35
psalm.xml Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="lib" />
<directory name="stubs" />
</projectFiles>
<extraFiles>
<directory name="vendor" />
<ignoreFiles>
<directory name="vendor/psalm" />
</ignoreFiles>
</extraFiles>
<issueHandlers>
<UndefinedDocblockClass>
<errorLevel type="suppress">
<referencedClass name="OC\AppFramework\OCS\BaseResponse" />
<referencedClass name="Doctrine\DBAL\Schema\Schema" />
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
<referencedClass name="Doctrine\DBAL\Driver\Statement" />
<referencedClass name="Doctrine\DBAL\Schema\Table" />
</errorLevel>
</UndefinedDocblockClass>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="OC" />
</errorLevel>
</UndefinedClass>
</issueHandlers>
</psalm>

View File

@ -0,0 +1,53 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Hooks;
/**
* Class Emitter
*
* interface for all classes that are able to emit events
*
* @package OC\Hooks
* @deprecated 18.0.0 use events and the \OCP\EventDispatcher\IEventDispatcher service
*/
interface Emitter {
/**
* @param string $scope
* @param string $method
* @param callable $callback
* @return void
* @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener
*/
public function listen($scope, $method, callable $callback);
/**
* @param string $scope optional
* @param string $method optional
* @param callable $callback optional
* @return void
* @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher::removeListener
*/
public function removeListener($scope = null, $method = null, callable $callback = null);
}

View File

@ -1,28 +1,28 @@
<?php
/** @var array $_ */
/** @var OCP\IURLGenerator $urlGenerator */
$urlGenerator = $_['urlGenerator'];
$downloadLink = $_['downloadLink'];
$fileId = $_['fileId'];
$fileName = $_['fileName'];
$fileType = $_['fileType'];
$scope = $_['scope'];
$cursor = $_['cursor'];
$defaults = $_['defaults'];
$preferences = $_['preferences'];
$metadata = $_['metadata'];
$annotations = $_['annotations'];
$title = htmlentities(basename($downloadLink));
$revision = '0048';
$version = \OC::$server->getAppManager()->getAppVersion('epubreader') . '.' . $revision;
/** @var array $_ */
/** @var OCP\IURLGenerator $urlGenerator */
$urlGenerator = $_['urlGenerator'];
$downloadLink = $_['downloadLink'];
$fileId = $_['fileId'];
$fileName = $_['fileName'];
$fileType = $_['fileType'];
$scope = $_['scope'];
$cursor = $_['cursor'];
$defaults = $_['defaults'];
$preferences = $_['preferences'];
$metadata = $_['metadata'];
$annotations = $_['annotations'];
$title = htmlentities(basename($downloadLink));
$revision = '0048';
$version = \OC::$server->getAppManager()->getAppVersion('epubreader') . '.' . $revision;
/* Mobile safari, the new IE6 */
$idevice = (strstr($_SERVER['HTTP_USER_AGENT'],'iPhone')
|| strstr($_SERVER['HTTP_USER_AGENT'],'iPad')
|| strstr($_SERVER['HTTP_USER_AGENT'],'iPod'));
/* Mobile safari, the new IE6 */
$idevice = (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')
|| strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')
|| strstr($_SERVER['HTTP_USER_AGENT'], 'iPod'));
/* Owncloud currently does not implement CSPv3, remove this test when it does */
$nonce = class_exists('\OC\Security\CSP\ContentSecurityPolicyNonceManager')
/* Owncloud currently does not implement CSPv3, remove this test when it does */
$nonce = class_exists('\OC\Security\CSP\ContentSecurityPolicyNonceManager')
? \OC::$server->getContentSecurityPolicyNonceManager()->getNonce()
: 'nonce_not_implemented';
?>
@ -32,7 +32,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- <base href="<?php p($urlGenerator->linkTo('epubreader',''));?>"> -->
<!-- <base href="<?php p($urlGenerator->linkTo('epubreader', ''));?>"> -->
<title>
<?php p($title);?>
</title>

View File

@ -1,28 +1,28 @@
<?php
/** @var array $_ */
/** @var OCP\IURLGenerator $urlGenerator */
$urlGenerator = $_['urlGenerator'];
$downloadLink = $_['downloadLink'];
$fileId = $_['fileId'];
$fileName = $_['fileName'];
$fileType = $_['fileType'];
$scope = $_['scope'];
$cursor = $_['cursor'];
$defaults = $_['defaults'];
$preferences = $_['preferences'];
$metadata = $_['metadata'];
$annotations = $_['annotations'];
$title = htmlentities(basename($downloadLink));
$revision = '0072';
$version = \OC::$server->getAppManager()->getAppVersion('epubreader') . '.' . $revision;
/** @var array $_ */
/** @var OCP\IURLGenerator $urlGenerator */
$urlGenerator = $_['urlGenerator'];
$downloadLink = $_['downloadLink'];
$fileId = $_['fileId'];
$fileName = $_['fileName'];
$fileType = $_['fileType'];
$scope = $_['scope'];
$cursor = $_['cursor'];
$defaults = $_['defaults'];
$preferences = $_['preferences'];
$metadata = $_['metadata'];
$annotations = $_['annotations'];
$title = htmlentities(basename($downloadLink));
$revision = '0072';
$version = \OC::$server->getAppManager()->getAppVersion('epubreader') . '.' . $revision;
/* Mobile safari, the new IE6 */
$idevice = (strstr($_SERVER['HTTP_USER_AGENT'],'iPhone')
|| strstr($_SERVER['HTTP_USER_AGENT'],'iPad')
|| strstr($_SERVER['HTTP_USER_AGENT'],'iPod'));
/* Mobile safari, the new IE6 */
$idevice = (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')
|| strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')
|| strstr($_SERVER['HTTP_USER_AGENT'], 'iPod'));
/* Owncloud currently does not implement CSPv3, remove this test when it does */
$nonce = class_exists('\OC\Security\CSP\ContentSecurityPolicyNonceManager')
/* Owncloud currently does not implement CSPv3, remove this test when it does */
$nonce = class_exists('\OC\Security\CSP\ContentSecurityPolicyNonceManager')
? \OC::$server->getContentSecurityPolicyNonceManager()->getNonce()
: 'nonce_not_implemented';
?>
@ -32,7 +32,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- <base href="<?php p($urlGenerator->linkTo('epubreader',''));?>"> -->
<!-- <base href="<?php p($urlGenerator->linkTo('epubreader', ''));?>"> -->
<title>
<?php p($title);?>
</title>
@ -113,21 +113,21 @@
<div class="control-group">
<div>
<input type="checkbox" id="custom_font_family" name="font_family">
<label for="custom_font_family"><?php print ($l->t ('custom font')); ?></label>
<label for="custom_font_family"><?php print($l->t('custom font')); ?></label>
<select id="font_family" disabled="">
<option value="verdana, trebuchet, droid sans serif, sans, sans-serif"> sans </option>
<option value="georgia, times new roman, droid serif, serif"> serif </option>
<option value="monospace"><?php print ($l->t ('monospace')); ?> </option>
<option value="monospace"><?php print($l->t('monospace')); ?> </option>
</select>
</div>
<div>
<input type="checkbox" id="custom_font_size" name="font_size">
<label for="custom_font_size"><?php print ($l->t ('font size')); ?></label>
<label for="custom_font_size"><?php print($l->t('font size')); ?></label>
<input type="number" id="font_size" value="100" min="50" max="150" disabled=""> %
</div>
<div>
<input type="checkbox" id="custom_font_weight" name="font_weight">
<label for="custom_font_weight"><?php print ($l->t ('font weight')); ?></label>
<label for="custom_font_weight"><?php print($l->t('font weight')); ?></label>
<select id="font_weight" disabled="">
<option value="100">thin</option>
<option value="200">extra light</option>
@ -154,7 +154,7 @@
<div class="control-group">
<input type="checkbox" id="use_custom_colors" name="use_custom_colors">
<label for="use_custom_colors">
<?php print ($l->t ('Use custom colors')); ?>;
<?php print($l->t('Use custom colors')); ?>;
</label>
<div class="center-box">
<input type="color" id="day_color" value="#0a0a0a">
@ -172,7 +172,7 @@
<legend>night</legend>
<div class="control-group">
<div class="center-box nightshift">
<?php print ($l->t ('night mode can be toggled by clicking the book title')); ?>;
<?php print($l->t('night mode can be toggled by clicking the book title')); ?>;
</div>
<div class="center-box">
<input type="color" id="night_color" value="#454545">
@ -202,19 +202,19 @@
<div class="control-group">
<input type="checkbox" id="sidebarReflow" name="sidebarReflow">
<label for="sidebarReflow">
<?php print ($l->t ('reflow text when sidebars are open')); ?>;
<?php print($l->t('reflow text when sidebars are open')); ?>;
</label>
</div>
<div class="control-group">
<input type="checkbox" id="touch_nav" name="touch_nav">
<label for="touch_nav">
<?php print ($l->t ('disable extra-wide page turn areas')); ?>;
<?php print($l->t('disable extra-wide page turn areas')); ?>;
</label>
</div>
<div class="control-group">
<input type="checkbox" id="page_turn_arrows" name="page_turn_arrows">
<label for="page_turn_arrows">
<?php print ($l->t ('show page turn arrows')); ?>;
<?php print($l->t('show page turn arrows')); ?>;
</label>
</div>

View File

@ -1,28 +1,28 @@
<?php
/** @var array $_ */
/** @var OCP\IURLGenerator $urlGenerator */
$urlGenerator = $_['urlGenerator'];
$downloadLink = $_['downloadLink'];
$fileId = $_['fileId'];
$fileName = $_['fileName'];
$fileType = $_['fileType'];
$scope = $_['scope'];
$cursor = $_['cursor'];
$defaults = $_['defaults'];
$preferences = $_['preferences'];
$metadata = $_['metadata'];
$annotations = $_['annotations'];
$title = htmlentities(basename($downloadLink));
$revision = '0130';
$version = \OC::$server->getAppManager()->getAppVersion('epubreader') . '.' . $revision;
/** @var array $_ */
/** @var OCP\IURLGenerator $urlGenerator */
$urlGenerator = $_['urlGenerator'];
$downloadLink = $_['downloadLink'];
$fileId = $_['fileId'];
$fileName = $_['fileName'];
$fileType = $_['fileType'];
$scope = $_['scope'];
$cursor = $_['cursor'];
$defaults = $_['defaults'];
$preferences = $_['preferences'];
$metadata = $_['metadata'];
$annotations = $_['annotations'];
$title = htmlentities(basename($downloadLink));
$revision = '0130';
$version = \OC::$server->getAppManager()->getAppVersion('epubreader') . '.' . $revision;
/* Mobile safari, the new IE6 */
$idevice = (strstr($_SERVER['HTTP_USER_AGENT'],'iPhone')
|| strstr($_SERVER['HTTP_USER_AGENT'],'iPad')
|| strstr($_SERVER['HTTP_USER_AGENT'],'iPod'));
/* Mobile safari, the new IE6 */
$idevice = (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')
|| strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')
|| strstr($_SERVER['HTTP_USER_AGENT'], 'iPod'));
/* Owncloud currently does not implement CSPv3, remove this test when it does */
$nonce = class_exists('\OC\Security\CSP\ContentSecurityPolicyNonceManager')
/* Owncloud currently does not implement CSPv3, remove this test when it does */
$nonce = class_exists('\OC\Security\CSP\ContentSecurityPolicyNonceManager')
? \OC::$server->getContentSecurityPolicyNonceManager()->getNonce()
: 'nonce_not_implemented';
?>
@ -32,7 +32,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- <base href="<?php p($urlGenerator->linkTo('epubreader',''));?>"> -->
<!-- <base href="<?php p($urlGenerator->linkTo('epubreader', ''));?>"> -->
<title>
<?php p($title);?>
</title>

View File

@ -19,7 +19,9 @@ style('epubreader', 'settings');
<p>
<input type="checkbox" name="EpubEnable" id="EpubEnable" class="checkbox"
value="1" <?php if ($_['EpubEnable'] === "true") print_unescaped('checked="checked"'); ?> />
value="1" <?php if ($_['EpubEnable'] === "true") {
print_unescaped('checked="checked"');
} ?> />
<label for="EpubEnable">
<?php p($l->t('Epub'));?>
</label>
@ -27,14 +29,18 @@ style('epubreader', 'settings');
<p>
<input type="checkbox" name="PdfEnable" id="PdfEnable" class="checkbox"
value="1" <?php if ($_['PdfEnable'] === "true") print_unescaped('checked="checked"'); ?> />
value="1" <?php if ($_['PdfEnable'] === "true") {
print_unescaped('checked="checked"');
} ?> />
<label for="PdfEnable">
<?php p($l->t('PDF'));?>
</label><br/>
</p>
<p>
<input type="checkbox" name="CbxEnable" id="CbxEnable" class="checkbox"
value="1" <?php if ($_['CbxEnable'] === "true") print_unescaped('checked="checked"'); ?> />
value="1" <?php if ($_['CbxEnable'] === "true") {
print_unescaped('checked="checked"');
} ?> />
<label for="CbxEnable">
<?php p($l->t('CBR/CBZ'));?>
</label><br/>