2010-07-01 23:48:07 +00:00
< ? php
2013-01-06 21:42:51 +00:00
function profiles_init ( & $a ) {
nav_set_selected ( 'profiles' );
if ( ! local_user ()) {
return ;
}
if (( argc () > 2 ) && ( argv ( 1 ) === " drop " ) && intval ( argv ( 2 ))) {
$r = q ( " SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1 " ,
intval ( $a -> argv [ 2 ]),
intval ( local_user ())
);
if ( ! count ( $r )) {
notice ( t ( 'Profile not found.' ) . EOL );
goaway ( $a -> get_baseurl ( true ) . '/profiles' );
return ; // NOTREACHED
}
$profile_guid = $r [ 'profile_guid' ];
check_form_security_token_redirectOnErr ( '/profiles' , 'profile_drop' , 't' );
// move every contact using this profile as their default to the user default
$r = q ( " UPDATE abook SET abook_profile = (SELECT profile_guid AS FROM profile WHERE is_default = 1 AND uid = %d LIMIT 1) WHERE abook_profile = '%s' AND abook_channel = %d " ,
intval ( local_user ()),
dbesc ( $profile_guid ),
intval ( local_user ())
);
$r = q ( " DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1 " ,
intval ( argv ( 2 )),
intval ( local_user ())
);
if ( $r )
info ( t ( 'Profile deleted.' ) . EOL );
goaway ( $a -> get_baseurl ( true ) . '/profiles' );
return ; // NOTREACHED
}
if (( argc () > 1 ) && ( argv ( 1 ) === 'new' )) {
2013-07-03 09:47:36 +00:00
// check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
2013-01-06 21:42:51 +00:00
$r0 = q ( " SELECT `id` FROM `profile` WHERE `uid` = %d " ,
intval ( local_user ()));
$num_profiles = count ( $r0 );
$name = t ( 'Profile-' ) . ( $num_profiles + 1 );
$r1 = q ( " SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is_default` = 1 LIMIT 1 " ,
intval ( local_user ()));
$r2 = q ( " INSERT INTO `profile` (`aid`, `uid` , `profile_guid`, `profile_name` , `name`, `photo`, `thumb`)
2013-03-21 17:38:34 +00:00
VALUES ( % d , '%s' , '%s' , '%s' , '%s' , '%s' , '%s' ) " ,
2013-01-06 21:42:51 +00:00
intval ( get_account_id ()),
intval ( local_user ()),
dbesc ( random_string ()),
dbesc ( $name ),
dbesc ( $r1 [ 0 ][ 'name' ]),
dbesc ( $r1 [ 0 ][ 'photo' ]),
dbesc ( $r1 [ 0 ][ 'thumb' ])
);
$r3 = q ( " SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1 " ,
intval ( local_user ()),
dbesc ( $name )
);
info ( t ( 'New profile created.' ) . EOL );
if ( count ( $r3 ) == 1 )
goaway ( $a -> get_baseurl ( true ) . '/profiles/' . $r3 [ 0 ][ 'id' ]);
goaway ( $a -> get_baseurl ( true ) . '/profiles' );
}
if (( argc () > 2 ) && ( argv ( 1 ) === 'clone' )) {
check_form_security_token_redirectOnErr ( '/profiles' , 'profile_clone' , 't' );
$r0 = q ( " SELECT `id` FROM `profile` WHERE `uid` = %d " ,
intval ( local_user ()));
$num_profiles = count ( $r0 );
$name = t ( 'Profile-' ) . ( $num_profiles + 1 );
$r1 = q ( " SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1 " ,
intval ( local_user ()),
intval ( $a -> argv [ 2 ])
);
if ( ! count ( $r1 )) {
notice ( t ( 'Profile unavailable to clone.' ) . EOL );
$a -> error = 404 ;
return ;
}
unset ( $r1 [ 0 ][ 'id' ]);
$r1 [ 0 ][ 'is_default' ] = 0 ;
$r1 [ 0 ][ 'publish' ] = 0 ;
$r1 [ 0 ][ 'profile_name' ] = dbesc ( $name );
$r1 [ 0 ][ 'profile_guid' ] = dbesc ( random_string ());
dbesc_array ( $r1 [ 0 ]);
$r2 = dbq ( " INSERT INTO `profile` (` "
. implode ( " `, ` " , array_keys ( $r1 [ 0 ]))
. " `) VALUES (' "
. implode ( " ', ' " , array_values ( $r1 [ 0 ]))
. " ') " );
$r3 = q ( " SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile_name` = '%s' LIMIT 1 " ,
intval ( local_user ()),
dbesc ( $name )
);
info ( t ( 'New profile created.' ) . EOL );
if ( count ( $r3 ) == 1 )
goaway ( $a -> get_baseurl ( true ) . '/profiles/' . $r3 [ 0 ][ 'id' ]);
goaway ( $a -> get_baseurl ( true ) . '/profiles' );
return ; // NOTREACHED
}
2014-08-04 11:40:45 +00:00
if (( argc () > 2 ) && ( argv ( 1 ) === 'export' )) {
$r1 = q ( " SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1 " ,
intval ( local_user ()),
intval ( argv ( 2 ))
);
if ( ! $r1 ) {
notice ( t ( 'Profile unavailable to export.' ) . EOL );
$a -> error = 404 ;
return ;
}
header ( 'content-type: application/octet_stream' );
header ( 'content-disposition: attachment; filename="' . $r1 [ 0 ][ 'profile_name' ] . '.json"' );
unset ( $r1 [ 0 ][ 'id' ]);
unset ( $r1 [ 0 ][ 'aid' ]);
unset ( $r1 [ 0 ][ 'uid' ]);
unset ( $r1 [ 0 ][ 'is_default' ]);
unset ( $r1 [ 0 ][ 'publish' ]);
unset ( $r1 [ 0 ][ 'profile_name' ]);
unset ( $r1 [ 0 ][ 'profile_guid' ]);
echo json_encode ( $r1 [ 0 ]);
killme ();
}
2013-01-06 21:42:51 +00:00
// Run profile_load() here to make sure the theme is set before
// we start loading content
if (( argc () > 1 ) && ( intval ( argv ( 1 )))) {
$r = q ( " SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1 " ,
intval ( $a -> argv [ 1 ]),
intval ( local_user ())
);
if ( ! count ( $r )) {
notice ( t ( 'Profile not found.' ) . EOL );
$a -> error = 404 ;
return ;
}
$chan = $a -> get_channel ();
profile_load ( $a , $chan [ 'channel_address' ], $r [ 0 ][ 'id' ]);
}
}
2010-07-01 23:48:07 +00:00
function profiles_post ( & $a ) {
if ( ! local_user ()) {
2010-08-19 11:59:31 +00:00
notice ( t ( 'Permission denied.' ) . EOL );
2010-07-01 23:48:07 +00:00
return ;
}
2010-08-09 04:03:08 +00:00
2012-10-22 00:23:21 +00:00
require_once ( 'include/activities.php' );
2010-08-09 04:03:08 +00:00
$namechanged = false ;
2011-01-20 23:30:45 +00:00
call_hooks ( 'profile_post' , $_POST );
2014-08-04 23:47:49 +00:00
// import from json export file.
// Only import fields that are allowed on this hub
if ( x ( $_FILES , 'userfile' )) {
$src = $_FILES [ 'userfile' ][ 'tmp_name' ];
$filesize = intval ( $_FILES [ 'userfile' ][ 'size' ]);
if ( $filesize ) {
$j = @ json_decode ( @ file_get_contents ( $src ), true );
@ unlink ( $src );
if ( $j ) {
$fields = get_profile_fields_advanced ();
if ( $fields ) {
foreach ( $j as $jj => $v ) {
foreach ( $fields as $f => $n ) {
if ( $jj == $f ) {
$_POST [ $f ] = $v ;
break ;
}
}
}
}
}
}
}
2012-10-19 22:40:13 +00:00
if (( argc () > 1 ) && ( argv ( 1 ) !== " new " ) && intval ( argv ( 1 ))) {
2010-08-09 04:03:08 +00:00
$orig = q ( " SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1 " ,
2010-07-01 23:48:07 +00:00
intval ( $a -> argv [ 1 ]),
2010-11-25 00:35:35 +00:00
intval ( local_user ())
2010-07-01 23:48:07 +00:00
);
2010-08-09 04:03:08 +00:00
if ( ! count ( $orig )) {
2010-08-19 11:59:31 +00:00
notice ( t ( 'Profile not found.' ) . EOL );
2010-07-01 23:48:07 +00:00
return ;
}
2012-03-12 20:17:37 +00:00
check_form_security_token_redirectOnErr ( '/profiles' , 'profile_edit' );
2012-08-31 01:17:38 +00:00
$is_default = (( $orig [ 0 ][ 'is_default' ]) ? 1 : 0 );
2010-07-01 23:48:07 +00:00
$profile_name = notags ( trim ( $_POST [ 'profile_name' ]));
if ( ! strlen ( $profile_name )) {
2010-08-19 11:59:31 +00:00
notify ( t ( 'Profile Name is required.' ) . EOL );
2010-07-01 23:48:07 +00:00
return ;
}
2014-08-04 23:47:49 +00:00
if ( $_POST [ 'dob' ]) {
$year = substr ( $_POST [ 'dob' ], 0 , 4 );
$month = substr ( $_POST [ 'dob' ], 5 , 2 );
$day = substr ( $_POST [ 'dob' ], 8 , 2 );
}
2010-07-01 23:48:07 +00:00
2010-07-10 23:47:10 +00:00
$year = intval ( $_POST [ 'year' ]);
if ( $year < 1900 || $year > 2100 || $year < 0 )
$year = 0 ;
$month = intval ( $_POST [ 'month' ]);
if (( $month > 12 ) || ( $month < 0 ))
$month = 0 ;
$mtab = array ( 0 , 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 );
$day = intval ( $_POST [ 'day' ]);
if (( $day > $mtab [ $month ]) || ( $day < 0 ))
$day = 0 ;
2013-07-03 23:55:57 +00:00
2014-05-02 01:40:00 +00:00
// if($year && (! ($month && $day))) {
// $month = 1; $day = 1;
// }
2013-07-03 23:55:57 +00:00
2014-08-29 05:18:11 +00:00
2010-07-10 23:47:10 +00:00
$dob = '0000-00-00' ;
$dob = sprintf ( '%04d-%02d-%02d' , $year , $month , $day );
2014-04-21 01:48:21 +00:00
$name = escape_tags ( trim ( $_POST [ 'name' ]));
2010-08-09 04:03:08 +00:00
if ( $orig [ 0 ][ 'name' ] != $name )
$namechanged = true ;
2012-04-13 04:10:32 +00:00
2014-08-29 05:18:11 +00:00
2014-04-21 01:48:21 +00:00
$pdesc = escape_tags ( trim ( $_POST [ 'pdesc' ]));
$gender = escape_tags ( trim ( $_POST [ 'gender' ]));
$address = escape_tags ( trim ( $_POST [ 'address' ]));
$locality = escape_tags ( trim ( $_POST [ 'locality' ]));
$region = escape_tags ( trim ( $_POST [ 'region' ]));
$postal_code = escape_tags ( trim ( $_POST [ 'postal_code' ]));
$country_name = escape_tags ( trim ( $_POST [ 'country_name' ]));
$keywords = escape_tags ( trim ( $_POST [ 'keywords' ]));
$marital = escape_tags ( trim ( $_POST [ 'marital' ]));
$howlong = escape_tags ( trim ( $_POST [ 'howlong' ]));
$sexual = escape_tags ( trim ( $_POST [ 'sexual' ]));
$homepage = escape_tags ( trim ( $_POST [ 'homepage' ]));
$hometown = escape_tags ( trim ( $_POST [ 'hometown' ]));
$politic = escape_tags ( trim ( $_POST [ 'politic' ]));
$religion = escape_tags ( trim ( $_POST [ 'religion' ]));
2012-10-22 00:23:21 +00:00
$likes = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'likes' ])));
$dislikes = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'dislikes' ])));
$about = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'about' ])));
$interest = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'interest' ])));
$contact = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'contact' ])));
2013-03-20 20:46:43 +00:00
$channels = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'channels' ])));
2012-10-22 00:23:21 +00:00
$music = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'music' ])));
$book = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'book' ])));
$tv = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'tv' ])));
$film = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'film' ])));
$romance = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'romance' ])));
$work = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'work' ])));
$education = fix_mce_lf ( escape_tags ( trim ( $_POST [ 'education' ])));
$hide_friends = (( $_POST [ 'hide_friends' ] == 1 ) ? 1 : 0 );
2010-08-10 05:58:58 +00:00
2014-04-21 01:48:21 +00:00
$with = (( x ( $_POST , 'with' )) ? escape_tags ( trim ( $_POST [ 'with' ])) : '' );
2010-12-04 06:46:42 +00:00
2012-06-02 09:30:26 +00:00
if ( ! strlen ( $howlong ))
2014-09-09 03:35:15 +00:00
$howlong = NULL_DATE ;
2012-06-02 09:30:26 +00:00
else
$howlong = datetime_convert ( date_default_timezone_get (), 'UTC' , $howlong );
2010-12-04 06:46:42 +00:00
// linkify the relationship target if applicable
2012-04-13 04:58:15 +00:00
$withchanged = false ;
2010-12-04 06:46:42 +00:00
if ( strlen ( $with )) {
if ( $with != strip_tags ( $orig [ 0 ][ 'with' ])) {
2012-04-13 04:58:15 +00:00
$withchanged = true ;
2010-12-04 06:46:42 +00:00
$prf = '' ;
$lookup = $with ;
2011-02-25 20:12:25 +00:00
if ( strpos ( $lookup , '@' ) === 0 )
$lookup = substr ( $lookup , 1 );
$lookup = str_replace ( '_' , ' ' , $lookup );
2014-01-23 23:43:35 +00:00
$newname = $lookup ;
$r = q ( " SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1 " ,
dbesc ( $newname ),
intval ( local_user ())
);
if ( ! $r ) {
$r = q ( " SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE xchan_addr = '%s' AND abook_channel = %d LIMIT 1 " ,
dbesc ( $lookup . '@%' ),
2012-10-02 01:02:11 +00:00
intval ( local_user ())
);
2010-12-04 06:46:42 +00:00
}
2014-01-23 23:43:35 +00:00
if ( $r ) {
$prf = $r [ 0 ][ 'xchan_url' ];
$newname = $r [ 0 ][ 'xchan_name' ];
}
2010-12-04 06:46:42 +00:00
if ( $prf ) {
$with = str_replace ( $lookup , '<a href="' . $prf . '">' . $newname . '</a>' , $with );
2011-02-25 20:12:25 +00:00
if ( strpos ( $with , '@' ) === 0 )
$with = substr ( $with , 1 );
2010-12-04 06:46:42 +00:00
}
}
else
$with = $orig [ 0 ][ 'with' ];
}
2014-08-29 05:18:11 +00:00
$profile_fields_basic = get_profile_fields_basic ();
$profile_fields_advanced = get_profile_fields_advanced ();
$advanced = (( feature_enabled ( local_user (), 'advanced_profiles' )) ? true : false );
if ( $advanced )
$fields = $profile_fields_advanced ;
else
$fields = $profile_fields_basic ;
$z = q ( " select * from profdef where true " );
if ( $z ) {
foreach ( $z as $zz ) {
if ( array_key_exists ( $zz [ 'field_name' ], $fields )) {
$w = q ( " select * from profext where channel_id = %d and hash = '%s' and k = '%s' limit 1 " ,
intval ( local_user ()),
dbesc ( $orig [ 0 ][ 'profile_guid' ]),
dbesc ( $zz [ 'field_name' ])
);
if ( $w ) {
q ( " update profext set v = '%s' where id = %d limit 1 " ,
dbesc ( escape_tags ( trim ( $_POST [ $zz [ 'field_name' ]]))),
intval ( $w [ 0 ][ 'id' ])
);
}
else {
2014-08-29 05:27:05 +00:00
q ( " insert into profext ( channel_id, hash, k, v ) values ( %d, '%s', '%s', '%s') " ,
2014-08-29 05:18:11 +00:00
intval ( local_user ()),
dbesc ( $orig [ 0 ][ 'profile_guid' ]),
dbesc ( $zz [ 'field_name' ]),
dbesc ( escape_tags ( trim ( $_POST [ $zz [ 'field_name' ]])))
);
}
}
}
}
2012-04-13 04:10:32 +00:00
$changes = array ();
2012-04-29 08:42:48 +00:00
$value = '' ;
2012-04-13 04:10:32 +00:00
if ( $is_default ) {
2012-04-29 08:42:48 +00:00
if ( $marital != $orig [ 0 ][ 'marital' ]) {
2012-04-29 09:11:33 +00:00
$changes [] = '[color=#ff0000]♥[/color] ' . t ( 'Marital Status' );
2012-04-29 08:42:48 +00:00
$value = $marital ;
}
if ( $withchanged ) {
2012-05-25 07:42:38 +00:00
$changes [] = '[color=#ff0000]♥[/color] ' . t ( 'Romantic Partner' );
2012-04-29 08:42:48 +00:00
$value = strip_tags ( $with );
2012-06-25 04:16:55 +00:00
}
if ( $likes != $orig [ 0 ][ 'likes' ]) {
$changes [] = t ( 'Likes' );
$value = $likes ;
}
if ( $dislikes != $orig [ 0 ][ 'dislikes' ]) {
$changes [] = t ( 'Dislikes' );
$value = $dislikes ;
}
2012-04-29 08:42:48 +00:00
if ( $work != $orig [ 0 ][ 'work' ]) {
$changes [] = t ( 'Work/Employment' );
}
if ( $religion != $orig [ 0 ][ 'religion' ]) {
$changes [] = t ( 'Religion' );
$value = $religion ;
}
if ( $politic != $orig [ 0 ][ 'politic' ]) {
$changes [] = t ( 'Political Views' );
$value = $politic ;
}
if ( $gender != $orig [ 0 ][ 'gender' ]) {
$changes [] = t ( 'Gender' );
$value = $gender ;
}
if ( $sexual != $orig [ 0 ][ 'sexual' ]) {
$changes [] = t ( 'Sexual Preference' );
$value = $sexual ;
}
if ( $homepage != $orig [ 0 ][ 'homepage' ]) {
$changes [] = t ( 'Homepage' );
$value = $homepage ;
}
if ( $interest != $orig [ 0 ][ 'interest' ]) {
$changes [] = t ( 'Interests' );
$value = $interest ;
}
2012-05-25 22:56:18 +00:00
if ( $address != $orig [ 0 ][ 'address' ]) {
$changes [] = t ( 'Address' );
// New address not sent in notifications, potential privacy issues
// in case this leaks to unintended recipients. Yes, it's in the public
// profile but that doesn't mean we have to broadcast it to everybody.
}
if ( $locality != $orig [ 0 ][ 'locality' ] || $region != $orig [ 0 ][ 'region' ]
2012-08-31 01:17:38 +00:00
|| $country_name != $orig [ 0 ][ 'country_name' ]) {
2012-04-29 08:42:48 +00:00
$changes [] = t ( 'Location' );
2012-05-25 22:56:18 +00:00
$comma1 = ((( $locality ) && ( $region || $country_name )) ? ', ' : ' ' );
$comma2 = (( $region && $country_name ) ? ', ' : '' );
$value = $locality . $comma1 . $region . $comma2 . $country_name ;
2012-04-29 08:42:48 +00:00
}
2012-04-13 04:10:32 +00:00
2012-04-29 08:42:48 +00:00
profile_activity ( $changes , $value );
2012-04-13 04:10:32 +00:00
}
2010-07-01 23:48:07 +00:00
$r = q ( " UPDATE `profile`
2012-08-27 08:22:08 +00:00
SET `profile_name` = '%s' ,
2010-07-01 23:48:07 +00:00
`name` = '%s' ,
2011-01-19 03:25:28 +00:00
`pdesc` = '%s' ,
2010-07-01 23:48:07 +00:00
`gender` = '%s' ,
2010-07-10 23:47:10 +00:00
`dob` = '%s' ,
2010-07-01 23:48:07 +00:00
`address` = '%s' ,
`locality` = '%s' ,
`region` = '%s' ,
2012-08-31 01:17:38 +00:00
`postal_code` = '%s' ,
`country_name` = '%s' ,
2010-07-01 23:48:07 +00:00
`marital` = '%s' ,
2010-12-04 06:46:42 +00:00
`with` = '%s' ,
2012-06-02 09:30:26 +00:00
`howlong` = '%s' ,
2010-07-10 23:47:10 +00:00
`sexual` = '%s' ,
2010-07-01 23:48:07 +00:00
`homepage` = '%s' ,
2012-06-03 03:58:20 +00:00
`hometown` = '%s' ,
2010-07-10 23:47:10 +00:00
`politic` = '%s' ,
`religion` = '%s' ,
2012-12-26 11:49:50 +00:00
`keywords` = '%s' ,
2012-06-25 04:16:55 +00:00
`likes` = '%s' ,
`dislikes` = '%s' ,
2010-07-10 23:47:10 +00:00
`about` = '%s' ,
`interest` = '%s' ,
`contact` = '%s' ,
2013-03-20 20:46:43 +00:00
`channels` = '%s' ,
2010-07-10 23:47:10 +00:00
`music` = '%s' ,
`book` = '%s' ,
`tv` = '%s' ,
`film` = '%s' ,
`romance` = '%s' ,
`work` = '%s' ,
2010-08-20 05:04:18 +00:00
`education` = '%s' ,
2012-08-31 01:17:38 +00:00
`hide_friends` = % d
2010-07-01 23:48:07 +00:00
WHERE `id` = % d AND `uid` = % d LIMIT 1 " ,
dbesc ( $profile_name ),
dbesc ( $name ),
2011-01-19 03:25:28 +00:00
dbesc ( $pdesc ),
2010-07-01 23:48:07 +00:00
dbesc ( $gender ),
2010-07-10 23:47:10 +00:00
dbesc ( $dob ),
2010-07-01 23:48:07 +00:00
dbesc ( $address ),
dbesc ( $locality ),
dbesc ( $region ),
dbesc ( $postal_code ),
dbesc ( $country_name ),
dbesc ( $marital ),
2010-12-04 06:46:42 +00:00
dbesc ( $with ),
2012-06-02 09:30:26 +00:00
dbesc ( $howlong ),
2010-07-10 23:47:10 +00:00
dbesc ( $sexual ),
2010-07-01 23:48:07 +00:00
dbesc ( $homepage ),
2012-06-03 03:58:20 +00:00
dbesc ( $hometown ),
2010-07-10 23:47:10 +00:00
dbesc ( $politic ),
dbesc ( $religion ),
2012-12-26 11:49:50 +00:00
dbesc ( $keywords ),
2012-06-25 04:16:55 +00:00
dbesc ( $likes ),
dbesc ( $dislikes ),
2010-07-01 23:48:07 +00:00
dbesc ( $about ),
2010-07-10 23:47:10 +00:00
dbesc ( $interest ),
dbesc ( $contact ),
2013-03-20 20:46:43 +00:00
dbesc ( $channels ),
2010-07-10 23:47:10 +00:00
dbesc ( $music ),
dbesc ( $book ),
dbesc ( $tv ),
dbesc ( $film ),
dbesc ( $romance ),
dbesc ( $work ),
dbesc ( $education ),
2010-08-20 05:04:18 +00:00
intval ( $hide_friends ),
2014-06-18 00:34:51 +00:00
intval ( argv ( 1 )),
2012-04-13 04:10:32 +00:00
intval ( local_user ())
2010-07-01 23:48:07 +00:00
);
if ( $r )
2011-05-23 09:39:57 +00:00
info ( t ( 'Profile updated.' ) . EOL );
2010-07-09 10:10:28 +00:00
2014-06-18 00:34:51 +00:00
$r = q ( " select * from profile where id = %d and uid = %d limit 1 " ,
intval ( argv ( 1 )),
intval ( local_user ())
);
if ( $r ) {
require_once ( 'include/zot.php' );
build_sync_packet ( local_user (), array ( 'profile' => $r ));
}
2012-10-19 22:40:13 +00:00
$channel = $a -> get_channel ();
2010-07-09 10:10:28 +00:00
2010-08-09 04:03:08 +00:00
if ( $namechanged && $is_default ) {
2013-05-18 01:52:15 +00:00
$r = q ( " UPDATE xchan SET xchan_name = '%s', xchan_name_date = '%s' WHERE xchan_hash = '%s' limit 1 " ,
2012-10-19 22:40:13 +00:00
dbesc ( $name ),
2010-08-09 04:03:08 +00:00
dbesc ( datetime_convert ()),
2012-10-19 22:40:13 +00:00
dbesc ( $channel [ 'xchan_hash' ])
2010-08-09 04:03:08 +00:00
);
}
2010-08-20 05:04:18 +00:00
2010-08-19 11:59:31 +00:00
if ( $is_default ) {
2012-12-19 03:10:56 +00:00
proc_run ( 'php' , 'include/directory.php' , local_user ());
2010-08-19 11:59:31 +00:00
}
2010-07-01 23:48:07 +00:00
}
}
function profiles_content ( & $a ) {
2011-01-19 03:25:28 +00:00
2010-10-31 23:38:22 +00:00
$o = '' ;
2010-11-25 00:35:35 +00:00
2014-08-08 01:22:50 +00:00
$channel = $a -> get_channel ();
2014-08-03 06:28:51 +00:00
2010-07-01 23:48:07 +00:00
if ( ! local_user ()) {
2010-08-19 11:59:31 +00:00
notice ( t ( 'Permission denied.' ) . EOL );
2010-07-01 23:48:07 +00:00
return ;
}
2014-08-03 06:28:51 +00:00
require_once ( 'include/identity.php' );
$profile_fields_basic = get_profile_fields_basic ();
$profile_fields_advanced = get_profile_fields_advanced ();
2012-10-19 22:40:13 +00:00
if (( argc () > 1 ) && ( intval ( argv ( 1 )))) {
2010-07-01 23:48:07 +00:00
$r = q ( " SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1 " ,
intval ( $a -> argv [ 1 ]),
2010-11-25 00:35:35 +00:00
intval ( local_user ())
2010-07-01 23:48:07 +00:00
);
if ( ! count ( $r )) {
2010-08-19 11:59:31 +00:00
notice ( t ( 'Profile not found.' ) . EOL );
2010-07-01 23:48:07 +00:00
return ;
}
2010-11-16 05:06:44 +00:00
require_once ( 'include/profile_selectors.php' );
2010-07-01 23:48:07 +00:00
2012-04-11 01:08:06 +00:00
2012-11-05 09:25:08 +00:00
$editselect = 'none' ;
2014-06-28 12:05:34 +00:00
// if(feature_enabled(local_user(),'richtext'))
// $editselect = 'textareas';
2012-04-11 01:08:06 +00:00
$a -> page [ 'htmlhead' ] .= replace_macros ( get_markup_template ( 'profed_head.tpl' ), array (
2012-10-22 00:23:21 +00:00
'$baseurl' => $a -> get_baseurl ( true ),
2012-04-11 01:08:06 +00:00
'$editselect' => $editselect ,
));
2014-08-01 08:24:03 +00:00
$advanced = (( feature_enabled ( local_user (), 'advanced_profiles' )) ? true : false );
2014-08-03 06:28:51 +00:00
if ( $advanced )
$fields = $profile_fields_advanced ;
else
$fields = $profile_fields_basic ;
2010-08-19 11:59:31 +00:00
2012-08-31 01:17:38 +00:00
$opt_tpl = get_markup_template ( " profile-hide_friends.tpl " );
2010-07-11 09:52:47 +00:00
$hide_friends = replace_macros ( $opt_tpl , array (
2012-10-22 00:23:21 +00:00
'$desc' => t ( 'Hide your contact/friend list from viewers of this profile?' ),
'$yes_str' => t ( 'Yes' ),
'$no_str' => t ( 'No' ),
2012-08-31 01:17:38 +00:00
'$yes_selected' => (( $r [ 0 ][ 'hide_friends' ]) ? " checked= \" checked \" " : " " ),
2012-10-22 00:23:21 +00:00
'$no_selected' => (( $r [ 0 ][ 'hide_friends' ] == 0 ) ? " checked= \" checked \" " : " " )
2010-07-11 09:52:47 +00:00
));
2014-08-21 06:01:25 +00:00
$q = q ( " select * from profdef where true " );
if ( $q ) {
$extra_fields = array ();
foreach ( $q as $qq ) {
$mine = q ( " select v from profext where k = '%s' and hash = '%s' and channel_id = %d limit 1 " ,
dbesc ( $qq [ 'field_name' ]),
dbesc ( $r [ 0 ][ 'profile_guid' ]),
intval ( local_user ())
);
if ( array_key_exists ( $qq [ 'field_name' ], $fields )) {
$extra_fields [] = array ( $qq [ 'field_name' ], $qq [ 'field_desc' ],(( $mine ) ? $mine [ 0 ][ 'v' ] : '' ), $qq [ 'field_help' ]);
}
}
}
logger ( 'extra_fields: ' . print_r ( $extra_fields , true ));
2012-04-11 01:08:06 +00:00
2011-07-26 03:59:25 +00:00
$f = get_config ( 'system' , 'birthday_input_format' );
if ( ! $f )
$f = 'ymd' ;
2010-07-10 14:09:57 +00:00
2012-08-31 01:17:38 +00:00
$is_default = (( $r [ 0 ][ 'is_default' ]) ? 1 : 0 );
2011-05-11 11:37:13 +00:00
$tpl = get_markup_template ( " profile_edit.tpl " );
2010-07-01 23:48:07 +00:00
$o .= replace_macros ( $tpl , array (
2012-10-22 00:23:21 +00:00
2012-03-12 20:17:37 +00:00
'$form_security_token' => get_form_security_token ( " profile_edit " ),
2014-07-25 04:29:07 +00:00
'$profile_clone_link' => (( feature_enabled ( local_user (), 'multi_profiles' )) ? 'profiles/clone/' . $r [ 0 ][ 'id' ] . '?t='
. get_form_security_token ( " profile_clone " ) : '' ),
2012-10-22 00:23:21 +00:00
'$profile_drop_link' => 'profiles/drop/' . $r [ 0 ][ 'id' ] . '?t='
. get_form_security_token ( " profile_drop " ),
2014-08-03 06:28:51 +00:00
'$fields' => $fields ,
2013-07-03 09:47:36 +00:00
'$guid' => $r [ 0 ][ 'profile_guid' ],
2012-10-22 00:23:21 +00:00
'$banner' => t ( 'Edit Profile Details' ),
'$submit' => t ( 'Submit' ),
'$viewprof' => t ( 'View this profile' ),
2014-08-03 06:28:51 +00:00
'$editvis' => t ( 'Edit visibility' ),
2012-12-08 19:59:21 +00:00
'$profpic' => t ( 'Change Profile Photo' ),
2012-10-22 00:23:21 +00:00
'$cr_prof' => t ( 'Create a new profile using these settings' ),
'$cl_prof' => t ( 'Clone this profile' ),
'$del_prof' => t ( 'Delete this profile' ),
2014-08-04 23:47:49 +00:00
'$exportable' => feature_enabled ( local_user (), 'profile_export' ),
'$lbl_import' => t ( 'Import profile from file' ),
'$lbl_export' => t ( 'Export profile to file' ),
2011-04-08 06:10:43 +00:00
'$lbl_profname' => t ( 'Profile Name:' ),
'$lbl_fullname' => t ( 'Your Full Name:' ),
2012-10-22 00:23:21 +00:00
'$lbl_title' => t ( 'Title/Description:' ),
'$lbl_gender' => t ( 'Your Gender:' ),
'$lbl_bd' => sprintf ( t ( " Birthday \x28 %s \x29 : " ), datesel_format ( $f )),
'$lbl_address' => t ( 'Street Address:' ),
'$lbl_city' => t ( 'Locality/City:' ),
'$lbl_zip' => t ( 'Postal/Zip Code:' ),
'$lbl_country' => t ( 'Country:' ),
'$lbl_region' => t ( 'Region/State:' ),
'$lbl_marital' => t ( '<span class="heart">♥</span> Marital Status:' ),
'$lbl_with' => t ( " Who: \x28 if applicable \x29 " ),
'$lbl_ex1' => t ( 'Examples: cathy123, Cathy Williams, cathy@example.com' ),
'$lbl_howlong' => t ( 'Since [date]:' ),
'$lbl_sexual' => t ( 'Sexual Preference:' ),
2011-04-08 06:10:43 +00:00
'$lbl_homepage' => t ( 'Homepage URL:' ),
2012-06-03 03:58:20 +00:00
'$lbl_hometown' => t ( 'Hometown:' ),
2012-10-22 00:23:21 +00:00
'$lbl_politic' => t ( 'Political Views:' ),
2011-04-08 06:10:43 +00:00
'$lbl_religion' => t ( 'Religious Views:' ),
2012-12-26 11:49:50 +00:00
'$lbl_pubkey' => t ( 'Keywords:' ),
2012-10-22 00:23:21 +00:00
'$lbl_likes' => t ( 'Likes:' ),
2012-06-25 04:16:55 +00:00
'$lbl_dislikes' => t ( 'Dislikes:' ),
2012-10-22 00:23:21 +00:00
'$lbl_ex2' => t ( 'Example: fishing photography software' ),
2012-12-26 11:49:50 +00:00
'$lbl_pubdsc' => t ( " Used in directory listings " ),
2012-10-22 00:23:21 +00:00
'$lbl_about' => t ( 'Tell us about yourself...' ),
'$lbl_hobbies' => t ( 'Hobbies/Interests' ),
'$lbl_social' => t ( 'Contact information and Social Networks' ),
2013-03-20 20:46:43 +00:00
'$lbl_channels' => t ( 'My other channels' ),
2012-10-22 00:23:21 +00:00
'$lbl_music' => t ( 'Musical interests' ),
'$lbl_book' => t ( 'Books, literature' ),
'$lbl_tv' => t ( 'Television' ),
'$lbl_film' => t ( 'Film/dance/culture/entertainment' ),
'$lbl_love' => t ( 'Love/romance' ),
'$lbl_work' => t ( 'Work/employment' ),
'$lbl_school' => t ( 'School/education' ),
'$disabled' => (( $is_default ) ? 'onclick="return false;" style="color: #BBBBFF;"' : '' ),
'$baseurl' => $a -> get_baseurl ( true ),
'$profile_id' => $r [ 0 ][ 'id' ],
2012-08-27 08:22:08 +00:00
'$profile_name' => $r [ 0 ][ 'profile_name' ],
2014-08-08 01:22:50 +00:00
'$is_default' => $is_default ,
'$default' => t ( 'This is your default profile.' ) . EOL . translate_scope ( map_scope ( $channel [ 'channel_r_profile' ])),
2014-08-01 08:24:03 +00:00
'$advanced' => $advanced ,
2012-10-22 00:23:21 +00:00
'$name' => $r [ 0 ][ 'name' ],
'$pdesc' => $r [ 0 ][ 'pdesc' ],
'$dob' => dob ( $r [ 0 ][ 'dob' ]),
2010-07-11 09:52:47 +00:00
'$hide_friends' => $hide_friends ,
2012-10-22 00:23:21 +00:00
'$address' => $r [ 0 ][ 'address' ],
'$locality' => $r [ 0 ][ 'locality' ],
'$region' => $r [ 0 ][ 'region' ],
'$postal_code' => $r [ 0 ][ 'postal_code' ],
2012-08-31 01:17:38 +00:00
'$country_name' => $r [ 0 ][ 'country_name' ],
2012-10-22 00:23:21 +00:00
'$age' => (( intval ( $r [ 0 ][ 'dob' ])) ? '(' . t ( 'Age: ' ) . age ( $r [ 0 ][ 'dob' ], $a -> user [ 'timezone' ], $a -> user [ 'timezone' ]) . ')' : '' ),
'$gender' => gender_selector ( $r [ 0 ][ 'gender' ]),
2014-08-01 08:24:03 +00:00
'$gender_min' => gender_selector_min ( $r [ 0 ][ 'gender' ]),
2012-10-22 00:23:21 +00:00
'$marital' => marital_selector ( $r [ 0 ][ 'marital' ]),
2014-08-01 08:24:03 +00:00
'$marital_min' => marital_selector_min ( $r [ 0 ][ 'marital' ]),
2014-04-21 01:48:21 +00:00
'$with' => $r [ 0 ][ 'with' ],
2014-09-09 03:35:15 +00:00
'$howlong' => ( $r [ 0 ][ 'howlong' ] === NULL_DATE ? '' : datetime_convert ( 'UTC' , date_default_timezone_get (), $r [ 0 ][ 'howlong' ])),
2012-10-22 00:23:21 +00:00
'$sexual' => sexpref_selector ( $r [ 0 ][ 'sexual' ]),
2014-08-01 08:24:03 +00:00
'$sexual_min' => sexpref_selector_min ( $r [ 0 ][ 'sexual' ]),
2012-10-22 00:23:21 +00:00
'$about' => $r [ 0 ][ 'about' ],
'$homepage' => $r [ 0 ][ 'homepage' ],
'$hometown' => $r [ 0 ][ 'hometown' ],
'$politic' => $r [ 0 ][ 'politic' ],
'$religion' => $r [ 0 ][ 'religion' ],
2012-12-26 11:49:50 +00:00
'$keywords' => $r [ 0 ][ 'keywords' ],
2012-10-22 00:23:21 +00:00
'$likes' => $r [ 0 ][ 'likes' ],
'$dislikes' => $r [ 0 ][ 'dislikes' ],
'$music' => $r [ 0 ][ 'music' ],
'$book' => $r [ 0 ][ 'book' ],
'$tv' => $r [ 0 ][ 'tv' ],
'$film' => $r [ 0 ][ 'film' ],
'$interest' => $r [ 0 ][ 'interest' ],
'$romance' => $r [ 0 ][ 'romance' ],
'$work' => $r [ 0 ][ 'work' ],
'$education' => $r [ 0 ][ 'education' ],
2013-03-20 20:46:43 +00:00
'$contact' => $r [ 0 ][ 'contact' ],
'$channels' => $r [ 0 ][ 'channels' ],
2014-08-21 06:01:25 +00:00
'$extra_fields' => $extra_fields ,
2010-07-01 23:48:07 +00:00
));
2011-01-20 23:30:45 +00:00
$arr = array ( 'profile' => $r [ 0 ], 'entry' => $o );
call_hooks ( 'profile_edit' , $arr );
2010-07-01 23:48:07 +00:00
return $o ;
}
else {
2012-06-18 19:18:43 +00:00
$r = q ( " SELECT * FROM `profile` WHERE `uid` = %d " ,
2010-11-25 00:35:35 +00:00
local_user ());
2010-07-01 23:48:07 +00:00
if ( count ( $r )) {
2011-05-11 11:37:13 +00:00
$tpl_header = get_markup_template ( 'profile_listing_header.tpl' );
2011-04-08 01:00:35 +00:00
$o .= replace_macros ( $tpl_header , array (
2011-11-03 22:14:33 +00:00
'$header' => t ( 'Edit/Manage Profiles' ),
2013-12-30 23:41:42 +00:00
'$addstuff' => t ( 'Add profile things' ),
'$stuff_desc' => t ( 'Include desirable objects in your profile' ),
2011-04-08 01:00:35 +00:00
'$chg_photo' => t ( 'Change profile photo' ),
2012-03-12 20:17:37 +00:00
'$cr_new' => t ( 'Create New Profile' ),
'$cr_new_link' => 'profiles/new?t=' . get_form_security_token ( " profile_new " )
2011-04-08 01:00:35 +00:00
));
2011-05-11 11:37:13 +00:00
$tpl = get_markup_template ( 'profile_entry.tpl' );
2010-07-01 23:48:07 +00:00
foreach ( $r as $rr ) {
2011-04-13 04:21:33 +00:00
$o .= replace_macros ( $tpl , array (
2013-01-22 08:20:25 +00:00
'$photo' => $rr [ 'thumb' ],
2010-07-01 23:48:07 +00:00
'$id' => $rr [ 'id' ],
2011-01-12 20:44:22 +00:00
'$alt' => t ( 'Profile Image' ),
2012-08-27 08:22:08 +00:00
'$profile_name' => $rr [ 'profile_name' ],
2012-10-22 00:23:21 +00:00
'$visible' => (( $rr [ 'is_default' ])
2014-08-08 01:47:09 +00:00
? '<strong>' . translate_scope ( map_scope ( $channel [ 'channel_r_profile' ])) . '</strong>'
2012-03-15 04:20:20 +00:00
: '<a href="' . $a -> get_baseurl ( true ) . '/profperm/' . $rr [ 'id' ] . '" />' . t ( 'Edit visibility' ) . '</a>' )
2010-07-01 23:48:07 +00:00
));
}
}
return $o ;
}
2011-05-23 09:39:57 +00:00
}