1
0
mirror of https://github.com/chylex/Nextcloud-News.git synced 2025-05-06 16:34:06 +02:00

Define an official codestyle and adhere to it.

This commit is contained in:
Sean Molenaar 2018-11-29 20:59:46 +01:00
parent 0f2645145a
commit becce6b752
68 changed files with 898 additions and 1079 deletions

View File

@ -1,8 +1,8 @@
# Contributing
Read this when you want to:
* file an issue (bug or feature request)
* help translate the News file to your language
* [file an issue (bug or feature request)](#Issues)
* [help translate the News file to your language](#Translation)
* start programming and change the way the News app works
* add cool new feeds to the feed explore section
* want to provide additional full text feed rules
@ -119,16 +119,8 @@ We usually hang out on **irc.freenode.net** in the **#nextcloud-news** and **#ne
### Coding Style Guidelines
* Use 4 spaces for indention. Why spaces? Because it looks the same on every machine and on the web where you can't normally control the tab width.
* Place the open curly braces on the same line as the parameter block, e.g.:
```php
if (condition) {
// code
} else {
// code
}
```
The PHP code should all adhere to [PSR-2](https://www.php-fig.org/psr/psr-2/).
*Note that this is a different codestyle than nextcloud itself uses.*
To test the codestyle you can run `make phpcs`.
* Place a space before and after the parameter block for if, else, for, foreach, function
* Everything should be in camelCase except classes which should be in PascalCase
* For linting JavaScript, a [jshint file](https://github.com/nextcloud/news/blob/master/js/.jshintrc) is used that is run before compiling the JavaScript
For linting JavaScript, a [jshint file](https://github.com/nextcloud/news/blob/master/js/.jshintrc) is used that is run before compiling the JavaScript

View File

@ -108,6 +108,11 @@ endif
clean:
rm -rf ./build
# Reports PHP codestyle violations
.PHONY: phpcs
phpcs:
./vendor/bin/phpcs --standard=PSR2 lib
# Same as clean but also removes dependencies installed by composer and
# npm
.PHONY: distclean
@ -183,3 +188,4 @@ test:
./vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-clover build/php-unit.clover
# \Test\TestCase is only allowed to access the db if TRAVIS environment variable is set
env TRAVIS=1 ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml --coverage-clover build/php-unit.clover
$(MAKE) phpcs

View File

@ -36,7 +36,8 @@
"nicolus/picofeed": "0.1.35"
},
"require-dev": {
"phpunit/phpunit": "^6.5"
"phpunit/phpunit": "^6.5",
"squizlabs/php_codesniffer": "^3.3"
},
"autoload": {
"psr-4": {

359
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "ac4e6dcfaee8b83840050366cacebc4c",
"content-hash": "f4a0d96b7e83ec4d9d232412b9e61566",
"packages": [
{
"name": "ezyang/htmlpurifier",
@ -322,262 +322,6 @@
],
"time": "2017-07-22T11:58:36+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.3.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba",
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.4",
"php": ">=5.5"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
"psr/log": "^1.0"
},
"suggest": {
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.3-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2018-04-22T15:46:56+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-12-20T10:07:11+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-03-20T17:10:46+00:00"
},
{
"name": "kevinrob/guzzle-cache-middleware",
"version": "v2.1.1",
"source": {
"type": "git",
"url": "https://github.com/Kevinrob/guzzle-cache-middleware.git",
"reference": "6952064f7747756b0be7b4c234c0fd7535ea4c8c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Kevinrob/guzzle-cache-middleware/zipball/6952064f7747756b0be7b4c234c0fd7535ea4c8c",
"reference": "6952064f7747756b0be7b4c234c0fd7535ea4c8c",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"cache/array-adapter": "^0.4",
"doctrine/cache": "^1.0",
"guzzlehttp/guzzle": "^6.0",
"illuminate/cache": "^5.0",
"league/flysystem": "^1.0",
"phpunit/phpunit": "^4.0 || ^5.0",
"psr/cache": "^1.0"
},
"suggest": {
"doctrine/cache": "This library have a lot of ready-to-use cache storage (to be use with Kevinrob\\GuzzleCache\\Storage\\DoctrineCacheStorage)",
"guzzlehttp/guzzle": "For using this library. It was created for Guzzle6. (but you can use it with any PSR-7 HTTP Client)",
"laravel/framework": "To be use with Kevinrob\\GuzzleCache\\Storage\\LaravelCacheStorage",
"league/flysystem": "To be use with Kevinrob\\GuzzleCache\\Storage\\FlysystemStorage",
"psr/cache": "To be use with Kevinrob\\GuzzleCache\\Storage\\Psr6CacheStorage"
},
"type": "library",
"autoload": {
"psr-4": {
"Kevinrob\\GuzzleCache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Kevin Robatel",
"email": "kevinrob2@gmail.com",
"homepage": "https://github.com/Kevinrob"
}
],
"description": "A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)",
"homepage": "https://github.com/Kevinrob/guzzle-cache-middleware",
"keywords": [
"Etag",
"Flysystem",
"Guzzle",
"cache",
"cache-control",
"doctrine",
"expiration",
"guzzle6",
"handler",
"http",
"http 1.1",
"middleware",
"performance",
"php",
"promise",
"psr6",
"psr7",
"rfc7234",
"validation"
],
"time": "2017-08-17T12:23:43+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.8.1",
@ -1335,56 +1079,6 @@
],
"time": "2018-08-09T05:50:03+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
},
{
"name": "sebastian/code-unit-reverse-lookup",
"version": "1.0.1",
@ -1944,6 +1638,57 @@
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2016-10-03T07:35:21+00:00"
},
{
"name": "squizlabs/php_codesniffer",
"version": "3.3.2",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e",
"reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e",
"shasum": ""
},
"require": {
"ext-simplexml": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
},
"bin": [
"bin/phpcs",
"bin/phpcbf"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Greg Sherwood",
"role": "lead"
}
],
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "http://www.squizlabs.com/php-codesniffer",
"keywords": [
"phpcs",
"standards"
],
"time": "2018-09-23T23:08:17+00:00"
},
{
"name": "theseer/tokenizer",
"version": "1.1.0",

View File

@ -1,8 +1,8 @@
# Installation/Update
## Dependencies
* PHP >= 5.6
* Nextcloud 12
* PHP >= 7.0
* Nextcloud 14
* libxml >= 2.7.8 (2.9 recommended)
* php-curl
* iconv

View File

@ -31,7 +31,6 @@ use OCP\ILogger;
use PicoFeed\Config\Config as PicoFeedConfig;
use PicoFeed\Reader\Reader as PicoFeedReader;
class Application extends App
{
@ -80,7 +79,6 @@ class Application extends App
}
});
$container->registerService(Config::class, function (IContainer $c): Config {
$config = new Config(
$c->query('ConfigView'),
@ -168,8 +166,5 @@ class Application extends App
return $fetcher;
});
}
}

View File

@ -42,5 +42,4 @@ class AfterUpdate extends Command
{
$this->updater->afterUpdate();
}
}

View File

@ -19,7 +19,6 @@ use Symfony\Component\Console\Output\OutputInterface;
use OCA\News\Service\FeedService;
class AllFeeds extends Command
{
private $feedService;
@ -55,5 +54,4 @@ class AllFeeds extends Command
print(json_encode($result));
}
}

