]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/theme.php
Possible hack for tags from private dents in public profile or wrong scope (both...
[quix0rs-gnu-social.git] / lib / theme.php
index 5caa046c208c05d13f6b4b6d37e913042608d545..fbcbbe052a3934eaad47fdd94d28ed15f1506dfd 100644 (file)
@@ -53,9 +53,14 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
  */
 class Theme
 {
+    const FALLBACK = 'neo';
+
     var $name = null;
     var $dir  = null;
     var $path = null;
+    protected $metadata = null; // access via getMetadata() lazy-loader
+    protected $externals = null;
+    protected $deps = null;
 
     /**
      * Constructor
@@ -96,7 +101,19 @@ class Theme
         if (file_exists($fulldir) && is_dir($fulldir)) {
             $this->dir = $fulldir;
             $this->path = $this->relativeThemePath('theme', 'theme', $name);
+            return;
         }
+
+        // Ruh roh. Fall back to default, then.
+
+        common_log(LOG_WARNING, sprintf("Unable to find theme '%s', falling back to default theme '%s'",
+                                        $name,
+                                        Theme::FALLBACK));
+
+        $this->name = Theme::FALLBACK;
+        $this->dir  = $instroot.'/'.Theme::FALLBACK;
+        $this->path = $this->relativeThemePath('theme', 'theme', Theme::FALLBACK);
+
     }
 
     /**
@@ -199,9 +216,12 @@ class Theme
      */
     function getDeps()
     {
-        $chain = $this->doGetDeps(array($this->name));
-        array_pop($chain); // Drop us back off
-        return $chain;
+        if ($this->deps === null) {
+            $chain = $this->doGetDeps(array($this->name));
+            array_pop($chain); // Drop us back off
+            $this->deps = $chain;
+        }
+        return $this->deps;
     }
 
     protected function doGetDeps($chain)
@@ -233,6 +253,20 @@ class Theme
      * @return associative array of strings
      */
     function getMetadata()
+    {
+        if ($this->metadata == null) {
+            $this->metadata = $this->doGetMetadata();
+        }
+        return $this->metadata;
+    }
+
+    /**
+     * Pull data from the theme's theme.ini file.
+     * @fixme calling getFile will fall back to default theme, this may be unsafe.
+     *
+     * @return associative array of strings
+     */
+    private function doGetMetadata()
     {
         $iniFile = $this->getFile('theme.ini');
         if (file_exists($iniFile)) {
@@ -242,6 +276,32 @@ class Theme
         }
     }
 
+    /**
+     * Get list of any external URLs required by this theme and any
+     * dependencies. These are lazy-loaded from theme.ini.
+     *
+     * @return array of URL strings
+     */
+    function getExternals()
+    {
+        if ($this->externals == null) {
+            $data = $this->getMetadata();
+            if (!empty($data['external'])) {
+                $ext = (array)$data['external'];
+            } else {
+                $ext = array();
+            }
+
+            if (!empty($data['include'])) {
+                $theme = new Theme($data['include']);
+                $ext = array_merge($ext, $theme->getExternals());
+            }
+
+            $this->externals = array_unique($ext);
+        }
+        return $this->externals;
+    }
+
     /**
      * Gets the full path of a file in a theme dir based on its relative name
      *