~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Helper/Theme.php

  • Committer: Dan Garner
  • Date: 2016-02-15 17:54:45 UTC
  • mto: (454.4.130)
  • mto: This revision was merged to the branch mainline in revision 484.
  • Revision ID: git-v1:dd226a6f84464ff28758a249e1fd52ca4a35d911
Correction to Layout Duration ToolTip
xibosignage/xibo#721

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * Xibo - Digital Signage - http://www.xibo.org.uk
 
4
 * Copyright (C) 2006-2013 Daniel Garner
 
5
 *
 
6
 * This file is part of Xibo.
 
7
 *
 
8
 * Xibo is free software: you can redistribute it and/or modify
 
9
 * it under the terms of the GNU Affero General Public License as published by
 
10
 * the Free Software Foundation, either version 3 of the License, or
 
11
 * any later version. 
 
12
 *
 
13
 * Xibo is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU Affero General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Affero General Public License
 
19
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
namespace Xibo\Helper;
 
22
use Exception;
 
23
use Slim\Slim;
 
24
use Xibo\Entity\Menu;
 
25
use Xibo\Exception\ConfigurationException;
 
26
use Xibo\Factory\MenuFactory;
 
27
 
 
28
 
 
29
class Theme
 
30
{
 
31
    private static $instance = null;
 
32
 
 
33
    private $name = '';
 
34
    private $config = null;
 
35
 
 
36
    public function __construct($theme = NULL)
 
37
    {
 
38
        // What is the currently selected theme?
 
39
        $globalTheme = ($theme == NULL) ? Config::GetSetting('GLOBAL_THEME_NAME', 'default') : $theme;
 
40
 
 
41
        // Is this theme valid?
 
42
        if (!is_dir(PROJECT_ROOT . '/web/theme/' . $globalTheme))
 
43
            throw new ConfigurationException(__('The theme "%s" does not exist', $globalTheme));
 
44
 
 
45
        // Store the theme name for later
 
46
        $this->name = $globalTheme;
 
47
 
 
48
        // Get config
 
49
        if (!file_exists(PROJECT_ROOT . '/web/theme/' . $this->name . '/config.php'))
 
50
            throw new Exception(__('The theme "%s" config file does not exist', $globalTheme));
 
51
 
 
52
        require(PROJECT_ROOT . '/web/theme/' . $this->name . '/config.php');
 
53
        $this->config = $config;
 
54
        $this->config['themeCode'] = $this->name;
 
55
 
 
56
        self::$instance = $this;
 
57
    }
 
58
 
 
59
    /**
 
60
     * GetInstance of Theme
 
61
     */
 
62
    public static function getInstance()
 
63
    {
 
64
        if (!isset(self::$instance))
 
65
            self::$instance = new Theme();
 
66
 
 
67
        return self::$instance;
 
68
    }
 
69
 
 
70
    /**
 
71
     * Get Theme Specific Settings
 
72
     * @param null $settingName
 
73
     * @param null $default
 
74
     * @return null
 
75
     */
 
76
    public static function getConfig($settingName = null, $default = null)
 
77
    {
 
78
        $theme = Theme::getInstance();
 
79
 
 
80
        if ($settingName == null)
 
81
            return $theme->config;
 
82
 
 
83
        if (isset($theme->config[$settingName]))
 
84
            return $theme->config[$settingName];
 
85
        else
 
86
            return $default;
 
87
    }
 
88
 
 
89
    /**
 
90
     * Get theme URI
 
91
     * @param string $uri
 
92
     * @param bool $local
 
93
     * @return string
 
94
     */
 
95
    public static function uri($uri, $local = false)
 
96
    {
 
97
        $rootUri = ($local) ? '' : Slim::getInstance()->rootUri;
 
98
 
 
99
        // Serve the appropriate theme file
 
100
        if (is_dir(PROJECT_ROOT . '/web/theme/' . self::getInstance()->name . '/' . $uri)) {
 
101
            return $rootUri . 'theme/' . self::getInstance()->name . '/' . $uri;
 
102
        }
 
103
        else if (file_exists(PROJECT_ROOT . '/web/theme/' . self::getInstance()->name . '/' . $uri)) {
 
104
            return $rootUri . 'theme/' . self::getInstance()->name . '/' . $uri;
 
105
        }
 
106
        else {
 
107
            return $rootUri . 'theme/default/' . $uri;
 
108
        }
 
109
    }
 
110
 
 
111
    public static function rootUri()
 
112
    {
 
113
        return Slim::getInstance()->rootUri;
 
114
    }
 
115
}