+/**
+ * @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())
+ );
+}