X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=twitter%2Ftwitter.php;h=74245fa276245feed513770ba9f5139df91103ee;hb=e7ead458456f0560afe4de8b10858c218e93729c;hp=253ed4ab1a2db4386f37a8762747e9490f2292b4;hpb=ae95b93de3274e9d936b077df7fac8a69b90d1a9;p=friendica-addons.git diff --git a/twitter/twitter.php b/twitter/twitter.php index 253ed4ab..74245fa2 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -494,7 +494,8 @@ function twitter_post_hook(&$a,&$b) { 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 :-) @@ -624,7 +625,12 @@ function twitter_cron($a,$b) { 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']); + } } } @@ -646,8 +652,12 @@ function twitter_cron($a,$b) { } 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 @@ -678,7 +688,15 @@ function twitter_expire($a,$b) { if ($days == 0) return; - $r = q("DELETE FROM `item` WHERE `deleted` AND `network` = '%s'", dbesc(NETWORK_TWITTER)); + if (method_exists('dba', 'delete')) { + $r = dba::select('item', array('id'), array('deleted' => true, 'network' => NETWORK_TWITTER)); + while ($row = dba::fetch($r)) { + dba::delete('item', array('id' => $row['id'])); + } + dba::close($r); + } else { + $r = q("DELETE FROM `item` WHERE `deleted` AND `network` = '%s'", dbesc(NETWORK_TWITTER)); + } require_once("include/items.php"); @@ -749,11 +767,12 @@ function twitter_do_mirrorpost($a, $uid, $post) { $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']); @@ -924,36 +943,11 @@ function twitter_fetch_contact($uid, $contact, $create_user) { $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)); @@ -968,10 +962,10 @@ function twitter_fetch_contact($uid, $contact, $create_user) { 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), @@ -986,6 +980,8 @@ function twitter_fetch_contact($uid, $contact, $create_user) { dbesc(NETWORK_TWITTER), intval(CONTACT_IS_FRIEND), intval(1), + dbesc($contact->location), + dbesc($contact->description), intval(1) ); @@ -1010,33 +1006,25 @@ function twitter_fetch_contact($uid, $contact, $create_user) { 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. @@ -1051,42 +1039,39 @@ function twitter_fetch_contact($uid, $contact, $create_user) { 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']) ); + } } } @@ -1363,6 +1348,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing ); if (count($r)) { + logger("Item with extid ".$postarray['uri']." found.", LOGGER_DEBUG); return(array()); } @@ -1412,6 +1398,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing $postarray['owner-link'] = $r[0]["url"]; $postarray['owner-avatar'] = $r[0]["photo"]; } else { + logger("No self contact for user ".$uid, LOGGER_DEBUG); return(array()); } } @@ -1433,6 +1420,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing 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()); }