use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
+use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
}
// if post comes from twitter don't send it back
- if ($b['extid'] == NETWORK_TWITTER) {
+ if ($b['extid'] == Protocol::TWITTER) {
return;
}
$s = serialize(['url' => $url, 'item' => $b['id'], 'post' => $post]);
- Queue::add($a->contact, NETWORK_TWITTER, $s);
+ Queue::add($a->contact, Protocol::TWITTER, $s);
notice(L10n::t('Twitter post failed. Queued for retry.') . EOL);
} elseif ($iscomment) {
logger('twitter_post: Update extid ' . $result->id_str . " for post id " . $b['id']);
return;
}
- $r = DBA::select('item', ['id', 'iaid', 'icid'], ['deleted' => true, 'network' => NETWORK_TWITTER]);
+ $r = Item::select(['id'], ['deleted' => true, 'network' => Protocol::TWITTER]);
while ($row = DBA::fetch($r)) {
DBA::delete('item', ['id' => $row['id']]);
- if (!empty($row['iaid']) && !DBA::exists('item', ['iaid' => $row['iaid']])) {
- DBA::delete('item-activity', ['id' => $row['iaid']]);
- }
- if (!empty($row['icid']) && !DBA::exists('item', ['icid' => $row['icid']])) {
- DBA::delete('item-content', ['id' => $row['icid']]);
- }
}
DBA::close($r);
if (DBA::isResult($r)) {
foreach ($r as $rr) {
logger('twitter_expire: user ' . $rr['uid']);
- Item::expire($rr['uid'], $days, NETWORK_TWITTER, true);
+ Item::expire($rr['uid'], $days, Protocol::TWITTER, true);
}
}
function twitter_prepare_body(App $a, array &$b)
{
- if ($b["item"]["network"] != NETWORK_TWITTER) {
+ if ($b["item"]["network"] != Protocol::TWITTER) {
return;
}
{
$datarray['api_source'] = true;
$datarray['profile_uid'] = $uid;
- $datarray['extid'] = NETWORK_TWITTER;
- $datarray['message_id'] = Item::newURI($uid, NETWORK_TWITTER . ':' . $post->id);
+ $datarray['extid'] = Protocol::TWITTER;
+ $datarray['message_id'] = Item::newURI($uid, Protocol::TWITTER . ':' . $post->id);
$datarray['protocol'] = Conversation::PARCEL_TWITTER;
$datarray['source'] = json_encode($post);
$datarray['title'] = '';
// 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);
+ if (empty($item['body'])) {
+ return [];
+ }
+
$datarray['body'] = "\n" . share_header(
$item['author-name'],
$item['author-link'],
} else {
$item = twitter_createpost($a, $uid, $post, ['id' => 0], false, false, false);
+ if (empty($item['body'])) {
+ return [];
+ }
+
$datarray['body'] = $item['body'];
}
$_REQUEST = twitter_do_mirrorpost($a, $uid, $post);
+ if (empty($_REQUEST['body'])) {
+ continue;
+ }
+
logger('twitter: posting for user ' . $uid);
item_post($a);
function twitter_queue_hook(App $a)
{
$qi = q("SELECT * FROM `queue` WHERE `network` = '%s'",
- DBA::escape(NETWORK_TWITTER)
+ DBA::escape(Protocol::TWITTER)
);
if (!DBA::isResult($qi)) {
return;
}
foreach ($qi as $x) {
- if ($x['network'] !== NETWORK_TWITTER) {
+ if ($x['network'] !== Protocol::TWITTER) {
continue;
}
function twitter_fetch_contact($uid, $data, $create_user)
{
- if ($data->id_str == "") {
+ if (empty($data->id_str)) {
return -1;
}
$url = "https://twitter.com/" . $data->screen_name;
$addr = $data->screen_name . "@twitter.com";
- GContact::update(["url" => $url, "network" => NETWORK_TWITTER,
+ GContact::update(["url" => $url, "network" => Protocol::TWITTER,
"photo" => $avatar, "hide" => true,
"name" => $data->name, "nick" => $data->screen_name,
"location" => $data->location, "about" => $data->description,
"addr" => $addr, "generation" => 2]);
- $fields = ['url' => $url, 'network' => NETWORK_TWITTER,
+ $fields = ['url' => $url, 'network' => Protocol::TWITTER,
'name' => $data->name, 'nick' => $data->screen_name, 'addr' => $addr,
'location' => $data->location, 'about' => $data->description];
//$dontincludemedia = true;
$type = $oembed_data->type;
$footerurl = $expanded_url;
- $footerlink = "[url=" . $expanded_url . "]" . $expanded_url . "[/url]";
+ $footerlink = "[url=" . $expanded_url . "]" . $url->display_url . "[/url]";
$body = str_replace($url->url, $footerlink, $body);
//} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia) {
$body = str_replace($url->url, "[url=" . $expanded_url . "][img]" . $oembed_data->url . "[/img][/url]", $body);
//$dontincludemedia = true;
} elseif ($oembed_data->type != "link") {
- $body = str_replace($url->url, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body);
+ $body = str_replace($url->url, "[url=" . $expanded_url . "]" . $url->display_url . "[/url]", $body);
} else {
$img_str = Network::fetchUrl($expanded_url, true, $redirects, 4);
$tempfile = tempnam(get_temppath(), "cache");
file_put_contents($tempfile, $img_str);
- $mime = image_type_to_mime_type(exif_imagetype($tempfile));
+
+ // See http://php.net/manual/en/function.exif-imagetype.php#79283
+ if (filesize($tempfile) > 11) {
+ $mime = image_type_to_mime_type(exif_imagetype($tempfile));
+ } else {
+ $mime = false;
+ }
+
unlink($tempfile);
if (substr($mime, 0, 6) == "image/") {
} else {
$type = $oembed_data->type;
$footerurl = $expanded_url;
- $footerlink = "[url=" . $expanded_url . "]" . $expanded_url . "[/url]";
+ $footerlink = "[url=" . $expanded_url . "]" . $url->display_url . "[/url]";
$body = str_replace($url->url, $footerlink, $body);
}
function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $only_existing_contact, $noquote)
{
$postarray = [];
- $postarray['network'] = NETWORK_TWITTER;
+ $postarray['network'] = Protocol::TWITTER;
$postarray['uid'] = $uid;
$postarray['wall'] = 0;
$postarray['uri'] = "twitter::" . $post->id_str;
$postarray['source'] = json_encode($post);
// Don't import our own comments
- if (DBA::exists('item', ['extid' => $postarray['uri'], 'uid' => $uid])) {
+ if (Item::exists(['extid' => $postarray['uri'], 'uid' => $uid])) {
logger("Item with extid " . $postarray['uri'] . " found.", LOGGER_DEBUG);
return [];
}
if (!empty($post->retweeted_status)) {
$retweet = twitter_createpost($a, $uid, $post->retweeted_status, $self, false, false, $noquote);
+ if (empty($retweet['body'])) {
+ return [];
+ }
+
$retweet['source'] = $postarray['source'];
$retweet['private'] = $postarray['private'];
$retweet['allow_cid'] = $postarray['allow_cid'];
if (!empty($post->quoted_status) && !$noquote) {
$quoted = twitter_createpost($a, $uid, $post->quoted_status, $self, false, false, true);
+ if (empty($quoted['body'])) {
+ return [];
+ }
+
$postarray['body'] = $statustext;
$postarray['body'] .= "\n" . share_header(
$posts = [];
- while ($post->in_reply_to_status_id_str != "") {
+ while (!empty($post->in_reply_to_status_id_str)) {
$parameters = ["trim_user" => false, "tweet_mode" => "extended", "id" => $post->in_reply_to_status_id_str];
try {
break;
}
- if (DBA::exists('item', ['uri' => 'twitter::' . $post->id_str, 'uid' => $uid])) {
+ if (Item::exists(['uri' => 'twitter::' . $post->id_str, 'uid' => $uid])) {
break;
}
$notify = false;
- if ($postarray['uri'] == $postarray['parent-uri']) {
+ if (($postarray['uri'] == $postarray['parent-uri']) && ($postarray['author-link'] == $postarray['owner-link'])) {
$contact = DBA::selectFirst('contact', [], ['id' => $postarray['contact-id'], 'self' => false]);
if (DBA::isResult($contact)) {
$notify = Item::isRemoteSelf($contact, $postarray);
$postarray = twitter_createpost($a, $uid, $post, $self, false, false, false);
- if (trim($postarray['body']) == "") {
+ if (empty($postarray['body'])) {
continue;
}