Webpage::run()   B
last analyzed

Complexity

Conditions 9
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 16
nc 1
nop 0
dl 0
loc 21
rs 7.041
c 0
b 0
f 0
1
<?php
2
/**
3
 * start page for webaccess
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Web
9
 * @author    Michael Cramer <[email protected]>
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
12
 * @version   SVN: $Id: class.Webpage.inc.php 661 2012-08-27 11:26:39Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * generate the dynamic webpage
17
 *
18
 * @category  PHP
19
 * @package   PSI_Web
20
 * @author    Michael Cramer <[email protected]>
21
 * @copyright 2009 phpSysInfo
22
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
23
 * @version   Release: 3.0
24
 * @link      http://phpsysinfo.sourceforge.net
25
 */
26
class Webpage extends Output implements PSI_Interface_Output
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
27
{
28
    /**
29
     * configured indexname
30
     *
31
     * @var String
32
     */
33
    private $_indexname;
34
35
    /**
36
     * configured language
37
     *
38
     * @var String
39
     */
40
    private $_language;
41
42
    /**
43
     * configured template
44
     *
45
     * @var String
46
     */
47
    private $_template;
48
49
    /**
50
     * all available templates
51
     *
52
     * @var Array
53
     */
54
    private $_templates = array();
55
56
    /**
57
     * configured bootstrap template
58
     *
59
     * @var String
60
     */
61
    private $_bootstrap_template;
62
63
    /**
64
     * all available bootstrap templates
65
     *
66
     * @var Array
67
     */
68
    private $_bootstrap_templates = array();
69
70
    /**
71
     * all available languages
72
     *
73
     * @var Array
74
     */
75
    private $_languages = array();
76
77
    /**
78
     * configured show picklist language
79
     *
80
     * @var boolean
81
     */
82
    private $_pick_language;
83
84
    /**
85
     * configured show picklist template
86
     *
87
     * @var boolean
88
     */
89
    private $_pick_template;
90
91
    /**
92
     * check for all extensions that are needed, initialize needed vars and read phpsysinfo.ini
93
     */
94
    public function __construct($indexname="dynamic")
95
    {
96
        $this->_indexname = $indexname;
97
        parent::__construct();
98
        $this->_getTemplateList();
99
        $this->_getLanguageList();
100
    }
101
102
    /**
103
     * checking phpsysinfo.ini setting for template, if not supportet set phpsysinfo.css as default
104
     * checking phpsysinfo.ini setting for language, if not supported set en as default
105
     *
106
     * @return void
107
     */
108
    private function _checkTemplateLanguage()
109
    {
110 View Code Duplication
        if (!defined("PSI_DEFAULT_TEMPLATE") || (($this->_template = strtolower(trim(PSI_DEFAULT_TEMPLATE))) == "") || !file_exists(APP_ROOT.'/templates/'.$this->_template.".css")) {
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...
111
            $this->_template = 'phpsysinfo';
112
        }
113 View Code Duplication
        if (!defined("PSI_DEFAULT_BOOTSTRAP_TEMPLATE") || (($this->_bootstrap_template = strtolower(trim(PSI_DEFAULT_BOOTSTRAP_TEMPLATE))) == "") || !file_exists(APP_ROOT.'/templates/'.$this->_bootstrap_template.".css")) {
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...
114
            $this->_bootstrap_template = 'phpsysinfo';
115
        }
116
        $this->_pick_template = !defined("PSI_SHOW_PICKLIST_TEMPLATE") || (PSI_SHOW_PICKLIST_TEMPLATE !== false);
117
118 View Code Duplication
        if (!defined("PSI_DEFAULT_LANG") || (($this->_language = strtolower(trim(PSI_DEFAULT_LANG))) == "") || !file_exists(APP_ROOT.'/language/'.$this->_language.".xml")) {
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...
119
            $this->_language = 'en';
120
        }
121
        $this->_pick_language = !defined("PSI_SHOW_PICKLIST_LANG") || (PSI_SHOW_PICKLIST_LANG !== false);
122
    }
123
124
    /**
125
     * get all available tamplates and store them in internal array
126
     *
127
     * @return void
128
     */
129
    private function _getTemplateList()
130
    {
131
        $dirlist = CommonFunctions::gdc(APP_ROOT.'/templates/');
132
        sort($dirlist);
133
        foreach ($dirlist as $file) {
134
            $tpl_ext = substr($file, strlen($file) - 4);
135
            $tpl_name = substr($file, 0, strlen($file) - 4);
136
            if ($tpl_ext === ".css") {
137
                if (preg_match("/(\S+)_bootstrap$/", $tpl_name, $ar_buf)) {
138
                    array_push($this->_bootstrap_templates, $ar_buf[1]);
139
                } else {
140
                    array_push($this->_templates, $tpl_name);
141
                }
142
            }
143
        }
144
    }
145
146
    /**
147
     * get all available translations and store them in internal array
148
     *
149
     * @return void
150
     */
151
    private function _getLanguageList()
152
    {
153
        $dirlist = CommonFunctions::gdc(APP_ROOT.'/language/');
154
        sort($dirlist);
155
        foreach ($dirlist as $file) {
156
            $lang_ext = substr($file, strlen($file) - 4);
157
            $lang_name = substr($file, 0, strlen($file) - 4);
158
            if ($lang_ext == ".xml") {
159
                array_push($this->_languages, $lang_name);
160
            }
161
        }
162
    }
163
164
    /**
165
     * render the page
166
     *
167
     * @return void
168
     */
169
    public function run()
170
    {
171
        $this->_checkTemplateLanguage();
172
173
        $tpl = new Template("/templates/html/index_".$this->_indexname.".html");
174
175
        $tpl->set("template", $this->_template);
176
        $tpl->set("templates", $this->_templates);
177
        $tpl->set("bootstraptemplate", $this->_bootstrap_template);
178
        $tpl->set("bootstraptemplates", $this->_bootstrap_templates);
179
        $tpl->set("picktemplate", $this->_pick_template);
180
        $tpl->set("language", $this->_language);
181
        $tpl->set("languages", $this->_languages);
182
        $tpl->set("picklanguage", $this->_pick_language);
183
        $tpl->set("showCPUListExpanded", defined('PSI_SHOW_CPULIST_EXPANDED') ? (PSI_SHOW_CPULIST_EXPANDED ? 'true' : 'false') : 'true');
184
        $tpl->set("showCPUInfoExpanded", defined('PSI_SHOW_CPUINFO_EXPANDED') ? (PSI_SHOW_CPUINFO_EXPANDED ? 'true' : 'false') : 'false');
185
        $tpl->set("showNetworkInfosExpanded", defined('PSI_SHOW_NETWORK_INFOS_EXPANDED') ? (PSI_SHOW_NETWORK_INFOS_EXPANDED ? 'true' : 'false') : 'false');
186
        $tpl->set("showMemoryInfosExpanded", defined('PSI_SHOW_MEMORY_INFOS_EXPANDED') ? (PSI_SHOW_MEMORY_INFOS_EXPANDED ? 'true' : 'false') : 'false');
187
188
        echo $tpl->fetch();
189
    }
190
}
191