]> git.mxchange.org Git - friendica.git/blob - include/forums.php
Merge pull request #2099 from rabuzarus/2611_new_user_addr
[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 App $a
64  * @return string
65  */
66 function widget_forumlist($a) {
67
68         if(! intval(feature_enabled(local_user(),'forumlist_widget')))
69                 return;
70
71         $o = '';
72
73         //sort by last updated item
74         $lastitem = true;
75
76         $contacts = get_forumlist($a->user['uid'],true,$lastitem, true);
77         $total = count($contacts);
78         $visible_forums = 10;
79
80         if(count($contacts)) {
81
82                 $id = 0;
83
84                 foreach($contacts as $contact) {
85
86                         $entry = array(
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),
92                                 'id' => ++$id,
93                         );
94                         $entries[] = $entry;
95                 }
96
97                 $tpl = get_markup_template('widget_forumlist.tpl');
98
99                 $o .= replace_macros($tpl,array(
100                         '$title'        => t('Forums'),
101                         '$forums'       => $entries,
102                         '$link_desc'    => t('External link to forum'),
103                         '$total'        => $total,
104                         '$visible_forums' => $visible_forums,
105                         '$showmore'     => t('show more'),
106                 ));
107         }
108
109         return $o;
110 }
111
112 /**
113  * @brief Format forumlist as contact block
114  * 
115  * This function is used to show the forumlist in
116  * the advanced profile.
117  * 
118  * @param int $uid
119  * @return string
120  * 
121  */
122 function forumlist_profile_advanced($uid) {
123
124         $profile = intval(feature_enabled($uid,'forumlist_profile'));
125         if(! $profile)
126                 return;
127
128         $o = '';
129
130         // place holder in case somebody wants configurability
131         $show_total = 9999;
132
133         //don't sort by last updated item
134         $lastitem = false;
135
136         $contacts = get_forumlist($uid,false,$lastitem,false);
137
138         $total_shown = 0;
139
140         foreach($contacts as $contact) {
141                 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
142                 $total_shown ++;
143                 if($total_shown == $show_total)
144                         break;
145         }
146
147         if(count($contacts) > 0)
148                 $o .= $forumlist;
149                 return $o;
150 }
151
152 /**
153  * @brief count unread forum items
154  *
155  * Count unread items of connected forums and private groups
156  * 
157  * @return array
158  *      'id' => contact id
159  *      'name' => contact/forum name
160  *      'count' => counted unseen forum items
161  * 
162  */
163
164 function forums_count_unseen() {
165         $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(`item`.`unseen`) 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`
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` ",
173                 intval(local_user())
174         );
175
176         return $r;
177 }