Source for file classes_file.php

Documentation is available at classes_file.php

  1. <?php
  2.  
  3. class b_resource extends b_object {
  4. //base resource definition
  5. var $path;
  6. var $resource_type;
  7. var $create_date;
  8. var $name;
  9. var $description;
  10. function b_resource( $constructID, $typeName, $objectInfo = NULL ) {
  11. $this->type =& $GLOBALS['core']->get_object_type( $typeName );
  12. if( !$object_info && !$object_info =& $this->type->object_info[ $constructID ] ) {
  13. global $db;
  14. if( $object_info = $db->get_results( "SELECT * FROM ".$this->type->type_table_name." WHERE id = '".$constructID."' || path = '".format_path($constructID)."'", ARRAY_A ) ) {
  15. $object_info = reset($object_info);
  16. }
  17. }
  18. parent::b_object( $object_info['id'], $typeName, $object_info );
  19. $this->create_date = toPhpDate( $this->create_date );
  20. $this->resource_type = $this->set_resource_type();
  21. }
  22. function verify_set( $post ) {
  23. //windows file handling
  24. if( $post['path'] ) { $post['path'] = format_path( $post['path'] ); }
  25. //date handling
  26. if( !$post['create_date'] && isset( $post['create_date'] ) ) {
  27. if( $post['create_date'] ) {
  28. $post['create_date'] = toDbDate( $post['create_date'] );
  29. } else {
  30. //if no date specified
  31. //use the file's last modify date or the current date
  32. if( !$time = filemtime( $this->path ) ) {
  33. $time = 'today';
  34. }
  35. $post['create_date'] = toDbDate( $time );
  36. }
  37. }
  38. //name handling
  39. if( $post['path'] && !$post['name'] ) {
  40. $post['name'] = basename($post['path'],"\/");
  41. }
  42. if( $post['path'] && !file_exists( $post['path'] ) ) {
  43. $returnArray['path'] = 'file or directory does not exist';
  44. }
  45. if( !count($returnArray) ) {
  46. parent::verify_set( $post );
  47. } else {
  48. $GLOBALS['errorArray'] = $returnArray;
  49. //$this->set_object( $post );
  50. }
  51. }
  52.  
  53. function set_resource_type() {
  54. //NOTE: this is currently set up to determine where the resource is located, not so much the type of the resource
  55. if( !$type ) {
  56. if( stristr( $this->path, 'http://' ) ) { return 'href'; }
  57. else if( stristr( $this->path, 'ftp://' ) ) { return 'ftp'; }
  58. else { return 'file'; }
  59. } else {
  60. return $type;
  61. }
  62. }
  63. function validate() {
  64. if( $this->resource_type == 'file' ) {
  65. return file_exists( $this->path );
  66. } else {
  67. return true;
  68. }
  69. }
  70. }
  71.  
  72. ?>

Documentation generated on Tue, 24 May 2005 03:57:04 -0400 by phpDocumentor 1.3.0RC3