X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fdocfile.php;h=583f7ebc9b3190353763ca2439f9d42f1815511c;hb=1663e2743bb295e04a0d0399d201b45668025e88;hp=1b7fde3cfe686741557ee817a9e70162550fd9e1;hpb=e5b070b141d5c0a2b9268d853ba82a26da4ee547;p=quix0rs-gnu-social.git diff --git a/lib/docfile.php b/lib/docfile.php index 1b7fde3cfe..583f7ebc9b 100644 --- a/lib/docfile.php +++ b/lib/docfile.php @@ -55,12 +55,8 @@ class DocFile $this->filename = $filename; } - static function forTitle($title, $paths) + static function forTitle($title, array $paths, $language=null) { - if (!is_array($paths)) { - $paths = array($paths); - } - $filename = null; if (Event::handle('StartDocFileForTitle', array($title, &$paths, &$filename))) { @@ -80,7 +76,7 @@ class DocFile } if (!empty($lang) || !empty($def)) { - $filename = self::negotiateLanguage($lang, $def); + $filename = self::negotiateLanguage($lang, $def, $language); break; } } @@ -95,12 +91,8 @@ class DocFile } } - function toHTML(array $args=null) + function toHTML(array $args=array()) { - if (is_null($args)) { - $args = array(); - } - if (empty($this->contents)) { $this->contents = file_get_contents($this->filename); } @@ -113,8 +105,8 @@ class DocFile $paths = array(INSTALLDIR.'/local/doc-src/', INSTALLDIR.'/doc-src/'); - $site = StatusNet::currentSite(); - + $site = GNUsocial::currentSite(); + if (!empty($site)) { array_unshift($paths, INSTALLDIR.'/local/doc-src/'.$site.'/'); } @@ -127,8 +119,8 @@ class DocFile $paths = array(INSTALLDIR.'/local/mail-src/', INSTALLDIR.'/mail-src/'); - $site = StatusNet::currentSite(); - + $site = GNUsocial::currentSite(); + if (!empty($site)) { array_unshift($paths, INSTALLDIR.'/local/mail-src/'.$site.'/'); } @@ -136,12 +128,20 @@ class DocFile return $paths; } - static function negotiateLanguage($filenames, $defaultFilename=null) + private static function negotiateLanguage(array $filenames, $defaultFilename=null, $language = null) { - // XXX: do this better - + // Default is current language $langcode = common_language(); + // Is a language set? + if (!empty($language)) { + // And is it valid? + if (common_valid_language($language)) { + // Use this as language (e.g. from form) + $langcode = strval($language); + } + } + foreach ($filenames as $filename) { if (preg_match('/\.'.$langcode.'$/', $filename)) { return $filename;