PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/print_post_mod/root/print_post.php

http://prekladyphpbbcz.googlecode.com/
PHP | 180 lines | 123 code | 25 blank | 32 comment | 19 complexity | 76e091b5858600f65a2d0a0976975058 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id: print_post.php,v 1.0.2 2008/12/30 18:39:48 rmcgirr83 Exp $
  6. * @copyright (c) Rich McGirr
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. include($phpbb_root_path . 'common.' . $phpEx);
  17. include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  18. // Start session management
  19. $user->session_begin();
  20. $auth->acl($user->data);
  21. $user->setup(array('mods/print_post','viewtopic'));
  22. $print_post = request_var('p', 0);
  23. $print_post_forum = request_var('f', 0);
  24. // is there a forum id?
  25. if (!$print_post_forum)
  26. {
  27. trigger_error('NO_FORUM');
  28. }
  29. // is there a post id?
  30. if(!$print_post)
  31. {
  32. trigger_error ('NO_POST');
  33. }
  34. // we do the following so no one can get clever
  35. // permissions check
  36. if (!$auth->acl_get('f_read', $print_post_forum))
  37. {
  38. if ($user->data['user_id'] != ANONYMOUS)
  39. {
  40. trigger_error('SORRY_AUTH_READ');
  41. }
  42. login_box('', $user->lang['LOGIN_VIEWFORUM']);
  43. }
  44. if(!$auth->acl_get('f_print', $print_post_forum))
  45. {
  46. trigger_error('SORRY_AUTH_PRINT');
  47. }
  48. // Go ahead and pull all data for this postid
  49. $sql = 'SELECT p.*, t.topic_title, u.user_id, u.username, u.user_colour
  50. FROM ' . POSTS_TABLE . ' p
  51. LEFT JOIN '. TOPICS_TABLE . ' t ON p.topic_id = t.topic_id
  52. LEFT JOIN ' . USERS_TABLE . ' u ON p.poster_id = u.user_id
  53. WHERE p.post_id = ' . $print_post;
  54. $result = $db->sql_query_limit($sql, 1);
  55. $row = $db->sql_fetchrow($result);
  56. $db->sql_freeresult($result);
  57. // check for a result
  58. if (!$row['post_id'])
  59. {
  60. trigger_error('NO_POST');
  61. }
  62. // check to make sure the post is approved..if there is one
  63. if(!$row['post_approved'])
  64. {
  65. trigger_error('POST_UNAPPROVED');
  66. }
  67. // everything is okay...let's go
  68. $server_path = generate_board_url() . '/';
  69. $topic_title = censor_text($row['topic_title']);
  70. $poster_id = (int) $row['user_id'];
  71. $post_id = (int) $row['post_id'];
  72. $message = censor_text($row['post_text']);
  73. // initialize attachment stuffs
  74. $attachments = $attach_list = $update_count = array();
  75. $has_attachments = $display_notice = false;
  76. // Does the post have an attachment(s)? If so, add it/them
  77. if ($row['post_attachment'] && $config['allow_attachments'])
  78. {
  79. $attach_list[] = $post_id;
  80. $has_attachments = true;
  81. }
  82. // Pull attachment data
  83. if (sizeof($attach_list))
  84. {
  85. if ($auth->acl_get('u_download') && $auth->acl_get('f_download', $print_post_forum))
  86. {
  87. $sql = 'SELECT *
  88. FROM ' . ATTACHMENTS_TABLE . '
  89. WHERE ' . $db->sql_in_set('post_msg_id', $attach_list) . '
  90. AND in_message = 0
  91. ORDER BY filetime DESC';
  92. $result = $db->sql_query($sql);
  93. while ($row2 = $db->sql_fetchrow($result))
  94. {
  95. $attachments[$row2['post_msg_id']][] = $row2;
  96. }
  97. $db->sql_freeresult($result);
  98. }
  99. else
  100. {
  101. $display_notice = true;
  102. }
  103. }
  104. // let's get us some attachments and show them...subsilver2 only though for now
  105. if (!empty($attachments[$row['post_id']]))
  106. {
  107. parse_attachments($print_post_forum, $message, $attachments[$row['post_id']], $update_count);
  108. }
  109. // initialize a needed variable for bbcode
  110. $bbcode_bitfield = '';
  111. // Define the global bbcode bitfield, will be used to load bbcodes
  112. $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
  113. // Instantiate BBCode if need be
  114. if ($bbcode_bitfield !== '')
  115. {
  116. $bbcode = new bbcode(base64_encode($bbcode_bitfield));
  117. }
  118. // Second parse bbcode here
  119. if ($row['bbcode_bitfield'])
  120. {
  121. $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
  122. }
  123. // pretty up the message
  124. $message = bbcode_nl2br($message);
  125. $message = smiley_text($message);
  126. //generate the page
  127. $template->assign_vars(array(
  128. 'MESSAGE' => $message,
  129. 'TOPIC_TITLE' => $topic_title,
  130. 'POST_DATE' => $user->format_date($row['post_time']),
  131. 'POST_AUTHOR_COLOUR' => get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
  132. 'POST_AUTHOR' => get_username_string('username', $poster_id, $row['username'], $row['user_colour'], $row['post_username']),
  133. 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']])) ? true : false,
  134. 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'],
  135. 'U_FORUM' => $server_path,
  136. 'U_POST' => "{$server_path}viewtopic.$phpEx?p=$post_id#p$post_id",
  137. ));
  138. // Display Attachments for this post
  139. if (!empty($attachments[$row['post_id']]))
  140. {
  141. foreach ($attachments[$row['post_id']] as $attachment)
  142. {
  143. $template->assign_block_vars('attachment', array(
  144. 'DISPLAY_ATTACHMENT' => $attachment)
  145. );
  146. }
  147. }
  148. unset($attachments[$row['post_id']]);
  149. // Output the page
  150. page_header($user->lang['PRINT_POST_VIEW']);
  151. $template->set_filenames(array(
  152. 'body' => 'viewtopic_print_post.html'
  153. ));
  154. page_footer();
  155. ?>