4 function network_init(&$a) {
5 require_once('include/group.php');
6 $a->page['aside'] .= group_side('network','network');
10 function network_content(&$a, $update = 0) {
15 require_once("include/bbcode.php");
17 $contact_id = $a->cid;
22 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
24 // pull out the group here because the updater might have different args
26 $group = intval($a->argv[1]);
27 $group_acl = array('allow_gid' => '<' . $group . '>');
29 $_SESSION['return_url'] = $a->cmd;
31 $geotag = (($a->user['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
33 $tpl = load_view_file('view/jot-header.tpl');
35 $a->page['htmlhead'] .= replace_macros($tpl, array(
36 '$baseurl' => $a->get_baseurl(),
40 require_once('view/acl_selectors.php');
42 $tpl = load_view_file("view/jot.tpl");
44 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'])))))
47 $lockstate = 'unlock';
49 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
51 $o .= replace_macros($tpl,array(
52 '$return_path' => $a->cmd,
53 '$baseurl' => $a->get_baseurl(),
54 '$defloc' => $a->user['default-location'],
55 '$visitor' => 'block',
56 '$lockstate' => $lockstate,
57 '$acl' => populate_acl((($group) ? $group_acl : $a->user), $celeb),
58 '$bang' => (($group) ? '!' : ''),
59 '$profile_uid' => $_SESSION['uid']
63 // The special div is needed for liveUpdate to kick in for this page.
64 // We only launch liveUpdate if you are on the front page, you aren't
65 // filtering by group and also you aren't writing a comment (the last
66 // criteria is discovered in javascript).
68 if($a->pager['start'] == 0 && $a->argc == 1) {
69 $o .= '<div id="live-network"></div>' . "\r\n";
70 $o .= "<script> var profile_uid = " . $_SESSION['uid'] . "; </script>\r\n";
75 // We aren't going to try and figure out at the item, group, and page level
76 // which items you've seen and which you haven't. You're looking at some
77 // subset of items, so just mark everything seen.
79 $r = q("UPDATE `item` SET `unseen` = 0
80 WHERE `unseen` = 1 AND `uid` = %d",
81 intval($_SESSION['uid'])
84 // We don't have to deal with ACL's on this page. You're looking at everything
85 // that belongs to you, hence you can see all of it. We will filter by group if
88 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
91 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
93 intval($_SESSION['uid'])
96 notice( t('No such group') . EOL );
97 goaway($a->get_baseurl() . '/network');
101 $contacts = expand_groups(array($group));
102 $contact_str = implode(',',$contacts);
103 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
104 $o = '<h4>' . t('Group: ') . $r[0]['name'] . '</h4>' . $o;
108 $r = q("SELECT COUNT(*) AS `total`
109 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
110 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
111 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
113 intval($_SESSION['uid'])
117 $a->set_pager_total($r[0]['total']);
119 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
120 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
121 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
122 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
123 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
124 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
125 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
127 ORDER BY `parent` DESC, `gravity` ASC, `created` ASC LIMIT %d ,%d ",
128 intval($_SESSION['uid']),
129 intval($a->pager['start']),
130 intval($a->pager['itemspage'])
134 $cmnt_tpl = load_view_file('view/comment_item.tpl');
135 $like_tpl = load_view_file('view/like.tpl');
136 $tpl = load_view_file('view/wall_item.tpl');
137 $wallwall = load_view_file('view/wallwall_item.tpl');
143 foreach($r as $item) {
147 if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) {
149 if(($item['network'] === 'dfrn') && (! $item['self'])) {
150 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
151 $sparkle = ' class="sparkle"';
153 if(! is_array($alike[$item['parent'] . '-l']))
154 $alike[$item['parent'] . '-l'] = array();
155 $alike[$item['parent']] ++;
156 $alike[$item['parent'] . '-l'][] = '<a href="'. $url . '"' . $sparkle . '>' . $item['name'] . '</a>';
158 if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) {
160 if(($item['network'] === 'dfrn') && (! $item['self'])) {
161 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
162 $sparkle = ' class="sparkle"';
164 if(! is_array($dlike[$item['parent'] . '-l']))
165 $dlike[$item['parent'] . '-l'] = array();
166 $dlike[$item['parent']] ++;
167 $dlike[$item['parent'] . '-l'][] = '<a href="'. $url . '"' . $sparkle . '>' . $item['name'] . '</a>';
171 foreach($r as $item) {
176 $owner_url = $owner_photo = $owner_name = '';
177 $profile_url = $item['url'];
178 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
180 if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent']))
183 $lock = (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
184 || strlen($item['deny_cid']) || strlen($item['deny_gid']))
185 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
186 : '<div class="wall-item-lock"></div>');
188 // Top-level wall post not written by the wall owner (wall-to-wall)
189 // First figure out who owns it.
193 if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
195 if($item['type'] === 'wall') {
196 // I do. Put me on the left of the wall-to-wall notice.
197 $owner_url = $a->contact['url'];
198 $owner_photo = $a->contact['thumb'];
199 $owner_name = $a->contact['name'];
200 $template = $wallwall;
203 if(($item['type'] === 'remote') && (strlen($item['owner-link'])) && ($item['owner-link'] != $item['author-link'])) {
205 $owner_url = $item['owner-link'];
206 $owner_photo = $item['owner-avatar'];
207 $owner_name = $item['owner-name'];
208 $template = $wallwall;
210 // If it is our contact, use a friendly redirect link
211 if(($item['owner-link'] == $item['url'])
212 && ($item['network'] === 'dfrn')) {
213 $owner_url = $redirect_url;
214 $osparkle = ' sparkle';
221 $return_url = $_SESSION['return_url'];
223 $return_url = $_SESSION['return_url'] = $a->cmd;
226 if($item['id'] == $item['parent']) {
227 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
230 if($item['last-child']) {
231 $comment = replace_macros($cmnt_tpl,array(
232 '$return_path' => $_SESSION['return_url'],
233 '$type' => 'net-comment',
234 '$id' => $item['item_id'],
235 '$parent' => $item['parent'],
236 '$profile_uid' => $_SESSION['uid'],
237 '$mylink' => $a->contact['url'],
238 '$mytitle' => t('This is you'),
239 '$myphoto' => $a->contact['thumb'],
244 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
248 if(($item['network'] === 'dfrn') && (! $item['self'] )) {
249 $profile_url = $redirect_url;
250 $sparkle = ' sparkle';
253 $photo = $item['photo'];
254 $thumb = $item['thumb'];
256 // Post was remotely authored.
258 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
259 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $thumb);
261 $profile_link = $profile_url;
263 // Can we use our special contact URL for this author?
265 if(strlen($item['author-link'])) {
266 if($item['author-link'] == $item['url'] && ($item['network'] === 'dfrn') && (! $item['self'])) {
267 $profile_link = $redirect_url;
268 $sparkle = ' sparkle';
271 $profile_link = $item['author-link'];
277 $like = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
278 $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
280 $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
281 $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
284 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
286 $location = '<span class="smalltext">' . $coord . '</span>';
291 $o .= replace_macros($template,array(
292 '$id' => $item['item_id'],
293 '$profile_url' => $profile_link,
294 '$name' => $profile_name,
295 '$thumb' => $profile_avatar,
296 '$osparkle' => $osparkle,
297 '$sparkle' => $sparkle,
298 '$title' => $item['title'],
299 '$body' => bbcode($item['body']),
300 '$ago' => relative_date($item['created']),
302 '$location' => $location,
303 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
304 '$owner_url' => $owner_url,
305 '$owner_photo' => $owner_photo,
306 '$owner_name' => $owner_name,
308 '$vote' => $likebuttons,
310 '$dislike' => $dislike,
311 '$comment' => $comment