mirror of
https://github.com/chylex/Nextcloud-News.git
synced 2025-09-12 04:53:10 +02:00
.github
.tx
appinfo
bin
css
docs
img
js
l10n
lib
AppInfo
Command
Config
Controller
AdminController.php
ApiController.php
EntityApiSerializer.php
ExportController.php
FeedApiController.php
FeedController.php
FolderApiController.php
FolderController.php
ItemApiController.php
ItemController.php
JSONHttpError.php
PageController.php
UserApiController.php
UtilityApiController.php
Cron
Db
DependencyInjection
Explore
Fetcher
Hooks
Http
Migration
Plugin
PostProcessor
Service
Settings
Utility
screenshots
templates
tests
.editorconfig
.gitignore
.mailmap
.travis.yml
AUTHORS.md
CHANGELOG.md
CONTRIBUTING.md
COPYING
Makefile
README.md
composer.json
composer.lock
issue_template.md
phpunit.integration.xml
phpunit.xml
203 lines
5.2 KiB
PHP
203 lines
5.2 KiB
PHP
<?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 2012 Alessandro Cosentino
|
|
* @copyright 2012-2014 Bernhard Posselt
|
|
*/
|
|
|
|
namespace OCA\News\Controller;
|
|
|
|
use OCP\IRequest;
|
|
use OCP\IConfig;
|
|
use OCP\IL10N;
|
|
use OCP\IURLGenerator;
|
|
use OCP\AppFramework\Controller;
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
use OCP\AppFramework\Http;
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
|
|
|
use OCA\News\Service\StatusService;
|
|
use OCA\News\Config\Config;
|
|
use OCA\News\Explore\RecommendedSites;
|
|
use OCA\News\Explore\RecommendedSiteNotFoundException;
|
|
use OCA\News\Db\FeedType;
|
|
|
|
class PageController extends Controller
|
|
{
|
|
use JSONHttpError;
|
|
|
|
private $settings;
|
|
private $l10n;
|
|
private $userId;
|
|
private $urlGenerator;
|
|
private $config;
|
|
private $recommendedSites;
|
|
|
|
private $statusService;
|
|
|
|
public function __construct(
|
|
$appName,
|
|
IRequest $request,
|
|
IConfig $settings,
|
|
IURLGenerator $urlGenerator,
|
|
Config $config,
|
|
IL10N $l10n,
|
|
RecommendedSites $recommendedSites,
|
|
StatusService $statusService,
|
|
$UserId
|
|
) {
|
|
parent::__construct($appName, $request);
|
|
$this->settings = $settings;
|
|
$this->urlGenerator = $urlGenerator;
|
|
$this->l10n = $l10n;
|
|
$this->userId = $UserId;
|
|
$this->config = $config;
|
|
$this->recommendedSites = $recommendedSites;
|
|
$this->statusService = $statusService;
|
|
}
|
|
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
* @NoCSRFRequired
|
|
*/
|
|
public function index()
|
|
{
|
|
$status = $this->statusService->getStatus();
|
|
$response = new TemplateResponse(
|
|
$this->appName,
|
|
'index',
|
|
[
|
|
'warnings' => $status['warnings'],
|
|
'url_generator' => $this->urlGenerator
|
|
]
|
|
);
|
|
|
|
$csp = new ContentSecurityPolicy();
|
|
$csp->addAllowedImageDomain('*')
|
|
->addAllowedMediaDomain('*')
|
|
->addAllowedConnectDomain('*')// chrome breaks on audio elements
|
|
->addAllowedFrameDomain('https://youtube.com')
|
|
->addAllowedFrameDomain('https://www.youtube.com')
|
|
->addAllowedFrameDomain('https://player.vimeo.com')
|
|
->addAllowedFrameDomain('https://www.player.vimeo.com')
|
|
->addAllowedFrameDomain('https://vk.com')
|
|
->addAllowedFrameDomain('https://www.vk.com');
|
|
$response->setContentSecurityPolicy($csp);
|
|
|
|
return $response;
|
|
}
|
|
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*/
|
|
public function settings()
|
|
{
|
|
$settings = [
|
|
'showAll',
|
|
'compact',
|
|
'preventReadOnScroll',
|
|
'oldestFirst',
|
|
'compactExpand'
|
|
];
|
|
|
|
$exploreUrl = $this->config->getExploreUrl();
|
|
if (trim($exploreUrl) === '') {
|
|
// default url should not feature the sites.en.json
|
|
$exploreUrl = $this->urlGenerator->linkToRoute(
|
|
'news.page.explore',
|
|
['lang' => 'en']
|
|
);
|
|
$exploreUrl = preg_replace('/feeds\.en\.json$/', '', $exploreUrl);
|
|
}
|
|
|
|
$result = [
|
|
'language' => $this->l10n->getLanguageCode(),
|
|
'exploreUrl' => $exploreUrl
|
|
];
|
|
|
|
foreach ($settings as $setting) {
|
|
$result[$setting] = $this->settings->getUserValue(
|
|
$this->userId,
|
|
$this->appName,
|
|
$setting
|
|
) === '1';
|
|
}
|
|
return ['settings' => $result];
|
|
}
|
|
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param bool $showAll
|
|
* @param bool $compact
|
|
* @param bool $preventReadOnScroll
|
|
* @param bool $oldestFirst
|
|
*/
|
|
public function updateSettings(
|
|
$showAll,
|
|
$compact,
|
|
$preventReadOnScroll,
|
|
$oldestFirst,
|
|
$compactExpand
|
|
) {
|
|
$settings = [
|
|
'showAll',
|
|
'compact',
|
|
'preventReadOnScroll',
|
|
'oldestFirst',
|
|
'compactExpand'
|
|
];
|
|
|
|
foreach ($settings as $setting) {
|
|
if (${$setting}) {
|
|
$value = '1';
|
|
} else {
|
|
$value = '0';
|
|
}
|
|
$this->settings->setUserValue(
|
|
$this->userId,
|
|
$this->appName,
|
|
$setting,
|
|
$value
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @NoAdminRequired
|
|
*
|
|
* @param string $lang
|
|
*/
|
|
public function explore($lang)
|
|
{
|
|
$this->settings->setUserValue(
|
|
$this->userId,
|
|
$this->appName,
|
|
'lastViewedFeedId',
|
|
0
|
|
);
|
|
$this->settings->setUserValue(
|
|
$this->userId,
|
|
$this->appName,
|
|
'lastViewedFeedType',
|
|
FeedType::EXPLORE
|
|
);
|
|
|
|
try {
|
|
return $this->recommendedSites->forLanguage($lang);
|
|
} catch (RecommendedSiteNotFoundException $ex) {
|
|
return $this->error($ex, Http::STATUS_NOT_FOUND);
|
|
}
|
|
}
|
|
}
|