View File

@ -43,5 +43,4 @@ class BeforeUpdate extends Command
{
$this->updater->beforeUpdate();
}
}

View File

@ -20,7 +20,6 @@ use Symfony\Component\Console\Output\OutputInterface;
use OCA\News\Service\FeedService;
class UpdateFeed extends Command
{
private $feedService;
@ -61,5 +60,4 @@ class UpdateFeed extends Command
);
}
}
}

View File

@ -16,7 +16,6 @@ namespace OCA\News\Config;
use OCP\ILogger;
use OCP\Files\Folder;
class Config
{
@ -34,7 +33,8 @@ class Config
private $maxSize;
private $exploreUrl;
public function __construct(Folder $fileSystem,
public function __construct(
Folder $fileSystem,
ILogger $logger,
$LoggerParameters
) {
@ -141,9 +141,7 @@ class Config
if ($createIfNotExists && !$this->fileSystem->nodeExists($configPath)) {
$this->fileSystem->newFile($configPath);
$this->write($configPath);
} else {
$content = $this->fileSystem->get($configPath)->getContent();
$configValues = parse_ini_string($content);
@ -153,7 +151,6 @@ class Config
$this->loggerParams
);
} else {
foreach ($configValues as $key => $value) {
if (property_exists($this, $key)) {
$type = gettype($this->$key);
@ -167,7 +164,6 @@ class Config
);
}
}
}
}
}
@ -194,6 +190,4 @@ class Config
$this->fileSystem->get($configPath)->putContent($ini);
}
}

View File

@ -26,6 +26,4 @@ class DependencyException extends \Exception
{
parent::__construct($msg);
}
}

View File

@ -28,9 +28,9 @@ use OCA\News\Service\ItemService;
*/
class AdminController extends Controller
{
private $_config;
private $_configPath;
private $_itemService;
private $config;
private $configPath;
private $itemService;
/**
* AdminController constructor.
@ -41,13 +41,17 @@ class AdminController extends Controller
* @param ItemService $itemService Service for items
* @param string $configFile Path to the config
*/
public function __construct($appName, IRequest $request, Config $config,
ItemService $itemService, $configFile
public function __construct(
$appName,
IRequest $request,
Config $config,
ItemService $itemService,
$configFile
) {
parent::__construct($appName, $request);
$this->_config = $config;
$this->_configPath = $configFile;
$this->_itemService = $itemService;
$this->config = $config;
$this->configPath = $configFile;
$this->itemService = $itemService;
}
/**
@ -62,13 +66,13 @@ class AdminController extends Controller
{
$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(),
$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($this->appName, 'admin', $data, 'blank');
}
@ -87,29 +91,33 @@ class AdminController extends Controller
*
* @return array with the updated values
*/
public function update($autoPurgeMinimumInterval, $autoPurgeCount,
$maxRedirects, $feedFetcherTimeout, $maxSize,
$useCronUpdates, $exploreUrl
public function update(
$autoPurgeMinimumInterval,
$autoPurgeCount,
$maxRedirects,
$feedFetcherTimeout,
$maxSize,
$useCronUpdates,
$exploreUrl
) {
$this->_config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval);
$this->_config->setAutoPurgeCount($autoPurgeCount);
$this->_config->setMaxRedirects($maxRedirects);
$this->_config->setMaxSize($maxSize);
$this->_config->setFeedFetcherTimeout($feedFetcherTimeout);
$this->_config->setUseCronUpdates($useCronUpdates);
$this->_config->setExploreUrl($exploreUrl);
$this->_config->write($this->_configPath);
$this->config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval);
$this->config->setAutoPurgeCount($autoPurgeCount);
$this->config->setMaxRedirects($maxRedirects);
$this->config->setMaxSize($maxSize);
$this->config->setFeedFetcherTimeout($feedFetcherTimeout);
$this->config->setUseCronUpdates($useCronUpdates);
$this->config->setExploreUrl($exploreUrl);
$this->config->write($this->configPath);
return [
'autoPurgeMinimumInterval' =>
$this->_config->getAutoPurgeMinimumInterval(),
'autoPurgeCount' => $this->_config->getAutoPurgeCount(),
'maxRedirects' => $this->_config->getMaxRedirects(),
'maxSize' => $this->_config->getMaxSize(),
'feedFetcherTimeout' => $this->_config->getFeedFetcherTimeout(),
'useCronUpdates' => $this->_config->getUseCronUpdates(),
'exploreUrl' => $this->_config->getExploreUrl(),
$this->config->getAutoPurgeMinimumInterval(),
'autoPurgeCount' => $this->config->getAutoPurgeCount(),
'maxRedirects' => $this->config->getMaxRedirects(),
'maxSize' => $this->config->getMaxSize(),
'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(),
'useCronUpdates' => $this->config->getUseCronUpdates(),
'exploreUrl' => $this->config->getExploreUrl(),
];
}
}

View File

@ -40,7 +40,8 @@ class ApiController extends BaseApiController
* @param IRequest $request The request
* @param IUserSession $userSession The user session
*/
public function __construct($appName, IRequest $request, IUserSession $userSession) {
public function __construct($appName, IRequest $request, IUserSession $userSession)
{
parent::__construct($appName, $request);
$this->userSession = $userSession;
}
@ -48,14 +49,16 @@ class ApiController extends BaseApiController
/**
* @return IUser
*/
protected function getUser() {
protected function getUser()
{
return $this->userSession->getUser();
}
/**
* @return string
*/
protected function getUserId() {
protected function getUserId()
{
return $this->getUser()->getUID();
}
@ -74,5 +77,4 @@ class ApiController extends BaseApiController
'apiLevels' => ['v1-2']
];
}
}

View File

@ -13,7 +13,6 @@ namespace OCA\News\Controller;
use \OCA\News\Db\IAPI;
class EntityApiSerializer
{
@ -68,5 +67,4 @@ class EntityApiSerializer
return $converted;
}
}

View File

@ -33,7 +33,8 @@ class ExportController extends Controller
private $itemService;
private $userId;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
FolderService $folderService,
FeedService $feedService,
@ -93,6 +94,4 @@ class ExportController extends Controller
);
return $response;
}
}

View File

