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
29 * 'thumb' => contact photo in format thumb
31 public static function get_list($uid, $showhidden = true, $lastitem, $showprivate = false) {
35 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
36 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
39 $select = '(`forum` OR `prv`)';
42 $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb` FROM `contact`
43 WHERE `network`= 'dfrn' AND $select AND `uid` = %d
44 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
45 AND `success_update` > `failure_update`
53 foreach($contacts as $contact) {
55 'url' => $contact['url'],
56 'name' => $contact['name'],
57 'id' => $contact['id'],
58 'micro' => $contact['micro'],
59 'thumb' => $contact['thumb'],
67 * @brief Forumlist widget
69 * Sidebar widget to show subcribed friendica forums. If activated
70 * in the settings, it appears at the notwork page sidebar
72 * @param int $uid The ID of the User
74 * The contact id which is used to mark a forum as "selected"
77 public static function widget($uid,$cid = 0) {
79 if(! intval(feature_enabled(local_user(),'forumlist_widget')))
84 //sort by last updated item
87 $contacts = self::get_list($uid,true,$lastitem, true);
88 $total = count($contacts);
91 if(dbm::is_result($contacts)) {
95 foreach($contacts as $contact) {
97 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
100 'url' => 'network?f=&cid=' . $contact['id'],
101 'external_url' => 'redir/' . $contact['id'],
102 'name' => $contact['name'],
103 'cid' => $contact['id'],
104 'selected' => $selected,
105 'micro' => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
111 $tpl = get_markup_template('widget_forumlist.tpl');
113 $o .= replace_macros($tpl,array(
114 '$title' => t('Forums'),
115 '$forums' => $entries,
116 '$link_desc' => t('External link to forum'),
118 '$visible_forums' => $visible_forums,
119 '$showmore' => t('show more'),
127 * @brief Format forumlist as contact block
129 * This function is used to show the forumlist in
130 * the advanced profile.
132 * @param int $uid The ID of the User
136 public static function profile_advanced($uid) {
138 $profile = intval(feature_enabled($uid,'forumlist_profile'));
144 // place holder in case somebody wants configurability
147 //don't sort by last updated item
150 $contacts = self::get_list($uid,false,$lastitem,false);
154 foreach($contacts as $contact) {
155 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
157 if($total_shown == $show_total)
161 if(count($contacts) > 0)
167 * @brief count unread forum items
169 * Count unread items of connected forums and private groups
173 * 'name' => contact/forum name
174 * 'count' => counted unseen forum items
177 public static function count_unseen_items() {
178 $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
179 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
180 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
181 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
182 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
183 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
184 AND `contact`.`success_update` > `failure_update`
185 GROUP BY `contact`.`id` ",