public function rewriteGadgetView(Gadget $gadget, ViewSpec $gadgetView)
 {
     // Dont rewrite content if the spec is unavailable
     $requires = $gadget->getRequires();
     if (isset($requires[ContentRewriteFeature::$REWRITE_TAG])) {
         // Store the feature in the spec so we dont keep parsing it
         $rewriteFeature = new ContentRewriteFeature();
         $rewriteFeature->createRewriteFeature($gadget);
     } else {
         return false;
     }
     if (!$rewriteFeature->isRewriteEnabled()) {
         return false;
     }
     if (ContentRewriteFeature::$PROXY_URL != null) {
         $defaultTags = ContentRewriteFeature::defaultHTMLTags();
         $htmlTags = null;
         if (count($rewriteFeature->getTagsParam()) > 0) {
             foreach ($rewriteFeature->getTagsParam() as $tag) {
                 if (isset($defaultTags[$tag])) {
                     $htmlTags[$tag] = $defaultTags[$tag];
                 }
             }
         } else {
             $htmlTags = $defaultTags;
         }
     }
     $gadgetView->setRewrittenContent($this->rewrite($gadgetView->getContent(), $htmlTags, $rewriteFeature->getExcludeParam(), $rewriteFeature->getIncludeParam(), Config::get('web_prefix') . ContentRewriteFeature::$PROXY_URL, $gadget->getId()->getURI(), $rewriteFeature->getTagsParam()));
     return true;
 }
 private function processContent(&$gadget, $content)
 {
     $attributes = $content->attributes();
     if (empty($attributes['type'])) {
         throw new SpecParserException("No content type specified!");
     }
     $view = isset($attributes['view']) ? trim($attributes['view']) : '';
     $views = explode(',', $view);
     $html = (string) $content;
     // no trim here since empty lines can have structural meaning, so typecast to string instead
     foreach ($views as $view) {
         if (empty($view)) {
             $view = DEFAULT_VIEW;
         }
         $viewSpec = new ViewSpec($view, $content);
         if (!isset($gadget->views[$view])) {
             $viewSpec->content = $html;
             $gadget->views[$view] = $viewSpec;
         } else {
             if ($gadget->views[$view]->getName() == $viewSpec->getName() && $viewSpec->getType() != $gadget->views[$view]->getType()) {
                 throw new SpecParserException("You may not mix content " . " types in the same view.");
             }
             $gadget->views[$view]->addContent($html);
         }
     }
 }
Ejemplo n.º 3
0
 private function processContent(&$gadget, $content, $views)
 {
     $html = (string) $content;
     // no trim here since empty lines can have structural meaning, so typecast to string instead
     foreach ($views as $view) {
         $viewSpec = new ViewSpec($view, $content);
         if (!isset($gadget->views[$view])) {
             $viewSpec->content = $html;
             $gadget->views[$view] = $viewSpec;
         } else {
             if ($gadget->views[$view]->getName() == $viewSpec->getName() && $viewSpec->getType() != $gadget->views[$view]->getType()) {
                 throw new SpecParserException("You may not mix content " . " types in the same view.");
             }
             $gadget->views[$view]->addContent($html);
         }
     }
 }