@ -25,10 +25,8 @@ use \OCA\News\Service\ItemService;
use \OCA\News\Service\ServiceNotFoundException;
use \OCA\News\Service\ServiceConflictException;
class FeedApiController extends ApiController
{
use JSONHttpError;
private $itemService;
@ -37,7 +35,8 @@ class FeedApiController extends ApiController
private $loggerParams;
private $serializer;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
FeedService $feedService,
@ -106,7 +105,6 @@ class FeedApiController extends ApiController
}
return $this->serializer->serialize($result);
} catch (ServiceConflictException $ex) {
return $this->error($ex, Http::STATUS_CONFLICT);
} catch (ServiceNotFoundException $ex) {
@ -162,7 +160,9 @@ class FeedApiController extends ApiController
{
try {
$this->feedService->patch(
$feedId, $this->getUserId(), ['folderId' => $folderId]
$feedId,
$this->getUserId(),
['folderId' => $folderId]
);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
@ -185,7 +185,9 @@ class FeedApiController extends ApiController
{
try {
$this->feedService->patch(
$feedId, $this->getUserId(), ['title' => $feedTitle]
$feedId,
$this->getUserId(),
['title' => $feedTitle]
);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
@ -233,6 +235,4 @@ class FeedApiController extends ApiController
);
}
}
}

View File

@ -25,10 +25,8 @@ use OCA\News\Service\ServiceNotFoundException;
use OCA\News\Service\ServiceConflictException;
use OCA\News\Db\FeedType;
class FeedController extends Controller
{
use JSONHttpError;
private $feedService;
@ -37,7 +35,8 @@ class FeedController extends Controller
private $userId;
private $settings;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
FolderService $folderService,
FeedService $feedService,
@ -88,10 +87,12 @@ class FeedController extends Controller
{
$feedId = (int) $this->settings->getUserValue(
$this->userId,
$this->appName, 'lastViewedFeedId'
$this->appName,
'lastViewedFeedId'
);
$feedType = $this->settings->getUserValue(
$this->userId, $this->appName,
$this->userId,
$this->appName,
'lastViewedFeedType'
);
@ -104,7 +105,6 @@ class FeedController extends Controller
try {
if ($feedType === FeedType::FOLDER) {
$this->folderService->find($feedId, $this->userId);
} elseif ($feedType === FeedType::FEED) {
$this->feedService->find($feedId, $this->userId);
@ -112,7 +112,6 @@ class FeedController extends Controller
} elseif ($feedType === null) {
throw new ServiceNotFoundException('');
}
} catch (ServiceNotFoundException $ex) {
$feedId = 0;
$feedType = FeedType::SUBSCRIPTIONS;
@ -137,8 +136,12 @@ class FeedController extends Controller
* @param string $password
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function create($url, $parentFolderId, $title=null,
$user=null, $password=null
public function create(
$url,
$parentFolderId,
$title = null,
$user = null,
$password = null
) {
try {
// we need to purge deleted feeds if a feed is created to
@ -146,9 +149,12 @@ class FeedController extends Controller
$this->feedService->purgeDeleted($this->userId, false);
$feed = $this->feedService->create(
$url, $parentFolderId,
$this->userId, $title,
$user, $password
$url,
$parentFolderId,
$this->userId,
$title,
$user,
$password
);
$params = ['feeds' => [$feed]];
@ -162,13 +168,11 @@ class FeedController extends Controller
}
return $params;
} catch (ServiceConflictException $ex) {
return $this->error($ex, Http::STATUS_CONFLICT);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY);
}
}
@ -211,11 +215,9 @@ class FeedController extends Controller
]
]
];
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
}
}
@ -291,8 +293,13 @@ class FeedController extends Controller
* @param int $folderId
* @param string $title
*/
public function patch($feedId, $pinned=null, $fullTextEnabled=null,
$updateMode=null, $ordering=null, $title=null,
public function patch(
$feedId,
$pinned = null,
$fullTextEnabled = null,
$updateMode = null,
$ordering = null,
$title = null,
$folderId = null
) {
$attributes = [
@ -305,7 +312,8 @@ class FeedController extends Controller
];
$diff = array_filter(
$attributes, function ($value) {
$attributes,
function ($value) {
return $value !== null;
}
);
@ -318,5 +326,4 @@ class FeedController extends Controller
return [];
}
}

View File

@ -25,17 +25,16 @@ use \OCA\News\Service\ServiceNotFoundException;
use \OCA\News\Service\ServiceConflictException;
use \OCA\News\Service\ServiceValidationException;
class FolderApiController extends ApiController
{
use JSONHttpError;
private $folderService;
private $itemService;
private $serializer;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
FolderService $folderService,
@ -116,7 +115,6 @@ class FolderApiController extends ApiController
{
try {
$this->folderService->rename($folderId, $name, $this->getUserId());
} catch (ServiceValidationException $ex) {
return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY);
} catch (ServiceConflictException $ex) {
@ -141,6 +139,4 @@ class FolderApiController extends ApiController
{
$this->itemService->readFolder($folderId, $newestItemId, $this->getUserId());
}
}

View File

@ -24,10 +24,8 @@ use \OCA\News\Service\ServiceNotFoundException;
use \OCA\News\Service\ServiceConflictException;
use \OCA\News\Service\ServiceValidationException;
class FolderController extends Controller
{
use JSONHttpError;
private $folderService;
@ -35,7 +33,8 @@ class FolderController extends Controller
private $itemService;
private $userId;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
FolderService $folderService,
FeedService $feedService,
@ -94,13 +93,11 @@ class FolderController extends Controller
$folder = $this->folderService->create($folderName, $this->userId);
return ['folders' => [$folder]];
} catch (ServiceConflictException $ex) {
return $this->error($ex, Http::STATUS_CONFLICT);
} catch (ServiceValidationException $ex) {
return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY);
}
}
@ -133,12 +130,12 @@ class FolderController extends Controller
{
try {
$folder = $this->folderService->rename(
$folderId, $folderName,
$folderId,
$folderName,
$this->userId
);
return ['folders' => [$folder]];
} catch (ServiceConflictException $ex) {
return $this->error($ex, Http::STATUS_CONFLICT);
} catch (ServiceValidationException $ex) {
@ -146,7 +143,6 @@ class FolderController extends Controller
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
}
}
/**
@ -159,7 +155,9 @@ class FolderController extends Controller
public function read($folderId, $highestItemId)
{
$this->itemService->readFolder(
$folderId, $highestItemId, $this->userId
$folderId,
$highestItemId,
$this->userId
);
return ['feeds' => $this->feedService->findAll($this->userId)];
@ -182,6 +180,4 @@ class FolderController extends Controller
return [];
}
}

View File

@ -24,13 +24,13 @@ use \OCA\News\Service\ServiceNotFoundException;
class ItemApiController extends ApiController
{
use JSONHttpError;
private $itemService;
private $serializer;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
ItemService $itemService
@ -54,12 +54,22 @@ class ItemApiController extends ApiController
* @param bool $oldestFirst
* @return array|mixed
*/
public function index($type=3, $id=0, $getRead=true, $batchSize=-1,
$offset=0, $oldestFirst=false
public function index(
$type = 3,
$id = 0,
$getRead = true,
$batchSize = -1,
$offset = 0,
$oldestFirst = false
) {
return $this->serializer->serialize(
$this->itemService->findAll(
$id, $type, $batchSize, $offset, $getRead, $oldestFirst,
$id,
$type,
$batchSize,
$offset,
$getRead,
$oldestFirst,
$this->getUserId()
)
);
@ -86,8 +96,11 @@ class ItemApiController extends ApiController
}
return $this->serializer->serialize(
$this->itemService->findAllNew(
$id, $type, $paddedLastModified,
true, $this->getUserId()
$id,
$type,
$paddedLastModified,
true,
$this->getUserId()
)
);
}
@ -137,7 +150,10 @@ class ItemApiController extends ApiController
{
try {
$this->itemService->star(
$feedId, $guidHash, $isStarred, $this->getUserId()
$feedId,
$guidHash,
$isStarred,
$this->getUserId()
);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
@ -233,8 +249,10 @@ class ItemApiController extends ApiController
foreach ($items as $item) {
try {
$this->itemService->star(
$item['feedId'], $item['guidHash'],
$isStarred, $this->getUserId()
$item['feedId'],
$item['guidHash'],
$isStarred,
$this->getUserId()
);
} catch (ServiceNotFoundException $ex) {
continue;
@ -267,6 +285,4 @@ class ItemApiController extends ApiController
{
$this->setMultipleStarred(false, $items);
}
}

View File

@ -23,10 +23,8 @@ use \OCA\News\Service\ServiceNotFoundException;
use \OCA\News\Service\ItemService;
use \OCA\News\Service\FeedService;
class ItemController extends Controller
{
use JSONHttpError;
private $itemService;
@ -34,7 +32,8 @@ class ItemController extends Controller
private $userId;
private $settings;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
FeedService $feedService,
ItemService $itemService,
@ -61,31 +60,45 @@ class ItemController extends Controller
* @param string $search
* @return array
*/
public function index($type=3, $id=0, $limit=50, $offset=0, $showAll=null,
$oldestFirst=null, $search=''
public function index(
$type = 3,
$id = 0,
$limit = 50,
$offset = 0,
$showAll = null,
$oldestFirst = null,
$search = ''
) {
// in case this is called directly and not from the website use the
// internal state
if ($showAll === null) {
$showAll = $this->settings->getUserValue(
$this->userId, $this->appName, 'showAll'
$this->userId,
$this->appName,
'showAll'
) === '1';
}
if ($oldestFirst === null) {
$oldestFirst = $this->settings->getUserValue(
$this->userId, $this->appName, 'oldestFirst'
$this->userId,
$this->appName,
'oldestFirst'
) === '1';
}
$this->settings->setUserValue(
$this->userId, $this->appName,
'lastViewedFeedId', $id
$this->userId,
$this->appName,
'lastViewedFeedId',
$id
);
$this->settings->setUserValue(
$this->userId, $this->appName,
'lastViewedFeedType', $type
$this->userId,
$this->appName,
'lastViewedFeedType',
$type
);
$params = [];
@ -100,7 +113,6 @@ class ItemController extends Controller
}
try {
// the offset is 0 if the user clicks on a new feed
// we need to pass the newest feeds to not let the unread count get
// out of sync
@ -113,8 +125,14 @@ class ItemController extends Controller
}
$params['items'] = $this->itemService->findAll(
$id, $type, $limit, $offset, $showAll, $oldestFirst,
$this->userId, $search
$id,
$type,
$limit,
$offset,
$showAll,
$oldestFirst,
$this->userId,
$search
);
// this gets thrown if there are no items
@ -137,7 +155,8 @@ class ItemController extends Controller
public function newItems($type, $id, $lastModified = 0)
{
$showAll = $this->settings->getUserValue(
$this->userId, $this->appName,
$this->userId,
$this->appName,
'showAll'
) === '1';
@ -150,8 +169,11 @@ class ItemController extends Controller
$params['starred'] =
$this->itemService->starredCount($this->userId);
$params['items'] = $this->itemService->findAllNew(
$id, $type,
$lastModified, $showAll, $this->userId
$id,
$type,
$lastModified,
$showAll,
$this->userId
);
// this gets thrown if there are no items
@ -175,7 +197,9 @@ class ItemController extends Controller
{
try {
$this->itemService->star(
$feedId, $guidHash, $isStarred,
$feedId,
$guidHash,
$isStarred,
$this->userId
);
} catch (ServiceException $ex) {
@ -233,6 +257,4 @@ class ItemController extends Controller
}
}
}
}

View File

@ -13,7 +13,6 @@ namespace OCA\News\Controller;
use \OCP\AppFramework\Http\JSONResponse;
trait JSONHttpError
{
@ -28,6 +27,4 @@ trait JSONHttpError
{
return new JSONResponse(['message' => $exception->getMessage()], $code);
}
}

View File

@ -31,6 +31,7 @@ use OCA\News\Db\FeedType;
class PageController extends Controller
{
use JSONHttpError;
private $settings;
private $l10n;
@ -38,11 +39,11 @@ class PageController extends Controller
private $urlGenerator;
private $config;
private $recommendedSites;
private $statusService;
use JSONHttpError;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
IConfig $settings,
IURLGenerator $urlGenerator,
@ -71,7 +72,9 @@ class PageController extends Controller
{
$status = $this->statusService->getStatus();
$response = new TemplateResponse(
$this->appName, 'index', [
$this->appName,
'index',
[
'warnings' => $status['warnings'],
'url_generator' => $this->urlGenerator
]
@ -110,7 +113,8 @@ class PageController extends Controller
if (trim($exploreUrl) === '') {
// default url should not feature the sites.en.json
$exploreUrl = $this->urlGenerator->linkToRoute(
'news.page.explore', ['lang' => 'en']
'news.page.explore',
['lang' => 'en']
);
$exploreUrl = preg_replace('/feeds\.en\.json$/', '', $exploreUrl);
}
@ -122,7 +126,9 @@ class PageController extends Controller
foreach ($settings as $setting) {
$result[$setting] = $this->settings->getUserValue(
$this->userId, $this->appName, $setting
$this->userId,
$this->appName,
$setting
) === '1';
}
return ['settings' => $result];
@ -137,10 +143,15 @@ class PageController extends Controller
* @param bool $preventReadOnScroll
* @param bool $oldestFirst
*/
public function updateSettings($showAll, $compact, $preventReadOnScroll,
$oldestFirst, $compactExpand
public function updateSettings(
$showAll,
$compact,
$preventReadOnScroll,
$oldestFirst,
$compactExpand
) {
$settings = ['showAll',
$settings = [
'showAll',
'compact',
'preventReadOnScroll',
'oldestFirst',
@ -154,8 +165,10 @@ class PageController extends Controller
$value = '0';
}
$this->settings->setUserValue(
$this->userId, $this->appName,
$setting, $value
$this->userId,
$this->appName,
$setting,
$value
);
}
}
@ -168,12 +181,16 @@ class PageController extends Controller
public function explore($lang)
{
$this->settings->setUserValue(
$this->userId, $this->appName,
'lastViewedFeedId', 0
$this->userId,
$this->appName,
'lastViewedFeedId',
0
);
$this->settings->setUserValue(
$this->userId, $this->appName,
'lastViewedFeedType', FeedType::EXPLORE
$this->userId,
$this->appName,
'lastViewedFeedType',
FeedType::EXPLORE
);
try {
@ -182,6 +199,4 @@ class PageController extends Controller
return $this->error($ex, Http::STATUS_NOT_FOUND);
}
}
}

View File

@ -27,7 +27,8 @@ class UserApiController extends ApiController
private $userSession;
private $rootFolder;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
IRootFolder $rootFolder
@ -71,5 +72,4 @@ class UserApiController extends ApiController
'avatar' => $avatar
];
}
}

View File

@ -23,7 +23,6 @@ use \OCP\AppFramework\Http;
use \OCA\News\Utility\Updater;
use \OCA\News\Service\StatusService;
class UtilityApiController extends ApiController
{
@ -31,7 +30,8 @@ class UtilityApiController extends ApiController
private $settings;
private $statusService;
public function __construct($appName,
public function __construct(
$appName,
IRequest $request,
IUserSession $userSession,
Updater $updater,
@ -89,6 +89,4 @@ class UtilityApiController extends ApiController
{
return $this->statusService->getStatus();
}
}

View File

@ -33,7 +33,9 @@ class Updater extends Job
*/
private $updaterService;
public function __construct(Config $config, StatusService $status,
public function __construct(
Config $config,
StatusService $status,
UpdaterService $updaterService
) {
$this->config = $config;
@ -51,5 +53,4 @@ class Updater extends Job
$this->updaterService->afterUpdate();
}
}
}

View File

@ -25,6 +25,4 @@ trait EntityJSONSerializer
}
return $result;
}
}

View File

@ -17,7 +17,6 @@ use OCP\AppFramework\Db\Entity;
class Feed extends Entity implements IAPI, \JsonSerializable
{
use EntityJSONSerializer;
/** @var string */

View File

@ -17,7 +17,6 @@ use OCA\News\Utility\Time;
use OCP\IDBConnection;
use OCP\AppFramework\Db\Entity;
class FeedMapper extends NewsMapper
{
@ -167,6 +166,4 @@ class FeedMapper extends NewsMapper
$sql = 'DELETE FROM `*PREFIX*news_feeds` WHERE `user_id` = ?';
$this->execute($sql, [$userId]);
}
}

View File

@ -13,7 +13,6 @@
namespace OCA\News\Db;
class FeedType
{
const FEED = 0;

View File

@ -17,7 +17,6 @@ use OCP\AppFramework\Db\Entity;
class Folder extends Entity implements IAPI, \JsonSerializable
{
use EntityJSONSerializer;
/** @var int|null */

View File

@ -114,6 +114,4 @@ class FolderMapper extends NewsMapper
$sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `user_id` = ?';
$this->execute($sql, [$userId]);
}
}

View File

@ -17,7 +17,6 @@ use OCP\AppFramework\Db\Entity;
class Item extends Entity implements IAPI, \JsonSerializable
{
use EntityJSONSerializer;
/** @var string|null */
@ -425,8 +424,7 @@ class Item extends Entity implements IAPI, \JsonSerializable
public function setUrl(string $url = null)
{
$url = trim($url);
if (
(strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0)
if ((strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0)
&& $this->url !== $url
) {
$this->url = $url;

View File

@ -18,7 +18,6 @@ use OCA\News\Utility\Time;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
class ItemMapper extends NewsMapper
{
@ -27,7 +26,9 @@ class ItemMapper extends NewsMapper
parent::__construct($db, 'news_items', Item::class, $time);
}
private function makeSelectQuery($prependTo = '', $oldestFirst = false,
private function makeSelectQuery(
$prependTo = '',
$oldestFirst = false,
$distinctFingerprint = false
) {
if ($oldestFirst) {
@ -88,7 +89,8 @@ class ItemMapper extends NewsMapper
function ($param) {
$param = addcslashes($param, '\\_%');
return '%' . mb_strtolower($param, 'UTF-8') . '%';
}, $search
},
$search
);
}
@ -230,8 +232,14 @@ class ItemMapper extends NewsMapper
}
public function findAllFeed($id, $limit, $offset, $showAll, $oldestFirst,
$userId, $search = []
public function findAllFeed(
$id,
$limit,
$offset,
$showAll,
$oldestFirst,
$userId,
$search = []
) {
$params = [$userId];
$params = array_merge($params, $this->buildLikeParameters($search));
@ -251,8 +259,14 @@ class ItemMapper extends NewsMapper
}
public function findAllFolder($id, $limit, $offset, $showAll, $oldestFirst,
$userId, $search = []
public function findAllFolder(
$id,
$limit,
$offset,
$showAll,
$oldestFirst,
$userId,
$search = []
) {
$params = [$userId];
$params = array_merge($params, $this->buildLikeParameters($search));
@ -272,7 +286,13 @@ class ItemMapper extends NewsMapper
}
public function findAll($limit, $offset, $type, $showAll, $oldestFirst, $userId,
public function findAll(
$limit,
$offset,
$type,
$showAll,
$oldestFirst,
$userId,
$search = []
) {
$params = [$userId];
@ -335,7 +355,6 @@ class ItemMapper extends NewsMapper
$result = $this->execute($sql, $params);
while ($row = $result->fetch()) {
$size = (int)$row['size'];
$limit = $size - $threshold;
@ -355,7 +374,6 @@ class ItemMapper extends NewsMapper
$this->execute($sql, $params);
}
}
}
@ -454,5 +472,4 @@ class ItemMapper extends NewsMapper
$this->update($item);
}
}
}

View File

@ -19,7 +19,6 @@ use OCP\IDBConnection;
use OCA\News\Db\Mysql\ItemMapper as MysqlItemMapper;
use OCA\News\DependencyInjection\IFactory;
class MapperFactory implements IFactory
{
@ -46,5 +45,4 @@ class MapperFactory implements IFactory
return new ItemMapper($this->db, $this->time);
}
}
}

View File

@ -46,7 +46,6 @@ class ItemMapper extends \OCA\News\Db\ItemMapper
$result = $this->execute($sql, $params);
while ($row = $result->fetch()) {
$size = (int) $row['size'];
$limit = $size - $threshold;
@ -63,7 +62,6 @@ class ItemMapper extends \OCA\News\Db\ItemMapper
$this->execute($sql, $params);
}
}
}
public function readItem($itemId, $isRead, $lastModified, $userId)
@ -86,5 +84,4 @@ class ItemMapper extends \OCA\News\Db\ItemMapper
$this->update($item);
}
}
}

