Exemplo n.º 1
0
 /**
  * Get file list (retrieve and sort)
  *
  * @param   array  $params
  * @return  array
  */
 public function filelist($params = [])
 {
     // Parse incoming params and establish defaults
     $filter = isset($params['filter']) ? $params['filter'] : NULL;
     $dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
     $showUntracked = isset($params['showUntracked']) ? $params['showUntracked'] : false;
     $remotes = isset($params['remoteConnections']) ? $params['remoteConnections'] : [];
     $sortdir = isset($params['sortdir']) && $params['sortdir'] == 'DESC' ? SORT_DESC : SORT_ASC;
     $sortby = isset($params['sortby']) ? $params['sortby'] : 'name';
     $files = isset($params['files']) && is_array($params['files']) ? $params['files'] : [];
     $dirsOnly = isset($params['dirsOnly']) ? $params['dirsOnly'] : false;
     if (!$dirsOnly) {
         // Get a list of files from the git repository
         $files = empty($files) ? $this->_git->getFiles($dirPath) : $files;
         // Add untracked?
         $untracked = $showUntracked ? $this->_git->getUntrackedFiles($dirPath) : [];
         if (!empty($untracked)) {
             $files = array_merge($files, $untracked);
         }
         // Include remote connections?
         if (!empty($remotes)) {
             foreach ($remotes as $name => $item) {
                 $files[] = $name;
             }
         }
     } else {
         // This is recursive by default
         $files = empty($files) ? $this->_git->getDirectories($dirPath) : $files;
         // Add untracked?
         $untracked = $showUntracked ? $this->_git->getUntrackedDirectories($dirPath) : [];
         if (!empty($untracked)) {
             $files = array_merge($files, $untracked);
         }
     }
     // Duplicates can be introduced by the remotes
     $files = array_unique($files);
     // Output containers
     $items = [];
     $sorting = [];
     // Apply the filter early, reduces iterations through foreach()
     if (isset($filter) && $filter != '') {
         $files = preg_grep("(" . $filter . ")", $files);
     }
     // Go through items and get what we need
     foreach ($files as $item) {
         $item = urldecode($item);
         if (trim($item) == '') {
             continue;
         }
         // Load basic file metadata
         $file = new Models\File($item, $this->_path);
         // Untracked?
         if (in_array($file->get('localPath'), $untracked)) {
             $file->set('untracked', true);
         }
         // Skip this
         if ($file->get('name') == '.gitignore') {
             continue;
         }
         // Check for remote connections
         $syncRecord = NULL;
         if (isset($remotes[$file->get('localPath')])) {
             // Pick up data from sync record
             $syncRecord = $remotes[$file->get('localPath')];
             $file->set('remote', $syncRecord->service);
             $file->set('author', $syncRecord->remote_author);
             $file->set('date', date('c', strtotime($syncRecord->remote_modified . ' UTC')));
             $file->set('mimeType', $syncRecord->remote_format);
             $file->set('converted', $syncRecord->remote_editing);
         }
         // Add to list
         if (empty($items[$file->get('name')])) {
             $items[$file->get('localPath')] = $file;
             // Collect info for sorting
             switch ($sortby) {
                 case 'size':
                     $sorting[] = $file->getSize();
                     break;
                 case 'modified':
                     // Need to get extra metadata (slower)
                     $sorting[] = $this->_file($file, $dirPath, 'date');
                     break;
                 case 'localpath':
                     $sorting[] = strtolower($file->get('localPath'));
                     break;
                 case 'name':
                 default:
                     $sorting[] = strtolower($file->get('name'));
                     break;
             }
         }
     }
     // Sort
     array_multisort($sorting, $sortdir, $items);
     // Apply start and limit, get complete metadata and return
     return $this->_list($items, $params);
 }
