Pārlūkot izejas kodu

! Allow for images and attachment images to be printed with Printpage.php
! minor cleanup of Printpage.template.php

Signed-off-by: Spuds

Spuds 12 gadi atpakaļ
vecāks
revīzija
e56717ee17

+ 62 - 1
Sources/Printpage.php

@@ -239,7 +239,7 @@ function PrintTopic()
 
 	// Split the topics up so we can print them.
 	$request = $smcFunc['db_query']('', '
-		SELECT subject, poster_time, body, IFNULL(mem.real_name, poster_name) AS poster_name
+		SELECT subject, poster_time, body, IFNULL(mem.real_name, poster_name) AS poster_name, id_msg
 		FROM {db_prefix}messages AS m
 			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
 		WHERE m.id_topic = {int:current_topic}' . ($modSettings['postmod_active'] && !allowedTo('approve_posts') ? '
@@ -264,6 +264,7 @@ function PrintTopic()
 			'time' => timeformat($row['poster_time'], false),
 			'timestamp' => forum_time(true, $row['poster_time']),
 			'body' => parse_bbc($row['body'], 'print'),
+			'id_msg' => $row['id_msg'],
 		);
 
 		if (!isset($context['topic_subject']))
@@ -271,6 +272,66 @@ function PrintTopic()
 	}
 	$smcFunc['db_free_result']($request);
 
+	// Fetch attachments so we can print them if asked, enabled and allowed
+	if (isset($_REQUEST['images']) && !empty($modSettings['attachmentEnable']) && allowedTo('view_attachments'))
+	{
+		$messages = array();
+		foreach($context['posts'] as $temp)
+			$messages[] = $temp['id_msg'];
+		
+		// build the request
+		$request = $smcFunc['db_query']('', '
+			SELECT
+				a.id_attach, a.id_msg, a.approved, a.width, a.height, a.file_hash, a.filename, a.id_folder, a.mime_type
+			FROM {db_prefix}attachments AS a
+			WHERE a.id_msg IN ({array_int:message_list})
+				AND a.attachment_type = {int:attachment_type}',
+			array(
+				'message_list' => $messages,
+				'attachment_type' => 0,
+				'is_approved' => 1,
+			)
+		);
+		$temp = array();
+		while ($row = $smcFunc['db_fetch_assoc']($request))
+		{
+			$temp[$row['id_attach']] = $row;
+			if (!isset($context['printattach'][$row['id_msg']]))
+				$context['printattach'][$row['id_msg']] = array();
+		}
+		$smcFunc['db_free_result']($request);
+		ksort($temp);
+
+		// load them into $context so the template can use them
+		foreach ($temp as $row)
+		{
+			if (!empty($row['width']) && !empty($row['height'])) 
+			{
+				if (!empty($modSettings['max_image_width']) && (empty($modSettings['max_image_height']) || $row['height'] * ($modSettings['max_image_width'] / $row['width']) <= $modSettings['max_image_height']))
+				{
+					if ($row['width'] > $modSettings['max_image_width']) 
+					{
+						$row['height'] = floor($row['height'] * ($modSettings['max_image_width'] / $row['width']));
+						$row['width'] = $modSettings['max_image_width'];
+					}
+				}
+				elseif (!empty($modSettings['max_image_width']))
+				{
+					if ($row['height'] > $modSettings['max_image_height']) 
+					{
+						$row['width'] = floor($row['width'] * $modSettings['max_image_height'] / $row['height']);
+						$row['height'] = $modSettings['max_image_height'];
+					}
+				}
+				
+				$row['filename'] = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']);
+
+				// save for the template
+				$context['printattach'][$row['id_msg']][] = $row;
+			}
+		}
+	}
+	
 	// Set a canonical URL for this page.
 	$context['canonical_url'] = $scripturl . '?topic=' . $topic . '.0';
 }

+ 75 - 36
Themes/default/Printpage.template.php

