/** * Processes an image upload for a content. * * @param XenForo_Upload $upload The uploaded image. * @param integer $contentId Content ID image belongs to * @param array|false $permissions User's permissions. False to skip permission checks * * @return array Changed image fields */ public function uploadImage(XenForo_Upload $upload, $contentId, $permissions) { $largestDimension = $this->getSizeFromCode('l'); if (!$upload->isValid()) { throw new XenForo_Exception($upload->getErrors(), true); } if (!$upload->isImage()) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $imageType = $upload->getImageInfoField('type'); //prd($imageType); if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $baseTempFile = $upload->getTempFile(); $width = $upload->getImageInfoField('width'); $height = $upload->getImageInfoField('height'); return $this->applyImage($contentId, $baseTempFile, $imageType, $width, $height, $permissions); }
public function insertUploadedAttachmentData(XenForo_Upload $file, $userId, array $extra = array()) { $filename = $file->getFileName(); $extension = XenForo_Helper_File::getFileExtension($filename); if ($extension == 'svg') { list($svgfile, $dimensions) = $this->extractDimensionsForSVG($file->getTempFile(), XenForo_Application::getOptions()->SV_RejectAttachmentWithBadTags); if (!empty($svgfile) && !empty($dimensions)) { if ($dimensions['thumbnail_width'] && $dimensions['thumbnail_height']) { $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf'); if ($tempThumbFile) { // update the width/height attributes $svgfile['width'] = (string) $dimensions['thumbnail_width']; $svgfile['height'] = (string) $dimensions['thumbnail_height']; $svgfile->asXML($tempThumbFile); SV_AttachmentImprovements_Globals::$tempThumbFile = $tempThumbFile; } } SV_AttachmentImprovements_Globals::$forcedDimensions = $dimensions; } } return parent::insertUploadedAttachmentData($file, $userId, $extra); }
public function uploadAvatar(XenForo_Upload $upload, $teamId) { if (!$teamId) { throw new Nobita_Teams_Exception_Abstract('Missing team ID.'); } if (!$upload->isValid()) { throw new Nobita_Teams_Exception_Abstract($upload->getErrors(), true); } if (!$upload->isImage()) { throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $imageType = $upload->getImageInfoField('type'); if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $baseTempFile = $upload->getTempFile(); $width = $upload->getImageInfoField('width'); $height = $upload->getImageInfoField('height'); if ($width < 280 || $height < 280) { throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('Teams_avatar_required_least_280x280_pixels'), true); } return $this->applyAvatar($teamId, $baseTempFile, $imageType, $width, $height); }
/** * Processes an cover upload for a user. * * @param XenForo_Upload $upload The uploaded cover. * @param integer $teamId User ID cover belongs to * * @return array Changed cover fields */ public function uploadCoverPhoto(XenForo_Upload $upload, $teamId, $existingCoverDate) { if (!$teamId) { throw new Nobita_Teams_Exception_Abstract("Missing team ID"); } if (!$upload->isValid()) { throw new Nobita_Teams_Exception_Abstract($upload->getErrors(), true); } if (!$upload->isImage()) { throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $imageType = $upload->getImageInfoField('type'); if (!in_array($imageType, array(IMAGETYPE_PNG, IMAGETYPE_JPEG))) { throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $baseTempFile = $upload->getTempFile(); $width = $upload->getImageInfoField('width'); $height = $upload->getImageInfoField('height'); if ($height < self::$minHeight) { throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('Teams_upload_image_greater_x', array('min' => self::$minHeight)), true); } return $this->applyCover($teamId, $baseTempFile, $imageType, $width, $height, $existingCoverDate); }
/** * Processes an avatar upload for a user. * * @param XenForo_Upload $upload The uploaded avatar. * @param integer $userId User ID avatar belongs to * @param array|false $permissions User's permissions. False to skip permission checks * * @return array Changed avatar fields */ public function uploadAvatar(XenForo_Upload $upload, $userId, $permissions) { if (!$userId) { throw new XenForo_Exception('Missing user ID.'); } if ($permissions !== false && !is_array($permissions)) { throw new XenForo_Exception('Invalid permission set.'); } $largestDimension = $this->getSizeFromCode('l'); if (!$upload->isValid()) { throw new XenForo_Exception($upload->getErrors(), true); } if (!$upload->isImage()) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $imageType = $upload->getImageInfoField('type'); if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $baseTempFile = $upload->getTempFile(); $width = $upload->getImageInfoField('width'); $height = $upload->getImageInfoField('height'); return $this->applyAvatar($userId, $baseTempFile, $imageType, $width, $height, $permissions); }
/** * Inserts uploaded attachment data. * * @param XenForo_Upload $file Uploaded attachment info. Assumed to be valid * @param integer $userId User ID uploading * @param array $extra Extra params to set * * @return integer Attachment data ID */ public function insertUploadedAttachmentData(XenForo_Upload $file, $userId, array $extra = array()) { if ($file->isImage() && XenForo_Image_Abstract::canResize($file->getImageInfoField('width'), $file->getImageInfoField('height'))) { $dimensions = array('width' => $file->getImageInfoField('width'), 'height' => $file->getImageInfoField('height')); $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf'); if ($tempThumbFile) { $image = XenForo_Image_Abstract::createFromFile($file->getTempFile(), $file->getImageInfoField('type')); if ($image) { if ($image->thumbnail(XenForo_Application::get('options')->attachmentThumbnailDimensions)) { $image->output($file->getImageInfoField('type'), $tempThumbFile); } else { copy($file->getTempFile(), $tempThumbFile); // no resize necessary, use the original } $dimensions['thumbnail_width'] = $image->getWidth(); $dimensions['thumbnail_height'] = $image->getHeight(); unset($image); } } } else { $tempThumbFile = ''; $dimensions = array(); } try { $dataDw = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData'); $dataDw->bulkSet($extra); $dataDw->set('user_id', $userId); $dataDw->set('filename', $file->getFileName()); $dataDw->bulkSet($dimensions); $dataDw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_TEMP_FILE, $file->getTempFile()); if ($tempThumbFile) { $dataDw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_TEMP_THUMB_FILE, $tempThumbFile); } $dataDw->save(); } catch (Exception $e) { if ($tempThumbFile) { @unlink($tempThumbFile); } throw $e; } if ($tempThumbFile) { @unlink($tempThumbFile); } // TODO: add support for "on rollback" behavior return $dataDw->get('data_id'); }
public function uploadAuthorCover(XenForo_Upload $cover, $userId) { if (!$userId) { return false; } if (!$cover->isValid()) { throw new XenForo_Exception($cover->getErrors(), true); } if (!$cover->isImage()) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $imageType = $cover->getImageInfoField('type'); if (!isset(sonnb_XenGallery_Model_ContentData::$extensionMap[$imageType])) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $baseTempFile = $cover->getTempFile(); $width = $cover->getImageInfoField('width'); $height = $cover->getImageInfoField('height'); return $this->applyAuthorCover($baseTempFile, $userId, $imageType, $width, $height); }
public function uploadVideoThumbnail(XenForo_Upload $upload, array $video) { if (!$video) { return false; } if (!$upload->isValid()) { throw new XenForo_Exception($upload->getErrors(), true); } if (!$upload->isImage()) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $baseTempFile = $upload->getTempFile(); $imageType = $upload->getImageInfoField('type'); $width = $upload->getImageInfoField('width'); $height = $upload->getImageInfoField('height'); return $this->applyVideoThumbnail($video, $baseTempFile, $imageType, $width, $height); }
public function uploadCategoryIcon(XenForo_Upload $upload, $categoryId) { if (!$categoryId) { throw new XenForo_Exception("Missing category ID."); } if (!$upload->isValid()) { throw new XenForo_Exception($upload->getErrors(), true); } if (!$upload->isImage()) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $baseTempFile = $upload->getTempFile(); $imageType = $upload->getImageInfoField('type'); $width = $upload->getImageInfoField('width'); $height = $upload->getImageInfoField('height'); return $this->applyCategoryIcon($categoryId, $baseTempFile, $imageType, $width, $height); }
public function insertUploadedPhotoData(XenForo_Upload $file, array $extra = array(), &$errorPhraseKey = '') { $return = false; if ($this->_getPhotoModel()->canResizeImage($file->getImageInfoField('width'), $file->getImageInfoField('height'))) { $xenOptions = XenForo_Application::getOptions(); $tempFile = $file->getTempFile(); $tempType = $file->getImageInfoField('type'); $dimensions = array('width' => $file->getImageInfoField('width'), 'height' => $file->getImageInfoField('height'), 'is_animated' => $this->_getPhotoModel()->isAnimatedGif($tempFile) ? 1 : 0); $smallThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf'); $mediumThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf'); $largeThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf'); $originalFile = false; $successCount = 0; if ($xenOptions->sonnbXG_enableResize) { $photoConstraints = $this->_getPhotoModel()->getPhotoDataConstraints(); //Resize original image if it excess user's limit. if ($dimensions['width'] > $photoConstraints['width'] || $dimensions['height'] > $photoConstraints['height']) { $image = XenForo_Image_Abstract::createFromFile($tempFile, $tempType); if ($image) { if ($image->thumbnail($photoConstraints['width'], $photoConstraints['height'])) { $image->output($tempType, $tempFile, 100); $dimensions['width'] = $image->getWidth(); $dimensions['height'] = $image->getHeight(); } unset($image); } } } if (!$xenOptions->sonnbXG_disableOriginal) { $originalFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf'); if ($this->_getContentDataModel()->copyFile($tempFile, $originalFile)) { $successCount++; } } $this->exifRotate($tempFile, $tempType, $tempFile); if ($largeThumbFile) { if ($this->createContentDataThumbnailFile($tempFile, $largeThumbFile, $tempType, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_LARGE, $fallback, $dimensions)) { $successCount++; } if ($fallback === true) { $dimensions['large_width'] = $file->getImageInfoField('width'); $dimensions['large_height'] = $file->getImageInfoField('height'); } } if ($mediumThumbFile) { if ($this->createContentDataThumbnailFile($largeThumbFile, $mediumThumbFile, $tempType, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_MEDIUM, $fallback)) { $successCount++; } if ($fallback === true) { $dimensions['medium_width'] = $file->getImageInfoField('width'); $dimensions['medium_height'] = $file->getImageInfoField('height'); } } if ($smallThumbFile) { if ($this->createContentDataThumbnailFile($largeThumbFile, $smallThumbFile, $tempType, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_SMALL, $fallback)) { $successCount++; } if ($fallback === true) { $dimensions['small_width'] = $file->getImageInfoField('width'); $dimensions['small_height'] = $file->getImageInfoField('height'); } } if ($xenOptions->sonnbXG_disableOriginal) { if ($successCount !== 3) { return $return; } $dimensions['width'] = $dimensions['large_width']; $dimensions['height'] = $dimensions['large_height']; $dimensions['is_animated'] = $this->_getPhotoModel()->isAnimatedGif($largeThumbFile) ? 1 : 0; } else { if ($successCount !== 4) { return $return; } } try { /** @var sonnb_XenGallery_DataWriter_ContentData $dataDw */ $dataDw = XenForo_DataWriter::create('sonnb_XenGallery_DataWriter_ContentData'); $dataDw->bulkSet($extra); $dataDw->bulkSet($dimensions); $dataDw->set('extension', sonnb_XenGallery_Model_ContentData::$extensionMap[$tempType]); if (!$xenOptions->sonnbXG_disableOriginal && $originalFile) { $dataDw->setExtraData(sonnb_XenGallery_DataWriter_ContentData::DATA_TEMP_FILE, $originalFile); } if ($smallThumbFile) { $dataDw->setExtraData(sonnb_XenGallery_DataWriter_ContentData::DATA_TEMP_SMALL_THUMB_FILE, $smallThumbFile); } if ($mediumThumbFile) { $dataDw->setExtraData(sonnb_XenGallery_DataWriter_ContentData::DATA_TEMP_MEDIUM_THUMB_FILE, $mediumThumbFile); } if ($largeThumbFile) { $dataDw->setExtraData(sonnb_XenGallery_DataWriter_ContentData::DATA_TEMP_LARGE_THUMB_FILE, $largeThumbFile); } $dataDw->save(); $return = $dataDw->getMergedData(); $exif = $this->_getPhotoModel()->getPhotoExif($return, $tempFile); $return['title'] = isset($exif['title']) ? trim($exif['title']) : ($xenOptions->sonnbXG_useFileName ? trim(pathinfo($file->getFileName(), PATHINFO_FILENAME)) : ''); $return['description'] = isset($exif['description']) ? trim($exif['description']) : ''; $return['location_lat'] = isset($exif['latitude']) ? $exif['latitude'] : ''; $return['location_lng'] = isset($exif['longitude']) ? $exif['longitude'] : ''; $return['content_location'] = isset($exif['address']) ? $exif['address'] : ''; } catch (Exception $e) { if ($smallThumbFile) { @unlink($smallThumbFile); } if ($mediumThumbFile) { @unlink($mediumThumbFile); } if ($largeThumbFile) { @unlink($largeThumbFile); } if (!$xenOptions->sonnbXG_disableOriginal && $originalFile) { @unlink($originalFile); } throw $e; } if ($smallThumbFile) { @unlink($smallThumbFile); } if ($mediumThumbFile) { @unlink($mediumThumbFile); } if ($largeThumbFile) { @unlink($largeThumbFile); } if (!$xenOptions->sonnbXG_disableOriginal && $originalFile) { @unlink($originalFile); } } unset($tempFile); return $return; }
public function uploadMediaThumbnail(XenForo_Upload $upload, array $media) { if (!$media) { throw new XenForo_Exception('Missing media record.'); } if (!$upload->isValid()) { throw new XenForo_Exception($upload->getErrors(), true); } if (!$upload->isImage()) { throw new XenForo_Exception(new XenForo_Phrase('uploaded_file_is_not_valid_image'), true); } $baseTempFile = $upload->getTempFile(); $imageType = $upload->getImageInfoField('type'); $width = $upload->getImageInfoField('width'); $height = $upload->getImageInfoField('height'); return $this->processMediaThumbnail($media, $baseTempFile, $imageType, $width, $height); }
/** * Inserts uploaded attachment data. * * @param XenForo_Upload $file Uploaded attachment info. Assumed to be valid * @param integer $userId User ID uploading * @param array $exif Exif data to cache * * @return integer Attachment data ID */ public function insertUploadedAttachmentData(XenForo_Upload $file, $userId, array $exif = array()) { $dimensions = array(); $fileIsVideo = false; $tempThumbFile = false; $options = XenForo_Application::getOptions(); if ($file->isImage()) { $dimensions = array('width' => $file->getImageInfoField('width'), 'height' => $file->getImageInfoField('height')); if (XenForo_Image_Abstract::canResize($dimensions['width'], $dimensions['height'])) { $imageFile = $file->getTempFile(); } else { $imageFile = $options->xengalleryDefaultNoThumb; } $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xfmg'); if ($tempThumbFile) { @copy($imageFile, $tempThumbFile); } } else { $fileIsVideo = true; if ($options->get('xengalleryVideoTranscoding', 'thumbnail')) { try { $video = new XenGallery_Helper_Video($file->getTempFile()); $tempThumbFile = $video->getKeyFrame(); list($width, $height) = $video->getVideoDimensions(); $dimensions['width'] = $width; $dimensions['height'] = $height; } catch (XenForo_Exception $e) { } } if (!$tempThumbFile) { $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xfmg'); if ($tempThumbFile) { @copy($options->xengalleryDefaultNoThumb, $tempThumbFile); } } } if ($tempThumbFile) { $image = new XenGallery_Helper_Image($tempThumbFile); if ($image) { $image->resize($dimensions['thumbnail_width'] = $options->xengalleryThumbnailDimension['width'], $dimensions['thumbnail_height'] = $options->xengalleryThumbnailDimension['height'], 'crop'); $image->saveToPath($tempThumbFile); unset($image); } } $mediaModel = $this->_getMediaModel(); try { $dataDw = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData'); $filename = $file->getFileName(); $dataDw->set('user_id', $userId); if ($fileIsVideo) { $filename = strtr($filename, strtolower(substr(strrchr($filename, '.'), 1)), 'mp4'); $dataDw->set('file_path', $mediaModel->getVideoFilePath()); } $dataDw->set('filename', $filename); $dataDw->bulkSet($dimensions); $dataDw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_TEMP_FILE, $file->getTempFile()); if ($tempThumbFile) { $dataDw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_TEMP_THUMB_FILE, $tempThumbFile); } $dataDw->setExtraData(XenGallery_DataWriter_AttachmentData::DATA_XMG_FILE_IS_VIDEO, $fileIsVideo); $dataDw->setExtraData(XenGallery_DataWriter_AttachmentData::DATA_XMG_DATA, true); $dataDw->save(); } catch (Exception $e) { if ($tempThumbFile) { @unlink($tempThumbFile); } throw $e; } if ($tempThumbFile) { @unlink($tempThumbFile); } $exif = $this->_getMediaModel()->sanitizeExifData($exif); $db = $this->_getDb(); $db->query(' INSERT IGNORE INTO xengallery_exif_cache (data_id, media_exif_data_cache_full, cache_date) VALUES (?, ?, ?) ', array($dataDw->get('data_id'), @json_encode($exif), XenForo_Application::$time)); return $dataDw->get('data_id'); }
public function importMedia($oldId, $tempFile, $contentType = '', array $xengalleryMedia = array(), array $xfAttachment = array(), array $xfAttachmentData = array()) { $db = $this->_getDb(); XenForo_Db::beginTransaction($db); $attachmentId = 0; if ($xfAttachment) { /** @var $attachmentDw XenForo_DataWriter_Attachment */ $attachmentDw = XenForo_DataWriter::create('XenForo_DataWriter_Attachment'); $attachmentDw->setImportMode(true); $attachmentDw->bulkSet($xfAttachment); $attachmentDw->save(); $attachmentId = $attachmentDw->get('attachment_id'); } $newId = false; if ($xengalleryMedia) { /** @var $mediaDw XenGallery_DataWriter_Media */ $mediaDw = XenForo_DataWriter::create('XenGallery_DataWriter_Media'); $mediaDw->setImportMode(true); $mediaDw->set('imported', XenForo_Application::$time); if ($this->_retainKeys) { $mediaDw->set('media_id', $oldId); } $xengalleryMedia['attachment_id'] = $attachmentId; $mediaDw->bulkSet($xengalleryMedia); if ($mediaDw->save()) { $newId = $mediaDw->get('media_id'); $this->_getImportModel()->logImportData('xengallery_media', $oldId, $newId); } $media = $mediaDw->getMergedData(); if ($media['likes'] && $media['like_users'] && $contentType) { $this->_convertLikesToNewContentType($oldId, $newId, $contentType, 'xengallery_media'); } } if ($xfAttachmentData) { $fileIsVideo = false; $db->update('xf_attachment', array('content_id' => $media['media_id']), 'attachment_id = ' . $db->quote($attachmentId)); $options = XenForo_Application::getOptions(); $upload = new XenForo_Upload($xfAttachmentData['filename'], $tempFile); if ($upload->isImage()) { $image = new XenGallery_Helper_Image($tempFile); $image->importMode = true; $dimensions = array('width' => $image->getWidth(), 'height' => $image->getHeight()); $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xfmg'); if ($tempThumbFile && $image) { $resized = $image->resize($dimensions['thumbnail_width'] = $options->xengalleryThumbnailDimension['width'], $dimensions['thumbnail_height'] = $options->xengalleryThumbnailDimension['height'], 'crop'); if (!$resized) { return false; } $image->saveToPath($tempThumbFile); unset($image); } else { return false; } } else { $dimensions = array(); $fileIsVideo = true; $tempThumbFile = false; if ($options->get('xengalleryVideoTranscoding', 'thumbnail')) { try { $video = new XenGallery_Helper_Video($upload->getTempFile()); $tempThumbFile = $video->getKeyFrame(); list($width, $height) = $video->getVideoDimensions(); $dimensions['width'] = $width; $dimensions['height'] = $height; } catch (XenForo_Exception $e) { } } if (!$tempThumbFile) { $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xfmg'); if ($tempThumbFile) { @copy($options->xengalleryDefaultNoThumb, $tempThumbFile); } } $image = new XenGallery_Helper_Image($tempThumbFile); if ($image) { $image->resize($dimensions['thumbnail_width'] = $options->xengalleryThumbnailDimension['width'], $dimensions['thumbnail_height'] = $options->xengalleryThumbnailDimension['height'], 'crop'); $image->saveToPath($tempThumbFile); unset($image); } } $mediaModel = $this->getModelFromCache('XenGallery_Model_Media'); try { $dataDw = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData'); $filename = $upload->getFileName(); if ($fileIsVideo) { $filename = strtr($filename, strtolower(substr(strrchr($filename, '.'), 1)), 'mp4'); $dataDw->set('file_path', $mediaModel->getVideoFilePath()); } $dataDw->set('filename', $filename); $dataDw->bulkSet($dimensions); $dataDw->bulkSet($xfAttachmentData); $dataDw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_TEMP_FILE, $tempFile); if ($tempThumbFile) { $dataDw->setExtraData(XenForo_DataWriter_AttachmentData::DATA_TEMP_THUMB_FILE, $tempThumbFile); } $dataDw->setExtraData(XenGallery_DataWriter_AttachmentData::DATA_XMG_FILE_IS_VIDEO, $fileIsVideo); $dataDw->setExtraData(XenGallery_DataWriter_AttachmentData::DATA_XMG_DATA, true); $dataDw->save(); $attachmentData = $dataDw->getMergedData(); $db->update('xf_attachment', array('data_id' => $attachmentData['data_id']), 'attachment_id = ' . $db->quote($attachmentId)); } catch (Exception $e) { if ($tempThumbFile) { @unlink($tempThumbFile); } throw $e; } if ($tempThumbFile) { @unlink($tempThumbFile); } } if ($newId) { XenForo_Db::commit($db); } else { XenForo_Db::rollback($db); } return $newId; }
public function importBibleZip(XenForo_Upload $file) { $path = $file->getTempFile(); $bibleId = pathinfo($file->getFileName(), PATHINFO_FILENAME); $internalData = XenForo_Helper_File::getInternalDataPath(); XenForo_Helper_File::createDirectory($internalData . '/bibles/' . $bibleId); $zip = new ZipArchive(); if (@$zip->open($path) === true) { for ($i = 0; $i < $zip->numFiles; $i++) { $filename = $zip->getNameIndex($i); copy("zip://" . $path . "#" . $filename, $internalData . '/bibles/' . $bibleId . '/' . $filename); } $zip->close(); } XenForo_Application::defer('ThemeHouse_Bible_Deferred_Import', array('bible_id' => $bibleId), 'BibleImport_' . $bibleId, true); }