"Documentation", 'tagline' => false, 'image' => false, 'theme' => 'blue', 'float' => true, 'repo' => false, 'twitter' => array(), 'links' => array(), 'colors' => false, 'google_analytics' => 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 "Daux.io Config Error:
The theme you set is not not a valid option. Please use one of the following options: " . join(array_keys($themes), ', ') . ' or learn more about how to customize the colors.'; exit; } } else { if (empty($options['colors'])) { echo 'Daux.io Config Error:
You are trying to use a custom theme, but did not setup your color options in the config. Learn more about how to customize the colors.'; exit; } } return $options; } function homepage_url($tree) { // Check for homepage if (isset($tree['index'])) { return '/'; } else { return docs_url($tree); } } function docs_url($tree, $branch = false) { // Get next branch if (!$branch) { $branch = current($tree); } if ($branch['type'] === 'file') { return $branch['url']; } else if (!empty($branch['tree'])) { return docs_url($branch['tree']); } else { // Try next folder... $branch = next($tree); if ($branch) { return docs_url($tree, $branch); } else { echo 'Daux.io Config Error:
Unable to find the first page in the /docs folder. Double check you have at least one file in the root of of the /docs folder. Also make sure you do not have any empty folders. Visit the docs to learn more about how the default routing works.'; exit; } } } function load_page($tree) { $branch = find_branch($tree); if (isset($branch['type']) && $branch['type'] == 'file') { $html = ''; if ($branch['name'] !== 'index') { $html .= ''; } $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) { // Remove Index unset($tree['index']); if (!is_array($url_params)) { $url_params = url_params(); } $url_path = url_path(); $html = ''; return $html; } function get_tree($path = '.', $clean_path = '', $title = ''){ $tree = array(); $ignore = array('config.json', 'cgi-bin', '.', '..'); $dh = @opendir($path); $index = 0; // Build array of paths $paths = array(); while(false !== ($file = readdir($dh))){ $paths[$file] = $file; } // Close the directory handle closedir($dh); // Sort paths sort($paths); // Loop through the paths // while(false !== ($file = readdir($dh))){ foreach($paths as $file) { // 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++; } return $tree; } ?>