Exemplo n.º 1
0
 public function execute(Request $request, ResourceTypeFactory $resourceTypeFactory, Acl $acl, EventDispatcher $dispatcher)
 {
     $copiedFiles = (array) $request->request->get('files');
     $copied = 0;
     $errors = array();
     // Initial validation
     foreach ($copiedFiles as $arr) {
         if (!isset($arr['name'], $arr['type'], $arr['folder'])) {
             throw new InvalidRequestException();
         }
         if (!$acl->isAllowed($arr['type'], $arr['folder'], Permission::FILE_VIEW)) {
             throw new UnauthorizedException();
         }
     }
     foreach ($copiedFiles as $arr) {
         if (empty($arr['name'])) {
             continue;
         }
         $name = $arr['name'];
         $type = $arr['type'];
         $folder = $arr['folder'];
         $resourceType = $resourceTypeFactory->getResourceType($type);
         $copiedFile = new CopiedFile($name, $folder, $resourceType, $this->app);
         $options = isset($arr['options']) ? $arr['options'] : '';
         $copiedFile->setCopyOptions($options);
         if ($copiedFile->isValid()) {
             $copyFileEvent = new CopyFileEvent($this->app, $copiedFile);
             $dispatcher->dispatch(CKFinderEvent::COPY_FILE, $copyFileEvent);
             if (!$copyFileEvent->isPropagationStopped()) {
                 if ($copiedFile->doCopy()) {
                     $copied++;
                 }
             }
         }
         $errors = array_merge($errors, $copiedFile->getErrors());
     }
     $data = array('copied' => $copied);
     if (!empty($errors)) {
         $data['error'] = array('number' => Error::COPY_FAILED, 'errors' => $errors);
     }
     return $data;
 }
Exemplo n.º 2
0
 public function execute(Request $request, ResourceTypeFactory $resourceTypeFactory, Acl $acl, EventDispatcher $dispatcher)
 {
     $deletedFiles = (array) $request->get('files');
     $deleted = 0;
     $errors = array();
     foreach ($deletedFiles as $arr) {
         if (!isset($arr['name'], $arr['type'], $arr['folder'])) {
             throw new InvalidRequestException();
         }
         if (empty($arr['name'])) {
             continue;
         }
         $name = $arr['name'];
         $type = $arr['type'];
         $folder = $arr['folder'];
         $resourceType = $resourceTypeFactory->getResourceType($type);
         $deletedFile = new DeletedFile($name, $folder, $resourceType, $this->app);
         if (!$acl->isAllowed($type, $folder, Permission::FILE_DELETE)) {
             throw new UnauthorizedException();
         }
         if ($deletedFile->isValid()) {
             $deleteFileEvent = new DeleteFileEvent($this->app, $deletedFile);
             $dispatcher->dispatch(CKFinderEvent::DELETE_FILE, $deleteFileEvent);
             if (!$deleteFileEvent->isPropagationStopped()) {
                 if ($deletedFile->doDelete()) {
                     $deleted++;
                 }
             }
         }
         $errors = array_merge($errors, $deletedFile->getErrors());
     }
     $data = array('deleted' => $deleted);
     if (!empty($errors)) {
         $data['error'] = array('number' => Error::DELETE_FAILED, 'errors' => $errors);
     }
     return $data;
 }
