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