Re-enabled the iframe generation for the metadata service
[shindig.git] / php / src / gadgets / render / GadgetUrlRenderer.php
blob2c298ce93749eb88b7567afc33f2edc309cdc85d
1 <?php
3 /**
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
22 class GadgetUrlRenderer extends GadgetRenderer {
24 /**
25 * Renders an 'URL' type view (where the iframe is redirected to the specified url)
26 * This is more a legacy iGoogle support feature then something that should be actually
27 * used. Proxied content is the socially aware (and higher performance) version of this
28 * See GadgetHrefRenderer for it's implementation.
30 * @param Gadget $gadget
31 * @param Array $view
33 public function renderGadget(Gadget $gadget, $view) {
34 // Preserve existing query string parameters.
35 $redirURI = $view['href'];
36 $queryStr = strpos($redirURI, '?') !== false ? substr($redirURI, strpos($redirURI, '?')) : '';
37 $query = $queryStr;
38 $query .= $this->getPrefsQueryString($gadget->gadgetSpec->userPrefs);
39 $features = array();
40 $forcedLibs = Config::get('focedJsLibs');
41 if ($forcedLibs == null) {
42 $features = $gadget->features;
43 } else {
44 $features = explode(':', $forcedLibs);
46 $query .= $this->appendLibsToQuery($features);
47 // code bugs out with me because of the invalid url syntax since we dont have a URI class to fix it for us
48 // this works around that
49 if (substr($query, 0, 1) == '&') {
50 $query = '?' . substr($query, 1);
52 $redirURI .= $query;
53 header('Location: ' . $redirURI);
56 /**
57 * Returns the requested libs (from getjsUrl) with the libs_param_name prepended
58 * ie: in libs=core:caja:etc.js format
60 * @param string $libs the libraries
61 * @param Gadget $gadget
62 * @return string the libs=... string to append to the redirection url
64 private function appendLibsToQuery($features) {
65 $ret = "&";
66 $ret .= Config::get('libs_param_name');
67 $ret .= "=";
68 $ret .= str_replace('?', '&', $this->getJsUrl($features));
69 return $ret;
72 /**
73 * Returns the user preferences in &up_<name>=<val> format
75 * @param array $libs array of features this gadget requires
76 * @param Gadget $gadget
77 * @return string the up_<name>=<val> string to use in the redirection url
79 private function getPrefsQueryString($prefs) {
80 $ret = '';
81 foreach ($prefs as $pref) {
82 $ret .= '&';
83 $ret .= Config::get('userpref_param_prefix');
84 $ret .= urlencode($pref['name']);
85 $ret .= '=';
86 $ret .= urlencode($pref['value']);
88 return $ret;