summaryrefslogtreecommitdiffstats
path: root/controllers
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2012-11-02 22:17:06 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2012-11-02 22:17:06 +0100
commitded22aaf4b1de1cdd813dcebae8ee52bbf351ae3 (patch)
treebc2836eca25b6b3c041caf61a7572fa9c3d26f77 /controllers
parent9112586eeca8ca5216d66b1820d175c12ef3cf0d (diff)
removed unforseen overwrite of controller classes
Diffstat (limited to 'controllers')
-rw-r--r--controllers/controller.php151
-rw-r--r--controllers/news.controller.php23
2 files changed, 27 insertions, 147 deletions
diff --git a/controllers/controller.php b/controllers/controller.php
index 43487f0ad..032cb45ee 100644
--- a/controllers/controller.php
+++ b/controllers/controller.php
@@ -10,15 +10,16 @@
*
*/
-
namespace OCA\News;
class Controller {
+ protected $userId;
protected $trans;
- private $safeParams;
+
public function __construct(){
+ $this->userId = \OCP\USER::getUser();
$this->trans = \OC_L10N::get('news');
$this->safeParams = array();
}
@@ -64,154 +65,36 @@ class Controller {
/**
- * Renders a renderer and sets the csrf check and logged in check to true
- * @param Renderer $renderer: the render which should be used to render the page
- */
- protected function render(Renderer $renderer){
- $renderer->render();
- }
-
-
- /**
* Binds variables to the template and prints it
- * @param $templateName the name of the template
+ * The following values are always assigned: userId, trans
* @param $arguments an array with arguments in $templateVar => $content
+ * @param $template the name of the template
* @param $safeParams template parameters which should not be escaped
* @param $fullPage if true, it will render a full page, otherwise only a part
* defaults to true
*/
- protected function renderTemplate($templateName, $arguments=array(),
- $safeParams=array(), $fullPage=true){
- $renderer = new TemplateRenderer($templateName, $fullPage);
- $renderer->bind($arguments);
- $renderer->bindSafe($safeParams);
- $this->render($renderer);
- }
-
- /**
- * Binds variables to a JSON array and prints it
- * @param $arguments an array with arguments in $key => $value
- * @param $error: Empty by default. If set, a log message written and the
- * $error will be sent to the client
- */
- protected function renderJSON($arguments=array(), $error=""){
- $renderer = new JSONRenderer($error);
- $renderer->bind($arguments);
- $this->render($renderer);
- }
-
-
-}
-
+ protected function render($template, $arguments=array(), $safeParams=array(),
+ $fullPage=true){
-/**
- * Renderers
- */
-interface Renderer {
- public function render();
- public function bind($params);
-}
-
-
-/**
- * Used to render a normal template
- */
-class TemplateRenderer implements Renderer {
-
- private $safeParams = array();
- private $template;
-
- /**
- * @param string $name: the template which we want to render
- * @param $fullPage: if the page should be included into the standard page
- */
- public function __construct($name, $fullPage=true){
if($fullPage){
- $this->template = new \OCP\Template('news', $name, 'user');
+ $template = new \OCP\Template('news', $template, 'user');
} else {
- $this->template = new \OCP\Template('news', $name);
+ $template = new \OCP\Template('news', $template);
}
- }
-
-
- /**
- * @brief binds parameters to the renderer which shouldnt be escaped
- * @param array $params: an array of the form $doNotEscape => true
- */
- public function bindSafe($params){
- $this->safeParams = $params;
- }
-
- /**
- * Bind parameters to the template
- * @param array $params: an array of the form $key => value which will be used
- * for access in templates
- */
- public function bind($params){
- foreach($params as $key => $value){
- if(array_key_exists($key, $this->safeParams)) {
- $this->template->assign($key, $value, false);
+ foreach($arguments as $key => $value){
+ if(array_key_exists($key, $safeParams)) {
+ $template->assign($key, $value, false);
} else {
- $this->template->assign($key, $value);
+ $template->assign($key, $value);
}
- }
- }
+ }
- /**
- * Print the page
- */
- public function render(){
- $this->template->printPage();
+ $template->assign('userId', $this->userId);
+ $template->assign('trans', $this->trans);
+ $template->printPage();
}
}
-
-
-
-/**
- * Use this to render JSON calls
- */
-class JSONRenderer implements Renderer {
-
- private $params;
-
- /**
- * @param string $error: if empty a success is sent, otherwise an error message
- * will be logged
- */
- public function __construct($error){
- $this->error = $error;
- }
-
-
- /**
- * Bind parameters to the template
- * @param array $params: an array which will be converted to JSON
- */
- public function bind($params){
- $this->params = $params;
- }
-
-
- /**
- * Print the json array
- */
- public function render(){
- if($this->error === ""){
- OCP\JSON::success($this->params);
- } else {
- OCP\JSON::error(array(
- 'data' => array('message' => $l->t('An error occured: ') . $error)
- )
- );
- OCP\Util::writeLog('news',$_SERVER['REQUEST_URI'] . 'Error: '. $error, OCP\Util::ERROR);
- exit();
- }
-
- }
-
-
-} \ No newline at end of file
diff --git a/controllers/news.controller.php b/controllers/news.controller.php
index bf31d08f2..0338c23e9 100644
--- a/controllers/news.controller.php
+++ b/controllers/news.controller.php
@@ -12,34 +12,31 @@
namespace OCA\News;
-require_once \OC_App::getAppPath('news') . '/controllers/controller.php';
-
-
class NewsController extends Controller {
/**
* Decides wether to show the feedpage or the firstrun page
*/
- public function index($request){
+ public function index(){
$feedMapper = new FeedMapper($this->userId);
if($feedMapper->feedCount() > 0){
- $this->feedPage($request);
+ $this->feedPage();
} else {
- $this->firstRun($request);
+ $this->firstRun();
}
}
- public function firstRun($request){
+ public function firstRun(){
$this->addScript('news');
$this->addScript('firstrun');
$this->addStyle('firstrun');
- $this->renderTemplate('firstrun');
+ $this->render('firstrun');
}
- public function feedPage($request){
+ public function feedPage(){
$this->addScript('main');
$this->addScript('news');
$this->addScript('menu');
@@ -54,10 +51,10 @@ class NewsController extends Controller {
$itemMapper = new ItemMapper($this->userId);
// if no feed id is passed as parameter, then show the last viewed feed on reload
- $lastViewedFeedId = isset( $request->get['feedid'] ) ? $request->get['feedid'] : (int)$this->getUserValue('lastViewedFeed');
- $lastViewedFeedType = isset( $request->get['feedid'] ) ? FeedType::FEED : (int)$this->getUserValue('lastViewedFeedType');
+ $lastViewedFeedId = isset( $_GET['feedid'] ) ? $_GET['feedid'] : (int)$this->getUserValue('lastViewedFeed');
+ $lastViewedFeedType = isset( $_GET['feedid'] ) ? FeedType::FEED : (int)$this->getUserValue('lastViewedFeedType');
- $showAll = $this->getUserValue('showAll');
+ $showAll = $this->getUserValue('showAll');
if( $lastViewedFeedId === null || $lastViewedFeedType === null) {
$lastViewedFeedId = $feedMapper->mostRecent();
@@ -90,7 +87,7 @@ class NewsController extends Controller {
'items' => $items
);
- $this->renderTemplate('main', $params, array('items' => true));
+ $this->render('main', $params, array('items' => true));
}