Exemplo n.º 1
0
 /**
  * Executa uma requisição DELETE.
  *
  * @param $part
  * @param array $data
  * @param array $headers
  * @return mixed
  */
 public function delete($part, $data = [], array $headers = [])
 {
     $opts = ['headers' => array_merge([], $this->headers, $headers)];
     $part = uri_params($part, $data);
     $response = new Response($this->client->delete($part, $opts));
     return $response->make();
 }
function access_token($tmhOAuth)
{
    $params = uri_params();
    if ($params['oauth_token'] !== $_SESSION['oauth']['oauth_token']) {
        error('The oauth token you started with doesn\'t match the one you\'ve been redirected with. do you have multiple tabs open?');
        session_unset();
        return;
    }
    if (!isset($params['oauth_verifier'])) {
        error('The oauth verifier is missing so we cannot continue. did you deny the appliction access?');
        session_unset();
        return;
    }
    // update with the temporary token and secret
    $tmhOAuth->reconfigure(array_merge($tmhOAuth->config, array('token' => $_SESSION['oauth']['oauth_token'], 'secret' => $_SESSION['oauth']['oauth_token_secret'])));
    $code = $tmhOAuth->user_request(array('method' => 'POST', 'url' => $tmhOAuth->url('oauth/access_token', ''), 'params' => array('oauth_verifier' => trim($params['oauth_verifier']))));
    if ($code == 200) {
        $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        ?>
<p>Congratulations, below is the user token and secret for @<?php 
        echo htmlspecialchars($oauth_creds['screen_name']);
        ?>
.
Use these to make authenticated calls to Twitter using the application with
consumer key: <?php 
        echo htmlspecialchars($tmhOAuth->config['consumer_key']);
        ?>
</p>

<p>User Token: <?php 
        echo htmlspecialchars($oauth_creds['oauth_token']);
        ?>
<br />
User Secret: <?php 
        echo htmlspecialchars($oauth_creds['oauth_token_secret']);
        ?>
</p>
<?php 
    }
}
Exemplo n.º 3
0
function access_token($tmhOAuth)
{
    $params = uri_params();
    if ($params['oauth_token'] !== $_SESSION['oauth']['oauth_token']) {
        error('The oauth token you started with doesn\'t match the one you\'ve been redirected with. do you have multiple tabs open?');
        return;
    }
    if (!isset($params['oauth_verifier'])) {
        error('The oauth verifier is missing so we cannot continue. did you deny the appliction access?');
        return;
    }
    // update with the temporary token and secret
    $tmhOAuth->reconfigure(array_merge($tmhOAuth->config, array('token' => $_SESSION['oauth']['oauth_token'], 'secret' => $_SESSION['oauth']['oauth_token_secret'])));
    $code = $tmhOAuth->user_request(array('method' => 'POST', 'url' => $tmhOAuth->url('oauth/access_token', ''), 'params' => array('oauth_verifier' => trim($params['oauth_verifier']))));
    if ($code == 200) {
        $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        verify_credentials($tmhOAuth, htmlspecialchars($oauth_creds['oauth_token']), htmlspecialchars($oauth_creds['oauth_token_secret']));
    } else {
        error("There was an error communicating with Twitter. {$tmhOAuth->response['response']}");
        return;
    }
}
Exemplo n.º 4
0
/**
 * Ejecuta el controlador que mapeo anteriormente
 * @param type $controlador_esp 
 */
