diff --git a/app/controllers/AboutController.php b/app/controllers/AboutController.php new file mode 100644 index 000000000..5f46d8626 --- /dev/null +++ b/app/controllers/AboutController.php @@ -0,0 +1,15 @@ +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); + } +} diff --git a/app/controllers/DisconnectController.php b/app/controllers/DisconnectController.php new file mode 100644 index 000000000..80bd506e8 --- /dev/null +++ b/app/controllers/DisconnectController.php @@ -0,0 +1,13 @@ +session_only = false; + } + + function dispatch() { + $user = new User(); + $user->desauth(); + $this->name = 'login'; + } +} diff --git a/app/controllers/LoginController.php b/app/controllers/LoginController.php new file mode 100644 index 000000000..e990c9284 --- /dev/null +++ b/app/controllers/LoginController.php @@ -0,0 +1,15 @@ +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'); + } +} diff --git a/app/controllers/MainController.php b/app/controllers/MainController.php new file mode 100644 index 000000000..6fc91b097 --- /dev/null +++ b/app/controllers/MainController.php @@ -0,0 +1,18 @@ +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'); + } +} diff --git a/themes/movim/about.tpl b/app/views/about.tpl similarity index 100% rename from themes/movim/about.tpl rename to app/views/about.tpl diff --git a/themes/movim/login.tpl b/app/views/login.tpl similarity index 100% rename from themes/movim/login.tpl rename to app/views/login.tpl diff --git a/app/views/main.tpl b/app/views/main.tpl new file mode 100644 index 000000000..432b8dbe3 --- /dev/null +++ b/app/views/main.tpl @@ -0,0 +1,25 @@ + +widget('Poller');?> +widget('Presence');?> +widget('Chat');?> +widget('ChatExt');?> + +
+
+ widget('Connection');?> + widget('Profile');?> + widget('Bookmark');?> + widget('Notifs');?> + widget('Location');?> +
+ +
+ widget('Feed');?> +
+ +
+ + diff --git a/bootstrap.php b/bootstrap.php index b45557550..2d53bc574 100644 --- a/bootstrap.php +++ b/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"); diff --git a/index.php b/index.php index 01703308d..25a746492 100644 --- a/index.php +++ b/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 * - * 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(); } } diff --git a/system/Tpl/TplPageBuilder.php b/system/Tpl/TplPageBuilder.php index c57c68c67..c12d12c91 100644 --- a/system/Tpl/TplPageBuilder.php +++ b/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. diff --git a/system/Tpl/TplTheme.php b/system/Tpl/TplTheme.php deleted file mode 100644 index d43955abc..000000000 --- a/system/Tpl/TplTheme.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * @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')); - } - } -} - -?> diff --git a/system/controllers/BaseController.php b/system/controllers/BaseController.php new file mode 100644 index 000000000..8452b3c12 --- /dev/null +++ b/system/controllers/BaseController.php @@ -0,0 +1,38 @@ +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'); + } +} diff --git a/system/controllers/FrontController.php b/system/controllers/FrontController.php index 2fc158a70..400ae92e5 100644 --- a/system/controllers/FrontController.php +++ b/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")); } } } diff --git a/system/i18n/i18n.php b/system/i18n/i18n.php index a9aa07943..c53be2d3e 100644 --- a/system/i18n/i18n.php +++ b/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;