Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

183 lines
4.3 KiB

  1. <?php
  2. /**
  3. * @file include/forums.php
  4. * @brief Functions related to forum functionality *
  5. */
  6. /**
  7. * @brief Function to list all forums a user is connected with
  8. *
  9. * @param int $uid of the profile owner
  10. * @param boolean $showhidden
  11. * Show frorums which are not hidden
  12. * @param boolean $lastitem
  13. * Sort by lastitem
  14. * @param boolean $showprivate
  15. * Show private groups
  16. *
  17. * @returns array
  18. * 'url' => forum url
  19. * 'name' => forum name
  20. * 'id' => number of the key from the array
  21. * 'micro' => contact photo in format micro
  22. */
  23. function get_forumlist($uid, $showhidden = true, $lastitem, $showprivate = false) {
  24. $forumlist = array();
  25. $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
  26. $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
  27. $select = '`forum` ';
  28. if ($showprivate) {
  29. $select = '(`forum` OR `prv`)';
  30. }
  31. $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
  32. WHERE `network`= 'dfrn' AND $select AND `uid` = %d
  33. AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
  34. AND `success_update` > `failure_update`
  35. $order ",
  36. intval($uid)
  37. );
  38. foreach($contacts as $contact) {
  39. $forumlist[] = array(
  40. 'url' => $contact['url'],
  41. 'name' => $contact['name'],
  42. 'id' => $contact['id'],
  43. 'micro' => $contact['micro'],
  44. );
  45. }
  46. return($forumlist);
  47. }
  48. /**
  49. * @brief Forumlist widget
  50. *
  51. * Sidebar widget to show subcribed friendica forums. If activated
  52. * in the settings, it appears at the notwork page sidebar
  53. *
  54. * @param int $uid
  55. * @param int $cid
  56. * The contact id which is used to mark a forum as "selected"
  57. * @return string
  58. */
  59. function widget_forumlist($uid,$cid = 0) {
  60. if(! intval(feature_enabled(local_user(),'forumlist_widget')))
  61. return;
  62. $o = '';
  63. //sort by last updated item
  64. $lastitem = true;
  65. $contacts = get_forumlist($uid,true,$lastitem, true);
  66. $total = count($contacts);
  67. $visible_forums = 10;
  68. if(count($contacts)) {
  69. $id = 0;
  70. foreach($contacts as $contact) {
  71. $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
  72. $entry = array(
  73. 'url' => z_root() . '/network?f=&cid=' . $contact['id'],
  74. 'external_url' => z_root() . '/redir/' . $contact['id'],
  75. 'name' => $contact['name'],
  76. 'cid' => $contact['id'],
  77. 'selected' => $selected,
  78. 'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
  79. 'id' => ++$id,
  80. );
  81. $entries[] = $entry;
  82. }
  83. $tpl = get_markup_template('widget_forumlist.tpl');
  84. $o .= replace_macros($tpl,array(
  85. '$title' => t('Forums'),
  86. '$forums' => $entries,
  87. '$link_desc' => t('External link to forum'),
  88. '$total' => $total,
  89. '$visible_forums' => $visible_forums,
  90. '$showmore' => t('show more'),
  91. ));
  92. }
  93. return $o;
  94. }
  95. /**
  96. * @brief Format forumlist as contact block
  97. *
  98. * This function is used to show the forumlist in
  99. * the advanced profile.
  100. *
  101. * @param int $uid
  102. * @return string
  103. *
  104. */
  105. function forumlist_profile_advanced($uid) {
  106. $profile = intval(feature_enabled($uid,'forumlist_profile'));
  107. if(! $profile)
  108. return;
  109. $o = '';
  110. // place holder in case somebody wants configurability
  111. $show_total = 9999;
  112. //don't sort by last updated item
  113. $lastitem = false;
  114. $contacts = get_forumlist($uid,false,$lastitem,false);
  115. $total_shown = 0;
  116. foreach($contacts as $contact) {
  117. $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
  118. $total_shown ++;
  119. if($total_shown == $show_total)
  120. break;
  121. }
  122. if(count($contacts) > 0)
  123. $o .= $forumlist;
  124. return $o;
  125. }
  126. /**
  127. * @brief count unread forum items
  128. *
  129. * Count unread items of connected forums and private groups
  130. *
  131. * @return array
  132. * 'id' => contact id
  133. * 'name' => contact/forum name
  134. * 'count' => counted unseen forum items
  135. *
  136. */
  137. function forums_count_unseen() {
  138. $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
  139. INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
  140. WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
  141. AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
  142. AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
  143. AND NOT `contact`.`pending` AND NOT `contact`.`archive`
  144. AND `contact`.`success_update` > `failure_update`
  145. GROUP BY `contact`.`id` ",
  146. intval(local_user())
  147. );
  148. return $r;
  149. }