3 * @file src/Content/ForumManager.php
4 * @brief ForumManager class with its methods related to forum functionality
6 namespace Friendica\Content;
9 use Friendica\Content\Feature;
10 use Friendica\Core\System;
11 use Friendica\Database\DBM;
15 * @brief This class handles methods related to the forum functionality
20 * @brief Function to list all forums a user is connected with
22 * @param int $uid of the profile owner
23 * @param boolean $lastitem Sort by lastitem
24 * @param boolean $showhidden Show frorums which are not hidden
25 * @param boolean $showprivate Show private groups
29 * 'name' => forum name
30 * 'id' => number of the key from the array
31 * 'micro' => contact photo in format micro
32 * 'thumb' => contact photo in format thumb
34 public static function getList($uid, $lastitem, $showhidden = true, $showprivate = false)
38 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
39 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
42 $select = '(`forum` OR `prv`)';
46 "SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb`
48 WHERE `network`= 'dfrn' AND $select AND `uid` = ?
49 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
50 AND `success_update` > `failure_update`
59 while ($contact = dba::fetch($contacts)) {
61 'url' => $contact['url'],
62 'name' => $contact['name'],
63 'id' => $contact['id'],
64 'micro' => $contact['micro'],
65 'thumb' => $contact['thumb'],
68 dba::close($contacts);
75 * @brief Forumlist widget
77 * Sidebar widget to show subcribed friendica forums. If activated
78 * in the settings, it appears at the notwork page sidebar
80 * @param int $uid The ID of the User
81 * @param int $cid The contact id which is used to mark a forum as "selected"
84 public static function widget($uid, $cid = 0)
86 if (! intval(Feature::isEnabled(local_user(), 'forumlist_widget'))) {
92 //sort by last updated item
95 $contacts = self::getList($uid, $lastitem, true, true);
96 $total = count($contacts);
99 if (DBM::is_result($contacts)) {
102 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(
122 '$title' => t('Forums'),
123 '$forums' => $entries,
124 '$link_desc' => t('External link to forum'),
126 '$visible_forums' => $visible_forums,
127 '$showmore' => t('show more'))
135 * @brief Format forumlist as contact block
137 * This function is used to show the forumlist in
138 * the advanced profile.
140 * @param int $uid The ID of the User
143 public static function profileAdvanced($uid)
145 $profile = intval(Feature::isEnabled($uid, 'forumlist_profile'));
152 // place holder in case somebody wants configurability
155 //don't sort by last updated item
158 $contacts = self::getList($uid, $lastitem, false, false);
162 foreach ($contacts as $contact) {
163 $forumlist .= micropro($contact, false, 'forumlist-profile-advanced');
165 if ($total_shown == $show_total) {
170 if (count($contacts) > 0) {
177 * @brief count unread forum items
179 * Count unread items of connected forums and private groups
183 * 'name' => contact/forum name
184 * 'count' => counted unseen forum items
186 public static function countUnseenItems()
189 "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
190 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
191 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
192 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
193 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
194 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
195 AND `contact`.`success_update` > `failure_update`
196 GROUP BY `contact`.`id` ",