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

/wp-content/plugins/simple-forum/template-tags/sf-template-tags-comments.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 128 lines | 63 code | 19 blank | 46 comment | 14 complexity | 12dcb2338326c8b68fd7f486eb4ebba8 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. Template Tag(s) - Linked Topics as Comments
  5. $LastChangedDate: 2010-12-17 09:42:54 -0700 (Fri, 17 Dec 2010) $
  6. $Rev: 5081 $
  7. */
  8. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
  9. die('Access Denied');
  10. }
  11. /* =====================================================================================
  12. sf_comments_number($no_comment="0 Comments", $one_comment="1 Comment", $many_comment="% Comments", $blogcomments)
  13. Replaces the WP Template Tag: comments_number()
  14. Supplies Count of topic posts and can optionally include the standard blog comments in the total
  15. parameters:
  16. $no_comment Used for zero comments text
  17. $one_comment Used for one comment text
  18. $many_comment Used for multiple comments text
  19. $blogcomments Include Standard Blog Comments (true or false)
  20. $postid Option to specify postid, otherwise $wp_query is used integer
  21. ===================================================================================*/
  22. function sf_comments_number($no_comment="0 Comments", $one_comment="1 Comment", $many_comment="% Comments", $blogcomments=false, $postid=0)
  23. {
  24. global $wp_query;
  25. sf_initialise_globals();
  26. $result = $no_comment;
  27. $total = 0;
  28. if (empty($postid)) $postid = $wp_query->post->ID;
  29. $links = sf_blog_links_control('read', $postid);
  30. # If linked get the post count (-1 of course)
  31. if ($links && sf_can_view_forum($links->forum_id))
  32. {
  33. $sfpostlinking = sf_get_option('sfpostlinking');
  34. # link found for this post
  35. $total = (sf_get_posts_count_in_linked_topic($links->topic_id, $sfpostlinking['sfhideduplicate'])-1);
  36. }
  37. # If to include standard blog comments add that number
  38. if($blogcomments)
  39. {
  40. $total += get_comments_number($postid);
  41. }
  42. if($total > 0)
  43. {
  44. if($total == 1 ? $result=$one_comment : $result=str_replace('%', number_format_i18n($total), $many_comment));
  45. }
  46. echo $result;
  47. return;
  48. }
  49. /* =====================================================================================
  50. sf_first_topic_post_link($blog_post_id, $link_text
  51. Creates a link to the first topic post in a blog post/topic linked thread
  52. parameters:
  53. $blog_post_id The ID pof the blog post ($post->ID in Post Loop)
  54. $link text What text to display as the link
  55. ===================================================================================*/
  56. function sf_first_topic_post_link($blogpostid, $linktext)
  57. {
  58. global $wpdb;
  59. $topiclink='';
  60. $blogpostid = sf_esc_int($blogpostid);
  61. if($blogpostid)
  62. {
  63. $links = sf_blog_links_control('read', $blogpostid);
  64. if ($links && sf_can_view_forum($links->forum_id))
  65. {
  66. $postid = $wpdb->get_var("SELECT post_id FROM ".SFPOSTS." WHERE topic_id=".$links->topic_id." AND post_index=1");
  67. $topiclink = '<a href="'.sf_build_url(sf_get_forum_slug($links->forum_id), sf_get_topic_slug($links->topic_id), 1, $postid, 1).'">'.$linktext.'</a>';
  68. }
  69. }
  70. echo $topiclink;
  71. return;
  72. }
  73. /* =====================================================================================
  74. sf_last_topic_post_link($blog_post_id, $link_text
  75. Creates a link to the last topic post in a blog post/topic linked thread
  76. parameters:
  77. $blog_post_id The ID pof the blog post ($post->ID in Post Loop)
  78. $link text What text to display as the link
  79. ===================================================================================*/
  80. function sf_last_topic_post_link($blogpostid, $linktext)
  81. {
  82. global $wpdb;
  83. $topiclink='';
  84. $blogpostid = sf_esc_int($blogpostid);
  85. if($blogpostid)
  86. {
  87. $links = sf_blog_links_control('read', $blogpostid);
  88. if ($links && sf_can_view_forum($links->forum_id))
  89. {
  90. $postid = $wpdb->get_var("SELECT post_id FROM ".SFPOSTS." WHERE topic_id=".$links->topic_id." ORDER BY post_index DESC LIMIT 1");
  91. $topiclink = '<a href="'.sf_build_url(sf_get_forum_slug($links->forum_id), sf_get_topic_slug($links->topic_id), 0, $postid).'">'.$linktext.'</a>';
  92. }
  93. }
  94. echo $topiclink;
  95. return;
  96. }
  97. ?>