You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ch...@apache.org on 2010/03/15 10:50:28 UTC
svn commit: r923138 - in
/shindig/tags/shindig-project-1.0-incubating/php/src/gadgets:
ContainerConfig.php GadgetServer.php oauth/BasicGadgetOAuthTokenStore.php
servlet/GadgetRenderingServlet.php
Author: chaowang
Date: Mon Mar 15 09:50:28 2010
New Revision: 923138
URL: http://svn.apache.org/viewvc?rev=923138&view=rev
Log:
Fix issue #1262 on Shindig-1.0: UserPref doesn't work
Modified:
shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/ContainerConfig.php
shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/GadgetServer.php
shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php
Modified: shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/ContainerConfig.php
URL: http://svn.apache.org/viewvc/shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/ContainerConfig.php?rev=923138&r1=923137&r2=923138&view=diff
==============================================================================
--- shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/ContainerConfig.php (original)
+++ shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/ContainerConfig.php Mon Mar 15 09:50:28 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/tags/shindig-project-1.0-incubating/php/src/gadgets/GadgetServer.php
URL: http://svn.apache.org/viewvc/shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/GadgetServer.php?rev=923138&r1=923137&r2=923138&view=diff
==============================================================================
--- shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/GadgetServer.php (original)
+++ shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/GadgetServer.php Mon Mar 15 09:50:28 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/tags/shindig-project-1.0-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
URL: http://svn.apache.org/viewvc/shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php?rev=923138&r1=923137&r2=923138&view=diff
==============================================================================
--- shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php (original)
+++ shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php Mon Mar 15 09:50:28 2010
@@ -1,21 +1,21 @@
<?php
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
class BasicGadgetOAuthTokenStore extends GadgetOAuthTokenStore {
@@ -31,13 +31,13 @@ class BasicGadgetOAuthTokenStore extends
}
public function initFromConfigFile($fetcher) {
- // Read our consumer keys and secrets from config/oauth.js
- // This actually involves fetching gadget specs
+ // Read our consumer keys and secrets from config/oauth.js
+ // This actually involves fetching gadget specs
try {
$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);
+ // 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 = self::removeComments($oauthConfigStr);
$oauthConfig = json_decode($contents, true);
if ($oauthConfig == $contents) {
throw new GadgetException("OAuth configuration json failed to parse.");
@@ -50,6 +50,15 @@ class BasicGadgetOAuthTokenStore extends
}
}
+ 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;
@@ -96,4 +105,4 @@ class BasicGadgetOAuthTokenStore extends
$kas = new ConsumerKeyAndSecret($consumerKey, $consumerSecret, $keyType);
$this->storeConsumerKeyAndSecret($gadgetUri, $serviceName, $kas);
}
-}
+}
Modified: shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php
URL: http://svn.apache.org/viewvc/shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php?rev=923138&r1=923137&r2=923138&view=diff
==============================================================================
--- shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php (original)
+++ shindig/tags/shindig-project-1.0-incubating/php/src/gadgets/servlet/GadgetRenderingServlet.php Mon Mar 15 09:50:28 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.