]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
introduce theme model and use it in jsscuttle. rest will follow
authorChristian Weiske <cweiske@cweiske.de>
Tue, 24 May 2011 16:21:54 +0000 (18:21 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 24 May 2011 16:21:54 +0000 (18:21 +0200)
build.xml
src/SemanticScuttle/Model/Theme.php [new file with mode: 0644]
src/SemanticScuttle/Service/Template.php
src/SemanticScuttle/header.php
www/jsScuttle.php

index 9773a6309360a649f8c6c10acdbd04d95232827f..7b3896b4af1526fecb2126c51282bac62312dcf0 100644 (file)
--- a/build.xml
+++ b/build.xml
 
      <replacement
       path="src/SemanticScuttle/header.php"
-      type="pear-config"
-      from="@data_dir@" to="data_dir"
+      type="pear-config" from="@data_dir@" to="data_dir"
+      />
+     <replacement
+      path="src/SemanticScuttle/header.php"
+      type="pear-config" from="@www_dir@" to="www_dir"
       />
      <replacement
       path="www/www-header.php"
-      type="pear-config"
-      from="@data_dir@" to="data_dir"
+      type="pear-config" from="@data_dir@" to="data_dir"
       />
      <replacement
       path="tests/prepare.php"
-      type="pear-config"
-      from="@data_dir@" to="data_dir"
+      type="pear-config" from="@data_dir@" to="data_dir"
       />
 
      <changelog version="0.97" date="2010-06-09" license="GPL">
diff --git a/src/SemanticScuttle/Model/Theme.php b/src/SemanticScuttle/Model/Theme.php
new file mode 100644 (file)
index 0000000..a2f4973
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  AGPL v3 or later http://www.gnu.org/licenses/agpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+
+/**
+ * A theme, the visual representation of SemanticScuttle.
+ *
+ * @category Bookmarking
+ * @package  SemanticScuttle
+ * @author   Christian Weiske <cweiske@cweiske.de>
+ * @license  AGPL v3 or later http://www.gnu.org/licenses/agpl.html
+ * @link     http://sourceforge.net/projects/semanticscuttle
+ */
+class SemanticScuttle_Model_Theme
+{
+    /**
+     * Theme name. Also the path part of template and resource files
+     *
+     * @var string
+     */
+    protected $name = null;
+
+    /**
+     * Local path to the www themes directory.
+     * Needs to have a trailing slash.
+     *
+     * @var string
+     */
+    protected $wwwThemeDir = null;
+
+
+
+    /**
+     * Create a new theme instance.
+     *
+     * @param string $name Theme name "data/templates/(*)/"
+     */
+    public function __construct($name = 'default')
+    {
+        $this->name = $name;
+        $this->wwwThemeDir = $GLOBALS['wwwdir'] . '/themes/';
+        //TODO: implement theme hierarchies with parent fallback
+    }
+
+
+
+    /**
+     * Returns the URL path to a resource file (www/themes/$name/$file).
+     * Automatically falls back to the parent theme if the file does not exist
+     * in the theme.
+     *
+     * Must always be used when adding i.e. images to the output.
+     *
+     * @param string $file File name to find the path for
+     *
+     * @return string Full path
+     */
+    public function resource($file)
+    {
+        $themeFile = $this->wwwThemeDir . $this->name . '/' . $file;
+        if (file_exists($themeFile)) {
+            return ROOT . 'themes/' . $this->name . '/' . $file;
+        }
+
+        $defaultFile = $this->wwwThemeDir . 'default/' . $file;
+        if (file_exists($defaultFile)) {
+            return ROOT . 'themes/default/' . $file;
+        }
+
+        //file does not exist. fall back to the theme file
+        // to guide the theme author a bit.
+        // TODO: logging. in admin mode, there should be a message
+        return ROOT . 'themes/' . $this->name . '/' . $file;
+    }
+
+
+
+    /**
+     * Returns the theme name.
+     *
+     * @return string Theme name
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+}
+?>
\ No newline at end of file
index 2a683d6b1e7f6a71a8d3563802a00e3ae4f0d837..b5d4cfacf14d5cdc2ccebb333e50deb4662d0bc6 100644 (file)
@@ -14,6 +14,7 @@
  */
 
 require_once 'SemanticScuttle/Model/Template.php';
+require_once 'SemanticScuttle/Model/Theme.php';
 
 /**
  * SemanticScuttle template service.
@@ -40,9 +41,9 @@ class SemanticScuttle_Service_Template extends SemanticScuttle_Service
 
     /**
      * The template theme to use.
-     * Set in constructor from $GLOBALS['theme']
+     * Set in constructor based on $GLOBALS['theme']
      *
-     * @var string
+     * @var SemanticScuttle_Model_Theme
      */
     protected $theme;
 
@@ -72,7 +73,7 @@ class SemanticScuttle_Service_Template extends SemanticScuttle_Service
     protected function __construct()
     {
         $this->basedir = $GLOBALS['TEMPLATES_DIR'];
-        $this->theme   = $GLOBALS['theme'];
+        $this->theme   = new SemanticScuttle_Model_Theme($GLOBALS['theme']);
         //FIXME: verify the theme exists
     }
 
@@ -84,6 +85,8 @@ class SemanticScuttle_Service_Template extends SemanticScuttle_Service
      * @param string $template Template filename relative
      *                         to template dir
      * @param array  $vars     Array of template variables.
+     *                         The current theme object will be added
+     *                         automatically with name "theme".
      *
      * @return SemanticScuttle_Model_Template Template object
      */
@@ -95,12 +98,13 @@ class SemanticScuttle_Service_Template extends SemanticScuttle_Service
 
         $oldIncPath = get_include_path();
         set_include_path(
-            $this->basedir . $this->theme
+            $this->basedir . $this->theme->getName()
             . PATH_SEPARATOR . $this->basedir . 'default'
             //needed since services are instantiated in templates
             . PATH_SEPARATOR . $oldIncPath
         );
 
+        $vars['theme'] = $this->theme;
         $tpl = new SemanticScuttle_Model_Template(
             $template, $vars, $this
         );
index 098e5c39fad82be5afc7ecd07b7a39f778f297a6..6c0d4dff71f3c247326b06461b2ab51274ffe3e1 100644 (file)
 if ('@data_dir@' == '@' . 'data_dir@') {
     //non pear-install
     $datadir = dirname(__FILE__) . '/../../data/';
+    $wwwdir  = dirname(__FILE__) . '/../../www/';
 } else {
     //pear installation; files are in include path
     $datadir = '@data_dir@/SemanticScuttle/';
+    //FIXME: when you have multiple installations, the www_dir will be wrong
+    $wwwdir  = '@www_dir@/SemanticScuttle/';
 }
 
 if (!file_exists($datadir . '/config.php')) {
index 4f9d3b7222a5cee6676c2285e6c424d293af92c2..5e5f31b84a30709fc4c7438983bb26ccd6005f8f 100644 (file)
@@ -3,6 +3,7 @@ $GLOBALS['saveInLastUrl'] = false;
 $httpContentType = 'text/javascript';
 require_once 'www-header.php';
 require_once 'SemanticScuttle/functions.php';
+$theme = new SemanticScuttle_Model_Theme($GLOBALS['theme']);
 $player_root = ROOT .'includes/player/';
 ?>
 
@@ -62,7 +63,7 @@ function isAvailable(input, response){
     username = username.trim();
     var availability = document.getElementById("availability");
     if (username != '') {
-        usernameField.style.backgroundImage = 'url(<?php echo ROOT . 'themes/' . $GLOBALS['theme']; ?>/images/loading.gif)';
+        usernameField.style.backgroundImage = 'url(<?php echo $theme->resource('images/loading.gif'); ?>)';
         if (response != '') {
             usernameField.style.backgroundImage = 'none';
             if (response == 'true') {
@@ -92,7 +93,7 @@ function useAddress(ele) {
 function getTitle(input, response){
     var title = document.getElementById('titleField');
     if (title.value == '') {
-        title.style.backgroundImage = 'url(<?php echo ROOT . 'themes/' . $GLOBALS['theme']; ?>/images/loading.gif)';
+        title.style.backgroundImage = 'url(<?php echo $theme->resource('images/loading.gif');?>)';
         if (response != null) {
             title.style.backgroundImage = 'none';
             title.value = response;