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]);
26 $_SESSION['return_url'] = $a->cmd;
28 $tpl = file_get_contents('view/jot-header.tpl');
30 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
32 require_once('view/acl_selectors.php');
34 $tpl = file_get_contents("view/jot.tpl");
36 $o .= replace_macros($tpl,array(
37 '$return_path' => $a->cmd,
38 '$baseurl' => $a->get_baseurl(),
39 '$defloc' => $a->user['default-location'],
40 '$visitor' => 'block',
41 '$lockstate' => 'unlock',
42 '$acl' => populate_acl($a->user),
43 '$profile_uid' => $_SESSION['uid']
47 // The special div is needed for liveUpdate to kick in for this page.
48 // We only launch liveUpdate if you are on the front page, you aren't
49 // filtering by group and also you aren't writing a comment (the last
50 // criteria is discovered in javascript).
52 if($a->pager['start'] == 0 && $a->argc == 1)
53 $o .= '<div id="live-network"></div>' . "\r\n";
56 // We aren't going to try and figure out at the item, group, and page level
57 // which items you've seen and which you haven't. You're looking at some
58 // subset of items, so just mark everything seen.
60 $r = q("UPDATE `item` SET `unseen` = 0
61 WHERE `unseen` = 1 AND `uid` = %d",
62 intval($_SESSION['uid'])
65 // We don't have to deal with ACL's on this page. You're looking at everything
66 // that belongs to you, hence you can see all of it. We will filter by group if
69 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` ) ";
72 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
74 intval($_SESSION['uid'])
77 notice( t('No such group') . EOL );
78 goaway($a->get_baseurl() . '/network');
82 $contacts = expand_groups(array($group));
83 $contact_str = implode(',',$contacts);
84 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `contact-id` IN ( $contact_str )) ";
85 $o = '<h4>' . t('Group: ') . $r[0]['name'] . '</h4>' . $o;
89 $r = q("SELECT COUNT(*) AS `total`
90 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
91 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
92 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
94 intval($_SESSION['uid'])
98 $a->set_pager_total($r[0]['total']);
100 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
101 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
102 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
103 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
104 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
105 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
106 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
108 ORDER BY `parent` DESC, `gravity` ASC, `created` ASC LIMIT %d ,%d ",
109 intval($_SESSION['uid']),
110 intval($a->pager['start']),
111 intval($a->pager['itemspage'])
115 $cmnt_tpl = file_get_contents('view/comment_item.tpl');
116 $like_tpl = file_get_contents('view/like.tpl');
117 $tpl = file_get_contents('view/wall_item.tpl');
118 $wallwall = file_get_contents('view/wallwall_item.tpl');
124 foreach($r as $item) {
126 if(($item['verb'] == ACTIVITY_LIKE) && ($item['id'] != $item['parent'])) {
128 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self']))
129 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
130 if(! is_array($alike[$item['parent'] . '-l']))
131 $alike[$item['parent'] . '-l'] = array();
132 $alike[$item['parent']] ++;
133 $alike[$item['parent'] . '-l'][] = '<a href="'. $url . '">' . $item['name'] . '</a>';
135 if(($item['verb'] == ACTIVITY_DISLIKE) && ($item['id'] != $item['parent'])) {
137 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self']))
138 $url = $a->get_baseurl() . '/redir/' . $item['contact-id'];
139 if(! is_array($dlike[$item['parent'] . '-l']))
140 $dlike[$item['parent'] . '-l'] = array();
141 $dlike[$item['parent']] ++;
142 $dlike[$item['parent'] . '-l'][] = '<a href="'. $url . '">' . $item['name'] . '</a>';
146 foreach($r as $item) {
152 $profile_url = $item['url'];
153 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
155 if((($item['verb'] == ACTIVITY_LIKE) || ($item['verb'] == ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent']))
158 // Top-level wall post not written by the wall owner (wall-to-wall)
159 // First figure out who owns it.
161 if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
163 if($item['type'] == 'wall') {
164 // I do. Put me on the left of the wall-to-wall notice.
165 $owner_url = $a->contact['url'];
166 $owner_photo = $a->contact['thumb'];
167 $owner_name = $a->contact['name'];
168 $template = $wallwall;
171 if($item['type'] == 'remote' && ($item['owner-link'] != $item['author-link'])) {
173 $owner_url = $item['owner-link'];
174 $owner_photo = $item['owner-avatar'];
175 $owner_name = $item['owner-name'];
176 $template = $wallwall;
178 // If it is our contact, use a friendly redirect link
179 if(($item['owner-link'] == $item['url']) && ($item['rel'] == REL_VIP || $item['rel'] == REL_BUD))
180 $owner_url = $redirect_url;
186 $return_url = $_SESSION['return_url'];
188 $return_url = $_SESSION['return_url'] = $a->cmd;
191 if($item['id'] == $item['parent']) {
192 $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
195 if($item['last-child']) {
196 $comment = replace_macros($cmnt_tpl,array(
197 '$return_path' => $_SESSION['return_url'],
198 '$type' => 'net-comment',
199 '$id' => $item['item_id'],
200 '$parent' => $item['parent'],
201 '$profile_uid' => $_SESSION['uid'],
202 '$mylink' => $a->contact['url'],
203 '$mytitle' => t('Me'),
204 '$myphoto' => $a->contact['thumb'],
210 $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
214 if(($item['rel'] == REL_VIP || $item['rel'] == REL_BUD) && (! $item['self'] ))
215 $profile_url = $redirect_url;
217 $photo = $item['photo'];
218 $thumb = $item['thumb'];
220 // Post was remotely authored.
222 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
223 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $thumb);
225 $profile_link = $profile_url;
227 // Can we use our special contact URL for this author?
229 if(strlen($item['author-link'])) {
230 if($item['author-link'] == $item['url'])
231 $profile_link = $redirect_url;
233 $profile_link = $item['author-link'];
237 $like = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
238 $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
243 $o .= replace_macros($template,array(
244 '$id' => $item['item_id'],
245 '$profile_url' => $profile_link,
246 '$name' => $profile_name,
247 '$thumb' => $profile_avatar,
248 '$title' => $item['title'],
249 '$body' => bbcode($item['body']),
250 '$ago' => relative_date($item['created']),
251 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
252 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
253 '$owner_url' => $owner_url,
254 '$owner_photo' => $owner_photo,
255 '$owner_name' => $owner_name,
257 '$vote' => $likebuttons,
259 '$dislike' => $dislike,
260 '$comment' => $comment