|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
use Chamilo\CourseBundle\Entity\CForumPost; |
|
5
|
|
|
use Chamilo\CourseBundle\Entity\CForumThread; |
|
6
|
|
|
use ChamiloSession as Session; |
|
7
|
|
|
use Zend\Feed\Reader\Entry\Rss; |
|
8
|
|
|
use Zend\Feed\Reader\Reader; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class SocialManager. |
|
12
|
|
|
* |
|
13
|
|
|
* This class provides methods for the social network management. |
|
14
|
|
|
* Include/require it in your code to use its features. |
|
15
|
|
|
* |
|
16
|
|
|
* @package chamilo.social |
|
17
|
|
|
*/ |
|
18
|
|
|
class SocialManager extends UserManager |
|
19
|
|
|
{ |
|
20
|
|
|
const DEFAULT_WALL_POSTS = 10; |
|
21
|
|
|
const DEFAULT_SCROLL_NEW_POST = 5; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Constructor. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct() |
|
27
|
|
|
{ |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Allow to see contacts list. |
|
32
|
|
|
* |
|
33
|
|
|
* @author isaac flores paz |
|
34
|
|
|
* |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function show_list_type_friends() |
|
38
|
|
|
{ |
|
39
|
|
|
$table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
|
40
|
|
|
$sql = 'SELECT id, title FROM '.$table.' |
|
41
|
|
|
WHERE id<>6 |
|
42
|
|
|
ORDER BY id ASC'; |
|
43
|
|
|
$result = Database::query($sql); |
|
44
|
|
|
$friend_relation_list = []; |
|
45
|
|
|
while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
46
|
|
|
$friend_relation_list[] = $row; |
|
47
|
|
|
} |
|
48
|
|
|
$count_list = count($friend_relation_list); |
|
49
|
|
|
if ($count_list == 0) { |
|
50
|
|
|
$friend_relation_list[] = get_lang('Unknown'); |
|
51
|
|
|
} else { |
|
52
|
|
|
return $friend_relation_list; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the kind of relation between contacts. |
|
58
|
|
|
* |
|
59
|
|
|
* @param int user id |
|
60
|
|
|
* @param int user friend id |
|
61
|
|
|
* @param string |
|
62
|
|
|
* |
|
63
|
|
|
* @return int |
|
64
|
|
|
* |
|
65
|
|
|
* @author isaac flores paz |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function get_relation_between_contacts($user_id, $user_friend) |
|
68
|
|
|
{ |
|
69
|
|
|
$table = Database::get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE); |
|
70
|
|
|
$userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
|
71
|
|
|
$sql = 'SELECT rt.id as id |
|
72
|
|
|
FROM '.$table.' rt |
|
73
|
|
|
WHERE rt.id = ( |
|
74
|
|
|
SELECT uf.relation_type |
|
75
|
|
|
FROM '.$userRelUserTable.' uf |
|
76
|
|
|
WHERE |
|
77
|
|
|
user_id='.((int) $user_id).' AND |
|
78
|
|
|
friend_user_id='.((int) $user_friend).' AND |
|
79
|
|
|
uf.relation_type <> '.USER_RELATION_TYPE_RRHH.' |
|
80
|
|
|
LIMIT 1 |
|
81
|
|
|
)'; |
|
82
|
|
|
$res = Database::query($sql); |
|
83
|
|
|
if (Database::num_rows($res) > 0) { |
|
84
|
|
|
$row = Database::fetch_array($res, 'ASSOC'); |
|
85
|
|
|
|
|
86
|
|
|
return $row['id']; |
|
87
|
|
|
} else { |
|
88
|
|
|
return USER_UNKNOWN; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get count of friends from user. |
|
94
|
|
|
* |
|
95
|
|
|
* @param int $userId |
|
96
|
|
|
* |
|
97
|
|
|
* @return int |
|
98
|
|
|
*/ |
|
99
|
|
|
public static function getCountFriends($userId) |
|
100
|
|
|
{ |
|
101
|
|
|
$table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
|
102
|
|
|
$userId = (int) $userId; |
|
103
|
|
|
if (empty($userId)) { |
|
104
|
|
|
return 0; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$sql = 'SELECT count(friend_user_id) count |
|
108
|
|
|
FROM '.$table.' |
|
109
|
|
|
WHERE |
|
110
|
|
|
relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
|
111
|
|
|
friend_user_id<>'.$userId.' AND |
|
112
|
|
|
user_id='.$userId; |
|
113
|
|
|
$res = Database::query($sql); |
|
114
|
|
|
if (Database::num_rows($res)) { |
|
115
|
|
|
$row = Database::fetch_array($res, 'ASSOC'); |
|
116
|
|
|
|
|
117
|
|
|
return (int) $row['count']; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return 0; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Gets friends id list. |
|
125
|
|
|
* |
|
126
|
|
|
* @param int user id |
|
127
|
|
|
* @param int group id |
|
128
|
|
|
* @param string name to search |
|
129
|
|
|
* @param bool true will load firstname, lastname, and image name |
|
130
|
|
|
* |
|
131
|
|
|
* @return array |
|
132
|
|
|
* |
|
133
|
|
|
* @author Julio Montoya <[email protected]> Cleaning code, function renamed, $load_extra_info option added |
|
134
|
|
|
* @author isaac flores paz |
|
135
|
|
|
*/ |
|
136
|
|
|
public static function get_friends( |
|
137
|
|
|
$user_id, |
|
138
|
|
|
$id_group = null, |
|
139
|
|
|
$search_name = null, |
|
140
|
|
|
$load_extra_info = true |
|
141
|
|
|
) { |
|
142
|
|
|
$user_id = (int) $user_id; |
|
143
|
|
|
|
|
144
|
|
|
$tbl_my_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
|
145
|
|
|
$tbl_my_user = Database::get_main_table(TABLE_MAIN_USER); |
|
146
|
|
|
$sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.' |
|
147
|
|
|
WHERE |
|
148
|
|
|
relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND |
|
149
|
|
|
friend_user_id<>'.$user_id.' AND |
|
150
|
|
|
user_id='.$user_id; |
|
151
|
|
|
if (isset($id_group) && $id_group > 0) { |
|
152
|
|
|
$sql .= ' AND relation_type='.$id_group; |
|
153
|
|
|
} |
|
154
|
|
|
if (isset($search_name)) { |
|
155
|
|
|
$search_name = trim($search_name); |
|
156
|
|
|
$search_name = str_replace(' ', '', $search_name); |
|
157
|
|
|
$sql .= ' AND friend_user_id IN ( |
|
158
|
|
|
SELECT user_id FROM '.$tbl_my_user.' |
|
159
|
|
|
WHERE |
|
160
|
|
|
firstName LIKE "%'.Database::escape_string($search_name).'%" OR |
|
161
|
|
|
lastName LIKE "%'.Database::escape_string($search_name).'%" OR |
|
162
|
|
|
'.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' LIKE concat("%","'.Database::escape_string($search_name).'","%") |
|
163
|
|
|
) '; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$res = Database::query($sql); |
|
167
|
|
|
$list = []; |
|
168
|
|
|
while ($row = Database::fetch_array($res, 'ASSOC')) { |
|
169
|
|
|
if ($load_extra_info) { |
|
170
|
|
|
$userInfo = api_get_user_info($row['friend_user_id']); |
|
171
|
|
|
$list[] = [ |
|
172
|
|
|
'friend_user_id' => $row['friend_user_id'], |
|
173
|
|
|
'firstName' => $userInfo['firstName'], |
|
174
|
|
|
'lastName' => $userInfo['lastName'], |
|
175
|
|
|
'username' => $userInfo['username'], |
|
176
|
|
|
'image' => $userInfo['avatar'], |
|
177
|
|
|
'user_info' => $userInfo, |
|
178
|
|
|
]; |
|
179
|
|
|
} else { |
|
180
|
|
|
$list[] = $row; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
return $list; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* get web path of user invitate. |
|
189
|
|
|
* |
|
190
|
|
|
* @author isaac flores paz |
|
191
|
|
|
* @author Julio Montoya setting variable array |
|
192
|
|
|
* |
|
193
|
|
|
* @param int user id |
|
194
|
|
|
* |
|
195
|
|
|
* @return array |
|
196
|
|
|
*/ |
|
197
|
|
|
public static function get_list_web_path_user_invitation_by_user_id($user_id) |
|
198
|
|
|
{ |
|
199
|
|
|
$list_ids = self::get_list_invitation_of_friends_by_user_id($user_id); |
|
200
|
|
|
$list = []; |
|
201
|
|
|
foreach ($list_ids as $values_ids) { |
|
202
|
|
|
$list[] = UserManager::get_user_picture_path_by_id( |
|
|
|
|
|
|
203
|
|
|
$values_ids['user_sender_id'], |
|
204
|
|
|
'web' |
|
205
|
|
|
); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
return $list; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Sends an invitation to contacts. |
|
213
|
|
|
* |
|
214
|
|
|
* @param int user id |
|
215
|
|
|
* @param int user friend id |
|
216
|
|
|
* @param string title of the message |
|
217
|
|
|
* @param string content of the message |
|
218
|
|
|
* |
|
219
|
|
|
* @return bool |
|
220
|
|
|
* |
|
221
|
|
|
* @author isaac flores paz |
|
222
|
|
|
* @author Julio Montoya <[email protected]> Cleaning code |
|
223
|
|
|
*/ |
|
224
|
|
|
public static function send_invitation_friend( |
|
225
|
|
|
$user_id, |
|
226
|
|
|
$friend_id, |
|
227
|
|
|
$message_title, |
|
228
|
|
|
$message_content |
|
229
|
|
|
) { |
|
230
|
|
|
$tbl_message = Database::get_main_table(TABLE_MESSAGE); |
|
231
|
|
|
$user_id = (int) $user_id; |
|
232
|
|
|
$friend_id = (int) $friend_id; |
|
233
|
|
|
|
|
234
|
|
|
//Just in case we replace the and \n and \n\r while saving in the DB |
|
235
|
|
|
$message_content = str_replace(["\n", "\n\r"], '<br />', $message_content); |
|
236
|
|
|
|
|
237
|
|
|
$clean_message_content = Database::escape_string($message_content); |
|
238
|
|
|
$now = api_get_utc_datetime(); |
|
239
|
|
|
$sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.' |
|
240
|
|
|
WHERE |
|
241
|
|
|
user_sender_id='.$user_id.' AND |
|
242
|
|
|
user_receiver_id='.$friend_id.' AND |
|
243
|
|
|
msg_status IN('.MESSAGE_STATUS_INVITATION_PENDING.', '.MESSAGE_STATUS_INVITATION_ACCEPTED.', '.MESSAGE_STATUS_INVITATION_DENIED.'); |
|
244
|
|
|
'; |
|
245
|
|
|
$res_exist = Database::query($sql); |
|
246
|
|
|
$row_exist = Database::fetch_array($res_exist, 'ASSOC'); |
|
247
|
|
|
|
|
248
|
|
|
if ($row_exist['count'] == 0) { |
|
249
|
|
|
$params = [ |
|
250
|
|
|
'user_sender_id' => $user_id, |
|
251
|
|
|
'user_receiver_id' => $friend_id, |
|
252
|
|
|
'msg_status' => MESSAGE_STATUS_INVITATION_PENDING, |
|
253
|
|
|
'send_date' => $now, |
|
254
|
|
|
'title' => $message_title, |
|
255
|
|
|
'content' => $message_content, |
|
256
|
|
|
'group_id' => 0, |
|
257
|
|
|
'parent_id' => 0, |
|
258
|
|
|
'update_date' => $now, |
|
259
|
|
|
]; |
|
260
|
|
|
$messageId = Database::insert($tbl_message, $params); |
|
261
|
|
|
|
|
262
|
|
|
$senderInfo = api_get_user_info($user_id); |
|
263
|
|
|
$notification = new Notification(); |
|
264
|
|
|
$notification->saveNotification( |
|
265
|
|
|
$messageId, |
|
|
|
|
|
|
266
|
|
|
Notification::NOTIFICATION_TYPE_INVITATION, |
|
267
|
|
|
[$friend_id], |
|
268
|
|
|
$message_title, |
|
269
|
|
|
$message_content, |
|
270
|
|
|
$senderInfo |
|
|
|
|
|
|
271
|
|
|
); |
|
272
|
|
|
|
|
273
|
|
|
return true; |
|
274
|
|
|
} else { |
|
275
|
|
|
// invitation already exist |
|
276
|
|
|
$sql = 'SELECT COUNT(*) AS count, id FROM '.$tbl_message.' |
|
277
|
|
|
WHERE |
|
278
|
|
|
user_sender_id='.$user_id.' AND |
|
279
|
|
|
user_receiver_id='.$friend_id.' AND |
|
280
|
|
|
msg_status = 7'; |
|
281
|
|
|
$res_if_exist = Database::query($sql); |
|
282
|
|
|
$row_if_exist = Database::fetch_array($res_if_exist, 'ASSOC'); |
|
283
|
|
|
if ($row_if_exist['count'] == 1) { |
|
284
|
|
|
$sql = 'UPDATE '.$tbl_message.' SET |
|
285
|
|
|
msg_status = 5, content = "'.$clean_message_content.'" |
|
286
|
|
|
WHERE |
|
287
|
|
|
user_sender_id='.$user_id.' AND |
|
288
|
|
|
user_receiver_id='.$friend_id.' AND |
|
289
|
|
|
msg_status = 7 '; |
|
290
|
|
|
Database::query($sql); |
|
291
|
|
|
|
|
292
|
|
|
return true; |
|
293
|
|
|
} else { |
|
294
|
|
|
return false; |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* Get number messages of the inbox. |
|
301
|
|
|
* |
|
302
|
|
|
* @author isaac flores paz |
|
303
|
|
|
* |
|
304
|
|
|
* @param int $userId user receiver id |
|
305
|
|
|
* |
|
306
|
|
|
* @return int |
|
307
|
|
|
*/ |
|
308
|
|
|
public static function get_message_number_invitation_by_user_id($userId) |
|
309
|
|
|
{ |
|
310
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
311
|
|
|
$userId = (int) $userId; |
|
312
|
|
|
$sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$table.' |
|
313
|
|
|
WHERE |
|
314
|
|
|
user_receiver_id='.$userId.' AND |
|
315
|
|
|
msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
|
316
|
|
|
$res = Database::query($sql); |
|
317
|
|
|
$row = Database::fetch_array($res, 'ASSOC'); |
|
318
|
|
|
if ($row) { |
|
319
|
|
|
return (int) $row['count_message_in_box']; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
return 0; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* Get number of messages sent to other users. |
|
327
|
|
|
* |
|
328
|
|
|
* @param int $userId |
|
329
|
|
|
* |
|
330
|
|
|
* @return int |
|
331
|
|
|
*/ |
|
332
|
|
|
public static function getCountMessagesSent($userId) |
|
333
|
|
|
{ |
|
334
|
|
|
$userId = (int) $userId; |
|
335
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
336
|
|
|
$sql = 'SELECT COUNT(*) FROM '.$table.' |
|
337
|
|
|
WHERE |
|
338
|
|
|
user_sender_id='.$userId.' AND |
|
339
|
|
|
msg_status < 5'; |
|
340
|
|
|
$res = Database::query($sql); |
|
341
|
|
|
$row = Database::fetch_row($res); |
|
342
|
|
|
|
|
343
|
|
|
return $row[0]; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* Get number of messages received from other users. |
|
348
|
|
|
* |
|
349
|
|
|
* @param int $receiver_id |
|
350
|
|
|
* |
|
351
|
|
|
* @return int |
|
352
|
|
|
*/ |
|
353
|
|
|
public static function getCountMessagesReceived($receiver_id) |
|
354
|
|
|
{ |
|
355
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
356
|
|
|
$sql = 'SELECT COUNT(*) FROM '.$table.' |
|
357
|
|
|
WHERE |
|
358
|
|
|
user_receiver_id='.intval($receiver_id).' AND |
|
359
|
|
|
msg_status < 4'; |
|
360
|
|
|
$res = Database::query($sql); |
|
361
|
|
|
$row = Database::fetch_row($res); |
|
362
|
|
|
|
|
363
|
|
|
return $row[0]; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* Get number of messages posted on own wall. |
|
368
|
|
|
* |
|
369
|
|
|
* @param int $userId |
|
370
|
|
|
* |
|
371
|
|
|
* @return int |
|
372
|
|
|
*/ |
|
373
|
|
|
public static function getCountWallPostedMessages($userId) |
|
374
|
|
|
{ |
|
375
|
|
|
$userId = (int) $userId; |
|
376
|
|
|
|
|
377
|
|
|
if (empty($userId)) { |
|
378
|
|
|
return 0; |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
382
|
|
|
$sql = 'SELECT COUNT(*) |
|
383
|
|
|
FROM '.$table.' |
|
384
|
|
|
WHERE |
|
385
|
|
|
user_sender_id='.$userId.' AND |
|
386
|
|
|
(msg_status = '.MESSAGE_STATUS_WALL.' OR |
|
387
|
|
|
msg_status = '.MESSAGE_STATUS_WALL_POST.') AND |
|
388
|
|
|
parent_id = 0'; |
|
389
|
|
|
$res = Database::query($sql); |
|
390
|
|
|
$row = Database::fetch_row($res); |
|
391
|
|
|
|
|
392
|
|
|
return $row[0]; |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
|
/** |
|
396
|
|
|
* Get invitation list received by user. |
|
397
|
|
|
* |
|
398
|
|
|
* @author isaac flores paz |
|
399
|
|
|
* |
|
400
|
|
|
* @param int $userId |
|
401
|
|
|
* @param int $limit |
|
402
|
|
|
* |
|
403
|
|
|
* @return array |
|
404
|
|
|
*/ |
|
405
|
|
|
public static function get_list_invitation_of_friends_by_user_id($userId, $limit = 0) |
|
406
|
|
|
{ |
|
407
|
|
|
$userId = (int) $userId; |
|
408
|
|
|
$limit = (int) $limit; |
|
409
|
|
|
|
|
410
|
|
|
if (empty($userId)) { |
|
411
|
|
|
return []; |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
415
|
|
|
$sql = 'SELECT user_sender_id, send_date, title, content |
|
416
|
|
|
FROM '.$table.' |
|
417
|
|
|
WHERE |
|
418
|
|
|
user_receiver_id = '.$userId.' AND |
|
419
|
|
|
msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
|
420
|
|
|
if ($limit != null && $limit > 0) { |
|
421
|
|
|
$sql .= ' LIMIT '.$limit; |
|
422
|
|
|
} |
|
423
|
|
|
$res = Database::query($sql); |
|
424
|
|
|
$list = []; |
|
425
|
|
|
while ($row = Database::fetch_array($res, 'ASSOC')) { |
|
426
|
|
|
$list[] = $row; |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
return $list; |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
/** |
|
433
|
|
|
* Get invitation list sent by user. |
|
434
|
|
|
* |
|
435
|
|
|
* @author Julio Montoya <[email protected]> |
|
436
|
|
|
* |
|
437
|
|
|
* @param int $userId |
|
438
|
|
|
* |
|
439
|
|
|
* @return array |
|
440
|
|
|
*/ |
|
441
|
|
|
public static function get_list_invitation_sent_by_user_id($userId) |
|
442
|
|
|
{ |
|
443
|
|
|
$userId = (int) $userId; |
|
444
|
|
|
|
|
445
|
|
|
if (empty($userId)) { |
|
446
|
|
|
return []; |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
450
|
|
|
$sql = 'SELECT user_receiver_id, send_date,title,content |
|
451
|
|
|
FROM '.$table.' |
|
452
|
|
|
WHERE |
|
453
|
|
|
user_sender_id = '.$userId.' AND |
|
454
|
|
|
msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
|
455
|
|
|
$res = Database::query($sql); |
|
456
|
|
|
$list = []; |
|
457
|
|
|
while ($row = Database::fetch_array($res, 'ASSOC')) { |
|
458
|
|
|
$list[$row['user_receiver_id']] = $row; |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
return $list; |
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
/** |
|
465
|
|
|
* Get count invitation sent by user. |
|
466
|
|
|
* |
|
467
|
|
|
* @author Julio Montoya <[email protected]> |
|
468
|
|
|
* |
|
469
|
|
|
* @param int $userId |
|
470
|
|
|
* |
|
471
|
|
|
* @return int |
|
472
|
|
|
*/ |
|
473
|
|
|
public static function getCountInvitationSent($userId) |
|
474
|
|
|
{ |
|
475
|
|
|
$userId = (int) $userId; |
|
476
|
|
|
|
|
477
|
|
|
if (empty($userId)) { |
|
478
|
|
|
return 0; |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
482
|
|
|
$sql = 'SELECT count(user_receiver_id) count |
|
483
|
|
|
FROM '.$table.' |
|
484
|
|
|
WHERE |
|
485
|
|
|
user_sender_id = '.$userId.' AND |
|
486
|
|
|
msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
|
487
|
|
|
$res = Database::query($sql); |
|
488
|
|
|
if (Database::num_rows($res)) { |
|
489
|
|
|
$row = Database::fetch_array($res, 'ASSOC'); |
|
490
|
|
|
|
|
491
|
|
|
return (int) $row['count']; |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
return 0; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* Accepts invitation. |
|
499
|
|
|
* |
|
500
|
|
|
* @param int $user_send_id |
|
501
|
|
|
* @param int $user_receiver_id |
|
502
|
|
|
* |
|
503
|
|
|
* @return bool |
|
504
|
|
|
* |
|
505
|
|
|
* @author isaac flores paz |
|
506
|
|
|
* @author Julio Montoya <[email protected]> Cleaning code |
|
507
|
|
|
*/ |
|
508
|
|
|
public static function invitation_accepted($user_send_id, $user_receiver_id) |
|
509
|
|
|
{ |
|
510
|
|
|
if (empty($user_send_id) || empty($user_receiver_id)) { |
|
511
|
|
|
return false; |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
515
|
|
|
$sql = "UPDATE $table |
|
516
|
|
|
SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED." |
|
517
|
|
|
WHERE |
|
518
|
|
|
user_sender_id = ".((int) $user_send_id)." AND |
|
519
|
|
|
user_receiver_id=".((int) $user_receiver_id)." AND |
|
520
|
|
|
msg_status = ".MESSAGE_STATUS_INVITATION_PENDING; |
|
521
|
|
|
Database::query($sql); |
|
522
|
|
|
|
|
523
|
|
|
return true; |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
/** |
|
527
|
|
|
* Denies invitation. |
|
528
|
|
|
* |
|
529
|
|
|
* @param int user sender id |
|
530
|
|
|
* @param int user receiver id |
|
531
|
|
|
* |
|
532
|
|
|
* @return bool |
|
533
|
|
|
* |
|
534
|
|
|
* @author isaac flores paz |
|
535
|
|
|
* @author Julio Montoya <[email protected]> Cleaning code |
|
536
|
|
|
*/ |
|
537
|
|
|
public static function invitation_denied($user_send_id, $user_receiver_id) |
|
538
|
|
|
{ |
|
539
|
|
|
if (empty($user_send_id) || empty($user_receiver_id)) { |
|
540
|
|
|
return false; |
|
541
|
|
|
} |
|
542
|
|
|
$table = Database::get_main_table(TABLE_MESSAGE); |
|
543
|
|
|
$sql = 'DELETE FROM '.$table.' |
|
544
|
|
|
WHERE |
|
545
|
|
|
user_sender_id = '.((int) $user_send_id).' AND |
|
546
|
|
|
user_receiver_id='.((int) $user_receiver_id).' AND |
|
547
|
|
|
msg_status = '.MESSAGE_STATUS_INVITATION_PENDING; |
|
548
|
|
|
Database::query($sql); |
|
549
|
|
|
|
|
550
|
|
|
return true; |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
/** |
|
554
|
|
|
* Get user's feeds. |
|
555
|
|
|
* |
|
556
|
|
|
* @param int $user User ID |
|
557
|
|
|
* @param int $limit Limit of posts per feed |
|
558
|
|
|
* |
|
559
|
|
|
* @return string HTML section with all feeds included |
|
560
|
|
|
* |
|
561
|
|
|
* @author Yannick Warnier |
|
562
|
|
|
* |
|
563
|
|
|
* @since Dokeos 1.8.6.1 |
|
564
|
|
|
*/ |
|
565
|
|
|
public static function getUserRssFeed($user, $limit = 5) |
|
566
|
|
|
{ |
|
567
|
|
|
$feed = UserManager::get_extra_user_data_by_field($user, 'rssfeeds'); |
|
568
|
|
|
|
|
569
|
|
|
if (empty($feed)) { |
|
570
|
|
|
return ''; |
|
571
|
|
|
} |
|
572
|
|
|
$feeds = explode(';', $feed['rssfeeds']); |
|
573
|
|
|
if (count($feeds) == 0) { |
|
574
|
|
|
return ''; |
|
575
|
|
|
} |
|
576
|
|
|
$res = ''; |
|
577
|
|
|
foreach ($feeds as $url) { |
|
578
|
|
|
if (empty($url)) { |
|
579
|
|
|
continue; |
|
580
|
|
|
} |
|
581
|
|
|
try { |
|
582
|
|
|
$channel = Reader::import($url); |
|
583
|
|
|
$i = 1; |
|
584
|
|
|
if (!empty($channel)) { |
|
585
|
|
|
$iconRss = ''; |
|
586
|
|
|
if (!empty($feed)) { |
|
587
|
|
|
$iconRss = Display::url( |
|
588
|
|
|
Display::return_icon('social_rss.png', '', [], 22), |
|
589
|
|
|
Security::remove_XSS($feed['rssfeeds']), |
|
590
|
|
|
['target' => '_blank'] |
|
591
|
|
|
); |
|
592
|
|
|
} |
|
593
|
|
|
|
|
594
|
|
|
$res .= '<h3 class="title-rss">'.$iconRss.' '.$channel->getTitle().'</h3>'; |
|
595
|
|
|
$res .= '<div class="rss-items">'; |
|
596
|
|
|
/** @var Rss $item */ |
|
597
|
|
|
foreach ($channel as $item) { |
|
598
|
|
|
if ($limit >= 0 and $i > $limit) { |
|
599
|
|
|
break; |
|
600
|
|
|
} |
|
601
|
|
|
$res .= '<h4 class="rss-title"><a href="'.$item->getLink().'">'.$item->getTitle().'</a></h4>'; |
|
602
|
|
|
$res .= '<div class="rss-date">'.api_get_local_time($item->getDateCreated()).'</div>'; |
|
603
|
|
|
$res .= '<div class="rss-content"><p>'.$item->getDescription().'</p></div>'; |
|
604
|
|
|
$i++; |
|
605
|
|
|
} |
|
606
|
|
|
$res .= '</div>'; |
|
607
|
|
|
} |
|
608
|
|
|
} catch (Exception $e) { |
|
609
|
|
|
error_log($e->getMessage()); |
|
610
|
|
|
} |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
|
|
return $res; |
|
614
|
|
|
} |
|
615
|
|
|
|
|
616
|
|
|
/** |
|
617
|
|
|
* Sends invitations to friends. |
|
618
|
|
|
* |
|
619
|
|
|
* @param int $userId |
|
620
|
|
|
* @param string $subject |
|
621
|
|
|
* @param string $content |
|
622
|
|
|
* |
|
623
|
|
|
* @return bool |
|
624
|
|
|
*/ |
|
625
|
|
|
public static function sendInvitationToUser($userId, $subject = '', $content = '') |
|
626
|
|
|
{ |
|
627
|
|
|
$user_info = api_get_user_info($userId); |
|
628
|
|
|
$success = get_lang('The message has been sent to'); |
|
629
|
|
|
$success .= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']); |
|
630
|
|
|
|
|
631
|
|
|
if (isset($subject) && isset($content) && isset($userId)) { |
|
632
|
|
|
$result = MessageManager::send_message($userId, $subject, $content); |
|
633
|
|
|
|
|
634
|
|
|
if ($result) { |
|
635
|
|
|
Display::addFlash( |
|
636
|
|
|
Display::return_message($success, 'normal', false) |
|
637
|
|
|
); |
|
638
|
|
|
} else { |
|
639
|
|
|
Display::addFlash( |
|
640
|
|
|
Display::return_message(get_lang('There was an error while trying to send the message.'), 'error', false) |
|
641
|
|
|
); |
|
642
|
|
|
} |
|
643
|
|
|
|
|
644
|
|
|
return false; |
|
645
|
|
|
} elseif (isset($userId) && !isset($subject)) { |
|
646
|
|
|
if (isset($userId) && $userId > 0) { |
|
647
|
|
|
$count = self::send_invitation_friend( |
|
648
|
|
|
api_get_user_id(), |
|
649
|
|
|
$userId, |
|
650
|
|
|
get_lang('Invitation'), |
|
651
|
|
|
$content |
|
652
|
|
|
); |
|
653
|
|
|
|
|
654
|
|
|
if ($count) { |
|
655
|
|
|
Display::addFlash( |
|
656
|
|
|
Display::return_message( |
|
657
|
|
|
api_htmlentities(get_lang('The invitation has been sent')), |
|
658
|
|
|
'normal', |
|
659
|
|
|
false |
|
660
|
|
|
) |
|
661
|
|
|
); |
|
662
|
|
|
} else { |
|
663
|
|
|
Display::addFlash( |
|
664
|
|
|
Display::return_message( |
|
665
|
|
|
api_htmlentities(get_lang('You already sent an invitation')), |
|
666
|
|
|
'warning', |
|
667
|
|
|
false |
|
668
|
|
|
) |
|
669
|
|
|
); |
|
670
|
|
|
} |
|
671
|
|
|
} |
|
672
|
|
|
} |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
/** |
|
676
|
|
|
* Shows the avatar block in social pages. |
|
677
|
|
|
* |
|
678
|
|
|
* @param string $show highlight link possible values: |
|
679
|
|
|
* group_add, |
|
680
|
|
|
* home, |
|
681
|
|
|
* messages, |
|
682
|
|
|
* messages_inbox, |
|
683
|
|
|
* messages_compose, |
|
684
|
|
|
* messages_outbox, |
|
685
|
|
|
* invitations, |
|
686
|
|
|
* shared_profile, |
|
687
|
|
|
* friends, |
|
688
|
|
|
* groups search |
|
689
|
|
|
* @param int $group_id |
|
690
|
|
|
* @param int $user_id |
|
691
|
|
|
*/ |
|
692
|
|
|
public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0) |
|
693
|
|
|
{ |
|
694
|
|
|
$user_id = (int) $user_id; |
|
695
|
|
|
$group_id = (int) $group_id; |
|
696
|
|
|
|
|
697
|
|
|
if (empty($user_id)) { |
|
698
|
|
|
$user_id = api_get_user_id(); |
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
|
|
$show_groups = [ |
|
702
|
|
|
'groups', |
|
703
|
|
|
'group_messages', |
|
704
|
|
|
'messages_list', |
|
705
|
|
|
'group_add', |
|
706
|
|
|
'mygroups', |
|
707
|
|
|
'group_edit', |
|
708
|
|
|
'member_list', |
|
709
|
|
|
'invite_friends', |
|
710
|
|
|
'waiting_list', |
|
711
|
|
|
'browse_groups', |
|
712
|
|
|
]; |
|
713
|
|
|
|
|
714
|
|
|
$template = new Template(null, false, false, false, false, false); |
|
715
|
|
|
|
|
716
|
|
|
if (in_array($show, $show_groups) && !empty($group_id)) { |
|
717
|
|
|
// Group image |
|
718
|
|
|
$userGroup = new UserGroup(); |
|
719
|
|
|
$group_info = $userGroup->get($group_id); |
|
720
|
|
|
|
|
721
|
|
|
$userGroupImage = $userGroup->get_picture_group( |
|
722
|
|
|
$group_id, |
|
723
|
|
|
$group_info['picture'], |
|
724
|
|
|
128, |
|
725
|
|
|
GROUP_IMAGE_SIZE_BIG |
|
726
|
|
|
); |
|
727
|
|
|
|
|
728
|
|
|
$template->assign('show_group', true); |
|
729
|
|
|
$template->assign('group_id', $group_id); |
|
730
|
|
|
$template->assign('user_group_image', $userGroupImage); |
|
731
|
|
|
$template->assign( |
|
732
|
|
|
'user_is_group_admin', |
|
733
|
|
|
$userGroup->is_group_admin( |
|
734
|
|
|
$group_id, |
|
735
|
|
|
api_get_user_id() |
|
736
|
|
|
) |
|
737
|
|
|
); |
|
738
|
|
|
} else { |
|
739
|
|
|
$template->assign('show_group', false); |
|
740
|
|
|
$template->assign('show_user', true); |
|
741
|
|
|
$template->assign( |
|
742
|
|
|
'user_image', |
|
743
|
|
|
[ |
|
744
|
|
|
'big' => UserManager::getUserPicture( |
|
745
|
|
|
$user_id, |
|
746
|
|
|
USER_IMAGE_SIZE_BIG |
|
747
|
|
|
), |
|
748
|
|
|
'normal' => UserManager::getUserPicture( |
|
749
|
|
|
$user_id, |
|
750
|
|
|
USER_IMAGE_SIZE_MEDIUM |
|
751
|
|
|
), |
|
752
|
|
|
] |
|
753
|
|
|
); |
|
754
|
|
|
} |
|
755
|
|
|
|
|
756
|
|
|
$skillBlock = $template->get_template('social/avatar_block.tpl'); |
|
757
|
|
|
|
|
758
|
|
|
return $template->fetch($skillBlock); |
|
759
|
|
|
} |
|
760
|
|
|
|
|
761
|
|
|
/** |
|
762
|
|
|
* Shows the right menu of the Social Network tool. |
|
763
|
|
|
* |
|
764
|
|
|
* @param string $show highlight link possible values: |
|
765
|
|
|
* group_add, |
|
766
|
|
|
* home, |
|
767
|
|
|
* messages, |
|
768
|
|
|
* messages_inbox, |
|
769
|
|
|
* messages_compose , |
|
770
|
|
|
* messages_outbox, |
|
771
|
|
|
* invitations, |
|
772
|
|
|
* shared_profile, |
|
773
|
|
|
* friends, |
|
774
|
|
|
* groups search |
|
775
|
|
|
* @param int $group_id group id |
|
776
|
|
|
* @param int $user_id user id |
|
777
|
|
|
* @param bool $show_full_profile show profile or not (show or hide the user image/information) |
|
778
|
|
|
* @param bool $show_delete_account_button |
|
779
|
|
|
*/ |
|
780
|
|
|
public static function show_social_menu( |
|
781
|
|
|
$show = '', |
|
782
|
|
|
$group_id = 0, |
|
783
|
|
|
$user_id = 0, |
|
784
|
|
|
$show_full_profile = false, |
|
785
|
|
|
$show_delete_account_button = false |
|
786
|
|
|
) { |
|
787
|
|
|
$user_id = (int) $user_id; |
|
788
|
|
|
$group_id = (int) $group_id; |
|
789
|
|
|
|
|
790
|
|
|
if (empty($user_id)) { |
|
791
|
|
|
$user_id = api_get_user_id(); |
|
792
|
|
|
} |
|
793
|
|
|
|
|
794
|
|
|
$usergroup = new UserGroup(); |
|
795
|
|
|
$show_groups = [ |
|
796
|
|
|
'groups', |
|
797
|
|
|
'group_messages', |
|
798
|
|
|
'messages_list', |
|
799
|
|
|
'group_add', |
|
800
|
|
|
'mygroups', |
|
801
|
|
|
'group_edit', |
|
802
|
|
|
'member_list', |
|
803
|
|
|
'invite_friends', |
|
804
|
|
|
'waiting_list', |
|
805
|
|
|
'browse_groups', |
|
806
|
|
|
]; |
|
807
|
|
|
|
|
808
|
|
|
// get count unread message and total invitations |
|
809
|
|
|
$count_unread_message = MessageManager::getCountNewMessagesFromDB(api_get_user_id()); |
|
810
|
|
|
$count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null; |
|
811
|
|
|
|
|
812
|
|
|
$number_of_new_messages_of_friend = self::get_message_number_invitation_by_user_id(api_get_user_id()); |
|
813
|
|
|
$group_pending_invitations = $usergroup->get_groups_by_user( |
|
814
|
|
|
api_get_user_id(), |
|
815
|
|
|
GROUP_USER_PERMISSION_PENDING_INVITATION, |
|
816
|
|
|
false |
|
817
|
|
|
); |
|
818
|
|
|
$group_pending_invitations = count($group_pending_invitations); |
|
819
|
|
|
$total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations; |
|
820
|
|
|
$total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : ''); |
|
821
|
|
|
|
|
822
|
|
|
$filesIcon = Display::return_icon('sn-files.png', get_lang('My files'), null, ICON_SIZE_SMALL); |
|
823
|
|
|
$friendsIcon = Display::return_icon('sn-friends.png', get_lang('Friends'), null, ICON_SIZE_SMALL); |
|
824
|
|
|
$groupsIcon = Display::return_icon('sn-groups.png', get_lang('Social groups'), null, ICON_SIZE_SMALL); |
|
825
|
|
|
$homeIcon = Display::return_icon('sn-home.png', get_lang('Home'), null, ICON_SIZE_SMALL); |
|
826
|
|
|
$invitationsIcon = Display::return_icon('sn-invitations.png', get_lang('Invitations'), null, ICON_SIZE_SMALL); |
|
827
|
|
|
$messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), null, ICON_SIZE_SMALL); |
|
828
|
|
|
$sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('My shared profile')); |
|
829
|
|
|
$searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), null, ICON_SIZE_SMALL); |
|
830
|
|
|
$portfolioIcon = Display::return_icon('wiki_task.png', get_lang('Portfolio')); |
|
831
|
|
|
$personalDataIcon = Display::return_icon('database.png', get_lang('Personal data')); |
|
832
|
|
|
$messageSocialIcon = Display::return_icon('promoted_message.png', get_lang('PromotedMessages')); |
|
833
|
|
|
|
|
834
|
|
|
$forumCourseId = api_get_configuration_value('global_forums_course_id'); |
|
835
|
|
|
$groupUrl = api_get_path(WEB_CODE_PATH).'social/groups.php'; |
|
836
|
|
|
if (!empty($forumCourseId)) { |
|
837
|
|
|
$courseInfo = api_get_course_info_by_id($forumCourseId); |
|
|
|
|
|
|
838
|
|
|
if (!empty($courseInfo)) { |
|
839
|
|
|
$groupUrl = api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$courseInfo['code']; |
|
840
|
|
|
} |
|
841
|
|
|
} |
|
842
|
|
|
|
|
843
|
|
|
$html = ''; |
|
844
|
|
|
$active = null; |
|
845
|
|
|
if (!in_array( |
|
846
|
|
|
$show, |
|
847
|
|
|
['shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'] |
|
848
|
|
|
)) { |
|
849
|
|
|
$links = '<ul class="nav nav-pills nav-stacked">'; |
|
850
|
|
|
$active = $show === 'home' ? 'active' : null; |
|
851
|
|
|
$links .= ' |
|
852
|
|
|
<li class="home-icon '.$active.'"> |
|
853
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/home.php"> |
|
854
|
|
|
'.$homeIcon.' '.get_lang('Home').' |
|
855
|
|
|
</a> |
|
856
|
|
|
</li>'; |
|
857
|
|
|
$active = $show === 'messages' ? 'active' : null; |
|
858
|
|
|
$links .= ' |
|
859
|
|
|
<li class="messages-icon '.$active.'"> |
|
860
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php"> |
|
861
|
|
|
'.$messagesIcon.' '.get_lang('Messages').$count_unread_message.' |
|
862
|
|
|
</a> |
|
863
|
|
|
</li>'; |
|
864
|
|
|
|
|
865
|
|
|
// Invitations |
|
866
|
|
|
$active = $show === 'invitations' ? 'active' : null; |
|
867
|
|
|
$links .= ' |
|
868
|
|
|
<li class="invitations-icon '.$active.'"> |
|
869
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php"> |
|
870
|
|
|
'.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.' |
|
871
|
|
|
</a> |
|
872
|
|
|
</li>'; |
|
873
|
|
|
|
|
874
|
|
|
// Shared profile and groups |
|
875
|
|
|
$active = $show === 'shared_profile' ? 'active' : null; |
|
876
|
|
|
$links .= ' |
|
877
|
|
|
<li class="shared-profile-icon'.$active.'"> |
|
878
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php"> |
|
879
|
|
|
'.$sharedProfileIcon.' '.get_lang('My shared profile').' |
|
880
|
|
|
</a> |
|
881
|
|
|
</li>'; |
|
882
|
|
|
$active = $show === 'friends' ? 'active' : null; |
|
883
|
|
|
$links .= ' |
|
884
|
|
|
<li class="friends-icon '.$active.'"> |
|
885
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php"> |
|
886
|
|
|
'.$friendsIcon.' '.get_lang('Friends').' |
|
887
|
|
|
</a> |
|
888
|
|
|
</li>'; |
|
889
|
|
|
$active = $show === 'browse_groups' ? 'active' : null; |
|
890
|
|
|
$links .= ' |
|
891
|
|
|
<li class="browse-groups-icon '.$active.'"> |
|
892
|
|
|
<a href="'.$groupUrl.'"> |
|
893
|
|
|
'.$groupsIcon.' '.get_lang('Social groups').' |
|
894
|
|
|
</a> |
|
895
|
|
|
</li>'; |
|
896
|
|
|
|
|
897
|
|
|
// Search users |
|
898
|
|
|
$active = $show === 'search' ? 'active' : null; |
|
899
|
|
|
$links .= ' |
|
900
|
|
|
<li class="search-icon '.$active.'"> |
|
901
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/search.php"> |
|
902
|
|
|
'.$searchIcon.' '.get_lang('Search').' |
|
903
|
|
|
</a> |
|
904
|
|
|
</li>'; |
|
905
|
|
|
|
|
906
|
|
|
// My files |
|
907
|
|
|
$active = $show === 'myfiles' ? 'active' : null; |
|
908
|
|
|
|
|
909
|
|
|
$myFiles = ' |
|
910
|
|
|
<li class="myfiles-icon '.$active.'"> |
|
911
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php"> |
|
912
|
|
|
'.$filesIcon.' '.get_lang('My files').' |
|
913
|
|
|
</a> |
|
914
|
|
|
</li>'; |
|
915
|
|
|
|
|
916
|
|
|
if (api_get_setting('allow_my_files') === 'false') { |
|
917
|
|
|
$myFiles = ''; |
|
918
|
|
|
} |
|
919
|
|
|
$links .= $myFiles; |
|
920
|
|
|
if (api_get_configuration_value('allow_portfolio_tool')) { |
|
921
|
|
|
$links .= ' |
|
922
|
|
|
<li class="portoflio-icon '.($show === 'portfolio' ? 'active' : '').'"> |
|
923
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php"> |
|
924
|
|
|
'.$portfolioIcon.' '.get_lang('Portfolio').' |
|
925
|
|
|
</a> |
|
926
|
|
|
</li> |
|
927
|
|
|
'; |
|
928
|
|
|
} |
|
929
|
|
|
|
|
930
|
|
|
if (!api_get_configuration_value('disable_gdpr')) { |
|
931
|
|
|
$active = $show === 'personal-data' ? 'active' : null; |
|
932
|
|
|
$personalData = ' |
|
933
|
|
|
<li class="personal-data-icon '.$active.'"> |
|
934
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/personal_data.php"> |
|
935
|
|
|
'.$personalDataIcon.' '.get_lang('Personal data').' |
|
936
|
|
|
</a> |
|
937
|
|
|
</li>'; |
|
938
|
|
|
$links .= $personalData; |
|
939
|
|
|
} |
|
940
|
|
|
|
|
941
|
|
|
if (api_is_platform_admin()) { |
|
942
|
|
|
$active = $show === 'promoted_messages' ? 'active' : null; |
|
943
|
|
|
$personalData = ' |
|
944
|
|
|
<li class="personal-data-icon '.$active.'"> |
|
945
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/promoted_messages.php"> |
|
946
|
|
|
'.$messageSocialIcon.' '.get_lang('PromotedMessages').' |
|
947
|
|
|
</a> |
|
948
|
|
|
</li>'; |
|
949
|
|
|
$links .= $personalData; |
|
950
|
|
|
} |
|
951
|
|
|
$links .= '</ul>'; |
|
952
|
|
|
$html .= Display::panelCollapse( |
|
953
|
|
|
get_lang('Social network'), |
|
954
|
|
|
$links, |
|
955
|
|
|
'social-network-menu', |
|
956
|
|
|
null, |
|
957
|
|
|
'sn-sidebar', |
|
958
|
|
|
'sn-sidebar-collapse' |
|
959
|
|
|
); |
|
960
|
|
|
} |
|
961
|
|
|
|
|
962
|
|
|
if (!empty($group_id) && in_array($show, $show_groups)) { |
|
963
|
|
|
$html .= $usergroup->show_group_column_information( |
|
964
|
|
|
$group_id, |
|
965
|
|
|
api_get_user_id(), |
|
966
|
|
|
$show |
|
967
|
|
|
); |
|
968
|
|
|
} |
|
969
|
|
|
|
|
970
|
|
|
if ($show === 'shared_profile') { |
|
971
|
|
|
$links = '<ul class="nav nav-pills nav-stacked">'; |
|
972
|
|
|
// My own profile |
|
973
|
|
|
if ($show_full_profile && $user_id == api_get_user_id()) { |
|
974
|
|
|
$links .= ' |
|
975
|
|
|
<li class="home-icon '.$active.'"> |
|
976
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/home.php"> |
|
977
|
|
|
'.$homeIcon.' '.get_lang('Home').' |
|
978
|
|
|
</a> |
|
979
|
|
|
</li> |
|
980
|
|
|
<li class="messages-icon '.$active.'"> |
|
981
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php"> |
|
982
|
|
|
'.$messagesIcon.' '.get_lang('Messages').$count_unread_message.' |
|
983
|
|
|
</a> |
|
984
|
|
|
</li>'; |
|
985
|
|
|
$active = $show === 'invitations' ? 'active' : null; |
|
986
|
|
|
$links .= ' |
|
987
|
|
|
<li class="invitations-icon'.$active.'"> |
|
988
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php"> |
|
989
|
|
|
'.$invitationsIcon.' '.get_lang('Invitations').$total_invitations.' |
|
990
|
|
|
</a> |
|
991
|
|
|
</li>'; |
|
992
|
|
|
|
|
993
|
|
|
$links .= ' |
|
994
|
|
|
<li class="shared-profile-icon active"> |
|
995
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php"> |
|
996
|
|
|
'.$sharedProfileIcon.' '.get_lang('My shared profile').' |
|
997
|
|
|
</a> |
|
998
|
|
|
</li> |
|
999
|
|
|
<li class="friends-icon"> |
|
1000
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php"> |
|
1001
|
|
|
'.$friendsIcon.' '.get_lang('Friends').' |
|
1002
|
|
|
</a> |
|
1003
|
|
|
</li>'; |
|
1004
|
|
|
|
|
1005
|
|
|
$links .= '<li class="browse-groups-icon"> |
|
1006
|
|
|
<a href="'.$groupUrl.'"> |
|
1007
|
|
|
'.$groupsIcon.' '.get_lang('Social groups').' |
|
1008
|
|
|
</a> |
|
1009
|
|
|
</li>'; |
|
1010
|
|
|
|
|
1011
|
|
|
$active = $show == 'search' ? 'active' : null; |
|
1012
|
|
|
$links .= ' |
|
1013
|
|
|
<li class="search-icon '.$active.'"> |
|
1014
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/search.php"> |
|
1015
|
|
|
'.$searchIcon.' '.get_lang('Search').' |
|
1016
|
|
|
</a> |
|
1017
|
|
|
</li>'; |
|
1018
|
|
|
$active = $show == 'myfiles' ? 'active' : null; |
|
1019
|
|
|
|
|
1020
|
|
|
$myFiles = ' |
|
1021
|
|
|
<li class="myfiles-icon '.$active.'"> |
|
1022
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php"> |
|
1023
|
|
|
'.$filesIcon.' '.get_lang('My files').' |
|
1024
|
|
|
</a> |
|
1025
|
|
|
</li>'; |
|
1026
|
|
|
|
|
1027
|
|
|
if (api_get_setting('allow_my_files') === 'false') { |
|
1028
|
|
|
$myFiles = ''; |
|
1029
|
|
|
} |
|
1030
|
|
|
$links .= $myFiles; |
|
1031
|
|
|
|
|
1032
|
|
|
if (api_get_configuration_value('allow_portfolio_tool')) { |
|
1033
|
|
|
$links .= ' |
|
1034
|
|
|
<li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'"> |
|
1035
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php"> |
|
1036
|
|
|
'.$portfolioIcon.' '.get_lang('Portfolio').' |
|
1037
|
|
|
</a> |
|
1038
|
|
|
</li> |
|
1039
|
|
|
'; |
|
1040
|
|
|
} |
|
1041
|
|
|
|
|
1042
|
|
|
if (!api_get_configuration_value('disable_gdpr')) { |
|
1043
|
|
|
$active = $show == 'personal-data' ? 'active' : null; |
|
1044
|
|
|
$personalData = ' |
|
1045
|
|
|
<li class="personal-data-icon '.$active.'"> |
|
1046
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'social/personal_data.php"> |
|
1047
|
|
|
'.$personalDataIcon.' '.get_lang('Personal data').' |
|
1048
|
|
|
</a> |
|
1049
|
|
|
</li>'; |
|
1050
|
|
|
$links .= $personalData; |
|
1051
|
|
|
$links .= '</ul>'; |
|
1052
|
|
|
} |
|
1053
|
|
|
} |
|
1054
|
|
|
|
|
1055
|
|
|
// My friend profile. |
|
1056
|
|
|
if ($user_id != api_get_user_id()) { |
|
1057
|
|
|
$sendMessageText = get_lang('Send message'); |
|
1058
|
|
|
$sendMessageIcon = Display::return_icon( |
|
1059
|
|
|
'new-message.png', |
|
1060
|
|
|
$sendMessageText |
|
1061
|
|
|
); |
|
1062
|
|
|
$sendMessageUrl = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?'.http_build_query([ |
|
1063
|
|
|
'a' => 'get_user_popup', |
|
1064
|
|
|
'user_id' => $user_id, |
|
1065
|
|
|
]); |
|
1066
|
|
|
|
|
1067
|
|
|
$links .= '<li>'; |
|
1068
|
|
|
$links .= Display::url( |
|
1069
|
|
|
"$sendMessageIcon $sendMessageText", |
|
1070
|
|
|
$sendMessageUrl, |
|
1071
|
|
|
[ |
|
1072
|
|
|
'class' => 'ajax', |
|
1073
|
|
|
'title' => $sendMessageText, |
|
1074
|
|
|
'data-title' => $sendMessageText, |
|
1075
|
|
|
] |
|
1076
|
|
|
); |
|
1077
|
|
|
$links .= '</li>'; |
|
1078
|
|
|
|
|
1079
|
|
|
if (api_get_configuration_value('allow_portfolio_tool')) { |
|
1080
|
|
|
$links .= ' |
|
1081
|
|
|
<li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'"> |
|
1082
|
|
|
<a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php?user='.$user_id.'"> |
|
1083
|
|
|
'.$portfolioIcon.' '.get_lang('Portfolio').' |
|
1084
|
|
|
</a> |
|
1085
|
|
|
</li> |
|
1086
|
|
|
'; |
|
1087
|
|
|
} |
|
1088
|
|
|
} |
|
1089
|
|
|
|
|
1090
|
|
|
// Check if I already sent an invitation message |
|
1091
|
|
|
$invitationSentList = self::get_list_invitation_sent_by_user_id(api_get_user_id()); |
|
1092
|
|
|
|
|
1093
|
|
|
if (isset($invitationSentList[$user_id]) && is_array($invitationSentList[$user_id]) && |
|
1094
|
|
|
count($invitationSentList[$user_id]) > 0 |
|
1095
|
|
|
) { |
|
1096
|
|
|
$links .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'. |
|
1097
|
|
|
Display::return_icon('invitation.png', get_lang('You already sent an invitation')) |
|
1098
|
|
|
.' '.get_lang('You already sent an invitation').'</a></li>'; |
|
1099
|
|
|
} else { |
|
1100
|
|
|
if (!$show_full_profile) { |
|
1101
|
|
|
$links .= '<li> |
|
1102
|
|
|
<a class="btn-to-send-invitation" href="#" data-send-to="'.$user_id.'" title="'.get_lang('Send invitation').'">'. |
|
1103
|
|
|
Display::return_icon('invitation.png', get_lang('Invite to join my group of friends')).' '.get_lang('Send invitation'). |
|
1104
|
|
|
'</a></li>'; |
|
1105
|
|
|
} |
|
1106
|
|
|
} |
|
1107
|
|
|
|
|
1108
|
|
|
$links .= '</ul>'; |
|
1109
|
|
|
$html .= Display::panelCollapse( |
|
1110
|
|
|
get_lang('Social network'), |
|
1111
|
|
|
$links, |
|
1112
|
|
|
'social-network-menu', |
|
1113
|
|
|
null, |
|
1114
|
|
|
'sn-sidebar', |
|
1115
|
|
|
'sn-sidebar-collapse' |
|
1116
|
|
|
); |
|
1117
|
|
|
|
|
1118
|
|
|
if ($show_full_profile && $user_id == api_get_user_id()) { |
|
1119
|
|
|
// Announcements |
|
1120
|
|
|
$announcements = []; |
|
1121
|
|
|
$announcementsByCourse = AnnouncementManager::getAnnoucementCourseTotalByUser($user_id); |
|
1122
|
|
|
if (!empty($announcementsByCourse)) { |
|
1123
|
|
|
foreach ($announcementsByCourse as $announcement) { |
|
1124
|
|
|
$url = Display::url( |
|
1125
|
|
|
Display::return_icon( |
|
1126
|
|
|
'announcement.png', |
|
1127
|
|
|
get_lang('Announcements') |
|
1128
|
|
|
).$announcement['course']['name'].' ('.$announcement['count'].')', |
|
1129
|
|
|
api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$announcement['course']['code'] |
|
1130
|
|
|
); |
|
1131
|
|
|
$announcements[] = Display::tag('li', $url); |
|
1132
|
|
|
} |
|
1133
|
|
|
} |
|
1134
|
|
|
|
|
1135
|
|
|
if (!empty($announcements)) { |
|
1136
|
|
|
$html .= '<div class="social_menu_items">'; |
|
1137
|
|
|
$html .= '<ul>'; |
|
1138
|
|
|
foreach ($announcements as $announcement) { |
|
1139
|
|
|
$html .= $announcement; |
|
1140
|
|
|
} |
|
1141
|
|
|
$html .= '</ul>'; |
|
1142
|
|
|
$html .= '</div>'; |
|
1143
|
|
|
} |
|
1144
|
|
|
} |
|
1145
|
|
|
} |
|
1146
|
|
|
|
|
1147
|
|
|
if ($show_delete_account_button) { |
|
1148
|
|
|
$html .= '<div class="panel panel-default"><div class="panel-body">'; |
|
1149
|
|
|
$html .= '<ul class="nav nav-pills nav-stacked"><li>'; |
|
1150
|
|
|
$url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php'; |
|
1151
|
|
|
$html .= Display::url( |
|
1152
|
|
|
Display::return_icon( |
|
1153
|
|
|
'delete.png', |
|
1154
|
|
|
get_lang('Unsubscribe'), |
|
1155
|
|
|
[], |
|
1156
|
|
|
ICON_SIZE_TINY |
|
1157
|
|
|
).get_lang('Unsubscribe'), |
|
1158
|
|
|
$url |
|
1159
|
|
|
); |
|
1160
|
|
|
$html .= '</li></ul>'; |
|
1161
|
|
|
$html .= '</div></div>'; |
|
1162
|
|
|
} |
|
1163
|
|
|
$html .= ''; |
|
1164
|
|
|
|
|
1165
|
|
|
return $html; |
|
1166
|
|
|
} |
|
1167
|
|
|
|
|
1168
|
|
|
/** |
|
1169
|
|
|
* Displays a sortable table with the list of online users. |
|
1170
|
|
|
* |
|
1171
|
|
|
* @param array $user_list The list of users to be shown |
|
1172
|
|
|
* @param bool $wrap Whether we want the function to wrap the spans list in a div or not |
|
1173
|
|
|
* |
|
1174
|
|
|
* @return string HTML block or null if and ID was defined |
|
1175
|
|
|
* @assert (null) === false |
|
1176
|
|
|
*/ |
|
1177
|
|
|
public static function display_user_list($user_list, $wrap = true) |
|
1178
|
|
|
{ |
|
1179
|
|
|
$html = ''; |
|
1180
|
|
|
|
|
1181
|
|
|
if (isset($_GET['id']) || count($user_list) < 1) { |
|
1182
|
|
|
return false; |
|
|
|
|
|
|
1183
|
|
|
} |
|
1184
|
|
|
|
|
1185
|
|
|
$course_url = ''; |
|
1186
|
|
|
if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { |
|
1187
|
|
|
$course_url = '&cidReq='.Security::remove_XSS($_GET['cidReq']); |
|
1188
|
|
|
} |
|
1189
|
|
|
|
|
1190
|
|
|
$hide = api_get_configuration_value('hide_complete_name_in_whoisonline'); |
|
1191
|
|
|
foreach ($user_list as $uid) { |
|
1192
|
|
|
$user_info = api_get_user_info($uid, true); |
|
1193
|
|
|
$lastname = $user_info['lastname']; |
|
1194
|
|
|
$firstname = $user_info['firstname']; |
|
1195
|
|
|
$completeName = $firstname.', '.$lastname; |
|
1196
|
|
|
$user_rol = $user_info['status'] == 1 ? Display::return_icon('teacher.png', get_lang('Trainer'), null, ICON_SIZE_TINY) : Display::return_icon('user.png', get_lang('Learner'), null, ICON_SIZE_TINY); |
|
1197
|
|
|
$status_icon_chat = null; |
|
1198
|
|
|
if (isset($user_info['user_is_online_in_chat']) && $user_info['user_is_online_in_chat'] == 1) { |
|
1199
|
|
|
$status_icon_chat = Display::return_icon('online.png', get_lang('Online')); |
|
1200
|
|
|
} else { |
|
1201
|
|
|
$status_icon_chat = Display::return_icon('offline.png', get_lang('Offline')); |
|
1202
|
|
|
} |
|
1203
|
|
|
|
|
1204
|
|
|
$userPicture = $user_info['avatar']; |
|
1205
|
|
|
$officialCode = ''; |
|
1206
|
|
|
if (api_get_setting('show_official_code_whoisonline') == 'true') { |
|
1207
|
|
|
$officialCode .= '<div class="items-user-official-code"><p style="min-height: 30px;" title="'.get_lang('Code').'">'.$user_info['official_code'].'</p></div>'; |
|
1208
|
|
|
} |
|
1209
|
|
|
|
|
1210
|
|
|
if ($hide === true) { |
|
1211
|
|
|
$completeName = ''; |
|
1212
|
|
|
$firstname = ''; |
|
1213
|
|
|
$lastname = ''; |
|
1214
|
|
|
} |
|
1215
|
|
|
|
|
1216
|
|
|
$img = '<img class="img-responsive img-circle" title="'.$completeName.'" alt="'.$completeName.'" src="'.$userPicture.'">'; |
|
1217
|
|
|
|
|
1218
|
|
|
$url = null; |
|
1219
|
|
|
// Anonymous users can't have access to the profile |
|
1220
|
|
|
if (!api_is_anonymous()) { |
|
1221
|
|
|
if (api_get_setting('allow_social_tool') === 'true') { |
|
1222
|
|
|
$url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url; |
|
1223
|
|
|
} else { |
|
1224
|
|
|
$url = '?id='.$uid.$course_url; |
|
1225
|
|
|
} |
|
1226
|
|
|
} else { |
|
1227
|
|
|
$url = null; |
|
1228
|
|
|
} |
|
1229
|
|
|
$name = '<a href="'.$url.'">'.$firstname.'<br>'.$lastname.'</a>'; |
|
1230
|
|
|
|
|
1231
|
|
|
$html .= '<div class="col-xs-6 col-md-2"> |
|
1232
|
|
|
<div class="items-user"> |
|
1233
|
|
|
<div class="items-user-avatar"><a href="'.$url.'">'.$img.'</a></div> |
|
1234
|
|
|
<div class="items-user-name"> |
|
1235
|
|
|
'.$name.' |
|
1236
|
|
|
</div> |
|
1237
|
|
|
'.$officialCode.' |
|
1238
|
|
|
<div class="items-user-status">'.$status_icon_chat.' '.$user_rol.'</div> |
|
1239
|
|
|
</div> |
|
1240
|
|
|
</div>'; |
|
1241
|
|
|
} |
|
1242
|
|
|
|
|
1243
|
|
|
return $html; |
|
1244
|
|
|
} |
|
1245
|
|
|
|
|
1246
|
|
|
/** |
|
1247
|
|
|
* Displays the information of an individual user. |
|
1248
|
|
|
* |
|
1249
|
|
|
* @param int $user_id |
|
1250
|
|
|
* |
|
1251
|
|
|
* @return string |
|
1252
|
|
|
*/ |
|
1253
|
|
|
public static function display_individual_user($user_id) |
|
1254
|
|
|
{ |
|
1255
|
|
|
global $interbreadcrumb; |
|
1256
|
|
|
$safe_user_id = (int) $user_id; |
|
1257
|
|
|
$currentUserId = api_get_user_id(); |
|
1258
|
|
|
|
|
1259
|
|
|
$user_table = Database::get_main_table(TABLE_MAIN_USER); |
|
1260
|
|
|
$sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id; |
|
1261
|
|
|
$result = Database::query($sql); |
|
1262
|
|
|
$html = null; |
|
1263
|
|
|
if (Database::num_rows($result) == 1) { |
|
1264
|
|
|
$user_object = Database::fetch_object($result); |
|
1265
|
|
|
$userInfo = api_get_user_info($user_id); |
|
1266
|
|
|
$alt = $userInfo['complete_name'].($currentUserId == $user_id ? ' ('.get_lang('Me').')' : ''); |
|
1267
|
|
|
$status = get_status_from_code($user_object->status); |
|
1268
|
|
|
$interbreadcrumb[] = ['url' => 'whoisonline.php', 'name' => get_lang('Online users list')]; |
|
1269
|
|
|
|
|
1270
|
|
|
$html .= '<div class ="thumbnail">'; |
|
1271
|
|
|
$fullurl = $userInfo['avatar']; |
|
1272
|
|
|
|
|
1273
|
|
|
$html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />'; |
|
1274
|
|
|
|
|
1275
|
|
|
if (!empty($status)) { |
|
1276
|
|
|
$html .= '<div class="caption">'.$status.'</div>'; |
|
1277
|
|
|
} |
|
1278
|
|
|
$html .= '</div>'; |
|
1279
|
|
|
|
|
1280
|
|
|
if (api_get_setting('show_email_addresses') == 'true') { |
|
1281
|
|
|
$html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />'; |
|
1282
|
|
|
} |
|
1283
|
|
|
|
|
1284
|
|
|
if ($user_object->competences) { |
|
1285
|
|
|
$html .= Display::page_subheader(get_lang('My competences')); |
|
1286
|
|
|
$html .= '<p>'.$user_object->competences.'</p>'; |
|
1287
|
|
|
} |
|
1288
|
|
|
if ($user_object->diplomas) { |
|
1289
|
|
|
$html .= Display::page_subheader(get_lang('My diplomas')); |
|
1290
|
|
|
$html .= '<p>'.$user_object->diplomas.'</p>'; |
|
1291
|
|
|
} |
|
1292
|
|
|
if ($user_object->teach) { |
|
1293
|
|
|
$html .= Display::page_subheader(get_lang('What I am able to teach')); |
|
1294
|
|
|
$html .= '<p>'.$user_object->teach.'</p>'; |
|
1295
|
|
|
} |
|
1296
|
|
|
self::display_productions($user_object->user_id); |
|
1297
|
|
|
if ($user_object->openarea) { |
|
1298
|
|
|
$html .= Display::page_subheader(get_lang('My personal open area')); |
|
1299
|
|
|
$html .= '<p>'.$user_object->openarea.'</p>'; |
|
1300
|
|
|
} |
|
1301
|
|
|
} else { |
|
1302
|
|
|
$html .= '<div class="actions-title">'; |
|
1303
|
|
|
$html .= get_lang('Online users list'); |
|
1304
|
|
|
$html .= '</div>'; |
|
1305
|
|
|
} |
|
1306
|
|
|
|
|
1307
|
|
|
return $html; |
|
1308
|
|
|
} |
|
1309
|
|
|
|
|
1310
|
|
|
/** |
|
1311
|
|
|
* Display productions in who is online. |
|
1312
|
|
|
* |
|
1313
|
|
|
* @param int $user_id User id |
|
1314
|
|
|
*/ |
|
1315
|
|
|
public static function display_productions($user_id) |
|
1316
|
|
|
{ |
|
1317
|
|
|
$webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web'); |
|
|
|
|
|
|
1318
|
|
|
$sysdir = UserManager::getUserPathById($user_id, 'system'); |
|
|
|
|
|
|
1319
|
|
|
$webdir = UserManager::getUserPathById($user_id, 'web'); |
|
|
|
|
|
|
1320
|
|
|
|
|
1321
|
|
|
if (!is_dir($sysdir)) { |
|
1322
|
|
|
mkdir($sysdir, api_get_permissions_for_new_directories(), true); |
|
1323
|
|
|
} |
|
1324
|
|
|
|
|
1325
|
|
|
$productions = UserManager::get_user_productions($user_id); |
|
1326
|
|
|
|
|
1327
|
|
|
if (count($productions) > 0) { |
|
1328
|
|
|
echo '<dt><strong>'.get_lang('Productions').'</strong></dt>'; |
|
1329
|
|
|
echo '<dd><ul>'; |
|
1330
|
|
|
foreach ($productions as $file) { |
|
1331
|
|
|
// Only display direct file links to avoid browsing an empty directory |
|
1332
|
|
|
if (is_file($sysdir.$file) && $file != $webdir_array['file']) { |
|
1333
|
|
|
echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>'; |
|
1334
|
|
|
} |
|
1335
|
|
|
// Real productions are under a subdirectory by the User's id |
|
1336
|
|
|
if (is_dir($sysdir.$file)) { |
|
1337
|
|
|
$subs = scandir($sysdir.$file); |
|
1338
|
|
|
foreach ($subs as $my => $sub) { |
|
1339
|
|
|
if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) { |
|
1340
|
|
|
echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>'; |
|
1341
|
|
|
} |
|
1342
|
|
|
} |
|
1343
|
|
|
} |
|
1344
|
|
|
} |
|
1345
|
|
|
echo '</ul></dd>'; |
|
1346
|
|
|
} |
|
1347
|
|
|
} |
|
1348
|
|
|
|
|
1349
|
|
|
/** |
|
1350
|
|
|
* @param string $content |
|
1351
|
|
|
* @param string $span_count |
|
1352
|
|
|
* |
|
1353
|
|
|
* @return string |
|
1354
|
|
|
*/ |
|
1355
|
|
|
public static function social_wrapper_div($content, $span_count) |
|
1356
|
|
|
{ |
|
1357
|
|
|
$span_count = (int) $span_count; |
|
1358
|
|
|
$html = '<div class="span'.$span_count.'">'; |
|
1359
|
|
|
$html .= '<div class="well_border">'; |
|
1360
|
|
|
$html .= $content; |
|
1361
|
|
|
$html .= '</div></div>'; |
|
1362
|
|
|
|
|
1363
|
|
|
return $html; |
|
1364
|
|
|
} |
|
1365
|
|
|
|
|
1366
|
|
|
/** |
|
1367
|
|
|
* Dummy function. |
|
1368
|
|
|
*/ |
|
1369
|
|
|
public static function get_plugins($place = SOCIAL_CENTER_PLUGIN) |
|
1370
|
|
|
{ |
|
1371
|
|
|
$content = ''; |
|
1372
|
|
|
switch ($place) { |
|
1373
|
|
|
case SOCIAL_CENTER_PLUGIN: |
|
1374
|
|
|
$social_plugins = [1, 2]; |
|
1375
|
|
|
if (is_array($social_plugins) && count($social_plugins) > 0) { |
|
1376
|
|
|
$content .= '<div id="social-plugins">'; |
|
1377
|
|
|
foreach ($social_plugins as $plugin) { |
|
1378
|
|
|
$content .= '<div class="social-plugin-item">'; |
|
1379
|
|
|
$content .= $plugin; |
|
1380
|
|
|
$content .= '</div>'; |
|
1381
|
|
|
} |
|
1382
|
|
|
$content .= '</div>'; |
|
1383
|
|
|
} |
|
1384
|
|
|
break; |
|
1385
|
|
|
case SOCIAL_LEFT_PLUGIN: |
|
1386
|
|
|
break; |
|
1387
|
|
|
case SOCIAL_RIGHT_PLUGIN: |
|
1388
|
|
|
break; |
|
1389
|
|
|
} |
|
1390
|
|
|
|
|
1391
|
|
|
return $content; |
|
1392
|
|
|
} |
|
1393
|
|
|
|
|
1394
|
|
|
/** |
|
1395
|
|
|
* Sends a message to someone's wall. |
|
1396
|
|
|
* |
|
1397
|
|
|
* @param int $userId id of author |
|
1398
|
|
|
* @param int $friendId id where we send the message |
|
1399
|
|
|
* @param string $messageContent of the message |
|
1400
|
|
|
* @param int $messageId id parent |
|
1401
|
|
|
* @param string $messageStatus status type of message |
|
1402
|
|
|
* |
|
1403
|
|
|
* @return int |
|
1404
|
|
|
* |
|
1405
|
|
|
* @author Yannick Warnier |
|
1406
|
|
|
*/ |
|
1407
|
|
|
public static function sendWallMessage( |
|
1408
|
|
|
$userId, |
|
1409
|
|
|
$friendId, |
|
1410
|
|
|
$messageContent, |
|
1411
|
|
|
$messageId = 0, |
|
1412
|
|
|
$messageStatus = '' |
|
1413
|
|
|
) { |
|
1414
|
|
|
$tblMessage = Database::get_main_table(TABLE_MESSAGE); |
|
1415
|
|
|
$userId = (int) $userId; |
|
1416
|
|
|
$friendId = (int) $friendId; |
|
1417
|
|
|
$messageId = (int) $messageId; |
|
1418
|
|
|
|
|
1419
|
|
|
if (empty($userId) || empty($friendId)) { |
|
1420
|
|
|
return 0; |
|
1421
|
|
|
} |
|
1422
|
|
|
|
|
1423
|
|
|
// Just in case we replace the and \n and \n\r while saving in the DB |
|
1424
|
|
|
$messageContent = str_replace(["\n", "\n\r"], '<br />', $messageContent); |
|
1425
|
|
|
$now = api_get_utc_datetime(); |
|
1426
|
|
|
|
|
1427
|
|
|
$attributes = [ |
|
1428
|
|
|
'user_sender_id' => $userId, |
|
1429
|
|
|
'user_receiver_id' => $friendId, |
|
1430
|
|
|
'msg_status' => $messageStatus, |
|
1431
|
|
|
'send_date' => $now, |
|
1432
|
|
|
'title' => '', |
|
1433
|
|
|
'content' => $messageContent, |
|
1434
|
|
|
'parent_id' => $messageId, |
|
1435
|
|
|
'group_id' => 0, |
|
1436
|
|
|
'update_date' => $now, |
|
1437
|
|
|
]; |
|
1438
|
|
|
|
|
1439
|
|
|
return Database::insert($tblMessage, $attributes); |
|
|
|
|
|
|
1440
|
|
|
} |
|
1441
|
|
|
|
|
1442
|
|
|
/** |
|
1443
|
|
|
* Send File attachment (jpg,png). |
|
1444
|
|
|
* |
|
1445
|
|
|
* @author Anibal Copitan |
|
1446
|
|
|
* |
|
1447
|
|
|
* @param int $userId id user |
|
1448
|
|
|
* @param array $fileAttach |
|
1449
|
|
|
* @param int $messageId id message (relation with main message) |
|
1450
|
|
|
* @param string $fileComment description attachment file |
|
1451
|
|
|
* |
|
1452
|
|
|
* @return bool|int |
|
1453
|
|
|
*/ |
|
1454
|
|
|
public static function sendWallMessageAttachmentFile( |
|
1455
|
|
|
$userId, |
|
1456
|
|
|
$fileAttach, |
|
1457
|
|
|
$messageId, |
|
1458
|
|
|
$fileComment = '' |
|
1459
|
|
|
) { |
|
1460
|
|
|
$safeFileName = Database::escape_string($fileAttach['name']); |
|
1461
|
|
|
|
|
1462
|
|
|
$extension = strtolower(substr(strrchr($safeFileName, '.'), 1)); |
|
1463
|
|
|
$allowedTypes = api_get_supported_image_extensions(); |
|
1464
|
|
|
|
|
1465
|
|
|
$allowedTypes[] = 'mp4'; |
|
1466
|
|
|
$allowedTypes[] = 'webm'; |
|
1467
|
|
|
$allowedTypes[] = 'ogg'; |
|
1468
|
|
|
|
|
1469
|
|
|
if (in_array($extension, $allowedTypes)) { |
|
1470
|
|
|
return MessageManager::saveMessageAttachmentFile($fileAttach, $fileComment, $messageId, $userId); |
|
1471
|
|
|
} |
|
1472
|
|
|
|
|
1473
|
|
|
return false; |
|
1474
|
|
|
} |
|
1475
|
|
|
|
|
1476
|
|
|
/** |
|
1477
|
|
|
* Gets all messages from someone's wall (within specific limits). |
|
1478
|
|
|
* |
|
1479
|
|
|
* @param int $userId id of wall shown |
|
1480
|
|
|
* @param int|string $parentId id message (Post main) |
|
1481
|
|
|
* @param int|array $groupId |
|
1482
|
|
|
* @param int|array $friendId |
|
1483
|
|
|
* @param string $startDate Date from which we want to show the messages, in UTC time |
|
1484
|
|
|
* @param int $start Limit for the number of parent messages we want to show |
|
1485
|
|
|
* @param int $length Wall message query offset |
|
1486
|
|
|
* @param bool $getCount |
|
1487
|
|
|
* @param array $threadList |
|
1488
|
|
|
* |
|
1489
|
|
|
* @return array|int |
|
1490
|
|
|
* |
|
1491
|
|
|
* @author Yannick Warnier |
|
1492
|
|
|
*/ |
|
1493
|
|
|
public static function getWallMessages( |
|
1494
|
|
|
$userId, |
|
1495
|
|
|
$parentId = 0, |
|
1496
|
|
|
$groupId = 0, |
|
1497
|
|
|
$friendId = 0, |
|
1498
|
|
|
$startDate = '', |
|
1499
|
|
|
$start = 0, |
|
1500
|
|
|
$length = 10, |
|
1501
|
|
|
$getCount = false, |
|
1502
|
|
|
$threadList = [] |
|
1503
|
|
|
) { |
|
1504
|
|
|
$tblMessage = Database::get_main_table(TABLE_MESSAGE); |
|
1505
|
|
|
|
|
1506
|
|
|
$parentId = (int) $parentId; |
|
1507
|
|
|
$userId = (int) $userId; |
|
1508
|
|
|
$start = (int) $start; |
|
1509
|
|
|
$length = (int) $length; |
|
1510
|
|
|
|
|
1511
|
|
|
$select = " SELECT |
|
1512
|
|
|
id, |
|
1513
|
|
|
user_sender_id, |
|
1514
|
|
|
user_receiver_id, |
|
1515
|
|
|
send_date, |
|
1516
|
|
|
content, |
|
1517
|
|
|
parent_id, |
|
1518
|
|
|
msg_status, |
|
1519
|
|
|
group_id, |
|
1520
|
|
|
'' as forum_id, |
|
1521
|
|
|
'' as thread_id, |
|
1522
|
|
|
'' as c_id |
|
1523
|
|
|
"; |
|
1524
|
|
|
|
|
1525
|
|
|
if ($getCount) { |
|
1526
|
|
|
$select = ' SELECT count(id) as count_items '; |
|
1527
|
|
|
} |
|
1528
|
|
|
|
|
1529
|
|
|
$sqlBase = "$select FROM $tblMessage m WHERE "; |
|
1530
|
|
|
$sql = []; |
|
1531
|
|
|
$sql[1] = $sqlBase."msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; |
|
1532
|
|
|
|
|
1533
|
|
|
// Get my own posts |
|
1534
|
|
|
$userReceiverCondition = ' ( |
|
1535
|
|
|
user_receiver_id = '.$userId.' AND |
|
1536
|
|
|
msg_status IN ('.MESSAGE_STATUS_WALL_POST.', '.MESSAGE_STATUS_WALL.') AND |
|
1537
|
|
|
parent_id = '.$parentId.' |
|
1538
|
|
|
)'; |
|
1539
|
|
|
|
|
1540
|
|
|
$sql[1] .= $userReceiverCondition; |
|
1541
|
|
|
|
|
1542
|
|
|
$sql[2] = $sqlBase.' msg_status = '.MESSAGE_STATUS_PROMOTED.' '; |
|
1543
|
|
|
|
|
1544
|
|
|
// Get my group posts |
|
1545
|
|
|
$groupCondition = ''; |
|
1546
|
|
|
if (!empty($groupId)) { |
|
1547
|
|
|
if (is_array($groupId)) { |
|
1548
|
|
|
$groupId = array_map('intval', $groupId); |
|
1549
|
|
|
$groupId = implode(",", $groupId); |
|
1550
|
|
|
$groupCondition = " ( group_id IN ($groupId) "; |
|
1551
|
|
|
} else { |
|
1552
|
|
|
$groupId = (int) $groupId; |
|
1553
|
|
|
$groupCondition = " ( group_id = $groupId "; |
|
1554
|
|
|
} |
|
1555
|
|
|
$groupCondition .= ' AND (msg_status = '.MESSAGE_STATUS_NEW.' OR msg_status = '.MESSAGE_STATUS_UNREAD.')) '; |
|
1556
|
|
|
} |
|
1557
|
|
|
if (!empty($groupCondition)) { |
|
1558
|
|
|
$sql[3] = $sqlBase.$groupCondition; |
|
1559
|
|
|
} |
|
1560
|
|
|
|
|
1561
|
|
|
// Get my friend posts |
|
1562
|
|
|
$friendCondition = ''; |
|
1563
|
|
|
if (!empty($friendId)) { |
|
1564
|
|
|
if (is_array($friendId)) { |
|
1565
|
|
|
$friendId = array_map('intval', $friendId); |
|
1566
|
|
|
$friendId = implode(",", $friendId); |
|
1567
|
|
|
$friendCondition = " ( user_receiver_id IN ($friendId) "; |
|
1568
|
|
|
} else { |
|
1569
|
|
|
$friendId = (int) $friendId; |
|
1570
|
|
|
$friendCondition = " ( user_receiver_id = $friendId "; |
|
1571
|
|
|
} |
|
1572
|
|
|
$friendCondition .= ' AND msg_status = '.MESSAGE_STATUS_WALL_POST.' AND parent_id = 0) '; |
|
1573
|
|
|
} |
|
1574
|
|
|
if (!empty($friendCondition)) { |
|
1575
|
|
|
$sql[4] = $sqlBase.$friendCondition; |
|
1576
|
|
|
} |
|
1577
|
|
|
|
|
1578
|
|
|
if (!empty($threadList)) { |
|
1579
|
|
|
if ($getCount) { |
|
1580
|
|
|
$select = ' SELECT count(iid) count_items '; |
|
1581
|
|
|
} else { |
|
1582
|
|
|
$select = " SELECT |
|
1583
|
|
|
iid as id, |
|
1584
|
|
|
poster_id as user_sender_id, |
|
1585
|
|
|
'' as user_receiver_id, |
|
1586
|
|
|
post_date as send_date, |
|
1587
|
|
|
post_text as content, |
|
1588
|
|
|
'' as parent_id, |
|
1589
|
|
|
".MESSAGE_STATUS_FORUM." as msg_status, |
|
1590
|
|
|
'' as group_id, |
|
1591
|
|
|
forum_id, |
|
1592
|
|
|
thread_id, |
|
1593
|
|
|
c_id |
|
1594
|
|
|
"; |
|
1595
|
|
|
} |
|
1596
|
|
|
|
|
1597
|
|
|
$threadList = array_map('intval', $threadList); |
|
1598
|
|
|
$threadList = implode("','", $threadList); |
|
1599
|
|
|
$condition = " thread_id IN ('$threadList') "; |
|
1600
|
|
|
$sql[5] = "$select |
|
1601
|
|
|
FROM c_forum_post |
|
1602
|
|
|
WHERE $condition |
|
1603
|
|
|
"; |
|
1604
|
|
|
} |
|
1605
|
|
|
|
|
1606
|
|
|
if ($getCount) { |
|
1607
|
|
|
$count = 0; |
|
1608
|
|
|
foreach ($sql as $oneQuery) { |
|
1609
|
|
|
if (!empty($oneQuery)) { |
|
1610
|
|
|
$res = Database::query($oneQuery); |
|
1611
|
|
|
$row = Database::fetch_array($res); |
|
1612
|
|
|
$count += (int) $row['count_items']; |
|
1613
|
|
|
} |
|
1614
|
|
|
} |
|
1615
|
|
|
|
|
1616
|
|
|
return $count; |
|
1617
|
|
|
} |
|
1618
|
|
|
|
|
1619
|
|
|
$sqlOrder = ' ORDER BY send_date DESC '; |
|
1620
|
|
|
$sqlLimit = " LIMIT $start, $length "; |
|
1621
|
|
|
$messages = []; |
|
1622
|
|
|
foreach ($sql as $index => $oneQuery) { |
|
1623
|
|
|
if ($index === 5) { |
|
1624
|
|
|
// Exception only for the forum query above (field name change) |
|
1625
|
|
|
$oneQuery .= ' ORDER BY post_date DESC '.$sqlLimit; |
|
1626
|
|
|
} else { |
|
1627
|
|
|
$oneQuery .= $sqlOrder.$sqlLimit; |
|
1628
|
|
|
} |
|
1629
|
|
|
$res = Database::query($oneQuery); |
|
1630
|
|
|
$em = Database::getManager(); |
|
1631
|
|
|
if (Database::num_rows($res) > 0) { |
|
1632
|
|
|
$repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); |
|
1633
|
|
|
$repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
|
1634
|
|
|
$groups = []; |
|
1635
|
|
|
$userGroup = new UserGroup(); |
|
1636
|
|
|
$urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id='; |
|
1637
|
|
|
while ($row = Database::fetch_array($res, 'ASSOC')) { |
|
1638
|
|
|
$row['group_info'] = []; |
|
1639
|
|
|
if (!empty($row['group_id'])) { |
|
1640
|
|
|
if (!in_array($row['group_id'], $groups)) { |
|
1641
|
|
|
$group = $userGroup->get($row['group_id']); |
|
1642
|
|
|
$group['url'] = $urlGroup.$group['id']; |
|
1643
|
|
|
$groups[$row['group_id']] = $group; |
|
1644
|
|
|
$row['group_info'] = $group; |
|
1645
|
|
|
} else { |
|
1646
|
|
|
$row['group_info'] = $groups[$row['group_id']]; |
|
1647
|
|
|
} |
|
1648
|
|
|
} |
|
1649
|
|
|
|
|
1650
|
|
|
// Forums |
|
1651
|
|
|
$row['post_title'] = ''; |
|
1652
|
|
|
$row['forum_title'] = ''; |
|
1653
|
|
|
$row['thread_url'] = ''; |
|
1654
|
|
|
if ($row['msg_status'] == MESSAGE_STATUS_FORUM) { |
|
1655
|
|
|
/** @var CForumPost $post */ |
|
1656
|
|
|
$post = $repo->find($row['id']); |
|
1657
|
|
|
/** @var CForumThread $thread */ |
|
1658
|
|
|
$thread = $repoThread->find($row['thread_id']); |
|
1659
|
|
|
if ($post && $thread) { |
|
1660
|
|
|
$courseInfo = api_get_course_info_by_id($post->getCId()); |
|
1661
|
|
|
$row['post_title'] = $post->getForumId(); |
|
1662
|
|
|
$row['forum_title'] = $thread->getThreadTitle(); |
|
1663
|
|
|
$row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
|
1664
|
|
|
'cidReq' => $courseInfo['code'], |
|
1665
|
|
|
'forum' => $post->getForumId(), |
|
1666
|
|
|
'thread' => $post->getThreadId(), |
|
|
|
|
|
|
1667
|
|
|
'post_id' => $post->getIid(), |
|
1668
|
|
|
]).'#post_id_'.$post->getIid(); |
|
1669
|
|
|
} |
|
1670
|
|
|
} |
|
1671
|
|
|
|
|
1672
|
|
|
$messages[$row['id']] = $row; |
|
1673
|
|
|
} |
|
1674
|
|
|
} |
|
1675
|
|
|
} |
|
1676
|
|
|
// Reordering messages by ID (reverse order) is enough to have the |
|
1677
|
|
|
// latest first, as there is currently no option to edit messages |
|
1678
|
|
|
// afterwards |
|
1679
|
|
|
krsort($messages); |
|
1680
|
|
|
|
|
1681
|
|
|
return $messages; |
|
1682
|
|
|
} |
|
1683
|
|
|
|
|
1684
|
|
|
/** |
|
1685
|
|
|
* Gets all messages from someone's wall (within specific limits), formatted. |
|
1686
|
|
|
* |
|
1687
|
|
|
* @param int $userId USER ID of the person's wall |
|
1688
|
|
|
* @param array $messageInfo |
|
1689
|
|
|
* @param string $start Start date (from when we want the messages until today) |
|
1690
|
|
|
* @param int $limit Limit to the number of messages we want |
|
1691
|
|
|
* @param int $offset Wall messages offset |
|
1692
|
|
|
* |
|
1693
|
|
|
* @return string HTML formatted string to show messages |
|
1694
|
|
|
*/ |
|
1695
|
|
|
public static function getWallPostComments( |
|
1696
|
|
|
$userId, |
|
1697
|
|
|
$messageInfo, |
|
1698
|
|
|
$start = null, |
|
1699
|
|
|
$limit = 10, |
|
1700
|
|
|
$offset = 0 |
|
1701
|
|
|
) { |
|
1702
|
|
|
$messageId = $messageInfo['id']; |
|
1703
|
|
|
$messages = MessageManager::getMessagesByParent($messageInfo['id'], 0, $offset, $limit); |
|
1704
|
|
|
$formattedList = '<div class="sub-mediapost row">'; |
|
1705
|
|
|
$users = []; |
|
1706
|
|
|
|
|
1707
|
|
|
// The messages are ordered by date descendant, for comments we need ascendant |
|
1708
|
|
|
krsort($messages); |
|
1709
|
|
|
foreach ($messages as $message) { |
|
1710
|
|
|
$userIdLoop = $message['user_sender_id']; |
|
1711
|
|
|
if (!isset($users[$userIdLoop])) { |
|
1712
|
|
|
$users[$userIdLoop] = api_get_user_info($userIdLoop); |
|
1713
|
|
|
} |
|
1714
|
|
|
$media = self::processPostComment($message, $users); |
|
1715
|
|
|
$formattedList .= $media; |
|
1716
|
|
|
} |
|
1717
|
|
|
|
|
1718
|
|
|
$formattedList .= '</div>'; |
|
1719
|
|
|
$formattedList .= '<div class="mediapost-form row">'; |
|
1720
|
|
|
$formattedList .= '<form class="form-horizontal" id="form_comment_'.$messageId.'" name="post_comment" method="POST"> |
|
1721
|
|
|
<div class="col-sm-9"> |
|
1722
|
|
|
<label for="comment" class="hide">'.get_lang('Write new comment').'</label> |
|
1723
|
|
|
<input type="hidden" name = "messageId" value="'.$messageId.'" /> |
|
1724
|
|
|
<textarea rows="3" class="form-control" placeholder="'.get_lang('Write new comment').'" name="comment" rows="1" ></textarea> |
|
1725
|
|
|
</div> |
|
1726
|
|
|
<div class="col-sm-3 pull-right"> |
|
1727
|
|
|
<a onclick="submitComment('.$messageId.');" href="javascript:void(0);" name="social_wall_new_msg_submit" class="btn btn-default btn-post"> |
|
1728
|
|
|
<em class="fa fa-pencil"></em> '.get_lang('Post').' |
|
1729
|
|
|
</a> |
|
1730
|
|
|
</div> |
|
1731
|
|
|
</form>'; |
|
1732
|
|
|
$formattedList .= '</div>'; |
|
1733
|
|
|
|
|
1734
|
|
|
return $formattedList; |
|
1735
|
|
|
} |
|
1736
|
|
|
|
|
1737
|
|
|
/** |
|
1738
|
|
|
* @param array $message |
|
1739
|
|
|
* @param array $users |
|
1740
|
|
|
* |
|
1741
|
|
|
* @return string |
|
1742
|
|
|
*/ |
|
1743
|
|
|
public static function processPostComment($message, $users = []) |
|
1744
|
|
|
{ |
|
1745
|
|
|
if (empty($message)) { |
|
1746
|
|
|
return false; |
|
|
|
|
|
|
1747
|
|
|
} |
|
1748
|
|
|
|
|
1749
|
|
|
$date = Display::dateToStringAgoAndLongDate($message['send_date']); |
|
1750
|
|
|
$currentUserId = api_get_user_id(); |
|
1751
|
|
|
$userIdLoop = $message['user_sender_id']; |
|
1752
|
|
|
$receiverId = $message['user_receiver_id']; |
|
1753
|
|
|
|
|
1754
|
|
|
if (!isset($users[$userIdLoop])) { |
|
1755
|
|
|
$users[$userIdLoop] = api_get_user_info($userIdLoop); |
|
1756
|
|
|
} |
|
1757
|
|
|
|
|
1758
|
|
|
$iconStatus = $users[$userIdLoop]['icon_status']; |
|
1759
|
|
|
$nameComplete = $users[$userIdLoop]['complete_name']; |
|
1760
|
|
|
$url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop; |
|
1761
|
|
|
|
|
1762
|
|
|
$comment = '<div class="rep-post col-md-12">'; |
|
1763
|
|
|
$comment .= '<div class="col-md-2 col-xs-2 social-post-answers">'; |
|
1764
|
|
|
$comment .= '<div class="user-image pull-right">'; |
|
1765
|
|
|
$comment .= '<a href="'.$url.'"> |
|
1766
|
|
|
<img src="'.$users[$userIdLoop]['avatar'].'" |
|
1767
|
|
|
alt="'.$users[$userIdLoop]['complete_name'].'" |
|
1768
|
|
|
class="avatar-thumb"> |
|
1769
|
|
|
</a>'; |
|
1770
|
|
|
$comment .= '</div>'; |
|
1771
|
|
|
$comment .= '</div>'; |
|
1772
|
|
|
$comment .= '<div class="col-md-7 col-xs-7 social-post-answers">'; |
|
1773
|
|
|
$comment .= '<div class="user-data">'; |
|
1774
|
|
|
$comment .= $iconStatus; |
|
1775
|
|
|
$comment .= '<div class="username"><a href="'.$url.'">'.$nameComplete.'</a> |
|
1776
|
|
|
<span>'.Security::remove_XSS($message['content']).'</span> |
|
1777
|
|
|
</div>'; |
|
1778
|
|
|
$comment .= '<div>'.$date.'</div>'; |
|
1779
|
|
|
$comment .= '<br />'; |
|
1780
|
|
|
$comment .= '</div>'; |
|
1781
|
|
|
$comment .= '</div>'; |
|
1782
|
|
|
|
|
1783
|
|
|
$comment .= '<div class="col-md-3 col-xs-3 social-post-answers">'; |
|
1784
|
|
|
$comment .= '<div class="pull-right btn-group btn-group-sm">'; |
|
1785
|
|
|
|
|
1786
|
|
|
$comment .= MessageManager::getLikesButton( |
|
1787
|
|
|
$message['id'], |
|
1788
|
|
|
$currentUserId |
|
1789
|
|
|
); |
|
1790
|
|
|
|
|
1791
|
|
|
$isOwnWall = $currentUserId == $userIdLoop || $currentUserId == $receiverId; |
|
1792
|
|
|
if ($isOwnWall) { |
|
1793
|
|
|
$comment .= Display::url( |
|
1794
|
|
|
Display::returnFontAwesomeIcon('trash', '', true), |
|
1795
|
|
|
'javascript:void(0)', |
|
1796
|
|
|
[ |
|
1797
|
|
|
'id' => 'message_'.$message['id'], |
|
1798
|
|
|
'title' => get_lang('Delete comment'), |
|
1799
|
|
|
'onclick' => 'deleteComment('.$message['id'].')', |
|
1800
|
|
|
'class' => 'btn btn-default', |
|
1801
|
|
|
] |
|
1802
|
|
|
); |
|
1803
|
|
|
} |
|
1804
|
|
|
$comment .= '</div>'; |
|
1805
|
|
|
$comment .= '</div>'; |
|
1806
|
|
|
$comment .= '</div>'; |
|
1807
|
|
|
|
|
1808
|
|
|
return $comment; |
|
1809
|
|
|
} |
|
1810
|
|
|
|
|
1811
|
|
|
/** |
|
1812
|
|
|
* @param array $message |
|
1813
|
|
|
* |
|
1814
|
|
|
* @return array |
|
1815
|
|
|
*/ |
|
1816
|
|
|
public static function getAttachmentPreviewList($message) |
|
1817
|
|
|
{ |
|
1818
|
|
|
$messageId = $message['id']; |
|
1819
|
|
|
|
|
1820
|
|
|
$list = []; |
|
1821
|
|
|
|
|
1822
|
|
|
if (empty($message['group_id'])) { |
|
1823
|
|
|
$files = MessageManager::getAttachmentList($messageId); |
|
1824
|
|
|
if ($files) { |
|
1825
|
|
|
$downloadUrl = api_get_path(WEB_CODE_PATH).'social/download.php?message_id='.$messageId; |
|
1826
|
|
|
foreach ($files as $row_file) { |
|
1827
|
|
|
$url = $downloadUrl.'&attachment_id='.$row_file['id']; |
|
1828
|
|
|
$display = Display::fileHtmlGuesser($row_file['filename'], $url); |
|
1829
|
|
|
$list[] = $display; |
|
1830
|
|
|
} |
|
1831
|
|
|
} |
|
1832
|
|
|
} else { |
|
1833
|
|
|
$list = MessageManager::getAttachmentLinkList($messageId, 0); |
|
1834
|
|
|
} |
|
1835
|
|
|
|
|
1836
|
|
|
return $list; |
|
1837
|
|
|
} |
|
1838
|
|
|
|
|
1839
|
|
|
/** |
|
1840
|
|
|
* @param array $message |
|
1841
|
|
|
* |
|
1842
|
|
|
* @return string |
|
1843
|
|
|
*/ |
|
1844
|
|
|
public static function getPostAttachment($message) |
|
1845
|
|
|
{ |
|
1846
|
|
|
$previews = self::getAttachmentPreviewList($message); |
|
1847
|
|
|
|
|
1848
|
|
|
if (empty($previews)) { |
|
1849
|
|
|
return ''; |
|
1850
|
|
|
} |
|
1851
|
|
|
|
|
1852
|
|
|
return implode('', $previews); |
|
1853
|
|
|
} |
|
1854
|
|
|
|
|
1855
|
|
|
/** |
|
1856
|
|
|
* @param array $messages |
|
1857
|
|
|
* |
|
1858
|
|
|
* @return array |
|
1859
|
|
|
*/ |
|
1860
|
|
|
public static function formatWallMessages($messages) |
|
1861
|
|
|
{ |
|
1862
|
|
|
$data = []; |
|
1863
|
|
|
$users = []; |
|
1864
|
|
|
foreach ($messages as $key => $message) { |
|
1865
|
|
|
$userIdLoop = $message['user_sender_id']; |
|
1866
|
|
|
$userFriendIdLoop = $message['user_receiver_id']; |
|
1867
|
|
|
if (!isset($users[$userIdLoop])) { |
|
1868
|
|
|
$users[$userIdLoop] = api_get_user_info($userIdLoop); |
|
1869
|
|
|
} |
|
1870
|
|
|
|
|
1871
|
|
|
if (!isset($users[$userFriendIdLoop])) { |
|
1872
|
|
|
$users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop); |
|
1873
|
|
|
} |
|
1874
|
|
|
|
|
1875
|
|
|
$html = self::headerMessagePost( |
|
1876
|
|
|
$users[$userIdLoop], |
|
1877
|
|
|
$users[$userFriendIdLoop], |
|
1878
|
|
|
$message |
|
1879
|
|
|
); |
|
1880
|
|
|
|
|
1881
|
|
|
$data[$key] = $message; |
|
1882
|
|
|
$data[$key]['html'] = $html; |
|
1883
|
|
|
} |
|
1884
|
|
|
|
|
1885
|
|
|
return $data; |
|
1886
|
|
|
} |
|
1887
|
|
|
|
|
1888
|
|
|
/** |
|
1889
|
|
|
* get html data with OpenGrap passing the URL. |
|
1890
|
|
|
* |
|
1891
|
|
|
* @param $link url |
|
1892
|
|
|
* |
|
1893
|
|
|
* @return string data html |
|
1894
|
|
|
*/ |
|
1895
|
|
|
public static function readContentWithOpenGraph($link) |
|
1896
|
|
|
{ |
|
1897
|
|
|
if (strpos($link, "://") === false && substr($link, 0, 1) != "/") { |
|
1898
|
|
|
$link = "http://".$link; |
|
1899
|
|
|
} |
|
1900
|
|
|
$graph = OpenGraph::fetch($link); |
|
1901
|
|
|
$link = parse_url($link); |
|
1902
|
|
|
$host = $link['host'] ? strtoupper($link['host']) : $link['path']; |
|
1903
|
|
|
if (!$graph) { |
|
1904
|
|
|
return false; |
|
|
|
|
|
|
1905
|
|
|
} |
|
1906
|
|
|
$url = $graph->url; |
|
1907
|
|
|
$image = $graph->image; |
|
1908
|
|
|
$description = $graph->description; |
|
1909
|
|
|
$title = $graph->title; |
|
1910
|
|
|
$html = '<div class="thumbnail social-thumbnail">'; |
|
1911
|
|
|
$html .= empty($image) ? '' : '<a target="_blank" href="'.$url.'"> |
|
1912
|
|
|
<img class="img-responsive social-image" src="'.$image.'" /></a>'; |
|
1913
|
|
|
$html .= '<div class="social-description">'; |
|
1914
|
|
|
$html .= '<a target="_blank" href="'.$url.'"><h5 class="social-title"><b>'.$title.'</b></h5></a>'; |
|
1915
|
|
|
$html .= empty($description) ? '' : '<span>'.$description.'</span>'; |
|
1916
|
|
|
$html .= empty($host) ? '' : '<p>'.$host.'</p>'; |
|
1917
|
|
|
$html .= '</div>'; |
|
1918
|
|
|
$html .= '</div>'; |
|
1919
|
|
|
|
|
1920
|
|
|
return $html; |
|
1921
|
|
|
} |
|
1922
|
|
|
|
|
1923
|
|
|
/** |
|
1924
|
|
|
* verify if Url Exist - Using Curl. |
|
1925
|
|
|
* |
|
1926
|
|
|
* @param $uri url |
|
1927
|
|
|
* |
|
1928
|
|
|
* @return bool |
|
1929
|
|
|
*/ |
|
1930
|
|
|
public static function verifyUrl($uri) |
|
1931
|
|
|
{ |
|
1932
|
|
|
$curl = curl_init($uri); |
|
1933
|
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, true); |
|
|
|
|
|
|
1934
|
|
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
|
1935
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
1936
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, 15); |
|
1937
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
|
1938
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
1939
|
|
|
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); |
|
1940
|
|
|
$response = curl_exec($curl); |
|
|
|
|
|
|
1941
|
|
|
curl_close($curl); |
|
|
|
|
|
|
1942
|
|
|
if (!empty($response)) { |
|
1943
|
|
|
return true; |
|
1944
|
|
|
} |
|
1945
|
|
|
|
|
1946
|
|
|
return false; |
|
1947
|
|
|
} |
|
1948
|
|
|
|
|
1949
|
|
|
/** |
|
1950
|
|
|
* Soft delete a message and his chidren. |
|
1951
|
|
|
* |
|
1952
|
|
|
* @param int $id id message to delete |
|
1953
|
|
|
* |
|
1954
|
|
|
* @return bool status query |
|
1955
|
|
|
*/ |
|
1956
|
|
|
public static function deleteMessage($id) |
|
1957
|
|
|
{ |
|
1958
|
|
|
$id = (int) $id; |
|
1959
|
|
|
$messageInfo = MessageManager::get_message_by_id($id); |
|
1960
|
|
|
if (!empty($messageInfo)) { |
|
1961
|
|
|
// Delete comments too |
|
1962
|
|
|
$messages = MessageManager::getMessagesByParent($id); |
|
1963
|
|
|
if (!empty($messages)) { |
|
1964
|
|
|
foreach ($messages as $message) { |
|
1965
|
|
|
self::deleteMessage($message['id']); |
|
1966
|
|
|
} |
|
1967
|
|
|
} |
|
1968
|
|
|
|
|
1969
|
|
|
// Soft delete message |
|
1970
|
|
|
$tblMessage = Database::get_main_table(TABLE_MESSAGE); |
|
1971
|
|
|
$statusMessage = MESSAGE_STATUS_WALL_DELETE; |
|
1972
|
|
|
$sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' "; |
|
1973
|
|
|
Database::query($sql); |
|
1974
|
|
|
|
|
1975
|
|
|
MessageManager::delete_message_attachment_file($id, $messageInfo['user_sender_id']); |
|
1976
|
|
|
MessageManager::delete_message_attachment_file($id, $messageInfo['user_receiver_id']); |
|
1977
|
|
|
|
|
1978
|
|
|
return true; |
|
1979
|
|
|
} |
|
1980
|
|
|
|
|
1981
|
|
|
return false; |
|
1982
|
|
|
} |
|
1983
|
|
|
|
|
1984
|
|
|
/** |
|
1985
|
|
|
* Generate the social block for a user. |
|
1986
|
|
|
* |
|
1987
|
|
|
* @param Template $template |
|
1988
|
|
|
* @param int $userId The user id |
|
1989
|
|
|
* @param string $groupBlock Optional. Highlight link possible values: |
|
1990
|
|
|
* group_add, home, messages, messages_inbox, messages_compose, |
|
1991
|
|
|
* messages_outbox, invitations, shared_profile, friends, groups, search |
|
1992
|
|
|
* @param int $groupId Optional. Group ID |
|
1993
|
|
|
* @param bool $show_full_profile |
|
1994
|
|
|
* |
|
1995
|
|
|
* @return string The HTML code with the social block |
|
1996
|
|
|
*/ |
|
1997
|
|
|
public static function setSocialUserBlock( |
|
1998
|
|
|
Template $template, |
|
1999
|
|
|
$userId, |
|
2000
|
|
|
$groupBlock = '', |
|
2001
|
|
|
$groupId = 0, |
|
2002
|
|
|
$show_full_profile = true |
|
2003
|
|
|
) { |
|
2004
|
|
|
if (api_get_setting('allow_social_tool') != 'true') { |
|
2005
|
|
|
return ''; |
|
2006
|
|
|
} |
|
2007
|
|
|
|
|
2008
|
|
|
$currentUserId = api_get_user_id(); |
|
2009
|
|
|
$userId = (int) $userId; |
|
2010
|
|
|
$userRelationType = 0; |
|
2011
|
|
|
|
|
2012
|
|
|
$socialAvatarBlock = self::show_social_avatar_block( |
|
2013
|
|
|
$groupBlock, |
|
2014
|
|
|
$groupId, |
|
2015
|
|
|
$userId |
|
2016
|
|
|
); |
|
2017
|
|
|
|
|
2018
|
|
|
$profileEditionLink = null; |
|
2019
|
|
|
if ($currentUserId === $userId) { |
|
2020
|
|
|
$profileEditionLink = Display::getProfileEditionLink($userId); |
|
2021
|
|
|
} else { |
|
2022
|
|
|
$userRelationType = self::get_relation_between_contacts($currentUserId, $userId); |
|
2023
|
|
|
} |
|
2024
|
|
|
|
|
2025
|
|
|
$options = api_get_configuration_value('profile_fields_visibility'); |
|
2026
|
|
|
if (isset($options['options'])) { |
|
2027
|
|
|
$options = $options['options']; |
|
2028
|
|
|
} |
|
2029
|
|
|
|
|
2030
|
|
|
$vCardUserLink = Display::getVCardUserLink($userId); |
|
2031
|
|
|
if (isset($options['vcard']) && $options['vcard'] === false) { |
|
2032
|
|
|
$vCardUserLink = ''; |
|
2033
|
|
|
} |
|
2034
|
|
|
|
|
2035
|
|
|
$userInfo = api_get_user_info($userId, true, false, true, true); |
|
2036
|
|
|
|
|
2037
|
|
|
if (isset($options['firstname']) && $options['firstname'] === false) { |
|
2038
|
|
|
$userInfo['firstname'] = ''; |
|
2039
|
|
|
} |
|
2040
|
|
|
if (isset($options['lastname']) && $options['lastname'] === false) { |
|
2041
|
|
|
$userInfo['lastname'] = ''; |
|
2042
|
|
|
} |
|
2043
|
|
|
|
|
2044
|
|
|
if (isset($options['email']) && $options['email'] === false) { |
|
2045
|
|
|
$userInfo['email'] = ''; |
|
2046
|
|
|
} |
|
2047
|
|
|
|
|
2048
|
|
|
// Ofaj |
|
2049
|
|
|
$hasCertificates = Certificate::getCertificateByUser($userId); |
|
2050
|
|
|
$userInfo['has_certificates'] = 0; |
|
2051
|
|
|
if (!empty($hasCertificates)) { |
|
2052
|
|
|
$userInfo['has_certificates'] = 1; |
|
2053
|
|
|
} |
|
2054
|
|
|
|
|
2055
|
|
|
$userInfo['is_admin'] = UserManager::is_admin($userId); |
|
2056
|
|
|
|
|
2057
|
|
|
$languageId = api_get_language_id($userInfo['language']); |
|
2058
|
|
|
$languageInfo = api_get_language_info($languageId); |
|
2059
|
|
|
if ($languageInfo) { |
|
2060
|
|
|
$userInfo['language'] = [ |
|
2061
|
|
|
'label' => $languageInfo['original_name'], |
|
2062
|
|
|
'value' => $languageInfo['english_name'], |
|
2063
|
|
|
'code' => $languageInfo['isocode'], |
|
2064
|
|
|
]; |
|
2065
|
|
|
} |
|
2066
|
|
|
|
|
2067
|
|
|
if (isset($options['language']) && $options['language'] === false) { |
|
2068
|
|
|
$userInfo['language'] = ''; |
|
2069
|
|
|
} |
|
2070
|
|
|
|
|
2071
|
|
|
if (isset($options['photo']) && $options['photo'] === false) { |
|
2072
|
|
|
$socialAvatarBlock = ''; |
|
2073
|
|
|
} |
|
2074
|
|
|
|
|
2075
|
|
|
$extraFieldBlock = self::getExtraFieldBlock($userId, true); |
|
2076
|
|
|
$showLanguageFlag = api_get_configuration_value('social_show_language_flag_in_profile'); |
|
2077
|
|
|
|
|
2078
|
|
|
$template->assign('user', $userInfo); |
|
2079
|
|
|
$template->assign('show_language_flag', $showLanguageFlag); |
|
2080
|
|
|
$template->assign('extra_info', $extraFieldBlock); |
|
2081
|
|
|
$template->assign('social_avatar_block', $socialAvatarBlock); |
|
2082
|
|
|
$template->assign('profile_edition_link', $profileEditionLink); |
|
2083
|
|
|
//Added the link to export the vCard to the Template |
|
2084
|
|
|
|
|
2085
|
|
|
//If not friend $show_full_profile is False and the user can't see Email Address and Vcard Download Link |
|
2086
|
|
|
if ($show_full_profile) { |
|
2087
|
|
|
$template->assign('vcard_user_link', $vCardUserLink); |
|
2088
|
|
|
} |
|
2089
|
|
|
|
|
2090
|
|
|
if (api_get_setting('gamification_mode') === '1') { |
|
2091
|
|
|
$gamificationPoints = GamificationUtils::getTotalUserPoints( |
|
2092
|
|
|
$userId, |
|
2093
|
|
|
$userInfo['status'] |
|
2094
|
|
|
); |
|
2095
|
|
|
|
|
2096
|
|
|
$template->assign('gamification_points', $gamificationPoints); |
|
2097
|
|
|
} |
|
2098
|
|
|
$chatEnabled = api_is_global_chat_enabled(); |
|
2099
|
|
|
|
|
2100
|
|
|
if (isset($options['chat']) && $options['chat'] === false) { |
|
2101
|
|
|
$chatEnabled = ''; |
|
2102
|
|
|
} |
|
2103
|
|
|
|
|
2104
|
|
|
$template->assign('chat_enabled', $chatEnabled); |
|
2105
|
|
|
$template->assign('user_relation', $userRelationType); |
|
2106
|
|
|
$template->assign('user_relation_type_friend', USER_RELATION_TYPE_FRIEND); |
|
2107
|
|
|
$template->assign('show_full_profile', $show_full_profile); |
|
2108
|
|
|
|
|
2109
|
|
|
$templateName = $template->get_template('social/user_block.tpl'); |
|
2110
|
|
|
|
|
2111
|
|
|
if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) { |
|
2112
|
|
|
$templateName = $template->get_template('social/group_block.tpl'); |
|
2113
|
|
|
} |
|
2114
|
|
|
|
|
2115
|
|
|
$template->assign('social_avatar_block', $template->fetch($templateName)); |
|
2116
|
|
|
} |
|
2117
|
|
|
|
|
2118
|
|
|
/** |
|
2119
|
|
|
* @param int $user_id |
|
2120
|
|
|
* @param $link_shared |
|
2121
|
|
|
* @param bool $showLinkToChat |
|
2122
|
|
|
* |
|
2123
|
|
|
* @return string |
|
2124
|
|
|
*/ |
|
2125
|
|
|
public static function listMyFriendsBlock($user_id, $link_shared = '', $showLinkToChat = false) |
|
2126
|
|
|
{ |
|
2127
|
|
|
//SOCIALGOODFRIEND , USER_RELATION_TYPE_FRIEND, USER_RELATION_TYPE_PARENT |
|
2128
|
|
|
$friends = self::get_friends($user_id, USER_RELATION_TYPE_FRIEND); |
|
2129
|
|
|
$numberFriends = count($friends); |
|
2130
|
|
|
$friendHtml = ''; |
|
2131
|
|
|
|
|
2132
|
|
|
if (!empty($numberFriends)) { |
|
2133
|
|
|
$friendHtml .= '<div class="list-group contact-list">'; |
|
2134
|
|
|
$j = 1; |
|
2135
|
|
|
|
|
2136
|
|
|
usort( |
|
2137
|
|
|
$friends, |
|
2138
|
|
|
function ($a, $b) { |
|
2139
|
|
|
return strcmp($b['user_info']['user_is_online_in_chat'], $a['user_info']['user_is_online_in_chat']); |
|
2140
|
|
|
} |
|
2141
|
|
|
); |
|
2142
|
|
|
|
|
2143
|
|
|
foreach ($friends as $friend) { |
|
2144
|
|
|
if ($j > $numberFriends) { |
|
2145
|
|
|
break; |
|
2146
|
|
|
} |
|
2147
|
|
|
$name_user = api_get_person_name($friend['firstName'], $friend['lastName']); |
|
2148
|
|
|
$user_info_friend = api_get_user_info($friend['friend_user_id'], true); |
|
2149
|
|
|
|
|
2150
|
|
|
$statusIcon = Display::return_icon('statusoffline.png', get_lang('Offline')); |
|
2151
|
|
|
$status = 0; |
|
2152
|
|
|
if (!empty($user_info_friend['user_is_online_in_chat'])) { |
|
2153
|
|
|
$statusIcon = Display::return_icon('statusonline.png', get_lang('Online')); |
|
2154
|
|
|
$status = 1; |
|
2155
|
|
|
} |
|
2156
|
|
|
|
|
2157
|
|
|
$friendAvatarMedium = UserManager::getUserPicture( |
|
2158
|
|
|
$friend['friend_user_id'], |
|
2159
|
|
|
USER_IMAGE_SIZE_MEDIUM |
|
2160
|
|
|
); |
|
2161
|
|
|
$friendAvatarSmall = UserManager::getUserPicture( |
|
2162
|
|
|
$friend['friend_user_id'], |
|
2163
|
|
|
USER_IMAGE_SIZE_SMALL |
|
2164
|
|
|
); |
|
2165
|
|
|
$friend_avatar = '<img src="'.$friendAvatarMedium.'" id="imgfriend_'.$friend['friend_user_id'].'" title="'.$name_user.'" class="user-image"/>'; |
|
2166
|
|
|
|
|
2167
|
|
|
$relation = self::get_relation_between_contacts( |
|
2168
|
|
|
$friend['friend_user_id'], |
|
2169
|
|
|
api_get_user_id() |
|
2170
|
|
|
); |
|
2171
|
|
|
|
|
2172
|
|
|
if ($showLinkToChat) { |
|
2173
|
|
|
$friendHtml .= '<a onclick="javascript:chatWith(\''.$friend['friend_user_id'].'\', \''.$name_user.'\', \''.$status.'\',\''.$friendAvatarSmall.'\')" href="javascript:void(0);" class="list-group-item">'; |
|
2174
|
|
|
$friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
|
2175
|
|
|
$friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
|
2176
|
|
|
} else { |
|
2177
|
|
|
$link_shared = empty($link_shared) ? '' : '&'.$link_shared; |
|
2178
|
|
|
$friendHtml .= '<a href="profile.php?'.'u='.$friend['friend_user_id'].$link_shared.'" class="list-group-item">'; |
|
2179
|
|
|
$friendHtml .= $friend_avatar.' <span class="username">'.$name_user.'</span>'; |
|
2180
|
|
|
$friendHtml .= '<span class="status">'.$statusIcon.'</span>'; |
|
2181
|
|
|
} |
|
2182
|
|
|
|
|
2183
|
|
|
$friendHtml .= '</a>'; |
|
2184
|
|
|
|
|
2185
|
|
|
$j++; |
|
2186
|
|
|
} |
|
2187
|
|
|
$friendHtml .= '</div>'; |
|
2188
|
|
|
} else { |
|
2189
|
|
|
$friendHtml = Display::return_message(get_lang('No friends in your contact list'), 'warning'); |
|
2190
|
|
|
} |
|
2191
|
|
|
|
|
2192
|
|
|
return $friendHtml; |
|
2193
|
|
|
} |
|
2194
|
|
|
|
|
2195
|
|
|
/** |
|
2196
|
|
|
* @return string Get the JS code necessary for social wall to load open graph from URLs. |
|
2197
|
|
|
*/ |
|
2198
|
|
|
public static function getScriptToGetOpenGraph() |
|
2199
|
|
|
{ |
|
2200
|
|
|
return '<script> |
|
2201
|
|
|
$(function() { |
|
2202
|
|
|
$("[name=\'social_wall_new_msg_main\']").on("paste", function(e) { |
|
2203
|
|
|
$.ajax({ |
|
2204
|
|
|
contentType: "application/x-www-form-urlencoded", |
|
2205
|
|
|
beforeSend: function() { |
|
2206
|
|
|
$("[name=\'wall_post_button\']").prop( "disabled", true ); |
|
2207
|
|
|
$(".panel-preview").hide(); |
|
2208
|
|
|
$(".spinner").html("' |
|
2209
|
|
|
.'<div class=\'text-center\'>' |
|
2210
|
|
|
.'<em class=\'fa fa-spinner fa-pulse fa-1x\'></em>' |
|
2211
|
|
|
.'<p>'.get_lang('Loading').' '.get_lang('Preview').'</p>' |
|
2212
|
|
|
.'</div>' |
|
2213
|
|
|
.'"); |
|
2214
|
|
|
}, |
|
2215
|
|
|
type: "POST", |
|
2216
|
|
|
url: "'.api_get_path(WEB_AJAX_PATH).'social.ajax.php?a=read_url_with_open_graph", |
|
2217
|
|
|
data: "social_wall_new_msg_main=" + e.originalEvent.clipboardData.getData("text"), |
|
2218
|
|
|
success: function(response) { |
|
2219
|
|
|
$("[name=\'wall_post_button\']").prop("disabled", false); |
|
2220
|
|
|
if (!response == false) { |
|
2221
|
|
|
$(".spinner").html(""); |
|
2222
|
|
|
$(".panel-preview").show(); |
|
2223
|
|
|
$(".url_preview").html(response); |
|
2224
|
|
|
$("[name=\'url_content\']").val(response); |
|
2225
|
|
|
$(".url_preview img").addClass("img-responsive"); |
|
2226
|
|
|
} else { |
|
2227
|
|
|
$(".spinner").html(""); |
|
2228
|
|
|
} |
|
2229
|
|
|
} |
|
2230
|
|
|
}); |
|
2231
|
|
|
}); |
|
2232
|
|
|
}); |
|
2233
|
|
|
</script>'; |
|
2234
|
|
|
} |
|
2235
|
|
|
|
|
2236
|
|
|
/** |
|
2237
|
|
|
* @param string $urlForm |
|
2238
|
|
|
* |
|
2239
|
|
|
* @return string |
|
2240
|
|
|
*/ |
|
2241
|
|
|
public static function getWallForm($urlForm) |
|
2242
|
|
|
{ |
|
2243
|
|
|
$userId = isset($_GET['u']) ? '?u='.intval($_GET['u']) : ''; |
|
2244
|
|
|
$form = new FormValidator( |
|
2245
|
|
|
'social_wall_main', |
|
2246
|
|
|
'post', |
|
2247
|
|
|
$urlForm.$userId, |
|
2248
|
|
|
null, |
|
2249
|
|
|
['enctype' => 'multipart/form-data'], |
|
2250
|
|
|
FormValidator::LAYOUT_HORIZONTAL |
|
2251
|
|
|
); |
|
2252
|
|
|
|
|
2253
|
|
|
$socialWallPlaceholder = isset($_GET['u']) ? get_lang('Write something on your friend\'s wall') : get_lang( |
|
2254
|
|
|
'Social wallWhatAreYouThinkingAbout' |
|
2255
|
|
|
); |
|
2256
|
|
|
|
|
2257
|
|
|
$form->addTextarea( |
|
2258
|
|
|
'social_wall_new_msg_main', |
|
2259
|
|
|
null, |
|
2260
|
|
|
[ |
|
2261
|
|
|
'placeholder' => $socialWallPlaceholder, |
|
2262
|
|
|
'cols-size' => [1, 12, 1], |
|
2263
|
|
|
'aria-label' => $socialWallPlaceholder, |
|
2264
|
|
|
] |
|
2265
|
|
|
); |
|
2266
|
|
|
$form->addHtml('<div class="form-group">'); |
|
2267
|
|
|
$form->addHtml('<div class="col-sm-6">'); |
|
2268
|
|
|
$form->addFile('picture', get_lang('File upload'), ['custom' => true]); |
|
2269
|
|
|
$form->addHtml('</div>'); |
|
2270
|
|
|
$form->addHtml('<div class="col-sm-6 "><div class="pull-right">'); |
|
2271
|
|
|
$form->addButtonSend( |
|
2272
|
|
|
get_lang('Post'), |
|
2273
|
|
|
'wall_post_button', |
|
2274
|
|
|
false, |
|
2275
|
|
|
[ |
|
2276
|
|
|
'cols-size' => [1, 10, 1], |
|
2277
|
|
|
'custom' => true, |
|
2278
|
|
|
] |
|
2279
|
|
|
); |
|
2280
|
|
|
$form->addHtml('</div></div>'); |
|
2281
|
|
|
$form->addHtml('</div>'); |
|
2282
|
|
|
$form->addHidden('url_content', ''); |
|
2283
|
|
|
$html = Display::panel($form->returnForm(), get_lang('Social wall')); |
|
2284
|
|
|
|
|
2285
|
|
|
return $html; |
|
2286
|
|
|
} |
|
2287
|
|
|
|
|
2288
|
|
|
/** |
|
2289
|
|
|
* @param int $userId |
|
2290
|
|
|
* @param int $start |
|
2291
|
|
|
* @param int $length |
|
2292
|
|
|
* @param array $threadList |
|
2293
|
|
|
* |
|
2294
|
|
|
* @return array |
|
2295
|
|
|
*/ |
|
2296
|
|
|
public static function getMyWallMessages($userId, $start = 0, $length = 10, $threadList = []) |
|
2297
|
|
|
{ |
|
2298
|
|
|
$userGroup = new UserGroup(); |
|
2299
|
|
|
$groups = $userGroup->get_groups_by_user($userId, [GROUP_USER_PERMISSION_READER, GROUP_USER_PERMISSION_ADMIN]); |
|
2300
|
|
|
$groupList = []; |
|
2301
|
|
|
if (!empty($groups)) { |
|
2302
|
|
|
$groupList = array_column($groups, 'id'); |
|
2303
|
|
|
} |
|
2304
|
|
|
|
|
2305
|
|
|
$friends = self::get_friends($userId, USER_RELATION_TYPE_FRIEND); |
|
2306
|
|
|
$friendList = []; |
|
2307
|
|
|
if (!empty($friends)) { |
|
2308
|
|
|
$friendList = array_column($friends, 'friend_user_id'); |
|
2309
|
|
|
} |
|
2310
|
|
|
|
|
2311
|
|
|
$messages = self::getWallMessages( |
|
2312
|
|
|
$userId, |
|
2313
|
|
|
0, |
|
2314
|
|
|
$groupList, |
|
2315
|
|
|
$friendList, |
|
2316
|
|
|
'', |
|
2317
|
|
|
$start, |
|
2318
|
|
|
$length, |
|
2319
|
|
|
false, |
|
2320
|
|
|
$threadList |
|
2321
|
|
|
); |
|
2322
|
|
|
|
|
2323
|
|
|
$countPost = self::getCountWallMessagesByUser($userId, $groupList, $friendList, $threadList); |
|
2324
|
|
|
$messages = self::formatWallMessages($messages); |
|
|
|
|
|
|
2325
|
|
|
|
|
2326
|
|
|
$html = ''; |
|
2327
|
|
|
foreach ($messages as $message) { |
|
2328
|
|
|
$post = $message['html']; |
|
2329
|
|
|
$comments = ''; |
|
2330
|
|
|
if (in_array($message['msg_status'], [MESSAGE_STATUS_WALL_POST, MESSAGE_STATUS_PROMOTED])) { |
|
2331
|
|
|
$comments = self::getWallPostComments($userId, $message); |
|
2332
|
|
|
} |
|
2333
|
|
|
|
|
2334
|
|
|
$html .= self::wrapPost($message, $post.$comments); |
|
2335
|
|
|
} |
|
2336
|
|
|
|
|
2337
|
|
|
return [ |
|
2338
|
|
|
'posts' => $html, |
|
2339
|
|
|
'count' => $countPost, |
|
2340
|
|
|
]; |
|
2341
|
|
|
} |
|
2342
|
|
|
|
|
2343
|
|
|
/** |
|
2344
|
|
|
* @param string $message |
|
2345
|
|
|
* @param string $content |
|
2346
|
|
|
* |
|
2347
|
|
|
* @return string |
|
2348
|
|
|
*/ |
|
2349
|
|
|
public static function wrapPost($message, $content) |
|
2350
|
|
|
{ |
|
2351
|
|
|
$class = ''; |
|
2352
|
|
|
if ($message['msg_status'] === MESSAGE_STATUS_PROMOTED) { |
|
2353
|
|
|
$class = 'promoted_post'; |
|
2354
|
|
|
} |
|
2355
|
|
|
|
|
2356
|
|
|
return Display::panel($content, '', |
|
2357
|
|
|
'', |
|
2358
|
|
|
'default', |
|
2359
|
|
|
'', |
|
2360
|
|
|
'post_'.$message['id'], |
|
2361
|
|
|
null, |
|
2362
|
|
|
$class |
|
2363
|
|
|
); |
|
2364
|
|
|
} |
|
2365
|
|
|
|
|
2366
|
|
|
/** |
|
2367
|
|
|
* @param int $userId |
|
2368
|
|
|
* @param array $groupList |
|
2369
|
|
|
* @param array $friendList |
|
2370
|
|
|
* @param array $threadList |
|
2371
|
|
|
* |
|
2372
|
|
|
* @return int |
|
2373
|
|
|
*/ |
|
2374
|
|
|
public static function getCountWallMessagesByUser($userId, $groupList = [], $friendList = [], $threadList = []) |
|
2375
|
|
|
{ |
|
2376
|
|
|
$count = self::getWallMessages( |
|
2377
|
|
|
$userId, |
|
2378
|
|
|
0, |
|
2379
|
|
|
$groupList, |
|
2380
|
|
|
$friendList, |
|
2381
|
|
|
'', |
|
2382
|
|
|
0, |
|
2383
|
|
|
0, |
|
2384
|
|
|
true, |
|
2385
|
|
|
$threadList |
|
2386
|
|
|
); |
|
2387
|
|
|
|
|
2388
|
|
|
return $count; |
|
2389
|
|
|
} |
|
2390
|
|
|
|
|
2391
|
|
|
/** |
|
2392
|
|
|
* @param int $userId |
|
2393
|
|
|
* |
|
2394
|
|
|
* @return string |
|
2395
|
|
|
*/ |
|
2396
|
|
|
public static function getWallMessagesByUser($userId) |
|
2397
|
|
|
{ |
|
2398
|
|
|
$messages = self::getWallMessages($userId); |
|
2399
|
|
|
$messages = self::formatWallMessages($messages); |
|
|
|
|
|
|
2400
|
|
|
|
|
2401
|
|
|
$html = ''; |
|
2402
|
|
|
foreach ($messages as $message) { |
|
2403
|
|
|
$post = $message['html']; |
|
2404
|
|
|
$comments = self::getWallPostComments($userId, $message); |
|
2405
|
|
|
$html .= self::wrapPost($message, $post.$comments); |
|
2406
|
|
|
} |
|
2407
|
|
|
|
|
2408
|
|
|
return $html; |
|
2409
|
|
|
} |
|
2410
|
|
|
|
|
2411
|
|
|
/** |
|
2412
|
|
|
* Get HTML code block for user skills. |
|
2413
|
|
|
* |
|
2414
|
|
|
* @param int $userId The user ID |
|
2415
|
|
|
* @param string $orientation |
|
2416
|
|
|
* |
|
2417
|
|
|
* @return string |
|
2418
|
|
|
*/ |
|
2419
|
|
|
public static function getSkillBlock($userId, $orientation = 'horizontal') |
|
2420
|
|
|
{ |
|
2421
|
|
|
if (Skill::isAllowed($userId, false) === false) { |
|
2422
|
|
|
return ''; |
|
2423
|
|
|
} |
|
2424
|
|
|
|
|
2425
|
|
|
$skill = new Skill(); |
|
2426
|
|
|
$ranking = $skill->getUserSkillRanking($userId); |
|
2427
|
|
|
|
|
2428
|
|
|
$template = new Template(null, false, false, false, false, false); |
|
2429
|
|
|
$template->assign('ranking', $ranking); |
|
2430
|
|
|
$template->assign('orientation', $orientation); |
|
2431
|
|
|
$template->assign('skills', $skill->getUserSkillsTable($userId, 0, 0, false)['skills']); |
|
2432
|
|
|
$template->assign('user_id', $userId); |
|
2433
|
|
|
$template->assign('show_skills_report_link', api_is_student() || api_is_student_boss() || api_is_drh()); |
|
2434
|
|
|
|
|
2435
|
|
|
$skillBlock = $template->get_template('social/skills_block.tpl'); |
|
2436
|
|
|
|
|
2437
|
|
|
return $template->fetch($skillBlock); |
|
2438
|
|
|
} |
|
2439
|
|
|
|
|
2440
|
|
|
/** |
|
2441
|
|
|
* @param int $user_id |
|
2442
|
|
|
* @param bool $isArray |
|
2443
|
|
|
* |
|
2444
|
|
|
* @return string|array |
|
2445
|
|
|
*/ |
|
2446
|
|
|
public static function getExtraFieldBlock($user_id, $isArray = false) |
|
2447
|
|
|
{ |
|
2448
|
|
|
$fieldVisibility = api_get_configuration_value('profile_fields_visibility'); |
|
2449
|
|
|
$fieldVisibilityKeys = []; |
|
2450
|
|
|
if (isset($fieldVisibility['options'])) { |
|
2451
|
|
|
$fieldVisibility = $fieldVisibility['options']; |
|
2452
|
|
|
$fieldVisibilityKeys = array_keys($fieldVisibility); |
|
2453
|
|
|
} |
|
2454
|
|
|
|
|
2455
|
|
|
$t_ufo = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS); |
|
2456
|
|
|
$extra_user_data = UserManager::get_extra_user_data($user_id); |
|
2457
|
|
|
|
|
2458
|
|
|
$extra_information = ''; |
|
2459
|
|
|
if (is_array($extra_user_data) && count($extra_user_data) > 0) { |
|
2460
|
|
|
$extra_information_value = ''; |
|
2461
|
|
|
$extraField = new ExtraField('user'); |
|
2462
|
|
|
$listType = []; |
|
2463
|
|
|
$extraFieldItem = []; |
|
2464
|
|
|
foreach ($extra_user_data as $key => $data) { |
|
2465
|
|
|
if (empty($data)) { |
|
2466
|
|
|
continue; |
|
2467
|
|
|
} |
|
2468
|
|
|
if (in_array($key, $fieldVisibilityKeys) && $fieldVisibility[$key] === false) { |
|
2469
|
|
|
continue; |
|
2470
|
|
|
} |
|
2471
|
|
|
|
|
2472
|
|
|
// Avoiding parameters |
|
2473
|
|
|
if (in_array( |
|
2474
|
|
|
$key, |
|
2475
|
|
|
[ |
|
2476
|
|
|
'mail_notify_invitation', |
|
2477
|
|
|
'mail_notify_message', |
|
2478
|
|
|
'mail_notify_group_message', |
|
2479
|
|
|
] |
|
2480
|
|
|
)) { |
|
2481
|
|
|
continue; |
|
2482
|
|
|
} |
|
2483
|
|
|
// get display text, visibility and type from user_field table |
|
2484
|
|
|
$field_variable = str_replace('extra_', '', $key); |
|
2485
|
|
|
|
|
2486
|
|
|
$extraFieldInfo = $extraField->get_handler_field_info_by_field_variable( |
|
2487
|
|
|
$field_variable |
|
2488
|
|
|
); |
|
2489
|
|
|
|
|
2490
|
|
|
if (in_array($extraFieldInfo['variable'], ['skype', 'linkedin_url'])) { |
|
2491
|
|
|
continue; |
|
2492
|
|
|
} |
|
2493
|
|
|
|
|
2494
|
|
|
// if is not visible skip |
|
2495
|
|
|
if ($extraFieldInfo['visible_to_self'] != 1) { |
|
2496
|
|
|
continue; |
|
2497
|
|
|
} |
|
2498
|
|
|
|
|
2499
|
|
|
// if is not visible to others skip also |
|
2500
|
|
|
if ($extraFieldInfo['visible_to_others'] != 1) { |
|
2501
|
|
|
continue; |
|
2502
|
|
|
} |
|
2503
|
|
|
|
|
2504
|
|
|
if (is_array($data)) { |
|
2505
|
|
|
switch ($extraFieldInfo['field_type']) { |
|
2506
|
|
|
case ExtraField::FIELD_TYPE_RADIO: |
|
2507
|
|
|
$objEfOption = new ExtraFieldOption('user'); |
|
2508
|
|
|
$value = $data['extra_'.$extraFieldInfo['variable']]; |
|
2509
|
|
|
$optionInfo = $objEfOption->get_field_option_by_field_and_option( |
|
2510
|
|
|
$extraFieldInfo['id'], |
|
2511
|
|
|
$value |
|
2512
|
|
|
); |
|
2513
|
|
|
|
|
2514
|
|
|
if ($optionInfo && isset($optionInfo[0])) { |
|
2515
|
|
|
$optionInfo = $optionInfo[0]; |
|
2516
|
|
|
$extraFieldItem = [ |
|
2517
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2518
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2519
|
|
|
'value' => $optionInfo['display_text'], |
|
2520
|
|
|
]; |
|
2521
|
|
|
} else { |
|
2522
|
|
|
$extraFieldItem = [ |
|
2523
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2524
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2525
|
|
|
'value' => implode(',', $data), |
|
2526
|
|
|
]; |
|
2527
|
|
|
} |
|
2528
|
|
|
break; |
|
2529
|
|
|
default: |
|
2530
|
|
|
$extra_information_value .= |
|
2531
|
|
|
'<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).' ' |
|
2532
|
|
|
.' '.implode(',', $data).'</li>'; |
|
2533
|
|
|
$extraFieldItem = [ |
|
2534
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2535
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2536
|
|
|
'value' => implode(',', $data), |
|
2537
|
|
|
]; |
|
2538
|
|
|
break; |
|
2539
|
|
|
} |
|
2540
|
|
|
} else { |
|
2541
|
|
|
switch ($extraFieldInfo['field_type']) { |
|
2542
|
|
|
case ExtraField::FIELD_TYPE_RADIO: |
|
2543
|
|
|
$objEfOption = new ExtraFieldOption('user'); |
|
2544
|
|
|
$optionInfo = $objEfOption->get_field_option_by_field_and_option($extraFieldInfo['id'], $extraFieldInfo['value']); |
|
2545
|
|
|
break; |
|
2546
|
|
|
case ExtraField::FIELD_TYPE_GEOLOCALIZATION_COORDINATES: |
|
2547
|
|
|
case ExtraField::FIELD_TYPE_GEOLOCALIZATION: |
|
2548
|
|
|
$data = explode('::', $data); |
|
2549
|
|
|
$data = $data[0]; |
|
2550
|
|
|
$extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>'; |
|
2551
|
|
|
$extraFieldItem = [ |
|
2552
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2553
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2554
|
|
|
'value' => $data, |
|
2555
|
|
|
]; |
|
2556
|
|
|
break; |
|
2557
|
|
|
case ExtraField::FIELD_TYPE_DOUBLE_SELECT: |
|
2558
|
|
|
$id_options = explode('::', $data); |
|
2559
|
|
|
$value_options = []; |
|
2560
|
|
|
// get option display text from user_field_options table |
|
2561
|
|
|
foreach ($id_options as $id_option) { |
|
2562
|
|
|
$sql = "SELECT display_text |
|
2563
|
|
|
FROM $t_ufo |
|
2564
|
|
|
WHERE id = '$id_option'"; |
|
2565
|
|
|
$res_options = Database::query($sql); |
|
2566
|
|
|
$row_options = Database::fetch_row($res_options); |
|
2567
|
|
|
$value_options[] = $row_options[0]; |
|
2568
|
|
|
} |
|
2569
|
|
|
$extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': ' |
|
2570
|
|
|
.' '.implode(' ', $value_options).'</li>'; |
|
2571
|
|
|
$extraFieldItem = [ |
|
2572
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2573
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2574
|
|
|
'value' => $value_options, |
|
2575
|
|
|
]; |
|
2576
|
|
|
break; |
|
2577
|
|
|
case ExtraField::FIELD_TYPE_TAG: |
|
2578
|
|
|
$user_tags = UserManager::get_user_tags($user_id, $extraFieldInfo['id']); |
|
2579
|
|
|
|
|
2580
|
|
|
$tag_tmp = ''; |
|
2581
|
|
|
foreach ($user_tags as $tags) { |
|
2582
|
|
|
$tag_tmp .= '<a class="label label_tag"' |
|
2583
|
|
|
.' href="'.api_get_path(WEB_PATH).'main/social/search.php?q='.$tags['tag'].'">' |
|
2584
|
|
|
.$tags['tag'] |
|
2585
|
|
|
.'</a>'; |
|
2586
|
|
|
} |
|
2587
|
|
|
if (is_array($user_tags) && count($user_tags) > 0) { |
|
2588
|
|
|
$extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': ' |
|
2589
|
|
|
.' '.$tag_tmp.'</li>'; |
|
2590
|
|
|
} |
|
2591
|
|
|
$extraFieldItem = [ |
|
2592
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2593
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2594
|
|
|
'value' => $tag_tmp, |
|
2595
|
|
|
]; |
|
2596
|
|
|
break; |
|
2597
|
|
|
case ExtraField::FIELD_TYPE_SOCIAL_PROFILE: |
|
2598
|
|
|
$icon_path = UserManager::get_favicon_from_url($data); |
|
2599
|
|
|
if (self::verifyUrl($icon_path) == false) { |
|
|
|
|
|
|
2600
|
|
|
break; |
|
2601
|
|
|
} |
|
2602
|
|
|
$bottom = '0.2'; |
|
2603
|
|
|
//quick hack for hi5 |
|
2604
|
|
|
$domain = parse_url($icon_path, PHP_URL_HOST); |
|
2605
|
|
|
if ($domain == 'www.hi5.com' || $domain == 'hi5.com') { |
|
2606
|
|
|
$bottom = '-0.8'; |
|
2607
|
|
|
} |
|
2608
|
|
|
$data = '<a href="'.$data.'">' |
|
2609
|
|
|
.'<img src="'.$icon_path.'" alt="icon"' |
|
2610
|
|
|
.' style="margin-right:0.5em;margin-bottom:'.$bottom.'em;" />' |
|
2611
|
|
|
.$extraFieldInfo['display_text'] |
|
2612
|
|
|
.'</a>'; |
|
2613
|
|
|
$extra_information_value .= '<li class="list-group-item">'.$data.'</li>'; |
|
2614
|
|
|
$extraFieldItem = [ |
|
2615
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2616
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2617
|
|
|
'value' => $data, |
|
2618
|
|
|
]; |
|
2619
|
|
|
break; |
|
2620
|
|
|
case ExtraField::FIELD_TYPE_SELECT_WITH_TEXT_FIELD: |
|
2621
|
|
|
$parsedData = explode('::', $data); |
|
2622
|
|
|
|
|
2623
|
|
|
if (!$parsedData) { |
|
|
|
|
|
|
2624
|
|
|
break; |
|
2625
|
|
|
} |
|
2626
|
|
|
|
|
2627
|
|
|
$objEfOption = new ExtraFieldOption('user'); |
|
2628
|
|
|
$optionInfo = $objEfOption->get($parsedData[0]); |
|
2629
|
|
|
|
|
2630
|
|
|
$extra_information_value .= '<li class="list-group-item">' |
|
2631
|
|
|
.$optionInfo['display_text'].': ' |
|
2632
|
|
|
.$parsedData[1].'</li>'; |
|
2633
|
|
|
$extraFieldItem = [ |
|
2634
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2635
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2636
|
|
|
'value' => $parsedData[1], |
|
2637
|
|
|
]; |
|
2638
|
|
|
break; |
|
2639
|
|
|
case ExtraField::FIELD_TYPE_TRIPLE_SELECT: |
|
2640
|
|
|
$optionIds = explode(';', $data); |
|
2641
|
|
|
$optionValues = []; |
|
2642
|
|
|
|
|
2643
|
|
|
foreach ($optionIds as $optionId) { |
|
2644
|
|
|
$objEfOption = new ExtraFieldOption('user'); |
|
2645
|
|
|
$optionInfo = $objEfOption->get($optionId); |
|
2646
|
|
|
|
|
2647
|
|
|
$optionValues[] = $optionInfo['display_text']; |
|
2648
|
|
|
} |
|
2649
|
|
|
$extra_information_value .= '<li class="list-group-item">' |
|
2650
|
|
|
.ucfirst($extraFieldInfo['display_text']).': ' |
|
2651
|
|
|
.implode(' ', $optionValues).'</li>'; |
|
2652
|
|
|
$extraFieldItem = [ |
|
2653
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2654
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2655
|
|
|
'value' => implode(' ', $optionValues), |
|
2656
|
|
|
]; |
|
2657
|
|
|
break; |
|
2658
|
|
|
default: |
|
2659
|
|
|
// Ofaj |
|
2660
|
|
|
// Converts "Date of birth" into "age" |
|
2661
|
|
|
if ($key === 'terms_datedenaissance') { |
|
2662
|
|
|
$dataArray = date_to_str_ago($data, 'UTC', true); |
|
2663
|
|
|
$dataToString = isset($dataArray['years']) && !empty($dataArray['years']) ? $dataArray['years'] : 0; |
|
2664
|
|
|
if (!empty($dataToString)) { |
|
2665
|
|
|
$data = $dataToString; |
|
2666
|
|
|
$extraFieldInfo['display_text'] = get_lang('Age'); |
|
2667
|
|
|
} |
|
2668
|
|
|
} |
|
2669
|
|
|
|
|
2670
|
|
|
$extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']).': '.$data.'</li>'; |
|
2671
|
|
|
$extraFieldItem = [ |
|
2672
|
|
|
'variable' => $extraFieldInfo['variable'], |
|
2673
|
|
|
'label' => ucfirst($extraFieldInfo['display_text']), |
|
2674
|
|
|
'value' => $data, |
|
2675
|
|
|
]; |
|
2676
|
|
|
break; |
|
2677
|
|
|
} |
|
2678
|
|
|
} |
|
2679
|
|
|
|
|
2680
|
|
|
$listType[] = $extraFieldItem; |
|
2681
|
|
|
} |
|
2682
|
|
|
|
|
2683
|
|
|
if ($isArray) { |
|
2684
|
|
|
return $listType; |
|
2685
|
|
|
} else { |
|
2686
|
|
|
// if there are information to show |
|
2687
|
|
|
if (!empty($extra_information_value)) { |
|
2688
|
|
|
$extra_information_value = '<ul class="list-group">'.$extra_information_value.'</ul>'; |
|
2689
|
|
|
$extra_information .= Display::panelCollapse( |
|
2690
|
|
|
get_lang('Extra information'), |
|
2691
|
|
|
$extra_information_value, |
|
2692
|
|
|
'sn-extra-information', |
|
2693
|
|
|
null, |
|
2694
|
|
|
'sn-extra-accordion', |
|
2695
|
|
|
'sn-extra-collapse' |
|
2696
|
|
|
); |
|
2697
|
|
|
} |
|
2698
|
|
|
} |
|
2699
|
|
|
} |
|
2700
|
|
|
|
|
2701
|
|
|
return $extra_information; |
|
2702
|
|
|
} |
|
2703
|
|
|
|
|
2704
|
|
|
/** |
|
2705
|
|
|
* @param string $url |
|
2706
|
|
|
*/ |
|
2707
|
|
|
public static function handlePosts($url) |
|
2708
|
|
|
{ |
|
2709
|
|
|
$friendId = isset($_GET['u']) ? (int) $_GET['u'] : api_get_user_id(); |
|
2710
|
|
|
$url = Security::remove_XSS($url); |
|
2711
|
|
|
|
|
2712
|
|
|
// Main post |
|
2713
|
|
|
if (!empty($_POST['social_wall_new_msg_main']) || !empty($_FILES['picture']['tmp_name'])) { |
|
2714
|
|
|
$messageContent = $_POST['social_wall_new_msg_main']; |
|
2715
|
|
|
if (!empty($_POST['url_content'])) { |
|
2716
|
|
|
$messageContent = $_POST['social_wall_new_msg_main'].'<br /><br />'.$_POST['url_content']; |
|
2717
|
|
|
} |
|
2718
|
|
|
|
|
2719
|
|
|
$messageId = self::sendWallMessage( |
|
2720
|
|
|
api_get_user_id(), |
|
2721
|
|
|
$friendId, |
|
2722
|
|
|
$messageContent, |
|
2723
|
|
|
0, |
|
2724
|
|
|
MESSAGE_STATUS_WALL_POST |
|
2725
|
|
|
); |
|
2726
|
|
|
|
|
2727
|
|
|
if ($messageId && !empty($_FILES['picture']['tmp_name'])) { |
|
2728
|
|
|
self::sendWallMessageAttachmentFile( |
|
2729
|
|
|
api_get_user_id(), |
|
2730
|
|
|
$_FILES['picture'], |
|
2731
|
|
|
$messageId |
|
2732
|
|
|
); |
|
2733
|
|
|
} |
|
2734
|
|
|
|
|
2735
|
|
|
Display::addFlash(Display::return_message(get_lang('Message Sent'))); |
|
2736
|
|
|
header('Location: '.$url); |
|
2737
|
|
|
exit; |
|
2738
|
|
|
} |
|
2739
|
|
|
} |
|
2740
|
|
|
|
|
2741
|
|
|
/** |
|
2742
|
|
|
* @param int $countPost |
|
2743
|
|
|
* @param array $htmlHeadXtra |
|
2744
|
|
|
*/ |
|
2745
|
|
|
public static function getScrollJs($countPost, &$htmlHeadXtra) |
|
2746
|
|
|
{ |
|
2747
|
|
|
// $ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php'; |
|
2748
|
|
|
$socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
|
2749
|
|
|
$javascriptDir = api_get_path(LIBRARY_PATH).'javascript/'; |
|
2750
|
|
|
$locale = api_get_language_isocode(); |
|
2751
|
|
|
|
|
2752
|
|
|
// Add Jquery scroll pagination plugin |
|
2753
|
|
|
//$htmlHeadXtra[] = api_get_js('jscroll/jquery.jscroll.js'); |
|
2754
|
|
|
// Add Jquery Time ago plugin |
|
2755
|
|
|
//$htmlHeadXtra[] = api_get_asset('jquery-timeago/jquery.timeago.js'); |
|
2756
|
|
|
$timeAgoLocaleDir = $javascriptDir.'jquery-timeago/locales/jquery.timeago.'.$locale.'.js'; |
|
2757
|
|
|
if (file_exists($timeAgoLocaleDir)) { |
|
2758
|
|
|
$htmlHeadXtra[] = api_get_js('jquery-timeago/locales/jquery.timeago.'.$locale.'.js'); |
|
2759
|
|
|
} |
|
2760
|
|
|
|
|
2761
|
|
|
if ($countPost > self::DEFAULT_WALL_POSTS) { |
|
2762
|
|
|
$htmlHeadXtra[] = '<script> |
|
2763
|
|
|
$(function() { |
|
2764
|
|
|
var container = $("#wallMessages"); |
|
2765
|
|
|
container.jscroll({ |
|
2766
|
|
|
loadingHtml: "<div class=\"well_border\">'.get_lang('Loading').' </div>", |
|
2767
|
|
|
nextSelector: "a.nextPage:last", |
|
2768
|
|
|
contentSelector: "", |
|
2769
|
|
|
callback: timeAgo |
|
2770
|
|
|
}); |
|
2771
|
|
|
}); |
|
2772
|
|
|
</script>'; |
|
2773
|
|
|
} |
|
2774
|
|
|
|
|
2775
|
|
|
$htmlHeadXtra[] = '<script> |
|
2776
|
|
|
function deleteMessage(id) |
|
2777
|
|
|
{ |
|
2778
|
|
|
$.ajax({ |
|
2779
|
|
|
url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
|
2780
|
|
|
success: function (result) { |
|
2781
|
|
|
if (result) { |
|
2782
|
|
|
$("#message_" + id).parent().parent().parent().parent().html(result); |
|
2783
|
|
|
} |
|
2784
|
|
|
} |
|
2785
|
|
|
}); |
|
2786
|
|
|
} |
|
2787
|
|
|
|
|
2788
|
|
|
function deleteComment(id) |
|
2789
|
|
|
{ |
|
2790
|
|
|
$.ajax({ |
|
2791
|
|
|
url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
|
2792
|
|
|
success: function (result) { |
|
2793
|
|
|
if (result) { |
|
2794
|
|
|
$("#message_" + id).parent().parent().parent().html(result); |
|
2795
|
|
|
} |
|
2796
|
|
|
} |
|
2797
|
|
|
}); |
|
2798
|
|
|
} |
|
2799
|
|
|
|
|
2800
|
|
|
function submitComment(messageId) |
|
2801
|
|
|
{ |
|
2802
|
|
|
var data = $("#form_comment_"+messageId).serializeArray(); |
|
2803
|
|
|
$.ajax({ |
|
2804
|
|
|
type : "POST", |
|
2805
|
|
|
url: "'.$socialAjaxUrl.'?a=send_comment" + "&id=" + messageId, |
|
2806
|
|
|
data: data, |
|
2807
|
|
|
success: function (result) { |
|
2808
|
|
|
if (result) { |
|
2809
|
|
|
$("#post_" + messageId + " textarea").val(""); |
|
2810
|
|
|
$("#post_" + messageId + " .sub-mediapost").prepend(result); |
|
2811
|
|
|
$("#post_" + messageId + " .sub-mediapost").append( |
|
2812
|
|
|
$(\'<div id=result_\' + messageId +\'>'.addslashes(get_lang('Saved.')).'</div>\') |
|
2813
|
|
|
); |
|
2814
|
|
|
|
|
2815
|
|
|
$("#result_" + messageId + "").fadeIn("fast", function() { |
|
2816
|
|
|
$("#result_" + messageId + "").delay(1000).fadeOut("fast", function() { |
|
2817
|
|
|
$(this).remove(); |
|
2818
|
|
|
}); |
|
2819
|
|
|
}); |
|
2820
|
|
|
} |
|
2821
|
|
|
} |
|
2822
|
|
|
}); |
|
2823
|
|
|
} |
|
2824
|
|
|
|
|
2825
|
|
|
$(function() { |
|
2826
|
|
|
timeAgo(); |
|
2827
|
|
|
|
|
2828
|
|
|
/*$(".delete_message").on("click", function() { |
|
2829
|
|
|
var id = $(this).attr("id"); |
|
2830
|
|
|
id = id.split("_")[1]; |
|
2831
|
|
|
$.ajax({ |
|
2832
|
|
|
url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
|
2833
|
|
|
success: function (result) { |
|
2834
|
|
|
if (result) { |
|
2835
|
|
|
$("#message_" + id).parent().parent().parent().parent().html(result); |
|
2836
|
|
|
} |
|
2837
|
|
|
} |
|
2838
|
|
|
}); |
|
2839
|
|
|
}); |
|
2840
|
|
|
|
|
2841
|
|
|
|
|
2842
|
|
|
$(".delete_comment").on("click", function() { |
|
2843
|
|
|
var id = $(this).attr("id"); |
|
2844
|
|
|
id = id.split("_")[1]; |
|
2845
|
|
|
$.ajax({ |
|
2846
|
|
|
url: "'.$socialAjaxUrl.'?a=delete_message" + "&id=" + id, |
|
2847
|
|
|
success: function (result) { |
|
2848
|
|
|
if (result) { |
|
2849
|
|
|
$("#message_" + id).parent().parent().parent().html(result); |
|
2850
|
|
|
} |
|
2851
|
|
|
} |
|
2852
|
|
|
}); |
|
2853
|
|
|
}); |
|
2854
|
|
|
*/ |
|
2855
|
|
|
}); |
|
2856
|
|
|
|
|
2857
|
|
|
function timeAgo() { |
|
2858
|
|
|
$(".timeago").timeago(); |
|
2859
|
|
|
} |
|
2860
|
|
|
</script>'; |
|
2861
|
|
|
} |
|
2862
|
|
|
|
|
2863
|
|
|
/** |
|
2864
|
|
|
* @param int $userId |
|
2865
|
|
|
* @param int $countPost |
|
2866
|
|
|
* |
|
2867
|
|
|
* @return string |
|
2868
|
|
|
*/ |
|
2869
|
|
|
public static function getAutoExtendLink($userId, $countPost) |
|
2870
|
|
|
{ |
|
2871
|
|
|
$userId = (int) $userId; |
|
2872
|
|
|
$socialAjaxUrl = api_get_path(WEB_AJAX_PATH).'social.ajax.php'; |
|
2873
|
|
|
$socialAutoExtendLink = ''; |
|
2874
|
|
|
if ($countPost > self::DEFAULT_WALL_POSTS) { |
|
2875
|
|
|
$socialAutoExtendLink = Display::url( |
|
2876
|
|
|
get_lang('See more'), |
|
2877
|
|
|
$socialAjaxUrl.'?u='.$userId.'&a=list_wall_message&start='. |
|
2878
|
|
|
self::DEFAULT_WALL_POSTS.'&length='.self::DEFAULT_SCROLL_NEW_POST, |
|
2879
|
|
|
[ |
|
2880
|
|
|
'class' => 'nextPage next', |
|
2881
|
|
|
] |
|
2882
|
|
|
); |
|
2883
|
|
|
} |
|
2884
|
|
|
|
|
2885
|
|
|
return $socialAutoExtendLink; |
|
2886
|
|
|
} |
|
2887
|
|
|
|
|
2888
|
|
|
/** |
|
2889
|
|
|
* @param int $userId |
|
2890
|
|
|
* |
|
2891
|
|
|
* @return array |
|
2892
|
|
|
*/ |
|
2893
|
|
|
public static function getThreadList($userId) |
|
2894
|
|
|
{ |
|
2895
|
|
|
$forumCourseId = api_get_configuration_value('global_forums_course_id'); |
|
2896
|
|
|
|
|
2897
|
|
|
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
|
2898
|
|
|
|
|
2899
|
|
|
$threads = []; |
|
2900
|
|
|
if (!empty($forumCourseId)) { |
|
2901
|
|
|
$courseInfo = api_get_course_info_by_id($forumCourseId); |
|
|
|
|
|
|
2902
|
|
|
getNotificationsPerUser($userId, true, $forumCourseId); |
|
2903
|
|
|
$notification = Session::read('forum_notification'); |
|
2904
|
|
|
Session::erase('forum_notification'); |
|
2905
|
|
|
|
|
2906
|
|
|
$threadUrlBase = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
|
2907
|
|
|
'cidReq' => $courseInfo['code'], |
|
2908
|
|
|
]).'&'; |
|
2909
|
|
|
if (isset($notification['thread']) && !empty($notification['thread'])) { |
|
2910
|
|
|
$threadList = array_filter(array_unique($notification['thread'])); |
|
2911
|
|
|
$em = Database::getManager(); |
|
2912
|
|
|
$repo = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
|
2913
|
|
|
foreach ($threadList as $threadId) { |
|
2914
|
|
|
/** @var \Chamilo\CourseBundle\Entity\CForumThread $thread */ |
|
2915
|
|
|
$thread = $repo->find($threadId); |
|
2916
|
|
|
if ($thread) { |
|
2917
|
|
|
$threadUrl = $threadUrlBase.http_build_query([ |
|
2918
|
|
|
'forum' => $thread->getForumId(), |
|
|
|
|
|
|
2919
|
|
|
'thread' => $thread->getIid(), |
|
2920
|
|
|
]); |
|
2921
|
|
|
$threads[] = [ |
|
2922
|
|
|
'id' => $threadId, |
|
2923
|
|
|
'url' => Display::url( |
|
2924
|
|
|
$thread->getThreadTitle(), |
|
2925
|
|
|
$threadUrl |
|
2926
|
|
|
), |
|
2927
|
|
|
'name' => Display::url( |
|
2928
|
|
|
$thread->getThreadTitle(), |
|
2929
|
|
|
$threadUrl |
|
2930
|
|
|
), |
|
2931
|
|
|
'description' => '', |
|
2932
|
|
|
]; |
|
2933
|
|
|
} |
|
2934
|
|
|
} |
|
2935
|
|
|
} |
|
2936
|
|
|
} |
|
2937
|
|
|
|
|
2938
|
|
|
return $threads; |
|
2939
|
|
|
} |
|
2940
|
|
|
|
|
2941
|
|
|
/** |
|
2942
|
|
|
* @param int $userId |
|
2943
|
|
|
* |
|
2944
|
|
|
* @return string |
|
2945
|
|
|
*/ |
|
2946
|
|
|
public static function getGroupBlock($userId) |
|
2947
|
|
|
{ |
|
2948
|
|
|
$threadList = self::getThreadList($userId); |
|
2949
|
|
|
$userGroup = new UserGroup(); |
|
2950
|
|
|
|
|
2951
|
|
|
$forumCourseId = api_get_configuration_value('global_forums_course_id'); |
|
2952
|
|
|
$courseInfo = null; |
|
2953
|
|
|
if (!empty($forumCourseId)) { |
|
2954
|
|
|
$courseInfo = api_get_course_info_by_id($forumCourseId); |
|
|
|
|
|
|
2955
|
|
|
} |
|
2956
|
|
|
|
|
2957
|
|
|
$social_group_block = ''; |
|
2958
|
|
|
if (!empty($courseInfo)) { |
|
2959
|
|
|
if (!empty($threadList)) { |
|
2960
|
|
|
$social_group_block .= '<div class="list-group">'; |
|
2961
|
|
|
foreach ($threadList as $group) { |
|
2962
|
|
|
$social_group_block .= ' <li class="list-group-item">'; |
|
2963
|
|
|
$social_group_block .= $group['name']; |
|
2964
|
|
|
$social_group_block .= '</li>'; |
|
2965
|
|
|
} |
|
2966
|
|
|
$social_group_block .= '</div>'; |
|
2967
|
|
|
} |
|
2968
|
|
|
|
|
2969
|
|
|
$social_group_block .= Display::url( |
|
2970
|
|
|
get_lang('See all communities'), |
|
2971
|
|
|
api_get_path(WEB_CODE_PATH).'forum/index.php?cidReq='.$courseInfo['code'] |
|
2972
|
|
|
); |
|
2973
|
|
|
|
|
2974
|
|
|
if (!empty($social_group_block)) { |
|
2975
|
|
|
$social_group_block = Display::panelCollapse( |
|
2976
|
|
|
get_lang('My communities'), |
|
2977
|
|
|
$social_group_block, |
|
2978
|
|
|
'sm-groups', |
|
2979
|
|
|
null, |
|
2980
|
|
|
'grups-acordion', |
|
2981
|
|
|
'groups-collapse' |
|
2982
|
|
|
); |
|
2983
|
|
|
} |
|
2984
|
|
|
} else { |
|
2985
|
|
|
// Load my groups |
|
2986
|
|
|
$results = $userGroup->get_groups_by_user( |
|
2987
|
|
|
$userId, |
|
2988
|
|
|
[ |
|
2989
|
|
|
GROUP_USER_PERMISSION_ADMIN, |
|
2990
|
|
|
GROUP_USER_PERMISSION_READER, |
|
2991
|
|
|
GROUP_USER_PERMISSION_MODERATOR, |
|
2992
|
|
|
GROUP_USER_PERMISSION_HRM, |
|
2993
|
|
|
] |
|
2994
|
|
|
); |
|
2995
|
|
|
|
|
2996
|
|
|
$myGroups = []; |
|
2997
|
|
|
if (!empty($results)) { |
|
2998
|
|
|
foreach ($results as $result) { |
|
2999
|
|
|
$id = $result['id']; |
|
3000
|
|
|
$result['description'] = Security::remove_XSS($result['description'], STUDENT, true); |
|
3001
|
|
|
$result['name'] = Security::remove_XSS($result['name'], STUDENT, true); |
|
3002
|
|
|
|
|
3003
|
|
|
$group_url = "group_view.php?id=$id"; |
|
3004
|
|
|
|
|
3005
|
|
|
$link = Display::url( |
|
3006
|
|
|
api_ucwords(cut($result['name'], 40, true)), |
|
3007
|
|
|
$group_url |
|
3008
|
|
|
); |
|
3009
|
|
|
|
|
3010
|
|
|
$result['name'] = $link; |
|
3011
|
|
|
|
|
3012
|
|
|
$picture = $userGroup->get_picture_group( |
|
3013
|
|
|
$id, |
|
3014
|
|
|
$result['picture'], |
|
3015
|
|
|
null, |
|
3016
|
|
|
GROUP_IMAGE_SIZE_BIG |
|
3017
|
|
|
); |
|
3018
|
|
|
|
|
3019
|
|
|
$result['picture'] = '<img class="img-responsive" src="'.$picture['file'].'" />'; |
|
3020
|
|
|
$group_actions = '<div class="group-more"><a class="btn btn-default" href="groups.php?#tab_browse-2">'. |
|
3021
|
|
|
get_lang('See more').'</a></div>'; |
|
3022
|
|
|
$group_info = '<div class="description"><p>'.cut($result['description'], 120, true)."</p></div>"; |
|
3023
|
|
|
$myGroups[] = [ |
|
3024
|
|
|
'url' => Display::url( |
|
3025
|
|
|
$result['picture'], |
|
3026
|
|
|
$group_url |
|
3027
|
|
|
), |
|
3028
|
|
|
'name' => $result['name'], |
|
3029
|
|
|
'description' => $group_info.$group_actions, |
|
3030
|
|
|
]; |
|
3031
|
|
|
} |
|
3032
|
|
|
|
|
3033
|
|
|
$social_group_block .= '<div class="list-group">'; |
|
3034
|
|
|
foreach ($myGroups as $group) { |
|
3035
|
|
|
$social_group_block .= ' <li class="list-group-item">'; |
|
3036
|
|
|
$social_group_block .= $group['name']; |
|
3037
|
|
|
$social_group_block .= '</li>'; |
|
3038
|
|
|
} |
|
3039
|
|
|
$social_group_block .= '</div>'; |
|
3040
|
|
|
|
|
3041
|
|
|
$form = new FormValidator( |
|
3042
|
|
|
'find_groups_form', |
|
3043
|
|
|
'get', |
|
3044
|
|
|
api_get_path(WEB_CODE_PATH).'social/search.php?search_type=2', |
|
3045
|
|
|
null, |
|
3046
|
|
|
null, |
|
3047
|
|
|
FormValidator::LAYOUT_BOX_NO_LABEL |
|
3048
|
|
|
); |
|
3049
|
|
|
$form->addHidden('search_type', 2); |
|
3050
|
|
|
|
|
3051
|
|
|
$form->addText( |
|
3052
|
|
|
'q', |
|
3053
|
|
|
get_lang('Search'), |
|
3054
|
|
|
false, |
|
3055
|
|
|
[ |
|
3056
|
|
|
'aria-label' => get_lang('Search'), |
|
3057
|
|
|
'custom' => true, |
|
3058
|
|
|
'placeholder' => get_lang('Search'), |
|
3059
|
|
|
] |
|
3060
|
|
|
); |
|
3061
|
|
|
|
|
3062
|
|
|
$social_group_block .= $form->returnForm(); |
|
3063
|
|
|
|
|
3064
|
|
|
if (!empty($social_group_block)) { |
|
3065
|
|
|
$social_group_block = Display::panelCollapse( |
|
3066
|
|
|
get_lang('My groups'), |
|
3067
|
|
|
$social_group_block, |
|
3068
|
|
|
'sm-groups', |
|
3069
|
|
|
null, |
|
3070
|
|
|
'grups-acordion', |
|
3071
|
|
|
'groups-collapse' |
|
3072
|
|
|
); |
|
3073
|
|
|
} |
|
3074
|
|
|
} |
|
3075
|
|
|
} |
|
3076
|
|
|
|
|
3077
|
|
|
return $social_group_block; |
|
3078
|
|
|
} |
|
3079
|
|
|
|
|
3080
|
|
|
/** |
|
3081
|
|
|
* Returns the formatted header message post. |
|
3082
|
|
|
* |
|
3083
|
|
|
* @param int $authorInfo |
|
3084
|
|
|
* @param int $receiverInfo |
|
3085
|
|
|
* @param array $message Message data |
|
3086
|
|
|
* |
|
3087
|
|
|
* @return string $html The formatted header message post |
|
3088
|
|
|
*/ |
|
3089
|
|
|
private static function headerMessagePost($authorInfo, $receiverInfo, $message) |
|
3090
|
|
|
{ |
|
3091
|
|
|
$currentUserId = api_get_user_id(); |
|
3092
|
|
|
$authorId = (int) $authorInfo['user_id']; |
|
3093
|
|
|
$receiverId = (int) $receiverInfo['user_id']; |
|
3094
|
|
|
$iconStatus = $authorInfo['icon_status']; |
|
3095
|
|
|
|
|
3096
|
|
|
$date = Display::dateToStringAgoAndLongDate($message['send_date']); |
|
3097
|
|
|
$avatarAuthor = $authorInfo['avatar']; |
|
3098
|
|
|
$urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId; |
|
3099
|
|
|
$nameCompleteAuthor = $authorInfo['complete_name']; |
|
3100
|
|
|
|
|
3101
|
|
|
$urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId; |
|
3102
|
|
|
$nameCompleteReceiver = $receiverInfo['complete_name']; |
|
3103
|
|
|
|
|
3104
|
|
|
$htmlReceiver = ''; |
|
3105
|
|
|
if ($authorId !== $receiverId) { |
|
3106
|
|
|
$htmlReceiver = ' > <a href="'.$urlReceiver.'">'.$nameCompleteReceiver.'</a> '; |
|
3107
|
|
|
} |
|
3108
|
|
|
|
|
3109
|
|
|
if (!empty($message['group_info'])) { |
|
3110
|
|
|
$htmlReceiver = ' > <a href="'.$message['group_info']['url'].'">'.$message['group_info']['name'].'</a> '; |
|
3111
|
|
|
} |
|
3112
|
|
|
$canEdit = ($currentUserId == $authorInfo['user_id'] || $currentUserId == $receiverInfo['user_id']) && empty($message['group_info']); |
|
|
|
|
|
|
3113
|
|
|
|
|
3114
|
|
|
if (!empty($message['thread_id'])) { |
|
3115
|
|
|
$htmlReceiver = ' > <a href="'.$message['thread_url'].'">'.$message['forum_title'].'</a> '; |
|
3116
|
|
|
$canEdit = false; |
|
3117
|
|
|
} |
|
3118
|
|
|
|
|
3119
|
|
|
$postAttachment = self::getPostAttachment($message); |
|
3120
|
|
|
|
|
3121
|
|
|
$html = '<div class="top-mediapost" >'; |
|
3122
|
|
|
$html .= '<div class="pull-right btn-group btn-group-sm">'; |
|
3123
|
|
|
|
|
3124
|
|
|
$html .= MessageManager::getLikesButton( |
|
3125
|
|
|
$message['id'], |
|
3126
|
|
|
$currentUserId, |
|
3127
|
|
|
!empty($message['group_info']['id']) ? (int) $message['group_info']['id'] : 0 |
|
3128
|
|
|
); |
|
3129
|
|
|
|
|
3130
|
|
|
if ($canEdit) { |
|
3131
|
|
|
$htmlDelete = Display::url( |
|
3132
|
|
|
Display::returnFontAwesomeIcon('trash', '', true), |
|
3133
|
|
|
'javascript:void(0)', |
|
3134
|
|
|
[ |
|
3135
|
|
|
'id' => 'message_'.$message['id'], |
|
3136
|
|
|
'title' => get_lang('Delete comment'), |
|
3137
|
|
|
'onclick' => 'deleteMessage('.$message['id'].')', |
|
3138
|
|
|
'class' => 'btn btn-default', |
|
3139
|
|
|
] |
|
3140
|
|
|
); |
|
3141
|
|
|
|
|
3142
|
|
|
$html .= $htmlDelete; |
|
3143
|
|
|
} |
|
3144
|
|
|
$html .= '</div>'; |
|
3145
|
|
|
|
|
3146
|
|
|
$html .= '<div class="user-image" >'; |
|
3147
|
|
|
$html .= '<a href="'.$urlAuthor.'"> |
|
3148
|
|
|
<img class="avatar-thumb" src="'.$avatarAuthor.'" alt="'.$nameCompleteAuthor.'"></a>'; |
|
3149
|
|
|
$html .= '</div>'; |
|
3150
|
|
|
$html .= '<div class="user-data">'; |
|
3151
|
|
|
$html .= $iconStatus; |
|
3152
|
|
|
$html .= '<div class="username"><a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</div>'; |
|
3153
|
|
|
$html .= '<div class="post-date">'.$date.'</div>'; |
|
3154
|
|
|
$html .= '</div>'; |
|
3155
|
|
|
$html .= '<div class="msg-content">'; |
|
3156
|
|
|
if (!empty($postAttachment)) { |
|
3157
|
|
|
$html .= '<div class="post-attachment thumbnail">'; |
|
3158
|
|
|
$html .= $postAttachment; |
|
3159
|
|
|
$html .= '</div>'; |
|
3160
|
|
|
} |
|
3161
|
|
|
$html .= '<div>'.Security::remove_XSS($message['content']).'</div>'; |
|
3162
|
|
|
$html .= '</div>'; |
|
3163
|
|
|
$html .= '</div>'; // end mediaPost |
|
3164
|
|
|
|
|
3165
|
|
|
// Popularity post functionality |
|
3166
|
|
|
$html .= '<div class="popularity-mediapost"></div>'; |
|
3167
|
|
|
|
|
3168
|
|
|
return $html; |
|
3169
|
|
|
} |
|
3170
|
|
|
} |
|
3171
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.