]> git.mxchange.org Git - friendica.git/blob - include/forums.php
vier smileybutton: little polish in dark.css
[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         if (!$contacts)
46                 return($forumlist);
47
48         foreach($contacts as $contact) {
49                 $forumlist[] = array(
50                         'url'   => $contact['url'],
51                         'name'  => $contact['name'],
52                         'id'    => $contact['id'],
53                         'micro' => $contact['micro'],
54                 );
55         }
56         return($forumlist);
57 }
58
59
60 /**
61  * @brief Forumlist widget
62  *
63  * Sidebar widget to show subcribed friendica forums. If activated
64  * in the settings, it appears at the notwork page sidebar
65  *
66  * @param int $uid
67  * @param int $cid
68  *      The contact id which is used to mark a forum as "selected"
69  * @return string
70  */
71 function widget_forumlist($uid,$cid = 0) {
72
73         if(! intval(feature_enabled(local_user(),'forumlist_widget')))
74                 return;
75
76         $o = '';
77
78         //sort by last updated item
79         $lastitem = true;
80
81         $contacts = get_forumlist($uid,true,$lastitem, true);
82         $total = count($contacts);
83         $visible_forums = 10;
84
85         if(count($contacts)) {
86
87                 $id = 0;
88
89                 foreach($contacts as $contact) {
90
91                         $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
92
93                         $entry = array(
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),
100                                 'id' => ++$id,
101                         );
102                         $entries[] = $entry;
103                 }
104
105                 $tpl = get_markup_template('widget_forumlist.tpl');
106
107                 $o .= replace_macros($tpl,array(
108                         '$title'        => t('Forums'),
109                         '$forums'       => $entries,
110                         '$link_desc'    => t('External link to forum'),
111                         '$total'        => $total,
112                         '$visible_forums' => $visible_forums,
113                         '$showmore'     => t('show more'),
114                 ));
115         }
116
117         return $o;
118 }
119
120 /**
121  * @brief Format forumlist as contact block
122  *
123  * This function is used to show the forumlist in
124  * the advanced profile.
125  *
126  * @param int $uid
127  * @return string
128  *
129  */
130 function forumlist_profile_advanced($uid) {
131
132         $profile = intval(feature_enabled($uid,'forumlist_profile'));
133         if(! $profile)
134                 return;
135
136         $o = '';
137
138         // place holder in case somebody wants configurability
139         $show_total = 9999;
140
141         //don't sort by last updated item
142         $lastitem = false;
143
144         $contacts = get_forumlist($uid,false,$lastitem,false);
145
146         $total_shown = 0;
147
148         foreach($contacts as $contact) {
149                 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
150                 $total_shown ++;
151                 if($total_shown == $show_total)
152                         break;
153         }
154
155         if(count($contacts) > 0)
156                 $o .= $forumlist;
157                 return $o;
158 }
159
160 /**
161  * @brief count unread forum items
162  *
163  * Count unread items of connected forums and private groups
164  *
165  * @return array
166  *      'id' => contact id
167  *      'name' => contact/forum name
168  *      'count' => counted unseen forum items
169  *
170  */
171
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` ",
181                 intval(local_user())
182         );
183
184         return $r;
185 }