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\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\System;
13 use Friendica\Database\DBA;
14 use Friendica\Model\Contact;
15 use Friendica\Util\Proxy as ProxyUtils;
17 require_once 'include/dba.php';
20 * @brief This class handles methods related to the forum functionality
25 * @brief Function to list all forums a user is connected with
27 * @param int $uid of the profile owner
28 * @param boolean $lastitem Sort by lastitem
29 * @param boolean $showhidden Show frorums which are not hidden
30 * @param boolean $showprivate Show private groups
34 * 'name' => forum name
35 * 'id' => number of the key from the array
36 * 'micro' => contact photo in format micro
37 * 'thumb' => contact photo in format thumb
39 public static function getList($uid, $lastitem, $showhidden = true, $showprivate = false)
42 $params = ['order' => ['last-item' => true]];
44 $params = ['order' => ['name']];
47 $condition_str = "`network` = ? AND `uid` = ? AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `success_update` > `failure_update` AND ";
50 $condition_str .= '(`forum` OR `prv`)';
52 $condition_str .= '`forum`';
56 $condition_str .= ' AND NOT `hidden`';
61 $fields = ['id', 'url', 'name', 'micro', 'thumb'];
62 $condition = [$condition_str, Protocol::DFRN, $uid];
63 $contacts = DBA::select('contact', $fields, $condition, $params);
68 while ($contact = DBA::fetch($contacts)) {
70 'url' => $contact['url'],
71 'name' => $contact['name'],
72 'id' => $contact['id'],
73 'micro' => $contact['micro'],
74 'thumb' => $contact['thumb'],
77 DBA::close($contacts);
84 * @brief Forumlist widget
86 * Sidebar widget to show subcribed friendica forums. If activated
87 * in the settings, it appears at the notwork page sidebar
89 * @param int $uid The ID of the User
90 * @param int $cid The contact id which is used to mark a forum as "selected"
93 public static function widget($uid, $cid = 0)
95 if (! intval(Feature::isEnabled(local_user(), 'forumlist_widget'))) {
101 //sort by last updated item
104 $contacts = self::getList($uid, $lastitem, true, true);
105 $total = count($contacts);
106 $visible_forums = 10;
108 if (DBA::isResult($contacts)) {
111 foreach ($contacts as $contact) {
112 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
115 'url' => 'network?f=&cid=' . $contact['id'],
116 'external_url' => Contact::magicLink($contact['url']),
117 'name' => $contact['name'],
118 'cid' => $contact['id'],
119 'selected' => $selected,
120 'micro' => System::removedBaseUrl(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
126 $tpl = get_markup_template('widget_forumlist.tpl');
128 $o .= Renderer::replaceMacros(
131 '$title' => L10n::t('Forums'),
132 '$forums' => $entries,
133 '$link_desc' => L10n::t('External link to forum'),
135 '$visible_forums' => $visible_forums,
136 '$showmore' => L10n::t('show more')]
144 * @brief Format forumlist as contact block
146 * This function is used to show the forumlist in
147 * the advanced profile.
149 * @param int $uid The ID of the User
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);
171 foreach ($contacts as $contact) {
172 $forumlist .= micropro($contact, false, 'forumlist-profile-advanced');
174 if ($total_shown == $show_total) {
179 if (count($contacts) > 0) {
186 * @brief count unread forum items
188 * Count unread items of connected forums and private groups
192 * 'name' => contact/forum name
193 * 'count' => counted unseen forum items
195 public static function countUnseenItems()
198 "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
199 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
200 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
201 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
202 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
203 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
204 AND `contact`.`success_update` > `failure_update`
205 GROUP BY `contact`.`id` ",