4 * @file include/ForumManager.php
5 * @brief ForumManager class with its methods related to forum functionality *
9 * @brief This class handles metheods related to the forum functionality
14 * @brief Function to list all forums a user is connected with
16 * @param int $uid of the profile owner
17 * @param boolean $showhidden
18 * Show frorums which are not hidden
19 * @param boolean $lastitem
21 * @param boolean $showprivate
26 * 'name' => forum name
27 * 'id' => number of the key from the array
28 * 'micro' => contact photo in format micro
30 public static function get_list($uid, $showhidden = true, $lastitem, $showprivate = false) {
34 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
35 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
38 $select = '(`forum` OR `prv`)';
41 $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
42 WHERE `network`= 'dfrn' AND $select AND `uid` = %d
43 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
44 AND `success_update` > `failure_update`
52 foreach($contacts as $contact) {
54 'url' => $contact['url'],
55 'name' => $contact['name'],
56 'id' => $contact['id'],
57 'micro' => $contact['micro'],
65 * @brief Forumlist widget
67 * Sidebar widget to show subcribed friendica forums. If activated
68 * in the settings, it appears at the notwork page sidebar
70 * @param int $uid The ID of the User
72 * The contact id which is used to mark a forum as "selected"
75 public static function widget($uid,$cid = 0) {
77 if(! intval(feature_enabled(local_user(),'forumlist_widget')))
82 //sort by last updated item
85 $contacts = self::get_list($uid,true,$lastitem, true);
86 $total = count($contacts);
89 if(count($contacts)) {
93 foreach($contacts as $contact) {
95 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
98 'url' => 'network?f=&cid=' . $contact['id'],
99 'external_url' => 'redir/' . $contact['id'],
100 'name' => $contact['name'],
101 'cid' => $contact['id'],
102 'selected' => $selected,
103 'micro' => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
109 $tpl = get_markup_template('widget_forumlist.tpl');
111 $o .= replace_macros($tpl,array(
112 '$title' => t('Forums'),
113 '$forums' => $entries,
114 '$link_desc' => t('External link to forum'),
116 '$visible_forums' => $visible_forums,
117 '$showmore' => t('show more'),
125 * @brief Format forumlist as contact block
127 * This function is used to show the forumlist in
128 * the advanced profile.
130 * @param int $uid The ID of the User
134 public static function profile_advanced($uid) {
136 $profile = intval(feature_enabled($uid,'forumlist_profile'));
142 // place holder in case somebody wants configurability
145 //don't sort by last updated item
148 $contacts = self::get_list($uid,false,$lastitem,false);
152 foreach($contacts as $contact) {
153 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
155 if($total_shown == $show_total)
159 if(count($contacts) > 0)
165 * @brief count unread forum items
167 * Count unread items of connected forums and private groups
171 * 'name' => contact/forum name
172 * 'count' => counted unseen forum items
175 public static function count_unseen_items() {
176 $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
177 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
178 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
179 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
180 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
181 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
182 AND `contact`.`success_update` > `failure_update`
183 GROUP BY `contact`.`id` ",