// - Adding last status
if (!$skip_status) {
$item = api_get_last_status($user_info['pid'], $user_info['uid']);
- if ($item) {
+ if (!empty($item)) {
$user_info['status'] = api_format_item($item, $type);
}
}
$status_info = [];
$item = api_get_item(['id' => $item_id]);
- if ($item) {
+ if (!empty($item)) {
$status_info = api_format_item($item, $type);
}
$user_info = api_get_user($a);
$item = api_get_last_status($user_info['pid'], $user_info['uid']);
- if ($item) {
+ if (!empty($item)) {
$user_info['status'] = api_format_item($item, $type);
}
Logger::log('API: api_statuses_repeat: '.$id);
- $fields = ['body', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
+ $fields = ['body', 'title', 'attach', 'tag', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Item::selectFirst($fields, ['id' => $id, 'private' => false]);
if (DBA::isResult($item) && $item['body'] != "") {
} else {
$post = share_header($item['author-name'], $item['author-link'], $item['author-avatar'], $item['guid'], $item['created'], $item['plink']);
+ if (!empty($item['title'])) {
+ $post .= '[h3]' . $item['title'] . "[/h3]\n";
+ }
+
$post .= $item['body'];
$post .= "[/share]";
}
$_REQUEST['body'] = $post;
+ $_REQUEST['tag'] = $item['tag'];
+ $_REQUEST['attach'] = $item['attach'];
$_REQUEST['profile_uid'] = api_user();
$_REQUEST['api_source'] = true;
function api_convert_item($item)
{
$body = $item['body'];
+ $entities = api_get_entitities($statustext, $body);
+
+ // Add pictures to the attachment array and remove them from the body
$attachments = api_get_attachments($body);
// Workaround for ostatus messages where the title is identically to the body
$statustext = mb_substr($statustext, 0, 1000) . "... \n" . ($item['plink'] ?? '');
}
- $statushtml = BBCode::convert(api_clean_attachments($body), false);
+ $statushtml = BBCode::convert(BBCode::removeAttachment($body), false);
// Workaround for clients with limited HTML parser functionality
$search = ["<br>", "<blockquote>", "</blockquote>",
$statushtml .= BBCode::convert($item['plink']);
}
- $entities = api_get_entitities($statustext, $body);
-
return [
"text" => $statustext,
"html" => $statushtml,
*/
function api_get_attachments(&$body)
{
- $text = $body;
- $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $text);
+ $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
+ $body = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $body);
$URLSearchString = "^\[\]";
- $ret = preg_match_all("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $text, $images);
-
- if (!$ret) {
+ if (!preg_match_all("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $body, $images)) {
return [];
}
+ // Remove all embedded pictures, since they are added as attachments
+ foreach ($images[0] as $orig) {
+ $body = str_replace($orig, '', $body);
+ }
+
$attachments = [];
foreach ($images[1] as $image) {
}
}
- if (strstr($_SERVER['HTTP_USER_AGENT'] ?? '', 'AndStatus')) {
- foreach ($images[0] as $orig) {
- $body = str_replace($orig, "", $body);
- }
- }
-
return $attachments;
}
$bbcode = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '#$2', $bbcode);
$bbcode = preg_replace("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism", '[url=$1]$2[/url]', $bbcode);
- //$bbcode = preg_replace("/\[url\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$bbcode);
$bbcode = preg_replace("/\[video\](.*?)\[\/video\]/ism", '[url=$1]$1[/url]', $bbcode);
$bbcode = preg_replace(
$bbcode = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $bbcode);
- //preg_match_all("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $bbcode, $urls1);
preg_match_all("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $bbcode, $urls);
$ordered_urls = [];
foreach ($urls[1] as $id => $url) {
- //$start = strpos($text, $url, $offset);
$start = iconv_strpos($text, $url, 0, "UTF-8");
if (!($start === false)) {
$ordered_urls[$start] = ["url" => $url, "title" => $urls[2][$id]];
ksort($ordered_urls);
$offset = 0;
- //foreach ($urls[1] AS $id=>$url) {
+
foreach ($ordered_urls as $url) {
if ((substr($url["title"], 0, 7) != "http://") && (substr($url["title"], 0, 8) != "https://")
&& !strpos($url["title"], "http://") && !strpos($url["title"], "https://")
}
}
- //$start = strpos($text, $url, $offset);
$start = iconv_strpos($text, $url["url"], $offset, "UTF-8");
if (!($start === false)) {
$entities["urls"][] = ["url" => $url["url"],
$ordered_images[$start] = ['url' => $image, 'alt' => ''];
}
}
- //$entities["media"] = array();
+
$offset = 0;
foreach ($ordered_images as $image) {
}
if (!empty($quoted_item)) {
- $conv_quoted = api_convert_item($quoted_item);
- $quoted_status = $status;
+ if ($quoted_item['id'] != $item['id']) {
+ $quoted_status = api_format_item($quoted_item);
+ /// @todo Only remove the attachments that are also contained in the quotes status
+ unset($status['attachments']);
+ unset($status['entities']);
+ } else {
+ $conv_quoted = api_convert_item($quoted_item);
+ $quoted_status = $status;
+ unset($quoted_status['attachments']);
+ unset($quoted_status['entities']);
+ unset($quoted_status['statusnet_conversation_id']);
+ $quoted_status['text'] = $conv_quoted['text'];
+ $quoted_status['statusnet_html'] = $conv_quoted['html'];
+ try {
+ $quoted_status["user"] = api_get_user($a, $quoted_item["author-id"]);
+ } catch (BadRequestException $e) {
+ // user not found. should be found?
+ /// @todo check if the user should be always found
+ $quoted_status["user"] = [];
+ }
+ }
unset($quoted_status['friendica_author']);
unset($quoted_status['friendica_owner']);
unset($quoted_status['friendica_activities']);
unset($quoted_status['friendica_private']);
- unset($quoted_status['statusnet_conversation_id']);
- $quoted_status['text'] = $conv_quoted['text'];
- $quoted_status['statusnet_html'] = $conv_quoted['html'];
- try {
- $quoted_status["user"] = api_get_user($a, $quoted_item["author-id"]);
- } catch (BadRequestException $e) {
- // user not found. should be found?
- /// @todo check if the user should be always found
- $quoted_status["user"] = [];
- }
}
if (!empty($retweeted_item)) {
}
}
- /// @TODO "$1" should maybe mean '$1' ?
- $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", "$1", $body);
- /*
- * Skip if there is no shared message in there
- * we already checked this in diaspora::isReshare()
- * but better one more than one less...
- */
- if (($body == $attributes) || empty($attributes)) {
+ $reshared = Item::getShareArray($item);
+ if (empty($reshared)) {
return false;
}
- // build the fake reshared item
$reshared_item = $item;
- $author = "";
- preg_match("/author='(.*?)'/ism", $attributes, $matches);
- if (!empty($matches[1])) {
- $author = html_entity_decode($matches[1], ENT_QUOTES, 'UTF-8');
- }
-
- preg_match('/author="(.*?)"/ism', $attributes, $matches);
- if (!empty($matches[1])) {
- $author = $matches[1];
- }
-
- $profile = "";
- preg_match("/profile='(.*?)'/ism", $attributes, $matches);
- if (!empty($matches[1])) {
- $profile = $matches[1];
- }
-
- preg_match('/profile="(.*?)"/ism', $attributes, $matches);
- if (!empty($matches[1])) {
- $profile = $matches[1];
- }
-
- $avatar = "";
- preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
- if (!empty($matches[1])) {
- $avatar = $matches[1];
- }
-
- preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
- if (!empty($matches[1])) {
- $avatar = $matches[1];
- }
-
- $link = "";
- preg_match("/link='(.*?)'/ism", $attributes, $matches);
- if (!empty($matches[1])) {
- $link = $matches[1];
- }
-
- preg_match('/link="(.*?)"/ism', $attributes, $matches);
- if (!empty($matches[1])) {
- $link = $matches[1];
- }
-
- $posted = "";
- preg_match("/posted='(.*?)'/ism", $attributes, $matches);
- if (!empty($matches[1])) {
- $posted = $matches[1];
- }
-
- preg_match('/posted="(.*?)"/ism', $attributes, $matches);
- if (!empty($matches[1])) {
- $posted = $matches[1];
- }
-
- if (!preg_match("/(.*?)\[share.*?\]\s?(.*?)\s?\[\/share\]\s?(.*?)/ism", $body, $matches)) {
+ if (empty($reshared['shared']) || empty($reshared['profile']) || empty($reshared['author']) || empty($reshared['avatar']) || empty($reshared['posted'])) {
return false;
}
- $pre_body = trim($matches[1]);
- if ($pre_body != '') {
- $item['body'] = $pre_body;
+ if (!empty($reshared['comment'])) {
+ $item['body'] = $reshared['comment'];
}
- $shared_body = trim($matches[2]);
+ $reshared_item["share-pre-body"] = $reshared['comment'];
+ $reshared_item["body"] = $reshared['shared'];
+ $reshared_item["author-id"] = Contact::getIdForURL($reshared['profile'], 0, true);
+ $reshared_item["author-name"] = $reshared['author'];
+ $reshared_item["author-link"] = $reshared['profile'];
+ $reshared_item["author-avatar"] = $reshared['avatar'];
+ $reshared_item["plink"] = $reshared['link'] ?? '';
+ $reshared_item["created"] = $reshared['posted'];
+ $reshared_item["edited"] = $reshared['posted'];
- if (($shared_body == "") || ($profile == "") || ($author == "") || ($avatar == "") || ($posted == "")) {
- return false;
+ // Try to fetch the original item
+ if (!empty($reshared['guid'])) {
+ $condition = ['guid' => $reshared['guid'], 'uid' => [0, $item['uid']]];
+ } elseif (!empty($reshared_item['plink']) && ($original_id = Item::searchByLink($reshared_item['plink']))) {
+ $condition = ['id' => $original_id];
+ } else {
+ $condition = [];
}
- $reshared_item["share-pre-body"] = $pre_body;
- $reshared_item["body"] = $shared_body;
- $reshared_item["author-id"] = Contact::getIdForURL($profile, 0, true);
- $reshared_item["author-name"] = $author;
- $reshared_item["author-link"] = $profile;
- $reshared_item["author-avatar"] = $avatar;
- $reshared_item["plink"] = $link;
- $reshared_item["created"] = $posted;
- $reshared_item["edited"] = $posted;
+ if (!empty($condition)) {
+ $original_item = Item::selectFirst([], $condition);
+ if (DBA::isResult($original_item)) {
+ $reshared_item = array_merge($reshared_item, $original_item);
+ }
+ }
return $reshared_item;
}
}
// Simplify "attachment" element
- $text = api_clean_attachments($text);
+ $text = BBCode::removeAttachment($text);
return $text;
}
-/**
- * @brief Removes most sharing information for API text export
- *
- * @param string $body The original body
- *
- * @return string Cleaned body
- * @throws InternalServerErrorException
- */
-function api_clean_attachments($body)
-{
- $data = BBCode::getAttachmentData($body);
-
- if (empty($data)) {
- return $body;
- }
- $body = "";
-
- if (isset($data["text"])) {
- $body = $data["text"];
- }
- if (($body == "") && isset($data["title"])) {
- $body = $data["title"];
- }
- if (isset($data["url"])) {
- $body .= "\n".$data["url"];
- }
- $body .= $data["after"];
-
- return $body;
-}
-
/**
*
* @param array $contacts