/** * 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); }
echo $this->option; ?> " /> <p><?php echo Lang::txt('PLG_PROJECTS_FILES_DELETE_FILES_CONFIRM'); ?> </p> <ul class="sample"> <?php foreach ($this->items as $file) { ?> <li> <?php echo \Components\Projects\Models\File::drawIcon($file->getExtension()); ?> <?php echo $file->getName(); ?> <?php echo $file->isDir() ? '<input type="hidden" name="folder[]" value="' . urlencode($file->getPath()) . '" />' : '<input type="hidden" name="asset[]" value="' . urlencode($file->getPath()) . '" />'; ?> </li> <?php } ?> </ul> <p class="submitarea"> <input type="submit" class="btn" value="<?php
/** * Draw list * * @return boolean */ public function drawPackageList($attachments, $element, $elementId, $pub, $blockParams, $authorized) { // Get configs $configs = $this->getConfigs($element->params, $elementId, $pub, $blockParams); $list = NULL; if (!$attachments) { return false; } $list .= '<li>' . \Components\Projects\Models\File::drawIcon('csv') . ' data.csv</li>'; // Add data files $dataFiles = array(); if (is_dir($configs->dataPath)) { $dataFiles = Filesystem::files($configs->dataPath, '.', true, true); } if (!empty($dataFiles)) { $list .= '<li>' . \Components\Projects\Models\File::drawIcon('folder') . ' data</li>'; foreach ($dataFiles as $e) { // Skip thumbnails and CSV if (preg_match("/_tn.gif/", $e) || preg_match("/_medium.gif/", $e) || preg_match("/data.csv/", $e)) { continue; } $file = new \Components\Projects\Models\File($e); $fileinfo = pathinfo($e); $a_dir = $fileinfo['dirname']; $a_dir = trim(str_replace($configs->dataPath, '', $a_dir), DS); $fPath = $a_dir && $a_dir != '.' ? $a_dir . DS : ''; $where = 'data' . DS . $fPath . basename($e); $list .= '<li class="level2"><span class="item-title">' . $file::drawIcon($file->get('ext')) . ' ' . trim($where, DS) . '</span></li>'; } } return $list; }
/** * 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); }
/** * Draw list * * @return boolean */ public function drawPackageList($attachments, $element, $elementId, $pub, $blockParams, $authorized) { // Get configs $configs = $this->getConfigs($element->params, $elementId, $pub, $blockParams); if ($configs->includeInPackage == false) { return false; } $list = NULL; if (!$attachments) { return false; } $class = $configs->multiZip == 1 && count($attachments) > 1 ? 'level2' : 'level1'; // Draw bundles if ($configs->multiZip == 1 && $attachments && count($attachments) > 1) { $title = $configs->bundleTitle ? $configs->bundleTitle : 'Bundle'; $list .= '<li>' . \Components\Projects\Models\File::drawIcon('zip') . ' ' . $title . '</li>'; } // Draw directories if ($configs->multiZip == 2 && $configs->subdir || $configs->bundleDirectory) { // Bundle name $name = $configs->bundleDirectory ? $configs->bundleDirectory : $configs->subdir; $list .= '<li>' . \Components\Projects\Models\File::drawIcon('folder') . ' ' . $name . '</li>'; $class = 'level2'; } // List individual foreach ($attachments as $attach) { $filePath = $this->getFilePath($attach->path, $attach->id, $configs, $attach->params); if (file_exists($filePath)) { $fileinfo = pathinfo($filePath); $a_dir = $fileinfo['dirname']; $a_dir = trim(str_replace($configs->pubPath, '', $a_dir), DS); $fPath = $a_dir && $a_dir != '.' ? $a_dir . DS : ''; $fPath .= basename($filePath); $where = ''; if ($configs->directory && strtolower($configs->bundleDirectory) != strtolower($configs->directory)) { $where .= $configs->directory != $pub->secret ? DS . $configs->directory : ''; } $where .= $configs->subdir && $class == 'level1' ? DS . $configs->subdir : ''; $where .= DS . $fPath; if (!$configs->bundleDirHierarchy) { $where = $configs->subdir && $class == 'level1' ? DS . $configs->subdir : ''; $where .= DS . basename($filePath); } // File model $file = new \Components\Projects\Models\File($filePath); $list .= '<li class="' . $class . '"><span class="item-title" id="file-' . $attach->id . '">' . $file::drawIcon($file->get('ext')) . ' ' . trim($where, DS) . '</span>'; $list .= '<span class="item-details">' . $attach->path . '</span>'; $list .= '</li>'; } } return $list; }
/** * 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; }
/** * 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; }
/** * Produce publication package * * @return boolean */ public function showPackageContents() { if (!$this->_pub) { return false; } // Get elements $prime = $this->getElements(1); $second = $this->getElements(2); $gallery = $this->getElements(3); $elements = array_merge($prime, $second, $gallery); // Do we have items to package? if (!$elements) { return '<p class="witherror">' . Lang::txt('COM_PUBLICATIONS_CURATION_PACKAGE_ERROR_NO_FILES') . '</p>'; } // Get attachment type model $attModel = new Attachments($this->_db); $contents = '<ul class="filelist">'; $contents .= $attModel->showPackagedItems($elements, $this->_pub); // Custom license to be included in LICENSE.txt if ($this->_pub->license_text) { $contents .= '<li>' . \Components\Projects\Models\File::drawIcon('txt') . ' LICENSE.txt</li>'; } $contents .= '<li>' . \Components\Projects\Models\File::drawIcon('txt') . ' README.txt</li>'; $contents .= '</ul>'; return $contents; }