Merge pull request #121 from Gautham/Dev

Remove date() Warnings during Static Generation
This commit is contained in:
Denis Kisselev 2014-02-19 10:50:01 -08:00
commit 9e7b58a814
3 changed files with 223 additions and 215 deletions

View File

@ -22,7 +22,8 @@ $(function () {
}); });
//Fix GitHub Ribbon overlapping Scrollbar //Fix GitHub Ribbon overlapping Scrollbar
if ($('article')[0].scrollHeight > $('.right-column').height()) $('#github-ribbon')[0].style.right = '16px' var t = $('#github-ribbon');
if (t[0] && $('article')[0].scrollHeight > $('.right-column').height()) t[0].style.right = '16px';
//Toggle Code Block Visibility //Toggle Code Block Visibility
function toggleCodeBlocks() { function toggleCodeBlocks() {

View File

@ -26,9 +26,16 @@ $base_url = '/';
// Set the base url of where the script is located // Set the base url of where the script is located
if (isset($_SERVER['SCRIPT_NAME'])) if (isset($_SERVER['SCRIPT_NAME']))
{ {
$base_url = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'] , '/')); // find the full URL to this application from server root $base_url = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'] , '/')); // find the full URL to this application from server root
} }
// Hide annoying date() Warnings due to no Timezone being set.
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('GMT');
}
function get_base_url() function get_base_url()
{ {
global $base_url; global $base_url;
@ -46,18 +53,18 @@ function get_options() {
'date_modified' => true, 'date_modified' => true,
'float' => true, 'float' => true,
'repo' => false, 'repo' => false,
'toggle_code' => false, 'toggle_code' => false,
'twitter' => array(), 'twitter' => array(),
'links' => array(), 'links' => array(),
'colors' => false, 'colors' => false,
'clean_urls' => true, 'clean_urls' => true,
'google_analytics' => false, 'google_analytics' => false,
'piwik_analytics' => false, 'piwik_analytics' => false,
'piwik_analytics_id' => 1, 'piwik_analytics_id' => 1,
'ignore' => array(), 'ignore' => array(),
'languages' => array(), 'languages' => array(),
'file_editor' => false, 'file_editor' => false,
'template' => 'default' 'template' => 'default'
); );
// Load User Config // Load User Config
@ -115,11 +122,11 @@ function docs_url($tree, $branch = false) {
} }
function load_page($tree, $url_params) { function load_page($tree, $url_params) {
if (count($url_params) > 0) { if (count($url_params) > 0) {
$branch = find_branch($tree, $url_params); $branch = find_branch($tree, $url_params);
} else { } else {
$branch = current($tree); $branch = current($tree);
} }
$page = array(); $page = array();
@ -273,15 +280,15 @@ function get_ignored() {
} }
function get_tree($path = '.', $clean_path = '', $title = '', $first = true, $language = null, &$flat_tree = null){ function get_tree($path = '.', $clean_path = '', $title = '', $first = true, $language = null, &$flat_tree = null){
$options = get_options(); $options = get_options();
$tree = array(); $tree = array();
$ignore = get_ignored(); $ignore = get_ignored();
$dh = @opendir($path); $dh = @opendir($path);
$index = 0; $index = 0;
// Build array of paths // Build array of paths
$paths = array(); $paths = array();
while(false !== ($file = readdir($dh))){ while(false !== ($file = readdir($dh))){
$paths[$file] = $file; $paths[$file] = $file;
} }
@ -291,79 +298,79 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true, $la
// Sort paths // Sort paths
sort($paths); sort($paths);
if ($first && $language !== null) { if ($first && $language !== null) {
$language_path = $language . "/"; $language_path = $language . "/";
} else { } else {
$language_path = ""; $language_path = "";
} }
// Loop through the paths // Loop through the paths
// while(false !== ($file = readdir($dh))){ // while(false !== ($file = readdir($dh))){
foreach($paths as $file) { foreach($paths as $file) {
// Check that this file or folder is not to be ignored // Check that this file or folder is not to be ignored
if(!in_array($file, $ignore) && $file[0] !== '.') { if(!in_array($file, $ignore) && $file[0] !== '.') {
$full_path = "$path/$file"; $full_path = "$path/$file";
$clean_sort = clean_sort($file); $clean_sort = clean_sort($file);
// If clean_urls is set to false and this is the first branch of the tree, append index.php to the clean_path. // If clean_urls is set to false and this is the first branch of the tree, append index.php to the clean_path.
if($options['clean_urls'] == false) if($options['clean_urls'] == false)
{ {
if($first) if($first)
{ {
$url = $clean_path . '/' . $language_path . 'index.php/' . $clean_sort; $url = $clean_path . '/' . $language_path . 'index.php/' . $clean_sort;
} }
else else
{ {
$url = $clean_path . '/' . $language_path . $clean_sort; $url = $clean_path . '/' . $language_path . $clean_sort;
} }
} }
else else
{ {
$url = $clean_path . '/' . $language_path . $clean_sort; $url = $clean_path . '/' . $language_path . $clean_sort;
} }
$clean_name = clean_name($clean_sort); $clean_name = clean_name($clean_sort);
// Title // Title
if (empty($title)) { if (empty($title)) {
$full_title = $clean_name; $full_title = $clean_name;
} else { } else {
$full_title = $title . ': ' . $clean_name; $full_title = $title . ': ' . $clean_name;
} }
if(is_dir("$path/$file")) { if(is_dir("$path/$file")) {
// Directory // Directory
$tree[$clean_sort] = array( $tree[$clean_sort] = array(
'type' => 'folder', 'type' => 'folder',
'name' => $clean_name, 'name' => $clean_name,
'title' => $full_title, 'title' => $full_title,
'path' => $full_path, 'path' => $full_path,
'clean' => $clean_sort, 'clean' => $clean_sort,
'url' => $url, 'url' => $url,
'tree'=> (isset($flat_tree) && $flat_tree!==NULL)? 'tree'=> (isset($flat_tree) && $flat_tree!==NULL)?
get_tree($full_path, $url, $full_title, false, $language, $flat_tree): get_tree($full_path, $url, $full_title, false, $language, $flat_tree):
get_tree($full_path, $url, $full_title, false, $language) get_tree($full_path, $url, $full_title, false, $language)
); );
} else { } else {
// File // File
$tree[$clean_sort] = array( $tree[$clean_sort] = array(
'type' => 'file', 'type' => 'file',
'name' => $clean_name, 'name' => $clean_name,
'title' => $full_title, 'title' => $full_title,
'path' => $full_path, 'path' => $full_path,
'clean' => $clean_sort, 'clean' => $clean_sort,
'url' => $url, 'url' => $url,
); );
if(isset($flat_tree) && $flat_tree!==NULL) if(isset($flat_tree) && $flat_tree!==NULL)
array_push($flat_tree, $tree[$clean_sort]); array_push($flat_tree, $tree[$clean_sort]);
} }
} }
$index++; $index++;
} }
return $tree; return $tree;
} }
/** /**
@ -387,58 +394,58 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true, $la
*/ */
function get_uri($prefix_slash = true) function get_uri($prefix_slash = true)
{ {
if (isset($_SERVER['PATH_INFO'])) if (isset($_SERVER['PATH_INFO']))
{ {
$uri = $_SERVER['PATH_INFO']; $uri = $_SERVER['PATH_INFO'];
} }
elseif (isset($_SERVER['REQUEST_URI'])) elseif (isset($_SERVER['REQUEST_URI']))
{ {
$uri = $_SERVER['REQUEST_URI']; $uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
{ {
$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
} }
elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
{ {
$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
} }
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
// URI is found, and also fixes the QUERY_STRING server var and $_GET array. // URI is found, and also fixes the QUERY_STRING server var and $_GET array.
if (strncmp($uri, '?/', 2) === 0) if (strncmp($uri, '?/', 2) === 0)
{ {
$uri = substr($uri, 2); $uri = substr($uri, 2);
} }
$parts = preg_split('#\?#i', $uri, 2); $parts = preg_split('#\?#i', $uri, 2);
$uri = $parts[0]; $uri = $parts[0];
if (isset($parts[1])) if (isset($parts[1]))
{ {
$_SERVER['QUERY_STRING'] = $parts[1]; $_SERVER['QUERY_STRING'] = $parts[1];
parse_str($_SERVER['QUERY_STRING'], $_GET); parse_str($_SERVER['QUERY_STRING'], $_GET);
} }
else else
{ {
$_SERVER['QUERY_STRING'] = ''; $_SERVER['QUERY_STRING'] = '';
$_GET = array(); $_GET = array();
} }
$uri = parse_url($uri, PHP_URL_PATH); $uri = parse_url($uri, PHP_URL_PATH);
} }
else else
{ {
// Couldn't determine the URI, so just return false // Couldn't determine the URI, so just return false
return false; return false;
} }
// Do some final cleaning of the URI and return it // Do some final cleaning of the URI and return it
return ($prefix_slash ? '/' : '').str_replace(array('//', '../'), '/', trim($uri, '/')); return ($prefix_slash ? '/' : '').str_replace(array('//', '../'), '/', trim($uri, '/'));
} }
function handle_editor_post($post, $page) { function handle_editor_post($post, $page) {
if(file_exists($page["path"])) { if(file_exists($page["path"])) {
file_put_contents($page["path"], $post["markdown"]); file_put_contents($page["path"], $post["markdown"]);
} else { } else {
throw new Exception("File doesn't exist", 1); throw new Exception("File doesn't exist", 1);
} }
} }
/** /**
@ -448,53 +455,53 @@ function handle_editor_post($post, $page) {
function generate_page($options, $url_params, $base_url, $return=FALSE, &$flat_tree=NULL){ function generate_page($options, $url_params, $base_url, $return=FALSE, &$flat_tree=NULL){
//documentation folder defined in various folder languages //documentation folder defined in various folder languages
if (count($options['languages']) > 0 && count($url_params) > 0 && strlen($url_params[0]) > 0) { if (count($options['languages']) > 0 && count($url_params) > 0 && strlen($url_params[0]) > 0) {
$language = array_shift($url_params); $language = array_shift($url_params);
$base_path = $options['docs_path']. DIRECTORY_SEPARATOR . $language; $base_path = $options['docs_path']. DIRECTORY_SEPARATOR . $language;
} else { } else {
$language = null; $language = null;
$base_path = $options['docs_path']; $base_path = $options['docs_path'];
} }
// If a timezone has been set in the config file, override the default PHP timezone for this application. // If a timezone has been set in the config file, override the default PHP timezone for this application.
if(isset($options['timezone'])) if(isset($options['timezone']))
{ {
date_default_timezone_set($options['timezone']); date_default_timezone_set($options['timezone']);
} }
$tree = (isset($flat_tree))? $tree = (isset($flat_tree))?
get_tree($base_path, $base_url, '', true, $language,$flat_tree): get_tree($base_path, $base_url, '', true, $language,$flat_tree):
get_tree($base_path, $base_url, '', true, $language); get_tree($base_path, $base_url, '', true, $language);
// If a language is set in the config, rewrite urls based on the language // If a language is set in the config, rewrite urls based on the language
if (! isset($language) || $language === null) { if (! isset($language) || $language === null) {
$homepage_url = homepage_url($tree); $homepage_url = homepage_url($tree);
} else { } else {
$homepage_url = "/"; $homepage_url = "/";
} }
// Redirect to docs, if there is no homepage // Redirect to docs, if there is no homepage
if ($homepage_url !== '/') { if ($homepage_url !== '/') {
header('Location: '.$homepage_url); header('Location: '.$homepage_url);
} }
$docs_url = docs_url($tree); $docs_url = docs_url($tree);
$page = load_page($tree, $url_params); $page = load_page($tree, $url_params);
// Handle AJAX requests for file editing // Handle AJAX requests for file editing
if(isset($_POST["markdown"]) && $options["file_editor"] === true) { if(isset($_POST["markdown"]) && $options["file_editor"] === true) {
handle_editor_post($_POST, $page); handle_editor_post($_POST, $page);
die; die;
} }
if($url_params[0]=='') if($url_params[0]=='')
$homepage = TRUE; $homepage = TRUE;
else else
$homepage = FALSE; $homepage = FALSE;
ob_start(); ob_start();
include('template/'.$options['template'].'.tpl'); include('template/'.$options['template'].'.tpl');
if ($return === TRUE) if ($return === TRUE)
{ {
$buffer = ob_get_contents(); $buffer = ob_get_contents();
@ob_end_clean(); @ob_end_clean();
@ -507,8 +514,8 @@ function generate_page($options, $url_params, $base_url, $return=FALSE, &$flat_t
function load_tpl_block($file, $options, $base_url){ function load_tpl_block($file, $options, $base_url){
ob_start(); ob_start();
include('template/'.$file.'.tpl'); include('template/'.$file.'.tpl');
$buffer = ob_get_contents(); $buffer = ob_get_contents();
@ob_end_clean(); @ob_end_clean();
return $buffer; return $buffer;
} }
@ -522,9 +529,9 @@ function copy_recursive($source, $dest, $ignoreList = array()){
RecursiveIteratorIterator::SELF_FIRST) as $item RecursiveIteratorIterator::SELF_FIRST) as $item
) { ) {
if ($item->isDir()) { if ($item->isDir()) {
@mkdir($dest . DIRECTORY_SEPARATOR . $src_folder . DIRECTORY_SEPARATOR .$iterator->getSubPathName()); @mkdir($dest . DIRECTORY_SEPARATOR . $src_folder . DIRECTORY_SEPARATOR .$iterator->getSubPathName());
} else { } else {
if (!$ignoreList || !in_array($item, $ignoreList)) @copy($item, $dest . DIRECTORY_SEPARATOR .$src_folder. DIRECTORY_SEPARATOR .$iterator->getSubPathName()); if (!$ignoreList || !in_array($item, $ignoreList)) @copy($item, $dest . DIRECTORY_SEPARATOR .$src_folder. DIRECTORY_SEPARATOR .$iterator->getSubPathName());
} }
} }
} }
@ -535,7 +542,7 @@ function clean_directory($directory){
new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS), new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST) as $item RecursiveIteratorIterator::SELF_FIRST) as $item
) { ) {
@unlink($directory.DIRECTORY_SEPARATOR.$iterator->getSubPathName()); @unlink($directory.DIRECTORY_SEPARATOR.$iterator->getSubPathName());
} }
} }
@ -551,23 +558,23 @@ function relative_base($count){
function clean_copy_assets($path){ function clean_copy_assets($path){
@mkdir($path); @mkdir($path);
$options = $GLOBALS["options"]; $options = $GLOBALS["options"];
//Clean //Clean
clean_directory($path); clean_directory($path);
//Copy assets //Copy assets
$unnecessaryImgs = array('./img/favicon.png', './img/favicon-blue.png', './img/favicon-green.png', './img/favicon-navy.png', './img/favicon-red.png'); $unnecessaryImgs = array('./img/favicon.png', './img/favicon-blue.png', './img/favicon-green.png', './img/favicon-navy.png', './img/favicon-red.png');
$unnecessaryJs = array(); $unnecessaryJs = array();
if ($options['colors']) { if ($options['colors']) {
@mkdir($path.'/less'); @mkdir($path.'/less');
@mkdir($path.'/less/import'); @mkdir($path.'/less/import');
@copy('./less/import/daux-base.less', $path.'/less/import/daux-base.less'); @copy('./less/import/daux-base.less', $path.'/less/import/daux-base.less');
$unnecessaryImgs = array_diff($unnecessaryImgs, array('./img/favicon.png')); $unnecessaryImgs = array_diff($unnecessaryImgs, array('./img/favicon.png'));
} else { } else {
$unnecessaryJs = array('./js/less.min.js'); $unnecessaryJs = array('./js/less.min.js');
@mkdir($path.'/css'); @mkdir($path.'/css');
@copy('./css/daux-'.$options['theme'].'.css', $path.'/css/daux-'.$options['theme'].'.css'); @copy('./css/daux-'.$options['theme'].'.min.css', $path.'/css/daux-'.$options['theme'].'.min.css');
$unnecessaryImgs = array_diff($unnecessaryImgs, array('./img/favicon-'.$options['theme'].'.png')); $unnecessaryImgs = array_diff($unnecessaryImgs, array('./img/favicon-'.$options['theme'].'.png'));
} }
copy_recursive('./img', $path.'/', $unnecessaryImgs); copy_recursive('./img', $path.'/', $unnecessaryImgs);
copy_recursive('./js', $path.'/', $unnecessaryJs); copy_recursive('./js', $path.'/', $unnecessaryJs);
} }

View File

@ -3,43 +3,43 @@
<head> <head>
<title><?php echo $options['title']; ?></title> <title><?php echo $options['title']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="<?php echo $options['tagline'];?>" /> <meta name="description" content="<?php echo $options['tagline'];?>" />
<meta name="author" content="<?php echo $options['title']; ?>"> <meta name="author" content="<?php echo $options['title']; ?>">
<?php if ($options['colors']) { ?> <?php if ($options['colors']) { ?>
<link rel="icon" href="<?php echo $base_url ?>/img/favicon.png" type="image/x-icon"> <link rel="icon" href="<?php echo $base_url ?>/img/favicon.png" type="image/x-icon">
<?php } else { ?> <?php } else { ?>
<link rel="icon" href="<?php echo $base_url ?>/img/favicon-<?php echo $options['theme'];?>.png" type="image/x-icon"> <link rel="icon" href="<?php echo $base_url ?>/img/favicon-<?php echo $options['theme'];?>.png" type="image/x-icon">
<?php } ?> <?php } ?>
<!-- LESS --> <!-- LESS -->
<?php if ($options['colors']) { ?> <?php if ($options['colors']) { ?>
<style type="text/less"> <style type="text/less">
<?php foreach($options['colors'] as $k => $v) { ?> <?php foreach($options['colors'] as $k => $v) { ?>
@<?php echo $k;?>: <?php echo $v;?>; @<?php echo $k;?>: <?php echo $v;?>;
<?php } ?> <?php } ?>
@import "<?php echo $base_url ?>/less/import/daux-base.less"; @import "<?php echo $base_url ?>/less/import/daux-base.less";
</style> </style>
<script src="<?php echo $base_url ?>/js/less.min.js"></script> <script src="<?php echo $base_url ?>/js/less.min.js"></script>
<?php } else { ?> <?php } else { ?>
<link rel="stylesheet" href="<?php echo $base_url ?>/css/daux-<?php echo $options['theme'];?>.css"> <link rel="stylesheet" href="<?php echo $base_url ?>/css/daux-<?php echo $options['theme'];?>.min.css">
<?php } ?> <?php } ?>
<link rel="stylesheet" href="<?php echo $base_url ?>/css/full-doc.css"> <link rel="stylesheet" href="<?php echo $base_url ?>/css/full-doc.css">
<!-- hightlight.js --> <!-- hightlight.js -->
<script src="<?php echo $base_url ?>/js/highlight.min.js"></script> <script src="<?php echo $base_url ?>/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script> <script>hljs.initHighlightingOnLoad();</script>
<!-- Navigation --> <!-- Navigation -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script> <script>
if (typeof jQuery == 'undefined') { if (typeof jQuery == 'undefined') {
document.write(unescape("%3Cscript src='<?php echo $base_url ?>/js/jquery-1.11.0.min.js' type='text/javascript'%3E%3C/script%3E")); document.write(unescape("%3Cscript src='<?php echo $base_url ?>/js/jquery-1.11.0.min.js' type='text/javascript'%3E%3C/script%3E"));
} }
</script> </script>
<script src="<?php echo $base_url ?>/js/bootstrap.min.js"></script> <script src="<?php echo $base_url ?>/js/bootstrap.min.js"></script>
<script src="<?php echo $base_url ?>/js/custom.js"></script> <script src="<?php echo $base_url ?>/js/custom.js"></script>
<!--[if lt IE 9]> <!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]--> <![endif]-->
</head> </head>
<body> <body>