]> git.mxchange.org Git - friendica.git/blob - include/forums.php
Merge remote-tracking branch 'upstream/develop' into 1511-forumlist-fix
[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                                 'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
91                                 'id' => ++$id,
92                         );
93                         $entries[] = $entry;
94                 }
95
96                 $tpl = get_markup_template('widget_forumlist.tpl');
97
98                 $o .= replace_macros($tpl,array(
99                         '$title'        => t('Forums'),
100                         '$forums'       => $entries,
101                         '$link_desc'    => t('External link to forum'),
102                         '$total'        => $total,
103                         '$visible_forums' => $visible_forums,
104                         '$showmore'     => t('show more'),
105                 ));
106         }
107
108         return $o;
109 }
110
111 /**
112  * @brief Format forumlist as contact block
113  * 
114  * This function is used to show the forumlist in
115  * the advanced profile.
116  * 
117  * @param int $uid
118  * @return string
119  * 
120  */
121 function forumlist_profile_advanced($uid) {
122
123         $profile = intval(feature_enabled($uid,'forumlist_profile'));
124         if(! $profile)
125                 return;
126
127         $o = '';
128
129         // place holder in case somebody wants configurability
130         $show_total = 9999;
131
132         //don't sort by last updated item
133         $lastitem = false;
134
135         $contacts = get_forumlist($uid,false,$lastitem,false);
136
137         $total_shown = 0;
138
139         foreach($contacts as $contact) {
140                 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
141                 $total_shown ++;
142                 if($total_shown == $show_total)
143                         break;
144         }
145
146         if(count($contacts) > 0)
147                 $o .= $forumlist;
148                 return $o;
149 }