Completed
Push — release-2.1 ( 9e09c0...33a060 )
by Mert
07:16
created

Printpage.template.php ➔ template_print_options()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 11
c 1
b 1
f 0
nc 2
nop 0
dl 0
loc 18
rs 9.4285
1
<?php
2
/**
3
 * Simple Machines Forum (SMF)
4
 *
5
 * @package SMF
6
 * @author Simple Machines http://www.simplemachines.org
7
 * @copyright 2016 Simple Machines and individual contributors
8
 * @license http://www.simplemachines.org/about/smf/license.php BSD
9
 *
10
 * @version 2.1 Beta 3
11
 */
12
13
/**
14
 * The header. Defines the look and layout of the page as well as a form for choosing print options.
15
 */
16
function template_print_above()
17
{
18
	global $context, $txt, $topic, $scripturl;
19
20
	echo '<!DOCTYPE html>
21
<html', $context['right_to_left'] ? ' dir="rtl"' : '', '>
22
	<head>
23
		<meta charset="', $context['character_set'], '">
24
		<meta name="robots" content="noindex">
25
		<link rel="canonical" href="', $context['canonical_url'], '">
26
		<title>', $txt['print_page'], ' - ', $context['topic_subject'], '</title>
27
		<style>
28
			body, a {
29
				color: #000;
30
				background: #fff;
31
			}
32
			body, td, .normaltext {
33
				font-family: Verdana, arial, helvetica, serif;
34
				font-size: small;
35
			}
36
			h1#title {
37
				font-size: large;
38
				font-weight: bold;
39
			}
40
			h2#linktree {
41
				margin: 1em 0 2.5em 0;
42
				font-size: small;
43
				font-weight: bold;
44
			}
45
			dl#posts {
46
				width: 90%;
47
				margin: 0;
48
				padding: 0;
49
				list-style: none;
50
			}
51
			div.postheader, #poll_data {
52
				border: solid #000;
53
				border-width: 1px 0;
54
				padding: 4px 0;
55
			}
56
			div.postbody {
57
				margin: 1em 0 2em 2em;
58
			}
59
			table {
60
				empty-cells: show;
61
			}
62
			blockquote {
63
				margin: 0 0 8px 0;
64
				padding: 6px 10px;
65
				font-size: small;
66
				border: 1px solid #d6dfe2;
67
				border-left: 2px solid #aaa;
68
				border-right: 2px solid #aaa;
69
			}
70
			blockquote cite {
71
				display: block;
72
				border-bottom: 1px solid #aaa;
73
				font-size: 0.9em;
74
			}
75
			blockquote cite:before {
76
				color: #aaa;
77
				font-size: 22px;
78
				font-style: normal;
79
				margin-right: 5px;
80
			}
81
			code {
82
				border: 1px solid #000;
83
				margin: 3px;
84
				padding: 1px;
85
				display: block;
86
			}
87
			code {
88
				font: x-small monospace;
89
			}
90
			.smalltext, .codeheader {
91
				font-size: x-small;
92
			}
93
			.largetext {
94
				font-size: large;
95
			}
96
			.centertext {
97
				text-align: center;
98
			}
99
			hr {
100
				height: 1px;
101
				border: 0;
102
				color: black;
103
				background-color: black;
104
			}
105
			.voted {
106
				font-weight: bold;
107
			}
108
			#footer {
109
				font-family: Verdana, sans-serif;
110
			}
111
			@media print {
112
				.print_options {
113
					display: none;
114
				}
115
			}
116
			@media screen {
117
				.print_options {
118
					margin: 1em 0;
119
				}
120
			}
121
		</style>
122
	</head>
123
	<body>';
124
125
	template_print_options();
126
127
	echo '
128
		</div>
129
		<h1 id="title">', $context['forum_name_html_safe'], '</h1>
130
		<h2 id="linktree">', $context['category_name'], ' => ', (!empty($context['parent_boards']) ? implode(' => ', $context['parent_boards']) . ' => ' : ''), $context['board_name'], ' => ', $txt['topic_started'], ': ', $context['poster_name'], ' ', $txt['search_on'], ' ', $context['post_time'], '</h2>
131
		<div id="posts">';
132
}
133
134
/**
135
 * The main page. This shows the relevent info in a printer-friendly format
136
 */
137
function template_main()
0 ignored issues
show
Best Practice introduced by
The function template_main() has been defined more than once; this definition is ignored, only the first definition in Themes/default/BoardIndex.template.php (L56-176) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
138
{
139
	global $context, $options, $txt, $scripturl, $topic;
140
141
	if (!empty($context['poll']))
142
	{
143
		echo '
144
			<div id="poll_data">', $txt['poll'], '
145
				<div class="question">', $txt['poll_question'], ': <strong>', $context['poll']['question'], '</strong>';
146
147
		$options = 1;
148
		foreach ($context['poll']['options'] as $option)
149
			echo '
150
					<div class="', $option['voted_this'] ? 'voted' : '', '">', $txt['option'], ' ', $options++, ': <strong>', $option['option'], '</strong>
151
						', $context['allow_poll_view'] ? $txt['votes'] . ': ' . $option['votes'] . '' : '', '
152
					</div>';
153
154
		echo '
155
			</div>';
156
	}
157
158
	foreach ($context['posts'] as $post)
159
	{
160
		echo '
161
			<div class="postheader">
162
				', $txt['title'], ': <strong>', $post['subject'], '</strong><br>
163
				', $txt['post_by'], ': <strong>', $post['member'], '</strong> ', $txt['search_on'], ' <strong>', $post['time'], '</strong>
164
			</div>
165
			<div class="postbody">
166
				', $post['body'];
167
168
		// Show attachment images
169
		if (isset($_GET['images']) && !empty($context['printattach'][$post['id_msg']]))
170
		{
171
			echo '
172
				<hr>';
173
174
			foreach ($context['printattach'][$post['id_msg']] as $attach)
175
				echo '
176
					<img width="' . $attach['width'] . '" height="' . $attach['height'] . '" src="', $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attach['id_attach'] . '" alt="">';
177
		}
178
179
		echo '
180
			</div>';
181
	}
182
}
183
184
/**
185
 * The footer.
186
 */
187
function template_print_below()
188
{
189
	global $topic, $txt, $scripturl;
190
191
	$url_text = $scripturl . '?action=printpage;topic=' . $topic . '.0';
192
	$url_images = $url_text . ';images';
0 ignored issues
show
Unused Code introduced by
$url_images is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
193
194
	echo '</div>
195
		</div>';
196
197
	template_print_options();
198
199
	echo '
200
		<div id="footer" class="smalltext">', theme_copyright(), '</div>
201
	</body>
202
</html>';
203
}
204
205
function template_print_options()
206
{
207
	global $scripturl, $topic, $txt;
208
209
	$url_text = $scripturl . '?action=printpage;topic=' . $topic . '.0';
210
	$url_images = $url_text . ';images';
211
212
	echo '
213
		<div class="print_options">';
214
215
	// which option is set, text or text&images
216
	if (isset($_REQUEST['images']))
217
		echo '
218
			<a href="', $url_text, '">', $txt['print_page_text'], '</a> | <strong><a href="', $url_images, '">', $txt['print_page_images'], '</a></strong>';
219
	else
220
		echo '
221
			<strong><a href="', $url_text, '">', $txt['print_page_text'], '</a></strong> | <a href="', $url_images, '">', $txt['print_page_images'], '</a>';
222
}
223
?>
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...