+ $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
+
+ // linkify the relationship target if applicable
+
+ if(strlen($with)) {
+ if($with != strip_tags($orig[0]['with'])) {
+ $prf = '';
+ $lookup = $with;
+ if(strpos($lookup,'@') === 0)
+ $lookup = substr($lookup,1);
+ $lookup = str_replace('_',' ', $lookup);
+ if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
+ $newname = $lookup;
+ $links = @lrdd($lookup);
+ if(count($links)) {
+ foreach($links as $link) {
+ if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
+ $prf = $link['@attributes']['href'];
+ }
+ }
+ }
+ }
+ else {
+ $newname = $lookup;
+ if(strstr($lookup,' ')) {
+ $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($newname),
+ intval(local_user())
+ );
+ }
+ else {
+ $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($lookup),
+ intval(local_user())
+ );
+ }
+ if(count($r)) {
+ $prf = $r[0]['url'];
+ $newname = $r[0]['name'];
+ }
+ }
+
+ if($prf) {
+ $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
+ if(strpos($with,'@') === 0)
+ $with = substr($with,1);
+ }
+ }
+ else
+ $with = $orig[0]['with'];
+ }
+