X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=twitter%2Ftwitter.php;h=8b42e1872bd4539e24a7a9d78698849d39a5d137;hb=30fa9ac76c7140de20a3a9b42f34dd979b7a66ba;hp=7260910b047435f572312e7885eca7348c3751ce;hpb=9a8b0948b8d8066b8a16dfcd73c565fd28ffa862;p=friendica-addons.git diff --git a/twitter/twitter.php b/twitter/twitter.php index 7260910b..8b42e187 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -60,11 +60,14 @@ * Requirements: PHP5, curl [Slinky library] */ -require_once('include/enotify.php'); -require_once("include/socgraph.php"); - use Friendica\Core\Config; use Friendica\Core\PConfig; +use Friendica\Core\Worker; +use Friendica\Model\GlobalContact; +use Friendica\Object\Photo; + +require_once 'include/enotify.php'; + define('TWITTER_DEFAULT_POLL_INTERVAL', 5); // given in minutes @@ -169,7 +172,7 @@ function twitter_jot_nets(&$a,&$b) { } } -function twitter_settings_post ($a,$post) { +function twitter_settings_post($a,$post) { if(! local_user()) return; // don't check twitter settings if twitter submit button is not clicked @@ -181,17 +184,17 @@ function twitter_settings_post ($a,$post) { * if the twitter-disconnect checkbox is set, clear the OAuth key/secret pair * from the user configuration */ - del_pconfig(local_user(), 'twitter', 'consumerkey'); - del_pconfig(local_user(), 'twitter', 'consumersecret'); - del_pconfig(local_user(), 'twitter', 'oauthtoken'); - del_pconfig(local_user(), 'twitter', 'oauthsecret'); - del_pconfig(local_user(), 'twitter', 'post'); - del_pconfig(local_user(), 'twitter', 'post_by_default'); - del_pconfig(local_user(), 'twitter', 'lastid'); - del_pconfig(local_user(), 'twitter', 'mirror_posts'); - del_pconfig(local_user(), 'twitter', 'import'); - del_pconfig(local_user(), 'twitter', 'create_user'); - del_pconfig(local_user(), 'twitter', 'own_id'); + PConfig::delete(local_user(), 'twitter', 'consumerkey'); + PConfig::delete(local_user(), 'twitter', 'consumersecret'); + PConfig::delete(local_user(), 'twitter', 'oauthtoken'); + PConfig::delete(local_user(), 'twitter', 'oauthsecret'); + PConfig::delete(local_user(), 'twitter', 'post'); + PConfig::delete(local_user(), 'twitter', 'post_by_default'); + PConfig::delete(local_user(), 'twitter', 'lastid'); + PConfig::delete(local_user(), 'twitter', 'mirror_posts'); + PConfig::delete(local_user(), 'twitter', 'import'); + PConfig::delete(local_user(), 'twitter', 'create_user'); + PConfig::delete(local_user(), 'twitter', 'own_id'); } else { if (isset($_POST['twitter-pin'])) { // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen @@ -220,7 +223,7 @@ function twitter_settings_post ($a,$post) { PConfig::set(local_user(), 'twitter', 'create_user', intval($_POST['twitter-create_user'])); if (!intval($_POST['twitter-mirror'])) - del_pconfig(local_user(),'twitter','lastid'); + PConfig::delete(local_user(),'twitter','lastid'); info(t('Twitter settings updated.') . EOL); }} @@ -232,7 +235,7 @@ function twitter_settings(&$a,&$s) { /*** * 1) Check that we have global consumer key & secret * 2) If no OAuthtoken & stuff is present, generate button to get some - * 3) Checkbox for "Send public notices (140 chars only) + * 3) Checkbox for "Send public notices (280 chars only) */ $ckey = Config::get('twitter', 'consumerkey' ); $csecret = Config::get('twitter', 'consumersecret' ); @@ -410,7 +413,7 @@ function twitter_post_hook(&$a,&$b) { return; } - if($b['parent'] != $b['id']) { + if ($b['parent'] != $b['id']) { logger("twitter_post_hook: parameter ".print_r($b, true), LOGGER_DATA); // Looking if its a reply to a twitter post @@ -444,8 +447,16 @@ function twitter_post_hook(&$a,&$b) { } else { $iscomment = false; - if($b['private'] || !strstr($b['postopts'],'twitter')) + if ($b['private'] || !strstr($b['postopts'],'twitter')) { return; + } + + // Dont't post if the post doesn't belong to us. + // This is a check for forum postings + $self = dba::select('contact', array('id'), array('uid' => $b['uid'], 'self' => true), array('limit' => 1)); + if ($b['contact-id'] != $self['id']) { + return; + } } if (($b['verb'] == ACTIVITY_POST) && $b['deleted']) @@ -473,7 +484,7 @@ function twitter_post_hook(&$a,&$b) { logger('twitter post invoked'); - load_pconfig($b['uid'], 'twitter'); + PConfig::load($b['uid'], 'twitter'); $ckey = Config::get('twitter', 'consumerkey'); $csecret = Config::get('twitter', 'consumersecret'); @@ -491,7 +502,7 @@ function twitter_post_hook(&$a,&$b) { require_once('include/bbcode.php'); $tweet = new TwitterOAuth($ckey,$csecret,$otoken,$osecret); - $max_char = 140; + $max_char = 280; require_once("include/plaintext.php"); $msgarr = plaintext($a, $b, $max_char, true, 8); $msg = $msgarr["text"]; @@ -646,7 +657,7 @@ function twitter_cron($a,$b) { if(count($r)) { foreach($r as $rr) { logger('twitter: fetching for user '.$rr['uid']); - proc_run(PRIORITY_MEDIUM, "addon/twitter/twitter_sync.php", 1, (int)$rr['uid']); + Worker::add(PRIORITY_MEDIUM, "addon/twitter/twitter_sync.php", 1, (int)$rr['uid']); } } @@ -668,7 +679,7 @@ function twitter_cron($a,$b) { } logger('twitter: importing timeline from user '.$rr['uid']); - proc_run(PRIORITY_MEDIUM, "addon/twitter/twitter_sync.php", 2, (int)$rr['uid']); + Worker::add(PRIORITY_MEDIUM, "addon/twitter/twitter_sync.php", 2, (int)$rr['uid']); /* // To-Do // check for new contacts once a day @@ -729,7 +740,7 @@ function twitter_prepare_body(&$a,&$b) { return; if ($b["preview"]) { - $max_char = 140; + $max_char = 280; require_once("include/plaintext.php"); $item = $b["item"]; $item["plink"] = $a->get_baseurl()."/display/".$a->user["nickname"]."/".$item["parent"]; @@ -940,7 +951,7 @@ function twitter_fix_avatar($avatar) { $new_avatar = str_replace("_normal.", ".", $avatar); - $info = get_photo_info($new_avatar); + $info = Photo::getPhotoInfo($new_avatar); if (!$info) $new_avatar = $avatar; @@ -954,7 +965,7 @@ function twitter_fetch_contact($uid, $contact, $create_user) { $avatar = twitter_fix_avatar($contact->profile_image_url_https); - update_gcontact(array("url" => "https://twitter.com/".$contact->screen_name, + GlobalContact::update(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, @@ -1017,7 +1028,7 @@ function twitter_fetch_contact($uid, $contact, $create_user) { require_once("Photo.php"); - $photos = import_profile_photo($avatar, $uid, $contact_id, true); + $photos = Photo::importProfilePhoto($avatar, $uid, $contact_id, true); if ($photos) { q("UPDATE `contact` SET `photo` = '%s', @@ -1050,7 +1061,7 @@ function twitter_fetch_contact($uid, $contact, $create_user) { require_once("Photo.php"); - $photos = import_profile_photo($avatar, $uid, $r[0]['id'], true); + $photos = Photo::importProfilePhoto($avatar, $uid, $r[0]['id'], true); if ($photos) { q("UPDATE `contact` SET `photo` = '%s', @@ -1850,7 +1861,7 @@ function twitter_fetch_own_contact($a, $uid) { if(count($r)) $contact_id = $r[0]["id"]; else - del_pconfig($uid, 'twitter', 'own_id'); + PConfig::delete($uid, 'twitter', 'own_id'); }