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 require_once('include/contact_widgets.php');
15 if(! x($a->page,'aside'))
16 $a->page['aside'] = '';
18 $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
21 $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
26 q("insert into `search` ( `uid`,`term` ) values ( %d, '%s') ",
32 if(x($_GET,'remove')) {
33 q("delete from `search` where `uid` = %d and `term` = '%s' limit 1",
41 // search terms header
42 if(x($_GET,'search')) {
43 $a->page['content'] .= '<h2>' . t('Search Results For:') . ' ' . $search . '</h2>';
46 $a->page['aside'] .= group_side('network','network',true,$group_id);
47 $a->page['aside'] .= networks_widget($a->get_baseurl(true) . '/network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
48 $a->page['aside'] .= saved_searches($search);
49 $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : ''));
53 function saved_searches($search) {
57 $srchurl = '/network?f='
58 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
59 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
60 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
61 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
62 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
63 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
64 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
65 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '');
70 $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
80 'term' => $rr['term'],
81 'encodedterm' => urlencode($rr['term']),
82 'delete' => t('Remove term'),
83 'selected' => ($search==$rr['term']),
89 $tpl = get_markup_template("saved_searches_aside.tpl");
90 $o = replace_macros($tpl, array(
91 '$title' => t('Saved Searches'),
93 '$searchbox' => search($search,'netsearch-box',$srchurl,true),
102 function network_content(&$a, $update = 0) {
104 require_once('include/conversation.php');
107 $_SESSION['return_url'] = $a->query_string;
111 $arr = array('query' => $a->query_string);
113 call_hooks('network_content_init', $arr);
118 // TODO: fix this logic, reduce duplication
119 //$a->page['content'] .= '<div class="tabs-wrapper">';
121 $starred_active = '';
123 $bookmarked_active = '';
129 if(($a->argc > 1 && $a->argv[1] === 'new')
130 || ($a->argc > 2 && $a->argv[2] === 'new')) {
131 $new_active = 'active';
134 if(x($_GET,'search')) {
135 $search_active = 'active';
138 if(x($_GET,'star')) {
139 $starred_active = 'active';
142 if(x($_GET,'bmark')) {
143 $bookmarked_active = 'active';
146 if(x($_GET,'conv')) {
147 $conv_active = 'active';
150 if(x($_GET,'spam')) {
151 $spam_active = 'active';
155 if (($new_active == '')
156 && ($starred_active == '')
157 && ($bookmarked_active == '')
158 && ($conv_active == '')
159 && ($search_active == '')
160 && ($spam_active == '')) {
161 $all_active = 'active';
165 $postord_active = '';
167 if($all_active && x($_GET,'order') && $_GET['order'] !== 'comment') {
169 $postord_active = 'active';
175 'label' => t('Commented Order'),
176 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?f=&cid=' . $_GET['cid'] : ''),
178 'title'=> t('Sort by Comment Date'),
181 'label' => t('Posted Order'),
182 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''),
183 'sel'=>$postord_active,
184 'title' => t('Sort by Post Date'),
188 'label' => t('Personal'),
189 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1',
190 'sel' => $conv_active,
191 'title' => t('Posts that mention or involve you'),
195 'url' => $a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . '/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
196 'sel' => $new_active,
197 'title' => t('Activity Stream - by date'),
200 'label' => t('Starred'),
201 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1',
202 'sel'=>$starred_active,
203 'title' => t('Favourite Posts'),
206 'label' => t('Shared Links'),
207 'url'=>$a->get_baseurl(true) . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&bmark=1',
208 'sel'=>$bookmarked_active,
209 'title'=> t('Interesting Links'),
212 // 'label' => t('Spam'),
213 // 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1'
214 // 'sel'=> $spam_active,
215 // 'title' => t('Posts flagged as SPAM'),
221 $arr = array('tabs' => $tabs);
222 call_hooks('network_tabs', $arr);
224 $o .= replace_macros(get_markup_template('common_tabs.tpl'), array('$tabs'=> $arr['tabs']));
226 // --- end item filter tabs
232 $contact_id = $a->cid;
237 require_once('include/acl_selectors.php');
239 $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0);
240 $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0);
241 $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
242 $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
243 $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
244 $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
245 $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0);
246 $nets = ((x($_GET,'nets')) ? $_GET['nets'] : '');
247 $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0);
248 $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99);
249 $file = ((x($_GET,'file')) ? $_GET['file'] : '');
251 if(($a->argc > 2) && $a->argv[2] === 'new')
255 if($a->argv[1] === 'new')
258 $group = intval($a->argv[1]);
259 $def_acl = array('allow_gid' => '<' . $group . '>');
263 if(x($_GET,'search') || x($_GET,'file'))
266 $def_acl = array('allow_cid' => '<' . intval($cid) . '>');
269 $r = q("select id from contact where uid = %d and network = '%s' and self = 0",
270 intval(local_user()),
277 $str .= '<' . $rr['id'] . '>';
279 $def_acl = array('allow_cid' => $str);
284 if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
285 notice( sprintf( tt('Warning: This group contains %s member from an insecure network.',
286 'Warning: This group contains %s members from an insecure network.',
288 notice( t('Private messages to this group are at risk of public disclosure.') . EOL);
292 nav_set_selected('network');
294 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
298 'allow_location' => $a->user['allow_location'],
299 'default_location' => $a->user['default-location'],
300 'nickname' => $a->user['nickname'],
301 'lockstate' => ((($group) || ($cid) || ($nets) || (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'),
302 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), $celeb),
303 'bang' => (($group || $cid || $nets) ? '!' : ''),
304 'visitor' => 'block',
305 'profile_uid' => local_user()
308 $o .= status_editor($a,$x);
313 // We don't have to deal with ACL's on this page. You're looking at everything
314 // that belongs to you, hence you can see all of it. We will filter by group if
318 $sql_options = (($star) ? " and starred = 1 " : '');
319 $sql_options .= (($bmark) ? " and bookmark = 1 " : '');
321 $sql_nets = (($nets) ? sprintf(" and `contact`.`network` = '%s' ", dbesc($nets)) : '');
323 $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) ";
326 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
328 intval($_SESSION['uid'])
333 notice( t('No such group') . EOL );
334 goaway($a->get_baseurl(true) . '/network');
338 $contacts = expand_groups(array($group));
339 if((is_array($contacts)) && count($contacts)) {
340 $contact_str = implode(',',$contacts);
343 $contact_str = ' 0 ';
344 info( t('Group is empty'));
347 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` like '" . protect_sprintf('%<' . intval($group) . '>%') . "' ) and deleted = 0 ) ";
348 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
352 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
353 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
357 $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) ";
358 $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
359 if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
360 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
365 notice( t('Invalid contact.') . EOL);
366 goaway($a->get_baseurl(true) . '/network');
371 if((! $group) && (! $cid) && (! $update)) {
372 $o .= get_birthdays();
377 // The special div is needed for liveUpdate to kick in for this page.
378 // We only launch liveUpdate if you aren't filtering in some incompatible
379 // way and also you aren't writing a comment (discovered in javascript).
381 $o .= '<div id="live-network"></div>' . "\r\n";
382 $o .= "<script> var profile_uid = " . $_SESSION['uid']
383 . "; var netargs = '" . substr($a->cmd,8)
385 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
386 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
387 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
388 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
389 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
390 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
391 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
392 . ((x($_GET,'spam')) ? '&spam=' . $_GET['spam'] : '')
393 . ((x($_GET,'nets')) ? '&nets=' . $_GET['nets'] : '')
394 . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
395 . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
396 . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '')
398 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
401 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
403 if(x($_GET,'search')) {
404 $search = escape_tags($_GET['search']);
405 if (get_config('system','use_fulltext_engine')) {
406 if(strpos($search,'#') === 0)
407 $sql_extra .= sprintf(" AND (MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ",
408 dbesc(protect_sprintf($search))
411 $sql_extra .= sprintf(" AND (MATCH(`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode)) ",
412 dbesc(protect_sprintf($search)),
413 dbesc(protect_sprintf($search))
416 $sql_extra .= sprintf(" AND ( `item`.`body` like '%s' OR `item`.`tag` like '%s' ) ",
417 dbesc(protect_sprintf('%' . $search . '%')),
418 dbesc(protect_sprintf('%]' . $search . '[%'))
423 $sql_extra .= file_tag_file_query('item',unxmlify($file));
427 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
428 $myurl = substr($myurl,strpos($myurl,'://')+3);
429 $myurl = str_replace('www.','',$myurl);
430 $diasp_url = str_replace('/profile/','/u/',$myurl);
431 if (get_config('system','use_fulltext_engine'))
432 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where (MATCH(`author-link`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(`tag`) AGAINST ('".'"%s"'."' in boolean mode) or MATCH(tag) AGAINST ('".'"%s"'."' in boolean mode))) ",
433 dbesc(protect_sprintf($myurl)),
434 dbesc(protect_sprintf($myurl)),
435 dbesc(protect_sprintf($diasp_url))
438 $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` like '%s' or `tag` like '%s' or tag like '%s' )) ",
439 dbesc(protect_sprintf('%' . $myurl)),
440 dbesc(protect_sprintf('%' . $myurl . '\\]%')),
441 dbesc(protect_sprintf('%' . $diasp_url . '\\]%'))
448 // only setup pagination on initial page view
453 $r = q("SELECT COUNT(*) AS `total`
454 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
455 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
456 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
458 $sql_extra $sql_nets ",
459 intval($_SESSION['uid'])
463 $a->set_pager_total($r[0]['total']);
464 $itemspage_network = get_pconfig(local_user(),'system','itemspage_network');
465 $a->set_pager_itemspage(((intval($itemspage_network)) ? $itemspage_network : 40));
467 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
470 $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
473 // "New Item View" - show all items unthreaded in reverse created date order
475 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
476 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
477 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
478 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
479 FROM `item`, `contact`
480 WHERE `item`.`uid` = %d AND `item`.`visible` = 1
481 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
483 AND `contact`.`id` = `item`.`contact-id`
484 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
486 ORDER BY `item`.`received` DESC $pager_sql ",
487 intval($_SESSION['uid'])
493 // Normal conversation view
496 if($order === 'post')
497 $ordering = "`created`";
499 $ordering = "`commented`";
501 // Fetch a page full of parent items for this page
504 $r = q("SELECT `parent` AS `item_id`, `contact`.`uid` AS `contact_uid`
505 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
506 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
507 and `item`.`moderated` = 0 and `item`.`unseen` = 1
508 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
509 $sql_extra $sql_nets ",
514 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
515 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
516 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
517 AND `item`.`moderated` = 0 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
518 AND `item`.`parent` = `item`.`id`
520 ORDER BY `item`.$ordering DESC $pager_sql ",
525 // Then fetch all the children of the parents that are on this page
527 $parents_arr = array();
532 if(! in_array($rr['item_id'],$parents_arr))
533 $parents_arr[] = $rr['item_id'];
534 $parents_str = implode(', ', $parents_arr);
536 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
537 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
538 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
539 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
540 FROM `item`, `contact`
541 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
542 AND `item`.`moderated` = 0 AND `contact`.`id` = `item`.`contact-id`
543 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
544 AND `item`.`parent` IN ( %s )
546 intval(local_user()),
550 $items = conv_sort($items,$ordering);
558 // We aren't going to try and figure out at the item, group, and page
559 // level which items you've seen and which you haven't. If you're looking
560 // at the top level network page just mark everything seen.
562 if((! $group) && (! $cid) && (! $star)) {
563 $r = q("UPDATE `item` SET `unseen` = 0
564 WHERE `unseen` = 1 AND `uid` = %d",
569 // Set this so that the conversation function can find out contact info for our wall-wall items
570 $a->page_contact = $a->contact;
572 $mode = (($nouveau) ? 'network-new' : 'network');
574 $o .= conversation($a,$items,$mode,$update);