Author: chabotc
Date: Fri Feb 6 14:12:36 2009
New Revision: 741570
URL: http://svn.apache.org/viewvc?rev=741570&view=rev
Log:
Final sync up with the trunk before unstable patches hit the trunk
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/common/BlobCrypter.php
incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetContext.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetServer.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetSpecParser.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/JsLibrary.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/UserPrefs.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/OAuthService.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/sample/BasicGadgetSpecFactory.php
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php
incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputAtomConverter.php
incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputXmlConverter.php
incubator/shindig/branches/1.0.x-incubating/php/src/social/oauth/OAuth.php
incubator/shindig/branches/1.0.x-incubating/php/src/social/sample/JsonDbOpensocialService.php
incubator/shindig/branches/1.0.x-incubating/php/src/social/service/ActivityHandler.php
incubator/shindig/branches/1.0.x-incubating/php/src/social/service/RequestItem.php
incubator/shindig/branches/1.0.x-incubating/php/src/social/servlet/DataServiceServlet.php
incubator/shindig/branches/1.0.x-incubating/php/src/social/spi/ActivityService.php
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/common/BlobCrypter.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/common/BlobCrypter.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
--- incubator/shindig/branches/1.0.x-incubating/php/src/common/BlobCrypter.php
(original)
+++ incubator/shindig/branches/1.0.x-incubating/php/src/common/BlobCrypter.php
Fri Feb 6 14:12:36 2009
@@ -19,34 +19,33 @@
*/
-class BlobCrypterException extends Exception {
-}
+class BlobCrypterException extends Exception { }
/**
* Utility interface for managing signed, encrypted, and time stamped blobs.
* Blobs are made up of name/value pairs. Time stamps are automatically
* included and checked.
- *
+ *
*/
abstract class BlobCrypter {
/**
* Time stamps, encrypts, and signs a blob.
- *
+ *
* @param in name/value pairs to encrypt
* @return a base64 encoded blob
- *
+ *
* @throws BlobCrypterException
*/
abstract public function wrap(Array $in);
/**
* Unwraps a blob.
- *
+ *
* @param in blob
* @param maxAgeSec maximum age for the blob
* @return the name/value pairs, including the origin timestamp.
- *
+ *
* @throws BlobExpiredException if the blob is too old to be accepted.
* @throws BlobCrypterException if the blob can't be decoded.
*/
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php
Fri Feb 6 14:12:36 2009
@@ -26,6 +26,8 @@
*/
class CacheMemcache extends Cache {
private $connection = false;
+ private $host;
+ private $port;
public function __construct() {
if (! function_exists('memcache_connect')) {
@@ -108,7 +110,7 @@
public function set($key, $value) {
$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(),
+ 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/branches/1.0.x-incubating/php/src/gadgets/GadgetContext.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetContext.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetContext.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetContext.php
Fri Feb 6 14:12:36 2009
@@ -46,7 +46,7 @@
public function __construct($renderingContext) {
// Rendering context is set by the calling event handler (either GADGET or
CONTAINER)
$this->setRenderingContext($renderingContext);
-
+
// Request variables
$this->setIgnoreCache($this->getIgnoreCacheParam());
$this->setForcedJsLibs($this->getFocedJsLibsParam());
@@ -133,17 +133,14 @@
return new $remoteContent();
}
- private function instanceCache() {
- $dataCache = Config::get('data_cache');
- return new $dataCache();
- }
-
private function instanceRegistry() {
// Profiling showed 40% of the processing time was spend in the feature
registry
// So by caching this and making it a one time initialization, we almost
double the performance
- if (! ($registry =
$this->getCache()->get(md5(Config::get('features_path'))))) {
+ $featureCache = Config::get('feature_cache');
+ $featureCache = new $featureCache();
+ if (! ($registry = $featureCache->get(md5(Config::get('features_path')))))
{
$registry = new GadgetFeatureRegistry(Config::get('features_path'));
- $this->getCache()->set(md5(Config::get('features_path')), $registry);
+ $featureCache->set(md5(Config::get('features_path')), $registry);
}
return $registry;
}
@@ -170,13 +167,6 @@
return $this->containerConfig;
}
- public function getCache() {
- if ($this->cache == null) {
- $this->setCache($this->instanceCache());
- }
- return $this->cache;
- }
-
public function getGadgetId() {
if ($this->gadgetId == null) {
$this->setGadgetId($this->instanceGadgetId($this->getUrl(),
$this->getModuleId()));
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetServer.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetServer.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetServer.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetServer.php
Fri Feb 6 14:12:36 2009
@@ -23,6 +23,7 @@
public function processGadget($context) {
$gadget = $this->specLoad($context);
$this->featuresLoad($gadget, $context);
+ $this->substitute($gadget, $context);
return $gadget;
}
@@ -45,8 +46,7 @@
$localeSpec = $this->localeSpec($gadget, $locale); // en-US
$language_allSpec = $this->localeSpec($gadget, new
Locale($locale->getLanguage(), "all")); // en-all
$all_allSpec = $this->localeSpec($gadget, new Locale("all", "all")); //
all-all
- $messagesArray = $this->getMessagesArrayForSpecs($context,
array($localeSpec, $language_allSpec,
- $all_allSpec));
+ $messagesArray = $this->getMessagesArrayForSpecs($context,
array($localeSpec, $language_allSpec, $all_allSpec));
if (count($messagesArray) == 0) {
return null;
}
@@ -81,7 +81,7 @@
// relative path's in the locale spec uri
$gadgetUrl = $context->getUrl();
$gadgetUrl = substr($gadgetUrl, 0, strrpos($gadgetUrl, '/') + 1);
- $uri = $gadgetUrl.$uri;
+ $uri = $gadgetUrl . $uri;
}
$requestArray[] = new RemoteContentRequest($uri);
$contextArray[] = $context;
@@ -113,7 +113,7 @@
return null;
}
- private function featuresLoad(Gadget $gadget, $context) {
+ private function substitute(Gadget $gadget, $context) {
//NOTE i've been a bit liberal here with folding code into this function,
while it did get a bit long, the many include()'s are slowing us down
// get the message bundle for this gadget
$bundle = $this->getBundle($context, $gadget);
@@ -137,6 +137,16 @@
$substitutor->addSubstitution('BIDI', "END_EDGE", $rtl ? "left" : "right");
$substitutor->addSubstitution('BIDI', "DIR", $rtl ? "rtl" : "ltr");
$substitutor->addSubstitution('BIDI', "REVERSE_DIR", $rtl ? "ltr" : "rtl");
+ foreach ($gadget->userPrefs as $pref) {
+ if (! empty($pref->displayName)) {
+ $pref->displayName =
$gadget->getSubstitutions()->substitute($pref->displayName);
+ }
+ if (is_array($pref->enumValues) && count($pref->enumValues)) {
+ foreach ($pref->enumValues as &$enum) {
+ $enum = $gadget->getSubstitutions()->substitute($enum);
+ }
+ }
+ }
// userPref's
$upValues = $gadget->getUserPrefValues();
foreach ($gadget->getUserPrefs() as $pref) {
@@ -151,6 +161,9 @@
$substitutor->addSubstitution('UP', $name, $value);
}
$this->substitutePreloads($gadget, $substitutor);
+ }
+
+ function featuresLoad(Gadget $gadget, $context) {
// Process required / desired features
$requires = $gadget->getRequires();
$needed = array();
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetSpecParser.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetSpecParser.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetSpecParser.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/GadgetSpecParser.php
Fri Feb 6 14:12:36 2009
@@ -54,8 +54,35 @@
foreach ($doc->UserPref as $pref) {
$this->processUserPref($gadget, $pref);
}
+ // Assume gadget v1
+ $explicit_profile = false;
foreach ($doc->Content as $content) {
- $this->processContent($gadget, $content);
+ $attributes = $content->attributes();
+ if (empty($attributes['type'])) {
+ throw new SpecParserException("No content type specified!");
+ }
+ $view = isset($attributes['view']) ? trim($attributes['view']) : '';
+ // Note if we find a profile explicity defined
+ if (strpos($view, "profile") !== false) {
+ $explicit_profile = true;
+ }
+ }
+ foreach ($doc->Content as $content) {
+ $attributes = $content->attributes();
+ if (empty($attributes['type'])) {
+ throw new SpecParserException("No content type specified!");
+ }
+ $view = isset($attributes['view']) ? trim($attributes['view']) : '';
+ // If view isnt defined and we didnt find a profile explicity defined
+ if ($view == '') {
+ if (! $explicit_profile) {
+ $this->processContent($gadget, $content, array(0 => DEFAULT_VIEW));
+ }
+ // If view isnt defined and a profile was found, this will catch it
+ } else {
+ $views = explode(',', $view);
+ $this->processContent($gadget, $content, $views);
+ }
}
foreach ($doc->ModulePrefs->Preload as $feature) {
$gadget->preloads[] = new Preload($feature);
@@ -166,18 +193,9 @@
$gadget->userPrefs[] = $preference;
}
- private function processContent(&$gadget, $content) {
- $attributes = $content->attributes();
- if (empty($attributes['type'])) {
- throw new SpecParserException("No content type specified!");
- }
- $view = isset($attributes['view']) ? trim($attributes['view']) : '';
- $views = explode(',', $view);
+ private function processContent(&$gadget, $content, $views) {
$html = (string)$content; // no trim here since empty lines can have
structural meaning, so typecast to string instead
foreach ($views as $view) {
- if (empty($view)) {
- $view = DEFAULT_VIEW;
- }
$viewSpec = new ViewSpec($view, $content);
if (! isset($gadget->views[$view])) {
$viewSpec->content = $html;
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/JsLibrary.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/JsLibrary.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
--- incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/JsLibrary.php
(original)
+++ incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/JsLibrary.php
Fri Feb 6 14:12:36 2009
@@ -38,11 +38,11 @@
public function getContent() {
if (! $this->loaded && $this->type == 'FILE') {
if (Config::get('compress_javascript')) {
- $dataCache = Config::get('data_cache');
- $dataCache = new $dataCache();
- if (! ($content = $dataCache->get(md5($this->content)))) {
+ $featureCache = Config::get('feature_cache');
+ $featureCache = new $featureCache();
+ if (! ($content = $featureCache->get(md5($this->content)))) {
$content = JsMin::minify(JsLibrary::loadData($this->content,
$this->type));
- $dataCache->set(md5($this->content), $content);
+ $featureCache->set(md5($this->content), $content);
$this->content = $content;
} else {
$this->content = $content;
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/UserPrefs.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/UserPrefs.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
--- incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/UserPrefs.php
(original)
+++ incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/UserPrefs.php
Fri Feb 6 14:12:36 2009
@@ -32,4 +32,4 @@
public function getPref($name) {
return isset($this->prefs[$name]) ? $this->prefs[$name] : null;
}
-}
\ No newline at end of file
+}
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
Fri Feb 6 14:12:36 2009
@@ -19,7 +19,7 @@
*/
class BasicGadgetOAuthTokenStore extends GadgetOAuthTokenStore {
-
+
/** default location for consumer keys and secrets */
private $OAUTH_CONFIG = "../config/oauth.json";
private $CONSUMER_SECRET_KEY = "consumer_secret";
@@ -96,5 +96,4 @@
$kas = new ConsumerKeyAndSecret($consumerKey, $consumerSecret, $keyType);
$this->storeConsumerKeyAndSecret($gadgetUri, $serviceName, $kas);
}
-
}
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/OAuthService.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/OAuthService.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/OAuthService.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/oauth/OAuthService.php
Fri Feb 6 14:12:36 2009
@@ -35,23 +35,29 @@
public function __construct($service) {
$attrs = $service->attributes();
$this->name = (string)$attrs['name'];
- $this->requestUrl = $this->parseEndPoint($service->Request->attributes());
- $this->authorizationUrl =
$this->parseEndPoint($service->Authorization->attributes());
- $this->accessUrl = $this->parseEndPoint($service->Access->attributes());
+ if (isset($service->Request)) {
+ $this->requestUrl =
$this->parseEndPoint($service->Request->attributes());
+ }
+ if (isset($service->Authorization)) {
+ $this->authorizationUrl =
$this->parseEndPoint($service->Authorization->attributes());
+ }
+ if (isset($service->Access)) {
+ $this->accessUrl = $this->parseEndPoint($service->Access->attributes());
+ }
}
private function parseEndPoint($element) {
- $url = (string)$element[OAuthService::$URL_ATTR];
+ $url = trim((string)$element[OAuthService::$URL_ATTR]);
if (empty($url)) {
throw new SpecParserException("Not an HTTP url");
}
$location = Location::$header;
- $locationString = (string)$element[OAuthService::$PARAM_LOCATION_ATTR];
+ $locationString =
trim((string)$element[OAuthService::$PARAM_LOCATION_ATTR]);
if (! empty($locationString)) {
$location = $locationString;
}
$method = Method::$GET;
- $methodString = (string)$element[OAuthService::$METHOD_ATTR];
+ $methodString = trim((string)$element[OAuthService::$METHOD_ATTR]);
if (! empty($methodString)) {
$method = $methodString;
}
@@ -88,9 +94,9 @@
* access token, or resource URL. (Lowercase to match gadget spec schema)
*/
class Location {
- public static $header = "header";
- public static $url = "url";
- public static $body = "body";
+ public static $header = "auth-header";
+ public static $url = "url-query";
+ public static $body = "post-body";
}
/**
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/sample/BasicGadgetSpecFactory.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/sample/BasicGadgetSpecFactory.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/sample/BasicGadgetSpecFactory.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/sample/BasicGadgetSpecFactory.php
Fri Feb 6 14:12:36 2009
@@ -22,8 +22,9 @@
* Basic implementation of a gadget spec factory.
*/
class BasicGadgetSpecFactory implements GadgetSpecFactory {
-
+
private $fetcher;
+ private $cache;
public function __construct($fetcher) {
$this->fetcher = $fetcher;
@@ -37,10 +38,7 @@
* 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);
+ return $this->fetchFromWeb($url, $ignoreCache);
}
/**
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php
Fri Feb 6 14:12:36 2009
@@ -166,7 +166,7 @@
$content .= sprintf($externFmt, Config::get('default_js_prefix') .
$this->getJsUrl($libs, $gadget) . "&container=" . $context->getContainer()) .
"\n";
}
$content .= "<script>\n";
-
+
if (! empty($forcedLibs)) {
// if some of the feature libraries are externalized (through a browser
cachable <script src="/gadgets/js/opensocial-0.7:settitle.js">
// type url), then we don't want to include dependencies twice, so find
the complete features chain, so we can skip over those
@@ -301,7 +301,8 @@
$buf .= $lib;
}
}
- $cache = $this->context->getCache();
+ $cache = Config::get('feature_cache');
+ $cache = new $cache();
if (($md5 = $cache->get(md5('getJsUrlMD5'))) === false) {
$registry = $this->context->getRegistry();
$features = $registry->getAllFeatures();
@@ -339,7 +340,7 @@
}
}
}
-
+
// Add gadgets.util support. This is calculated dynamically based on
request inputs.
// See
java/org/apache/shindig/gadgets/render/RenderingContentRewriter.java for
reference.
$requires = array();
@@ -347,7 +348,7 @@
$requires[$feature->name] = new EmptyClass();
}
$gadgetConfig['core.util'] = $requires;
-
+
return "gadgets.config.init(" . json_encode($gadgetConfig) . ");\n";
}
@@ -417,7 +418,7 @@
$responses = $brc->multiFetch($unsignedRequests, $unsignedContexts);
foreach ($responses as $response) {
$resp[$response->getUrl()] = array(
- 'body' => $response->getResponseContent(),
+ 'body' => $response->getResponseContent(),
'rc' => $response->getHttpCode());
}
} catch (Exception $e) {
@@ -430,7 +431,7 @@
$responses = $fetcher->multiFetchRequest($signedRequests);
foreach ($responses as $response) {
$resp[$response->getNotSignedUrl()] = array(
- 'body' => $response->getResponseContent(),
+ 'body' => $response->getResponseContent(),
'rc' => $response->getHttpCode());
}
} catch (Exception $e) {
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputAtomConverter.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputAtomConverter.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputAtomConverter.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputAtomConverter.php
Fri Feb 6 14:12:36 2009
@@ -28,10 +28,8 @@
private static $xmlVersion = '1.0';
private static $charSet = 'UTF-8';
private static $formatOutput = true;
- //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',
+ private static $entryTypes = array('people' => 'person', 'appdata' =>
'appdata',
'activities' => 'activity', 'messages' => 'messages');
private $doc;
@@ -44,17 +42,17 @@
$guid = 'urn:guid:' . $userId;
$authorName = $_SERVER['HTTP_HOST'] . ':' . $userId;
$updatedAtom = date(DATE_ATOM);
-
- // Check to see if this is a single entry, or a collection, and construct
either an atom
- // feed (collection) or an entry (single)
+
+ // Check to see if this is a single entry, or a collection, and construct
either an atom
+ // feed (collection) or an entry (single)
if ($responseItem->getResponse() instanceof RestfulCollection) {
$totalResults = $responseItem->getResponse()->getTotalResults();
$itemsPerPage = $requestItem->getCount();
$startIndex = $requestItem->getStartIndex();
-
+
// The root Feed element
$entry = $this->addNode($doc, 'feed', '', false, self::$nameSpace);
-
+
// Required Atom fields
$endPos = ($startIndex + $itemsPerPage) > $totalResults ? $totalResults
: ($startIndex + $itemsPerPage);
$this->addNode($entry, 'title', $requestType . ' feed for id ' .
$authorName . ' (' . $startIndex . ' - ' . ($endPos - 1) . ' of ' .
$totalResults . ')');
@@ -63,7 +61,7 @@
$this->addNode($author, 'name', $authorName);
$this->addNode($entry, 'updated', $updatedAtom);
$this->addNode($entry, 'id', $guid);
- $this->addNode($entry, 'link', '', array('rel' => 'self',
+ $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);
@@ -99,12 +97,12 @@
$this->addNode($feedEntry, 'title', $requestType . ' feed entry for
id ' . $idField);
$this->addNode($feedEntry, 'updated', $updatedAtom);
}
-
+
// recursively add responseItem data to the xml structure
$this->addData($content, $requestType, $response, self::$osNameSpace);
}
} else {
- // Single entry = Atom:Entry
+ // Single entry = Atom:Entry
$entry = $doc->appendChild($doc->createElementNS(self::$nameSpace,
"entry"));
// Atom fields
$this->addNode($entry, 'title', $requestType . ' entry for ' .
$authorName);
@@ -199,7 +197,7 @@
}
/**
- * Recursive function that maps an data array or object to it's xml
represantation
+ * Recursive function that maps an data array or object to it's xml
represantation
*
* @param DOMElement $element the element to append the new node(s) to
* @param string $name the name of the to be created node
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputXmlConverter.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputXmlConverter.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputXmlConverter.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/social/converters/OutputXmlConverter.php
Fri Feb 6 14:12:36 2009
@@ -28,8 +28,8 @@
private static $formatOutput = true;
// this maps the REST url to the xml tags
- private static $entryTypes = array('people' => 'person', 'appdata' =>
'appdata',
- 'activities' => 'activity', 'messages' => 'messages');
+ private static $entryTypes = array('people' => 'entry', 'appdata' =>
'entry',
+ 'activities' => 'entry', 'messages' => 'entry');
private $doc;
function outputResponse(ResponseItem $responseItem, RestRequestItem
$requestItem) {
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/social/oauth/OAuth.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/social/oauth/OAuth.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
--- incubator/shindig/branches/1.0.x-incubating/php/src/social/oauth/OAuth.php
(original)
+++ incubator/shindig/branches/1.0.x-incubating/php/src/social/oauth/OAuth.php
Fri Feb 6 14:12:36 2009
@@ -1,4 +1,5 @@
<?php
+
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -82,12 +83,9 @@
public function build_signature($request, $consumer, $token) {
$base_string = $request->get_signature_base_string();
$request->base_string = $base_string;
-
$key_parts = array($consumer->secret, ($token) ? $token->secret : "");
-
$key_parts = array_map(array('OAuthUtil', 'urlencodeRFC3986'), $key_parts);
$key = implode('&', $key_parts);
-
return base64_encode(hash_hmac('sha1', $base_string, $key, true));
}
}
@@ -100,17 +98,17 @@
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);
}
}
@@ -142,39 +140,39 @@
public function build_signature(&$request, $consumer, $token) {
$base_string = $request->get_signature_base_string();
$request->base_string = $base_string;
-
+
// Fetch the private key cert based on the request
$cert = $this->fetch_private_cert($request);
-
+
// Pull the private key ID from the certificate
$privatekeyid = openssl_get_privatekey($cert);
-
+
// Sign using the key
$ok = openssl_sign($base_string, $signature, $privatekeyid);
-
+
// 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();
-
+
// Fetch the public key cert based on the request
$cert = $this->fetch_public_cert($request);
-
+
// Pull the public key ID from the certificate
$publickeyid = openssl_get_publickey($cert);
-
+
// Check the computed signature against the one passed in the query
$ok = openssl_verify($base_string, $decoded_sig, $publickeyid);
-
+
// Release the key resource
openssl_free_key($publickeyid);
-
+
return $ok == 1;
}
}
@@ -201,9 +199,9 @@
$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
@@ -215,7 +213,7 @@
if ($http_method == "POST" && @$request_headers["Content-Type"] ==
"application/x-www-form-urlencoded") {
$req_parameters = array_merge($req_parameters, $_POST);
}
-
+
// 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
@@ -226,7 +224,7 @@
} else
$req = new OAuthRequest($http_method, $http_url, $req_parameters);
}
-
+
return $req;
}
@@ -235,12 +233,9 @@
*/
public static function from_consumer_and_token($consumer, $token,
$http_method, $http_url, $parameters = NULL) {
@$parameters or $parameters = array();
- $defaults = array("oauth_version" => OAuthRequest::$version,
- "oauth_nonce" => OAuthRequest::generate_nonce(),
- "oauth_timestamp" => OAuthRequest::generate_timestamp(),
- "oauth_consumer_key" => $consumer->key);
+ $defaults = array("oauth_version" => OAuthRequest::$version, "oauth_nonce"
=> OAuthRequest::generate_nonce(), "oauth_timestamp" =>
OAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key);
$parameters = array_merge($defaults, $parameters);
-
+
if ($token) {
$parameters['oauth_token'] = $token->key;
}
@@ -261,38 +256,38 @@
/**
* Returns the normalized parameters of the request
- *
+ *
* This will be all (except oauth_signature) parameters,
* sorted first by key, and if duplicate keys, then by
* value.
*
* The returned string will be all the key=value pairs
* concated by &.
- *
+ *
* @return string
*/
public function get_signable_parameters() {
// Grab all parameters
$params = $this->parameters;
-
+
// Remove oauth_signature if present
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);
-
+
// Sort by keys (natsort)
uksort($params, 'strnatcmp');
-
+
// Generate key=value pairs
$pairs = array();
foreach ($params as $key => $value) {
if (is_array($value)) {
- // If the value is an array, it's because there are multiple
+ // 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) {
@@ -302,7 +297,7 @@
$pairs[] = $key . '=' . $value;
}
}
-
+
// Return the pairs, concated with &
return implode('&', $pairs);
}
@@ -315,11 +310,10 @@
* and the concated with &.
*/
public function get_signature_base_string() {
- $parts = array($this->get_normalized_http_method(),
$this->get_normalized_http_url(),
- $this->get_signable_parameters());
-
+ $parts = array($this->get_normalized_http_method(),
$this->get_normalized_http_url(), $this->get_signable_parameters());
+
$parts = array_map(array('OAuthUtil', 'urlencodeRFC3986'), $parts);
-
+
return implode('&', $parts);
}
@@ -336,14 +330,14 @@
*/
public function get_normalized_http_url() {
$parts = parse_url($this->http_url);
-
+
$port = @$parts['port'];
$scheme = $parts['scheme'];
$host = $parts['host'];
$path = @$parts['path'];
-
+
$port or $port = ($scheme == 'https') ? '443' : '80';
-
+
if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port
!= '80')) {
$host = "$host:$port";
}
@@ -412,7 +406,7 @@
private static function generate_nonce() {
$mt = microtime();
$rand = mt_rand();
-
+
return md5($mt . $rand); // md5s look nicer than numbers
}
@@ -421,9 +415,9 @@
* parameters, has to do some unescaping
*/
private static function split_header($header) {
- // remove 'OAuth ' at the start of a header
+ // remove 'OAuth ' at the start of a header
$header = substr($header, 6);
-
+
// error cases: commas in parameter values?
$parts = explode(",", $header);
$out = array();
@@ -431,9 +425,9 @@
$param = ltrim($param);
// skip the "realm" param, nobody ever uses it anyway
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));
@@ -470,7 +464,7 @@
protected $timestamp_threshold = 300; // in seconds, five minutes
protected $version = 1.0; // hi blaine
protected $signature_methods = array();
-
+
protected $data_store;
function __construct($data_store) {
@@ -482,7 +476,7 @@
}
// high level functions
-
+
/**
* process a request_token request
@@ -490,16 +484,16 @@
*/
public function fetch_request_token(&$request) {
$this->get_version($request);
-
+
$consumer = $this->get_consumer($request);
-
+
// no token required for the initial token request
$token = NULL;
-
+
$this->check_signature($request, $consumer, $token);
-
+
$new_token = $this->data_store->new_request_token($consumer);
-
+
return $new_token;
}
@@ -509,16 +503,16 @@
*/
public function fetch_access_token(&$request) {
$this->get_version($request);
-
+
$consumer = $this->get_consumer($request);
-
+
// requires authorized request token
$token = $this->get_token($request, $consumer, "request");
-
+
$this->check_signature($request, $consumer, $token);
-
+
$new_token = $this->data_store->new_access_token($token, $consumer);
-
+
return $new_token;
}
@@ -570,12 +564,12 @@
if (! $consumer_key) {
throw new OAuthException("Invalid consumer key");
}
-
+
$consumer = $this->data_store->lookup_consumer($consumer_key);
if (! $consumer) {
throw new OAuthException("Invalid consumer");
}
-
+
return $consumer;
}
@@ -599,15 +593,12 @@
// this should probably be in a different method
$timestamp = @$request->get_parameter('oauth_timestamp');
$nonce = @$request->get_parameter('oauth_nonce');
-
$this->check_timestamp($timestamp);
$this->check_nonce($consumer, $token, $nonce, $timestamp);
-
$signature_method = $this->get_signature_method($request);
-
$signature = $request->get_parameter('oauth_signature');
+ //MARK2
$valid_sig = $signature_method->check_signature($request, $consumer,
$token, $signature);
-
if (! $valid_sig) {
throw new OAuthException("Invalid signature");
}
@@ -655,93 +646,18 @@
abstract function new_access_token($token, $consumer);
abstract function authorize_request_token($token);
-
-}
-
-/* A very naive dbm-based oauth storage
- */
-class SimpleOAuthDataStore extends OAuthDataStore {
- private $dbh;
-
- function __construct($path = "oauth.gdbm") {
- $this->dbh = dba_popen($path, 'c', 'gdbm');
- }
-
- function __destruct() {
- dba_close($this->dbh);
- }
-
- function lookup_consumer($consumer_key) {
- $rv = dba_fetch("consumer_$consumer_key", $this->dbh);
- if ($rv === FALSE) {
- return NULL;
- }
- $obj = unserialize($rv);
- if (! ($obj instanceof OAuthConsumer)) {
- return NULL;
- }
- return $obj;
- }
-
- function lookup_token($consumer, $token_type, $token) {
- $rv = dba_fetch("${token_type}_${token}", $this->dbh);
- if ($rv === FALSE) {
- return NULL;
- }
- $obj = unserialize($rv);
- if (! ($obj instanceof OAuthToken)) {
- return NULL;
- }
- return $obj;
- }
-
- function lookup_nonce($consumer, $token, $nonce, $timestamp) {
- if (dba_exists("nonce_$nonce", $this->dbh)) {
- return TRUE;
- } else {
- dba_insert("nonce_$nonce", "1", $this->dbh);
- return FALSE;
- }
- }
-
- function new_token($consumer, $type = "request") {
- $key = md5(time());
- $secret = time() + time();
- $token = new OAuthToken($key, md5(md5($secret)));
- if (! dba_insert("${type}_$key", serialize($token), $this->dbh)) {
- throw new OAuthException("doooom!");
- }
- return $token;
- }
-
- function new_request_token($consumer) {
- return $this->new_token($consumer, "request");
- }
-
- function new_access_token($token, $consumer) {
- // TODO: check if request token is authorized first
- $token = $this->new_token($consumer, 'access');
- dba_delete("request_" . $token->key, $this->dbh);
- return $token;
- }
-
- function authorize_request_token($token) {
- dba_insert('request_' . $token->key . '_authorized', 1, $this->dbh);
- }
}
class OAuthUtil {
public static function urlencodeRFC3986($string) {
return str_replace('+', ' ', str_replace('%7E', '~',
rawurlencode($string)));
-
}
- // This decode function isn't taking into consideration the above
- // modifications to the encoding process. However, this method doesn't
+ // This decode function isn't taking into consideration the above
+ // modifications to the encoding process. However, this method doesn't
// seem to be used anywhere so leaving it as is.
public static function urldecodeRFC3986($string) {
return rawurldecode($string);
}
-}
-
+}
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/social/sample/JsonDbOpensocialService.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/social/sample/JsonDbOpensocialService.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/social/sample/JsonDbOpensocialService.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/social/sample/JsonDbOpensocialService.php
Fri Feb 6 14:12:36 2009
@@ -345,7 +345,7 @@
}
public function getActivity($userId, $groupId, $appdId, $fields,
$activityId, SecurityToken $token) {
- $activities = $this->getActivities($userId, $groupId, $appdId, null, null,
null, null, $fields, $token);
+ $activities = $this->getActivities($userId, $groupId, $appdId, null, null,
null, null, $fields, array($activityId), $token);
if ($activities instanceof RestfulCollection) {
$activities = $activities->getEntry();
foreach ($activities as $activity) {
@@ -357,7 +357,7 @@
throw new SocialSpiException("Activity not found",
ResponseError::$NOT_FOUND);
}
- public function getActivities($userIds, $groupId, $appId, $sortBy,
$filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $token) {
+ public function getActivities($userIds, $groupId, $appId, $sortBy,
$filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $activityIds,
$token) {
$db = $this->getDb();
$friendsTable = $db[self::$FRIEND_LINK_TABLE];
$ids = array();
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/social/service/ActivityHandler.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/social/service/ActivityHandler.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/social/service/ActivityHandler.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/social/service/ActivityHandler.php
Fri Feb 6 14:12:36 2009
@@ -20,7 +20,7 @@
class ActivityHandler extends DataRequestHandler {
private $service;
-
+
private static $ACTIVITY_ID_PATH =
"/activities/{userId}/{groupId}/appId/{activityId}";
public function __construct() {
@@ -65,7 +65,7 @@
return $this->service->getActivities($userIds[0],
$requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getSortBy(),
$requestItem->getFilterBy(), $requestItem->getFilterOperation(),
$requestItem->getFilterValue(), $requestItem->getStartIndex(),
$requestItem->getCount(), $requestItem->getFields(), $optionalActivityIds,
$requestItem->getToken());
}
}
- return $this->service->getActivities($userIds, $requestItem->getGroup(),
$requestItem->getAppId(), $requestItem->getSortBy(),
$requestItem->getFilterBy(), $requestItem->getFilterOperation(),
$requestItem->getFilterValue(), $requestItem->getStartIndex(),
$requestItem->getCount(), $requestItem->getFields(), $requestItem->getToken());
+ return $this->service->getActivities($userIds, $requestItem->getGroup(),
$requestItem->getAppId(), $requestItem->getSortBy(),
$requestItem->getFilterBy(), $requestItem->getFilterOperation(),
$requestItem->getFilterValue(), $requestItem->getStartIndex(),
$requestItem->getCount(), $requestItem->getFields(), null,
$requestItem->getToken());
}
/**
@@ -89,6 +89,12 @@
if (! empty($activityIds)) {
throw new InvalidArgumentException("Cannot specify activityId in
create");
}
+ /*
+ * Note, on just about all types of social networks you would only allow
activities to be created when the owner == viewer, and the userId == viewer as
well, in code this would mean:
+ * if ($token->getOwnerId() != $token->getViewerId() ||
$token->getViewerId() != $userId->getUserId($token)) {
+ * throw new SocialSpiException("Create activity permission denied.",
ResponseError::$UNAUTHORIZED);
+ * }
+ */
return $this->service->createActivity($userIds[0],
$requestItem->getGroup(), $requestItem->getAppId(), $requestItem->getFields(),
$requestItem->getParameter("activity"), $requestItem->getToken());
}
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/social/service/RequestItem.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/social/service/RequestItem.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/social/service/RequestItem.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/social/service/RequestItem.php
Fri Feb 6 14:12:36 2009
@@ -163,7 +163,7 @@
$cleanResult = array();
foreach ($result as $field) {
if (! in_array($field, $cleanResult)) {
- $cleanResult[] = $field;
+ $cleanResult[] = urldecode($field);
}
}
$result = $cleanResult;
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/social/servlet/DataServiceServlet.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/social/servlet/DataServiceServlet.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/social/servlet/DataServiceServlet.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/social/servlet/DataServiceServlet.php
Fri Feb 6 14:12:36 2009
@@ -71,7 +71,8 @@
public function sendError(ResponseItem $responseItem) {
$unauthorized = false;
$errorMessage = $responseItem->getErrorMessage();
- switch ($responseItem->getError()) {
+ $errorCode = $responseItem->getError();
+ switch ($errorCode) {
case ResponseError::$BAD_REQUEST:
$code = '400 Bad Request';
break;
@@ -82,7 +83,7 @@
case ResponseError::$FORBIDDEN:
$code = '403 Forbidden';
break;
- case ResponseError::$FORBIDDEN:
+ case ResponseError::$NOT_FOUND:
$code = '404 Not Found';
break;
case ResponseError::$NOT_IMPLEMENTED:
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/social/spi/ActivityService.php
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/social/spi/ActivityService.php?rev=741570&r1=741569&r2=741570&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/php/src/social/spi/ActivityService.php
(original)
+++
incubator/shindig/branches/1.0.x-incubating/php/src/social/spi/ActivityService.php
Fri Feb 6 14:12:36 2009
@@ -23,7 +23,7 @@
/**
* Returns a list of activities that correspond to the passed in person ids.
*/
- public function getActivities($userIds, $groupId, $appId, $sortBy,
$filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $token);
+ public function getActivities($userIds, $groupId, $appId, $sortBy,
$filterBy, $filterOp, $filterValue, $startIndex, $count, $fields, $activityIds,
$token);
public function getActivity($userId, $groupId, $appdId, $fields,
$activityId, SecurityToken $token);