cvs: docweb /include lib_url_entities.inc.php /scripts checkent.php
[email protected] ("Sean Coates")
| Newsgroups | php.doc.web |
|---|---|
| Message-ID | <cvssean1106406926@cvsserver> |
sean Sat Jan 22 10:15:26 2005 EDT
Modified files:
/docweb/include lib_url_entities.inc.php
/docweb/scripts checkent.php
Log:
more checkent cleanup
http://cvs.php.net/diff.php/docweb/include/lib_url_entities.inc.php?r1=1.1&r2=1.2&ty=u
Index: docweb/include/lib_url_entities.inc.php
diff -u docweb/include/lib_url_entities.inc.php:1.1 docweb/include/lib_url_entities.inc.php:1.2
--- docweb/include/lib_url_entities.inc.php:1.1 Sat Jan 22 09:22:57 2005
+++ docweb/include/lib_url_entities.inc.php Sat Jan 22 10:15:26 2005
@@ -19,7 +19,7 @@
| Mehdi Achour <[email protected]> |
| Sean Coates <[email protected]> |
+----------------------------------------------------------------------+
-$Id: lib_url_entities.inc.php,v 1.1 2005/01/22 14:22:57 sean Exp $
+$Id: lib_url_entities.inc.php,v 1.2 2005/01/22 15:15:26 sean Exp $
*/
// user agent
@@ -64,6 +64,18 @@
HTTP_NOT_FOUND => FALSE,
);
+// Schemes currently supported
+$schemes = array('http');
+if (extension_loaded('openssl')) {
+ $schemes[] = 'https';
+}
+if (function_exists('ftp_connect')) {
+ $schemes[] = 'ftp';
+}
+
+// SQLite DB file
+define('URL_ENT_SQLITE_FILE', SQLITE_DIR . "checkent_{$entType}.sqlite");
+
/**
* Handles relative HTTP URLs
*
@@ -203,4 +215,33 @@
}
return array(SUCCESS, array($num));
}
+
+/**
+ * Stores the result of the check_url function
+ *
+ * @param resource $sqlite sqlite connection resource
+ * @param int $num entity url number (sequence)
+ * @param string $name entity name
+ * @param string $url entity url
+ * @param array $result result of check_url()
+ * @return void
+ */
+function url_store_result(&$sqlite, $num, $name, $url, $result)
+{
+ $return_val = isset($result[1][1]) ? $result[1][1] : '';
+ $sql = "
+ INSERT
+ INTO
+ checked_urls (url_num, entity, url, check_result, return_val)
+ VALUES
+ (
+ $num,
+ '". sqlite_escape_string($name) ."',
+ '". sqlite_escape_string($url) ."',
+ {$result[0]},
+ '". sqlite_escape_string($return_val) ."'
+ )
+ ";
+ sqlite_query($sqlite, $sql);
+}
?>
http://cvs.php.net/diff.php/docweb/scripts/checkent.php?r1=1.14&r2=1.15&ty=u
Index: docweb/scripts/checkent.php
diff -u docweb/scripts/checkent.php:1.14 docweb/scripts/checkent.php:1.15
--- docweb/scripts/checkent.php:1.14 Sat Jan 22 09:30:23 2005
+++ docweb/scripts/checkent.php Sat Jan 22 10:15:26 2005
@@ -19,14 +19,14 @@
| Mehdi Achour <[email protected]> |
| Sean Coates <[email protected]> |
+----------------------------------------------------------------------+
-$Id: checkent.php,v 1.14 2005/01/22 14:30:23 sean Exp $
+$Id: checkent.php,v 1.15 2005/01/22 15:15:26 sean Exp $
*/
set_time_limit(0);
$inCli = true;
require_once '../include/init.inc.php';
-require_once '../include/lib_url_entities.inc.php';
+// determine type (and display usage on fail)
switch (isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : false) {
case 'phpdoc':
$filename = CVS_DIR . '/phpdoc-all/entities/global.ent';
@@ -48,25 +48,18 @@
die();
}
+require_once '../include/lib_url_entities.inc.php';
-// Schemes currently supported
-$schemes = array('http');
-if (function_exists('ftp_connect')) {
- $schemes[] = 'ftp';
-}
-
-if (extension_loaded('openssl')) {
- $schemes[] = 'https';
-}
-
-$dbFile = SQLITE_DIR . "checkent_{$entType}.sqlite";
-if (is_file($dbFile) && !unlink($dbFile)) {
+// create a new database (remove old first, if exists)
+if (is_file(URL_ENT_SQLITE_FILE) && !unlink(URL_ENT_SQLITE_FILE)) {
echo "Error removing old database.\n";
die();
}
-if (!($sqlite = sqlite_open($dbFile, 0666))) {
+if (!($sqlite = sqlite_open(URL_ENT_SQLITE_FILE, 0666))) {
echo "Error creating database.\n";
}
+
+// Table creation
$sqlCreateMeta = "
CREATE
TABLE
@@ -77,6 +70,7 @@
schemes VARCHAR(100)
);
";
+sqlite_query($sqlite, $sqlCreateMeta);
$sqlCreateChecked = "
CREATE
TABLE
@@ -89,18 +83,13 @@
return_val VARCHAR(255)
);
";
-sqlite_query($sqlite, $sqlCreateMeta);
sqlite_query($sqlite, $sqlCreateChecked);
+// read entities
if (!$file = @file_get_contents($filename)) {
- // ouput the html
- echo "<?php include_once '../include/init.inc.php';
- echo site_header('docweb.common.header.checkent');
- echo '<h1>No entities found</h1>';
- echo site_footer(); ?>";
- exit;
+ echo "No entities found.\n";
+ die();
}
-
$array = explode('<!-- Obsoletes -->', $file);
// Find entity names and URLs
@@ -111,9 +100,9 @@
$entity_names = $entities_found[1];
$entity_urls = $entities_found[3];
-$errors = array();
-$numb = 0;
+echo "Found: ". count($entity_urls) ."URLs\n";
+// log start time && schemes in DB
$sql = "
INSERT
INTO
@@ -123,32 +112,13 @@
";
sqlite_query($sqlite, $sql);
-echo "Found: ". count($entity_urls) ."URLs\n";
-
// Walk through entities found
foreach ($entity_urls as $num => $entity_url) {
-
- ++$numb;
echo "Checking: $entity_url\n";
- $err = check_url($num, $entity_url);
- $errors[$err[0]][] = $err[1];
-
- $return_val = isset($err[1][1]) ? $err[1][1] : '';
- $sql = "
- INSERT
- INTO
- checked_urls (url_num, entity, url, check_result, return_val)
- VALUES
- (
- $num,
- '". sqlite_escape_string($entity_names[$num]) ."',
- '". sqlite_escape_string($entity_url) ."',
- {$err[0]},
- '". sqlite_escape_string($return_val) ."'
- )
- ";
- sqlite_query($sqlite, $sql);
+ url_store_result($sqlite, $num, $entity_names[$num], $entity_url, check_url($num, $entity_url));
}
+
+// log end time in DB
$sql = "
UPDATE
meta_info
@@ -157,4 +127,6 @@
";
sqlite_query($sqlite, $sql);
+echo "Done.\n";
+
?>