You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ch...@apache.org on 2008/05/22 02:13:06 UTC

svn commit: r658951 - in /incubator/shindig/trunk/php/src/gadgets: JsFeatureLoader.php http/SigningFetcher.php oauth/OAuth.php samplecontainer/BasicRemoteContentFetcher.php

Author: chabotc
Date: Wed May 21 17:13:06 2008
New Revision: 658951

URL: http://svn.apache.org/viewvc?rev=658951&view=rev
Log:
few small fixes in the ongoing process to finish oauth/signed fetching:

- Reworked SigningFetcher to use parse_url() instead of Zend_Uri, the later was crashing on some (misformatted) url
- Added original query params back to signRequest(), they shouldn't be skipped :)
- Added a OAuth container/synd key hack (to be fixed properly soon) so the code path is at least testable
- Reworked JsFeatureLoader and removed the recursion from loadFiles(), it was picking up on mvn generated files and thus loading things twice if you also mvn'd
- Added CURLOPT_SSL_VERIFYPEER option to BasicRemoteContentFetcher, not all gadget cert's are verifiable


Modified:
    incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php
    incubator/shindig/trunk/php/src/gadgets/http/SigningFetcher.php
    incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php
    incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php

Modified: incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php?rev=658951&r1=658950&r2=658951&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php Wed May 21 17:13:06 2008
@@ -39,20 +39,11 @@
 
 	private function loadFiles($path, &$features)
 	{
-		if (is_dir($path)) {
-			foreach (glob("$path/*") as $file) {
-				// prevents us from looping over '.', '..' and 'hidden files', this last bit IS 
-				// different from the java version but it's the unix standard really..
-				if (substr(basename($file), 0, 1) != '.') {
-					$features = $this->loadFiles($file, $features);
-				}
-			}
-		} else {
-			if (basename($path) == 'feature.xml') {
-				$feature = $this->processFile($path);
-				if ($feature != null) {
-					$features[$feature->name] = $feature;
-				}
+		foreach (glob("$path/*/feature.xml") as $file) {
+			$file = realpath($file);
+			$feature = $this->processFile($file);
+			if ($feature != null) {
+				$features[$feature->name] = $feature;
 			}
 		}
 		return $features;

Modified: incubator/shindig/trunk/php/src/gadgets/http/SigningFetcher.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/SigningFetcher.php?rev=658951&r1=658950&r2=658951&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/SigningFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/http/SigningFetcher.php Wed May 21 17:13:06 2008
@@ -110,9 +110,8 @@
 			// Parse the request into parameters for OAuth signing, stripping out
 			// any OAuth or OpenSocial parameters injected by the client
 			///////////////////////////////////////////////
-			require 'src/common/Zend/Uri.php';
-			$uri = Zend_Uri::factory($url);
-			$resource = $uri->getUri();
+			$parsedUri = parse_url($url);
+			$resource = $url;
 			$queryParams = $this->sanitize($_GET);
 			$postParams = $this->sanitize($_POST);
 			$msgParams = array();
@@ -144,18 +143,23 @@
 			foreach ($postParams as $key => $param) {
 				$forPost[$key] = $param;
 			}
-			$newQuery = array();
+			$newQuery = '';
 			foreach ($req_req->get_parameters() as $key => $param) {
 				if (! isset($forPost[$key])) {
-					$newQuery[$key] = $param;
+					$newQuery .= urlencode($key).'='.urlencode($param).'&';
 				}
 			}
-			
+			// and stick on the original query params too
+			$oldQuery = array();
+			parse_str($parsedUri['query'], $oldQuery);
+			foreach ($oldQuery as $key => $val) {
+				$newQuery .= urlencode($key).'='.urlencode($val).'&';
+			}			
 			// Careful here; the OAuth form encoding scheme is slightly different than
 			// the normal form encoding scheme, so we have to use the OAuth library
-			// formEncode method.
-			$uri->setQuery($newQuery);
-			return new RemoteContentRequest($uri->getUri());
+			// formEncode method.
+			$url = $parsedUri['scheme'].'://'.$parsedUri['host'].$parsedUri['path'].'?'.$newQuery;
+			return new RemoteContentRequest($url);
 		} catch (Exception $e) {
 			throw new GadgetException($e);
 		}

Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php?rev=658951&r1=658950&r2=658951&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php Wed May 21 17:13:06 2008
@@ -261,8 +261,12 @@
 	 */
 	public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL)
 	{
-		@$parameters or $parameters = array();
-		$defaults = array("oauth_nonce" => OAuthRequest::generate_nonce(), "oauth_timestamp" => OAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key);
+		$parameters = is_array($parameters) ? $parameters : array();
+		$defaults = array("oauth_nonce" => OAuthRequest::generate_nonce(), "oauth_timestamp" => OAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key,
+		// quick hack to make this demo'able
+		'synd' => 'partuza',
+		'container' => 'partuza'
+		);
 		$parameters = array_merge($defaults, $parameters);
 		if (isset($token)) {
 			$parameters['oauth_token'] = $token;
@@ -365,7 +369,7 @@
 	{
 		$tmp = $this->parameters;
 		$parts = parse_url($this->http_url);
-		$params = split('[&=]', @$parts['query']);
+		$params = parse_str(@$parts['query']);
 		if (count($params) > 1) {
 			for ($i = 0; $i < count($params); $i += 2) {
 				$this->parameters[$params[$i]] = urldecode($params[$i + 1]);

Modified: incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php?rev=658951&r1=658950&r2=658951&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php Wed May 21 17:13:06 2008
@@ -36,6 +36,7 @@
 		curl_setopt($request->handle, CURLOPT_CONNECTTIMEOUT, 10);
 		curl_setopt($request->handle, CURLOPT_TIMEOUT, 20);
 		curl_setopt($request->handle, CURLOPT_HEADER, 1);
+		curl_setopt($request->handle, CURLOPT_SSL_VERIFYPEER, 0);
 		if ($request->hasHeaders()) {
 			$headers = explode("\n", $request->getHeaders());
 			$outHeaders = array();