Exemplo n.º 2
0
 /**
  * Add files to repo from extracted archive
  *
  * @return  boolean
  */
 protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
 {
     $reserved = isset($params['reserved']) ? $params['reserved'] : array();
     $dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
     $extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
     // check for viruses - scans the directory for efficency
     $command = "clamscan -i --no-summary --block-encrypted -r " . $extractPath;
     exec($command, $output, $virus_status);
     $virusChecked = FALSE;
     if ($virus_status == 0) {
         $virusChecked = TRUE;
     } else {
         Filesystem::deleteDirectory($extractPath);
         $this->setError('The antivirus software has rejected your files.');
         return false;
     }
     $z = 0;
     foreach ($extracted as $e) {
         $fileinfo = pathinfo($e);
         $a_dir = $fileinfo['dirname'];
         $a_dir = str_replace($extractPath . DS, '', $a_dir);
         // Skip certain system files
         if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
             continue;
         }
         $file = $fileinfo['basename'];
         $size = filesize($e);
         // Run some checks, stop in case of a problem
         if (!$this->_check($file, $e, $size, $available, $virusChecked)) {
             return false;
         }
         // Clean up filename
         $safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
         $safe_dir = trim($safe_dir, DS);
         $safe_file = Filesystem::clean($file);
         // Strips out temporary path
         if (strpos($safe_dir, 'tmp/') !== FALSE) {
             $parts = explode('/', $safe_dir);
             $safe_dir = str_replace($parts[0] . '/', '', $safe_dir);
             $safe_dir = str_replace($parts[1] . '/', '', $safe_dir);
         }
         $skipDir = false;
         if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
             $skipDir = true;
         }
         $safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
         $localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
         $where = $target . DS . $safeName;
         $exists = is_file($where) ? true : false;
         // Provision directory
         if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
             if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
                 // File object
                 $localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
                 $fileObject = new Models\File(trim($localDirPath), $this->get('path'));
                 $fileObject->set('type', 'folder');
                 $params['file'] = $fileObject;
                 $params['replace'] = false;
                 // Success - check in change
                 $this->call('checkin', $params);
                 $z++;
             }
         }
         // Strips out temporary path
         if (strpos($safeName, 'tmp/') !== FALSE) {
             $parts = explode('/', $safeName);
             $safeName = str_replace($parts[0] . '/', '', $safeName);
             $safeName = str_replace($parts[1] . '/', '', $safeName);
         }
         // Copy file into project
         if (Filesystem::copy($e, $target . DS . $safeName)) {
             // File object
             $fileObject = new Models\File(trim($localPath), $this->get('path'));
             $params['file'] = $fileObject;
             $params['replace'] = $exists;
             // Success - check in change
             $this->call('checkin', $params);
             $z++;
         }
     }
     return $z;
 }
