/**
  * Checks if the current user has any storage quota left.
  *
  * @return bool `false` if current user storage quota was exceeded, `true` otherwise.
  */
 protected function isQuotaAvailable()
 {
     // Get the user quota in bytes.
     $quota = Utils::returnBytes($this->app['config']->get('DiskQuota.userQuota'));
     /**
      * For documentation purposes it is only a method stub.
      *
      * @todo Custom implementation of the current user quota check.
      */
     return true;
 }
예제 #2
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;
 }
예제 #3
0
 /**
  * Processes configuration array
  */
 protected function process()
 {
     $this->options['defaultResourceTypes'] = array_filter(array_map('trim', explode(',', $this->options['defaultResourceTypes'])), 'strlen');
     $formatToArray = function ($input) {
         $input = is_array($input) ? $input : explode(',', $input);
         return array_filter(array_map('strtolower', array_map('trim', $input)), 'strlen');
     };
     foreach ($this->options['resourceTypes'] as $i => $resourceTypeConfig) {
         $resourceTypeConfig['allowedExtensions'] = $formatToArray($resourceTypeConfig['allowedExtensions']);
         $resourceTypeConfig['deniedExtensions'] = $formatToArray($resourceTypeConfig['deniedExtensions']);
         $resourceTypeConfig['maxSize'] = Utils::returnBytes((string) $resourceTypeConfig['maxSize']);
         $this->options['resourceTypes'][$resourceTypeConfig['name']] = $resourceTypeConfig;
         unset($this->options['resourceTypes'][$i]);
     }
     $this->options['htmlExtensions'] = $formatToArray($this->options['htmlExtensions']);
 }
 /**
  * @link http://pl.php.net/manual/pl/function.imagecreatefromjpeg.php
  * function posted by e dot a dot schultz at gmail dot com
  *
  * @param $imageWidth
  * @param $imageHeight
  * @param $imageBits
  * @param $imageChannels
  *
  * @return bool
  */
 public function setMemory($imageWidth, $imageHeight, $imageBits, $imageChannels)
 {
     $MB = 1048576;
     // number of bytes in 1M
     $K64 = 65536;
     // number of bytes in 64K
     $TWEAKFACTOR = 2.4;
     // Or whatever works for you
     $memoryNeeded = round(($imageWidth * $imageHeight * $imageBits * $imageChannels / 8 + $K64) * $TWEAKFACTOR) + 3 * $MB;
     //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also
     //Default memory limit is 8MB so well stick with that.
     //To find out what yours is, view your php.ini file.
     $memoryLimit = Utils::returnBytes(@ini_get('memory_limit')) / $MB;
     // There are no memory limits, nothing to do
     if ($memoryLimit == -1) {
         return true;
     }
     if (!$memoryLimit) {
         $memoryLimit = 8;
     }
     $memoryLimitMB = $memoryLimit * $MB;
     if (function_exists('memory_get_usage')) {
         if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) {
             $newLimit = $memoryLimit + ceil((memory_get_usage() + $memoryNeeded - $memoryLimitMB) / $MB);
             if (@ini_set('memory_limit', $newLimit . 'M') === false) {
                 return false;
             }
         }
     } else {
         if ($memoryNeeded + 3 * $MB > $memoryLimitMB) {
             $newLimit = $memoryLimit + ceil((3 * $MB + $memoryNeeded - $memoryLimitMB) / $MB);
             if (false === @ini_set('memory_limit', $newLimit . 'M')) {
                 return false;
             }
         }
     }
     return true;
 }