/** * Get a list of files in a specific directory. * * @param string $path * @return array */ public function getObjectsInContainer($path) { $dir = $this->fileHandler->postfixSlash($path); $bases = $this->getBases($dir); if (empty($bases['pathAbsolute'])) { return array(); } $fullPath = $bases['pathAbsolute'] . $dir; $modAuth = $_SESSION["modx.{$this->xpdo->context->get('key')}.user.token"]; /* get default settings */ $imageExtensions = $this->getOption('imageExtensions', $this->properties, 'jpg,jpeg,png,gif'); $imageExtensions = explode(',', $imageExtensions); $use_multibyte = $this->ctx->getOption('use_multibyte', false); $encoding = $this->ctx->getOption('modx_charset', 'UTF-8'); $allowedFileTypes = $this->getOption('allowedFileTypes', $this->properties, ''); $allowedFileTypes = !empty($allowedFileTypes) && is_string($allowedFileTypes) ? explode(',', $allowedFileTypes) : $allowedFileTypes; $thumbnailType = $this->getOption('thumbnailType', $this->properties, 'png'); $thumbnailQuality = $this->getOption('thumbnailQuality', $this->properties, 90); $skipFiles = $this->getOption('skipFiles', $this->properties, '.svn,.git,_notes,.DS_Store'); $skipFiles = explode(',', $skipFiles); $skipFiles[] = '.'; $skipFiles[] = '..'; /* iterate */ $files = array(); if (!is_dir($fullPath)) { $this->addError('dir', $this->xpdo->lexicon('file_folder_err_ns') . $fullPath); return array(); } /** @var DirectoryIterator $file */ foreach (new DirectoryIterator($fullPath) as $file) { if (in_array($file, $skipFiles)) { continue; } if (!$file->isReadable()) { continue; } $fileName = $file->getFilename(); $filePathName = $file->getPathname(); if (!$file->isDir()) { $fileExtension = pathinfo($filePathName, PATHINFO_EXTENSION); $fileExtension = $use_multibyte ? mb_strtolower($fileExtension, $encoding) : strtolower($fileExtension); if (!empty($allowedFileTypes) && !in_array($fileExtension, $allowedFileTypes)) { continue; } $filesize = @filesize($filePathName); $url = ltrim($dir . $fileName, '/'); /* get thumbnail */ if (in_array($fileExtension, $imageExtensions)) { $imageWidth = $this->ctx->getOption('filemanager_image_width', 400); $imageHeight = $this->ctx->getOption('filemanager_image_height', 300); $thumbHeight = $this->ctx->getOption('filemanager_thumb_height', 60); $thumbWidth = $this->ctx->getOption('filemanager_thumb_width', 80); $size = @getimagesize($filePathName); if (is_array($size)) { $imageWidth = $size[0] > 800 ? 800 : $size[0]; $imageHeight = $size[1] > 600 ? 600 : $size[1]; } /* ensure max h/w */ if ($thumbWidth > $imageWidth) { $thumbWidth = $imageWidth; } if ($thumbHeight > $imageHeight) { $thumbHeight = $imageHeight; } /* generate thumb/image URLs */ $thumbQuery = http_build_query(array('src' => $url, 'w' => $thumbWidth, 'h' => $thumbHeight, 'f' => $thumbnailType, 'q' => $thumbnailQuality, 'HTTP_MODAUTH' => $modAuth, 'wctx' => $this->ctx->get('key'), 'source' => $this->get('id'))); $imageQuery = http_build_query(array('src' => $url, 'w' => $imageWidth, 'h' => $imageHeight, 'HTTP_MODAUTH' => $modAuth, 'f' => $thumbnailType, 'q' => $thumbnailQuality, 'wctx' => $this->ctx->get('key'), 'source' => $this->get('id'))); $thumb = $this->ctx->getOption('connectors_url', MODX_CONNECTORS_URL) . 'system/phpthumb.php?' . urldecode($thumbQuery); $image = $this->ctx->getOption('connectors_url', MODX_CONNECTORS_URL) . 'system/phpthumb.php?' . urldecode($imageQuery); } else { $thumb = $image = $this->ctx->getOption('manager_url', MODX_MANAGER_URL) . 'templates/default/images/restyle/nopreview.jpg'; $thumbWidth = $imageWidth = $this->ctx->getOption('filemanager_thumb_width', 80); $thumbHeight = $imageHeight = $this->ctx->getOption('filemanager_thumb_height', 60); } $octalPerms = substr(sprintf('%o', $file->getPerms()), -4); $files[] = array('id' => $bases['urlAbsoluteWithPath'] . $fileName, 'name' => $fileName, 'cls' => 'icon-' . $fileExtension, 'image' => $image, 'image_width' => $imageWidth, 'image_height' => $imageHeight, 'thumb' => $thumb, 'thumb_width' => $thumbWidth, 'thumb_height' => $thumbHeight, 'url' => ltrim($dir . $fileName, '/'), 'relativeUrl' => ltrim($dir . $fileName, '/'), 'fullRelativeUrl' => rtrim($bases['url']) . ltrim($dir . $fileName, '/'), 'ext' => $fileExtension, 'pathname' => str_replace('//', '/', $filePathName), 'lastmod' => $file->getMTime(), 'disabled' => false, 'perms' => $octalPerms, 'leaf' => true, 'size' => $filesize, 'menu' => array(array('text' => $this->xpdo->lexicon('file_remove'), 'handler' => 'this.removeFile'))); } } return $files; }