Ejemplo n.º 1
0
 private static function treatDirectory($directory)
 {
     $site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath(JPATH_ROOT));
     $directory = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($directory));
     // Trim site root from beginning of directory
     if (substr($directory, 0, strlen($site_root)) == $site_root) {
         $directory = substr($directory, strlen($site_root));
         if (substr($directory, 0, 1) == '/') {
             $directory = substr($directory, 1);
         }
     }
     return $directory;
 }
Ejemplo n.º 2
0
 private static function treatDirectory($directory)
 {
     // Get the site's root
     $configuration = AEFactory::getConfiguration();
     if ($configuration->get('akeeba.platform.override_root', 0)) {
         $root = $configuration->get('akeeba.platform.newroot', '[SITEROOT]');
         if (stristr($root, '[')) {
             $root = AEUtilFilesystem::translateStockDirs($root);
         }
         $site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($root));
     } else {
         $site_root = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath(JPATH_ROOT));
     }
     $directory = AEUtilFilesystem::TrimTrailingSlash(AEUtilFilesystem::TranslateWinPath($directory));
     // Trim site root from beginning of directory
     if (substr($directory, 0, strlen($site_root)) == $site_root) {
         $directory = substr($directory, strlen($site_root));
         if (substr($directory, 0, 1) == '/') {
             $directory = substr($directory, 1);
         }
     }
     return $directory;
 }
