Merge branch 'tagging'

This commit is contained in:
zotlabs 2017-09-24 19:50:55 -07:00
commit b195407028
7 changed files with 119 additions and 48 deletions

View File

@ -33,6 +33,7 @@ class Acl extends \Zotlabs\Web\Controller {
// $type = // $type =
// '' => standard ACL request // '' => standard ACL request
// 'g' => Groups only ACL request // 'g' => Groups only ACL request
// 'f' => forums only ACL request
// 'c' => Connections only ACL request or editor (textarea) mention request // 'c' => Connections only ACL request or editor (textarea) mention request
// $_REQUEST['search'] contains ACL search text. // $_REQUEST['search'] contains ACL search text.
@ -56,12 +57,12 @@ class Acl extends \Zotlabs\Web\Controller {
$search = $_REQUEST['query']; $search = $_REQUEST['query'];
} }
if( (! local_channel()) && (! ($type == 'x' || $type == 'c'))) if( (! local_channel()) && (! in_array($type, [ 'x', 'c', 'f' ])))
killme(); killme();
$permitted = []; $permitted = [];
if(in_array($type, [ 'm', 'a', 'c' ])) { if(in_array($type, [ 'm', 'a', 'c', 'f' ])) {
// These queries require permission checking. We'll create a simple array of xchan_hash for those with // These queries require permission checking. We'll create a simple array of xchan_hash for those with
// the requisite permissions which we can check against. // the requisite permissions which we can check against.
@ -154,7 +155,7 @@ class Acl extends \Zotlabs\Web\Controller {
} }
} }
if($type == '' || $type == 'c') { if($type == '' || $type == 'c' || $type === 'f') {
$extra_channels_sql = ''; $extra_channels_sql = '';
@ -336,12 +337,12 @@ class Acl extends \Zotlabs\Web\Controller {
$g['nick'] = $t[0] . '@'; $g['nick'] = $t[0] . '@';
} }
if(in_array($g['hash'],$permitted) && $type == 'c' && (! $noforums)) { if(in_array($g['hash'],$permitted) && in_array($type, [ 'c', 'f' ]) && (! $noforums)) {
$contacts[] = array( $contacts[] = array(
"type" => "c", "type" => "c",
"photo" => "images/twopeople.png", "photo" => "images/twopeople.png",
"name" => $g['name'] . '+', "name" => $g['name'] . (($type === 'f') ? '' : '+'),
"id" => $g['id'] . '+', "id" => $g['id'] . (($type === 'f') ? '' : '+'),
"xid" => $g['hash'], "xid" => $g['hash'],
"link" => $g['nick'], "link" => $g['nick'],
"nick" => substr($g['nick'],0,strpos($g['nick'],'@')), "nick" => substr($g['nick'],0,strpos($g['nick'],'@')),
@ -350,18 +351,20 @@ class Acl extends \Zotlabs\Web\Controller {
"label" => t('network') "label" => t('network')
); );
} }
$contacts[] = array( if($type !== 'f') {
"type" => "c", $contacts[] = array(
"photo" => $g['micro'], "type" => "c",
"name" => $g['name'], "photo" => $g['micro'],
"id" => $g['id'], "name" => $g['name'],
"xid" => $g['hash'], "id" => $g['id'],
"link" => $g['nick'], "xid" => $g['hash'],
"nick" => (($g['nick']) ? substr($g['nick'],0,strpos($g['nick'],'@')) : $g['nick']), "link" => $g['nick'],
"self" => (intval($g['abook_self']) ? 'abook-self' : ''), "nick" => (($g['nick']) ? substr($g['nick'],0,strpos($g['nick'],'@')) : $g['nick']),
"taggable" => '', "self" => (intval($g['abook_self']) ? 'abook-self' : ''),
"label" => '', "taggable" => '',
); "label" => '',
);
}
} }
} }

View File

@ -425,6 +425,7 @@ define ( 'TERM_THING', 7 );
define ( 'TERM_BOOKMARK', 8 ); define ( 'TERM_BOOKMARK', 8 );
define ( 'TERM_HIERARCHY', 9 ); define ( 'TERM_HIERARCHY', 9 );
define ( 'TERM_COMMUNITYTAG', 10 ); define ( 'TERM_COMMUNITYTAG', 10 );
define ( 'TERM_FORUM', 11 );
define ( 'TERM_OBJ_POST', 1 ); define ( 'TERM_OBJ_POST', 1 );
define ( 'TERM_OBJ_PHOTO', 2 ); define ( 'TERM_OBJ_PHOTO', 2 );

