wez Tue May 4 21:38:16 2004 EDT Added files: /livedocs mk_notes.php
Modified files: /livedocs build-ops.in build.sh common.php configure.in livedoc.php /livedocs/themes/default livedoc.css Log: Set build log default to be stdout, so that you can watch the progress from your terminal. Add --with-notes-token configure option to specify the token to use to fetch the user notes from the master. This is used by the new mk_notes.php script to generate livedoc-notes.sqlite. This database contains all the user contributed notes (and currently occupies 13MB of disk for ~9000 notes). The notes database can be queried to emit the user contributed notes as part of the html content generation. This allows the notes to be cached in the pre-generated documentation, or queried dynamically if livedocs is configured that way.
http://cvs.php.net/diff.php/livedocs/build-ops.in?r1=1.7&r2=1.8&ty=u Index: livedocs/build-ops.in diff -u livedocs/build-ops.in:1.7 livedocs/build-ops.in:1.8 --- livedocs/build-ops.in:1.7 Wed Mar 17 05:45:50 2004 +++ livedocs/build-ops.in Tue May 4 21:35:41 2004 @@ -16,4 +16,6 @@ # "en" should be the first! # LANGUAGES="en ar cs de es fi fr he hk hu it ja kr lt nl pl pt_BR ro ru sk sl sv tr tw zh" LANGUAGES="@LANGUAGES@" +TOKEN="@TOKEN@" + http://cvs.php.net/diff.php/livedocs/build.sh?r1=1.23&r2=1.24&ty=u Index: livedocs/build.sh diff -u livedocs/build.sh:1.23 livedocs/build.sh:1.24 --- livedocs/build.sh:1.23 Tue May 4 11:19:57 2004 +++ livedocs/build.sh Tue May 4 21:37:02 2004 @@ -6,6 +6,12 @@ echo "####################" +if test -n "$TOKEN" ; then + export TOKEN + echo "Building user notes" + ${PHP} ${LIVEDOCSFORPHP}/mk_notes.php ${OUTPUTDIR} +fi + # running ./buildconf cd ${PHPDOC} autoconf http://cvs.php.net/diff.php/livedocs/common.php?r1=1.11&r2=1.12&ty=u Index: livedocs/common.php diff -u livedocs/common.php:1.11 livedocs/common.php:1.12 --- livedocs/common.php:1.11 Sun Mar 21 15:10:47 2004 +++ livedocs/common.php Tue May 4 21:37:03 2004 @@ -18,7 +18,7 @@ // | Common PHP header, with some basic settings | // +----------------------------------------------------------------------+ // -// $Id: common.php,v 1.11 2004/03/21 20:10:47 nlopess Exp $ +// $Id: common.php,v 1.12 2004/05/05 01:37:03 wez Exp $ set_magic_quotes_runtime(0); /*$compare = version_compare(phpversion(), '5.0.0RC1'); @@ -62,6 +62,7 @@ define('BASE', PHPDOC . "/$lang/"); define('INDEX', OUTPUTDIR . "/livedoc-idx.$lang.sqlite"); +define('NOTESDB', OUTPUTDIR . "/livedoc-notes.sqlite"); define('FALLBACK_INDEX', OUTPUTDIR . '/livedoc-idx.' . FALLBACK_LANG . ".sqlite"); define('FALLBACK_BASE', PHPDOC . "/" . FALLBACK_LANG . "/"); @@ -76,5 +77,11 @@ if (!$idx) { die ("No index found"); } +if (file_exists(NOTESDB)) { + $NOTESDB = @sqlite_open(NOTESDB); +} else { + $NOTESDB = false; +} + ?> http://cvs.php.net/diff.php/livedocs/configure.in?r1=1.24&r2=1.25&ty=u Index: livedocs/configure.in diff -u livedocs/configure.in:1.24 livedocs/configure.in:1.25 --- livedocs/configure.in:1.24 Sat Apr 3 14:22:43 2004 +++ livedocs/configure.in Tue May 4 21:37:04 2004 @@ -1,5 +1,5 @@ ## A configure script -## $Id: configure.in,v 1.24 2004/04/03 19:22:43 nlopess Exp $ +## $Id: configure.in,v 1.25 2004/05/05 01:37:04 wez Exp $ AC_PREREQ(2.13) AC_INIT(livedoc.php) @@ -49,7 +49,7 @@ AC_ARG_WITH(build-log,[ --with-build-log[=FILE] Log file [default=/var/log/livedocs-index]], [BUILDLOG="$withval"], - [BUILDLOG="/var/log/livedocs-index"]) + [BUILDLOG="/dev/stdout"]) AC_ARG_WITH(build-type,[ --with-build-type[=BUILD_TYPE] Build type (phpdoc|peardoc|smarty) [default=phpdoc]], [BUILDTYPE="$withval"], @@ -83,6 +83,9 @@ fi ],[FORCE_DYNAMIC=1]) +AC_ARG_WITH(notes-token,[ --with-notes-token=token Token for fetching user notes], + [TOKEN="$withval"], + [TOKEN=""]) AC_ARG_WITH(web-base,[ --with-web-base[=DIR] Relative URL for livedocs links [default=/]], [WEBBASE="$withval"], @@ -124,6 +127,7 @@ AC_SUBST(LIVEDOCSFORPHP) AC_SUBST(OUTPUTDIRFORPHP) AC_SUBST(XSLTPROC) +AC_SUBST(TOKEN) AC_OUTPUT(build-ops config.php .htaccess) http://cvs.php.net/diff.php/livedocs/livedoc.php?r1=1.100&r2=1.101&ty=u Index: livedocs/livedoc.php diff -u livedocs/livedoc.php:1.100 livedocs/livedoc.php:1.101 --- livedocs/livedoc.php:1.100 Mon May 3 08:50:10 2004 +++ livedocs/livedoc.php Tue May 4 21:37:05 2004 @@ -18,7 +18,7 @@ // | Generate an HTML version of a phpdoc/docbook page on the fly | // +----------------------------------------------------------------------+ // -// $Id: livedoc.php,v 1.100 2004/05/03 12:50:10 wez Exp $ +// $Id: livedoc.php,v 1.101 2004/05/05 01:37:05 wez Exp $ define('LIVEDOC_SOURCE', dirname(__FILE__)); include LIVEDOC_SOURCE . '/common.php'; @@ -117,6 +117,7 @@ echo call_user_func($aliases[$current_page]); } else { echo $page->transform($map, $current_page); + echo format_user_notes($current_page); } if (empty($file_revision)) { @@ -410,6 +411,38 @@ } } +function format_user_notes($id) +{ + $notes = sqlite_array_query($GLOBALS['NOTESDB'], "SELECT id, xwhen, who, note from notes where sect='$id' order by xwhen desc"); + if (count($notes) == 0) + return ''; + + $inner = <<<HTML +<div class="usernotes"> + <span class="title">User Contributed Notes</span> +HTML; + + foreach ($notes as $note) { + $date = date("d-M-Y h:i", $note['xwhen']); + + $node = new stdClass; + $node->content = $note['note']; + $node->attributes['role'] = 'php'; + $the_note = format_listing($node); + + $inner .= <<<HTML +<div class="usernote"> + <div class="noteheader"> + <span class="user">$note[who]</span><br /> + <span class="when">$date</span> + </div> + $the_note +</div> +HTML; + } + + return $inner . "</div>"; +} function lookup_title($nodeid) { http://cvs.php.net/diff.php/livedocs/themes/default/livedoc.css?r1=1.3&r2=1.4&ty=u Index: livedocs/themes/default/livedoc.css diff -u livedocs/themes/default/livedoc.css:1.3 livedocs/themes/default/livedoc.css:1.4 --- livedocs/themes/default/livedoc.css:1.3 Mon May 3 10:56:58 2004 +++ livedocs/themes/default/livedoc.css Tue May 4 21:37:13 2004 @@ -1,4 +1,4 @@ -/* $Id: livedoc.css,v 1.3 2004/05/03 14:56:58 wez Exp $ */ +/* $Id: livedoc.css,v 1.4 2004/05/05 01:37:13 wez Exp $ */ body { font-family: verdana; font-size: 11pt; @@ -324,4 +324,30 @@ width: 30em; } +/* Notes */ +div.usernotes { + border: 2px dashed #dddddd; + padding-top: 0.8em; +} + +div.usernotes span.title { + font-weight: bold; + font-size: 0.8em; + margin: 1em; +} + +div.usernotes div.usernote { + border-top: solid 2px #ccccff; + padding: 0.2em; + margin: 0.6em; +} + +div.usernotes div.noteheader { + font-weight: bold; + font-size: 0.8em; +} + +div.usernote div.phpcode { + margin: 0.2em; +} http://cvs.php.net/co.php/livedocs/mk_notes.php?r=1.1&p=1 Index: livedocs/mk_notes.php +++ livedocs/mk_notes.php <?php /* vim: set tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 3.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available through the world-wide-web at the following url: | // | http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | [EMAIL PROTECTED] so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Wez Furlong | // +----------------------------------------------------------------------+ // | Create a notes database from the master, which can then be used by | // | livedocs. | // +----------------------------------------------------------------------+ // // $Id: mk_notes.php,v 1.1 2004/05/05 01:37:07 wez Exp $ $token = getenv("TOKEN"); $create = <<<SQL BEGIN; CREATE TABLE notes ( id INTEGER PRIMARY KEY, sect TEXT, rate INTEGER, xwhen INTEGER, who TEXT, note TEXT ); CREATE INDEX notes_sect_idx on notes(sect); SQL; $dbname = $argv[1] . '/livedoc-notes.sqlite'; if (file_exists($dbname)) unlink($dbname); $DB = sqlite_open($dbname); sqlite_query($DB, 'PRAGMA default_synchronous=OFF'); sqlite_query($DB, 'PRAGMA count_changes=OFF'); sqlite_query($DB, 'PRAGMA cache_size=100000'); sqlite_query($DB, $create); $n_notes = 0; $n_data = 0; $fp = fopen("http://master.php.net/fetch/user-notes.php?token=$token", "r"); do { $line = fgets($fp); $n_data += strlen($line); if (!strlen($line)) break; if (!strstr($line, '|')) { echo "LINE: $line\n\n"; continue; } list ($id, $sect, $rate, $ts, $user, $note) = explode('|', $line); $n_notes++; $note = sqlite_escape_string(gzuncompress(base64_decode($note))); $user = sqlite_escape_string($user); printf("\r%d notes %d bytes", $n_notes, $n_data); sqlite_query($DB, "INSERT INTO notes values ($id, '$sect', $rate, $ts, '$user', '$note');"); } while (true); printf("\rDone: %d notes %d bytes\n", $n_notes, $n_data); sqlite_query($DB, 'COMMIT;'); ?>