Merge remote-tracking branch 'sysadminstory/fix-settings'
This commit is contained in:
commit
342a57ee70
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ownCloud - Epubreader App
|
|
||||||
*
|
|
||||||
* @author Frank de Lange
|
|
||||||
* @copyright 2014,2018 Frank de Lange
|
|
||||||
*
|
|
||||||
* This file is licensed under the Affero General Public License version 3 or
|
|
||||||
* later.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace OCA\Epubreader;
|
|
||||||
|
|
||||||
\OC_JSON::callCheck();
|
|
||||||
\OC_JSON::checkLoggedIn();
|
|
||||||
|
|
||||||
$l = \OC::$server->getL10N('epubreader');
|
|
||||||
|
|
||||||
$EpubEnable = isset($_POST['EpubEnable']) ? $_POST['EpubEnable'] : 'false';
|
|
||||||
$PdfEnable = isset($_POST['PdfEnable']) ? $_POST['PdfEnable'] : 'false';
|
|
||||||
$CbxEnable = isset($_POST['CbxEnable']) ? $_POST['CbxEnable'] : 'false';
|
|
||||||
|
|
||||||
Config::set('epub_enable', $EpubEnable);
|
|
||||||
Config::set('pdf_enable', $PdfEnable);
|
|
||||||
Config::set('cbx_enable', $CbxEnable);
|
|
||||||
|
|
||||||
\OC_JSON::success(
|
|
||||||
array(
|
|
||||||
'data' => array('message'=> $l->t('Settings updated successfully.'))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
exit();
|
|
||||||
|
|
@ -19,4 +19,3 @@ $l = \OC::$server->getL10N('epubreader');
|
|||||||
|
|
||||||
\OCA\Epubreader\Hooks::register();
|
\OCA\Epubreader\Hooks::register();
|
||||||
Util::addscript('epubreader', 'plugin');
|
Util::addscript('epubreader', 'plugin');
|
||||||
\OCP\App::registerPersonal('epubreader', 'personal');
|
|
||||||
|
@ -48,4 +48,8 @@ See [README] for more exhaustive information on features and potential misfeatur
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<nextcloud min-version="21" max-version="23"/>
|
<nextcloud min-version="21" max-version="23"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<settings>
|
||||||
|
<personal>OCA\Epubreader\Settings\Personal</personal>
|
||||||
|
<personal-section>OCA\Epubreader\Settings\PersonalSection</personal-section>
|
||||||
|
</settings>
|
||||||
</info>
|
</info>
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
* later.
|
* later.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$this->create('reader_personal_settings', 'ajax/personal.php')->actionInclude('epubreader/ajax/personal.php');
|
|
||||||
|
|
||||||
return ['routes' => [
|
return ['routes' => [
|
||||||
// Page
|
// Page
|
||||||
['name' => 'page#showReader', 'url' => '/', 'verb' => 'GET'],
|
['name' => 'page#showReader', 'url' => '/', 'verb' => 'GET'],
|
||||||
@ -36,5 +34,8 @@ return ['routes' => [
|
|||||||
['name' => 'preference#get', 'url' => '/preference/{fileId}/{scope}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']],
|
['name' => 'preference#get', 'url' => '/preference/{fileId}/{scope}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']],
|
||||||
['name' => 'preference#set', 'url' => '/preference', 'verb' => 'POST'],
|
['name' => 'preference#set', 'url' => '/preference', 'verb' => 'POST'],
|
||||||
['name' => 'preference#delete', 'url' => '/preference/{fileId}/{scope}/{name}', 'verb' => 'DELETE'],
|
['name' => 'preference#delete', 'url' => '/preference/{fileId}/{scope}/{name}', 'verb' => 'DELETE'],
|
||||||
|
|
||||||
|
// User Settings
|
||||||
|
['name' => 'settings#setPreference', 'url' => '/settings/set', 'verb' => 'POST'],
|
||||||
]];
|
]];
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
OC.msg.startSaving('#reader-personal .msg');
|
OC.msg.startSaving('#reader-personal .msg');
|
||||||
$.post(OC.filePath('epubreader', 'lib', 'personal-back.php'), data, readerSettings.afterSave);
|
$.post(OC.generateUrl('apps/epubreader/settings/set'), data, readerSettings.afterSave);
|
||||||
},
|
},
|
||||||
afterSave : function(data){
|
afterSave : function(data){
|
||||||
OC.msg.finishedSaving('#reader-personal .msg', data);
|
OC.msg.finishedSaving('#reader-personal .msg', data);
|
||||||
|
@ -9,7 +9,7 @@ window.addEventListener('DOMContentLoaded', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
OC.msg.startSaving('#reader-personal .msg');
|
OC.msg.startSaving('#reader-personal .msg');
|
||||||
$.post(OC.filePath('epubreader', 'ajax', 'personal.php'), data, readerSettings.afterSave);
|
$.post(OC.generateUrl('apps/epubreader/settings/set'), data, readerSettings.afterSave);
|
||||||
},
|
},
|
||||||
afterSave : function(data){
|
afterSave : function(data){
|
||||||
OC.msg.finishedSaving('#reader-personal .msg', data);
|
OC.msg.finishedSaving('#reader-personal .msg', data);
|
||||||
|
69
lib/Controller/SettingsController.php
Normal file
69
lib/Controller/SettingsController.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ownCloud - Epubreader App
|
||||||
|
*
|
||||||
|
* @author Frank de Lange
|
||||||
|
* @copyright 2014,2018 Frank de Lange
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Epubreader\Controller;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
private $urlGenerator;
|
||||||
|
private $preferenceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $AppName
|
||||||
|
* @param IRequest $request
|
||||||
|
* @param IURLGenerator $urlGenerator
|
||||||
|
* @param PreferenceService $preferenceService
|
||||||
|
*/
|
||||||
|
public function __construct($AppName,
|
||||||
|
IRequest $request,
|
||||||
|
IURLGenerator $urlGenerator,
|
||||||
|
PreferenceService $preferenceService ) {
|
||||||
|
|
||||||
|
parent::__construct($AppName, $request);
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
$this->preferenceService = $preferenceService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief set preference for file type association
|
||||||
|
*
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* @param int $EpubEnable
|
||||||
|
* @param int $EpubEnable
|
||||||
|
* @param int $CbxEnable
|
||||||
|
*
|
||||||
|
* @return array|\OCP\AppFramework\Http\JSONResponse
|
||||||
|
*/
|
||||||
|
public function setPreference(string $EpubEnable, string $PdfEnable, string $CbxEnable) {
|
||||||
|
|
||||||
|
$l = \OC::$server->getL10N('epubreader');
|
||||||
|
|
||||||
|
Config::set('epub_enable', $EpubEnable);
|
||||||
|
Config::set('pdf_enable', $PdfEnable);
|
||||||
|
Config::set('cbx_enable', $CbxEnable);
|
||||||
|
|
||||||
|
$response = array(
|
||||||
|
'data' => array('message'=> $l->t('Settings updated successfully.')),
|
||||||
|
'status' => 'success'
|
||||||
|
);
|
||||||
|
|
||||||
|
return new JSONResponse($response);
|
||||||
|
}
|
||||||
|
}
|
89
lib/Settings/Personal.php
Normal file
89
lib/Settings/Personal.php
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ownCloud - Epubreader App
|
||||||
|
*
|
||||||
|
* @author Frank de Lange
|
||||||
|
* @copyright 2014,2018 Frank de Lange
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Epubreader\Settings;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\Settings\ISettings;
|
||||||
|
use OCP\IConfig;
|
||||||
|
|
||||||
|
class Personal implements ISettings
|
||||||
|
{
|
||||||
|
|
||||||
|
private $userId;
|
||||||
|
private $configManager;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
$userId,
|
||||||
|
IConfig $configManager
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$this->userId = $userId;
|
||||||
|
$this->configManager = $configManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
|
||||||
|
* @since 9.1
|
||||||
|
*/
|
||||||
|
public function getForm()
|
||||||
|
{
|
||||||
|
|
||||||
|
$parameters = [
|
||||||
|
'EpubEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'epub_enable'),
|
||||||
|
'PdfEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'pdf_enable'),
|
||||||
|
'CbxEnable' => $this->configManager->getUserValue($this->userId, 'epubreader', 'cbx_enable'),
|
||||||
|
];
|
||||||
|
return new TemplateResponse('epubreader', 'settings-personal', $parameters, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print config section (ownCloud 10)
|
||||||
|
*
|
||||||
|
* @return TemplateResponse
|
||||||
|
*/
|
||||||
|
public function getPanel()
|
||||||
|
{
|
||||||
|
return $this->getForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string the section ID, e.g. 'sharing'
|
||||||
|
* @since 9.1
|
||||||
|
*/
|
||||||
|
public function getSection()
|
||||||
|
{
|
||||||
|
return 'epubreader';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get section ID (ownCloud 10)
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getSectionID()
|
||||||
|
{
|
||||||
|
return 'epubreader';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int whether the form should be rather on the top or bottom of
|
||||||
|
* the admin section. The forms are arranged in ascending order of the
|
||||||
|
* priority values. It is required to return a value between 0 and 100.
|
||||||
|
*
|
||||||
|
* E.g.: 70
|
||||||
|
* @since 9.1
|
||||||
|
*/
|
||||||
|
public function getPriority()
|
||||||
|
{
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
}
|
70
lib/Settings/PersonalSection.php
Normal file
70
lib/Settings/PersonalSection.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ownCloud - Epubreader App
|
||||||
|
*
|
||||||
|
* @author Frank de Lange
|
||||||
|
* @copyright 2014,2018 Frank de Lange
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\Epubreader\Settings;
|
||||||
|
|
||||||
|
use OCP\IL10N;
|
||||||
|
use OCP\IURLGenerator;
|
||||||
|
use OCP\Settings\IIconSection;
|
||||||
|
|
||||||
|
class PersonalSection implements IIconSection
|
||||||
|
{
|
||||||
|
/** @var IURLGenerator */
|
||||||
|
private $urlGenerator;
|
||||||
|
/** @var IL10N */
|
||||||
|
private $l;
|
||||||
|
|
||||||
|
public function __construct(IURLGenerator $urlGenerator, IL10N $l)
|
||||||
|
{
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
$this->l = $l;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the relative path to an 16*16 icon describing the section.
|
||||||
|
*
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
public function getIcon()
|
||||||
|
{
|
||||||
|
return $this->urlGenerator->imagePath('epubreader', 'app.svg');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the ID of the section. It is supposed to be a lower case string,
|
||||||
|
*
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
public function getID()
|
||||||
|
{
|
||||||
|
return 'epubreader';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the translated name as it should be displayed
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->l->t('EPUB/CBZ/PDF ebook reader');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns priority for positioning
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getPriority()
|
||||||
|
{
|
||||||
|
return 20;
|
||||||
|
}
|
||||||
|
}
|
25
personal.php
25
personal.php
@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* ownCloud - Epubreader app
|
|
||||||
*
|
|
||||||
* Copyright (c) 2014,2018 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;
|
|
||||||
|
|
||||||
use OCP\Util;
|
|
||||||
|
|
||||||
#$l = \OC::$server->getL10N('epubreader');
|
|
||||||
|
|
||||||
$tmpl = new \OCP\Template('epubreader', 'settings-personal');
|
|
||||||
$EpubEnable = Config::get('epub_enable', 'true');
|
|
||||||
$PdfEnable = Config::get('pdf_enable', 'true');
|
|
||||||
$CbxEnable = Config::get('cbx_enable', 'true');
|
|
||||||
$tmpl->assign('EpubEnable', $EpubEnable);
|
|
||||||
$tmpl->assign('PdfEnable', $PdfEnable);
|
|
||||||
$tmpl->assign('CbxEnable', $CbxEnable);
|
|
||||||
|
|
||||||
return $tmpl->fetchPage();
|
|
Reference in New Issue
Block a user