4 use Friendica\Core\System;
5 use Friendica\Database\DBM;
8 * @file include/ForumManager.php
9 * @brief ForumManager class with its methods related to forum functionality *
13 * @brief This class handles metheods related to the forum functionality
18 * @brief Function to list all forums a user is connected with
20 * @param int $uid of the profile owner
21 * @param boolean $showhidden
22 * Show frorums which are not hidden
23 * @param boolean $lastitem
25 * @param boolean $showprivate
30 * 'name' => forum name
31 * 'id' => number of the key from the array
32 * 'micro' => contact photo in format micro
33 * 'thumb' => contact photo in format thumb
35 public static function get_list($uid, $showhidden = true, $lastitem, $showprivate = false) {
39 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
40 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
43 $select = '(`forum` OR `prv`)';
46 $contacts = dba::p("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb` FROM `contact`
47 WHERE `network`= 'dfrn' AND $select AND `uid` = ?
48 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
49 AND `success_update` > `failure_update`
57 while ($contact = dba::fetch($contacts)) {
59 'url' => $contact['url'],
60 'name' => $contact['name'],
61 'id' => $contact['id'],
62 'micro' => $contact['micro'],
63 'thumb' => $contact['thumb'],
66 dba::close($contacts);
73 * @brief Forumlist widget
75 * Sidebar widget to show subcribed friendica forums. If activated
76 * in the settings, it appears at the notwork page sidebar
78 * @param int $uid The ID of the User
80 * The contact id which is used to mark a forum as "selected"
83 public static function widget($uid,$cid = 0) {
85 if(! intval(feature_enabled(local_user(),'forumlist_widget')))
90 //sort by last updated item
93 $contacts = self::get_list($uid,true,$lastitem, true);
94 $total = count($contacts);
97 if (DBM::is_result($contacts)) {
101 foreach($contacts as $contact) {
103 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
106 'url' => 'network?f=&cid=' . $contact['id'],
107 'external_url' => 'redir/' . $contact['id'],
108 'name' => $contact['name'],
109 'cid' => $contact['id'],
110 'selected' => $selected,
111 'micro' => System::removedBaseUrl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
117 $tpl = get_markup_template('widget_forumlist.tpl');
119 $o .= replace_macros($tpl,array(
120 '$title' => t('Forums'),
121 '$forums' => $entries,
122 '$link_desc' => t('External link to forum'),
124 '$visible_forums' => $visible_forums,
125 '$showmore' => t('show more'),
133 * @brief Format forumlist as contact block
135 * This function is used to show the forumlist in
136 * the advanced profile.
138 * @param int $uid The ID of the User
142 public static function profile_advanced($uid) {
144 $profile = intval(feature_enabled($uid,'forumlist_profile'));
150 // place holder in case somebody wants configurability
153 //don't sort by last updated item
156 $contacts = self::get_list($uid,false,$lastitem,false);
160 foreach($contacts as $contact) {
161 $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
163 if($total_shown == $show_total)
167 if(count($contacts) > 0)
173 * @brief count unread forum items
175 * Count unread items of connected forums and private groups
179 * 'name' => contact/forum name
180 * 'count' => counted unseen forum items
183 public static function count_unseen_items() {
184 $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
185 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
186 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
187 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
188 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
189 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
190 AND `contact`.`success_update` > `failure_update`
191 GROUP BY `contact`.`id` ",