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