3 * @file src/Content/ForumManager.php
4 * @brief ForumManager class with its methods related to forum functionality
6 namespace Friendica\Content;
9 use Friendica\Core\System;
10 use Friendica\Database\DBM;
14 * @brief This class handles methods related to the forum functionality
19 * @brief Function to list all forums a user is connected with
21 * @param int $uid of the profile owner
22 * @param boolean $lastitem Sort by lastitem
23 * @param boolean $showhidden Show frorums which are not hidden
24 * @param boolean $showprivate Show private groups
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 getList($uid, $lastitem, $showhidden = true, $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`)';
45 "SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb`
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`
58 while ($contact = dba::fetch($contacts)) {
60 'url' => $contact['url'],
61 'name' => $contact['name'],
62 'id' => $contact['id'],
63 'micro' => $contact['micro'],
64 'thumb' => $contact['thumb'],
67 dba::close($contacts);
74 * @brief Forumlist widget
76 * Sidebar widget to show subcribed friendica forums. If activated
77 * in the settings, it appears at the notwork page sidebar
79 * @param int $uid The ID of the User
80 * @param int $cid 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'))) {
91 //sort by last updated item
94 $contacts = self::getList($uid, $lastitem, true, true);
95 $total = count($contacts);
98 if (DBM::is_result($contacts)) {
101 foreach ($contacts as $contact) {
102 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
105 'url' => 'network?f=&cid=' . $contact['id'],
106 'external_url' => 'redir/' . $contact['id'],
107 'name' => $contact['name'],
108 'cid' => $contact['id'],
109 'selected' => $selected,
110 'micro' => System::removedBaseUrl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
116 $tpl = get_markup_template('widget_forumlist.tpl');
118 $o .= replace_macros(
121 '$title' => t('Forums'),
122 '$forums' => $entries,
123 '$link_desc' => t('External link to forum'),
125 '$visible_forums' => $visible_forums,
126 '$showmore' => t('show more'))
134 * @brief Format forumlist as contact block
136 * This function is used to show the forumlist in
137 * the advanced profile.
139 * @param int $uid The ID of the User
142 public static function profileAdvanced($uid)
144 $profile = intval(feature_enabled($uid, 'forumlist_profile'));
151 // place holder in case somebody wants configurability
154 //don't sort by last updated item
157 $contacts = self::getList($uid, $lastitem, false, false);
161 foreach ($contacts as $contact) {
162 $forumlist .= micropro($contact, false, 'forumlist-profile-advanced');
164 if ($total_shown == $show_total) {
169 if (count($contacts) > 0) {
176 * @brief count unread forum items
178 * Count unread items of connected forums and private groups
182 * 'name' => contact/forum name
183 * 'count' => counted unseen forum items
185 public static function countUnseenItems()
188 "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
189 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
190 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
191 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
192 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
193 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
194 AND `contact`.`success_update` > `failure_update`
195 GROUP BY `contact`.`id` ",