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`
48 foreach($contacts as $contact) {
50 'url' => $contact['url'],
51 'name' => $contact['name'],
52 'id' => $contact['id'],
53 'micro' => $contact['micro'],
61 * @brief Forumlist widget
63 * Sidebar widget to show subcribed friendica forums. If activated
64 * in the settings, it appears at the notwork page sidebar
68 * The contact id which is used to mark a forum as "selected"
71 function widget_forumlist($uid,$cid = 0) {
73 if(! intval(feature_enabled(local_user(),'forumlist_widget')))
78 //sort by last updated item
81 $contacts = get_forumlist($uid,true,$lastitem, true);
82 $total = count($contacts);
85 if(count($contacts)) {
89 foreach($contacts as $contact) {
91 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
94 'url' => z_root() . '/network?f=&cid=' . $contact['id'],
95 'external_url' => z_root() . '/redir/' . $contact['id'],
96 'name' => $contact['name'],
97 'cid' => $contact['id'],
98 'selected' => $selected,
99 'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
105 $tpl = get_markup_template('widget_forumlist.tpl');
107 $o .= replace_macros($tpl,array(
108 '$title' => t('Forums'),
109 '$forums' => $entries,
110 '$link_desc' => t('External link to forum'),
112 '$visible_forums' => $visible_forums,
113 '$showmore' => t('show more'),
121 * @brief Format forumlist as contact block
123 * This function is used to show the forumlist in
124 * the advanced profile.
130 function forumlist_profile_advanced($uid) {
132 $profile = intval(feature_enabled($uid,'forumlist_profile'));
138 // place holder in case somebody wants configurability
141 //don't sort by last updated item
144 $contacts = get_forumlist($uid,false,$lastitem,false);
148 foreach($contacts as $contact) {
149 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
151 if($total_shown == $show_total)
155 if(count($contacts) > 0)
161 * @brief count unread forum items
163 * Count unread items of connected forums and private groups
167 * 'name' => contact/forum name
168 * 'count' => counted unseen forum items
172 function forums_count_unseen() {
173 $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
174 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
175 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
176 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
177 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
178 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
179 AND `contact`.`success_update` > `failure_update`
180 GROUP BY `contact`.`id` ",