X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fdocfile.php;h=2e2afbd014de511f6c3acb75fa04eee8e56e9006;hb=931753229328d0ebdf80b76b898a736c06dc70a4;hp=e3968706953003e5a88e752930c956f22ec0967f;hpb=0dbdcf2936a00282114f1368ead2f5edebc6ae61;p=quix0rs-gnu-social.git diff --git a/lib/docfile.php b/lib/docfile.php index e396870695..2e2afbd014 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($args=null) + function toHTML(array $args=array()) { - if (is_null($args)) { - $args = array(); - } - if (empty($this->contents)) { $this->contents = file_get_contents($this->filename); } @@ -114,7 +106,7 @@ class DocFile INSTALLDIR.'/doc-src/'); $site = StatusNet::currentSite(); - + if (!empty($site)) { array_unshift($paths, INSTALLDIR.'/local/doc-src/'.$site.'/'); } @@ -128,7 +120,7 @@ class DocFile INSTALLDIR.'/mail-src/'); $site = StatusNet::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;