X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=appnet%2Fappnet.php;h=0c53a49f470e07a79a458e6274effa54ff3a898d;hb=3506b62ff69ce66c7e0df023dc547042f9367f15;hp=a07ceb99de732cb8de45cd88507273d2eaf3afb3;hpb=23fe74a97f92f528a153ed24e89906b602ddcabd;p=friendica-addons.git diff --git a/appnet/appnet.php b/appnet/appnet.php index a07ceb99..0c53a49f 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -2,7 +2,7 @@ /** * Name: App.net Connector - * Description: app.net postings import and export + * Description: Bidirectional (posting and reading) connector for app.net. * Version: 0.2 * Author: Michael Vogel */ @@ -12,8 +12,12 @@ - Use embedded pictures for the attachment information (large attachment) - Sound links must be handled - https://alpha.app.net/sr_rolando/post/32365203 - double pictures + - https://alpha.app.net/opendev/post/34396399 - location data */ +require_once('include/enotify.php'); +require_once("include/socgraph.php"); + define('APPNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes function appnet_install() { @@ -23,6 +27,8 @@ function appnet_install() { register_hook('cron', 'addon/appnet/appnet.php', 'appnet_cron'); register_hook('connector_settings', 'addon/appnet/appnet.php', 'appnet_settings'); register_hook('connector_settings_post','addon/appnet/appnet.php', 'appnet_settings_post'); + register_hook('prepare_body', 'addon/appnet/appnet.php', 'appnet_prepare_body'); + register_hook('check_item_notification','addon/appnet/appnet.php', 'appnet_check_item_notification'); } @@ -31,8 +37,10 @@ function appnet_uninstall() { unregister_hook('notifier_normal', 'addon/appnet/appnet.php', 'appnet_send'); unregister_hook('jot_networks', 'addon/appnet/appnet.php', 'appnet_jot_nets'); unregister_hook('cron', 'addon/appnet/appnet.php', 'appnet_cron'); - unregister_hook('connector_settings', 'addon/appnet/appnet.php', 'appnet_settings'); + unregister_hook('connector_settings', 'addon/appnet/appnet.php', 'appnet_settings'); unregister_hook('connector_settings_post', 'addon/appnet/appnet.php', 'appnet_settings_post'); + unregister_hook('prepare_body', 'addon/appnet/appnet.php', 'appnet_prepare_body'); + unregister_hook('check_item_notification','addon/appnet/appnet.php', 'appnet_check_item_notification'); } function appnet_module() {} @@ -61,11 +69,47 @@ function appnet_content(&$a) { return $o; } +function appnet_check_item_notification($a, &$notification_data) { + $own_id = get_pconfig($notification_data["uid"], 'appnet', 'ownid'); + + $own_user = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", + intval($notification_data["uid"]), + dbesc("adn::".$own_id) + ); + + if ($own_user) + $notification_data["profiles"][] = $own_user[0]["url"]; +} + +function appnet_plugin_admin(&$a, &$o){ + $t = get_markup_template( "admin.tpl", "addon/appnet/" ); + + $o = replace_macros($t, array( + '$submit' => t('Save Settings'), + // name, label, value, help, [extra values] + '$clientid' => array('clientid', t('Client ID'), get_config('appnet', 'clientid' ), ''), + '$clientsecret' => array('clientsecret', t('Client Secret'), get_config('appnet', 'clientsecret' ), ''), + )); +} + +function appnet_plugin_admin_post(&$a){ + $clientid = ((x($_POST,'clientid')) ? notags(trim($_POST['clientid'])) : ''); + $clientsecret = ((x($_POST,'clientsecret')) ? notags(trim($_POST['clientsecret'])): ''); + set_config('appnet','clientid',$clientid); + set_config('appnet','clientsecret',$clientsecret); + info( t('Settings updated.'). EOL ); +} + function appnet_connect(&$a) { require_once 'addon/appnet/AppDotNet.php'; - $clientId = get_pconfig(local_user(),'appnet','clientid'); - $clientSecret = get_pconfig(local_user(),'appnet','clientsecret'); + $clientId = get_config('appnet','clientid'); + $clientSecret = get_config('appnet','clientsecret'); + + if (($clientId == "") OR ($clientSecret == "")) { + $clientId = get_pconfig(local_user(),'appnet','clientid'); + $clientSecret = get_pconfig(local_user(),'appnet','clientsecret'); + } $app = new AppDotNet($clientId, $clientSecret); @@ -105,8 +149,14 @@ function appnet_settings(&$a,&$s) { return; $token = get_pconfig(local_user(),'appnet','token'); - $app_clientId = get_pconfig(local_user(),'appnet','clientid'); - $app_clientSecret = get_pconfig(local_user(),'appnet','clientsecret'); + + $app_clientId = get_config('appnet','clientid'); + $app_clientSecret = get_config('appnet','clientsecret'); + + if (($app_clientId == "") OR ($app_clientSecret == "")) { + $app_clientId = get_pconfig(local_user(),'appnet','clientid'); + $app_clientSecret = get_pconfig(local_user(),'appnet','clientsecret'); + } /* Add our stylesheet to the page so we can make our settings look nice */ $a->page['htmlhead'] .= '' . "\r\n"; @@ -125,11 +175,11 @@ function appnet_settings(&$a,&$s) { $ownid = get_pconfig(local_user(),'appnet','ownid'); $s .= ''; - $s .= '

'. t('App.net Export').'

'; + $s .= '

'. t('App.net Import/Export').'

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