if (isset($msgarr["url"]) AND ($msgarr["type"] != "photo"))
$msg .= "\n".$msgarr["url"];
- elseif (isset($msgarr["image"]) AND ($msgarr["type"] != "video"))
+
+ if (isset($msgarr["image"]) AND ($msgarr["type"] != "video"))
$image = $msgarr["image"];
// and now tweet it :-)
if(count($r)) {
foreach($r as $rr) {
logger('twitter: fetching for user '.$rr['uid']);
- twitter_fetchtimeline($a, $rr['uid']);
+
+ if (get_config("system", "worker")) {
+ proc_run(PRIORITY_MEDIUM, "addon/twitter/twitter_sync.php", 1, $rr['uid']);
+ } else {
+ twitter_fetchtimeline($a, $rr['uid']);
+ }
}
}
}
logger('twitter: importing timeline from user '.$rr['uid']);
- twitter_fetchhometimeline($a, $rr["uid"]);
+ if (get_config("system", "worker")) {
+ proc_run(PRIORITY_MEDIUM, "addon/twitter/twitter_sync.php", 2, $rr['uid']);
+ } else {
+ twitter_fetchhometimeline($a, $rr["uid"]);
+ }
/*
// To-Do
// check for new contacts once a day
$datarray["profile_uid"] = $uid;
$datarray["extid"] = NETWORK_TWITTER;
$datarray['message_id'] = item_new_uri($a->get_hostname(), $uid, NETWORK_TWITTER.":".$post->id);
+ $datarray['object'] = json_encode($post);
$datarray["title"] = "";
if (is_object($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, array('id' => 0), false, false, true);
+ $item = twitter_createpost($a, $uid, $post->retweeted_status, array('id' => 0), false, false, true);
$datarray['body'] = "\n".share_header($item['author-name'], $item['author-link'], $item['author-avatar'], "",
$item['created'], $item['plink']);
require_once('library/twitteroauth.php');
$connection = new TwitterOAuth($ckey,$csecret,$otoken,$osecret);
- //$parameters = array("exclude_replies" => true, "trim_user" => false, "contributor_details" => true, "include_rts" => true);
$parameters = array("exclude_replies" => true, "trim_user" => false, "contributor_details" => true, "include_rts" => true, "tweet_mode" => "extended");
$first_time = ($lastid == "");
$avatar = twitter_fix_avatar($contact->profile_image_url_https);
- if (function_exists("update_gcontact"))
- update_gcontact(array("url" => "https://twitter.com/".$contact->screen_name,
- "network" => NETWORK_TWITTER, "photo" => $avatar, "hide" => true,
- "name" => $contact->name, "nick" => $contact->screen_name,
- "location" => $contact->location, "about" => $contact->description,
- "addr" => $contact->screen_name."@twitter.com", "generation" => 2));
- else {
- // Old Code
- $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
- dbesc(normalise_link("https://twitter.com/".$contact->screen_name)));
-
- if (count($r) == 0)
- q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
- dbesc(normalise_link("https://twitter.com/".$contact->screen_name)),
- dbesc($contact->name),
- dbesc($contact->screen_name),
- dbesc($avatar));
- else
- q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'",
- dbesc($contact->name),
- dbesc($contact->screen_name),
- dbesc($avatar),
- dbesc(normalise_link("https://twitter.com/".$contact->screen_name)));
-
- if (DB_UPDATE_VERSION >= "1177")
- q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'",
- dbesc($contact->location),
- dbesc($contact->description),
- dbesc(normalise_link("https://twitter.com/".$contact->screen_name)));
- }
+ update_gcontact(array("url" => "https://twitter.com/".$contact->screen_name,
+ "network" => NETWORK_TWITTER, "photo" => $avatar, "hide" => true,
+ "name" => $contact->name, "nick" => $contact->screen_name,
+ "location" => $contact->location, "about" => $contact->description,
+ "addr" => $contact->screen_name."@twitter.com", "generation" => 2));
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
intval($uid), dbesc("twitter::".$contact->id_str));
if(!count($r)) {
// create contact record
- q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
+ q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
`name`, `nick`, `photo`, `network`, `rel`, `priority`,
- `writable`, `blocked`, `readonly`, `pending` )
- VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0) ",
+ `location`, `about`, `writable`, `blocked`, `readonly`, `pending`)
+ VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, 0, 0, 0)",
intval($uid),
dbesc(datetime_convert()),
dbesc("https://twitter.com/".$contact->screen_name),
dbesc(NETWORK_TWITTER),
intval(CONTACT_IS_FRIEND),
intval(1),
+ dbesc($contact->location),
+ dbesc($contact->description),
intval(1)
);
require_once("Photo.php");
- $photos = import_profile_photo($avatar,$uid,$contact_id);
-
- q("UPDATE `contact` SET `photo` = '%s',
- `thumb` = '%s',
- `micro` = '%s',
- `name-date` = '%s',
- `uri-date` = '%s',
- `avatar-date` = '%s'
- WHERE `id` = %d",
- dbesc($photos[0]),
- dbesc($photos[1]),
- dbesc($photos[2]),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- intval($contact_id)
- );
+ $photos = import_profile_photo($avatar, $uid, $contact_id, true);
- if (DB_UPDATE_VERSION >= "1177")
- q("UPDATE `contact` SET `location` = '%s',
- `about` = '%s'
+ if ($photos) {
+ q("UPDATE `contact` SET `photo` = '%s',
+ `thumb` = '%s',
+ `micro` = '%s',
+ `name-date` = '%s',
+ `uri-date` = '%s',
+ `avatar-date` = '%s'
WHERE `id` = %d",
- dbesc($contact->location),
- dbesc($contact->description),
+ dbesc($photos[0]),
+ dbesc($photos[1]),
+ dbesc($photos[2]),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
intval($contact_id)
);
-
+ }
} else {
// update profile photos once every two weeks as we have no notification of when they change.
require_once("Photo.php");
- $photos = import_profile_photo($avatar, $uid, $r[0]['id']);
-
- q("UPDATE `contact` SET `photo` = '%s',
- `thumb` = '%s',
- `micro` = '%s',
- `name-date` = '%s',
- `uri-date` = '%s',
- `avatar-date` = '%s',
- `url` = '%s',
- `nurl` = '%s',
- `addr` = '%s',
- `name` = '%s',
- `nick` = '%s'
- WHERE `id` = %d",
- dbesc($photos[0]),
- dbesc($photos[1]),
- dbesc($photos[2]),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc("https://twitter.com/".$contact->screen_name),
- dbesc(normalise_link("https://twitter.com/".$contact->screen_name)),
- dbesc($contact->screen_name."@twitter.com"),
- dbesc($contact->name),
- dbesc($contact->screen_name),
- intval($r[0]['id'])
- );
-
- if (DB_UPDATE_VERSION >= "1177")
- q("UPDATE `contact` SET `location` = '%s',
+ $photos = import_profile_photo($avatar, $uid, $r[0]['id'], true);
+
+ if ($photos) {
+ q("UPDATE `contact` SET `photo` = '%s',
+ `thumb` = '%s',
+ `micro` = '%s',
+ `name-date` = '%s',
+ `uri-date` = '%s',
+ `avatar-date` = '%s',
+ `url` = '%s',
+ `nurl` = '%s',
+ `addr` = '%s',
+ `name` = '%s',
+ `nick` = '%s',
+ `location` = '%s',
`about` = '%s'
WHERE `id` = %d",
+ dbesc($photos[0]),
+ dbesc($photos[1]),
+ dbesc($photos[2]),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc("https://twitter.com/".$contact->screen_name),
+ dbesc(normalise_link("https://twitter.com/".$contact->screen_name)),
+ dbesc($contact->screen_name."@twitter.com"),
+ dbesc($contact->name),
+ dbesc($contact->screen_name),
dbesc($contact->location),
dbesc($contact->description),
intval($r[0]['id'])
);
+ }
}
}
$postarray['uri'] = "twitter::".$post->id_str;
$postarray['object'] = json_encode($post);
+ // Don't import our own comments
$r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($postarray['uri']),
intval($uid)
);
if (count($r)) {
+ logger("Item with extid ".$postarray['uri']." found.", LOGGER_DEBUG);
return(array());
}
$postarray['owner-link'] = $r[0]["url"];
$postarray['owner-avatar'] = $r[0]["photo"];
} else {
+ logger("No self contact for user ".$uid, LOGGER_DEBUG);
return(array());
}
}
if(($contactid == 0) AND !$only_existing_contact) {
$contactid = $self['id'];
} elseif ($contactid <= 0) {
+ logger("Contact ID is zero or less than zero.", LOGGER_DEBUG);
return(array());
}
$retweet = twitter_createpost($a, $uid, $post->retweeted_status, $self, false, false, $noquote);
$retweet['object'] = $postarray['object'];
+ $retweet['private'] = $postarray['private'];
+ $retweet['allow_cid'] = $postarray['allow_cid'];
$retweet['contact-id'] = $postarray['contact-id'];
$retweet['owner-name'] = $postarray['owner-name'];
$retweet['owner-link'] = $postarray['owner-link'];