+ $itemuid = $r[0]["uid"];
+ }
+ }
+ if (count($r)) {
+ if ($r[0]["id"] != $r[0]["parent"])
+ $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network` FROM `item`
+ WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
+ AND `id` = %d", $r[0]["parent"]);
+
+ if (!strstr(normalise_link($r[0]["author-link"]), normalise_link($a->get_baseurl()))) {
+ require_once("mod/proxy.php");
+ require_once("include/bbcode.php");
+ $profiledata["uid"] = -1;
+ $profiledata["nickname"] = $r[0]["author-name"];
+ $profiledata["name"] = $r[0]["author-name"];
+ $profiledata["picdate"] = "";
+ $profiledata["photo"] = proxy_url($r[0]["author-avatar"]);
+ $profiledata["url"] = $r[0]["author-link"];
+ $profiledata["network"] = $r[0]["network"];
+
+ // Fetching profile data from unique contacts
+ // To-do: Extend "unique contacts" table for further contact data like location, ...
+ $r = q("SELECT `avatar`, `nick` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"]));
+ if (count($r)) {
+ $profiledata["photo"] = proxy_url($r[0]["avatar"]);
+ if ($r[0]["nick"] != "")
+ $profiledata["nickname"] = $r[0]["nick"];
+ } else {
+ // Is this case possible?
+ // Fetching further contact data from the contact table, when it isn't available in the "unique contacts"
+ $r = q("SELECT `photo`, `nick` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
+ normalise_link($profiledata["url"]), $itemuid);
+ if (count($r)) {
+ $profiledata["photo"] = proxy_url($r[0]["photo"]);
+ if ($r[0]["nick"] != "")
+ $profiledata["nickname"] = $r[0]["nick"];
+ }
+ }
+
+ if (local_user()) {
+ if ($profiledata["network"] == NETWORK_DFRN) {
+ $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"])."&addr=".bin2hex($a->get_baseurl()."/profile/".$a->user["nickname"]);
+ $profiledata["remoteconnect"] = $connect;
+ } elseif ($profiledata["network"] == NETWORK_DIASPORA)
+ $profiledata["remoteconnect"] = $a->get_baseurl()."/contacts?add=".GetProfileUsername($profiledata["url"], "", true);
+ } elseif ($profiledata["network"] == NETWORK_DFRN) {
+ $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
+ $profiledata["remoteconnect"] = $connect;
+ }
+ } else {
+ $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($r[0]["author-link"]));
+
+ if (($nickname != $a->user["nickname"])) {
+ $profiledata["url"] = $r[0]["author-link"];
+
+ $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `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)
+ );
+ if (count($r))
+ $profiledata = $r[0];
+ $profiledata["network"] = NETWORK_DFRN;
+ }
+ }