cvs: docweb /include lib_auth.inc.php lib_general.inc.php lib_phpt_generator.inc.php /scripts setup_tests_database.php /sql tests.sql /templates/all/www phpt_edit.tpl.php phpt_list.tpl.php /www phpt_generator.php /www/style common.css
[email protected] ("Etienne Kneuss")
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <cvscolder1159917749@cvsserver> |
colder Tue Oct 3 23:22:29 2006 UTC
Added files:
/docweb/include lib_phpt_generator.inc.php
/docweb/scripts setup_tests_database.php
/docweb/sql tests.sql
/docweb/templates/all/www phpt_edit.tpl.php phpt_list.tpl.php
/docweb/www phpt_generator.php
Modified files:
/docweb/include lib_auth.inc.php lib_general.inc.php
/docweb/www/style common.css
Log:
Implement phpt-generator
colder-20061003232229.txt
(text/plain, 28.2 KB)
http://cvs.php.net/viewvc.cgi/docweb/include/lib_auth.inc.php?r1=1.13&r2=1.14&diff_format=u Index: docweb/include/lib_auth.inc.php diff -u docweb/include/lib_auth.inc.php:1.13 docweb/include/lib_auth.inc.php:1.14 --- docweb/include/lib_auth.inc.php:1.13 Sun Feb 5 11:17:37 2006 +++ docweb/include/lib_auth.inc.php Tue Oct 3 23:22:28 2006 @@ -17,7 +17,7 @@ * | Nuno Lopes <[email protected]> | * +----------------------------------------------------------------------+ * - * $Id: lib_auth.inc.php,v 1.13 2006/02/05 11:17:37 mazzanet Exp $ + * $Id: lib_auth.inc.php,v 1.14 2006/10/03 23:22:28 colder Exp $ */ require_once 'cvs-auth.inc'; @@ -36,6 +36,7 @@ 'sean', 'vincent', 'mazzanet', + 'colder', ); $user = $password = false; http://cvs.php.net/viewvc.cgi/docweb/include/lib_general.inc.php?r1=1.50&r2=1.51&diff_format=u Index: docweb/include/lib_general.inc.php diff -u docweb/include/lib_general.inc.php:1.50 docweb/include/lib_general.inc.php:1.51 --- docweb/include/lib_general.inc.php:1.50 Thu Aug 11 15:25:37 2005 +++ docweb/include/lib_general.inc.php Tue Oct 3 23:22:28 2006 @@ -18,7 +18,7 @@ | Gabor Hojtsy <[email protected]> | | Sean Coates <[email protected]> | +----------------------------------------------------------------------+ -$Id: lib_general.inc.php,v 1.50 2005/08/11 15:25:37 nlopess Exp $ +$Id: lib_general.inc.php,v 1.51 2006/10/03 23:22:28 colder Exp $ */ require_once dirname(__FILE__) . '/lib_auth.inc.php'; @@ -209,11 +209,12 @@ switch(SITE) { case 'php': - $links['orphan-notes'] = BASE_URL . '/orphan_notes.php'; - $links['notes-stats'] = BASE_URL . '/notes_stats.php'; - $links['undoc-functions'] = BASE_URL . '/undoc_functions.php'; + $links['orphan-notes'] = BASE_URL . '/orphan_notes.php'; + $links['notes-stats'] = BASE_URL . '/notes_stats.php'; + $links['undoc-functions'] = BASE_URL . '/undoc_functions.php'; $links['missing-examples'] = BASE_URL . '/missing_examples.php'; - + $links['phpt-generator'] = BASE_URL . '/phpt_generator.php'; + case 'pear': case 'smarty': } http://cvs.php.net/viewvc.cgi/docweb/www/style/common.css?r1=1.2&r2=1.3&diff_format=u Index: docweb/www/style/common.css diff -u docweb/www/style/common.css:1.2 docweb/www/style/common.css:1.3 --- docweb/www/style/common.css:1.2 Fri Jan 21 18:19:12 2005 +++ docweb/www/style/common.css Tue Oct 3 23:22:29 2006 @@ -1,4 +1,4 @@ -/* $Id: common.css,v 1.2 2005/01/21 18:19:12 nlopess Exp $ */ +/* $Id: common.css,v 1.3 2006/10/03 23:22:29 colder Exp $ */ body { @@ -229,3 +229,32 @@ /* howto's nav footer */ div.NAVFOOTER { clear: both; } + +/* phpt classes */ +tr.phpt_approved td { + background-color: #D9FFCC; +} +tr.phpt_implemented td { + background-color: #CCD9FF; +} +tr.phpt_filled td { + background-color: #FFF2CC; +} +tr.phpt_none td { + background-color: #f5f5f5; +} +form.phpt input, form.phpt textarea { + display: block; + margin-bottom: 20px; +} + +form.phpt input[type="submit"]{ + margin-bottom: 0px; + margin-right: 5px; + display: inline; +} + +form.phpt td input{ + display: inline; + margin-bottom: 0px; +} http://cvs.php.net/viewvc.cgi/docweb/include/lib_phpt_generator.inc.php?view=markup&rev=1.1 Index: docweb/include/lib_phpt_generator.inc.php +++ docweb/include/lib_phpt_generator.inc.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: +----------------------------------------------------------------------+ | PHP Documentation Site Source Code | +----------------------------------------------------------------------+ | Copyright (c) 1997-2005 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_01.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. | +----------------------------------------------------------------------+ | Authors: Etienne Kneuss <[email protected]> | +----------------------------------------------------------------------+ $Id: lib_phpt_generator.inc.php,v 1.1 2006/10/03 23:22:28 colder Exp $ */ /** * Parameters */ define('PHPT_EOL', "\n"); define('PHPT_SQLITE_FILE', SQLITE_DIR . 'tests.sqlite'); define('PHPT_DOC_PATH', CVS_DIR.'/phpdoc-all/en/'); define('PHPT_LIMIT_RESULTS', 200); define('PHPT_EXAMPLE_REGEX', '#<example>\s*<title>(.+)</title>\s*<programlisting role="php">\s*<!\[CDATA\[(.+)]]>\s*</programlisting>(.+)</example>#isU'); define('PHPT_OUTPUT_REGEX', '#&example\.outputs;\s*<screen>\s*<!\[CDATA\[(.+)]]>\s*</screen>#isU'); define('PHPT_FLAG_IMPORTED', 1); define('PHPT_FLAG_FILLED', 2); define('PHPT_FLAG_APPROVED', 4); define('PHPT_FLAG_IMPLEMENTED', 8); define('PHPT_FORMAT_SKIPIF', "--TEST--".PHPT_EOL. "%s (generated)".PHPT_EOL. "--SKIPIF--".PHPT_EOL. "%s".PHPT_EOL. "--FILE--".PHPT_EOL. "%s".PHPT_EOL. "--EXPECT--".PHPT_EOL. "%s"); define('PHPT_FORMAT', "--TEST--".PHPT_EOL. "%s (generated)".PHPT_EOL. "--FILE--".PHPT_EOL. "%s".PHPT_EOL. "--EXPECT--".PHPT_EOL. "%s"); // disable magic_quotes_gpc function phpt_clean_gpc (&$item, $key) { $item = stripslashes($item); } /** * Opens a new SQLite connection for URLs * * @return resource SQLite connection */ function phpt_sqlite_open() { return @sqlite_open(PHPT_SQLITE_FILE, 0666); } /** * Extrapolate informations from the sql result * * @return resource SQLite connection */ function phpt_extrapolate($row) { $return = array('id' => (int) $row['id'], 'title' => $row['title'], 'location' => '', 'class' => '', 'status' => '', 'expected' => '', 'test' => '', 'skipif' => '', 'approve_checkbox' => '', 'cvs_link' => 'http://cvs.php.net/viewvc.cgi/phpdoc/en/'.$row['location'].'?view=markup', 'test_lines' => 4, 'expected_lines' => 4, 'skipif_lines' => 1, ); // clean up location $path_pieces = explode('/', $row['location']); $return['location'] = implode('/', array_slice($path_pieces, -3)); // generate the status and the status class if (($row['flags'] & PHPT_FLAG_IMPLEMENTED) === PHPT_FLAG_IMPLEMENTED) { $return['status'] = '&docweb.phpt.implemented;'; $return['class'] = 'phpt_implemented'; } else if (($row['flags'] & PHPT_FLAG_APPROVED) === PHPT_FLAG_APPROVED) { $return['status'] = '&docweb.phpt.approved;'; $return['class'] = 'phpt_approved'; } else if (($row['flags'] & PHPT_FLAG_FILLED) === PHPT_FLAG_FILLED) { $return['status'] = '&docweb.phpt.filled;'; $return['class'] = 'phpt_filled'; } else { $return['status'] = '&docweb.phpt.imported;'; $return['class'] = 'phpt_none'; } if (!empty($row['expected'])) { if(($num = substr_count($row['expected'], "\n")) > $return['expected_lines']) { if($num > 30) { $num = 30; } $return['expected_lines'] = $num; } $return['expected'] = htmlentities($row['expected']); } if (!empty($row['test'])) { if(($num = substr_count($row['test'], "\n")) > $return['test_lines']) { if($num > 30) { $num = 30; } $return['test_lines'] = $num; } $return['test'] = htmlentities($row['test']); } if (!empty($row['skipif'])) { if(($num = substr_count($row['skipif'], "\n")) > $return['skipif_lines']) { if($num > 30) { $num = 30; } $return['skipif_lines'] = $num; } $return['skipif'] = htmlentities($row['skipif']); } // approve checkbox if (($row['flags'] & PHPT_FLAG_APPROVED) === PHPT_FLAG_APPROVED) { $return['approve_checkbox'] = ' checked'; } // careful with large titles $return['title_limited'] = trim($return['title']); if (strlen($return['title_limited']) > 40) { $return['title_limited'] = substr($return['title_limited'], 0, 37).'...'; } $return['title'] = trim(htmlentities($return['title'])); $return['title_limited'] = htmlentities($return['title_limited']); return $return; } /** * Import examples from doc sources. * * @return int, number of imported examples */ function phpt_import_from_source($sqlite) { // Begin the listing $userdata = array('examples_added' => 0, 'sqlite' => $sqlite); $path = ''; phpt_list_files(PHPT_DOC_PATH, $path, $userdata); return $userdata['examples_added']; } /** * List files recursivly and scan them * * @return bool */ function phpt_list_files($prefix, $path, &$userdata) { if (is_dir($prefix.$path) && is_resource($handle = @opendir($prefix.$path))) { while ($name = readdir($handle)) { if (strpos($name, ".xml") !== false) { phpt_scan_file($prefix, $path.$name, $userdata); } else if(is_dir($prefix.$path.$name) && $name !== 'CVS' && $name !== '.' && $name !== '..') { phpt_list_files($prefix, $path.$name.DIRECTORY_SEPARATOR, $userdata); } } closedir($handle); return true; } else { return false; } } /** * Scan files for examples, and insert them * * @return null */ function phpt_scan_file($prefix, $path, &$userdata) { if (!is_file($prefix.$path)) { return false; } $content = file_get_contents($prefix.$path); if ($number = preg_match_all(PHPT_EXAMPLE_REGEX, $content, $matches)) { // found at least an example foreach ($matches[2] as $key => $example) { $expected = ''; $flags = 1; /* Parse the extra content */ $extra = $matches[3][$key]; if (preg_match(PHPT_OUTPUT_REGEX, $extra, $match)) { $expected = $match[1]; $flags |= PHPT_FLAG_FILLED; } $title = preg_replace('#<function>([\w_-]+)</function>#', '\1()', $matches[1][$key]); //$example = preg_replace('/print_r(\s+)\(/', 'var_dump\1(', $example); // let's create the entry $sql_query = "INSERT INTO tests ( title, location, test, expected, import_date, flags ) VALUES ( '".sqlite_escape_string($title)."', '".sqlite_escape_string($path)."', '".sqlite_escape_string(phpt_clean_ws($example))."', '".sqlite_escape_String(phpt_clean_ws($expected))."', datetime('now'), $flags )"; // @ here to avoid "column test is not unique". if (!@sqlite_exec($userdata['sqlite'], $sql_query)) { $number--; } } $userdata['examples_added'] += $number; } } /** * Generate a list of examples * * @return null */ function phpt_generate_list($sqlite, $ids) { $ids = array_map('intval', $ids); // select data $sql_query = 'SELECT id, title, location, test, skipif, expected, edit_date, import_date, flags FROM tests WHERE id IN ('.implode(',', $ids).')'; $results = sqlite_query($sqlite, $sql_query); if (count($ids) === 1) { phpt_download(sqlite_fetch_array($results, SQLITE_ASSOC)); } else { $archivePath = '/tmp/phpt_'.md5(implode('-', $ids)).'.tgz'; header('Content-Type: application/gzip'); header('Content-Disposition: attachment; filename='.basename($archivePath)); $myArchive = new Archive_Tar($archivePath, 'gz'); while ($row = sqlite_fetch_array($results, SQLITE_ASSOC)) { $myArchive->addString('test'.$row['id'].'.phpt', phpt_generate($row)); } readfile($archivePath); unlink($archivePath); } } /** * Delete a list of tests * * @return null */ function phpt_delete_list($sqlite, $ids) { $ids = array_map('intval', $ids); $sql_query = 'DELETE FROM tests WHERE id IN ('.implode(',', $ids).')'; return var_dump(sqlite_exec($sqlite, $sql_query)); } /** * Generate one example * * @return null */ function phpt_generate($infos) { if (empty($infos['skipif'])) { return sprintf(PHPT_FORMAT, $infos['title'], $infos['test'], $infos['expected']); } else { return sprintf(PHPT_FORMAT_SKIPIF, $infos['title'], $infos['skipif'], $infos['test'], $infos['expected']); } } /** * Generate one example and make it available to download * * @return null */ function phpt_download($infos) { if (headers_sent()) { return false; } $path_pieces = explode('/', $infos['location']); $name = implode('_', array_slice($path_pieces, -3)); $name = substr($name, 0, -4).'.phpt'; header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="'.$name.'"'); echo phpt_generate($infos); } /** * Commit changes * * @return true/false */ function phpt_commit_changes($sqlite, $input) { $title = !empty($input['title']) ? sqlite_escape_string($input['title']) : ''; $test = !empty($input['test']) ? sqlite_escape_string(phpt_clean_ws($input['test'])) : ''; $skipif = !empty($input['skipif']) ? sqlite_escape_string(phpt_clean_ws($input['skipif'])) : ''; $expected = !empty($input['expected']) ? sqlite_escape_string(phpt_clean_ws($input['expected'])) : ''; $flags = isset($input['approve']) ? PHPT_FLAG_APPROVED : 0; if (!empty($expected)) { $flags |= PHPT_FLAG_FILLED; } $sql_query = "UPDATE tests SET edit_date = datetime('now'), title = '$title', test = '$test', skipif = '$skipif', expected = '$expected', flags = flags | $flags WHERE id = ".intval($input['editId']); //echo $sql_query; return @sqlite_exec($sqlite, $sql_query); } /** * clean linefeeds and extra spaces */ function phpt_clean_ws($string) { $string = trim($string); return str_replace(array("\r\n", "\r", "\n"), PHPT_EOL, $string); } http://cvs.php.net/viewvc.cgi/docweb/scripts/setup_tests_database.php?view=markup&rev=1.1 Index: docweb/scripts/setup_tests_database.php +++ docweb/scripts/setup_tests_database.php #!/usr/local/bin/php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: +----------------------------------------------------------------------+ | PHP Documentation Site Source Code | +----------------------------------------------------------------------+ | Copyright (c) 1997-2005 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_01.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. | +----------------------------------------------------------------------+ | Authors: Etienne Kneuss <[email protected]> | +----------------------------------------------------------------------+ $Id: setup_tests_database.php,v 1.1 2006/10/03 23:22:28 colder Exp $ */ $path = '../sqlite/tests.sqlite'; $idx = sqlite_open($path, 0666); if (!$idx) { die('Could not open '.$path); } sqlite_query($idx, file_get_contents("../sql/tests.sql")); sqlite_close($idx); http://cvs.php.net/viewvc.cgi/docweb/sql/tests.sql?view=markup&rev=1.1 Index: docweb/sql/tests.sql +++ docweb/sql/tests.sql /* * Tables for the RFC system * Original PEPr sql can be found at pearweb/sql/pepr.sql * * This is for a SQLite database, only edit if you * know what SQLite doesn't support */ ; CREATE TABLE tests ( id INTEGER PRIMARY KEY, title varchar(150) NOT NULL default '', location varchar(80) NOT NULL default '', test text NOT NULL UNIQUE, skipif, text NOT NULL default '', expected text NOT NULL default '', edit_date timestamp(14) NOT NULL default '0', import_date timestamp(14) NOT NULL default '0', flags INTEGER NOT NULL default 1 ) http://cvs.php.net/viewvc.cgi/docweb/templates/all/www/phpt_edit.tpl.php?view=markup&rev=1.1 Index: docweb/templates/all/www/phpt_edit.tpl.php +++ docweb/templates/all/www/phpt_edit.tpl.php <?php if (!empty($error)) { echo <<<HTML <h2>Error:</h2> $error; <br /><br /><a href="phpt_generator.php?q={$q}">&docweb.phpt.return;</a> HTML; return; } if ($edited === false) { echo '<h2>&docweb.phpt.edit.error;</h2>'; } else if ($edited === true) { echo '<h2>&docweb.phpt.edit.ok;</h2>'; } echo <<<HTML <h1>&docweb.phpt.edit;</h1> <a href="phpt_generator.php?q={$q}">&docweb.phpt.return;</a><br /> <a href="phpt_generator.php?generateId={$test['id']}">&docweb.phpt.generate;</a><br /> <form action="" method="POST" class="phpt"> <h2>&docweb.phpt.edit.title;</h2> <input name="title" type="text" value="{$test['title']}" size="80" /> <h2>&docweb.phpt.edit.skipif;</h2> <textarea name="skipif" rows="{$test['skipif_lines']}" cols="80">{$test['skipif']}</textarea> <h2>&docweb.phpt.edit.test;</h2> <textarea name="test" rows="{$test['test_lines']}" cols="80">{$test['test']}</textarea> <h2>&docweb.phpt.edit.expected;</h2> <textarea name="expected" rows="{$test['expected_lines']}" cols="80">{$test['expected']}</textarea> <h2>&docweb.phpt.edit.approve;</h2> <input name="approve" type="checkbox"{$test['approve_checkbox']}/> <input type="submit" name="commit" value="&docweb.phpt.commit;"> </form> HTML; ?> http://cvs.php.net/viewvc.cgi/docweb/templates/all/www/phpt_list.tpl.php?view=markup&rev=1.1 Index: docweb/templates/all/www/phpt_list.tpl.php +++ docweb/templates/all/www/phpt_list.tpl.php <?php if ($ntotal == 200) { $limitError = '<strong>&docweb.phpt.limitreached;</strong><br />'; } else { $limitError = ''; } echo <<<HTML <h1>&docweb.phpt.list;</h1> <a href="?import">&docweb.phpt.import;</a><br /><br /> <form action="phpt_generator.php" method="post" class="phpt"> <input type="text" name="q" value="{$search}" style="display:inline; margin: 0px;" /> <input type="submit" name="search" value="&docweb.phpt.search;"/> HTML; if (!empty($tests)) { echo <<<HTML <br /><br /><br /> <input type="submit" name="generate" value="&docweb.phpt.generate;"/> <input type="submit" name="delete" value="&docweb.phpt.delete;"/><br /><br /> {$limitError}Stats: $ntotal examples, $napproved approved, $nfilled filled, $nimported imported.<br /> <table border="1"> <tr> <th>&docweb.phpt.list.id;</th> <th>&docweb.phpt.list.location;</th> <th>&docweb.phpt.list.title;</th> <th>&docweb.phpt.list.status;</th> </tr> HTML; foreach ($tests as $test) { echo <<<HTML <tr class="{$test['class']}"> <td><input type="checkbox" name="ids[{$test['id']}]" /> <a href="?editId={$test['id']}&q={$search_enc}" title="Edit">{$test['id']}</a></td> <td><a href="{$test['cvs_link']}" target="_blank">{$test['location']}</a></td> <td>{$test['title_limited']}</td> <td>{$test['status']}</td> </tr> HTML; } echo <<<HTML </table> <br /><input type="submit" name="generate" value="&docweb.phpt.generate;"/> <input type="submit" name="delete" value="&docweb.phpt.delete;"/> HTML; } ?> </form> http://cvs.php.net/viewvc.cgi/docweb/www/phpt_generator.php?view=markup&rev=1.1 Index: docweb/www/phpt_generator.php +++ docweb/www/phpt_generator.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: +----------------------------------------------------------------------+ | PHP Documentation Site Source Code | +----------------------------------------------------------------------+ | Copyright (c) 1997-2005 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available at through the world-wide-web at | | http://www.php.net/license/3_01.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. | +----------------------------------------------------------------------+ | Authors: Etienne Kneuss <[email protected]> | +----------------------------------------------------------------------+ $Id: phpt_generator.php,v 1.1 2006/10/03 23:22:29 colder Exp $ */ require_once '../include/init.inc.php'; require_once '../include/lib_phpt_generator.inc.php'; require_once '../include/lib_auth.inc.php'; require_once 'Archive/Tar.php'; // clean magic_quotes_gpc if (get_magic_quotes_gpc()) { array_walk_recursive($_GET, 'phpt_clean_gpc'); array_walk_recursive($_POST, 'phpt_clean_gpc'); array_walk_recursive($_REQUEST, 'phpt_clean_gpc'); array_walk_recursive($_COOKIE, 'phpt_clean_gpc'); } if (!$sqlite = phpt_sqlite_open()) { echo site_header('docweb.common.header.phptgen'); echo '<p>Unable to open examples database</p>'; echo site_footer(); exit(); } /** * Generate tests */ if (!empty($_REQUEST['ids']) && isset($_REQUEST['generate'])) { phpt_generate_list($sqlite, array_keys($_REQUEST['ids'])); exit; } /** * Generate one test */ if (!empty($_REQUEST['generateId'])) { $sql_query = 'SELECT id, title, location, test, skipif, expected, edit_date, import_date, flags FROM tests WHERE id = '.(int)$_REQUEST['generateId']; $results = sqlite_query($sqlite, $sql_query); phpt_download(sqlite_fetch_array($results, SQLITE_ASSOC)); exit; } /** * check rights when admin required. */ if ((!empty($_REQUEST['ids']) && isset($_REQUEST['delete'])) || isset($_REQUEST['import']) || (!empty($_REQUEST['editId']) && isset($_REQUEST['commit']))) { auth(); if (!is_admin()) { die('you are not an admin!'); } } echo site_header('docweb.common.header.phptgen'); /** * Remove tests */ if (!empty($_REQUEST['ids']) && isset($_REQUEST['delete'])) { phpt_delete_list($sqlite, array_keys($_REQUEST['ids'])); } /** * Import tests */ if (isset($_REQUEST['import'])) { // this operation requires authentication as // it can waste a lot of server resources $num = phpt_import_from_source($sqlite); echo "<h2>Imported $num examples</h2>"; } /** * Handle edition */ if (!empty($_REQUEST['editId'])) { $test_id = (int)$_REQUEST['editId']; $edited = null; $error = ''; $testData = array(); $q = !empty($_REQUEST['q']) ? rawurlencode($_REQUEST['q']) : ''; if (isset($_REQUEST['commit'])) { $edited = phpt_commit_changes($sqlite, $_REQUEST); } $sql_query = 'SELECT id, title, location, test, skipif, expected, edit_date, import_date, flags FROM tests WHERE id = '.$test_id; $results = sqlite_query($sqlite, $sql_query); $row = sqlite_fetch_array($results, SQLITE_ASSOC); if (empty($row)) { $error = '&docweb.phpt.editidnotfound;'; } else { $testData = phpt_extrapolate($row); } echo DocWeb_Template::get( 'phpt_edit.tpl.php', array( 'test' => $testData, 'error' => $error, 'edited' => $edited, 'q' => $q, ) ); echo site_footer(); exit; } /** * Display listing */ $testsData = array(); $imported = 0; $filled = 0; $approved = 0; $total = 0; $q = ''; if (!empty($_REQUEST['q'])) { $q = trim($_REQUEST['q']); $q_sql = str_replace('\%', '%', sqlite_escape_string($q)); $sql_query = 'SELECT id, title, location, test, expected, edit_date, import_date, flags FROM tests WHERE location LIKE \'%'.$q_sql.'%\' ORDER BY flags DESC, location, id LIMIT '.PHPT_LIMIT_RESULTS; $results = sqlite_query($sqlite, $sql_query); while ($row = sqlite_fetch_array($results, SQLITE_ASSOC)) { $testsData[$row['id']] = phpt_extrapolate($row); if (($row['flags'] & PHPT_FLAG_APPROVED) === PHPT_FLAG_APPROVED) { $approved ++; } if (($row['flags'] & PHPT_FLAG_FILLED) === PHPT_FLAG_FILLED) { $filled ++; } if ($row['flags'] === PHPT_FLAG_IMPORTED) { $imported ++; } $total++; } } echo DocWeb_Template::get( 'phpt_list.tpl.php', array( 'tests' => $testsData, 'search' => htmlentities($q), 'search_enc' => rawurlencode($q), 'nimported' => $imported, 'nfilled' => $filled, 'napproved' => $approved, 'ntotal' => $total ) ); echo site_footer(); ?>