Browse Source

- Refactor the global dispatcher to pake it more clean

pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
1038491727
  1. 15
      app/controllers/AboutController.php
  2. 13
      app/controllers/DisconnectController.php
  3. 15
      app/controllers/LoginController.php
  4. 18
      app/controllers/MainController.php
  5. 0
      app/views/about.tpl
  6. 0
      app/views/login.tpl
  7. 25
      app/views/main.tpl
  8. 9
      bootstrap.php
  9. 10
      index.php
  10. 10
      system/Tpl/TplPageBuilder.php
  11. 55
      system/Tpl/TplTheme.php
  12. 38
      system/controllers/BaseController.php
  13. 42
      system/controllers/FrontController.php
  14. 3
      system/i18n/i18n.php

15
app/controllers/AboutController.php

@ -0,0 +1,15 @@
<?php
class AboutController extends BaseController {
function load() {
$this->session_only = false;
}
function dispatch() {
$this->page->setTitle(t('%s - About', APP_TITLE));
$this->page->menuAddLink(t('Home'), 'main');
$this->page->menuAddLink(t('Discover'), 'discover');
$this->page->menuAddLink(t('About'), 'about', true);
}
}

13
app/controllers/DisconnectController.php

@ -0,0 +1,13 @@
<?php
class DisconnectController extends BaseController {
function load() {
$this->session_only = false;
}
function dispatch() {
$user = new User();
$user->desauth();
$this->name = 'login';
}
}

15
app/controllers/LoginController.php

@ -0,0 +1,15 @@
<?php
class LoginController extends BaseController {
function load() {
$this->session_only = false;
}
function dispatch() {
$this->page->setTitle(t('%s - Login to Movim', APP_TITLE));
$this->page->menuAddLink(t('Home'), 'main', true);
$this->page->menuAddLink(t('Discover'), 'discover');
$this->page->menuAddLink(t('About'), 'about');
}
}

18
app/controllers/MainController.php

@ -0,0 +1,18 @@
<?php
class MainController extends BaseController {
function load() {
$this->session_only = true;
}
function dispatch() {
$this->page->setTitle(t('%s - Welcome to Movim', APP_TITLE));
$this->page->menuAddLink(t('Home'), 'main', true);
$this->page->menuAddLink(t('News'), 'news');
$this->page->menuAddLink(t('Explore'), 'explore');
$this->page->menuAddLink(t('Profile'), 'profile');
$this->page->menuAddLink(t('Media'), 'media');
$this->page->menuAddLink(t('Configuration'), 'conf');
$this->page->menuAddLink(t('Help'), 'help');
}
}

0
themes/movim/about.tpl → app/views/about.tpl

0
themes/movim/login.tpl → app/views/login.tpl

25
app/views/main.tpl

@ -0,0 +1,25 @@
<?php /* -*- mode: html -*- */
?>
<?php $this->widget('Poller');?>
<?php $this->widget('Presence');?>
<?php $this->widget('Chat');?>
<?php //$this->widget('ChatExt');?>
<div id="main">
<div id="left">
<?php $this->widget('Connection');?>
<?php $this->widget('Profile');?>
<?php $this->widget('Bookmark');?>
<?php $this->widget('Notifs');?>
<?php $this->widget('Location');?>
</div>
<div id="center">
<?php $this->widget('Feed');?>
</div>
</div>
<div id="right">
<?php $this->widget('Roster');?>
</div>

9
bootstrap.php

