Skip to content
Browse files

Fix issue #1262 on Shindig-1.0: UserPref doesn't work

  • Loading branch information...
1 parent 9de3bc7 commit cfcc8090c2b4ed7783ea2ff992f6b6790e02b44e Jacky Wang committed
View
11 php/src/gadgets/ContainerConfig.php
@@ -50,7 +50,7 @@ private function loadFromFile($file) {
$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 @@ private function loadFromFile($file) {
}
}
+ 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])) {
View
3 php/src/gadgets/GadgetServer.php
@@ -149,6 +149,7 @@ private function substitute(Gadget $gadget, $context) {
}
// userPref's
$upValues = $gadget->getUserPrefValues();
+ $userPrefs = array();
foreach ($gadget->getUserPrefs() as $pref) {
$name = $pref->getName();
$value = $upValues->getPref($name);
@@ -158,8 +159,10 @@ private function substitute(Gadget $gadget, $context) {
if ($value == null) {
$value = "";
}
+ $userPrefs[$name] = $value;
$substitutor->addSubstitution('UP', $name, $value);
}
+ $gadget->setPrefs(new UserPrefs($userPrefs));
$this->substitutePreloads($gadget, $substitutor);
}
View
55 php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
@@ -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 @@ public function __construct($store, $fetcher) {
}
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 @@ public function initFromConfigFile($fetcher) {
}
}
+ 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 @@ private function storeConsumerInfo($gadgetUri, $serviceName, $consumerInfo) {
$kas = new ConsumerKeyAndSecret($consumerKey, $consumerSecret, $keyType);
$this->storeConsumerKeyAndSecret($gadgetUri, $serviceName, $kas);
}
-}
+}
View
7 php/src/gadgets/servlet/GadgetRenderingServlet.php
@@ -187,7 +187,7 @@ private function outputHtmlGadget($gadget, $context, $view) {
}
// 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 @@ private function appendMessages($gadget) {
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.

0 comments on commit cfcc809

Please sign in to comment.
Something went wrong with that request. Please try again.