4 function network_init(&$a) {
6 notice( t('Permission denied.') . EOL);
10 $group_id = (($a->argc > 1 && intval($a->argv[1])) ? intval($a->argv[1]) : 0);
12 require_once('include/group.php');
13 if(! x($a->page,'aside'))
14 $a->page['aside'] = '';
16 $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
17 $srchurl = '/network' . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '');
20 $a->page['aside'] .= search($search,'netsearch-box',$srchurl);
22 $a->page['aside'] .= '<div id="network-new-link">';
25 $a->page['aside'] .= '<div id="network-view-link">';
26 if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new') || x($_GET,'search'))
27 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') . '">' . t('View Conversations') . '</a></div>';
29 $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' . t('View New Items') . '</a></div>';
32 $a->page['aside'] .= '<div id="network-star-link">'
33 . '<a class="network-star" href="' . $a->get_baseurl() . '/' . $a->cmd
34 . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">'
35 . t('View Any Items') . '</a>'
36 . '<span class="network-star icon starred"></span>'
37 . '<span class="network-star icon unstarred"></span>'
38 . '<div class="clear"></div></div>';
40 $a->page['aside'] .= '<div id="network-star-link">'
41 . '<a class="network-star" href="' . $a->get_baseurl() . '/' . $a->cmd
42 . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&star=1" >'
43 . t('View Starred Items') . '</a>'
44 . '<span class="network-star icon starred"></span>'
45 . '<div class="clear"></div></div>';
49 $a->page['aside'] .= '</div>';
51 $a->page['aside'] .= group_side('network','network',true,$group_id);
55 function network_content(&$a, $update = 0) {
57 require_once('include/conversation.php');
64 $contact_id = $a->cid;
69 require_once('include/acl_selectors.php');
71 $cid = ((x($_GET['cid'])) ? intval($_GET['cid']) : 0);
72 $star = ((x($_GET['star'])) ? intval($_GET['star']) : 0);
74 if(($a->argc > 2) && $a->argv[2] === 'new')
78 if($a->argv[1] === 'new')
81 $group = intval($a->argv[1]);
82 $def_acl = array('allow_gid' => '<' . $group . '>');
89 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
93 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
94 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
95 'Warning: This group contains %s members from an insecure network.',
97 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
101 $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
103 $_SESSION['return_url'] = $a->cmd;
105 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
109 'allow_location' => $a->user['allow_location'],
110 'default_location' => $a->user['default_location'],
111 'nickname' => $a->user['nickname'],
112 'lockstate' => ((($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']))))) ? 'lock' : 'unlock'),
113 'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
114 'bang' => (($group || $cid) ? '!' : ''),
115 'visitor' => 'block',
116 'profile_uid' => local_user()
119 $o .= status_editor($a,$x);
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)
130 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
131 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
132 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
133 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
137 // We aren't going to try and figure out at the item, group, and page
138 // level which items you've seen and which you haven't. If you're looking
139 // at the top level network page just mark everything seen.
141 if((! $group) && (! $cid) && (! $star)) {
142 $r = q("UPDATE `item` SET `unseen` = 0
143 WHERE `unseen` = 1 AND `uid` = %d",
144 intval($_SESSION['uid'])
148 // We don't have to deal with ACL's on this page. You're looking at everything
149 // that belongs to you, hence you can see all of it. We will filter by group if
152 $star_sql = (($star) ? " AND `starred` = 1 " : '');
154 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql ) ";
157 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
159 intval($_SESSION['uid'])
164 notice( t('No such group') . EOL );
165 goaway($a->get_baseurl() . '/network');
169 $contacts = expand_groups(array($group));
170 if((is_array($contacts)) && count($contacts)) {
171 $contact_str = implode(',',$contacts);
174 $contact_str = ' 0 ';
175 info( t('Group is empty'));
179 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' )) ";
180 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
184 $r = q("SELECT `id`,`name`,`network`,`writable` FROM `contact` WHERE `id` = %d
185 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
189 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $star_sql AND `contact-id` IN ( " . intval($cid) . " )) ";
190 $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
191 if($r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
192 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
197 notice( t('Invalid contact.') . EOL);
198 goaway($a->get_baseurl() . '/network');
203 if((! $group) && (! $cid) && (! $update))
204 $o .= get_birthdays();
206 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
208 if(x($_GET,'search'))
209 $sql_extra .= " AND `item`.`body` REGEXP '" . dbesc(escape_tags($_GET['search'])) . "' ";
212 $r = q("SELECT COUNT(*) AS `total`
213 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
214 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
215 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
218 intval($_SESSION['uid'])
222 $a->set_pager_total($r[0]['total']);
223 $a->set_pager_itemspage(40);
229 // "New Item View" - show all items unthreaded in reverse created date order
231 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
232 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
233 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
234 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
235 FROM `item`, `contact`
236 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
237 AND `contact`.`id` = `item`.`contact-id`
238 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
240 ORDER BY `item`.`received` DESC LIMIT %d ,%d ",
241 intval($_SESSION['uid']),
242 intval($a->pager['start']),
243 intval($a->pager['itemspage'])
249 // Normal conversation view
250 // First fetch a known number of parent items
252 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
253 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
254 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
255 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
256 AND `item`.`parent` = `item`.`id`
258 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
259 intval(local_user()),
260 intval($a->pager['start']),
261 intval($a->pager['itemspage'])
265 // Then fetch all the children of the parents that are on this page
267 $parents_arr = array();
272 $parents_arr[] = $rr['item_id'];
273 $parents_str = implode(', ', $parents_arr);
275 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
276 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
277 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
278 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
279 FROM `item`, (SELECT `p`.`id`,`p`.`created` FROM `item` AS `p` WHERE `p`.`parent`=`p`.`id`) as `parentitem`, `contact`
280 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
281 AND `contact`.`id` = `item`.`contact-id`
282 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
283 AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
285 ORDER BY `parentitem`.`created` DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
286 intval(local_user()),
292 // Set this so that the conversation function can find out contact info for our wall-wall items
293 $a->page_contact = $a->contact;
295 $mode = (($nouveau) ? 'network-new' : 'network');
297 $o .= conversation($a,$r,$mode,$update);