From: Michael Vogel Date: Sun, 15 Jun 2014 15:33:16 +0000 (+0200) Subject: Appnet: Now you can add a central oauth configuration as well. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=179b19473cd5c88f9a7236e26c151ecdd46a609f;p=friendica-addons.git Appnet: Now you can add a central oauth configuration as well. --- diff --git a/appnet/appnet.php b/appnet/appnet.php index 03be4820..db595c99 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -61,11 +61,35 @@ function appnet_content(&$a) { return $o; } +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 +129,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"; @@ -169,11 +199,11 @@ function appnet_settings(&$a,&$s) { $s .= sprintf(t("Use '%s' as Redirect URI

"), $a->get_baseurl().'/appnet/connect'); $s .= '

'; $s .= ''; - $s .= ''; + $s .= ''; $s .= '
'; $s .= '
'; $s .= ''; - $s .= ''; + $s .= ''; $s .= '
'; $s .= "
"; $s .= t('

Second way: fetch a token at http://dev-lite.jonathonduerig.com/. '); diff --git a/appnet/templates/admin.tpl b/appnet/templates/admin.tpl new file mode 100644 index 00000000..a933f3d3 --- /dev/null +++ b/appnet/templates/admin.tpl @@ -0,0 +1,3 @@ +{{include file="field_input.tpl" field=$clientid}} +{{include file="field_input.tpl" field=$clientsecret}} +