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
22 class GadgetUrlRenderer
extends GadgetRenderer
{
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
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, '?')) : '';
38 $query .= $this->getPrefsQueryString($gadget->gadgetSpec
->userPrefs
);
40 $forcedLibs = Config
::get('focedJsLibs');
41 if ($forcedLibs == null) {
42 $features = $gadget->features
;
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);
53 header('Location: ' . $redirURI);
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) {
66 $ret .= Config
::get('libs_param_name');
68 $ret .= str_replace('?', '&', $this->getJsUrl($features));
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) {
81 foreach ($prefs as $pref) {
83 $ret .= Config
::get('userpref_param_prefix');
84 $ret .= urlencode($pref['name']);
86 $ret .= urlencode($pref['value']);