Page MenuHomeDevCentral

No OneTemporary

diff --git a/controllers/anonymous.php b/controllers/anonymous.php
index da2b4c7..b36e0ee 100755
--- a/controllers/anonymous.php
+++ b/controllers/anonymous.php
@@ -1,148 +1,148 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Controller to handle the pages for not logged in users.
*
* It recognizes the following URLs:
* /invite the page to claim the invites.
*
* In all other cases, it prints the login form.
*
* @package ObsidianWorkspaces
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
//
// Prepares the page
//
switch ($url[0]) {
case 'invite':
echo "You have been invited to use Obsidian. This feature is currently disabled. Please ask the person who invited you to contact our support desk to create your account.";
/* Code from Zed
//Invite form
if ($_POST['form'] == 'account.create') {
//User tries to claim its invite to create an account
require_once('includes/objects/invite.php');
require_once('includes/objects/user.php');
//Gets invite
$invite = new Invite($_POST['invite_code']);
if ($invite->lastError != '') {
//Not existant invite.
$smarty->assign('NOTIFY', lang_get("IncorrectInviteCode"));
} elseif ($invite->is_claimed()) {
//The invitation have already claimed by someone else.
$smarty->assign('NOTIFY', lang_get("InviteCodeAlreadyClaimed"));
} else {
//Checks if the given information is correct
//We ignore bad mails. All we really need is a login and a pass.
//We fill our array $errors with all the errors
$errors = array();
if (!$_POST['username']) {
$errors[] = lang_get('MissingUsername');
} elseif (!User::is_available_login($_POST['username'])) {
$errors[] = lang_get('LoginUnavailable');
}
if (User::get_username_from_email($_POST['email']) !== false) {
$errors[] = "There is already an account with this e-mail.";
}
if (!$_POST['passwd']) {
$errors[] = lang_get('MissingPassword');
}
if (count($errors)) {
$smarty->assign('WAP', join('<br />', $errors));
} else {
//Creates account
$user = new User();
$user->regdate = time();
$user->generate_id();
$user->name = $_POST['username'];
$user->active = 1;
$user->email = $_POST['email'];
$user->set_password($_POST['passwd']);
$user->save_to_database();
//Updates invite
$invite->to_user_id = $user->id;
$invite->save_to_database();
//Notifies inviter
require_once('includes/objects/message.php');
$message = new Message();
$message->from = 0;
$message->to = $invite->from_perso_id;
$message->text = sprintf(lang_get('InviteHaveBeenClaimed'), $invite->code);
$message->send();
//Logs in user
login($user->id, $user->name);
//Prints confirm message
$smarty->assign('WAP', lang_get("AccountCreated"));
//Redirects users to homepage
header('refresh: 5; url=' . get_url());
//Calls void controller
$smarty->assign('screen', 'user.create');
define('NO_FOOTER_EXTRA', true);
include("void.php");
exit;
}
}
//Keeps username, email, invite code printed on account create form
$smarty->assign('username', $_POST['username']);
$smarty->assign('invite_code', $_POST['invite_code']);
$smarty->assign('email', $_POST['email']);
}
//If the invite code is specified, checks format
if ($url[1]) {
if (preg_match("/^([A-Z]){3}([0-9]){3}$/i", $url[1])) {
$smarty->assign('invite_code', strtoupper($url[1]));
} else {
$smarty->assign('NOTIFY', lang_get("IncorrectInviteCode"));
}
}
$template = 'account_create.tpl';
*/
break;
default:
//Login form
if (array_key_exists('LastUsername', $_COOKIE)) {
$smarty->assign('username', $_COOKIE['LastUsername']);
}
if (array_key_exists('LastOpenID', $_COOKIE)) {
$smarty->assign('OpenID', $_COOKIE['LastOpenID']);
}
$smarty->assign('LoginError', $LoginError);
- $smarty->assign('PostURL', $action = get_url() . implode('/', $url));
+ $smarty->assign('PostURL', $action = get_url() . implode('/', $context->url));
$template = 'login.tpl';
break;
}
//
// HTML output
//
if ($template) {
$smarty->display($template);
}
diff --git a/controllers/application.php b/controllers/application.php
new file mode 100644
index 0000000..e69de29
diff --git a/controllers/footer.php b/controllers/footer.php
index 1f50197..ddc75cb 100755
--- a/controllers/footer.php
+++ b/controllers/footer.php
@@ -1,24 +1,31 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Controller for footer (called on every regular page)
*
* @package ObsidianWorkspaces
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
- //
- // HTML output
- //
+/**
+ * Footer controller
+ */
+class FooterController extends Controller {
+
+ /**
+ * Handle controller request
+ */
+ public function handleRequest () {
+ $this->context->templateEngine->display('footer.tpl');
+ }
-//Prints the template
-$smarty->display('footer.tpl');
+}
diff --git a/controllers/header.php b/controllers/header.php
index 615884e..f7ecbf3 100755
--- a/controllers/header.php
+++ b/controllers/header.php
@@ -1,44 +1,42 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Controller for header (called on every regular page)
*
* @package ObsidianWorkspaces
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
-//
-// Gets header resources
-//
-
-$workspaces = $CurrentUser->get_workspaces();
-$workspaces_count = count($workspaces);
+/**
+ * Header controller
+ */
+class HeaderController extends Controller {
+ /**
+ * Handle controller request
+ */
+ public function handleRequest () {
+ //Gets header resources
+ $workspaces = $this->context->user->get_workspaces();
-//
-// HTML output
-//
+ //HTML output
+ $smarty = $this->context->templateEngine;
+ $smarty->assign('current_username', $context->user->name);
+ $smarty->assign('workspaces', $workspaces);
+ $smarty->assign('workspaces_count', count($workspaces));
+ if ($this->context->workspace !== null) {
+ $smarty->assign('current_workspace', $this->context->workspace);
+ }
-//Assigns header information
-$smarty->assign('current_username', $CurrentUser->name);
-if (isset($workspace)) {
- $smarty->assign('current_workspace', $workspace);
+ $smarty->display('header.tpl');
+ define('HEADER_PRINTED', true);
+ }
}
-$smarty->assign('workspaces', $workspaces);
-$smarty->assign('workspaces_count', $workspaces_count);
-
-//Prints the template
-$smarty->display('header.tpl');
-
-/**
- * This constant indicates the header have been printed
- */
-define('HEADER_PRINTED', true);
diff --git a/controllers/help.php b/controllers/help.php
index 163c2d3..9b6c180 100755
--- a/controllers/help.php
+++ b/controllers/help.php
@@ -1,38 +1,38 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Controller
*
* @package ObsidianWorkspaces
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
//
// HTML output
//
-$file = $Config['Content']['Help'] . '/' . ($url[1] ? $url[1] : 'index') . '.html';
+$file = $Config['Content']['Help'] . '/' . ($context->url[1] ? $context->url[1] : 'index') . '.html';
if (file_exists($file)) {
//Header
$smarty->assign('controller_custom_nav', 'nav_help.tpl');
- include('header.php');
+ HeaderController::Run($context);
//Help page
$smarty->assign('help_file', $file);
$smarty->display('help.tpl');
//Footer
- include('footer.php');
+ FooterController::Run($context);
} else {
define('ERROR_PAGE', 404);
include("controllers/errorpage.php");
}
diff --git a/controllers/home.php b/controllers/home.php
index 51f35ae..297332f 100755
--- a/controllers/home.php
+++ b/controllers/home.php
@@ -1,31 +1,31 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Controller for homepage content
*
* @package ObsidianWorkspaces
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
//
// HTML output
//
//Serves header
$smarty->assign('PAGE_TITLE', "Home");
-include('header.php');
+HeaderController::run($context);
//Serves homepage content
$smarty->display("home.tpl");
//Serves footer
-include('footer.php');
+FooterController::run($context);
diff --git a/controllers/reports.php b/controllers/reports.php
index d1e3809..ae63b19 100755
--- a/controllers/reports.php
+++ b/controllers/reports.php
@@ -1,33 +1,33 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Controller for reports
*
* @package ObsidianWorkspaces
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
$template = 'reports_view';
//
// HTML output
//
//Serves header
$smarty->assign('PAGE_TITLE', "Reports");
-include('header.php');
+HeaderController::run($context);
//Servers controller content
$smarty->display("$template.tpl");
//Serves footer
-include('footer.php');
+FooterController::run($context);
diff --git a/controllers/void.php b/controllers/void.php
index 32f728d..becebdb 100755
--- a/controllers/void.php
+++ b/controllers/void.php
@@ -1,30 +1,30 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Controller when no content has to be served
*
* @package ObsidianWorkspaces
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
//
// HTML output
//
//Serves header
$smarty->assign('PAGE_TITLE', $title);
-include('header.php');
+HeaderController::run($context);
//Doesn't serve any content;
//Servers footer
-include('footer.php');
+FooterController::run($context);
\ No newline at end of file
diff --git a/includes/autoload.php b/includes/autoload.php
new file mode 100644
index 0000000..aa7f184
--- /dev/null
+++ b/includes/autoload.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * _, __, _, _ __, _ _, _, _
+ * / \ |_) (_ | | \ | /_\ |\ |
+ * \ / |_) , ) | |_/ | | | | \|
+ * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ *
+ * Classes auto loader
+ *
+ * @package ObsidianWorkspaces
+ * @filesource
+ */
+
+/**
+ * This magic method is called when a class can't be loaded
+ */
+function obsidian_autoload ($className) {
+ //Core controllers
+ if ($className == 'HeaderController') { require './controllers/header.php'; return true; }
+ if ($className == 'FooterController') { require './controllers/footer.php'; return true; }
+
+ //Keruald and Obsidian Workspaces Libraries
+ if ($className == 'Application') { require './includes/apps/Application.php'; return true; }
+ if ($className == 'ApplicationContext') { require './includes/apps/ApplicationContext.php'; return true; }
+
+ if ($className == 'Cache') { require './includes/cache/cache.php'; return true; }
+ if ($className == 'CacheMemcached') { require './includes/cache/memcached.php'; return true; }
+ if ($className == 'CacheVoid') { require './includes/cache/void.php'; return true; }
+
+ if ($className == 'Context') { require './includes/controller/Context.php'; return true; }
+ if ($className == 'Controller') { require './includes/controller/Controller.php'; return true; }
+
+ if ($className == 'User') { require './includes/objects/user.php'; return true; }
+ if ($className == 'UserGroup') { require './includes/objects/usergroup.php'; return true; }
+ if ($className == 'Workspace') { require './includes/objects/workspace.php'; return true; }
+
+ return false;
+}
+
+spl_autoload_register('obsidian_autoload');
diff --git a/includes/controller/Context.php b/includes/controller/Context.php
new file mode 100644
index 0000000..2e57c9e
--- /dev/null
+++ b/includes/controller/Context.php
@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * _, __, _, _ __, _ _, _, _
+ * / \ |_) (_ | | \ | /_\ |\ |
+ * \ / |_) , ) | |_/ | | | | \|
+ * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ *
+ * Application context class
+ *
+ * @package ObsidianWorkspaces
+ * @subpackage Controller
+ * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD
+ * @filesource
+ */
+
+/**
+ * Context class
+ *
+ * This class describes the site context.
+ */
+class Context {
+ /**
+ * @var WorkSpace the workspace currently enabled
+ */
+ public $workspace;
+
+ /**
+ * @var User the user currently logged in
+ */
+ public $user;
+
+ /**
+ * @var Session the current session
+ */
+ public $session;
+
+ /**
+ * @var Array the URL fragments
+ */
+ public $url;
+
+ /**
+ * @var Smarty the template engine
+ */
+ public $templateEngine;
+}
diff --git a/includes/controller/Controller.php b/includes/controller/Controller.php
new file mode 100644
index 0000000..d296652
--- /dev/null
+++ b/includes/controller/Controller.php
@@ -0,0 +1,42 @@
+<?php
+
+/**
+ * _, __, _, _ __, _ _, _, _
+ * / \ |_) (_ | | \ | /_\ |\ |
+ * \ / |_) , ) | |_/ | | | | \|
+ * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ *
+ * Controller class
+ *
+ * @package ObsidianWorkspaces
+ * @subpackage Controller
+ * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD
+ * @filesource
+ */
+
+/**
+ * Controller class
+ *
+ * This class describes a controller
+ */
+class Controller {
+ /**
+ * @var string the application name
+ */
+ public static $name;
+
+ /**
+ * @var Context the site context
+ */
+ public $context;
+
+ /**
+ * Initializes a new instance of the controller with the specified context and handle request
+ */
+ public static function Run (Context $context) {
+ $controller = new static;
+ $controller->context = $context;
+ $controller->handleRequest();
+ }
+}
\ No newline at end of file
diff --git a/includes/core.php b/includes/core.php
index f5b35e1..12588b3 100755
--- a/includes/core.php
+++ b/includes/core.php
@@ -1,455 +1,456 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Core global functions
*
* @package ObsidianWorkspaces
* @subpackage Keruald
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
////////////////////////////////////////////////////////////////////////////////
/// ///
/// Configures PHP and loads site-wide used libraries ///
/// ///
////////////////////////////////////////////////////////////////////////////////
//Disables register globals
ini_set('register_globals', 'off');
//Reports all errors, help notices
error_reporting(E_ALL & ~E_NOTICE);
//Loads configuration
if (isset($_SERVER) && array_key_exists('OBSIDIAN_CONFIG', $_SERVER)) {
$configFile = $_SERVER['OBSIDIAN_CONFIG'];
if (file_exists($configFile)) {
include_once($configFile);
unset($configFile);
} else {
die("You've specified a custom configuration file path in the environment, but this file doesn't exist: $configFile");
}
} else {
include_once("config.php");
}
//Loads libraries
include_once("error.php"); //Error management
include_once("mysql.php"); //MySQL layer
include_once("session.php"); //Sessions handler
+include_once("autoload.php"); //Autoloader for needed classes
////////////////////////////////////////////////////////////////////////////////
/// ///
/// Information helper functions ///
/// ///
////////////////////////////////////////////////////////////////////////////////
/*
* Gets the username matching specified user id
* @param string $user_id the user ID
* @return string the username
*/
function get_username ($user_id) {
global $db;
$user_id = $db->sql_escape($user_id);
$sql = 'SELECT username FROM '. TABLE_USERS . " WHERE user_id = '$userid'";
return $db->sql_query_express($sql, "Can't get username from specified user id");
}
/*
* Gets the user id matching specified username
* @param string $username the username
* @return string the user ID
*/
function get_userid ($username) {
global $db;
$username = $db->sql_escape($username);
$sql = 'SELECT user_id FROM '. TABLE_USERS . " WHERE username LIKE '$username'";
return $db->sql_query_express($sql, "Can't get user id from specified username");
}
////////////////////////////////////////////////////////////////////////////////
/// ///
/// Misc helper functions ///
/// ///
////////////////////////////////////////////////////////////////////////////////
//Plural management
/*
* Gets a "s" if the specified amount requests the plural
* @param mixed $amount the quantity (should be numeric)
* @return string 's' if the amount is greater or equal than 2 ; otherwise, ''
*/
function s ($amount) {
if ($amount >= 2 || $amount <= -2 ) return 's';
}
/*
* Prints human-readable information about a variable, wrapped in a <pre> block
* @param mixed $mixed the variable to dump
*/
function dprint_r ($mixed) {
echo '<pre>';
print_r($mixed);
echo '</pre>';
}
/*
* Generates a new GUID
* @return string a guid (without {})
*/
function new_guid () {
//The guid chars
$chars = explode(',', 'a,b,c,d,e,f,0,1,2,3,4,5,6,7,8,9');
//Let's build our 36 characters string
//e.g. 68ed40c6-f5bb-4a4a-8659-3adf23536b75
$guid = "";
for ($i = 0 ; $i < 36 ; $i++) {
if ($i == 8 || $i == 13 || $i == 18 || $i == 23) {
//Dashes at position 9, 14, 19 and 24
$guid .= "-";
} else {
//0-f hex digit elsewhere
$guid .= $chars[mt_rand() % sizeof($characters)];
}
}
return $guid;
}
/*
* Determines if the expression is a valid guid (in uuid notation, without {})
* @param string $expression the guid to check
* @return true if the expression is a valid guid ; otherwise, false
*/
function is_guid ($expression) {
//We avoid regexp to speed up the check
//A guid is a 36 characters string
if (strlen($expression) != 36) return false;
$expression = strtolower($expression);
for ($i = 0 ; $i < 36 ; $i++) {
if ($i == 8 || $i == 13 || $i == 18 || $i == 23) {
//with dashes
if ($expression[$i] != '-') return false;
} else {
//and hex numbers
if (!is_numeric($expression[$i]) && $expression[$i] != 'a' && $expression[$i] != 'b' && $expression[$i] != 'c' && $expression[$i] != 'd' && $expression[$i] != 'e' && $expression[$i] != 'f' ) return false;
}
}
return true;
}
/*
* Gets file extension
* @param string $file the file to get the extension
*/
function get_extension ($file) {
$dotPosition = strrpos($file, ".");
return substr($file, $dotPosition + 1);
}
/*
* Determines if a string starts with specified substring
* @param string $haystack the string to check
* @param string $needle the substring to determines if it's the start
* @param boolean $case_sensitive determines if the search must be case sensitive
* @return boolean true if $haystack starts with $needle ; otherwise, false.
*/
function string_starts_with ($haystack, $needle, $case_sensitive = true) {
if (!$case_sensitive) {
$haystack = strtoupper($haystack);
$needle = strtoupper($needle);
}
if ($haystack == $needle) return true;
return strpos($haystack, $needle) === 0;
}
////////////////////////////////////////////////////////////////////////////////
/// ///
/// Localization (l10n) ///
/// ///
////////////////////////////////////////////////////////////////////////////////
/**
* Defines the LANG constant, to lang to print
*
* This information is contained in the session, or if not yet defined,
* it's to determine according the user's browser preferences.
* @see find_lang
*/
function initialize_lang () {
//If $_SESSION['lang'] doesn't exist yet, find a common language
if (!array_key_exists('lang', $_SESSION)) {
$lang = find_lang();
$_SESSION['lang'] = $lang ? $lang : '-';
}
if ($_SESSION['lang'] != '-')
define('LANG', $_SESSION['lang']);
}
/**
* Gets a common lang spoken by the site and the user's browser
* @see get_http_accept_languages
*
* @return string the language
*/
function find_lang () {
if (file_exists('lang') && is_dir('lang')) {
//Gets lang/ subdirectories: this is the list of available languages
$handle = opendir('lang');
while ($file = readdir($handle)) {
if ($file != '.' && $file != '..' && is_dir("lang/$file")) {
$langs[] = $file;
}
}
//The array $langs contains now the language available.
//Gets the langs the user should want:
if (!$userlangs = get_http_accept_languages())
return;
//Gets the intersection between the both languages arrays
//If it matches, returns first result
$intersect = array_intersect($userlangs, $langs);
if (count($intersect)) {
return $intersect[0];
}
//Now it's okay with Opera and Firefox but Internet Explorer will
//by default return en-US and not en or fr-BE and not fr, so second pass
foreach ($userlangs as $userlang) {
$lang = explode('-', $userlang);
if (count($lang) > 1)
$userlangs2[] = $lang[0];
}
$intersect = array_intersect($userlangs2, $langs);
if (count($intersect)) {
return $intersect[0];
}
}
}
/**
* Gets the languages accepted by the browser, by order of priority.
*
* This will read the HTTP_ACCEPT_LANGUAGE variable sent by the browser in the
* HTTP request.
*
* @return Array an array of string, each item a language accepted by browser
*/
function get_http_accept_languages () {
//What language to print is sent by browser in HTTP_ACCEPT_LANGUAGE var.
//This will be something like en,fr;q=0.8,fr-fr;q=0.5,en-us;q=0.3
if (!array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
return null;
}
$http_accept_language = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
foreach ($http_accept_language as $language) {
$userlang = explode(';q=', $language);
if (count($userlang) == 1) {
$userlangs[] = array(1, $language);
} else {
$userlangs[] = array($userlang[1], $userlang[0]);
}
}
rsort($userlangs);
foreach ($userlangs as $userlang) {
$result[] = $userlang[1];
}
return $result;
}
/**
* Loads specified language Smarty configuration file
*
* @param string $file the file to load
* @param mixed $sections array of section names, single section or null
*/
function lang_load ($file, $sections = null) {
global $smarty;
//Loads English file as fallback if some parameters are missing
if (file_exists("lang/en/$file"))
$smarty->configLoad("lang/en/$file", $sections);
//Loads wanted file (if it exists and a language have been defined)
if (defined('LANG') && LANG != 'en' && file_exists('lang/' . LANG . '/' . $file))
$smarty->configLoad('lang/' . LANG . '/' . $file, $sections);
}
/**
* Gets a specified language expression defined in configuration file
*
* @param string $key the configuration key matching the value to get
* @return string The value in the configuration file
*/
function lang_get ($key) {
global $smarty;
$smartyConfValue = $smarty->config_vars[$key];
return $smartyConfValue ? $smartyConfValue : "#$key#";
}
////////////////////////////////////////////////////////////////////////////////
/// ///
/// URL helpers functions ///
/// ///
////////////////////////////////////////////////////////////////////////////////
/*
* Gets URL
* @return string URL
*/
function get_url () {
global $Config;
if (func_num_args() > 0) {
$pieces = func_get_args();
return $Config['BaseURL'] . '/' . implode('/', $pieces);
} elseif ($Config['BaseURL'] == "" || $Config['BaseURL'] == "/index.php") {
return "/";
} else {
return $Config['BaseURL'];
}
}
/*
* Gets page URL
* @return string URL
*/
function get_page_url () {
$url = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'];
if (substr($url, -10) == "/index.php") {
return substr($url, 0, -9);
}
return $url;
}
/*
* Gets server URL
* @todo find a way to detect https:// on non standard port
* @return string the server URL
*/
function get_server_url () {
switch ($port = $_SERVER['SERVER_PORT']) {
case '80':
return "http://$_SERVER[SERVER_NAME]";
case '443':
return "https://$_SERVER[SERVER_NAME]";
default:
return "http://$_SERVER[SERVER_NAME]:$_SERVER[SERVER_PORT]";
}
}
/*
* Gets $_SERVER['PATH_INFO'] or computes the equivalent if not defined.
* @return string the relevant URL part
*/
function get_current_url () {
global $Config;
//Gets relevant URL part from relevant $_SERVER variables
if (array_key_exists('PATH_INFO', $_SERVER)) {
//Without mod_rewrite, and url like /index.php/controller
//we use PATH_INFO. It's the easiest case.
return $_SERVER["PATH_INFO"];
}
//In other cases, we'll need to get the relevant part of the URL
$current_url = get_server_url() . $_SERVER['REQUEST_URI'];
//Relevant URL part starts after the site URL
$len = strlen($Config['SiteURL']);
//We need to assert it's the correct site
if (substr($current_url, 0, $len) != $Config['SiteURL']) {
dieprint_r(GENERAL_ERROR, "Edit includes/config.php and specify the correct site URL<br /><strong>Current value:</strong> $Config[SiteURL]<br /><strong>Expected value:</strong> a string starting by " . get_server_url(), "Setup");
}
if (array_key_exists('REDIRECT_URL', $_SERVER)) {
//With mod_rewrite, we can use REDIRECT_URL
//We takes the end of the URL, ie *FROM* $len position
return substr(get_server_url() . $_SERVER["REDIRECT_URL"], $len);
}
//Last possibility: use REQUEST_URI, but remove QUERY_STRING
//If you need to edit here, use $_SERVER['REQUEST_URI']
//but you need to discard $_SERVER['QUERY_STRING']
//We takes the end of the URL, ie *FROM* $len position
$url = substr(get_server_url() . $_SERVER["REQUEST_URI"], $len);
//But if there are a query string (?action=... we need to discard it)
if ($_SERVER['QUERY_STRING']) {
return substr($url, 0, strlen($url) - strlen($_SERVER['QUERY_STRING']) - 1);
}
return $url;
}
/*
* Gets an array of url fragments to be processed by controller
* @return array an array containing URL fragments
*/
function get_current_url_fragments () {
$url_source = get_current_url();
if ($url_source == '/index.php') return array();
return explode('/', substr($url_source, 1));
}
////////////////////////////////////////////////////////////////////////////////
/// ///
/// URL xmlHttpRequest helpers functions ///
/// ///
////////////////////////////////////////////////////////////////////////////////
/*
* Gets an hash value to check the integrity of URLs in /do.php calls
* @param Array $args the args to compute the hash
* @return the hash paramater for your xmlHttpRequest url
*/
function get_xhr_hash ($args) {
global $Config;
array_shift($args);
return md5($_SESSION['ID'] . $Config['SecretKey'] . implode('', $args));
}
/*
* Gets the URL to call do.php, the xmlHttpRequest controller
* @return string the xmlHttpRequest url, with an integrity hash
*/
function get_xhr_hashed_url () {
global $Config;
$args = func_get_args();
$args[] = get_xhr_hash($args);
return $Config['DoURL'] . '/' . implode('/', $args);
}
/*
* Gets the URL to call do.php, the xmlHttpRequest controller
* @return string the xmlHttpRequest url
*/
function get_xhr_url () {
global $Config;
$args = func_get_args();
return $Config['DoURL'] . '/' .implode('/', $args);
}
diff --git a/index.php b/index.php
index 3117512..1babfcb 100755
--- a/index.php
+++ b/index.php
@@ -1,101 +1,105 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Main web application entry point
*
* @package ObsidianWorkspaces
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*
*/
////////////////////////////////////////////////////////////////////////////////
///
/// Initialization
///
//Keruald and Obsidian Workspaces libraries
include('includes/core.php');
-include('includes/cache/cache.php');
-include('includes/objects/workspace.php');
+
+//New application context
+$context = new ApplicationContext();
////////////////////////////////////////////////////////////////////////////////
///
/// Session
///
//Starts a new session or recovers current session
-$Session = Session::load();
+$context->session = Session::load();
//Handles login or logout
include("includes/login.php");
//Gets current user information
-$CurrentUser = $Session->get_logged_user();
+$context->user = $context->session->get_logged_user();
////////////////////////////////////////////////////////////////////////////////
///
/// Template/L10n engine
///
define('THEME', 'bluegray');
require('includes/smarty/Smarty.class.php');
+define('SMARTY_SPL_AUTOLOAD', 1);
+
$smarty = new Smarty();
$current_dir = dirname(__FILE__);
$smarty->template_dir = $current_dir . '/skins/' . THEME;
$smarty->compile_dir = $Config['Content']['Cache'] . '/compiled';
$smarty->cache_dir = $Config['Content']['Cache'];
$smarty->config_dir = $current_dir;
$smarty->config_vars['StaticContentURL'] = $Config['StaticContentURL'];
+$context->templateEngine = $smarty;
//Loads language files
initialize_lang();
lang_load('core.conf');
////////////////////////////////////////////////////////////////////////////////
///
/// Serves the requested page
///
-$url = get_current_url_fragments();
+$context->url = get_current_url_fragments();
//If the user isn't logged in (is anonymous), prints login/invite page & dies.
-if ($CurrentUser->id == ANONYMOUS_USER) {
+if ($context->user->id == ANONYMOUS_USER) {
//Anonymous user
include('controllers/anonymous.php');
exit;
}
//Workspace
-if (Workspace::is_workspace($url[0])) {
- $workspace = new Workspace(array_shift($url));
+if (Workspace::is_workspace($context->url[0])) {
+ $workspace = new Workspace(array_shift($context->url));
}
-switch ($controller = $url[0]) {
+switch ($controller = $context->url[0]) {
case '':
//Calls homepage controller
include("controllers/home.php");
break;
case 'help':
case 'reports':
//Calls requested controller
include("controllers/$controller.php");
break;
default:
//Not a workspace, nor a controller toponomy
define('ERROR_PAGE', 404);
include("controllers/errorpage.php");
break;
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Sep 15, 05:38 (14 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2983775
Default Alt Text
(34 KB)

Event Timeline