View File

@ -1130,7 +1130,7 @@ function encode_item_xchan($xchan) {
function encode_item_terms($terms,$mirror = false) { function encode_item_terms($terms,$mirror = false) {
$ret = array(); $ret = array();
$allowed_export_terms = array( TERM_UNKNOWN, TERM_HASHTAG, TERM_MENTION, TERM_CATEGORY, TERM_BOOKMARK, TERM_COMMUNITYTAG ); $allowed_export_terms = array( TERM_UNKNOWN, TERM_HASHTAG, TERM_MENTION, TERM_CATEGORY, TERM_BOOKMARK, TERM_COMMUNITYTAG, TERM_FORUM );
if($mirror) { if($mirror) {
$allowed_export_terms[] = TERM_PCATEGORY; $allowed_export_terms[] = TERM_PCATEGORY;
@ -1178,7 +1178,7 @@ function decode_item_meta($meta) {
* @return string * @return string
*/ */
function termtype($t) { function termtype($t) {
$types = array('unknown','hashtag','mention','category','private_category','file','search','thing','bookmark', 'hierarchy', 'communitytag'); $types = array('unknown','hashtag','mention','category','private_category','file','search','thing','bookmark', 'hierarchy', 'communitytag', 'forum');
return(($types[$t]) ? $types[$t] : 'unknown'); return(($types[$t]) ? $types[$t] : 'unknown');
} }
@ -1227,6 +1227,9 @@ function decode_tags($t) {
case 'communitytag': case 'communitytag':
$tag['ttype'] = TERM_COMMUNITYTAG; $tag['ttype'] = TERM_COMMUNITYTAG;
break; break;
case 'forum':
$tag['ttype'] = TERM_FORUM;
break;
default: default:
case 'unknown': case 'unknown':
$tag['ttype'] = TERM_UNKNOWN; $tag['ttype'] = TERM_UNKNOWN;
@ -2457,7 +2460,7 @@ function tag_deliver($uid, $item_id) {
* Now we've got those out of the way. Let's see if this is a post that's tagged for re-delivery * Now we've got those out of the way. Let's see if this is a post that's tagged for re-delivery
*/ */
$terms = get_terms_oftype($item['term'],TERM_MENTION); $terms = array_merge(get_terms_oftype($item['term'],TERM_MENTION),get_terms_oftype($item['term'],TERM_FORUM));
if($terms) if($terms)
logger('tag_deliver: post mentions: ' . print_r($terms,true), LOGGER_DATA); logger('tag_deliver: post mentions: ' . print_r($terms,true), LOGGER_DATA);
@ -2492,25 +2495,46 @@ function tag_deliver($uid, $item_id) {
$plustagged = false; $plustagged = false;
$matches = array(); $matches = array();
$pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'],'/') . '\[\/zrl\]/'; $pattern = '/[\!@]\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'],'/') . '\[\/zrl\]/';
if(preg_match($pattern,$body,$matches)) if(preg_match($pattern,$body,$matches))
$tagged = true; $tagged = true;
$pattern = '/@\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\+\[\/zrl\]/'; // original red forum tagging sequence @forumname+
// standard forum tagging sequence !forumname
// statusnet style group tags $pluspattern = '/@\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\+\[\/zrl\]/';
$pattern2 = '/^|[^@]\!\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\+\[\/zrl\]/';
if(preg_match_all($pattern,$body,$matches,PREG_SET_ORDER)) { $forumpattern = '/\!\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\[\/zrl\]/';
$max_forums = get_config('system','max_tagged_forums');
if(! $max_forums) $found = false;
$max_forums = 2;
$matched_forums = 0; $max_forums = get_config('system','max_tagged_forums');
if(! $max_forums)
$max_forums = 2;
$matched_forums = 0;
$matches = array();
if(preg_match_all($pluspattern,$body,$matches,PREG_SET_ORDER)) {
foreach($matches as $match) { foreach($matches as $match) {
$matched_forums ++; $matched_forums ++;
if($term['url'] === $match[1] && $term['term'] === $match[2]) { if($term['url'] === $match[1] && $term['term'] === $match[2]) {
if($matched_forums <= $max_forums) { if($matched_forums <= $max_forums) {
$plustagged = true; $plustagged = true;
$found = true;
break;
}
logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring');
}
}
}
if(preg_match_all($forumpattern,$body,$matches,PREG_SET_ORDER)) {
foreach($matches as $match) {
$matched_forums ++;
if($term['url'] === $match[1] && $term['term'] === $match[2]) {
if($matched_forums <= $max_forums) {
$plustagged = true;
$found = true;
break; break;
} }
logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring'); logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring');
@ -2609,7 +2633,8 @@ function tgroup_check($uid,$item) {
if(! $u) if(! $u)
return false; return false;
$terms = get_terms_oftype($item['term'],TERM_MENTION);
$terms = array_merge(get_terms_oftype($item['term'],TERM_MENTION),get_terms_oftype($item['term'],TERM_FORUM));
if($terms) if($terms)
logger('tgroup_check: post mentions: ' . print_r($terms,true), LOGGER_DATA); logger('tgroup_check: post mentions: ' . print_r($terms,true), LOGGER_DATA);
@ -2640,18 +2665,34 @@ function tgroup_check($uid,$item) {
$body = preg_replace('/\[share(.*?)\[\/share\]/','',$body); $body = preg_replace('/\[share(.*?)\[\/share\]/','',$body);
// $pattern = '/@\!?\[zrl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'] . '+','/') . '\[\/zrl\]/';
$pattern = '/@\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\+\[\/zrl\]/'; $pluspattern = '/@\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\+\[\/zrl\]/';
$forumpattern = '/\!\!?\[zrl\=([^\]]*?)\]((?:.(?!\[zrl\=))*?)\[\/zrl\]/';
$found = false; $found = false;
$max_forums = get_config('system','max_tagged_forums');
if(! $max_forums)
$max_forums = 2;
$matched_forums = 0;
$matches = array(); $matches = array();
if(preg_match_all($pattern,$body,$matches,PREG_SET_ORDER)) { if(preg_match_all($pluspattern,$body,$matches,PREG_SET_ORDER)) {
$max_forums = get_config('system','max_tagged_forums'); foreach($matches as $match) {
if(! $max_forums) $matched_forums ++;
$max_forums = 2; if($term['url'] === $match[1] && $term['term'] === $match[2]) {
$matched_forums = 0; if($matched_forums <= $max_forums) {
$found = true;
break;
}
logger('forum ' . $term['term'] . ' exceeded max_tagged_forums - ignoring');
}
}
}
if(preg_match_all($forumpattern,$body,$matches,PREG_SET_ORDER)) {
foreach($matches as $match) { foreach($matches as $match) {
$matched_forums ++; $matched_forums ++;
if($term['url'] === $match[1] && $term['term'] === $match[2]) { if($term['url'] === $match[1] && $term['term'] === $match[2]) {

View File

@ -134,6 +134,8 @@ function format_term_for_display($term) {
$s = ''; $s = '';
if(($term['ttype'] == TERM_HASHTAG) || ($term['ttype'] == TERM_COMMUNITYTAG)) if(($term['ttype'] == TERM_HASHTAG) || ($term['ttype'] == TERM_COMMUNITYTAG))
$s .= '#'; $s .= '#';
elseif($term['ttype'] == TERM_FORUM)
$s .= '!';
elseif($term['ttype'] == TERM_MENTION) elseif($term['ttype'] == TERM_MENTION)
$s .= '@'; $s .= '@';
else else

View File

@ -794,7 +794,7 @@ function get_tags($s) {
// match any double quoted tags // match any double quoted tags
if(preg_match_all('/([@#]\&quot\;.*?\&quot\;)/',$s,$match)) { if(preg_match_all('/([@#!]\&quot\;.*?\&quot\;)/',$s,$match)) {
foreach($match[1] as $mtch) { foreach($match[1] as $mtch) {
$ret[] = $mtch; $ret[] = $mtch;
} }
@ -823,7 +823,7 @@ function get_tags($s) {
// Otherwise pull out single word tags. These can be @nickname, @first_last // Otherwise pull out single word tags. These can be @nickname, @first_last
// and #hash tags. // and #hash tags.
if(preg_match_all('/(?<![a-zA-Z0-9=\/\?\;])([@#][^ \x0D\x0A,;:?\[]+)/',$s,$match)) { if(preg_match_all('/(?<![a-zA-Z0-9=\/\?\;])([@#\!][^ \x0D\x0A,;:?\[]+)/',$s,$match)) {
foreach($match[1] as $mtch) { foreach($match[1] as $mtch) {
if(substr($mtch,-1,1) === '.') if(substr($mtch,-1,1) === '.')
$mtch = substr($mtch,0,-1); $mtch = substr($mtch,0,-1);
@ -2383,8 +2383,9 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $d
$r = null; $r = null;
$match = array(); $match = array();
$termtype = ((strpos($tag,'#') === 0) ? TERM_HASHTAG : TERM_UNKNOWN); $termtype = ((strpos($tag,'#') === 0) ? TERM_HASHTAG : TERM_UNKNOWN);
$termtype = ((strpos($tag,'@') === 0) ? TERM_MENTION : $termtype); $termtype = ((strpos($tag,'@') === 0) ? TERM_MENTION : $termtype);
$termtype = ((strpos($tag,'!') === 0) ? TERM_FORUM : $termtype);
$termtype = ((strpos($tag,'#^[') === 0) ? TERM_BOOKMARK : $termtype); $termtype = ((strpos($tag,'#^[') === 0) ? TERM_BOOKMARK : $termtype);
//is it a hash tag? //is it a hash tag?
@ -2441,10 +2442,16 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $d
//is it a person tag? //is it a person tag?
if(strpos($tag,'@') === 0) { $grouptag = false;
if(strpos($tag,'!') === 0) {
$grouptag = true;
}
if(strpos($tag,'@') === 0 || $grouptag) {
// The @! tag will alter permissions // The @! tag will alter permissions
$exclusive = ((strpos($tag,'!') === 1 && (! $diaspora)) ? true : false); $exclusive = (((! $grouptag) && (strpos($tag,'!') === 1) && (! $diaspora)) ? true : false);
//is it already replaced? //is it already replaced?
if(strpos($tag,'[zrl=')) if(strpos($tag,'[zrl='))
@ -2616,8 +2623,15 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $d
//create profile link //create profile link
$profile = str_replace(',','%2c',$profile); $profile = str_replace(',','%2c',$profile);
$url = $profile; $url = $profile;
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . (($forum && ! $trailing_plus_name) ? '+' : '') . '[/zrl]'; if($grouptag) {
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body); $newtag = '!' . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
$body = str_replace('!' . $name, $newtag, $body);
}
else {
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . (($forum && ! $trailing_plus_name) ? '+' : '') . '[/zrl]';
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
}
//append tag to str_tags //append tag to str_tags
if(! stristr($str_tags,$newtag)) { if(! stristr($str_tags,$newtag)) {
if(strlen($str_tags)) if(strlen($str_tags))

View File

@ -1432,7 +1432,7 @@ function public_recips($msg) {
if($msg['message']['tags']) { if($msg['message']['tags']) {
if(is_array($msg['message']['tags']) && $msg['message']['tags']) { if(is_array($msg['message']['tags']) && $msg['message']['tags']) {
foreach($msg['message']['tags'] as $tag) { foreach($msg['message']['tags'] as $tag) {
if(($tag['type'] === 'mention') && (strpos($tag['url'],z_root()) !== false)) { if(($tag['type'] === 'mention' || $tag['type'] === 'forum') && (strpos($tag['url'],z_root()) !== false)) {
$address = basename($tag['url']); $address = basename($tag['url']);
if($address) { if($address) {
$z = q("select channel_hash as hash from channel where channel_address = '%s' $z = q("select channel_hash as hash from channel where channel_address = '%s'

View File

@ -192,6 +192,16 @@ function string2bb(element) {
template: contact_format template: contact_format
}; };
// Autocomplete forums
forums = {
match: /(^|\s)(\!)([^ \n]+)$/,
index: 3,
search: function(term, callback) { contact_search(term, callback, backend_url, 'f', extra_channels, spinelement=false); },
replace: editor_replace,
template: contact_format
};
smilies = { smilies = {
match: /(^|\s)(:[a-z_:]{2,})$/, match: /(^|\s)(:[a-z_:]{2,})$/,
index: 2, index: 2,
@ -201,7 +211,7 @@ function string2bb(element) {
template: smiley_format template: smiley_format
}; };
this.attr('autocomplete','off'); this.attr('autocomplete','off');
this.textcomplete([contacts,smilies], {className:'acpopup', zIndex:1020}); this.textcomplete([contacts,forums,smilies], {className:'acpopup', zIndex:1020});
}; };
})( jQuery ); })( jQuery );