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/08/05 00:12:58 UTC
svn commit: r682527 [1/2] - in /incubator/shindig/trunk/php/src: common/
common/samplecontainer/ gadgets/ gadgets/http/ gadgets/oauth/ social-api/
social-api/converters/ social-api/dataservice/ social-api/http/
social-api/opensocial/model/ social-api/s...
Author: chabotc
Date: Mon Aug 4 15:12:56 2008
New Revision: 682527
URL: http://svn.apache.org/viewvc?rev=682527&view=rev
Log:
The new automated testing tool revealed a 'few' formatting glitches, this is the mass cleanup .. sorry for the commit spam
Modified:
incubator/shindig/trunk/php/src/common/CacheMemcache.php
incubator/shindig/trunk/php/src/common/HttpServlet.php
incubator/shindig/trunk/php/src/common/JsMin.php
incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
incubator/shindig/trunk/php/src/common/SecurityToken.php
incubator/shindig/trunk/php/src/common/SecurityTokenDecoder.php
incubator/shindig/trunk/php/src/common/samplecontainer/BasicBlobCrypter.php
incubator/shindig/trunk/php/src/common/samplecontainer/BasicRemoteContentFetcher.php
incubator/shindig/trunk/php/src/common/samplecontainer/BasicSecurityToken.php
incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php
incubator/shindig/trunk/php/src/gadgets/Gadget.php
incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php
incubator/shindig/trunk/php/src/gadgets/GadgetSigner.php
incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php
incubator/shindig/trunk/php/src/gadgets/HttpUtil.php
incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php
incubator/shindig/trunk/php/src/gadgets/LinkSpec.php
incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php
incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php
incubator/shindig/trunk/php/src/gadgets/Preload.php
incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php
incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php
incubator/shindig/trunk/php/src/gadgets/Substitutions.php
incubator/shindig/trunk/php/src/gadgets/http/JsServlet.php
incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
incubator/shindig/trunk/php/src/gadgets/oauth/BasicOAuthStore.php
incubator/shindig/trunk/php/src/gadgets/oauth/GadgetOAuthTokenStore.php
incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php
incubator/shindig/trunk/php/src/gadgets/oauth/OAuthAccessor.php
incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php
incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php
incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php
incubator/shindig/trunk/php/src/social-api/ResponseItem.php
incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php
incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php
incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php
incubator/shindig/trunk/php/src/social-api/converters/OutputConverter.php
incubator/shindig/trunk/php/src/social-api/converters/OutputJsonConverter.php
incubator/shindig/trunk/php/src/social-api/dataservice/ActivitiesService.php
incubator/shindig/trunk/php/src/social-api/dataservice/AppDataService.php
incubator/shindig/trunk/php/src/social-api/dataservice/DataRequestHandler.php
incubator/shindig/trunk/php/src/social-api/dataservice/GroupId.php
incubator/shindig/trunk/php/src/social-api/dataservice/MessagesHandler.php
incubator/shindig/trunk/php/src/social-api/dataservice/UserId.php
incubator/shindig/trunk/php/src/social-api/http/RestServlet.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Address.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/ApiCollection.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/BodyType.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Email.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Enum.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/IdSpec.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Message.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Name.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Organization.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Person.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Phone.php
incubator/shindig/trunk/php/src/social-api/opensocial/model/Url.php
incubator/shindig/trunk/php/src/social-api/samplecontainer/BasicActivitiesService.php
incubator/shindig/trunk/php/src/social-api/samplecontainer/BasicAppDataService.php
Modified: incubator/shindig/trunk/php/src/common/CacheMemcache.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/CacheMemcache.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/CacheMemcache.php (original)
+++ incubator/shindig/trunk/php/src/common/CacheMemcache.php Mon Aug 4 15:12:56 2008
@@ -116,7 +116,8 @@
{
$this->check();
// we store it with the cache_time default expiration so objects will atleast get cleaned eventually.
- if (@memcache_set($this->connection, $key, array('time' => time(), 'data' => $value), false, Config::Get('cache_time')) == false) {
+ if (@memcache_set($this->connection, $key, array('time' => time(),
+ 'data' => $value), false, Config::Get('cache_time')) == false) {
throw new CacheException("Couldn't store data in cache");
}
}
Modified: incubator/shindig/trunk/php/src/common/HttpServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/HttpServlet.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/HttpServlet.php (original)
+++ incubator/shindig/trunk/php/src/common/HttpServlet.php Mon Aug 4 15:12:56 2008
@@ -52,7 +52,7 @@
public function __destruct()
{
if (! $this->noHeaders) {
- header("Content-Type: $this->contentType".(!empty($this->charset) ? "; charset={$this->charset}" : ''));
+ header("Content-Type: $this->contentType" . (! empty($this->charset) ? "; charset={$this->charset}" : ''));
header('Accept-Ranges: bytes');
$content = ob_get_contents();
if ($this->noCache) {
@@ -66,7 +66,7 @@
// Obey browsers (or proxy's) request to send a fresh copy if we recieve a no-cache pragma or cache-control request
if (! isset($_SERVER['HTTP_PRAGMA']) || ! strstr(strtolower($_SERVER['HTTP_PRAGMA']), 'no-cache') && (! isset($_SERVER['HTTP_CACHE_CONTROL']) || ! strstr(strtolower($_SERVER['HTTP_CACHE_CONTROL']), 'no-cache'))) {
// If the browser send us a E-TAG check if it matches (md5 sum of content), if so send a not modified header instead of content
- $etag = '"'.md5($content).'"';
+ $etag = '"' . md5($content) . '"';
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) {
header("ETag: \"$etag\"");
if ($this->lastModified) {
@@ -95,12 +95,12 @@
}
}
}
-
+
public function getCharset()
{
return $this->charset;
}
-
+
public function setCharset($charset)
{
$this->charset = $charset;
Modified: incubator/shindig/trunk/php/src/common/JsMin.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/JsMin.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/JsMin.php (original)
+++ incubator/shindig/trunk/php/src/common/JsMin.php Mon Aug 4 15:12:56 2008
@@ -1,5 +1,4 @@
<?php
-
/**
* jsmin.php - PHP implementation of Douglas Crockford's JSMin.
*
@@ -91,7 +90,7 @@
$this->a = $this->b;
if ($this->a === "'" || $this->a === '"') {
- for (; ; ) {
+ for (;;) {
$this->output .= $this->a;
$this->a = $this->get();
@@ -117,7 +116,7 @@
$this->output .= $this->a . $this->b;
- for (; ; ) {
+ for (;;) {
$this->a = $this->get();
if ($this->a === '/') {
@@ -254,7 +253,7 @@
if ($c === '/') {
switch ($this->peek()) {
case '/':
- for (; ; ) {
+ for (;;) {
$c = $this->get();
if (ord($c) <= self::ORD_LF) {
@@ -265,7 +264,7 @@
case '*':
$this->get();
- for (; ; ) {
+ for (;;) {
switch ($this->get()) {
case '*':
if ($this->peek() === '/') {
Modified: incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContentRequest.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContentRequest.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContentRequest.php Mon Aug 4 15:12:56 2008
@@ -1,5 +1,4 @@
<?php
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Modified: incubator/shindig/trunk/php/src/common/SecurityToken.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/SecurityToken.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/SecurityToken.php (original)
+++ incubator/shindig/trunk/php/src/common/SecurityToken.php Mon Aug 4 15:12:56 2008
@@ -24,10 +24,14 @@
*/
abstract class SecurityToken {
- static public function createFromToken($token, $maxage) {}
+ static public function createFromToken($token, $maxage)
+ {
+ }
+
+ static public function createFromValues($owner, $viewer, $app, $domain, $appUrl, $moduleId)
+ {
+ }
- static public function createFromValues($owner, $viewer, $app, $domain, $appUrl, $moduleId) {}
-
/**
* is this an anonymous token? Always check this before using the owner/viewer/etc
*
Modified: incubator/shindig/trunk/php/src/common/SecurityTokenDecoder.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/SecurityTokenDecoder.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/SecurityTokenDecoder.php (original)
+++ incubator/shindig/trunk/php/src/common/SecurityTokenDecoder.php Mon Aug 4 15:12:56 2008
@@ -23,12 +23,12 @@
*/
abstract class SecurityTokenDecoder {
- /**
- * Decrypts and verifies a gadget security token to return a gadget token.
- *
- * @param tokenString String representation of the token to be created.
- * @return The token representation of the input data.
- * @throws GadgetException If tokenString is not a valid token
- */
- abstract public function createToken($tokenString);
+ /**
+ * Decrypts and verifies a gadget security token to return a gadget token.
+ *
+ * @param tokenString String representation of the token to be created.
+ * @return The token representation of the input data.
+ * @throws GadgetException If tokenString is not a valid token
+ */
+ abstract public function createToken($tokenString);
}
Modified: incubator/shindig/trunk/php/src/common/samplecontainer/BasicBlobCrypter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/samplecontainer/BasicBlobCrypter.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/samplecontainer/BasicBlobCrypter.php (original)
+++ incubator/shindig/trunk/php/src/common/samplecontainer/BasicBlobCrypter.php Mon Aug 4 15:12:56 2008
@@ -115,7 +115,7 @@
{
$map = array();
$items = split("[&=]", $plain);
- for ($i = 0; $i < count($items); ) {
+ for ($i = 0; $i < count($items);) {
$key = urldecode($items[$i ++]);
$value = urldecode($items[$i ++]);
$map[$key] = $value;
Modified: incubator/shindig/trunk/php/src/common/samplecontainer/BasicRemoteContentFetcher.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/samplecontainer/BasicRemoteContentFetcher.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/samplecontainer/BasicRemoteContentFetcher.php (original)
+++ incubator/shindig/trunk/php/src/common/samplecontainer/BasicRemoteContentFetcher.php Mon Aug 4 15:12:56 2008
@@ -38,7 +38,7 @@
curl_setopt($request->handle, CURLOPT_HEADER, 1);
curl_setopt($request->handle, CURLOPT_SSL_VERIFYPEER, 0);
$proxy = Config::get('proxy');
- if (!empty($proxy)) {
+ if (! empty($proxy)) {
curl_setopt($request->handle, CURLOPT_PROXY, $proxy);
}
if ($request->hasHeaders()) {
Modified: incubator/shindig/trunk/php/src/common/samplecontainer/BasicSecurityToken.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/samplecontainer/BasicSecurityToken.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/samplecontainer/BasicSecurityToken.php (original)
+++ incubator/shindig/trunk/php/src/common/samplecontainer/BasicSecurityToken.php Mon Aug 4 15:12:56 2008
@@ -89,7 +89,7 @@
$this->token = $this->crypter->wrap($this->tokenData);
}
}
-
+
public function isAnonymous()
{
return ($this->tokenData[$this->OWNER_KEY] === 0 && $this->tokenData[$this->VIEWER_KEY] === 0);
Modified: incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/BasicGadgetSpecFactory.php Mon Aug 4 15:12:56 2008
@@ -1,4 +1,4 @@
-<?php
+<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -16,45 +16,49 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
-
+ */
+
/**
* Basic implementation of a gadget spec factory.
- */
-class BasicGadgetSpecFactory implements GadgetSpecFactory {
-
- private $fetcher;
-
- public function __construct($fetcher) {
- $this->fetcher = $fetcher;
- }
-
- public function getGadgetSpec(GadgetContext $context) {
- return $this->getGadgetSpecUri($context->getUrl(), $context->getIgnoreCache());
- }
-
+ */
+class BasicGadgetSpecFactory implements GadgetSpecFactory {
+
+ private $fetcher;
+
+ public function __construct($fetcher)
+ {
+ $this->fetcher = $fetcher;
+ }
+
+ public function getGadgetSpec(GadgetContext $context)
+ {
+ return $this->getGadgetSpecUri($context->getUrl(), $context->getIgnoreCache());
+ }
+
/**
* Retrieves a gadget specification from the cache or from the Internet.
- */
- public function getGadgetSpecUri($url, $ignoreCache) {
- if ($ignoreCache) {
- return $this->fetchFromWeb($url, true);
- }
- return $this->fetchFromWeb($url, false);
- }
-
+ */
+ public function getGadgetSpecUri($url, $ignoreCache)
+ {
+ if ($ignoreCache) {
+ return $this->fetchFromWeb($url, true);
+ }
+ return $this->fetchFromWeb($url, false);
+ }
+
/**
* Retrieves a gadget specification from the Internet, processes its views and
* adds it to the cache.
- */
- private function fetchFromWeb($url, $ignoreCache) {
- $remoteContentRequest = new RemoteContentRequest($url);
- $remoteContentRequest->getRequest($url, $ignoreCache);
- $spec = $this->fetcher->fetchRequest($remoteContentRequest);
- $specParser = new GadgetSpecParser();
- $context = new ProxyGadgetContext($url);
- $gadgetSpec = $specParser->parse($spec->getResponseContent(), $context);
- return $gadgetSpec;
- }
-
+ */
+ private function fetchFromWeb($url, $ignoreCache)
+ {
+ $remoteContentRequest = new RemoteContentRequest($url);
+ $remoteContentRequest->getRequest($url, $ignoreCache);
+ $spec = $this->fetcher->fetchRequest($remoteContentRequest);
+ $specParser = new GadgetSpecParser();
+ $context = new ProxyGadgetContext($url);
+ $gadgetSpec = $specParser->parse($spec->getResponseContent(), $context);
+ return $gadgetSpec;
+ }
+
}
Modified: incubator/shindig/trunk/php/src/gadgets/Gadget.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/Gadget.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/Gadget.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/Gadget.php Mon Aug 4 15:12:56 2008
@@ -22,7 +22,8 @@
* The main gadget class, this gets filled in by the GadgetSpecParser, etc
* and contains all the gadget information.
*
- */class Gadget {
+ */
+class Gadget {
private $jsLibraries;
private $substitutions;
private $userPrefValues;
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php Mon Aug 4 15:12:56 2008
@@ -102,7 +102,7 @@
return;
}
foreach ($feature->deps as $dep) {
- //TODO: Temporal fix, double check where empty dependencies are being added
+ //TODO: Temporal fix, double check where empty dependencies are being added
if (! empty($dep)) {
$this->addFeatureToResults($results, $this->features[$dep]);
}
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetSigner.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetSigner.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetSigner.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetSigner.php Mon Aug 4 15:12:56 2008
@@ -24,6 +24,7 @@
* way that is suitable for their site.
*/
abstract class GadgetSigner {
+
/**
* Generates a token for the given gadget.
* Implementations should also add their own user-related context data
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetSpecFactory.php Mon Aug 4 15:12:56 2008
@@ -1,4 +1,4 @@
-<?php
+<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -16,15 +16,15 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
-
-/** Factory of gadget specs */
-interface GadgetSpecFactory {
-
- /** Return a gadget spec for a context */
- public function getGadgetSpec(GadgetContext $context);
-
- /** Return a gadget spec for a URI */
- public function getGadgetSpecUri($url, $ignoreCache);
-
+ */
+
+/** Factory of gadget specs */
+interface GadgetSpecFactory {
+
+ /** Return a gadget spec for a context */
+ public function getGadgetSpec(GadgetContext $context);
+
+ /** Return a gadget spec for a URI */
+ public function getGadgetSpecUri($url, $ignoreCache);
+
}
Modified: incubator/shindig/trunk/php/src/gadgets/HttpUtil.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/HttpUtil.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/HttpUtil.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/HttpUtil.php Mon Aug 4 15:12:56 2008
@@ -22,21 +22,21 @@
* Collection of HTTP utilities
*/
class HttpUtil {
-
+
static public function getView($gadget, $context)
{
- $view = $gadget->getView($context->getView());
+ $view = $gadget->getView($context->getView());
if (empty($view)) {
$containerConfig = $context->getContainerConfig();
$config = $containerConfig->getConfig('default', 'gadgets.features');
$configViews = $config['views'];
if (isset($configViews[$context->getView()])) {
$views = $configViews[$context->getView()];
- if (!empty($views)) {
+ if (! empty($views)) {
$aliasesViews = $views['aliases'];
- for ($i = 0; $i < count($aliasesViews); $i++) {
+ for ($i = 0; $i < count($aliasesViews); $i ++) {
$view = $gadget->getView($aliasesViews[$i]);
- if (!empty($view)) {
+ if (! empty($view)) {
break;
}
}
Modified: incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php Mon Aug 4 15:12:56 2008
@@ -90,7 +90,7 @@
$response['moduleId'] = $gadgetModuleId;
$response['url'] = $gadgetUrl;
$response['iframeUrl'] = UrlGenerator::getIframeURL($gadget, $context);
- $response['userPrefs'] = $prefs;
+ $response['userPrefs'] = $prefs;
return $response;
}
}
\ No newline at end of file
Modified: incubator/shindig/trunk/php/src/gadgets/LinkSpec.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/LinkSpec.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/LinkSpec.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/LinkSpec.php Mon Aug 4 15:12:56 2008
@@ -23,7 +23,7 @@
public $href;
public $method;
- public function __construct($rel, $href, $method='GET')
+ public function __construct($rel, $href, $method = 'GET')
{
$this->rel = $rel;
$this->href = $href;
@@ -34,7 +34,7 @@
{
return $this->rel;
}
-
+
public function getHref()
{
return $this->href;
Modified: incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/LocaleMessageBundle.php Mon Aug 4 15:12:56 2008
@@ -25,16 +25,19 @@
private $name;
private $desc;
- public function __construct($name, $desc) {
+ public function __construct($name, $desc)
+ {
$this->name = $name;
$this->desc = $desc;
}
- public function getName() {
+ public function getName()
+ {
return $this->name;
}
- public function getDesc() {
+ public function getDesc()
+ {
return $this->desc;
}
}
\ No newline at end of file
Modified: incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php Mon Aug 4 15:12:56 2008
@@ -31,7 +31,7 @@
public function parse($xml)
{
$doc = @simplexml_load_string($xml);
- if (!$doc) {
+ if (! $doc) {
throw new Exception("Invalid XML structure in message bundle");
}
$messages = array();
Modified: incubator/shindig/trunk/php/src/gadgets/Preload.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/Preload.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/Preload.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/Preload.php Mon Aug 4 15:12:56 2008
@@ -25,7 +25,7 @@
private $signViewer;
private $signOwner;
private $views = array();
-
+
/**
* Creates a new Preload from an xml node.
*
Modified: incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php Mon Aug 4 15:12:56 2008
@@ -183,7 +183,7 @@
}
}
$etag = md5($result->getResponseContent());
- $lastModified = $result->getResponseHeader('Last-Modified') != null ? $result->getResponseHeader('Last-Modified') : gmdate('D, d M Y H:i:s', $result->getCreated().' GMT');
+ $lastModified = $result->getResponseHeader('Last-Modified') != null ? $result->getResponseHeader('Last-Modified') : gmdate('D, d M Y H:i:s', $result->getCreated() . ' GMT');
$notModified = false;
// If HTTP_PRAGMA | HTTP_CACHE_CONTROL == no-cache, the browser wants to do a 'forced reload'
if (! isset($_SERVER['HTTP_PRAGMA']) || ! strstr(strtolower($_SERVER['HTTP_PRAGMA']), 'no-cache') && (! isset($_SERVER['HTTP_CACHE_CONTROL']) || ! strstr(strtolower($_SERVER['HTTP_CACHE_CONTROL']), 'no-cache'))) {
@@ -201,13 +201,13 @@
}
$this->setCachingHeaders($etag, $this->context->getRefreshInterval(), $lastModified);
// If the cached file time is within the refreshInterval params value and the ETag match, return not-modified
- if ($notModified) {
- header('HTTP/1.0 304 Not Modified', true);
- header('Content-Length: 0', true);
- } else {
+ if ($notModified) {
+ header('HTTP/1.0 304 Not Modified', true);
+ header('Content-Length: 0', true);
+ } else {
// then echo the content
echo $result->getResponseContent();
- }
+ }
} else {
@ob_end_clean();
header("HTTP/1.0 404 Not Found", true);
@@ -229,6 +229,7 @@
{
//TODO get actual character encoding from the request
+
// Extract the request headers from the $_SERVER super-global (this -does- unfortunatly mean that any header that php doesn't understand won't be proxied thru though)
// if this turns out to be a problem we could add support for HTTP_RAW_HEADERS, but this depends on a php.ini setting, so i'd rather prevent that from being required
$headers = '';
Modified: incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php Mon Aug 4 15:12:56 2008
@@ -28,8 +28,8 @@
protected static $OPENSOCIAL_VIEWERID = "opensocial_viewer_id";
protected static $OPENSOCIAL_APPID = "opensocial_app_id";
protected static $XOAUTH_PUBLIC_KEY = "xoauth_signature_publickey";
- protected static $ALLOWED_PARAM_NAME = '^[-_[:alnum:]]+$';
-
+ protected static $ALLOWED_PARAM_NAME = '^[-_[:alnum:]]+$';
+
/**
* Authentication token for the user and gadget making the request.
*/
@@ -115,7 +115,7 @@
// in the $_POST to the Shindig proxy server
// Here we parse it and put it into the $postDataParams array which then is merged into the postParams
// to be used for the GET/POST request and the building of the signature
- $postDataParams = array();
+ $postDataParams = array();
if (isset($_POST['postData']) && count($postDataParts = split('&', urldecode($_POST['postData']))) > 0) {
foreach ($postDataParts as $postDataPart) {
$postDataPartsPair = split('=', $postDataPart);
@@ -139,7 +139,7 @@
// We have to be careful not to copy POST parameters into the query.
// If post and query parameters share a name, they end up being removed
// from the query.
- $forPost = array();
+ $forPost = array();
$postData = false;
if ($method == 'POST') {
foreach ($postParams as $key => $param) {
Modified: incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/SigningFetcherFactory.php Mon Aug 4 15:12:56 2008
@@ -1,5 +1,4 @@
<?php
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Modified: incubator/shindig/trunk/php/src/gadgets/Substitutions.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/Substitutions.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/Substitutions.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/Substitutions.php Mon Aug 4 15:12:56 2008
@@ -21,7 +21,7 @@
class Substitutions {
private $types = array('MESSAGE' => 'MSG', 'BIDI' => 'BIDI', 'USER_PREF' => 'UP',
'MODULE' => 'MODULE');
-
+
private $substitutions = array();
public function __construct()
@@ -65,12 +65,13 @@
* @param uri
* @return The substituted uri, or a dummy value if the result is invalid.
*/
- public function substituteUri($type, $uri) {
+ public function substituteUri($type, $uri)
+ {
if (empty($uri)) {
return null;
}
try {
- if (!empty($type)) {
+ if (! empty($type)) {
return $this->substituteType($type, $uri);
} else {
return $this->substitute($uri);
Modified: incubator/shindig/trunk/php/src/gadgets/http/JsServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/JsServlet.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/JsServlet.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/http/JsServlet.php Mon Aug 4 15:12:56 2008
@@ -73,7 +73,7 @@
$jsLib = $feature;
foreach ($jsLib->getLibraries($context) as $lib) {
if ($lib->getType() != 'URL') {
- $jsData .= $lib->getContent()."\n";
+ $jsData .= $lib->getContent() . "\n";
}
}
}
Modified: incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php Mon Aug 4 15:12:56 2008
@@ -47,7 +47,7 @@
foreach ($oauthConfig as $gadgetUri => $value) {
$this->storeConsumerInfos($gadgetUri, $value);
}
- } catch (Exception $e) {
+ } catch (Exception $e) {
throw new GadgetException($e);
}
}
@@ -62,12 +62,10 @@
}
private function storeConsumerInfo($gadgetUri, $serviceName, $consumerInfo)
- {
- if (!isset($consumerInfo[$this->CONSUMER_SECRET_KEY]) ||
- !isset($consumerInfo[$this->CONSUMER_KEY_KEY]) ||
- !isset($consumerInfo[$this->KEY_TYPE_KEY]) ) {
- throw new Exception("Invalid configuration in oauth.json");
- }
+ {
+ if (! isset($consumerInfo[$this->CONSUMER_SECRET_KEY]) || ! isset($consumerInfo[$this->CONSUMER_KEY_KEY]) || ! isset($consumerInfo[$this->KEY_TYPE_KEY])) {
+ throw new Exception("Invalid configuration in oauth.json");
+ }
$consumerSecret = $consumerInfo[$this->CONSUMER_SECRET_KEY];
$consumerKey = $consumerInfo[$this->CONSUMER_KEY_KEY];
$keyTypeStr = $consumerInfo[$this->KEY_TYPE_KEY];
@@ -100,7 +98,7 @@
}
}
$kas = new ConsumerKeyAndSecret($consumerKey, $consumerSecret, $keyType);
- $this->storeConsumerKeyAndSecret($gadgetUri, $serviceName, $kas);
+ $this->storeConsumerKeyAndSecret($gadgetUri, $serviceName, $kas);
}
}
Modified: incubator/shindig/trunk/php/src/gadgets/oauth/BasicOAuthStore.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/BasicOAuthStore.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/BasicOAuthStore.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/BasicOAuthStore.php Mon Aug 4 15:12:56 2008
@@ -57,7 +57,7 @@
}
public function getOAuthAccessorProviderKey(ProviderKey $providerKey, ProviderInfo $provInfo)
- {
+ {
if ($provInfo == null) {
throw new OAuthNoDataException("must pass non-null provider info to getOAuthAccessor");
}
@@ -68,10 +68,10 @@
//ConsumerKeyAndSecret
$key = md5(serialize($providerKey));
$consumerKeyAndSecret = null;
- if (isset($this->consumerInfos[$key])) {
+ if (isset($this->consumerInfos[$key])) {
$consumerKeyAndSecret = $this->consumerInfos[$key];
} else {
- throw new OAuthNoDataException("The Key was invalid for consumerInfos, maybe your oauth.json configuration is wrong.");
+ throw new OAuthNoDataException("The Key was invalid for consumerInfos, maybe your oauth.json configuration is wrong.");
}
if ($consumerKeyAndSecret == null) {
if ($this->defaultConsumerKey == null || $this->defaultConsumerSecret == null) {
Modified: incubator/shindig/trunk/php/src/gadgets/oauth/GadgetOAuthTokenStore.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/GadgetOAuthTokenStore.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/GadgetOAuthTokenStore.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/GadgetOAuthTokenStore.php Mon Aug 4 15:12:56 2008
@@ -130,7 +130,7 @@
if (empty($getUserId)) {
throw new OAuthStoreException("found empty userId in TokenKey");
}
- $gadgetSpec = $this->specFactory->getGadgetSpecUri($gadgetUri, $ignoreCache);
+ $gadgetSpec = $this->specFactory->getGadgetSpecUri($gadgetUri, $ignoreCache);
$provInfo = $this->getProviderInfo($gadgetSpec, $tokenKey->getServiceName());
return $this->store->getOAuthAccessorTokenKey($tokenKey, $provInfo);
}
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=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php Mon Aug 4 15:12:56 2008
@@ -1,4 +1,4 @@
-<?php
+<?php
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -16,325 +16,325 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
- */
-
-class OAuth {
- public static $VERSION_1_0 = "1.0";
- public static $ENCODING = "UTF-8";
- public static $FORM_ENCODED = "application/x-www-form-urlencoded";
- public static $OAUTH_CONSUMER_KEY = "oauth_consumer_key";
- public static $OAUTH_TOKEN = "oauth_token";
- public static $OAUTH_TOKEN_SECRET = "oauth_token_secret";
- public static $OAUTH_SIGNATURE_METHOD = "oauth_signature_method";
- public static $OAUTH_SIGNATURE = "oauth_signature";
- public static $OAUTH_TIMESTAMP = "oauth_timestamp";
- public static $OAUTH_NONCE = "oauth_nonce";
- public static $OAUTH_VERSION = "oauth_version";
- public static $HMAC_SHA1 = "HMAC_SHA1";
- public static $RSA_SHA1 = "RSA_SHA1";
- public static $BEGIN_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----";
- public static $END_PRIVATE_KEY = "-----END PRIVATE KEY-----";
- public static $OAUTH_PROBLEM = "oauth_problem";
-}
-
+ */
+
+class OAuth {
+ public static $VERSION_1_0 = "1.0";
+ public static $ENCODING = "UTF-8";
+ public static $FORM_ENCODED = "application/x-www-form-urlencoded";
+ public static $OAUTH_CONSUMER_KEY = "oauth_consumer_key";
+ public static $OAUTH_TOKEN = "oauth_token";
+ public static $OAUTH_TOKEN_SECRET = "oauth_token_secret";
+ public static $OAUTH_SIGNATURE_METHOD = "oauth_signature_method";
+ public static $OAUTH_SIGNATURE = "oauth_signature";
+ public static $OAUTH_TIMESTAMP = "oauth_timestamp";
+ public static $OAUTH_NONCE = "oauth_nonce";
+ public static $OAUTH_VERSION = "oauth_version";
+ public static $HMAC_SHA1 = "HMAC_SHA1";
+ public static $RSA_SHA1 = "RSA_SHA1";
+ public static $BEGIN_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----";
+ public static $END_PRIVATE_KEY = "-----END PRIVATE KEY-----";
+ public static $OAUTH_PROBLEM = "oauth_problem";
+}
+
/* Generic exception class
- */
-class OAuthException extends Exception {}
-
-class OAuthProblemException extends Exception {}
-
-class OAuthProtocolException extends Exception {}
-
-class OAuthConsumer {
- public $key;
- public $secret;
- public $callback_url;
- private $properties = array();
-
- function __construct($key, $secret, $callback_url = NULL)
- {
- $this->key = $key;
- $this->secret = $secret;
- $this->callback_url = $callback_url;
- }
-
- public function getProperty($name)
- {
- return $this->properties[$name];
- }
-
- public function setProperty($name, $value)
- {
- $this->properties[$name] = $value;
- }
-
-}
-
-class OAuthToken {
+ */
+class OAuthException extends Exception {}
+
+class OAuthProblemException extends Exception {}
+
+class OAuthProtocolException extends Exception {}
+
+class OAuthConsumer {
+ public $key;
+ public $secret;
+ public $callback_url;
+ private $properties = array();
+
+ function __construct($key, $secret, $callback_url = NULL)
+ {
+ $this->key = $key;
+ $this->secret = $secret;
+ $this->callback_url = $callback_url;
+ }
+
+ public function getProperty($name)
+ {
+ return $this->properties[$name];
+ }
+
+ public function setProperty($name, $value)
+ {
+ $this->properties[$name] = $value;
+ }
+
+}
+
+class OAuthToken {
// access tokens and request tokens
- public $key;
- public $secret;
-
+ public $key;
+ public $secret;
+
/**
* key = the token
* secret = the token secret
- */
- function __construct($key, $secret)
- {
- $this->key = $key;
- $this->secret = $secret;
- }
-
+ */
+ function __construct($key, $secret)
+ {
+ $this->key = $key;
+ $this->secret = $secret;
+ }
+
/**
* generates the basic string serialization of a token that a server
* would respond to request_token and access_token calls with
- */
- function to_string()
- {
- return "oauth_token=" . OAuthUtil::urlencodeRFC3986($this->key) . "&oauth_token_secret=" . OAuthUtil::urlencodeRFC3986($this->secret);
- }
-
- function __toString()
- {
- return $this->to_string();
- }
-}
-
-class OAuthSignatureMethod {
-
- public function check_signature(&$request, $consumer, $token, $signature)
- {
- $built = $this->build_signature($request, $consumer, $token);
- return $built == $signature;
- }
-}
-
-class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {
-
- function get_name()
- {
- return "HMAC-SHA1";
- }
-
- public function build_signature($request, $consumer, $token)
- {
- $base_string = $request->get_signature_base_string();
- $request->base_string = $base_string;
- $key_parts = array($consumer->secret, (isset($token)) ? $token : "");
- $key_parts = array_map(array('OAuthUtil', 'urlencodeRFC3986'), $key_parts);
- $key = implode('&', $key_parts);
- return base64_encode(hash_hmac('sha1', $base_string, $key, true));
- }
-
+ */
+ function to_string()
+ {
+ return "oauth_token=" . OAuthUtil::urlencodeRFC3986($this->key) . "&oauth_token_secret=" . OAuthUtil::urlencodeRFC3986($this->secret);
+ }
+
+ function __toString()
+ {
+ return $this->to_string();
+ }
+}
+
+class OAuthSignatureMethod {
+
+ public function check_signature(&$request, $consumer, $token, $signature)
+ {
+ $built = $this->build_signature($request, $consumer, $token);
+ return $built == $signature;
+ }
+}
+
+class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod {
+
+ function get_name()
+ {
+ return "HMAC-SHA1";
+ }
+
+ public function build_signature($request, $consumer, $token)
+ {
+ $base_string = $request->get_signature_base_string();
+ $request->base_string = $base_string;
+ $key_parts = array($consumer->secret, (isset($token)) ? $token : "");
+ $key_parts = array_map(array('OAuthUtil', 'urlencodeRFC3986'), $key_parts);
+ $key = implode('&', $key_parts);
+ return base64_encode(hash_hmac('sha1', $base_string, $key, true));
+ }
+
//TODO: Double check this!
- public function check_signature(&$request, $consumer, $token, $signature)
- {
- $sign = $this->build_signature($request, $consumer, $token);
- return $sign == $signature;
- }
-}
-
-class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod {
-
- public function get_name()
- {
- return "PLAINTEXT";
- }
-
- public function build_signature($request, $consumer, $token)
- {
- $sig = array(OAuthUtil::urlencodeRFC3986($consumer->secret));
- if ($token) {
- array_push($sig, OAuthUtil::urlencodeRFC3986($token->secret));
- } else {
- array_push($sig, '');
- }
- $raw = implode("&", $sig);
+ public function check_signature(&$request, $consumer, $token, $signature)
+ {
+ $sign = $this->build_signature($request, $consumer, $token);
+ return $sign == $signature;
+ }
+}
+
+class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod {
+
+ public function get_name()
+ {
+ return "PLAINTEXT";
+ }
+
+ public function build_signature($request, $consumer, $token)
+ {
+ $sig = array(OAuthUtil::urlencodeRFC3986($consumer->secret));
+ if ($token) {
+ array_push($sig, OAuthUtil::urlencodeRFC3986($token->secret));
+ } else {
+ array_push($sig, '');
+ }
+ $raw = implode("&", $sig);
// for debug purposes
- $request->base_string = $raw;
- return OAuthUtil::urlencodeRFC3986($raw);
- }
-
+ $request->base_string = $raw;
+ return OAuthUtil::urlencodeRFC3986($raw);
+ }
+
//TODO: Double check this!
- public function check_signature(&$request, $consumer, $token, $signature)
- {
- $raw = OAuthUtil::urldecodeRFC3986($request->base_string);
- $sig = explode("&", $raw);
- array_pop($sig);
- $secret = array(OAuthUtil::urldecodeRFC3986($consumer->secret));
- return $sig == $secret;
- }
-}
-
-class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod {
- public static $PRIVATE_KEY = "RSA-SHA1.PrivateKey";
-
- public function get_name()
- {
- return "RSA-SHA1";
- }
-
- protected function fetch_public_cert(&$request)
- {
+ public function check_signature(&$request, $consumer, $token, $signature)
+ {
+ $raw = OAuthUtil::urldecodeRFC3986($request->base_string);
+ $sig = explode("&", $raw);
+ array_pop($sig);
+ $secret = array(OAuthUtil::urldecodeRFC3986($consumer->secret));
+ return $sig == $secret;
+ }
+}
+
+class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod {
+ public static $PRIVATE_KEY = "RSA-SHA1.PrivateKey";
+
+ public function get_name()
+ {
+ return "RSA-SHA1";
+ }
+
+ protected function fetch_public_cert(&$request)
+ {
// not implemented yet, ideas are:
// (1) do a lookup in a table of trusted certs keyed off of consumer
// (2) fetch via http using a url provided by the requester
// (3) some sort of specific discovery code based on request
//
// either way should return a string representation of the certificate
- throw Exception("fetch_public_cert not implemented");
- }
-
- protected function fetch_private_cert(&$request)
- {
+ throw Exception("fetch_public_cert not implemented");
+ }
+
+ protected function fetch_private_cert(&$request)
+ {
// not implemented yet, ideas are:
// (1) do a lookup in a table of trusted certs keyed off of consumer
//
// either way should return a string representation of the certificate
- throw new Exception("fetch_private_cert not implemented");
- }
-
- public function build_signature(&$request, OAuthConsumer $consumer, $token)
- {
- $base_string = $request->get_signature_base_string();
+ throw new Exception("fetch_private_cert not implemented");
+ }
+
+ public function build_signature(&$request, OAuthConsumer $consumer, $token)
+ {
+ $base_string = $request->get_signature_base_string();
// Fetch the private key cert based on the request
- $cert = $consumer->getProperty(OAuthSignatureMethod_RSA_SHA1::$PRIVATE_KEY);
+ $cert = $consumer->getProperty(OAuthSignatureMethod_RSA_SHA1::$PRIVATE_KEY);
// Pull the private key ID from the certificate
//FIXME this function seems to be called both for a oauth.json action where
// there is no phrase required, but for signed requests too, which do require it
// this is a dirty hack to make it work .. kinda
- if (! $privatekeyid = @openssl_pkey_get_private($cert)) {
- if (! $privatekeyid = @openssl_pkey_get_private($cert, Config::get('private_key_phrase') != '' ? (Config::get('private_key_phrase')) : null)) {
- throw new Exception("Could not load private key");
- }
- }
+ if (! $privatekeyid = @openssl_pkey_get_private($cert)) {
+ if (! $privatekeyid = @openssl_pkey_get_private($cert, Config::get('private_key_phrase') != '' ? (Config::get('private_key_phrase')) : null)) {
+ throw new Exception("Could not load private key");
+ }
+ }
// Sign using the key
- $signature = '';
- if (($ok = openssl_sign($base_string, $signature, $privatekeyid)) === false) {
- throw new OAuthException("Could not create signature");
- }
+ $signature = '';
+ if (($ok = openssl_sign($base_string, $signature, $privatekeyid)) === false) {
+ throw new OAuthException("Could not create signature");
+ }
// Release the key resource
- @openssl_free_key($privatekeyid);
- return base64_encode($signature);
- }
-
- public function check_signature(&$request, $consumer, $token, $signature)
- {
- $decoded_sig = base64_decode($signature);
- $base_string = $request->get_signature_base_string();
+ @openssl_free_key($privatekeyid);
+ return base64_encode($signature);
+ }
+
+ public function check_signature(&$request, $consumer, $token, $signature)
+ {
+ $decoded_sig = base64_decode($signature);
+ $base_string = $request->get_signature_base_string();
// Fetch the public key cert based on the request
- $cert = $this->fetch_public_cert($request);
+ $cert = $this->fetch_public_cert($request);
// Pull the public key ID from the certificate
- $publickeyid = openssl_get_publickey($cert);
+ $publickeyid = openssl_get_publickey($cert);
// Check the computed signature against the one passed in the query
- $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
+ $ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
// Release the key resource
- @openssl_free_key($publickeyid);
- return $ok == 1;
- }
-}
-
-class OAuthRequest {
- private $parameters;
- private $http_method;
- private $http_url;
- public $base_string;
- public static $version = '1.0';
-
- function __construct($http_method, $http_url, $parameters = NULL)
- {
- @$parameters or $parameters = array();
- $this->parameters = $parameters;
- $this->http_method = $http_method;
- $this->http_url = $http_url;
- }
-
+ @openssl_free_key($publickeyid);
+ return $ok == 1;
+ }
+}
+
+class OAuthRequest {
+ private $parameters;
+ private $http_method;
+ private $http_url;
+ public $base_string;
+ public static $version = '1.0';
+
+ function __construct($http_method, $http_url, $parameters = NULL)
+ {
+ @$parameters or $parameters = array();
+ $this->parameters = $parameters;
+ $this->http_method = $http_method;
+ $this->http_url = $http_url;
+ }
+
/**
* attempt to build up a request from what was passed to the server
- */
- public static function from_request($http_method = NULL, $http_url = NULL, $parameters = NULL)
- {
- $scheme = (! isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https';
- @$http_url or $http_url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
- @$http_method or $http_method = $_SERVER['REQUEST_METHOD'];
- $request_headers = OAuthRequest::get_headers();
+ */
+ public static function from_request($http_method = NULL, $http_url = NULL, $parameters = NULL)
+ {
+ $scheme = (! isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https';
+ @$http_url or $http_url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+ @$http_method or $http_method = $_SERVER['REQUEST_METHOD'];
+ $request_headers = OAuthRequest::get_headers();
// let the library user override things however they'd like, if they know
// which parameters to use then go for it, for example XMLRPC might want to
// do this
- if ($parameters) {
- $req = new OAuthRequest($http_method, $http_url, $parameters);
- } elseif (@substr($request_headers['Authorization'], 0, 5) == "OAuth") {
+ if ($parameters) {
+ $req = new OAuthRequest($http_method, $http_url, $parameters);
+ } elseif (@substr($request_headers['Authorization'], 0, 5) == "OAuth") {
// next check for the auth header, we need to do some extra stuff
// if that is the case, namely suck in the parameters from GET or POST
// so that we can include them in the signature
- $header_parameters = OAuthRequest::split_header($request_headers['Authorization']);
- if ($http_method == "GET") {
- $req_parameters = $_GET;
- } else
- if ($http_method = "POST") {
- $req_parameters = $_POST;
- }
- $parameters = array_merge($header_parameters, $req_parameters);
- $req = new OAuthRequest($http_method, $http_url, $parameters);
- } elseif ($http_method == "GET") {
- $req = new OAuthRequest($http_method, $http_url, $_GET);
- } elseif ($http_method == "POST") {
- $req = new OAuthRequest($http_method, $http_url, $_POST);
- }
- return $req;
- }
-
+ $header_parameters = OAuthRequest::split_header($request_headers['Authorization']);
+ if ($http_method == "GET") {
+ $req_parameters = $_GET;
+ } else
+ if ($http_method = "POST") {
+ $req_parameters = $_POST;
+ }
+ $parameters = array_merge($header_parameters, $req_parameters);
+ $req = new OAuthRequest($http_method, $http_url, $parameters);
+ } elseif ($http_method == "GET") {
+ $req = new OAuthRequest($http_method, $http_url, $_GET);
+ } elseif ($http_method == "POST") {
+ $req = new OAuthRequest($http_method, $http_url, $_POST);
+ }
+ return $req;
+ }
+
/**
* pretty much a helper function to set up the request
- */
- public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL)
- {
- $parameters = is_array($parameters) ? $parameters : array();
- $defaults = array("oauth_nonce" => OAuthRequest::generate_nonce(),
- "oauth_timestamp" => OAuthRequest::generate_timestamp(),
- "oauth_consumer_key" => $consumer->key);
- $parameters = array_merge($defaults, $parameters);
- if (isset($token)) {
- $parameters['oauth_token'] = $token;
- }
- return new OAuthRequest($http_method, $http_url, $parameters);
- }
-
- public function set_parameter($name, $value)
- {
- $this->parameters[$name] = $value;
- }
-
- public function get_parameter($name)
- {
- return @$this->parameters[$name];
- }
-
- public function get_parameters()
- {
- return $this->parameters;
- }
-
- public function set_parameters($params)
- {
- return $this->parameters = $params;
- }
-
+ */
+ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL)
+ {
+ $parameters = is_array($parameters) ? $parameters : array();
+ $defaults = array("oauth_nonce" => OAuthRequest::generate_nonce(),
+ "oauth_timestamp" => OAuthRequest::generate_timestamp(),
+ "oauth_consumer_key" => $consumer->key);
+ $parameters = array_merge($defaults, $parameters);
+ if (isset($token)) {
+ $parameters['oauth_token'] = $token;
+ }
+ return new OAuthRequest($http_method, $http_url, $parameters);
+ }
+
+ public function set_parameter($name, $value)
+ {
+ $this->parameters[$name] = $value;
+ }
+
+ public function get_parameter($name)
+ {
+ return @$this->parameters[$name];
+ }
+
+ public function get_parameters()
+ {
+ return $this->parameters;
+ }
+
+ public function set_parameters($params)
+ {
+ return $this->parameters = $params;
+ }
+
//TODO double check if hash can be used
- public function requireParameters($names)
- {
- $present = $this->parameters;
- $absent = array();
- foreach ($names as $required) {
- if (! in_array($required, $present)) {
- $absent[] = $required;
- }
- }
- if (count($absent) == 0) {
- throw new OAuthProblemException("oauth_parameters_absent: " . OAuthUtil::urlencodeRFC3986($absent));
- }
- }
-
+ public function requireParameters($names)
+ {
+ $present = $this->parameters;
+ $absent = array();
+ foreach ($names as $required) {
+ if (! in_array($required, $present)) {
+ $absent[] = $required;
+ }
+ }
+ if (count($absent) == 0) {
+ throw new OAuthProblemException("oauth_parameters_absent: " . OAuthUtil::urlencodeRFC3986($absent));
+ }
+ }
+
/**
* Returns the normalized parameters of the request
*
@@ -346,307 +346,307 @@
* concated by &.
*
* @return string
- */
- public function get_signable_parameters()
- {
+ */
+ public function get_signable_parameters()
+ {
// Grab all parameters
- $params = $this->parameters;
+ $params = $this->parameters;
// Remove oauth_signature if present
- if (isset($params['oauth_signature'])) {
- unset($params['oauth_signature']);
- }
+ if (isset($params['oauth_signature'])) {
+ unset($params['oauth_signature']);
+ }
// Urlencode both keys and values
- $keys = array_map(array('OAuthUtil', 'urlencodeRFC3986'), array_keys($params));
- $values = array_map(array('OAuthUtil', 'urlencodeRFC3986'), array_values($params));
- $params = array_combine($keys, $values);
+ $keys = array_map(array('OAuthUtil', 'urlencodeRFC3986'), array_keys($params));
+ $values = array_map(array('OAuthUtil', 'urlencodeRFC3986'), array_values($params));
+ $params = array_combine($keys, $values);
// Sort by keys (natsort)
- uksort($params, 'strnatcmp');
+ uksort($params, 'strnatcmp');
// Generate key=value pairs
- $pairs = array();
- foreach ($params as $key => $value) {
- if (is_array($value)) {
+ $pairs = array();
+ foreach ($params as $key => $value) {
+ if (is_array($value)) {
// If the value is an array, it's because there are multiple
// with the same key, sort them, then add all the pairs
- natsort($value);
- foreach ($value as $v2) {
- $pairs[] = $key . '=' . $v2;
- }
- } else {
- $pairs[] = $key . '=' . $value;
- }
- }
+ natsort($value);
+ foreach ($value as $v2) {
+ $pairs[] = $key . '=' . $v2;
+ }
+ } else {
+ $pairs[] = $key . '=' . $value;
+ }
+ }
// Return the pairs, concated with &
- return implode('&', $pairs);
- }
-
+ return implode('&', $pairs);
+ }
+
/**
* Returns the base string of this request
*
* The base string defined as the method, the url
* and the parameters (normalized), each urlencoded
* and the concated with &.
- */
- public function get_signature_base_string()
- {
- $tmp = $this->parameters;
- $parts = parse_url($this->http_url);
- parse_str(@$parts['query'], $params);
- foreach ($params as $key => $value) {
- if ($key == "signOwner" || $key == "signViewer") {
- continue;
- }
- $this->parameters[$key] = $value;
- }
- $parts = array($this->get_normalized_http_method(), $this->get_normalized_http_url(),
- $this->get_signable_parameters());
- $parts = array_map(array('OAuthUtil', 'urlencodeRFC3986'), $parts);
- $this->parameters = $tmp;
- return implode('&', $parts);
- }
-
+ */
+ public function get_signature_base_string()
+ {
+ $tmp = $this->parameters;
+ $parts = parse_url($this->http_url);
+ parse_str(@$parts['query'], $params);
+ foreach ($params as $key => $value) {
+ if ($key == "signOwner" || $key == "signViewer") {
+ continue;
+ }
+ $this->parameters[$key] = $value;
+ }
+ $parts = array($this->get_normalized_http_method(), $this->get_normalized_http_url(),
+ $this->get_signable_parameters());
+ $parts = array_map(array('OAuthUtil', 'urlencodeRFC3986'), $parts);
+ $this->parameters = $tmp;
+ return implode('&', $parts);
+ }
+
/**
* just uppercases the http method
- */
- public function get_normalized_http_method()
- {
- return strtoupper($this->http_method);
- }
-
+ */
+ public function get_normalized_http_method()
+ {
+ return strtoupper($this->http_method);
+ }
+
/**
* parses the url and rebuilds it to be
* scheme://host/path
- */
- public function get_normalized_http_url()
- {
- $parts = parse_url($this->http_url);
+ */
+ public function get_normalized_http_url()
+ {
+ $parts = parse_url($this->http_url);
// FIXME: port should handle according to http://groups.google.com/group/oauth/browse_thread/thread/1b203a51d9590226
- $port = (isset($parts['port']) && $parts['port'] != '80') ? ':' . $parts['port'] : '';
- $path = (isset($parts['path'])) ? $parts['path'] : '';
-
- return $parts['scheme'] . '://' . $parts['host'] . $port . $path;
- }
-
+ $port = (isset($parts['port']) && $parts['port'] != '80') ? ':' . $parts['port'] : '';
+ $path = (isset($parts['path'])) ? $parts['path'] : '';
+
+ return $parts['scheme'] . '://' . $parts['host'] . $port . $path;
+ }
+
/**
* builds a url usable for a GET request
- */
- public function to_url()
- {
- $out = $this->get_normalized_http_url() . "?";
- $out .= $this->to_postdata();
- $parts = parse_url($this->http_url);
- $out .= "&" . @$parts['query'];
- return $out;
- }
-
- public function get_url()
- {
- return $this->http_url;
- }
-
+ */
+ public function to_url()
+ {
+ $out = $this->get_normalized_http_url() . "?";
+ $out .= $this->to_postdata();
+ $parts = parse_url($this->http_url);
+ $out .= "&" . @$parts['query'];
+ return $out;
+ }
+
+ public function get_url()
+ {
+ return $this->http_url;
+ }
+
/**
* builds the data one would send in a POST request
- */
- public function to_postdata()
- {
- $total = array();
- foreach ($this->parameters as $k => $v) {
- $total[] = OAuthUtil::urlencodeRFC3986($k) . "=" . OAuthUtil::urlencodeRFC3986($v);
- }
- $out = implode("&", $total);
- return $out;
- }
-
+ */
+ public function to_postdata()
+ {
+ $total = array();
+ foreach ($this->parameters as $k => $v) {
+ $total[] = OAuthUtil::urlencodeRFC3986($k) . "=" . OAuthUtil::urlencodeRFC3986($v);
+ }
+ $out = implode("&", $total);
+ return $out;
+ }
+
/**
* builds the Authorization: header
- */
- public function to_header()
- {
- $out = '"Authorization: OAuth realm="",';
- foreach ($this->parameters as $k => $v) {
- if (substr($k, 0, 5) != "oauth")
- continue;
- $out .= ',' . OAuthUtil::urlencodeRFC3986($k) . '="' . OAuthUtil::urlencodeRFC3986($v) . '"';
- }
- return $out;
- }
-
- public function __toString()
- {
- return $this->to_url();
- }
-
- public function sign_request($signature_method, $consumer, $token)
- {
- $this->set_parameter("oauth_signature_method", $signature_method->get_name());
- $signature = $this->build_signature($signature_method, $consumer, $token);
- $this->set_parameter("oauth_signature", $signature);
- }
-
- public function build_signature($signature_method, $consumer, $token)
- {
- $signature = $signature_method->build_signature($this, $consumer, $token);
- return $signature;
- }
-
+ */
+ public function to_header()
+ {
+ $out = '"Authorization: OAuth realm="",';
+ foreach ($this->parameters as $k => $v) {
+ if (substr($k, 0, 5) != "oauth")
+ continue;
+ $out .= ',' . OAuthUtil::urlencodeRFC3986($k) . '="' . OAuthUtil::urlencodeRFC3986($v) . '"';
+ }
+ return $out;
+ }
+
+ public function __toString()
+ {
+ return $this->to_url();
+ }
+
+ public function sign_request($signature_method, $consumer, $token)
+ {
+ $this->set_parameter("oauth_signature_method", $signature_method->get_name());
+ $signature = $this->build_signature($signature_method, $consumer, $token);
+ $this->set_parameter("oauth_signature", $signature);
+ }
+
+ public function build_signature($signature_method, $consumer, $token)
+ {
+ $signature = $signature_method->build_signature($this, $consumer, $token);
+ return $signature;
+ }
+
/**
* util function: current timestamp
- */
- private static function generate_timestamp()
- {
- return time();
- }
-
+ */
+ private static function generate_timestamp()
+ {
+ return time();
+ }
+
/**
* util function: current nonce
- */
- public static function generate_nonce()
- {
- $mt = microtime();
- $rand = mt_rand();
+ */
+ public static function generate_nonce()
+ {
+ $mt = microtime();
+ $rand = mt_rand();
return md5($mt . $rand); // md5s look nicer than numbers
- }
-
+ }
+
/**
* util function for turning the Authorization: header into
* parameters, has to do some unescaping
- */
- private static function split_header($header)
- {
+ */
+ private static function split_header($header)
+ {
// this should be a regex
// error cases: commas in parameter values
- $parts = explode(",", $header);
- $out = array();
- foreach ($parts as $param) {
- $param = ltrim($param);
+ $parts = explode(",", $header);
+ $out = array();
+ foreach ($parts as $param) {
+ $param = ltrim($param);
// skip the "realm" param, nobody ever uses it anyway
- if (substr($param, 0, 5) != "oauth")
- continue;
- $param_parts = explode("=", $param);
+ if (substr($param, 0, 5) != "oauth")
+ continue;
+ $param_parts = explode("=", $param);
// rawurldecode() used because urldecode() will turn a "+" in the
// value into a space
- $out[$param_parts[0]] = rawurldecode(substr($param_parts[1], 1, - 1));
- }
- return $out;
- }
-
+ $out[$param_parts[0]] = rawurldecode(substr($param_parts[1], 1, - 1));
+ }
+ return $out;
+ }
+
/**
* helper to try to sort out headers for people who aren't running apache
- */
- private static function get_headers()
- {
- if (function_exists('apache_request_headers')) {
+ */
+ private static function get_headers()
+ {
+ if (function_exists('apache_request_headers')) {
// we need this to get the actual Authorization: header
// because apache tends to tell us it doesn't exist
- return apache_request_headers();
- }
+ return apache_request_headers();
+ }
// otherwise we don't have apache and are just going to have to hope
// that $_SERVER actually contains what we need
- $out = array();
- foreach ($_SERVER as $key => $value) {
- if (substr($key, 0, 5) == "HTTP_") {
+ $out = array();
+ foreach ($_SERVER as $key => $value) {
+ if (substr($key, 0, 5) == "HTTP_") {
// this is chaos, basically it is just there to capitalize the first
// letter of every word that is not an initial HTTP and strip HTTP
// code from przemek
- $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
- $out[$key] = $value;
- }
- }
- return $out;
- }
-}
-
-class OAuthUtil {
-
- public static $AUTH_SCHEME = "OAuth";
- private static $AUTHORIZATION = "\ *[a-zA-Z0-9*]\ +(.*)";
- private static $NVP = "(\\S*)\\s*\\=\\s*\"([^\"]*)\"";
-
- public static function getPostBodyString(Array $params)
- {
- $result = '';
- $first = true;
- foreach ($params as $key => $val) {
- if ($first) {
- $first = false;
- } else {
- $result .= '&';
- }
- $result .= OAuthUtil::urlencodeRFC3986($key) . "=" . OAuthUtil::urlencodeRFC3986($val);
- }
- return $result;
- }
-
- public static function urlencodeRFC3986($string)
- {
- return str_replace('%7E', '~', rawurlencode($string));
- }
-
- public static function urldecodeRFC3986($string)
- {
- return rawurldecode($string);
- }
-
- /** Return true if the given Content-Type header means FORM_ENCODED. */
- public static function isFormEncoded($contentType)
- {
- if (! isset($contentType)) {
- return false;
- }
- $semi = strpos($contentType, ";");
- if ($semi >= 0) {
- $contentType = substr($contentType, 0, $semi);
- }
- return strtolower(OAuth::$FORM_ENCODED) == strtolower(trim($contentType));
- }
-
- public static function addParameters($url, $oauthParams)
- {
- $url .= strchr($url, '?') === false ? '?' : '&';
- foreach ($oauthParams as $key => $value) {
- $url .= "$key=$value&";
- }
- return $url;
- }
-
- public static function decodeForm($form)
- {
- $parameters = array();
- $explodedForm = explode("&", $form);
- foreach ($explodedForm as $params) {
- $value = explode("=", $params);
- if (! empty($value[0]) && ! empty($value[1])) {
- $parameters[OAuthUtil::urldecodeRFC3986($value[0])] = OAuthUtil::urldecodeRFC3986($value[1]);
- }
- }
- return $parameters;
- }
-
+ $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
+ $out[$key] = $value;
+ }
+ }
+ return $out;
+ }
+}
+
+class OAuthUtil {
+
+ public static $AUTH_SCHEME = "OAuth";
+ private static $AUTHORIZATION = "\ *[a-zA-Z0-9*]\ +(.*)";
+ private static $NVP = "(\\S*)\\s*\\=\\s*\"([^\"]*)\"";
+
+ public static function getPostBodyString(Array $params)
+ {
+ $result = '';
+ $first = true;
+ foreach ($params as $key => $val) {
+ if ($first) {
+ $first = false;
+ } else {
+ $result .= '&';
+ }
+ $result .= OAuthUtil::urlencodeRFC3986($key) . "=" . OAuthUtil::urlencodeRFC3986($val);
+ }
+ return $result;
+ }
+
+ public static function urlencodeRFC3986($string)
+ {
+ return str_replace('%7E', '~', rawurlencode($string));
+ }
+
+ public static function urldecodeRFC3986($string)
+ {
+ return rawurldecode($string);
+ }
+
+ /** Return true if the given Content-Type header means FORM_ENCODED. */
+ public static function isFormEncoded($contentType)
+ {
+ if (! isset($contentType)) {
+ return false;
+ }
+ $semi = strpos($contentType, ";");
+ if ($semi >= 0) {
+ $contentType = substr($contentType, 0, $semi);
+ }
+ return strtolower(OAuth::$FORM_ENCODED) == strtolower(trim($contentType));
+ }
+
+ public static function addParameters($url, $oauthParams)
+ {
+ $url .= strchr($url, '?') === false ? '?' : '&';
+ foreach ($oauthParams as $key => $value) {
+ $url .= "$key=$value&";
+ }
+ return $url;
+ }
+
+ public static function decodeForm($form)
+ {
+ $parameters = array();
+ $explodedForm = explode("&", $form);
+ foreach ($explodedForm as $params) {
+ $value = explode("=", $params);
+ if (! empty($value[0]) && ! empty($value[1])) {
+ $parameters[OAuthUtil::urldecodeRFC3986($value[0])] = OAuthUtil::urldecodeRFC3986($value[1]);
+ }
+ }
+ return $parameters;
+ }
+
/**
* Parse the parameters from an OAuth Authorization or WWW-Authenticate
* header. The realm is included as a parameter. If the given header doesn't
* start with "OAuth ", return an empty list.
- */
- public static function decodeAuthorization($authorization)
- {
- $into = array();
- if ($authorization != null) {
- $m = ereg(self::$AUTHORIZATION, $authorization);
- if ($m !== false) {
- if (strpos($authorization, OAuthUtil::$AUTH_SCHEME) == 0) {
- $authorization = str_replace("OAuth ", "", $authorization);
- $authParams = explode(", ", $authorization);
- foreach ($authParams as $params) {
- $m = ereg(OAuthUtil::$NVP, $params);
- if ($m == 1) {
- $keyValue = explode("=", $params);
- $name = OAuthUtil::urlencodeRFC3986($keyValue[0]);
- $value = OAuthUtil::urlencodeRFC3986(str_replace("\"", "", $keyValue[1]));
- $into[$name] = $value;
- }
- }
- }
- }
- }
- return $into;
- }
+ */
+ public static function decodeAuthorization($authorization)
+ {
+ $into = array();
+ if ($authorization != null) {
+ $m = ereg(self::$AUTHORIZATION, $authorization);
+ if ($m !== false) {
+ if (strpos($authorization, OAuthUtil::$AUTH_SCHEME) == 0) {
+ $authorization = str_replace("OAuth ", "", $authorization);
+ $authParams = explode(", ", $authorization);
+ foreach ($authParams as $params) {
+ $m = ereg(OAuthUtil::$NVP, $params);
+ if ($m == 1) {
+ $keyValue = explode("=", $params);
+ $name = OAuthUtil::urlencodeRFC3986($keyValue[0]);
+ $value = OAuthUtil::urlencodeRFC3986(str_replace("\"", "", $keyValue[1]));
+ $into[$name] = $value;
+ }
+ }
+ }
+ }
+ }
+ return $into;
+ }
}
Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthAccessor.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthAccessor.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthAccessor.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthAccessor.php Mon Aug 4 15:12:56 2008
@@ -58,11 +58,12 @@
$signatureMethod = null;
if ($parameters[OAuth::$OAUTH_SIGNATURE_METHOD] == OAuth::$RSA_SHA1) {
$signatureMethod = new OAuthSignatureMethod_RSA_SHA1();
- } else if ($parameters[OAuth::$OAUTH_SIGNATURE_METHOD] == OAuth::$HMAC_SHA1) {
- $signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
- } else { //PLAINTEXT
- $signatureMethod = new OAuthSignatureMethod_PLAINTEXT();
- }
+ } else
+ if ($parameters[OAuth::$OAUTH_SIGNATURE_METHOD] == OAuth::$HMAC_SHA1) {
+ $signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
+ } else { //PLAINTEXT
+ $signatureMethod = new OAuthSignatureMethod_PLAINTEXT();
+ }
$message->sign_request($signatureMethod, $this->consumer, $this->tokenSecret);
return $message;
}
Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php Mon Aug 4 15:12:56 2008
@@ -137,8 +137,7 @@
if ($origClientState != null && strlen($origClientState) > 0) {
try {
$this->origClientState = $this->oauthCrypter->unwrap($origClientState, self::$CLIENT_STATE_MAX_AGE_SECS);
- } catch (BlobCrypterException $e) {
- // Probably too old, pretend we never saw it at all.
+ } catch (BlobCrypterException $e) { // Probably too old, pretend we never saw it at all.
}
}
if ($this->origClientState == null) {
@@ -159,12 +158,12 @@
$errorBuf = '';
$errorBuf .= $e->getMessage();
$errorBuf .= "\n\n";
- $this->errorText = $errorBuf;
+ $this->errorText = $errorBuf;
return $this->buildNonDataResponse();
}
private function buildNonDataResponse()
- {
+ {
return $this->addResponseMetadata();
}
@@ -209,17 +208,18 @@
// owner identity seems reasonable.
$tokenKey->setUserId($this->authToken->getOwnerId());
return $tokenKey;
- }
-
- public function fetch($request) {
- try {
- $this->lookupOAuthMetadata();
- } catch (Exception $e) {
- $this->error = OAuthError::$BAD_OAUTH_CONFIGURATION;
- return $this->buildErrorResponse($e);
- }
- $this->realRequest = $request;
- $response = $this->fetchRequest($request);
+ }
+
+ public function fetch($request)
+ {
+ try {
+ $this->lookupOAuthMetadata();
+ } catch (Exception $e) {
+ $this->error = OAuthError::$BAD_OAUTH_CONFIGURATION;
+ return $this->buildErrorResponse($e);
+ }
+ $this->realRequest = $request;
+ $response = $this->fetchRequest($request);
return $response;
}
@@ -269,7 +269,7 @@
* @throws GadgetException
*/
private function checkCanApprove()
- {
+ {
$pageOwner = $this->authToken->getOwnerId();
$pageViewer = $this->authToken->getViewerId();
$stateOwner = @$this->origClientState[self::$OWNER_KEY];
@@ -612,6 +612,6 @@
}
if ($this->errorText != null) {
$this->responseMetadata[self::$ERROR_TEXT] = $this->errorText;
- }
+ }
}
}
\ No newline at end of file
Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php Mon Aug 4 15:12:56 2008
@@ -48,13 +48,12 @@
{
try {
$BBC = new BasicBlobCrypter();
- $this->oauthCrypter = new BasicBlobCrypter(srand($BBC->MASTER_KEY_MIN_LEN));
+ $this->oauthCrypter = new BasicBlobCrypter(srand($BBC->MASTER_KEY_MIN_LEN));
$specFactory = new BasicGadgetSpecFactory($fetcher);
$basicStore = new BasicGadgetOAuthTokenStore(new BasicOAuthStore(), $specFactory);
$basicStore->initFromConfigFile($fetcher);
$this->tokenStore = $basicStore;
- } catch (Exeption $e) {
- }
+ } catch (Exeption $e) {}
}
/**
Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthRequestParams.php Mon Aug 4 15:12:56 2008
@@ -73,10 +73,10 @@
}
public static function parseBypassSpecCacheParam()
- {
- if (isset($_REQUEST[self::$BYPASS_SPEC_CACHE_PARAM])) {
- return "1" == $_REQUEST[self::$BYPASS_SPEC_CACHE_PARAM];
- }
+ {
+ if (isset($_REQUEST[self::$BYPASS_SPEC_CACHE_PARAM])) {
+ return "1" == $_REQUEST[self::$BYPASS_SPEC_CACHE_PARAM];
+ }
return false;
}
Modified: incubator/shindig/trunk/php/src/social-api/ResponseItem.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/ResponseItem.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/ResponseItem.php (original)
+++ incubator/shindig/trunk/php/src/social-api/ResponseItem.php Mon Aug 4 15:12:56 2008
@@ -37,7 +37,7 @@
unset($this->errorMessage);
}
}
-
+
/**
* the json_encode function does not trim null values,
* so we do this manually
@@ -67,7 +67,7 @@
}
return $object;
}
-
+
public function getError()
{
return isset($this->error) ? $this->error : null;
Modified: incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php (original)
+++ incubator/shindig/trunk/php/src/social-api/converters/InputAtomConverter.php Mon Aug 4 15:12:56 2008
@@ -31,23 +31,23 @@
{
$activity = array();
$xml = simplexml_load_string($requestParam, 'SimpleXMLElement', LIBXML_NOCDATA);
- if (!isset($xml->title)) {
+ if (! isset($xml->title)) {
throw new Exception("Mallformed activity xml");
}
// remember to either type cast to (string) or trim() the string so we don't get
// SimpleXMLString types in the internal data representation. I often prefer
// using trim() since it cleans up the data too
- $activity['id'] = isset($xml->id) ? trim($xml->id) : '';
+ $activity['id'] = isset($xml->id) ? trim($xml->id) : '';
$activity['title'] = trim($xml->title);
- $activity['body'] = isset($xml->summary) ? trim($xml->summary) : '';
- $activity['streamTitle'] = isset($xml->content->activity->streamTitle) ? trim($xml->content->activity->streamTitle) : '';
- $activity['streamId'] = isset($xml->content->activity->streamId) ? trim($xml->content->activity->streamId) : '';
- $activity['updated'] = isset($xml->updated) ? trim($xml->updated) : '';
+ $activity['body'] = isset($xml->summary) ? trim($xml->summary) : '';
+ $activity['streamTitle'] = isset($xml->content->activity->streamTitle) ? trim($xml->content->activity->streamTitle) : '';
+ $activity['streamId'] = isset($xml->content->activity->streamId) ? trim($xml->content->activity->streamId) : '';
+ $activity['updated'] = isset($xml->updated) ? trim($xml->updated) : '';
if (isset($xml->content->activity->mediaItems)) {
$activity['mediaItems'] = array();
foreach ($xml->content->activity->mediaItems->MediaItem as $mediaItem) {
$item = array();
- if (!isset($mediaItem->type) || !isset($mediaItem->mimeType) || !isset($mediaItem->url)) {
+ if (! isset($mediaItem->type) || ! isset($mediaItem->mimeType) || ! isset($mediaItem->url)) {
throw new Exception("Invalid media item in activity xml");
}
$item['type'] = trim($mediaItem->type);
@@ -62,7 +62,7 @@
public function convertAppData($requestParam)
{
$xml = simplexml_load_string($requestParam, 'SimpleXMLElement', LIBXML_NOCDATA);
- if (!isset($xml->content) || !isset($xml->content->appdata)) {
+ if (! isset($xml->content) || ! isset($xml->content->appdata)) {
throw new Exception("Mallformed AppData xml");
}
$data = array();
@@ -71,20 +71,20 @@
}
return $data;
}
-
+
public function convertMessages($requestParam)
{
$xml = simplexml_load_string($requestParam, 'SimpleXMLElement', LIBXML_NOCDATA);
$message = array();
- if (!isset($xml->title) || !isset($xml->content)) {
+ if (! isset($xml->title) || ! isset($xml->content)) {
throw new Exception("Invalid message structure");
}
$message['id'] = isset($xml->id) ? trim($xml->id) : null;
$message['title'] = trim($xml->title);
$message['body'] = trim($xml->content);
// retrieve recipients by looking at the osapi name space
- $xml = simplexml_load_string($requestParam, 'SimpleXMLElement', LIBXML_NOCDATA, "http://opensocial.org/2008/opensocialapi");
- if (!isset($xml->recipient)) {
+ $xml = simplexml_load_string($requestParam, 'SimpleXMLElement', LIBXML_NOCDATA, "http://opensocial.org/2008/opensocialapi");
+ if (! isset($xml->recipient)) {
throw new Exception("Invalid message structure");
}
$message['recipients'] = array();
Modified: incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php (original)
+++ incubator/shindig/trunk/php/src/social-api/converters/InputConverter.php Mon Aug 4 15:12:56 2008
@@ -25,8 +25,12 @@
* hoisting rules somewhere..
*/
abstract class InputConverter {
+
abstract public function convertPeople($requestParam);
+
abstract public function convertActivities($requestParam);
+
abstract public function convertAppData($requestParam);
+
abstract public function convertMessages($requestParam);
}
\ No newline at end of file
Modified: incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php (original)
+++ incubator/shindig/trunk/php/src/social-api/converters/OutputAtomConverter.php Mon Aug 4 15:12:56 2008
@@ -1,5 +1,4 @@
<?php
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -31,7 +30,8 @@
//FIXME osearch fields break the validator ... remove option once i know if they should be included or not
private static $includeOsearch = false;
// this maps the REST url to the atom content type
- private static $entryTypes = array('people' => 'person', 'appdata' => 'appdata', 'activities' => 'activity', 'messages' => 'messages');
+ private static $entryTypes = array('people' => 'person', 'appdata' => 'appdata',
+ 'activities' => 'activity', 'messages' => 'messages');
private $doc;
function outputResponse(ResponseItem $responseItem, RestRequestItem $requestItem)
@@ -62,7 +62,8 @@
$this->addNode($author, 'name', $authorName);
$this->addNode($entry, 'updated', $updatedAtom);
$this->addNode($entry, 'id', $guid);
- $this->addNode($entry, 'link', '', array('rel' => 'self', 'href' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
+ $this->addNode($entry, 'link', '', array('rel' => 'self',
+ 'href' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
// Add osearch & next link to the entry
$this->addPagingFields($entry, $startIndex, $itemsPerPage, $totalResults);
// Add response entries to feed
@@ -72,7 +73,8 @@
$idField = is_object($response) && isset($response->id) ? $response->id : (is_array($response) && isset($response['id']) ? $response['id'] : $requestItem->getUser()->getUserId($requestItem->getToken()));
// construct <entry> blocks this record
$feedEntry = $this->addNode($entry, 'entry');
- $content = $this->addNode($feedEntry, 'content', '', array('type' => 'application/xml'));
+ $content = $this->addNode($feedEntry, 'content', '', array(
+ 'type' => 'application/xml'));
// Author node
$author = $this->addNode($feedEntry, 'author');
$this->addNode($author, 'uri', $guid);
@@ -259,7 +261,7 @@
} else {
if (is_numeric($key)) {
$key = is_object($val) ? get_class($val) : $key = $name;
- }
+ }
$elm = $newElement->appendChild($this->doc->createElement($key));
$elm->appendChild($this->doc->createTextNode($val));
}
Modified: incubator/shindig/trunk/php/src/social-api/converters/OutputConverter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/OutputConverter.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/converters/OutputConverter.php (original)
+++ incubator/shindig/trunk/php/src/social-api/converters/OutputConverter.php Mon Aug 4 15:12:56 2008
@@ -23,26 +23,25 @@
*/
abstract class OutputConverter {
private $boundry;
-
+
abstract function outputResponse(ResponseItem $responseItem, RestRequestItem $requestItem);
+
abstract function outputBatch(Array $responses, SecurityToken $token);
-
+
/**
* Output the multipart/mixed headers and returns the boundry token used
*
*/
public function boundryHeaders()
{
- $this->boundry = '--batch-'.md5(rand(0,32000));
+ $this->boundry = '--batch-' . md5(rand(0, 32000));
header("HTTP/1.1 200 OK", true);
header("Content-Type: multipart/mixed; boundary=$this->boundry", true);
}
-
+
public function outputPart($part, $code)
{
- $boundryHeader = "{$this->boundry}\r\n".
- "Content-Type: application/http;version=1.1\r\n".
- "Content-Transfer-Encoding: binary\r\n\r\n";
+ $boundryHeader = "{$this->boundry}\r\n" . "Content-Type: application/http;version=1.1\r\n" . "Content-Transfer-Encoding: binary\r\n\r\n";
echo $boundryHeader;
switch ($code) {
case BAD_REQUEST:
@@ -66,6 +65,6 @@
break;
}
echo "$code\r\n\r\n";
- echo $part."\n";
+ echo $part . "\n";
}
}
Modified: incubator/shindig/trunk/php/src/social-api/converters/OutputJsonConverter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/converters/OutputJsonConverter.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/converters/OutputJsonConverter.php (original)
+++ incubator/shindig/trunk/php/src/social-api/converters/OutputJsonConverter.php Mon Aug 4 15:12:56 2008
@@ -22,12 +22,12 @@
*
*/
class OutputJsonConverter extends OutputConverter {
-
+
function outputResponse(ResponseItem $responseItem, RestRequestItem $requestItem)
{
echo json_encode($responseItem->getResponse());
}
-
+
function outputBatch(Array $responses, SecurityToken $token)
{
$this->boundryHeaders();
@@ -38,7 +38,7 @@
$this->outputPart($part, $response->getError());
}
}
-
+
function outputJsonBatch(Array $responses, SecurityToken $token)
{
echo json_encode(array("responses" => $responses, "error" => false));
Modified: incubator/shindig/trunk/php/src/social-api/dataservice/ActivitiesService.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/dataservice/ActivitiesService.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/dataservice/ActivitiesService.php (original)
+++ incubator/shindig/trunk/php/src/social-api/dataservice/ActivitiesService.php Mon Aug 4 15:12:56 2008
@@ -26,7 +26,7 @@
* @return a response item with the list of activities.
*/
abstract public function getActivities(UserId $userId, $groupId, $first, $max, SecurityToken $token);
-
+
abstract public function getActivity(UserId $userId, $groupId, $activityId, $first, $max, SecurityToken $token);
/**
Modified: incubator/shindig/trunk/php/src/social-api/dataservice/AppDataService.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/dataservice/AppDataService.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/dataservice/AppDataService.php (original)
+++ incubator/shindig/trunk/php/src/social-api/dataservice/AppDataService.php Mon Aug 4 15:12:56 2008
@@ -31,7 +31,7 @@
abstract public function getPersonData(UserId $userId, GroupId $groupId, $fields, $appId, SecurityToken $token);
abstract public function deletePersonData(UserId $userId, GroupId $groupId, $fields, $appId, SecurityToken $token);
-
+
/**
* Updates the data key for the given person with the new value.
*
Modified: incubator/shindig/trunk/php/src/social-api/dataservice/DataRequestHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social-api/dataservice/DataRequestHandler.php?rev=682527&r1=682526&r2=682527&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social-api/dataservice/DataRequestHandler.php (original)
+++ incubator/shindig/trunk/php/src/social-api/dataservice/DataRequestHandler.php Mon Aug 4 15:12:56 2008
@@ -26,7 +26,7 @@
if ($token->isAnonymous() && $method != 'GET') {
// Anonymous requests are only allowed to GET data (not create/edit/delete)
$response = new ResponseItem(BAD_REQUEST, "[$method] not allowed for anonymous users", null);
- } elseif ($method == 'GET') {
+ } elseif ($method == 'GET') {
$response = $this->handleGet($requestItem);
} elseif ($method == 'POST') {
$response = $this->handlePost($requestItem);
@@ -60,7 +60,10 @@
}
abstract public function handleDelete(RestRequestItem $requestItem);
+
abstract public function handleGet(RestRequestItem $requestItem);
+
abstract public function handlePost(RestRequestItem $requestItem);
+
abstract public function handlePut(RestRequestItem $requestItem);
}