X-Git-Url: https://git.mxchange.org/?p=friendica-addons.git;a=blobdiff_plain;f=statusnet%2Fstatusnet.php;h=c54ff55f6c923ce65d4b4e3051bf2d770144884c;hp=4b36859c1e4574a77d83e0c807d63d28142d7222;hb=3268eecd722126c532f9cef18b8657c10046a89e;hpb=6e6f64a5374772aca891464ebb08e70aac53c12c
diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php
index 4b36859c..c54ff55f 100644
--- a/statusnet/statusnet.php
+++ b/statusnet/statusnet.php
@@ -33,143 +33,58 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-/*
- * We have to alter the TwitterOAuth class a little bit to work with any GNU Social
- * installation abroad. Basically it's only make the API path variable and be happy.
- *
- * Thank you guys for the Twitter compatible API!
- */
-
define('STATUSNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes
-require_once 'library/twitteroauth.php';
+require_once __DIR__ . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'statusnetoauth.php';
require_once 'include/enotify.php';
+use Codebird\Codebird;
+use CodebirdSN\CodebirdSN;
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\Model\GContact;
use Friendica\Model\Group;
+use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\User;
-
-class StatusNetOAuth extends TwitterOAuth
-{
- function get_maxlength()
- {
- $config = $this->get($this->host . 'statusnet/config.json');
- return $config->site->textlimit;
- }
-
- function accessTokenURL()
- {
- return $this->host . 'oauth/access_token';
- }
-
- function authenticateURL()
- {
- return $this->host . 'oauth/authenticate';
- }
-
- function authorizeURL()
- {
- return $this->host . 'oauth/authorize';
- }
-
- function requestTokenURL()
- {
- return $this->host . 'oauth/request_token';
- }
-
- function __construct($apipath, $consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL)
- {
- parent::__construct($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
- $this->host = $apipath;
- }
-
- /**
- * Make an HTTP request
- *
- * @return API results
- *
- * Copied here from the twitteroauth library and complemented by applying the proxy settings of friendica
- */
- function http($url, $method, $postfields = NULL)
- {
- $this->http_info = array();
- $ci = curl_init();
- /* Curl settings */
- $prx = Config::get('system', 'proxy');
- if (strlen($prx)) {
- curl_setopt($ci, CURLOPT_HTTPPROXYTUNNEL, 1);
- curl_setopt($ci, CURLOPT_PROXY, $prx);
- $prxusr = Config::get('system', 'proxyuser');
- if (strlen($prxusr)) {
- curl_setopt($ci, CURLOPT_PROXYUSERPWD, $prxusr);
- }
- }
- curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
- curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
- curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
- curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
- curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
- curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
- curl_setopt($ci, CURLOPT_HEADER, FALSE);
-
- switch ($method) {
- case 'POST':
- curl_setopt($ci, CURLOPT_POST, TRUE);
- if (!empty($postfields)) {
- curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
- }
- break;
- case 'DELETE':
- curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
- if (!empty($postfields)) {
- $url = "{$url}?{$postfields}";
- }
- }
-
- curl_setopt($ci, CURLOPT_URL, $url);
- $response = curl_exec($ci);
- $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
- $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
- $this->url = $url;
- curl_close($ci);
- return $response;
- }
-}
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Network;
function statusnet_install()
{
// we need some hooks, for the configuration and for sending tweets
- register_hook('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
- register_hook('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
- register_hook('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
- register_hook('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local');
- register_hook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
- register_hook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
- register_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
- register_hook('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
+ Addon::registerHook('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
+ Addon::registerHook('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
+ Addon::registerHook('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
+ Addon::registerHook('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local');
+ Addon::registerHook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
+ Addon::registerHook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
+ Addon::registerHook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
+ Addon::registerHook('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
logger("installed GNU Social");
}
function statusnet_uninstall()
{
- unregister_hook('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
- unregister_hook('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
- unregister_hook('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
- unregister_hook('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local');
- unregister_hook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
- unregister_hook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
- unregister_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
- unregister_hook('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
+ Addon::unregisterHook('connector_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
+ Addon::unregisterHook('connector_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
+ Addon::unregisterHook('notifier_normal', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
+ Addon::unregisterHook('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local');
+ Addon::unregisterHook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
+ Addon::unregisterHook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
+ Addon::unregisterHook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
+ Addon::unregisterHook('check_item_notification', 'addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
// old setting - remove only
- unregister_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
- unregister_hook('plugin_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
- unregister_hook('plugin_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
+ Addon::unregisterHook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
+ Addon::unregisterHook('addon_settings', 'addon/statusnet/statusnet.php', 'statusnet_settings');
+ Addon::unregisterHook('addon_settings_post', 'addon/statusnet/statusnet.php', 'statusnet_settings_post');
}
function statusnet_check_item_notification(App $a, &$notification_data)
@@ -188,7 +103,7 @@ function statusnet_jot_nets(App $a, &$b)
$statusnet_defpost = PConfig::get(local_user(), 'statusnet', 'post_by_default');
$selected = ((intval($statusnet_defpost) == 1) ? ' checked="checked" ' : '');
$b .= '
'
- . t('Post to GNU Social') . '
';
+ . L10n::t('Post to GNU Social') . '';
}
}
@@ -229,25 +144,25 @@ function statusnet_settings_post(App $a, $post)
foreach ($globalsn as $asn) {
if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl']) {
$apibase = $asn['apiurl'];
- $c = fetch_url($apibase . 'statusnet/version.xml');
+ $c = Network::fetchUrl($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) {
PConfig::set(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey']);
PConfig::set(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret']);
PConfig::set(local_user(), 'statusnet', 'baseapi', $asn['apiurl']);
//PConfig::set(local_user(), 'statusnet', 'application_name', $asn['applicationname'] );
} else {
- notice(t('Please contact your site administrator. The provided API URL is not valid.') . EOL . $asn['apiurl'] . EOL);
+ notice(L10n::t('Please contact your site administrator. The provided API URL is not valid.') . EOL . $asn['apiurl'] . EOL);
}
}
}
- goaway($a->get_baseurl() . '/settings/connectors');
+ goaway('settings/connectors');
} else {
if (isset($_POST['statusnet-consumersecret'])) {
// check if we can reach the API of the GNU Social server
// we'll check the API Version for that, if we don't get one we'll try to fix the path but will
// resign quickly after this one try to fix the path ;-)
$apibase = $_POST['statusnet-baseapi'];
- $c = fetch_url($apibase . 'statusnet/version.xml');
+ $c = Network::fetchUrl($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) {
// ok the API path is correct, let's save the settings
PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
@@ -257,7 +172,7 @@ function statusnet_settings_post(App $a, $post)
} else {
// the API path is not correct, maybe missing trailing / ?
$apibase = $apibase . '/';
- $c = fetch_url($apibase . 'statusnet/version.xml');
+ $c = Network::fetchUrl($apibase . 'statusnet/version.xml');
if (strlen($c) > 0) {
// ok the API path is now correct, let's save the settings
PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']);
@@ -265,10 +180,10 @@ function statusnet_settings_post(App $a, $post)
PConfig::set(local_user(), 'statusnet', 'baseapi', $apibase);
} else {
// still not the correct API base, let's do noting
- notice(t('We could not contact the GNU Social API with the Path you entered.') . EOL);
+ notice(L10n::t('We could not contact the GNU Social API with the Path you entered.') . EOL);
}
}
- goaway($a->get_baseurl() . '/settings/connectors');
+ goaway('settings/connectors');
} else {
if (isset($_POST['statusnet-pin'])) {
// if the user supplied us with a PIN from GNU Social, let the magic of OAuth happen
@@ -286,7 +201,7 @@ function statusnet_settings_post(App $a, $post)
PConfig::set(local_user(), 'statusnet', 'post', 1);
PConfig::set(local_user(), 'statusnet', 'post_taglinks', 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 dent for every new __public__ posting to the wall
@@ -299,7 +214,7 @@ function statusnet_settings_post(App $a, $post)
if (!intval($_POST['statusnet-mirror']))
PConfig::delete(local_user(), 'statusnet', 'lastid');
- info(t('GNU Social settings updated.') . EOL);
+ info(L10n::t('GNU Social settings updated.') . EOL);
}
}
}
@@ -330,7 +245,7 @@ function statusnet_settings(App $a, &$s)
$mirrorenabled = PConfig::get(local_user(), 'statusnet', 'mirror_posts');
$mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : '');
$import = PConfig::get(local_user(), 'statusnet', 'import');
- $importselected = array("", "", "");
+ $importselected = ["", "", ""];
$importselected[$import] = ' selected="selected"';
//$importenabled = PConfig::get(local_user(),'statusnet','import');
//$importchecked = (($importenabled) ? ' checked="checked" ' : '');
@@ -340,11 +255,11 @@ function statusnet_settings(App $a, &$s)
$css = (($enabled) ? '' : '-disabled');
$s .= '';
- $s .= '
' . t('GNU Social Import/Export/Mirror') . '
';
+ $s .= '
' . L10n::t('GNU Social Import/Export/Mirror') . '
';
$s .= '';
$s .= '
';
$s .= '';
- $s .= '
' . t('GNU Social Import/Export/Mirror') . '
';
+ $s .= '
' . L10n::t('GNU Social Import/Export/Mirror') . '
';
$s .= '';
if ((!$ckey) && (!$csecret)) {
@@ -359,31 +274,31 @@ function statusnet_settings(App $a, &$s)
* ignore this option entirely.
*/
if (!$globalsn == null) {
- $s .= '
' . t('Globally Available GNU Social OAuthKeys') . '
';
- $s .= '
' . t("There are preconfigured OAuth key pairs for some GNU Social servers available. If you are using one of them, please use these credentials. If not feel free to connect to any other GNU Social instance \x28see below\x29.") . '
';
+ $s .= '
' . L10n::t('Globally Available GNU Social OAuthKeys') . '
';
+ $s .= '
' . L10n::t("There are preconfigured OAuth key pairs for some GNU Social servers available. If you are using one of them, please use these credentials. If not feel free to connect to any other GNU Social instance \x28see below\x29.") . '
' . t('No consumer key pair for GNU Social found. Register your Friendica Account as an desktop client on your GNU Social account, copy the consumer key pair here and enter the API base root. Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendica installation at your favorited GNU Social installation.') . '
';
+ $s .= '
' . L10n::t('Provide your own OAuth Credentials') . '
';
+ $s .= '
' . L10n::t('No consumer key pair for GNU Social found. Register your Friendica Account as an desktop client on your GNU Social account, copy the consumer key pair here and enter the API base root. Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendica installation at your favorited GNU Social installation.') . '
';
} else {
/* * *
@@ -402,22 +317,22 @@ function statusnet_settings(App $a, &$s)
/* * *
* make some nice form
*/
- $s .= '
' . t('To connect to your GNU Social account click the button below to get a security code from GNU Social which you have to copy into the input box below and submit the form. Only your public posts will be posted to GNU Social.') . '
';
- $s .= '';
+ $s .= '
' . L10n::t('To connect to your GNU Social account click the button below to get a security code from GNU Social which you have to copy into the input box below and submit the form. Only your public posts will be posted to GNU Social.') . '
' . t('If enabled all your public postings can be posted to the associated GNU Social account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.') . '
' . L10n::t('If enabled all your public postings can be posted to the associated GNU Social 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 GNU Social will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') . '
';
+ $s .= '
' . L10n::t('Note: Due your privacy settings (Hide your profile details from unknown viewers?) the link potentially included in public postings relayed to GNU Social will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') . '