$this->filename = $filename;
}
- static function forTitle($title, $paths)
+ static function forTitle($title, array $paths, $language=null)
{
- if (is_string($paths)) {
- $paths = array($paths);
- }
-
$filename = null;
- foreach ($paths as $path) {
+ if (Event::handle('StartDocFileForTitle', array($title, &$paths, &$filename))) {
- $def = $path.'/'.$title;
- if (!file_exists($def)) {
- $def = null;
- }
+ foreach ($paths as $path) {
- $lang = glob($path.'/'.$title.'.*');
+ $def = $path.'/'.$title;
- if ($lang === false) {
- $lang = array();
- }
+ if (!file_exists($def)) {
+ $def = null;
+ }
+
+ $lang = glob($path.'/'.$title.'.*');
- if (!empty($lang) || !empty($def)) {
- $filename = self::negotiateLanguage($lang, $def);
- break;
+ if ($lang === false) {
+ $lang = array();
+ }
+
+ if (!empty($lang) || !empty($def)) {
+ $filename = self::negotiateLanguage($lang, $def, $language);
+ break;
+ }
}
+
+ Event::handle('EndDocFileForTitle', array($title, $paths, &$filename));
}
if (empty($filename)) {
}
}
- function toHTML()
+ function toHTML(array $args=array())
{
if (empty($this->contents)) {
$this->contents = file_get_contents($this->filename);
}
- $this->output = common_markup_to_html($this->contents);
+ return common_markup_to_html($this->contents, $args);
}
static function defaultPaths()
INSTALLDIR.'/doc-src/');
$site = StatusNet::currentSite();
-
+
if (!empty($site)) {
array_unshift($paths, INSTALLDIR.'/local/doc-src/'.$site.'/');
}
+
+ return $paths;
}
- static function negotiateLanguage($filenames, $defaultFilename=null)
+ static function mailPaths()
{
- // XXX: do this better
+ $paths = array(INSTALLDIR.'/local/mail-src/',
+ INSTALLDIR.'/mail-src/');
+
+ $site = StatusNet::currentSite();
+
+ if (!empty($site)) {
+ array_unshift($paths, INSTALLDIR.'/local/mail-src/'.$site.'/');
+ }
+
+ return $paths;
+ }
+ private static function negotiateLanguage(array $filenames, $defaultFilename=null, $language = null)
+ {
+ // 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;