]> git.mxchange.org Git - friendica.git/blob - include/ForumManager.php
Class file relocations
[friendica.git] / include / ForumManager.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5 use Friendica\Database\DBM;
6
7 /**
8  * @file include/ForumManager.php
9  * @brief ForumManager class with its methods related to forum functionality *
10  */
11
12 /**
13  * @brief This class handles metheods related to the forum functionality
14  */
15 class ForumManager {
16
17         /**
18          * @brief Function to list all forums a user is connected with
19          *
20          * @param int $uid of the profile owner
21          * @param boolean $showhidden
22          *      Show frorums which are not hidden
23          * @param boolean $lastitem
24          *      Sort by lastitem
25          * @param boolean $showprivate
26          *      Show private groups
27          *
28          * @returns array
29          *      'url'   => forum url
30          *      'name'  => forum name
31          *      'id'    => number of the key from the array
32          *      'micro' => contact photo in format micro
33          *      'thumb' => contact photo in format thumb
34          */
35         public static function get_list($uid, $showhidden = true, $lastitem, $showprivate = false) {
36
37                 $forumlist = array();
38
39                 $order = (($showhidden) ? '' : ' AND NOT `hidden` ');
40                 $order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
41                 $select = '`forum` ';
42                 if ($showprivate) {
43                         $select = '(`forum` OR `prv`)';
44                 }
45
46                 $contacts = dba::p("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro`, `contact`.`thumb` FROM `contact`
47                                 WHERE `network`= 'dfrn' AND $select AND `uid` = ?
48                                 AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
49                                 AND `success_update` > `failure_update`
50                                 $order ",
51                                 $uid
52                 );
53
54                 if (!$contacts)
55                         return($forumlist);
56
57                 while ($contact = dba::fetch($contacts)) {
58                         $forumlist[] = array(
59                                 'url'   => $contact['url'],
60                                 'name'  => $contact['name'],
61                                 'id'    => $contact['id'],
62                                 'micro' => $contact['micro'],
63                                 'thumb' => $contact['thumb'],
64                         );
65                 }
66                 dba::close($contacts);
67
68                 return($forumlist);
69         }
70
71
72         /**
73          * @brief Forumlist widget
74          *
75          * Sidebar widget to show subcribed friendica forums. If activated
76          * in the settings, it appears at the notwork page sidebar
77          *
78          * @param int $uid The ID of the User
79          * @param int $cid
80          *      The contact id which is used to mark a forum as "selected"
81          * @return string
82          */
83         public static function widget($uid,$cid = 0) {
84
85                 if(! intval(feature_enabled(local_user(),'forumlist_widget')))
86                         return;
87
88                 $o = '';
89
90                 //sort by last updated item
91                 $lastitem = true;
92
93                 $contacts = self::get_list($uid,true,$lastitem, true);
94                 $total = count($contacts);
95                 $visible_forums = 10;
96
97                 if (DBM::is_result($contacts)) {
98
99                         $id = 0;
100
101                         foreach($contacts as $contact) {
102
103                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
104
105                                 $entry = array(
106                                         'url' => 'network?f=&cid=' . $contact['id'],
107                                         'external_url' => 'redir/' . $contact['id'],
108                                         'name' => $contact['name'],
109                                         'cid' => $contact['id'],
110                                         'selected'      => $selected,
111                                         'micro' => System::removedBaseUrl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
112                                         'id' => ++$id,
113                                 );
114                                 $entries[] = $entry;
115                         }
116
117                         $tpl = get_markup_template('widget_forumlist.tpl');
118
119                         $o .= replace_macros($tpl,array(
120                                 '$title'        => t('Forums'),
121                                 '$forums'       => $entries,
122                                 '$link_desc'    => t('External link to forum'),
123                                 '$total'        => $total,
124                                 '$visible_forums' => $visible_forums,
125                                 '$showmore'     => t('show more'),
126                         ));
127                 }
128
129                 return $o;
130         }
131
132         /**
133          * @brief Format forumlist as contact block
134          *
135          * This function is used to show the forumlist in
136          * the advanced profile.
137          *
138          * @param int $uid The ID of the User
139          * @return string
140          *
141          */
142         public static function profile_advanced($uid) {
143
144                 $profile = intval(feature_enabled($uid,'forumlist_profile'));
145                 if(! $profile)
146                         return;
147
148                 $o = '';
149
150                 // place holder in case somebody wants configurability
151                 $show_total = 9999;
152
153                 //don't sort by last updated item
154                 $lastitem = false;
155
156                 $contacts = self::get_list($uid,false,$lastitem,false);
157
158                 $total_shown = 0;
159
160                 foreach($contacts as $contact) {
161                         $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
162                         $total_shown ++;
163                         if($total_shown == $show_total)
164                                 break;
165                 }
166
167                 if(count($contacts) > 0)
168                         $o .= $forumlist;
169                         return $o;
170         }
171
172         /**
173          * @brief count unread forum items
174          *
175          * Count unread items of connected forums and private groups
176          *
177          * @return array
178          *      'id' => contact id
179          *      'name' => contact/forum name
180          *      'count' => counted unseen forum items
181          *
182          */
183         public static function count_unseen_items() {
184                 $r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
185                                 INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
186                                 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
187                                 AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
188                                 AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
189                                 AND NOT `contact`.`pending` AND NOT `contact`.`archive`
190                                 AND `contact`.`success_update` > `failure_update`
191                                 GROUP BY `contact`.`id` ",
192                         intval(local_user())
193                 );
194
195                 return $r;
196         }
197
198 }