Merge pull request #11974 from annando/issue-11969
Issue 11969: Simplified share
This commit is contained in:
commit
47dd19ab95
3 changed files with 27 additions and 29 deletions
|
@ -21,13 +21,11 @@
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\Protocol;
|
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Util\Network;
|
|
||||||
|
|
||||||
function share_init(App $a) {
|
function share_init(App $a) {
|
||||||
$post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0);
|
$post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0);
|
||||||
|
@ -36,30 +34,21 @@ function share_init(App $a) {
|
||||||
System::exit();
|
System::exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar',
|
$fields = ['private', 'body', 'uri'];
|
||||||
'guid', 'created', 'plink', 'uri', 'title', 'network'];
|
|
||||||
$item = Post::selectFirst($fields, ['id' => $post_id]);
|
$item = Post::selectFirst($fields, ['id' => $post_id]);
|
||||||
|
|
||||||
if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) {
|
if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) {
|
||||||
System::exit();
|
System::exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($item['body'], "[/share]") !== false) {
|
$shared = BBCode::fetchShareAttributes($item['body']);
|
||||||
$pos = strpos($item['body'], "[share");
|
if (!empty($shared['message_id']) || !empty($shared['link'])) {
|
||||||
$o = substr($item['body'], $pos);
|
$content = '[share]' . ($shared['message_id'] ?: $shared['link']) . '[/share]';
|
||||||
} elseif (Network::isValidHttpUrl($item['uri']) && in_array($item['network'], Protocol::FEDERATED)) {
|
} elseif (strpos($item['body'], '[/share]') !== false) {
|
||||||
$o = "[share]" . $item['uri'] . "[/share]";
|
$pos = strpos($item['body'], '[share');
|
||||||
|
$content = substr($item['body'], $pos);
|
||||||
} else {
|
} else {
|
||||||
$o = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid']);
|
$content = '[share]' . $item['uri'] . '[/share]';
|
||||||
|
|
||||||
if ($item['title']) {
|
|
||||||
$o .= '[h3]'.$item['title'].'[/h3]'."\n";
|
|
||||||
}
|
}
|
||||||
|
System::httpExit($content);
|
||||||
$o .= $item['body'];
|
|
||||||
$o .= "[/share]";
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $o;
|
|
||||||
System::exit();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1016,6 +1016,7 @@ class BBCode
|
||||||
* - avatar : (Optional) Profile picture URL of the shared author
|
* - avatar : (Optional) Profile picture URL of the shared author
|
||||||
* - link : (Optional) Canonical URL of the shared post
|
* - link : (Optional) Canonical URL of the shared post
|
||||||
* - posted : (Optional) Date the shared post was initially posted ("Y-m-d H:i:s" in GMT)
|
* - posted : (Optional) Date the shared post was initially posted ("Y-m-d H:i:s" in GMT)
|
||||||
|
* - message_id: (Optional) Shared post URI if any
|
||||||
* - guid : (Optional) Shared post GUID if any
|
* - guid : (Optional) Shared post GUID if any
|
||||||
*/
|
*/
|
||||||
public static function fetchShareAttributes(string $text): array
|
public static function fetchShareAttributes(string $text): array
|
||||||
|
|
|
@ -3671,7 +3671,15 @@ class Item
|
||||||
return $item['body'];
|
return $item['body'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = self::fetchByLink($shared['link'] ?: $shared['message_id']);
|
$link = $shared['link'] ?: $shared['message_id'];
|
||||||
|
|
||||||
|
if (!empty($item['uid'])) {
|
||||||
|
$id = self::searchByLink($link, $item['uid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($id)) {
|
||||||
|
$id = self::fetchByLink($link);
|
||||||
|
}
|
||||||
Logger::debug('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'uri' => $shared['message_id'], 'callstack' => System::callstack()]);
|
Logger::debug('Fetched shared post', ['uri-id' => $item['uri-id'], 'id' => $id, 'author' => $shared['profile'], 'url' => $shared['link'], 'guid' => $shared['guid'], 'uri' => $shared['message_id'], 'callstack' => System::callstack()]);
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
return $item['body'];
|
return $item['body'];
|
||||||
|
|
Loading…
Reference in a new issue