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