]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/docfile.php
Misses this file to merge. I like the comments.
[quix0rs-gnu-social.git] / lib / docfile.php
index ca03370d29e3df3ca42b2321bcbbd9dbd430ca30..583f7ebc9b3190353763ca2439f9d42f1815511c 100644 (file)
@@ -55,31 +55,33 @@ class DocFile
         $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)) {
@@ -89,13 +91,13 @@ class DocFile
         }
     }
 
-    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()
@@ -103,19 +105,43 @@ 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.'/');
         }
+
+        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 = GNUsocial::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;