This repository has been archived on 2024-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
epubreader/lib/Hooks.php

66 lines
2.6 KiB
PHP
Raw Normal View History

2020-04-21 20:37:42 +00:00
<?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\Epubreader;
2020-04-21 20:37:42 +00:00
2023-06-16 22:07:40 +00:00
use OCA\Epubreader\AppInfo\Application;
use OCP\IConfig;
2023-06-16 14:58:23 +00:00
use OCP\IDBConnection;
2023-06-16 22:52:17 +00:00
use OCP\IUserSession;
2023-06-16 22:07:40 +00:00
use OCP\Server;
2020-04-21 20:37:42 +00:00
class Hooks {
2023-06-17 10:01:19 +00:00
public static function announce_settings(array $settings): void {
2023-06-16 14:58:23 +00:00
// Nextcloud encodes this as JSON, Owncloud does not (yet) (#75)
2023-06-16 22:07:40 +00:00
// TODO: remove this when Owncloud starts encoding oc_appconfig as JSON just like it already encodes most other properties
2023-06-16 22:52:17 +00:00
$user = Server::get(IUserSession::class)->getUser();
if ($user &&
array_key_exists('array', $settings) &&
2023-06-16 19:31:46 +00:00
is_array($settings['array']) &&
array_key_exists('oc_appconfig', $settings['array'])
) {
$isJson = self::isJson($settings['array']['oc_appconfig']);
/** @var array $array */
$array = ($isJson) ? json_decode((string) $settings['array']['oc_appconfig'], true) : $settings['array']['oc_appconfig'];
$array['filesReader'] = [
2023-06-16 22:52:17 +00:00
'enableEpub' => Server::get(IConfig::class)->getUserValue($user->getUID(), Application::APP_ID, 'epub_enable', 'true'),
'enablePdf' => Server::get(IConfig::class)->getUserValue($user->getUID(), Application::APP_ID, 'pdf_enable', 'true'),
'enableCbx' => Server::get(IConfig::class)->getUserValue($user->getUID(), Application::APP_ID, 'cbx_enable', 'true'),
2023-06-16 19:31:46 +00:00
];
$settings['array']['oc_appconfig'] = ($isJson) ? json_encode($array) : $array;
}
2023-06-16 14:58:23 +00:00
}
2020-04-21 20:37:42 +00:00
2023-06-17 10:12:40 +00:00
protected static function deleteFile(IDBConnection $connection, int $fileId): void {
2023-06-16 14:58:23 +00:00
$queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_bookmarks')->where('file_id = file_id')->setParameter('file_id', $fileId);
2023-06-16 19:20:03 +00:00
$queryBuilder->executeStatement();
2020-04-21 20:37:42 +00:00
2023-06-16 14:58:23 +00:00
$queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_prefs')->where('file_id = file_id')->setParameter('file_id', $fileId);
2023-06-16 19:20:03 +00:00
$queryBuilder->executeStatement();
2023-06-16 14:58:23 +00:00
}
2020-04-21 20:37:42 +00:00
2023-06-17 10:12:40 +00:00
protected static function deleteUser(IDBConnection $connection, string $userId): void {
2023-06-16 14:58:23 +00:00
$queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_bookmarks')->where('user_id = user_id')->setParameter('user_id', $userId);
2023-06-16 19:20:03 +00:00
$queryBuilder->executeStatement();
2020-04-21 20:37:42 +00:00
2023-06-16 14:58:23 +00:00
$queryBuilder = $connection->getQueryBuilder();
$queryBuilder->delete('reader_prefs')->where('user_id = user_id')->setParameter('user_id', $userId);
2023-06-16 19:20:03 +00:00
$queryBuilder->executeStatement();
2023-06-16 14:58:23 +00:00
}
2020-04-21 20:37:42 +00:00
2023-06-17 10:01:19 +00:00
private static function isJson(mixed $string): bool {
2023-06-16 14:58:23 +00:00
return is_string($string) && is_array(json_decode($string, true)) && (json_last_error() == JSON_ERROR_NONE) ? true : false;
}
2020-04-21 20:37:42 +00:00
}