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 MetadataHandler
{
23 public function process($requests) {
25 foreach ($requests->gadgets
as $gadget) {
27 $gadgetUrl = $gadget->url
;
28 $gadgetModuleId = $gadget->moduleId
;
29 $context = new MetadataGadgetContext($requests->context
, $gadgetUrl);
30 $gadgetServer = new GadgetFactory($context, null);
31 $gadget = $gadgetServer->createGadget($gadgetUrl);
32 $response[] = $this->makeResponse($gadget, $gadgetModuleId, $gadgetUrl, $context);
33 } catch (Exception
$e) {
34 $response[] = array('errors' => array($e->getMessage()), 'moduleId' => $gadgetModuleId, 'url' => $gadgetUrl);
40 private function getIframeURL(Gadget
$gadget, GadgetContext
$context) {
41 $v = $gadget->getChecksum();
42 $view = $gadget->getView($context->getView());
44 foreach ($gadget->gadgetSpec
->userPrefs
as $pref) {
45 $up .= '&up_' . urlencode($pref['name']) . '=' . urlencode($pref['value']);
47 $locale = $context->getLocale();
48 //Note: putting the URL last, else some browsers seem to get confused (reported by hi5)
49 return Config
::get('default_iframe_prefix') . 'container=' . $context->getContainer() . ($context->getIgnoreCache() ?
'&nocache=1' : '&v=' . $v) . ($context->getModuleId() != 0 ?
'&mid=' . $context->getModuleId() : '') . '&lang=' . $locale['lang'] . '&country=' . $locale['country'] . '&view=' . $view['view'] . $up . '&url=' . urlencode($context->getUrl());
53 private function makeResponse($gadget, $gadgetModuleId, $gadgetUrl, $context) {
56 foreach ($gadget->gadgetSpec
->userPrefs
as $pref) {
57 $prefs[$pref['name']] = $pref;
60 foreach ($gadget->gadgetSpec
->views
as $name => $view) {
61 // we want to include all information, except for the content
62 unset($view['content']);
63 $views[$name] = $view;
68 $oauthspec = $gadget->getOAuthSpec();
69 if (! empty($oauthspec)) {
70 foreach ($oauthspec->getServices() as $oauthservice) {
71 $oauth[$oauthservice->getName()] = array("request" => $oauthservice->getRequestUrl(), "access" => $oauthservice->getAccessUrl(), "authorization" => $oauthservice->getAuthorizationUrl());
76 $response['iframeUrl'] = $this->getIframeURL($gadget, $context);
77 $response['features'] = $gadget->features
;
78 $response['links'] = $gadget->gadgetSpec
->links
;
79 $response['icons'] = $gadget->gadgetSpec
->icon
;
80 $response['views'] = $views;
81 $response['author'] = $gadget->getAuthor();
82 $response['authorEmail'] = $gadget->getAuthorEmail();
83 $response['description'] = $gadget->getDescription();
84 $response['directoryTitle'] = $gadget->getDirectoryTitle();
85 $response['screenshot'] = $gadget->getScreenShot();
86 $response['thumbnail'] = $gadget->getThumbnail();
87 $response['title'] = $gadget->getTitle();
88 $response['titleUrl'] = $gadget->getTitleUrl();
89 $response['authorAffiliation'] = $gadget->getAuthorAffiliation();
90 $response['authorLocation'] = $gadget->getAuthorLocation();
91 $response['authorPhoto'] = $gadget->getAuthorPhoto();
92 $response['authorAboutme'] = $gadget->getAuthorAboutme();
93 $response['authorQuote'] = $gadget->getAuthorQuote();
94 $response['authorLink'] = $gadget->getAuthorLink();
95 $response['showInDirectory'] = $gadget->getShowInDirectory();
96 $response['showStats'] = $gadget->getShowStats();
97 $response['width'] = $gadget->getWidth();
98 $response['height'] = $gadget->getHeight();
99 $response['categories'] = Array($gadget->getCategory(), $gadget->getCategory2());
100 $response['singleton'] = $gadget->getSingleton();
101 $response['scaling'] = $gadget->getScaling();
102 $response['scrolling'] = $gadget->getScrolling();
103 $response['moduleId'] = $gadgetModuleId;
104 $response['url'] = $gadgetUrl;
105 $response['userPrefs'] = $prefs;
106 $response['oauth'] = $oauth;