Printpage.php 3.3 KB

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