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