Page MenuHomeDevCentral

No OneTemporary

diff --git a/apps/staticcontent/StaticContentApplication.php b/apps/staticcontent/StaticContentApplication.php
new file mode 100644
index 0000000..f7d8a01
--- /dev/null
+++ b/apps/staticcontent/StaticContentApplication.php
@@ -0,0 +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");
+ }
+ }
+
+ /**
+ * Handles controller request
+ */
+ public function handleRequest () {
+ //Serves file from a static directory
+ $this->serveFile($this->context->url[1]);
+ }
+}
diff --git a/apps/staticcontent/StaticContentApplicationConfiguration.php b/apps/staticcontent/StaticContentApplicationConfiguration.php
new file mode 100644
index 0000000..6f2cd2b
--- /dev/null
+++ b/apps/staticcontent/StaticContentApplicationConfiguration.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * _, __, _, _ __, _ _, _, _
+ * / \ |_) (_ | | \ | /_\ |\ |
+ * \ / |_) , ) | |_/ | | | | \|
+ * ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
+ *
+ * Static content application configuration 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 configuration class
+ */
+class StaticContentApplicationConfiguration extends ApplicationConfiguration {
+ /**
+ * @var string The path to the files to serve
+ */
+ public $path;
+}
diff --git a/includes/autoload.php b/includes/autoload.php
index 7bcaa22..0c5abea 100644
--- a/includes/autoload.php
+++ b/includes/autoload.php
@@ -1,50 +1,52 @@
<?php
/**
* _, __, _, _ __, _ _, _, _
* / \ |_) (_ | | \ | /_\ |\ |
* \ / |_) , ) | |_/ | | | | \|
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
* Classes auto loader
*
* @package ObsidianWorkspaces
* @filesource
*/
/**
* This magic method is called when a class can't be loaded
*/
function obsidian_autoload ($className) {
//Applications
if ($className == 'HelloWorldApplication') { require './apps/helloworld/HelloWorldApplication.php'; return true; }
+ if ($className == 'StaticContentApplication') { require './apps/staticcontent/StaticContentApplication.php'; return true; }
+ if ($className == 'StaticContentApplicationConfiguration') { require './apps/staticcontent/StaticContentApplicationConfiguration.php'; return true; }
//Core controllers
if ($className == 'HeaderController') { require './controllers/header.php'; return true; }
if ($className == 'FooterController') { require './controllers/footer.php'; return true; }
if ($className == 'HomepageController') { require './controllers/home.php'; return true; }
//Keruald and Obsidian Workspaces Libraries
if ($className == 'Application') { require './includes/apps/Application.php'; return true; }
if ($className == 'ApplicationConfiguration') { require './includes/apps/ApplicationConfiguration.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 == 'Message') { require './includes/i18n/Message.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/workspaces/Workspace.php'; return true; }
if ($className == 'WorkspaceConfiguration') { require './includes/workspaces/WorkspaceConfiguration.php'; return true; }
return false;
}
spl_autoload_register('obsidian_autoload');

File Metadata

Mime Type
text/x-diff
Expires
Sat, Mar 21, 06:08 (15 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3546522
Default Alt Text
(6 KB)

Event Timeline