PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/sugarcrm/SugarCE-Full-5.0.0/translate/inc/sugar_inc/dir_inc.php

http://twpug.googlecode.com/
PHP | 140 lines | 105 code | 10 blank | 25 comment | 29 complexity | 01549f2318b5ec440f47dc65b6eb738a MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /*********************************************************************************
  3. * The contents of this file are subject to the SugarCRM Public License Version
  4. * 1.1.3 ("License"); You may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
  6. * Software distributed under the License is distributed on an "AS IS" basis,
  7. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  8. * for the specific language governing rights and limitations under the
  9. * License.
  10. *
  11. * All copies of the Covered Code must include on each user interface screen:
  12. * (i) the "Powered by SugarCRM" logo and
  13. * (ii) the SugarCRM copyright notice
  14. * in the same form as they appear in the distribution. See full license for
  15. * requirements.
  16. *
  17. * The Original Code is: SugarCRM Open Source
  18. * The Initial Developer of the Original Code is SugarCRM, Inc.
  19. * Portions created by SugarCRM are Copyright (C) 2004-2005 SugarCRM, Inc.;
  20. * All Rights Reserved.
  21. * Contributor(s): ______________________________________.
  22. ********************************************************************************/
  23. function copy_recursive( $source, $dest ){
  24. if( is_file( $source ) ){
  25. return( copy( $source, $dest ) );
  26. }
  27. if( !is_dir($dest) ){
  28. mkdir( $dest );
  29. }
  30. $status = true;
  31. $d = dir( $source );
  32. while( $f = $d->read() ){
  33. if( $f == "." || $f == ".." ){
  34. continue;
  35. }
  36. $status &= copy_recursive( "$source/$f", "$dest/$f" );
  37. }
  38. $d->close();
  39. return( $status );
  40. }
  41. function mkdir_recursive( $path , $check_is_parent_dir = false){
  42. if( is_dir( $path ) ){
  43. return( true );
  44. }
  45. if( is_file( $path ) ){
  46. print( "ERROR: mkdir_recursive(): argument $path is already a file.\n" );
  47. return( false );
  48. }
  49. $parent_dir = substr( $path, 0, strrpos( $path, "/" ) );
  50. if( mkdir_recursive( $parent_dir ) ){
  51. return ($check_is_parent_dir && is_dir($path))|| ( mkdir( $path ) );
  52. }
  53. return( false );
  54. }
  55. function rmdir_recursive( $path ){
  56. if( is_file( $path ) ){
  57. return( unlink( $path ) );
  58. }
  59. if( !is_dir( $path ) ){
  60. print( "ERROR: rmdir_recursive(): argument $path is not a file or a dir.\n" );
  61. return( false );
  62. }
  63. $status = true;
  64. $d = dir( $path );
  65. while( $f = $d->read() ){
  66. if( $f == "." || $f == ".." ){
  67. continue;
  68. }
  69. $status &= rmdir_recursive( "$path/$f" );
  70. }
  71. $d->close();
  72. rmdir( $path );
  73. return( $status );
  74. }
  75. function findTextFiles( $the_dir, $the_array ){
  76. $d = dir( $the_dir );
  77. while( $f = $d->read() ){
  78. if( $f == "." || $f == ".." ){
  79. continue;
  80. }
  81. if( is_dir( "$the_dir/$f" ) ){
  82. // i think depth first is ok, given our cvs repo structure -Bob.
  83. $the_array = findTextFiles( "$the_dir/$f", $the_array );
  84. }
  85. else {
  86. switch( mime_content_type( "$the_dir/$f" ) ){
  87. // we take action on these cases
  88. case "text/html":
  89. case "text/plain":
  90. array_push( $the_array, "$the_dir/$f" );
  91. break;
  92. // we consciously skip these types
  93. case "application/pdf":
  94. case "application/x-zip":
  95. case "image/gif":
  96. case "image/jpeg":
  97. case "image/png":
  98. case "text/rtf":
  99. break;
  100. default:
  101. debug( "no type handler for $the_dir/$f with mime_content_type: " . mime_content_type( "$the_dir/$f" ) . "\n" );
  102. }
  103. }
  104. }
  105. return( $the_array );
  106. }
  107. function findAllFiles( $the_dir, $the_array ){
  108. $d = dir( $the_dir );
  109. while( $f = $d->read() ){
  110. if( $f == "." || $f == ".." ){
  111. continue;
  112. }
  113. if( is_dir( "$the_dir/$f" ) ){
  114. // i think depth first is ok, given our cvs repo structure -Bob.
  115. $the_array = findAllFiles( "$the_dir/$f", $the_array );
  116. }
  117. else {
  118. array_push( $the_array, "$the_dir/$f" );
  119. }
  120. }
  121. return( $the_array );
  122. }
  123. function findAllFilesRelative( $the_dir, $the_array ){
  124. $original_dir = getCwd();
  125. chdir( $the_dir );
  126. $the_array = findAllFiles( ".", $the_array );
  127. chdir( $original_dir );
  128. return( $the_array );
  129. }
  130. ?>