]> git.mxchange.org Git - friendica.git/blob - mod/network.php
096c8a79ff1e45a59fdfb9ca5476b8eb40df0cca
[friendica.git] / mod / network.php
1 <?php
2
3
4 function network_init(&$a) {
5         if(! local_user()) {
6                 notice( t('Permission denied.') . EOL);
7                 return;
8         }
9   
10   
11         require_once('include/group.php');
12         if(! x($a->page,'aside'))
13                 $a->page['aside'] = '';
14
15         $a->page['aside'] .= '<div id="network-new-link">';
16
17         if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new'))
18                 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '">' . t('Normal View') . '</a>';
19         else 
20                 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . '">' . t('New Item View') . '</a>';
21
22         $a->page['aside'] .= '</div>';
23
24         $a->page['aside'] .= group_side('network','network');
25 }
26
27
28 function network_content(&$a, $update = 0) {
29
30         if(! local_user())
31         return login(false);
32
33         $o = '';
34
35         require_once("include/bbcode.php");
36
37         $contact_id = $a->cid;
38
39         $group = 0;
40
41         if(! $update) {
42                 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
43
44                 $nouveau = false;
45
46                 if(($a->argc > 2) && $a->argv[2] === 'new')
47                         $nouveau = true;
48
49                         // pull out the group here because the updater might have different args
50                 if($a->argc > 1) {
51                         if($a->argv[1] === 'new')
52                                 $nouveau = true;
53                         else {
54                                 $group = intval($a->argv[1]);
55                                 $group_acl = array('allow_gid' => '<' . $group . '>');
56                         }
57                 }
58
59                 $_SESSION['return_url'] = $a->cmd;
60
61                 $geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
62
63                 $tpl = load_view_file('view/jot-header.tpl');
64         
65                 $a->page['htmlhead'] .= replace_macros($tpl, array(
66                         '$baseurl' => $a->get_baseurl(),
67                         '$geotag' => $geotag,
68                         '$nickname' => $a->user['nickname']
69                 ));
70
71                 require_once('include/acl_selectors.php');
72
73                 $tpl = load_view_file("view/jot.tpl");
74                 
75                 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'])))))
76                                 $lockstate = 'lock';
77                         else
78                                 $lockstate = 'unlock';
79
80                 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
81
82                 $o .= replace_macros($tpl,array(
83                         '$return_path' => $a->cmd,
84                         '$baseurl' => $a->get_baseurl(),
85                         '$defloc' => $a->user['default-location'],
86                         '$visitor' => 'block',
87                         '$lockstate' => $lockstate,
88                         '$acl' => populate_acl((($group) ? $group_acl : $a->user), $celeb),
89                         '$bang' => (($group) ? '!' : ''),
90                         '$profile_uid' => $_SESSION['uid']
91                 ));
92
93
94                 // The special div is needed for liveUpdate to kick in for this page.
95                 // We only launch liveUpdate if you are on the front page, you aren't
96                 // filtering by group and also you aren't writing a comment (the last
97                 // criteria is discovered in javascript).
98
99                 if($a->pager['start'] == 0 && $a->argc == 1) {
100                         $o .= '<div id="live-network"></div>' . "\r\n";
101                         $o .= "<script> var profile_uid = " . $_SESSION['uid'] . "; </script>\r\n";
102                 }
103
104         }
105
106         // We aren't going to try and figure out at the item, group, and page level 
107         // which items you've seen and which you haven't. You're looking at some
108         // subset of items, so just mark everything seen. 
109         
110         $r = q("UPDATE `item` SET `unseen` = 0 
111                 WHERE `unseen` = 1 AND `uid` = %d",
112                 intval($_SESSION['uid'])
113         );
114
115         // We don't have to deal with ACL's on this page. You're looking at everything
116         // that belongs to you, hence you can see all of it. We will filter by group if
117         // desired. 
118
119         $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
120
121         if($group) {
122                 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
123                         intval($group),
124                         intval($_SESSION['uid'])
125                 );
126                 if(! count($r)) {
127                         notice( t('No such group') . EOL );
128                         goaway($a->get_baseurl() . '/network');
129                         return; // NOTREACHED
130                 }
131
132                 $contacts = expand_groups(array($group));
133                 if((is_array($contacts)) && count($contacts)) {
134                         $contact_str = implode(',',$contacts);
135                 }
136                 else {
137                                 $contact_str = ' 0 ';
138                                 notice( t('Group is empty'));
139                 }
140
141                 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
142                 $o = '<h4>' . t('Group: ') . $r[0]['name'] . '</h4>' . $o;
143         }
144
145         if((! $group) && (! $update))
146                 $o .= get_birthdays();
147
148
149         $r = q("SELECT COUNT(*) AS `total`
150                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
151                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
152                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
153                 $sql_extra ",
154                 intval($_SESSION['uid'])
155         );
156
157         if(count($r))
158                 $a->set_pager_total($r[0]['total']);
159
160         if($nouveau) {
161                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
162                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
163                         `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
164                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
165                         FROM `item`, `contact`
166                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
167                         AND `contact`.`id` = `item`.`contact-id`
168                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
169                         $sql_extra
170                         ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
171                         intval($_SESSION['uid']),
172                         intval($a->pager['start']),
173                         intval($a->pager['itemspage'])
174                 );
175         }
176         else {
177                 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
178                         `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
179                         `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
180                         `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
181                         FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact` 
182                         WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
183                         AND `contact`.`id` = `item`.`contact-id`
184                         AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
185                         AND `item`.`parent` = `parentitem`.`id`
186                         $sql_extra
187                         ORDER BY `parentitem`.`created`  DESC, `item`.`gravity` ASC, `item`.`created` ASC LIMIT %d ,%d ",
188                         intval($_SESSION['uid']),
189                         intval($a->pager['start']),
190                         intval($a->pager['itemspage'])
191                 );
192         }
193
194
195         $cmnt_tpl = load_view_file('view/comment_item.tpl');
196         $like_tpl = load_view_file('view/like.tpl');
197         $tpl = load_view_file('view/wall_item.tpl');
198         $wallwall = load_view_file('view/wallwall_item.tpl');
199
200         $alike = array();
201         $dlike = array();
202         
203         if(count($r)) {
204
205                 if($nouveau) {
206
207                         $tpl = load_view_file('view/search_item.tpl');
208                         $droptpl = load_view_file('view/wall_fake_drop.tpl');
209
210                         foreach($r as $item) {
211
212                                 $comment     = '';
213                                 $owner_url   = '';
214                                 $owner_photo = '';
215                                 $owner_name  = '';
216                                 $sparkle     = '';
217                         
218                                 $profile_name   = ((strlen($item['author-name']))   ? $item['author-name']   : $item['name']);
219                                 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
220                                 $profile_link   = ((strlen($item['author-link']))   ? $item['author-link']   : $item['url']);
221
222
223                                 $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
224                                 $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
225                                 if($coord) {
226                                         if($location)
227                                                 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
228                                         else
229                                                 $location = '<span class="smalltext">' . $coord . '</span>';
230                                 }
231
232                                 $drop = replace_macros($droptpl,array('$id' => $item['id']));
233                                 $lock = '<div class="wall-item-lock"></div>';
234
235                                 $o .= replace_macros($tpl,array(
236                                         '$id' => $item['item_id'],
237                                         '$profile_url' => $profile_link,
238                                         '$name' => $profile_name,
239                                         '$sparkle' => $sparkle,
240                                         '$lock' => $lock,
241                                         '$thumb' => $profile_avatar,
242                                         '$title' => $item['title'],
243                                         '$body' => bbcode($item['body']),
244                                         '$ago' => relative_date($item['created']),
245                                         '$location' => $location,
246                                         '$indent' => '',
247                                         '$owner_url' => $owner_url,
248                                         '$owner_photo' => $owner_photo,
249                                         '$owner_name' => $owner_name,
250                                         '$drop' => $drop,
251                                         '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
252                                 ));
253
254                         }
255                         $o .= paginate($a);
256
257                         return $o;
258
259                 }
260
261
262
263                 foreach($r as $item) {
264                         like_puller($a,$item,$alike,'like');
265                         like_puller($a,$item,$dlike,'dislike');
266                 }
267
268                 foreach($r as $item) {
269
270                         $comment = '';
271                         $template = $tpl;
272                         $commentww = '';
273                         $owner_url = $owner_photo = $owner_name = '';
274
275                         $profile_url = $item['url'];
276
277                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
278
279                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
280                                 continue;
281
282
283                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
284                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
285                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
286                                 : '<div class="wall-item-lock"></div>');
287
288
289                         // Top-level wall post not written by the wall owner (wall-to-wall)
290                         // First figure out who owns it. 
291
292                         $osparkle = '';
293
294                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
295
296                                 if($item['type'] === 'wall') {
297                                         // I do. Put me on the left of the wall-to-wall notice.
298                                         $owner_url = $a->contact['url'];
299                                         $owner_photo = $a->contact['thumb'];
300                                         $owner_name = $a->contact['name'];
301                                         $template = $wallwall;
302                                         $commentww = 'ww';      
303                                 }
304                                 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
305                                         // Could be anybody. 
306                                         $owner_url = $item['owner-link'];
307                                         $owner_photo = $item['owner-avatar'];
308                                         $owner_name = $item['owner-name'];
309                                         $template = $wallwall;
310                                         $commentww = 'ww';
311                                         // If it is our contact, use a friendly redirect link
312                                         if((link_compare($item['owner-link'],$item['url'])) 
313                                                 && ($item['network'] === 'dfrn')) {
314                                                 $owner_url = $redirect_url;
315                                                 $osparkle = ' sparkle';
316                                         }
317
318                                 }
319                         }
320
321                         if($update)
322                                 $return_url = $_SESSION['return_url'];
323                         else
324                                 $return_url = $_SESSION['return_url'] = $a->cmd;
325
326                         $likebuttons = '';
327                         if($item['id'] == $item['parent']) {
328                                 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
329                         }
330
331                         if($item['last-child']) {
332                                 $comment = replace_macros($cmnt_tpl,array(
333                                         '$return_path' => $_SESSION['return_url'],
334                                         '$type' => 'net-comment',
335                                         '$id' => $item['item_id'],
336                                         '$parent' => $item['parent'],
337                                         '$profile_uid' =>  $_SESSION['uid'],
338                                         '$mylink' => $a->contact['url'],
339                                         '$mytitle' => t('This is you'),
340                                         '$myphoto' => $a->contact['thumb'],
341                                         '$ww' => $commentww
342                                 ));
343                         }
344
345                         $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
346
347
348         
349                         if(($item['network'] === 'dfrn') && (! $item['self'] )) {
350                                 $profile_url = $redirect_url;
351                                 $sparkle = ' sparkle';
352                         }
353
354                         $photo = $item['photo'];
355                         $thumb = $item['thumb'];
356
357                         // Post was remotely authored.
358
359                         $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
360
361                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
362                         $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
363
364
365                         $profile_link = $profile_url;
366
367                         // Can we use our special contact URL for this author? 
368
369                         if(strlen($item['author-link'])) {
370                                 if((link_compare($item['author-link'],$item['url'])) && ($item['network'] === 'dfrn') && (! $item['self'])) {
371                                         $profile_link = $redirect_url;
372                                         $sparkle = ' sparkle';
373                                 }
374                                 else {
375                                         $profile_link = $item['author-link'];
376                                         $sparkle = '';
377                                 }
378                         }
379
380
381                         $like    = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
382                         $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
383
384                         $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
385                         $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
386                         if($coord) {
387                                 if($location)
388                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
389                                 else
390                                         $location = '<span class="smalltext">' . $coord . '</span>';
391                         }
392
393                         $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
394
395                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
396                                 $indent .= ' shiny'; 
397
398
399                         // Build the HTML
400
401                         $tmp_item = replace_macros($template,array(
402                                 '$id' => $item['item_id'],
403                                 '$title' => t('View $name\'s profile'),
404                                 '$profile_url' => $profile_link,
405                                 '$name' => $profile_name,
406                                 '$thumb' => $profile_avatar,
407                                 '$osparkle' => $osparkle,
408                                 '$sparkle' => $sparkle,
409                                 '$title' => $item['title'],
410                                 '$body' => smilies(bbcode($item['body'])),
411                                 '$ago' => relative_date($item['created']),
412                                 '$lock' => $lock,
413                                 '$location' => $location,
414                                 '$indent' => $indent,
415                                 '$owner_url' => $owner_url,
416                                 '$owner_photo' => $owner_photo,
417                                 '$owner_name' => $owner_name,
418                                 '$drop' => $drop,
419                                 '$vote' => $likebuttons,
420                                 '$like' => $like,
421                                 '$dislike' => $dislike,
422                                 '$comment' => $comment
423                         ));
424
425                         $arr = array('item' => $item, 'output' => $tmp_item);
426                         call_hooks('display_item', $arr);
427
428                         $o .= $arr['output'];
429
430                 }
431         }
432
433         if(! $update)
434                 $o .= paginate($a);
435
436         return $o;
437 }