aboutsummaryrefslogtreecommitdiff
path: root/src/SemanticScuttle/Model/Theme.php
blob: 65861b872c03f2c965a6c75c7054c9cc51af59f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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;
    }
}
?>