add auth flag to share attributes so we can make a costly determination to use zid at post submission time instead of making multiple calls to is_matrix_url() at render time

This commit is contained in:
zotlabs 2018-03-15 17:51:24 -07:00
parent 34fee2a790
commit 91b710b07d
6 changed files with 43 additions and 52 deletions

View File

@ -123,11 +123,13 @@ class Share {
$bb = substr($this->item['body'], $pos); $bb = substr($this->item['body'], $pos);
} else { } else {
$bb = "[share author='".urlencode($this->item['author']['xchan_name']). $bb = "[share author='".urlencode($this->item['author']['xchan_name']).
"' profile='".$this->item['author']['xchan_url'] . "' profile='" . $this->item['author']['xchan_url'] .
"' avatar='".$this->item['author']['xchan_photo_s']. "' avatar='" . $this->item['author']['xchan_photo_s'] .
"' link='".$this->item['plink']. "' link='" . $this->item['plink'] .
"' posted='".$this->item['created']. "' auth='" . (($this->item['author']['network'] === 'zot') ? 'true' : 'false') .
"' message_id='".$this->item['mid']."']"; "' posted='" . $this->item['created'] .
"' message_id='" . $this->item['mid'] .
"']";
if($this->item['title']) if($this->item['title'])
$bb .= '[b]'.$this->item['title'].'[/b]'."\r\n"; $bb .= '[b]'.$this->item['title'].'[/b]'."\r\n";
$bb .= (($is_photo) ? $photo_bb . "\r\n" . $this->item['body'] : $this->item['body']); $bb .= (($is_photo) ? $photo_bb . "\r\n" . $this->item['body'] : $this->item['body']);

View File

@ -125,6 +125,7 @@ class Oep extends \Zotlabs\Web\Controller {
"' profile='".$p[0]['author']['xchan_url'] . "' profile='".$p[0]['author']['xchan_url'] .
"' avatar='".$p[0]['author']['xchan_photo_s']. "' avatar='".$p[0]['author']['xchan_photo_s'].
"' link='".$p[0]['plink']. "' link='".$p[0]['plink'].
"' auth='".(($p[0]['author']['network'] === 'zot') ? 'true' : 'false') .
"' posted='".$p[0]['created']. "' posted='".$p[0]['created'].
"' message_id='".$p[0]['mid']."']"; "' message_id='".$p[0]['mid']."']";
if($p[0]['title']) if($p[0]['title'])
@ -209,6 +210,7 @@ class Oep extends \Zotlabs\Web\Controller {
"' profile='".$p[0]['author']['xchan_url'] . "' profile='".$p[0]['author']['xchan_url'] .
"' avatar='".$p[0]['author']['xchan_photo_s']. "' avatar='".$p[0]['author']['xchan_photo_s'].
"' link='".$p[0]['plink']. "' link='".$p[0]['plink'].
"' auth='".(($p[0]['author']['network'] === 'zot') ? 'true' : 'false') .
"' posted='".$p[0]['created']. "' posted='".$p[0]['created'].
"' message_id='".$p[0]['mid']."']"; "' message_id='".$p[0]['mid']."']";
if($p[0]['title']) if($p[0]['title'])
@ -292,6 +294,7 @@ class Oep extends \Zotlabs\Web\Controller {
"' profile='".$p[0]['author']['xchan_url'] . "' profile='".$p[0]['author']['xchan_url'] .
"' avatar='".$p[0]['author']['xchan_photo_s']. "' avatar='".$p[0]['author']['xchan_photo_s'].
"' link='".$p[0]['plink']. "' link='".$p[0]['plink'].
"' auth='".(($p[0]['author']['network'] === 'zot') ? 'true' : 'false') .
"' posted='".$p[0]['created']. "' posted='".$p[0]['created'].
"' message_id='".$p[0]['mid']."']"; "' message_id='".$p[0]['mid']."']";
if($p[0]['title']) if($p[0]['title'])
@ -366,6 +369,7 @@ class Oep extends \Zotlabs\Web\Controller {
"' profile='".$p[0]['author']['xchan_url'] . "' profile='".$p[0]['author']['xchan_url'] .
"' avatar='".$p[0]['author']['xchan_photo_s']. "' avatar='".$p[0]['author']['xchan_photo_s'].
"' link='".$p[0]['plink']. "' link='".$p[0]['plink'].
"' auth='".(($p[0]['author']['network'] === 'zot') ? 'true' : 'false') .
"' posted='".$p[0]['created']. "' posted='".$p[0]['created'].
"' message_id='".$p[0]['mid']."']"; "' message_id='".$p[0]['mid']."']";
if($p[0]['title']) if($p[0]['title'])

View File

@ -111,43 +111,7 @@ class Rpost extends \Zotlabs\Web\Controller {
} }
if($_REQUEST['post_id']) { if($_REQUEST['post_id']) {
$r = q("SELECT * from item WHERE id = %d LIMIT 1", $_REQUEST['body'] .= '[share=' . intval($_REQUEST['post_id']) . '][/share]';
intval($_REQUEST['post_id'])
);
if(($r) && (! intval($r[0]['item_private']))) {
$sql_extra = item_permissions_sql($r[0]['uid']);
$r = q("select * from item where id = %d $sql_extra",
intval($_REQUEST['post_id'])
);
if($r && $r[0]['mimetype'] === 'text/bbcode') {
xchan_query($r);
$is_photo = (($r[0]['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false);
if($is_photo) {
$object = json_decode($r[0]['obj'],true);
$photo_bb = $object['body'];
}
if (strpos($r[0]['body'], "[/share]") !== false) {
$pos = strpos($r[0]['body'], "[share");
$i = substr($r[0]['body'], $pos);
} else {
$i = "[share author='".urlencode($r[0]['author']['xchan_name']).
"' profile='".$r[0]['author']['xchan_url'] .
"' avatar='".$r[0]['author']['xchan_photo_s'].
"' link='".$r[0]['plink'].
"' posted='".$r[0]['created'].
"' message_id='".$r[0]['mid']."']";
if($r[0]['title'])
$i .= '[b]'.$r[0]['title'].'[/b]'."\r\n";
$i .= (($is_photo) ? $photo_bb . "\r\n" . $r[0]['body'] : $r[0]['body']);
$i .= "[/share]";
}
}
}
$_REQUEST['body'] = $_REQUEST['body'] . $i;
} }
$x = array( $x = array(

View File

@ -14,10 +14,15 @@ class Share extends \Zotlabs\Web\Controller {
if(! $post_id) if(! $post_id)
killme(); killme();
echo '[share=' . $post_id . '][/share]'; echo '[share=' . $post_id . '][/share]';
killme(); killme();
/**
* The remaining code is deprecated and handled in Zotlabs/Lib/Share.php at post
* submission time.
*/
if(! (local_channel() || remote_channel())) if(! (local_channel() || remote_channel()))
killme(); killme();
@ -60,12 +65,14 @@ class Share extends \Zotlabs\Web\Controller {
$pos = strpos($r[0]['body'], "[share"); $pos = strpos($r[0]['body'], "[share");
$o = substr($r[0]['body'], $pos); $o = substr($r[0]['body'], $pos);
} else { } else {
$o = "[share author='".urlencode($r[0]['author']['xchan_name']). $o = "[share author='" . urlencode($r[0]['author']['xchan_name']) .
"' profile='".$r[0]['author']['xchan_url'] . "' profile='" . $r[0]['author']['xchan_url'] .
"' avatar='".$r[0]['author']['xchan_photo_s']. "' avatar='" . $r[0]['author']['xchan_photo_s'] .
"' link='".$r[0]['plink']. "' link='" . $r[0]['plink'] .
"' posted='".$r[0]['created']. "' auth='" . (($r[0]['author']['network'] === 'zot') ? 'true' : 'false') .
"' message_id='".$r[0]['mid']."']"; "' posted='" . $r[0]['created'] .
"' message_id='" . $r[0]['mid'] .
"']";
if($r[0]['title']) if($r[0]['title'])
$o .= '[b]'.$r[0]['title'].'[/b]'."\r\n"; $o .= '[b]'.$r[0]['title'].'[/b]'."\r\n";
$o .= (($is_photo) ? $photo_bb . "\r\n" . $r[0]['body'] : $r[0]['body']); $o .= (($is_photo) ? $photo_bb . "\r\n" . $r[0]['body'] : $r[0]['body']);

View File

@ -311,6 +311,19 @@ function bb_ShareAttributes($match) {
if ($matches[1] != "") if ($matches[1] != "")
$posted = $matches[1]; $posted = $matches[1];
$auth = "";
preg_match("/auth='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "") {
if($matches[1] === 'true')
$auth = true;
else
$auth = false;
}
if($auth === EMPTY_STR) {
$auth = is_matrix_url($profile);
}
// message_id is never used, do we still need it? // message_id is never used, do we still need it?
$message_id = ""; $message_id = "";
preg_match("/message_id='(.*?)'/ism", $attributes, $matches); preg_match("/message_id='(.*?)'/ism", $attributes, $matches);
@ -329,7 +342,7 @@ function bb_ShareAttributes($match) {
$headline = '<div class="shared_container"> <div class="shared_header">'; $headline = '<div class="shared_container"> <div class="shared_header">';
if ($avatar != "") if ($avatar != "")
$headline .= '<a href="' . ((is_matrix_url($profile)) ? zid($profile) : $profile) . '" ><img src="' . $avatar . '" alt="' . $author . '" height="32" width="32" /></a>'; $headline .= '<a href="' . (($auth) ? zid($profile) : $profile) . '" ><img src="' . $avatar . '" alt="' . $author . '" height="32" width="32" /></a>';
if(strpos($link,'/cards/')) if(strpos($link,'/cards/'))
$type = t('card'); $type = t('card');
@ -341,8 +354,8 @@ function bb_ShareAttributes($match) {
// Bob Smith wrote the following post 2 hours ago // Bob Smith wrote the following post 2 hours ago
$fmt = sprintf( t('%1$s wrote the following %2$s %3$s'), $fmt = sprintf( t('%1$s wrote the following %2$s %3$s'),
'<a href="' . ((is_matrix_url($profile)) ? zid($profile) : $profile) . '" >' . $author . '</a>', '<a href="' . (($auth) ? zid($profile) : $profile) . '" >' . $author . '</a>',
'<a href="' . ((is_matrix_url($link)) ? zid($link) : $link) . '" >' . $type . '</a>', '<a href="' . (($auth) ? zid($link) : $link) . '" >' . $type . '</a>',
$reldate $reldate
); );

View File

@ -934,6 +934,7 @@ function feed_get_reshare(&$res,$item) {
"' profile='" . $share['profile'] . "' profile='" . $share['profile'] .
"' avatar='" . $share['avatar'] . "' avatar='" . $share['avatar'] .
"' link='" . $share['alternate'] . "' link='" . $share['alternate'] .
"' auth='" . 'false' .
"' posted='" . $share['created'] . "' posted='" . $share['created'] .
"' message_id='" . $share['message_id'] . "']"; "' message_id='" . $share['message_id'] . "']";