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(
@ -893,13 +895,14 @@ 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,116 +926,90 @@ 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? $newname = $name;
if((strpos($name,'@')) || (strpos($name,'http://'))) { $alias = '';
$newname = $name; $tagcid = 0;
//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;
$alias = '';
$tagcid = 0;
//is it some generated name?
if(strrpos($newname,'+')) {
//get the id
$tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
//remove the next word from tag's name
if(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 //is it some generated name?
if(strrpos($newname,'+')) {
//get the id
$tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
//remove the next word from tag's name
if(strpos($name,' ')) {
$name = substr($name,0,strpos($name,' '));
}
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 { }
$newname = str_replace('_',' ',$name);
//select someone from this user's contacts by name else {
$r = q("SELECT * FROM abook left join xchan on abook_xchan - xchan_hash $newname = str_replace('_',' ',$name);
WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1",
dbesc($newname),
intval($profile_uid)
);
if(! $r) { //select someone from this user's contacts by name
//select someone by attag or nick and the name passed in $r = q("SELECT * FROM abook left join xchan on abook_xchan - xchan_hash
/* $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1",
dbesc($name), dbesc($newname),
dbesc($name), intval($profile_uid)
intval($profile_uid) );
);
*/ } if(! $r) {
}
/* } 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 //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)
); );
}*/ }
//$r is set, if someone could be selected }
if($r) {
$profile = $r[0]['xchan_url']; //$r is set, if someone could be selected
$newname = $r[0]['xchan_name'];
//add person's id to $inform if($r) {
$profile = $r[0]['xchan_url'];
$newname = $r[0]['xchan_name'];
//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(isset($profile)) {
$replaced = true; //if there is an url for this persons profile
//create profile link if(isset($profile)) {
$profile = str_replace(',','%2c',$profile); $replaced = true;
$url = $profile; //create profile link
$newtag = '@[zrl=' . $profile . ']' . $newname . '[/zrl]'; $profile = str_replace(',','%2c',$profile);
$body = str_replace('@' . $name, $newtag, $body); $url = $profile;
//append tag to str_tags $newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
if(! stristr($str_tags,$newtag)) { $body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
if(strlen($str_tags)) //append tag to str_tags
$str_tags .= ','; if(! stristr($str_tags,$newtag)) {
$str_tags .= $newtag; if(strlen($str_tags))
} $str_tags .= ',';
$str_tags .= $newtag;
} }
} }
}
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]);
} }