You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ch...@apache.org on 2009/02/23 19:29:45 UTC
svn commit: r747098 -
/incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriter.php
Author: chabotc
Date: Mon Feb 23 18:29:45 2009
New Revision: 747098
URL: http://svn.apache.org/viewvc?rev=747098&view=rev
Log:
This implements a very simple style rewriter, it works but i still have to check if it doesn't break stuff in some cases :)
Modified:
incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriter.php
Modified: incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriter.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriter.php?rev=747098&r1=747097&r2=747098&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriter.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/rewrite/ContentRewriter.php Mon Feb 23 18:29:45 2009
@@ -1,4 +1,5 @@
<?php
+
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,7 +19,6 @@
* under the License.
*/
-
/**
* Implements the Content-Rewrite feature which rewrites all image, css and script
* links to their proxied versions, which can be quite a latency improvement, and
@@ -54,7 +54,6 @@
$gadgetRewriter->addObserver('link', $this, 'rewriteStyleLink');
}
-
/**
* Produces the proxied version of a URL if it falls within the content-rewrite params and
* will append a refresh param to the proxied url based on the expires param, and the gadget
@@ -109,9 +108,37 @@
}
}
+ /**
+ * Tries to find url(<url tag>) constructs and rewrite them to their
+ * proxied counterparts
+ *
+ * @param DOMElement $node
+ */
public function rewriteStyle(DOMElement &$node) {
- // find import('foo') statements
- // find and rewrite url('foo') statements (background, etc)
+ $content = $node->nodeValue;
+ $newVal = '';
+ // loop through the url elements in the content
+ while (($pos = strpos($content, 'url')) !== false) {
+ // output everything before this url tag
+ $newVal .= substr($content, 0, $pos + 3);
+ $content = substr($content, $pos + 3);
+ // low tech protection against miss-reading tags, if the open ( is to far away, this is probabbly a miss-read
+ if (($beginTag = strpos($content, '(')) < 4) {
+ $content = substr($content, $beginTag + 1);
+ $endTag = strpos($content, ')');
+ $tag = str_replace(array("'", "\""), '', trim(substr($content, 0, $endTag)));
+ // at this point $tag should be the actual url aka: http://example.org/bar/foo.gif
+ if ($this->includedUrl($tag)) {
+ $newVal .= "('" . $this->getProxyUrl($tag) . "')";
+ } else {
+ $newVal .= "('$tag')";
+ }
+ $content = substr($content, $endTag + 1);
+ }
+ }
+ // append what's left
+ $newVal .= $content;
+ $node->nodeValue = $newVal;
}
public function rewriteScript(DOMElement &$node) {