3 * StatusNet, the distributed open-source microblogging tool
5 * Utilities for theme files and paths
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
36 * Class for querying and manipulating a theme
38 * Themes are directories with some expected sub-directories and files
39 * in them. They're found in either local/theme (for locally-installed themes)
40 * or theme/ subdir of installation dir.
42 * This used to be a couple of functions, but for various reasons it's nice
43 * to have a class instead.
47 * @author Evan Prodromou <evan@status.net>
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49 * @link http://status.net/
60 * Determines the proper directory and path for this theme.
62 * @param string $name Name of the theme; defaults to config value
65 function __construct($name=null)
68 $name = common_config('site', 'theme');
71 // Check to see if it's in the local dir
73 $localroot = Theme::localRoot();
75 $fulldir = $localroot.'/'.$name;
77 if (file_exists($fulldir) && is_dir($fulldir)) {
78 $this->dir = $fulldir;
79 $this->path = common_path('local/theme/'.$name.'/');
83 // Check to see if it's in the distribution dir
85 $instroot = Theme::installRoot();
87 $fulldir = $instroot.'/'.$name;
89 if (file_exists($fulldir) && is_dir($fulldir)) {
91 $this->dir = $fulldir;
93 $path = common_config('theme', 'path');
96 $path = common_config('site', 'path') . '/theme/';
99 if ($path[strlen($path)-1] != '/') {
103 if ($path[0] != '/') {
107 $server = common_config('theme', 'server');
109 if (empty($server)) {
110 $server = common_config('site', 'server');
115 $this->path = 'http://'.$server.$path.$name;
120 * Gets the full local filename of a file in this theme.
122 * @param string $relative relative name, like 'logo.png'
124 * @return string full pathname, like /var/www/mublog/theme/default/logo.png
127 function getFile($relative)
129 return $this->dir.'/'.$relative;
133 * Gets the full HTTP url of a file in this theme
135 * @param string $relative relative name, like 'logo.png'
137 * @return string full URL, like 'http://example.com/theme/default/logo.png'
140 function getPath($relative)
142 return $this->path.'/'.$relative;
146 * Gets the full path of a file in a theme dir based on its relative name
148 * @param string $relative relative path within the theme directory
149 * @param string $name name of the theme; defaults to current theme
151 * @return string File path to the theme file
154 static function file($relative, $name=null)
156 $theme = new Theme($name);
157 return $theme->getFile($relative);
161 * Gets the full URL of a file in a theme dir based on its relative name
163 * @param string $relative relative path within the theme directory
164 * @param string $name name of the theme; defaults to current theme
166 * @return string URL of the file
169 static function path($relative, $name=null)
171 $theme = new Theme($name);
172 return $theme->getPath($relative);
176 * Local root dir for themes
178 * @return string local root dir for themes
181 protected static function localRoot()
183 return INSTALLDIR.'/local/theme';
187 * Root dir for themes that are shipped with StatusNet
189 * @return string root dir for StatusNet themes
192 protected static function installRoot()
194 $instroot = common_config('theme', 'dir');
196 if (empty($instroot)) {
197 $instroot = INSTALLDIR.'/theme';