private function getConfig() { $config = array(); $config['coverHeight'] = $this->service->getConfig($this->groupId, 'coverHeight'); $config['avatarSize'] = 100; return $config; }
private function uploadCover($file, $query) { $groupId = $query['groupId']; if (!GHEADER_CLASS_CreditsBridge::getInstance()->credits->isAvaliable(GHEADER_CLASS_Credits::ACTION_ADD)) { $error = GHEADER_CLASS_CreditsBridge::getInstance()->credits->getErrorMessage(GHEADER_CLASS_Credits::ACTION_ADD); throw new InvalidArgumentException($error); } $canvasWidth = $query['canvas']['width']; $canvasHeight = $this->service->getConfig($groupId, 'coverHeight'); $this->validateFile($file); $pluginfilesDir = OW::getPluginManager()->getPlugin('uheader')->getPluginFilesDir(); $tmpCoverPath = $pluginfilesDir . uniqid('tmp_') . '.jpg'; if (!move_uploaded_file($file['tmp_name'], $tmpCoverPath)) { throw new InvalidArgumentException('Moving uploaded file faild'); } $coverImage = new UTIL_Image($tmpCoverPath); $imageHeight = $coverImage->getHeight(); $imageWidth = $coverImage->getWidth(); $css = array('width' => 'auto', 'height' => 'auto'); $tmp = $canvasWidth * $imageHeight / $imageWidth; if ($tmp >= $canvasHeight) { $css['width'] = '100%'; } else { $css['height'] = '100%'; } $this->validateImage($coverImage, $canvasWidth, $canvasHeight); $cover = $this->service->findCoverByGroupId($groupId, GHEADER_BOL_Cover::STATUS_TMP); if ($cover === null) { $cover = new GHEADER_BOL_Cover(); } $extension = UTIL_File::getExtension($file['name']); $cover->file = uniqid('cover-' . $groupId . '-') . '.' . $extension; $cover->groupId = $groupId; $cover->status = GHEADER_BOL_Cover::STATUS_TMP; $cover->timeStamp = time(); $dimensions = array('height' => $imageHeight, 'width' => $imageWidth); $cover->setSettings(array('dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0))); $this->service->saveCover($cover); $coverPath = $this->service->getCoverPath($cover); OW::getStorage()->copyFile($tmpCoverPath, $coverPath); @unlink($tmpCoverPath); $coverUrl = $this->service->getCoverUrl($cover); return array('src' => $coverUrl, 'data' => $cover->getSettings()); }