private function multisite_url($url) { $stage_url = new Url($url); $current_site = new Url(get_home_url(get_current_blog_id())); $current_site->host = str_replace($current_site->registerableDomain, $stage_url->registerableDomain, $current_site->host); return rtrim($current_site->getUrl(), '/') . $_SERVER['REQUEST_URI']; }
public function handle() { $client = new Client(); $post = DB::table('posts')->where('id', $this->post_id)->first(); $urls = \Purl\Url::extract($post->content); if (config('twitter.oauth_token')) { $credentials = array('consumer_key' => config('twitter.id'), 'consumer_secret' => config('twitter.secret'), 'oauth_token' => config('twitter.oauth_token'), 'oauth_token_secret' => config('twitter.oauth_secret')); $auth = new SingleUserAuth($credentials, new ArraySerializer()); $params = ['status' => $post->content]; $response = $auth->post('statuses/update', $params); } if (config('linkedin.oauth_token')) { try { $post_data = array('comment' => $post->content, 'content' => array('description' => $post->content), 'visibility' => array('code' => 'anyone')); if (!empty($urls)) { $post_data['content']['submittedUrl'] = trim($urls[0]); } $request_body = $post_data; $linkedin_resource = '/v1/people/~/shares'; $request_format = 'json'; $linkedin_params = array('oauth2_access_token' => config('linkedin.oauth_token'), 'format' => $request_format); $linkedinurl_info = parse_url('https://api.linkedin.com' . $linkedin_resource); if (isset($linkedinurl_info['query'])) { $query = parse_str($linkedinurl_info['query']); $linkedin_params = array_merge($linkedin_params, $query); } $request_url = 'https://api.linkedin.com' . $linkedinurl_info['path'] . '?' . http_build_query($linkedin_params); $request_body = json_encode($request_body); $linkedin_response = CurlRequester::requestCURL('POST', $request_url, $request_body, $request_format); } catch (Exception $e) { } } if (config('facebook.oauth_token')) { try { $post_data = array('access_token' => config('facebook.oauth_token'), 'message' => $post->content); if (!empty($urls)) { $post_data['link'] = trim($urls[0]); } $res = $client->post('https://graph.facebook.com/me/feed', array('query' => $post_data)); $response_body = $res->getBody(); $response_body = json_decode($response_body, true); } catch (Exception $e) { } } }
} // Add database configuration to config array $config->add($dbConfig); /** * Start Request Response Objects */ $request = function () { return \Sabre\HTTP\Sapi::getRequest(); }; $response = function () { return new \Sabre\HTTP\Response(); }; /** * Start url parser */ $url = \Purl\Url::fromCurrent(); // determine if we are on https or not $ssl = $url['port'] == '443' ? true : false; /** * Start dic container */ $dic = new \Auryn\Injector(); // Share object instances $services = [$config, $db, $mail(), $request(), $response(), $time(), $url]; foreach ($services as $service) { $dic->share($service); } //check if user is a robot $robots = (require_once __DIR__ . '/Config/' . ENVIRONMENT . '/Robots.php'); /** * Start user object
/** * Return an instance with the specified user information. * * This method MUST retain the state of the current instance, and return * an instance that contains the specified user information. * * Password is optional, but the user information MUST include the * user; an empty string for the user is equivalent to removing user * information. * * @param string $user The user name to use for authority. * @param null|string $password The password associated with $user. * @return self A new instance with the specified user information. */ public function withUserInfo($user, $password = null) { $uriAsString = $this->uriAsString; $url = new Url($uriAsString); if (empty($user)) { $url->set('user', null); $url->set('pass', null); } else { $url->set('user', $user); $url->set('pass', $password); } return new self($url->getUrl()); }
/** * @param AntiMattr\OAuth\OAuth $oauth * @param Buzz\Message\RequestInterface $request * * @throws RuntimeException */ protected function attachOAuthSignature(OAuth $oauth, RequestInterface $request) { $method = $request->getMethod(); $url = new Url($request->getUrl()); $parameters = $url->query->getData(); if ($request instanceof FormRequestInterface) { $fields = $request->getFields(); $parameters = array_merge($fields, $parameters); } // Parameters are sorted by name, using lexicographical byte value ordering. // Ref: Spec: 9.1.1 (1) uksort($parameters, 'strcmp'); // Validate required parameters foreach (array('oauth_consumer_key', 'oauth_timestamp', 'oauth_nonce', 'oauth_version', 'oauth_signature_method') as $parameter) { if (!isset($parameters[$parameter])) { throw new RuntimeException(sprintf('Parameter "%s" must be set.', $parameter)); } } // Remove oauth_signature if present // Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.") if (isset($parameters['oauth_signature'])) { unset($parameters['oauth_signature']); } // Remove default ports // Ref: Spec: 9.1.2 $explicitPort = $url->has('port') ? $url->get('port') : null; if ('https' === $url->get('scheme') && 443 === $explicitPort || 'http' === $url->get('scheme') && 80 === $explicitPort) { $explicitPort = null; } // Remove query params from URL // Ref: Spec: 9.1.2 $urlString = sprintf('%s://%s%s%s', $url->get('scheme'), $url->get('host'), $explicitPort ? ':' . $explicitPort : '', $url->has('path') ? $url->get('path') : ''); // Parameters are sorted by name, using lexicographical byte value ordering. // Ref: Spec: 9.1.1 (1) uksort($parameters, 'strcmp'); // http_build_query should use RFC3986 $parts = array(strtoupper($method), rawurlencode($urlString), rawurlencode(str_replace(array('%7E', '+'), array('~', '%20'), http_build_query($parameters, '', '&')))); $baseString = implode('&', $parts); $signatureMethod = $oauth->getSignatureMethod(); $consumerSecret = $oauth->getConsumerSecret(); $oAuthTokenSecret = $oauth->getOAuthTokenSecret(); switch ($signatureMethod) { case OAuth::SIGNATURE_METHOD_HMAC: $keyParts = array(rawurlencode($consumerSecret), rawurlencode($oAuthTokenSecret)); $signature = hash_hmac('sha1', $baseString, implode('&', $keyParts), true); break; case OAuth::SIGNATURE_METHOD_RSA: if (!function_exists('openssl_pkey_get_private')) { throw new RuntimeException('RSA-SHA1 signature method requires the OpenSSL extension.'); } $privateKey = openssl_pkey_get_private(file_get_contents($consumerSecret), $oAuthTokenSecret); $signature = false; openssl_sign($baseString, $signature, $privateKey); openssl_free_key($privateKey); break; case OAuth::SIGNATURE_METHOD_PLAINTEXT: $signature = $baseString; break; default: throw new RuntimeException(sprintf('Unknown signature method selected %s.', $signatureMethod)); } $encoded = base64_encode($signature); if ($request instanceof FormRequestInterface) { $fields = $request->getFields(); $fields['oauth_signature'] = $encoded; // Parameters are sorted by name, using lexicographical byte value ordering. // Ref: Spec: 9.1.1 (1) uksort($fields, 'strcmp'); $request->setFields($fields); } else { $parameters['oauth_signature'] = $encoded; // Parameters are sorted by name, using lexicographical byte value ordering. // Ref: Spec: 9.1.1 (1) uksort($parameters, 'strcmp'); $url->query->setData($parameters); $url = $url->getUrl(); $request->fromUrl($url); } }
public function testRelativeUrl() { // test all resource parts $url = new Url('/path1/path2?x=1&y=2#frag'); $this->assertFalse($url->isAbsolute()); $this->assertEquals('/path1/path2?x=1&y=2#frag', (string) $url); // test base path $url = new Url('/path1'); $this->assertEquals('/path1', (string) $url); // test minimal path $url = new Url('/'); $this->assertEquals('/', (string) $url); // test feature request $url = new Url('/events'); $url->query->set('param1', 'value1'); $this->assertEquals('/events?param1=value1', (string) $url); }
public function testIdeGettersAndSetters() { $url = new Url('http://jwage.com'); $url->setPath(new Path('about')); $url->setQuery(new Query('param=value')); $url->setFragment(new Fragment(new Path('about'), new Query('param=value'))); $this->assertEquals('http://jwage.com/about?param=value#about?param=value', (string) $url); }
use GuzzleHttp\Client; use TwitterOAuth\Auth\SingleUserAuth; use TwitterOAuth\Serializer\ArraySerializer; $app->get('/', 'HomeController@index'); $app->get('/publish', 'HomeController@publish'); $app->get('/{category}', 'HomeController@index'); use Carbon\Carbon; $app->get('/d/e/f', function () { $date = date('Y-m-d', strtotime('+' . mt_rand(1, 30) . ' days')); $times = config('times.publishing_times'); $index = array_rand($times); $date_time = Carbon::parse($date . ' ' . $times[$index]); }); $app->get('fo/fa/fi', function () { $post = DB::table('posts')->where('id', 2)->first(); $urls = \Purl\Url::extract($post->content); if (!empty($urls)) { return $urls[0]; } }); $app->get('/a/b/c', function () { $client = new Client(); $content = 'The App-ocalypse: can web standards make mobile apps obsolete? http://arstechnica.com/information-technology/2015/12/the-app-ocalypse-can-web-standards-make-mobile-apps-obsolete/'; $post_url = 'http://arstechnica.com/information-technology/2015/12/the-app-ocalypse-can-web-standards-make-mobile-apps-obsolete/'; $content = 'testing ahead'; /* Twitter::setOAuthToken(config('twitter.oauth_token')); Twitter::setOAuthTokenSecret(config('twitter.oauth_secret')); $twitter_response = Twitter::statusesUpdate($content);
public function testFromCurrentServerVariables() { $_SERVER['HTTP_HOST'] = 'jwage.com'; $_SERVER['SERVER_PORT'] = 80; $_SERVER['REQUEST_URI'] = '/about?param=value'; $url = Url::fromCurrent(); $this->assertEquals('http://jwage.com/about?param=value', (string) $url); $_SERVER['HTTPS'] = 'off'; $_SERVER['HTTP_HOST'] = 'jwage.com'; unset($_SERVER['SERVER_PORT']); unset($_SERVER['REQUEST_URI']); $url = Url::fromCurrent(); $this->assertEquals('http://jwage.com/', (string) $url); $_SERVER['HTTPS'] = 'on'; $_SERVER['HTTP_HOST'] = 'jwage.com'; $_SERVER['SERVER_PORT'] = 443; unset($_SERVER['REQUEST_URI']); $url = Url::fromCurrent(); $this->assertEquals('https://jwage.com/', (string) $url); unset($_SERVER['HTTPS']); $_SERVER['HTTP_HOST'] = 'jwage.com'; $_SERVER['SERVER_PORT'] = 8080; unset($_SERVER['REQUEST_URI']); $url = Url::fromCurrent(); $this->assertEquals('http://jwage.com:8080/', (string) $url); unset($_SERVER['HTTPS']); $_SERVER['HTTP_HOST'] = 'jwage.com'; $_SERVER['SERVER_PORT'] = 80; unset($_SERVER['REQUEST_URI']); $_SERVER['PHP_AUTH_USER'] = '******'; $_SERVER['PHP_AUTH_PW'] = 'passwd123'; $url = Url::fromCurrent(); $this->assertEquals('http://*****:*****@jwage.com/', (string) $url); }
/** * Return the path portion of the URL * i.e. http://abc.foo.co.uk/this/path => this/path * * @return string */ public static function path($url) { return (string) Purl::parse($url)->path; }
public function connect(Request $request) { $url = new Url('https://www.dropbox.com/1/oauth2/authorize'); $url->query->setData(array('response_type' => 'token', 'client_id' => 'dln6kugesxo1smk', 'redirect_uri' => 'https://file-requester-ardeelete.c9users.io/login')); return redirect($url->getUrl()); }