iTx Technologies offre gratuitement
cet espace pour SugarCRM !

title

Body

[fermer]

/include/ -> dir_inc.php (source)

   1  <?php
   2  if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
   3  /*********************************************************************************
   4   * SugarCRM is a customer relationship management program developed by
   5   * SugarCRM, Inc. Copyright (C) 2004 - 2009 SugarCRM Inc.
   6   * 
   7   * This program is free software; you can redistribute it and/or modify it under
   8   * the terms of the GNU General Public License version 3 as published by the
   9   * Free Software Foundation with the addition of the following permission added
  10   * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11   * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12   * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13   * 
  14   * This program is distributed in the hope that it will be useful, but WITHOUT
  15   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  17   * details.
  18   * 
  19   * You should have received a copy of the GNU General Public License along with
  20   * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21   * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22   * 02110-1301 USA.
  23   * 
  24   * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25   * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26   * 
  27   * The interactive user interfaces in modified source and object code versions
  28   * of this program must display Appropriate Legal Notices, as required under
  29   * Section 5 of the GNU General Public License version 3.
  30   * 
  31   * In accordance with Section 7(b) of the GNU General Public License version 3,
  32   * these Appropriate Legal Notices must retain the display of the "Powered by
  33   * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34   * technical reasons, the Appropriate Legal Notices must display the words
  35   * "Powered by SugarCRM".
  36   ********************************************************************************/
  37  
  38  
  39  function copy_recursive( $source, $dest ){
  40  
  41  
  42  
  43  
  44  
  45  
  46  
  47      if( is_file( $source ) ){
  48          return( copy( $source, $dest ) );
  49      }
  50      if( !sugar_is_dir($dest, 'instance') ){
  51          sugar_mkdir( $dest );
  52      }
  53  
  54      $status = true;
  55  
  56      $d = dir( $source );
  57      while( $f = $d->read() ){
  58          if( $f == "." || $f == ".." ){
  59              continue;
  60          }
  61          $status &= copy_recursive( "$source/$f", "$dest/$f" );
  62      }
  63      $d->close();
  64      return( $status );
  65  }
  66  
  67  function mkdir_recursive($path, $check_is_parent_dir = false) {
  68      if(sugar_is_dir($path, 'instance')) {
  69          return(true);
  70      }
  71      if(sugar_is_file($path, 'instance')) {
  72          print("ERROR: mkdir_recursive(): argument $path is already a file.\n");
  73          return false;
  74      }
  75  
  76      $path = clean_path($path);
  77      $path = str_replace(clean_path(getcwd()), '', $path);
  78      $thePath = '';
  79      $dirStructure = explode("/", $path);
  80      $status = true;
  81      foreach($dirStructure as $dirPath) {
  82          $thePath .= '/'.$dirPath;
  83          $mkPath = getcwd().'/'.$thePath;
  84  
  85          if(!is_dir($mkPath )) {
  86              $status = $status & sugar_mkdir($mkPath);
  87          }
  88      }
  89      return $status;
  90  
  91  }
  92  
  93  function rmdir_recursive( $path ){
  94      if( is_file( $path ) ){
  95          return( unlink( $path ) );
  96      }
  97      if( !is_dir( $path ) ){
  98          print( "ERROR: rmdir_recursive(): argument $path is not a file or a dir.\n" );
  99          return( false );
 100      }
 101  
 102      $status = true;
 103  
 104      $d = dir( $path );
 105      while( $f = $d->read() ){
 106          if( $f == "." || $f == ".." ){
 107              continue;
 108          }
 109          $status &= rmdir_recursive( "$path/$f" );
 110      }
 111      $d->close();
 112      rmdir( $path );
 113      return( $status );
 114  }
 115  
 116  function findTextFiles( $the_dir, $the_array ){
 117      if(!is_dir($the_dir)) {
 118          return $the_array;
 119      }
 120      $d = dir($the_dir);
 121      while (false !== ($f = $d->read())) {
 122          if( $f == "." || $f == ".." ){
 123              continue;
 124          }
 125          if( is_dir( "$the_dir/$f" ) ){
 126              // i think depth first is ok, given our cvs repo structure -Bob.
 127              $the_array = findTextFiles( "$the_dir/$f", $the_array );
 128          }
 129          else {
 130              switch( mime_content_type( "$the_dir/$f" ) ){
 131                  // we take action on these cases
 132                  case "text/html":
 133                  case "text/plain":
 134                      array_push( $the_array, "$the_dir/$f" );
 135                      break;
 136                  // we consciously skip these types
 137                  case "application/pdf":
 138                  case "application/x-zip":
 139                  case "image/gif":
 140                  case "image/jpeg":
 141                  case "image/png":
 142                  case "text/rtf":
 143                      break;
 144                  default:
 145                      debug( "no type handler for $the_dir/$f with mime_content_type: " . mime_content_type( "$the_dir/$f" ) . "\n" );
 146              }
 147          }
 148      }
 149      return( $the_array );
 150  }
 151  
 152  function findAllFiles( $the_dir, $the_array, $include_dirs=false, $ext='', $exclude_dir=''){
 153      // jchi  #24296 
 154      if(!empty($exclude_dir)){
 155          $exclude_dir = is_array($exclude_dir)?$exclude_dir:array($exclude_dir);
 156          foreach($exclude_dir as $ex_dir){             
 157              if($the_dir == $ex_dir){
 158                    return $the_array;
 159              }                
 160          }
 161      }
 162      //end
 163      if(!is_dir($the_dir)) {
 164          return $the_array;
 165      }
 166      $d = dir($the_dir);
 167      while (false !== ($f = $d->read())) {
 168          if( $f == "." || $f == ".." ){
 169              continue;
 170          }
 171  
 172          if( is_dir( "$the_dir/$f" ) ) {
 173              // jchi  #24296 
 174              if(!empty($exclude_dir)){
 175                  //loop through array to compare directories..
 176                  foreach($exclude_dir as $ex_dir){             
 177                      if("$the_dir/$f" == $ex_dir){
 178                            continue 2;
 179                      }                
 180                  }
 181              }
 182              //end
 183              
 184              if($include_dirs) {
 185                  $the_array[] = clean_path("$the_dir/$f");
 186              }
 187              $the_array = findAllFiles( "$the_dir/$f/", $the_array, $include_dirs, $ext);
 188          } else {
 189              if(empty($ext) || preg_match("/{$ext}$/i", $f)){
 190                  $the_array[] = clean_path("$the_dir/$f");
 191              }
 192          }
 193  
 194  
 195      }
 196      rsort($the_array);
 197      return $the_array;
 198  }
 199  
 200  function findAllFilesRelative( $the_dir, $the_array ){
 201      if(!is_dir($the_dir)) {
 202          return $the_array;
 203      }
 204      $original_dir   = getCwd();
 205      if(is_dir($the_dir)){
 206          chdir( $the_dir );
 207          $the_array = findAllFiles( ".", $the_array );
 208          if(is_dir($original_dir)){
 209              chdir( $original_dir );
 210          }
 211      }
 212      return( $the_array );
 213  }
 214  
 215  /*
 216   * Obtain an array of files that have been modified after the $date_modified
 217   *
 218   * @param the_dir            the directory to begin the search
 219   * @param the_array            array to hold the results
 220   * @param date_modified        the date to use when searching for files that have
 221   *                             been modified
 222   * @param filter            optional regular expression filter
 223   *
 224   * return                    an array containing all of the files that have been
 225   *                             modified since date_modified
 226   */
 227  function findAllTouchedFiles( $the_dir, $the_array, $date_modified, $filter=''){
 228      if(!is_dir($the_dir)) {
 229          return $the_array;
 230      }
 231      $d = dir($the_dir);
 232      while (false !== ($f = $d->read())) {
 233          if( $f == "." || $f == ".." ){
 234              continue;
 235          }
 236          if( is_dir( "$the_dir/$f" ) ){
 237              // i think depth first is ok, given our cvs repo structure -Bob.
 238              $the_array = findAllTouchedFiles( "$the_dir/$f", $the_array, $date_modified, $filter);
 239          }
 240          else {
 241              $file_date = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s', filemtime("$the_dir/$f"))) - date('Z'));
 242  
 243              if(strtotime($file_date) > strtotime($date_modified) && (empty($filter) || preg_match($filter, $f))){
 244                   array_push( $the_array, "$the_dir/$f");
 245              }
 246          }
 247      }
 248      return( $the_array );
 249  }
 250  ?>


Generé en: Thu Mar 4 09:44:50 2010 | Cross-referenced par PHPXref 0.7