Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to embed resources internally, without loading from urls. #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions classes/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Resources {

// outputs the specified resource, if defined in this class.
// the main script should do no further output after calling this function.
public static function output($resource)
public static function output($resource, $echo=true)
{
if (isset(self::$_resources[$resource])) {
$res =& self::$_resources[$resource];
Expand All @@ -40,30 +40,38 @@ public static function output($resource)

// use last-modified time as etag; etag must be quoted
$etag = '"' . filemtime($filename) . '"';
if ($echo)
{
// check headers for matching etag; if etag hasn't changed, use the cached version
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
header('HTTP/1.0 304 Not Modified');
return;
}

// check headers for matching etag; if etag hasn't changed, use the cached version
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
header('HTTP/1.0 304 Not Modified');
return;
}

header('Etag: ' . $etag);

// cache file for at most 30 days
header('Cache-control: max-age=2592000');
header('Etag: ' . $etag);

// output resource
header('Content-type: ' . $res['mime']);
// cache file for at most 30 days
header('Cache-control: max-age=2592000');

// output resource
header('Content-type: ' . $res['mime']);
}

$result = '';
if (isset($data)) {
if (isset($res['base64'])) {
echo base64_decode($data);
$result = base64_decode($data);
} else {
echo $data;
$result = $data;
}
} else {
readfile($filename);
$result = file_get_contents($filename);
}

if ($echo)
echo $result;
else
return $result;
}
}

Expand Down
15 changes: 11 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function pla_autoload($classname)
// up here, we don't output anything. debug output might appear here which is catched by ob and thrown later
ob_start();

// if inline_resources set
$inline_resources = isset($inline_resources) ? $inline_resources : false;

// Resource output (css and javascript files)
// we get out of the main code as soon as possible, without inizializing the session
if (isset($_GET['resource']))
Expand Down Expand Up @@ -1455,7 +1458,7 @@ function parseSize($size)
<head>
<!-- Copyright <?php echo date("Y").' '.PROJECT.' ('.PROJECT_URL.')'; ?> -->
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<link rel="shortcut icon" href="?resource=favicon" />
<link rel="shortcut icon" href="<?php echo $inline_resources ? 'data:image/png;base64,'.base64_encode(Resources::output('favicon', false)) : '?resource=favicon';?>" />
<title><?php echo PROJECT ?></title>

<?php
Expand All @@ -1467,10 +1470,10 @@ function parseSize($size)

if (file_exists($theme))
// an external stylesheet exists - import it
echo "<link href='{$theme}' rel='stylesheet' type='text/css' />", PHP_EOL;
echo ($inline_resources ? '<style>'.Resources::output('css', false).'</style>' : "<link href='{$theme}' rel='stylesheet' type='text/css' />". PHP_EOL);
else
// only use the default stylesheet if an external one does not exist
echo "<link href='?resource=css' rel='stylesheet' type='text/css' />", PHP_EOL;
echo ($inline_resources ? '<style>'.Resources::output('css', false).'</style>' : "<link href='?resource=css' rel='stylesheet' type='text/css' />". PHP_EOL);

// HTML: output help text, then exit
if(isset($_GET['help']))
Expand Down Expand Up @@ -1514,8 +1517,12 @@ function parseSize($size)
{
//- Javascript include
?>
<!-- JavaScript Support -->
<!-- JavaScript Support -->
<?php if ($inline_resources) { ?>
<script type='text/javascript'><?php echo Resources::output('javascript', false);?></script>
<?php } else { ?>
<script type='text/javascript' src='?resource=javascript'></script>
<?php } ?>
<script type="text/javascript">
var fileUploadMaxSize = <?php echo fileUploadMaxSize(); ?>;
var fileUploadMaxSizeErrorMsg = '<?php echo $lang['err'].': \n'.$lang['max_file_size']; ?>';
Expand Down
3 changes: 3 additions & 0 deletions phpliteadmin.config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
//whether or not to scan the subdirectories of the above directory infinitely deep
$subdirectories = false;

//whether or not embedd css/js content directly into HTML head
$inline_resources = false;

//if the above $directory variable is set to false, you must specify the databases manually in an array as the next variable
//if any of the databases do not exist as they are referenced by their path, they will be created automatically
$databases = array(
Expand Down