OpenPKG CVS Repository
http://cvs.openpkg.org/
____________________________________________________________________________
Server: cvs.openpkg.org Name: Ralf S. Engelschall
Root: /v/openpkg/cvs Email: [EMAIL PROTECTED]
Module: openpkg-meta Date: 12-Mar-2006 18:44:53
Branch: HEAD Handle: 2006031217445200
Added files:
openpkg-meta meta.php sample.php
Log:
add a sample consumer page (sample.php) and the consumer glue code
(meta.php)
Summary:
Revision Changes Path
1.1 +134 -0 openpkg-meta/meta.php
1.1 +25 -0 openpkg-meta/sample.php
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: openpkg-meta/meta.php
============================================================================
$ cvs diff -u -r0 -r1.1 meta.php
--- /dev/null 2006-03-12 18:44:15 +0100
+++ meta.php 2006-03-12 18:44:53 +0100
@@ -0,0 +1,134 @@
+<script language="php">
+
+# diversion support
+$div = array();
+$div["name"] = "";
+$div["data"] = array();
+function divert_start ($name) {
+ global $div;
+ $div["name"] = $name;
+ if (!isset($div["data"][$diversion_name])) {
+ $div["data"][$diversion_name] = "";
+ }
+ ob_start();
+}
+function divert_end () {
+ global $div;
+ if ($div["name"] != "") {
+ $div["data"][$div["name"]] .= ob_get_contents();
+ ob_end_clean();
+ }
+}
+function divert ($name) {
+ global $div;
+ if ($div["name"] != $name) {
+ divert_end();
+ divert_start($name);
+ }
+}
+function undivert ($name) {
+ global $div;
+ if ($div["name"] == $name) {
+ $div["data"][$div["name"]] .= ob_get_contents();
+ ob_clean();
+ }
+ return $div["data"][$name];
+}
+
+# scramble an email address/link somewhat to prevent
+# trivial address crawlers from picking it up
+function email ($url, $link) {
+ $html = $url;
+ $html = preg_replace('/@/', '<!-- XXX -->@<!-- XXX -->', $html);
+ $html = preg_replace('/\./', '<!-- XXX -->.<!-- XXX -->', $html);
+ if ($link) {
+ $href = $url;
+ $href = preg_replace('/@/', '@', $href);
+ $href = preg_replace('/\./', '.', $href);
+ $html = "<a href=\"mailto:$href\">$html</a>";
+ }
+ echo $html;
+}
+
+# URL fetching
+function fetch_url($url, $max_caching) {
+ $content = null;
+
+ # try to read content from cache
+ $dba = dba_open("meta.d/meta.db", "c", "db4");
+ if (!is_null($dba)) {
+ $obj = dba_fetch($url, $dba);
+ if ($obj) {
+ $obj = unserialize($obj);
+ if (is_array($obj)) {
+ if ($obj["expiry"] > time())
+ $content = $obj["content"];
+ }
+ }
+ }
+ if (is_null($content)) {
+ # content not found in cache, so fetch from origin server
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, $url);
+ curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ $content = curl_exec($curl);
+ if (curl_errno($curl))
+ $content = "cURL" . curl_error($curl);
+ curl_close($curl);
+
+ # store content into cache
+ if (!is_null($dba)) {
+ $obj = array("content" => $content, "expiry" => time() +
$max_caching);
+ $obj = serialize($obj);
+ dba_replace($url, $obj, $dba);
+ }
+ }
+ if (!is_null($dba))
+ dba_close($dba);
+
+ # return content
+ return $content;
+}
+
+# meta template support
+$html = "";
+function meta_start ($options) {
+ global $html;
+
+ # fetch meta HTML template
+ $options .= "&canvas=absolute";
+ if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"]))
+ $options .= "&embed=js";
+ # $url = "http://meta.openpkg.org/?$options";
+ $url = "http://en1.home.engelschall.com/openpkg-meta/?$options";
+ $html = fetch_url($url, 10);
+
+ # by default divert into body
+ divert("html:body");
+}
+function meta_end ($option) {
+ global $html;
+
+ # flush buffers
+ divert_end();
+
+ # assemble content by inserting head and body into template
+ $content = "";
+ $tag_head = "<!-- CANVAS: HEAD -->";
+ $tag_body = "<!-- CANVAS: BODY -->";
+ $n = strpos($html, $tag_head);
+ $content .= substr($html, 0, $n);
+ $html = substr($html, $n+strlen($tag_head));
+ $content .= undivert("html:head");
+ $n = strpos($html, $tag_body);
+ $content .= substr($html, 0, $n);
+ $html = substr($html, $n+strlen($tag_body));
+ $content .= undivert("html:body");
+ $content .= $html;
+
+ # determine content length and output content
+ header(sprintf("Content-Length: %d", strlen($content)));
+ print $content;
+}
+</script>
@@ .
patch -p0 <<'@@ .'
Index: openpkg-meta/sample.php
============================================================================
$ cvs diff -u -r0 -r1.1 sample.php
--- /dev/null 2006-03-12 18:44:15 +0100
+++ sample.php 2006-03-12 18:44:53 +0100
@@ -0,0 +1,25 @@
+<script language="php">
+ include("meta.php");
+ meta_start("path=project.registry.help&pane=2");
+</script>
+
+<script language="php">
+ divert("html:head");
+</script>
+<style type="text/css">
+ span.sample {
+ font-weight: bold;
+ color: #cc3333;
+ }
+</style>
+<script language="php">
+ divert("html:body");
+</script>
+
+<h1>Sample Page</h1>
+
+This is a <span class="sample">Sample</span> page for meta.openpkg.org.
+
+<script language="php">
+ meta_end();
+</script>
@@ .
______________________________________________________________________
The OpenPKG Project www.openpkg.org
CVS Repository Commit List [email protected]