Exemplo n.º 1
0
 /**
  * Parse the gadget views
  *
  * @param DOMDocument $doc
  * @param GadgetSpec $gadget
  */
 private function parseViews(DOMDocument &$doc, GadgetSpec &$gadget)
 {
     $views = $doc->getElementsByTagName('Content');
     if (!$views || $views->length < 1) {
         throw new GadgetSpecException("A gadget needs to have at least one view");
     }
     $gadget->views = array();
     foreach ($views as $viewNode) {
         if ($viewNode->getAttribute('type' == 'url') && $viewNode->getAttribute('href') == null) {
             throw new GadgetSpecException("Malformed <Content> href value");
         }
         foreach (explode(',', $viewNode->getAttribute('view')) as $view) {
             $view = trim($view);
             $href = trim($viewNode->getAttribute('href'));
             $type = trim(strtoupper($viewNode->getAttribute('type')));
             if (empty($type)) {
                 $type = 'html';
             }
             $dataPipeliningRequests = array();
             if (!empty($href) && $type == 'HTML') {
                 require_once 'src/gadgets/templates/DataPipelining.php';
                 // a non empty href & type == 'HTML' means there might be data-pipelining tags in the content section
                 $dataPipeliningRequests = DataPipelining::parse($viewNode);
             }
             if (isset($gadget->views[$view])) {
                 $gadget->views[$view]['content'] .= $viewNode->nodeValue;
             } else {
                 $gadget->views[$view] = array('view' => $view, 'type' => $type, 'href' => $href, 'preferedHeight' => $viewNode->getAttribute('prefered_height'), 'preferedWidth' => $viewNode->getAttribute('prefered_width'), 'quirks' => $viewNode->getAttribute('quirks'), 'content' => $viewNode->nodeValue, 'authz' => $viewNode->getAttribute('authz'), 'oauthServiceName' => $viewNode->getAttribute('oauth_service_name'), 'oauthTokenName' => $viewNode->getAttribute('oauth_token_name'), 'oauthRequestToken' => $viewNode->getAttribute('oauth_request_token'), 'oauthRequestTokenSecret' => $viewNode->getAttribute('oauth_request_token_secret'), 'signOwner' => $viewNode->getAttribute('sign_owner'), 'signViewer' => $viewNode->getAttribute('sign_viewer'), 'refreshInterval' => $viewNode->getAttribute('refresh_interval'), 'dataPipelining' => $dataPipeliningRequests);
             }
         }
     }
 }