X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fdocfile.php;h=583f7ebc9b3190353763ca2439f9d42f1815511c;hb=b53e1439969bfa2c0b551d8cc2fc8fe15652c62a;hp=e3968706953003e5a88e752930c956f22ec0967f;hpb=0dbdcf2936a00282114f1368ead2f5edebc6ae61;p=quix0rs-gnu-social.git diff --git a/lib/docfile.php b/lib/docfile.php index e396870695..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($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;