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 = dba::p("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb` FROM `contact`
45 WHERE `network`= 'dfrn' AND $select AND `uid` = ?
46 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
47 AND `success_update` > `failure_update`
55 while ($contact = dba::fetch($contacts)) {
57 'url' => $contact['url'],
58 'name' => $contact['name'],
59 'id' => $contact['id'],
60 'micro' => $contact['micro'],
61 'thumb' => $contact['thumb'],
64 dba::close($contacts);
71 * @brief Forumlist widget
73 * Sidebar widget to show subcribed friendica forums. If activated
74 * in the settings, it appears at the notwork page sidebar
76 * @param int $uid The ID of the User
78 * The contact id which is used to mark a forum as "selected"
81 public static function widget($uid,$cid = 0) {
83 if(! intval(feature_enabled(local_user(),'forumlist_widget')))
88 //sort by last updated item
91 $contacts = self::get_list($uid,true,$lastitem, true);
92 $total = count($contacts);
95 if (dbm::is_result($contacts)) {
99 foreach($contacts as $contact) {
101 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
104 'url' => 'network?f=&cid=' . $contact['id'],
105 'external_url' => 'redir/' . $contact['id'],
106 'name' => $contact['name'],
107 'cid' => $contact['id'],
108 'selected' => $selected,
109 'micro' => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
115 $tpl = get_markup_template('widget_forumlist.tpl');
117 $o .= replace_macros($tpl,array(
118 '$title' => t('Forums'),
119 '$forums' => $entries,
120 '$link_desc' => t('External link to forum'),
122 '$visible_forums' => $visible_forums,
123 '$showmore' => t('show more'),
131 * @brief Format forumlist as contact block
133 * This function is used to show the forumlist in
134 * the advanced profile.
136 * @param int $uid The ID of the User
140 public static function profile_advanced($uid) {
142 $profile = intval(feature_enabled($uid,'forumlist_profile'));
148 // place holder in case somebody wants configurability
151 //don't sort by last updated item
154 $contacts = self::get_list($uid,false,$lastitem,false);
158 foreach($contacts as $contact) {
159 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
161 if($total_shown == $show_total)
165 if(count($contacts) > 0)
171 * @brief count unread forum items
173 * Count unread items of connected forums and private groups
177 * 'name' => contact/forum name
178 * 'count' => counted unseen forum items
181 public static function count_unseen_items() {
182 $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
183 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
184 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
185 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
186 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
187 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
188 AND `contact`.`success_update` > `failure_update`
189 GROUP BY `contact`.`id` ",