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']) : '');
19 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
24 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
30 if(x($_GET,'remove')) {
31 q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
39 // search terms header
40 if(x($_GET,'search')) {
41 $a->page['content'] .= '<h2>' . t('Search Results For:') . ' ' . $search . '</h2>';
44 $a->page['aside'] .= group_side('network','network',true,$group_id);
45 $a->page['aside'] .= saved_searches($search);
49 function saved_searches($search) {
52 . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '')
53 . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '')
54 . ((x($_GET,'bmark')) ? '?bmark=' . $_GET['bmark'] : '')
55 . ((x($_GET,'conv')) ? '?conv=' . $_GET['conv'] : '');
59 $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
69 'term' => $rr['term'],
70 'encodedterm' => urlencode($rr['term']),
71 'delete' => t('Remove term'),
72 'selected' => ($search==$rr['term']),
78 $tpl = get_markup_template("saved_searches_aside.tpl");
79 $o = replace_macros($tpl, array(
80 '$title' => t('Saved Searches'),
82 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
91 function network_content(&$a, $update = 0) {
93 require_once('include/conversation.php');
101 // TODO: fix this logic, reduce duplication
102 //$a->page['content'] .= '<div class="tabs-wrapper">';
104 $starred_active = '';
106 $bookmarked_active = '';
111 if(($a->argc > 1 && $a->argv[1] === 'new')
112 || ($a->argc > 2 && $a->argv[2] === 'new')) {
113 $new_active = 'active';
116 if(x($_GET,'search')) {
117 $search_active = 'active';
120 if(x($_GET,'star')) {
121 $starred_active = 'active';
125 $bookmarked_active = 'active';
129 $conv_active = 'active';
133 if (($new_active == '')
134 && ($starred_active == '')
135 && ($bookmarked_active == '')
136 && ($conv_active == '')
137 && ($search_active == '')) {
138 $all_active = 'active';
142 $postord_active = '';
144 if($all_active && x($_GET,'order') && $_GET['order'] !== 'comment') {
146 $postord_active = 'active';
154 'label' => t('Commented Order'),
155 'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : ''),
159 'label' => t('Posted Order'),
160 'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '?order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
161 'sel'=>$postord_active,
165 'label' => t('Personal'),
166 'url' => $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&conv=1',
167 'sel' => $conv_active,
171 'url' => $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : ''),
172 'sel' => $new_active,
175 'label' => t('Starred'),
176 'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&star=1',
177 'sel'=>$starred_active,
180 'label' => t('Bookmarks'),
181 'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&bmark=1',
182 'sel'=>$bookmarked_active,
185 $tpl = get_markup_template('common_tabs.tpl');
186 $o .= replace_macros($tpl, array('$tabs'=>$tabs));
187 // --- end item filter tabs
193 $contact_id = $a->cid;
198 require_once('include/acl_selectors.php');
200 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
201 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
202 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
203 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
204 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
205 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
208 if(($a->argc > 2) && $a->argv[2] === 'new')
212 if($a->argv[1] === 'new')
215 $group = intval($a->argv[1]);
216 $def_acl = array('allow_gid' => '<' . $group . '>');
220 if(x($_GET,'search'))
223 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
227 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
228 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
229 'Warning: This group contains %s members from an insecure network.',
231 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
235 nav_set_selected('network');
237 $_SESSION['return_url'] = $a->cmd;
239 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
243 'allow_location' => $a->user['allow_location'],
244 'default_location' => $a->user['default_location'],
245 'nickname' => $a->user['nickname'],
246 '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'),
247 'acl' => populate_acl((($group || $cid) ? $def_acl : $a->user), $celeb),
248 'bang' => (($group || $cid) ? '!' : ''),
249 'visitor' => 'block',
250 'profile_uid' => local_user()
253 $o .= status_editor($a,$x);
258 // We don't have to deal with ACL's on this page. You're looking at everything
259 // that belongs to you, hence you can see all of it. We will filter by group if
263 $sql_options = (($star) ? " and starred = 1 " : '');
264 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
266 // We'll need the following line if starred/bookmarks are allowed in comments in the future
267 // $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
269 // Otherwise, this is a bit faster:
270 $sql_extra = $sql_options;
273 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
275 intval($_SESSION['uid'])
280 notice( t('No such group') . EOL );
281 goaway($a->get_baseurl() . '/network');
285 $contacts = expand_groups(array($group));
286 if((is_array($contacts)) && count($contacts)) {
287 $contact_str = implode(',',$contacts);
290 $contact_str = ' 0 ';
291 info( t('Group is empty'));
294 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' )) ";
295 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
299 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
300 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
304 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " ) ";
305 $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
306 if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
307 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
312 notice( t('Invalid contact.') . EOL);
313 goaway($a->get_baseurl() . '/network');
318 if((! $group) && (! $cid) && (! $update)) {
319 $o .= get_birthdays();
324 // The special div is needed for liveUpdate to kick in for this page.
325 // We only launch liveUpdate if you aren't filtering in some incompatible
326 // way and also you aren't writing a comment (discovered in javascript).
328 $o .= '<div id="live-network"></div>' . "\r\n";
329 $o .= "<script> var profile_uid = " . $_SESSION['uid']
330 . "; var netargs = '" . substr($a->cmd,8)
332 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
333 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
334 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
335 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
336 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
337 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
338 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
339 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
342 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
344 if(x($_GET,'search')) {
345 $search = escape_tags($_GET['search']);
346 $sql_extra .= sprintf(" AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' ) ",
347 dbesc(preg_quote($search)),
348 dbesc('\\]' . preg_quote($search) . '\\[')
353 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
354 $myurl = substr($myurl,strpos($myurl,'://')+3);
355 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
356 $diasp_url = str_replace('/profile/','/u/',$myurl);
357 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` regexp '%s' or `tag` regexp '%s' or tag regexp '%s' )) ",
359 dbesc($myurl . '\\]'),
360 dbesc($diasp_url . '\\]')
367 // only setup pagination on initial page view
372 $r = q("SELECT COUNT(*) AS `total`
373 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
374 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
375 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
378 intval($_SESSION['uid'])
382 $a->set_pager_total($r[0]['total']);
383 $a->set_pager_itemspage(40);
385 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
388 $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
391 // "New Item View" - show all items unthreaded in reverse created date order
393 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
394 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
395 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
396 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
397 FROM `item`, `contact`
398 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
400 AND `contact`.`id` = `item`.`contact-id`
401 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
403 ORDER BY `item`.`received` DESC $pager_sql ",
404 intval($_SESSION['uid'])
410 // Normal conversation view
413 if($order === 'post')
414 $ordering = "`created`";
416 $ordering = "`commented`";
418 // Fetch a page full of parent items for this page
421 $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid`
422 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
423 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
424 and `item`.`unseen` = 1
425 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
431 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
432 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
433 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
434 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
435 AND `item`.`parent` = `item`.`id`
437 ORDER BY `item`.$ordering DESC $pager_sql ",
442 // Then fetch all the children of the parents that are on this page
444 $parents_arr = array();
449 if(! array_key_exists($rr['item_id'],$parents_arr))
450 $parents_arr[] = $rr['item_id'];
451 $parents_str = implode(', ', $parents_arr);
453 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
454 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
455 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
456 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
457 FROM `item`, `contact`
458 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
459 AND `contact`.`id` = `item`.`contact-id`
460 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
461 AND `item`.`parent` IN ( %s )
463 intval(local_user()),
467 $items = conv_sort($items,$ordering);
473 // We aren't going to try and figure out at the item, group, and page
474 // level which items you've seen and which you haven't. If you're looking
475 // at the top level network page just mark everything seen.
477 if((! $group) && (! $cid) && (! $star)) {
478 $r = q("UPDATE `item` SET `unseen` = 0
479 WHERE `unseen` = 1 AND `uid` = %d",
484 // Set this so that the conversation function can find out contact info for our wall-wall items
485 $a->page_contact = $a->contact;
487 $mode = (($nouveau) ? 'network-new' : 'network');
489 $o .= conversation($a,$items,$mode,$update);