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
21 class GadgetUrlRenderer
extends GadgetRenderer
{
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
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, '?')) : '';
37 $query .= $this->getPrefsQueryString($gadget->gadgetSpec
->userPrefs
);
39 $forcedLibs = Config
::get('focedJsLibs');
40 if ($forcedLibs == null) {
41 $features = $gadget->features
;
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);
52 header('Location: ' . $redirURI);
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) {
65 $ret .= Config
::get('libs_param_name');
67 $ret .= str_replace('?', '&', $this->getJsUrl($features));
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) {
80 foreach ($prefs as $pref) {
82 $ret .= Config
::get('userpref_param_prefix');
83 $ret .= urlencode($pref['name']);
85 $ret .= urlencode($pref['value']);