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/05/06 13:55:18 UTC
svn commit: r653753 - in /incubator/shindig/trunk/php: ./ src/common/
src/gadgets/ src/gadgets/http/ src/gadgets/samplecontainer/
src/socialdata/http/ src/socialdata/opensocial/model/
src/socialdata/samplecontainer/
Author: chabotc
Date: Tue May 6 04:55:16 2008
New Revision: 653753
URL: http://svn.apache.org/viewvc?rev=653753&view=rev
Log:
- Restructured views to support multiple views per content block ("profile,canvas" type format).
- Added view quirk attribute support too
- Moved $config to $shindigConfig to avoid namespace collisions
- Eradicated the last global $config occurances
- Made source formatting more consistent
- Fixed the proxy handler that crashed on empty tokens
- Couple of other small things
Added:
incubator/shindig/trunk/php/src/common/UrlGenerator.php
incubator/shindig/trunk/php/src/gadgets/ViewSpec.php
incubator/shindig/trunk/php/src/gadgets/http/HttpUtil.php
Modified:
incubator/shindig/trunk/php/config.php
incubator/shindig/trunk/php/src/common/BlobCrypter.php
incubator/shindig/trunk/php/src/common/Cache.php
incubator/shindig/trunk/php/src/common/Crypto.php
incubator/shindig/trunk/php/src/common/HttpServlet.php
incubator/shindig/trunk/php/src/common/Locale.php
incubator/shindig/trunk/php/src/common/RemoteContent.php
incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php
incubator/shindig/trunk/php/src/gadgets/Gadget.php
incubator/shindig/trunk/php/src/gadgets/GadgetContext.php
incubator/shindig/trunk/php/src/gadgets/GadgetException.php
incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php
incubator/shindig/trunk/php/src/gadgets/GadgetServer.php
incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php
incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php
incubator/shindig/trunk/php/src/gadgets/JsLibrary.php
incubator/shindig/trunk/php/src/gadgets/JsLibraryFeatureFactory.php
incubator/shindig/trunk/php/src/gadgets/JsonRpcGadgetContext.php
incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php
incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php
incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
incubator/shindig/trunk/php/src/gadgets/Substitutions.php
incubator/shindig/trunk/php/src/gadgets/http/FilesServlet.php
incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php
incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php
incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicBlobCrypter.php
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetTokenDecoder.php
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContent.php
incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php
incubator/shindig/trunk/php/src/socialdata/http/GadgetDataServlet.php
incubator/shindig/trunk/php/src/socialdata/opensocial/model/idSpec.php
incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicActivitiesService.php
incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicDataService.php
incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicPeopleService.php
Modified: incubator/shindig/trunk/php/config.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/config.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/config.php (original)
+++ incubator/shindig/trunk/php/config.php Tue May 6 04:55:16 2008
@@ -4,7 +4,7 @@
* But since PHP lacks a propper way to set application configurations, and any other method
* would be horribly slow (db, xml, ini files etc), so ... here's our config.php
*/
-$config = array(
+$shindigConfig = array(
// Show debug backtrace? Set this to false on anything that resembles a production env
'debug' => false,
@@ -35,10 +35,11 @@
'features_path' => realpath(dirname(__FILE__)) . '/../features/',
'container_path' => realpath(dirname(__FILE__)) . '/../config/',
'javascript_path' => realpath(dirname(__FILE__)) . '/../javascript/',
+ 'container_config' => realpath(dirname(__FILE__)) . '/../config/container.js',
// The data handlers for the social data, this is a list of class names
// seperated by a , For example:
- // 'handlers' => 'OpenSocialDataHandler,StateFileDataHandler',
+ // 'handlers' => 'PartuzaHandler',
// if the value is empty, the defaults used in the example above will be used.
'handlers' => '',
@@ -51,7 +52,7 @@
// as the output file. Leave empty if you don't want this functionality.
//
// Config example for using the yuicompressor:
- //'compress_command' => "java -jar " . realpath(dirname(__FILE__)) . "/../../yuicompressor-2.3.5.jar -o %2\$s %1\$s",
+ //'compress_command' => "java -jar " . realpath(dirname(__FILE__)) . "/yuicompressor-2.3.5.jar -o %2\$s %1\$s",
'compress_command' => '',
// Configurable classes to use, this way we provide extensibility for what
@@ -81,15 +82,21 @@
'base_path' => realpath(dirname(__FILE__))
);
+class ConfigException extends Exception {}
+
/**
* Abstracts how to retrieve configuration values so we can replace the
* not so pretty $config array some day.
*
- */class Config {
+ */
+class Config {
static function get($key)
{
- global $config;
- return $config[$key];
+ global $shindigConfig;
+ if (isset($shindigConfig[$key])) {
+ return $shindigConfig[$key];
+ } else {
+ throw new ConfigException("Invalid Config Key");
+ }
}
-
}
Modified: incubator/shindig/trunk/php/src/common/BlobCrypter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/BlobCrypter.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/BlobCrypter.php (original)
+++ incubator/shindig/trunk/php/src/common/BlobCrypter.php Tue May 6 04:55:16 2008
@@ -18,8 +18,7 @@
* under the License.
*/
-class BlobCrypterException extends Exception {
-}
+class BlobCrypterException extends Exception {}
/**
* Utility interface for managing signed, encrypted, and time stamped blobs.
Modified: incubator/shindig/trunk/php/src/common/Cache.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Cache.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/Cache.php (original)
+++ incubator/shindig/trunk/php/src/common/Cache.php Tue May 6 04:55:16 2008
@@ -18,8 +18,7 @@
*
*/
-class CacheException extends Exception {
-}
+class CacheException extends Exception {}
abstract class Cache {
Modified: incubator/shindig/trunk/php/src/common/Crypto.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Crypto.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/Crypto.php (original)
+++ incubator/shindig/trunk/php/src/common/Crypto.php Tue May 6 04:55:16 2008
@@ -18,8 +18,7 @@
* under the License.
*/
-class GeneralSecurityException extends Exception {
-}
+class GeneralSecurityException extends Exception {}
final class Crypto {
Modified: incubator/shindig/trunk/php/src/common/HttpServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/HttpServlet.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/HttpServlet.php (original)
+++ incubator/shindig/trunk/php/src/common/HttpServlet.php Tue May 6 04:55:16 2008
@@ -71,7 +71,7 @@
} else {
// attempt at some propper header handling from php
// this departs a little from the shindig code but it should give is valid http protocol handling
- header('Cache-Control: public,max-age=' . Config::get('cache_time') . ',must-revalidate');
+ header('Cache-Control: public,max-age=' . Config::get('cache_time'));
header("Expires: " . gmdate("D, d M Y H:i:s", time() + Config::get('cache_time')) . " GMT");
// 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'))) {
Modified: incubator/shindig/trunk/php/src/common/Locale.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Locale.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/Locale.php (original)
+++ incubator/shindig/trunk/php/src/common/Locale.php Tue May 6 04:55:16 2008
@@ -3,7 +3,7 @@
/**
* Locale class doesn't exist in php, so to allow the code base to be closer to the java and it's spec
* interpretation one, we created our own
- */
+ */
class Locale {
public $language;
public $country;
Modified: incubator/shindig/trunk/php/src/common/RemoteContent.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContent.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContent.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContent.php Tue May 6 04:55:16 2008
@@ -26,8 +26,7 @@
* it's kept in the spirit of the java variant as much as possible
*/
-class RemoteContentException extends Exception {
-}
+class RemoteContentException extends Exception {}
abstract class RemoteContent {
Added: incubator/shindig/trunk/php/src/common/UrlGenerator.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/UrlGenerator.php?rev=653753&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/UrlGenerator.php (added)
+++ incubator/shindig/trunk/php/src/common/UrlGenerator.php Tue May 6 04:55:16 2008
@@ -0,0 +1,29 @@
+<?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.
+ *
+ */
+
+class UrlGenerator {
+ static function getIframeURL($gadget)
+ {
+ //TODO this
+ // returns fake demo value to make the basic JsonRpc service work
+ // note: put the URL last, else some browsers seem to get confused (reported by hi5)
+ return "/gadgets/ifr?container=default&mid=1&v=db18c863f15d5d1e758a91f2a44881b4&lang=en&country=US&url=http%3A%2F%2Fwww.google.com%2Fig%2Fmodules%2Fhello.xml";
+ }
+}
Modified: incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ContainerConfig.php Tue May 6 04:55:16 2008
@@ -1,4 +1,22 @@
-<?
+<?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.
+ *
+ */
class ContainerConfig {
public $default_container = 'default';
@@ -17,7 +35,7 @@
if (! file_exists($containers) || ! is_dir($containers)) {
throw new Exception("Invalid container path");
}
- foreach ( glob("$containers/*.js") as $file ) {
+ foreach (glob("$containers/*.js") as $file) {
if (! is_readable($file)) {
throw new Exception("Could not read container config: $file");
}
@@ -42,7 +60,7 @@
}
$container = $config[$this->container_key][0];
$this->config[$container] = array();
- foreach ( $config as $key => $val ) {
+ foreach ($config as $key => $val) {
$this->config[$container][$key] = $val;
}
}
@@ -56,6 +74,7 @@
if ($container != $this->default_container && isset($this->config[$container][$name])) {
$config = $this->mergeConfig($this->config[$container][$name], $config);
}
+
return $config;
}
@@ -66,15 +85,15 @@
{
$arrays = func_get_args();
$narrays = count($arrays);
- for($i = 0; $i < $narrays; $i ++) {
+ for ($i = 0; $i < $narrays; $i ++) {
if (! is_array($arrays[$i])) {
trigger_error('Argument #' . ($i + 1) . ' is not an array - trying to merge array with scalar! Returning null!', E_USER_WARNING);
return null;
}
}
$ret = $arrays[0];
- for($i = 1; $i < $narrays; $i ++) {
- foreach ( $arrays[$i] as $key => $value ) {
+ for ($i = 1; $i < $narrays; $i ++) {
+ foreach ($arrays[$i] as $key => $value) {
if (((string)$key) === ((string)intval($key))) { // integer or string as integer key - append
$ret[] = $value;
} else {
Modified: incubator/shindig/trunk/php/src/gadgets/Gadget.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/Gadget.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/Gadget.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/Gadget.php Tue May 6 04:55:16 2008
@@ -36,8 +36,6 @@
public $authorEmail;
public $description;
public $directoryTitle;
- public $contentType;
- public $contentHref;
public $contentData = array();
public $localeSpecs = array();
public $preloads = array();
@@ -64,7 +62,8 @@
public $renderInline;
public $scaling;
public $scrolling;
-
+ public $views = array();
+
public function __construct($id = false, $context)
{
if ($id) {
@@ -97,27 +96,6 @@
return $this->substitutions->substitute($this->authorEmail);
}
- public function getContentData($view = false)
- {
- if (empty($view) || ! $view) {
- $view = DEFAULT_VIEW;
- }
- if ($this->contentType != 'HTML') {
- throw new SpecParserException("getContentData() requires contentType HTML");
- }
- if (!isset($this->contentData[$view]) && isset($this->contentData['default'])) {
- $view = 'default';
- } elseif (!isset($this->contentData[$view]) && isset($this->contentData['*'])) {
- $view = '*';
- }
- return $this->substitutions->substitute(isset($this->contentData[$view]) ? trim($this->contentData[$view]) : '');
- }
-
- public function getContentHref()
- {
- return $this->substitutions->substitute($this->getContentType() == 'URL' ? $this->contentHref : null);
- }
-
public function getMessageBundle()
{
return $this->messageBundle;
@@ -168,7 +146,7 @@
public function getPreloads()
{
$ret = array();
- foreach ( $this->preloads as $preload ) {
+ foreach ($this->preloads as $preload) {
$ret[] = $this->substitutions->substitute($preload);
}
return $ret;
@@ -198,7 +176,7 @@
{
return $this->substitutions->substitute($this->title);
}
-
+
public function getTitleUrl()
{
$ret = null;
@@ -285,12 +263,12 @@
public function getScaling()
{
- return $this->scaling;
+ return $this->scaling;
}
public function getScrolling()
{
- return $this->scrolling;
+ return $this->scrolling;
}
public function getUserPrefs()
@@ -308,21 +286,14 @@
$this->messageBundle = $messageBundle;
}
- /* gadget Spec functions */
- public function addContent($view, $data)
+ public function getViews()
{
- if (empty($view)) {
- $view = DEFAULT_VIEW;
- }
- if (! isset($this->contentData[$view])) {
- $this->contentData[$view] = '';
- }
- $this->contentData[$view] .= $data;
+ return $this->views;
}
- public function getContentType()
+ public function getView($viewName)
{
- return $this->contentType;
+ return $this->views[$viewName];
}
}
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetContext.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetContext.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetContext.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetContext.php Tue May 6 04:55:16 2008
@@ -55,17 +55,17 @@
$this->setView($this->getViewParam());
$this->setContainer($this->getContainerParam());
//NOTE All classes are initialized when called (aka lazy loading) because we don't
- //need all of them in every situation
+ //need all of them in every situation
}
private function getContainerParam()
{
$container = 'default';
- if (!empty($_GET['container'])) {
+ if (! empty($_GET['container'])) {
$container = $_GET['container'];
} elseif (! empty($_POST['container'])) {
$container = $_POST['container'];
- //FIXME The paramater used to be called 'synd' & is scheduled for removal
+ //FIXME The paramater used to be called 'synd' & is scheduled for removal
} elseif (! empty($_GET['synd'])) {
$container = $_GET['synd'];
} elseif (! empty($_POST['synd'])) {
@@ -119,7 +119,7 @@
{
$prefs = array();
$userPrefParamPrefix = Config::get('userpref_param_prefix');
- foreach ( $_GET as $key => $val ) {
+ foreach ($_GET as $key => $val) {
if (substr($key, 0, strlen($userPrefParamPrefix)) == $userPrefParamPrefix) {
$name = substr($key, strlen($userPrefParamPrefix));
$prefs[$name] = $val;
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetException.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetException.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetException.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetException.php Tue May 6 04:55:16 2008
@@ -1,5 +1,4 @@
<?php
-class GadgetException extends Exception {
-}
+class GadgetException extends Exception {}
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetFeatureRegistry.php Tue May 6 04:55:16 2008
@@ -39,14 +39,14 @@
$loader = new JsFeatureLoader($this->debug);
$jsFeatures = $loader->loadFeatures($featurePath, $this);
if (! $this->coreDone) {
- foreach ( $jsFeatures as $entry ) {
+ foreach ($jsFeatures as $entry) {
if (strtolower(substr($entry->name, 0, strlen('core'))) == 'core') {
$coreDeps[] = $entry->name;
$this->core[$entry->name] = $entry->name;
}
}
// Make sure non-core features depend on core.
- foreach ( $jsFeatures as $entry ) {
+ foreach ($jsFeatures as $entry) {
if (strtolower(substr($entry->name, 0, strlen('core'))) != 'core') {
$entry->deps = array_merge($entry->deps, $this->core);
}
@@ -89,7 +89,7 @@
$resultsFound = $this->core;
return true;
}
- foreach ( $needed as $featureName ) {
+ foreach ($needed as $featureName) {
$entry = isset($this->features[$featureName]) ? $this->features[$featureName] : null;
if ($entry == null) {
$resultsMissing[] = $featureName;
@@ -102,7 +102,7 @@
private function addEntryToSet(&$results, $entry)
{
- foreach ( $entry->deps as $dep ) {
+ foreach ($entry->deps as $dep) {
$this->addEntryToSet($results, $this->features[$dep]);
}
$results[$entry->name] = $entry->name;
@@ -124,7 +124,7 @@
{
$this->name = $name;
if ($deps != null) {
- foreach ( $deps as $dep ) {
+ foreach ($deps as $dep) {
$entry = $registry->getEntry($dep);
$this->deps[$entry->name] = $entry->name;
}
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetServer.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetServer.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetServer.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetServer.php Tue May 6 04:55:16 2008
@@ -65,7 +65,7 @@
private function localeSpec($gadget, $locale)
{
$localeSpecs = $gadget->getLocaleSpecs();
- foreach ( $localeSpecs as $locSpec ) {
+ foreach ($localeSpecs as $locSpec) {
//fix me
if ($locSpec->getLocale()->equals($locale)) {
return $locSpec;
@@ -125,7 +125,7 @@
// userPref's
$upValues = $gadget->getUserPrefValues();
- foreach ( $gadget->getUserPrefs() as $pref ) {
+ foreach ($gadget->getUserPrefs() as $pref) {
$name = $pref->getName();
$value = $upValues->getPref($name);
if ($value == null) {
@@ -141,7 +141,7 @@
$requires = $gadget->getRequires();
$needed = array();
$optionalNames = array();
- foreach ( $requires as $key => $entry ) {
+ foreach ($requires as $key => $entry) {
$needed[] = $key;
if ($entry->isOptional()) {
$optionalNames[] = $key;
@@ -152,7 +152,7 @@
$missingOptional = array();
$missingRequired = array();
$context->getRegistry()->getIncludedFeatures($needed, $resultsFound, $resultsMissing);
- foreach ( $resultsMissing as $missingResult ) {
+ foreach ($resultsMissing as $missingResult) {
if (in_array($missingResult, $optionalNames)) {
$missingOptional[$missingResult] = $missingResult;
} else {
@@ -164,16 +164,16 @@
}
// create features
$features = array();
- foreach ( $resultsFound as $entry ) {
+ foreach ($resultsFound as $entry) {
$features[$entry] = $context->getRegistry()->getEntry($entry)->getFeature()->create();
}
// prepare them
- foreach ( $features as $key => $feature ) {
+ foreach ($features as $key => $feature) {
$params = $gadget->getFeatureParams($gadget, $context->getRegistry()->getEntry($key));
$feature->prepare($gadget, $context, $params);
}
// and process them
- foreach ( $features as $key => $feature ) {
+ foreach ($features as $key => $feature) {
$params = $gadget->getFeatureParams($gadget, $context->getRegistry()->getEntry($key));
$feature->process($gadget, $context, $params);
}
Modified: incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetSpecParser.php Tue May 6 04:55:16 2008
@@ -18,12 +18,10 @@
*
*/
-class SpecParserException extends Exception {
-}
+class SpecParserException extends Exception {}
class GadgetSpecParser {
- //public function parse(GadgetId $id, String $xml)
public function parse($xml, $context)
{
if (empty($xml)) {
@@ -40,20 +38,19 @@
// process ModulePref attributes
$this->processModulePrefs($gadget, $doc->ModulePrefs);
// process UserPrefs, if any
- foreach ( $doc->UserPref as $pref ) {
+ foreach ($doc->UserPref as $pref) {
$this->processUserPref($gadget, $pref);
}
- foreach ( $doc->Content as $content ) {
+ foreach ($doc->Content as $content) {
$this->processContent($gadget, $content);
}
- //FIXME : should we add an else { throw new SpecParserException("Missing <Content> block"); } here ? Java version doesn't but it seems like we should ?
- foreach ( $doc->ModulePrefs->Require as $feature ) {
+ foreach ($doc->ModulePrefs->Require as $feature) {
$this->processFeature($gadget, $feature, true);
}
- foreach ( $doc->ModulePrefs->Optional as $feature ) {
+ foreach ($doc->ModulePrefs->Optional as $feature) {
$this->processFeature($gadget, $feature, false);
}
- //TODO java version has a todo here for parsing icons
+ //TODO Parse icons
return $gadget;
}
@@ -63,9 +60,9 @@
if (empty($attributes['title'])) {
throw new SpecParserException("Missing or empty \"title\" attribute.");
}
- // Get ModulePrefs attributes
- // (trim is used here since it not only cleans up the text, but also auto-casts the SimpleXMLElement to a string)
+ // Get ModulePrefs base and extended attributes
// See http://code.google.com/apis/gadgets/docs/gadgets-extended-xsd.html
+ // (trim is used here since it not only cleans up the text, but also auto-casts the SimpleXMLElement to a string)
$gadget->title = trim($attributes['title']);
$gadget->author = isset($attributes['author']) ? trim($attributes['author']) : '';
$gadget->authorEmail = isset($attributes['author_email']) ? trim($attributes['author_email']) : '';
@@ -92,7 +89,7 @@
$gadget->renderInline = isset($attributes['render_inline']) ? trim($attributes['render_inline']) : '';
$gadget->scaling = isset($attributes['scaling']) ? trim($attributes['scaling']) : '';
$gadget->scrolling = isset($attributes['scrolling']) ? trim($attributes['scrolling']) : '';
- foreach ( $ModulePrefs->Locale as $locale ) {
+ foreach ($ModulePrefs->Locale as $locale) {
$gadget->localeSpecs[] = $this->processLocale($locale);
}
}
@@ -126,7 +123,7 @@
$preference->dataType = isset($attributes['datatype']) && in_array(strtoupper($attributes['datatype']), $preference->DataTypes) ? strtoupper($attributes['datatype']) : 'STRING';
$preference->defaultValue = isset($attributes['default_value']) ? trim($attributes['default_value']) : '';
if (isset($pref->EnumValue)) {
- foreach ( $pref->EnumValue as $enum ) {
+ foreach ($pref->EnumValue as $enum) {
$attr = $enum->attributes();
// java based shindig doesn't throw an exception here, but it -is- invalid and should trigger a parse error
if (empty($attr['value'])) {
@@ -146,21 +143,22 @@
if (empty($attributes['type'])) {
throw new SpecParserException("No content type specified!");
}
- $type = trim($attributes['type']);
- if ($type == 'url') {
- if (empty($attributes['href'])) {
- throw new SpecParserException("Malformed <Content> href value");
+ $view = isset($attributes['view']) ? trim($attributes['view']) : '';
+ $views = explode(',', $view);
+ $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;
}
- $url = trim($attributes['href']);
- $gadget->contentType = 'URL';
- $gadget->contentHref = $url;
- } else {
- $gadget->contentType = 'HTML';
- $html = (string)$content; // no trim here since empty lines can have structural meaning, so typecast to string instead
- $view = isset($attributes['view']) ? trim($attributes['view']) : '';
- $views = explode(',', $view);
- foreach ( $views as $view ) {
- $gadget->addContent($view, $html);
+ $viewSpec = new ViewSpec($view, $content);
+ if (! isset($gadget->views[$view])) {
+ $viewSpec->content = $html;
+ $gadget->views[$view] = $viewSpec;
+ } else {
+ if ($gadget->views[$view]->getName() == $viewSpec->getName() && $viewSpec->getType() != $gadget->views[$view]->getType()) {
+ throw new SpecParserException("You may not mix content " . " types in the same view.");
+ }
+ $gadget->views[$view]->addContent($html);
}
}
}
@@ -170,11 +168,11 @@
$featureSpec = new FeatureSpec();
$attributes = $feature->attributes();
if (empty($attributes['feature'])) {
- throw new SpecParserException("Feature not specified in <" . (required ? "Required" : "Optional") . "> tag");
+ throw new SpecParserException("Feature not specified in <" . ($required ? "Required" : "Optional") . "> tag");
}
$featureSpec->name = trim($attributes['feature']);
$featureSpec->optional = ! $required;
- foreach ( $feature->Param as $param ) {
+ foreach ($feature->Param as $param) {
$attr = $param->attributes();
if (empty($attr['name'])) {
throw new SpecParserException("Missing name attribute in <Param>.");
Modified: incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/JsFeatureLoader.php Tue May 6 04:55:16 2008
@@ -33,7 +33,7 @@
$deps = array();
$deps = $this->loadFiles($path, $deps);
// This ensures that we register everything in the right order.
- foreach ( $deps as $entry ) {
+ foreach ($deps as $entry) {
$feature = $entry;
$feat = $this->register($registry, $feature, $registered, $deps);
if ($feat != null) {
@@ -46,7 +46,7 @@
private function loadFiles($path, &$features)
{
if (is_dir($path)) {
- foreach ( glob("$path/*") as $file ) {
+ foreach (glob("$path/*") as $file) {
// prevents us from looping over '.', '..' and 'hidden files', this last bit IS
// different from the java version but it's the unix standard really..
if (substr(basename($file), 0, 1) != '.') {
@@ -80,7 +80,7 @@
if (isset($registered[$feature->name])) {
return null;
}
- foreach ( $feature->deps as $dep ) {
+ foreach ($feature->deps as $dep) {
if (isset($all[$dep]) && ! in_array($dep, $registered)) {
$this->register($registry, $all[$dep], $registered, $all);
}
@@ -100,13 +100,13 @@
}
$feature->name = trim($doc->name);
- foreach ( $doc->gadget as $gadget ) {
+ foreach ($doc->gadget as $gadget) {
$feature = $this->processContext($feature, $gadget, false);
}
- foreach ( $doc->container as $container ) {
+ foreach ($doc->container as $container) {
$feature = $this->processContext($feature, $container, true);
}
- foreach ( $doc->dependency as $dependency ) {
+ foreach ($doc->dependency as $dependency) {
$feature->deps[] = trim($dependency);
}
return $feature;
@@ -114,7 +114,7 @@
private function processContext(&$feature, $context, $isContainer)
{
- foreach ( $context->script as $script ) {
+ foreach ($context->script as $script) {
$attributes = $script->attributes();
if (! isset($attributes['src'])) {
// inline content
Modified: incubator/shindig/trunk/php/src/gadgets/JsLibrary.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/JsLibrary.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/JsLibrary.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/JsLibrary.php Tue May 6 04:55:16 2008
@@ -82,7 +82,6 @@
static private function loadFile($fileName, $debug)
{
- global $config;
if (empty($fileName)) {
return '';
}
@@ -95,15 +94,16 @@
if (! is_readable($fileName)) {
throw new Exception("JsLibrary file not readable: $fileName");
}
- if ($debug || empty($config['compress_command'])) {
+ $compressCommand = Config::get('compress_command');
+ if ($debug || empty($compressCommand)) {
if (! ($content = @file_get_contents($fileName))) {
throw new Exception("JsLibrary error reading file: $fileName");
}
} else {
// attempt to compress the feature javascript file
$input_file = escapeshellarg($fileName);
- $output_file = tempnam($config['cache_root'], 'js-comp');
- $cmd = sprintf($config['compress_command'], $input_file, $output_file);
+ $output_file = tempnam(Config::get('cache_root'), 'js-comp');
+ $cmd = sprintf($compressCommand, $input_file, $output_file);
$null = $status = 0;
exec($cmd, $null, $status);
if ($status === 0) {
Modified: incubator/shindig/trunk/php/src/gadgets/JsLibraryFeatureFactory.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/JsLibraryFeatureFactory.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/JsLibraryFeatureFactory.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/JsLibraryFeatureFactory.php Tue May 6 04:55:16 2008
@@ -66,7 +66,7 @@
{
$libraries = array();
$libraries = $context->getRenderingContext() == 'GADGET' ? $this->gadgetLibraries : $this->containerLibraries;
- foreach ( $libraries as $library ) {
+ foreach ($libraries as $library) {
$gadget->addJsLibrary($library);
}
}
Modified: incubator/shindig/trunk/php/src/gadgets/JsonRpcGadgetContext.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/JsonRpcGadgetContext.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/JsonRpcGadgetContext.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/JsonRpcGadgetContext.php Tue May 6 04:55:16 2008
@@ -5,7 +5,7 @@
private $view = null;
private $url = null;
private $container = null;
-
+
public function __construct($jsonContext, $url)
{
parent::__construct('GADGET');
Modified: incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/JsonRpcHandler.php Tue May 6 04:55:16 2008
@@ -5,7 +5,7 @@
public function process($requests)
{
$response = array();
- foreach ( $requests->gadgets as $gadget ) {
+ foreach ($requests->gadgets as $gadget) {
try {
$gadgetUrl = $gadget->url;
$gadgetModuleId = $gadget->moduleId;
@@ -13,7 +13,7 @@
$gadgetServer = new GadgetServer();
$gadget = $gadgetServer->processGadget($context);
$response[] = $this->makeResponse($gadget, $gadgetModuleId, $gadgetUrl);
- } catch ( Exception $e ) {
+ } catch (Exception $e) {
$response[] = array('errors' => array($e->getMessage()), 'moduleId' => $gadgetModuleId, 'url' => $gadgetUrl);
}
}
@@ -25,12 +25,7 @@
$response = array();
$prefs = array();
foreach ($gadget->getUserPrefs() as $pref) {
- $prefs[$pref->getName()] = array(
- 'displayName' => $pref->getDisplayName(),
- 'type' => $pref->getDataType(),
- 'default' => $pref->getDefaultValue(),
- 'enumValues' => $pref->getEnumValues()
- );
+ $prefs[$pref->getName()] = array('displayName' => $pref->getDisplayName(), 'type' => $pref->getDataType(), 'default' => $pref->getDefaultValue(), 'enumValues' => $pref->getEnumValues());
}
$features = array();
foreach ($gadget->getRequires() as $feature) {
@@ -45,8 +40,8 @@
$response['title'] = $gadget->getTitle();
$response['singleton'] = $gadget->getSingleton();
$response['categories'] = Array($gadget->getCategory(), $gadget->getCategory2());
- $response['views'] ='';
- /*stdClass Object
+ $response['views'] = '';
+ /*stdClass Object
(
$response['default'] = stdClass Object
(
@@ -55,7 +50,7 @@
)
)*/
- $response['description'] = $gadget->getDescription();
+ $response['description'] = $gadget->getDescription();
$response['screenshot'] = $gadget->getScreenShot();
$response['thumbnail'] = $gadget->getThumbnail();
$response['height'] = $gadget->getHeight();
@@ -69,7 +64,7 @@
$response['titleUrl'] = $gadget->getTitleUrl();
$response['directoryTitle'] = $gadget->getDirectoryTitle();
$response['author'] = $gadget->getAuthor();
- $response['iframeUrl'] = "/gadgets/ifr?url=http%3A%2F%2Fwww.google.com%2Fig%2Fmodules%2Fhello.xml&container=default&mid=1&v=db18c863f15d5d1e758a91f2a44881b4&lang=en&country=US";
+ $response['iframeUrl'] = UrlGenerator::getIframeURL($gadget);
$response['userPrefs'] = $prefs;
return $response;
}
Modified: incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/MessageBundleParser.php Tue May 6 04:55:16 2008
@@ -32,8 +32,10 @@
{
$doc = simplexml_load_string($xml);
$messages = array();
- foreach ( $doc->msg as $msg ) {
- $this->processMessage($messages, $msg);
+ if (isset($doc->msg)) {
+ foreach ($doc->msg as $msg) {
+ $this->processMessage($messages, $msg);
+ }
}
return new MessageBundle($messages);
}
Modified: incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php Tue May 6 04:55:16 2008
@@ -84,7 +84,12 @@
*/
public function fetch($url, $signer, $method)
{
- $token = $this->extractAndValidateToken($signer);
+ try {
+ $token = $this->extractAndValidateToken($signer);
+ } catch (Exception $e) {
+ $token = '';
+ // no token given, safe to ignore
+ }
$originalUrl = $this->validateUrl($url);
$signedUrl = $this->signUrl($originalUrl, $token);
//TODO: Fetcher needs to handle variety of HTTP methods.
Modified: incubator/shindig/trunk/php/src/gadgets/Substitutions.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/Substitutions.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/Substitutions.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/Substitutions.php Tue May 6 04:55:16 2008
@@ -25,7 +25,7 @@
public function __construct()
{
- foreach ( $this->types as $type ) {
+ foreach ($this->types as $type) {
$this->substitutions[$type] = array();
}
}
@@ -37,14 +37,14 @@
public function addSubstitutions($type, $array)
{
- foreach ( $array as $key => $value ) {
+ foreach ($array as $key => $value) {
$this->addSubstitution($type, $key, $value);
}
}
public function substitute($input)
{
- foreach ( $this->types as $type ) {
+ foreach ($this->types as $type) {
$input = $this->substituteType($type, $input);
}
return $input;
Added: incubator/shindig/trunk/php/src/gadgets/ViewSpec.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ViewSpec.php?rev=653753&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ViewSpec.php (added)
+++ incubator/shindig/trunk/php/src/gadgets/ViewSpec.php Tue May 6 04:55:16 2008
@@ -0,0 +1,90 @@
+<?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.
+ *
+ */
+
+/**
+ * Represents a Content section, but normalized into an individual
+ * view value after views are split on commas.
+ */
+class ViewSpec {
+
+ public $name;
+ public $type;
+ public $href;
+ public $quirks;
+ public $content;
+ public $view;
+
+ public function __construct($name, $gadgetContent)
+ {
+ $attributes = $gadgetContent->attributes();
+ $this->name = $name;
+ $this->view = isset($attributes['view']) ? trim($attributes['view']) : '';
+ $this->quirks = trim($attributes['quirks']);
+ if (empty($this->quirks)) {
+ $this->quirks = true;
+ } else {
+ $this->quirks = false;
+ }
+ if (strtolower(trim($attributes['type'])) == 'url') {
+ if (empty($attributes['href'])) {
+ throw new SpecParserException("Malformed <Content> href value");
+ }
+ $this->type = 'URL';
+ $this->href = trim($attributes['href']);
+ } else {
+ $this->type = 'HTML';
+ }
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function getHref()
+ {
+ return $this->href;
+ }
+
+ public function getQuirks()
+ {
+ return $this->quirks;
+ }
+
+ public function getContent()
+ {
+ return $this->content;
+ }
+
+ public function getView()
+ {
+ return $this->view;
+ }
+
+ public function addContent($data)
+ {
+ $this->content .= $data;
+ }
+}
Modified: incubator/shindig/trunk/php/src/gadgets/http/FilesServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/FilesServlet.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/FilesServlet.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/http/FilesServlet.php Tue May 6 04:55:16 2008
@@ -61,7 +61,6 @@
$this->setContentType('text/css');
}
}
- $this->setNoCache(true);
$this->setLastModified(filemtime($file));
readfile($file);
}
Modified: incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/http/GadgetRenderingServlet.php Tue May 6 04:55:16 2008
@@ -25,7 +25,7 @@
*
*/
class GadgetRenderingServlet extends HttpServlet {
- private $context;
+ private $context;
/**
* Creates the gadget using the GadgetServer class and calls outputGadget
@@ -33,7 +33,7 @@
*/
public function doGet()
{
- try {
+ try {
if (empty($_GET['url'])) {
throw new GadgetException("Missing required parameter: url");
}
@@ -77,14 +77,15 @@
* @param Gadget $gadget gadget to render
* @param string $view the view to render (only valid with a html content type)
*/
- private function outputGadget($gadget, $view)
- {
- switch ( $gadget->getContentType()) {
+ private function outputGadget($gadget, $context)
+ {
+ $view = HttpUtil::getView($gadget, $context);
+ switch ($view->getType()) {
case 'HTML' :
- $this->outputHtmlGadget($gadget, $view);
+ $this->outputHtmlGadget($gadget, $context, $view);
break;
case 'URL' :
- $this->outputUrlGadget($gadget);
+ $this->outputUrlGadget($gadget, $context, $view);
break;
}
}
@@ -99,10 +100,13 @@
* @param Gadget $gadget
* @param GadgetContext $context
*/
- private function outputHtmlGadget($gadget, $context)
- {
+ private function outputHtmlGadget($gadget, $context, $view)
+ {
$this->setContentType("text/html; charset=UTF-8");
- $output = '';
+ $output = '';
+ if (!$view->getQuirks()) {
+ $output .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">";
+ }
$output .= "<html>\n<head>\n";
// TODO: This is so wrong. (todo copied from java shindig, but i would agree with it :))
$output .= "<style type=\"text/css\">body,td,div,span,p{font-family:arial,sans-serif;} a {color:#0000cc;}a:visited {color:#551a8b;}a:active {color:#ff0000;}body{margin: 0px;padding: 0px;background-color:white;}</style>\n";
@@ -138,16 +142,14 @@
if (strlen($externJs) > 0) {
$output .= $externJs;
}
-
$output .= "<script><!--\n";
$output .= $this->appendJsConfig($context, $gadget);
$output .= $this->appendMessages($gadget);
$output .= "-->\n</script>\n";
-
$gadgetExceptions = array();
- $content = $gadget->getContentData($context->getView());
+ $content = $gadget->getSubstitutions()->substitute($view->getContent());
if (empty($content)) {
- // unknown view
+ // Unknown view
$gadgetExceptions[] = "View: '" . $context->getView() . "' invalid for gadget: " . $gadget->getId()->getKey();
}
if (count($gadgetExceptions)) {
@@ -168,10 +170,10 @@
*
* @param Gadget $gadget
*/
- private function outputUrlGadget($gadget)
- {
+ private function outputUrlGadget($gadget, $context, $view)
+ {
// Preserve existing query string parameters.
- $redirURI = $gadget->getContentHref();
+ $redirURI = $view->getHref();
$queryStr = strpos($redirURI, '?') !== false ? substr($redirURI, strpos($redirURI, '?')) : '';
$query = $queryStr;
// TODO: userprefs on the fragment rather than query string
Added: incubator/shindig/trunk/php/src/gadgets/http/HttpUtil.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/HttpUtil.php?rev=653753&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/HttpUtil.php (added)
+++ incubator/shindig/trunk/php/src/gadgets/http/HttpUtil.php Tue May 6 04:55:16 2008
@@ -0,0 +1,49 @@
+<?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.
+ *
+ */
+
+/**
+ * Collection of HTTP utilities
+ */
+class HttpUtil {
+
+ static public function getView($gadget, $context)
+ {
+ $view = $gadget->getView($context->getView());
+ if (empty($view)) {
+ $containerConfig = $context->getContainerConfig();
+ $config = $containerConfig->getConfig('default', 'gadgets.features');
+ $configViews = $config['views'];
+ $views = $configViews[$context->getView()];
+ if (!empty($views)) {
+ $aliasesViews = $views['aliases'];
+ for ($i = 0; $i < count($aliasesViews); $i++) {
+ $view = $gadget->getView($aliasesViews[$i]);
+ if (!empty($view)) {
+ break;
+ }
+ }
+ }
+ if (empty($view)) {
+ $view = $gadget->getView(DEFAULT_VIEW);
+ }
+ }
+ return $view;
+ }
+}
Modified: incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/http/JsonRpcServlet.php Tue May 6 04:55:16 2008
@@ -39,7 +39,7 @@
header("HTTP/1.0 500 Internal Server Error", true, 500);
echo "<html><body><h1>Internal Server Error</h1><br />";
if (Config::get('debug')) {
- echo $e->getMessage()."<br /><pre>";
+ echo $e->getMessage() . "<br /><pre>";
print_r(debug_backtrace());
echo "</pre>";
}
Modified: incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php Tue May 6 04:55:16 2008
@@ -22,7 +22,6 @@
public function doGet()
{
- global $config;
$this->noHeaders = true;
$context = new GadgetContext('GADGET');
// those should be doable in one statement, but php seems to still evauluate the second ? and : pair,
@@ -40,7 +39,8 @@
header("HTTP/1.0 400 Bad Request", true);
echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
}
- $gadgetSigner = new $config['gadget_signer']();
+ $gadgetSigner = Config::get('gadget_signer');
+ $gadgetSigner = new $gadgetSigner();
$proxyHandler = new ProxyHandler($context);
if (! empty($_GET['output']) && $_GET['output'] == 'js') {
$proxyHandler->fetchJson($url, $gadgetSigner, $method);
Modified: incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicBlobCrypter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicBlobCrypter.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicBlobCrypter.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicBlobCrypter.php Tue May 6 04:55:16 2008
@@ -4,8 +4,7 @@
*
*/
-class BlobExpiredException extends Exception {
-}
+class BlobExpiredException extends Exception {}
//FIXME make this compatible with the java's blobcrypter
class BasicBlobCrypter extends BlobCrypter {
@@ -49,7 +48,7 @@
private function serializeAndTimestamp(Array $in)
{
$encoded = "";
- foreach ( $in as $key => $val ) {
+ foreach ($in as $key => $val) {
$encoded .= urlencode($key) . "=" . urlencode($val) . "&";
}
$encoded .= $this->TIMESTAMP_KEY . "=" . time();
Modified: incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetBlacklist.php Tue May 6 04:55:16 2008
@@ -23,8 +23,7 @@
public function __construct()
{
- global $config;
- $file = $config['base_path'] . '/blacklist.txt';
+ $file = Config::get('base_path') . '/blacklist.txt';
//TODO make this a configurable location
if (file_exists($file) && is_readable($file)) {
$this->rules = explode("\n", file_get_contents($file));
@@ -33,11 +32,11 @@
function isBlacklisted($url)
{
- foreach ( $this->rules as $rule ) {
+ foreach ($this->rules as $rule) {
if (preg_match($rule, $url)) {
return true;
}
}
return false;
}
-}
\ No newline at end of file
+}
Modified: incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetTokenDecoder.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetTokenDecoder.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetTokenDecoder.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicGadgetTokenDecoder.php Tue May 6 04:55:16 2008
@@ -25,12 +25,12 @@
private $CONTAINER_INDEX = 3;
private $APP_URL_INDEX = 4;
private $MODULE_ID_INDEX = 5;
-
+
/**
- * {@inheritDoc}
- *
- * Returns a token with some faked out values.
- */
+ * {@inheritDoc}
+ *
+ * Returns a token with some faked out values.
+ */
public function createToken($stringToken)
{
if (empty($stringToken)) {
@@ -41,15 +41,8 @@
// in the example files
if (Config::get('allow_plaintext_token') && count(explode(':', $stringToken)) == 6) {
$tokens = explode(":", $stringToken);
- return new BasicGadgetToken(null,null,
- urldecode($tokens[$this->OWNER_INDEX]),
- urldecode($tokens[$this->VIEWER_INDEX]),
- urldecode($tokens[$this->APP_ID_INDEX]),
- urldecode($tokens[$this->CONTAINER_INDEX]),
- urldecode($tokens[$this->APP_URL_INDEX]),
- urldecode($tokens[$this->MODULE_ID_INDEX])
- );
- } else {
+ return new BasicGadgetToken(null, null, urldecode($tokens[$this->OWNER_INDEX]), urldecode($tokens[$this->VIEWER_INDEX]), urldecode($tokens[$this->APP_ID_INDEX]), urldecode($tokens[$this->CONTAINER_INDEX]), urldecode($tokens[$this->APP_URL_INDEX]), urldecode($tokens[$this->MODULE_ID_INDEX]));
+ } else {
return BasicGadgetToken::createFromToken($stringToken, Config::get('st_max_age'));
}
} catch (Exception $e) {
Modified: incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContent.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContent.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContent.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContent.php Tue May 6 04:55:16 2008
@@ -22,8 +22,8 @@
public function fetch($request, $context)
{
- global $config;
- $cache = new $config['data_cache']();
+ $cache = Config::get('data_cache');
+ $cache = new $cache();
$remoteContentFetcher = new BasicRemoteContentFetcher();
if (! ($request instanceof RemoteContentRequest)) {
throw new RemoteContentException("Invalid request type in remoteContent");
Modified: incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/samplecontainer/BasicRemoteContentFetcher.php Tue May 6 04:55:16 2008
@@ -39,7 +39,7 @@
if ($request->hasHeaders()) {
$headers = explode("\n", $request->getHeaders());
$outHeaders = array();
- foreach ( $headers as $header ) {
+ foreach ($headers as $header) {
if (strpos($header, ':')) {
$key = trim(substr($header, 0, strpos($header, ':')));
$val = trim(substr($header, strpos($header, ':') + 1));
@@ -59,7 +59,7 @@
$header = '';
$body = '';
// on redirects and such we get multiple headers back from curl it seems, we really only want the last one
- while ( substr($content, 0, strlen('HTTP')) == 'HTTP' && strpos($content, "\r\n\r\n") !== false ) {
+ while (substr($content, 0, strlen('HTTP')) == 'HTTP' && strpos($content, "\r\n\r\n") !== false) {
$header = substr($content, 0, strpos($content, "\r\n\r\n"));
$content = $body = substr($content, strlen($header) + 4);
}
Modified: incubator/shindig/trunk/php/src/socialdata/http/GadgetDataServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/socialdata/http/GadgetDataServlet.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/socialdata/http/GadgetDataServlet.php (original)
+++ incubator/shindig/trunk/php/src/socialdata/http/GadgetDataServlet.php Tue May 6 04:55:16 2008
@@ -18,7 +18,7 @@
$this->handlers[] = new StateFileDataHandler();
} else {
$handlers = explode(',', $handlers);
- foreach ( $handlers as $handler ) {
+ foreach ($handlers as $handler) {
$this->handlers[] = new $handler();
}
}
@@ -41,7 +41,7 @@
try {
$response = new DataResponse($this->createResponse($requestParam, $token));
- } catch ( Exception $e ) {
+ } catch (Exception $e) {
$response = new DataResponse(false, BAD_REQUEST);
}
echo json_encode($response);
@@ -49,11 +49,11 @@
private function createResponse($requestParam, $token)
{
- global $config;
if (empty($token)) {
throw new Exception("INVALID_GADGET_TOKEN");
}
- $gadgetSigner = new $config['gadget_signer']();
+ $gadgetSigner = Config::get('gadget_signer');
+ $gadgetSigner = new $gadgetSigner();
//FIXME currently don't have a propper token, impliment and re-enable this asap
$securityToken = $gadgetSigner->createToken($token);
$responseItems = array();
@@ -63,10 +63,10 @@
// it just returns the original string
throw new Exception("Invalid request JSON");
}
- foreach ( $requests as $request ) {
+ foreach ($requests as $request) {
$requestItem = new RequestItem($request['type'], $request, $securityToken);
$response = new ResponseItem(NOT_IMPLEMENTED, $request['type'] . " has not been implemented yet.", array());
- foreach ( $this->handlers as $handler ) {
+ foreach ($this->handlers as $handler) {
if ($handler->shouldHandle($request['type'])) {
$response = $handler->handleRequest($requestItem);
}
Modified: incubator/shindig/trunk/php/src/socialdata/opensocial/model/idSpec.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/socialdata/opensocial/model/idSpec.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/socialdata/opensocial/model/idSpec.php (original)
+++ incubator/shindig/trunk/php/src/socialdata/opensocial/model/idSpec.php Tue May 6 04:55:16 2008
@@ -53,7 +53,7 @@
$userIdArray = array($userIdArray);
}
$userIds = array();
- foreach ( $userIdArray as $id ) {
+ foreach ($userIdArray as $id) {
$userIds[] = (string)$id;
}
return $userIds;
Modified: incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicActivitiesService.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicActivitiesService.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicActivitiesService.php (original)
+++ incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicActivitiesService.php Tue May 6 04:55:16 2008
@@ -23,7 +23,7 @@
{
$allActivities = XmlStateFileFetcher::get()->getActivities();
$activities = array();
- foreach ( $ids as $id ) {
+ foreach ($ids as $id) {
if (isset($allActivities[$id])) {
$activities[] = $allActivities[$id];
}
Modified: incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicDataService.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicDataService.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicDataService.php (original)
+++ incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicDataService.php Tue May 6 04:55:16 2008
@@ -23,11 +23,11 @@
{
$allData = XmlStateFileFetcher::get()->getAppData();
$data = array();
- foreach ( $ids as $id ) {
+ foreach ($ids as $id) {
if (isset($allData[$id])) {
$allPersonData = $allData[$id];
$personData = array();
- foreach ( array_keys($allPersonData) as $key ) {
+ foreach (array_keys($allPersonData) as $key) {
if (in_array($key, $keys) || $keys[0] == "*") {
$personData[$key] = $allPersonData[$key];
}
@@ -59,7 +59,7 @@
if (empty($key)) {
return false;
}
- for($i = 0; $i < strlen($key); ++ $i) {
+ for ($i = 0; $i < strlen($key); ++ $i) {
$c = substr($key, $i, 1);
if (($c >= 'a' && $c <= 'z') || ($c >= 'A' && $c <= 'Z') || ($c >= '0' && $c <= '9') || ($c == '-') || ($c == '_') || ($c == '.')) {
continue;
Modified: incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicPeopleService.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicPeopleService.php?rev=653753&r1=653752&r2=653753&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicPeopleService.php (original)
+++ incubator/shindig/trunk/php/src/socialdata/samplecontainer/BasicPeopleService.php Tue May 6 04:55:16 2008
@@ -33,7 +33,7 @@
{
$allPeople = XmlStateFileFetcher::get()->getAllPeople();
$people = array();
- foreach ( $ids as $id ) {
+ foreach ($ids as $id) {
$person = null;
if (isset($allPeople[$id])) {
$person = $allPeople[$id];
@@ -53,7 +53,7 @@
$newPerson['isOwner'] = $person->isOwner;
$newPerson['isViewer'] = $person->isViewer;
$newPerson['name'] = $person->name;
- foreach ( $profileDetails as $field ) {
+ foreach ($profileDetails as $field) {
if (isset($person->$field) && ! isset($newPerson[$field])) {
$newPerson[$field] = $person->$field;
}
@@ -82,20 +82,20 @@
{
$friendIds = XmlStateFileFetcher::get()->getFriendIds();
$ids = array();
- switch ( $idSpec->getType()) {
- case 'OWNER' :
+ switch ($idSpec->getType()) {
+ case 'OWNER':
$ids[] = $token->getOwnerId();
break;
- case 'VIEWER' :
+ case 'VIEWER':
$ids[] = $token->getViewerId();
break;
- case 'OWNER_FRIENDS' :
+ case 'OWNER_FRIENDS':
$ids = $friendIds[$token->getOwnerId()];
break;
- case 'VIEWER_FRIENDS' :
+ case 'VIEWER_FRIENDS':
$ids = $friendIds[$token->getViewerId()];
break;
- case 'USER_IDS' :
+ case 'USER_IDS':
$ids = $idSpec->fetchUserIds();
break;
}