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;
18 require_once 'include/dba.php';
21 * @brief This class handles methods related to the forum functionality
26 * @brief Function to list all forums a user is connected with
28 * @param int $uid of the profile owner
29 * @param boolean $lastitem Sort by lastitem
30 * @param boolean $showhidden Show frorums which are not hidden
31 * @param boolean $showprivate Show private groups
35 * 'name' => forum name
36 * 'id' => number of the key from the array
37 * 'micro' => contact photo in format micro
38 * 'thumb' => contact photo in format thumb
40 public static function getList($uid, $lastitem, $showhidden = true, $showprivate = false)
43 $params = ['order' => ['last-item' => true]];
45 $params = ['order' => ['name']];
48 $condition_str = "`network` = ? AND `uid` = ? AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `success_update` > `failure_update` AND ";
51 $condition_str .= '(`forum` OR `prv`)';
53 $condition_str .= '`forum`';
57 $condition_str .= ' AND NOT `hidden`';
62 $fields = ['id', 'url', 'name', 'micro', 'thumb'];
63 $condition = [$condition_str, Protocol::DFRN, $uid];
64 $contacts = DBA::select('contact', $fields, $condition, $params);
69 while ($contact = DBA::fetch($contacts)) {
71 'url' => $contact['url'],
72 'name' => $contact['name'],
73 'id' => $contact['id'],
74 'micro' => $contact['micro'],
75 'thumb' => $contact['thumb'],
78 DBA::close($contacts);
85 * @brief Forumlist widget
87 * Sidebar widget to show subcribed friendica forums. If activated
88 * in the settings, it appears at the notwork page sidebar
90 * @param int $uid The ID of the User
91 * @param int $cid The contact id which is used to mark a forum as "selected"
94 public static function widget($uid, $cid = 0)
98 //sort by last updated item
101 $contacts = self::getList($uid, $lastitem, true, true);
102 $total = count($contacts);
103 $visible_forums = 10;
105 if (DBA::isResult($contacts)) {
108 foreach ($contacts as $contact) {
109 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
112 'url' => 'network?f=&cid=' . $contact['id'],
113 'external_url' => Contact::magicLink($contact['url']),
114 'name' => $contact['name'],
115 'cid' => $contact['id'],
116 'selected' => $selected,
117 'micro' => System::removedBaseUrl(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
123 $tpl = Renderer::getMarkupTemplate('widget_forumlist.tpl');
125 $o .= Renderer::replaceMacros(
128 '$title' => L10n::t('Forums'),
129 '$forums' => $entries,
130 '$link_desc' => L10n::t('External link to forum'),
132 '$visible_forums' => $visible_forums,
133 '$showmore' => L10n::t('show more')]
141 * @brief Format forumlist as contact block
143 * This function is used to show the forumlist in
144 * the advanced profile.
146 * @param int $uid The ID of the User
149 public static function profileAdvanced($uid)
151 $profile = intval(Feature::isEnabled($uid, 'forumlist_profile'));
158 // place holder in case somebody wants configurability
161 //don't sort by last updated item
164 $contacts = self::getList($uid, $lastitem, false, false);
168 foreach ($contacts as $contact) {
169 $forumlist .= HTML::micropro($contact, false, 'forumlist-profile-advanced');
171 if ($total_shown == $show_total) {
176 if (count($contacts) > 0) {
183 * @brief count unread forum items
185 * Count unread items of connected forums and private groups
189 * 'name' => contact/forum name
190 * 'count' => counted unseen forum items
192 public static function countUnseenItems()
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` = %d 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 AND `contact`.`success_update` > `failure_update`
202 GROUP BY `contact`.`id` ",