diff options
author | Mark Pemberton <mpemberton5@gmail.com> | 2011-06-04 00:38:07 -0400 |
---|---|---|
committer | Mark Pemberton <mpemberton5@gmail.com> | 2011-06-04 00:38:07 -0400 |
commit | b628e63e015bc3b2eadc712feaa6c4d05cf75bbd (patch) | |
tree | ebdcec5c8133a3b6f86d06dc3f6fb3de46609f04 /src/SemanticScuttle | |
parent | 84e603aa91a303a1419962ff3ff6086710a7b1a9 (diff) | |
parent | 4c8a53c5bc632302aaf8978e711eb53a03166db5 (diff) | |
download | semanticscuttle-b628e63e015bc3b2eadc712feaa6c4d05cf75bbd.tar.gz semanticscuttle-b628e63e015bc3b2eadc712feaa6c4d05cf75bbd.tar.bz2 |
Merge branch 'master' into privatekey2
Conflicts:
data/templates/default/bookmarks.tpl.php
Diffstat (limited to 'src/SemanticScuttle')
-rw-r--r-- | src/SemanticScuttle/Model/Template.php | 3 | ||||
-rw-r--r-- | src/SemanticScuttle/Model/Theme.php | 97 | ||||
-rw-r--r-- | src/SemanticScuttle/Service/Template.php | 29 | ||||
-rw-r--r-- | src/SemanticScuttle/header.php | 3 |
4 files changed, 130 insertions, 2 deletions
diff --git a/src/SemanticScuttle/Model/Template.php b/src/SemanticScuttle/Model/Template.php index ff5fbbe..234e23f 100644 --- a/src/SemanticScuttle/Model/Template.php +++ b/src/SemanticScuttle/Model/Template.php @@ -76,6 +76,9 @@ class SemanticScuttle_Model_Template * Sets variables and includes the template file, * causing it to be rendered. * + * Does not take care of themes and so. + * The include path must be set so the correct theme is used. + * * @return void */ public function parse() diff --git a/src/SemanticScuttle/Model/Theme.php b/src/SemanticScuttle/Model/Theme.php new file mode 100644 index 0000000..65861b8 --- /dev/null +++ b/src/SemanticScuttle/Model/Theme.php @@ -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, i.e. "scuttle.css". + * + * @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 diff --git a/src/SemanticScuttle/Service/Template.php b/src/SemanticScuttle/Service/Template.php index efa8d28..b5d4cfa 100644 --- a/src/SemanticScuttle/Service/Template.php +++ b/src/SemanticScuttle/Service/Template.php @@ -14,6 +14,7 @@ */ require_once 'SemanticScuttle/Model/Template.php'; +require_once 'SemanticScuttle/Model/Theme.php'; /** * SemanticScuttle template service. @@ -38,6 +39,14 @@ class SemanticScuttle_Service_Template extends SemanticScuttle_Service */ protected $basedir; + /** + * The template theme to use. + * Set in constructor based on $GLOBALS['theme'] + * + * @var SemanticScuttle_Model_Theme + */ + protected $theme; + /** @@ -64,6 +73,8 @@ class SemanticScuttle_Service_Template extends SemanticScuttle_Service protected function __construct() { $this->basedir = $GLOBALS['TEMPLATES_DIR']; + $this->theme = new SemanticScuttle_Model_Theme($GLOBALS['theme']); + //FIXME: verify the theme exists } @@ -74,19 +85,33 @@ 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 */ - function loadTemplate($template, $vars = null) + public function loadTemplate($template, $vars = null) { if (substr($template, -4) != '.php') { $template .= '.php'; } + + $oldIncPath = get_include_path(); + set_include_path( + $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( - $this->basedir .'/'. $template, $vars, $this + $template, $vars, $this ); $tpl->parse(); + set_include_path($oldIncPath); + return $tpl; } } diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php index 098e5c3..6c0d4df 100644 --- a/src/SemanticScuttle/header.php +++ b/src/SemanticScuttle/header.php @@ -18,9 +18,12 @@ 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')) { |