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' );
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
2012-08-17 04:41:07 +00:00
if ( ! local_user ())
return ;
2012-10-31 04:37:58 +00:00
if (( argc () == 2 ) && intval ( argv ( 1 ))) {
$r = q ( " SELECT abook.*, xchan.*
FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = % d and abook_id = % d LIMIT 1 " ,
2012-08-17 04:41:07 +00:00
intval ( local_user ()),
2012-10-31 04:37:58 +00:00
intval ( argv ( 1 ))
2012-08-17 04:41:07 +00:00
);
2012-10-31 04:37:58 +00:00
if ( $r ) {
$a -> data [ 'abook' ] = $r [ 0 ];
2012-08-17 04:41:07 +00:00
}
2012-10-31 04:37:58 +00:00
}
2013-07-08 00:22:40 +00:00
$channel = $a -> get_channel ();
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-10 10:54:29 +00:00
function connections_aside ( & $a ) {
2012-08-17 04:41:07 +00:00
2012-12-08 22:18:02 +00:00
if ( x ( $a -> data , 'abook' )) {
2013-01-24 00:06:01 +00:00
$a -> set_widget ( 'vcard' , vcard_from_xchan ( $a -> data [ 'abook' ], $a -> get_observer ()));
2012-12-08 22:18:02 +00:00
}
else {
2012-11-10 10:54:29 +00:00
$a -> set_widget ( 'follow' , follow_widget ());
2012-12-08 22:18:02 +00:00
}
2012-08-17 04:41:07 +00:00
2013-02-02 19:04:38 +00:00
$a -> set_widget ( 'collections' , group_side ( 'connections' , 'group' , false , 0 ,(( array_key_exists ( 'abook' , $a -> data )) ? $a -> data [ 'abook' ][ 'abook_xchan' ] : '' )));
2012-11-15 05:27:05 +00:00
$a -> set_widget ( 'findpeople' , findpeople_widget ());
2012-08-17 04:41:07 +00:00
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_post ( & $a ) {
2012-08-17 04:41:07 +00:00
if ( ! local_user ())
return ;
2012-11-09 01:33:38 +00:00
$contact_id = intval ( argv ( 1 ));
2012-08-17 04:41:07 +00:00
if ( ! $contact_id )
return ;
2012-11-09 01:33:38 +00:00
$orig_record = q ( " SELECT * FROM abook WHERE abook_id = %d AND abook_channel = %d LIMIT 1 " ,
2012-08-17 04:41:07 +00:00
intval ( $contact_id ),
intval ( local_user ())
);
2012-11-09 01:33:38 +00:00
if ( ! $orig_record ) {
2012-08-17 04:41:07 +00:00
notice ( t ( 'Could not access contact record.' ) . EOL );
2013-02-02 19:04:38 +00:00
goaway ( $a -> get_baseurl ( true ) . '/connections' );
2012-08-17 04:41:07 +00:00
return ; // NOTREACHED
}
call_hooks ( 'contact_edit_post' , $_POST );
2013-07-03 08:50:39 +00:00
$profile_id = $_POST [ 'profile-assign' ];
2012-08-17 04:41:07 +00:00
if ( $profile_id ) {
2013-07-03 08:50:39 +00:00
$r = q ( " SELECT profile_guid FROM profile WHERE profile_guid = '%s' AND `uid` = %d LIMIT 1 " ,
dbesc ( $profile_id ),
2012-08-17 04:41:07 +00:00
intval ( local_user ())
);
if ( ! count ( $r )) {
notice ( t ( 'Could not locate selected profile.' ) . EOL );
return ;
}
}
$hidden = intval ( $_POST [ 'hidden' ]);
$priority = intval ( $_POST [ 'poll' ]);
if ( $priority > 5 || $priority < 0 )
$priority = 0 ;
$closeness = intval ( $_POST [ 'closeness' ]);
if ( $closeness < 0 )
$closeness = 99 ;
2012-11-09 01:33:38 +00:00
$abook_my_perms = 0 ;
2012-08-17 04:41:07 +00:00
2012-11-09 01:33:38 +00:00
foreach ( $_POST as $k => $v ) {
if ( strpos ( $k , 'perms_' ) === 0 ) {
$abook_my_perms += $v ;
}
}
2013-01-28 01:05:32 +00:00
$abook_flags = $orig_record [ 0 ][ 'abook_flags' ];
2013-08-28 04:06:11 +00:00
$new_friend = false ;
2013-01-28 01:05:32 +00:00
if (( $_REQUEST [ 'pending' ]) && ( $abook_flags & ABOOK_FLAG_PENDING )) {
$abook_flags = ( $abook_flags ^ ABOOK_FLAG_PENDING );
2013-08-28 04:06:11 +00:00
$new_friend = true ;
2013-01-28 01:05:32 +00:00
}
2013-07-03 08:50:39 +00:00
$r = q ( " UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_flags = %d
2012-11-09 01:33:38 +00:00
where abook_id = % d AND abook_channel = % d LIMIT 1 " ,
2013-07-03 08:50:39 +00:00
dbesc ( $profile_id ),
2012-11-09 01:33:38 +00:00
intval ( $abook_my_perms ),
2012-08-17 04:41:07 +00:00
intval ( $closeness ),
2013-01-28 01:05:32 +00:00
intval ( $abook_flags ),
2012-08-17 04:41:07 +00:00
intval ( $contact_id ),
intval ( local_user ())
);
if ( $r )
2012-11-09 01:33:38 +00:00
info ( t ( 'Connection updated.' ) . EOL );
2012-08-17 04:41:07 +00:00
else
2013-02-02 19:04:38 +00:00
notice ( t ( 'Failed to update connection record.' ) . EOL );
2012-08-17 04:41:07 +00:00
2013-01-24 05:15:40 +00:00
if (( x ( $a -> data , 'abook' )) && $a -> data [ 'abook' ][ 'abook_my_perms' ] != $abook_my_perms
&& ( ! ( $a -> data [ 'abook' ][ 'abook_flags' ] & ABOOK_FLAG_SELF ))) {
2012-11-10 11:01:07 +00:00
proc_run ( 'php' , 'include/notifier.php' , 'permission_update' , $contact_id );
}
2013-08-28 04:06:11 +00:00
if ( $new_friend ) {
// Check if settings permit ("post new friend activity" is allowed, and
// friends in general or this friend in particular aren't hidden)
// and send out a new friend activity
// TODO
}
2012-11-09 01:33:38 +00:00
// Refresh the structure in memory with the new data
$r = q ( " SELECT abook.*, xchan.*
FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_channel = % d and abook_id = % d LIMIT 1 " ,
intval ( local_user ()),
intval ( $contact_id )
2012-08-17 04:41:07 +00:00
);
2013-06-26 21:28:11 +00:00
if ( $r ) {
2012-11-09 01:33:38 +00:00
$a -> data [ 'abook' ] = $r [ 0 ];
2013-06-26 21:28:11 +00:00
}
2013-07-26 05:57:06 +00:00
connections_clone ( $a );
2012-08-17 04:41:07 +00:00
return ;
}
2013-06-26 21:28:11 +00:00
function connections_clone ( & $a ) {
if ( ! array_key_exists ( 'abook' , $a -> data ))
return ;
$clone = $a -> data [ 'abook' ];
unset ( $clone [ 'abook_id' ]);
unset ( $clone [ 'abook_account' ]);
unset ( $clone [ 'abook_channel' ]);
2013-07-25 23:00:04 +00:00
2013-06-27 00:31:02 +00:00
build_sync_packet ( 0 /* use the current local_user */ , array ( 'abook' => array ( $clone )));
2013-06-26 21:28:11 +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 = '' ;
if ( ! local_user ()) {
notice ( t ( 'Permission denied.' ) . EOL );
return ;
}
if ( argc () == 3 ) {
$contact_id = intval ( argv ( 1 ));
if ( ! $contact_id )
return ;
$cmd = argv ( 2 );
2012-10-31 04:37:58 +00:00
$orig_record = q ( " SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash
2013-01-04 00:24:30 +00:00
WHERE abook_id = % d AND abook_channel = % d AND NOT ( abook_flags & % d ) and not ( abook_flags & % d ) LIMIT 1 " ,
2012-08-17 04:41:07 +00:00
intval ( $contact_id ),
2012-10-31 04:37:58 +00:00
intval ( local_user ()),
2012-11-30 07:06:03 +00:00
intval ( ABOOK_FLAG_SELF ),
2013-08-15 08:32:09 +00:00
// allow drop even if pending, just duplicate the self query
intval (( $cmd === 'drop' ) ? ABOOK_FLAG_SELF : ABOOK_FLAG_PENDING )
2012-08-17 04:41:07 +00:00
);
if ( ! count ( $orig_record )) {
2012-10-31 04:37:58 +00:00
notice ( t ( 'Could not access address book record.' ) . EOL );
2012-11-03 09:00:48 +00:00
goaway ( $a -> get_baseurl ( true ) . '/connections' );
2012-08-17 04:41:07 +00:00
}
if ( $cmd === 'update' ) {
// pull feed and consume it, which should subscribe to the hub.
proc_run ( 'php' , " include/poller.php " , " $contact_id " );
2012-11-03 09:00:48 +00:00
goaway ( $a -> get_baseurl ( true ) . '/connections/' . $contact_id );
2012-10-31 04:37:58 +00:00
2012-08-17 04:41:07 +00:00
}
2013-01-04 00:17:22 +00:00
if ( $cmd === 'refresh' ) {
2013-01-04 00:48:18 +00:00
if ( ! zot_refresh ( $orig_record [ 0 ], get_app () -> get_channel ()))
notice ( t ( 'Refresh failed - channel is currently unavailable.' ) );
2013-01-04 00:17:22 +00:00
goaway ( $a -> get_baseurl ( true ) . '/connections/' . $contact_id );
}
2012-08-17 04:41:07 +00:00
if ( $cmd === 'block' ) {
2013-06-26 21:28:11 +00:00
if ( abook_toggle_flag ( $orig_record [ 0 ], ABOOK_FLAG_BLOCKED )) {
2012-10-31 04:37:58 +00:00
info ((( $orig_record [ 0 ][ 'abook_flags' ] & ABOOK_FLAG_BLOCKED )
? t ( 'Channel has been unblocked' )
: t ( 'Channel has been blocked' )) . EOL );
2013-06-26 21:28:11 +00:00
connections_clone ( $a );
}
2012-10-31 04:37:58 +00:00
else
notice ( t ( 'Unable to set address book parameters.' ) . EOL );
2012-11-03 09:00:48 +00:00
goaway ( $a -> get_baseurl ( true ) . '/connections/' . $contact_id );
2012-08-17 04:41:07 +00:00
}
if ( $cmd === 'ignore' ) {
2013-06-26 21:28:11 +00:00
if ( abook_toggle_flag ( $orig_record [ 0 ], ABOOK_FLAG_IGNORED )) {
2012-10-31 04:37:58 +00:00
info ((( $orig_record [ 0 ][ 'abook_flags' ] & ABOOK_FLAG_IGNORED )
? t ( 'Channel has been unignored' )
: t ( 'Channel has been ignored' )) . EOL );
2013-06-26 21:28:11 +00:00
connections_clone ( $a );
}
2012-10-31 04:37:58 +00:00
else
notice ( t ( 'Unable to set address book parameters.' ) . EOL );
2012-11-03 09:00:48 +00:00
goaway ( $a -> get_baseurl ( true ) . '/connections/' . $contact_id );
2012-08-17 04:41:07 +00:00
}
if ( $cmd === 'archive' ) {
2013-06-26 21:28:11 +00:00
if ( abook_toggle_flag ( $orig_record [ 0 ], ABOOK_FLAG_ARCHIVED )) {
2012-10-31 04:37:58 +00:00
info ((( $orig_record [ 0 ][ 'abook_flags' ] & ABOOK_FLAG_ARCHIVED )
? t ( 'Channel has been unarchived' )
: t ( 'Channel has been archived' )) . EOL );
2013-06-26 21:28:11 +00:00
connections_clone ( $a );
}
2012-10-31 04:37:58 +00:00
else
notice ( t ( 'Unable to set address book parameters.' ) . EOL );
2012-11-03 09:00:48 +00:00
goaway ( $a -> get_baseurl ( true ) . '/connections/' . $contact_id );
2012-08-17 04:41:07 +00:00
}
2012-10-31 04:37:58 +00:00
if ( $cmd === 'hide' ) {
2013-06-26 21:28:11 +00:00
if ( abook_toggle_flag ( $orig_record [ 0 ], ABOOK_FLAG_HIDDEN )) {
2012-10-31 04:37:58 +00:00
info ((( $orig_record [ 0 ][ 'abook_flags' ] & ABOOK_FLAG_HIDDEN )
? t ( 'Channel has been unhidden' )
: t ( 'Channel has been hidden' )) . EOL );
2013-06-26 21:28:11 +00:00
connections_clone ( $a );
}
2012-10-31 04:37:58 +00:00
else
notice ( t ( 'Unable to set address book parameters.' ) . EOL );
2012-11-03 09:00:48 +00:00
goaway ( $a -> get_baseurl ( true ) . '/connections/' . $contact_id );
2012-10-31 04:37:58 +00:00
}
2012-08-17 04:41:07 +00:00
2013-01-28 01:05:32 +00:00
// We'll prevent somebody from unapproving a contact.
if ( $cmd === 'approve' ) {
if ( $orig_record [ 0 ][ 'abook_flags' ] & ABOOK_FLAG_PENDING ) {
2013-06-26 21:28:11 +00:00
if ( abook_toggle_flag ( $orig_record [ 0 ], ABOOK_FLAG_PENDING )) {
2013-01-28 01:05:32 +00:00
info ((( $orig_record [ 0 ][ 'abook_flags' ] & ABOOK_FLAG_PENDING )
? t ( 'Channel has been approved' )
: t ( 'Channel has been unapproved' )) . EOL );
2013-06-26 21:28:11 +00:00
connections_clone ( $a );
}
2013-01-28 01:05:32 +00:00
else
notice ( t ( 'Unable to set address book parameters.' ) . EOL );
}
goaway ( $a -> get_baseurl ( true ) . '/connections/' . $contact_id );
}
2012-08-17 04:41:07 +00:00
2012-11-10 10:54:29 +00:00
if ( $cmd === 'drop' ) {
2012-08-17 04:41:07 +00:00
2012-11-10 10:54:29 +00:00
require_once ( 'include/Contact.php' );
// FIXME
// terminate_friendship($a->get_channel(),$orig_record[0]);
2012-10-31 04:37:58 +00:00
2013-01-26 00:18:35 +00:00
contact_remove ( local_user (), $orig_record [ 0 ][ 'abook_id' ]);
2013-06-26 21:28:11 +00:00
// FIXME - send to clones
2012-11-10 10:54:29 +00:00
info ( t ( 'Contact has been removed.' ) . EOL );
if ( x ( $_SESSION , 'return_url' ))
goaway ( $a -> get_baseurl ( true ) . '/' . $_SESSION [ 'return_url' ]);
goaway ( $a -> get_baseurl ( true ) . '/contacts' );
2012-10-31 04:37:58 +00:00
2012-11-10 10:54:29 +00:00
}
2012-08-17 04:41:07 +00:00
}
2012-10-31 04:37:58 +00:00
if (( x ( $a -> data , 'abook' )) && ( is_array ( $a -> data [ 'abook' ]))) {
2012-08-17 04:41:07 +00:00
2012-10-31 04:37:58 +00:00
$contact_id = $a -> data [ 'abook' ][ 'abook_id' ];
$contact = $a -> data [ 'abook' ];
2012-08-17 04:41:07 +00:00
2012-11-08 02:48:31 +00:00
2013-01-24 05:15:40 +00:00
$tabs = array (
array (
'label' => t ( 'View Profile' ),
'url' => $a -> get_baseurl ( true ) . '/chanview/?f=&cid=' . $contact [ 'abook_id' ],
'sel' => '' ,
'title' => sprintf ( t ( 'View %s\'s profile' ), $contact [ 'xchan_name' ]),
),
array (
'label' => t ( 'Refresh Permissions' ),
'url' => $a -> get_baseurl ( true ) . '/connections/' . $contact [ 'abook_id' ] . '/refresh' ,
'sel' => '' ,
'title' => t ( 'Fetch updated permissions' ),
),
2013-09-29 09:47:36 +00:00
array (
'label' => t ( 'Recent Activity' ),
'url' => $a -> get_baseurl ( true ) . '/network/?f=&cid=' . $contact [ 'abook_id' ],
'sel' => '' ,
'title' => t ( 'View recent posts and comments' ),
),
2013-01-24 05:15:40 +00:00
array (
'label' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_BLOCKED ) ? t ( 'Unblock' ) : t ( 'Block' )),
'url' => $a -> get_baseurl ( true ) . '/connections/' . $contact [ 'abook_id' ] . '/block' ,
'sel' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_BLOCKED ) ? 'active' : '' ),
'title' => t ( 'Block or Unblock this connection' ),
),
array (
'label' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_IGNORED ) ? t ( 'Unignore' ) : t ( 'Ignore' )),
'url' => $a -> get_baseurl ( true ) . '/connections/' . $contact [ 'abook_id' ] . '/ignore' ,
'sel' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_IGNORED ) ? 'active' : '' ),
'title' => t ( 'Ignore or Unignore this connection' ),
),
array (
'label' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_ARCHIVED ) ? t ( 'Unarchive' ) : t ( 'Archive' )),
'url' => $a -> get_baseurl ( true ) . '/connections/' . $contact [ 'abook_id' ] . '/archive' ,
'sel' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_ARCHIVED ) ? 'active' : '' ),
'title' => t ( 'Archive or Unarchive this connection' ),
),
array (
'label' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_HIDDEN ) ? t ( 'Unhide' ) : t ( 'Hide' )),
'url' => $a -> get_baseurl ( true ) . '/connections/' . $contact [ 'abook_id' ] . '/hide' ,
'sel' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_HIDDEN ) ? 'active' : '' ),
'title' => t ( 'Hide or Unhide this connection' ),
),
array (
'label' => t ( 'Delete' ),
'url' => $a -> get_baseurl ( true ) . '/connections/' . $contact [ 'abook_id' ] . '/drop' ,
'sel' => '' ,
'title' => t ( 'Delete this connection' ),
),
2012-11-08 02:48:31 +00:00
2013-01-24 05:15:40 +00:00
);
2012-11-08 02:48:31 +00:00
2013-01-24 05:15:40 +00:00
$self = false ;
2012-11-08 02:48:31 +00:00
2013-01-24 05:15:40 +00:00
if ( ! ( $contact [ 'abook_flags' ] & ABOOK_FLAG_SELF )) {
$tab_tpl = get_markup_template ( 'common_tabs.tpl' );
$t = replace_macros ( $tab_tpl , array ( '$tabs' => $tabs ));
}
else
$self = true ;
2012-08-17 04:41:07 +00:00
$a -> page [ 'htmlhead' ] .= replace_macros ( get_markup_template ( 'contact_head.tpl' ), array (
'$baseurl' => $a -> get_baseurl ( true ),
2013-01-24 05:15:40 +00:00
'$editselect' => $editselect
2012-08-17 04:41:07 +00:00
));
require_once ( 'include/contact_selectors.php' );
$tpl = get_markup_template ( " abook_edit.tpl " );
2012-11-29 03:23:39 +00:00
if ( feature_enabled ( local_user (), 'affinity' )) {
$slider_tpl = get_markup_template ( 'contact_slider.tpl' );
$slide = replace_macros ( $slider_tpl , array (
'$me' => t ( 'Me' ),
2013-05-24 13:02:30 +00:00
'$val' => (( $contact [ 'abook_closeness' ]) ? $contact [ 'abook_closeness' ] : 99 ),
2012-11-29 03:23:39 +00:00
'$intimate' => t ( 'Best Friends' ),
'$friends' => t ( 'Friends' ),
'$oldfriends' => t ( 'Former Friends' ),
'$acquaintances' => t ( 'Acquaintances' ),
'$world' => t ( 'Unknown' )
));
}
2012-08-17 04:41:07 +00:00
2012-11-09 01:33:38 +00:00
$perms = array ();
$channel = $a -> get_channel ();
$global_perms = get_perms ();
2013-05-18 08:25:54 +00:00
$existing = get_all_perms ( local_user (), $contact [ 'abook_xchan' ]);
2012-12-31 09:17:52 +00:00
2013-01-28 01:05:32 +00:00
$unapproved = array ( 'pending' , t ( 'Approve this connection' ), '' , t ( 'Accept connection to allow communication' ));
2013-01-24 05:15:40 +00:00
2012-11-09 01:33:38 +00:00
foreach ( $global_perms as $k => $v ) {
2013-05-20 00:57:06 +00:00
$thisperm = (( $contact [ 'abook_my_perms' ] & $v [ 1 ]) ? " 1 " : '' );
// For auto permissions (when $self is true) we don't want to look at existing
// permissions because they are enabled for the channel owner
if (( ! $self ) && ( $existing [ $k ]))
$thisperm = " 1 " ;
$perms [] = array ( 'perms_' . $k , $v [ 3 ], (( $contact [ 'abook_their_perms' ] & $v [ 1 ]) ? " 1 " : " " ), $thisperm , $v [ 1 ], (( $channel [ $v [ 0 ]] == PERMS_SPECIFIC ) ? '' : '1' ), $v [ 4 ]);
2012-11-09 01:33:38 +00:00
}
2012-08-17 04:41:07 +00:00
$o .= replace_macros ( $tpl , array (
2013-01-24 05:15:40 +00:00
'$header' => (( $self ) ? t ( 'Automatic Permissions Settings' ) : sprintf ( t ( 'Connections: settings for %s' ), $contact [ 'xchan_name' ])),
'$addr' => $contact [ 'xchan_addr' ],
'$notself' => (( $self ) ? '' : '1' ),
'$self' => (( $self ) ? '1' : '' ),
2013-02-02 19:04:38 +00:00
'$autolbl' => t ( 'When receiving a channel introduction, any permissions provided here will be applied to the new connection automatically and the introduction approved. Leave this page if you do not wish to use this feature.' ),
2013-01-24 05:15:40 +00:00
'$viewprof' => t ( 'View Profile' ),
'$lbl_slider' => t ( 'Slide to adjust your degree of friendship' ),
'$slide' => $slide ,
'$tabs' => $t ,
'$tab_str' => $tab_str ,
2013-01-28 01:05:32 +00:00
'$is_pending' => (( $contact [ 'abook_flags' ] & ABOOK_FLAG_PENDING ) ? 1 : '' ),
'$unapproved' => $unapproved ,
2013-10-13 22:42:30 +00:00
'$inherited' => t ( 'inherited' ),
2013-01-28 01:05:32 +00:00
'$approve' => t ( 'Approve this connection' ),
2013-05-22 00:13:51 +00:00
'$noperms' => ((( ! $self ) && ( ! $contact [ 'abook_my_perms' ])) ? t ( 'Connection has no individual permissions!' ) : '' ),
2013-08-09 11:00:34 +00:00
'$noperm_desc' => ((( ! $self ) && ( ! $contact [ 'abook_my_perms' ])) ? t ( 'This may be appropriate based on your <a href="settings">privacy settings</a>, though you may wish to review the "Advanced Permissions".' ) : '' ),
2013-01-24 05:15:40 +00:00
'$submit' => t ( 'Submit' ),
'$lbl_vis1' => t ( 'Profile Visibility' ),
2013-07-03 08:50:39 +00:00
'$lbl_vis2' => sprintf ( t ( 'Please choose the profile you would like to display to %s when viewing your profile securely.' ), $contact [ 'xchan_name' ]),
2013-01-24 05:15:40 +00:00
'$lbl_info1' => t ( 'Contact Information / Notes' ),
'$infedit' => t ( 'Edit contact notes' ),
'$close' => $contact [ 'abook_closeness' ],
'$them' => t ( 'Their Settings' ),
'$me' => t ( 'My Settings' ),
'$perms' => $perms ,
'$forum' => t ( 'Forum Members' ),
2013-02-10 08:13:34 +00:00
'$soapbox' => t ( 'Soapbox' ),
2013-01-24 05:15:40 +00:00
'$full' => t ( 'Full Sharing' ),
'$cautious' => t ( 'Cautious Sharing' ),
'$follow' => t ( 'Follow Only' ),
2013-05-22 00:13:51 +00:00
'$permlbl' => t ( 'Individual Permissions' ),
2013-10-13 22:42:30 +00:00
'$permnote' => t ( 'Some permissions may be inherited from your <a href="settings">privacy settings</a>, which have higher priority. Changing those on this page will have no effect.' ),
2013-01-24 05:15:40 +00:00
'$advanced' => t ( 'Advanced Permissions' ),
'$quick' => t ( 'Quick Links' ),
'$common_link' => $a -> get_baseurl ( true ) . '/common/loc/' . local_user () . '/' . $contact [ 'id' ],
'$all_friends' => $all_friends ,
'$relation_text' => $relation_text ,
'$visit' => sprintf ( t ( 'Visit %s\'s profile - %s' ), $contact [ 'xchan_name' ], $contact [ 'xchan_url' ]),
'$blockunblock' => t ( 'Block/Unblock contact' ),
'$ignorecont' => t ( 'Ignore contact' ),
'$lblcrepair' => t ( " Repair URL settings " ),
'$lblrecent' => t ( 'View conversations' ),
'$lblsuggest' => $lblsuggest ,
'$delete' => t ( 'Delete contact' ),
'$poll_interval' => contact_poll_interval ( $contact [ 'priority' ],( ! $poll_enabled )),
'$poll_enabled' => $poll_enabled ,
'$lastupdtext' => t ( 'Last update:' ),
'$lost_contact' => $lost_contact ,
'$updpub' => t ( 'Update public posts' ),
'$last_update' => $last_update ,
'$udnow' => t ( 'Update now' ),
2013-07-03 08:50:39 +00:00
'$profile_select' => contact_profile_assign ( $contact [ 'abook_profile' ]),
'$multiprofs' => feature_enabled ( local_user (), 'multi_profiles' ),
2013-01-24 05:15:40 +00:00
'$contact_id' => $contact [ 'abook_id' ],
'$block_text' => (( $contact [ 'blocked' ]) ? t ( 'Unblock' ) : t ( 'Block' ) ),
'$ignore_text' => (( $contact [ 'readonly' ]) ? t ( 'Unignore' ) : t ( 'Ignore' ) ),
'$blocked' => (( $contact [ 'blocked' ]) ? t ( 'Currently blocked' ) : '' ),
'$ignored' => (( $contact [ 'readonly' ]) ? t ( 'Currently ignored' ) : '' ),
'$archived' => (( $contact [ 'archive' ]) ? t ( 'Currently archived' ) : '' ),
2013-01-28 01:05:32 +00:00
'$pending' => (( $contact [ 'archive' ]) ? t ( 'Currently pending' ) : '' ),
2013-01-24 05:15:40 +00:00
'$hidden' => array ( 'hidden' , t ( 'Hide this contact from others' ), ( $contact [ 'hidden' ] == 1 ), t ( 'Replies/likes to your public posts <strong>may</strong> still be visible' )),
'$photo' => $contact [ 'photo' ],
'$name' => $contact [ 'name' ],
'$dir_icon' => $dir_icon ,
'$alt_text' => $alt_text ,
'$sparkle' => $sparkle ,
'$url' => $url
2012-08-17 04:41:07 +00:00
));
$arr = array ( 'contact' => $contact , 'output' => $o );
call_hooks ( 'contact_edit' , $arr );
return $arr [ 'output' ];
}
2013-01-24 05:15:40 +00:00
$blocked = false ;
$hidden = false ;
$ignored = false ;
$archived = false ;
2012-11-30 02:15:13 +00:00
$unblocked = false ;
2013-01-28 01:05:32 +00:00
$pending = false ;
2012-08-17 04:41:07 +00:00
$all = false ;
$_SESSION [ 'return_url' ] = $a -> query_string ;
2012-10-31 04:37:58 +00:00
$search_flags = 0 ;
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' :
$search_flags = ABOOK_FLAG_BLOCKED ;
2013-01-28 01:05:32 +00:00
$head = t ( 'Blocked' );
2012-10-31 04:37:58 +00:00
$blocked = true ;
break ;
case 'ignored' :
$search_flags = ABOOK_FLAG_IGNORED ;
2013-01-28 01:05:32 +00:00
$head = t ( 'Ignored' );
2012-10-31 04:37:58 +00:00
$ignored = true ;
break ;
case 'hidden' :
$search_flags = ABOOK_FLAG_HIDDEN ;
2013-01-28 01:05:32 +00:00
$head = t ( 'Hidden' );
2012-10-31 04:37:58 +00:00
$hidden = true ;
break ;
case 'archived' :
$search_flags = ABOOK_FLAG_ARCHIVED ;
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' :
$search_flags = ABOOK_FLAG_PENDING ;
$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 ;
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 :
$search_flags = 0 ;
$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
$sql_extra = (( $search_flags ) ? " and ( abook_flags & " . $search_flags . " ) " : " " );
}
else {
$sql_extra = " and not ( abook_flags & " . ABOOK_FLAG_BLOCKED . " ) " ;
$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 (
array (
'label' => t ( 'Suggestions' ),
'url' => $a -> get_baseurl ( true ) . '/suggest' ,
'sel' => '' ,
2012-11-03 09:00:48 +00:00
'title' => t ( 'Suggest new connections' ),
2012-08-17 04:41:07 +00:00
),
2013-01-28 01:05:32 +00:00
array (
'label' => t ( 'New Connections' ),
'url' => $a -> get_baseurl ( true ) . '/connections/pending' ,
'sel' => ( $pending ) ? 'active' : '' ,
'title' => t ( 'Show pending (new) connections' ),
),
2012-08-17 04:41:07 +00:00
array (
2012-11-03 09:00:48 +00:00
'label' => t ( 'All Connections' ),
'url' => $a -> get_baseurl ( true ) . '/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
),
array (
'label' => t ( 'Unblocked' ),
2012-11-03 09:00:48 +00:00
'url' => $a -> get_baseurl ( true ) . '/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
),
array (
'label' => t ( 'Blocked' ),
2012-11-03 09:00:48 +00:00
'url' => $a -> get_baseurl ( true ) . '/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
),
array (
'label' => t ( 'Ignored' ),
2012-11-03 09:00:48 +00:00
'url' => $a -> get_baseurl ( true ) . '/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
),
array (
'label' => t ( 'Archived' ),
2012-11-03 09:00:48 +00:00
'url' => $a -> get_baseurl ( true ) . '/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
),
array (
'label' => t ( 'Hidden' ),
2012-11-03 09:00:48 +00:00
'url' => $a -> get_baseurl ( true ) . '/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
),
);
$tab_tpl = get_markup_template ( 'common_tabs.tpl' );
$t = replace_macros ( $tab_tpl , array ( '$tabs' => $tabs ));
$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
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
2013-01-28 01:05:32 +00:00
where abook_channel = % d and not ( abook_flags & % d ) $sql_extra $sql_extra2 " ,
2012-10-31 23:55:19 +00:00
intval ( local_user ()),
2013-01-28 01:05:32 +00:00
intval ( ABOOK_FLAG_SELF )
2012-10-31 23:55:19 +00:00
);
2012-08-17 04:41:07 +00:00
if ( count ( $r )) {
$a -> set_pager_total ( $r [ 0 ][ 'total' ]);
$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
2013-01-28 01:05:32 +00:00
WHERE abook_channel = % d and not ( abook_flags & % d ) $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT % d , % d " ,
2012-10-31 23:55:19 +00:00
intval ( local_user ()),
intval ( ABOOK_FLAG_SELF ),
2012-08-17 04:41:07 +00:00
intval ( $a -> pager [ 'start' ]),
intval ( $a -> pager [ 'itemspage' ])
);
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' ]) {
$contacts [] = array (
'img_hover' => sprintf ( t ( '%1$s [%2$s]' ), $rr [ 'xchan_name' ], $rr [ 'xchan_url' ]),
'edit_hover' => t ( 'Edit contact' ),
'photo_menu' => contact_photo_menu ( $rr ),
'id' => $rr [ 'abook_id' ],
'alt_text' => $alt_text ,
'dir_icon' => $dir_icon ,
'thumb' => $rr [ 'xchan_photo_m' ],
'name' => $rr [ 'xchan_name' ],
'username' => $rr [ 'xchan_name' ],
'sparkle' => $sparkle ,
'link' => z_root () . '/connections/' . $rr [ 'abook_id' ],
'url' => $rr [ 'xchan_url' ],
'network' => network_to_name ( $rr [ 'network' ]),
);
}
2012-08-17 04:41:07 +00:00
}
}
2013-01-28 01:05:32 +00:00
2012-08-17 04:41:07 +00:00
$tpl = get_markup_template ( " contacts-template.tpl " );
$o .= replace_macros ( $tpl , array (
2013-02-02 19:04:38 +00:00
'$header' => t ( 'Connections' ) . (( $head ) ? ' - ' . $head : '' ),
2012-08-17 04:41:07 +00:00
'$tabs' => $t ,
'$total' => $total ,
'$search' => $search_hdr ,
2013-02-02 19:04:38 +00:00
'$desc' => t ( 'Search your connections' ),
2012-08-17 04:41:07 +00:00
'$finding' => (( $searching ) ? t ( 'Finding: ' ) . " ' " . $search . " ' " : " " ),
'$submit' => t ( 'Find' ),
'$cmd' => $a -> cmd ,
'$contacts' => $contacts ,
'$paginate' => paginate ( $a ),
));
return $o ;
}