+}
+
+/**
+ * @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
+ *
+ * @param string $email
+ * @param string $sitename
+ * @param string $username
+ * @return NULL|boolean from notification() and email() inherited
+ */
+function send_register_pending_eml($email, $sitename, $username) {
+ $body = deindent(t('
+ Dear %1$s,
+ Thank you for registering at %2$s. Your account is pending for approval by the administrator.
+ '));
+
+ $body = sprintf($body, $username, $sitename);
+
+ return notification(array(
+ 'type' => "SYSTEM_EMAIL",
+ 'to_email' => $email,
+ 'subject'=> sprintf( t('Registration at %s'), $sitename),
+ 'body' => $body));
+}
+
+/*
+ * send registration confirmation.
+ * It's here as a function because the mail is sent
+ * from different parts
+ */
+function send_register_open_eml($email, $sitename, $siteurl, $username, $password){
+ $preamble = deindent(t('
+ Dear %1$s,
+ Thank you for registering at %2$s. Your account has been created.
+ '));
+ $body = deindent(t('
+ The login details are as follows:
+ Site Location: %3$s
+ Login Name: %1$s
+ Password: %5$s
+
+ You may change your password from your account "Settings" page after logging
+ in.
+
+ Please take a few moments to review the other account settings on that page.
+
+ You may also wish to add some basic information to your default profile
+ (on the "Profiles" page) so that other people can easily find you.
+
+ We recommend setting your full name, adding a profile photo,
+ adding some profile "keywords" (very useful in making new friends) - and
+ perhaps what country you live in; if you do not wish to be more specific
+ than that.
+
+ We fully respect your right to privacy, and none of these items are necessary.
+ If you are new and do not know anybody here, they may help
+ you to make some new and interesting friends.
+
+
+ Thank you and welcome to %2$s.'));
+
+ $preamble = sprintf($preamble, $username, $sitename);
+ $body = sprintf($body, $email, $sitename, $siteurl, $username, $password);
+
+ return notification(array(
+ 'type' => "SYSTEM_EMAIL",
+ 'to_email' => $email,
+ 'subject'=> sprintf( t('Registration details for %s'), $sitename),
+ 'preamble'=> $preamble,
+ 'body' => $body));
+}