View File

@ -26,7 +26,10 @@ abstract class NewsMapper extends Mapper
*/
private $time;
public function __construct(IDBConnection $db, $table, $entity,
public function __construct(
IDBConnection $db,
$table,
$entity,
Time $time
) {
parent::__construct($db, $table, $entity);
@ -68,7 +71,7 @@ abstract class NewsMapper extends Mapper
*/
public function where(array $search = [], $limit = null, $offset = null)
{
$entity = new $this->entityClass;
$entity = new $this->entityClass();
// turn keys into sql query filter, e.g. feedId -> feed_id = :feedId
$filter = array_map(
@ -83,7 +86,8 @@ abstract class NewsMapper extends Mapper
$column = $entity->propertyToColumn($property);
return $column . ' = :' . $property;
}, array_keys($search)
},
array_keys($search)
);
$andStatement = implode(' AND ', $filter);
@ -96,5 +100,4 @@ abstract class NewsMapper extends Mapper
return $this->findEntities($sql, $search, $limit, $offset);
}
}

View File

@ -22,5 +22,4 @@ interface IFactory
* @return mixed the constructed object
*/
public function build();
}

View File

@ -40,6 +40,4 @@ class RecommendedSites
throw new RecommendedSiteNotFoundException($msg);
}
}
}

