+/**
+ * @brief Get all profil data of a local user
+ * If the viewer is an authenticated remote viewer, the profile displayed is the
+ * one that has been configured for his/her viewing in the Contact manager.
+ * Passing a non-zero profile ID can also allow a preview of a selected profile
+ * by the owner
+ *
+ * @param string $nickname
+ * @param int $uid
+ * @param int $profile
+ * ID of the profile
+ * @returns array
+ * Includes all available profile data
+ */
+function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) {
+ if(remote_user() && count($_SESSION['remote'])) {
+ foreach($_SESSION['remote'] as $visitor) {
+ if($visitor['uid'] == $uid) {
+ $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1",
+ intval($visitor['cid'])
+ );
+ if(count($r))
+ $profile = $r[0]['profile-id'];
+ break;
+ }
+ }
+ }
+
+ $r = null;
+
+ if($profile) {
+ $profile_int = intval($profile);
+ $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.* FROM `profile`
+ INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
+ WHERE `user`.`nickname` = '%s' AND `profile`.`id` = %d AND `contact`.`self` = 1 LIMIT 1",
+ dbesc($nickname),
+ intval($profile_int)
+ );
+ }
+ if((!$r) && (!count($r))) {
+ $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.* FROM `profile`
+ INNER JOIN `contact` ON `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
+ WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 AND `contact`.`self` = 1 LIMIT 1",
+ dbesc($nickname)
+ );
+ }
+
+ return $r[0];
+
+}
+
+