SHINDIG-1056 by lipeng, BasicRemoteContentTest doesn't depend on static private key...
[shindig.git] / php / src / gadgets / render / GadgetUrlRenderer.php
blob7c1523c057980a2a39edd30e01735d75f1e15b0a
1 <?php
2 /**
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
21 class GadgetUrlRenderer extends GadgetRenderer {
23 /**
24 * Renders an 'URL' type view (where the iframe is redirected to the specified url)
25 * This is more a legacy iGoogle support feature then something that should be actually
26 * used. Proxied content is the socially aware (and higher performance) version of this
27 * See GadgetHrefRenderer for it's implementation.
29 * @param Gadget $gadget
30 * @param Array $view
32 public function renderGadget(Gadget $gadget, $view) {
33 // Preserve existing query string parameters.
34 $redirURI = $view['href'];
35 $queryStr = strpos($redirURI, '?') !== false ? substr($redirURI, strpos($redirURI, '?')) : '';
36 $query = $queryStr;
37 $query .= $this->getPrefsQueryString($gadget->gadgetSpec->userPrefs);
38 $features = array();
39 $forcedLibs = Config::get('focedJsLibs');
40 if ($forcedLibs == null) {
41 $features = $gadget->features;
42 } else {
43 $features = explode(':', $forcedLibs);
45 $query .= $this->appendLibsToQuery($features);
46 $query .= '&lang=' . urlencode(isset($_GET['lang']) ? $_GET['lang'] : 'en');
47 $query .= '&country=' . urlencode(isset($_GET['country']) ? $_GET['country'] : 'US');
48 if (substr($query, 0, 1) == '&') {
49 $query = '?' . substr($query, 1);
51 $redirURI .= $query;
52 header('Location: ' . $redirURI);
55 /**
56 * Returns the requested libs (from getjsUrl) with the libs_param_name prepended
57 * ie: in libs=core:caja:etc.js format
59 * @param string $libs the libraries
60 * @param Gadget $gadget
61 * @return string the libs=... string to append to the redirection url
63 private function appendLibsToQuery($features) {
64 $ret = "&";
65 $ret .= Config::get('libs_param_name');
66 $ret .= "=";
67 $ret .= str_replace('?', '&', $this->getJsUrl($features));
68 return $ret;
71 /**
72 * Returns the user preferences in &up_<name>=<val> format
74 * @param array $libs array of features this gadget requires
75 * @param Gadget $gadget
76 * @return string the up_<name>=<val> string to use in the redirection url
78 private function getPrefsQueryString($prefs) {
79 $ret = '';
80 foreach ($prefs as $pref) {
81 $ret .= '&';
82 $ret .= Config::get('userpref_param_prefix');
83 $ret .= urlencode($pref['name']);
84 $ret .= '=';
85 $ret .= urlencode($pref['value']);
87 return $ret;