Exemplo n.º 3
0
 public function execute(Request $request, Acl $acl, Config $config, ResourceTypeFactory $resourceTypeFactory)
 {
     $data = new \stdClass();
     /**
      * Connector is always enabled here
      *
      * @see CKFinder::checkAuth()
      */
     $data->enabled = true;
     $ln = '';
     $lc = str_replace('-', '', ($config->get('licenseKey') ?: $config->get('LicenseKey')) . '                                  ');
     $pos = strpos(CKFinder::CHARS, $lc[2]) % 5;
     if ($pos == 1 || $pos == 2) {
         $ln = $config->get('licenseName') ?: $config->get('LicenseName');
     }
     $data->s = $ln;
     $data->c = trim($lc[1] . $lc[8] . $lc[17] . $lc[22] . $lc[3] . $lc[13] . $lc[11] . $lc[20] . $lc[5] . $lc[24] . $lc[27]);
     // Thumbnails
     $thumbnailsConfig = $config->get('thumbnails');
     $thumbnailsEnabled = (bool) $thumbnailsConfig['enabled'];
     if ($thumbnailsEnabled) {
         $sizes = array();
         foreach ($thumbnailsConfig['sizes'] as $sizeInfo) {
             $sizes[] = sprintf("%dx%d", $sizeInfo['width'], $sizeInfo['height']);
         }
         $data->thumbs = $sizes;
     }
     // Images
     $imagesConfig = $config->get('images');
     $images = array('max' => $imagesConfig['maxWidth'] . 'x' . $imagesConfig['maxHeight']);
     if (isset($imagesConfig['sizes'])) {
         $resize = array();
         foreach ($imagesConfig['sizes'] as $name => $sizeInfo) {
             $resize[$name] = $sizeInfo['width'] . 'x' . $sizeInfo['height'];
         }
         $images['sizes'] = $resize;
     }
     $data->images = $images;
     $resourceTypesNames = $config->getDefaultResourceTypes() ?: $config->getResourceTypes();
     $data->resourceTypes = array();
     if (!empty($resourceTypesNames)) {
         $phpMaxSize = 0;
         $maxUpload = Utils::returnBytes(ini_get('upload_max_filesize'));
         if ($maxUpload) {
             $phpMaxSize = $maxUpload;
         }
         $maxPost = Utils::returnBytes(ini_get('post_max_size'));
         if ($maxPost) {
             $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $maxPost) : $maxPost;
         }
         //ini_get('memory_limit') only works if compiled with "--enable-memory-limit"
         $memoryLimit = Utils::returnBytes(@ini_get('memory_limit'));
         if ($memoryLimit && $memoryLimit != -1) {
             $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $memoryLimit) : $memoryLimit;
         }
         $data->uploadMaxSize = $phpMaxSize;
         $data->uploadCheckImages = !$config->get('checkSizeAfterScaling');
         $requestedType = (string) $request->query->get('type');
         foreach ($resourceTypesNames as $resourceTypeName) {
             if ($requestedType && $requestedType !== $resourceTypeName) {
                 continue;
             }
             $aclMask = $acl->getComputedMask($resourceTypeName, '/');
             if (!(Permission::FOLDER_VIEW & $aclMask)) {
                 continue;
             }
             $resourceType = $resourceTypeFactory->getResourceType($resourceTypeName);
             $resourceTypeObject = array('name' => $resourceTypeName, 'allowedExtensions' => implode(",", $resourceType->getAllowedExtensions()), 'deniedExtensions' => implode(",", $resourceType->getDeniedExtensions()), 'hash' => $resourceType->getHash(), 'acl' => $aclMask, 'maxSize' => $resourceType->getMaxSize() ? min($resourceType->getMaxSize(), $phpMaxSize) : $phpMaxSize);
             $resourceTypeBackend = $resourceType->getBackend();
             if ($resourceType->isLazyLoaded()) {
                 $resourceTypeObject['hasChildren'] = false;
                 $resourceTypeObject['lazyLoad'] = true;
             } else {
                 $resourceTypeObject['hasChildren'] = $resourceTypeBackend->containsDirectories($resourceType, $resourceType->getDirectory());
             }
             if ($label = $resourceType->getLabel()) {
                 $resourceTypeObject['label'] = $label;
             }
             $useProxyCommand = $resourceTypeBackend->usesProxyCommand();
             if ($useProxyCommand) {
                 $resourceTypeObject['useProxyCommand'] = true;
             } else {
                 $baseUrl = $resourceTypeBackend->getBaseUrl();
                 if ($baseUrl) {
                     $resourceTypeObject['url'] = rtrim(Path::combine($baseUrl, $resourceType->getDirectory()), '/') . '/';
                 }
             }
             $trackedOperations = $resourceTypeBackend->getTrackedOperations();
             if (!empty($trackedOperations)) {
                 $resourceTypeObject['trackedOperations'] = $trackedOperations;
             }
             $data->resourceTypes[] = $resourceTypeObject;
         }
     }
     $enabledPlugins = $config->get('plugins');
     if (!empty($enabledPlugins)) {
         $data->plugins = $enabledPlugins;
     }
     $proxyCacheLifetime = (int) $config->get('cache.proxyCommand');
     if ($proxyCacheLifetime) {
         $data->proxyCache = $proxyCacheLifetime;
     }
     return $data;
 }