Completed
Push — master ( ac8acd...d50551 )
by Justin
04:00
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
		//meta tags
87
		$meta = array(
88
			'description' => $page->getMetaDescription(),
89
			'keywords' => $page->getKeywords()
90
		);
91
92
		Events::throwEvent("meta_tags", array(
93
			'page' => &$page,
94
			'translated_title' => &$title,
95
			'registry' => &$registry,
96
			'template' => &$template,
97
			'meta' => &$meta
98
		));
99
100
		$template->assign("meta", $meta);
101
102
		//create new css builder
103
		/*$css_builder = new CSSBuilder();
104
105
		//create new js builder
106
		$js_builder = new JSBuilder();
107
108
		$current_style = $registry->getSetting("current_style_name");
109
		$template->assign("CSS_HASH_ALL", $css_builder->getHash($current_style, "ALL", "header"));
110
		$template->assign("JS_HASH_ALL_HEADER", $js_builder->getHash($current_style, "ALL", "header"));
111
		$template->assign("JS_HASH_ALL_FOOTER", $js_builder->getHash($current_style, "ALL", "footer"));
112
113
		//set empty flags
114
		$template->assign("CSS_ALL_EMPTY", $css_builder->isEmpty($current_style, "ALL", "header"));
115
		$template->assign("JS_ALL_HEADER_EMPTY", $js_builder->isEmpty($current_style, "ALL", "header"));
116
		$template->assign("JS_ALL_FOOTER_EMPTY", $js_builder->isEmpty($current_style, "ALL", "footer"));*/
117
118
		//set sidebar arrays
119
		$left_sidebar = Registry::singleton()->getObject("left_sidebar");
120
		$right_sidebar = Registry::singleton()->getObject("right_sidebar");
121
		$sidebars_var = array(
122
			'left_sidebar' => $left_sidebar->listWidgetTplArray(),
123
			'right_sidebar' => $right_sidebar->listWidgetTplArray()
124
		);
125
		$template->assign("sidebars", $sidebars_var);
126
127
		//set version and build number
128
		if (PermissionChecker::current()->hasRight("can_see_cms_version")) {
129
			$template->assign("VERSION", Version::current()->getVersion());
130
			$template->assign("BUILD", Version::current()->getBuildNumber());
131
		} else {
132
			$template->assign("VERSION", "Unknown");
133
			$template->assign("BUILD", "Unknown");
134
		}
135
136
		//userid and username
137
		$user = User::current();
138
		/*$template->assign("USERID", $user->getID());
139
		$template->assign("USERNAME", $user->getUsername());*/
140
		$template->assign("IS_LOGGED_IN", $user->isLoggedIn());
141
142
		//assign menu code
143
		$globalMenu = $registry->getObject("main_menu");
144
		$localMenu = $registry->getObject("local_menu");
145
		$template->assign("MENU", $globalMenu->getCode());
146
		$template->assign("LOCALMENU", $localMenu->getCode());
147
148
		if (User::current()->isLoggedIn()) {
149
			$template->assign("is_logged_in", true);
150
			//$template->parse("main.logged_in");
151
		} else {
152
			$template->assign("is_logged_in", false);
153
			//$template->parse("main.not_logged_in");
154
		}
155
156
		//throw event
157
		Events::throwEvent("show_page", array(
158
			'registry' => &$registry,
159
			'page' => &$page,
160
			'page_type' => &$page_type,
161
			'template' => &$template
162
		));
163
164
		if ($page_type->showFooter()) {
165
			$template->assign("show_footer", true);
166
			//$template->parse("main.footer");
167
		} else {
168
			$template->assign("show_footer", false);
169
		}
170
171
		//$template->parse();
172
173
		echo $template->getCode();
174
	}
175
176
}
177
178
?>
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...
179