+ if($item_id) {
+ $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ intval($item_id),
+ intval(local_user())
+ );
+ }
+ if(count($r)) {
+ $old_tag = $r[0]['tag'];
+ $old_inform = $r[0]['inform'];
+ }
+
+ if(strlen($rawtags)) {
+
+ $str_tags = '';
+ $inform = '';
+
+ // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
+
+ $x = substr($rawtags,0,1);
+ if($x !== '@' && $x !== '#')
+ $rawtags = '#' . $rawtags;
+
+ $taginfo = array();
+ $tags = get_tags($rawtags);
+
+ if(count($tags)) {
+ foreach($tags as $tag) {
+ if(strpos($tag,'@') === 0) {
+ $name = substr($tag,1);
+ if((strpos($name,'@')) || (strpos($name,'http://'))) {
+ $newname = $name;
+ $links = @lrdd($name);
+ if(count($links)) {
+ foreach($links as $link) {
+ if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
+ $profile = $link['@attributes']['href'];
+ if($link['@attributes']['rel'] === 'salmon') {
+ $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
+ if(strlen($inform))
+ $inform .= ',';
+ $inform .= $salmon;
+ }
+ }
+ }
+ $taginfo[] = array($newname,$profile,$salmon);
+ }
+ else {
+ $newname = $name;
+ if(strstr($name,'_')) {
+ $newname = str_replace('_',' ',$name);
+ $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($name),
+ intval(local_user())
+ );
+ }
+ if(count($r)) {
+ $newname = $r[0]['name'];
+ $profile = $r[0]['url'];
+ $notify = 'cid:' . $r[0]['id'];
+ if(strlen($inform))
+ $inform .= ',';
+ $inform .= $notify;
+ }
+ }
+ if($profile) {
+ if(substr($notify,0,4) === 'cid:')
+ $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
+ else
+ $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
+ if(strlen($str_tags))
+ $str_tags .= ',';
+ $profile = str_replace(',','%2c',$profile);
+ $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
+ }
+ }
+ }
+ }
+
+ $newtag = $old_tag;
+ if(strlen($newtag) && strlen($str_tags))
+ $newtag .= ',';
+ $newtag .= $str_tags;
+
+ $newinform = $old_inform;
+ if(strlen($newinform) && strlen($inform))
+ $newinform .= ',';
+ $newinform .= $inform;
+
+ $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ dbesc($newtag),
+ dbesc($newinform),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ intval($item_id),
+ intval(local_user())
+ );
+
+ $best = 0;
+ foreach($p as $scales) {
+ if(intval($scales['scale']) == 2) {
+ $best = 2;
+ break;
+ }
+ if(intval($scales['scale']) == 4) {
+ $best = 4;
+ break;
+ }
+ }