3 * @file src/Content/ForumManager.php
4 * ForumManager class with its methods related to forum functionality
6 namespace Friendica\Content;
8 use Friendica\Content\Text\HTML;
9 use Friendica\Core\Protocol;
10 use Friendica\Core\Renderer;
11 use Friendica\Database\DBA;
13 use Friendica\Model\Contact;
14 use Friendica\Util\Proxy as ProxyUtils;
17 * This class handles methods related to the forum functionality
22 * Function to list all forums a user is connected with
24 * @param int $uid of the profile owner
25 * @param boolean $lastitem Sort by lastitem
26 * @param boolean $showhidden Show frorums which are not hidden
27 * @param boolean $showprivate Show private groups
31 * 'name' => forum name
32 * 'id' => number of the key from the array
33 * 'micro' => contact photo in format micro
34 * 'thumb' => contact photo in format thumb
37 public static function getList($uid, $lastitem, $showhidden = true, $showprivate = false)
40 $params = ['order' => ['last-item' => true]];
42 $params = ['order' => ['name']];
45 $condition_str = "`network` IN (?, ?) AND `uid` = ? AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND ";
48 $condition_str .= '(`forum` OR `prv`)';
50 $condition_str .= '`forum`';
54 $condition_str .= ' AND NOT `hidden`';
59 $fields = ['id', 'url', 'name', 'micro', 'thumb'];
60 $condition = [$condition_str, Protocol::DFRN, Protocol::ACTIVITYPUB, $uid];
61 $contacts = DBA::select('contact', $fields, $condition, $params);
66 while ($contact = DBA::fetch($contacts)) {
68 'url' => $contact['url'],
69 'name' => $contact['name'],
70 'id' => $contact['id'],
71 'micro' => $contact['micro'],
72 'thumb' => $contact['thumb'],
75 DBA::close($contacts);
84 * Sidebar widget to show subcribed friendica forums. If activated
85 * in the settings, it appears at the notwork page sidebar
87 * @param int $uid The ID of the User
88 * @param int $cid The contact id which is used to mark a forum as "selected"
90 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
91 * @throws \ImagickException
93 public static function widget($uid, $cid = 0)
97 //sort by last updated item
100 $contacts = self::getList($uid, $lastitem, true, true);
101 $total = count($contacts);
102 $visible_forums = 10;
104 if (DBA::isResult($contacts)) {
109 foreach ($contacts as $contact) {
110 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
113 'url' => 'network?cid=' . $contact['id'],
114 'external_url' => Contact::magicLink($contact['url']),
115 'name' => $contact['name'],
116 'cid' => $contact['id'],
117 'selected' => $selected,
118 'micro' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
124 $tpl = Renderer::getMarkupTemplate('widget_forumlist.tpl');
126 $o .= Renderer::replaceMacros(
129 '$title' => DI::l10n()->t('Forums'),
130 '$forums' => $entries,
131 '$link_desc' => DI::l10n()->t('External link to forum'),
133 '$visible_forums' => $visible_forums,
134 '$showmore' => DI::l10n()->t('show more')]
142 * Format forumlist as contact block
144 * This function is used to show the forumlist in
145 * the advanced profile.
147 * @param int $uid The ID of the User
149 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
150 * @throws \ImagickException
152 public static function profileAdvanced($uid)
154 $profile = intval(Feature::isEnabled($uid, 'forumlist_profile'));
161 // place holder in case somebody wants configurability
164 //don't sort by last updated item
167 $contacts = self::getList($uid, $lastitem, false, false);
170 foreach ($contacts as $contact) {
171 $o .= HTML::micropro($contact, true, 'forumlist-profile-advanced');
173 if ($total_shown == $show_total) {
182 * count unread forum items
184 * Count unread items of connected forums and private groups
188 * 'name' => contact/forum name
189 * 'count' => counted unseen forum items
192 public static function countUnseenItems()
194 $stmtContacts = DBA::p(
195 "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
196 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
197 WHERE `item`.`uid` = ? AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
198 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
199 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
200 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
201 GROUP BY `contact`.`id` ",
205 return DBA::toArray($stmtContacts);