diff options
Diffstat (limited to 'appinfo/routes.php')
-rw-r--r-- | appinfo/routes.php | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php new file mode 100644 index 000000000..21c1de90d --- /dev/null +++ b/appinfo/routes.php @@ -0,0 +1,202 @@ +<?php +/** +* ownCloud - News app +* +* @author Bernhard Posselt +* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + +namespace OCA\News; + +require_once \OC_App::getAppPath('news') . '/appinfo/bootstrap.php'; + +/** + * Shortcut for calling a controller method and printing the result + * @param string $controllerName: the name of the controller under which it is + * stored in the DI container + * @param string $methodName: the method that you want to call + * @param array $urlParams: an array with variables extracted from the routes + * @param bool $disableAdminCheck: disables the check for adminuser rights + * @param bool $isAjax: if the request is an ajax request + */ +function callController($controllerName, $methodName, $urlParams, $disableAdminCheck=true, + $isAjax=false){ + $container = createDIContainer(); + + // run security checks + $security = $container['Security']; + runSecurityChecks($security, $isAjax, $disableAdminCheck); + + // call the controller and render the page + $controller = $container[$controllerName]; + $response = $controller->$methodName($urlParams); + echo $response->render(); +} + + +/** + * Shortcut for calling an ajax controller method and printing the result + * @param string $controllerName: the name of the controller under which it is + * stored in the DI container + * @param string $methodName: the method that you want to call + * @param array $urlParams: an array with variables extracted from the routes + * @param bool $disableAdminCheck: disables the check for adminuser rights + */ +function callAjaxController($controllerName, $methodName, $urlParams, $disableAdminCheck=true){ + callController($controllerName, $methodName, $urlParams, $disableAdminCheck, true); +} + + +/** + * Runs the security checks and exits on error + * @param Security $security: the security object + * @param bool $isAjax: if true, the ajax checks will be run, otherwise the normal + * checks + * @param bool $disableAdminCheck: disables the check for adminuser rights + */ +function runSecurityChecks($security, $isAjax=false, $disableAdminCheck=true){ + if($disableAdminCheck){ + $security->setIsAdminCheck(false); + } + + if($isAjax){ + $security->runAJAXChecks(); + } else { + $security->runChecks(); + } +} + + +/************************* + * Define your routes here + */ + + +/** + * Normal Routes + */ +$this->create('news_index', '/')->action( + function($params){ + callController('NewsController', 'index', $params, true); + } +); + +$this->create('news_index_feed', '/feed/{feedid}')->action( + function($params){ + callController('NewsController', 'index', $params, true); + } +); + +$this->create('news_export_opml', '/export/opml')->action( + function($params){ + callController('NewsController', 'exportOPML', $params, true); + } +); + + +/** + * AJAX Routes + */ +$this->create('news_ajax_init', '/ajax/init')->action( + function($params){ + callAjaxController('NewsAjaxController', 'init', $params); + } +); + +$this->create('news_ajax_setshowall', '/ajax/setshowall')->action( + function($params){ + callAjaxController('NewsAjaxController', 'setShowAll', $params); + } +); + + +/** + * Folders + */ +$this->create('news_ajax_collapsefolder', '/ajax/collapsefolder')->action( + function($params){ + callAjaxController('NewsAjaxController', 'collapseFolder', $params); + } +); + +$this->create('news_ajax_changefoldername', '/ajax/changefoldername')->action( + function($params){ + callAjaxController('NewsAjaxController', 'changeFolderName', $params); + } +); + +$this->create('news_ajax_createfolder', '/ajax/createfolder')->action( + function($params){ + callAjaxController('NewsAjaxController', 'createFolder', $params); + } +); + +$this->create('news_ajax_deletefolder', '/ajax/deletefolder')->action( + function($params){ + callAjaxController('NewsAjaxController', 'deleteFolder', $params); + } +); + + +/** + * Feeds + */ +$this->create('news_ajax_loadfeed', '/ajax/loadfeed')->action( + function($params){ + callAjaxController('NewsAjaxController', 'loadFeed', $params); + } +); + +$this->create('news_ajax_deletefeed', '/ajax/deletefeed')->action( + function($params){ + callAjaxController('NewsAjaxController', 'deleteFeed', $params); + } +); + +$this->create('news_ajax_movefeedtofolder', '/ajax/movefeedtofolder')->action( + function($params){ + callAjaxController('NewsAjaxController', 'moveFeedToFolder', $params); + } +); + +$this->create('news_ajax_updatefeed', '/ajax/updatefeed')->action( + function($params){ + callAjaxController('NewsAjaxController', 'updateFeed', $params); + } +); + +$this->create('news_ajax_createfeed', '/ajax/createfeed')->action( + function($params){ + callAjaxController('NewsAjaxController', 'createFeed', $params); + } +); + + +/** + * Items + */ +$this->create('news_ajax_setitemstatus', '/ajax/setitemstatus')->action( + function($params){ + callAjaxController('NewsAjaxController', 'setItemStatus', $params); + } +); + +$this->create('news_ajax_setallitemsread', '/ajax/setallitemsread')->action( + function($params){ + callAjaxController('NewsAjaxController', 'setAllItemsRead', $params); + } +); + + +/** + * Import stuff + */ +$this->create('news_ajax_importOPML', '/import')->action( + function($params){ + callAjaxController('NewsAjaxController', 'uploadOPML', $params); + } +); |