6 * @file include/ForumManager.php
7 * @brief ForumManager class with its methods related to forum functionality *
11 * @brief This class handles metheods related to the forum functionality
16 * @brief Function to list all forums a user is connected with
18 * @param int $uid of the profile owner
19 * @param boolean $showhidden
20 * Show frorums which are not hidden
21 * @param boolean $lastitem
23 * @param boolean $showprivate
28 * 'name' => forum name
29 * 'id' => number of the key from the array
30 * 'micro' => contact photo in format micro
31 * 'thumb' => contact photo in format thumb
33 public static function get_list($uid, $showhidden = true, $lastitem, $showprivate = false) {
37 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
38 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
41 $select = '(`forum` OR `prv`)';
44 $contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb` FROM `contact`
45 WHERE `network`= 'dfrn' AND $select AND `uid` = %d
46 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
47 AND `success_update` > `failure_update`
55 foreach($contacts as $contact) {
57 'url' => $contact['url'],
58 'name' => $contact['name'],
59 'id' => $contact['id'],
60 'micro' => $contact['micro'],
61 'thumb' => $contact['thumb'],
69 * @brief Forumlist widget
71 * Sidebar widget to show subcribed friendica forums. If activated
72 * in the settings, it appears at the notwork page sidebar
74 * @param int $uid The ID of the User
76 * The contact id which is used to mark a forum as "selected"
79 public static function widget($uid,$cid = 0) {
81 if(! intval(feature_enabled(local_user(),'forumlist_widget')))
86 //sort by last updated item
89 $contacts = self::get_list($uid,true,$lastitem, true);
90 $total = count($contacts);
93 if (dbm::is_result($contacts)) {
97 foreach($contacts as $contact) {
99 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
102 'url' => 'network?f=&cid=' . $contact['id'],
103 'external_url' => 'redir/' . $contact['id'],
104 'name' => $contact['name'],
105 'cid' => $contact['id'],
106 'selected' => $selected,
107 'micro' => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
113 $tpl = get_markup_template('widget_forumlist.tpl');
115 $o .= replace_macros($tpl,array(
116 '$title' => t('Forums'),
117 '$forums' => $entries,
118 '$link_desc' => t('External link to forum'),
120 '$visible_forums' => $visible_forums,
121 '$showmore' => t('show more'),
129 * @brief Format forumlist as contact block
131 * This function is used to show the forumlist in
132 * the advanced profile.
134 * @param int $uid The ID of the User
138 public static function profile_advanced($uid) {
140 $profile = intval(feature_enabled($uid,'forumlist_profile'));
146 // place holder in case somebody wants configurability
149 //don't sort by last updated item
152 $contacts = self::get_list($uid,false,$lastitem,false);
156 foreach($contacts as $contact) {
157 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
159 if($total_shown == $show_total)
163 if(count($contacts) > 0)
169 * @brief count unread forum items
171 * Count unread items of connected forums and private groups
175 * 'name' => contact/forum name
176 * 'count' => counted unseen forum items
179 public static function count_unseen_items() {
180 $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
181 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
182 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
183 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
184 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
185 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
186 AND `contact`.`success_update` > `failure_update`
187 GROUP BY `contact`.`id` ",