made a copy
[atutor.git] / mods / _standard / social / sublinks.php
1 <?php
2
3 if (!defined('AT_INCLUDE_PATH')) { exit; }
4 include_once(AT_INCLUDE_PATH.'../mods/_standard/social/lib/friends.inc.php');
5
6 function substring($str, $length)
7 {
8         preg_match_all("|(.*)((<[^>]+>)(.*)(</[^>]+>))|U", $str, $matches, PREG_SET_ORDER);
9 //      print_r($matches);
10         
11         $rtn = '';
12         
13         if (is_array($matches))
14         {
15                 $curr_len = 0;
16                 foreach ($matches as $i => $tag)
17                 {
18                         if (($curr_len + strlen($tag[1])) > $length)
19                         {
20                                 $rtn .= substr($tag[1], 0, ($length - $curr_len)) . ' ...';
21                                 break;
22                         }
23                         else
24                         {
25                                 $rtn .= $tag[1];
26                                 $curr_len += strlen($tag[1]);
27                         }
28                         
29                         if (($curr_len + strlen($tag[4])) > $length)
30                         {
31                                 $rtn .= $tag[3].substr($tag[4], 0, ($length - $curr_len)).'...'.$tag[5];
32                                 break;
33                         }
34                         else
35                         {
36                                 $rtn .= $tag[2];
37                                 $curr_len += strlen($tag[4]);
38                         }
39                 }
40                 
41                 $pos_after_last_match = strpos($str, $tag[0]) + strlen($tag[0]);
42                 $str_after_last_match = substr($str, $pos_after_last_match);
43         
44                 if (($curr_len + strlen($str_after_last_match)) > $length)
45                         $rtn .= substr($str_after_last_match, 0, ($length - $curr_len)).' ...';
46                 else
47                         $rtn = $str;
48         }
49         else
50                 $rtn = substr($str, 0, $length);
51         
52         return $rtn;
53 }
54
55 global $db;
56
57 $link_limit = 3;                //Numero massimo dei possibili sottocontenuti visualizzabili nella home-page
58 $cnt = 0;
59
60 $actvity_obj = new Activity();
61 $activities = $actvity_obj->getFriendsActivities($_SESSION['member_id']);
62
63 if (is_array($activities)) {
64         foreach ($activities as $i => $activity) {
65                 if ($cnt >= $link_limit) break;
66                 $cnt++;
67                 
68                 $link_title = printSocialName($activity['member_id']).' '. $activity['title'];
69
70                 $list[] = '<span title="'.strip_tags($link_title).'">'.substring($link_title, SUBLINK_TEXT_LEN)."</span>";
71         }
72         return $list;   
73 } else {
74         return 0;
75 }
76
77 ?>