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