View File

@ -47,7 +47,8 @@ class FeedFetcher implements IFeedFetcher
private $time;
private $clientService;
public function __construct(Reader $reader,
public function __construct(
Reader $reader,
PicoFeedFaviconFactory $faviconFactory,
IL10N $l10n,
Time $time,
@ -74,34 +75,34 @@ class FeedFetcher implements IFeedFetcher
* Fetch a feed from remote
*
* @param string $url remote url of the feed
* @param boolean $getFavicon if the favicon should also be fetched,
* defaults to true
* @param string $lastModified a last modified value from an http header
* defaults to false. If lastModified
* matches the http header from the feed no
* results are fetched
* @param boolean $getFavicon if the favicon should also be fetched, defaults to true
* @param string $lastModified a last modified value from an http header defaults to false.
* If lastModified matches the http header from the feed no results are fetched
* @param string $etag an etag from an http header.
* If lastModified matches the
* http header from the feed no
* results are fetched
* @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
* If lastModified matches the http header from the feed no results are fetched
* @param bool $fullTextEnabled if true tells the fetcher to enhance the articles by fetching more content
* @param string $basicAuthUser if given, basic auth is set for this feed
* @param string $basicAuthPassword if given, basic auth is set for this
* feed. Ignored if user is null or an
* empty string
* @param string $basicAuthPassword if given, basic auth is set for this feed. Ignored if user is empty
*
* @throws FetcherException if it fails
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
public function fetch($url, $getFavicon = true, $lastModified = null,
$etag = null, $fullTextEnabled = false,
$basicAuthUser = null, $basicAuthPassword = null
public function fetch(
$url,
$getFavicon = true,
$lastModified = null,
$etag = null,
$fullTextEnabled = false,
$basicAuthUser = null,
$basicAuthPassword = null
) {
try {
if ($basicAuthUser !== null && trim($basicAuthUser) !== '') {
$resource = $this->reader->discover(
$url, $lastModified, $etag,
$url,
$lastModified,
$etag,
$basicAuthUser,
$basicAuthPassword
);
@ -123,13 +124,24 @@ class FeedFetcher implements IFeedFetcher
if ($fullTextEnabled) {
$parser->enableContentGrabber();
$parser->getItemPostProcessor()->register(new LWNProcessor($basicAuthUser, $basicAuthPassword, $this->clientService));
$parser->getItemPostProcessor()->register(
new LWNProcessor(
$basicAuthUser,
$basicAuthPassword,
$this->clientService
)
);
}
$parsedFeed = $parser->execute();
$feed = $this->buildFeed(
$parsedFeed, $url, $getFavicon, $lastModified, $etag, $location
$parsedFeed,
$url,
$getFavicon,
$lastModified,
$etag,
$location
);
$items = [];
@ -138,11 +150,9 @@ class FeedFetcher implements IFeedFetcher
}
return [$feed, $items];
} catch (Exception $ex) {
$this->handleError($ex, $url);
}
}
@ -238,9 +248,12 @@ class FeedFetcher implements IFeedFetcher
{
return html_entity_decode(
html_entity_decode(
$string, ENT_QUOTES | ENT_HTML5, 'UTF-8'
$string,
ENT_QUOTES | ENT_HTML5,
'UTF-8'
),
ENT_QUOTES | ENT_HTML5, 'UTF-8'
ENT_QUOTES | ENT_HTML5,
'UTF-8'
);
}
@ -276,7 +289,8 @@ class FeedFetcher implements IFeedFetcher
// purification is done in the service layer
$body = $parsedItem->getContent();
$body = mb_convert_encoding(
$body, 'HTML-ENTITIES',
$body,
'HTML-ENTITIES',
mb_detect_encoding($body)
);
$item->setBody($body);
@ -298,8 +312,13 @@ class FeedFetcher implements IFeedFetcher
}
protected function buildFeed($parsedFeed, $url, $getFavicon, $modified,
$etag, $location
protected function buildFeed(
$parsedFeed,
$url,
$getFavicon,
$modified,
$etag,
$location
) {
$feed = new Feed();
@ -327,5 +346,4 @@ class FeedFetcher implements IFeedFetcher
return $feed;
}
}

View File

@ -13,7 +13,6 @@
namespace OCA\News\Fetcher;
class Fetcher
{
@ -39,35 +38,37 @@ class Fetcher
* Fetch a feed from remote
*
* @param string $url remote url of the feed
* @param boolean $getFavicon if the favicon should also be fetched,
* defaults to true
* @param string $lastModified a last modified value from an http header
* defaults to false. If lastModified
* matches the http header from the feed no
* results are fetched
* @param boolean $getFavicon if the favicon should also be fetched, defaults to true
* @param string $lastModified a last modified value from an http header defaults to false.
* If lastModified matches the http header from the feed no results are fetched
* @param string $etag an etag from an http header.
* If lastModified matches the
* http header from the feed no
* results are fetched
* @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
* If lastModified matches the http header from the feed no results are fetched
* @param bool $fullTextEnabled if true tells the fetcher to enhance the articles by fetching more content
* @param string $basicAuthUser if given, basic auth is set for this feed
* @param string $basicAuthPassword if given, basic auth is set for this
* feed. Ignored if user is null or an
* empty string
* @param string $basicAuthPassword if given, basic auth is set for this feed. Ignored if user is empty
*
* @throws FetcherException if simple pie fails
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
public function fetch($url, $getFavicon=true, $lastModified=null,
$etag=null, $fullTextEnabled=false,
$basicAuthUser=null, $basicAuthPassword=null
public function fetch(
$url,
$getFavicon = true,
$lastModified = null,
$etag = null,
$fullTextEnabled = false,
$basicAuthUser = null,
$basicAuthPassword = null
) {
foreach ($this->fetchers as $fetcher) {
if ($fetcher->canHandle($url)) {
return $fetcher->fetch(
$url, $getFavicon, $lastModified, $etag,
$fullTextEnabled, $basicAuthUser,
$url,
$getFavicon,
$lastModified,
$etag,
$fullTextEnabled,
$basicAuthUser,
$basicAuthPassword
);
}
@ -75,6 +76,4 @@ class Fetcher
return [null, []];
}
}

View File

@ -25,5 +25,4 @@ class FetcherException extends \Exception
{
parent::__construct($msg);
}
}

View File

@ -17,37 +17,39 @@ interface IFeedFetcher
{
/**
* Fetch feed content.
*
* @param string $url remote url of the feed
* @param boolean $getFavicon if the favicon should also be fetched,
* defaults to true
* @param string $lastModified a last modified value from an http header
* defaults to false. If lastModified
* matches the http header from the feed no
* results are fetched
* @param boolean $getFavicon if the favicon should also be fetched, defaults to true
* @param string $lastModified a last modified value from an http header defaults to false.
* If lastModified matches the http header from the feed no results are fetched
* @param string $etag an etag from an http header.
* If lastModified matches the
* http header from the feed no
* results are fetched
* @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
* If lastModified matches the http header from the feed no results are fetched
* @param bool $fullTextEnabled if true tells the fetcher to enhance the articles by fetching more content
* @param string $basicAuthUser if given, basic auth is set for this feed
* @param string $basicAuthPassword if given, basic auth is set for this
* feed. Ignored if user is null or an
* empty string
* @param string $basicAuthPassword if given, basic auth is set for this feed. Ignored if user is empty
*
* @throws FetcherException if the fetcher encounters a problem
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
function fetch($url, $getFavicon=true, $lastModified=null, $etag=null,
$fullTextEnabled=false, $basicAuthUser=null,
public function fetch(
$url,
$getFavicon = true,
$lastModified = null,
$etag = null,
$fullTextEnabled = false,
$basicAuthUser = null,
$basicAuthPassword = null
);
/**
* Can a fetcher handle a feed.
*
* @param string $url the url that should be fetched
*
* @return boolean if the fetcher can handle the url. This fetcher will be
* used exclusively to fetch the feed and the items of the page
*/
function canHandle($url);
public function canHandle($url);
}

View File

@ -11,7 +11,6 @@
namespace OCA\News\Fetcher;
class YoutubeFetcher implements IFeedFetcher
{
@ -50,35 +49,38 @@ class YoutubeFetcher implements IFeedFetcher
* Fetch a feed from remote
*
* @param string $url remote url of the feed
* @param boolean $getFavicon if the favicon should also be fetched,
* defaults to true
* @param string $lastModified a last modified value from an http header
* defaults to false. If lastModified
* matches the http header from the feed no
* results are fetched
* @param boolean $getFavicon if the favicon should also be fetched, defaults to true
* @param string $lastModified a last modified value from an http header defaults to false.
* If lastModified matches the http header from the feed no results are fetched
* @param string $etag an etag from an http header.
* If lastModified matches the
* http header from the feed no
* results are fetched
* @param bool fullTextEnabled if true tells the fetcher to enhance the
* articles by fetching custom enhanced content
* If lastModified matches the http header from the feed no results are fetched
* @param bool $fullTextEnabled if true tells the fetcher to enhance the articles by fetching more content
* @param string $basicAuthUser if given, basic auth is set for this feed
* @param string $basicAuthPassword if given, basic auth is set for this
* feed. Ignored if user is null or an
* empty string
* @param string $basicAuthPassword if given, basic auth is set for this feed. Ignored if user is empty
*
* @throws FetcherException if it fails
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
public function fetch($url, $getFavicon=true, $lastModified=null,
$etag=null, $fullTextEnabled=false,
$basicAuthUser=null, $basicAuthPassword=null
public function fetch(
$url,
$getFavicon = true,
$lastModified = null,
$etag = null,
$fullTextEnabled = false,
$basicAuthUser = null,
$basicAuthPassword = null
) {
$transformedUrl = $this->buildUrl($url);
$result = $this->feedFetcher->fetch(
$transformedUrl, $getFavicon, $lastModified, $etag,
$fullTextEnabled, $basicAuthUser, $basicAuthPassword
$transformedUrl,
$getFavicon,
$lastModified,
$etag,
$fullTextEnabled,
$basicAuthUser,
$basicAuthPassword
);
// reset feed url so we know the correct added url for the feed
@ -86,6 +88,4 @@ class YoutubeFetcher implements IFeedFetcher
return $result;
}
}

View File

@ -33,5 +33,4 @@ class User
$container->query(FeedService::class)->deleteUser($userId);
$container->query(FolderService::class)->deleteUser($userId);
}
}

View File

@ -15,7 +15,6 @@ namespace OCA\News\Http;
use \OCP\AppFramework\Http\DownloadResponse;
/**
* Prompts the user to download the a text file
*/
@ -49,6 +48,4 @@ class TextDownloadResponse extends DownloadResponse
{
return $this->content;
}
}

View File

@ -46,6 +46,4 @@ class TextResponse extends Response
{
return $this->content;
}
}

