Completed
Push — master ( 28d609...3df7e0 )
by Justin
03:16
created

HTMLWidget::useTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 2
rs 10
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
20
/**
21
 * Project: JuKuCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 23.08.2018
25
 * Time: 23:37
26
 */
27
28
class HTMLWidget extends Widget {
29
30
	/**
31
	 * get html code which is shown on website
32
	 */
33
	public function getCode() {
34
		return $this->getContent();
35
	}
36
37
	/**
38
	 * get formular html code which is shown in admin area if user edits the widget
39
	 */
40
	public function getAdminForm() {
41
		// TODO: Implement getAdminForm() method.
42
	}
43
44
	/**
45
	 * save widget data when new settings are saved in the admin area
46
	 */
47
	public function save() {
48
		// TODO: Implement save() method.
49
	}
50
51
	public function useTemplate() {
52
		return false;
53
	}
54
55
	public static function create (int $sidebar_id, string $title, string $content, string $unique_name = "") {
56
		if (empty($unique_name)) {
57
			$unique_name = md5($title . "_" . $sidebar_id . "_" . time());
58
		}
59
60
		Database::getInstance()->execute("INSERT INTO `{praefix}sidebar_widgets` (
61
			`id`, `sidebar_id`, `title`, `content`, `class_name`, `widget_params`, `css_id`, `css_class`, `before_widget`, `after_widget`, `unique_name`, `order`
62
		) VALUES (
63
			NULL, :sidebar_id, :title, :content, 'HTMLWidget', '', :widget_params, '', '', '', '', :unique_name, 10
64
		) ON DUPLICATE KEY UPDATE `title` = :title, `content` = :content, `class_name` = 'HTMLWidget', `widget_params` = :widget_params, `unique_name` = :unique_name; ", array(
65
			'sidebar_id' => $sidebar_id,
66
			'title' => $title,
67
			'content' => $content,
68
			'widget_params' => serialize(array()),
69
			'unique_name' => $unique_name
70
		));
71
72
		Cache::clear("sidebars");
73
	}
74
75
}
76
77
?>
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...
78