social.lib.php 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // PLUGIN PLACES
  4. define('SOCIAL_LEFT_PLUGIN', 1);
  5. define('SOCIAL_CENTER_PLUGIN', 2);
  6. define('SOCIAL_RIGHT_PLUGIN', 3);
  7. define('CUT_GROUP_NAME', 50);
  8. //This require is necessary because we use constants that need to be loaded before the SocialManager class
  9. require_once api_get_path(LIBRARY_PATH).'message.lib.php';
  10. /**
  11. * Class SocialManager
  12. *
  13. * This class provides methods for the social network management.
  14. * Include/require it in your code to use its features.
  15. *
  16. * @package chamilo.social
  17. */
  18. class SocialManager extends UserManager
  19. {
  20. public function __construct()
  21. {
  22. }
  23. /**
  24. * Allow to see contacts list
  25. * @author isaac flores paz
  26. * @return array
  27. */
  28. public static function show_list_type_friends()
  29. {
  30. $friend_relation_list = array();
  31. $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
  32. $sql = 'SELECT id,title FROM '.$tbl_my_friend_relation_type.' WHERE id<>6 ORDER BY id ASC';
  33. $result = Database::query($sql);
  34. while ($row = Database::fetch_array($result, 'ASSOC')) {
  35. $friend_relation_list[] = $row;
  36. }
  37. $count_list = count($friend_relation_list);
  38. if ($count_list == 0) {
  39. $friend_relation_list[] = get_lang('Unknown');
  40. } else {
  41. return $friend_relation_list;
  42. }
  43. }
  44. /**
  45. * Get relation type contact by name
  46. * @param string names of the kind of relation
  47. * @return int
  48. * @author isaac flores paz
  49. */
  50. public static function get_relation_type_by_name($relation_type_name)
  51. {
  52. $list_type_friend = self::show_list_type_friends();
  53. foreach ($list_type_friend as $value_type_friend) {
  54. if (strtolower($value_type_friend['title']) == $relation_type_name) {
  55. return $value_type_friend['id'];
  56. }
  57. }
  58. }
  59. /**
  60. * Get the kind of relation between contacts
  61. * @param int user id
  62. * @param int user friend id
  63. * @param string
  64. * @author isaac flores paz
  65. */
  66. public static function get_relation_between_contacts($user_id, $user_friend)
  67. {
  68. $tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
  69. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
  70. $sql = 'SELECT rt.id as id FROM '.$tbl_my_friend_relation_type.' rt
  71. WHERE rt.id = (
  72. SELECT uf.relation_type FROM '.$tbl_my_friend.' uf
  73. WHERE
  74. user_id='.((int) $user_id).' AND
  75. friend_user_id='.((int) $user_friend).' AND
  76. uf.relation_type <> '.USER_RELATION_TYPE_RRHH.'
  77. LIMIT 1
  78. )';
  79. $res = Database::query($sql);
  80. if (Database::num_rows($res) > 0) {
  81. $row = Database::fetch_array($res, 'ASSOC');
  82. return $row['id'];
  83. } else {
  84. return USER_UNKNOW;
  85. }
  86. }
  87. /**
  88. * Gets friends id list
  89. * @param int user id
  90. * @param int group id
  91. * @param string name to search
  92. * @param bool true will load firstname, lastname, and image name
  93. * @return array
  94. * @author Julio Montoya <gugli100@gmail.com> Cleaning code, function renamed, $load_extra_info option added
  95. * @author isaac flores paz
  96. */
  97. public static function get_friends($user_id, $id_group = null, $search_name = null, $load_extra_info = true)
  98. {
  99. $list_ids_friends = array();
  100. $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
  101. $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER);
  102. $sql = 'SELECT friend_user_id FROM '.$tbl_my_friend.'
  103. WHERE relation_type NOT IN ('.USER_RELATION_TYPE_DELETED.', '.USER_RELATION_TYPE_RRHH.') AND friend_user_id<>'.((int) $user_id).' AND user_id='.((int) $user_id);
  104. if (isset($id_group) && $id_group > 0) {
  105. $sql.=' AND relation_type='.$id_group;
  106. }
  107. if (isset($search_name)) {
  108. $search_name = trim($search_name);
  109. $search_name = str_replace(' ', '', $search_name);
  110. $sql.=' AND friend_user_id IN (SELECT user_id FROM '.$tbl_my_user.' WHERE firstName LIKE "%'.Database::escape_string($search_name).'%" OR lastName LIKE "%'.Database::escape_string($search_name).'%" OR '.(api_is_western_name_order() ? 'concat(firstName, lastName)' : 'concat(lastName, firstName)').' like concat("%","'.Database::escape_string($search_name).'","%") ) ';
  111. }
  112. $res = Database::query($sql);
  113. while ($row = Database::fetch_array($res, 'ASSOC')) {
  114. if ($load_extra_info) {
  115. $path = UserManager::get_user_picture_path_by_id($row['friend_user_id'], 'web', false, true);
  116. $my_user_info = api_get_user_info($row['friend_user_id']);
  117. $list_ids_friends[] = array(
  118. 'friend_user_id' => $row['friend_user_id'],
  119. 'firstName' => $my_user_info['firstName'],
  120. 'lastName' => $my_user_info['lastName'],
  121. 'username' => $my_user_info['username'],
  122. 'image' => $path['file']
  123. );
  124. } else {
  125. $list_ids_friends[] = $row;
  126. }
  127. }
  128. return $list_ids_friends;
  129. }
  130. /**
  131. * get list web path of contacts by user id
  132. * @param int user id
  133. * @param int group id
  134. * @param string name to search
  135. * @param array
  136. * @author isaac flores paz
  137. */
  138. public static function get_list_path_web_by_user_id($user_id, $id_group = null, $search_name = null)
  139. {
  140. $combine_friend = array();
  141. $list_ids = self::get_friends($user_id, $id_group, $search_name);
  142. if (is_array($list_ids)) {
  143. foreach ($list_ids as $values_ids) {
  144. $list_path_image_friend[] = UserManager::get_user_picture_path_by_id($values_ids['friend_user_id'], 'web', false, true);
  145. $combine_friend = array(
  146. 'id_friend' => $list_ids,
  147. 'path_friend' => $list_path_image_friend
  148. );
  149. }
  150. }
  151. return $combine_friend;
  152. }
  153. /**
  154. * get web path of user invitate
  155. * @author isaac flores paz
  156. * @author Julio Montoya setting variable array
  157. * @param int user id
  158. * @return array
  159. */
  160. public static function get_list_web_path_user_invitation_by_user_id($user_id)
  161. {
  162. $list_ids = self::get_list_invitation_of_friends_by_user_id((int) $user_id);
  163. $list_path_image_friend = array();
  164. foreach ($list_ids as $values_ids) {
  165. $list_path_image_friend[] = UserManager::get_user_picture_path_by_id(
  166. $values_ids['user_sender_id'],
  167. 'web',
  168. false,
  169. true
  170. );
  171. }
  172. return $list_path_image_friend;
  173. }
  174. /**
  175. * Sends an invitation to contacts
  176. * @param int user id
  177. * @param int user friend id
  178. * @param string title of the message
  179. * @param string content of the message
  180. * @return boolean
  181. * @author isaac flores paz
  182. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  183. */
  184. public static function send_invitation_friend($user_id, $friend_id, $message_title, $message_content)
  185. {
  186. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  187. $user_id = intval($user_id);
  188. $friend_id = intval($friend_id);
  189. //Just in case we replace the and \n and \n\r while saving in the DB
  190. $message_content = str_replace(array("\n", "\n\r"), '<br />', $message_content);
  191. $clean_message_title = Database::escape_string($message_title);
  192. $clean_message_content = Database::escape_string($message_content);
  193. $now = api_get_utc_datetime();
  194. $sql_exist = 'SELECT COUNT(*) AS count FROM '.$tbl_message.'
  195. WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status IN(5,6,7);';
  196. $res_exist = Database::query($sql_exist);
  197. $row_exist = Database::fetch_array($res_exist, 'ASSOC');
  198. if ($row_exist['count'] == 0) {
  199. $sql = ' INSERT INTO '.$tbl_message.'(user_sender_id,user_receiver_id,msg_status,send_date,title,content)
  200. VALUES('.$user_id.','.$friend_id.','.MESSAGE_STATUS_INVITATION_PENDING.',"'.$now.'","'.$clean_message_title.'","'.$clean_message_content.'") ';
  201. Database::query($sql);
  202. $sender_info = api_get_user_info($user_id);
  203. $notification = new Notification();
  204. $notification->save_notification(
  205. Notification::NOTIFICATION_TYPE_INVITATION,
  206. array($friend_id),
  207. $message_title,
  208. $message_content,
  209. $sender_info
  210. );
  211. return true;
  212. } else {
  213. //invitation already exist
  214. $sql_if_exist = 'SELECT COUNT(*) AS count, id FROM '.$tbl_message.'
  215. WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7';
  216. $res_if_exist = Database::query($sql_if_exist);
  217. $row_if_exist = Database::fetch_array($res_if_exist, 'ASSOC');
  218. if ($row_if_exist['count'] == 1) {
  219. $sql = 'UPDATE '.$tbl_message.'SET msg_status=5, content = "'.$clean_message_content.'"
  220. WHERE user_sender_id='.$user_id.' AND user_receiver_id='.$friend_id.' AND msg_status = 7 ';
  221. Database::query($sql);
  222. return true;
  223. } else {
  224. return false;
  225. }
  226. }
  227. }
  228. /**
  229. * Get number messages of the inbox
  230. * @author isaac flores paz
  231. * @param int user receiver id
  232. * @return int
  233. */
  234. public static function get_message_number_invitation_by_user_id($user_receiver_id)
  235. {
  236. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  237. $sql = 'SELECT COUNT(*) as count_message_in_box FROM '.$tbl_message.'
  238. WHERE user_receiver_id='.intval($user_receiver_id).' AND msg_status='.MESSAGE_STATUS_INVITATION_PENDING;
  239. $res = Database::query($sql);
  240. $row = Database::fetch_array($res, 'ASSOC');
  241. return $row['count_message_in_box'];
  242. }
  243. /**
  244. * Get invitation list received by user
  245. * @author isaac flores paz
  246. * @param int user id
  247. * @return array()
  248. */
  249. public static function get_list_invitation_of_friends_by_user_id($user_id)
  250. {
  251. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  252. $sql = 'SELECT user_sender_id,send_date,title,content
  253. FROM '.$tbl_message.'
  254. WHERE user_receiver_id='.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
  255. $res = Database::query($sql);
  256. $list_friend_invitation = array();
  257. while ($row = Database::fetch_array($res, 'ASSOC')) {
  258. $list_friend_invitation[] = $row;
  259. }
  260. return $list_friend_invitation;
  261. }
  262. /**
  263. * Get invitation list sent by user
  264. * @author Julio Montoya <gugli100@gmail.com>
  265. * @param int user id
  266. * @return array()
  267. */
  268. public static function get_list_invitation_sent_by_user_id($user_id)
  269. {
  270. $list_friend_invitation = array();
  271. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  272. $sql = 'SELECT user_receiver_id, send_date,title,content
  273. FROM '.$tbl_message.'
  274. WHERE user_sender_id = '.intval($user_id).' AND msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
  275. $res = Database::query($sql);
  276. while ($row = Database::fetch_array($res, 'ASSOC')) {
  277. $list_friend_invitation[$row['user_receiver_id']] = $row;
  278. }
  279. return $list_friend_invitation;
  280. }
  281. /**
  282. * Accepts invitation
  283. * @param int $user_send_id
  284. * @param int $user_receiver_id
  285. * @author isaac flores paz
  286. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  287. */
  288. public static function invitation_accepted($user_send_id, $user_receiver_id)
  289. {
  290. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  291. $sql = "UPDATE $tbl_message
  292. SET msg_status = ".MESSAGE_STATUS_INVITATION_ACCEPTED."
  293. WHERE
  294. user_sender_id = ".((int) $user_send_id)." AND
  295. user_receiver_id=".((int) $user_receiver_id)." AND
  296. msg_status = ".MESSAGE_STATUS_INVITATION_PENDING;
  297. Database::query($sql);
  298. }
  299. /**
  300. * Denies invitation
  301. * @param int user sender id
  302. * @param int user receiver id
  303. * @author isaac flores paz
  304. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  305. */
  306. public static function invitation_denied($user_send_id, $user_receiver_id)
  307. {
  308. $tbl_message = Database::get_main_table(TABLE_MAIN_MESSAGE);
  309. $sql = 'DELETE FROM '.$tbl_message.'
  310. WHERE
  311. user_sender_id = '.((int) $user_send_id).' AND
  312. user_receiver_id='.((int) $user_receiver_id).' AND
  313. msg_status = '.MESSAGE_STATUS_INVITATION_PENDING;
  314. Database::query($sql);
  315. }
  316. /**
  317. * allow attach to group
  318. * @author isaac flores paz
  319. * @param int user to qualify
  320. * @param int kind of rating
  321. * @return void()
  322. */
  323. public static function qualify_friend($id_friend_qualify, $type_qualify)
  324. {
  325. $tbl_user_friend = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
  326. $user_id = api_get_user_id();
  327. $sql = 'UPDATE '.$tbl_user_friend.' SET relation_type='.((int) $type_qualify).'
  328. WHERE user_id = '.((int) $user_id).' AND friend_user_id='.(int) $id_friend_qualify;
  329. Database::query($sql);
  330. }
  331. /**
  332. * Sends invitations to friends
  333. * @author Isaac Flores Paz <isaac.flores.paz@gmail.com>
  334. * @author Julio Montoya <gugli100@gmail.com> Cleaning code
  335. * @param void
  336. * @return string message invitation
  337. */
  338. public static function send_invitation_friend_user($userfriend_id, $subject_message = '', $content_message = '')
  339. {
  340. global $charset;
  341. $user_info = api_get_user_info($userfriend_id);
  342. $succes = get_lang('MessageSentTo');
  343. $succes.= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']);
  344. if (isset($subject_message) && isset($content_message) && isset($userfriend_id)) {
  345. $send_message = MessageManager::send_message($userfriend_id, $subject_message, $content_message);
  346. if ($send_message) {
  347. echo Display::display_confirmation_message($succes, true);
  348. } else {
  349. echo Display::display_error_message(get_lang('ErrorSendingMessage'), true);
  350. }
  351. return false;
  352. } elseif (isset($userfriend_id) && !isset($subject_message)) {
  353. $count_is_true = false;
  354. if (isset($userfriend_id) && $userfriend_id > 0) {
  355. $message_title = get_lang('Invitation');
  356. $count_is_true = self::send_invitation_friend(api_get_user_id(), $userfriend_id, $message_title, $content_message);
  357. if ($count_is_true) {
  358. echo Display::display_confirmation_message(api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES, $charset), false);
  359. } else {
  360. echo Display::display_warning_message(api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES, $charset), false);
  361. }
  362. }
  363. }
  364. }
  365. /**
  366. * Get user's feeds
  367. * @param int User ID
  368. * @param int Limit of posts per feed
  369. * @return string HTML section with all feeds included
  370. * @author Yannick Warnier
  371. * @since Dokeos 1.8.6.1
  372. */
  373. public static function get_user_feeds($user, $limit = 5)
  374. {
  375. if (!function_exists('fetch_rss')) {
  376. return '';
  377. }
  378. $feed = UserManager::get_extra_user_data_by_field($user, 'rssfeeds');
  379. if (empty($feed)) {
  380. return '';
  381. }
  382. $feeds = explode(';', $feed['rssfeeds']);
  383. if (count($feeds) == 0) {
  384. return '';
  385. }
  386. $res = '';
  387. foreach ($feeds as $url) {
  388. if (empty($url)) {
  389. continue;
  390. }
  391. $rss = @fetch_rss($url);
  392. $i = 1;
  393. if (!empty($rss->items)) {
  394. $icon_rss = '';
  395. if (!empty($feed)) {
  396. $icon_rss = Display::url(Display::return_icon('rss.png', '', array(), 32), Security::remove_XSS($feed['rssfeeds']), array('target' => '_blank'));
  397. }
  398. $res .= '<h2>'.$rss->channel['title'].''.$icon_rss.'</h2>';
  399. $res .= '<div class="social-rss-channel-items">';
  400. foreach ($rss->items as $item) {
  401. if ($limit >= 0 and $i > $limit) {
  402. break;
  403. }
  404. $res .= '<h3><a href="'.$item['link'].'">'.$item['title'].'</a></h3>';
  405. $res .= '<div class="social-rss-item-date">'.api_get_local_time($item['date_timestamp']).'</div>';
  406. $res .= '<div class="social-rss-item-content">'.$item['description'].'</div><br />';
  407. $i++;
  408. }
  409. $res .= '</div>';
  410. }
  411. }
  412. return $res;
  413. }
  414. /**
  415. * Helper functions definition
  416. */
  417. public static function get_logged_user_course_html($my_course, $count)
  418. {
  419. global $nosession, $nbDigestEntries, $orderKey, $digest, $thisCourseSysCode;
  420. if (!$nosession) {
  421. global $now, $date_start, $date_end;
  422. }
  423. //initialise
  424. $result = '';
  425. // Table definitions
  426. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  427. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  428. $course_code = $my_course['code'];
  429. $course_visual_code = $my_course['course_info']['official_code'];
  430. $course_title = $my_course['course_info']['title'];
  431. $course_info = Database :: get_course_info($course_code);
  432. $course_id = $course_info['real_id'];
  433. $course_access_settings = CourseManager :: get_access_settings($course_code);
  434. $course_visibility = $course_access_settings['visibility'];
  435. $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_code);
  436. //function logic - act on the data
  437. $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($course_code);
  438. if ($is_virtual_course) {
  439. // If the current user is also subscribed in the real course to which this
  440. // virtual course is linked, we don't need to display the virtual course entry in
  441. // the course list - it is combined with the real course entry.
  442. $target_course_code = CourseManager :: get_target_of_linked_course($course_code);
  443. $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code);
  444. if ($is_subscribed_in_target_course) {
  445. return; //do not display this course entry
  446. }
  447. }
  448. $s_htlm_status_icon = Display::return_icon('course.gif', get_lang('Course'));
  449. //display course entry
  450. $result .= '<div id="div_'.$count.'">';
  451. //$result .= '<h3><img src="../img/nolines_plus.gif" id="btn_'.$count.'" onclick="toogle_course(this,\''.$course_id.'\' )">';
  452. $result .= $s_htlm_status_icon;
  453. //show a hyperlink to the course, unless the course is closed and user is not course admin
  454. if ($course_visibility != COURSE_VISIBILITY_HIDDEN && ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER)) {
  455. //$result .= '<a href="javascript:void(0)" id="ln_'.$count.'" onclick=toogle_course(this,\''.$course_id.'\');>&nbsp;'.$course_title.'</a>';
  456. $result .= $course_title;
  457. } else {
  458. $result .= $course_title." "." ".get_lang('CourseClosed')."";
  459. }
  460. $result .= '</h3>';
  461. //$current_course_settings = CourseManager :: get_access_settings($my_course['k']);
  462. // display the what's new icons
  463. /*if ($nbDigestEntries > 0) {
  464. reset($digest);
  465. $result .= '<ul>';
  466. while (list ($key2) = each($digest[$thisCourseSysCode])) {
  467. $result .= '<li>';
  468. if ($orderKey[1] == 'keyTools') {
  469. $result .= "<a href=\"$toolsList[$key2] [\"path\"] $thisCourseSysCode \">";
  470. $result .= "$toolsList[$key2][\"name\"]</a>";
  471. } else {
  472. $result .= api_convert_and_format_date($key2, DATE_FORMAT_LONG, date_default_timezone_get());
  473. }
  474. $result .= '</li>';
  475. $result .= '<ul>';
  476. reset($digest[$thisCourseSysCode][$key2]);
  477. while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) {
  478. $result .= '<li>';
  479. if ($orderKey[2] == 'keyTools') {
  480. $result .= "<a href=\"$toolsList[$key3] [\"path\"] $thisCourseSysCode \">";
  481. $result .= "$toolsList[$key3][\"name\"]</a>";
  482. } else {
  483. $result .= api_convert_and_format_date($key3, DATE_FORMAT_LONG, date_default_timezone_get());
  484. }
  485. $result .= '<ul compact="compact">';
  486. reset($digest[$thisCourseSysCode][$key2][$key3]);
  487. while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) {
  488. $result .= '<li>';
  489. $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT));
  490. $result .= '</li>';
  491. }
  492. $result .= '</ul>';
  493. $result .= '</li>';
  494. }
  495. $result .= '</ul>';
  496. $result .= '</li>';
  497. }
  498. $result .= '</ul>';
  499. }*/
  500. $result .= '</li>';
  501. $result .= '</div>';
  502. if (!$nosession) {
  503. $session = '';
  504. $active = false;
  505. if (!empty($my_course['session_name'])) {
  506. // Request for the name of the general coach
  507. $sql = 'SELECT lastname, firstname
  508. FROM '.$tbl_session.' ts LEFT JOIN '.$main_user_table.' tu
  509. ON ts.id_coach = tu.user_id
  510. WHERE ts.id='.(int) $my_course['id_session'].' LIMIT 1';
  511. $rs = Database::query($sql);
  512. $sessioncoach = Database::store_result($rs);
  513. $sessioncoach = $sessioncoach[0];
  514. $session = array();
  515. $session['title'] = $my_course['session_name'];
  516. if ($my_course['date_start'] == '0000-00-00') {
  517. $session['dates'] = get_lang('WithoutTimeLimits');
  518. if (api_get_setting('show_session_coach') === 'true') {
  519. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  520. }
  521. $active = true;
  522. } else {
  523. $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end'];
  524. if (api_get_setting('show_session_coach') === 'true') {
  525. $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
  526. }
  527. $active = ($date_start <= $now && $date_end >= $now) ? true : false;
  528. }
  529. }
  530. $my_course['id_session'] = isset($my_course['id_session']) ? $my_course['id_session'] : 0;
  531. $output = array($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active' => $active);
  532. } else {
  533. $output = array($my_course['user_course_cat'], $result);
  534. }
  535. //$my_course['creation_date'];
  536. return $output;
  537. }
  538. /**
  539. * Shows the avatar block in social pages
  540. *
  541. * @param string highlight link possible values: group_add, home, messages, messages_inbox, messages_compose ,messages_outbox ,invitations, shared_profile, friends, groups search
  542. * @param int group id
  543. * @param int user id
  544. *
  545. */
  546. public static function show_social_avatar_block($show = '', $group_id = 0, $user_id = 0)
  547. {
  548. if (empty($user_id)) {
  549. $user_id = api_get_user_id();
  550. }
  551. $show_groups = array(
  552. 'groups',
  553. 'group_messages',
  554. 'messages_list',
  555. 'group_add',
  556. 'mygroups',
  557. 'group_edit',
  558. 'member_list',
  559. 'invite_friends',
  560. 'waiting_list',
  561. 'browse_groups'
  562. );
  563. // get count unread message and total invitations
  564. $count_unread_message = MessageManager::get_number_of_messages(true);
  565. $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null;
  566. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  567. $group_pending_invitations = GroupPortalManager::get_groups_by_user(api_get_user_id(), GROUP_USER_PERMISSION_PENDING_INVITATION, false);
  568. $group_pending_invitations = count($group_pending_invitations);
  569. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  570. $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : '');
  571. $showUserImage = user_is_online($user_id) || api_is_platform_admin();
  572. $html = '<div>';
  573. if (in_array($show, $show_groups) && !empty($group_id)) {
  574. //--- Group image
  575. $group_info = GroupPortalManager::get_group_data($group_id);
  576. $big = GroupPortalManager::get_picture_group($group_id, $group_info['picture_uri'], 160, GROUP_IMAGE_SIZE_BIG);
  577. $html .= '<div class="social-content-image">';
  578. $html .= '<div class="well social-background-content">';
  579. $html .= Display::url('<img src='.$big['file'].' class="social-groups-image" /> </a><br /><br />', api_get_path(WEB_CODE_PATH).'social/groups.php?id='.$group_id);
  580. if (GroupPortalManager::is_group_admin($group_id, api_get_user_id())) {
  581. $html .= '<div id="edit_image" class="hidden_message" style="display:none">
  582. <a href="'.api_get_path(WEB_CODE_PATH).'social/group_edit.php?id='.$group_id.'">'.
  583. get_lang('EditGroup').'</a></div>';
  584. }
  585. $html .= '</div>';
  586. $html .= '</div>';
  587. } else {
  588. if ($showUserImage) {
  589. $img_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true, true);
  590. } else {
  591. $img_array = UserManager::get_user_picture_path_by_id(null, 'web', true, true);
  592. }
  593. $big_image = UserManager::get_picture_user($user_id, $img_array['file'], '', USER_IMAGE_SIZE_BIG);
  594. $big_image = $big_image['file'].'?'.uniqid();
  595. $normal_image = $img_array['dir'].$img_array['file'].'?'.uniqid();
  596. //--- User image
  597. $html .= '<div class="well social-background-content">';
  598. if ($img_array['file'] != 'unknown.jpg') {
  599. $html .= '<a class="thumbnail thickbox" href="'.$big_image.'"><img src='.$normal_image.' /> </a>';
  600. } else {
  601. $html .= '<img src='.$normal_image.' width="110px" />';
  602. }
  603. if (api_get_user_id() == $user_id) {
  604. $html .= '<div id="edit_image" class="hidden_message" style="display:none">';
  605. $html .= '<a href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php">'.get_lang('EditProfile').'</a></div>';
  606. }
  607. $html .= '</div>';
  608. }
  609. $html .= '</div>';
  610. return $html;
  611. }
  612. /**
  613. * Shows the right menu of the Social Network tool
  614. *
  615. * @param string $show highlight link possible values:
  616. * group_add,
  617. * home,
  618. * messages,
  619. * messages_inbox,
  620. * messages_compose ,
  621. * messages_outbox,
  622. * invitations,
  623. * shared_profile,
  624. * friends,
  625. * groups search
  626. * @param int $group_id group id
  627. * @param int $user_id user id
  628. * @param bool $show_full_profile show profile or not (show or hide the user image/information)
  629. * @param bool $show_delete_account_button
  630. *
  631. */
  632. public static function show_social_menu(
  633. $show = '',
  634. $group_id = 0,
  635. $user_id = 0,
  636. $show_full_profile = false,
  637. $show_delete_account_button = false
  638. ) {
  639. if (empty($user_id)) {
  640. $user_id = api_get_user_id();
  641. }
  642. $user_info = api_get_user_info($user_id, true);
  643. $current_user_id = api_get_user_id();
  644. $current_user_info = api_get_user_info($current_user_id, true);
  645. if ($current_user_id == $user_id) {
  646. $user_friend_relation = null;
  647. } else {
  648. $user_friend_relation = SocialManager::get_relation_between_contacts($current_user_id, $user_id);
  649. }
  650. $show_groups = array(
  651. 'groups',
  652. 'group_messages',
  653. 'messages_list',
  654. 'group_add',
  655. 'mygroups',
  656. 'group_edit',
  657. 'member_list',
  658. 'invite_friends',
  659. 'waiting_list',
  660. 'browse_groups'
  661. );
  662. // get count unread message and total invitations
  663. $count_unread_message = MessageManager::get_number_of_messages(true);
  664. $count_unread_message = !empty($count_unread_message) ? Display::badge($count_unread_message) : null;
  665. $number_of_new_messages_of_friend = SocialManager::get_message_number_invitation_by_user_id(api_get_user_id());
  666. $group_pending_invitations = GroupPortalManager::get_groups_by_user(
  667. api_get_user_id(),
  668. GROUP_USER_PERMISSION_PENDING_INVITATION,
  669. false
  670. );
  671. $group_pending_invitations = count($group_pending_invitations);
  672. $total_invitations = $number_of_new_messages_of_friend + $group_pending_invitations;
  673. $total_invitations = (!empty($total_invitations) ? Display::badge($total_invitations) : '');
  674. $html = '';
  675. $active = null;
  676. if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends'))) {
  677. $html .= '<div class="well sidebar-nav"><ul class="nav nav-list">';
  678. $active = $show == 'home' ? 'active' : null;
  679. $html .= '<li class="home-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">'.get_lang('Home').'</a></li>';
  680. $active = $show == 'messages' ? 'active' : null;
  681. $html .= '<li class="messages-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php?f=social">'.get_lang('Messages').$count_unread_message.'</a></li>';
  682. //Invitations
  683. $active = $show == 'invitations' ? 'active' : null;
  684. $html .= '<li class="invitations-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'.get_lang('Invitations').$total_invitations.'</a></li>';
  685. //Shared profile and groups
  686. $active = $show == 'shared_profile' ? 'active' : null;
  687. $html .= '<li class="shared-profile-icon'.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php">'.get_lang('ViewMySharedProfile').'</a></li>';
  688. $active = $show == 'friends' ? 'active' : null;
  689. $html .= '<li class="friends-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php">'.get_lang('Friends').'</a></li>';
  690. $active = $show == 'browse_groups' ? 'active' : null;
  691. $html .= '<li class="browse-groups-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/groups.php">'.get_lang('SocialGroups').'</a></li>';
  692. //Search users
  693. $active = $show == 'search' ? 'active' : null;
  694. $html .= '<li class="search-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/search.php">'.get_lang('Search').'</a></li>';
  695. //My files
  696. $active = $show == 'myfiles' ? 'active' : null;
  697. $html .= '<li class="myfiles-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php">'.get_lang('MyFiles').'</span></a></li>';
  698. $html .='</ul>
  699. </div>';
  700. }
  701. if (in_array($show, $show_groups) && !empty($group_id)) {
  702. $html .= GroupPortalManager::show_group_column_information(
  703. $group_id,
  704. api_get_user_id(),
  705. $show
  706. );
  707. }
  708. if ($show == 'shared_profile') {
  709. $html .= '<div class="well sidebar-nav">
  710. <ul class="nav nav-list">';
  711. // My own profile
  712. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  713. $html .= '<li class="home-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/home.php">'.get_lang('Home').'</a></li>
  714. <li class="messages-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'messages/inbox.php?f=social">'.get_lang('Messages').$count_unread_message.'</a></li>';
  715. $active = $show == 'invitations' ? 'active' : null;
  716. $html .= '<li class="invitations-icon'.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'.get_lang('Invitations').$total_invitations.'</a></li>';
  717. $html .= '<li class="shared-profile-icon active"><a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php">'.get_lang('ViewMySharedProfile').'</a></li>
  718. <li class="friends-icon"><a href="'.api_get_path(WEB_CODE_PATH).'social/friends.php">'.get_lang('Friends').'</a></li>
  719. <li class="browse-groups-icon"><a href="'.api_get_path(WEB_CODE_PATH).'social/groups.php">'.get_lang('SocialGroups').'</a></li>';
  720. $active = $show == 'search' ? 'active' : null;
  721. $html .= '<li class="search-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/search.php">'.get_lang('Search').'</a></li>';
  722. $active = $show == 'myfiles' ? 'active' : null;
  723. $html .= '<li class="myfiles-icon '.$active.'"><a href="'.api_get_path(WEB_CODE_PATH).'social/myfiles.php">'.get_lang('MyFiles').'</a></li>';
  724. }
  725. // My friend profile.
  726. if ($user_id != api_get_user_id()) {
  727. $html .= '<li><a href="javascript:void(0);" onclick="javascript:send_message_to_user(\''.$user_id.'\');" title="'.get_lang('SendMessage').'">';
  728. $html .= Display::return_icon('compose_message.png', get_lang('SendMessage')).'&nbsp;&nbsp;'.get_lang('SendMessage').'</a></li>';
  729. }
  730. // Check if I already sent an invitation message
  731. $invitation_sent_list = SocialManager::get_list_invitation_sent_by_user_id(api_get_user_id());
  732. if (isset($invitation_sent_list[$user_id]) && is_array($invitation_sent_list[$user_id]) && count($invitation_sent_list[$user_id]) > 0) {
  733. $html .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/invitations.php">'.Display::return_icon('invitation.png', get_lang('YouAlreadySentAnInvitation')).'&nbsp;&nbsp;'.get_lang('YouAlreadySentAnInvitation').'</a></li>';
  734. } else {
  735. if (!$show_full_profile) {
  736. $html .= '<li><a href="javascript:void(0);" onclick="javascript:send_invitation_to_user(\''.$user_id.'\');" title="'.get_lang('SendInvitation').'">'.Display :: return_icon('invitation.png', get_lang('SocialInvitationToFriends')).'&nbsp;'.get_lang('SendInvitation').'</a></li>';
  737. }
  738. }
  739. // Chat
  740. //@todo check if user is online and if it's a friend to show the chat link
  741. if (api_is_global_chat_enabled()) {
  742. $user_name = $user_info['complete_name'];
  743. if ($user_friend_relation == USER_RELATION_TYPE_FRIEND) {
  744. if ($user_id != api_get_user_id()) {
  745. //Only show chat if I'm available to talk
  746. if ($current_user_info['user_is_online_in_chat'] == 1) {
  747. $options = array('onclick' => "javascript:chatWith('".$user_id."', '".Security::remove_XSS($user_name)."', '".$user_info['user_is_online_in_chat']."')");
  748. $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
  749. $html .= Display::tag('li',
  750. Display::url(
  751. $chat_icon.'&nbsp;&nbsp;'.get_lang('Chat'),
  752. 'javascript:void(0);',
  753. $options
  754. )
  755. );
  756. }
  757. }
  758. } else {
  759. if ($user_id != api_get_user_id()) {
  760. if ($current_user_info['user_is_online_in_chat'] == 1) {
  761. $message = Security::remove_XSS(sprintf(get_lang("YouHaveToAddXAsAFriendFirst"), $user_name));
  762. $options = array('onclick' => "javascript:chatNotYetWith('".$message."')");
  763. $chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
  764. $html .= Display::tag('li',
  765. Display::url(
  766. $chat_icon.'&nbsp;&nbsp;'.get_lang('Chat'),
  767. 'javascript:void(0);',
  768. $options
  769. )
  770. );
  771. }
  772. }
  773. }
  774. }
  775. $html .= '</ul></div>';
  776. if ($show_full_profile && $user_id == intval(api_get_user_id())) {
  777. $personal_course_list = UserManager::get_personal_session_course_list($user_id);
  778. $course_list_code = array();
  779. $i = 1;
  780. if (is_array($personal_course_list)) {
  781. foreach ($personal_course_list as $my_course) {
  782. if ($i <= 10) {
  783. $course_list_code[] = array('code' => $my_course['code']);
  784. } else {
  785. break;
  786. }
  787. $i++;
  788. }
  789. //to avoid repeted courses
  790. $course_list_code = array_unique_dimensional($course_list_code);
  791. }
  792. //-----Announcements
  793. $my_announcement_by_user_id = intval($user_id);
  794. $announcements = array();
  795. foreach ($course_list_code as $course) {
  796. $course_info = api_get_course_info($course['code']);
  797. if (!empty($course_info)) {
  798. $content = AnnouncementManager::get_all_annoucement_by_user_course($course_info['code'], $my_announcement_by_user_id);
  799. if (!empty($content)) {
  800. $url = Display::url(Display::return_icon('announcement.png', get_lang('Announcements')).$course_info['name'].' ('.$content['count'].')', api_get_path(WEB_CODE_PATH).'announcements/announcements.php?cidReq='.$course['code']);
  801. $announcements[] = Display::tag('li', $url);
  802. }
  803. }
  804. }
  805. if (!empty($announcements)) {
  806. $html .= '<div class="social_menu_items">';
  807. $html .= '<ul>';
  808. foreach ($announcements as $announcement) {
  809. $html .= $announcement;
  810. }
  811. $html .= '</ul>';
  812. $html .= '</div>';
  813. }
  814. }
  815. }
  816. if ($show_delete_account_button) {
  817. $html .= '<div class="sidebar-nav"><ul><li>';
  818. $url = api_get_path(WEB_CODE_PATH).'auth/unsubscribe_account.php';
  819. $html .= Display::url(Display::return_icon('delete.png', get_lang('Unsubscribe'), array(), ICON_SIZE_TINY).get_lang('Unsubscribe'), $url);
  820. $html .= '</li></ul></div>';
  821. }
  822. $html .= '';
  823. return $html;
  824. }
  825. /**
  826. * Displays a sortable table with the list of online users.
  827. * @param array $user_list The list of users to be shown
  828. * @param bool $wrap Whether we want the function to wrap the spans list in a div or not
  829. * @return string HTML block or null if and ID was defined
  830. * @assert (null) === false
  831. */
  832. public static function display_user_list($user_list, $wrap = true)
  833. {
  834. $html = null;
  835. if (isset($_GET['id']) or count($user_list) < 1) {
  836. return false;
  837. }
  838. $column_size = '9';
  839. $add_row = false;
  840. if (api_is_anonymous()) {
  841. $column_size = '12';
  842. $add_row = true;
  843. }
  844. $extra_params = array();
  845. $course_url = '';
  846. if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
  847. $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  848. $course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
  849. }
  850. if ($wrap) {
  851. if ($add_row) {
  852. $html .='<div class="row">';
  853. }
  854. $html .= '<div class="span'.$column_size.'">';
  855. $html .= '<ul id="online_grid_container" class="thumbnails">';
  856. }
  857. foreach ($user_list as $uid) {
  858. $user_info = api_get_user_info($uid);
  859. // Anonymous users can't have access to the profile
  860. if (!api_is_anonymous()) {
  861. if (api_get_setting('allow_social_tool') == 'true') {
  862. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$uid.$course_url;
  863. } else {
  864. $url = '?id='.$uid.$course_url;
  865. }
  866. } else {
  867. $url = '#';
  868. }
  869. $image_array = UserManager::get_user_picture_path_by_id($uid, 'system', false, true);
  870. // reduce image
  871. $name = $user_info['complete_name'];
  872. $status_icon = Display::span('', array('class' => 'online_user_in_text'));
  873. $user_status = $user_info['status'] == 1 ? Display::span('', array('class' => 'teacher_online')) : Display::span('', array('class' => 'student_online'));
  874. if ($image_array['file'] == 'unknown.jpg' || !file_exists($image_array['dir'].$image_array['file'])) {
  875. $friends_profile['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_180_100.jpg';
  876. $img = '<img title = "'.$name.'" alt="'.$name.'" src="'.$friends_profile['file'].'">';
  877. } else {
  878. $friends_profile = UserManager::get_picture_user($uid, $image_array['file'], 80, USER_IMAGE_SIZE_ORIGINAL);
  879. $img = '<img title = "'.$name.'" alt="'.$name.'" src="'.$friends_profile['file'].'">';
  880. }
  881. $name = '<a href="'.$url.'">'.$status_icon.$user_status.$name.'</a><br>';
  882. $html .= '<li class="span'.($column_size / 3).'"><div class="thumbnail">'.$img.'<div class="caption">'.$name.'</div</div></li>';
  883. }
  884. $counter = $_SESSION['who_is_online_counter'];
  885. if ($wrap) {
  886. $html .= '</ul></div>';
  887. }
  888. if (count($user_list) >= 9) {
  889. $html .= '<div class="span'.$column_size.'"><a class="btn btn-large" id="link_load_more_items" data_link="'.$counter.'" >'.get_lang('More').'</a></div>';
  890. }
  891. if ($wrap && $add_row) {
  892. $html .= '</div>';
  893. }
  894. return $html;
  895. }
  896. /**
  897. * Displays the information of an individual user
  898. * @param int $user_id
  899. */
  900. public static function display_individual_user($user_id)
  901. {
  902. global $interbreadcrumb;
  903. $safe_user_id = intval($user_id);
  904. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  905. $sql = "SELECT * FROM $user_table WHERE user_id = ".$safe_user_id;
  906. $result = Database::query($sql);
  907. $html = null;
  908. if (Database::num_rows($result) == 1) {
  909. $user_object = Database::fetch_object($result);
  910. $alt = GetFullUserName($user_id).($_SESSION['_uid'] == $user_id ? '&nbsp;('.get_lang('Me').')' : '');
  911. $status = get_status_from_code($user_object->status);
  912. $interbreadcrumb[] = array('url' => 'whoisonline.php', 'name' => get_lang('UsersOnLineList'));
  913. $html .= '<div class ="thumbnail">';
  914. if (strlen(trim($user_object->picture_uri)) > 0) {
  915. $sysdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'system');
  916. $sysdir = $sysdir_array['dir'];
  917. $webdir_array = UserManager::get_user_picture_path_by_id($safe_user_id, 'web');
  918. $webdir = $webdir_array['dir'];
  919. $fullurl = $webdir.$user_object->picture_uri;
  920. $system_image_path = $sysdir.$user_object->picture_uri;
  921. list($width, $height, $type, $attr) = @getimagesize($system_image_path);
  922. $height += 30;
  923. $width += 30;
  924. // get the path,width and height from original picture
  925. $big_image = $webdir.'big_'.$user_object->picture_uri;
  926. $big_image_size = api_getimagesize($big_image);
  927. $big_image_width = $big_image_size['width'];
  928. $big_image_height = $big_image_size['height'];
  929. $url_big_image = $big_image.'?rnd='.time();
  930. //echo '<a href="javascript:void()" onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');" >';
  931. $html .= '<img src="'.$fullurl.'" alt="'.$alt.'" />';
  932. } else {
  933. $html .= Display::return_icon('unknown.jpg', get_lang('Unknown'));
  934. }
  935. if (!empty($status)) {
  936. $html .= '<div class="caption">'.$status.'</div>';
  937. }
  938. $html .= '</div>';
  939. if (api_get_setting('show_email_addresses') == 'true') {
  940. $html .= Display::encrypted_mailto_link($user_object->email, $user_object->email).'<br />';
  941. }
  942. if ($user_object->competences) {
  943. $html .= Display::page_subheader(get_lang('MyCompetences'));
  944. $html .= '<p>'.$user_object->competences.'</p>';
  945. }
  946. if ($user_object->diplomas) {
  947. $html .= Display::page_subheader(get_lang('MyDiplomas'));
  948. $html .= '<p>'.$user_object->diplomas.'</p>';
  949. }
  950. if ($user_object->teach) {
  951. $html .= Display::page_subheader(get_lang('MyTeach'));
  952. $html .= '<p>'.$user_object->teach.'</p>';
  953. }
  954. SocialManager::display_productions($user_object->user_id);
  955. if ($user_object->openarea) {
  956. $html .= Display::page_subheader(get_lang('MyPersonalOpenArea'));
  957. $html .= '<p>'.$user_object->openarea.'</p>';
  958. }
  959. } else {
  960. $html .= '<div class="actions-title">';
  961. $html .= get_lang('UsersOnLineList');
  962. $html .= '</div>';
  963. }
  964. return $html;
  965. }
  966. /**
  967. * Display productions in who is online
  968. * @param int $user_id User id
  969. */
  970. public static function display_productions($user_id)
  971. {
  972. $sysdir_array = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
  973. $sysdir = $sysdir_array['dir'];
  974. $webdir_array = UserManager::get_user_picture_path_by_id($user_id, 'web', true);
  975. $webdir = $webdir_array['dir'];
  976. if (!is_dir($sysdir)) {
  977. mkdir($sysdir, api_get_permissions_for_new_directories(), true);
  978. }
  979. $productions = UserManager::get_user_productions($user_id);
  980. if (count($productions) > 0) {
  981. echo '<dt><strong>'.get_lang('Productions').'</strong></dt>';
  982. echo '<dd><ul>';
  983. foreach ($productions as $file) {
  984. // Only display direct file links to avoid browsing an empty directory
  985. if (is_file($sysdir.$file) && $file != $webdir_array['file']) {
  986. echo '<li><a href="'.$webdir.urlencode($file).'" target=_blank>'.$file.'</a></li>';
  987. }
  988. // Real productions are under a subdirectory by the User's id
  989. if (is_dir($sysdir.$file)) {
  990. $subs = scandir($sysdir.$file);
  991. foreach ($subs as $my => $sub) {
  992. if (substr($sub, 0, 1) != '.' && is_file($sysdir.$file.'/'.$sub)) {
  993. echo '<li><a href="'.$webdir.urlencode($file).'/'.urlencode($sub).'" target=_blank>'.$sub.'</a></li>';
  994. }
  995. }
  996. }
  997. }
  998. echo '</ul></dd>';
  999. }
  1000. }
  1001. /**
  1002. * @param string $content
  1003. * @param string $span_count
  1004. * @return string
  1005. */
  1006. public static function social_wrapper_div($content, $span_count)
  1007. {
  1008. $span_count = intval($span_count);
  1009. $html = '<div class="span'.$span_count.'">';
  1010. $html .= '<div class="well_border">';
  1011. $html .= $content;
  1012. $html .= '</div></div>';
  1013. return $html;
  1014. }
  1015. /**
  1016. * Dummy function
  1017. *
  1018. */
  1019. public static function get_plugins($place = SOCIAL_CENTER_PLUGIN)
  1020. {
  1021. $content = '';
  1022. switch ($place) {
  1023. case SOCIAL_CENTER_PLUGIN:
  1024. $social_plugins = array(1, 2);
  1025. if (is_array($social_plugins) && count($social_plugins) > 0) {
  1026. $content.= '<div id="social-plugins">';
  1027. foreach ($social_plugins as $plugin) {
  1028. $content.= '<div class="social-plugin-item">';
  1029. $content.= $plugin;
  1030. $content.= '</div>';
  1031. }
  1032. $content.= '</div>';
  1033. }
  1034. break;
  1035. case SOCIAL_LEFT_PLUGIN:
  1036. break;
  1037. case SOCIAL_RIGHT_PLUGIN:
  1038. break;
  1039. }
  1040. return $content;
  1041. }
  1042. /**
  1043. * Sends a message to someone's wall
  1044. * @param int $userId id of author
  1045. * @param int $friendId id where we send the message
  1046. * @param string $messageContent of the message
  1047. * @param int $messageId id parent
  1048. * @param string $messageStatus status type of message
  1049. * @return boolean
  1050. * @author Yannick Warnier
  1051. */
  1052. public static function sendWallMessage($userId, $friendId, $messageContent, $messageId = 0 ,$messageStatus)
  1053. {
  1054. $tblMessage = Database::get_main_table(TABLE_MAIN_MESSAGE);
  1055. $userId = intval($userId);
  1056. $friendId = intval($friendId);
  1057. $messageId = intval($messageId);
  1058. //Just in case we replace the and \n and \n\r while saving in the DB
  1059. $messageContent = str_replace(array("\n", "\n\r"), '<br />', $messageContent);
  1060. $cleanMessageContent = Database::escape_string($messageContent);
  1061. $attributes = array(
  1062. 'user_sender_id' => $userId,
  1063. 'user_receiver_id' => $friendId,
  1064. 'msg_status' => $messageStatus,
  1065. 'send_date' => api_get_utc_datetime(),
  1066. 'title' => '',
  1067. 'content' => $cleanMessageContent,
  1068. 'parent_id' => $messageId
  1069. );
  1070. return Database::insert($tblMessage, $attributes);
  1071. /* Deprecated since 2014-10-29
  1072. $senderInfo = api_get_user_info($userId);
  1073. $notification = new Notification();
  1074. $notification->save_notification(Notification::NOTIFICATION_TYPE_WALL_MESSAGE, array($friendId), '', $messageContent, $senderInfo);
  1075. */
  1076. }
  1077. /**
  1078. * Send File attachment (jpg,png)
  1079. * @author Anibal Copitan
  1080. * @param int $userId id user
  1081. * @param array $fileAttach
  1082. * @param int $messageId id message (relation with main message)
  1083. * @param string $fileComment description attachment file
  1084. * @return bool
  1085. */
  1086. public static function sendWallMessageAttachmentFile($userId, $fileAttach, $messageId, $fileComment = '')
  1087. {
  1088. $flag = false;
  1089. $tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
  1090. // create directory
  1091. $pathUserInfo = UserManager::get_user_picture_path_by_id($userId, 'system', true);
  1092. $social = '/social/';
  1093. $pathMessageAttach = $pathUserInfo['dir'] . 'message_attachments'. $social;
  1094. $safeFileComment = Database::escape_string($fileComment);
  1095. $safeFileName = Database::escape_string($fileAttach['name']);
  1096. $extension = strtolower(substr(strrchr($safeFileName, '.'), 1));
  1097. $allowedTypes = api_get_supported_image_extensions();
  1098. if (!in_array($extension, $allowedTypes)) {
  1099. $flag = false;
  1100. } else {
  1101. $newFileName = uniqid('') . '.' . $extension;
  1102. if (!file_exists($pathMessageAttach)) {
  1103. @mkdir($pathMessageAttach, api_get_permissions_for_new_directories(), true);
  1104. }
  1105. $newPath = $pathMessageAttach . $newFileName;
  1106. if (is_uploaded_file($fileAttach['tmp_name'])) {
  1107. @copy($fileAttach['tmp_name'], $newPath);
  1108. }
  1109. $small = self::resize_picture($newPath, IMAGE_WALL_SMALL_SIZE);
  1110. $medium = self::resize_picture($newPath, IMAGE_WALL_MEDIUM_SIZE);
  1111. $big = new Image($newPath);
  1112. $ok = $small && $small->send_image($pathMessageAttach . IMAGE_WALL_SMALL . '_' . $newFileName) &&
  1113. $medium && $medium->send_image($pathMessageAttach . IMAGE_WALL_MEDIUM .'_' . $newFileName) &&
  1114. $big && $big->send_image($pathMessageAttach . IMAGE_WALL_BIG . '_' . $newFileName);
  1115. // Insert
  1116. $newFileName = $social.$newFileName;
  1117. $sql = "INSERT INTO $tbl_message_attach(filename, comment, path, message_id, size)
  1118. VALUES ( '$safeFileName', '$safeFileComment', '$newFileName' , '$messageId', '".$fileAttach['size']."' )";
  1119. Database::query($sql);
  1120. $flag = true;
  1121. }
  1122. return $flag;
  1123. }
  1124. /**
  1125. * Gets all messages from someone's wall (within specific limits)
  1126. * @param int $userId id of wall shown
  1127. * @param string $messageStatus status wall message
  1128. * @param int|string $parentId id message (Post main)
  1129. * @param date $start Date from which we want to show the messages, in UTC time
  1130. * @param int $limit Limit for the number of parent messages we want to show
  1131. * @param int $offset Wall message query offset
  1132. * @return boolean
  1133. * @author Yannick Warnier
  1134. */
  1135. public static function getWallMessages($userId, $messageStatus, $parentId = '', $start = null, $limit = 10, $offset = 0)
  1136. {
  1137. if (empty($start)) {
  1138. $start = '0000-00-00';
  1139. }
  1140. $tblMessage = Database::get_main_table(TABLE_MAIN_MESSAGE);
  1141. $userId = intval($userId);
  1142. $start = Database::escape_string($start);
  1143. // TODO: set a maximum of 3 months for messages
  1144. //if ($start == '0000-00-00') {
  1145. //
  1146. //}
  1147. $limit = intval($limit);
  1148. $messages = array();
  1149. $sql = "SELECT id, user_sender_id,user_receiver_id, send_date, content, parent_id,
  1150. (SELECT ma.path from message_attachment ma WHERE ma.message_id = tm.id ) as path,
  1151. (SELECT ma.filename from message_attachment ma WHERE ma.message_id = tm.id ) as filename
  1152. FROM $tblMessage tm
  1153. WHERE user_receiver_id = $userId
  1154. AND send_date > '$start' ";
  1155. $sql .= (empty($messageStatus) || is_null($messageStatus)) ? '' : " AND msg_status = '$messageStatus' ";
  1156. $sql .= (empty($parentId) || is_null($parentId)) ? '' : " AND parent_id = '$parentId' ";
  1157. $sql .= " ORDER BY send_date DESC LIMIT $offset, $limit ";
  1158. $res = Database::query($sql);
  1159. if (Database::num_rows($res) > 0) {
  1160. while ($row = Database::fetch_array($res)) {
  1161. $messages[] = $row;
  1162. }
  1163. }
  1164. return $messages;
  1165. }
  1166. /**
  1167. * Gets all messages from someone's wall (within specific limits), formatted
  1168. * @param int $userId USER ID of the person's wall
  1169. * @param int $friendId id person
  1170. * @param int $idMessage id message
  1171. * @param string $start Start date (from when we want the messages until today)
  1172. * @param int $limit Limit to the number of messages we want
  1173. * @param int $offset Wall messages offset
  1174. * @return string HTML formatted string to show messages
  1175. */
  1176. public static function getWallMessagesHTML($userId, $friendId, $idMessage, $start = null, $limit = 10, $offset = 0)
  1177. {
  1178. if (empty($start)) {
  1179. $start = '0000-00-00';
  1180. }
  1181. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1182. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL, $idMessage, $start, $limit, $offset);
  1183. $formattedList = '<div class="mediaPost" style="width:calc(100%-14px);
  1184. display:block;padding-left:14px">';
  1185. $users = array();
  1186. // The messages are ordered by date descendant, for comments we need ascendant
  1187. krsort($messages);
  1188. foreach ($messages as $message) {
  1189. $date = api_get_local_time($message['send_date']);
  1190. $userIdLoop = $message['user_sender_id'];
  1191. if (!isset($users[$userIdLoop])) {
  1192. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1193. }
  1194. $nameComplete = api_is_western_name_order()
  1195. ? $users[$userIdLoop]['firstname'] .' ' . $users[$userIdLoop]['lastname']
  1196. : $users[$userIdLoop]['lastname'] . ' ' . $users[$userIdLoop]['firstname'];
  1197. $url = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$userIdLoop;
  1198. $media = '';
  1199. $media .= '<div class="media" style="width:100%; display:inline-block; margin-bottom:5px;">';
  1200. $media .= '<div class="media-body" style="width: 100%; height: 32px; margin-bottom:5px;">';
  1201. $media .= '<div class="pull-left" style="width: 32px; height: 100%;">';
  1202. $media .= '<a href="'.$url.'" >'
  1203. . '<img class="" src="'. $users[$userIdLoop]['avatar'] .'" '
  1204. . 'alt="'.$users[$userIdLoop]['complete_name'].'" style="width: 32px; height: 32px;"> '
  1205. . '</a>';
  1206. $media .= '</div>';
  1207. $media .= '<div class="pull-left" style="padding-left:4px;width: calc(100% - 36px);height: 100%;">';
  1208. $media .= '<div style="width: 100%; height: 50%;">';
  1209. $media .= '<h4 class="media-heading" style="width: inherit;">'
  1210. . '<a href="'.$url.'">'.$nameComplete.'</a></h4>';
  1211. $media .= '</div>';
  1212. $media .= '<div style="width: 100%; height: 50%;">';
  1213. $media .= '<div class="pull-left" style="height: 100%;">';
  1214. $media .= '<small><span class="time timeago" title="'.$date.'">'.$date.'</span></small>';
  1215. $media .= '</div>';
  1216. $media .= '</div>';
  1217. $media .= '</div>';
  1218. $media .= '</div>';
  1219. if ($isOwnWall) {
  1220. $media .= '<div style="width: 100%;height:20px">';
  1221. $media .= '<div><a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1222. $message['id'].'">'.get_lang('SocialMessageDelete').'</a></div>';
  1223. $media .= '</div>';
  1224. }
  1225. $media .= '<div style="width:100%;text-align:justify;">';
  1226. $media .= '<span class="content">'.Security::remove_XSS($message['content']).'</span>';
  1227. $media .= '</div>';
  1228. $media .= '</div>'; // end media
  1229. $formattedList .= $media;
  1230. }
  1231. $formattedList .= '</div>';
  1232. $formattedList .= '<div class="mediaPost" style="display:inline-block;">';
  1233. $formattedList .= '<form name="social_wall_message" method="POST">
  1234. <label for="social_wall_new_msg" class="hide">'.get_lang('SocialWriteNewComment').'</label>
  1235. <input type="hidden" name = "messageId" value="'.$idMessage.'" />
  1236. <textarea placeholder="'.get_lang('SocialWriteNewComment').
  1237. '" name="social_wall_new_msg" rows="1" cols="80" style="width: 98%"></textarea>
  1238. <br />
  1239. <input type="submit" name="social_wall_new_msg_submit"
  1240. value="'.get_lang('Post').'" class="float right btn" />
  1241. </form>';
  1242. $formattedList .= '</div>';
  1243. return $formattedList;
  1244. }
  1245. /**
  1246. * Gets all user's starting wall messages (within specific limits)
  1247. * @param int $userId User's id
  1248. * @param int $friendId Friend's id
  1249. * @param date $start Start date (from when we want the messages until today)
  1250. * @param int $limit Limit to the number of messages we want
  1251. * @param int $offset Wall messages offset
  1252. * @return array $data return user's starting wall messages along with message extra data
  1253. */
  1254. public static function getWallMessagesPostHTML($userId, $friendId = 0, $start = null, $limit = 10, $offset= 0)
  1255. {
  1256. if (empty($start)) {
  1257. $start = '0000-00-00';
  1258. }
  1259. $isOwnWall = (api_get_user_id() == $userId && $userId == $friendId);
  1260. $messages = self::getWallMessages($userId, MESSAGE_STATUS_WALL_POST , null, $start, $limit, $offset);
  1261. $users = array();
  1262. $data = array();
  1263. foreach ($messages as $key => $message) {
  1264. $date = api_get_local_time($message['send_date']);
  1265. $userIdLoop = $message['user_sender_id'];
  1266. $userFriendIdLoop = $message['user_receiver_id'];
  1267. if (!isset($users[$userIdLoop])) {
  1268. $users[$userIdLoop] = api_get_user_info($userIdLoop);
  1269. }
  1270. if (!isset($users[$userFriendIdLoop])) {
  1271. $users[$userFriendIdLoop] = api_get_user_info($userFriendIdLoop);
  1272. }
  1273. $html = '';
  1274. $html .= self::headerMessagePost(
  1275. $message['user_sender_id'],
  1276. $message['user_receiver_id'],
  1277. $users,
  1278. $message,
  1279. $isOwnWall
  1280. );
  1281. $data[$key]['id'] = $message['id'];
  1282. $data[$key]['html'] = $html;
  1283. }
  1284. return $data;
  1285. }
  1286. /**
  1287. * Returns the formatted header message post
  1288. * @param int $authorId Author's id
  1289. * @param int $receiverId Receiver's id
  1290. * @param array $users Author's and receiver's data
  1291. * @param array $message Message data
  1292. * @param boolean $isOwnWall Determines if the author is in its own social wall or not
  1293. * @return string $html The formatted header message post
  1294. */
  1295. private static function headerMessagePost($authorId, $receiverId, $users, $message, $isOwnWall = false)
  1296. {
  1297. $date = api_get_local_time($message['send_date']);
  1298. $avatarAuthor = $users[$authorId]['avatar'];
  1299. $urlAuthor = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$authorId;
  1300. $nameCompleteAuthor = api_get_person_name(
  1301. $users[$authorId]['firstname'],
  1302. $users[$authorId]['lastname']
  1303. );
  1304. // Deprecated since 2014-10-29
  1305. //$avatarReceiver = $users[$receiverId]['avatar'];
  1306. $urlReceiver = api_get_path(WEB_CODE_PATH).'social/profile.php?u='.$receiverId;
  1307. $nameCompleteReceiver = api_get_person_name(
  1308. $users[$receiverId]['firstname'],
  1309. $users[$receiverId]['lastname']
  1310. );
  1311. $htmlReceiver = '';
  1312. if ($authorId != $receiverId) {
  1313. $htmlReceiver = ' > <a href="'.$urlReceiver.'">' . $nameCompleteReceiver . '</a> ';
  1314. }
  1315. $wallImage = '';
  1316. if (!empty($message['path'])) {
  1317. $pathUserInfo = UserManager::get_user_picture_path_by_id($authorId, 'web', true);
  1318. $pathImg = $pathUserInfo['dir'] . 'message_attachments';
  1319. $imageBig = $pathImg .self::getImagePath($message['path'], IMAGE_WALL_BIG);
  1320. $imageSmall = $pathImg. self::getImagePath($message['path'], IMAGE_WALL_SMALL);
  1321. $wallImage = '<a class="thumbnail thickbox" href="'.$imageBig.'"><img src="'.$imageSmall.'"></a>';
  1322. }
  1323. $htmlDelete = '';
  1324. if ($isOwnWall) {
  1325. $htmlDelete .= '<a href="'.api_get_path(WEB_CODE_PATH).'social/profile.php?messageId='.
  1326. $message['id'].'">'.get_lang('SocialMessageDelete').'</a>';
  1327. }
  1328. $html = '';
  1329. $html .= '<div class="mediaPost" style="width: 100%; display:inline-block; margin-bottom:5px;">';
  1330. $html .= '<div class="media-body" style="width: 100%; height: 40px; margin-bottom:5px;">';
  1331. $html .= '<div class="pull-left" style="width: 40px; height: 100%;">';
  1332. $html .= '<a href="'.$urlAuthor.'">'.'<img class="" src="'.$avatarAuthor.
  1333. '" alt="'.$nameCompleteAuthor.'" style="width: 40px; height: 40px;"></a>';
  1334. $html .= '</div>';
  1335. $html .= '<div class="pull-left" style="padding-left:4px; width: calc(100% - 44px);height: 100%;">';
  1336. $html .= '<div style="width: 100%; height: 50%;">';
  1337. $html .= '<h4 class="media-heading" style="width: inherit;">';
  1338. $html .= '<a href="'.$urlAuthor.'">'.$nameCompleteAuthor.'</a>'.$htmlReceiver.'</h4>';
  1339. $html .= '</div>';
  1340. $html .= '<div style="width: 100%; height: 50%;">';
  1341. $html .= '<div class="pull-left" style="height: 100%;">';
  1342. $html .= '<small><span class="time timeago" title="'.$date.'">'.$date.'</span></small>';
  1343. $html .= '</div>';
  1344. $html .= '</div>';
  1345. $html .= '</div>';
  1346. $html .= '</div>';
  1347. if ($isOwnWall) {
  1348. $html .= '<div style="width: 100%;height:20px">';
  1349. $html .= $htmlDelete;
  1350. $html .= '</div>';
  1351. }
  1352. $html .= '<div style="width: 100%;">';
  1353. $html .= $wallImage;
  1354. $html .= '</div>';
  1355. $html .= '<div style="width:100%;text-align:justify;">';
  1356. $html .= '<span class="content">'.
  1357. Security::remove_XSS(self::readContentWithOpenGraph($message['content'])).'</span>';
  1358. $html .= '</div>';
  1359. $html .= '</div>'; // end mediaPost
  1360. return $html;
  1361. }
  1362. /**
  1363. * Get schedule html (with data openGrap)
  1364. * @param string $text Content text
  1365. * @return string $newText Content text with OpenGraph
  1366. */
  1367. public static function readContentWithOpenGraph($text)
  1368. {
  1369. // search link in first line
  1370. $regExUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
  1371. $newText = '';
  1372. $count = 0;
  1373. if(preg_match($regExUrl, $text, $url)) {
  1374. // make the urls hyper links
  1375. $newText .= preg_replace($regExUrl, "<a target=\"_blank\" href=" . $url[0] . ">".$url[0]."</a> ", $text);
  1376. if ($count == 0) {
  1377. // Comment this line to disable OpenGraph
  1378. //$newText .= self::getHtmlByLink($url[0]);
  1379. }
  1380. $count++;
  1381. } else {
  1382. $newText .= $text;
  1383. }
  1384. return $newText;
  1385. }
  1386. /**
  1387. * html with data OpenGrap
  1388. * @param $link url
  1389. * @return string data html
  1390. */
  1391. public static function getHtmlByLink($link)
  1392. {
  1393. $graph = OpenGraph::fetch($link);
  1394. $title = $graph->title;
  1395. $html = '<div>';
  1396. $html .= '<a target="_blank" href="'.$link.'"><h3>'.$title.'</h3>';
  1397. $html .= empty($graph->image) ? '' : '<img alt="" src="'.$graph->image.'" height="160" ></a>';
  1398. $html .= empty($graph->description) ? '' : '<div>'.$graph->description.'</div>';
  1399. $html .= "</div>";
  1400. return $html;
  1401. }
  1402. /**
  1403. * Get full image path from a path and a size
  1404. * @param string $path
  1405. * @return string
  1406. */
  1407. private static function getImagePath($path, $size = '')
  1408. {
  1409. $name = '';
  1410. $array = preg_split('#\/#', $path);
  1411. if (isset($array[2]) && !empty($array[2])) {
  1412. if ($size == IMAGE_WALL_SMALL) {
  1413. $name = IMAGE_WALL_SMALL. '_' . $array[2];
  1414. }else if($size == IMAGE_WALL_MEDIUM){
  1415. $name = IMAGE_WALL_MEDIUM. '_' . $array[2];
  1416. }else if($size == IMAGE_WALL_BIG){
  1417. $name = IMAGE_WALL_BIG. '_' . $array[2];
  1418. }else {
  1419. $name = IMAGE_WALL_SMALL. '_' . $array[2];
  1420. }
  1421. $lessImage = str_replace($array[2], '', $path);
  1422. $name = $lessImage . $name;
  1423. }
  1424. return $name;
  1425. }
  1426. /**
  1427. * Delete messages delete logic
  1428. * @param int $id indice message to delete.
  1429. * @return status query
  1430. */
  1431. public static function deleteMessage($id)
  1432. {
  1433. $id = intval($id);
  1434. $tblMessage = Database::get_main_table(TABLE_MESSAGE);
  1435. $statusMessage = MESSAGE_STATUS_WALL_DELETE;
  1436. $sql = "UPDATE $tblMessage SET msg_status = '$statusMessage' WHERE id = '{$id}' ";
  1437. return Database::query($sql);
  1438. }
  1439. }