function appnet_settings(&$a, &$s) { require_once 'addon/appnet/AppDotNet.php'; if (!local_user()) { return; } $token = get_pconfig(local_user(), 'appnet', 'token'); $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'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/appnet/appnet.css' . '" media="all" />' . "\r\n"; $enabled = get_pconfig(local_user(), 'appnet', 'post'); $checked = $enabled ? ' checked="checked" ' : ''; $css = $enabled ? '' : '-disabled'; $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 .= '<span id="settings_appnet_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_appnet_expanded\'); openClose(\'settings_appnet_inflated\');">'; $s .= '<img class="connector' . $css . '" src="images/appnet.png" /><h3 class="connector">' . t('App.net Import/Export') . '</h3>'; $s .= '</span>'; $s .= '<div id="settings_appnet_expanded" class="settings-block" style="display: none;">'; $s .= '<span class="fakelink" onclick="openClose(\'settings_appnet_expanded\'); openClose(\'settings_appnet_inflated\');">'; $s .= '<img class="connector' . $css . '" src="images/appnet.png" /><h3 class="connector">' . t('App.net Import/Export') . '</h3>'; $s .= '</span>'; if ($token != "") { $app = new AppDotNet($app_clientId, $app_clientSecret); $app->setAccessToken($token); try { $userdata = $app->getUser(); if ($ownid != $userdata["id"]) { set_pconfig(local_user(), 'appnet', 'ownid', $userdata["id"]); } $s .= '<div id="appnet-info" ><img id="appnet-avatar" src="' . $userdata["avatar_image"]["url"] . '" /><p id="appnet-info-block">' . t('Currently connected to: ') . '<a href="' . $userdata["canonical_url"] . '" target="_appnet">' . $userdata["username"] . '</a><br /><em>' . $userdata["description"]["text"] . '</em></p></div>'; $s .= '<div id="appnet-enable-wrapper">'; $s .= '<label id="appnet-enable-label" for="appnet-checkbox">' . t('Enable App.net Post Plugin') . '</label>'; $s .= '<input id="appnet-checkbox" type="checkbox" name="appnet" value="1" ' . $checked . '/>'; $s .= '</div><div class="clear"></div>'; $s .= '<div id="appnet-bydefault-wrapper">'; $s .= '<label id="appnet-bydefault-label" for="appnet-bydefault">' . t('Post to App.net by default') . '</label>'; $s .= '<input id="appnet-bydefault" type="checkbox" name="appnet_bydefault" value="1" ' . $def_checked . '/>'; $s .= '</div><div class="clear"></div>'; $s .= '<label id="appnet-import-label" for="appnet-import">' . t('Import the remote timeline') . '</label>'; $s .= '<input id="appnet-import" type="checkbox" name="appnet_import" value="1" ' . $importchecked . '/>'; $s .= '<div class="clear"></div>'; } catch (AppDotNetException $e) { $s .= t("<p>Error fetching user profile. Please clear the configuration and try again.</p>"); } } elseif ($app_clientId == '' or $app_clientSecret == '') { $s .= t("<p>You have two ways to connect to App.net.</p>"); $s .= "<hr />"; $s .= t('<p>First way: Register an application at <a href="https://account.app.net/developer/apps/">https://account.app.net/developer/apps/</a> and enter Client ID and Client Secret. '); $s .= sprintf(t("Use '%s' as Redirect URI<p>"), $a->get_baseurl() . '/appnet/connect'); $s .= '<div id="appnet-clientid-wrapper">'; $s .= '<label id="appnet-clientid-label" for="appnet-clientid">' . t('Client ID') . '</label>'; $s .= '<input id="appnet-clientid" type="text" name="clientid" value="" />'; $s .= '</div><div class="clear"></div>'; $s .= '<div id="appnet-clientsecret-wrapper">'; $s .= '<label id="appnet-clientsecret-label" for="appnet-clientsecret">' . t('Client Secret') . '</label>'; $s .= '<input id="appnet-clientsecret" type="text" name="clientsecret" value="" />'; $s .= '</div><div class="clear"></div>'; $s .= "<hr />"; $s .= t('<p>Second way: fetch a token at <a href="http://dev-lite.jonathonduerig.com/">http://dev-lite.jonathonduerig.com/</a>. '); $s .= t("Set these scopes: 'Basic', 'Stream', 'Write Post', 'Public Messages', 'Messages'.</p>"); $s .= '<div id="appnet-token-wrapper">'; $s .= '<label id="appnet-token-label" for="appnet-token">' . t('Token') . '</label>'; $s .= '<input id="appnet-token" type="text" name="token" value="' . $token . '" />'; $s .= '</div><div class="clear"></div>'; } else { $app = new AppDotNet($app_clientId, $app_clientSecret); $scope = array('basic', 'stream', 'write_post', 'public_messages', 'messages'); $url = $app->getAuthUrl($a->get_baseurl() . '/appnet/connect', $scope); $s .= '<div class="clear"></div>'; $s .= '<a href="' . $url . '">' . t("Sign in using App.net") . '</a>'; } if ($app_clientId != '' or $app_clientSecret != '' or $token != '') { $s .= '<div id="appnet-disconnect-wrapper">'; $s .= '<label id="appnet-disconnect-label" for="appnet-disconnect">' . t('Clear OAuth configuration') . '</label>'; $s .= '<input id="appnet-disconnect" type="checkbox" name="appnet-disconnect" value="1" />'; $s .= '</div><div class="clear"></div>'; } /* provide a submit button */ $s .= '<div class="settings-submit-wrapper" ><input type="submit" name="appnet-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>'; $s .= '</div>'; }
<?php require_once 'AppDotNet.php'; $app = new AppDotNet(); // check that the user is signed in if ($app->getSession()) { // get the current user as JSON $data = $app->getUser(); // accessing the user's cover image echo '<body style="background:url(' . $data['cover_image']['url'] . ')">'; echo '<div style="background:#fff;opacity:0.8;padding:20px;margin:10px;border-radius:15px;">'; echo '<h1>Welcome to <a target="_blank" href="https://github.com/jdolitsky/AppDotNetPHP">'; echo 'AppDotNetPHP</a></h1>'; // accessing the user's name echo '<h3>' . $data['name'] . '</h3>'; // accessing the user's avatar image echo '<img style="border:2px solid #000;" src="' . $data['avatar_image']['url'] . '" /><br>'; // try posting to ADN if (isset($_POST['run_tests'])) { print "<hr />"; print "<h3>Testing ADN functionality</h3>"; print '<pre>'; print "<b>Attempting to post a test message to app.net...</b>\n"; print "<blockquote>"; $sampleText = "Testing posting to app.net using AppDotNetPHP - " . uniqid(mt_rand(0, 100000)); $create = $app->createPost($sampleText); // we should now have a post ID and the text should be the same as above if (!$create || !$create['id'] || $create['text'] != $sampleText) { print "Error posting sample text to ADN\n"; var_dump($create); exit;