X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=statusnet%2Fstatusnet.php;h=f7158a40187c73b7e9f68b7db3c210bb530eb9b2;hb=c3e93f1ed9a487f823bcc75ddd43024334c25bfc;hp=1109a0f2cb1ff9ccb69fa38f0ad75f6d28f178f2;hpb=b34489d5c1e3242eb00ac1620a6cef262954264f;p=friendica-addons.git diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 1109a0f2..f7158a40 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -1,7 +1,7 @@ * Author: Michael Vogel @@ -35,7 +35,7 @@ /*** - * We have to alter the TwitterOAuth class a little bit to work with any StatusNet + * 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! @@ -44,6 +44,11 @@ define('STATUSNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes require_once('library/twitteroauth.php'); +require_once('include/enotify.php'); +require_once("include/socgraph.php"); + +use Friendica\Core\Config; +use Friendica\Core\PConfig; class StatusNetOAuth extends TwitterOAuth { function get_maxlength() { @@ -69,11 +74,11 @@ class StatusNetOAuth extends TwitterOAuth { $this->http_info = array(); $ci = curl_init(); /* Curl settings */ - $prx = get_config('system','proxy'); + $prx = Config::get('system','proxy'); if(strlen($prx)) { curl_setopt($ci, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ci, CURLOPT_PROXY, $prx); - $prxusr = get_config('system','proxyuser'); + $prxusr = Config::get('system','proxyuser'); if(strlen($prxusr)) curl_setopt($ci, CURLOPT_PROXYUSERPWD, $prxusr); } @@ -118,7 +123,9 @@ function statusnet_install() { 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'); - logger("installed statusnet"); + register_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body'); + register_hook('check_item_notification','addon/statusnet/statusnet.php', 'statusnet_check_item_notification'); + logger("installed GNU Social"); } @@ -129,6 +136,8 @@ function statusnet_uninstall() { 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'); // old setting - remove only unregister_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook'); @@ -137,29 +146,33 @@ function statusnet_uninstall() { } +function statusnet_check_item_notification($a, &$notification_data) { + $notification_data["profiles"][] = PConfig::get($notification_data["uid"], 'statusnet', 'own_url'); +} + function statusnet_jot_nets(&$a,&$b) { if(! local_user()) return; - $statusnet_post = get_pconfig(local_user(),'statusnet','post'); + $statusnet_post = PConfig::get(local_user(),'statusnet','post'); if(intval($statusnet_post) == 1) { - $statusnet_defpost = get_pconfig(local_user(),'statusnet','post_by_default'); + $statusnet_defpost = PConfig::get(local_user(),'statusnet','post_by_default'); $selected = ((intval($statusnet_defpost) == 1) ? ' checked="checked" ' : ''); - $b .= '
' - . t('Post to StatusNet') . '
'; + $b .= '
' + . t('Post to GNU Social') . '
'; } } function statusnet_settings_post ($a,$post) { if(! local_user()) return; - // don't check statusnet settings if statusnet submit button is not clicked + // don't check GNU Social settings if GNU Social submit button is not clicked if (!x($_POST,'statusnet-submit')) return; if (isset($_POST['statusnet-disconnect'])) { /*** - * if the statusnet-disconnect checkbox is set, clear the statusnet configuration + * if the GNU Social-disconnect checkbox is set, clear the GNU Social configuration */ del_pconfig(local_user(), 'statusnet', 'consumerkey'); del_pconfig(local_user(), 'statusnet', 'consumersecret'); @@ -168,30 +181,28 @@ function statusnet_settings_post ($a,$post) { del_pconfig(local_user(), 'statusnet', 'oauthtoken'); del_pconfig(local_user(), 'statusnet', 'oauthsecret'); del_pconfig(local_user(), 'statusnet', 'baseapi'); - del_pconfig(local_user(), 'statusnet', 'post_taglinks'); del_pconfig(local_user(), 'statusnet', 'lastid'); del_pconfig(local_user(), 'statusnet', 'mirror_posts'); - del_pconfig(local_user(), 'statusnet', 'intelligent_shortening'); del_pconfig(local_user(), 'statusnet', 'import'); - del_pconfig(local_user(), 'statusnet', 'create_user'); - del_pconfig(local_user(), 'statusnet', 'own_id'); + del_pconfig(local_user(), 'statusnet', 'create_user'); + del_pconfig(local_user(), 'statusnet', 'own_id'); } else { if (isset($_POST['statusnet-preconf-apiurl'])) { /*** - * If the user used one of the preconfigured StatusNet server credentials + * If the user used one of the preconfigured GNU Social server credentials * use them. All the data are available in the global config. * Check the API Url never the less and blame the admin if it's not working ^^ */ - $globalsn = get_config('statusnet', 'sites'); + $globalsn = Config::get('statusnet', 'sites'); foreach ( $globalsn as $asn) { if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl'] ) { $apibase = $asn['apiurl']; $c = fetch_url( $apibase . 'statusnet/version.xml' ); if (strlen($c) > 0) { - set_pconfig(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey'] ); - set_pconfig(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret'] ); - set_pconfig(local_user(), 'statusnet', 'baseapi', $asn['apiurl'] ); - set_pconfig(local_user(), 'statusnet', 'application_name', $asn['applicationname'] ); + 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 ); } @@ -200,61 +211,63 @@ function statusnet_settings_post ($a,$post) { goaway($a->get_baseurl().'/settings/connectors'); } else { if (isset($_POST['statusnet-consumersecret'])) { - // check if we can reach the API of the StatusNet server + // 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' ); if (strlen($c) > 0) { // ok the API path is correct, let's save the settings - set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); - set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); - set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase ); - set_pconfig(local_user(), 'statusnet', 'application_name', $_POST['statusnet-applicationname'] ); + PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); + PConfig::set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); + PConfig::set(local_user(), 'statusnet', 'baseapi', $apibase ); + //PConfig::set(local_user(), 'statusnet', 'application_name', $_POST['statusnet-applicationname'] ); } else { // the API path is not correct, maybe missing trailing / ? $apibase = $apibase . '/'; $c = fetch_url( $apibase . 'statusnet/version.xml' ); if (strlen($c) > 0) { // ok the API path is now correct, let's save the settings - set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); - set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); - set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase ); + PConfig::set(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); + PConfig::set(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); + 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 StatusNet API with the Path you entered.').EOL ); + notice( t('We could not contact the GNU Social API with the Path you entered.').EOL ); } } goaway($a->get_baseurl().'/settings/connectors'); } else { if (isset($_POST['statusnet-pin'])) { - // if the user supplied us with a PIN from StatusNet, let the magic of OAuth happen - $api = get_pconfig(local_user(), 'statusnet', 'baseapi'); - $ckey = get_pconfig(local_user(), 'statusnet', 'consumerkey' ); - $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' ); + // if the user supplied us with a PIN from GNU Social, let the magic of OAuth happen + $api = PConfig::get(local_user(), 'statusnet', 'baseapi'); + $ckey = PConfig::get(local_user(), 'statusnet', 'consumerkey' ); + $csecret = PConfig::get(local_user(), 'statusnet', '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 StatusNet using these token + // form as token and token2, we need a new connection to GNU Social using these token // and secret to request a Access Token with the PIN $connection = new StatusNetOAuth($api, $ckey, $csecret, $_POST['statusnet-token'], $_POST['statusnet-token2']); $token = $connection->getAccessToken( $_POST['statusnet-pin'] ); // ok, now that we have the Access Token, save them in the user config - set_pconfig(local_user(),'statusnet', 'oauthtoken', $token['oauth_token']); - set_pconfig(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']); - set_pconfig(local_user(),'statusnet', 'post', 1); - set_pconfig(local_user(),'statusnet', 'post_taglinks', 1); + PConfig::set(local_user(),'statusnet', 'oauthtoken', $token['oauth_token']); + PConfig::set(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']); + 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'); } 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 - set_pconfig(local_user(),'statusnet','post',intval($_POST['statusnet-enable'])); - set_pconfig(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default'])); - set_pconfig(local_user(),'statusnet','post_taglinks',intval($_POST['statusnet-sendtaglinks'])); - set_pconfig(local_user(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror'])); - set_pconfig(local_user(), 'statusnet', 'intelligent_shortening', intval($_POST['statusnet-shortening'])); - set_pconfig(local_user(), 'statusnet', 'import', intval($_POST['statusnet-import'])); - set_pconfig(local_user(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user'])); - info( t('StatusNet settings updated.') . EOL); + PConfig::set(local_user(),'statusnet','post',intval($_POST['statusnet-enable'])); + PConfig::set(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default'])); + PConfig::set(local_user(), 'statusnet', 'mirror_posts', intval($_POST['statusnet-mirror'])); + PConfig::set(local_user(), 'statusnet', 'import', intval($_POST['statusnet-import'])); + PConfig::set(local_user(), 'statusnet', 'create_user', intval($_POST['statusnet-create_user'])); + + if (!intval($_POST['statusnet-mirror'])) + del_pconfig(local_user(),'statusnet','lastid'); + + info( t('GNU Social settings updated.') . EOL); }}}} } function statusnet_settings(&$a,&$s) { @@ -267,53 +280,49 @@ function statusnet_settings(&$a,&$s) { * allow the user to cancel the connection process at this step * 3) Checkbox for "Send public notices (respect size limitation) */ - $api = get_pconfig(local_user(), 'statusnet', 'baseapi'); - $ckey = get_pconfig(local_user(), 'statusnet', 'consumerkey' ); - $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' ); - $otoken = get_pconfig(local_user(), 'statusnet', 'oauthtoken' ); - $osecret = get_pconfig(local_user(), 'statusnet', 'oauthsecret' ); - $enabled = get_pconfig(local_user(), 'statusnet', 'post'); + $api = PConfig::get(local_user(), 'statusnet', 'baseapi'); + $ckey = PConfig::get(local_user(), 'statusnet', 'consumerkey'); + $csecret = PConfig::get(local_user(), 'statusnet', 'consumersecret'); + $otoken = PConfig::get(local_user(), 'statusnet', 'oauthtoken'); + $osecret = PConfig::get(local_user(), 'statusnet', 'oauthsecret'); + $enabled = PConfig::get(local_user(), 'statusnet', 'post'); $checked = (($enabled) ? ' checked="checked" ' : ''); - $defenabled = get_pconfig(local_user(),'statusnet','post_by_default'); + $defenabled = PConfig::get(local_user(),'statusnet','post_by_default'); $defchecked = (($defenabled) ? ' checked="checked" ' : ''); - $linksenabled = get_pconfig(local_user(),'statusnet','post_taglinks'); - $linkschecked = (($linksenabled) ? ' checked="checked" ' : ''); - $mirrorenabled = get_pconfig(local_user(),'statusnet','mirror_posts'); + $mirrorenabled = PConfig::get(local_user(),'statusnet','mirror_posts'); $mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : ''); - $shorteningenabled = get_pconfig(local_user(),'statusnet','intelligent_shortening'); - $shorteningchecked = (($shorteningenabled) ? ' checked="checked" ' : ''); - $importenabled = get_pconfig(local_user(),'statusnet','import'); - $importchecked = (($importenabled) ? ' checked="checked" ' : ''); - $create_userenabled = get_pconfig(local_user(),'statusnet','create_user'); - $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : ''); + $import = PConfig::get(local_user(),'statusnet','import'); + $importselected = array("", "", ""); + $importselected[$import] = ' selected="selected"'; + //$importenabled = PConfig::get(local_user(),'statusnet','import'); + //$importchecked = (($importenabled) ? ' checked="checked" ' : ''); + $create_userenabled = PConfig::get(local_user(),'statusnet','create_user'); + $create_userchecked = (($create_userenabled) ? ' checked="checked" ' : ''); $css = (($enabled) ? '' : '-disabled'); - $globalshortening = get_config('statusnet','intelligent_shortening'); - - $s .= ''; - $s .= '

'. t('StatusNet Import/Export/Mirror').'

'; + $s .= '

'. t('GNU Social Import/Export/Mirror').'

'; $s .= '
'; $s .= '