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