X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=twitter%2Ftwitter.php;h=5168aa0ecfda12c57df03abcb4ea64f2ffa13173;hb=f1514063559930de791c0bff18a3f6ae4b455f7c;hp=ca5da52ff0bcb69f57f596ad08e41e6e657dec01;hpb=2cbf89c0f5e15774ebd0d08fe7914e7a633aca89;p=friendica-addons.git
diff --git a/twitter/twitter.php b/twitter/twitter.php
index ca5da52f..5168aa0e 100644
--- a/twitter/twitter.php
+++ b/twitter/twitter.php
@@ -1,5 +1,4 @@
config['twitter']['consumerkey'] = 'your consumer_key here';
* $a->config['twitter']['consumersecret'] = 'your consumer_secret here';
*
- * To activate the plugin itself add it to the $a->config['system']['addon']
+ * To activate the addon itself add it to the $a->config['system']['addon']
* setting. After this, your user can configure their Twitter account settings
- * from "Settings -> Plugin Settings".
+ * from "Settings -> Addon Settings".
*
* Requirements: PHP5, curl [Slinky library]
*/
use Friendica\App;
use Friendica\Content\OEmbed;
+use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\Plaintext;
+use Friendica\Core\Addon;
use Friendica\Core\Config;
+use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\Photo;
+use Friendica\Model\Queue;
use Friendica\Model\User;
use Friendica\Object\Image;
+use Friendica\Util\Network;
require_once 'include/enotify.php';
@@ -78,38 +83,38 @@ define('TWITTER_DEFAULT_POLL_INTERVAL', 5); // given in minutes
function twitter_install()
{
// we need some hooks, for the configuration and for sending tweets
- register_hook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings');
- register_hook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
- register_hook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local');
- register_hook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook');
- register_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
- register_hook('cron', 'addon/twitter/twitter.php', 'twitter_cron');
- register_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook');
- register_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
- register_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
- register_hook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
- register_hook('check_item_notification', 'addon/twitter/twitter.php', 'twitter_check_item_notification');
+ Addon::registerHook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings');
+ Addon::registerHook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
+ Addon::registerHook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local');
+ Addon::registerHook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook');
+ Addon::registerHook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
+ Addon::registerHook('cron', 'addon/twitter/twitter.php', 'twitter_cron');
+ Addon::registerHook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook');
+ Addon::registerHook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
+ Addon::registerHook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
+ Addon::registerHook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
+ Addon::registerHook('check_item_notification', 'addon/twitter/twitter.php', 'twitter_check_item_notification');
logger("installed twitter");
}
function twitter_uninstall()
{
- unregister_hook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings');
- unregister_hook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
- unregister_hook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local');
- unregister_hook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook');
- unregister_hook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
- unregister_hook('cron', 'addon/twitter/twitter.php', 'twitter_cron');
- unregister_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook');
- unregister_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
- unregister_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
- unregister_hook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
- unregister_hook('check_item_notification', 'addon/twitter/twitter.php', 'twitter_check_item_notification');
+ Addon::unregisterHook('connector_settings', 'addon/twitter/twitter.php', 'twitter_settings');
+ Addon::unregisterHook('connector_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
+ Addon::unregisterHook('post_local', 'addon/twitter/twitter.php', 'twitter_post_local');
+ Addon::unregisterHook('notifier_normal', 'addon/twitter/twitter.php', 'twitter_post_hook');
+ Addon::unregisterHook('jot_networks', 'addon/twitter/twitter.php', 'twitter_jot_nets');
+ Addon::unregisterHook('cron', 'addon/twitter/twitter.php', 'twitter_cron');
+ Addon::unregisterHook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook');
+ Addon::unregisterHook('follow', 'addon/twitter/twitter.php', 'twitter_follow');
+ Addon::unregisterHook('expire', 'addon/twitter/twitter.php', 'twitter_expire');
+ Addon::unregisterHook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body');
+ Addon::unregisterHook('check_item_notification', 'addon/twitter/twitter.php', 'twitter_check_item_notification');
// old setting - remove only
- unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
- unregister_hook('plugin_settings', 'addon/twitter/twitter.php', 'twitter_settings');
- unregister_hook('plugin_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
+ Addon::unregisterHook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook');
+ Addon::unregisterHook('addon_settings', 'addon/twitter/twitter.php', 'twitter_settings');
+ Addon::unregisterHook('addon_settings_post', 'addon/twitter/twitter.php', 'twitter_settings_post');
}
function twitter_check_item_notification(App $a, &$notification_data)
@@ -151,7 +156,7 @@ function twitter_follow(App $a, &$contact)
$cb->setConsumerKey($ckey, $csecret);
$cb->setToken($otoken, $osecret);
- $parameters = array();
+ $parameters = [];
$parameters["screen_name"] = $nickname;
$user = $cb->friendships_create($parameters);
@@ -178,7 +183,7 @@ function twitter_jot_nets(App $a, &$b)
$tw_defpost = PConfig::get(local_user(), 'twitter', 'post_by_default');
$selected = ((intval($tw_defpost) == 1) ? ' checked="checked" ' : '');
$b .= '
'
- . t('Post to Twitter') . '
';
+ . L10n::t('Post to Twitter') . '';
}
}
@@ -225,7 +230,7 @@ function twitter_settings_post(App $a, $post)
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($a->get_baseurl() . '/settings/connectors');
+ 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
@@ -239,7 +244,7 @@ function twitter_settings_post(App $a, $post)
PConfig::delete(local_user(), 'twitter', 'lastid');
}
- info(t('Twitter settings updated.') . EOL);
+ info(L10n::t('Twitter settings updated.') . EOL);
}
}
}
@@ -259,25 +264,21 @@ function twitter_settings(App $a, &$s)
$csecret = Config::get('twitter', 'consumersecret' );
$otoken = PConfig::get(local_user(), 'twitter', 'oauthtoken' );
$osecret = PConfig::get(local_user(), 'twitter', 'oauthsecret' );
- $enabled = PConfig::get(local_user(), 'twitter', 'post');
- $checked = (($enabled) ? ' checked="checked" ' : '');
- $defenabled = PConfig::get(local_user(), 'twitter', 'post_by_default');
- $defchecked = (($defenabled) ? ' checked="checked" ' : '');
- $mirrorenabled = PConfig::get(local_user(), 'twitter', 'mirror_posts');
- $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : '');
- $importenabled = PConfig::get(local_user(), 'twitter', 'import');
- $importchecked = (($importenabled) ? ' checked="checked" ' : '');
- $create_userenabled = PConfig::get(local_user(), 'twitter', 'create_user');
- $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : '');
+
+ $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 .= '
' . L10n::t('Twitter Import/Export/Mirror') . '
';
$s .= '';
$s .= '
';
$s .= '';
- $s .= '
' . t('Twitter Import/Export/Mirror') . '
';
+ $s .= '
' . L10n::t('Twitter Import/Export/Mirror') . '
';
$s .= '';
if ((!$ckey) && (!$csecret)) {
@@ -285,7 +286,7 @@ function twitter_settings(App $a, &$s)
* 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 .= '
' . L10n::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
@@ -304,15 +305,15 @@ function twitter_settings(App $a, &$s)
/* * *
* 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 .= '
' . 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.') . '
' . 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', L10n::t('Allow posting to Twitter'), $enabled, L10n::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 .= '
' . L10n::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.') . '