diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2017-05-13 22:31:25 +0300 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2017-05-13 22:35:17 +0300 |
commit | 53822bb4bc21cadc135d70d3d099c5fd117424b0 (patch) | |
tree | 0fe2e35c648cf5441fb3be7f7412aa11d8cfedc1 /lib | |
parent | 86c39a75f04a42be50b7f685f84dae46e54fc137 (diff) |
add new apis
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Config/AppConfig.php | 139 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 51 | ||||
-rw-r--r-- | lib/Cron/Updater.php | 42 | ||||
-rw-r--r-- | lib/Settings/Admin.php | 38 | ||||
-rw-r--r-- | lib/Settings/Section.php | 33 |
5 files changed, 98 insertions, 205 deletions
diff --git a/lib/Config/AppConfig.php b/lib/Config/AppConfig.php deleted file mode 100644 index 9c30b4f80..000000000 --- a/lib/Config/AppConfig.php +++ /dev/null @@ -1,139 +0,0 @@ -<?php -/** - * Nextcloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Config; - -use OCP\BackgroundJob\IJobList; -use SimpleXMLElement; - -use OCP\INavigationManager; -use OCP\IURLGenerator; -use OCP\Util; -use OCP\App; - -// Used to parse app.json file, should be in core at some point -class AppConfig { - - private $config; - private $navigationManager; - private $urlGenerator; - private $jobList; - - /** - * TODO: External deps that are needed: - * - add jobs - * - connect to hooks - */ - public function __construct(INavigationManager $navigationManager, - IURLGenerator $urlGenerator, - IJobList $jobList) { - $this->navigationManager = $navigationManager; - $this->urlGenerator = $urlGenerator; - $this->config = []; - $this->jobList = $jobList; - } - - - /** - * Parse an xml config - */ - private function parseConfig($string) { - // no need to worry about XXE since local file - $xml = simplexml_load_string($string, 'SimpleXMLElement'); - return json_decode(json_encode((array)$xml), true); - } - - - /** - * @param string|array $data path to the config file or an array with the - * config - */ - public function loadConfig($data) { - if(is_array($data)) { - $this->config = $data; - } else { - $this->config = $this->parseConfig($data); - } - } - - - /** - * @param string $key if given returns the value of the config at index $key - * @return array|mixed the config - */ - public function getConfig($key=null) { - // FIXME: is this function interface a good idea? - if($key !== null) { - return $this->config[$key]; - } else { - return $this->config; - } - } - - - /** - * Registers all config options - */ - public function registerAll() { - $this->registerNavigation(); - $this->registerHooks(); - $this->jobList->add('OC\BackgroundJob\Legacy\RegularJob', [$this->config['cron']['job'], 'run']); - App::registerAdmin($this->config['id'], $this->config['admin']); - } - - - /** - * Parses the navigation and creates a navigation entry if needed - */ - public function registerNavigation() { - if (array_key_exists('navigation', $this->config)) { - $this->navigationManager->add(function () { - $nav =& $this->config['navigation']; - - $navConfig = [ - 'id' => $this->config['id'], - 'order' => $nav['order'], - 'name' => $nav['name'] - ]; - - $navConfig['href'] = $this->urlGenerator->linkToRoute( - $nav['route'] - ); - $navConfig['icon'] = $this->urlGenerator->imagePath( - $this->config['id'], $nav['icon'] - ); - - return $navConfig; - }); - } - } - - - /** - * Registers all hooks in the config - */ - public function registerHooks() { - // FIXME: this is temporarily static because core emitters are not - // future proof, therefore legacy code in here - foreach ($this->config['hooks'] as $hook) { - $listener = explode('::', $hook['channel']); - $reaction = explode('::', $hook['subscriber']); - - // config is written like HookNamespace::method => Class::method - Util::connectHook($listener[0], $listener[1], $reaction[0], - $reaction[1]); - } - } - - -} diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index b01b9971d..3d1db0d57 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -24,7 +24,6 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCA\News\Service\StatusService; -use OCA\News\Config\AppConfig; use OCA\News\Config\Config; use OCA\News\Explore\RecommendedSites; use OCA\News\Explore\RecommendedSiteNotFoundException; @@ -35,7 +34,6 @@ class PageController extends Controller { private $settings; private $l10n; private $userId; - private $appConfig; private $urlGenerator; private $config; private $recommendedSites; @@ -47,7 +45,6 @@ class PageController extends Controller { IRequest $request, IConfig $settings, IURLGenerator $urlGenerator, - AppConfig $appConfig, Config $config, IL10N $l10n, RecommendedSites $recommendedSites, @@ -56,7 +53,6 @@ class PageController extends Controller { parent::__construct($AppName, $request); $this->settings = $settings; $this->urlGenerator = $urlGenerator; - $this->appConfig = $appConfig; $this->l10n = $l10n; $this->userId = $UserId; $this->config = $config; @@ -155,53 +151,6 @@ class PageController extends Controller { } } - - /** - * @NoCSRFRequired - * @PublicPage - * - * Generates a web app manifest, according to specs in: - * https://developer.mozilla.org/en-US/Apps/Build/Manifest - */ - public function manifest() { - $config = $this->appConfig->getConfig(); - - // size of the icons: 128x128 is required by FxOS for all app manifests - $iconSizes = ['128', '512']; - $icons = []; - - $locale = str_replace('_', '-', $this->l10n->getLanguageCode()); - - foreach ($iconSizes as $size) { - $filename = 'app-' . $size . '.png'; - if (file_exists(__DIR__ . '/../../img/' . $filename)) { - $icons[$size] = $this->urlGenerator->imagePath($config['id'], - $filename); - } - } - - - $data = [ - "name" => $config['name'], - "type" => 'web', - "default_locale" => $locale, - "description" => $config['description'], - "launch_path" => $this->urlGenerator->linkToRoute( - $config['navigation']['route']), - "icons" => $icons, - "developer" => [ - "name" => $config['author'], - "url" => $config['homepage'] - ] - ]; - - $response = new JSONResponse($data); - $response->addHeader('Content-Type', - 'application/x-web-app-manifest+json'); - - return $response; - } - /** * @NoAdminRequired * diff --git a/lib/Cron/Updater.php b/lib/Cron/Updater.php index 5caa2223e..6d8fea832 100644 --- a/lib/Cron/Updater.php +++ b/lib/Cron/Updater.php @@ -5,34 +5,46 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino <cosenal@gmail.com> * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 * @copyright Bernhard Posselt 2012, 2014 */ namespace OCA\News\Cron; -use OCA\News\AppInfo\Application; +use OC\BackgroundJob\Job; + use OCA\News\Config\Config; use OCA\News\Service\StatusService; use OCA\News\Utility\Updater as UpdaterService; -class Updater { +class Updater extends Job { - public static function run() { - $app = new Application(); + /** + * @var Config + */ + private $config; + /** + * @var StatusService + */ + private $status; + /** + * @var UpdaterService + */ + private $updaterService; - $container = $app->getContainer(); + public function __construct(Config $config, StatusService $status, + UpdaterService $updaterService) { + $this->config = $config; + $this->status = $status; + $this->updaterService = $updaterService; + } - // make it possible to turn off cron updates if you use an external - // script to execute updates in parallel - $useCronUpdates = $container->query(Config::class)->getUseCronUpdates(); - $isProperlyConfigured = $container->query(StatusService::class)->isProperlyConfigured(); - if ($useCronUpdates && $isProperlyConfigured) { - $container->query(UpdaterService::class)->update(); - $container->query(UpdaterService::class)->beforeUpdate(); - $container->query(UpdaterService::class)->afterUpdate(); + protected function run($argument) { + if ($this->config->getUseCronUpdates() && + $this->status->isProperlyConfigured()) { + $this->updaterService->update(); + $this->updaterService->beforeUpdate(); + $this->updaterService->afterUpdate(); } } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php new file mode 100644 index 000000000..a256999f0 --- /dev/null +++ b/lib/Settings/Admin.php @@ -0,0 +1,38 @@ +<?php + +namespace OCA\News\Settings; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; + +use OCA\News\Config\Config; + +class Admin implements ISettings { + private $config; + + public function __construct(Config $config) { + $this->config = $config; + } + + public function getForm() { + $data = [ + 'autoPurgeMinimumInterval' => + $this->config->getAutoPurgeMinimumInterval(), + 'autoPurgeCount' => $this->config->getAutoPurgeCount(), + 'maxRedirects' => $this->config->getMaxRedirects(), + 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), + 'useCronUpdates' => $this->config->getUseCronUpdates(), + 'maxSize' => $this->config->getMaxSize(), + 'exploreUrl' => $this->config->getExploreUrl(), + ]; + return new TemplateResponse('news', 'admin', $data, ''); + } + + public function getSection() { + return 'news'; + } + + public function getPriority() { + return 40; + } +} diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php new file mode 100644 index 000000000..5e1e47476 --- /dev/null +++ b/lib/Settings/Section.php @@ -0,0 +1,33 @@ +<?php + +namespace OCA\News\Settings; + +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\Settings\ISection; + +class Section implements ISection { + private $l; + private $url; + + public function __construct(IURLGenerator $url, IL10N $l) { + $this->url = $url; + $this->l = $l; + } + + public function getID() { + return 'news'; + } + + public function getName() { + return $this->l->t('News'); + } + + public function getPriority() { + return 10; + } + + public function getIcon() { + return $this->url->imagePath('news', 'app.svg'); + } +}
\ No newline at end of file |