X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fuser.php;h=df871c5468ac7d3abb7087adb87635b453633d25;hb=2ff494d899f239e6005a073b503d5c24b77119eb;hp=7e97a1ddf2ff9d72ee6c0685bdd7a1f84ced9d9a;hpb=a905522eb58612dfc9e4479998de2bd6477b3868;p=friendica.git diff --git a/include/user.php b/include/user.php index 7e97a1ddf2..df871c5468 100644 --- a/include/user.php +++ b/include/user.php @@ -216,7 +216,7 @@ function create_user($arr) { dbesc($default_service_class) ); - if($r) { + if ($r) { $r = q("SELECT * FROM `user` WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", dbesc($username), @@ -241,7 +241,7 @@ function create_user($arr) { WHERE `nickname` = '%s' ", dbesc($nickname) ); - if((count($r) > 1) && $newuid) { + if ((dbm::is_result($r)) && (count($r) > 1) && $newuid) { $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; q("DELETE FROM `user` WHERE `uid` = %d", intval($newuid) @@ -262,35 +262,16 @@ function create_user($arr) { intval($netpublish) ); - if($r === false) { + if ($r === false) { $result['message'] .= t('An error occurred creating your default profile. Please try again.') . EOL; // Start fresh next time. $r = q("DELETE FROM `user` WHERE `uid` = %d", intval($newuid)); return $result; } - $r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`, - `addr`, `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness` ) - VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0 ) ", - intval($newuid), - datetime_convert(), - dbesc($username), - dbesc($nickname), - dbesc(z_root() . "/photo/profile/{$newuid}.jpg"), - dbesc(z_root() . "/photo/avatar/{$newuid}.jpg"), - dbesc(z_root() . "/photo/micro/{$newuid}.jpg"), - dbesc(z_root() . "/profile/$nickname"), - dbesc(normalise_link(z_root() . "/profile/$nickname")), - dbesc($nickname . '@' . substr(z_root(), strpos(z_root(),'://') + 3 )), - dbesc(z_root() . "/dfrn_request/$nickname"), - dbesc(z_root() . "/dfrn_notify/$nickname"), - dbesc(z_root() . "/dfrn_poll/$nickname"), - dbesc(z_root() . "/dfrn_confirm/$nickname"), - dbesc(z_root() . "/poco/$nickname"), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()) - ); + + // Create the self contact + user_create_self_contact($newuid); // Create a group with no members. This allows somebody to use it // right away as a default group for new contacts. @@ -344,24 +325,27 @@ function create_user($arr) { $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } $img->scaleImage(80); $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } $img->scaleImage(48); $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } - if(! $photo_failure) { + if (! $photo_failure) { q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ", dbesc($hash) ); @@ -377,6 +361,49 @@ function create_user($arr) { } +/** + * @brief create the "self" contact from data from the user table + * + * @param integer $uid + */ +function user_create_self_contact($uid) { + + // Only create the entry if it doesn't exist yet + $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid)); + if (dbm::is_result($r)) { + return; + } + + $r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `uid` = %d", intval($uid)); + if (!dbm::is_result($r)) { + return; + } + + $user = $r[0]; + + q("INSERT INTO `contact` (`uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`, + `addr`, `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness`) + VALUES (%d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0)", + intval($user['uid']), + datetime_convert(), + dbesc($user['username']), + dbesc($user['nickname']), + dbesc(z_root()."/photo/profile/".$user['uid'].".jpg"), + dbesc(z_root()."/photo/avatar/".$user['uid'].".jpg"), + dbesc(z_root()."/photo/micro/".$user['uid'].".jpg"), + dbesc(z_root()."/profile/".$user['nickname']), + dbesc(normalise_link(z_root()."/profile/".$user['nickname'])), + dbesc($user['nickname'].'@'.substr(z_root(), strpos(z_root(),'://') + 3)), + dbesc(z_root()."/dfrn_request/".$user['nickname']), + dbesc(z_root()."/dfrn_notify/".$user['nickname']), + dbesc(z_root()."/dfrn_poll/".$user['nickname']), + dbesc(z_root()."/dfrn_confirm/".$user['nickname']), + dbesc(z_root()."/poco/".$user['nickname']), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(datetime_convert()) + ); +} /** * @brief send registration confiŕmation with the intormation that reg is pending