Printpage.php 3.3 KB

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