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