X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=appnet%2Fappnet.php;h=7e80c6abd2d9471aa3f31c6ece0d688f4e5526af;hb=3d8d0e2860c3cb379e486e5a9565df5cbcc041a0;hp=e30ecdca40e59832bc83e25a1852289d7c9bcecd;hpb=2275f7e32797949265104e1aec1913a377dd8e37;p=friendica-addons.git diff --git a/appnet/appnet.php b/appnet/appnet.php index e30ecdca..7e80c6ab 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -2,17 +2,29 @@ /** * Name: App.net Connector - * Description: Post to app.net - * Version: 0.1 + * Description: app.net postings import and export + * Version: 0.2 * Author: Michael Vogel */ +/* + To-Do: + - 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 +*/ + +define('APPNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes + function appnet_install() { - register_hook('post_local', 'addon/appnet/appnet.php', 'appnet_post_local'); - register_hook('notifier_normal', 'addon/appnet/appnet.php', 'appnet_send'); - register_hook('jot_networks', 'addon/appnet/appnet.php', 'appnet_jot_nets'); - register_hook('connector_settings', 'addon/appnet/appnet.php', 'appnet_settings'); - register_hook('connector_settings_post', 'addon/appnet/appnet.php', 'appnet_settings_post'); + register_hook('post_local', 'addon/appnet/appnet.php', 'appnet_post_local'); + register_hook('notifier_normal', 'addon/appnet/appnet.php', 'appnet_send'); + register_hook('jot_networks', 'addon/appnet/appnet.php', 'appnet_jot_nets'); + 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'); } @@ -20,41 +32,67 @@ function appnet_uninstall() { unregister_hook('post_local', 'addon/appnet/appnet.php', 'appnet_post_local'); unregister_hook('notifier_normal', 'addon/appnet/appnet.php', 'appnet_send'); unregister_hook('jot_networks', 'addon/appnet/appnet.php', 'appnet_jot_nets'); - unregister_hook('connector_settings', 'addon/appnet/appnet.php', 'appnet_settings'); + unregister_hook('cron', 'addon/appnet/appnet.php', 'appnet_cron'); + 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'); } function appnet_module() {} function appnet_content(&$a) { - if(! local_user()) { - notice( t('Permission denied.') . EOL); - return ''; - } + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return ''; + } - require_once("mod/settings.php"); - settings_init($a); - - if (isset($a->argv[1])) - switch ($a->argv[1]) { - case "connect": - $o = appnet_connect($a); - break; - default: - $o = print_r($a->argv, true); - break; - } - else + require_once("mod/settings.php"); + settings_init($a); + + if (isset($a->argv[1])) + switch ($a->argv[1]) { + case "connect": + $o = appnet_connect($a); + break; + default: + $o = print_r($a->argv, true); + break; + } + else $o = appnet_connect($a); - return $o; + 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); @@ -94,8 +132,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"; @@ -108,12 +152,17 @@ function appnet_settings(&$a,&$s) { $def_enabled = get_pconfig(local_user(),'appnet','post_by_default'); $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); + $importenabled = get_pconfig(local_user(),'appnet','import'); + $importchecked = (($importenabled) ? ' checked="checked" ' : ''); + + $ownid = get_pconfig(local_user(),'appnet','ownid'); + $s .= ''; - $s .= '

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

'; + $s .= '

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

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