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; }
public function createRewriteFeature(Gadget $gadget) { $requires = $gadget->getRequires(); if (!isset($requires[ContentRewriteFeature::$REWRITE_TAG])) { return; } $rewriteFeature = $requires[ContentRewriteFeature::$REWRITE_TAG]; $rewriteParams = $rewriteFeature->getParams(); if (isset($rewriteParams[ContentRewriteFeature::$INCLUDE_URLS])) { $this->includeParam = $this->normalizeParam($rewriteParams[ContentRewriteFeature::$INCLUDE_URLS], '//'); } else { $this->includeParam = '//'; } if (isset($rewriteParams[ContentRewriteFeature::$EXCLUDE_URLS])) { $this->excludeParam = $this->normalizeParam($rewriteParams[ContentRewriteFeature::$EXCLUDE_URLS], '//'); } else { $this->excludeParam = '//'; } if (isset($rewriteParams[ContentRewriteFeature::$INCLUDE_TAGS])) { $this->tagsParam = $rewriteParams[ContentRewriteFeature::$INCLUDE_TAGS]; $this->tagsParam = explode(',', $this->tagsParam); } else { $this->tagsParam = array(); } if ($this->excludeParam == '.*' || $this->includeParam == null) { $this->includeNone = true; } if ($this->includeParam == '.*' || $this->excludeParam == null) { $this->includeAll = true; } }
/** * Output's a URL content type gadget, it adds libs=<list:of:js:libraries>.js and user preferences * to the href url, and redirects the browser to it * * @param Gadget $gadget */ private function outputUrlGadget($gadget, $context, $view) { // Preserve existing query string parameters. $redirURI = $view->getHref(); $queryStr = strpos($redirURI, '?') !== false ? substr($redirURI, strpos($redirURI, '?')) : ''; $query = $queryStr; // TODO: userprefs on the fragment rather than query string $query .= $this->getPrefsQueryString($gadget->getUserPrefValues()); $libs = array(); $forcedLibs = Config::get('focedJsLibs'); if ($forcedLibs == null) { $reqs = $gadget->getRequires(); foreach ($reqs as $key => $val) { $libs[] = $key; } } else { $libs = explode(':', $forcedLibs); } $query .= $this->appendLibsToQuery($libs, $gadget); // code bugs out with me because of the invalid url syntax since we dont have a URI class to fix it for us // this works around that if (substr($query, 0, 1) == '&') { $query = '?' . substr($query, 1); } $redirURI .= $query; header('Location: ' . $redirURI); die; }
/** * Tests Gadget->getRequires() */ public function testGetRequires() { $this->Gadget->requires = 'requires'; $this->assertEquals('requires', $this->Gadget->getRequires()); }
function featuresLoad(Gadget $gadget, $context) { // Process required / desired features $requires = $gadget->getRequires(); $needed = array(); $optionalNames = array(); foreach ($requires as $key => $entry) { $needed[] = $key; if ($entry->isOptional()) { $optionalNames[] = $key; } } $resultsFound = array(); $resultsMissing = array(); $missingOptional = array(); $missingRequired = array(); $context->getRegistry()->getIncludedFeatures($needed, $resultsFound, $resultsMissing); foreach ($resultsMissing as $missingResult) { if (in_array($missingResult, $optionalNames)) { $missingOptional[$missingResult] = $missingResult; } else { $missingRequired[$missingResult] = $missingResult; } } if (count($missingRequired)) { throw new GadgetException("Unsupported feature(s): " . implode(', ', $missingRequired)); } // create features $features = array(); foreach ($resultsFound as $entry) { $features[$entry] = $context->getRegistry()->getEntry($entry)->getFeature()->create(); } // prepare them foreach ($features as $key => $feature) { $params = $gadget->getFeatureParams($gadget, $context->getRegistry()->getEntry($key)); $feature->prepare($gadget, $context, $params); } // and process them foreach ($features as $key => $feature) { $params = $gadget->getFeatureParams($gadget, $context->getRegistry()->getEntry($key)); $feature->process($gadget, $context, $params); } }