You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2010/05/08 01:02:03 UTC
svn commit: r942263 - in /shindig/branches/1.0.x/php/src/gadgets:
ContainerConfig.php GadgetServer.php oauth/BasicGadgetOAuthTokenStore.php
servlet/GadgetRenderingServlet.php
Author: lindner
Date: Fri May 7 23:02:02 2010
New Revision: 942263
URL: http://svn.apache.org/viewvc?rev=942263&view=rev
Log:
SHINDIG-1262 | Backpatch from Tim Wintle
Modified:
shindig/branches/1.0.x/php/src/gadgets/ContainerConfig.php
shindig/branches/1.0.x/php/src/gadgets/GadgetServer.php
shindig/branches/1.0.x/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
shindig/branches/1.0.x/php/src/gadgets/servlet/GadgetRenderingServlet.php
Modified: shindig/branches/1.0.x/php/src/gadgets/ContainerConfig.php
URL: http://svn.apache.org/viewvc/shindig/branches/1.0.x/php/src/gadgets/ContainerConfig.php?rev=942263&r1=942262&r2=942263&view=diff
==============================================================================
--- shindig/branches/1.0.x/php/src/gadgets/ContainerConfig.php (original)
+++ shindig/branches/1.0.x/php/src/gadgets/ContainerConfig.php Fri May 7 23:02:02 2010
@@ -50,7 +50,7 @@ class ContainerConfig {
$contents = file_get_contents($file);
// remove all comments (both /* */ and // style) because this confuses the json parser
// note: the json parser also crashes on trailing ,'s in records so please don't use them
- $contents = preg_replace('/[^http:\/\/|^https:\/\/]\/\/.*$/m', '', preg_replace('@/\\*(?:.|[\\n\\r])*?\\*/@', '', $contents));
+ $contents = self::removeComments($contents);
$config = json_decode($contents, true);
if ($config == $contents) {
throw new Exception("Failed to json_decode the container configuration");
@@ -65,6 +65,15 @@ class ContainerConfig {
}
}
+ public static function removeComments($str) {
+ // remove /* */ style comments
+ $str = preg_replace('@/\\*.*?\\*/@s', '', $str);
+ // remove // style comments, but keep 'http://' 'https://' and '"//'
+ // for example: "gadgets.oauthGadgetCallbackTemplate" : "//%host%/gadgets/oauthcallback"
+ $str = preg_replace('/[^http:\/\/|^https:\/\/|"\/\/]\/\/.*$/m', '', $str);
+ return $str;
+ }
+
public function getConfig($container, $name) {
$config = array();
if (isset($this->config[$container]) && isset($this->config[$container][$name])) {
Modified: shindig/branches/1.0.x/php/src/gadgets/GadgetServer.php
URL: http://svn.apache.org/viewvc/shindig/branches/1.0.x/php/src/gadgets/GadgetServer.php?rev=942263&r1=942262&r2=942263&view=diff
==============================================================================
--- shindig/branches/1.0.x/php/src/gadgets/GadgetServer.php (original)
+++ shindig/branches/1.0.x/php/src/gadgets/GadgetServer.php Fri May 7 23:02:02 2010
@@ -149,6 +149,7 @@ class GadgetServer {
}
// userPref's
$upValues = $gadget->getUserPrefValues();
+ $userPrefs = array();
foreach ($gadget->getUserPrefs() as $pref) {
$name = $pref->getName();
$value = $upValues->getPref($name);
@@ -158,8 +159,10 @@ class GadgetServer {
if ($value == null) {
$value = "";
}
+ $userPrefs[$name] = $value;
$substitutor->addSubstitution('UP', $name, $value);
}
+ $gadget->setPrefs(new UserPrefs($userPrefs));
$this->substitutePreloads($gadget, $substitutor);
}
Modified: shindig/branches/1.0.x/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
URL: http://svn.apache.org/viewvc/shindig/branches/1.0.x/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php?rev=942263&r1=942262&r2=942263&view=diff
==============================================================================
--- shindig/branches/1.0.x/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php (original)
+++ shindig/branches/1.0.x/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php Fri May 7 23:02:02 2010
@@ -38,7 +38,7 @@ class BasicGadgetOAuthTokenStore extends
$oauthConfigStr = file_get_contents($this->OAUTH_CONFIG);
// remove all comments because this confuses the json parser
// note: the json parser also crashes on trailing ,'s in records so please don't use them
- $contents = preg_replace('@/\\*(?:.|[\\n\\r])*?\\*/@', '', $oauthConfigStr);
+ $contents = self::removeComments($oauthConfigStr);
$oauthConfig = json_decode($contents, true);
if ($oauthConfig == $contents) {
throw new GadgetException("OAuth configuration json failed to parse.");
@@ -50,7 +50,16 @@ class BasicGadgetOAuthTokenStore extends
throw new GadgetException($e);
}
}
-
+
+ public static function removeComments($str) {
+ // remove /* */ style comments
+ $str = preg_replace('@/\\*.*?\\*/@s', '', $str);
+ // remove // style comments, but keep 'http://' 'https://' and '"//'
+ // for example: "gadgets.oauthGadgetCallbackTemplate" : "//%host%/gadgets/oauthcallback"
+ $str = preg_replace('/[^http:\/\/|^https:\/\/|"\/\/]\/\/.*$/m', '', $str);
+ return $str;
+ }
+
private function storeConsumerInfos($gadgetUri, $oauthConfig) {
foreach ($oauthConfig as $key => $value) {
$serviceName = $key;
Modified: shindig/branches/1.0.x/php/src/gadgets/servlet/GadgetRenderingServlet.php
URL: http://svn.apache.org/viewvc/shindig/branches/1.0.x/php/src/gadgets/servlet/GadgetRenderingServlet.php?rev=942263&r1=942262&r2=942263&view=diff
==============================================================================
--- shindig/branches/1.0.x/php/src/gadgets/servlet/GadgetRenderingServlet.php (original)
+++ shindig/branches/1.0.x/php/src/gadgets/servlet/GadgetRenderingServlet.php Fri May 7 23:02:02 2010
@@ -187,7 +187,7 @@ class GadgetRenderingServlet extends Htt
}
// otherwise it was already included by config.forceJsLibs.
}
- $content .= $this->appendJsConfig($context, $gadget, ! empty($forcedLibs)) . $this->appendMessages($gadget) . $this->appendPreloads($gadget, $context) . "</script>";
+ $content .= $this->appendJsConfig($context, $gadget, ! empty($forcedLibs)) . $this->appendMessages($gadget) . $this->appendPreferences($gadget) . $this->appendPreloads($gadget, $context) . "</script>";
if (strlen($externJs) > 0) {
$content .= $externJs;
}
@@ -361,6 +361,11 @@ class GadgetRenderingServlet extends Htt
return "gadgets.Prefs.setMessages_($msgs);\n";
}
+ private function appendPreferences(Gadget $gadget) {
+ $prefs = json_encode($gadget->getUserPrefValues()->getPrefs());
+ return "gadgets.Prefs.setDefaultPrefs_($prefs);\n";
+ }
+
/**
* Appends data from <Preload> elements to make them available to
* gadgets.io.