4 function network_init(&$a) {
6 notice( t('Permission denied.') . EOL);
11 require_once('include/group.php');
12 if(! x($a->page,'aside'))
13 $a->page['aside'] = '';
15 $a->page['aside'] .= '<div id="network-new-link">';
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>';
20 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . '">' . t('New Item View') . '</a>';
22 $a->page['aside'] .= '</div>';
24 $a->page['aside'] .= group_side('network','network');
28 function network_content(&$a, $update = 0) {
35 require_once("include/bbcode.php");
37 $contact_id = $a->cid;
42 require_once('include/acl_selectors.php');
44 if(($a->argc > 2) && $a->argv[2] === 'new')
48 if($a->argv[1] === 'new')
51 $group = intval($a->argv[1]);
52 $group_acl = array('allow_gid' => '<' . $group . '>');
57 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
59 $_SESSION['return_url'] = $a->cmd;
61 $geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
63 $tpl = load_view_file('view/jot-header.tpl');
65 $a->page['htmlhead'] .= replace_macros($tpl, array(
66 '$baseurl' => $a->get_baseurl(),
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 '$title' => t('Enter a title for this item')
78 $tpl = load_view_file("view/jot.tpl");
80 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'])))))
83 $lockstate = 'unlock';
85 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
89 call_hooks('jot_tool', $jotplugins);
90 call_hooks('jot_networks', $jotnets);
92 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
94 $o .= replace_macros($tpl,array(
95 '$return_path' => $a->cmd,
97 '$share' => t('Share'),
98 '$upload' => t('Upload photo'),
99 '$weblink' => t('Insert web link'),
100 '$youtube' => t('Insert YouTube video'),
101 '$video' => t('Insert Vorbis [.ogg] video'),
102 '$audio' => t('Insert Vorbis [.ogg] audio'),
103 '$setloc' => t('Set your location'),
104 '$noloc' => t('Clear browser location'),
105 '$title' => t('Set title'),
106 '$wait' => t('Please wait'),
107 '$permset' => t('Permission settings'),
110 '$baseurl' => $a->get_baseurl(),
111 '$defloc' => $a->user['default-location'],
112 '$visitor' => 'block',
113 '$emailcc' => t('CC: email addresses'),
114 '$jotnets' => $jotnets,
115 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
116 '$lockstate' => $lockstate,
117 '$acl' => populate_acl((($group) ? $group_acl : $a->user), $celeb),
118 '$bang' => (($group) ? '!' : ''),
119 '$profile_uid' => local_user()
123 // The special div is needed for liveUpdate to kick in for this page.
124 // We only launch liveUpdate if you are on the front page, you aren't
125 // filtering by group and also you aren't writing a comment (the last
126 // criteria is discovered in javascript).
128 $o .= '<div id="live-network"></div>' . "\r\n";
129 $o .= "<script> var profile_uid = " . $_SESSION['uid']
130 . "; var netargs = '" . substr($a->cmd,8)
131 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
135 // We aren't going to try and figure out at the item, group, and page level
136 // which items you've seen and which you haven't. You're looking at some
137 // subset of items, so just mark everything seen.
139 $r = q("UPDATE `item` SET `unseen` = 0
140 WHERE `unseen` = 1 AND `uid` = %d",
141 intval($_SESSION['uid'])
144 // We don't have to deal with ACL's on this page. You're looking at everything
145 // that belongs to you, hence you can see all of it. We will filter by group if
148 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
151 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
153 intval($_SESSION['uid'])
158 notice( t('No such group') . EOL );
159 goaway($a->get_baseurl() . '/network');
160 return; // NOTREACHED
163 $contacts = expand_groups(array($group));
164 if((is_array($contacts)) && count($contacts)) {
165 $contact_str = implode(',',$contacts);
168 $contact_str = ' 0 ';
169 notice( t('Group is empty'));
172 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
173 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
176 if((! $group) && (! $update))
177 $o .= get_birthdays();
180 $r = q("SELECT COUNT(*) AS `total`
181 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
182 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
183 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
185 intval($_SESSION['uid'])
189 $a->set_pager_total($r[0]['total']);
190 $a->set_pager_itemspage(40);
196 // "New Item View" - show all items unthreaded in reverse created date order
198 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
199 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
200 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
201 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
202 FROM `item`, `contact`
203 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
204 AND `contact`.`id` = `item`.`contact-id`
205 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
207 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
208 intval($_SESSION['uid']),
209 intval($a->pager['start']),
210 intval($a->pager['itemspage'])
215 // Normal conversation view
216 // First fetch a known number of parent items
218 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
219 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
220 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
221 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
222 AND `item`.`parent` = `item`.`id`
224 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
225 intval(local_user()),
226 intval($a->pager['start']),
227 intval($a->pager['itemspage'])
231 // Then fetch all the children of the parents that are on this page
233 $parents_arr = array();
238 $parents_arr[] = $rr['item_id'];
239 $parents_str = implode(', ', $parents_arr);
241 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
242 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
243 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
244 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
245 FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
246 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
247 AND `contact`.`id` = `item`.`contact-id`
248 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
249 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
251 ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
252 intval(local_user()),
258 // find all the authors involved in remote conversations
259 // We will use a local profile photo if they are one of our contacts
260 // otherwise we have to get the photo from the item owner's site
262 $author_contacts = extract_item_authors($r,local_user());
264 $cmnt_tpl = load_view_file('view/comment_item.tpl');
265 $like_tpl = load_view_file('view/like.tpl');
266 $noshare_tpl = load_view_file('view/like_noshare.tpl');
267 $tpl = load_view_file('view/wall_item.tpl');
268 $wallwall = load_view_file('view/wallwall_item.tpl');
277 // "New Item View" - just loop through the items and format them minimally for display
279 $tpl = load_view_file('view/search_item.tpl');
280 $droptpl = load_view_file('view/wall_fake_drop.tpl');
282 foreach($r as $item) {
290 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
291 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
292 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
294 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
296 if(strlen($item['author-link'])) {
297 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
298 $profile_link = $redirect_url;
299 $sparkle = ' sparkle';
301 elseif(isset($author_contacts[$item['author-link']])) {
302 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
303 $sparkle = ' sparkle';
307 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
308 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
311 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
313 $location = '<span class="smalltext">' . $coord . '</span>';
316 $drop = replace_macros($droptpl,array('$id' => $item['id']));
317 $lock = '<div class="wall-item-lock"></div>';
319 $o .= replace_macros($tpl,array(
320 '$id' => $item['item_id'],
321 '$linktitle' => t('View $name\'s profile'),
322 '$profile_url' => $profile_link,
323 '$name' => $profile_name,
324 '$sparkle' => $sparkle,
326 '$thumb' => $profile_avatar,
327 '$title' => $item['title'],
328 '$body' => smilies(bbcode($item['body'])),
329 '$ago' => relative_date($item['created']),
330 '$location' => $location,
332 '$owner_url' => $owner_url,
333 '$owner_photo' => $owner_photo,
334 '$owner_name' => $owner_name,
336 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
349 // Figure out how many comments each parent has
350 // (Comments all have gravity of 6)
351 // Store the result in the $comments array
355 if(intval($rr['gravity']) == 6) {
356 if(! x($comments,$rr['parent']))
357 $comments[$rr['parent']] = 1;
359 $comments[$rr['parent']] += 1;
363 // map all the like/dislike activities for each parent item
364 // Store these in the $alike and $dlike arrays
366 foreach($r as $item) {
367 like_puller($a,$item,$alike,'like');
368 like_puller($a,$item,$dlike,'dislike');
371 $comments_collapsed = false;
375 foreach($r as $item) {
381 $owner_url = $owner_photo = $owner_name = '';
384 // We've already parsed out like/dislike for special treatment. We can ignore them now
386 if(((activity_match($item['verb'],ACTIVITY_LIKE))
387 || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
388 && ($item['id'] != $item['parent']))
391 // Take care of author collapsing and comment collapsing
392 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
393 // If there are more than two comments, squash all but the last 2.
395 if($item['id'] == $item['parent']) {
396 if($blowhard == $item['cid'] && (! $item['self'])) {
398 if($blowhard_count == 3) {
399 $o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent'] . '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\');" >' . t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-' . $item['parent'] . '" style="display: none;" >';
403 $blowhard = $item['cid'];
404 if($blowhard_count >= 3)
410 $comments_collapsed = false;
416 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
417 if(! $comments_collapsed) {
418 $o .= '<div class="ccollapse-wrapper fakelink" id="ccollapse-wrapper-' . $item['parent'] . '" onclick="openClose(' . '\'ccollapse-' . $item['parent'] . '\');" >' . sprintf( t('See all %d comments'), $comments[$item['parent']]) . '</div>';
419 $o .= '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
420 $comments_collapsed = true;
423 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
429 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
431 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
432 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
433 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
434 : '<div class="wall-item-lock"></div>');
437 // Top-level wall post not written by the wall owner (wall-to-wall)
438 // First figure out who owns it.
442 if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
444 if($item['type'] === 'wall') {
445 // I do. Put me on the left of the wall-to-wall notice.
446 $owner_url = $a->contact['url'];
447 $owner_photo = $a->contact['thumb'];
448 $owner_name = $a->contact['name'];
449 $template = $wallwall;
452 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
454 $owner_url = $item['owner-link'];
455 $owner_photo = $item['owner-avatar'];
456 $owner_name = $item['owner-name'];
457 $template = $wallwall;
459 // If it is our contact, use a friendly redirect link
460 if((link_compare($item['owner-link'],$item['url']))
461 && ($item['network'] === 'dfrn')) {
462 $owner_url = $redirect_url;
463 $osparkle = ' sparkle';
469 $return_url = $_SESSION['return_url'];
471 $return_url = $_SESSION['return_url'] = $a->cmd;
474 if($item['id'] == $item['parent']) {
475 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
476 '$id' => $item['id'],
477 '$likethis' => t("I like this \x28toggle\x29"),
478 '$nolike' => t("I don't like this \x28toggle\x29"),
479 '$share' => t('Share'),
480 '$wait' => t('Please wait')
484 if($item['last-child']) {
485 $comment = replace_macros($cmnt_tpl,array(
486 '$return_path' => '',
487 '$jsreload' => '', // $_SESSION['return_url'],
488 '$type' => 'net-comment',
489 '$id' => $item['item_id'],
490 '$parent' => $item['parent'],
491 '$profile_uid' => $_SESSION['uid'],
492 '$mylink' => $a->contact['url'],
493 '$mytitle' => t('This is you'),
494 '$myphoto' => $a->contact['thumb'],
500 if(($item['id'] == $item['parent']) && (intval($item['wall']) == 1))
501 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
502 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
504 $photo = $item['photo'];
505 $thumb = $item['thumb'];
507 // Post was remotely authored.
509 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
511 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
512 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
514 if(strlen($item['author-link'])) {
515 $profile_link = $item['author-link'];
516 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
517 $profile_link = $redirect_url;
518 $sparkle = ' sparkle';
520 elseif(isset($author_contacts[$item['author-link']])) {
521 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
522 $sparkle = ' sparkle';
526 $profile_link = $item['url'];
528 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
529 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
531 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
532 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
535 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
537 $location = '<span class="smalltext">' . $coord . '</span>';
540 $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
542 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
548 $tmp_item = replace_macros($template,array(
549 '$id' => $item['item_id'],
550 '$linktitle' => t('View $name\'s profile'),
551 '$olinktitle' => t('View $owner_name\'s profile'),
553 '$wall' => t('Wall-to-Wall'),
554 '$vwall' => t('via Wall-To-Wall:'),
555 '$profile_url' => $profile_link,
556 '$name' => $profile_name,
557 '$thumb' => $profile_avatar,
558 '$osparkle' => $osparkle,
559 '$sparkle' => $sparkle,
560 '$title' => $item['title'],
561 '$body' => smilies(bbcode($item['body'])),
562 '$ago' => relative_date($item['created']),
564 '$location' => $location,
565 '$indent' => $indent,
566 '$owner_url' => $owner_url,
567 '$owner_photo' => $owner_photo,
568 '$owner_name' => $owner_name,
569 '$plink' => get_plink($item),
570 '$edpost' => $edpost,
572 '$vote' => $likebuttons,
574 '$dislike' => $dislike,
575 '$comment' => $comment
578 $arr = array('item' => $item, 'output' => $tmp_item);
579 call_hooks('display_item', $arr);
581 $o .= $arr['output'];
588 // if author collapsing is in force but didn't get closed, close it off now.
590 if($blowhard_count >= 3)
595 $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>';