Exemplo n.º 3
0
 /**
  * Get file list (retrieve and sort)
  *
  * @param      array	$params
  *
  * @return     array
  */
 public function filelist($params = array())
 {
     // Accept params
     $filter = isset($params['filter']) ? $params['filter'] : NULL;
     $dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
     $showUntracked = isset($params['showUntracked']) ? $params['showUntracked'] : false;
     $remotes = isset($params['remoteConnections']) ? $params['remoteConnections'] : array();
     $sortdir = isset($params['sortdir']) && $params['sortdir'] == 'DESC' ? SORT_DESC : SORT_ASC;
     $sortby = isset($params['sortby']) ? $params['sortby'] : 'name';
     $getParents = isset($params['getParents']) ? $params['getParents'] : false;
     $getChildren = isset($params['getChildren']) ? $params['getChildren'] : false;
     $files = isset($params['files']) && is_array($params['files']) ? $params['files'] : array();
     // Get a list of files Git repo
     $files = empty($files) ? $this->_git->getFiles($dirPath, false) : $files;
     // Add untracked?
     $untracked = $showUntracked ? $this->_git->getFiles($dirPath, true) : array();
     if (!empty($untracked)) {
         $files = array_merge($files, $untracked);
     }
     // Include remote connections?
     if (!empty($remotes)) {
         foreach ($remotes as $name => $item) {
             $files[] = $name;
         }
     }
     $remote = $this->get('remote');
     // Output containers
     $items = array();
     $sorting = array();
     $folders = array();
     if ($dirPath) {
         $folders[] = $dirPath;
     }
     // Go through items and get what we need
     foreach ($files as $item) {
         $item = urldecode($item);
         if (trim($item) == '') {
             continue;
         }
         // Load basic file metadata
         $file = new Models\File($item, $this->_path);
         // Search filter applied
         if ($filter && strpos(trim($file->get('localPath')), trim($filter)) === false && strpos(trim($file->get('localPath')), trim($filter)) === false) {
             continue;
         } elseif ($filter) {
             $getParents = false;
         }
         // Untracked?
         if (in_array($file->get('localPath'), $untracked)) {
             $file->set('untracked', true);
         }
         // Do we have a parent? Get folder information
         if ($file->get('dirname') && !in_array($file->get('dirname'), $folders)) {
             // Folder metadata
             $file->setFolder();
             // Add to list
             if (empty($items[$file->get('name')])) {
                 // Recursive check
                 if ($getChildren || !$getChildren && $file->getDirLevel($dirPath) > $file->getDirLevel($file->get('dirname'))) {
                     $folders[] = $file->get('localPath');
                     if (!$getParents) {
                         continue;
                     }
                     $items[$file->get('name')] = $file;
                     // Collect info for sorting
                     switch ($sortby) {
                         case 'size':
                             $sorting[] = $file->getSize();
                             break;
                         case 'modified':
                             // Need to get extra metadata (slower)
                             $sorting[] = '';
                             break;
                         case 'localpath':
                             $sorting[] = strtolower($file->get('localPath'));
                             break;
                         case 'name':
                         default:
                             $sorting[] = strtolower($file->get('name'));
                             break;
                     }
                 }
             }
         }
         // Getting parent information?
         if ($getParents) {
             $file->setParents();
         }
         // Do not recurse
         if (!$getChildren && $file->get('dirname')) {
             if (!$dirPath || $dirPath != $file->get('dirname')) {
                 continue;
             }
         }
         // Skip this
         if ($file->get('name') == '.gitignore') {
             continue;
         }
         // Check for remote connections
         $syncRecord = NULL;
         if (isset($remotes[$file->get('localPath')])) {
             // Pick up data from sync record
             $syncRecord = $remotes[$file->get('localPath')];
             $file->set('remote', $syncRecord->service);
             $file->set('author', $syncRecord->remote_author);
             $file->set('date', date('c', strtotime($syncRecord->remote_modified . ' UTC')));
             $file->set('mimeType', $syncRecord->remote_format);
         }
         // Add to list
         if (empty($items[$file->get('name')])) {
             $items[$file->get('name')] = $file;
             // Collect info for sorting
             switch ($sortby) {
                 case 'size':
                     $sorting[] = $file->getSize();
                     break;
                 case 'modified':
                     // Need to get extra metadata (slower)
                     $sorting[] = $this->_file($file, $dirPath, 'date');
                     break;
                 case 'localpath':
                     $sorting[] = strtolower($file->get('localPath'));
                     break;
                 case 'name':
                 default:
                     $sorting[] = strtolower($file->get('name'));
                     break;
             }
         }
     }
     // Sort
     array_multisort($sorting, $sortdir, $items);
     // Apply start and limit, get complete metadata and return
     return $this->_list($items, $params);
 }
Exemplo n.º 4
0
 /**
  * Add files to repo from extracted archive
  *
  * @return  boolean
  */
 protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
 {
     $reserved = isset($params['reserved']) ? $params['reserved'] : array();
     $dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
     $extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
     $z = 0;
     foreach ($extracted as $e) {
         $fileinfo = pathinfo($e);
         $a_dir = $fileinfo['dirname'];
         $a_dir = str_replace($extractPath . DS, '', $a_dir);
         // Skip certain system files
         if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
             continue;
         }
         $file = $fileinfo['basename'];
         $size = filesize($e);
         // Run some checks, stop in case of a problem
         if (!$this->_check($file, $e, $size, $available)) {
             return false;
         }
         // Clean up filename
         $safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
         $safe_dir = trim($safe_dir, DS);
         $safe_file = Filesystem::clean($file);
         $skipDir = false;
         if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
             $skipDir = true;
         }
         $safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
         $localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
         $where = $target . DS . $safeName;
         $exists = is_file($where) ? true : false;
         // Provision directory
         if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
             if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
                 // File object
                 $localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
                 $fileObject = new Models\File(trim($localDirPath), $this->get('path'));
                 $fileObject->set('type', 'folder');
                 $params['file'] = $fileObject;
                 $params['replace'] = false;
                 // Success - check in change
                 $this->call('checkin', $params);
                 $z++;
             }
         }
         // Copy file into project
         if (Filesystem::copy($e, $target . DS . $safeName)) {
             // File object
             $fileObject = new Models\File(trim($localPath), $this->get('path'));
             $params['file'] = $fileObject;
             $params['replace'] = $exists;
             // Success - check in change
             $this->call('checkin', $params);
             $z++;
         }
     }
     return $z;
 }