public function getAuthUrl($redirectUri = null, $scope = null)
 {
     global $app_redirectUri, $app_scope;
     if (is_null($redirectUri)) {
         $redirectUri = $app_redirectUri;
     }
     if (is_null($scope)) {
         $scope = $app_scope;
     }
     return parent::getAuthUrl($redirectUri, $scope);
 }
示例#2
0
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>';
}
示例#3
0
            var_dump($delete);
            exit;
        }
        print "Successfully deleted the sample post from ADN, post ID was " . $delete['id'] . "\n";
        print "</blockquote>";
        // more tests can/should be included here
        // done tests!
        print "<b>All test completed successfully!</b>\n";
        print "</pre>";
    } else {
        print "<hr />";
        print "<h3>Complete user data</h3>";
        echo '<pre style="font-weight:bold;font-size:16px">';
        print_r($data);
        echo '</pre>';
    }
    print "<hr />";
    print '<form method="POST" action="index.php"><input type="submit" name="run_tests" value="Run POST/GET/DELETE tests" /><br />This will post a test message to your stream under your name, fetch it, then delete it.</form>';
    print "<hr />";
    echo '<h2><a href="signout.php">Sign out</a></h2>';
    echo '</div></body>';
    // otherwise prompt to sign in
} else {
    $url = $app->getAuthUrl();
    echo '<a href="' . $url . '"><h2>Sign in using App.net</h2></a>';
}
?>