PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/simple-forum/forum/sf-topic-view.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 371 lines | 252 code | 63 blank | 56 comment | 94 complexity | 77f728d230c017d91d6e07631c7655ff MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /*
  3. Simple:Press
  4. Topic View Display
  5. $LastChangedDate: 2011-06-16 22:56:41 -0700 (Thu, 16 Jun 2011) $
  6. $Rev: 6329 $
  7. */
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  9. die('Access Denied');
  10. }
  11. function sf_render_topic()
  12. {
  13. global $sfvars, $current_user, $sfglobals, $sfavatarcache, $sfsigcache, $sfrankcache, $sfidentitycache;
  14. if(!sf_topic_exists($sfvars['topicid']))
  15. {
  16. status_header(404);
  17. $sfvars['error'] = true;
  18. update_sfnotice('sfmessage', '1@'.sprintf(__('Topic %s Not Found', 'sforum'), $sfvars['topicslug']));
  19. $out = sf_render_queued_message()."\n";
  20. $out.= '<div class="sfmessagestrip">'."\n";
  21. $out.= sprintf(__("There is no such topic named %s", "sforum"), $sfvars['topicslug'])."\n";
  22. $out.= '</div>'."\n";
  23. return $out;
  24. }
  25. if($current_user->sfaccess)
  26. {
  27. # Get Topic Record
  28. $topic=sf_get_combined_topics_and_posts($sfvars['topicid']);
  29. if($topic)
  30. {
  31. $sfavatarcache = array();
  32. $sfsigcache = array();
  33. $sfrankcache = array();
  34. $sfidentitycache = array();
  35. # Setup stuff we will need
  36. $editstrip = false;
  37. $admintools = false;
  38. $userposts = 0;
  39. if(isset($_POST['useredit']) || isset($_POST['adminedit']))
  40. {
  41. $sfvars['displaymode'] = 'edit';
  42. } else {
  43. $sfvars['displaymode'] = 'posts';
  44. }
  45. # == IS FORUM LOCKED OR CAN WE ADD
  46. if($current_user->sfreply) $showadd = true;
  47. if($current_user->forumadmin) $showadd = true;
  48. if ($sfglobals['lockdown']) $showadd = false;
  49. if(($sfglobals['admin']['sftools']) && ($current_user->sftopicicons)) $admintools=true;
  50. $lastpost = false;
  51. # Setup more stuff we will need
  52. $topiclock = false;
  53. if($topic['topic_status'] || $topic['forum_status']) $topiclock = true;
  54. # Does this have a link to blog post
  55. $bloglink = $topic['blog_post_id'];
  56. # Setup page links for this topic
  57. $thispagelinks = sf_compile_paged_posts($sfvars['forumslug'], $sfvars['topicslug'], $sfvars['topicid'], $sfvars['page'], $topic['post_count']);
  58. # Start display
  59. $out = '';
  60. $out.= '<div id="topic-'.$sfvars['topicid'].'" class="sfblock">'."\n";
  61. $out.= sf_render_main_header_table('topic', 0, sf_filter_title_display($topic['topic_name']), '', SFRESOURCES.'topic.png', false, $showadd, $topiclock, $topic['blog_post_id'], '', false, 0, $topic['topic_status_set'], $topic['topic_status_flag']);
  62. # Display top page link navigation
  63. $out.= sf_render_post_pagelinks($thispagelinks, false, $topiclock, $topic['topic_subs'], $topic['topic_page'], $topic['topic_total_pages']);
  64. # Display any tags for this topic if enabled
  65. if ($topic['use_tags'] && $sfglobals['display']['posts']['tagstop'])
  66. {
  67. $out.= '<table class="sffooter"><tr><td>'."\n";
  68. $out.= '<div class="sfstatustags">';
  69. $out.= sf_render_topic_tags($topic['use_tags'], $topic, true, 'top');
  70. $out.= '</div>';
  71. $out.= '</td></tr></table>';
  72. $out.= sf_process_hook('sf_hook_post_topic_top_tags', array($sfvars['forumid'], $sfvars['topicid']));
  73. }
  74. if($topic['posts'])
  75. {
  76. $numposts=count($topic['posts']);
  77. $thispost=1;
  78. $alt = '';
  79. # Start the Outer Table
  80. $out.= '<table class="sfposttable">'."\n";
  81. # Display post column headers
  82. $out.= sf_render_topic_column_header_row();
  83. foreach($topic['posts'] as $post)
  84. {
  85. # Setup even more stuff we will need
  86. $currentguest = false;
  87. $currentmember = false;
  88. $posterstatus = 'user';
  89. $postcount = '';
  90. $sig = false;
  91. $displaypost = true;
  92. $approve_text = '';
  93. $editmode = false;
  94. $postboxclass = '';
  95. # is this the last post (which can have the edit button)
  96. if(($sfglobals['display']['posts']['sortdesc']==true && $thispost==1) ||
  97. ($sfglobals['display']['posts']['sortdesc']==false && ($thispost == $numposts)))
  98. {
  99. $lastpost = true;
  100. }
  101. # Status of the poster of this post (first check Amdin)
  102. if ($post['admin']) $posterstatus = 'admin';
  103. # Or was it posted by the user currently loading the page?
  104. if(($current_user->member) && ($current_user->ID == $post['user_id'])) $currentmember=true;
  105. # Prepare Posters name and URL if exists
  106. $poster = '';
  107. $cacheid = $post['guest_email'];
  108. if($post['user_id'])
  109. {
  110. $poster=sf_build_name_display($post['user_id'], sf_filter_name_display($post['display_name']));
  111. $cacheid = $post['user_id'];
  112. }
  113. $username = sf_filter_name_display($post['display_name']);
  114. if(empty($poster))
  115. {
  116. # Must be a guest
  117. $poster = sf_filter_name_display($post['guest_name']);
  118. $posterstatus = 'guest';
  119. # Was it the guest currently loading the page?
  120. if(($current_user->guestname == $poster) && ($current_user->guestemail == sf_filter_email_display($post['guest_email']))) $currentguest = true;
  121. $username = $poster;
  122. }
  123. # Are we in 'edit' mode with this post?
  124. if (((isset($_POST['useredit']) && $_POST['useredit'] == $post['post_id']) ||
  125. (isset($_POST['adminedit'])) && ($_POST['adminedit'] == $post['post_id'])) &&
  126. (($current_user->sfstopedit && $lastpost) || $current_user->sfeditall))
  127. {
  128. # in edit mode. But is current user original poster?
  129. if (($currentmember || $currentguest || $current_user->sfeditall) && !$sfglobals['lockdown'])
  130. {
  131. $editmode=true;
  132. $sfvars['displaymode'] = 'edit';
  133. $showadd = false;
  134. }
  135. }
  136. if(!$editmode) $postboxclass= 'class="sfpostcontent '.$alt.'"';
  137. # Get post count if poster was a member
  138. if(!empty($post['user_id']))
  139. {
  140. $userposts = $post['posts'];
  141. $postcount = __("posts ", "sforum").$userposts;
  142. }
  143. # Setup Signature line if exists
  144. if($posterstatus != 'guest')
  145. {
  146. $sig = sf_filter_text_display($post['signature']);
  147. }
  148. # Determine approval status of post - is it still awaiting aproval?
  149. if($post['post_status'] == 1)
  150. {
  151. $approve_text.= '<p><em>'.__("Post Awaiting Approval by Forum Administrator", "sforum").'</em></p>';
  152. $postboxclass= 'class="sfpostcontent sfmoderate"';
  153. if($current_user->moderator == false || $current_user->sfapprove == false)
  154. {
  155. $displaypost = false;
  156. }
  157. }
  158. # Outer table - display post row (in sections)
  159. if (!array_key_exists($cacheid, $sfrankcache))
  160. {
  161. $sfrankcache[$cacheid] = sf_render_usertype($posterstatus, $post['user_id'], $userposts);
  162. }
  163. $rank = $sfrankcache[$cacheid];
  164. $rank_class = apply_filters('sanitize_title', $rank);
  165. $out.= '<tr id="post-'.$post['post_id'].'" class="rank-'.$rank_class.' sftype-'.$posterstatus.'" valign="top">'."\n";
  166. # Poster Details Cell
  167. if($sfglobals['display']['posts']['userabove'] || $editmode == true)
  168. {
  169. # Open outer cell (above)
  170. $out.= '<td colspan="2" class="sfuserinfoabove '.$alt.'">'."\n";
  171. $out.= '<a id="p'.$post['post_id'].'"></a>'."\n";
  172. $out.= sf_render_poster_details_above($post, $posterstatus, $poster, $rank, $postcount, $alt, $cacheid);
  173. } else {
  174. # Open outer cell (side)
  175. $out.= '<td class="sfuserinfoside '.$alt.'">'."\n";
  176. $out.= '<a id="p'.$post['post_id'].'"></a>'."\n";
  177. $out.= sf_render_poster_details_side($post, $posterstatus, $poster, $rank, $postcount, $alt, $cacheid);
  178. }
  179. # Close outer cell
  180. $out.= '</td>'."\n";
  181. # Close poster detail row and prepare next (post content) if single column mode
  182. if($sfglobals['display']['posts']['userabove'] || $editmode == true) $out.= '</tr><tr valign="top">'."\n";
  183. # Open outer cell
  184. if($editmode == true)
  185. {
  186. $out.= '<td colspan="2" class="'.$alt.'">'."\n";
  187. } else {
  188. $out.= '<td class="'.$alt.'">'."\n";
  189. }
  190. # Start Inner post cell table
  191. $out.= '<table class="sfinnerposttable">'."\n";
  192. # we only want the bloglink on the first post otherwise send a zero
  193. if($post['post_index'] == 1 ? $passbloglink = $bloglink : $passbloglink = 0);
  194. # Display post icon strip if not in edit mode
  195. if(!$editmode)
  196. {
  197. $out.='<tr>'."\n";
  198. $out.= sf_render_post_icon_strip($post, $posterstatus, $current_user->ID, $username, $currentguest, $currentmember, $displaypost, $topiclock, $lastpost, $alt, $admintools, $topic['post_ratings']);
  199. # Close the inner iconstrip row
  200. $out.= '</tr>'."\n";
  201. $editstrip=true;
  202. }
  203. # open postcontent row, inner table cell
  204. $out.= '<tr>'."\n";
  205. # Display Post Content (Edit/Normal/Moderation modes)
  206. $out.= '<td '.$postboxclass.'>'."\n";
  207. # Pre Post-content hook
  208. $out.= sf_process_hook('sf_hook_pre_post', array($sfvars['topicid'], $post['post_id']));
  209. $out.= sf_render_post_content($post, $editmode, $displaypost, $approve_text, $currentguest, $currentmember, $passbloglink);
  210. $out.= '</td>'."\n";
  211. # Close the inner post content row
  212. $out.= '</tr>'."\n";
  213. # Display Signature of set
  214. if ($sig && !$editmode)
  215. {
  216. $out.= '<tr><td class="sfsignature '.$alt.'">'."\n";
  217. if (!array_key_exists($cacheid, $sfsigcache))
  218. {
  219. $sfsigcache[$cacheid] = sf_render_signature_strip($sig);
  220. }
  221. $out.= $sfsigcache[$cacheid];
  222. $out.= '</td>'."\n";
  223. $out.= '</tr>'."\n";
  224. }
  225. # Feedburner 'Flare' Hook/first and last post hooks
  226. $permalink = sf_build_url($sfvars['forumslug'], $sfvars['topicslug'], $sfvars['page'], $post['post_id'], $post['post_index']);
  227. $hook = '';
  228. $hook.= sf_process_hook('sf_hook_post_feedflare', array($permalink));
  229. if($post['post_index'] == 1)
  230. {
  231. $hook.= sf_process_hook('sf_hook_first_post', array($sfvars['forumid'], $sfvars['topicid']));
  232. }
  233. if($lastpost == true)
  234. {
  235. $hook.= sf_process_hook('sf_hook_last_post', array($sfvars['forumid'], $sfvars['topicid']));
  236. }
  237. if($post['post_index'] != 1 && $lastpost == false)
  238. {
  239. $hook.= sf_process_hook('sf_hook_other_posts', array($sfvars['forumid'], $sfvars['topicid']));
  240. }
  241. if($hook)
  242. {
  243. $out.= '<tr><td class="'.$alt.'">'.$hook.'</td></tr>'."\n";
  244. $hook='';
  245. }
  246. # Post post-content hook
  247. $hook = '';
  248. $hook.= sf_process_hook('sf_hook_post_post', array($sfvars['topicid'], $post['post_id']));
  249. $hook.= sf_process_hook('sf_hook_post_post_by_position', array($sfvars['topicid'], $post['post_id'], $thispost));
  250. if($hook)
  251. {
  252. $out.= '<tr><td class="'.$alt.'">'.$hook.'</td></tr>'."\n";
  253. $hook='';
  254. }
  255. # End Inner post cell table
  256. $out.= '</table>'."\n";
  257. # End Outer post cell middle
  258. $out.= '</td>'."\n";
  259. # Close outer right cell
  260. $out.= '</tr>'."\n";
  261. $thispost++;
  262. if ($alt == '') $alt = 'sfalt'; else $alt = '';
  263. }
  264. # Close outer table
  265. $out.= '</table>'."\n";
  266. $out.= '<div class="sfdivider"></div>';
  267. # topic status updater
  268. if($sfglobals['display']['posts']['topicstatuschanger'])
  269. {
  270. if(!empty($topic['topic_status_set']))
  271. {
  272. $out.= sf_render_topic_status_updater($topic['topic_status_set'], $topic['topic_status_flag'], $topic['user_id']);
  273. }
  274. }
  275. # Display any tags for this topic if enabled
  276. if ($topic['use_tags'] && $sfglobals['display']['posts']['tagsbottom'])
  277. {
  278. $out.= '<table class="sfclear sffooter"><tr><td>'."\n";
  279. $out.= '<div class="sfstatustags">';
  280. $out.= sf_render_topic_tags($topic['use_tags'], $topic, true, 'bottom');
  281. $out.= '</div>';
  282. $out.= '</td></tr></table>';
  283. $out.= sf_process_hook('sf_hook_post_topic_bottom_tags', array($sfvars['forumid'], $sfvars['topicid']));
  284. }
  285. # Topic footer hook
  286. $out.= sf_process_hook('sf_hook_topic_footer', array($sfvars['forumid'], $sfvars['topicid']));
  287. # Display bottom page link navigation
  288. $out.= sf_render_post_pagelinks($thispagelinks, true, $topiclock, '', $topic['topic_page'], $topic['topic_total_pages']);
  289. } else {
  290. $out.= '<div class="sfmessagestrip">'.__("There are No Posts for this Topic", "sforum").'</div>'."\n";
  291. }
  292. $out.= '</div>'."\n";
  293. }
  294. # Display Add Post form (hidden)
  295. if((!$topiclock) || ($current_user->forumadmin))
  296. {
  297. if($current_user->sfreply && $sfvars['displaymode'] == 'posts')
  298. {
  299. $out.= '<a id="dataform"></a>'."\n";
  300. $out.= sf_add_post($sfvars['forumid'], $sfvars['topicid'], $topic['topic_name'], $topic['topic_status_set'], $topic['topic_status_flag'], $topic['user_id'], $topic['topic_subs'], $topic['topic_watches']);
  301. }
  302. }
  303. } else {
  304. $out = 'Access Denied';
  305. }
  306. return $out;
  307. }
  308. ?>