svn: /pear/pearweb/trunk/cron/ find-documentation.php sample.xml

[email protected] ("Daniel O'Connor") Thu, 09 Sep 2010 08:22:08 +0000
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
clockwerx                                Thu, 09 Sep 2010 08:22:08 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=303211

Log:
Rewritten find-documentation checker.

Changed paths:
    U   pear/pearweb/trunk/cron/find-documentation.php
    A   pear/pearweb/trunk/cron/sample.xml

Modified: pear/pearweb/trunk/cron/find-documentation.php
===================================================================
--- pear/pearweb/trunk/cron/find-documentation.php	2010-09-09 08:03:49 UTC (rev 303210)
+++ pear/pearweb/trunk/cron/find-documentation.php	2010-09-09 08:22:08 UTC (rev 303211)
@@ -59,8 +59,34 @@
     (doc_link IS NULL OR doc_link NOT LIKE 'http://%' OR doc_link LIKE '" . $host . "/%')";
 $update = $dbh->prepare($sql);

+function checkDocumentation($path) {
+
+    $dom = new DOMDocument();
+    @$dom->loadHTML(file_get_contents($path)); // I know: @ is evil, but it's either that or load chapters.ent - 422K of DTD
+
+    $document = simplexml_import_dom($dom);
+    $titles = $document->xpath("//title");
+    $books = $document->xpath("//book");
+
+    if (empty($titles)) {
+        throw new Exception("No //title element");
+    }
+
+    if (empty($books)) {
+        throw new Exception("No //book element");
+    }
+
+    $attributes = $books[0]->attributes();
+
+    if (empty($attributes['xml:id'])) {
+        throw new Exception("Missing package xml:id attribute");
+    }
+
+    return array((string)$titles[0], $attributes['xml:id']);
+}
+
+
 // {{{ readFolder()
-
 function readFolder($folder)
 {
     global $vfs, $basepath, $dbh, $update, $host;
@@ -85,38 +111,35 @@
             $level--;
         } else {
             if ($level == 2 && preg_match("/\.xml$/", $file['name'])) {
-
                 $path = $basepath . $folder . '/' . $file['name'];
-                $content = file_get_contents($path);

-                preg_match("/<title>\s*(\w+)\s*<\/title>/s", $content, $matches1);
-                preg_match("/<book.*?xml:id\=\"(.*?)\"\s*>/s", $content, $matches2);
+                try {
+                    list($title, $package) = checkDocumentation($path);

-                if (empty($matches2[1])) {
-                    print "Unable to match /<book.*?xml:id\=\"(.*?)\"\s*>/s for " . $path . ", skipping\n";
-                    continue;
-                }
+
+                    $url = '/manual/en/' . $package . '.php';

-                $url = '/manual/en/' . $matches2[1] . '.php';
+                    $request = new HTTP_Request2($host . $url);
+                    $response = $request->send();

-                $request = new HTTP_Request2($host . $url);
-                $response = $request->send();
+                    if ($response->getStatus() == 404) {
+                        $new_url = preg_replace("=\.([^\.]+)\.php$=", ".php", $url);
+                        $request->setURL($host . $new_url);
+                        $response = $request->send();
+                        $url = $response->getStatus() == 404 ? $new_url : '';
+                    }

-                if ($response->getStatus() == 404) {
-                    $new_url = preg_replace("=\.([^\.]+)\.php$=", ".php", $url);
-                    $request->setURL($host . $new_url);
-                    $response = $request->send();
-                    $url = $response->getStatus() != 404 ? $new_url : '';
+                    if ($url) {
+                        $res = $dbh->execute($update, array($url, $matches1[1]));
+                    }
+                } catch (Exception $e) {
+                    print $e->getMessage() . "\n";
                 }
-
-                if ($url) {
-                    $res = $dbh->execute($update, array($url, $matches1[1]));
-                }
             }
         }
     }
 }

 // }}}
-
+//checkDocumentation(dirname(__FILE__) . '/sample.xml');
 readFolder('.');

Added: pear/pearweb/trunk/cron/sample.xml
===================================================================
--- pear/pearweb/trunk/cron/sample.xml	                        (rev 0)
+++ pear/pearweb/trunk/cron/sample.xml	2010-09-09 08:22:08 UTC (rev 303211)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<book
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ version="lillet" xml:id="package.networking.net-ldap2"
+>
+ <info>
+  <title>Net_LDAP2</title>
+  <abstract>
+    <para>
+        Net_LDAP2 allows you to query and manipulate the data stored in directory
+        servers using PHP in an object-oriented way.
+    </para>
+    <para>
+        Detailed usage examples are available at: <literal>/your/pear/path/docs/Net_LDAP2/examples/</literal>
+    </para>
+  </abstract>
+ </info>
+
+
+ <chapter>
+    &package.networking.net-ldap2.introduction;
+    &package.networking.net-ldap2.errorhandling;
+    &package.networking.net-ldap2.connect;
+    &package.networking.net-ldap2.search;
+    &package.networking.net-ldap2.fetching;
+    &package.networking.net-ldap2.attributes;
+    &package.networking.net-ldap2.entries;
+    &package.networking.net-ldap2.filter;
+    &package.networking.net-ldap2.ldif;
+    &package.networking.net-ldap2.schemacache;
+ </chapter>
+</book>