diff options
author | zotlabs <mike@macgirvin.com> | 2018-04-24 15:32:24 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2018-04-24 15:32:24 -0700 |
commit | 8face5a66c82e7086c379ca4b07f178a85a781b3 (patch) | |
tree | f617c210b1abb8bb8790c8a7aeb8c677d20d5f5d | |
parent | a6c42e875633e8e67bbf93425182cce4de3eb653 (diff) | |
download | volse-hubzilla-8face5a66c82e7086c379ca4b07f178a85a781b3.tar.gz volse-hubzilla-8face5a66c82e7086c379ca4b07f178a85a781b3.tar.bz2 volse-hubzilla-8face5a66c82e7086c379ca4b07f178a85a781b3.zip |
make tag autocomplete less scary looking in the editor. If this works out we can simplify and get rid of a huge amount of spaghetti tag logic.
-rw-r--r-- | Zotlabs/Module/Acl.php | 4 | ||||
-rw-r--r-- | include/text.php | 112 | ||||
-rw-r--r-- | view/js/autocomplete.js | 7 |
3 files changed, 77 insertions, 46 deletions
diff --git a/Zotlabs/Module/Acl.php b/Zotlabs/Module/Acl.php index 4c5883e88..35594ae9f 100644 --- a/Zotlabs/Module/Acl.php +++ b/Zotlabs/Module/Acl.php @@ -354,7 +354,7 @@ class Acl extends \Zotlabs\Web\Controller { "name" => $g['name'] . (($type === 'f') ? '' : '+'), "id" => urlencode($g['id']) . (($type === 'f') ? '' : '+'), "xid" => $g['hash'], - "link" => $g['nick'], + "link" => (($g['nick']) ? $g['nick'] : $g['url']), "nick" => substr($g['nick'],0,strpos($g['nick'],'@')), "self" => (intval($g['abook_self']) ? 'abook-self' : ''), "taggable" => 'taggable', @@ -368,7 +368,7 @@ class Acl extends \Zotlabs\Web\Controller { "name" => $g['name'], "id" => urlencode($g['id']), "xid" => $g['hash'], - "link" => $g['nick'], + "link" => (($g['nick']) ? $g['nick'] : $g['url']), "nick" => (($g['nick']) ? substr($g['nick'],0,strpos($g['nick'],'@')) : $g['nick']), "self" => (intval($g['abook_self']) ? 'abook-self' : ''), "taggable" => '', diff --git a/include/text.php b/include/text.php index 411576fa6..4d6d0ffb5 100644 --- a/include/text.php +++ b/include/text.php @@ -822,6 +822,14 @@ function get_tags($s) { } } + // match bracket mentions + + if(preg_match_all('/([@!]\{.*?\})/',$s,$match)) { + foreach($match[1] as $mtch) { + $ret[] = $mtch; + } + } + // Match full names against @tags including the space between first and last // We will look these up afterward to see if they are full names or not recognisable. @@ -2029,18 +2037,33 @@ function undo_post_tagging($s) { $cnt = preg_match_all('/([@#])(\!*)\[zrl=(.*?)\](.*?)\[\/zrl\]/ism',$s,$matches,PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { - $s = str_replace($mtch[0], $mtch[1] . $mtch[2] . quote_tag($mtch[4]),$s); + $x = q("select xchan_addr, xchan_url from xchan where xchan_url = '%s' limit 1", + dbesc($mtch[3]) + ); + if($x) { + $s = str_replace($mtch[0], $mtch[1] . $mtch[2] . '{' . (($x[0]['xchan_addr']) ? $x[0]['xchan_addr'] : $x[0]['xchan_url']) . '}', $s); + } + else { + $s = str_replace($mtch[0], $mtch[1] . $mtch[2] . quote_tag($mtch[4]),$s); + } } } // undo forum tags $cnt = preg_match_all('/\!\[zrl=(.*?)\](.*?)\[\/zrl\]/ism',$s,$matches,PREG_SET_ORDER); if($cnt) { foreach($matches as $mtch) { - $s = str_replace($mtch[0], '!' . quote_tag($mtch[2]),$s); + $x = q("select xchan_addr, xchan_url from xchan where xchan_url = '%s' limit 1", + dbesc($mtch[1]) + ); + if($x) { + $s = str_replace($mtch[0], '!' . '{' . (($x[0]['xchan_addr']) ? $x[0]['xchan_addr'] : $x[0]['xchan_url']) . '}', $s); + } + else { + $s = str_replace($mtch[0], '!' . quote_tag($mtch[2]),$s); + } } } - return $s; } @@ -2615,53 +2638,66 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $d $forum = false; $trailing_plus_name = false; - // @channel+ is a forum or network delivery tag - - if(substr($newname,-1,1) === '+') { - $forum = true; + if(substr($name,0,1) === '{' && substr($name,-1,1) === '}') { + $newname = substr($name,1); $newname = substr($newname,0,-1); + + $r = q("select * from xchan where xchan_addr = '%s' or xchan_url = '%s' limit 1", + dbesc($newname), + dbesc($newname) + ); } - // Here we're looking for an address book entry as provided by the auto-completer - // of the form something+nnn where nnn is an abook_id or the first chars of xchan_hash + if(! $r) { + // @channel+ is a forum or network delivery tag - // If there's a +nnn in the string make sure there isn't a space preceding it + if(substr($newname,-1,1) === '+') { + $forum = true; + $newname = substr($newname,0,-1); + } - $t1 = strpos($newname,' '); - $t2 = strrpos($newname,'+'); + // Here we're looking for an address book entry as provided by the auto-completer + // of the form something+nnn where nnn is an abook_id or the first chars of xchan_hash - if($t1 && $t2 && $t1 < $t2) - $t2 = 0; - if(($t2) && (! $diaspora)) { - //get the id + // If there's a +nnn in the string make sure there isn't a space preceding it - $tagcid = urldecode(substr($newname,$t2 + 1)); + $t1 = strpos($newname,' '); + $t2 = strrpos($newname,'+'); + + if($t1 && $t2 && $t1 < $t2) + $t2 = 0; - if(strrpos($tagcid,' ')) - $tagcid = substr($tagcid,0,strrpos($tagcid,' ')); + if(($t2) && (! $diaspora)) { + //get the id - if(strlen($tagcid) < 16) - $abook_id = intval($tagcid); - //remove the next word from tag's name - if(strpos($name,' ')) { - $name = substr($name,0,strpos($name,' ')); - } + $tagcid = urldecode(substr($newname,$t2 + 1)); - if($abook_id) { // if there was an id - // select channel with that id from the logged in user's address book - $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_id = %d AND abook_channel = %d LIMIT 1", - intval($abook_id), - intval($profile_uid) - ); - } - else { - $r = q("SELECT * FROM xchan - WHERE xchan_hash like '%s%%' LIMIT 1", - dbesc($tagcid) - ); + if(strrpos($tagcid,' ')) + $tagcid = substr($tagcid,0,strrpos($tagcid,' ')); + + if(strlen($tagcid) < 16) + $abook_id = intval($tagcid); + //remove the next word from tag's name + if(strpos($name,' ')) { + $name = substr($name,0,strpos($name,' ')); + } + + if($abook_id) { // if there was an id + // select channel with that id from the logged in user's address book + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash + WHERE abook_id = %d AND abook_channel = %d LIMIT 1", + intval($abook_id), + intval($profile_uid) + ); + } + else { + $r = q("SELECT * FROM xchan + WHERE xchan_hash like '%s%%' LIMIT 1", + dbesc($tagcid) + ); + } } } diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js index be632a07e..76c3fb69e 100644 --- a/view/js/autocomplete.js +++ b/view/js/autocomplete.js @@ -84,13 +84,8 @@ function editor_replace(item) { } // $2 ensures that prefix (@,@!) is preserved - var id = item.id; - // 16 chars of hash should be enough. Full hash could be used if it can be done in a visually appealing way. - // 16 chars is also the minimum length in the backend (otherwise it's interpreted as a local id). - if(id.length > 16) - id = item.id.substring(0,16); - return '$1$2' + item.nick.replace(' ', '') + '+' + id + ' '; + return '$1$2{' + item.link + '} '; } function basic_replace(item) { |