diff options
author | zotlabs <mike@macgirvin.com> | 2018-08-20 20:20:57 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2018-08-20 20:20:57 -0700 |
commit | 066febdf4092a308d70e9989b322afb470253132 (patch) | |
tree | bc74661ddc623c6a8e2525355bb12c8f439529bf | |
parent | 9b620b2a35e256c905b6e3bd0e6f0228a0426e07 (diff) | |
parent | e25db4d1b57116353ad4e4909eb93824a673ffb3 (diff) | |
download | volse-hubzilla-066febdf4092a308d70e9989b322afb470253132.tar.gz volse-hubzilla-066febdf4092a308d70e9989b322afb470253132.tar.bz2 volse-hubzilla-066febdf4092a308d70e9989b322afb470253132.zip |
Merge branch 'dev' of https://framagit.org/hubzilla/core into xdev_merge
-rwxr-xr-x | Zotlabs/Render/SmartyTemplate.php | 19 | ||||
-rwxr-xr-x | boot.php | 5 | ||||
-rw-r--r-- | include/help.php | 99 | ||||
-rwxr-xr-x | include/plugin.php | 55 |
4 files changed, 119 insertions, 59 deletions
diff --git a/Zotlabs/Render/SmartyTemplate.php b/Zotlabs/Render/SmartyTemplate.php index ffe58e286..f14d63064 100755 --- a/Zotlabs/Render/SmartyTemplate.php +++ b/Zotlabs/Render/SmartyTemplate.php @@ -64,17 +64,20 @@ class SmartyTemplate implements TemplateEngine { public function get_intltext_template($file, $root='') { $lang = \App::$language; - - if(file_exists("view/$lang/$file")) - $template_file = "view/$lang/$file"; - elseif(file_exists("view/en/$file")) - $template_file = "view/en/$file"; - else - $template_file = theme_include($file,$root); + if ($root != '' && substr($root,-1) != '/' ) { + $root .= '/'; + } + foreach (Array( + $root."view/$lang/$file", + $root."view/en/$file", + '' + ) as $template_file) { + if (is_file($template_file)) { break; } + } + if ($template_file=='') {$template_file = theme_include($file,$root);} if($template_file) { $template = new SmartyInterface(); $template->filename = $template_file; - return $template; } return ""; @@ -728,6 +728,11 @@ class App { private static $perms = null; // observer permissions private static $widgets = array(); // widgets for this page public static $config = array(); // config cache + public static $override_intltext_templates = array(); + public static $override_markup_templates = array(); + public static $override_templateroot = null; + public static $override_helproot = null; + public static $override_helpfiles = array(); public static $session = null; public static $groups; diff --git a/include/help.php b/include/help.php index ce389b4db..3b56a7238 100644 --- a/include/help.php +++ b/include/help.php @@ -2,6 +2,50 @@ use \Michelf\MarkdownExtra; + +/** + * @brief + * + * @param string $path + * @return string|unknown + */ +function get_help_fullpath($path,$suffix=null) { + + $docroot = (\App::$override_helproot) ? \App::$override_helproot : 'doc/'; + $docroot = (substr($docroot,-1)!='/') ? $docroot .= '/' : $docroot; + + // Determine the language and modify the path accordingly + $x = determine_help_language(); + $lang = $x['language']; + $url_idx = ($x['from_url'] ? 1 : 0); + // The English translation is at the root of /doc/. Other languages are in + // subfolders named by the language code such as "de", "es", etc. + if($lang !== 'en') { + $langpath = $lang . '/' . $path; + } else { + $langpath = $path; + } + + $newpath = (isset(\App::$override_helpfiles[$langpath])) ? \App::$override_helpfiles[$langpath] : $langpath; + $newpath = ($newpath == $langpath) ? $docroot . $newpath : $newpath; + + if ($suffix) { + if (file_exists($newpath . $suffix)) { + return $newpath; + } + } elseif (file_exists($newpath . '.md') || + file_exists($newpath . '.bb') || + file_exists($newpath . '.html')) { + return $newpath; + } + + $newpath = (isset(\App::$override_helpfiles[$path])) ? \App::$override_helpfiles[$path] : null; + + $newpath = (!$newpath) ? $docroot.$path : $newpath; + return $newpath; +} + + /** * @brief * @@ -9,7 +53,6 @@ use \Michelf\MarkdownExtra; * @return string|unknown */ function get_help_content($tocpath = false) { - global $lang; $doctype = 'markdown'; @@ -17,6 +60,8 @@ function get_help_content($tocpath = false) { $text = ''; $path = (($tocpath !== false) ? $tocpath : ''); + $docroot = (\App::$override_helproot) ? \App::$override_helproot : 'doc/'; + $docroot = (substr($docroot,-1)!='/') ? $docroot .= '/' : $docroot; if($tocpath === false && argc() > 1) { $path = ''; @@ -27,8 +72,9 @@ function get_help_content($tocpath = false) { } } - if($path) { + if($path) { + $fullpath = get_help_fullpath($path); $title = basename($path); if(! $tocpath) \App::$page['title'] = t('Help:') . ' ' . ucwords(str_replace('-',' ',notags($title))); @@ -39,21 +85,22 @@ function get_help_content($tocpath = false) { // TODO: This is incompatible with the hierarchical TOC construction // defined in /Zotlabs/Widget/Helpindex.php. if($tocpath !== false && - load_doc_file('doc/' . $path . '.md') === '' && - load_doc_file('doc/' . $path . '.bb') === '' && - load_doc_file('doc/' . $path . '.html') === '' + load_doc_file($fullpath . '.md') === '' && + load_doc_file($fullpath . '.bb') === '' && + load_doc_file($fullpath . '.html') === '' ) { $path = $title; } - $text = load_doc_file('doc/' . $path . '.md'); + $fullpath = get_help_fullpath($path); + $text = load_doc_file($fullpath . '.md'); if(! $text) { - $text = load_doc_file('doc/' . $path . '.bb'); + $text = load_doc_file($fullpath . '.bb'); if($text) $doctype = 'bbcode'; } if(! $text) { - $text = load_doc_file('doc/' . $path . '.html'); + $text = load_doc_file($fullpath . '.html'); if($text) $doctype = 'html'; } @@ -64,12 +111,16 @@ function get_help_content($tocpath = false) { if($tocpath === false) { if(! $text) { - $text = load_doc_file('doc/Site.md'); + $path = 'Site'; + $fullpath = get_help_fullpath($path,'.md'); + $text = load_doc_file($fullpath . '.md'); \App::$page['title'] = t('Help'); } if(! $text) { $doctype = 'bbcode'; - $text = load_doc_file('doc/main.bb'); + $path = 'main'; + $fullpath = get_help_fullpath($path,'.md'); + $text = load_doc_file($fullpath . '.bb'); goaway('/help/about/about'); \App::$page['title'] = t('Help'); } @@ -146,35 +197,7 @@ function determine_help_language() { } function load_doc_file($s) { - $path = 'doc'; - // Determine the language and modify the path accordingly - $x = determine_help_language(); - $lang = $x['language']; - $url_idx = ($x['from_url'] ? 1 : 0); - // The English translation is at the root of /doc/. Other languages are in - // subfolders named by the language code such as "de", "es", etc. - if($lang !== 'en') { - $path .= '/' . $lang; - } - $b = basename($s); - - for($i=1+$url_idx; $i<argc()-1; $i++) { - $path .= '/' . argv($i); - } - $c = find_doc_file($path . '/' . $b); - if($c) - return $c; - // Possibly a translation was requested that has not been translated, so fall - // back to the English version - $path = 'doc'; - for($i=1+$url_idx; $i<argc()-1; $i++) { - $path .= '/' . argv($i); - } - $c = find_doc_file($path . '/' . $b); - if($c) - return $c; - // Try one last time to find the file at the explicit path input to the function $c = find_doc_file($s); if($c) return $c; diff --git a/include/plugin.php b/include/plugin.php index 13652c620..23cb2b5f6 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -959,9 +959,8 @@ function format_js_if_exists($source) { function theme_include($file, $root = '') { // Make sure $root ends with a slash / if it's not blank - if($root !== '' && $root[strlen($root)-1] !== '/') + if($root !== '' && substr($root,-1) !== '/') $root = $root . '/'; - $theme_info = App::$theme_info; if(array_key_exists('extends',$theme_info)) @@ -992,21 +991,51 @@ function theme_include($file, $root = '') { return ''; } - function get_intltext_template($s, $root = '') { - - $t = App::template_engine(); - - $template = $t->get_intltext_template($s, $root); - return $template; + $testroot = ($root=='') ? $testroot = "ROOT" : $root; + $t = App::template_engine(); + + if (isset(\App::$override_intltext_templates[$testroot][$s]["content"])) { + return \App::$override_intltext_templates[$testroot][$s]["content"]; + } else { + if (isset(\App::$override_intltext_templates[$testroot][$s]["root"]) && + isset(\App::$override_intltext_templates[$testroot][$s]["file"])) { + $s = \App::$override_intltext_templates[$testroot][$s]["file"]; + $root = \App::$override_intltext_templates[$testroot][$s]["root"]; + } elseif (\App::$override_templateroot) { + $newroot = \App::$override_templateroot.$root; + if ($newroot != '' && substr($newroot,-1) != '/' ) { + $newroot .= '/'; + } + $template = $t->get_intltext_template($s, $newroot); + } + $template = $t->get_intltext_template($s, $root); + return $template; + } } - function get_markup_template($s, $root = '') { - - $t = App::template_engine(); - $template = $t->get_markup_template($s, $root); - return $template; + $testroot = ($root=='') ? $testroot = "ROOT" : $root; + + $t = App::template_engine(); + + if (isset(\App::$override_markup_templates[$testroot][$s]["content"])) { + return \App::$override_markup_templates[$testroot][$s]["content"]; + } else { + if (isset(\App::$override_markup_templates[$testroot][$s]["root"]) && + isset(\App::$override_markup_templates[$testroot][$s]["file"])) { + $s = \App::$override_markup_templates[$testroot][$s]["file"]; + $root = \App::$override_markup_templates[$testroot][$s]["root"]; + } elseif (\App::$override_templateroot) { + $newroot = \App::$override_templateroot.$root; + if ($newroot != '' && substr($newroot,-1) != '/' ) { + $newroot .= '/'; + } + $template = $t->get_markup_template($s, $newroot); + } + $template = $t->get_markup_template($s, $root); + return $template; + } } /** |