@@ -12,7 +12,10 @@
 
 function template_print_above()
 {
-	global $context, $settings, $options, $txt;
+	global $context, $txt, $topic, $scripturl;
+	
+	$url_text = $scripturl . '?action=printpage;topic=' . $topic . '.0';
+	$url_images = $url_text . ';images';
 
 	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
@@ -22,89 +25,95 @@ function template_print_above()
 		<link rel="canonical" href="', $context['canonical_url'], '" />
 		<title>', $txt['print_page'], ' - ', $context['topic_subject'], '</title>
 		<style type="text/css">
-			body, a
-			{
+			body, a {
 				color: #000;
 				background: #fff;
 			}
-			body, td, .normaltext
-			{
+			body, td, .normaltext {
 				font-family: Verdana, arial, helvetica, serif;
 				font-size: small;
 			}
-			h1#title
-			{
+			h1#title {
 				font-size: large;
 				font-weight: bold;
 			}
-			h2#linktree
-			{
+			h2#linktree {
 				margin: 1em 0 2.5em 0;
 				font-size: small;
 				font-weight: bold;
 			}
-			dl#posts
-			{
+			dl#posts {
 				width: 90%;
 				margin: 0;
 				padding: 0;
 				list-style: none;
 			}
-			div.postheader, #poll_data
-			{
+			div.postheader, #poll_data {
 				border: solid #000;
 				border-width: 1px 0;
 				padding: 4px 0;
 			}
-			div.postbody
-			{
+			div.postbody {
 				margin: 1em 0 2em 2em;
 			}
-			table
-			{
+			table {
 				empty-cells: show;
 			}
-			blockquote, code
-			{
+			blockquote, code {
 				border: 1px solid #000;
 				margin: 3px;
 				padding: 1px;
 				display: block;
 			}
-			code
-			{
+			code {
 				font: x-small monospace;
 			}
-			blockquote
-			{
+			blockquote {
 				font-size: x-small;
 			}
-			.smalltext, .quoteheader, .codeheader
-			{
+			.smalltext, .quoteheader, .codeheader {
 				font-size: x-small;
 			}
-			.largetext
-			{
+			.largetext {
 				font-size: large;
 			}
-			.centertext
-			{
+			.centertext {
 				text-align: center;
 			}
-			hr
-			{
+			hr {
 				height: 1px;
 				border: 0;
 				color: black;
 				background-color: black;
 			}
-			.voted
-			{
+			.voted {
 				font-weight: bold;
 			}
+			@media print {
+				.print_options {
+					display:none;
+				}
+			}
+			@media screen {
+				.print_options {
+					margin:1em;
+				}
+			}
 		</style>
 	</head>
 	<body>
+		<div class="print_options">';
+
+	// which option is set, text or text&images
+	if (isset($_REQUEST['images']))
+		echo '
+			<a href="', $url_text, '">', $txt['print_page_text'], '</a> | <strong><a href="', $url_images, '">', $txt['print_page_images'], '</a></strong>';
+	else
+		echo '
+			<strong><a href="', $url_text, '">', $txt['print_page_text'], '</a></strong> | <a href="', $url_images, '">', $txt['print_page_images'], '</a>';
+
+	echo '
+		</div>
 		<h1 id="title">', $context['forum_name_html_safe'], '</h1>
 		<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>
 		<div id="posts">';
@@ -112,7 +121,7 @@ function template_print_above()
 
 function template_main()
 {
-	global $context, $settings, $options, $txt;
+	global $context, $options, $txt, $scripturl, $topic;
 
 	if (!empty($context['poll']))
 	{
@@ -132,19 +141,49 @@ function template_main()
 	}
 
 	foreach ($context['posts'] as $post)
+	{
 		echo '
 			<div class="postheader">
 				', $txt['title'], ': <strong>', $post['subject'], '</strong><br />
 				', $txt['post_by'], ': <strong>', $post['member'], '</strong> ', $txt['search_on'], ' <strong>', $post['time'], '</strong>
 			</div>
 			<div class="postbody">
-				', $post['body'], '
+				', $post['body'];
+				
+		// Show attachment images
+		if (isset($_GET['images']) && !empty($context['printattach'][$post['id_msg']]))
+		{
+			echo '
+				<hr />';
+			
+			foreach ($context['printattach'][$post['id_msg']] as $attach)
+				echo '
+					<img width="' . $attach['width'] . '" height="' . $attach['height'] . '" src="', $scripturl . '?action=dlattach;topic=' . $topic . '.0;attach=' . $attach['id_attach'] . '" alt="" />';
+		}
+			
+		echo '
 			</div>';
+	}
 }
 
 function template_print_below()
 {
-	global $context, $settings, $options;
+	global $topic, $txt, $scripturl;
+	
+	$url_text = $scripturl . '?action=printpage;topic=' . $topic . '.0';
+	$url_images = $url_text . ';images';
+	
+	echo '
+		</div>
+		<div class="print_options">';
+
+	// Show the text / image links
+	if (isset($_GET['images']))
+		echo '
+			<a href="', $url_text, '">', $txt['print_page_text'], '</a> | <strong><a href="', $url_images, '">', $txt['print_page_images'], '</a></strong>';
+	else
+		echo '
+			<strong><a href="', $url_text, '">', $txt['print_page_text'], '</a></strong> | <a href="', $url_images, '">', $txt['print_page_images'], '</a>';
 
 	echo '
 		</div>

+ 2 - 0
Themes/default/languages/index.english.php

@@ -364,6 +364,8 @@ $txt['you_have_many_msgs'] = 'You\'ve got %2$d messages... Click <a href="%1$s">
 $txt['total_boards'] = 'Total Boards';
 
 $txt['print_page'] = 'Print Page';
+$txt['print_page_text'] = 'Text only';
+$txt['print_page_images'] = 'Test with Images';
 
 $txt['valid_email'] = 'This must be a valid email address.';