Merge remote-tracking branch 'mike/master' into dev

This commit is contained in:
Mario Vavti 2019-02-04 10:03:38 +01:00
commit cf80f03084
12 changed files with 139 additions and 97 deletions

View File

@ -1411,6 +1411,9 @@ class Activity {
$s['owner_xchan'] = $act->actor['id']; $s['owner_xchan'] = $act->actor['id'];
$s['author_xchan'] = $act->actor['id']; $s['author_xchan'] = $act->actor['id'];
// ensure we store the original actor
self::actor_store($act->actor['id'],$act->actor);
$s['mid'] = $act->obj['id']; $s['mid'] = $act->obj['id'];
$s['parent_mid'] = $act->parent_id; $s['parent_mid'] = $act->parent_id;
@ -1483,7 +1486,8 @@ class Activity {
$s['verb'] = self::activity_decode_mapper($act->type); $s['verb'] = self::activity_decode_mapper($act->type);
if($act->type === 'Tombstone') {
if($act->type === 'Tombstone' || ($act->type === 'Create' && $act->obj['type'] === 'Tombstone')) {
$s['item_deleted'] = 1; $s['item_deleted'] = 1;
} }
@ -1492,7 +1496,6 @@ class Activity {
$s['obj_type'] = ACTIVITY_OBJ_COMMENT; $s['obj_type'] = ACTIVITY_OBJ_COMMENT;
} }
if($act->obj['type'] === 'Event') { if($act->obj['type'] === 'Event') {
$s['obj'] = []; $s['obj'] = [];
$s['obj']['asld'] = $act->obj; $s['obj']['asld'] = $act->obj;

View File

@ -119,7 +119,7 @@ class Site {
del_config('system', 'admininfo'); del_config('system', 'admininfo');
} else { } else {
require_once('include/text.php'); require_once('include/text.php');
linkify_tags($a, $admininfo, local_channel()); linkify_tags($admininfo, local_channel());
set_config('system', 'admininfo', $admininfo); set_config('system', 'admininfo', $admininfo);
} }
set_config('system','siteinfo',$siteinfo); set_config('system','siteinfo',$siteinfo);

View File

@ -97,8 +97,8 @@ class Events extends \Zotlabs\Web\Controller {
$type = escape_tags(trim($_POST['type'])); $type = escape_tags(trim($_POST['type']));
require_once('include/text.php'); require_once('include/text.php');
linkify_tags($a, $desc, local_channel()); linkify_tags($desc, local_channel());
linkify_tags($a, $location, local_channel()); linkify_tags($location, local_channel());
//$action = ($event_hash == '') ? 'new' : "event/" . $event_hash; //$action = ($event_hash == '') ? 'new' : "event/" . $event_hash;

View File

@ -553,8 +553,8 @@ class Item extends Controller {
// Look for tags and linkify them // Look for tags and linkify them
$results = linkify_tags($a, $summary, ($uid) ? $uid : $profile_uid); $results = linkify_tags($summary, ($uid) ? $uid : $profile_uid);
$results = linkify_tags($a, $body, ($uid) ? $uid : $profile_uid); $results = linkify_tags($body, ($uid) ? $uid : $profile_uid);
if($results) { if($results) {

View File

@ -34,7 +34,7 @@ class Mail extends \Zotlabs\Web\Controller {
} }
else { else {
$body = cleanup_bbcode($body); $body = cleanup_bbcode($body);
$results = linkify_tags($a, $body, local_channel()); $results = linkify_tags($body, local_channel());
if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) { if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) {
$attachments = array(); $attachments = array();
@ -111,7 +111,7 @@ class Mail extends \Zotlabs\Web\Controller {
} }
require_once('include/text.php'); require_once('include/text.php');
linkify_tags($a, $body, local_channel()); linkify_tags($body, local_channel());
if(! $recipient) { if(! $recipient) {

View File

@ -422,7 +422,7 @@ class Photos extends \Zotlabs\Web\Controller {
require_once('include/text.php'); require_once('include/text.php');
$profile_uid = \App::$profile['profile_uid']; $profile_uid = \App::$profile['profile_uid'];
$results = linkify_tags($a, $rawtags, (local_channel()) ? local_channel() : $profile_uid); $results = linkify_tags($rawtags, (local_channel()) ? local_channel() : $profile_uid);
$success = $results['success']; $success = $results['success'];
$post_tags = array(); $post_tags = array();

View File

@ -354,20 +354,20 @@ class Profiles extends \Zotlabs\Web\Controller {
require_once('include/text.php'); require_once('include/text.php');
linkify_tags($a, $likes, local_channel()); linkify_tags($likes, local_channel());
linkify_tags($a, $dislikes, local_channel()); linkify_tags($dislikes, local_channel());
linkify_tags($a, $about, local_channel()); linkify_tags($about, local_channel());
linkify_tags($a, $interest, local_channel()); linkify_tags($interest, local_channel());
linkify_tags($a, $interest, local_channel()); linkify_tags($interest, local_channel());
linkify_tags($a, $contact, local_channel()); linkify_tags($contact, local_channel());
linkify_tags($a, $channels, local_channel()); linkify_tags($channels, local_channel());
linkify_tags($a, $music, local_channel()); linkify_tags($music, local_channel());
linkify_tags($a, $book, local_channel()); linkify_tags($book, local_channel());
linkify_tags($a, $tv, local_channel()); linkify_tags($tv, local_channel());
linkify_tags($a, $film, local_channel()); linkify_tags($film, local_channel());
linkify_tags($a, $romance, local_channel()); linkify_tags($romance, local_channel());
linkify_tags($a, $work, local_channel()); linkify_tags($work, local_channel());
linkify_tags($a, $education, local_channel()); linkify_tags($education, local_channel());
$with = ((x($_POST,'with')) ? escape_tags(trim($_POST['with'])) : ''); $with = ((x($_POST,'with')) ? escape_tags(trim($_POST['with'])) : '');

View File

@ -4561,7 +4561,7 @@ function set_linkified_perms($linkified, &$str_contact_allow, &$str_group_allow,
$first_access_tag = true; $first_access_tag = true;
foreach($linkified as $x) { foreach($linkified as $x) {
$access_tag = $x['access_tag']; $access_tag = $x['success']['access_tag'];
if(($access_tag) && (! $parent_item)) { if(($access_tag) && (! $parent_item)) {
logger('access_tag: ' . $tag . ' ' . print_r($access_tag,true), LOGGER_DATA); logger('access_tag: ' . $tag . ' ' . print_r($access_tag,true), LOGGER_DATA);
if ($first_access_tag && (! get_pconfig($profile_uid,'system','no_private_mention_acl_override'))) { if ($first_access_tag && (! get_pconfig($profile_uid,'system','no_private_mention_acl_override'))) {

View File

@ -44,7 +44,7 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
$body = cleanup_bbcode($body); $body = cleanup_bbcode($body);
$results = linkify_tags($a, $body, $uid); $results = linkify_tags($body, $uid);
if(! $raw) { if(! $raw) {
if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match)) { if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match)) {

View File

@ -356,7 +356,7 @@ function photo_upload($channel, $observer, $args) {
$large_photos = feature_enabled($channel['channel_id'], 'large_photos'); $large_photos = feature_enabled($channel['channel_id'], 'large_photos');
linkify_tags($a, $args['body'], $channel_id); linkify_tags($args['body'], $channel_id);
if($large_photos) { if($large_photos) {
$scale = 1; $scale = 1;

View File

@ -2631,8 +2631,9 @@ function extra_query_args() {
* @param boolean $in_network default true * @param boolean $in_network default true
* @return boolean true if replaced, false if not replaced * @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; $replaced = false;
$r = null; $r = null;
$match = array(); $match = array();
@ -2688,21 +2689,20 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
$str_tags .= $newtag; $str_tags .= $newtag;
} }
return [ return [ [
'replaced' => $replaced, 'replaced' => $replaced,
'termtype' => $termtype, 'termtype' => $termtype,
'term' => $basetag, 'term' => $basetag,
'url' => $url, 'url' => $url,
'contact' => [] 'contact' => [],
]; 'access_tag' => '',
]];
} }
// END hashtags // END hashtags
// BEGIN mentions // BEGIN mentions
if ( in_array($termtype, [ TERM_MENTION, TERM_FORUM ] )) { if ( in_array($termtype, [ TERM_MENTION, TERM_FORUM ] )) {
// The @! tag and !! tag will alter permissions // 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); $exclusive = (((strpos(substr($tag,1), '!') === 0) && $in_network) ? true : false);
//is it already replaced? //is it already replaced?
if(strpos($tag,'[zrl=') || strpos($tag,'[url=')) if(strpos($tag,"[zrl=") || strpos($tag,"[url="))
return $replaced; return $replaced;
// get the channel name // 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($name,1);
$newname = substr($newname,0,-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),
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 // select someone from this user's contacts by name
$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 xchan_name = '%s' AND abook_channel = %d LIMIT 1", WHERE xchan_name = '%s' AND abook_channel = %d ",
dbesc($newname), dbesc($newname),
intval($profile_uid) intval($profile_uid)
); );
@ -2763,7 +2763,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
if((! $r) && strpos($newname,'@')) { if((! $r) && strpos($newname,'@')) {
$r = q("SELECT * FROM xchan left join hubloc on xchan_hash = hubloc_hash $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) dbesc($newname)
); );
} }
@ -2772,7 +2772,7 @@ function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag, $i
if(! $r) { if(! $r) {
$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 xchan_addr like ('%s') AND abook_channel = %d LIMIT 1", WHERE xchan_addr like ('%s') AND abook_channel = %d ",
dbesc(((strpos($newname,'@')) ? $newname : $newname . '@%')), dbesc(((strpos($newname,'@')) ? $newname : $newname . '@%')),
intval($profile_uid) 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 // $r is set if we found something
$channel = App::get_channel();
if($r) { if($r) {
$profile = $r[0]['xchan_url']; foreach($r as $xc) {
$newname = $r[0]['xchan_name']; $profile = $xc['xchan_url'];
// add the channel's xchan_hash to $access_tag if exclusive $newname = $xc['xchan_name'];
if($exclusive) { // add the channel's xchan_hash to $access_tag if exclusive
$access_tag .= 'cid:' . $r[0]['xchan_hash']; 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 { 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. // weird - as all the other tags are linked to something.
if(local_channel() && local_channel() == $profile_uid) { if(local_channel() && local_channel() == $profile_uid) {
require_once('include/group.php');
$grp = group_byname($profile_uid,$name); $grp = group_byname($profile_uid,$name);
if($grp) { 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)) { // if there is a url for this channel
$replaced = true;
//create profile link if(isset($profile)) {
$profile = str_replace(',','%2c',$profile); $replaced = true;
$url = $profile; //create profile link
if($termtype === TERM_FORUM) { $profile = str_replace(',','%2c',$profile);
$newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]'; $url = $profile;
$body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body); if($termtype === TERM_FORUM) {
} $newtag = '!' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]';
else { $body = str_replace('!' . (($exclusive) ? '!' : '') . $name, $newtag, $body);
// ( $termtype === TERM_MENTION ) }
$newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . '[/zrl]'; else {
$body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body); // ( $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 $fn_results[] = [
if(! stristr($str_tags,$newtag)) { 'replaced' => $replaced,
if(strlen($str_tags)) 'termtype' => $termtype,
$str_tags .= ','; 'term' => $newname,
$str_tags .= $newtag; '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; $str_tags = EMPTY_STR;
$tagged = [];
$results = []; $results = [];
$tags = get_tags($body); $tags = get_tags($body);
if(count($tags)) { if(count($tags)) {
foreach($tags as $tag) { 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); foreach($success as $handled_tag) {
if($success['replaced']) $tagged[] = $tag; $results[] = [ 'success' => $handled_tag ];
}
} }
} }

View File

@ -106,10 +106,9 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
$tags=get_tags($text); $tags=get_tags($text);
$inform='';
$str_tags=''; $str_tags='';
foreach($tags as $tag) { foreach($tags as $tag) {
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); handle_tag($text, $str_tags, 11, $tag);
} }
//correct tags found? //correct tags found?
@ -117,7 +116,6 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(in_array("@Mike", $tags)); $this->assertTrue(in_array("@Mike", $tags));
//correct output from handle_tag? //correct output from handle_tag?
$this->assertEquals("cid:15", $inform);
$this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);
$this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url]", $text); $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url]", $text);
} }
@ -135,9 +133,8 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($tags)); $this->assertEquals(1, count($tags));
$this->assertTrue(in_array("@Mike.because", $tags)); $this->assertTrue(in_array("@Mike.because", $tags));
$inform='';
$str_tags=''; $str_tags='';
handle_tag($this->a, $text, $inform, $str_tags, 11, $tags[0]); handle_tag($text, $str_tags, 11, $tags[0]);
// (mike) - This is a tricky case. // (mike) - This is a tricky case.
// we support mentions as in @mike@example.com - which contains a period. // we support mentions as in @mike@example.com - which contains a period.
@ -149,7 +146,6 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
// $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); // $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);
// $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url].because", $text); // $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url].because", $text);
$this->assertEquals("", $inform);
$this->assertEquals("", $str_tags); $this->assertEquals("", $str_tags);
} }
@ -195,13 +191,11 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(in_array("@Mike This", $tags)); $this->assertTrue(in_array("@Mike This", $tags));
$this->assertTrue(in_array("#test_case", $tags)); $this->assertTrue(in_array("#test_case", $tags));
$inform='';
$str_tags=''; $str_tags='';
foreach($tags as $tag) { foreach($tags as $tag) {
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); handle_tag($text, $str_tags, 11, $tag);
} }
$this->assertEquals("cid:15", $inform);
$this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url],#[url=baseurl/search?tag=test%20case]test case[/url]", $str_tags); $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url],#[url=baseurl/search?tag=test%20case]test case[/url]", $str_tags);
$this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url] This is a #[url=baseurl/search?tag=test%20case]test case[/url]", $text); $this->assertEquals("hi @[url=http://justatest.de]Mike Lastname[/url] This is a #[url=baseurl/search?tag=test%20case]test case[/url]", $text);
@ -255,16 +249,13 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
//happens right now, but it shouldn't be necessary //happens right now, but it shouldn't be necessary
$this->assertTrue(in_array("@mike+15 id", $tags)); $this->assertTrue(in_array("@mike+15 id", $tags));
$inform='';
$str_tags=''; $str_tags='';
foreach($tags as $tag) { foreach($tags as $tag) {
handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); handle_tag($text, $str_tags, 11, $tag);
} }
$this->assertEquals("Test with @[url=http://justatest.de]Mike Lastname[/url] id tag", $text); $this->assertEquals("Test with @[url=http://justatest.de]Mike Lastname[/url] id tag", $text);
$this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags); $this->assertEquals("@[url=http://justatest.de]Mike Lastname[/url]", $str_tags);
// this test may produce two cid:15 entries - which is OK because duplicates are pruned before delivery
$this->assertContains("cid:15",$inform);
} }
/** /**