diff options
Diffstat (limited to 'lib/Controller')
-rw-r--r-- | lib/Controller/AdminController.php | 121 | ||||
-rw-r--r-- | lib/Controller/ApiController.php | 30 | ||||
-rw-r--r-- | lib/Controller/EntityApiSerializer.php | 28 | ||||
-rw-r--r-- | lib/Controller/ExportController.php | 40 | ||||
-rw-r--r-- | lib/Controller/FeedApiController.php | 76 | ||||
-rw-r--r-- | lib/Controller/FeedController.php | 123 | ||||
-rw-r--r-- | lib/Controller/FolderApiController.php | 41 | ||||
-rw-r--r-- | lib/Controller/FolderController.php | 57 | ||||
-rw-r--r-- | lib/Controller/ItemApiController.php | 91 | ||||
-rw-r--r-- | lib/Controller/ItemController.php | 108 | ||||
-rw-r--r-- | lib/Controller/JSONHttpError.php | 12 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 68 | ||||
-rw-r--r-- | lib/Controller/UserApiController.php | 25 | ||||
-rw-r--r-- | lib/Controller/UtilityApiController.php | 42 |
14 files changed, 518 insertions, 344 deletions
diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index e5cd55711..7feff907b 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -7,8 +7,9 @@ * * @author Alessandro Cosentino <cosenal@gmail.com> * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -20,68 +21,94 @@ use OCP\AppFramework\Controller; use OCA\News\Config\Config; use OCA\News\Service\ItemService; -class AdminController extends Controller { - - private $config; - private $configPath; - private $itemService; +/** + * Class AdminController + * + * @package OCA\News\Controller + */ +class AdminController extends Controller +{ + private $_config; + private $_configPath; + private $_itemService; - public function __construct($AppName, IRequest $request, Config $config, - ItemService $itemService, $configFile){ - parent::__construct($AppName, $request); - $this->config = $config; - $this->configPath = $configFile; - $this->itemService = $itemService; + /** + * AdminController constructor. + * + * @param string $appName The name of the app + * @param IRequest $request The request + * @param Config $config Config for nextcloud + * @param ItemService $itemService Service for items + * @param string $configFile Path to the config + */ + public function __construct($appName, IRequest $request, Config $config, + ItemService $itemService, $configFile + ) { + parent::__construct($appName, $request); + $this->_config = $config; + $this->_configPath = $configFile; + $this->_itemService = $itemService; } - // There are no checks for the index method since the output is rendered - // in admin/admin.php - public function index() { + /** + * Controller main entry. + * + * There are no checks for the index method since the output is + * rendered in admin/admin.php + * + * @return TemplateResponse + */ + public function index() + { $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'); } /** - * @param int $autoPurgeMinimumInterval - * @param int $autoPurgeCount - * @param int $maxRedirects - * @param int $feedFetcherTimeout - * @param int $maxSize - * @param bool $useCronUpdates - * @param string $exploreUrl + * Update the app config. + * + * @param int $autoPurgeMinimumInterval New minimum interval for auto-purge + * @param int $autoPurgeCount New value of auto-purge count + * @param int $maxRedirects New value for max amount of redirects + * @param int $feedFetcherTimeout New timeout value for feed fetcher + * @param int $maxSize New max feed size + * @param bool $useCronUpdates Whether or not to use cron updates + * @param string $exploreUrl URL to use for the explore feed + * * @return array with the updated values */ 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); + $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); 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(), ]; } diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index d16c6438d..f5052b49a 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -7,8 +7,8 @@ * * @author Alessandro Cosentino <cosenal@gmail.com> * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 + * @copyright 2012 Alessandro Cosentino + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -16,19 +16,35 @@ namespace OCA\News\Controller; use OCP\IRequest; use OCP\AppFramework\ApiController as BaseApiController; -class ApiController extends BaseApiController { - - public function __construct($appName, - IRequest $request){ +/** + * Class ApiController + * + * @package OCA\News\Controller + */ +class ApiController extends BaseApiController +{ + /** + * ApiController constructor. + * + * @param string $appName The name of the app + * @param IRequest $request The request + */ + public function __construct($appName, IRequest $request) + { parent::__construct($appName, $request); } /** + * Indication of the API levels + * * @PublicPage * @NoCSRFRequired * @CORS + * + * @return array */ - public function index() { + public function index() + { return [ 'apiLevels' => ['v1-2'] ]; diff --git a/lib/Controller/EntityApiSerializer.php b/lib/Controller/EntityApiSerializer.php index af126045e..f624eb84c 100644 --- a/lib/Controller/EntityApiSerializer.php +++ b/lib/Controller/EntityApiSerializer.php @@ -5,8 +5,8 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Bernhard Posselt 2014 + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright 2012-2014 Bernhard Posselt */ namespace OCA\News\Controller; @@ -14,11 +14,13 @@ namespace OCA\News\Controller; use \OCA\News\Db\IAPI; -class EntityApiSerializer { +class EntityApiSerializer +{ private $level; - public function __construct($level) { + public function __construct($level) + { $this->level = $level; } @@ -26,14 +28,15 @@ class EntityApiSerializer { /** * Call toAPI() method on all entities. Works on * - * @param mixed $data : - * * Entity - * * Entity[] - * * array('level' => Entity[]) - * * Response + * @param mixed $data : + * * Entity + * * Entity[] + * * array('level' => Entity[]) + * * Response * @return array|mixed */ - public function serialize($data) { + public function serialize($data) + { if($data instanceof IAPI) { return [$this->level => [$data->toAPI()]]; @@ -49,14 +52,15 @@ class EntityApiSerializer { } - private function convert($entities) { + private function convert($entities) + { $converted = []; foreach($entities as $entity) { if($entity instanceof IAPI) { $converted[] = $entity->toAPI(); - // break if it contains anything else than entities + // break if it contains anything else than entities } else { return $entities; } diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php index 11060f075..1ce81963d 100644 --- a/lib/Controller/ExportController.php +++ b/lib/Controller/ExportController.php @@ -5,10 +5,10 @@ * 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 + * @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; @@ -24,7 +24,8 @@ use \OCA\News\Service\FeedService; use \OCA\News\Service\ItemService; use \OCA\News\Utility\OPMLExporter; -class ExportController extends Controller { +class ExportController extends Controller +{ private $opmlExporter; private $folderService; @@ -32,14 +33,15 @@ class ExportController extends Controller { private $itemService; private $userId; - public function __construct($AppName, - IRequest $request, - FolderService $folderService, - FeedService $feedService, - ItemService $itemService, - OPMLExporter $opmlExporter, - $UserId){ - parent::__construct($AppName, $request); + public function __construct($appName, + IRequest $request, + FolderService $folderService, + FeedService $feedService, + ItemService $itemService, + OPMLExporter $opmlExporter, + $UserId + ) { + parent::__construct($appName, $request); $this->feedService = $feedService; $this->folderService = $folderService; $this->opmlExporter = $opmlExporter; @@ -52,7 +54,8 @@ class ExportController extends Controller { * @NoAdminRequired * @NoCSRFRequired */ - public function opml(){ + public function opml() + { $feeds = $this->feedService->findAll($this->userId); $folders = $this->folderService->findAll($this->userId); $opml = $this->opmlExporter->build($folders, $feeds)->saveXML(); @@ -66,7 +69,8 @@ class ExportController extends Controller { * @NoAdminRequired * @NoCSRFRequired */ - public function articles(){ + public function articles() + { $feeds = $this->feedService->findAll($this->userId); $items = $this->itemService->getUnreadOrStarred($this->userId); @@ -82,8 +86,10 @@ class ExportController extends Controller { } $response = new JSONResponse($articles); - $response->addHeader('Content-Disposition', - 'attachment; filename="articles.json"'); + $response->addHeader( + 'Content-Disposition', + 'attachment; filename="articles.json"' + ); return $response; } diff --git a/lib/Controller/FeedApiController.php b/lib/Controller/FeedApiController.php index eb57198d8..344d72bd0 100644 --- a/lib/Controller/FeedApiController.php +++ b/lib/Controller/FeedApiController.php @@ -5,10 +5,10 @@ * 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 + * @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; @@ -23,7 +23,8 @@ use \OCA\News\Service\ServiceNotFoundException; use \OCA\News\Service\ServiceConflictException; -class FeedApiController extends ApiController { +class FeedApiController extends ApiController +{ use JSONHttpError; @@ -34,14 +35,15 @@ class FeedApiController extends ApiController { private $loggerParams; private $serializer; - public function __construct($AppName, - IRequest $request, - FeedService $feedService, - ItemService $itemService, - ILogger $logger, - $UserId, - $LoggerParameters){ - parent::__construct($AppName, $request); + public function __construct($appName, + IRequest $request, + FeedService $feedService, + ItemService $itemService, + ILogger $logger, + $UserId, + $LoggerParameters + ) { + parent::__construct($appName, $request); $this->feedService = $feedService; $this->itemService = $itemService; $this->userId = $UserId; @@ -56,7 +58,8 @@ class FeedApiController extends ApiController { * @NoCSRFRequired * @CORS */ - public function index() { + public function index() + { $result = [ 'starredCount' => $this->itemService->starredCount($this->userId), @@ -68,8 +71,9 @@ class FeedApiController extends ApiController { $result['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - // in case there are no items, ignore - } catch(ServiceNotFoundException $ex) {} + // in case there are no items, ignore + } catch(ServiceNotFoundException $ex) { + } return $this->serializer->serialize($result); } @@ -81,10 +85,11 @@ class FeedApiController extends ApiController { * @CORS * * @param string $url - * @param int $folderId + * @param int $folderId * @return array|mixed|\OCP\AppFramework\Http\JSONResponse */ - public function create($url, $folderId=0) { + public function create($url, $folderId=0) + { try { $this->feedService->purgeDeleted($this->userId, false); @@ -95,8 +100,9 @@ class FeedApiController extends ApiController { $result['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - // in case there are no items, ignore - } catch(ServiceNotFoundException $ex) {} + // in case there are no items, ignore + } catch(ServiceNotFoundException $ex) { + } return $this->serializer->serialize($result); @@ -116,7 +122,8 @@ class FeedApiController extends ApiController { * @param int $feedId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function delete($feedId) { + public function delete($feedId) + { try { $this->feedService->delete($feedId, $this->userId); } catch(ServiceNotFoundException $ex) { @@ -135,7 +142,8 @@ class FeedApiController extends ApiController { * @param int $feedId * @param int $newestItemId */ - public function read($feedId, $newestItemId) { + public function read($feedId, $newestItemId) + { $this->itemService->readFeed($feedId, $newestItemId, $this->userId); } @@ -149,7 +157,8 @@ class FeedApiController extends ApiController { * @param int $folderId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function move($feedId, $folderId) { + public function move($feedId, $folderId) + { try { $this->feedService->patch( $feedId, $this->userId, ['folderId' => $folderId] @@ -167,11 +176,12 @@ class FeedApiController extends ApiController { * @NoCSRFRequired * @CORS * - * @param int $feedId + * @param int $feedId * @param string $feedTitle * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function rename($feedId, $feedTitle) { + public function rename($feedId, $feedTitle) + { try { $this->feedService->patch( $feedId, $this->userId, ['title' => $feedTitle] @@ -188,7 +198,8 @@ class FeedApiController extends ApiController { * @NoCSRFRequired * @CORS */ - public function fromAllUsers() { + public function fromAllUsers() + { $feeds = $this->feedService->findAllFromAllUsers(); $result = ['feeds' => []]; @@ -207,15 +218,18 @@ class FeedApiController extends ApiController { * @NoCSRFRequired * * @param string $userId - * @param int $feedId + * @param int $feedId */ - public function update($userId, $feedId) { + public function update($userId, $feedId) + { try { $this->feedService->update($feedId, $userId); - // ignore update failure + // ignore update failure } catch(\Exception $ex) { - $this->logger->debug('Could not update feed ' . $ex->getMessage(), - $this->loggerParams); + $this->logger->debug( + 'Could not update feed ' . $ex->getMessage(), + $this->loggerParams + ); } } diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php index fecd58398..cf323b58e 100644 --- a/lib/Controller/FeedController.php +++ b/lib/Controller/FeedController.php @@ -5,10 +5,10 @@ * 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 + * @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; @@ -26,7 +26,8 @@ use OCA\News\Service\ServiceConflictException; use OCA\News\Db\FeedType; -class FeedController extends Controller { +class FeedController extends Controller +{ use JSONHttpError; @@ -36,14 +37,15 @@ class FeedController extends Controller { private $userId; private $settings; - public function __construct($AppName, - IRequest $request, - FolderService $folderService, - FeedService $feedService, - ItemService $itemService, - IConfig $settings, - $UserId){ - parent::__construct($AppName, $request); + public function __construct($appName, + IRequest $request, + FolderService $folderService, + FeedService $feedService, + ItemService $itemService, + IConfig $settings, + $UserId + ) { + parent::__construct($appName, $request); $this->feedService = $feedService; $this->folderService = $folderService; $this->itemService = $itemService; @@ -55,7 +57,8 @@ class FeedController extends Controller { /** * @NoAdminRequired */ - public function index(){ + public function index() + { // this method is also used to update the interface // because of this we also pass the starred count and the newest @@ -69,9 +72,10 @@ class FeedController extends Controller { $params['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - // An exception occurs if there is a newest item. If there is none, - // simply ignore it and do not add the newestItemId - } catch (ServiceNotFoundException $ex) {} + // An exception occurs if there is a newest item. If there is none, + // simply ignore it and do not add the newestItemId + } catch (ServiceNotFoundException $ex) { + } return $params; } @@ -80,27 +84,32 @@ class FeedController extends Controller { /** * @NoAdminRequired */ - public function active(){ - $feedId = (int) $this->settings->getUserValue($this->userId, - $this->appName,'lastViewedFeedId'); - $feedType = $this->settings->getUserValue($this->userId, $this->appName, - 'lastViewedFeedType'); + public function active() + { + $feedId = (int) $this->settings->getUserValue( + $this->userId, + $this->appName, 'lastViewedFeedId' + ); + $feedType = $this->settings->getUserValue( + $this->userId, $this->appName, + 'lastViewedFeedType' + ); // cast from null to int is 0 - if($feedType !== null){ + if($feedType !== null) { $feedType = (int) $feedType; } // check if feed or folder exists try { - if($feedType === FeedType::FOLDER){ + if($feedType === FeedType::FOLDER) { $this->folderService->find($feedId, $this->userId); - } elseif ($feedType === FeedType::FEED){ + } elseif ($feedType === FeedType::FEED) { $this->feedService->find($feedId, $this->userId); - // if its the first launch, those values will be null - } elseif($feedType === null){ + // if its the first launch, those values will be null + } elseif($feedType === null) { throw new ServiceNotFoundException(''); } @@ -122,31 +131,35 @@ class FeedController extends Controller { * @NoAdminRequired * * @param string $url - * @param int $parentFolderId + * @param int $parentFolderId * @param string $title * @param string $user * @param string $password * @return array|\OCP\AppFramework\Http\JSONResponse */ public function create($url, $parentFolderId, $title=null, - $user=null, $password=null){ + $user=null, $password=null + ) { try { // we need to purge deleted feeds if a feed is created to // prevent already exists exceptions $this->feedService->purgeDeleted($this->userId, false); - $feed = $this->feedService->create($url, $parentFolderId, - $this->userId, $title, - $user, $password); + $feed = $this->feedService->create( + $url, $parentFolderId, + $this->userId, $title, + $user, $password + ); $params = ['feeds' => [$feed]]; try { $params['newestItemId'] = $this->itemService->getNewestItemId($this->userId); - // An exception occurs if there is a newest item. If there is none, - // simply ignore it and do not add the newestItemId - } catch (ServiceNotFoundException $ex) {} + // An exception occurs if there is a newest item. If there is none, + // simply ignore it and do not add the newestItemId + } catch (ServiceNotFoundException $ex) { + } return $params; @@ -165,7 +178,8 @@ class FeedController extends Controller { * @param int $feedId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function delete($feedId){ + public function delete($feedId) + { try { $this->feedService->markDeleted($feedId, $this->userId); } catch(ServiceNotFoundException $ex) { @@ -182,7 +196,8 @@ class FeedController extends Controller { * @param int $feedId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function update($feedId){ + public function update($feedId) + { try { $feed = $this->feedService->update($feedId, $this->userId); @@ -210,7 +225,8 @@ class FeedController extends Controller { * @param array $json * @return array */ - public function import($json) { + public function import($json) + { $feed = $this->feedService->importArticles($json, $this->userId); $params = [ @@ -232,7 +248,8 @@ class FeedController extends Controller { * @param int $highestItemId * @return array */ - public function read($feedId, $highestItemId){ + public function read($feedId, $highestItemId) + { $this->itemService->readFeed($feedId, $highestItemId, $this->userId); return [ @@ -252,7 +269,8 @@ class FeedController extends Controller { * @param int $feedId * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function restore($feedId){ + public function restore($feedId) + { try { $this->feedService->unmarkDeleted($feedId, $this->userId); } catch(ServiceNotFoundException $ex) { @@ -265,17 +283,18 @@ class FeedController extends Controller { /** * @NoAdminRequired * - * @param int $feedId - * @param bool $pinned - * @param bool $fullTextEnabled - * @param int $updateMode - * @param int $ordering - * @param int $folderId + * @param int $feedId + * @param bool $pinned + * @param bool $fullTextEnabled + * @param int $updateMode + * @param int $ordering + * @param int $folderId * @param string $title * |