]> git.mxchange.org Git - friendica.git/blob - include/forums.php
forumlist: oh forgot to raise $visible_forums after testing
[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 `hidden` = 0 ');
31         $order .= (($lastitem) ? ' ORDER BY `last-item` ASC ' : ' ORDER BY `name` ASC ');
32         $select = '`forum` = 1';
33         if ($showprivate) {
34                 $select = '( `forum` = 1 OR `prv` = 1 )';
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 `blocked` = 0 AND `hidden` = 0 AND `pending` = 0 AND `archive` = 0
40                         $order ",
41                         intval($uid)
42         );
43
44         foreach($contacts as $contact) {
45                 $forumlist[] = array(
46                         'url'   => $contact['url'],
47                         'name'  => $contact['name'],
48                         'id'    => $contact['id'],
49                         'micro' => $contact['micro'],
50                 );
51         }
52         return($forumlist);
53 }
54
55
56 /**
57  * @brief Forumlist widget
58  * 
59  * Sidebar widget to show subcribed friendica forums. If activated
60  * in the settings, it appears at the notwork page sidebar
61  * 
62  * @param App $a
63  * @return string
64  */
65 function widget_forumlist($a) {
66
67         if(! intval(feature_enabled(local_user(),'forumlist_widget')))
68                 return;
69
70         $o = '';
71
72         //sort by last updated item
73         $lastitem = true;
74
75         $contacts = get_forumlist($a->user['uid'],true,$lastitem, true);
76         $total = count($contacts);
77         $visible_forums = 10;
78
79         if(count($contacts)) {
80
81                 $id = 0;
82
83                 foreach($contacts as $contact) {
84
85                         $entry = array(
86                                 'url' => $a->get_baseurl() . '/network?f=&cid=' . $contact['id'],
87                                 'external_url' => $a->get_baseurl() . '/redir/' . $contact['id'],
88                                 'name' => $contact['name'],
89                                 'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
90                                 'id' => ++$id,
91                         );
92                         $entries[] = $entry;
93                 }
94
95                 $tpl = get_markup_template('widget_forumlist.tpl');
96
97                 $o .= replace_macros($tpl,array(
98                         '$title'        => t('Forums'),
99                         '$forums'       => $entries,
100                         '$link_desc'    => t('External link to forum'),
101                         '$total'        => $total,
102                         '$visible_forums' => $visible_forums,
103                         '$showmore'     => t('show more'),
104                 ));
105         }
106
107         return $o;
108 }
109
110 /**
111  * @brief Format forumlist as contact block
112  * 
113  * This function is used to show the forumlist in
114  * the advanced profile.
115  * 
116  * @param int $uid
117  * @return string
118  * 
119  */
120 function forumlist_profile_advanced($uid) {
121
122         $profile = intval(feature_enabled($uid,'forumlist_profile'));
123         if(! $profile)
124                 return;
125
126         $o = '';
127
128         // place holder in case somebody wants configurability
129         $show_total = 9999;
130
131         //don't sort by last updated item
132         $lastitem = false;
133
134         $contacts = get_forumlist($uid,false,$lastitem,false);
135
136         $total_shown = 0;
137
138         foreach($contacts as $contact) {
139                 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
140                 $total_shown ++;
141                 if($total_shown == $show_total)
142                         break;
143         }
144
145         if(count($contacts) > 0)
146                 $o .= $forumlist;
147                 return $o;
148 }