home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / files / files.class.php < prev    next >
Encoding:
PHP Script  |  2003-10-27  |  3.5 KB  |  133 lines

  1. <?php /* FILES $Id: files.class.php,v 1.7 2003/10/27 00:05:29 ajdonnison Exp $ */
  2. /**
  3. * File Class
  4. */
  5. class CFile extends CDpObject {
  6.     var $file_id = NULL;
  7.     var $file_project = NULL;
  8.     var $file_real_filename = NULL;
  9.     var $file_task = NULL;
  10.     var $file_name = NULL;
  11.     var $file_parent = NULL;
  12.     var $file_description = NULL;
  13.     var $file_type = NULL;
  14.     var $file_owner = NULL;
  15.     var $file_date = NULL;
  16.     var $file_size = NULL;
  17.     var $file_version = NULL;
  18.  
  19.     function CFile() {
  20.         $this->CDpObject( 'files', 'file_id' );
  21.     }
  22.  
  23.     function check() {
  24.     // ensure the integrity of some variables
  25.         $this->file_id = intval( $this->file_id );
  26.         $this->file_parent = intval( $this->file_parent );
  27.         $this->file_task = intval( $this->file_task );
  28.         $this->file_project = intval( $this->file_project );
  29.  
  30.         return NULL; // object is ok
  31.     }
  32.  
  33.     function delete() {
  34.         global $AppUI;
  35.     // remove the file from the file system
  36.         @unlink( "{$AppUI->cfg['root_dir']}/files/$this->file_project/$this->file_real_filename" );
  37.     // delete any index entries
  38.         $sql = "DELETE FROM files_index WHERE file_id = $this->file_id";
  39.         if (!db_exec( $sql )) {
  40.             return db_error();
  41.         }
  42.     // delete the main table reference
  43.         $sql = "DELETE FROM files WHERE file_id = $this->file_id";
  44.         if (!db_exec( $sql )) {
  45.             return db_error();
  46.         }
  47.         return NULL;
  48.     }
  49.  
  50. // move a file from a temporary (uploaded) location to the file system
  51.     function moveTemp( $upload ) {
  52.         global $AppUI;
  53.     // check that directories are created
  54.         if (!is_dir("{$AppUI->cfg['root_dir']}/files")) {
  55.             $res = mkdir( "{$AppUI->cfg['root_dir']}/files", 0777 );
  56.             if (!$res) {
  57.                  return false;
  58.              }
  59.         }
  60.         if (!is_dir("{$AppUI->cfg['root_dir']}/files/$this->file_project")) {
  61.             $res = mkdir( "{$AppUI->cfg['root_dir']}/files/$this->file_project", 0777 );
  62.              if (!$res) {
  63.                  return false;
  64.              }
  65.         }
  66.  
  67.  
  68.         $this->_filepath = "{$AppUI->cfg['root_dir']}/files/$this->file_project/$this->file_real_filename";
  69.     // move it
  70.         $res = move_uploaded_file( $upload['tmp_name'], $this->_filepath );
  71.         if (!$res) {
  72.             return false;
  73.         }
  74.         return true;
  75.     }
  76.  
  77. // parse file for indexing
  78.     function indexStrings() {
  79.         GLOBAL $ft, $AppUI;
  80.     // get the parser application
  81.         $parser = @$ft[$this->file_type];
  82.         if (!$parser) {
  83.             return false;
  84.         }
  85.     // buffer the file
  86.         $fp = fopen( $this->_filepath, "rb" );
  87.         $x = fread( $fp, $this->file_size );
  88.         fclose( $fp );
  89.     // parse it
  90.         $parser = $parser . " " . $this->_filepath;
  91.         $pos = strpos( $parser, '/pdf' );
  92.         if (false !== $pos) {
  93.             $x = `$parser -`;
  94.         } else {
  95.             $x = `$parser`;
  96.         }
  97.     // if nothing, return
  98.         if (strlen( $x ) < 1) {
  99.             return 0;
  100.         }
  101.     // remove punctuation and parse the strings
  102.         $x = str_replace( array( ".", ",", "!", "@", "(", ")" ), " ", $x );
  103.         $warr = split( "[[:space:]]", $x );
  104.  
  105.         $wordarr = array();
  106.         $nwords = count( $warr );
  107.         for ($x=0; $x < $nwords; $x++) {
  108.             $newword = $warr[$x];
  109.             if (!ereg( "[[:punct:]]", $newword )
  110.                 && strlen( trim( $newword ) ) > 2
  111.                 && !ereg( "[[:digit:]]", $newword )) {
  112.                 $wordarr[] = array( "word" => $newword, "wordplace" => $x );
  113.             }
  114.         }
  115.         db_exec( "LOCK TABLES files_index WRITE" );
  116.     // filter out common strings
  117.         $ignore = array();
  118.         include "{$AppUI->cfg['root_dir']}/modules/files/file_index_ignore.php";
  119.         foreach ($ignore as $w) {
  120.             unset( $wordarr[$w] );
  121.         }
  122.     // insert the strings into the table
  123.         while (list( $key, $val ) = each( $wordarr )) {
  124.             $sql = "INSERT INTO files_index VALUES ('" . $this->file_id . "', '" . $wordarr[$key]['word'] . "', '" . $wordarr[$key]['wordplace'] . "')";
  125.             db_exec( $sql );
  126.         }
  127.  
  128.         db_exec( "UNLOCK TABLES;" );
  129.         return nwords;
  130.     }
  131. }
  132. ?>
  133.