Manual merge of PR 69

This commit is contained in:
Denis Kisselev 2013-10-03 14:16:42 -07:00
commit 78b510a766
3 changed files with 88 additions and 20 deletions

View File

@ -228,6 +228,37 @@ If your server does not have a default timezone set in php.ini, it may return er
}
```
###Multi-language
Enables multi-language support which needs seperate directories for each language in `docs/` folder.
```json
{
"languages": { "en": "English", "de": "German" }
}
```
Directory structure:
```
├── docs/
│ ├── index.md
│ ├── en
│ │ ├── 00_Getting_Started.md
│ │ ├── 01_Examples
│ │ │ ├── 01_GitHub_Flavored_Markdown.md
│ │ │ ├── 05_Code_Highlighting.md
│ │ ├── 05_More_Examples
│ │ │ ├── Hello_World.md
│ │ │ ├── 05_Code_Highlighting.md
│ ├── de
│ │ ├── 00_Getting_Started.md
│ │ ├── 01_Examples
│ │ │ ├── 01_GitHub_Flavored_Markdown.md
│ │ │ ├── 05_Code_Highlighting.md
│ │ ├── 05_More_Examples
│ │ │ ├── Hello_World.md
│ │ │ ├── 05_Code_Highlighting.md
```
## Running Remotely
Copy the files from the repo to a web server that can run PHP 5.3 or greater.

View File

@ -67,10 +67,31 @@ require_once('libs/functions.php');
$options = get_options();
$tree = get_tree($options['docs_path'], $base_url);
$homepage_url = homepage_url($tree);
$docs_url = docs_url($tree);
$page = load_page($tree);
// If a language is set in the config, rewrite urls based on the language
if ($language === null) {
$homepage_url = homepage_url($tree);
$docs_url = docs_url($tree);
} else {
$homepage_url = "/";
}
$docs_url = docs_url($tree);
$url_params = url_params();
if (count($options['languages']) > 0 && count($url_params) > 0 && strlen($url_params[0]) > 0) {
$language = array_shift($url_params);
$base_path = "docs/" . $language;
} else {
$language = null;
$base_path = "docs";
}
$tree = get_tree($base_path, $base_url, '', true, $language);
$page = load_page($tree, $url_params);
// If a timezone has been set in the config file, override the default PHP timezone for this application.
if(isset($options['timezone']))
@ -174,9 +195,17 @@ if ($homepage && $homepage_url !== '/') {
View On GitHub
</a>
<?php } ?>
<?php if (count($options['languages']) > 0) { ?>
<?php foreach ($options['languages'] as $language_key => $language_name) { ?>
<a href="<?php echo $base_url . "/" . $language_key . "/"; ?>" class="btn btn-primary btn-hero">
<?php echo $language_name; ?>
</a>
<?php } ?>
<?php } else { ?>
<a href="<?php echo $docs_url;?>" class="btn btn-primary btn-hero">
View Documentation
</a>
<?php } ?>
</div>
</div>
</div>
@ -246,7 +275,7 @@ if ($homepage && $homepage_url !== '/') {
</div>
<div id="sub-nav-collapse" class="sub-nav-collapse">
<!-- Navigation -->
<?php echo build_nav($tree); ?>
<?php echo build_nav($tree, $url_params); ?>
<?php if (!empty($options['links']) || !empty($options['twitter'])) { ?>
<div class="well well-sidebar">

View File

@ -44,7 +44,8 @@ function get_options() {
'clean_urls' => true,
'google_analytics' => false,
'piwik_analytics' => false,
'ignore' => array()
'ignore' => array(),
'languages' => array()
);
// Load User Config
@ -75,7 +76,7 @@ function homepage_url($tree) {
if (isset($tree['index'])) {
return '/';
} else {
return docs_url($tree);
return docs_url($tree, false);
}
}
@ -101,8 +102,12 @@ function docs_url($tree, $branch = false) {
}
}
function load_page($tree) {
$branch = find_branch($tree);
function load_page($tree, $url_params) {
if (count($url_params) > 0) {
$branch = find_branch($tree, $url_params);
} else {
$branch = current($tree);
}
$page = array();
@ -129,9 +134,9 @@ function load_page($tree) {
return $page;
}
function find_branch($tree) {
$path = url_params();
foreach($path as $peice) {
function find_branch($tree, $url_params) {
foreach($url_params as $peice) {
// Support for cyrillic URLs
$peice = urldecode($peice);
@ -192,13 +197,10 @@ function RFC3986UrlEncode($string) {
return str_replace($entities, $replacements, urlencode($string));
}
function build_nav($tree, $url_params = false) {
function build_nav($tree, $url_params) {
// Remove Index
unset($tree['index']);
if (!is_array($url_params)) {
$url_params = url_params();
}
$url_path = url_path();
$html = '<ul class="nav nav-list">';
foreach($tree as $key => $val) {
@ -254,7 +256,7 @@ function get_ignored() {
return $all_ignored;
}
function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
function get_tree($path = '.', $clean_path = '', $title = '', $first = true, $language = null){
$options = get_options();
$tree = array();
$ignore = get_ignored();
@ -273,6 +275,12 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
// Sort paths
sort($paths);
if ($first && $language !== null) {
$language_path = $language . "/";
} else {
$language_path = "";
}
// Loop through the paths
// while(false !== ($file = readdir($dh))){
foreach($paths as $file) {
@ -287,16 +295,16 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
{
if($first)
{
$url = $clean_path . '/index.php/' . $clean_sort;
$url = $clean_path . '/' . $language_path . 'index.php/' . $clean_sort;
}
else
{
$url = $clean_path . '/' . $clean_sort;
$url = $clean_path . '/' . $language_path . $clean_sort;
}
}
else
{
$url = $clean_path . '/' . $clean_sort;
$url = $clean_path . '/' . $language_path . $clean_sort;
}
$clean_name = clean_name($clean_sort);
@ -317,7 +325,7 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
'path' => $full_path,
'clean' => $clean_sort,
'url' => $url,
'tree'=> get_tree($full_path, $url, $full_title, false)
'tree'=> get_tree($full_path, $url, $full_title, false, $language)
);
} else {
// File