4 * @file include/forums.php
5 * @brief Functions related to forum functionality *
10 * @brief Function to list all forums a user is connected with
12 * @param int $uid of the profile owner
13 * @param boolean $showhidden
14 * Show frorums which are not hidden
15 * @param boolean $lastitem
17 * @param boolean $showprivate
22 * 'name' => forum name
23 * 'id' => number of the key from the array
24 * 'micro' => contact photo in format micro
26 function get_forumlist($uid, $showhidden = true, $lastitem, $showprivate = false) {
30 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
31 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
34 $select = '(`forum` OR `prv`)';
37 $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
38 WHERE `network`= 'dfrn' AND $select AND `uid` = %d
39 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
40 AND `success_update` > `failure_update`
45 foreach($contacts as $contact) {
47 'url' => $contact['url'],
48 'name' => $contact['name'],
49 'id' => $contact['id'],
50 'micro' => $contact['micro'],
58 * @brief Forumlist widget
60 * Sidebar widget to show subcribed friendica forums. If activated
61 * in the settings, it appears at the notwork page sidebar
66 function widget_forumlist($a) {
68 if(! intval(feature_enabled(local_user(),'forumlist_widget')))
73 //sort by last updated item
76 $contacts = get_forumlist($a->user['uid'],true,$lastitem, true);
77 $total = count($contacts);
80 if(count($contacts)) {
84 foreach($contacts as $contact) {
87 'url' => $a->get_baseurl() . '/network?f=&cid=' . $contact['id'],
88 'external_url' => $a->get_baseurl() . '/redir/' . $contact['id'],
89 'name' => $contact['name'],
90 'cid' => $contact['id'],
91 'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
97 $tpl = get_markup_template('widget_forumlist.tpl');
99 $o .= replace_macros($tpl,array(
100 '$title' => t('Forums'),
101 '$forums' => $entries,
102 '$link_desc' => t('External link to forum'),
104 '$visible_forums' => $visible_forums,
105 '$showmore' => t('show more'),
113 * @brief Format forumlist as contact block
115 * This function is used to show the forumlist in
116 * the advanced profile.
122 function forumlist_profile_advanced($uid) {
124 $profile = intval(feature_enabled($uid,'forumlist_profile'));
130 // place holder in case somebody wants configurability
133 //don't sort by last updated item
136 $contacts = get_forumlist($uid,false,$lastitem,false);
140 foreach($contacts as $contact) {
141 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
143 if($total_shown == $show_total)
147 if(count($contacts) > 0)
153 * @brief count unread forum items
155 * Count unread items of connected forums and private groups
159 * 'name' => contact/forum name
160 * 'count' => counted unseen forum items
164 function forums_count_unseen() {
165 $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
166 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
167 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
168 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
169 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
170 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
171 AND `contact`.`success_update` > `failure_update`
172 GROUP BY `contact`.`id` ",