themes.php ➔ get_theme_css_file()   B
last analyzed

Complexity

Conditions 5
Paths 7

Size

Total Lines 22
Code Lines 9

Duplication

Lines 7
Ratio 31.82 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 7
nop 1
dl 7
loc 22
rs 8.6737
c 0
b 0
f 0
1
<?php
2
3
//------------------------------------------------------------------------------
4
//
5
//  eTraxis - Records tracking web-based system
6
//  Copyright (C) 2010-2011  Artem Rodygin
7
//
8
//  This program is free software: you can redistribute it and/or modify
9
//  it under the terms of the GNU General Public License as published by
10
//  the Free Software Foundation, either version 3 of the License, or
11
//  (at your option) any later version.
12
//
13
//  This program 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 General Public License for more details.
17
//
18
//  You should have received a copy of the GNU General Public License
19
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//------------------------------------------------------------------------------
22
23
/**
24
 * Themes
25
 *
26
 * This module implements Themes support of eTraxis UI.
27
 *
28
 * @package Engine
29
 * @subpackage Themes
30
 * @author Mark Brockmann
31
 */
32
33
/**#@+
34
 * Dependency.
35
 */
36
require_once('../engine/resource.php');
37
require_once('../config.php');
38
require_once('../engine/debug.php');
39
require_once('../engine/utility.php');
40
require_once('../engine/sessions.php');
41
/**#@-*/
42
43
//------------------------------------------------------------------------------
44
//  Definitions.
45
//------------------------------------------------------------------------------
46
47
/**#@+
48
 * Data restriction.
49
 */
50
define('MAX_THEME_NAME', 50);
51
52
/**#@+
53
 * Name of basic theme.
54
 */
55
define('DEF_THEME_NAME', 'Emerald');
56
57
//------------------------------------------------------------------------------
58
//  Functions.
59
//------------------------------------------------------------------------------
60
61
/**
62
 * Returns array of available themes sorted alphabetically.
63
 *
64
 * @return array Array with available themes.
65
 */
66
function get_available_themes_sorted ()
67
{
68
    debug_write_log(DEBUG_TRACE, '[get_available_themes_sorted]');
69
70
    $available_themes = array();
71
72
    foreach (array_diff(scandir('../themes/'), array ('.', '..')) as $item)
73
    {
74
        if (is_dir("../themes/{$item}"))
75
        {
76
            debug_write_log(DEBUG_DUMP, '[get_available_themes_sorted] $item = ' . $item);
77
            $available_themes[] = $item;
78
        }
79
    }
80
81
    asort($available_themes);
82
83
    return $available_themes;
84
}
85
86
/**
87
 * Returns the file path for the given css file.
88
 *
89
 * @return string Path to css file.
90
 */
91
function get_theme_css_file ($cssfile)
92
{
93 View Code Duplication
    if (isset($_SESSION[VAR_THEME_NAME]))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        if (is_file(LOCALROOT . '/themes/' . ustr2html($_SESSION[VAR_THEME_NAME]) . '/css/' . $cssfile))
96
        {
97
            return LOCALROOT . '/themes/' . ustr2html($_SESSION[VAR_THEME_NAME]) . '/css/' . $cssfile;
98
        }
99
    }
100
101
    if (is_file(LOCALROOT . '/themes/' . ustr2html(THEME_DEFAULT) . '/css/' . $cssfile))
102
    {
103
        return LOCALROOT . '/themes/' . ustr2html(THEME_DEFAULT) . '/css/' . $cssfile;
104
    }
105
106
    if (is_file(LOCALROOT . '/themes/' . DEF_THEME_NAME . '/css/' . $cssfile))
107
    {
108
        return LOCALROOT . '/themes/' . DEF_THEME_NAME . '/css/' . $cssfile;
109
    }
110
111
    return NULL;
112
}
113
114
/**
115
 * Returns the file path for the given xsl file.
116
 *
117
 * @return string Path to xsl file.
118
 */
119
function get_theme_xsl_file ($xslfile)
120
{
121
    debug_write_log(DEBUG_TRACE, '[get_theme_xsl_file]');
122
123
    if (isset($_SESSION[VAR_THEME_NAME]))
124
    {
125
        debug_write_log(DEBUG_DUMP,  '[get_theme_xsl_file] $_SESSION[VAR_THEME_NAME] = ' . $_SESSION[VAR_THEME_NAME]);
126
127 View Code Duplication
        if (is_file(LOCALROOT . '/themes/' . ustr2html($_SESSION[VAR_THEME_NAME]) . '/' . $xslfile))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
        {
129
            return LOCALROOT . '/themes/' . ustr2html($_SESSION[VAR_THEME_NAME]) . '/' . $xslfile;
130
        }
131
    }
132
133
    if (is_file(LOCALROOT . '/themes/' . ustr2html(THEME_DEFAULT) . '/' . $xslfile))
134
    {
135
        return LOCALROOT . '/themes/' . ustr2html(THEME_DEFAULT) . '/' . $xslfile;
136
    }
137
138
    if (is_file(LOCALROOT . '/themes/' . DEF_THEME_NAME . '/' . $xslfile))
139
    {
140
        return LOCALROOT . '/themes/' . DEF_THEME_NAME . '/' . $xslfile;
141
    }
142
143
    debug_write_log(DEBUG_WARNING, '[get_theme_xsl_file] Valid filepath for xsl file "' . $xslfile . '" is not found.');
144
145
    return LOCALROOT . '/engine/' . $xslfile;
146
}
147
148
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
149