From 004fcbbcc7609ca83807f2e38967ef54f469bf72 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 23 Jul 2016 21:24:54 +0200 Subject: Move to new directory structure --- controller/admincontroller.php | 88 ----------- controller/apicontroller.php | 37 ----- controller/entityapiserializer.php | 68 -------- controller/exportcontroller.php | 91 ----------- controller/feedapicontroller.php | 224 --------------------------- controller/feedcontroller.php | 301 ------------------------------------ controller/folderapicontroller.php | 139 ----------------- controller/foldercontroller.php | 176 --------------------- controller/itemapicontroller.php | 245 ----------------------------- controller/itemcontroller.php | 218 -------------------------- controller/jsonhttperror.php | 31 ---- controller/pagecontroller.php | 224 --------------------------- controller/userapicontroller.php | 72 --------- controller/utilityapicontroller.php | 83 ---------- 14 files changed, 1997 deletions(-) delete mode 100644 controller/admincontroller.php delete mode 100644 controller/apicontroller.php delete mode 100644 controller/entityapiserializer.php delete mode 100644 controller/exportcontroller.php delete mode 100644 controller/feedapicontroller.php delete mode 100644 controller/feedcontroller.php delete mode 100644 controller/folderapicontroller.php delete mode 100644 controller/foldercontroller.php delete mode 100644 controller/itemapicontroller.php delete mode 100644 controller/itemcontroller.php delete mode 100644 controller/jsonhttperror.php delete mode 100644 controller/pagecontroller.php delete mode 100644 controller/userapicontroller.php delete mode 100644 controller/utilityapicontroller.php (limited to 'controller') diff --git a/controller/admincontroller.php b/controller/admincontroller.php deleted file mode 100644 index a673566de..000000000 --- a/controller/admincontroller.php +++ /dev/null @@ -1,88 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use OCP\AppFramework\Http\TemplateResponse; -use OCP\IRequest; -use OCP\AppFramework\Controller; - -use OCA\News\Config\Config; -use OCA\News\Service\itemService; - -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; - } - - // There are no checks for the index method since the output is rendered - // in admin/admin.php - 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(), - ]; - 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 - * @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); - - 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(), - ]; - } - -} diff --git a/controller/apicontroller.php b/controller/apicontroller.php deleted file mode 100644 index f3b77b379..000000000 --- a/controller/apicontroller.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use OCP\IRequest; -use OCP\AppFramework\ApiController as BaseApiController; - -class ApiController extends BaseApiController { - - public function __construct($appName, - IRequest $request){ - parent::__construct($appName, $request); - } - - /** - * @PublicPage - * @NoCSRFRequired - * @CORS - */ - public function index() { - return [ - 'apiLevels' => ['v1-2'] - ]; - } - -} diff --git a/controller/entityapiserializer.php b/controller/entityapiserializer.php deleted file mode 100644 index 073ad5c39..000000000 --- a/controller/entityapiserializer.php +++ /dev/null @@ -1,68 +0,0 @@ - - * @copyright Bernhard Posselt 2014 - */ - -namespace OCA\News\Controller; - -use \OCA\News\Db\IAPI; - - -class EntityApiSerializer { - - private $level; - - public function __construct($level) { - $this->level = $level; - } - - - /** - * Call toAPI() method on all entities. Works on - * - * @param mixed $data : - * * Entity - * * Entity[] - * * array('level' => Entity[]) - * * Response - * @return array|mixed - */ - public function serialize($data) { - - if($data instanceof IAPI) { - return [$this->level => [$data->toAPI()]]; - } - - if(is_array($data) && array_key_exists($this->level, $data)) { - $data[$this->level] = $this->convert($data[$this->level]); - } elseif(is_array($data)) { - $data = [$this->level => $this->convert($data)]; - } - - return $data; - } - - - private function convert($entities) { - $converted = []; - - foreach($entities as $entity) { - if($entity instanceof IAPI) { - $converted[] = $entity->toAPI(); - - // break if it contains anything else than entities - } else { - return $entities; - } - } - - return $converted; - } - -} \ No newline at end of file diff --git a/controller/exportcontroller.php b/controller/exportcontroller.php deleted file mode 100644 index bc9fc0ff1..000000000 --- a/controller/exportcontroller.php +++ /dev/null @@ -1,91 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http; -use \OCP\AppFramework\Http\JSONResponse; - -use \OCA\News\Http\TextDownloadResponse; -use \OCA\News\Service\FolderService; -use \OCA\News\Service\FeedService; -use \OCA\News\Service\ItemService; -use \OCA\News\Utility\OPMLExporter; - -class ExportController extends Controller { - - private $opmlExporter; - private $folderService; - private $feedService; - private $itemService; - private $userId; - - 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; - $this->itemService = $itemService; - $this->userId = $UserId; - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - */ - public function opml(){ - $feeds = $this->feedService->findAll($this->userId); - $folders = $this->folderService->findAll($this->userId); - $opml = $this->opmlExporter->build($folders, $feeds)->saveXML(); - $name = 'subscriptions.opml'; - $mimeType = 'text/xml'; - return new TextDownloadResponse($opml, $name, $mimeType); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - */ - public function articles(){ - $feeds = $this->feedService->findAll($this->userId); - $items = $this->itemService->getUnreadOrStarred($this->userId); - - // build assoc array for fast access - $feedsDict = []; - foreach($feeds as $feed) { - $feedsDict['feed' . $feed->getId()] = $feed; - } - - $articles = []; - foreach($items as $item) { - $articles[] = $item->toExport($feedsDict); - } - - $response = new JSONResponse($articles); - $response->addHeader('Content-Disposition', - 'attachment; filename="articles.json"'); - return $response; - } - - -} \ No newline at end of file diff --git a/controller/feedapicontroller.php b/controller/feedapicontroller.php deleted file mode 100644 index 9713db8cf..000000000 --- a/controller/feedapicontroller.php +++ /dev/null @@ -1,224 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\ILogger; -use \OCP\AppFramework\ApiController; -use \OCP\AppFramework\Http; - -use \OCA\News\Service\FeedService; -use \OCA\News\Service\ItemService; -use \OCA\News\Service\ServiceNotFoundException; -use \OCA\News\Service\ServiceConflictException; - - -class FeedApiController extends ApiController { - - use JSONHttpError; - - private $itemService; - private $feedService; - private $userId; - private $logger; - private $loggerParams; - private $serializer; - - 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; - $this->logger = $logger; - $this->loggerParams = $LoggerParameters; - $this->serializer = new EntityApiSerializer('feeds'); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - */ - public function index() { - - $result = [ - 'starredCount' => $this->itemService->starredCount($this->userId), - 'feeds' => $this->feedService->findAll($this->userId) - ]; - - - try { - $result['newestItemId'] = - $this->itemService->getNewestItemId($this->userId); - - // in case there are no items, ignore - } catch(ServiceNotFoundException $ex) {} - - return $this->serializer->serialize($result); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param string $url - * @param int $folderId - * @return array|mixed|\OCP\AppFramework\Http\JSONResponse - */ - public function create($url, $folderId=0) { - try { - $this->feedService->purgeDeleted($this->userId, false); - - $feed = $this->feedService->create($url, $folderId, $this->userId); - $result = ['feeds' => [$feed]]; - - try { - $result['newestItemId'] = - $this->itemService->getNewestItemId($this->userId); - - // in case there are no items, ignore - } catch(ServiceNotFoundException $ex) {} - - return $this->serializer->serialize($result); - - } catch(ServiceConflictException $ex) { - return $this->error($ex, Http::STATUS_CONFLICT); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $feedId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function delete($feedId) { - try { - $this->feedService->delete($feedId, $this->userId); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $feedId - * @param int $newestItemId - */ - public function read($feedId, $newestItemId) { - $this->itemService->readFeed($feedId, $newestItemId, $this->userId); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $feedId - * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function move($feedId, $folderId) { - try { - $this->feedService->patch( - $feedId, $this->userId, ['folderId' => $folderId] - ); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $feedId - * @param string $feedTitle - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function rename($feedId, $feedTitle) { - try { - $this->feedService->patch( - $feedId, $this->userId, ['title' => $feedTitle] - ); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoCSRFRequired - * @CORS - */ - public function fromAllUsers() { - $feeds = $this->feedService->findAllFromAllUsers(); - $result = ['feeds' => []]; - - foreach ($feeds as $feed) { - $result['feeds'][] = [ - 'id' => $feed->getId(), - 'userId' => $feed->getUserId() - ]; - } - - return $result; - } - - - /** - * @NoCSRFRequired - * - * @param string $userId - * @param int $feedId - */ - public function update($userId, $feedId) { - try { - $this->feedService->update($feedId, $userId); - // ignore update failure - } catch(\Exception $ex) { - $this->logger->debug('Could not update feed ' . $ex->getMessage(), - $this->loggerParams); - } - } - - -} diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php deleted file mode 100644 index 2b95794a3..000000000 --- a/controller/feedcontroller.php +++ /dev/null @@ -1,301 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use OCP\IRequest; -use OCP\IConfig; -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http; - -use OCA\News\Service\ItemService; -use OCA\News\Service\FeedService; -use OCA\News\Service\FolderService; -use OCA\News\Service\ServiceNotFoundException; -use OCA\News\Service\ServiceConflictException; -use OCA\News\Db\FeedType; - - -class FeedController extends Controller { - - use JSONHttpError; - - private $feedService; - private $folderService; - private $itemService; - private $userId; - private $settings; - - 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; - $this->userId = $UserId; - $this->settings = $settings; - } - - - /** - * @NoAdminRequired - */ - public function index(){ - - // this method is also used to update the interface - // because of this we also pass the starred count and the newest - // item id which will be used for marking feeds read - $params = [ - 'feeds' => $this->feedService->findAll($this->userId), - 'starred' => $this->itemService->starredCount($this->userId) - ]; - - 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) {} - - return $params; - } - - - /** - * @NoAdminRequired - */ - 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){ - $feedType = (int) $feedType; - } - - // check if feed or folder exists - try { - if($feedType === FeedType::FOLDER){ - $this->folderService->find($feedId, $this->userId); - - } elseif ($feedType === FeedType::FEED){ - $this->feedService->find($feedId, $this->userId); - - // if its the first launch, those values will be null - } elseif($feedType === null){ - throw new ServiceNotFoundException(''); - } - - } catch (ServiceNotFoundException $ex){ - $feedId = 0; - $feedType = FeedType::SUBSCRIPTIONS; - } - - return [ - 'activeFeed' => [ - 'id' => $feedId, - 'type' => $feedType - ] - ]; - } - - - /** - * @NoAdminRequired - * - * @param string $url - * @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){ - 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); - $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) {} - - return $params; - - } catch(ServiceConflictException $ex) { - return $this->error($ex, Http::STATUS_CONFLICT); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); - } - - } - - - /** - * @NoAdminRequired - * - * @param int $feedId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function delete($feedId){ - try { - $this->feedService->markDeleted($feedId, $this->userId); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * - * @param int $feedId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function update($feedId){ - try { - $feed = $this->feedService->update($feedId, $this->userId); - - return [ - 'feeds' => [ - // only pass unread count to not accidentally readd - // the feed again - [ - 'id' => $feed->getId(), - 'unreadCount' => $feed->getUnreadCount() - ] - ] - ]; - - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - } - - - /** - * @NoAdminRequired - * - * @param array $json - * @return array - */ - public function import($json) { - $feed = $this->feedService->importArticles($json, $this->userId); - - $params = [ - 'starred' => $this->itemService->starredCount($this->userId) - ]; - - if($feed) { - $params['feeds'] = [$feed]; - } - - return $params; - } - - - /** - * @NoAdminRequired - * - * @param int $feedId - * @param int $highestItemId - * @return array - */ - public function read($feedId, $highestItemId){ - $this->itemService->readFeed($feedId, $highestItemId, $this->userId); - - return [ - 'feeds' => [ - [ - 'id' => $feedId, - 'unreadCount' => 0 - ] - ] - ]; - } - - - /** - * @NoAdminRequired - * - * @param int $feedId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function restore($feedId){ - try { - $this->feedService->unmarkDeleted($feedId, $this->userId); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - /** - * @NoAdminRequired - * - * @param int $feedId - * @param bool $pinned - * @param bool $fullTextEnabled - * @param int $updateMode - * @param int $ordering - * @param int $folderId - * @param string $title - */ - public function patch($feedId, $pinned=null, $fullTextEnabled=null, - $updateMode=null, $ordering=null, $title=null, - $folderId=null) { - $attributes = [ - 'pinned' => $pinned, - 'fullTextEnabled' => $fullTextEnabled, - 'updateMode' => $updateMode, - 'ordering' => $ordering, - 'title' => $title, - 'folderId' => $folderId - ]; - - $diff = array_filter($attributes, function ($value) { - return $value !== null; - }); - - try { - $this->feedService->patch($feedId, $this->userId, $diff); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - -} diff --git a/controller/folderapicontroller.php b/controller/folderapicontroller.php deleted file mode 100644 index 53693e84f..000000000 --- a/controller/folderapicontroller.php +++ /dev/null @@ -1,139 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\AppFramework\ApiController; -use \OCP\AppFramework\Http; - -use \OCA\News\Service\FolderService; -use \OCA\News\Service\ItemService; -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 $userId; - private $serializer; - - public function __construct($AppName, - IRequest $request, - FolderService $folderService, - ItemService $itemService, - $UserId){ - parent::__construct($AppName, $request); - $this->folderService = $folderService; - $this->itemService = $itemService; - $this->userId = $UserId; - $this->serializer = new EntityApiSerializer('folders'); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - */ - public function index() { - return $this->serializer->serialize( - $this->folderService->findAll($this->userId) - ); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param string $name - * @return array|mixed|\OCP\AppFramework\Http\JSONResponse - */ - public function create($name) { - try { - $this->folderService->purgeDeleted($this->userId, false); - return $this->serializer->serialize( - $this->folderService->create($name, $this->userId) - ); - } catch(ServiceValidationException $ex) { - return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); - } catch(ServiceConflictException $ex) { - return $this->error($ex, Http::STATUS_CONFLICT); - } - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function delete($folderId) { - try { - $this->folderService->delete($folderId, $this->userId); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * @param int $folderId - * @param string $name - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function update($folderId, $name) { - try { - $this->folderService->rename($folderId, $name, $this->userId); - - } catch(ServiceValidationException $ex) { - return $this->error($ex, Http::STATUS_UNPROCESSABLE_ENTITY); - } catch(ServiceConflictException $ex) { - return $this->error($ex, Http::STATUS_CONFLICT); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $folderId - * @param int $newestItemId - */ - public function read($folderId, $newestItemId) { - $this->itemService->readFolder($folderId, $newestItemId, $this->userId); - } - - -} diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php deleted file mode 100644 index e8c0b0e6c..000000000 --- a/controller/foldercontroller.php +++ /dev/null @@ -1,176 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http; - -use \OCA\News\Service\FolderService; -use \OCA\News\Service\FeedService; -use \OCA\News\Service\ItemService; -use \OCA\News\Service\ServiceNotFoundException; -use \OCA\News\Service\ServiceConflictException; -use \OCA\News\Service\ServiceValidationException; - - -class FolderController extends Controller { - - use JSONHttpError; - - private $folderService; - private $feedService; - private $itemService; - private $userId; - - public function __construct($AppName, - IRequest $request, - FolderService $folderService, - FeedService $feedService, - ItemService $itemService, - $UserId) { - parent::__construct($AppName, $request); - $this->folderService = $folderService; - $this->feedService = $feedService; - $this->itemService = $itemService; - $this->userId = $UserId; - } - - - /** - * @NoAdminRequired - */ - public function index() { - $folders = $this->folderService->findAll($this->userId); - return ['folders' => $folders]; - } - - - /** - * @NoAdminRequired - * - * @param int $folderId - * @param bool $open - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function open($folderId, $open) { - try { - $this->folderService->open($folderId, $open, $this->userId); - } catch(ServiceNotFoundException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * - * @param string $folderName - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function create($folderName) { - try { - // we need to purge deleted folders if a folder is created to - // prevent already exists exceptions - $this->folderService->purgeDeleted($this->userId, false); - $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); - } - - } - - - /** - * @NoAdminRequired - * - * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function delete($folderId) { - try { - $this->folderService->markDeleted($folderId, $this->userId); - } catch (ServiceNotFoundException $ex){ - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * - * @param string $folderName - * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function rename($folderName, $folderId) { - try { - $folder = $this->folderService->rename($folderId, $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); - } catch (ServiceNotFoundException $ex){ - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - } - - /** - * @NoAdminRequired - * - * @param int $folderId - * @param int $highestItemId - * @return array - */ - public function read($folderId, $highestItemId) { - $this->itemService->readFolder( - $folderId, $highestItemId, $this->userId - ); - - return ['feeds' => $this->feedService->findAll($this->userId)]; - } - - - /** - * @NoAdminRequired - * - * @param int $folderId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function restore($folderId) { - try { - $this->folderService->unmarkDeleted($folderId, $this->userId); - } catch (ServiceNotFoundException $ex){ - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - -} \ No newline at end of file diff --git a/controller/itemapicontroller.php b/controller/itemapicontroller.php deleted file mode 100644 index ec0baabfe..000000000 --- a/controller/itemapicontroller.php +++ /dev/null @@ -1,245 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\AppFramework\ApiController; -use \OCP\AppFramework\Http; - -use \OCA\News\Service\ItemService; -use \OCA\News\Service\ServiceNotFoundException; - -class ItemApiController extends ApiController { - - use JSONHttpError; - - private $itemService; - private $userId; - private $serializer; - - public function __construct($AppName, - IRequest $request, - ItemService $itemService, - $UserId){ - parent::__construct($AppName, $request); - $this->itemService = $itemService; - $this->userId = $UserId; - $this->serializer = new EntityApiSerializer('items'); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $type - * @param int $id - * @param bool $getRead - * @param int $batchSize - * @param int $offset - * @param bool $oldestFirst - * @return array|mixed - */ - 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, - $this->userId - ) - ); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $type - * @param int $id - * @param int $lastModified - * @return array|mixed - */ - public function updated($type=3, $id=0, $lastModified=0) { - return $this->serializer->serialize( - $this->itemService->findAllNew($id, $type, $lastModified, - true, $this->userId) - ); - } - - - private function setRead($isRead, $itemId) { - try { - $this->itemService->read($itemId, $isRead, $this->userId); - } catch(ServiceNotFoundException $ex){ - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $itemId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function read($itemId) { - return $this->setRead(true, $itemId); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $itemId - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function unread($itemId) { - return $this->setRead(false, $itemId); - } - - - private function setStarred($isStarred, $feedId, $guidHash) { - try { - $this->itemService->star( - $feedId, $guidHash, $isStarred, $this->userId - ); - } catch(ServiceNotFoundException $ex){ - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $feedId - * @param string $guidHash - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function star($feedId, $guidHash) { - return $this->setStarred(true, $feedId, $guidHash); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $feedId - * @param string $guidHash - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function unstar($feedId, $guidHash) { - return $this->setStarred(false, $feedId, $guidHash); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int $newestItemId - */ - public function readAll($newestItemId) { - $this->itemService->readAll($newestItemId, $this->userId); - } - - - private function setMultipleRead($isRead, $items) { - foreach($items as $id) { - try { - $this->itemService->read($id, $isRead, $this->userId); - } catch(ServiceNotFoundException $ex) { - continue; - } - } - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int[] item ids - */ - public function readMultiple($items) { - $this->setMultipleRead(true, $items); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int[] item ids - */ - public function unreadMultiple($items) { - $this->setMultipleRead(false, $items); - } - - - private function setMultipleStarred($isStarred, $items) { - foreach($items as $item) { - try { - $this->itemService->star($item['feedId'], $item['guidHash'], - $isStarred, $this->userId); - } catch(ServiceNotFoundException $ex) { - continue; - } - } - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int[] item ids - */ - public function starMultiple($items) { - $this->setMultipleStarred(true, $items); - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - * - * @param int[] item ids - */ - public function unstarMultiple($items) { - $this->setMultipleStarred(false, $items); - } - - -} diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php deleted file mode 100644 index ac838f1bf..000000000 --- a/controller/itemcontroller.php +++ /dev/null @@ -1,218 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\IConfig; -use \OCP\AppFramework\Controller; -use \OCP\AppFramework\Http; - -use \OCA\News\Service\ServiceException; -use \OCA\News\Service\ServiceNotFoundException; -use \OCA\News\Service\ItemService; -use \OCA\News\Service\FeedService; - - -class ItemController extends Controller { - - use JSONHttpError; - - private $itemService; - private $feedService; - private $userId; - private $settings; - - public function __construct($AppName, - IRequest $request, - FeedService $feedService, - ItemService $itemService, - IConfig $settings, - $UserId){ - parent::__construct($AppName, $request); - $this->itemService = $itemService; - $this->feedService = $feedService; - $this->userId = $UserId; - $this->settings = $settings; - } - - - /** - * @NoAdminRequired - * - * @param int $type - * @param int $id - * @param int $limit - * @param int $offset - * @param bool $showAll - * @param bool $oldestFirst - * @param string $search - * @return array - */ - 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' - ) === '1'; - } - - if ($oldestFirst === null) { - $oldestFirst = $this->settings->getUserValue( - $this->userId, $this->appName, 'oldestFirst' - ) === '1'; - } - - $this->settings->setUserValue($this->userId, $this->appName, - 'lastViewedFeedId', $id); - $this->settings->setUserValue($this->userId, $this->appName, - 'lastViewedFeedType', $type); - - $params = []; - - // split search parameter on url space - $search = trim(urldecode($search)); - $search = preg_replace('/\s+/', ' ', $search); // remove multiple ws - if ($search === '') { - $search = []; - } else { - $search = explode(' ', $search); - } - - 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 - if($offset === 0) { - $params['newestItemId'] = - $this->itemService->getNewestItemId($this->userId); - $params['feeds'] = $this->feedService->findAll($this->userId); - $params['starred'] = - $this->itemService->starredCount($this->userId); - } - - $params['items'] = $this->itemService->findAll( - $id, $type, $limit, $offset, $showAll, $oldestFirst, - $this->userId, $search - ); - - // this gets thrown if there are no items - // in that case just return an empty array - } catch(ServiceException $ex) {} - - return $params; - } - - - /** - * @NoAdminRequired - * - * @param int $type - * @param int $id - * @param int $lastModified - * @return array - */ - public function newItems($type, $id, $lastModified=0) { - $showAll = $this->settings->getUserValue($this->userId, $this->appName, - 'showAll') === '1'; - - $params = []; - - try { - $params['newestItemId'] = - $this->itemService->getNewestItemId($this->userId); - $params['feeds'] = $this->feedService->findAll($this->userId); - $params['starred'] = - $this->itemService->starredCount($this->userId); - $params['items'] = $this->itemService->findAllNew($id, $type, - $lastModified, $showAll, $this->userId); - - // this gets thrown if there are no items - // in that case just return an empty array - } catch(ServiceException $ex) {} - - return $params; - } - - - /** - * @NoAdminRequired - * - * @param int $feedId - * @param string $guidHash - * @param bool $isStarred - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function star($feedId, $guidHash, $isStarred){ - try { - $this->itemService->star($feedId, $guidHash, $isStarred, - $this->userId); - } catch(ServiceException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * - * @param int $itemId - * @param bool $isRead - * @return array|\OCP\AppFramework\Http\JSONResponse - */ - public function read($itemId, $isRead=true){ - try { - $this->itemService->read($itemId, $isRead, $this->userId); - } catch(ServiceException $ex) { - return $this->error($ex, Http::STATUS_NOT_FOUND); - } - - return []; - } - - - /** - * @NoAdminRequired - * - * @param int $highestItemId - * @return array - */ - public function readAll($highestItemId){ - $this->itemService->readAll($highestItemId, $this->userId); - return ['feeds' => $this->feedService->findAll($this->userId)]; - } - - - /** - * @NoAdminRequired - * - * @param int[] item ids - */ - public function readMultiple($itemIds) { - foreach($itemIds as $id) { - try { - $this->itemService->read($id, true, $this->userId); - } catch(ServiceNotFoundException $ex) { - continue; - } - } - } - - -} diff --git a/controller/jsonhttperror.php b/controller/jsonhttperror.php deleted file mode 100644 index 722019ae1..000000000 --- a/controller/jsonhttperror.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @copyright Bernhard Posselt 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\AppFramework\Http\JSONResponse; - - -trait JSONHttpError { - - - /** - * @param \Exception $exception the message that is returned taken from the - * exception - * @param int $code the http error code - * @return \OCP\AppFramework\Http\JSONResponse - */ - public function error(\Exception $exception, $code) { - return new JSONResponse(['message' => $exception->getMessage()], $code); - } - - -} \ No newline at end of file diff --git a/controller/pagecontroller.php b/controller/pagecontroller.php deleted file mode 100644 index 09257ee3b..000000000 --- a/controller/pagecontroller.php +++ /dev/null @@ -1,224 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -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\AppConfig; -use OCA\News\Config\Config; -use OCA\News\Explore\RecommendedSites; -use OCA\News\Explore\RecommendedSiteNotFoundException; -use OCA\News\Db\FeedType; - -class PageController extends Controller { - - private $settings; - private $l10n; - private $userId; - private $appConfig; - private $urlGenerator; - private $config; - private $recommendedSites; - private $statusService; - - use JSONHttpError; - - public function __construct($AppName, - IRequest $request, - IConfig $settings, - IURLGenerator $urlGenerator, - AppConfig $appConfig, - Config $config, - IL10N $l10n, - RecommendedSites $recommendedSites, - StatusService $statusService, - $UserId){ - parent::__construct($AppName, $request); - $this->settings = $settings; - $this->urlGenerator = $urlGenerator; - $this->appConfig = $appConfig; - $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', [ - 'cronWarning' => $status['warnings']['improperlyConfiguredCron'], - '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); - } - } - - - /** - * @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 - * - * @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); - } - } - - -} diff --git a/controller/userapicontroller.php b/controller/userapicontroller.php deleted file mode 100644 index 8db2b6937..000000000 --- a/controller/userapicontroller.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\IUserSession; -use \OCP\IURLGenerator; -use \OCP\Files\IRootFolder; -use \OCP\AppFramework\ApiController; -use \OCP\AppFramework\Http; - -class UserApiController extends ApiController { - - private $userSession; - private $rootFolder; - - public function __construct($AppName, - IRequest $request, - IUserSession $userSession, - IRootFolder $rootFolder){ - parent::__construct($AppName, $request); - $this->userSession = $userSession; - $this->rootFolder = $rootFolder; - } - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - */ - public function index() { - $user = $this->userSession->getUser(); - - // find the avatar - $jpgAvatar = '/' . $user->getUID() . '/avatar.jpg'; - $pngAvatar = '/' . $user->getUID() . '/avatar.png'; - $avatar = null; - - if ($this->rootFolder->nodeExists($jpgAvatar)) { - $file = $this->rootFolder->get($jpgAvatar); - $avatar = [ - 'data' => base64_encode($file->getContent()), - 'mime' => 'image/jpeg' - ]; - } elseif ($this->rootFolder->nodeExists($pngAvatar)) { - $file = $this->rootFolder->get($pngAvatar); - $avatar = [ - 'data' => base64_encode($file->getContent()), - 'mime' => 'image/png' - ]; - } - - return [ - 'userId' => $user->getUID(), - 'displayName' => $user->getDisplayName(), - 'lastLoginTimestamp' => $user->getLastLogin(), - 'avatar' => $avatar - ]; - } - -} diff --git a/controller/utilityapicontroller.php b/controller/utilityapicontroller.php deleted file mode 100644 index e613e70a5..000000000 --- a/controller/utilityapicontroller.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Controller; - -use \OCP\IRequest; -use \OCP\IConfig; -use \OCP\AppFramework\ApiController; -use \OCP\AppFramework\Http; - -use \OCA\News\Utility\Updater; -use \OCA\News\Service\StatusService; - - -class UtilityApiController extends ApiController { - - private $updater; - private $settings; - private $statusService; - - public function __construct($AppName, - IRequest $request, - Updater $updater, - IConfig $settings, - StatusService $statusService){ - parent::__construct($AppName, $request); - $this->updater = $updater; - $this->settings = $settings; - $this->statusService = $statusService; - } - - - /** - * @NoAdminRequired - * @NoCSRFRequired - * @CORS - */ - public function version() { - $version = $this->settings->getAppValue($this->appName, - 'installed_version'); - return ['version' => $version]; - } - - - /** - * @NoCSRFRequired - * @CORS - */ - public function beforeUpdate() { - $this->updater->beforeUpdate(); - } - - - /** - * @NoCSRFRequired - * @CORS - */ - public function afterUpdate() { - $this->updater->afterUpdate(); - } - - - /** - * @CORS - * @NoCSRFRequired - * @NoAdminRequired - */ - public function status() { - return $this->statusService->getStatus(); - } - - -} -- cgit v1.2.3