]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/theme.php
734284b27972393d869ba82ceaf446ddbd35e683
[quix0rs-gnu-social.git] / lib / theme.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Utilities for theme files and paths
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Paths
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2008 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/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * Gets the full path of a file in a theme dir based on its relative name
37  *
38  * @param string $relative relative path within the theme directory
39  * @param string $theme    name of the theme; defaults to current theme
40  *
41  * @return string File path to the theme file
42  */
43
44 function theme_file($relative, $theme=null)
45 {
46     if (empty($theme)) {
47         $theme = common_config('site', 'theme');
48     }
49     $dir = common_config('theme', 'dir');
50     if (empty($dir)) {
51         $dir = INSTALLDIR.'/theme';
52     }
53     return $dir.'/'.$theme.'/'.$relative;
54 }
55
56 /**
57  * Gets the full URL of a file in a theme dir based on its relative name
58  *
59  * @param string $relative relative path within the theme directory
60  * @param string $theme    name of the theme; defaults to current theme
61  *
62  * @return string URL of the file
63  */
64
65 function theme_path($relative, $theme=null)
66 {
67     if (empty($theme)) {
68         $theme = common_config('site', 'theme');
69     }
70
71     $path = common_config('theme', 'path');
72
73     if (empty($path)) {
74         $path = common_config('site', 'path') . '/theme/';
75     }
76
77     if ($path[strlen($path)-1] != '/') {
78         $path .= '/';
79     }
80
81     if ($path[0] != '/') {
82         $path = '/'.$path;
83     }
84
85     $server = common_config('theme', 'server');
86
87     if (empty($server)) {
88         $server = common_config('site', 'server');
89     }
90
91     // XXX: protocol
92
93     return 'http://'.$server.$path.$theme.'/'.$relative;
94 }