pearweb_manual
[ class tree: pearweb_manual ] [ index: pearweb_manual ] [ all elements ]

Source for file find-documentation.php

Documentation is available at find-documentation.php

  1. <?php
  2. /**
  3.  * Trying to find documentation URLs for PEAR packages in the peardoc Docbook sources.
  4.  * Updates the package doc links in database if they are empty.
  5.  *
  6.  * Parameters:
  7.  *  --debug   Display debugging data
  8.  *
  9.  * @author  Martin Jansen <mj@php.net>
  10.  * @license LGPL
  11.  * @version $Revision$
  12.  */
  13. require_once dirname(dirname(__FILE__)) '/include/pear-config.php';
  14. require_once 'PEAR.php';
  15. require_once 'VFS.php';
  16. require_once 'VFS/file.php';
  17. require_once 'HTTP/Request2.php';
  18.  
  19. require_once 'DB.php';
  20.  
  21. if (!file_exists('en/package')) {
  22.     echo "Please cd into peardoc checkout\n";
  23.     exit(2);
  24. }
  25. $basepath getcwd('/en/package/';
  26. $debug in_array('--debug'$argv);
  27.  
  28. $vfs = new VFS_file(array('vfsroot' => $basepath));
  29.  
  30. $options = array(
  31.     'persistent'  => false,
  32.     'portability' => DB_PORTABILITY_ALL,
  33. );
  34. $dbh =DB::connect(PEAR_DATABASE_DSN$options);
  35. if (DB::isError($dbh)) {
  36.     print $dbh->getMessage("\n" $dbh->getUserInfo("\n";
  37.     exit(1);
  38. }
  39.  
  40. $host 'http://' . PEAR_CHANNELNAME;
  41.  
  42. $sql "
  43.     UPDATE packages SET
  44.         doc_link = ?
  45.     WHERE name = ? AND
  46.     (doc_link IS NULL OR doc_link NOT LIKE 'http://%' OR doc_link LIKE '" $host "/%')";
  47. $update $dbh->prepare($sql);
  48.  
  49. function checkDocumentation($path{
  50.     checkDocLog('checkDocumentation of ' $path);
  51.     //our xml file contains entities that include other files
  52.     // we need to remove them since loading them would take really really long
  53.     $xmlstr preg_replace(
  54.         '/&[a-zA-Z0-9._-]+;/',
  55.         '',
  56.         file_get_contents($path)
  57.     );
  58.  
  59.     $document simplexml_load_string($xmlstr);
  60.     $document->registerXPathNamespace('db''http://docbook.org/ns/docbook');
  61.     $titles $document->xpath("//db:title");
  62.     $books $document->xpath("//db:book");
  63.  
  64.     if (empty($titles)) {
  65.         throw new Exception("No //title element");
  66.     }
  67.  
  68.     if (empty($books)) {
  69.         throw new Exception("No //book element");
  70.     }
  71.  
  72.     $attributes $books[0]->attributes('http://www.w3.org/XML/1998/namespace');
  73.     if (empty($attributes['id'])) {
  74.         throw new Exception('Missing package xml:id attribute');
  75.     }
  76.  
  77.     return array((string)$titles[0]$attributes['id']);
  78. }
  79.  
  80. function checkDocLog($msg)
  81. {
  82.     $GLOBALS['debug'&& print($msg "\n");
  83. }
  84.  
  85. // {{{ readFolder()
  86. function readFolder($folder)
  87. {
  88.     global $vfs$basepath$dbh$update$host;
  89.  
  90.     static $level;
  91.     $level++;
  92.  
  93.     if (substr($folder-5== '/.svn'{
  94.         return;
  95.     }
  96.  
  97.     checkDocLog('readFolder ' $folder);
  98.     $result $vfs->listFolder($folder);
  99.  
  100.     if ($folder == '.'{
  101.         $folder '';
  102.     }
  103.  
  104.     foreach ($result as $file{
  105.        if (is_dir($basepath $folder '/' $file['name'])) {
  106.             if ($folder == ''{
  107.                 $newfolder $file['name'];
  108.             else {
  109.                 $newfolder $folder '/' $file['name'];
  110.             }
  111.             readFolder($newfolder);
  112.             $level--;
  113.         else {
  114.             if ($level == 2 && preg_match("/\.xml$/"$file['name'])) {
  115.                 $path $basepath $folder '/' $file['name'];
  116.  
  117.                 try {
  118.                     list($title$packagecheckDocumentation($path);
  119.  
  120.                     $url '/manual/en/' $package '.php';
  121.  
  122.                     checkDocLog('trying  ' $host $url);
  123.                     $request = new HTTP_Request2($host $url);
  124.                     $response $request->send();
  125.  
  126.                     if ($response->getStatus(>= 400{
  127.                         $new_url preg_replace("=\.([^\.]+)\.php$="".php"$url);
  128.                         $request->setURL($host $new_url);
  129.                         checkDocLog('trying2 ' $host $new_url);
  130.                         $response $request->send();
  131.                         $url $response->getStatus(> 400 ? '' $new_url;
  132.                     }
  133.  
  134.                     if ($url{
  135.                         checkDocLog('Found doc url: ' $url ', title: ' $title);
  136.                         $res $dbh->execute($updatearray($url$title));
  137.                     else {
  138.                         checkDocLog('No url for ' $title);
  139.                     }
  140.                 catch (Exception $e{
  141.                     print $e->getMessage("\n";
  142.                 }
  143.             }
  144.         }
  145.     }
  146. }
  147.  
  148. // }}}
  149. //checkDocumentation(dirname(__FILE__) . '/sample.xml');

Documentation generated on Mon, 11 Mar 2019 16:04:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.