annotate forum/Sources/Printpage.php @ 85:6d7b61434be7 website

Add a copy of this here, just in case!
author Chris Cannam
date Mon, 20 Jan 2014 11:02:36 +0000
parents e3e11437ecea
children
rev   line source
Chris@76 1 <?php
Chris@76 2
Chris@76 3 /**
Chris@76 4 * Simple Machines Forum (SMF)
Chris@76 5 *
Chris@76 6 * @package SMF
Chris@76 7 * @author Simple Machines http://www.simplemachines.org
Chris@76 8 * @copyright 2011 Simple Machines
Chris@76 9 * @license http://www.simplemachines.org/about/smf/license.php BSD
Chris@76 10 *
Chris@76 11 * @version 2.0
Chris@76 12 */
Chris@76 13
Chris@76 14 if (!defined('SMF'))
Chris@76 15 die('Hacking attempt...');
Chris@76 16
Chris@76 17 /* This file contains just one function that formats a topic to be printer
Chris@76 18 friendly.
Chris@76 19
Chris@76 20 void PrintTopic()
Chris@76 21 - is called to format a topic to be printer friendly.
Chris@76 22 - must be called with a topic specified.
Chris@76 23 - uses the Printpage (main sub template.) template.
Chris@76 24 - uses the print_above/print_below later without the main layer.
Chris@76 25 - is accessed via ?action=printpage.
Chris@76 26 */
Chris@76 27
Chris@76 28 function PrintTopic()
Chris@76 29 {
Chris@76 30 global $topic, $txt, $scripturl, $context, $user_info;
Chris@76 31 global $board_info, $smcFunc, $modSettings;
Chris@76 32
Chris@76 33 // Redirect to the boardindex if no valid topic id is provided.
Chris@76 34 if (empty($topic))
Chris@76 35 redirectexit();
Chris@76 36
Chris@76 37 // Whatever happens don't index this.
Chris@76 38 $context['robot_no_index'] = true;
Chris@76 39
Chris@76 40 // Get the topic starter information.
Chris@76 41 $request = $smcFunc['db_query']('', '
Chris@76 42 SELECT m.poster_time, IFNULL(mem.real_name, m.poster_name) AS poster_name
Chris@76 43 FROM {db_prefix}messages AS m
Chris@76 44 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
Chris@76 45 WHERE m.id_topic = {int:current_topic}
Chris@76 46 ORDER BY m.id_msg
Chris@76 47 LIMIT 1',
Chris@76 48 array(
Chris@76 49 'current_topic' => $topic,
Chris@76 50 )
Chris@76 51 );
Chris@76 52 // Redirect to the boardindex if no valid topic id is provided.
Chris@76 53 if ($smcFunc['db_num_rows']($request) == 0)
Chris@76 54 redirectexit();
Chris@76 55 $row = $smcFunc['db_fetch_assoc']($request);
Chris@76 56 $smcFunc['db_free_result']($request);
Chris@76 57
Chris@76 58 // Lets "output" all that info.
Chris@76 59 loadTemplate('Printpage');
Chris@76 60 $context['template_layers'] = array('print');
Chris@76 61 $context['board_name'] = $board_info['name'];
Chris@76 62 $context['category_name'] = $board_info['cat']['name'];
Chris@76 63 $context['poster_name'] = $row['poster_name'];
Chris@76 64 $context['post_time'] = timeformat($row['poster_time'], false);
Chris@76 65 $context['parent_boards'] = array();
Chris@76 66 foreach ($board_info['parent_boards'] as $parent)
Chris@76 67 $context['parent_boards'][] = $parent['name'];
Chris@76 68
Chris@76 69 // Split the topics up so we can print them.
Chris@76 70 $request = $smcFunc['db_query']('', '
Chris@76 71 SELECT subject, poster_time, body, IFNULL(mem.real_name, poster_name) AS poster_name
Chris@76 72 FROM {db_prefix}messages AS m
Chris@76 73 LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
Chris@76 74 WHERE m.id_topic = {int:current_topic}' . ($modSettings['postmod_active'] && !allowedTo('approve_posts') ? '
Chris@76 75 AND (m.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR m.id_member = {int:current_member}') . ')' : '') . '
Chris@76 76 ORDER BY m.id_msg',
Chris@76 77 array(
Chris@76 78 'current_topic' => $topic,
Chris@76 79 'is_approved' => 1,
Chris@76 80 'current_member' => $user_info['id'],
Chris@76 81 )
Chris@76 82 );
Chris@76 83 $context['posts'] = array();
Chris@76 84 while ($row = $smcFunc['db_fetch_assoc']($request))
Chris@76 85 {
Chris@76 86 // Censor the subject and message.
Chris@76 87 censorText($row['subject']);
Chris@76 88 censorText($row['body']);
Chris@76 89
Chris@76 90 $context['posts'][] = array(
Chris@76 91 'subject' => $row['subject'],
Chris@76 92 'member' => $row['poster_name'],
Chris@76 93 'time' => timeformat($row['poster_time'], false),
Chris@76 94 'timestamp' => forum_time(true, $row['poster_time']),
Chris@76 95 'body' => parse_bbc($row['body'], 'print'),
Chris@76 96 );
Chris@76 97
Chris@76 98 if (!isset($context['topic_subject']))
Chris@76 99 $context['topic_subject'] = $row['subject'];
Chris@76 100 }
Chris@76 101 $smcFunc['db_free_result']($request);
Chris@76 102
Chris@76 103 // Set a canonical URL for this page.
Chris@76 104 $context['canonical_url'] = $scripturl . '?topic=' . $topic . '.0';
Chris@76 105 }
Chris@76 106
Chris@76 107 ?>