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 $sql_extra = $sql_options;
269 $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
271 intval($_SESSION['uid'])
276 notice( t('No such group') . EOL );
277 goaway($a->get_baseurl() . '/network');
281 $contacts = expand_groups(array($group));
282 if((is_array($contacts)) && count($contacts)) {
283 $contact_str = implode(',',$contacts);
286 $contact_str = ' 0 ';
287 info( t('Group is empty'));
290 $sql_extra = " AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` REGEXP '<" . intval($group) . ">' ) $sql_options ";
291 $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o;
295 $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d
296 AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
300 $sql_extra = " AND `contact-id` = " . intval($cid) . " $sql_options ";
301 $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o;
302 if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) {
303 notice( t('Private messages to this person are at risk of public disclosure.') . EOL);
308 notice( t('Invalid contact.') . EOL);
309 goaway($a->get_baseurl() . '/network');
314 if((! $group) && (! $cid) && (! $update)) {
315 $o .= get_birthdays();
320 // The special div is needed for liveUpdate to kick in for this page.
321 // We only launch liveUpdate if you aren't filtering in some incompatible
322 // way and also you aren't writing a comment (discovered in javascript).
324 $o .= '<div id="live-network"></div>' . "\r\n";
325 $o .= "<script> var profile_uid = " . $_SESSION['uid']
326 . "; var netargs = '" . substr($a->cmd,8)
328 . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '')
329 . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '')
330 . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '')
331 . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : '')
332 . ((x($_GET,'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
333 . ((x($_GET,'liked')) ? '&liked=' . $_GET['liked'] : '')
334 . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '')
335 . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
338 $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
340 if(x($_GET,'search')) {
341 $search = escape_tags($_GET['search']);
342 $sql_extra .= sprintf(" AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' ) ",
343 dbesc(preg_quote($search)),
344 dbesc('\\]' . preg_quote($search) . '\\[')
349 $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
350 $myurl = substr($myurl,strpos($myurl,'://')+3);
351 $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
352 $diasp_url = str_replace('/profile/','/u/',$myurl);
353 $sql_extra .= sprintf(" AND ( `author-link` regexp '%s' or `tag` regexp '%s' or tag regexp '%s' ) ",
355 dbesc($myurl . '\\]'),
356 dbesc($diasp_url . '\\]')
362 // only setup pagination on initial page view
367 $r = q("SELECT COUNT(*) AS `total`
368 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
369 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
370 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
373 intval($_SESSION['uid'])
377 $a->set_pager_total($r[0]['total']);
378 $a->set_pager_itemspage(40);
380 $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
383 $simple_update = (($update) ? " and `item`.`unseen` = 1 " : '');
386 // "New Item View" - show all items unthreaded in reverse created date order
388 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
389 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
390 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
391 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
392 FROM `item`, `contact`
393 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
395 AND `contact`.`id` = `item`.`contact-id`
396 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
398 ORDER BY `item`.`received` DESC $pager_sql ",
399 intval($_SESSION['uid'])
405 // Normal conversation view
408 if($order === 'post')
409 $ordering = "`created`";
411 $ordering = "`commented`";
413 // Fetch a page full of parent items for this page
416 $r = q("SELECT distinct(`parent`) AS `item_id`, `contact`.`uid` AS `contact_uid`
417 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
418 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
419 and `item`.`unseen` = 1
420 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
426 $r = q("SELECT `item`.`id` AS `item_id`, `contact`.`uid` AS `contact_uid`
427 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
428 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
429 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
430 AND `item`.`parent` = `item`.`id`
432 ORDER BY `item`.$ordering DESC $pager_sql ",
437 // Then fetch all the children of the parents that are on this page
439 $parents_arr = array();
444 $parents_arr[] = $rr['item_id'];
445 $parents_str = implode(', ', $parents_arr);
447 $items = q("SELECT `item`.*, `item`.`id` AS `item_id`,
448 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`, `contact`.`writable`,
449 `contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
450 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
451 FROM `item`, `contact`
452 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
453 AND `contact`.`id` = `item`.`contact-id`
454 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
455 AND `item`.`parent` IN ( %s )
457 intval(local_user()),
461 $items = conv_sort($items,$ordering);
467 // We aren't going to try and figure out at the item, group, and page
468 // level which items you've seen and which you haven't. If you're looking
469 // at the top level network page just mark everything seen.
471 if((! $group) && (! $cid) && (! $star)) {
472 $r = q("UPDATE `item` SET `unseen` = 0
473 WHERE `unseen` = 1 AND `uid` = %d",
478 // Set this so that the conversation function can find out contact info for our wall-wall items
479 $a->page_contact = $a->contact;
481 $mode = (($nouveau) ? 'network-new' : 'network');
483 $o .= conversation($a,$items,$mode,$update);