cvs: docweb /cron/daily entities /include lib_url_entities.inc.php /scripts grab_livedocs_db.php /templates/all/www entities.tpl.php /www entities.php

[email protected] ("Sean Coates")
Newsgroups php.doc.web
Message-ID <cvssean1106631770@cvsserver>
sean		Tue Jan 25 00:42:50 2005 EDT

  Added files:                 
    /docweb/cron/daily	entities 
    /docweb/scripts	grab_livedocs_db.php 
    /docweb/templates/all/www	entities.tpl.php 
    /docweb/www	entities.php 

  Modified files:              
    /docweb/include	lib_url_entities.inc.php 
  Log:
  Port of: http://www.phpdoc.info/entities/
  Not complete, but it works; will clean up CS and language entities later
  #need sleep
  
  
http://cvs.php.net/diff.php/docweb/include/lib_url_entities.inc.php?r1=1.7&r2=1.8&ty=u
Index: docweb/include/lib_url_entities.inc.php
diff -u docweb/include/lib_url_entities.inc.php:1.7 docweb/include/lib_url_entities.inc.php:1.8
--- docweb/include/lib_url_entities.inc.php:1.7	Mon Jan 24 15:51:39 2005
+++ docweb/include/lib_url_entities.inc.php	Tue Jan 25 00:42:49 2005
@@ -19,7 +19,7 @@
 |              Mehdi Achour <[email protected]>                            |
 |              Sean Coates <[email protected]>                              |
 +----------------------------------------------------------------------+
-$Id: lib_url_entities.inc.php,v 1.7 2005/01/24 20:51:39 vincent Exp $
+$Id: lib_url_entities.inc.php,v 1.8 2005/01/25 05:42:49 sean Exp $
 */
 
 // user agent
@@ -80,11 +80,15 @@
 define('URL_ALLOW_FORK',    function_exists('pcntl_fork') && isset($_ENV['NUMFORKS']));
 define('NUM_ALLOWED_FORKS', URL_ALLOW_FORK ? $_ENV['NUMFORKS'] : 0);
 
-// SQLite DB file
-define('URL_ENT_SQLITE_FILE', SQLITE_DIR . "checkent_{$entType}.sqlite");
+// SQLite DB files
+if (isset($entType)) { // don't bother defining if $entType isn't set
+  define('URL_ENT_SQLITE_FILE',     SQLITE_DIR . "checkent_{$entType}.sqlite");
+}
+define('ENTITY_SQLITE_FILE',        SQLITE_DIR . 'livedoc-idx.en.sqlite');
+define('REMOTE_ENTITY_SQLITE_FILE', LIVEDOCS   . 'livedoc-idx.en.sqlite');
 
 /**
- * Opens a new SQLite connection
+ * Opens a new SQLite connection for URLs
  *
  * @return resource SQLite connection
  */
@@ -94,6 +98,16 @@
 }
 
 /**
+ * Opens a new SQLite connection for Entities
+ *
+ * @return resource SQLite connection
+ */
+function ent_sqlite_open()
+{
+    return @sqlite_open(ENTITY_SQLITE_FILE, 0666);
+}
+
+/**
  * Handles relative HTTP URLs
  *
  * @param string  $url    URL to handle
@@ -273,4 +287,33 @@
     ";
     sqlite_query($sqlite, $sql);
 }
+
+function url_callback($m)
+{
+  $maxLen = 57; $threshold = 3;
+  $url = $m[1] .'://'. $m[2];
+
+  if (strlen($url) > ($maxLen + $threshold))
+  {
+    $link = substr($url, 0, $maxLen) .'...';
+  }
+  else
+  {
+    $link = $url;
+  }
+
+  $html = '<a href="'. $url .'" title="'. $url .'">'. $link .'</a>';
+  return $html;
+}
+
+function ent_value($eVal)
+{
+  return preg_replace_callback('#(http|ftp)://([^\s]+)#', 'url_callback', $eVal);
+}
+
+function ent_link($eVal)
+{
+  return preg_replace('/&([^;]+);/', '<a href="entities.php#ent-\1">&amp;\1;</a>', $eVal);
+}
+
 ?>

http://cvs.php.net/co.php/docweb/scripts/grab_livedocs_db.php?r=1.1&p=1
Index: docweb/scripts/grab_livedocs_db.php
+++ docweb/scripts/grab_livedocs_db.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
+----------------------------------------------------------------------+
| PHP Documentation Site Source Code                                   |
+----------------------------------------------------------------------+
| Copyright (c) 2005 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 at through the world-wide-web at                           |
| 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.               |
+----------------------------------------------------------------------+
| Authors: Sean Coates <[email protected]>                                  |
+----------------------------------------------------------------------+
$Id: grab_livedocs_db.php,v 1.1 2005/01/25 05:42:49 sean Exp $
*/

