Exemplo n.º 1
0
 private function _fetch_fireeagle_positions($fireeagle_access_key, $fireeagle_access_secret)
 {
     $position = array();
     require_once MIDCOM_ROOT . '/external/fireeagle.php';
     $fireeagle = new FireEagle($this->_config->get('fireeagle_consumer_key'), $this->_config->get('fireeagle_consumer_secret'), $fireeagle_access_key, $fireeagle_access_secret);
     // Note: this must be C so we get floats correctly from JSON. See http://bugs.php.net/bug.php?id=41403
     setlocale(LC_NUMERIC, 'C');
     $user_data = $fireeagle->user();
     if (!$user_data || !$user_data->user || empty($user_data->user->location_hierarchy)) {
         return $position;
     }
     $best_position = $user_data->user->location_hierarchy[0];
     switch ($best_position->level_name) {
         case 'exact':
             $position['accuracy'] = 10;
             break;
         case 'postal':
             $position['accuracy'] = 20;
             break;
         case 'city':
             $position['accuracy'] = 30;
             break;
         default:
             $position['accuracy'] = 60;
             break;
     }
     $position['latitude'] = $best_position->latitude;
     $position['longitude'] = $best_position->longitude;
     $position['date'] = strtotime($best_position->located_at);
     return $position;
 }
Exemplo n.º 2
0
    
</style>
<h1>Auth me, Amadeus!</h1>
<?php 
    if (isset($_GET['oauth_token'])) {
        // We have a return! So, get the user key!
        $sess = unserialize(base64_decode($_COOKIE['amadeus_request']));
        if ($sess['auth_state'] != "start") {
            echo "<p><strong class='error'>OAuth flow out of sequence.</strong> <a href='/'>Start Again</a>.</p>";
            exit;
        }
        if ($_GET['oauth_token'] != $sess['request_token']) {
            echo "<p><strong class='error'>OAuth token mismatch</strong>. <a href='/'>Start Again</a>.</p>";
            exit;
        }
        $fe = new FireEagle($sess['app_consumer'], $sess['app_secret'], $sess['request_token'], $sess['request_secret']);
        $tok = $fe->getAccessToken();
        if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) {
            error_log("Bad token from FireEagle::getAccessToken(): " . var_export($tok, TRUE));
            echo "ERROR! FireEagle::getAccessToken() returned an invalid response. Giving up.";
            exit;
        }
        ?>
        
        <p><em>Awesome</em>, you've authed and now have some user credentials to use in your script.
            <strong>Remember to keep these secret, they are for your personal use only!</strong>.</p>
        
        <dl>
            <dt>User Token:</dt>
            <dd><?php 
        echo $tok['oauth_token'];
Exemplo n.º 3
0
        $session->set('request_secret', $request_token['oauth_token_secret']);
        ?>
        <p><a href="<?php 
        echo $fireeagle->getAuthorizeURL($request_token['oauth_token']);
        ?>
" target="_blank">Authorize this application</a></p>
        <p><a href="?f=callback">And then click here</a></p>
        <?php 
        midcom::get()->finish();
        _midcom_stop_request();
    } elseif (isset($_GET['f']) && $_GET['f'] == 'callback') {
        // the user has authorized us at FE, so now we can pick up our access token + secret
        if (!$session->exists('auth_state') || $session->get('auth_state') != 'start') {
            throw new midcom_error("Out of sequence.");
        }
        $fireeagle = new FireEagle($fireeagle_consumer_key, $fireeagle_consumer_secret, $session->get('request_token'), $session->get('request_secret'));
        $access_token = $fireeagle->getAccessToken();
        if (!isset($access_token['oauth_token']) || !is_string($access_token['oauth_token']) || !isset($access_token['oauth_token_secret']) || !is_string($access_token['oauth_token_secret'])) {
            throw new midcom_error("Failed to get FireEagle access token\n");
        }
        $user->set_parameter('net.yahoo.fireeagle', 'access_key', $access_token['oauth_token']);
        $user->set_parameter('net.yahoo.fireeagle', 'access_secret', $access_token['oauth_token_secret']);
        midcom::get()->relocate($_SERVER['SCRIPT_NAME']);
        // This will exit
    }
    ?>
    <p><a href="?f=start">Start Fire Eagle authentication</a></p>
    <?php 
    midcom::get()->finish();
    _midcom_stop_request();
}
Exemplo n.º 4
0
function wpfe_wp_admin()
{
    global $fe_key;
    global $fe_secret;
    $access_token = get_option('wpfe_access_token');
    $access_secret = get_option('wpfe_access_secret');
    ?>
  <div class="wrap">
  <h2>FireEagle Configuration</h2>
  
  <?php 
    if (!empty($_REQUEST['action'])) {
        switch ($_REQUEST['action']) {
            case 'token':
                $fe = new FireEagle($fe_key, $fe_secret, $_SESSION['request_token'], $_SESSION['request_secret']);
                $tok = $fe->getAccessToken();
                if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) {
                    error_log("Bad token from FireEagle::getAccessToken(): " . var_export($tok, TRUE));
                    echo "ERROR! FireEagle::getAccessToken() returned an invalid response. Giving up.";
                    exit;
                }
                $_SESSION['auth_state'] = "done";
                update_option('wpfe_access_token', $tok['oauth_token']);
                update_option('wpfe_access_secret', $tok['oauth_token_secret']);
                $access_token = get_option('wpfe_access_token');
                $access_secret = get_option('wpfe_access_secret');
                break;
        }
    }
    // check if we have tokens and be happy about it then
    if ($access_token != false && $access_secret != false) {
        $fe = new FireEagle($fe_key, $fe_secret, $access_token, $access_secret);
        ?>
    <h3>Authentication</h3>
    <p>Congratulations, your FireEagle account is sucesfully authorized with this Wordpress installation.</p>
    <p>If you want, you can <a href="#">revoke it</a> (to be implemented).</p>
    
    <h3>Location</h3>
    <p>FireEagle's best guess about your current location is: <b><?php 
        wpfe_display_best_guess_name();
        ?>
</b>.</p>
    <p><b>Note:</b> plugin checkes FireEagle for updated location status every 15 minutes.</p>
    
    <?php 
    } else {
        // otherwise start authentication process
        $fe = new FireEagle($fe_key, $fe_secret);
        $tok = $fe->getRequestToken();
        if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) {
            echo "ERROR! FireEagle::getRequestToken() returned an invalid response Giving up.";
            exit;
        }
        $_SESSION['auth_state'] = "start";
        $_SESSION['request_token'] = $token = $tok['oauth_token'];
        $_SESSION['request_secret'] = $tok['oauth_token_secret'];
        ?>
  <div align="center">
    <h3>Step 1:</h3>
    <form>
      <input type="button" value="Authenticate" onclick="window.open('<?php 
        echo $fe->getAuthorizeURL($token);
        ?>
')" style="background: url( images/fade-butt.png ); border: 3px double #999; border-left-color: #ccc; border-top-color: #ccc; color: #333; padding: 0.25em; font-size: 1.5em;" />
    </form>

    <h3>Step 2:</h3>
    <form method="post" action="<?php 
        echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']);
        ?>
">
      <input type="hidden" name="action" value="token" />
      <input type="submit" name="Submit" value="<?php 
        _e('Finish &raquo;');
        ?>
" style="background: url( images/fade-butt.png ); border: 3px double #999; border-left-color: #ccc; border-top-color: #ccc; color: #333; padding: 0.25em; font-size: 1.5em;" />
    </form>
  </div>
  
  <?php 
    }
    ?>
  </div><?php 
}