/** * Read storage * * @param \XLite\Model\Base\Storage $storage Storage * * @return void */ protected function readStorage(\XLite\Model\Base\Storage $storage) { $range = null; if (isset($_SERVER['HTTP_RANGE'])) { list($sizeUnit, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); if ('bytes' == $sizeUnit) { list($range, $extra) = explode(',', $range, 2); } } $start = null; $length = $storage->getSize(); if ($range) { $size = $length; list($start, $end) = explode('-', $range, 2); $start = abs(intval($start)); $end = abs(intval($end)); $end = $end ? min($end, $size - 1) : $size - 1; $start = !$start || $end < $start ? 0 : max($start, 0); if ($start > 0 || $end < $size - 1) { header('HTTP/1.1 206 Partial Content', true, 206); } header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size); $length = $end - $start + 1; } header('Accept-Ranges: bytes'); header('Content-Length: ' . $length); if (!\XLite\Core\Request::getInstance()->isHead()) { $storage->readOutput($start, $length); } }
/** * Get valid file system storage root * * @return string */ protected function getStoreFileSystemRoot() { $shipments = $this->getLink()->getManifest()->getShipments(); $path = parent::getStoreFileSystemRoot() . $shipments[0]->getParcel()->getOrder()->getOrderId() . LC_DS; \Includes\Utils\FileManager::mkdirRecursive($path); return $path; }
/** * Clone for attachment * * @param \XLite\Module\CDev\FileAttachments\Model\Product\Attachment $attachment Attachment * * @return \XLite\Model\AEntity */ public function cloneEntityForAttachment(\XLite\Module\CDev\FileAttachments\Model\Product\Attachment $attachment) { $newStorage = parent::cloneEntity(); $attachment->setStorage($newStorage); $newStorage->setAttachment($attachment); $newStorage->setPath(''); $newStorage->loadFromURL(parent::getURL(), true); return $newStorage; }
/** * Get valid file system storage root * * @return string */ protected function getStoreFileSystemRoot() { $path = parent::getStoreFileSystemRoot() . $this->getOrderId() . LC_DS; \Includes\Utils\FileManager::mkdirRecursive($path); return $path; }
/** * Copy resource * * @param \XLite\Model\Base\Storage $storage Storage * @param string $subdirectory Subdirectory * * @return boolean */ protected function copyResource(\XLite\Model\Base\Storage $storage, $subdirectory) { $dir = LC_DIR_VAR . $this->generator->getOptions()->dir . LC_DS . $subdirectory; if (!\Includes\Utils\FileManager::isExists($dir)) { \Includes\Utils\FileManager::mkdir($dir); } $name = basename($storage->getPath()); return \Includes\Utils\FileManager::write($dir . LC_DS . $name, $storage->getBody()) ? $subdirectory . LC_DS . $name : false; }
/** * Renew properties by path * * @param string $path Path * * @return boolean */ protected function renewByPath($path) { $result = parent::renewByPath($path); if ($result) { $data = @getimagesize($path); if (is_array($data)) { $this->setWidth($data[0]); $this->setHeight($data[1]); $this->setMime($data['mime']); $hash = \Includes\Utils\FileManager::getHash($path); if ($hash) { $this->setHash($hash); } } else { $result = false; } } return $result; }
/** * Read storage * * @param \XLite\Model\Base\Storage $storage Storage * * @return void */ protected function readStorage(\XLite\Model\Base\Storage $storage) { $storage->readOutput(); }
/** * Get valid file system storage root * * @return string */ protected function getValidFileSystemRoot() { $path = parent::getValidFileSystemRoot(); if (!file_exists($path . LC_DS . '.htaccess')) { file_put_contents($path . LC_DS . '.htaccess', 'Options -Indexes' . PHP_EOL . 'Allow from all' . PHP_EOL); } return $path; }