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