]> git.mxchange.org Git - friendica.git/blob - mod/network.php
c5845f63c8c81a301b624d3f27c187130d901606
[friendica.git] / mod / network.php
1 <?php
2
3
4 function network_init(&$a) {
5         require_once('include/group.php');
6         $a->page['aside'] .= group_side('network','network');
7 }
8
9
10 function network_content(&$a, $update = false) {
11
12         if(! local_user())
13                 return;
14
15         require_once("include/bbcode.php");
16
17         $contact_id = $a->cid;
18
19         $group = 0;
20
21         if(! $update) {
22                 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
23
24                         // pull out the group here because the updater might have different args
25                 if($a->argc > 1) {
26                         $group = intval($a->argv[1]);
27                         $group_acl = array('allow_gid' => '<' . $group . '>');
28                 }
29                 $_SESSION['return_url'] = $a->cmd;
30
31                 $tpl = file_get_contents('view/jot-header.tpl');
32         
33                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
34
35                 require_once('view/acl_selectors.php');
36
37                 $tpl = file_get_contents("view/jot.tpl");
38                 
39                 if(($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid'])))))
40                                 $lockstate = 'lock';
41                         else
42                                 $lockstate = 'unlock';
43
44                 $o .= replace_macros($tpl,array(
45                         '$return_path' => $a->cmd,
46                         '$baseurl' => $a->get_baseurl(),
47                         '$defloc' => $a->user['default-location'],
48                         '$visitor' => 'block',
49                         '$lockstate' => $lockstate,
50                         '$acl' => populate_acl(($group) ? $group_acl : $a->user),
51                         '$bang' => (($group) ? '!' : ''),
52                         '$profile_uid' => $_SESSION['uid']
53                 ));
54
55
56                 // The special div is needed for liveUpdate to kick in for this page.
57                 // We only launch liveUpdate if you are on the front page, you aren't
58                 // filtering by group and also you aren't writing a comment (the last
59                 // criteria is discovered in javascript).
60
61                 if($a->pager['start'] == 0 && $a->argc == 1)
62                         $o .= '<div id="live-network"></div>' . "\r\n";
63         }
64
65         // We aren't going to try and figure out at the item, group, and page level 
66         // which items you've seen and which you haven't. You're looking at some
67         // subset of items, so just mark everything seen. 
68         
69         $r = q("UPDATE `item` SET `unseen` = 0 
70                 WHERE `unseen` = 1 AND `uid` = %d",
71                 intval($_SESSION['uid'])
72         );
73
74         // We don't have to deal with ACL's on this page. You're looking at everything
75         // that belongs to you, hence you can see all of it. We will filter by group if
76         // desired. 
77
78         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
79
80         if($group) {
81                 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
82                         intval($group),
83                         intval($_SESSION['uid'])
84                 );
85                 if(! count($r)) {
86                         notice( t('No such group') . EOL );
87                         goaway($a->get_baseurl() . '/network');
88                         return; // NOTREACHED
89                 }
90
91                 $contacts = expand_groups(array($group));
92                 $contact_str = implode(',',$contacts);
93                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
94                 $o = '<h4>' . t('Group: ') . $r[0]['name'] . '</h4>' . $o;
95
96         }
97
98         $r = q("SELECT COUNT(*) AS `total`
99                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
100                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
101                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
102                 $sql_extra ",
103                 intval($_SESSION['uid'])
104         );
105
106         if(count($r))
107                 $a->set_pager_total($r[0]['total']);
108
109         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
110                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
111                 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
112                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
113                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
114                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
115                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
116                 $sql_extra
117                 ORDER BY `parent` DESC, `gravity` ASC, `created` ASC LIMIT %d ,%d ",
118                 intval($_SESSION['uid']),
119                 intval($a->pager['start']),
120                 intval($a->pager['itemspage'])
121         );
122
123
124         $cmnt_tpl = file_get_contents('view/comment_item.tpl');
125         $like_tpl = file_get_contents('view/like.tpl');
126         $tpl = file_get_contents('view/wall_item.tpl');
127         $wallwall = file_get_contents('view/wallwall_item.tpl');
128
129         $alike = array();
130         $dlike = array();
131         
132         if(count($r)) {
133                 foreach($r as $item) {
134
135                         if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) {
136                                 $url = $item['url'];
137                                 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) 
138                                         $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
139                                 if(! is_array($alike[$item['parent'] . '-l']))
140                                         $alike[$item['parent'] . '-l'] = array();
141                                 $alike[$item['parent']] ++;
142                                 $alike[$item['parent'] . '-l'][] = '<a href="'. $url . '">' . $item['name'] . '</a>';
143                         }
144                         if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) {
145                                 $url = $item['url'];
146                                 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'])) 
147                                         $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
148                                 if(! is_array($dlike[$item['parent'] . '-l']))
149                                         $dlike[$item['parent'] . '-l'] = array();
150                                 $dlike[$item['parent']] ++;
151                                 $dlike[$item['parent'] . '-l'][] = '<a href="'. $url . '">' . $item['name'] . '</a>';
152                         }
153                 }
154
155                 foreach($r as $item) {
156
157                         $comment = '';
158                         $template = $tpl;
159                         $commentww = '';
160
161                         $profile_url = $item['url'];
162                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
163
164                         if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) 
165                                 continue;
166
167                         // Top-level wall post not written by the wall owner (wall-to-wall)
168                         // First figure out who owns it. 
169
170                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
171
172                                 if($item['type'] == 'wall') {
173                                         // I do. Put me on the left of the wall-to-wall notice.
174                                         $owner_url = $a->contact['url'];
175                                         $owner_photo = $a->contact['thumb'];
176                                         $owner_name = $a->contact['name'];
177                                         $template = $wallwall;
178                                         $commentww = 'ww';      
179                                 }
180                                 if($item['type'] == 'remote' && ($item['owner-link'] != $item['author-link'])) {
181                                         // Could be anybody. 
182                                         $owner_url = $item['owner-link'];
183                                         $owner_photo = $item['owner-avatar'];
184                                         $owner_name = $item['owner-name'];
185                                         $template = $wallwall;
186                                         $commentww = 'ww';
187                                         // If it is our contact, use a friendly redirect link
188                                         if(($item['owner-link'] == $item['url']) && ($item['rel'] == REL_VIP || $item['rel'] == REL_BUD))
189                                                 $owner_url = $redirect_url;
190
191                                 }
192                         }
193
194                         if($update)
195                                 $return_url = $_SESSION['return_url'];
196                         else
197                                 $return_url = $_SESSION['return_url'] = $a->cmd;
198
199                         $likebuttons = '';
200                         if($item['id'] == $item['parent']) {
201                                 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
202                         }
203
204                         if($item['last-child']) {
205                                 $comment = replace_macros($cmnt_tpl,array(
206                                         '$return_path' => $_SESSION['return_url'],
207                                         '$type' => 'net-comment',
208                                         '$id' => $item['item_id'],
209                                         '$parent' => $item['parent'],
210                                         '$profile_uid' =>  $_SESSION['uid'],
211                                         '$mylink' => $a->contact['url'],
212                                         '$mytitle' => t('Me'),
213                                         '$myphoto' => $a->contact['thumb'],
214                                         '$ww' => $commentww
215                                 ));
216                         }
217
218
219                         $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
220
221
222         
223                         if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'] ))
224                                 $profile_url = $redirect_url;
225
226                         $photo = $item['photo'];
227                         $thumb = $item['thumb'];
228
229                         // Post was remotely authored.
230
231                         $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
232                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $thumb);
233
234                         $profile_link = $profile_url;
235
236                         // Can we use our special contact URL for this author? 
237
238                         if(strlen($item['author-link'])) {
239                                 if($item['author-link'] == $item['url'])
240                                         $profile_link = $redirect_url;
241                                 else
242                                         $profile_link = $item['author-link'];
243                         }
244
245
246                         $like    = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
247                         $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
248
249
250                         // Build the HTML
251
252                         $o .= replace_macros($template,array(
253                                 '$id' => $item['item_id'],
254                                 '$profile_url' => $profile_link,
255                                 '$name' => $profile_name,
256                                 '$thumb' => $profile_avatar,
257                                 '$title' => $item['title'],
258                                 '$body' => bbcode($item['body']),
259                                 '$ago' => relative_date($item['created']),
260                                 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
261                                 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
262                                 '$owner_url' => $owner_url,
263                                 '$owner_photo' => $owner_photo,
264                                 '$owner_name' => $owner_name,
265                                 '$drop' => $drop,
266                                 '$vote' => $likebuttons,
267                                 '$like' => $like,
268                                 '$dislike' => $dislike,
269                                 '$comment' => $comment
270                         ));
271                 }
272         }
273
274         if(! $update)
275                 $o .= paginate($a);
276
277         return $o;
278 }