Passed
Push — master ( 358905...02a0dd )
by Justin
25:34 queued 21:45
created

SendMailPage::getAdditionalHeaderCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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: 24.04.2018
25
 * Time: 21:25
26
 */
27
28
class SendMailPage extends PageType {
29
30
	public function getAdditionalHeaderCode(): string {
31
		$base_url = DomainUtils::getBaseURL() . "/";
32
33
		return "<!-- iCheck -->
34
  				<link rel=\"stylesheet\" href=\"" . $base_url . "styles/admin/plugins/iCheck/flat/blue.css\">
35
		
36
				<!-- bootstrap wysihtml5 - text editor -->
37
  				<link rel=\"stylesheet\" href=\"" . $base_url . "styles/admin/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css\">";
38
	}
39
40
	public function getFooterScripts(): string {
41
		$base_url = DomainUtils::getBaseURL() . "/";
42
43
		return "<!-- iCheck -->
44
				<script src=\"" . $base_url . "styles/admin/plugins/iCheck/icheck.min.js\"></script>
45
				<!-- Bootstrap WYSIHTML5 -->
46
				<script src=\"" . $base_url . "styles/admin/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js\"></script>
47
				<!-- Page Script -->
48
				<script>
49
				  $(function () {
50
					//Add text editor
51
					$(\"#compose-textarea\").wysihtml5({
52
						\"font-styles\": true, /*Font styling, e.g. h1, h2, etc. Default true*/
53
						\"emphasis\": true, /*Italics, bold, etc. Default true*/
54
						\"lists\": true, /*(Un)ordered lists, e.g. Bullets, Numbers. Default true*/
55
						\"html\": true, /*Button which allows you to edit the generated HTML. Default false*/
56
						\"link\": true, /*Button to insert a link. Default true*/
57
						\"image\": false, /*Button to insert an image. Default true,*/
58
						\"color\": true /*Button to change color of font*/
59
					});
60
				  });
61
				</script>";
62
	}
63
64
	public function getContent(): string {
65
		$template = new DwooTemplate("pages/sendmail");
66
67
		$template->assign("form_action", DomainUtils::generateURL("admin/sendmail"));
68
		$template->assign("content", "");
69
70
		if (isset($_REQUEST['submit'])) {
71
			//first, check csrf token
72
			if (!Security::checkCSRFToken()) {
73
				$template->assign("error_message", "Wrong CSRF token!");
74
75
				if (isset($_POST['content'])) {
76
					$template->assign("content", $_POST['content']);
77
				}
78
			} else {
79
				$required_fields = array("to_mail", "subject", "content");
80
81
				foreach ($required_fields as $field) {
82
					if (!isset($_POST[$field]) || empty($_POST[$field])) {
83
						$template->assign("error_message", "Please complete form!");
84
85
						if (isset($_POST['content'])) {
86
							$template->assign("content", $_POST['content']);
87
						}
88
89
						return $template->getCode();
90
					}
91
				}
92
93
				//form is complete
94
95
				//get values
96
				$to_mail = $_POST['to_mail'];
97
				$subject = $_POST['subject'];
98
				$content = $_POST['content'];
99
100
				//check, if mail is valide
101
				if (!(new Validator_Mail())->isValide($to_mail)) {
102
					$template->assign("error_message", "Mail is not valide!");
103
104
					if (isset($_POST['content'])) {
105
						$template->assign("content", $_POST['content']);
106
					}
107
				} else if (!(new Validator_String())->isValide($subject)) {
108
					$template->assign("error_message", "Subject is not valide!");
109
110
					if (isset($_POST['content'])) {
111
						$template->assign("content", $_POST['content']);
112
					}
113
				} else {
114
					//parameters are valide, send mail
115
116
					if (MailApi::sendHTMLMail($to_mail, $subject, $content)) {
117
						$template->assign("success_message", "Mail sended successfully!");
118
					} else {
119
						$template->assign("error_message", "Sending of mail failed!");
120
121
						if (isset($_POST['content'])) {
122
							$template->assign("content", $_POST['content']);
123
						}
124
					}
125
				}
126
			}
127
		}
128
129
		return $template->getCode();
130
	}
131
132
	public function listRequiredPermissions(): array {
133
		return array("can_send_board_mails");
134
	}
135
136
}
137
138
?>
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...
139