use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\ItemContent;
+use Friendica\Model\ItemURI;
+use Friendica\Model\Tag;
+use Friendica\Model\Term;
use Friendica\Model\User;
use Friendica\Protocol\Activity;
use Friendica\Util\ConfigFileLoader;
if (!empty($post->retweeted_status)) {
// We don't support nested shares, so we mustn't show quotes as shares on retweets
- $item = twitter_createpost($a, $uid, $post->retweeted_status, ['id' => 0], false, false, true);
+ $item = twitter_createpost($a, $uid, $post->retweeted_status, ['id' => 0], false, false, true, -1);
if (empty($item['body'])) {
return [];
$datarray['body'] .= $item['body'] . '[/share]';
} else {
- $item = twitter_createpost($a, $uid, $post, ['id' => 0], false, false, false);
+ $item = twitter_createpost($a, $uid, $post, ['id' => 0], false, false, false, -1);
if (empty($item['body'])) {
return [];
$plain = $body;
$tags = [];
+ $taglist = [];
$replacementList = [];
foreach ($status->entities->hashtags AS $hashtag) {
$replace = '#[url=' . DI::baseUrl()->get() . '/search?tag=' . $hashtag->text . ']' . $hashtag->text . '[/url]';
$tags['#' . $hashtag->text] = $replace;
+ $taglist['#' . $hashtag->text] = ['#', $hashtag->text, ''];
$replacementList[$hashtag->indices[0]] = [
'replace' => $replace,
foreach ($status->entities->user_mentions AS $mention) {
$replace = '@[url=https://twitter.com/' . rawurlencode($mention->screen_name) . ']' . $mention->screen_name . '[/url]';
$tags['@' . $mention->screen_name] = $replace;
+ $taglist['@' . $mention->screen_name] = ['@', $mention->screen_name, 'https://twitter.com/' . rawurlencode($mention->screen_name)];
$replacementList[$mention->indices[0]] = [
'replace' => $replace,
}
}
- return ['body' => $body, 'tags' => $tags, 'plain' => $plain];
+ return ['body' => $body, 'tags' => $tags, 'plain' => $plain, 'taglist' => $taglist];
}
/**
return '';
}
-function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $only_existing_contact, $noquote)
+function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $only_existing_contact, $noquote, int $uriid = 0)
{
$postarray = [];
$postarray['network'] = Protocol::TWITTER;
$postarray['protocol'] = Conversation::PARCEL_TWITTER;
$postarray['source'] = json_encode($post);
+ if (empty($uriid)) {
+ $uriid = $postarray['uri-id'] = ItemURI::insert(['uri' => $postarray['uri']]);
+ }
+
// Don't import our own comments
if (Item::exists(['extid' => $postarray['uri'], 'uid' => $uid])) {
Logger::log("Item with extid " . $postarray['uri'] . " found.", Logger::DEBUG);
$converted = twitter_expand_entities($postarray['body'], $post, $picture);
$postarray['body'] = $converted['body'];
- $postarray['tag'] = implode($converted['tags'], ',');
+ $postarray['tag'] = implode(',', $converted['tags']);
$postarray['created'] = DateTimeFormat::utc($post->created_at);
$postarray['edited'] = DateTimeFormat::utc($post->created_at);
+ if ($uriid > 0) {
+ twitter_store_tags($uriid, $converted['taglist']);
+ }
+
$statustext = $converted["plain"];
if (!empty($post->place->name)) {
}
if (!empty($post->quoted_status) && !$noquote) {
- $quoted = twitter_createpost($a, $uid, $post->quoted_status, $self, false, false, true);
+ $quoted = twitter_createpost($a, $uid, $post->quoted_status, $self, false, false, true, $uriid);
if (!empty($quoted['body'])) {
$postarray['body'] .= "\n" . share_header(
return $postarray;
}
+/**
+ * Store tags and mentions
+ *
+ * @param integer $uriid
+ * @param array $taglist
+ */
+function twitter_store_tags(int $uriid, array $taglist)
+{
+ foreach ($taglist as $tag) {
+ Tag::storeByHash($uriid, $tag[0], $tag[1], $tag[2]);
+ }
+}
+
function twitter_fetchparentposts(App $a, $uid, $post, TwitterOAuth $connection, array $self)
{
Logger::log("twitter_fetchparentposts: Fetching for user " . $uid . " and post " . $post->id_str, Logger::DEBUG);
return $content . "\n\n" . $attributes['link'];
}
- if ($author_contact['network'] == Protocol::TWITTER) {
+ if (!empty($author_contact['network']) && ($author_contact['network'] == Protocol::TWITTER)) {
$mention = '@' . $author_contact['nick'];
} else {
$mention = $author_contact['addr'];