View File

@ -45,5 +45,4 @@ class Plugin
{
return self::$scripts;
}
}

View File

@ -50,7 +50,8 @@ class LWNProcessor implements ItemProcessorInterface
$client = $this->clientService->newClient();
$response = $client->post(
'https://lwn.net/login', [
'https://lwn.net/login',
[
'cookies' => $this->cookieJar,
'body' => [
'Username' => $this->user,
@ -66,12 +67,14 @@ class LWNProcessor implements ItemProcessorInterface
{
$client = $this->clientService->newClient();
$response = $client->get(
$url, [
$url,
[
'cookies' => $this->cookieJar
]
);
$parser = new RuleParser(
$response->getBody(), [
$response->getBody(),
[
'body' => array(
'//div[@class="ArticleText"]',
),

View File

@ -28,7 +28,6 @@ use OCA\News\Fetcher\FetcherException;
use OCA\News\Config\Config;
use OCA\News\Utility\Time;
class FeedService extends Service
{
@ -42,7 +41,8 @@ class FeedService extends Service
private $purifier;
private $loggerParams;
public function __construct(FeedMapper $feedMapper,
public function __construct(
FeedMapper $feedMapper,
Fetcher $feedFetcher,
ItemMapper $itemMapper,
ILogger $logger,
@ -103,8 +103,13 @@ class FeedService extends Service
* @throws ServiceNotFoundException if the url points to an invalid feed
* @return Feed the newly created feed
*/
public function create($feedUrl, $folderId, $userId, $title=null,
$basicAuthUser=null, $basicAuthPassword=null
public function create(
$feedUrl,
$folderId,
$userId,
$title = null,
$basicAuthUser = null,
$basicAuthPassword = null
) {
// first try if the feed exists already
try {
@ -113,8 +118,12 @@ class FeedService extends Service
* @var Item[] $items
*/
list($feed, $items) = $this->feedFetcher->fetch(
$feedUrl, true,
null, null, false, $basicAuthUser,
$feedUrl,
true,
null,
null,
false,
$basicAuthUser,
$basicAuthPassword
);
@ -154,7 +163,9 @@ class FeedService extends Service
// and ignore it if it does
try {
$this->itemMapper->findByGuidHash(
$item->getGuidHash(), $item->getFeedId(), $userId
$item->getGuidHash(),
$item->getFeedId(),
$userId
);
continue;
} catch (DoesNotExistException $ex) {
@ -263,14 +274,15 @@ class FeedService extends Service
try {
$dbItem = $this->itemMapper->findByGuidHash(
$item->getGuidHash(), $feedId, $userId
$item->getGuidHash(),
$feedId,
$userId
);
// in case of update
if ($forceUpdate
|| $item->getUpdatedDate() > $dbItem->getUpdatedDate()
) {
$dbItem->setTitle($item->getTitle());
$dbItem->setUrl($item->getUrl());
$dbItem->setAuthor($item->getAuthor());
@ -303,7 +315,6 @@ class FeedService extends Service
// mark feed as successfully updated
$existingFeed->setUpdateErrorCount(0);
$existingFeed->setLastUpdateError('');
} catch (FetcherException $ex) {
$existingFeed->setUpdateErrorCount(
$existingFeed->getUpdateErrorCount() + 1
@ -369,7 +380,9 @@ class FeedService extends Service
try {
// if item exists, copy the status
$existingItem = $this->itemMapper->findByGuidHash(
$item->getGuidHash(), $feed->getId(), $userId
$item->getGuidHash(),
$feed->getId(),
$userId
);
$existingItem->setStatus($item->getStatus());
$this->itemMapper->update($existingItem);
@ -487,5 +500,4 @@ class FeedService extends Service
return $this->feedMapper->update($feed);
}
}

View File

@ -19,7 +19,6 @@ use OCA\News\Db\FolderMapper;
use OCA\News\Config\Config;
use OCA\News\Utility\Time;
class FolderService extends Service
{
@ -28,7 +27,8 @@ class FolderService extends Service
private $autoPurgeMinimumInterval;
private $folderMapper;
public function __construct(FolderMapper $folderMapper,
public function __construct(
FolderMapper $folderMapper,
IL10N $l10n,
Time $timeFactory,
Config $config
@ -58,7 +58,6 @@ class FolderService extends Service
$existingFolders =
$this->folderMapper->findByName($folderName, $userId);
if (count($existingFolders) > 0) {
throw new ServiceConflictException(
$this->l10n->t('Can not add folder: Exists already')
);
@ -192,6 +191,4 @@ class FolderService extends Service
{
$this->folderMapper->deleteUser($userId);
}
}

View File

@ -22,7 +22,6 @@ use OCA\News\Db\FeedType;
use OCA\News\Config\Config;
use OCA\News\Utility\Time;
class ItemService extends Service
{
@ -31,7 +30,8 @@ class ItemService extends Service
private $itemMapper;
private $systemConfig;
public function __construct(ItemMapper $itemMapper,
public function __construct(
ItemMapper $itemMapper,
Time $timeFactory,
Config $config,
IConfig $systemConfig
@ -61,15 +61,24 @@ class ItemService extends Service
switch ($type) {
case FeedType::FEED:
return $this->itemMapper->findAllNewFeed(
$id, $updatedSince, $showAll, $userId
$id,
$updatedSince,
$showAll,
$userId
);
case FeedType::FOLDER:
return $this->itemMapper->findAllNewFolder(
$id, $updatedSince, $showAll, $userId
$id,
$updatedSince,
$showAll,
$userId
);
default:
return $this->itemMapper->findAllNew(
$updatedSince, $type, $showAll, $userId
$updatedSince,
$type,
$showAll,
$userId
);
}
}
@ -90,23 +99,46 @@ class ItemService extends Service
* or body
* @return array of items
*/
public function findAll($id, $type, $limit, $offset, $showAll, $oldestFirst,
$userId, $search=[]
public function findAll(
$id,
$type,
$limit,
$offset,
$showAll,
$oldestFirst,
$userId,
$search = []
) {
switch ($type) {
case FeedType::FEED:
return $this->itemMapper->findAllFeed(
$id, $limit, $offset, $showAll, $oldestFirst, $userId,
$id,
$limit,
$offset,
$showAll,
$oldestFirst,
$userId,
$search
);
case FeedType::FOLDER:
return $this->itemMapper->findAllFolder(
$id, $limit, $offset, $showAll, $oldestFirst, $userId,
$id,
$limit,
$offset,
$showAll,
$oldestFirst,
$userId,
$search
);
default:
return $this->itemMapper->findAll(
$limit, $offset, $type, $showAll, $oldestFirst, $userId, $search
$limit,
$offset,
$type,
$showAll,
$oldestFirst,
$userId,
$search
);
}
}
@ -129,7 +161,9 @@ class ItemService extends Service
* @var Item $item
*/
$item = $this->itemMapper->findByGuidHash(
$guidHash, $feedId, $userId
$guidHash,
$feedId,
$userId
);
$item->setStarred($isStarred);
@ -189,7 +223,10 @@ class ItemService extends Service
{
$time = $this->timeFactory->getMicroTime();
$this->itemMapper->readFolder(
$folderId, $highestItemId, $time, $userId
$folderId,
$highestItemId,
$time,
$userId
);
}
@ -282,5 +319,4 @@ class ItemService extends Service
{
$this->itemMapper->updateSearchIndices();
}
}

View File

@ -18,7 +18,6 @@ use \OCP\AppFramework\Db\MultipleObjectsReturnedException;
use \OCA\News\Db\NewsMapper;
abstract class Service
{
@ -64,5 +63,4 @@ abstract class Service
throw new ServiceNotFoundException($ex->getMessage());
}
}
}

View File

@ -13,7 +13,6 @@
namespace OCA\News\Service;
class ServiceConflictException extends ServiceException
{
@ -26,5 +25,4 @@ class ServiceConflictException extends ServiceException
{
parent::__construct($msg);
}
}

View File

@ -13,7 +13,6 @@
namespace OCA\News\Service;
class ServiceException extends \Exception
{
@ -26,5 +25,4 @@ class ServiceException extends \Exception
{
parent::__construct($msg);
}
}

View File

@ -13,7 +13,6 @@
namespace OCA\News\Service;
class ServiceNotFoundException extends ServiceException
{
@ -26,5 +25,4 @@ class ServiceNotFoundException extends ServiceException
{
parent::__construct($msg);
}
}

View File

@ -13,7 +13,6 @@
namespace OCA\News\Service;
class ServiceValidationException extends ServiceException
{
@ -26,5 +25,4 @@ class ServiceValidationException extends ServiceException
{
parent::__construct($msg);
}
}

View File

@ -20,7 +20,6 @@ use OCP\IDBConnection;
use OCA\News\Config\Config;
class StatusService
{
@ -32,8 +31,11 @@ class StatusService
*/
private $connection;
public function __construct(IConfig $settings, IDBConnection $connection,
Config $config, $AppName
public function __construct(
IConfig $settings,
IDBConnection $connection,
Config $config,
$AppName
) {
$this->settings = $settings;
$this->config = $config;
@ -44,7 +46,8 @@ class StatusService
public function isProperlyConfigured()
{
$cronMode = $this->settings->getAppValue(
'core', 'backgroundjobs_mode'
'core',
'backgroundjobs_mode'
);
$cronOff = !$this->config->getUseCronUpdates();
@ -56,7 +59,8 @@ class StatusService
public function getStatus()
{
$version = $this->settings->getAppValue(
$this->appName, 'installed_version'
$this->appName,
'installed_version'
);
return [
@ -67,5 +71,4 @@ class StatusService
]
];
}
}

View File

@ -94,7 +94,4 @@ class OPMLExporter
$feedOutline->setAttribute('htmlUrl', $feed->getLink());
return $feedOutline;
}
}

View File

@ -39,6 +39,4 @@ class PicoFeedClientFactory
$client->setConfig($this->config);
return $client;
}
}

View File

@ -37,6 +37,4 @@ class PicoFeedFaviconFactory
{
return new Favicon($this->config);
}
}

View File

@ -16,7 +16,6 @@ namespace OCA\News\Utility;
use \OCP\IConfig;
class ProxyConfigParser
{
@ -64,6 +63,4 @@ class ProxyConfigParser
return $result;
}
}

View File

@ -26,5 +26,4 @@ class Time
list($millisecs, $secs) = explode(" ", microtime());
return $secs . substr($millisecs, 2, 6);
}
}

View File

@ -18,7 +18,6 @@ use \OCA\News\Service\FolderService;
use \OCA\News\Service\FeedService;
use \OCA\News\Service\ItemService;
class Updater
{
@ -27,7 +26,8 @@ class Updater
private $feedService;
private $itemService;
public function __construct(FolderService $folderService,
public function __construct(
FolderService $folderService,
FeedService $feedService,
ItemService $itemService
) {
@ -54,6 +54,4 @@ class Updater
{
$this->itemService->autoPurgeOld();
}
}