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?')
77 $tpl = load_view_file("view/jot.tpl");
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'])))))
82 $lockstate = 'unlock';
84 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
88 call_hooks('jot_tool', $jotplugins);
89 call_hooks('jot_networks', $jotnets);
91 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
93 $o .= replace_macros($tpl,array(
94 '$return_path' => $a->cmd,
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'),
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']
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).
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";
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.
137 $r = q("UPDATE `item` SET `unseen` = 0
138 WHERE `unseen` = 1 AND `uid` = %d",
139 intval($_SESSION['uid'])
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
146 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
149 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
151 intval($_SESSION['uid'])
156 notice( t('No such group') . EOL );
157 goaway($a->get_baseurl() . '/network');
158 return; // NOTREACHED
161 $contacts = expand_groups(array($group));
162 if((is_array($contacts)) && count($contacts)) {
163 $contact_str = implode(',',$contacts);
166 $contact_str = ' 0 ';
167 notice( t('Group is empty'));
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;
174 if((! $group) && (! $update))
175 $o .= get_birthdays();
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
183 intval($_SESSION['uid'])
187 $a->set_pager_total($r[0]['total']);
188 $a->set_pager_itemspage(40);
193 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
194 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
195 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
196 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
197 FROM `item`, `contact`
198 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
199 AND `contact`.`id` = `item`.`contact-id`
200 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
202 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
203 intval($_SESSION['uid']),
204 intval($a->pager['start']),
205 intval($a->pager['itemspage'])
209 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
210 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
211 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
212 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
213 AND `item`.`parent` = `item`.`id`
215 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
216 intval(local_user()),
217 intval($a->pager['start']),
218 intval($a->pager['itemspage'])
221 $parents_arr = array();
226 $parents_arr[] = $rr['item_id'];
227 $parents_str = implode(', ', $parents_arr);
229 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
230 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
231 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
232 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
233 FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
234 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
235 AND `contact`.`id` = `item`.`contact-id`
236 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
237 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
239 ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
240 intval(local_user()),
246 $author_contacts = extract_item_authors($r,local_user());
248 $cmnt_tpl = load_view_file('view/comment_item.tpl');
249 $like_tpl = load_view_file('view/like.tpl');
250 $noshare_tpl = load_view_file('view/like_noshare.tpl');
251 $tpl = load_view_file('view/wall_item.tpl');
252 $wallwall = load_view_file('view/wallwall_item.tpl');
261 $tpl = load_view_file('view/search_item.tpl');
262 $droptpl = load_view_file('view/wall_fake_drop.tpl');
264 foreach($r as $item) {
272 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
273 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
274 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
276 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
278 if(strlen($item['author-link'])) {
279 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
280 $profile_link = $redirect_url;
281 $sparkle = ' sparkle';
283 elseif(isset($author_contacts[$item['author-link']])) {
284 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
285 $sparkle = ' sparkle';
289 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
290 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
293 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
295 $location = '<span class="smalltext">' . $coord . '</span>';
298 $drop = replace_macros($droptpl,array('$id' => $item['id']));
299 $lock = '<div class="wall-item-lock"></div>';
301 $o .= replace_macros($tpl,array(
302 '$id' => $item['item_id'],
303 '$linktitle' => t('View $name\'s profile'),
304 '$profile_url' => $profile_link,
305 '$name' => $profile_name,
306 '$sparkle' => $sparkle,
308 '$thumb' => $profile_avatar,
309 '$title' => $item['title'],
310 '$body' => smilies(bbcode($item['body'])),
311 '$ago' => relative_date($item['created']),
312 '$location' => $location,
314 '$owner_url' => $owner_url,
315 '$owner_photo' => $owner_photo,
316 '$owner_name' => $owner_name,
318 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
331 if(intval($rr['gravity']) == 6) {
332 if(! x($comments,$rr['parent']))
333 $comments[$rr['parent']] = 1;
335 $comments[$rr['parent']] += 1;
339 foreach($r as $item) {
340 like_puller($a,$item,$alike,'like');
341 like_puller($a,$item,$dlike,'dislike');
344 $comments_collapsed = false;
348 foreach($r as $item) {
354 $owner_url = $owner_photo = $owner_name = '';
356 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
359 if($item['id'] == $item['parent']) {
360 if($blowhard == $item['cid'] && (! $item['self'])) {
362 if($blowhard_count == 3) {
363 $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;" >';
367 $blowhard = $item['cid'];
368 if($blowhard_count > 3)
374 $comments_collapsed = false;
380 if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) {
381 if(! $comments_collapsed) {
382 $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>';
383 $o .= '<div class="ccollapse" id="ccollapse-' . $item['parent'] . '" style="display: none;" >';
384 $comments_collapsed = true;
387 if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) {
391 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
393 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
394 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
395 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
396 : '<div class="wall-item-lock"></div>');
399 // Top-level wall post not written by the wall owner (wall-to-wall)
400 // First figure out who owns it.
404 if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
406 if($item['type'] === 'wall') {
407 // I do. Put me on the left of the wall-to-wall notice.
408 $owner_url = $a->contact['url'];
409 $owner_photo = $a->contact['thumb'];
410 $owner_name = $a->contact['name'];
411 $template = $wallwall;
414 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
416 $owner_url = $item['owner-link'];
417 $owner_photo = $item['owner-avatar'];
418 $owner_name = $item['owner-name'];
419 $template = $wallwall;
421 // If it is our contact, use a friendly redirect link
422 if((link_compare($item['owner-link'],$item['url']))
423 && ($item['network'] === 'dfrn')) {
424 $owner_url = $redirect_url;
425 $osparkle = ' sparkle';
431 $return_url = $_SESSION['return_url'];
433 $return_url = $_SESSION['return_url'] = $a->cmd;
436 if($item['id'] == $item['parent']) {
437 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
438 '$id' => $item['id'],
439 '$likethis' => t("I like this \x28toggle\x29"),
440 '$nolike' => t("I don't like this \x28toggle\x29"),
441 '$share' => t('Share'),
442 '$wait' => t('Please wait')
446 if($item['last-child']) {
447 $comment = replace_macros($cmnt_tpl,array(
448 '$return_path' => '',
449 '$jsreload' => '', // $_SESSION['return_url'],
450 '$type' => 'net-comment',
451 '$id' => $item['item_id'],
452 '$parent' => $item['parent'],
453 '$profile_uid' => $_SESSION['uid'],
454 '$mylink' => $a->contact['url'],
455 '$mytitle' => t('This is you'),
456 '$myphoto' => $a->contact['thumb'],
462 if(($item['id'] == $item['parent']) && (intval($item['wall']) == 1))
463 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
464 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
466 $photo = $item['photo'];
467 $thumb = $item['thumb'];
469 // Post was remotely authored.
471 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
473 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
474 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
476 if(strlen($item['author-link'])) {
477 $profile_link = $item['author-link'];
478 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
479 $profile_link = $redirect_url;
480 $sparkle = ' sparkle';
482 elseif(isset($author_contacts[$item['author-link']])) {
483 $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
484 $sparkle = ' sparkle';
488 $profile_link = $item['url'];
490 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
491 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
493 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
494 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
497 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
499 $location = '<span class="smalltext">' . $coord . '</span>';
502 $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
504 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
510 $tmp_item = replace_macros($template,array(
511 '$id' => $item['item_id'],
512 '$linktitle' => t('View $name\'s profile'),
513 '$olinktitle' => t('View $owner_name\'s profile'),
515 '$wall' => t('Wall-to-Wall'),
516 '$vwall' => t('via Wall-To-Wall:'),
517 '$profile_url' => $profile_link,
518 '$name' => $profile_name,
519 '$thumb' => $profile_avatar,
520 '$osparkle' => $osparkle,
521 '$sparkle' => $sparkle,
522 '$title' => $item['title'],
523 '$body' => smilies(bbcode($item['body'])),
524 '$ago' => relative_date($item['created']),
526 '$location' => $location,
527 '$indent' => $indent,
528 '$owner_url' => $owner_url,
529 '$owner_photo' => $owner_photo,
530 '$owner_name' => $owner_name,
531 '$plink' => get_plink($item),
532 '$edpost' => $edpost,
534 '$vote' => $likebuttons,
536 '$dislike' => $dislike,
537 '$comment' => $comment
540 $arr = array('item' => $item, 'output' => $tmp_item);
541 call_hooks('display_item', $arr);
543 $o .= $arr['output'];
550 $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>';