Ejemplo n.º 3
0
 /**
  * Scans a directory for files and directories, updating the directory_list and file_list
  * private fields
  *
  * @return bool True if more work has to be done, false if the dirextory stack is empty
  */
 private function scan_directory()
 {
     // Are we supposed to scan for more files?
     if ($this->done_scanning) {
         return true;
     }
     // Get the next directory to scan, if the folders and files of the last directory
     // have been scanned.
     if ($this->done_subdir_scanning && $this->done_file_scanning) {
         if (count($this->directory_list) == 0) {
             // No directories left to scan
             return false;
         } else {
             // Get and remove the last entry from the $directory_list array
             $this->current_directory = array_pop($this->directory_list);
             $this->setStep($this->current_directory);
             $this->done_subdir_scanning = false;
             $this->done_file_scanning = false;
             $this->processed_files_counter = 0;
         }
     }
     $engine = AEFactory::getScanEngine();
     // Break directory components
     if (AEFactory::getConfiguration()->get('akeeba.platform.override_root', 0)) {
         $siteroot = AEFactory::getConfiguration()->get('akeeba.platform.newroot', '[SITEROOT]');
     } else {
         $siteroot = '[SITEROOT]';
     }
     $root = $this->root;
     if ($this->root == $siteroot) {
         $translated_root = AEUtilFilesystem::translateStockDirs($siteroot, true);
     } else {
         $translated_root = $this->remove_path_prefix;
     }
     $dir = AEUtilFilesystem::TrimTrailingSlash($this->current_directory);
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $translated_root = AEUtilFilesystem::TranslateWinPath($translated_root);
         $dir = AEUtilFilesystem::TranslateWinPath($dir);
     }
     if (substr($dir, 0, strlen($translated_root)) == $translated_root) {
         $dir = substr($dir, strlen($translated_root));
     } elseif (in_array(substr($translated_root, -1), array('/', '\\'))) {
         $new_translated_root = rtrim($translated_root, '/\\');
         if (substr($dir, 0, strlen($new_translated_root)) == $new_translated_root) {
             $dir = substr($dir, strlen($new_translated_root));
         }
     }
     if (substr($dir, 0, 1) == '/') {
         $dir = substr($dir, 1);
     }
     // get a filters instance
     $filters = AEFactory::getFilters();
     // Scan subdirectories, if they have not yet been scanned.
     if (!$this->done_subdir_scanning) {
         // Apply DEF (directory exclusion filters)
         // Note: the !empty($dir) prevents the site's root from being filtered out
         if ($filters->isFiltered($dir, $root, 'dir', 'all') && !empty($dir)) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping directory " . $this->current_directory);
             $this->done_subdir_scanning = true;
             $this->done_file_scanning = true;
             return true;
         }
         // Apply Skip Contained Directories Filters
         if ($filters->isFiltered($dir, $root, 'dir', 'children')) {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping subdirectories of directory " . $this->current_directory);
             $this->done_subdir_scanning = true;
         } else {
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Scanning directories of " . $this->current_directory);
             // Get subdirectories
             $subdirs = $engine->getFolders($this->current_directory);
             // Error propagation
             $this->propagateFromObject($engine);
             // If the list contains "too many" items, please break this step!
             $registry = AEFactory::getConfiguration();
             if ($registry->get('volatile.breakflag', false)) {
                 // Log the step break decision, for debugging reasons
                 AEUtilLogger::WriteLog(_AE_LOG_INFO, "Large directory " . $this->current_directory . " while scanning for subdirectories; I will resume scanning in next step.");
                 // Return immediately, marking that we are not done yet!
                 return true;
             }
             // Error control
             if ($this->getError()) {
                 return false;
             }
             if (!empty($subdirs) && is_array($subdirs)) {
                 $registry = AEFactory::getConfiguration();
                 $dereferencesymlinks = $registry->get('engine.archiver.common.dereference_symlinks');
                 if ($dereferencesymlinks) {
                     // Treat symlinks to directories as actual directories
                     foreach ($subdirs as $subdir) {
                         $this->directory_list[] = $subdir;
                         $this->progressAddFolder();
                     }
                 } else {
                     // Treat symlinks to directories as simple symlink files (ONLY WORKS WITH CERTAIN ARCHIVERS!)
                     foreach ($subdirs as $subdir) {
                         if (is_link($subdir)) {
                             // Symlink detected; apply file filters to it
                             if (empty($dir)) {
                                 $dirSlash = $dir;
                             } else {
                                 $dirSlash = $dir . '/';
                             }
                             $check = $dir . basename($subdir);
                             if (_AKEEBA_IS_WINDOWS) {
                                 $check = AEUtilFilesystem::TranslateWinPath($check);
                             }
                             // Do I need this? $dir contains a path relative to the root anyway...
                             $check = ltrim(str_replace($translated_root, '', $check), '/');
                             if ($filters->isFiltered($check, $root, 'file', 'all')) {
                                 AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping directory symlink " . $check);
                             } else {
                                 AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Adding symlink to folder as file: ' . $check);
                                 $this->file_list[] = $subdir;
                                 $this->progressAddFile();
                             }
                         } else {
                             $this->directory_list[] = $subdir;
                             $this->progressAddFolder();
                         }
                     }
                 }
             }
         }
         $this->done_subdir_scanning = true;
         return true;
         // Break operation
     }
     // If we are here, we have not yet scanned the directory for files, so there
     // is no need to test for done_file_scanning (saves a tiny amount of CPU time)
     // Apply Skipfiles
     if ($filters->isFiltered($dir, $root, 'dir', 'content')) {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping files of directory " . $this->current_directory);
         // Try to find and include .htaccess and index.htm(l) files
         // # Fix 2.4: Do not add DIRECTORY_SEPARATOR if we are on the site's root and it's an empty string
         $ds = $this->current_directory == '' || $this->current_directory == '/' ? '' : DIRECTORY_SEPARATOR;
         $checkForTheseFiles = array($this->current_directory . $ds . '.htaccess', $this->current_directory . $ds . 'index.html', $this->current_directory . $ds . 'index.htm', $this->current_directory . $ds . 'robots.txt');
         $this->processed_files_counter = 0;
         foreach ($checkForTheseFiles as $fileName) {
             if (@file_exists($fileName)) {
                 // Fix 3.3 - We have to also put them through other filters, ahem!
                 if (!$filters->isFiltered($fileName, $root, 'file', 'all')) {
                     $this->file_list[] = $fileName;
                     $this->processed_files_counter++;
                 }
             }
         }
         $this->done_file_scanning = true;
     } else {
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Scanning files of " . $this->current_directory);
         // Get file listing
         $fileList = $engine->getFiles($this->current_directory);
         // Error propagation
         $this->propagateFromObject($engine);
         // If the list contains "too many" items, please break this step!
         $registry = AEFactory::getConfiguration();
         if ($registry->get('volatile.breakflag', false)) {
             // Log the step break decision, for debugging reasons
             AEUtilLogger::WriteLog(_AE_LOG_INFO, "Large directory " . $this->current_directory . " while scanning for files; I will resume scanning in next step.");
             // Return immediately, marking that we are not done yet!
             return true;
         }
         // Error control
         if ($this->getError()) {
             return false;
         }
         $this->processed_files_counter = 0;
         if ($fileList === false) {
             // A non-browsable directory; however, it seems that I never get FALSE reported here?!
             $this->setWarning('Unreadable directory ' . $this->current_directory);
         } else {
             if (is_array($fileList) && !empty($fileList)) {
                 // Add required trailing slash to $dir
                 if (!empty($dir)) {
                     $dir .= '/';
                 }
                 // Scan all directory entries
                 foreach ($fileList as $fileName) {
                     $check = $dir . basename($fileName);
                     if (_AKEEBA_IS_WINDOWS) {
                         $check = AEUtilFilesystem::TranslateWinPath($check);
                     }
                     // Do I need this? $dir contains a path relative to the root anyway...
                     $check = ltrim(str_replace($translated_root, '', $check), '/');
                     $skipThisFile = $filters->isFiltered($check, $root, 'file', 'all');
                     if ($skipThisFile) {
                         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Skipping file {$fileName}");
                     } else {
                         $this->file_list[] = $fileName;
                         $this->processed_files_counter++;
                         $this->progressAddFile();
                     }
                 }
                 // end foreach
             }
             // end if
         }
         // end filelist not false
         $this->done_file_scanning = true;
     }
     // Check to see if there were no contents of this directory added to our search list
     if ($this->processed_files_counter == 0) {
         $archiver = AEFactory::getArchiverEngine();
         if ($this->current_directory != $this->remove_path_prefix) {
             $archiver->addFile($this->current_directory, $this->remove_path_prefix, $this->path_prefix);
         }
         // Error propagation
         $this->propagateFromObject($archiver);
         if ($this->getError()) {
             return false;
         }
         AEUtilLogger::WriteLog(_AE_LOG_INFO, "Empty directory " . $this->current_directory);
         unset($archiver);
         $this->done_scanning = false;
         // Because it was an empty dir $file_list is empty and we have to scan for more files
     } else {
         // Next up, add the files to the archive!
         $this->done_scanning = true;
     }
     // We're done listing the contents of this directory
     unset($engine);
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Returns the site root, the translated site root and the translated current directory
  *
  * @return array
  */
 private function getCleanDirectoryComponents()
 {
     // Break directory components
     if (AEFactory::getConfiguration()->get('akeeba.platform.override_root', 0)) {
         $siteroot = AEFactory::getConfiguration()->get('akeeba.platform.newroot', '[SITEROOT]');
     } else {
         $siteroot = '[SITEROOT]';
     }
     $root = $this->root;
     if ($this->root == $siteroot) {
         $translated_root = AEUtilFilesystem::translateStockDirs($siteroot, true);
     } else {
         $translated_root = $this->remove_path_prefix;
     }
     $dir = AEUtilFilesystem::TrimTrailingSlash($this->current_directory);
     if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
         $translated_root = AEUtilFilesystem::TranslateWinPath($translated_root);
         $dir = AEUtilFilesystem::TranslateWinPath($dir);
     }
     if (substr($dir, 0, strlen($translated_root)) == $translated_root) {
         $dir = substr($dir, strlen($translated_root));
     } elseif (in_array(substr($translated_root, -1), array('/', '\\'))) {
         $new_translated_root = rtrim($translated_root, '/\\');
         if (substr($dir, 0, strlen($new_translated_root)) == $new_translated_root) {
             $dir = substr($dir, strlen($new_translated_root));
         }
     }
     if (substr($dir, 0, 1) == '/') {
         $dir = substr($dir, 1);
     }
     return array($root, $translated_root, $dir);
 }