function execute_controller($controlador_esp, $uriapp = NULL)
{
    $dir = "";
    if (!isset($controlador_esp['location'])) {
        $dir = PATHAPP . 'source/controllers/' . $controlador_esp['class'] . '.php';
    } else {
        $dir = PATHAPP . $controlador_esp['location'] . '/' . $controlador_esp['class'] . '.php';
    }
    $controlador = NULL;
    $dinamic_method = FALSE;
    $method = NULL;
    //Analiza si existe el archivo
    if (file_exists($dir)) {
        require_once $dir;
        $dir = explode("/", $controlador_esp['class']);
        $class = $dir[count($dir) - 1];
        $controlador = new $class();
        //Agrego los parametros URI
        $uri_params = uri_params($controlador_esp['url'], $uriapp);
        $dinamic_method = $uri_params['dinamic'];
        $method = $uri_params['method'];
        $controlador->setUriParams($uri_params['params']);
        //Analizo si hay parametros en la configuracion
        if (isset($controlador_esp['params'])) {
            foreach ($controlador_esp['params'] as $key => $value) {
                $controlador->{$key} = $value;
            }
        }
    } else {
        //Avisa que el archivo no existe
        general_error('Controller Error', 'The controller ' . $controlador_esp['class'] . ' dont exists');
    }
    //Saca el metodo HTPP y en base a eso hace una llamada al metodo correspondiente
    $metodo = $_SERVER['REQUEST_METHOD'];
    if ($dinamic_method) {
        if (method_exists($controlador, $method)) {
            $controlador->{$method}();
        } else {
            general_error('HTTP Method Error', "The HTTP method {$method} is not supported");
        }
    } else {
        switch ($metodo) {
            case 'GET':
                $controlador->doGet();
                break;
            case 'POST':
                $controlador->doPost();
                break;
            case 'UPDATE':
                $controlador->doUpdate();
                break;
            case 'DELETE':
                $controlador->doDelete();
                break;
            case 'HEAD':
                $controlador->doHead();
                break;
            case 'TRACE':
                $controlador->doTrace();
                break;
            case 'URI':
                $controlador->doUri();
                break;
            case "OPTIONS":
                $controlador->doOptions();
                break;
            case 'CONNECT':
                $controlador->doConnect();
                break;
            default:
                general_error('HTTP Method Error', "The HTTP method {$metodo} is not supported");
        }
    }
}
function access_token($tmhOAuth)
{
    global $c;
    $params = uri_params();
    if ($params['oauth_token'] !== $_SESSION['oauth']['oauth_token']) {
        Flash('The oauth token you started with doesn\'t match the one you\'ve been redirected with. do you have multiple tabs open?');
        unset($_SESSION['oauth']);
        //session_unset();
        return;
    }
    if (!isset($params['oauth_verifier'])) {
        Flash('The oauth verifier is missing so we cannot continue. did you deny the appliction access?');
        unset($_SESSION['oauth']);
        //session_unset();
        return;
    }
    // update with the temporary token and secret
    $tmhOAuth->reconfigure(array_merge($tmhOAuth->config, array('token' => $_SESSION['oauth']['oauth_token'], 'secret' => $_SESSION['oauth']['oauth_token_secret'])));
    $code = $tmhOAuth->user_request(array('method' => 'POST', 'url' => $tmhOAuth->url('oauth/access_token', ''), 'params' => array('oauth_verifier' => trim($params['oauth_verifier']))));
    if ($code == 200) {
        $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        // Save the credentials in the DB
        $socialy_params = $oauth_creds;
        $socialy_params['owner_id'] = $_SESSION['user_details']['user_id'];
        $socialy_params['type'] = 'twitter';
        $socialy_params['is_active'] = '1';
        $social_response = $c->sendRequest('socialy/account/add', $socialy_params, 'post', true);
        // If there was an error saving the account to the API
        if (array_key_exists('error', $social_response['response']) && is_array($social_response['response']['error'])) {
            Flash($social_response['response']['error']['message'], 'error');
        }
        // Try to get the info for the account
        $tmhOAuth->config['user_token'] = $oauth_creds['oauth_token'];
        $tmhOAuth->config['user_secret'] = $oauth_creds['oauth_token_secret'];
        $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/account/verify_credentials'));
        Pre($code);
        // If this user is valid
        if ($code == 200) {
            // Get the response
            $resp = json_decode($tmhOAuth->response['response'], true);
            Pre($resp);
            // Update it in the twitter account table
            $account_params = $resp;
            $account_params['account_id'] = $social_response['response']['account']['account_id'];
            $account_params['owner_id'] = $_SESSION['user_details']['user_id'];
            unset($account_params['status']);
            $account_response = $c->sendRequest('socialy/twitterinfo/add', $account_params, 'post', true);
            Pre($account_response);
            // If there was an error saving the account to the API
            if (is_array($account_response['response']['error'])) {
                Flash($account_response['response']['error']['message'], 'error');
            } else {
                Flash('Account "' . $account_response['response']['twitter']['screen_name'] . '" added successfully!');
            }
        }
        //header('Location: ' . php_self());
        //die();
    }
}