Only add picture link under conditions

pull/569/head
Michael 2018-04-02 07:12:43 +00:00
parent b3236d69a1
commit 476cb92a3b
1 changed files with 10 additions and 3 deletions

View File

@ -528,8 +528,8 @@ function twitter_post_hook(App $a, &$b)
$connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret); $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
// Set the timeout for upload to 15 seconds // Set the timeout for upload to 30 seconds
$connection->setTimeouts(10, 15); $connection->setTimeouts(10, 30);
$max_char = 280; $max_char = 280;
$msgarr = BBCode::toPlaintext($b, $max_char, true, 8); $msgarr = BBCode::toPlaintext($b, $max_char, true, 8);
@ -543,6 +543,9 @@ function twitter_post_hook(App $a, &$b)
if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) { if (isset($msgarr["url"]) && ($msgarr["type"] != "photo")) {
$msg .= "\n" . $msgarr["url"]; $msg .= "\n" . $msgarr["url"];
$url_added = true;
} else {
$url_added = false;
} }
if (isset($msgarr["image"]) && ($msgarr["type"] != "video")) { if (isset($msgarr["image"]) && ($msgarr["type"] != "video")) {
@ -572,7 +575,11 @@ function twitter_post_hook(App $a, &$b)
logger('Exception when trying to send to Twitter: ' . $e->getMessage()); logger('Exception when trying to send to Twitter: ' . $e->getMessage());
// Workaround: Remove the picture link so that the post can be reposted without it // Workaround: Remove the picture link so that the post can be reposted without it
$msg .= " " . $image; // When there is another url already added, a second url would be superfluous.
if (!$url_added) {
$msg .= "\n" . $image;
}
$image = ""; $image = "";
} }
} }