Reworking the config
This commit is contained in:
225
libs/functions.php
Normal file
225
libs/functions.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?
|
||||
|
||||
/*
|
||||
* WARNING: DO NOT EDIT THIS FILE.
|
||||
* If you edit this file, you will not be able to update to new versions of
|
||||
* Daux.io without overwritting your changes. Instead use the config.json file
|
||||
* in the /docs folder to customize your documentation.
|
||||
*
|
||||
* Learn more about what you can customize here: http://daux.io
|
||||
*/
|
||||
|
||||
require_once('libs/markdown_extended.php');
|
||||
|
||||
// Check for homepage
|
||||
$path = url_path();
|
||||
if ($path === '/' || $path === '') {
|
||||
$homepage = true;
|
||||
} else {
|
||||
$homepage = false;
|
||||
}
|
||||
|
||||
// TM-Docs Functions
|
||||
function get_options() {
|
||||
$options = array(
|
||||
'title' => "Documentation",
|
||||
'tagline' => false,
|
||||
'image' => false,
|
||||
'homepage' => false,
|
||||
'theme' => 'blue',
|
||||
'float' => true,
|
||||
'repo' => false,
|
||||
'twitter' => array(),
|
||||
'links' => array(),
|
||||
'colors' => false
|
||||
);
|
||||
|
||||
// Load User Config
|
||||
$config_file = './docs/config.json';
|
||||
if (file_exists($config_file)) {
|
||||
$config = json_decode(file_get_contents($config_file), true);
|
||||
$options = array_merge($options, $config);
|
||||
}
|
||||
|
||||
if ($options['theme'] !== 'custom') {
|
||||
// Load Theme
|
||||
if (!in_array($options['theme'], array("blue","navy","green","red"))) {
|
||||
echo "<strong>Daux.io Config Error:</strong><br>The theme you set is not not a valid option. Please use one of the following options: " . join(array_keys($themes), ', ') . ' or <a href="http://daux.io">learn more</a> about how to customize the colors.';
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
if (empty($options['colors'])) {
|
||||
echo '<strong>Daux.io Config Error:</strong><br>You are trying to use a custom theme, but did not setup your color options in the config. <a href="http://daux.io">Learn more</a> about how to customize the colors.';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Homepage Redirect?
|
||||
$path = url_path();
|
||||
if ($path === '/') {
|
||||
// Custom Homepage?
|
||||
if ($options['homepage']) {
|
||||
header('Location: '.$options['homepage']);
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function load_page($tree) {
|
||||
$branch = find_branch($tree);
|
||||
|
||||
if (isset($branch['type']) && $branch['type'] == 'file') {
|
||||
$html = '';
|
||||
if ($branch['name'] !== 'index') {
|
||||
$html .= '<div class="page-header"><h1>'. $branch['title'] . '</h1></div>';
|
||||
}
|
||||
$html .= MarkdownExtended(file_get_contents($branch['path']));
|
||||
return $html;
|
||||
} else {
|
||||
return "Oh No. That page dosn't exist";
|
||||
}
|
||||
}
|
||||
|
||||
function find_branch($tree) {
|
||||
$path = url_params();
|
||||
foreach($path as $peice) {
|
||||
// Check for homepage
|
||||
if (empty($peice)) {
|
||||
$peice = 'index';
|
||||
}
|
||||
|
||||
if (isset($tree[$peice])) {
|
||||
if ($tree[$peice]['type'] == 'folder') {
|
||||
$tree = $tree[$peice]['tree'];
|
||||
} else {
|
||||
$tree = $tree[$peice];
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
function url_path() {
|
||||
$url = parse_url($_SERVER['REQUEST_URI']);
|
||||
$url = $url['path'];
|
||||
return $url;
|
||||
}
|
||||
|
||||
function url_params() {
|
||||
$url = url_path();
|
||||
$params = explode('/', trim($url, '/'));
|
||||
return $params;
|
||||
}
|
||||
|
||||
function clean_sort($text) {
|
||||
// Remove .md file extension
|
||||
$text = str_replace('.md', '', $text);
|
||||
|
||||
// Remove sort placeholder
|
||||
$parts = explode('_', $text);
|
||||
if (isset($parts[0]) && is_numeric($parts[0])) {
|
||||
unset($parts[0]);
|
||||
}
|
||||
$text = implode('_', $parts);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
function clean_name($text) {
|
||||
$text = str_replace('_', ' ', $text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
function build_nav($tree, $url_params = false) {
|
||||
if (!is_array($url_params)) {
|
||||
$url_params = url_params();
|
||||
}
|
||||
$url_path = url_path();
|
||||
$html = '<ul class="nav nav-list">';
|
||||
foreach($tree as $key => $val) {
|
||||
// Active Tree Node
|
||||
if (isset($url_params[0]) && $url_params[0] == $val['clean']) {
|
||||
array_shift($url_params);
|
||||
|
||||
// Final Node
|
||||
if ($url_path == $val['url']) {
|
||||
$html .= '<li class="active">';
|
||||
} else {
|
||||
$html .= '<li class="open">';
|
||||
}
|
||||
} else {
|
||||
$html .= '<li>';
|
||||
}
|
||||
|
||||
if ($val['type'] == 'folder') {
|
||||
$html .= '<a href="#" class="aj-nav folder">'.$val['name'].'</a>';
|
||||
$html .= build_nav($val['tree'], $url_params);
|
||||
} else {
|
||||
$html .= '<a href="'.$val['url'].'">'.$val['name'].'</a>';
|
||||
}
|
||||
|
||||
$html .= '</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
function get_tree($path = '.', $clean_path = '', $title = ''){
|
||||
$tree = array();
|
||||
$ignore = array('config.json', 'cgi-bin', '.', '..');
|
||||
$dh = @opendir($path);
|
||||
$index = 0;
|
||||
|
||||
// Loop through the directory
|
||||
while(false !== ($file = readdir($dh))){
|
||||
|
||||
// Check that this file is not to be ignored
|
||||
if(!in_array($file, $ignore)) {
|
||||
$full_path = "$path/$file";
|
||||
$clean_sort = clean_sort($file);
|
||||
$url = $clean_path . '/' . $clean_sort;
|
||||
$clean_name = clean_name($clean_sort);
|
||||
|
||||
// Title
|
||||
if (empty($title)) {
|
||||
$full_title = $clean_name;
|
||||
} else {
|
||||
$full_title = $title . ': ' . $clean_name;
|
||||
}
|
||||
|
||||
if(is_dir("$path/$file")) {
|
||||
// Directory
|
||||
$tree[$clean_sort] = array(
|
||||
'type' => 'folder',
|
||||
'name' => $clean_name,
|
||||
'title' => $full_title,
|
||||
'path' => $full_path,
|
||||
'clean' => $clean_sort,
|
||||
'url' => $url,
|
||||
'tree'=> get_tree($full_path, $url, $full_title)
|
||||
);
|
||||
} else {
|
||||
// File
|
||||
$tree[$clean_sort] = array(
|
||||
'type' => 'file',
|
||||
'name' => $clean_name,
|
||||
'title' => $full_title,
|
||||
'path' => $full_path,
|
||||
'clean' => $clean_sort,
|
||||
'url' => $url,
|
||||
);
|
||||
}
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
|
||||
// Close the directory handle
|
||||
closedir($dh);
|
||||
|
||||
return $tree;
|
||||
}
|
||||
?>
|
2932
libs/markdown.php
Executable file
2932
libs/markdown.php
Executable file
File diff suppressed because it is too large
Load Diff
161
libs/markdown_extended.php
Executable file
161
libs/markdown_extended.php
Executable file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
require_once('markdown.php');
|
||||
define( 'MARKDOWNEXTRAEXTENDED_VERSION', "0.3" );
|
||||
|
||||
function MarkdownExtended($text, $default_claases = array()){
|
||||
$parser = new MarkdownExtraExtended_Parser($default_claases);
|
||||
return $parser->transform($text);
|
||||
}
|
||||
|
||||
class MarkdownExtraExtended_Parser extends MarkdownExtra_Parser {
|
||||
# Tags that are always treated as block tags:
|
||||
var $block_tags_re = 'figure|figcaption|p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend';
|
||||
var $default_classes;
|
||||
|
||||
function MarkdownExtraExtended_Parser($default_classes = array()) {
|
||||
$default_classes = $default_classes;
|
||||
|
||||
$this->block_gamut += array(
|
||||
"doFencedFigures" => 7,
|
||||
);
|
||||
|
||||
parent::MarkdownExtra_Parser();
|
||||
}
|
||||
|
||||
function transform($text) {
|
||||
$text = parent::transform($text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
function doHardBreaks($text) {
|
||||
# Do hard breaks:
|
||||
# EXTENDED: changed to allow breaks without two spaces and just one new line
|
||||
# original code /* return preg_replace_callback('/ {2,}\n/', */
|
||||
return preg_replace_callback('/ *\n/',
|
||||
array(&$this, '_doHardBreaks_callback'), $text);
|
||||
}
|
||||
|
||||
|
||||
function doBlockQuotes($text) {
|
||||
$text = preg_replace_callback('/
|
||||
(?>^[ ]*>[ ]?
|
||||
(?:\((.+?)\))?
|
||||
[ ]*(.+\n(?:.+\n)*)
|
||||
)+
|
||||
/xm',
|
||||
array(&$this, '_doBlockQuotes_callback'), $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
function _doBlockQuotes_callback($matches) {
|
||||
$cite = $matches[1];
|
||||
$bq = '> ' . $matches[2];
|
||||
# trim one level of quoting - trim whitespace-only lines
|
||||
$bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq);
|
||||
$bq = $this->runBlockGamut($bq); # recurse
|
||||
|
||||
$bq = preg_replace('/^/m', " ", $bq);
|
||||
# These leading spaces cause problem with <pre> content,
|
||||
# so we need to fix that:
|
||||
$bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx',
|
||||
array(&$this, '_doBlockQuotes_callback2'), $bq);
|
||||
|
||||
$res = "<blockquote";
|
||||
$res .= empty($cite) ? ">" : " cite=\"$cite\">";
|
||||
$res .= "\n$bq\n</blockquote>";
|
||||
return "\n". $this->hashBlock($res)."\n\n";
|
||||
}
|
||||
|
||||
function doFencedCodeBlocks($text) {
|
||||
$less_than_tab = $this->tab_width;
|
||||
|
||||
$text = preg_replace_callback('{
|
||||
(?:\n|\A)
|
||||
# 1: Opening marker
|
||||
(
|
||||
~{3,}|`{3,} # Marker: three tilde or more.
|
||||
)
|
||||
|
||||
[ ]?(\w+)?(?:,[ ]?(\d+))?[ ]* \n # Whitespace and newline following marker.
|
||||
|
||||
# 3: Content
|
||||
(
|
||||
(?>
|
||||
(?!\1 [ ]* \n) # Not a closing marker.
|
||||
.*\n+
|
||||
)+
|
||||
)
|
||||
|
||||
# Closing marker.
|
||||
\1 [ ]* \n
|
||||
}xm',
|
||||
array(&$this, '_doFencedCodeBlocks_callback'), $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
function _doFencedCodeBlocks_callback($matches) {
|
||||
$codeblock = $matches[4];
|
||||
$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
|
||||
$codeblock = preg_replace_callback('/^\n+/',
|
||||
array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock);
|
||||
//$codeblock = "<pre><code>$codeblock</code></pre>";
|
||||
//$cb = "<pre><code";
|
||||
$cb = empty($matches[3]) ? "<pre><code" : "<pre class=\"linenums:$matches[3]\"><code";
|
||||
$cb .= empty($matches[2]) ? ">" : " class=\"language-$matches[2]\">";
|
||||
$cb .= "$codeblock</code></pre>";
|
||||
return "\n\n".$this->hashBlock($cb)."\n\n";
|
||||
}
|
||||
|
||||
function doFencedFigures($text){
|
||||
$text = preg_replace_callback('{
|
||||
(?:\n|\A)
|
||||
# 1: Opening marker
|
||||
(
|
||||
={3,} # Marker: equal sign.
|
||||
)
|
||||
|
||||
[ ]?(?:\[([^\]]+)\])?[ ]* \n # Whitespace and newline following marker.
|
||||
|
||||
# 3: Content
|
||||
(
|
||||
(?>
|
||||
(?!\1 [ ]?(?:\[([^\]]+)\])?[ ]* \n) # Not a closing marker.
|
||||
.*\n+
|
||||
)+
|
||||
)
|
||||
|
||||
# Closing marker.
|
||||
\1 [ ]?(?:\[([^\]]+)\])?[ ]* \n
|
||||
}xm', array(&$this, '_doFencedFigures_callback'), $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
function _doFencedFigures_callback($matches) {
|
||||
# get figcaption
|
||||
$topcaption = empty($matches[2]) ? null : $this->runBlockGamut($matches[2]);
|
||||
$bottomcaption = empty($matches[5]) ? null : $this->runBlockGamut($matches[5]);
|
||||
$figure = $matches[3];
|
||||
$figure = $this->runBlockGamut($figure); # recurse
|
||||
|
||||
$figure = preg_replace('/^/m', " ", $figure);
|
||||
# These leading spaces cause problem with <pre> content,
|
||||
# so we need to fix that - reuse blockqoute code to handle this:
|
||||
$figure = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx',
|
||||
array(&$this, '_doBlockQuotes_callback2'), $figure);
|
||||
|
||||
$res = "<figure>";
|
||||
if(!empty($topcaption)){
|
||||
$res .= "\n<figcaption>$topcaption</figcaption>";
|
||||
}
|
||||
$res .= "\n$figure\n";
|
||||
if(!empty($bottomcaption) && empty($topcaption)){
|
||||
$res .= "<figcaption>$bottomcaption</figcaption>";
|
||||
}
|
||||
$res .= "</figure>";
|
||||
return "\n". $this->hashBlock($res)."\n\n";
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user