';
}
}
-function twitter_settings_post ($a,$post) {
- if(! local_user())
+function twitter_settings_post(App $a, $post)
+{
+ if (!local_user()) {
return;
+ }
// don't check twitter settings if twitter submit button is not clicked
- if (!x($_POST,'twitter-submit'))
+ if (!x($_POST, 'twitter-submit')) {
return;
+ }
if (isset($_POST['twitter-disconnect'])) {
- /***
+ /* * *
* 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');
- } else {
- if (isset($_POST['twitter-pin'])) {
- // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen
- logger('got a Twitter PIN');
- require_once('library/twitteroauth.php');
- $ckey = get_config('twitter', 'consumerkey');
- $csecret = get_config('twitter', 'consumersecret');
- // the token and secret for which the PIN was generated were hidden in the settings
- // 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'] );
- // ok, now that we have the Access Token, save them in the user config
- set_pconfig(local_user(),'twitter', 'oauthtoken', $token['oauth_token']);
- set_pconfig(local_user(),'twitter', 'oauthsecret', $token['oauth_token_secret']);
- set_pconfig(local_user(),'twitter', 'post', 1);
- // reload the Addon Settings page, if we don't do it see Bug #42
- goaway($a->get_baseurl().'/settings/connectors');
+ 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 no PIN is supplied in the POST variables, the user has changed the setting
- // to post a tweet for every new __public__ posting to the wall
- set_pconfig(local_user(),'twitter','post',intval($_POST['twitter-enable']));
- set_pconfig(local_user(),'twitter','post_by_default',intval($_POST['twitter-default']));
- set_pconfig(local_user(), 'twitter', 'mirror_posts', intval($_POST['twitter-mirror']));
- set_pconfig(local_user(), 'twitter', 'import', intval($_POST['twitter-import']));
- set_pconfig(local_user(), 'twitter', 'create_user', intval($_POST['twitter-create_user']));
-
- if (!intval($_POST['twitter-mirror']))
- del_pconfig(local_user(),'twitter','lastid');
-
- info(t('Twitter settings updated.') . EOL);
- }}
+ if (isset($_POST['twitter-pin'])) {
+ // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen
+ logger('got a Twitter PIN');
+ require_once 'library/twitteroauth.php';
+ $ckey = Config::get('twitter', 'consumerkey');
+ $csecret = Config::get('twitter', 'consumersecret');
+ // the token and secret for which the PIN was generated were hidden in the settings
+ // 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']);
+ // 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']);
+ PConfig::set(local_user(), 'twitter', 'post', 1);
+ // reload the Addon Settings page, if we don't do it see Bug #42
+ goaway('settings/connectors');
+ } else {
+ // if no PIN is supplied in the POST variables, the user has changed the setting
+ // to post a tweet for every new __public__ posting to the wall
+ PConfig::set(local_user(), 'twitter', 'post', intval($_POST['twitter-enable']));
+ PConfig::set(local_user(), 'twitter', 'post_by_default', intval($_POST['twitter-default']));
+ PConfig::set(local_user(), 'twitter', 'mirror_posts', intval($_POST['twitter-mirror']));
+ PConfig::set(local_user(), 'twitter', 'import', intval($_POST['twitter-import']));
+ PConfig::set(local_user(), 'twitter', 'create_user', intval($_POST['twitter-create_user']));
+
+ if (!intval($_POST['twitter-mirror'])) {
+ PConfig::delete(local_user(), 'twitter', 'lastid');
+ }
+
+ info(t('Twitter settings updated.') . EOL);
+ }
+ }
}
-function twitter_settings(&$a,&$s) {
- if(! local_user())
+
+function twitter_settings(App $a, &$s)
+{
+ if (!local_user()) {
return;
+ }
$a->page['htmlhead'] .= '' . "\r\n";
- /***
+ /* * *
* 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 = get_config('twitter', 'consumerkey' );
- $csecret = get_config('twitter', 'consumersecret' );
- $otoken = get_pconfig(local_user(), 'twitter', 'oauthtoken' );
- $osecret = get_pconfig(local_user(), 'twitter', 'oauthsecret' );
- $enabled = get_pconfig(local_user(), 'twitter', 'post');
- $checked = (($enabled) ? ' checked="checked" ' : '');
- $defenabled = get_pconfig(local_user(),'twitter','post_by_default');
- $defchecked = (($defenabled) ? ' checked="checked" ' : '');
- $mirrorenabled = get_pconfig(local_user(),'twitter','mirror_posts');
- $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : '');
- $importenabled = get_pconfig(local_user(),'twitter','import');
- $importchecked = (($importenabled) ? ' checked="checked" ' : '');
- $create_userenabled = get_pconfig(local_user(),'twitter','create_user');
- $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : '');
+ $ckey = Config::get('twitter', 'consumerkey' );
+ $csecret = Config::get('twitter', 'consumersecret' );
+ $otoken = PConfig::get(local_user(), 'twitter', 'oauthtoken' );
+ $osecret = PConfig::get(local_user(), 'twitter', 'oauthsecret' );
+
+ $enabled = intval(PConfig::get(local_user(), 'twitter', 'post'));
+ $defenabled = intval(PConfig::get(local_user(), 'twitter', 'post_by_default'));
+ $mirrorenabled = intval(PConfig::get(local_user(), 'twitter', 'mirror_posts'));
+ $importenabled = intval(PConfig::get(local_user(), 'twitter', 'import'));
+ $create_userenabled = intval(PConfig::get(local_user(), 'twitter', 'create_user'));
$css = (($enabled) ? '' : '-disabled');
$s .= '';
- $s .= '
'. t('Twitter Import/Export/Mirror').'
';
+ $s .= '
' . t('Twitter Import/Export/Mirror') . '
';
$s .= '';
$s .= '
';
$s .= '';
- $s .= '
'. t('Twitter Import/Export/Mirror').'
';
+ $s .= '
' . t('Twitter Import/Export/Mirror') . '
';
$s .= '';
- if ( (!$ckey) && (!$csecret) ) {
- /***
+ if ((!$ckey) && (!$csecret)) {
+ /* * *
* no global consumer keys
* display warning and skip personal config
*/
- $s .= '
'. t('No consumer key pair for Twitter found. Please contact your site administrator.') .'
';
+ $s .= '
' . t('No consumer key pair for Twitter found. Please contact your site administrator.') . '
';
} else {
- /***
+ /* * *
* ok we have a consumer key pair now look into the OAuth stuff
*/
- if ( (!$otoken) && (!$osecret) ) {
- /***
+ if ((!$otoken) && (!$osecret)) {
+ /* * *
* the user has not yet connected the account to twitter...
* get a temporary OAuth key/secret pair and display a button with
* which the user can request a PIN to connect the account to a
* account at Twitter.
*/
- require_once('library/twitteroauth.php');
+ require_once 'library/twitteroauth.php';
$connection = new TwitterOAuth($ckey, $csecret);
$request_token = $connection->getRequestToken();
$token = $request_token['oauth_token'];
- /***
+ /* * *
* make some nice form
*/
- $s .= '
'. t('At this Friendica instance the Twitter plugin 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 .= '';
+ $s .= '
' . t('At this Friendica instance the Twitter plugin 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 .= '';
} else {
- /***
+ /* * *
* we have an OAuth key / secret pair for the user
* so let's give a chance to disable the postings to Twitter
*/
- require_once('library/twitteroauth.php');
- $connection = new TwitterOAuth($ckey,$csecret,$otoken,$osecret);
+ require_once 'library/twitteroauth.php';
+ $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
$details = $connection->get('account/verify_credentials');
- $s .= '
'. t('If enabled all your public postings can be posted to the associated Twitter account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.') .'
';
- if ($a->user['hidewall']) {
- $s .= '
'. t('Note: Due your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to Twitter will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') .'
';
- $s .= '';
- $s .= '';
- $s .= '';
+ $s .= replace_macros($field_checkbox, [
+ '$field' => ['twitter-enable', t('Allow posting to Twitter'), $enabled, t('If enabled all your public postings can be posted to the associated Twitter account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.')]
+ ]);
+ if ($a->user['hidewall']) {
+ $s .= '
' . t('Note: Due to your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to Twitter will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') . '