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