/* Note: If someone has a more efficient way of doing this,
 *       please fee free to step up. I'm just re-using what livedocs
 *       already seems to do well... only the `ents` table is required.
 *         -S
 */

set_time_limit(0);
$scriptBegin = time();
$inCli = true;
require_once '../include/init.inc.php';
require_once '../include/lib_url_entities.inc.php';

echo "Grabbing livedocs DB...\n";

// open local file
if (!$fw = @fopen(ENTITY_SQLITE_FILE, 'w')) {
    die("Error opening local file: " . ENTITY_SQLITE_FILE ."\n");
}

// open remote livedocs DB file
if (!$fr = @fopen(REMOTE_ENTITY_SQLITE_FILE, 'r')) {
    die("Error opening remote file: " . REMOTE_ENTITY_SQLITE_FILE ."\n");
}

$bytesRead = 0;
$chunkSize = 32 * 1024; // read (up to) 32k chunks
while ($d = fread($fr, $chunkSize)) {
    $bytesRead += strlen($d);
    fwrite($fw, $d);
}

fclose($fw);
fclose($fr);

$scriptTime = time() - $scriptBegin;
$bytesSec = number_format(round($bytesRead / $scriptTime));
$bytesRead = number_format($bytesRead);
echo "Completed in $scriptTime seconds\n";
echo "$bytesRead bytes read (~$bytesSec bytes/sec)\n";

?>

http://cvs.php.net/co.php/docweb/templates/all/www/entities.tpl.php?r=1.1&p=1
Index: docweb/templates/all/www/entities.tpl.php
+++ docweb/templates/all/www/entities.tpl.php
<h1>Entities in the PHP Documentation</h1>
(non-file entities)

<table>
 <tr>
  <th>Entitiy ID</th>
  <th>Value</th>
 </tr>

 <?php foreach ($entData as $eID => $eVal) { ?>
  <tr>
   <td><a name="ent-<?php echo $eID;?>"><?php echo $eID; ?></a></td>
   <td><?php echo ent_value(ent_link(strip_tags($eVal))); ?></td>
  </tr>
 <?php } ?>
</table>

http://cvs.php.net/co.php/docweb/www/entities.php?r=1.1&p=1
Index: docweb/www/entities.php
+++ docweb/www/entities.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.0 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_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.               |
+----------------------------------------------------------------------+
| Authors: Sean Coates <[email protected]>                                  |
+----------------------------------------------------------------------+
$Id: entities.php,v 1.1 2005/01/25 05:42:49 sean Exp $
*/

require_once '../include/init.inc.php';

$entType = SITE;
require_once '../include/lib_url_entities.inc.php';

if (!$sqlite = ent_sqlite_open()) {
    echo site_header('docweb.common.header.entities'); 
    echo '<p>entities not found!</p>'; // @@@ template this
    echo site_footer();
    exit();
}

$entData = array();
$sql = "
    SELECT
        entid, value
    FROM
        ents
    WHERE
        is_file = 0
    ORDER BY
        entid
";
$entsQ = sqlite_query($sqlite, $sql);
while ($row = sqlite_fetch_array($entsQ)) {
    $entData[$row['entid']] = $row['value'];
}

echo site_header('docweb.common.header.entities');
echo DocWeb_Template::get(
        'entities.tpl.php',
        array(
            'entData'    => $entData,
        )
    );
echo site_footer();

?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.