Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions files_opds/ajax/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace OCA\Files_Opds;

\OCP\JSON::callCheck();
\OCP\JSON::checkLoggedIn();
\OC_JSON::callCheck();
\OC_JSON::checkLoggedIn();
$defaults = new \OC_Defaults();

$l = \OC::$server->getL10N('files_opds');
Expand Down Expand Up @@ -53,7 +53,7 @@
Config::setPreview('OC\Preview\MSOffice2007',$opdsPreviewMsOffice);
}

\OCP\JSON::success(
\OC_JSON::success(
array(
'data' => array('message'=> $l->t('Settings updated successfully.'))
)
Expand Down
6 changes: 3 additions & 3 deletions files_opds/ajax/clear_bookshelf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

$l = \OC::$server->getL10N('files_opds');

\OCP\JSON::checkLoggedIn();
\OCP\JSON::callCheck();
\OC_JSON::checkLoggedIn();
\OC_JSON::callCheck();

Bookshelf::clear();
\OCP\JSON::success(array( "data" => array( "message" => $l->t("Bookshelf cleared"))));
\OC_JSON::success(array( "data" => array( "message" => $l->t("Bookshelf cleared"))));
10 changes: 5 additions & 5 deletions files_opds/ajax/personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

namespace OCA\Files_Opds;

\OCP\JSON::callCheck();
\OCP\JSON::checkLoggedIn();
\OC_JSON::callCheck();
\OC_JSON::checkLoggedIn();

$l = \OC::$server->getL10N('files_opds');

$opdsEnable = isset($_POST['opdsEnable']) ? $_POST['opdsEnable'] : 'false';
$rootPath = isset($_POST['rootPath']) ? $_POST['rootPath'] : '/Library';
$fileTypes = isset($_POST['fileTypes']) ? $_POST['fileTypes'] : '';
$skipList = isset($_POST['skipList']) ? $_POST['skipList'] : 'metadata.opf,cover.jpg';
$feedTitle = isset($_POST['feedTitle']) ? $_POST['feedTitle'] : $l->t("%s's Library", \OCP\User::getDisplayName());
$feedTitle = isset($_POST['feedTitle']) ? $_POST['feedTitle'] : $l->t("%s's Library", \OC_User::getDisplayName());

if (!strlen($rootPath) ||
\OC\Files\Filesystem::isValidPath($rootPath) === false ||
\OC\Files\Filesystem::file_exists($rootPath) === false ) {
\OCP\JSON::error(
\OC_JSON::error(
array(
'data' => array('message'=> $l->t('Directory does not exist!'))
)
Expand All @@ -39,7 +39,7 @@
Config::set('feed_title', $feedTitle);
Config::set('id', Util::genUuid());

\OCP\JSON::success(
\OC_JSON::success(
array(
'data' => array('message'=> $l->t('Settings updated successfully.'))
)
Expand Down
6 changes: 3 additions & 3 deletions files_opds/ajax/schedule_rescan.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

$l = \OC::$server->getL10N('files_opds');

\OCP\JSON::checkLoggedIn();
\OCP\JSON::callCheck();
\OC_JSON::checkLoggedIn();
\OC_JSON::callCheck();

Meta::rescan();
\OCP\JSON::success(array( "data" => array( "message" => $l->t("Rescan scheduled"))));
\OC_JSON::success(array( "data" => array( "message" => $l->t("Rescan scheduled"))));
7 changes: 5 additions & 2 deletions files_opds/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ See [README] for more information on (mis)features of this app.
<database>sqlite</database>
<database>mysql</database>
<owncloud min-version="8.2" max-version="10.0" />
<nextcloud min-version="8.1" max-version="13.0" />
<nextcloud min-version="8.1" max-version="16.0" />
</dependencies>
<settings>
<admin>OCA\Files_Opds\Settings\Admin</admin>
<admin>OCA\Files_Opds\Settings\Admin</admin>
<admin-section>OCA\Files_Opds\Settings\AdminSection</admin-section>
<personal>OCA\Files_Opds\Settings\Personal</personal>
<personal-section>OCA\Files_Opds\Settings\PersonalSection</personal-section>
</settings>
<ocsid>168132</ocsid>
</info>
Expand Down
89 changes: 89 additions & 0 deletions files_opds/lib/Settings/PersonalSection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\File_Opds\Settings;

use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;

class PersonalSection implements IIconSection {

/** @var IL10N */
private $l;

/** @var IURLGenerator */
private $url;

/**
* @param IURLGenerator $url
* @param IL10N $l
*/
public function __construct(IURLGenerator $url, IL10N $l) {
$this->url = $url;
$this->l = $l;
}

/**
* returns the relative path to an 16*16 icon describing the section.
* e.g. '/core/img/places/files.svg'
*
* @returns string
* @since 16.0
*/
public function getIcon() {
return $this->url->imagePath('files_opds', 'files_opds-dark.svg');
}

/**
* returns the ID of the section. It is supposed to be a lower case string,
* e.g. 'ldap'
*
* @returns string
* @since 16.0
*/
public function getID() {
return 'files_opds';
}

/**
* returns the translated name as it should be displayed, e.g. 'LDAP / AD
* integration'. Use the L10N service to translate it.
*
* @return string
* @since 16.0
*/
public function getName() {
return $this->l->t('OPDS Library');
}

/**
* @return int whether the form should be rather on the top or bottom of
* the settings navigation. The sections are arranged in ascending order of
* the priority values. It is required to return a value between 0 and 99.
*
* E.g.: 70
* @since 16.0
*/
public function getPriority() {
return 10;
}
}
16 changes: 8 additions & 8 deletions files_opds/lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Config
* @return string retrieved value or default
*/
public static function get($key, $default) {
return \OCP\Config::getUserValue(\OCP\User::getUser(), 'files_opds', $key, $default);
return \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'files_opds', $key, $default);
}

/**
Expand All @@ -36,7 +36,7 @@ public static function get($key, $default) {
* @return bool success
*/
public static function set($key, $value) {
return \OCP\Config::setUserValue(\OCP\User::getUser(), 'files_opds', $key, $value);
return \OC::$server->getConfig()->setUserValue(\OC_User::getUser(), 'files_opds', $key, $value);
}

/**
Expand All @@ -47,7 +47,7 @@ public static function set($key, $value) {
* @return string retrieved value or default
*/
public static function getApp($key, $default) {
return \OCP\Config::getAppValue('files_opds', $key, $default);
return \OC::$server->getConfig()->getAppValue('files_opds', $key, $default);
}

/**
Expand All @@ -58,7 +58,7 @@ public static function getApp($key, $default) {
* @return bool success
*/
public static function setApp($key, $value) {
return \OCP\Config::setAppValue('files_opds', $key, $value);
return \OC::$server->getConfig()->setAppValue('files_opds', $key, $value);
}

/**
Expand All @@ -68,7 +68,7 @@ public static function setApp($key, $value) {
* @return bool (true = enabled, false = disabled)
*/
public static function getPreview($format) {
$enablePreviewProviders = \OCP\Config::getSystemValue('enabledPreviewProviders', null);
$enablePreviewProviders = \OC::$server->getConfig()->getSystemValue('enabledPreviewProviders', null);
if (!($enablePreviewProviders === null)) {
return in_array($format, $enablePreviewProviders);
}
Expand All @@ -83,7 +83,7 @@ public static function getPreview($format) {
* @return bool
*/
public static function setPreview($format, $enable = 'false') {
$enablePreviewProviders = \OCP\Config::getSystemValue('enabledPreviewProviders', null);
$enablePreviewProviders = \OC::$server->getConfig()->getSystemValue('enabledPreviewProviders', null);
if ($enable == 'true') {
if ($enablePreviewProviders === null) {
// set up default providers
Expand All @@ -103,8 +103,8 @@ public static function setPreview($format, $enable = 'false') {
}
}

if (!(\OCP\Config::setSystemValue('enabledPreviewProviders', $enablePreviewProviders))) {
logWarn("Failed to enable " . $format . " preview provider (config.php readonly?)");
if (!(\OC::$server->getConfig()->setSystemValue('enabledPreviewProviders', $enablePreviewProviders))) {
Util::logWarn("Failed to enable " . $format . " preview provider (config.php readonly?)");
return true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions files_opds/lib/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function getFeedId() {
* @param int $id file id
*/
public static function serveFile($path, $id) {
\OCP\User::checkLoggedIn();
\OC_JSON::checkLoggedIn();
\OC::$server->getSession()->close();
Bookshelf::add($id);
$dirName = dirname($path);
Expand Down Expand Up @@ -66,8 +66,8 @@ public static function serveFeed($dir, $id, $type) {
$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"));
$tmpl->assign('user', \OC_User::getDisplayName());
$tmpl->assign('feed_title', Config::get('feed_title',\OC_User::getDisplayName() . "'s Library"));
$tmpl->assign('feed_subtitle', Config::getApp('feed_subtitle', $defaults->getName() . " OPDS catalog"));
$tmpl->assign('feed_updated', time());
$tmpl->printPage();
Expand All @@ -82,7 +82,7 @@ public static function serveFeed($dir, $id, $type) {
* @param string type type of preview requested
*/
public static function servePreview($path, $type) {
\OCP\User::checkLoggedIn();
\OC_Join::checkLoggedIn();
\OC::$server->getSession()->close();
$i = \OC\Files\Filesystem::getFileInfo($path,false);

Expand Down
25 changes: 13 additions & 12 deletions files_opds/lib/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

namespace OCA\Files_Opds;
use OCP\ILogger;

/**
* Meta (data) class for OPDS
Expand Down Expand Up @@ -61,13 +62,13 @@ public static function isValid($meta) {
*
* @return array or false
*/
protected static function load($id) {
protected static function xload($id) {
$sql = 'SELECT * FROM `*PREFIX*opds_metadata` WHERE id = ?';
$args = array($id);
$query = \OCP\DB::prepare($sql);
$query = \OC_DB::prepare($sql);
$result = $query->execute($args);

return ($row = $result->fetchRow()) ? $row : false;
return ($row = $result->fetch()) ? $row : false;
}

/**
Expand All @@ -79,9 +80,9 @@ protected static function load($id) {
protected static function save($meta) {
$sql = "SELECT `id` FROM *PREFIX*opds_metadata WHERE `id`=?";
$args = array($meta['id']);
$query = \OCP\DB::prepare($sql);
$query = \OC_DB::prepare($sql);
$result = $query->execute($args);
$data = $result->fetchRow();
$data = $result->fetch();
if (isset($data['id'])) {
$sql = "UPDATE *PREFIX*opds_metadata SET `updated`=?, `date`=?, `author`=?, `title`=?, `language`=?, `publisher`=?, `isbn`=?, `copyright`=?, `description`=?, `subjects`=?, `cover`=?, `rescan`=? WHERE id=?";
$args = array(
Expand All @@ -99,7 +100,6 @@ protected static function save($meta) {
$meta['rescan'],
$meta['id']
);

} else {
$sql = "INSERT INTO *PREFIX*opds_metadata (`id`, `updated`, `date`, `author`, `title`, `language`, `publisher`, `isbn`, `copyright`, `description`, `subjects`, `cover`, `rescan`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
$args = array(
Expand All @@ -117,8 +117,9 @@ protected static function save($meta) {
$meta['cover'],
$meta['rescan']
);

}
$query = \OCP\DB::prepare($sql);
$query = \OC_DB::prepare($sql);

return $query->execute($args);
}
Expand All @@ -132,7 +133,7 @@ protected static function save($meta) {
* @return array of metadata
*/
public static function get($id) {
if (!($meta = self::load($id)) || (isset($meta['rescan']) && time() > strtotime($meta['rescan']))) {
if (!($meta = self::xload($id)) || (isset($meta['rescan']) && time() > strtotime($meta['rescan']))) {
if(isset($meta['rescan'])) {
$meta['rescan'] = null;
}
Expand All @@ -150,7 +151,7 @@ public static function get($id) {
public static function remove($id) {
$sql = "DELETE FROM *PREFIX*opds_metadata WHERE `id`=?";
$args = array($id);
$query = \OCP\DB::prepare($sql);
$query = \OC_DB::prepare($sql);

return $query->execute($args);
}
Expand All @@ -162,7 +163,7 @@ public static function remove($id) {
public static function rescan() {
$sql = "UPDATE *PREFIX*opds_metadata SET `rescan`=?";
$args = array(date("Y-m-d H:i:s"));
$query = \OCP\DB::prepare($sql);
$query = \OC_DB::prepare($sql);
$result = $query->execute($args);
}

Expand Down Expand Up @@ -229,7 +230,7 @@ public static function epub($path,&$meta) {
$meta['subjects'] = json_encode($epub->Subjects());
}
} catch (\Exception $e) {
\OCP\Util::writeLog(get_class(), $e->getMessage(), \OCP\Util::ERROR);
\OCP\Util::writeLog(get_class(), $e->getMessage(), ILogger::ERROR);
}
}

Expand Down Expand Up @@ -257,7 +258,7 @@ public static function fb2($path,&$meta) {
$meta['subjects'] = json_encode($fb2->Subjects());
}
} catch (\Exception $e) {
\OCP\Util::writeLog(get_class(), $e->getMessage(), \OCP\Util::ERROR);
\OCP\Util::writeLog(get_class(), $e->getMessage(), ILogger::ERROR);
}
}

Expand Down
Loading