Completed
Push — master ( 266e07...eebe1f )
by Justin
14:53 queued 11:44
created

StyleController::getCurrentStyle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 19
rs 9.9332
cc 2
nc 2
nop 3
1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
class StyleController {
20
21
	/**
22
	 * get name of current style
23
	 *
24
	 * @param $registry Registry instance
25
	 *
26
	 * @return current style as string name
0 ignored issues
show
Bug introduced by
The type current was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
	 */
28
	public static function getCurrentStyle (Registry &$registry, Page &$page, PageType &$page_type) : string {
0 ignored issues
show
Unused Code introduced by
The parameter $page_type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
	public static function getCurrentStyle (Registry &$registry, Page &$page, /** @scrutinizer ignore-unused */ PageType &$page_type) : string {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $page is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
	public static function getCurrentStyle (Registry &$registry, /** @scrutinizer ignore-unused */ Page &$page, PageType &$page_type) : string {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
		//get default styles
30
		$default_style_name = Settings::get("default_style_name");
31
		$default_mobile_style_name = Settings::get("default_mobile_style_name");
32
33
		$style_name = !Browser::isMobile() ? $default_style_name : $default_mobile_style_name;
34
35
		//apply style rules
36
		$style_name = StyleRules::getStyle($registry, $style_name);
37
38
		//throw event, so plugins can change style
39
		Events::throwEvent("get_style", array(
40
			'default_style_name' => $default_style_name,
41
			'default_mobile_style_name' => $default_mobile_style_name,
42
			'style_name' => &$style_name,
43
			'registry' => $registry
44
		));
45
46
		return $style_name;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $style_name returns the type string which is incompatible with the documented return type current.
Loading history...
47
	}
48
49
	public static function showPage (Registry &$registry, Page &$page, PageType &$page_type) {
50
		//create new template
51
		$template = new DwooTemplate("index");
52
53
		$title_preafix = Settings::get("title_praefix", "");
54
		$title_suffix = Settings::get("title_suffix", "");
55
56
		//translate title
57
		$title = Translator::translateTitle($page->getTitle());
58
59
		//assign variables
60
		$template->assign("TITLE", $title_preafix . $title . $title_suffix);
61
		$template->assign("SHORT_TITLE", $title);
62
		$template->assign("RAW_TITLE", $page->getTitle());
63
		$template->assign("REGISTRY", $registry->listSettings());
64
65
		$head_content = "";
66
67
		Events::throwEvent("get_head", array(
68
			'registry' => &$registry,
69
			'page' => &$page,
70
			'page_type' => &$page_type,
71
			'head_content' => $head_content
72
		));
73
74
		$template->assign("HEAD", $head_content . $page_type->getAdditionalHeaderCode());
75
76
		$template->assign("CONTENT", $page_type->getContent());
77
		$template->assign("HEADER", $registry->getSetting("header", ""));
0 ignored issues
show
Unused Code introduced by
The call to Registry::getSetting() has too many arguments starting with ''. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
		$template->assign("HEADER", $registry->/** @scrutinizer ignore-call */ getSetting("header", ""));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
78
		$template->assign("FOOTER", $registry->getSetting("footer", ""));
79
		$template->assign("COPYRIGHT", Settings::get("copyright", "<strong>Copyright &copy; 2018 <a href=\"http://jukusoft.com\">JuKuSoft.com</a></strong>, All Rights Reserved."));
80
81
		$template->assign("FOOTER_SCRIPTS", $page_type->getFooterScripts());
82
83
		$template->assign("MY_GROUP_IDS", implode(",", $registry->getObject("groups")->listGroupIDs()));
84
		$template->assign("CHARSET", $page_type->getCharset());
85
86
		//create new css builder
87
		/*$css_builder = new CSSBuilder();
88
89
		//create new js builder
90
		$js_builder = new JSBuilder();
91
92
		$current_style = $registry->getSetting("current_style_name");
93
		$template->assign("CSS_HASH_ALL", $css_builder->getHash($current_style, "ALL", "header"));
94
		$template->assign("JS_HASH_ALL_HEADER", $js_builder->getHash($current_style, "ALL", "header"));
95
		$template->assign("JS_HASH_ALL_FOOTER", $js_builder->getHash($current_style, "ALL", "footer"));
96
97
		//set empty flags
98
		$template->assign("CSS_ALL_EMPTY", $css_builder->isEmpty($current_style, "ALL", "header"));
99
		$template->assign("JS_ALL_HEADER_EMPTY", $js_builder->isEmpty($current_style, "ALL", "header"));
100
		$template->assign("JS_ALL_FOOTER_EMPTY", $js_builder->isEmpty($current_style, "ALL", "footer"));*/
101
102
		//set sidebar arrays
103
		$left_sidebar = Registry::singleton()->getObject("left_sidebar");
104
		$right_sidebar = Registry::singleton()->getObject("right_sidebar");
105
		$sidebars_var = array(
106
			'left_sidebar' => $left_sidebar->listWidgetTplArray(),
107
			'right_sidebar' => $right_sidebar->listWidgetTplArray()
108
		);
109
		$template->assign("sidebars", $sidebars_var);
110
111
		//set version and build number
112
		if (PermissionChecker::current()->hasRight("can_see_cms_version")) {
113
			$template->assign("VERSION", Version::current()->getVersion());
114
			$template->assign("BUILD", Version::current()->getBuildNumber());
115
		} else {
116
			$template->assign("VERSION", "Unknown");
117
			$template->assign("BUILD", "Unknown");
118
		}
119
120
		//userid and username
121
		$user = User::current();
122
		/*$template->assign("USERID", $user->getID());
123
		$template->assign("USERNAME", $user->getUsername());*/
124
		$template->assign("IS_LOGGED_IN", $user->isLoggedIn());
125
126
		//assign menu code
127
		$globalMenu = $registry->getObject("main_menu");
128
		$localMenu = $registry->getObject("local_menu");
129
		$template->assign("MENU", $globalMenu->getCode());
130
		$template->assign("LOCALMENU", $localMenu->getCode());
131
132
		if (User::current()->isLoggedIn()) {
133
			$template->assign("is_logged_in", true);
134
			//$template->parse("main.logged_in");
135
		} else {
136
			$template->assign("is_logged_in", false);
137
			//$template->parse("main.not_logged_in");
138
		}
139
140
		//throw event
141
		Events::throwEvent("show_page", array(
142
			'registry' => &$registry,
143
			'page' => &$page,
144
			'page_type' => &$page_type,
145
			'template' => &$template
146
		));
147
148
		if ($page_type->showFooter()) {
149
			$template->assign("show_footer", true);
150
			//$template->parse("main.footer");
151
		} else {
152
			$template->assign("show_footer", false);
153
		}
154
155
		//$template->parse();
156
157
		echo $template->getCode();
158
	}
159
160
}
161
162
?>
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...
163