3 * @file src/Content/ForumManager.php
4 * @brief ForumManager class with its methods related to forum functionality
6 namespace Friendica\Content;
9 use Friendica\Content\Feature;
10 use Friendica\Core\System;
11 use Friendica\Database\DBM;
14 require_once 'include/dba.php';
17 * @brief This class handles methods related to the forum functionality
22 * @brief 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
36 public static function getList($uid, $lastitem, $showhidden = true, $showprivate = false)
40 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
41 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
44 $select = '(`forum` OR `prv`)';
48 "SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb`
50 WHERE `network`= 'dfrn' AND $select AND `uid` = ?
51 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
52 AND `success_update` > `failure_update`
61 while ($contact = dba::fetch($contacts)) {
63 'url' => $contact['url'],
64 'name' => $contact['name'],
65 'id' => $contact['id'],
66 'micro' => $contact['micro'],
67 'thumb' => $contact['thumb'],
70 dba::close($contacts);
77 * @brief Forumlist widget
79 * Sidebar widget to show subcribed friendica forums. If activated
80 * in the settings, it appears at the notwork page sidebar
82 * @param int $uid The ID of the User
83 * @param int $cid The contact id which is used to mark a forum as "selected"
86 public static function widget($uid, $cid = 0)
88 if (! intval(Feature::isEnabled(local_user(), 'forumlist_widget'))) {
94 //sort by last updated item
97 $contacts = self::getList($uid, $lastitem, true, true);
98 $total = count($contacts);
101 if (DBM::is_result($contacts)) {
104 foreach ($contacts as $contact) {
105 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
108 'url' => 'network?f=&cid=' . $contact['id'],
109 'external_url' => 'redir/' . $contact['id'],
110 'name' => $contact['name'],
111 'cid' => $contact['id'],
112 'selected' => $selected,
113 'micro' => System::removedBaseUrl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
119 $tpl = get_markup_template('widget_forumlist.tpl');
121 $o .= replace_macros(
124 '$title' => t('Forums'),
125 '$forums' => $entries,
126 '$link_desc' => t('External link to forum'),
128 '$visible_forums' => $visible_forums,
129 '$showmore' => t('show more'))
137 * @brief Format forumlist as contact block
139 * This function is used to show the forumlist in
140 * the advanced profile.
142 * @param int $uid The ID of the User
145 public static function profileAdvanced($uid)
147 $profile = intval(Feature::isEnabled($uid, 'forumlist_profile'));
154 // place holder in case somebody wants configurability
157 //don't sort by last updated item
160 $contacts = self::getList($uid, $lastitem, false, false);
164 foreach ($contacts as $contact) {
165 $forumlist .= micropro($contact, false, 'forumlist-profile-advanced');
167 if ($total_shown == $show_total) {
172 if (count($contacts) > 0) {
179 * @brief count unread forum items
181 * Count unread items of connected forums and private groups
185 * 'name' => contact/forum name
186 * 'count' => counted unseen forum items
188 public static function countUnseenItems()
191 "SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
192 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
193 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
194 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
195 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
196 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
197 AND `contact`.`success_update` > `failure_update`
198 GROUP BY `contact`.`id` ",