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