@ -124,6 +124,8 @@ class Bootstrap {
define('LOCALES_PATH', DOCUMENT_ROOT . '/locales/');
define('CACHE_PATH', DOCUMENT_ROOT . '/cache/');
define('VIEWS_PATH', DOCUMENT_ROOT . '/app/views/');
if (!defined('DOCTYPE')) {
define('DOCTYPE','text/html');
}
@ -183,12 +185,15 @@ class Bootstrap {
}
private function loadDispatcher() {
require_once(SYSTEM_PATH . "controllers/ControllerBase.php");
require_once(SYSTEM_PATH . "controllers/ControllerMain.php");
//require_once(SYSTEM_PATH . "controllers/ControllerMain.php");
require_once(SYSTEM_PATH . "controllers/ControllerAjax.php");
//require_once(SYSTEM_PATH . "controllers/FrontController.php");
require_once(SYSTEM_PATH . "Route.php");
require_once(SYSTEM_PATH . "controllers/BaseController.php");
require_once(SYSTEM_PATH . "controllers/FrontController.php");
require_once(SYSTEM_PATH . "template/TplPageBuilder.php");

10
index.php

@ -2,14 +2,14 @@
/**
* @file index.php
* This file is part of MOVIM.
* This file is part of Movim.
*
* @brief Prepares all the needed fixtures and fires up the main request
* handler.
*
* @author Movim Project <movim@movim.eu>
*
* Copyright (C)2010 Movim Project
* Copyright (C)2013 Movim Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@ -52,7 +52,8 @@ try {
$bootstrap->boot();
$rqst = new ControllerMain();
//$rqst = new ControllerMain();
$rqst = new FrontController();
$rqst->handle();
WidgetWrapper::getInstance(false);
@ -81,7 +82,8 @@ try {
if(FAIL_SAFE) {
$r = new Route;
$rqst = new ControllerMain();
//$rqst = new ControllerMain();
$rqst = new FrontController();
$rqst->handle();
}
}

10
system/Tpl/TplPageBuilder.php

@ -38,9 +38,9 @@ class TplPageBuilder
$this->theme = $conf->getServerConfElement('theme');
}
function theme_path($file)
function view_path($file)
{
return THEMES_PATH . $this->theme . '/' . $file;
return VIEWS_PATH . '/' . $file;
}
/**
@ -90,18 +90,18 @@ class TplPageBuilder
/**
* Actually generates the page from templates.
*/
function build($template)
/*function build($template)
{
if (ENVIRONMENT === 'production')ob_clean();
ob_start();
require($this->theme_path($template));
require($this->view_path($template));
$outp = ob_get_clean();
$outp = str_replace('<%scripts%>',
$this->printCss() . $this->printScripts(),
$outp);
return $outp;
}
}*/
/**
* Sets the page's title.

55
system/Tpl/TplTheme.php

@ -1,55 +0,0 @@
<?php
/**
* @file TplTheme.php
* This file is part of MOVIM.
*
* @brief This objects abstracts a Movim theme and its configuration.
*
* @author Guillaume Pasquet <etenil@etenilsrealm.nl>
*
* @version 1.0
* @date 1 April 2011
*
* Copyright (C) 2011 MOVIM Project.
*
* See included COPYING file for licensing details.
*/
class TplTheme
{
private $regions;
private $name;
private $desc;
private $author;
private $license;
private $path;
/**
* Class constructor.
* @param theme_name is the theme's name
*/
public function __construct($theme_name)
{
$this->load($theme_name);
}
/**
* Loads up the theme's files and configuration.
* @param name is the theme's name.
*/
private function load($name)
{
$this->name = $name;
$this->path = THEMES_PATH . $this->name . '/';
if(file_exists($this->path . 'conf.xml')) {
$this->conf = simplexml_load_file($this->path . 'conf.xml');
} else {
throw new MovimException(t("Couldn't load file %s", $this->path . 'conf.xml'));
}
}
}
?>

38
system/controllers/BaseController.php

@ -0,0 +1,38 @@
<?php
class BaseController {
public $name = 'main'; // The name of the current page
protected $session_only = false;// The page is protected by a session ?
protected $page;
function __construct() {
$this->page = new TplPageBuilder();
$this->page->addScript('movim_hash.js');
$this->page->addScript('movim_utils.js');
$this->page->addScript('movim_base.js');
$this->page->addScript('movim_tpl.js');
$this->page->addScript('movim_rpc.js');
}
function check_session() {
if($this->session_only) {
$user = new User();
if(!$user->isLogged()) {
$this->name = 'login';
}
}
}
function display() {
if($this->session_only) {
$user = new User();
$content = new TplPageBuilder($user);
} else {
$content = new TplPageBuilder();
}
$this->page->setContent($content->build($this->name.'.tpl'));
echo $this->page->build('page.tpl');
}
}

42
system/controllers/FrontController.php

@ -12,7 +12,7 @@
* See COPYING for licensing deatils.
*/
class FrontController
class FrontController extends ControllerBase
{
public function handle() {
$r = new Route();
@ -23,25 +23,45 @@ class FrontController
$this->error404();
}
}
/*
* Here we load, instanciate and execute the correct controller
*/
public function run_req($request) {
if(file_exists(APP_PATH . 'controllers/'.ucfirst($request).'.php')) {
$controller_path = file_exists(APP_PATH . 'controllers/'.ucfirst($request).'.php');
private function load_controller($request) {
$class_name = ucfirst($request).'Controller';
if(file_exists(APP_PATH . 'controllers/'.$class_name.'.php')) {
$controller_path = APP_PATH . 'controllers/'.$class_name.'.php';
}
else {
Logger::log(t("Requested controller '%s' doesn't exist.", $request));
\system\Logs\Logger::log(t("Requested controller '%s' doesn't exist.", $class_name));
exit;
}
require_once($controller_path);
$c = new $request();
return new $class_name();
}
/*
* Here we load, instanciate and execute the correct controller
*/
public function run_req($request) {
$c = $this->load_controller($request);
if(is_callable(array($c, 'load'))) {
$c->name = $request;
$c->load();
$c->check_session();
// If the controller ask to display a different page
if($request != $c->name) {
$new_name = $c->name;
$c = $this->load_controller($new_name);
$c->name = $new_name;
$c->load();
}
$c->dispatch();
$c->display();
} else {
Logger::log(t("Could not call the load method on the current controller"));
\system\Logs\Logger::log(t("Could not call the load method on the current controller"));
}
}
}

3
system/i18n/i18n.php

@ -143,7 +143,8 @@ function load_language_auto()
}
while((list($key, $value) = each($langs)) && $langNotFound == true) {
$key = reset(explode('-', $key));
$exploded = explode('-', $key);
$key = reset($exploded);
if($key == 'en') {
load_language(\system\Conf::getServerConfElement('defLang'));
$langNotFound = false;

Loading…
Cancel
Save