2012-08-17 04:41:07 +00:00
< ? php
require_once ( 'include/Contact.php' );
require_once ( 'include/socgraph.php' );
require_once ( 'include/contact_selectors.php' );
2012-10-31 04:37:58 +00:00
require_once ( 'include/group.php' );
require_once ( 'include/contact_widgets.php' );
2013-01-04 00:18:52 +00:00
require_once ( 'include/zot.php' );
2013-12-09 04:08:50 +00:00
require_once ( 'include/widgets.php' );
2012-08-17 04:41:07 +00:00
2012-11-03 09:00:48 +00:00
function connections_init ( & $a ) {
2012-10-31 04:37:58 +00:00
2015-01-29 04:56:04 +00:00
if ( ! local_channel ())
2012-08-17 04:41:07 +00:00
return ;
2016-03-31 23:06:03 +00:00
$channel = App :: get_channel ();
2013-07-08 00:22:40 +00:00
if ( $channel )
head_set_icon ( $channel [ 'xchan_photo_s' ]);
2012-11-10 10:54:29 +00:00
}
2012-08-17 04:41:07 +00:00
2012-11-03 09:00:48 +00:00
function connections_content ( & $a ) {
2012-08-17 04:41:07 +00:00
$sort_type = 0 ;
$o = '' ;
2015-01-29 04:56:04 +00:00
if ( ! local_channel ()) {
2012-08-17 04:41:07 +00:00
notice ( t ( 'Permission denied.' ) . EOL );
2013-11-03 06:56:29 +00:00
return login ();
2012-08-17 04:41:07 +00:00
}
2014-03-04 22:35:42 +00:00
$blocked = false ;
$hidden = false ;
$ignored = false ;
$archived = false ;
$unblocked = false ;
$pending = false ;
$unconnected = false ;
$all = false ;
2012-08-17 04:41:07 +00:00
2015-01-07 22:35:03 +00:00
if ( ! $_REQUEST [ 'aj' ])
2016-03-31 23:06:03 +00:00
$_SESSION [ 'return_url' ] = App :: $query_string ;
2012-08-17 04:41:07 +00:00
2015-06-15 04:08:00 +00:00
$search_flags = '' ;
2013-01-28 01:05:32 +00:00
$head = '' ;
2012-10-31 04:37:58 +00:00
if ( argc () == 2 ) {
switch ( argv ( 1 )) {
case 'blocked' :
2015-06-15 04:08:00 +00:00
$search_flags = " and abook_blocked = 1 " ;
2013-01-28 01:05:32 +00:00
$head = t ( 'Blocked' );
2012-10-31 04:37:58 +00:00
$blocked = true ;
break ;
case 'ignored' :
2015-06-15 04:08:00 +00:00
$search_flags = " and abook_ignored = 1 " ;
2013-01-28 01:05:32 +00:00
$head = t ( 'Ignored' );
2012-10-31 04:37:58 +00:00
$ignored = true ;
break ;
case 'hidden' :
2015-06-15 04:08:00 +00:00
$search_flags = " and abook_hidden = 1 " ;
2013-01-28 01:05:32 +00:00
$head = t ( 'Hidden' );
2012-10-31 04:37:58 +00:00
$hidden = true ;
break ;
case 'archived' :
2015-06-15 04:08:00 +00:00
$search_flags = " and abook_archived = 1 " ;
2013-01-28 01:05:32 +00:00
$head = t ( 'Archived' );
2012-10-31 04:37:58 +00:00
$archived = true ;
break ;
2013-01-28 01:05:32 +00:00
case 'pending' :
2015-06-15 04:08:00 +00:00
$search_flags = " and abook_pending = 1 " ;
2013-01-28 01:05:32 +00:00
$head = t ( 'New' );
$pending = true ;
2013-08-02 03:10:03 +00:00
nav_set_selected ( 'intros' );
2013-01-28 01:05:32 +00:00
break ;
2014-04-04 23:56:49 +00:00
case 'ifpending' :
2015-06-15 04:19:13 +00:00
$r = q ( " SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 " ,
2015-06-15 04:08:00 +00:00
intval ( local_channel ())
2014-04-04 23:56:49 +00:00
);
if ( $r && $r [ 0 ][ 'total' ]) {
2015-06-15 04:08:00 +00:00
$search_flags = " and abook_pending = 1 " ;
2014-04-04 23:56:49 +00:00
$head = t ( 'New' );
$pending = true ;
nav_set_selected ( 'intros' );
2016-03-31 23:06:03 +00:00
App :: $argv [ 1 ] = 'pending' ;
2014-04-04 23:56:49 +00:00
}
else {
$head = t ( 'All' );
2015-06-15 04:08:00 +00:00
$search_flags = '' ;
2014-04-04 23:56:49 +00:00
$all = true ;
2016-03-31 23:06:03 +00:00
App :: $argc = 1 ;
unset ( App :: $argv [ 1 ]);
2014-04-04 23:56:49 +00:00
}
2014-06-14 13:49:57 +00:00
nav_set_selected ( 'intros' );
2014-04-04 23:56:49 +00:00
break ;
2014-07-18 03:54:30 +00:00
// case 'unconnected':
2015-06-15 04:08:00 +00:00
// $search_flags = " and abook_unconnected = 1 ";
2014-07-18 03:54:30 +00:00
// $head = t('Unconnected');
// $unconnected = true;
// break;
2013-01-28 01:05:32 +00:00
2012-10-31 04:37:58 +00:00
case 'all' :
2013-01-28 01:05:32 +00:00
$head = t ( 'All' );
2012-10-31 04:37:58 +00:00
default :
2015-06-15 04:08:00 +00:00
$search_flags = '' ;
2012-10-31 04:37:58 +00:00
$all = true ;
break ;
2012-11-30 02:15:13 +00:00
2012-10-31 04:37:58 +00:00
}
2012-11-30 02:15:13 +00:00
2015-06-15 04:08:00 +00:00
$sql_extra = $search_flags ;
2014-03-01 00:00:29 +00:00
if ( argv ( 1 ) === 'pending' )
2015-06-15 04:08:00 +00:00
$sql_extra .= " and abook_ignored = 0 " ;
2012-11-30 02:15:13 +00:00
}
else {
2015-06-15 04:08:00 +00:00
$sql_extra = " and abook_blocked = 0 " ;
2012-11-30 02:15:13 +00:00
$unblocked = true ;
2012-08-17 04:41:07 +00:00
}
2012-10-31 04:37:58 +00:00
$search = (( x ( $_REQUEST , 'search' )) ? notags ( trim ( $_REQUEST [ 'search' ])) : '' );
2012-08-17 04:41:07 +00:00
$tabs = array (
2016-01-14 12:50:47 +00:00
/*
2012-08-17 04:41:07 +00:00
array (
'label' => t ( 'Suggestions' ),
2014-03-04 22:35:42 +00:00
'url' => z_root () . '/suggest' ,
2012-08-17 04:41:07 +00:00
'sel' => '' ,
2012-11-03 09:00:48 +00:00
'title' => t ( 'Suggest new connections' ),
2012-08-17 04:41:07 +00:00
),
2016-01-14 12:50:47 +00:00
*/
'pending' => array (
2013-01-28 01:05:32 +00:00
'label' => t ( 'New Connections' ),
2014-03-04 22:35:42 +00:00
'url' => z_root () . '/connections/pending' ,
2013-01-28 01:05:32 +00:00
'sel' => ( $pending ) ? 'active' : '' ,
'title' => t ( 'Show pending (new) connections' ),
),
2016-01-14 12:50:47 +00:00
'all' => array (
2012-11-03 09:00:48 +00:00
'label' => t ( 'All Connections' ),
2014-03-04 22:35:42 +00:00
'url' => z_root () . '/connections/all' ,
2012-08-17 04:41:07 +00:00
'sel' => ( $all ) ? 'active' : '' ,
2012-11-03 09:00:48 +00:00
'title' => t ( 'Show all connections' ),
2012-08-17 04:41:07 +00:00
),
2016-01-14 12:50:47 +00:00
/*
2012-08-17 04:41:07 +00:00
array (
'label' => t ( 'Unblocked' ),
2014-03-04 22:35:42 +00:00
'url' => z_root () . '/connections' ,
2012-11-30 02:15:13 +00:00
'sel' => (( $unblocked ) && ( ! $search ) && ( ! $nets )) ? 'active' : '' ,
2012-11-03 09:00:48 +00:00
'title' => t ( 'Only show unblocked connections' ),
2012-08-17 04:41:07 +00:00
),
2016-01-14 12:50:47 +00:00
*/
2012-08-17 04:41:07 +00:00
2016-01-14 12:50:47 +00:00
'blocked' => array (
2012-08-17 04:41:07 +00:00
'label' => t ( 'Blocked' ),
2014-03-04 22:35:42 +00:00
'url' => z_root () . '/connections/blocked' ,
2012-08-17 04:41:07 +00:00
'sel' => ( $blocked ) ? 'active' : '' ,
2012-11-03 09:00:48 +00:00
'title' => t ( 'Only show blocked connections' ),
2012-08-17 04:41:07 +00:00
),
2016-01-14 12:50:47 +00:00
'ignored' => array (
2012-08-17 04:41:07 +00:00
'label' => t ( 'Ignored' ),
2014-03-04 22:35:42 +00:00
'url' => z_root () . '/connections/ignored' ,
2012-08-17 04:41:07 +00:00
'sel' => ( $ignored ) ? 'active' : '' ,
2012-11-03 09:00:48 +00:00
'title' => t ( 'Only show ignored connections' ),
2012-08-17 04:41:07 +00:00
),
2016-01-14 12:50:47 +00:00
'archived' => array (
2012-08-17 04:41:07 +00:00
'label' => t ( 'Archived' ),
2014-03-04 22:35:42 +00:00
'url' => z_root () . '/connections/archived' ,
2012-08-17 04:41:07 +00:00
'sel' => ( $archived ) ? 'active' : '' ,
2012-11-03 09:00:48 +00:00
'title' => t ( 'Only show archived connections' ),
2012-08-17 04:41:07 +00:00
),
2016-01-14 12:50:47 +00:00
'hidden' => array (
2012-08-17 04:41:07 +00:00
'label' => t ( 'Hidden' ),
2014-03-04 22:35:42 +00:00
'url' => z_root () . '/connections/hidden' ,
2012-08-17 04:41:07 +00:00
'sel' => ( $hidden ) ? 'active' : '' ,
2012-11-03 09:00:48 +00:00
'title' => t ( 'Only show hidden connections' ),
2012-08-17 04:41:07 +00:00
),
2014-07-18 03:54:30 +00:00
// array(
// 'label' => t('Unconnected'),
// 'url' => z_root() . '/connections/unconnected',
// 'sel' => ($unconnected) ? 'active' : '',
// 'title' => t('Only show one-way connections'),
// ),
2014-03-04 22:35:42 +00:00
2012-08-17 04:41:07 +00:00
);
2016-01-14 12:50:47 +00:00
//$tab_tpl = get_markup_template('common_tabs.tpl');
//$t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
2012-08-17 04:41:07 +00:00
$searching = false ;
if ( $search ) {
$search_hdr = $search ;
$search_txt = dbesc ( protect_sprintf ( preg_quote ( $search )));
$searching = true ;
}
2012-11-13 10:57:15 +00:00
$sql_extra .= (( $searching ) ? protect_sprintf ( " AND xchan_name like '% $search_txt %' " ) : " " );
2012-08-17 04:41:07 +00:00
2014-08-18 00:48:41 +00:00
if ( $_REQUEST [ 'gid' ]) {
2015-01-29 04:56:04 +00:00
$sql_extra .= " and xchan_hash in ( select xchan from group_member where gid = " . intval ( $_REQUEST [ 'gid' ]) . " and uid = " . intval ( local_channel ()) . " ) " ;
2014-08-18 00:48:41 +00:00
}
2012-11-10 10:54:29 +00:00
2012-10-31 23:55:19 +00:00
$r = q ( " SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash
2015-06-15 04:08:00 +00:00
where abook_channel = % d and abook_self = 0 and xchan_deleted = 0 and xchan_orphan = 0 $sql_extra $sql_extra2 " ,
intval ( local_channel ())
2012-10-31 23:55:19 +00:00
);
2014-04-05 00:43:44 +00:00
if ( $r ) {
2016-03-31 23:06:03 +00:00
App :: set_pager_total ( $r [ 0 ][ 'total' ]);
2012-08-17 04:41:07 +00:00
$total = $r [ 0 ][ 'total' ];
}
2012-12-08 22:18:02 +00:00
2012-11-02 05:23:13 +00:00
$r = q ( " SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash
2015-06-15 04:08:00 +00:00
WHERE abook_channel = % d and abook_self = 0 and xchan_deleted = 0 and xchan_orphan = 0 $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT % d OFFSET % d " ,
2015-01-29 04:56:04 +00:00
intval ( local_channel ()),
2016-03-31 23:06:03 +00:00
intval ( App :: $pager [ 'itemspage' ]),
intval ( App :: $pager [ 'start' ])
2012-08-17 04:41:07 +00:00
);
2012-12-08 22:18:02 +00:00
2012-08-17 04:41:07 +00:00
$contacts = array ();
if ( count ( $r )) {
foreach ( $r as $rr ) {
2013-08-04 12:12:11 +00:00
if ( $rr [ 'xchan_url' ]) {
2016-01-14 22:23:12 +00:00
$status_str = '' ;
$status = array (
2016-01-15 09:42:44 +00:00
(( intval ( $rr [ 'abook_pending' ])) ? t ( 'Pending approval' ) : '' ),
2016-01-14 22:23:12 +00:00
(( intval ( $rr [ 'abook_archived' ])) ? t ( 'Archived' ) : '' ),
(( intval ( $rr [ 'abook_hidden' ])) ? t ( 'Hidden' ) : '' ),
(( intval ( $rr [ 'abook_ignored' ])) ? t ( 'Ignored' ) : '' ),
(( intval ( $rr [ 'abook_blocked' ])) ? t ( 'Blocked' ) : '' )
);
foreach ( $status as $str ) {
if ( ! $str )
continue ;
$status_str .= $str ;
$status_str .= ', ' ;
}
$status_str = rtrim ( $status_str , ', ' );
2013-08-04 12:12:11 +00:00
$contacts [] = array (
'img_hover' => sprintf ( t ( '%1$s [%2$s]' ), $rr [ 'xchan_name' ], $rr [ 'xchan_url' ]),
2014-09-11 06:08:24 +00:00
'edit_hover' => t ( 'Edit connection' ),
2016-01-14 12:50:47 +00:00
'delete_hover' => t ( 'Delete connection' ),
2013-08-04 12:12:11 +00:00
'id' => $rr [ 'abook_id' ],
'thumb' => $rr [ 'xchan_photo_m' ],
'name' => $rr [ 'xchan_name' ],
2015-06-15 04:08:00 +00:00
'classes' => ( intval ( $rr [ 'abook_archived' ]) ? 'archived' : '' ),
2013-12-18 09:00:08 +00:00
'link' => z_root () . '/connedit/' . $rr [ 'abook_id' ],
2016-01-15 11:08:04 +00:00
'deletelink' => z_root () . '/connedit/' . intval ( $rr [ 'abook_id' ]) . '/drop' ,
2016-01-14 12:50:47 +00:00
'delete' => t ( 'Delete' ),
2014-04-07 04:40:23 +00:00
'url' => chanlink_url ( $rr [ 'xchan_url' ]),
2016-01-15 09:42:44 +00:00
'webbie_label' => t ( 'Channel address' ),
'webbie' => $rr [ 'xchan_addr' ],
'network_label' => t ( 'Network' ),
2016-01-14 22:23:12 +00:00
'network' => network_to_name ( $rr [ 'xchan_network' ]),
'public_forum' => (( intval ( $rr [ 'xchan_pubforum' ])) ? true : false ),
'status_label' => t ( 'Status' ),
'status' => $status_str ,
'connected_label' => t ( 'Connected' ),
2016-01-15 10:28:05 +00:00
'connected' => datetime_convert ( 'UTC' , date_default_timezone_get (), $rr [ 'abook_created' ], 'c' ),
'approve_hover' => t ( 'Approve connection' ),
2016-01-15 11:08:04 +00:00
'approve' => (( $rr [ 'abook_pending' ]) ? t ( 'Approve' ) : false ),
2016-01-27 00:57:36 +00:00
'ignore_hover' => t ( 'Ignore connection' ),
'ignore' => (( ! $rr [ 'abook_ignored' ]) ? t ( 'Ignore' ) : false ),
2016-01-15 11:08:04 +00:00
'recent_label' => t ( 'Recent activity' ),
'recentlink' => z_root () . '/network/?f=&cid=' . intval ( $rr [ 'abook_id' ])
2013-08-04 12:12:11 +00:00
);
}
2012-08-17 04:41:07 +00:00
}
}
2014-09-11 06:08:24 +00:00
if ( $_REQUEST [ 'aj' ]) {
if ( $contacts ) {
$o = replace_macros ( get_markup_template ( 'contactsajax.tpl' ), array (
'$contacts' => $contacts ,
'$edit' => t ( 'Edit' ),
));
}
else {
$o = '<div id="content-complete"></div>' ;
}
echo $o ;
killme ();
}
else {
$o .= " <script> var page_query = ' " . $_GET [ 'q' ] . " '; var extra_args = ' " . extra_query_args () . " ' ; </script> " ;
$o .= replace_macros ( get_markup_template ( 'connections.tpl' ), array (
2016-01-14 12:50:47 +00:00
'$header' => t ( 'Connections' ) . (( $head ) ? ': ' . $head : '' ),
'$tabs' => $tabs ,
2014-09-11 06:08:24 +00:00
'$total' => $total ,
'$search' => $search_hdr ,
2016-01-14 12:50:47 +00:00
'$label' => t ( 'Search' ),
2014-09-11 06:08:24 +00:00
'$desc' => t ( 'Search your connections' ),
2016-01-14 12:50:47 +00:00
'$finding' => (( $searching ) ? t ( 'Connections search' ) . " : ' " . $search . " ' " : " " ),
2014-09-11 06:08:24 +00:00
'$submit' => t ( 'Find' ),
'$edit' => t ( 'Edit' ),
2016-03-31 23:06:03 +00:00
'$cmd' => App :: $cmd ,
2014-09-11 06:08:24 +00:00
'$contacts' => $contacts ,
'$paginate' => paginate ( $a ),
));
}
if ( ! $contacts )
$o .= '<div id="content-complete"></div>' ;
2012-08-17 04:41:07 +00:00
return $o ;
}