Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F13143948
StaticContentApplication.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
StaticContentApplication.php
View Options
<?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
]);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 21, 16:54 (23 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3159327
Default Alt Text
StaticContentApplication.php (2 KB)
Attached To
Mode
rOBSIDIAN Obsidian Workspaces
Attached
Detach File
Event Timeline
Log In to Comment