public function createPhotoThumbnails($filename, $data, $importToStore = false) { $xenOptions = XenForo_Application::getOptions(); $photoDataModel = $this->_getPhotoDataModel(); $extensionType = sonnb_XenGallery_Model_ContentData::$typeMap; $smallThumbFile = $photoDataModel->getContentDataSmallThumbnailFile($data); $mediumThumbFile = $photoDataModel->getContentDataMediumThumbnailFile($data); $largeThumbFile = $photoDataModel->getContentDataLargeThumbnailFile($data); $originalFile = $photoDataModel->getContentDataFile($data); if ($originalFile && !$xenOptions->sonnbXG_disableOriginal) { $directory = dirname($originalFile); if (XenForo_Helper_File::createDirectory($directory, true)) { @copy($filename, $originalFile); XenForo_Helper_File::makeWritableByFtpUser($originalFile); } } $photoDataModel->createContentDataThumbnailFile($filename, $largeThumbFile, $extensionType[$data['extension']], sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_LARGE); $photoDataModel->createContentDataThumbnailFile($largeThumbFile, $mediumThumbFile, $extensionType[$data['extension']], sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_MEDIUM); $photoDataModel->createContentDataThumbnailFile($largeThumbFile, $smallThumbFile, $extensionType[$data['extension']], sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_SMALL); $db = $this->_getDb(); if ($importToStore !== false) { $useAttachmentStore = $xenOptions->sonnbXG_useBdStore; $engine = ''; if (XenForo_Application::isRegistered('addOns')) { $addOns = XenForo_Application::get('addOns'); } if (!class_exists('bdAttachmentStore_Option') || empty($addOns['bdAttachmentStore'])) { $useAttachmentStore = false; } if ($useAttachmentStore) { $fileModel = $this->_bdAttachmentStore_getFileModel(); $defaultEngine = $fileModel->getDefaultEngine(); if ($defaultEngine === bdAttachmentStore_Option::MODE_ATTACHMENT || $defaultEngine === bdAttachmentStore_Option::MODE_EXTERNAL_DATA) { $defaultEngine = ''; } if (!empty($defaultEngine)) { $engine = $defaultEngine; } } if (!empty($engine)) { $fileModel = $this->_bdAttachmentStore_getFileModel(); $storeOptions = $fileModel->getStorageOptions($engine); if (!isset($storeOptions['keepLocalCopy'])) { $storeOptions['keepLocalCopy'] = bdAttachmentStore_Option::get('keepLocalCopy'); } $smallThumbFileStore = $photoDataModel->getStoreContentDataSmallThumbnailFile($data); $mediumThumbFileStore = $photoDataModel->getStoreContentDataMediumThumbnailFile($data); $largeThumbFileStore = $photoDataModel->getStoreContentDataLargeThumbnailFile($data); $originalFileStore = $photoDataModel->getStoreContentDataFile($data); if (!$xenOptions->sonnbXG_disableOriginal) { $fileModel->saveFile($engine, $storeOptions, $originalFile, $originalFileStore, basename($originalFileStore)); } $fileModel->saveFile($engine, $storeOptions, $largeThumbFile, $largeThumbFileStore, basename($largeThumbFileStore)); $fileModel->saveFile($engine, $storeOptions, $mediumThumbFile, $mediumThumbFileStore, basename($mediumThumbFileStore)); $fileModel->saveFile($engine, $storeOptions, $smallThumbFile, $smallThumbFileStore, basename($smallThumbFileStore)); $db->update('sonnb_xengallery_content_data', array('bdattachmentstore_engine' => $engine, 'bdattachmentstore_options' => serialize($storeOptions)), array('content_data_id = ?' => $data['content_data_id'])); if (empty($storeOptions['keepLocalCopy'])) { @unlink($smallThumbFile); @unlink($mediumThumbFile); @unlink($largeThumbFile); @unlink($originalFile); } } } $db->update('sonnb_xengallery_content_data', array('unassociated' => 0), array('content_data_id = ?' => $data['content_data_id'])); }
public function applyAuthorCover($tempFile, $userId, $imageType = null, $width = null, $height = null) { if (!$imageType || !$width || !$height) { $imageInfo = @getimagesize($tempFile); if (!$imageInfo) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $width = $imageInfo[0]; $height = $imageInfo[1]; $imageType = $imageInfo[2]; } if (!$this->_getPhotoModel()->canResizeImage($width, $height)) { throw new XenForo_Exception(new XenForo_Phrase('sonnb_xengallery_your_image_is_too_big_cannot_set_cover'), true); } $xenOptions = XenForo_Application::getOptions(); $useAttachmentStore = $xenOptions->sonnbXG_useBdStore; $engine = $storeOptions = array(); if (!class_exists('bdAttachmentStore_Option')) { $useAttachmentStore = false; } if ($useAttachmentStore && empty($engine)) { $fileModel = $this->_bdAttachmentStore_getFileModel(); $defaultEngine = $fileModel->getDefaultEngine(); if ($defaultEngine === bdAttachmentStore_Option::MODE_ATTACHMENT || $defaultEngine === bdAttachmentStore_Option::MODE_EXTERNAL_DATA) { $defaultEngine = ''; } if (!empty($defaultEngine)) { $engine = $defaultEngine; } } if (!empty($engine)) { $fileModel = $this->_bdAttachmentStore_getFileModel(); $storeOptions = $fileModel->getStorageOptions($engine); if (!isset($storeOptions['keepLocalCopy'])) { $storeOptions['keepLocalCopy'] = bdAttachmentStore_Option::get('keepLocalCopy'); } } $user = array('user_id' => $userId, 'sonnb_xengallery_cover' => array('bdattachmentstore_engine' => $engine, 'bdattachmentstore_options' => $storeOptions, 'upload_date' => XenForo_Application::$time, 'extension' => sonnb_XenGallery_Model_ContentData::$extensionMap[$imageType], 'width' => $width, 'height' => $height)); $outputFile = $this->_getGalleryModel()->getAuthorCoverFile($user, true); $directory = dirname($outputFile); $success = false; if (!empty($engine)) { $filePathStore = $this->getAuthorCoverStoreFile($user); $success = $this->_bdAttachmentStore_getFileModel()->saveFile($engine, $storeOptions, $tempFile, $filePathStore, basename($filePathStore)); } if (empty($engine) || !empty($engine) && $storeOptions['keepLocalCopy']) { if (XenForo_Helper_File::createDirectory($directory, true)) { $success = @copy($tempFile, $outputFile); } } if ($tempFile) { @unlink($tempFile); } if ($success) { $db = $this->_getDb(); $db->update('xf_user', array('sonnb_xengallery_cover' => serialize(array('bdattachmentstore_engine' => $engine, 'bdattachmentstore_options' => $storeOptions, 'upload_date' => $user['sonnb_xengallery_cover']['upload_date'], 'extension' => sonnb_XenGallery_Model_ContentData::$extensionMap[$imageType]))), 'user_id = ' . $userId); return $user['sonnb_xengallery_cover']; } return false; }
public function moveContentData($target) { if (!class_exists('bdAttachmentStore_Model_File')) { return; } $contentType = $this->get('content_type'); $contentSize = $this->get('file_size'); $xenOptions = XenForo_Application::getOptions(); $disableOriginal = $xenOptions->sonnbXG_disableOriginal; $contentDataModel = $this->_getContentDataModel(); $contentData = $this->getMergedData(); $needSuccess = 4; if ($disableOriginal && !empty($contentSize)) { $needSuccess = 3; } if ($target === 'store') { $engine = $contentData['bdattachmentstore_engine']; $fileModel = $this->_bdAttachmentStore_getFileModel(); $defaultEngine = $fileModel->getDefaultEngine(); if ($defaultEngine === bdAttachmentStore_Option::MODE_ATTACHMENT || $defaultEngine === bdAttachmentStore_Option::MODE_EXTERNAL_DATA) { $defaultEngine = ''; } if (!empty($defaultEngine) && empty($engine)) { $storeOptions = $fileModel->getStorageOptions($defaultEngine, $contentData); if (!isset($storeOptions['keepLocalCopy'])) { $storeOptions['keepLocalCopy'] = bdAttachmentStore_Option::get('keepLocalCopy'); } $large = $contentDataModel->getContentDataLargeThumbnailFile($contentData, true); $medium = $contentDataModel->getContentDataMediumThumbnailFile($contentData, true); $small = $contentDataModel->getContentDataSmallThumbnailFile($contentData, true); $smallStore = $contentDataModel->getStoreContentDataSmallThumbnailFile($contentData); $mediumStore = $contentDataModel->getStoreContentDataMediumThumbnailFile($contentData); $largeStore = $contentDataModel->getStoreContentDataLargeThumbnailFile($contentData); $successCount = 0; if (!$disableOriginal && !empty($contentSize)) { $original = $contentDataModel->getContentDataFile($contentData, true); $originalStore = $contentDataModel->getStoreContentDataFile($contentData); if ($fileModel->saveFile($defaultEngine, $storeOptions, $original, $originalStore, basename($originalStore))) { $successCount++; } } if ($fileModel->saveFile($defaultEngine, $storeOptions, $large, $largeStore, basename($largeStore))) { $successCount++; } if ($fileModel->saveFile($defaultEngine, $storeOptions, $medium, $mediumStore, basename($mediumStore))) { $successCount++; } if ($fileModel->saveFile($defaultEngine, $storeOptions, $small, $smallStore, basename($smallStore))) { $successCount++; } if ($successCount === $needSuccess) { if (empty($storeOptions['keepLocalCopy'])) { if (!$disableOriginal && !empty($contentSize)) { @unlink($original); } @unlink($large); @unlink($medium); @unlink($small); } $this->bulkSet(array('bdattachmentstore_engine' => $defaultEngine, 'bdattachmentstore_options' => $storeOptions)); } } } else { $engine = $contentData['bdattachmentstore_engine']; $fileModel = $this->_bdAttachmentStore_getFileModel(); $engineOptions = @unserialize($contentData['bdattachmentstore_options']); if (!empty($engine)) { $successCount = 0; if (!empty($storeOptions['keepLocalCopy'])) { $large = $contentDataModel->getContentDataLargeThumbnailFile($contentData, true); $medium = $contentDataModel->getContentDataMediumThumbnailFile($contentData, true); $small = $contentDataModel->getContentDataSmallThumbnailFile($contentData, true); $smallStore = $contentDataModel->getStoreContentDataSmallThumbnailFile($contentData); $mediumStore = $contentDataModel->getStoreContentDataMediumThumbnailFile($contentData); $largeStore = $contentDataModel->getStoreContentDataLargeThumbnailFile($contentData); if (!$disableOriginal && !empty($contentSize)) { $original = $contentDataModel->getContentDataFile($contentData, true); $originalStore = $contentDataModel->getStoreContentDataFile($contentData); if (is_file($original)) { $successCount++; } else { $originalTemp = $fileModel->getAccessibleFilePath($engine, $engineOptions, $originalStore, true); if ($originalTemp) { if ($this->_writeDataFileLocal($originalTemp, $contentData, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_ORIGINAL)) { $successCount++; } } } } if (is_file($large)) { $successCount++; } else { $largeTemp = $fileModel->getAccessibleFilePath($engine, $engineOptions, $largeStore, true); if ($largeTemp) { if ($this->_writeDataFileLocal($largeTemp, $contentData, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_LARGE)) { $successCount++; } } } if (is_file($medium)) { $successCount++; } else { $mediumTemp = $fileModel->getAccessibleFilePath($engine, $engineOptions, $mediumStore, true); if ($mediumTemp) { if ($this->_writeDataFileLocal($mediumTemp, $contentData, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_MEDIUM)) { $successCount++; } } } if (is_file($small)) { $successCount++; } else { $smallTemp = $fileModel->getAccessibleFilePath($engine, $engineOptions, $smallStore, true); if ($smallTemp) { if ($this->_writeDataFileLocal($smallTemp, $contentData, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_SMALL)) { $successCount++; } } } } else { $smallStore = $contentDataModel->getStoreContentDataSmallThumbnailFile($contentData); $mediumStore = $contentDataModel->getStoreContentDataMediumThumbnailFile($contentData); $largeStore = $contentDataModel->getStoreContentDataLargeThumbnailFile($contentData); if (!$disableOriginal && !empty($contentSize)) { $originalStore = $contentDataModel->getStoreContentDataFile($contentData); $originalTemp = $fileModel->getAccessibleFilePath($engine, $engineOptions, $originalStore, true); if ($originalTemp) { if ($this->_writeDataFileLocal($originalTemp, $contentData, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_ORIGINAL)) { $successCount++; } } } $largeTemp = $fileModel->getAccessibleFilePath($engine, $engineOptions, $largeStore, true); if ($largeTemp) { if ($this->_writeDataFileLocal($largeTemp, $contentData, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_LARGE)) { $successCount++; } } $mediumTemp = $fileModel->getAccessibleFilePath($engine, $engineOptions, $mediumStore, true); if ($mediumTemp) { if ($this->_writeDataFileLocal($mediumTemp, $contentData, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_MEDIUM)) { $successCount++; } } $smallTemp = $fileModel->getAccessibleFilePath($engine, $engineOptions, $smallStore, true); if ($smallTemp) { if ($this->_writeDataFileLocal($smallTemp, $contentData, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_SMALL)) { $successCount++; } } } if ($successCount === $needSuccess) { if (!$disableOriginal && !empty($contentSize)) { $fileModel->deleteFile($engine, $engineOptions, $originalStore); } $fileModel->deleteFile($engine, $engineOptions, $largeStore); $fileModel->deleteFile($engine, $engineOptions, $mediumStore); $fileModel->deleteFile($engine, $engineOptions, $smallStore); $this->bulkSet(array('bdattachmentstore_engine' => '', 'bdattachmentstore_options' => 'a:0:{}')); } } } }