basic support for exclusion tags - we just need to use the results to tweak the ACL.

This commit is contained in:
friendica 2013-12-29 16:12:39 -08:00
parent f36be066af
commit c03c0724ed
2 changed files with 69 additions and 92 deletions

View File

@ -151,7 +151,7 @@ ACPopup.prototype.onkey = function(event){
} }
function ContactAutocomplete(element,backend_url){ function ContactAutocomplete(element,backend_url){
this.pattern=/@([^ \n]+)$/; this.pattern=/@(\!*)([^ \n]+)$/;
this.popup=null; this.popup=null;
var that = this; var that = this;
@ -170,7 +170,7 @@ function ContactAutocomplete(element,backend_url){
if (that.popup===null){ if (that.popup===null){
that.popup = new ACPopup(this, backend_url); that.popup = new ACPopup(this, backend_url);
} }
if (that.popup.ready && match[1]!==that.popup.searchText) that.popup.search(match[1]); if (that.popup.ready && match[2]!==that.popup.searchText) that.popup.search(match[2]);
if (!that.popup.ready) that.popup=null; if (!that.popup.ready) that.popup=null;
} else { } else {

View File

@ -492,7 +492,9 @@ function item_post(&$a) {
$success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag); $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag);
logger('handle_tag: ' . print_r($success,tue)); logger('handle_tag: ' . print_r($success,tue));
if($inform) {
logger('inform: ' . $tag . ' ' . print_r($inform,true));
}
if($success['replaced']) { if($success['replaced']) {
$tagged[] = $tag; $tagged[] = $tag;
$post_tags[] = array( $post_tags[] = array(
@ -894,12 +896,13 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
//is it a hash tag? //is it a hash tag?
if(strpos($tag,'#') === 0) { if(strpos($tag,'#') === 0) {
// if the tag is replaced... // if the tag is replaced...
if(strpos($tag,'[zrl=')) if(strpos($tag,'[zrl=')) {
//...do nothing //...do nothing
return $replaced; return $replaced;
}
if($tag == '#getzot') { if($tag == '#getzot') {
$basetag = 'getzot'; $basetag = 'getzot';
$url = 'http://getzot.com'; $url = 'https://redmatrix.me';
$newtag = '#[zrl=' . $url . ']' . $basetag . '[/zrl]'; $newtag = '#[zrl=' . $url . ']' . $basetag . '[/zrl]';
$body = str_replace($tag,$newtag,$body); $body = str_replace($tag,$newtag,$body);
$replaced = true; $replaced = true;
@ -923,36 +926,22 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
} }
return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $basetag, 'url' => $url, 'contact' => $r[0]); return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $basetag, 'url' => $url, 'contact' => $r[0]);
} }
//is it a person tag? //is it a person tag?
if(strpos($tag,'@') === 0) { if(strpos($tag,'@') === 0) {
$exclusive = ((strpos($tag,'!') === 1) ? true : false);
//is it already replaced? //is it already replaced?
if(strpos($tag,'[zrl=')) if(strpos($tag,'[zrl='))
return $replaced; return $replaced;
$stat = false; $stat = false;
//get the person's name //get the person's name
$name = substr($tag,1); $name = substr($tag,(($exclusive) ? 2 : 1));
//is it a link or a full dfrn address?
if((strpos($name,'@')) || (strpos($name,'http://'))) {
$newname = $name;
//get the profile links
$links = @lrdd($name);
if(count($links)) {
//for all links, collect how is to inform and how's profile is to link
foreach($links as $link) {
if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
$profile = $link['@attributes']['href'];
if($link['@attributes']['rel'] === 'salmon') {
if(strlen($inform))
$inform .= ',';
$inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
}
}
}
} else { //if it is a name rather than an address
$newname = $name; $newname = $name;
$alias = ''; $alias = '';
$tagcid = 0; $tagcid = 0;
//is it some generated name? //is it some generated name?
if(strrpos($newname,'+')) { if(strrpos($newname,'+')) {
//get the id //get the id
$tagcid = intval(substr($newname,strrpos($newname,'+') + 1)); $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
@ -960,17 +949,17 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
if(strpos($name,' ')) { if(strpos($name,' ')) {
$name = substr($name,0,strpos($name,' ')); $name = substr($name,0,strpos($name,' '));
} }
}
if($tagcid) { //if there was an id
//select contact with that id from the logged in user's contact list if($tagcid) { // 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 $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash
WHERE abook_id = %d AND abook_channel = %d LIMIT 1", WHERE abook_id = %d AND abook_channel = %d LIMIT 1",
intval($tagcid), intval($tagcid),
intval($profile_uid) intval($profile_uid)
); );
} }
}
else { else {
$newname = str_replace('_',' ',$name); $newname = str_replace('_',' ',$name);
@ -983,47 +972,36 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
if(! $r) { if(! $r) {
//select someone by attag or nick and the name passed in //select someone by attag or nick and the name passed in
/* $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", $r = q("SELECT * FROM abook left join xchan on abook_xchan - xchan_hash
dbesc($name), WHERE xchan_addr like ('%s') AND abook_channel = %d LIMIT 1",
dbesc($name), dbesc($newname . '@%'),
intval($profile_uid) intval($profile_uid)
); );
*/ }
} }
/* } elseif(strstr($name,'_') || strstr($name,' ')) { //no id }
//get the real name
$newname = str_replace('_',' ',$name);
//select someone from this user's contacts by name
$r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
dbesc($newname),
intval($profile_uid)
);
} else {
//select someone by attag or nick and the name passed in
$r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
dbesc($name),
dbesc($name),
intval($profile_uid)
);
}*/
//$r is set, if someone could be selected //$r is set, if someone could be selected
if($r) { if($r) {
$profile = $r[0]['xchan_url']; $profile = $r[0]['xchan_url'];
$newname = $r[0]['xchan_name']; $newname = $r[0]['xchan_name'];
//add person's id to $inform //add person's id to $inform if exclusive
if($exclusive) {
if(strlen($inform)) if(strlen($inform))
$inform .= ','; $inform .= ',';
$inform .= 'cid:' . $r[0]['id']; $inform .= 'cid:' . $r[0]['abook_id'];
} }
} }
//if there is an url for this persons profile //if there is an url for this persons profile
if(isset($profile)) { if(isset($profile)) {
$replaced = true; $replaced = true;
//create profile link //create profile link
$profile = str_replace(',','%2c',$profile); $profile = str_replace(',','%2c',$profile);
$url = $profile; $url = $profile;
$newtag = '@[zrl=' . $profile . ']' . $newname . '[/zrl]'; $newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
$body = str_replace('@' . $name, $newtag, $body); $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))
@ -1032,7 +1010,6 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
} }
} }
} }
return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $newname, 'url' => $url, 'contact' => $r[0]); return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $newname, 'url' => $url, 'contact' => $r[0]);
} }