Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11725907
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
14 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/apps/staticcontent/StaticContentApplication.php b/apps/staticcontent/StaticContentApplication.php
index 0983e7f..d82086a 100644
--- a/apps/staticcontent/StaticContentApplication.php
+++ b/apps/staticcontent/StaticContentApplication.php
@@ -1,87 +1,87 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Static content application class
*
* @package ObsidianWorkspaces
* @subpackage StaticContent
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @filesource
*/
/**
* Static content application class
*
* Serves the static files of a directory
*/
class StaticContentApplication extends Application {
/**
* @var string the application name
*/
public static $name = "StaticContent";
private function getFilePath ($file) {
global $Config;
if ($file === "" || $file === NULL) {
$file = "index.html";
}
return $Config['Content']['Workspaces']
. DIRECTORY_SEPARATOR
. $this->context->workspace->code
. DIRECTORY_SEPARATOR
. $this->context->configuration->path
. DIRECTORY_SEPARATOR
. $file;
}
public function serveFile ($file) {
$path = $this->getFilePath($file);
$smarty = $this->context->templateEngine;
if (file_exists($path)) {
switch ($ext = strtolower(get_extension($path))) {
case "html":
case "htm":
$smarty->assign('PAGE_TITLE', $title);
HeaderController::run($this->context);
include($path);
FooterController::run($this->context);
break;
case "jpg": case "png": case "gif": case "svg": case "ico":
case "css": case "js":
case "txt": case "pdf": case "docx":
$type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
$fp = fopen($path, 'rb');
header('Content-Type: ' . $type);
header('Content-Length: ' . filesize($path));
ob_clean();
flush();
fpassthru($fp);
exit;
default:
echo "Can't serve $ext file";
}
} else {
- define('ERROR_PAGE', 404);
- include("controllers/errorpage.php");
+ ErrorPageController::show($context, 404);
+ exit;
}
}
/**
* Handles controller request
*/
public function handleRequest () {
//Serves file from a static directory
$this->serveFile($this->context->url[1]);
}
}
diff --git a/controllers/errorpage.php b/controllers/errorpage.php
index 49626ef..8631d6e 100755
--- a/controllers/errorpage.php
+++ b/controllers/errorpage.php
@@ -1,36 +1,68 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Controller for error pages
*
* @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
*
*/
-//
-// Common variables
-//
-$smarty->assign("URL_HOME", get_url());
+/**
+ * Error pages controller
+ */
+class ErrorPageController extends Controller {
+ /**
+ * @var int The HTTP error code
+ */
+ protected $errorCode;
+
+ /**
+ * Shows an error page
+ *
+ * @param Context $context The application or site context
+ * @param $errorCode The HTTP error code
+ */
+ public static function show($context, $errorCode) {
+ static::load($context)
+ ->setErrorCode($errorCode)
+ ->handleRequest();
+ }
+
+ /**
+ * Sets HTTP error code
+ *
+ * @param $errorCode The HTTP error code
+ * @return ErrorPageController the current instance
+ */
+ public function setErrorCode ($errorCode) {
+ $this->errorCode = $errorCode;
+ return $this;
+ }
-//
-// HTML output
-//
+ /**
+ * Handles controller request
+ */
+ public function handleRequest () {
+ $smarty = $this->context->templateEngine;
+ $smarty->assign("URL_HOME", get_url());
-switch (ERROR_PAGE) {
- case 404:
- header("HTTP/1.0 404 Not Found");
- $smarty->display("errors/404.tpl");
- break;
+ switch ($this->errorCode) {
+ case 404:
+ header("HTTP/1.0 404 Not Found");
+ $smarty->display("errors/404.tpl");
+ break;
- default:
- die("Unknown error page: " . ERROR_PAGE);
+ default:
+ die("Unknown error page: " . $this->errorCode);
+ }
+ }
}
diff --git a/controllers/help.php b/controllers/help.php
index 7fa917b..149229b 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'] . '/' . ($context->url[1] ? $context->url[1] : 'index') . '.html';
-if (file_exists($file)) {
- //Header
- $smarty->assign('controller_custom_nav', 'nav_help.tpl');
- HeaderController::run($context);
+if (!file_exists($file)) {
+ ErrorPageController::show($context, 404);
+ exit;
+}
- //Help page
- $smarty->assign('help_file', $file);
- $smarty->display('help.tpl');
+//Header
+$smarty->assign('controller_custom_nav', 'nav_help.tpl');
+HeaderController::run($context);
- //Footer
- FooterController::run($context);
-} else {
- define('ERROR_PAGE', 404);
- include("controllers/errorpage.php");
-}
+//Help page
+$smarty->assign('help_file', $file);
+$smarty->display('help.tpl');
+
+//Footer
+FooterController::run($context);
diff --git a/includes/autoload.php b/includes/autoload.php
index c625e85..84aa174 100644
--- a/includes/autoload.php
+++ b/includes/autoload.php
@@ -1,88 +1,89 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Classes and interfaces auto loader
*
* @package ObsidianWorkspaces
* @filesource
*/
/**
* This SPL autoloader method is called when a class or an interface can't be loaded.
*/
function obsidian_autoload ($name) {
$dir = dirname(__DIR__);
///
/// Applications
///
if ($name == 'DocumentsApplication') { require $dir . '/apps/documents/DocumentsApplication.php'; return true; }
if ($name == 'DocumentsApplicationConfiguration') { require $dir . '/apps/documents/DocumentsApplicationConfiguration.php'; return true; }
if ($name == 'HelloWorldApplication') { require $dir . '/apps/helloworld/HelloWorldApplication.php'; return true; }
if ($name == 'MediaWikiMirrorApplication') { require $dir . '/apps/mediawikimirror/MediaWikiMirrorApplication.php'; return true; }
if ($name == 'MediaWikiMirrorApplicationConfiguration') { require $dir . '/apps/mediawikimirror/MediaWikiMirrorApplicationConfiguration.php'; return true; }
if ($name == 'StaticContentApplication') { require $dir . '/apps/staticcontent/StaticContentApplication.php'; return true; }
if ($name == 'StaticContentApplicationConfiguration') { require $dir . '/apps/staticcontent/StaticContentApplicationConfiguration.php'; return true; }
///
/// Core controllers
///
+ if ($name == 'ErrorPageController') { require $dir . '/controllers/errorpage.php'; return true; }
if ($name == 'FooterController') { require $dir . '/controllers/footer.php'; return true; }
if ($name == 'HeaderController') { require $dir . '/controllers/header.php'; return true; }
if ($name == 'HomepageController') { require $dir . '/controllers/home.php'; return true; }
///
/// Keruald and Obsidian Workspaces libraries
///
if ($name == 'ObjectDeserializable') { require $dir . '/includes/ObjectDeserializable.php'; return true; }
if ($name == 'ObjectDeserializableWithContext') { require $dir . '/includes/ObjectDeserializable.php'; return true; }
if ($name == 'Application') { require $dir . '/includes/apps/Application.php'; return true; }
if ($name == 'ApplicationConfiguration') { require $dir . '/includes/apps/ApplicationConfiguration.php'; return true; }
if ($name == 'ApplicationContext') { require $dir . '/includes/apps/ApplicationContext.php'; return true; }
if ($name == 'AddToGroupUserAction') { require $dir . '/includes/auth/AddToGroupUserAction.php'; return true; }
if ($name == 'AuthenticationMethod') { require $dir . '/includes/auth/AuthenticationMethod.php'; return true; }
if ($name == 'AzharProvider') { require $dir . '/includes/auth/AzharProvider.php'; return true; }
if ($name == 'GivePermissionUserAction') { require $dir . '/includes/auth/GivePermissionUserAction.php'; return true; }
if ($name == 'UserAction') { require $dir . '/includes/auth/UserAction.php'; return true; }
if ($name == 'Cache') { require $dir . '/includes/cache/cache.php'; return true; }
if ($name == 'CacheMemcached') { require $dir . '/includes/cache/memcached.php'; return true; }
if ($name == 'CacheVoid') { require $dir . '/includes/cache/void.php'; return true; }
if ($name == 'Collection') { require $dir . '/includes/collection/Collection.php'; return true; }
if ($name == 'CollectionDocument') { require $dir . '/includes/collection/CollectionDocument.php'; return true; }
if ($name == 'FilesCollection') { require $dir . '/includes/collection/FilesCollection.php'; return true; }
if ($name == 'MongoDBCollection') { require $dir . '/includes/collection/MongoDBCollection.php'; return true; }
if ($name == 'Context') { require $dir . '/includes/controller/Context.php'; return true; }
if ($name == 'Controller') { require $dir . '/includes/controller/Controller.php'; return true; }
if ($name == 'RunnableWithContext') { require $dir . '/includes/controller/RunnableWithContext.php'; return true; }
if ($name == 'Message') { require $dir . '/includes/i18n/Message.php'; return true; }
if ($name == 'TextFileMessage') { require $dir . '/includes/i18n/TextFileMessage.php'; return true; }
if ($name == 'Disclaimer') { require $dir . '/includes/objects/Disclaimer.php'; return true; }
if ($name == 'Permission') { require $dir . '/includes/objects/Permission.php'; return true; }
if ($name == 'User') { require $dir . '/includes/objects/user.php'; return true; }
if ($name == 'UserGroup') { require $dir . '/includes/objects/usergroup.php'; return true; }
if ($name == 'Workspace') { require $dir . '/includes/workspaces/Workspace.php'; return true; }
if ($name == 'WorkspaceConfiguration') { require $dir . '/includes/workspaces/WorkspaceConfiguration.php'; return true; }
return false;
}
spl_autoload_register('obsidian_autoload');
diff --git a/index.php b/index.php
index b4cc922..a66ece0 100755
--- a/index.php
+++ b/index.php
@@ -1,115 +1,114 @@
<?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');
$session = Session::load();
////////////////////////////////////////////////////////////////////////////////
///
/// 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'];
//Loads language files
initialize_lang();
lang_load('core.conf');
////////////////////////////////////////////////////////////////////////////////
///
/// Session and context
///
//Prepares the site context
$context = new ApplicationContext();
$context->session = $session;;
$context->url = get_current_url_fragments();
$context->templateEngine = $smarty;
if (Workspace::is_workspace($context->url[0])) {
$context->workspace = Workspace::fromCode(array_shift($context->url));
$context->workspace->loadConfiguration($context);
}
//Handles login or logout
include("includes/login.php");
//Gets current user information
$context->user = $context->session->get_logged_user();
////////////////////////////////////////////////////////////////////////////////
///
/// Serves the requested page
///
//If the user isn't logged in (is anonymous), prints login/invite page & dies.
if ($context->user->id == ANONYMOUS_USER) {
//Anonymous user
include('controllers/anonymous.php');
exit;
}
switch ($controller = $context->url[0]) {
case '':
//Calls homepage controller
HomepageController::run($context);
break;
case 'help':
case 'reports':
//Calls requested controller
include("controllers/$controller.php");
break;
default:
//Current workspace application controller?
$workspaceConfig = $context->workspace->configuration;
$applicationConfiguration = NULL;
if ($workspaceConfig != NULL && $workspaceConfig->hasControllerBind($controller, $applicationConfiguration)) {
//Runs controller
$controllerClass = $applicationConfiguration->name;
$appContext = ApplicationContext::loadFromContext($context, $applicationConfiguration);
$controllerClass::run($appContext);
break;
}
//Not a workspace, nor a controller toponomy
- define('ERROR_PAGE', 404);
- include("controllers/errorpage.php");
- break;
+ ErrorPageController::show($context, 404);
+ exit;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 18, 22:31 (7 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2991871
Default Alt Text
(14 KB)
Attached To
Mode
rOBSIDIAN Obsidian Workspaces
Attached
Detach File
Event Timeline
Log In to Comment