Manual merge of PR 69
This commit is contained in:
commit
78b510a766
31
README.md
31
README.md
@ -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
|
## Running Remotely
|
||||||
|
|
||||||
Copy the files from the repo to a web server that can run PHP 5.3 or greater.
|
Copy the files from the repo to a web server that can run PHP 5.3 or greater.
|
||||||
|
33
index.php
33
index.php
@ -67,10 +67,31 @@ require_once('libs/functions.php');
|
|||||||
|
|
||||||
$options = get_options();
|
$options = get_options();
|
||||||
$tree = get_tree($options['docs_path'], $base_url);
|
$tree = get_tree($options['docs_path'], $base_url);
|
||||||
|
|
||||||
|
// If a language is set in the config, rewrite urls based on the language
|
||||||
|
if ($language === null) {
|
||||||
$homepage_url = homepage_url($tree);
|
$homepage_url = homepage_url($tree);
|
||||||
$docs_url = docs_url($tree);
|
$docs_url = docs_url($tree);
|
||||||
|
} else {
|
||||||
|
$homepage_url = "/";
|
||||||
|
}
|
||||||
|
|
||||||
$page = load_page($tree);
|
$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 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']))
|
||||||
@ -174,9 +195,17 @@ if ($homepage && $homepage_url !== '/') {
|
|||||||
View On GitHub
|
View On GitHub
|
||||||
</a>
|
</a>
|
||||||
<?php } ?>
|
<?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">
|
<a href="<?php echo $docs_url;?>" class="btn btn-primary btn-hero">
|
||||||
View Documentation
|
View Documentation
|
||||||
</a>
|
</a>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -246,7 +275,7 @@ if ($homepage && $homepage_url !== '/') {
|
|||||||
</div>
|
</div>
|
||||||
<div id="sub-nav-collapse" class="sub-nav-collapse">
|
<div id="sub-nav-collapse" class="sub-nav-collapse">
|
||||||
<!-- Navigation -->
|
<!-- Navigation -->
|
||||||
<?php echo build_nav($tree); ?>
|
<?php echo build_nav($tree, $url_params); ?>
|
||||||
|
|
||||||
<?php if (!empty($options['links']) || !empty($options['twitter'])) { ?>
|
<?php if (!empty($options['links']) || !empty($options['twitter'])) { ?>
|
||||||
<div class="well well-sidebar">
|
<div class="well well-sidebar">
|
||||||
|
@ -44,7 +44,8 @@ function get_options() {
|
|||||||
'clean_urls' => true,
|
'clean_urls' => true,
|
||||||
'google_analytics' => false,
|
'google_analytics' => false,
|
||||||
'piwik_analytics' => false,
|
'piwik_analytics' => false,
|
||||||
'ignore' => array()
|
'ignore' => array(),
|
||||||
|
'languages' => array()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Load User Config
|
// Load User Config
|
||||||
@ -75,7 +76,7 @@ function homepage_url($tree) {
|
|||||||
if (isset($tree['index'])) {
|
if (isset($tree['index'])) {
|
||||||
return '/';
|
return '/';
|
||||||
} else {
|
} else {
|
||||||
return docs_url($tree);
|
return docs_url($tree, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +102,12 @@ function docs_url($tree, $branch = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function load_page($tree) {
|
function load_page($tree, $url_params) {
|
||||||
$branch = find_branch($tree);
|
if (count($url_params) > 0) {
|
||||||
|
$branch = find_branch($tree, $url_params);
|
||||||
|
} else {
|
||||||
|
$branch = current($tree);
|
||||||
|
}
|
||||||
|
|
||||||
$page = array();
|
$page = array();
|
||||||
|
|
||||||
@ -129,9 +134,9 @@ function load_page($tree) {
|
|||||||
return $page;
|
return $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
function find_branch($tree) {
|
|
||||||
$path = url_params();
|
function find_branch($tree, $url_params) {
|
||||||
foreach($path as $peice) {
|
foreach($url_params as $peice) {
|
||||||
|
|
||||||
// Support for cyrillic URLs
|
// Support for cyrillic URLs
|
||||||
$peice = urldecode($peice);
|
$peice = urldecode($peice);
|
||||||
@ -192,13 +197,10 @@ function RFC3986UrlEncode($string) {
|
|||||||
return str_replace($entities, $replacements, urlencode($string));
|
return str_replace($entities, $replacements, urlencode($string));
|
||||||
}
|
}
|
||||||
|
|
||||||
function build_nav($tree, $url_params = false) {
|
function build_nav($tree, $url_params) {
|
||||||
// Remove Index
|
// Remove Index
|
||||||
unset($tree['index']);
|
unset($tree['index']);
|
||||||
|
|
||||||
if (!is_array($url_params)) {
|
|
||||||
$url_params = url_params();
|
|
||||||
}
|
|
||||||
$url_path = url_path();
|
$url_path = url_path();
|
||||||
$html = '<ul class="nav nav-list">';
|
$html = '<ul class="nav nav-list">';
|
||||||
foreach($tree as $key => $val) {
|
foreach($tree as $key => $val) {
|
||||||
@ -254,7 +256,7 @@ function get_ignored() {
|
|||||||
return $all_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();
|
$options = get_options();
|
||||||
$tree = array();
|
$tree = array();
|
||||||
$ignore = get_ignored();
|
$ignore = get_ignored();
|
||||||
@ -273,6 +275,12 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
|
|||||||
// Sort paths
|
// Sort paths
|
||||||
sort($paths);
|
sort($paths);
|
||||||
|
|
||||||
|
if ($first && $language !== null) {
|
||||||
|
$language_path = $language . "/";
|
||||||
|
} else {
|
||||||
|
$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) {
|
||||||
@ -287,16 +295,16 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
|
|||||||
{
|
{
|
||||||
if($first)
|
if($first)
|
||||||
{
|
{
|
||||||
$url = $clean_path . '/index.php/' . $clean_sort;
|
$url = $clean_path . '/' . $language_path . 'index.php/' . $clean_sort;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$url = $clean_path . '/' . $clean_sort;
|
$url = $clean_path . '/' . $language_path . $clean_sort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$url = $clean_path . '/' . $clean_sort;
|
$url = $clean_path . '/' . $language_path . $clean_sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
$clean_name = clean_name($clean_sort);
|
$clean_name = clean_name($clean_sort);
|
||||||
@ -317,7 +325,7 @@ function get_tree($path = '.', $clean_path = '', $title = '', $first = true){
|
|||||||
'path' => $full_path,
|
'path' => $full_path,
|
||||||
'clean' => $clean_sort,
|
'clean' => $clean_sort,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'tree'=> get_tree($full_path, $url, $full_title, false)
|
'tree'=> get_tree($full_path, $url, $full_title, false, $language)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// File
|
// File
|
||||||
|
Loading…
Reference in New Issue
Block a user