X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=twitter%2Ftwitter.php;h=cc12e8de8448dad7a223358b27fde337e35e6400;hb=e4f32f8ac8dbee577dc31195b1104add371f77eb;hp=50239b8bef54cb670dce859ad088f8fb77152ad5;hpb=01738518a25392aefea8586463121024ae3a1a4c;p=friendica-addons.git diff --git a/twitter/twitter.php b/twitter/twitter.php index 50239b8b..cc12e8de 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -72,18 +72,20 @@ use Friendica\Core\PConfig; use Friendica\Core\Worker; use Friendica\Model\GContact; use Friendica\Model\Group; +use Friendica\Model\Item; use Friendica\Model\Photo; use Friendica\Model\Queue; use Friendica\Model\User; use Friendica\Object\Image; use Friendica\Util\Network; +use Friendica\Util\Temporal; require_once 'boot.php'; require_once 'include/dba.php'; require_once 'include/enotify.php'; require_once 'include/text.php'; -require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; +require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; define('TWITTER_DEFAULT_POLL_INTERVAL', 5); // given in minutes @@ -157,6 +159,12 @@ function twitter_follow(App $a, &$contact) $otoken = PConfig::get($uid, 'twitter', 'oauthtoken'); $osecret = PConfig::get($uid, 'twitter', 'oauthsecret'); + // If the addon is not configured (general or for this user) quit here + if (empty($ckey) || empty($csecret) || empty($otoken) || empty($osecret)) { + $contact = false; + return; + } + $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret); $connection->post('friendships/create', ['screen_name' => $nickname]); @@ -222,7 +230,7 @@ function twitter_settings_post(App $a, $post) // form as token and token2, we need a new connection to Twitter using these token // and secret to request a Access Token with the PIN $connection = new TwitterOAuth($ckey, $csecret, $_POST['twitter-token'], $_POST['twitter-token2']); - $token = $connection->getAccessToken($_POST['twitter-pin']); + $token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $_POST['twitter-pin']]); // ok, now that we have the Access Token, save them in the user config PConfig::set(local_user(), 'twitter', 'oauthtoken', $token['oauth_token']); PConfig::set(local_user(), 'twitter', 'oauthsecret', $token['oauth_token_secret']); @@ -297,18 +305,17 @@ function twitter_settings(App $a, &$s) * account at Twitter. */ $connection = new TwitterOAuth($ckey, $csecret); - $request_token = $connection->getRequestToken(); - $token = $request_token['oauth_token']; + $result = $connection->oauth('oauth/request_token', ['oauth_callback' => 'oob']); /* * * * make some nice form */ $s .= '

' . L10n::t('At this Friendica instance the Twitter addon was enabled but you have not yet connected your account to your Twitter account. To do so click the button below to get a PIN from Twitter which you have to copy into the input box below and submit the form. Only your public posts will be posted to Twitter.') . '

'; - $s .= '' . L10n::t('Log in with Twitter') . ''; + $s .= '' . L10n::t('Log in with Twitter') . ''; $s .= '
'; $s .= ''; $s .= ''; - $s .= ''; - $s .= ''; + $s .= ''; + $s .= ''; $s .= '
'; $s .= '
'; } else { @@ -675,7 +682,7 @@ function twitter_cron(App $a, $b) $abandon_days = 0; } - $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400); + $abandon_limit = date(Temporal::MYSQL, time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1'"); if (count($r)) { @@ -738,7 +745,7 @@ function twitter_expire(App $a, $b) if (count($r)) { foreach ($r as $rr) { logger('twitter_expire: user ' . $rr['uid']); - item_expire($rr['uid'], $days, NETWORK_TWITTER, true); + Item::expire($rr['uid'], $days, NETWORK_TWITTER, true); } } @@ -1010,7 +1017,7 @@ function twitter_fetch_contact($uid, $contact, $create_user) `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(Temporal::utcNow()), dbesc("https://twitter.com/" . $contact->screen_name), dbesc(normalise_link("https://twitter.com/" . $contact->screen_name)), dbesc($contact->screen_name."@twitter.com"), @@ -1054,16 +1061,16 @@ function twitter_fetch_contact($uid, $contact, $create_user) dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Temporal::utcNow()), + dbesc(Temporal::utcNow()), + dbesc(Temporal::utcNow()), intval($contact_id) ); } } else { // update profile photos once every two weeks as we have no notification of when they change. - //$update_photo = (($r[0]['avatar-date'] < datetime_convert('','','now -2 days')) ? true : false); - $update_photo = ($r[0]['avatar-date'] < datetime_convert('', '', 'now -12 hours')); + //$update_photo = (($r[0]['avatar-date'] < Temporal::convert('now -2 days', '', '', )) ? true : false); + $update_photo = ($r[0]['avatar-date'] < Temporal::convert('now -12 hours')); // check that we have all the photos, this has been known to fail on occasion if ((!$r[0]['photo']) || (!$r[0]['thumb']) || (!$r[0]['micro']) || ($update_photo)) { @@ -1089,9 +1096,9 @@ function twitter_fetch_contact($uid, $contact, $create_user) dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Temporal::utcNow()), + dbesc(Temporal::utcNow()), + dbesc(Temporal::utcNow()), dbesc("https://twitter.com/".$contact->screen_name), dbesc(normalise_link("https://twitter.com/".$contact->screen_name)), dbesc($contact->screen_name."@twitter.com"), @@ -1483,8 +1490,8 @@ function twitter_createpost(App $a, $uid, $post, $self, $create_user, $only_exis $converted = twitter_expand_entities($a, $postarray['body'], $post, false, $picture); $postarray['body'] = $converted["body"]; $postarray['tag'] = $converted["tags"]; - $postarray['created'] = datetime_convert('UTC', 'UTC', $post->created_at); - $postarray['edited'] = datetime_convert('UTC', 'UTC', $post->created_at); + $postarray['created'] = Temporal::convert($post->created_at); + $postarray['edited'] = Temporal::convert($post->created_at); $statustext = $converted["plain"]; @@ -1588,7 +1595,7 @@ function twitter_checknotification(App $a, $uid, $own_id, $top_item, $postarray) 'to_email' => $user[0]['email'], 'uid' => $user[0]['uid'], 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($top_item)), + 'link' => $a->get_baseurl() . '/display/' . urlencode(Item::getGuidById($top_item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], @@ -1643,7 +1650,7 @@ function twitter_fetchparentposts(App $a, $uid, $post, $connection, $self, $own_ continue; } - $item = item_store($postarray); + $item = Item::insert($postarray); $postarray["id"] = $item; logger('twitter_fetchparentpost: User ' . $self["nick"] . ' posted parent timeline item ' . $item); @@ -1759,7 +1766,7 @@ function twitter_fetchhometimeline(App $a, $uid) continue; } - $item = item_store($postarray); + $item = Item::insert($postarray); $postarray["id"] = $item; logger('twitter_fetchhometimeline: User ' . $self["nick"] . ' posted home timeline item ' . $item); @@ -1811,7 +1818,7 @@ function twitter_fetchhometimeline(App $a, $uid) continue; } - $item = item_store($postarray); + $item = Item::insert($postarray); $postarray["id"] = $item; if ($item && function_exists("check_item_notification")) { @@ -1847,7 +1854,7 @@ function twitter_fetchhometimeline(App $a, $uid) 'to_email' => $u[0]['email'], 'uid' => $u[0]['uid'], 'item' => $postarray, - 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($item)), + 'link' => $a->get_baseurl() . '/display/' . urlencode(Item::getGuidById($item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'],