move code up one directory
[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 //      debug($matches);exit;
10         
11         $rtn = '';
12         if (is_array($matches))
13         {
14                 $curr_len = 0;
15                 foreach ($matches as $i => $tag)
16                 {
17                         if (($curr_len + strlen($tag[1])) > $length)
18                         {
19                                 $rtn .= substr($tag[1], 0, ($length - $curr_len)) . ' ...';
20                                 return $rtn;
21                         }
22                         else
23                         {
24                                 $rtn .= $tag[1];
25                                 $curr_len += strlen($tag[1]);
26                         }
27                         
28                         if (($curr_len + strlen($tag[4])) > $length)
29                         {
30                                 $rtn .= $tag[3].substr($tag[4], 0, ($length - $curr_len)).'...'.$tag[5];
31                                 return $rtn;
32                         }
33                         else
34                         {
35                                 $rtn .= $tag[2];
36                                 $curr_len += strlen($tag[4]);
37                         }
38                 }
39                 
40                 $pos_after_last_match = strpos($str, $tag[0]) + strlen($tag[0]);
41                 $str_after_last_match = substr($str, $pos_after_last_match);
42
43                 if (($curr_len + strlen($str_after_last_match)) > $length)
44                         $rtn .= substr($str_after_last_match, 0, ($length - $curr_len)).' ...';
45                 else
46                         $rtn = $str;
47         }
48         else
49                 $rtn = substr($str, 0, $length);
50         
51         return $rtn;
52 }
53
54 global $db;
55
56 $link_limit = 3;                //Numero massimo dei possibili sottocontenuti visualizzabili nella home-page
57 $cnt = 0;
58
59 $actvity_obj = new Activity();
60 $activities = $actvity_obj->getFriendsActivities($_SESSION['member_id']);
61
62 if (is_array($activities)) {
63         foreach ($activities as $i => $activity) {
64                 if ($cnt >= $link_limit) break;
65                 $cnt++;
66                 
67                 $link_title = printSocialName($activity['member_id']).' '. $activity['title'];
68
69                 $list[] = '<span title="'.strip_tags($link_title).'">'.substring($link_title, SUBLINK_TEXT_LEN)."</span>";
70         }
71         return $list;   
72 } else {
73         return 0;
74 }
75
76 ?>