3 * @file src/Content/ForumManager.php
4 * @brief ForumManager class with its methods related to forum functionality
6 namespace Friendica\Content;
8 use Friendica\Content\Feature;
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Contact;
13 use Friendica\Util\Proxy as ProxyUtils;
15 require_once 'include/dba.php';
18 * @brief This class handles methods related to the forum functionality
23 * @brief Function to list all forums a user is connected with
25 * @param int $uid of the profile owner
26 * @param boolean $lastitem Sort by lastitem
27 * @param boolean $showhidden Show frorums which are not hidden
28 * @param boolean $showprivate Show private groups
32 * 'name' => forum name
33 * 'id' => number of the key from the array
34 * 'micro' => contact photo in format micro
35 * 'thumb' => contact photo in format thumb
37 public static function getList($uid, $lastitem, $showhidden = true, $showprivate = false)
41 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
42 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
45 $select = '(`forum` OR `prv`)';
49 "SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb`
51 WHERE `network`= 'dfrn' AND $select AND `uid` = ?
52 AND NOT `blocked` AND NOT `pending` AND NOT `archive`
53 AND `success_update` > `failure_update`
62 while ($contact = DBA::fetch($contacts)) {
64 'url' => $contact['url'],
65 'name' => $contact['name'],
66 'id' => $contact['id'],
67 'micro' => $contact['micro'],
68 'thumb' => $contact['thumb'],
71 DBA::close($contacts);
78 * @brief Forumlist widget
80 * Sidebar widget to show subcribed friendica forums. If activated
81 * in the settings, it appears at the notwork page sidebar
83 * @param int $uid The ID of the User
84 * @param int $cid The contact id which is used to mark a forum as "selected"
87 public static function widget($uid, $cid = 0)
89 if (! intval(Feature::isEnabled(local_user(), 'forumlist_widget'))) {
95 //sort by last updated item
98 $contacts = self::getList($uid, $lastitem, true, true);
99 $total = count($contacts);
100 $visible_forums = 10;
102 if (DBA::isResult($contacts)) {
105 foreach ($contacts as $contact) {
106 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
109 'url' => 'network?f=&cid=' . $contact['id'],
110 'external_url' => Contact::magicLink($contact['url']),
111 'name' => $contact['name'],
112 'cid' => $contact['id'],
113 'selected' => $selected,
114 'micro' => System::removedBaseUrl(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
120 $tpl = get_markup_template('widget_forumlist.tpl');
122 $o .= replace_macros(
125 '$title' => L10n::t('Forums'),
126 '$forums' => $entries,
127 '$link_desc' => L10n::t('External link to forum'),
129 '$visible_forums' => $visible_forums,
130 '$showmore' => L10n::t('show more')]
138 * @brief Format forumlist as contact block
140 * This function is used to show the forumlist in
141 * the advanced profile.
143 * @param int $uid The ID of the User
146 public static function profileAdvanced($uid)
148 $profile = intval(Feature::isEnabled($uid, 'forumlist_profile'));
155 // place holder in case somebody wants configurability
158 //don't sort by last updated item
161 $contacts = self::getList($uid, $lastitem, false, false);
165 foreach ($contacts as $contact) {
166 $forumlist .= micropro($contact, false, 'forumlist-profile-advanced');
168 if ($total_shown == $show_total) {
173 if (count($contacts) > 0) {
180 * @brief count unread forum items
182 * Count unread items of connected forums and private groups
186 * 'name' => contact/forum name
187 * 'count' => counted unseen forum items
189 public static function countUnseenItems()
192 "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
193 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
194 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
195 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
196 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
197 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
198 AND `contact`.`success_update` > `failure_update`
199 GROUP BY `contact`.`id` ",