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