3 * @file src/Content/ForumManager.php
4 * @brief ForumManager class with its methods related to forum functionality
6 namespace Friendica\Content;
8 use Friendica\Core\Protocol;
9 use Friendica\Content\Feature;
10 use Friendica\Content\Text\HTML;
11 use Friendica\Core\L10n;
12 use Friendica\Core\Renderer;
13 use Friendica\Core\System;
14 use Friendica\Database\DBA;
15 use Friendica\Model\Contact;
16 use Friendica\Util\Proxy as ProxyUtils;
19 * @brief This class handles methods related to the forum functionality
24 * @brief Function to list all forums a user is connected with
26 * @param int $uid of the profile owner
27 * @param boolean $lastitem Sort by lastitem
28 * @param boolean $showhidden Show frorums which are not hidden
29 * @param boolean $showprivate Show private groups
33 * 'name' => forum name
34 * 'id' => number of the key from the array
35 * 'micro' => contact photo in format micro
36 * 'thumb' => contact photo in format thumb
38 public static function getList($uid, $lastitem, $showhidden = true, $showprivate = false)
41 $params = ['order' => ['last-item' => true]];
43 $params = ['order' => ['name']];
46 $condition_str = "`network` = ? AND `uid` = ? AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `success_update` > `failure_update` AND ";
49 $condition_str .= '(`forum` OR `prv`)';
51 $condition_str .= '`forum`';
55 $condition_str .= ' AND NOT `hidden`';
60 $fields = ['id', 'url', 'name', 'micro', 'thumb'];
61 $condition = [$condition_str, Protocol::DFRN, $uid];
62 $contacts = DBA::select('contact', $fields, $condition, $params);
67 while ($contact = DBA::fetch($contacts)) {
69 'url' => $contact['url'],
70 'name' => $contact['name'],
71 'id' => $contact['id'],
72 'micro' => $contact['micro'],
73 'thumb' => $contact['thumb'],
76 DBA::close($contacts);
83 * @brief Forumlist widget
85 * Sidebar widget to show subcribed friendica forums. If activated
86 * in the settings, it appears at the notwork page sidebar
88 * @param int $uid The ID of the User
89 * @param int $cid The contact id which is used to mark a forum as "selected"
92 public static function widget($uid, $cid = 0)
96 //sort by last updated item
99 $contacts = self::getList($uid, $lastitem, true, true);
100 $total = count($contacts);
101 $visible_forums = 10;
103 if (DBA::isResult($contacts)) {
106 foreach ($contacts as $contact) {
107 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
110 'url' => 'network?f=&cid=' . $contact['id'],
111 'external_url' => Contact::magicLink($contact['url']),
112 'name' => $contact['name'],
113 'cid' => $contact['id'],
114 'selected' => $selected,
115 'micro' => System::removedBaseUrl(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
121 $tpl = Renderer::getMarkupTemplate('widget_forumlist.tpl');
123 $o .= Renderer::replaceMacros(
126 '$title' => L10n::t('Forums'),
127 '$forums' => $entries,
128 '$link_desc' => L10n::t('External link to forum'),
130 '$visible_forums' => $visible_forums,
131 '$showmore' => L10n::t('show more')]
139 * @brief Format forumlist as contact block
141 * This function is used to show the forumlist in
142 * the advanced profile.
144 * @param int $uid The ID of the User
147 public static function profileAdvanced($uid)
149 $profile = intval(Feature::isEnabled($uid, 'forumlist_profile'));
156 // place holder in case somebody wants configurability
159 //don't sort by last updated item
162 $contacts = self::getList($uid, $lastitem, false, false);
166 foreach ($contacts as $contact) {
167 $forumlist .= HTML::micropro($contact, false, 'forumlist-profile-advanced');
169 if ($total_shown == $show_total) {
174 if (count($contacts) > 0) {
181 * @brief count unread forum items
183 * Count unread items of connected forums and private groups
187 * 'name' => contact/forum name
188 * 'count' => counted unseen forum items
190 public static function countUnseenItems()
193 "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
194 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
195 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
196 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
197 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
198 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
199 AND `contact`.`success_update` > `failure_update`
200 GROUP BY `contact`.`id` ",