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 = false) {
15 require_once("include/bbcode.php");
17 $contact_id = $a->cid;
22 // pull out the group here because the updater might have different args
24 $group = intval($a->argv[1]);
25 $group_acl = array('allow_gid' => '<' . $group . '>');
27 $_SESSION['return_url'] = $a->cmd;
29 $tpl = file_get_contents('view/jot-header.tpl');
31 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
33 require_once('view/acl_selectors.php');
35 $tpl = file_get_contents("view/jot.tpl");
37 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'])))))
40 $lockstate = 'unlock';
42 $o .= replace_macros($tpl,array(
43 '$return_path' => $a->cmd,
44 '$baseurl' => $a->get_baseurl(),
45 '$defloc' => $a->user['default-location'],
46 '$visitor' => 'block',
47 '$lockstate' => $lockstate,
48 '$acl' => populate_acl(($group) ? $group_acl : $a->user),
49 '$bang' => (($group) ? '!' : ''),
50 '$profile_uid' => $_SESSION['uid']
54 // The special div is needed for liveUpdate to kick in for this page.
55 // We only launch liveUpdate if you are on the front page, you aren't
56 // filtering by group and also you aren't writing a comment (the last
57 // criteria is discovered in javascript).
59 if($a->pager['start'] == 0 && $a->argc == 1)
60 $o .= '<div id="live-network"></div>' . "\r\n";
63 // We aren't going to try and figure out at the item, group, and page level
64 // which items you've seen and which you haven't. You're looking at some
65 // subset of items, so just mark everything seen.
67 $r = q("UPDATE `item` SET `unseen` = 0
68 WHERE `unseen` = 1 AND `uid` = %d",
69 intval($_SESSION['uid'])
72 // We don't have to deal with ACL's on this page. You're looking at everything
73 // that belongs to you, hence you can see all of it. We will filter by group if
76 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
79 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
81 intval($_SESSION['uid'])
84 notice( t('No such group') . EOL );
85 goaway($a->get_baseurl() . '/network');
89 $contacts = expand_groups(array($group));
90 $contact_str = implode(',',$contacts);
91 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
92 $o = '<h4>' . t('Group: ') . $r[0]['name'] . '</h4>' . $o;
96 $r = q("SELECT COUNT(*) AS `total`
97 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
98 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
99 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
101 intval($_SESSION['uid'])
105 $a->set_pager_total($r[0]['total']);
107 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
108 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
109 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
110 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
111 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
112 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
113 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
115 ORDER BY `parent` DESC, `gravity` ASC, `created` ASC LIMIT %d ,%d ",
116 intval($_SESSION['uid']),
117 intval($a->pager['start']),
118 intval($a->pager['itemspage'])
122 $cmnt_tpl = file_get_contents('view/comment_item.tpl');
123 $like_tpl = file_get_contents('view/like.tpl');
124 $tpl = file_get_contents('view/wall_item.tpl');
125 $wallwall = file_get_contents('view/wallwall_item.tpl');
131 foreach($r as $item) {
133 if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) {
135 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self']))
136 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
137 if(! is_array($alike[$item['parent'] . '-l']))
138 $alike[$item['parent'] . '-l'] = array();
139 $alike[$item['parent']] ++;
140 $alike[$item['parent'] . '-l'][] = '<a href="'. $url . '">' . $item['name'] . '</a>';
142 if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) {
144 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self']))
145 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
146 if(! is_array($dlike[$item['parent'] . '-l']))
147 $dlike[$item['parent'] . '-l'] = array();
148 $dlike[$item['parent']] ++;
149 $dlike[$item['parent'] . '-l'][] = '<a href="'. $url . '">' . $item['name'] . '</a>';
153 foreach($r as $item) {
159 $profile_url = $item['url'];
160 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
162 if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent']))
165 // Top-level wall post not written by the wall owner (wall-to-wall)
166 // First figure out who owns it.
168 if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
170 if($item['type'] == 'wall') {
171 // I do. Put me on the left of the wall-to-wall notice.
172 $owner_url = $a->contact['url'];
173 $owner_photo = $a->contact['thumb'];
174 $owner_name = $a->contact['name'];
175 $template = $wallwall;
178 if($item['type'] == 'remote' && ($item['owner-link'] != $item['author-link'])) {
180 $owner_url = $item['owner-link'];
181 $owner_photo = $item['owner-avatar'];
182 $owner_name = $item['owner-name'];
183 $template = $wallwall;
185 // If it is our contact, use a friendly redirect link
186 if(($item['owner-link'] == $item['url']) && ($item['rel'] == REL_VIP || $item['rel'] == REL_BUD))
187 $owner_url = $redirect_url;
193 $return_url = $_SESSION['return_url'];
195 $return_url = $_SESSION['return_url'] = $a->cmd;
198 if($item['id'] == $item['parent']) {
199 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
202 if($item['last-child']) {
203 $comment = replace_macros($cmnt_tpl,array(
204 '$return_path' => $_SESSION['return_url'],
205 '$type' => 'net-comment',
206 '$id' => $item['item_id'],
207 '$parent' => $item['parent'],
208 '$profile_uid' => $_SESSION['uid'],
209 '$mylink' => $a->contact['url'],
210 '$mytitle' => t('Me'),
211 '$myphoto' => $a->contact['thumb'],
217 $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
221 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'] ))
222 $profile_url = $redirect_url;
224 $photo = $item['photo'];
225 $thumb = $item['thumb'];
227 // Post was remotely authored.
229 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
230 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $thumb);
232 $profile_link = $profile_url;
234 // Can we use our special contact URL for this author?
236 if(strlen($item['author-link'])) {
237 if($item['author-link'] == $item['url'])
238 $profile_link = $redirect_url;
240 $profile_link = $item['author-link'];
244 $like = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
245 $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
250 $o .= replace_macros($template,array(
251 '$id' => $item['item_id'],
252 '$profile_url' => $profile_link,
253 '$name' => $profile_name,
254 '$thumb' => $profile_avatar,
255 '$title' => $item['title'],
256 '$body' => bbcode($item['body']),
257 '$ago' => relative_date($item['created']),
258 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
259 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
260 '$owner_url' => $owner_url,
261 '$owner_photo' => $owner_photo,
262 '$owner_name' => $owner_name,
264 '$vote' => $likebuttons,
266 '$dislike' => $dislike,
267 '$comment' => $comment