4 function network_init(&$a) {
10 require_once('include/group.php');
11 if(! x($a->page,'aside'))
12 $a->page['aside'] = '';
14 $a->page['aside'] .= '<div id="network-new-link">';
16 if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new'))
17 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '">' . t('Normal View') . '</a>';
19 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . '">' . t('New Item View') . '</a>';
21 $a->page['aside'] .= '</div>';
23 $a->page['aside'] .= group_side('network','network');
27 function network_content(&$a, $update = 0) {
34 require_once("include/bbcode.php");
36 $contact_id = $a->cid;
41 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
45 if(($a->argc > 2) && $a->argv[2] === 'new')
48 // pull out the group here because the updater might have different args
50 if($a->argv[1] === 'new')
53 $group = intval($a->argv[1]);
54 $group_acl = array('allow_gid' => '<' . $group . '>');
58 $_SESSION['return_url'] = $a->cmd;
60 $geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
62 $tpl = load_view_file('view/jot-header.tpl');
64 $a->page['htmlhead'] .= replace_macros($tpl, array(
65 '$baseurl' => $a->get_baseurl(),
67 '$nickname' => $a->user['nickname']
70 require_once('include/acl_selectors.php');
72 $tpl = load_view_file("view/jot.tpl");
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'])))))
77 $lockstate = 'unlock';
79 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
81 $o .= replace_macros($tpl,array(
82 '$return_path' => $a->cmd,
83 '$baseurl' => $a->get_baseurl(),
84 '$defloc' => $a->user['default-location'],
85 '$visitor' => 'block',
86 '$lockstate' => $lockstate,
87 '$acl' => populate_acl((($group) ? $group_acl : $a->user), $celeb),
88 '$bang' => (($group) ? '!' : ''),
89 '$profile_uid' => $_SESSION['uid']
93 // The special div is needed for liveUpdate to kick in for this page.
94 // We only launch liveUpdate if you are on the front page, you aren't
95 // filtering by group and also you aren't writing a comment (the last
96 // criteria is discovered in javascript).
98 if($a->pager['start'] == 0 && $a->argc == 1) {
99 $o .= '<div id="live-network"></div>' . "\r\n";
100 $o .= "<script> var profile_uid = " . $_SESSION['uid'] . "; </script>\r\n";
105 // We aren't going to try and figure out at the item, group, and page level
106 // which items you've seen and which you haven't. You're looking at some
107 // subset of items, so just mark everything seen.
109 $r = q("UPDATE `item` SET `unseen` = 0
110 WHERE `unseen` = 1 AND `uid` = %d",
111 intval($_SESSION['uid'])
114 // We don't have to deal with ACL's on this page. You're looking at everything
115 // that belongs to you, hence you can see all of it. We will filter by group if
118 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
121 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
123 intval($_SESSION['uid'])
126 notice( t('No such group') . EOL );
127 goaway($a->get_baseurl() . '/network');
128 return; // NOTREACHED
131 $contacts = expand_groups(array($group));
132 if((is_array($contacts)) && count($contacts)) {
133 $contact_str = implode(',',$contacts);
136 $contact_str = ' 0 ';
137 notice( t('Group is empty'));
140 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
141 $o = '<h4>' . t('Group: ') . $r[0]['name'] . '</h4>' . $o;
144 if((! $group) && (! $update))
145 $o .= get_birthdays();
148 $r = q("SELECT COUNT(*) AS `total`
149 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
150 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
151 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
153 intval($_SESSION['uid'])
157 $a->set_pager_total($r[0]['total']);
160 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
161 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
162 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
163 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
164 FROM `item`, `contact`
165 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
166 AND `contact`.`id` = `item`.`contact-id`
167 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
169 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
170 intval($_SESSION['uid']),
171 intval($a->pager['start']),
172 intval($a->pager['itemspage'])
176 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
177 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
178 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
179 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
180 FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
181 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
182 AND `contact`.`id` = `item`.`contact-id`
183 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
184 AND `item`.`parent` = `parentitem`.`id`
186 ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC LIMIT %d ,%d ",
187 intval($_SESSION['uid']),
188 intval($a->pager['start']),
189 intval($a->pager['itemspage'])
194 $cmnt_tpl = load_view_file('view/comment_item.tpl');
195 $like_tpl = load_view_file('view/like.tpl');
196 $tpl = load_view_file('view/wall_item.tpl');
197 $wallwall = load_view_file('view/wallwall_item.tpl');
206 $tpl = load_view_file('view/search_item.tpl');
207 $droptpl = load_view_file('view/wall_fake_drop.tpl');
209 foreach($r as $item) {
217 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
218 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
219 $profile_link = ((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
222 $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
223 $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
226 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
228 $location = '<span class="smalltext">' . $coord . '</span>';
231 $drop = replace_macros($droptpl,array('$id' => $item['id']));
232 $lock = '<div class="wall-item-lock"></div>';
234 $o .= replace_macros($tpl,array(
235 '$id' => $item['item_id'],
236 '$profile_url' => $profile_link,
237 '$name' => $profile_name,
238 '$sparkle' => $sparkle,
240 '$thumb' => $profile_avatar,
241 '$title' => $item['title'],
242 '$body' => bbcode($item['body']),
243 '$ago' => relative_date($item['created']),
244 '$location' => $location,
246 '$owner_url' => $owner_url,
247 '$owner_photo' => $owner_photo,
248 '$owner_name' => $owner_name,
250 '$conv' => '<a href="' . $a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $item['id'] . '">' . t('View in context') . '</a>'
262 foreach($r as $item) {
263 like_puller($a,$item,$alike,'like');
264 like_puller($a,$item,$dlike,'dislike');
267 foreach($r as $item) {
272 $owner_url = $owner_photo = $owner_name = '';
274 $profile_url = $item['url'];
276 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
278 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
282 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
283 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
284 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
285 : '<div class="wall-item-lock"></div>');
288 // Top-level wall post not written by the wall owner (wall-to-wall)
289 // First figure out who owns it.
293 if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
295 if($item['type'] === 'wall') {
296 // I do. Put me on the left of the wall-to-wall notice.
297 $owner_url = $a->contact['url'];
298 $owner_photo = $a->contact['thumb'];
299 $owner_name = $a->contact['name'];
300 $template = $wallwall;
303 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
305 $owner_url = $item['owner-link'];
306 $owner_photo = $item['owner-avatar'];
307 $owner_name = $item['owner-name'];
308 $template = $wallwall;
310 // If it is our contact, use a friendly redirect link
311 if((link_compare($item['owner-link'],$item['url']))
312 && ($item['network'] === 'dfrn')) {
313 $owner_url = $redirect_url;
314 $osparkle = ' sparkle';
321 $return_url = $_SESSION['return_url'];
323 $return_url = $_SESSION['return_url'] = $a->cmd;
326 if($item['id'] == $item['parent']) {
327 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
330 if($item['last-child']) {
331 $comment = replace_macros($cmnt_tpl,array(
332 '$return_path' => $_SESSION['return_url'],
333 '$type' => 'net-comment',
334 '$id' => $item['item_id'],
335 '$parent' => $item['parent'],
336 '$profile_uid' => $_SESSION['uid'],
337 '$mylink' => $a->contact['url'],
338 '$mytitle' => t('This is you'),
339 '$myphoto' => $a->contact['thumb'],
344 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
348 if(($item['network'] === 'dfrn') && (! $item['self'] )) {
349 $profile_url = $redirect_url;
350 $sparkle = ' sparkle';
353 $photo = $item['photo'];
354 $thumb = $item['thumb'];
356 // Post was remotely authored.
358 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
360 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
361 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb);
364 $profile_link = $profile_url;
366 // Can we use our special contact URL for this author?
368 if(strlen($item['author-link'])) {
369 if((link_compare($item['author-link'],$item['url'])) && ($item['network'] === 'dfrn') && (! $item['self'])) {
370 $profile_link = $redirect_url;
371 $sparkle = ' sparkle';
374 $profile_link = $item['author-link'];
380 $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
381 $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
383 $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
384 $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
387 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
389 $location = '<span class="smalltext">' . $coord . '</span>';
392 $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
394 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
400 $tmp_item = replace_macros($template,array(
401 '$id' => $item['item_id'],
402 '$title' => t('View $name\'s profile'),
403 '$profile_url' => $profile_link,
404 '$name' => $profile_name,
405 '$thumb' => $profile_avatar,
406 '$osparkle' => $osparkle,
407 '$sparkle' => $sparkle,
408 '$title' => $item['title'],
409 '$body' => smilies(bbcode($item['body'])),
410 '$ago' => relative_date($item['created']),
412 '$location' => $location,
413 '$indent' => $indent,
414 '$owner_url' => $owner_url,
415 '$owner_photo' => $owner_photo,
416 '$owner_name' => $owner_name,
418 '$vote' => $likebuttons,
420 '$dislike' => $dislike,
421 '$comment' => $comment
424 $arr = array('item' => $item, 'output' => $tmp_item);
425 call_hooks('display_item', $arr);
427 $o .= $arr['output'];