fix linkify_tags() so it works with xchans across multiple protocols, also some fixes to activity parsing from upstream.
This commit is contained in:
162
include/text.php
162
include/text.php
@@ -2631,8 +2631,9 @@ function extra_query_args() {
|
||||
* @param boolean $in_network default true
|
||||
* @return boolean true if replaced, false if not replaced
|
||||
*/
|
||||
function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $in_network = true) {
|
||||
function handle_tag(&$body, &$str_tags, $profile_uid, $tag, $in_network = true) {
|
||||
|
||||
$channel = App::get_channel();
|
||||
$replaced = false;
|
||||
$r = null;
|
||||
$match = array();
|
||||
@@ -2688,21 +2689,20 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
return [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $basetag,
|
||||
'url' => $url,
|
||||
'contact' => []
|
||||
];
|
||||
|
||||
return [ [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $basetag,
|
||||
'url' => $url,
|
||||
'contact' => [],
|
||||
'access_tag' => '',
|
||||
]];
|
||||
}
|
||||
|
||||
// END hashtags
|
||||
|
||||
// BEGIN mentions
|
||||
|
||||
|
||||
if ( in_array($termtype, [ TERM_MENTION, TERM_FORUM ] )) {
|
||||
|
||||
// The @! tag and !! tag will alter permissions
|
||||
@@ -2713,7 +2713,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
$exclusive = (((strpos(substr($tag,1), '!') === 0) && $in_network) ? true : false);
|
||||
|
||||
//is it already replaced?
|
||||
if(strpos($tag,'[zrl=') || strpos($tag,'[url='))
|
||||
if(strpos($tag,"[zrl=") || strpos($tag,"[url="))
|
||||
return $replaced;
|
||||
|
||||
// get the channel name
|
||||
@@ -2731,7 +2731,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
$newname = substr($name,1);
|
||||
$newname = substr($newname,0,-1);
|
||||
|
||||
$r = q("select * from xchan where xchan_addr = '%s' or xchan_url = '%s' limit 1",
|
||||
$r = q("select * from xchan where xchan_addr = '%s' or xchan_url = '%s'",
|
||||
dbesc($newname),
|
||||
dbesc($newname)
|
||||
);
|
||||
@@ -2754,7 +2754,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
// select someone from this user's contacts by name
|
||||
|
||||
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1",
|
||||
WHERE xchan_name = '%s' AND abook_channel = %d ",
|
||||
dbesc($newname),
|
||||
intval($profile_uid)
|
||||
);
|
||||
@@ -2763,7 +2763,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
|
||||
if((! $r) && strpos($newname,'@')) {
|
||||
$r = q("SELECT * FROM xchan left join hubloc on xchan_hash = hubloc_hash
|
||||
WHERE hubloc_addr = '%s' LIMIT 1",
|
||||
WHERE hubloc_addr = '%s' ",
|
||||
dbesc($newname)
|
||||
);
|
||||
}
|
||||
@@ -2772,7 +2772,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
|
||||
if(! $r) {
|
||||
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash
|
||||
WHERE xchan_addr like ('%s') AND abook_channel = %d LIMIT 1",
|
||||
WHERE xchan_addr like ('%s') AND abook_channel = %d ",
|
||||
dbesc(((strpos($newname,'@')) ? $newname : $newname . '@%')),
|
||||
intval($profile_uid)
|
||||
);
|
||||
@@ -2780,17 +2780,62 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$fn_results = [];
|
||||
$access_tag = EMPTY_STR;
|
||||
|
||||
|
||||
// $r is set if we found something
|
||||
|
||||
$channel = App::get_channel();
|
||||
|
||||
if($r) {
|
||||
$profile = $r[0]['xchan_url'];
|
||||
$newname = $r[0]['xchan_name'];
|
||||
// add the channel's xchan_hash to $access_tag if exclusive
|
||||
if($exclusive) {
|
||||
$access_tag .= 'cid:' . $r[0]['xchan_hash'];
|
||||
foreach($r as $xc) {
|
||||
$profile = $xc['xchan_url'];
|
||||
$newname = $xc['xchan_name'];
|
||||
// add the channel's xchan_hash to $access_tag if exclusive
|
||||
if($exclusive) {
|
||||
$access_tag = 'cid:' . $xc['xchan_hash'];
|
||||
}
|
||||
|
||||
// if there is a url for this channel
|
||||
|
||||
if(isset($profile)) {
|
||||
$replaced = true;
|
||||
//create profile link
|
||||
$profile = str_replace(',','%2c',$profile);
|
||||
$url = $profile;
|
||||
if($termtype === TERM_FORUM) {
|
||||
$newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
else {
|
||||
// ( $termtype === TERM_MENTION )
|
||||
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
|
||||
// append tag to str_tags
|
||||
if(! stristr($str_tags,$newtag)) {
|
||||
if(strlen($str_tags))
|
||||
$str_tags .= ',';
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$fn_results[] = [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $newname,
|
||||
'url' => $url,
|
||||
'access_tag' => $access_tag,
|
||||
'contact' => (($r) ? $xc : []),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -2802,7 +2847,6 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
// weird - as all the other tags are linked to something.
|
||||
|
||||
if(local_channel() && local_channel() == $profile_uid) {
|
||||
require_once('include/group.php');
|
||||
$grp = group_byname($profile_uid,$name);
|
||||
|
||||
if($grp) {
|
||||
@@ -2819,58 +2863,62 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if there is a url for this channel
|
||||
|
||||
if(isset($profile)) {
|
||||
$replaced = true;
|
||||
//create profile link
|
||||
$profile = str_replace(',','%2c',$profile);
|
||||
$url = $profile;
|
||||
if($termtype === TERM_FORUM) {
|
||||
$newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
else {
|
||||
// ( $termtype === TERM_MENTION )
|
||||
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
// if there is a url for this channel
|
||||
|
||||
if(isset($profile)) {
|
||||
$replaced = true;
|
||||
//create profile link
|
||||
$profile = str_replace(',','%2c',$profile);
|
||||
$url = $profile;
|
||||
if($termtype === TERM_FORUM) {
|
||||
$newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
else {
|
||||
// ( $termtype === TERM_MENTION )
|
||||
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
|
||||
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
|
||||
}
|
||||
|
||||
// append tag to str_tags
|
||||
if(! stristr($str_tags,$newtag)) {
|
||||
if(strlen($str_tags))
|
||||
$str_tags .= ',';
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
}
|
||||
|
||||
// append tag to str_tags
|
||||
if(! stristr($str_tags,$newtag)) {
|
||||
if(strlen($str_tags))
|
||||
$str_tags .= ',';
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
$fn_results[] = [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $newname,
|
||||
'url' => $url,
|
||||
'access_tag' => $access_tag,
|
||||
'contact' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $fn_results;
|
||||
|
||||
return [
|
||||
'replaced' => $replaced,
|
||||
'termtype' => $termtype,
|
||||
'term' => $newname,
|
||||
'url' => $url,
|
||||
'contact' => (($r) ? $r[0] : [])
|
||||
];
|
||||
}
|
||||
|
||||
function linkify_tags($a, &$body, $uid, $in_network = true) {
|
||||
function linkify_tags(&$body, $uid, $in_network = true) {
|
||||
$str_tags = EMPTY_STR;
|
||||
$tagged = [];
|
||||
$results = [];
|
||||
|
||||
$tags = get_tags($body);
|
||||
|
||||
if(count($tags)) {
|
||||
foreach($tags as $tag) {
|
||||
$access_tag = '';
|
||||
|
||||
$success = handle_tag($a, $body, $access_tag, $str_tags, ($uid) ? $uid : App::$profile_uid , $tag, $in_network);
|
||||
$success = handle_tag($body, $str_tags, ($uid) ? $uid : App::$profile_uid , $tag, $in_network);
|
||||
|
||||
$results[] = array('success' => $success, 'access_tag' => $access_tag);
|
||||
if($success['replaced']) $tagged[] = $tag;
|
||||
foreach($success as $handled_tag) {
|
||||
$results[] = [ 'success' => $handled_tag ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user