Esempio n. 1
0
 public function actionXenGallerySave()
 {
     $this->_assertPostOnly();
     $input = $this->_input->filter(array('group_id' => XenForo_Input::STRING, 'options' => XenForo_Input::ARRAY_SIMPLE, 'options_listed' => array(XenForo_Input::STRING, array('array' => true))));
     $options = XenForo_Application::getOptions();
     $optionModel = $this->_getOptionModel();
     $group = $optionModel->getOptionGroupById($input['group_id']);
     foreach ($input['options_listed'] as $optionName) {
         if ($optionName == 'xengalleryUploadWatermark') {
             continue;
         }
         if (!isset($input['options'][$optionName])) {
             $input['options'][$optionName] = '';
         }
     }
     $delete = $this->_input->filterSingle('delete_watermark', XenForo_Input::BOOLEAN);
     if ($delete) {
         $existingWatermark = $options->get('xengalleryUploadWatermark');
         if ($existingWatermark) {
             $watermarkWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Watermark', XenForo_DataWriter::ERROR_SILENT);
             $watermarkWriter->setExistingData($existingWatermark);
             $watermarkWriter->delete();
             $input['options']['xengalleryUploadWatermark'] = 0;
             $optionModel->updateOptions($input['options']);
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(XenForo_Link::buildAdminLink('options/list', $group)));
         }
     }
     $fileTransfer = new Zend_File_Transfer_Adapter_Http();
     if ($fileTransfer->isUploaded('watermark')) {
         $fileInfo = $fileTransfer->getFileInfo('watermark');
         $fileName = $fileInfo['watermark']['tmp_name'];
         $watermarkWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Watermark', XenForo_DataWriter::ERROR_SILENT);
         $existingWatermark = $options->get('xengalleryUploadWatermark');
         if ($existingWatermark) {
             $watermarkWriter->setExistingData($existingWatermark);
         }
         $watermarkData = array('watermark_user_id' => XenForo_Visitor::getUserId(), 'is_site' => 1);
         $watermarkWriter->bulkSet($watermarkData);
         $watermarkWriter->save();
         $image = new XenGallery_Helper_Image($fileName);
         $image->resize($options->xengalleryWatermarkDimensions['width'], $options->xengalleryWatermarkDimensions['height'], 'fit');
         $watermarkModel = $this->_getWatermarkModel();
         $watermarkPath = $watermarkModel->getWatermarkFilePath($watermarkWriter->get('watermark_id'));
         if (XenForo_Helper_File::createDirectory(dirname($watermarkPath), true)) {
             XenForo_Helper_File::safeRename($fileName, $watermarkPath);
             $input['options']['xengalleryUploadWatermark'] = $watermarkWriter->get('watermark_id');
         }
     }
     $optionModel->updateOptions($input['options']);
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(XenForo_Link::buildAdminLink('options/list', $group)));
 }
Esempio n. 2
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('position' => 0, 'batch' => 10), $data);
     $data['batch'] = max(1, $data['batch']);
     /* @var $mediaModel XenGallery_Model_Media */
     $mediaModel = XenForo_Model::create('XenGallery_Model_Media');
     /* @var $attachmentModel XenForo_Model_Attachment */
     $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment');
     $watermarkModel = $this->_getWatermarkModel();
     if (!$this->_db) {
         $this->_db = XenForo_Application::getDb();
     }
     $mediaIds = $mediaModel->getMediaIdsInRange($data['position'], $data['batch']);
     if (sizeof($mediaIds) == 0) {
         return true;
     }
     $options = XenForo_Application::getOptions();
     $fetchOptions = array('join' => XenGallery_Model_Media::FETCH_ATTACHMENT);
     $media = $mediaModel->getMediaByIds($mediaIds, $fetchOptions);
     $media = $mediaModel->prepareMediaItems($media);
     foreach ($media as $item) {
         $data['position'] = $item['media_id'];
         if (empty($item['watermark_id'])) {
             continue;
         }
         try {
             $attachment = $attachmentModel->getAttachmentById($item['attachment_id']);
             $originalPath = $mediaModel->getOriginalDataFilePath($attachment, true);
             $filePath = $attachmentModel->getAttachmentDataFilePath($attachment);
             $watermarkPath = $watermarkModel->getWatermarkFilePath($item['watermark_id']);
             if (XenForo_Helper_File::createDirectory(dirname($originalPath), true)) {
                 $image = new XenGallery_Helper_Image($originalPath);
                 $watermark = new XenGallery_Helper_Image($watermarkPath);
                 $watermark->resize($image->getWidth() / 100 * $options->xengalleryWatermarkDimensions['width'], $image->getHeight() / 100 * $options->xengalleryWatermarkDimensions['height'], 'fit');
                 $image->addWatermark($watermark->tmpFile);
                 $image->writeWatermark($options->xengalleryWatermarkOpacity, $options->xengalleryWatermarkMargin['h'], $options->xengalleryWatermarkMargin['v'], $options->xengalleryWatermarkHPos, $options->xengalleryWatermarkVPos);
                 $image->saveToPath($filePath);
                 unset($watermark);
                 unset($image);
                 clearstatcache();
                 $this->_db->update('xf_attachment_data', array('file_size' => filesize($filePath)), 'data_id = ' . $attachment['data_id']);
                 $mediaWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Media');
                 $mediaWriter->setExistingData($item['media_id']);
                 $mediaWriter->set('last_edit_date', XenForo_Application::$time);
                 $mediaWriter->save();
             }
         } catch (Exception $e) {
         }
     }
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = new XenForo_Phrase('xengallery_rebuild_watermarks');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position']));
     return $data;
 }
Esempio n. 3
0
 /**
  * Saves a thumbnail locally
  *
  * @param $thumbnailUrl
  */
 public function saveThumbnail()
 {
     $this->_videoId = XenGallery_Helper_String::cleanVideoId($this->_videoId);
     $this->_mediaSiteId = preg_replace('#[^a-zA-Z0-9_]#', '', $this->_mediaSiteId);
     if (!$this->_mediaSiteId || !$this->_videoId || !$this->_thumbnailUrl) {
         return false;
     }
     $options = XenForo_Application::getOptions();
     $this->_thumbnailPath = XenForo_Application::$externalDataPath . '/xengallery/' . $this->_mediaSiteId;
     try {
         $thumbnailPath = $this->_thumbnailPath . '/' . $this->_mediaSiteId . '_' . $this->_videoId . '.jpg';
         $client = XenForo_Helper_Http::getClient($this->_thumbnailUrl);
         XenForo_Helper_File::createDirectory(dirname($thumbnailPath), true);
         $fp = @fopen($thumbnailPath, 'w');
         if (!$fp) {
             return false;
         }
         fwrite($fp, $client->request('GET')->getBody());
         fclose($fp);
     } catch (Zend_Http_Client_Exception $e) {
         return false;
     }
     $image = new XenGallery_Helper_Image($thumbnailPath);
     $image->resize($options->xengalleryThumbnailDimension['width'], $options->xengalleryThumbnailDimension['height'], 'crop');
     return $image->save($this->_mediaSiteId . '_' . $this->_videoId . '_thumb', $this->_thumbnailPath, 'jpg');
 }
Esempio n. 4
0
 public function rebuildThumbnail(array $media, array $imageInfo, $deleteExisting = true, $skipThumbnail = 0)
 {
     $originalThumbFile = $this->getMediaThumbnailFilePath($media);
     $media['file_hash'] = $imageInfo['file_hash'];
     $options = XenForo_Application::getOptions();
     $thumbFile = $this->getMediaThumbnailFilePath($media);
     $thumbImage = false;
     if ($skipThumbnail) {
         XenForo_Helper_File::safeRename($originalThumbFile, $thumbFile);
     } else {
         if ($media['media_type'] == 'image_upload') {
             $originalFile = $this->getOriginalDataFilePath($media, true);
             $thumbImage = new XenGallery_Helper_Image($originalFile);
         } else {
             if ($media['media_type'] == 'video_upload') {
                 $originalFile = $this->getAttachmentDataFilePath($media);
                 $tempThumbFile = false;
                 if ($options->get('xengalleryVideoTranscoding', 'thumbnail')) {
                     try {
                         $video = new XenGallery_Helper_Video($originalFile);
                         $tempThumbFile = $video->getKeyFrame();
                     } catch (XenForo_Exception $e) {
                     }
                 }
                 if (!$tempThumbFile) {
                     $tempThumbFile = tempnam(XenForo_Helper_File::getTempDir(), 'xfmg');
                     if ($tempThumbFile) {
                         @copy($options->xengalleryDefaultNoThumb, $tempThumbFile);
                     }
                 }
                 $thumbImage = new XenGallery_Helper_Image($tempThumbFile);
             }
         }
         if ($thumbImage) {
             $thumbImage->resize($options->xengalleryThumbnailDimension['width'], $options->xengalleryThumbnailDimension['height'], 'crop');
             $thumbnailed = $thumbImage->saveToPath($thumbFile);
             if ($thumbnailed && $deleteExisting) {
                 @unlink($originalThumbFile);
             }
         }
     }
     $mediaWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Media');
     $mediaWriter->setExistingData($media);
     $mediaWriter->bulkSet(array('last_edit_date' => XenForo_Application::$time, 'thumbnail_date' => $media['thumbnail_date']));
     $mediaWriter->save();
     if ($media['album_id']) {
         $albumWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Album');
         $albumWriter->setExistingData($media['album_id']);
         if (!$albumWriter->get('manual_media_cache') && !$albumWriter->get('album_thumbnail_date')) {
             $mediaItems = $this->getMediaForAlbumCache($media['album_id']);
             $albumWriter->bulkSet(array('last_update_date' => XenForo_Application::$time, 'media_cache' => serialize($mediaItems)));
             $albumWriter->save();
         }
     }
 }
Esempio n. 5
0
    /**
     * 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');
    }
Esempio n. 6
0
 /**
  * Dynamically creates a dummy image based on the configured aspect ratio (if required).
  * Can be useful for spacing and as a placeholder.
  *
  * @return string
  */
 public static function helperDummyImage($visibility = 'hidden', $title = '', $classes = '', $pathOnly = false)
 {
     $dimensions = XenForo_Application::getOptions()->get('xengalleryThumbnailDimension');
     $imagePath = XenForo_Template_Helper_Core::styleProperty('imagePath');
     $dummyPath = "{$imagePath}/xengallery/nothumb.jpg";
     if (!file_exists($dummyPath)) {
         $dummyPath = 'styles/default/xengallery/nothumb.jpg';
     }
     $writePath = XenForo_Application::$externalDataPath . '/xengallery/dummy/dummy.jpg';
     $writeUrl = XenForo_Application::$externalDataUrl . '/xengallery/dummy/dummy.jpg';
     XenForo_Helper_File::createDirectory(dirname($writePath));
     if (is_readable($dummyPath)) {
         $baseImage = new XenGallery_Helper_Image($dummyPath);
         $newDummyImage = false;
         if (is_readable($writePath)) {
             $currentImage = new XenGallery_Helper_Image($writePath);
             if ($currentImage->getWidth() != $dimensions['width'] || $currentImage->getHeight() != $dimensions['height']) {
                 $newDummyImage = true;
             }
         }
         if ($newDummyImage || !file_exists($writePath)) {
             $baseImage->resize($dimensions['width'], $dimensions['height'], 'crop');
             $baseImage->saveToPath($writePath);
         }
     }
     if ($pathOnly) {
         return $writePath;
     }
     $writeUrl .= '?' . XenForo_Application::$time;
     return "<img src=\"{$writeUrl}\" style=\"width: 100%; visibility: {$visibility}\" class=\"dummyImage {$classes}\" title=\"{$title}\" alt=\"{$title}\" />";
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $data = array_merge(array('position' => 0, 'batch' => 10), $data);
     $data['batch'] = max(1, $data['batch']);
     /* @var $mediaModel XenGallery_Model_Media */
     $mediaModel = XenForo_Model::create('XenGallery_Model_Media');
     $mediaIds = $mediaModel->getMediaIdsInRange($data['position'], $data['batch'], 'all');
     if (sizeof($mediaIds) == 0) {
         return true;
     }
     $options = XenForo_Application::getOptions();
     $fetchOptions = array('join' => XenGallery_Model_Media::FETCH_ATTACHMENT);
     $media = $mediaModel->getMediaByIds($mediaIds, $fetchOptions);
     $media = $mediaModel->prepareMediaItems($media);
     foreach ($media as $item) {
         $data['position'] = $item['media_id'];
         if ($item['thumbnail_date']) {
             continue;
         }
         $thumbnailPath = $mediaModel->getMediaThumbnailFilePath($item);
         $dataPath = $mediaModel->getOriginalDataFilePath($item, true);
         if ($item['media_type'] == 'image_upload') {
             XenForo_Helper_File::createDirectory(dirname($thumbnailPath), true);
             if (!file_exists($dataPath) || !is_readable($dataPath)) {
                 continue;
             }
             $image = new XenGallery_Helper_Image($dataPath);
             if ($image) {
                 $image->resize($dimensions['thumbnail_width'] = $options->xengalleryThumbnailDimension['width'], $dimensions['thumbnail_height'] = $options->xengalleryThumbnailDimension['height'], 'crop');
                 $image->saveToPath($thumbnailPath);
                 unset($image);
                 $attachmentDataWriter = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData');
                 $attachmentDataWriter->setExistingData($item['data_id']);
                 $attachmentDataWriter->bulkSet($dimensions);
                 $attachmentDataWriter->save();
             }
         } else {
             if ($item['media_type'] == 'video_upload') {
                 XenForo_Helper_File::createDirectory(dirname($thumbnailPath), true);
                 if (!file_exists($dataPath) || !is_readable($dataPath)) {
                     continue;
                 }
                 $tempThumbFile = false;
                 if ($options->get('xengalleryVideoTranscoding', 'thumbnail')) {
                     try {
                         $video = new XenGallery_Helper_Video($dataPath);
                         $tempThumbFile = $video->getKeyFrame();
                     } 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($thumbnailPath);
                     unset($image);
                     $attachmentDataWriter = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData');
                     $attachmentDataWriter->setExistingData($item['data_id']);
                     $attachmentDataWriter->bulkSet($dimensions);
                     $attachmentDataWriter->save();
                 }
             } else {
                 if ($item['media_type'] == 'video_embed') {
                     preg_match('/\\[media=(.*?)\\](.*?)\\[\\/media\\]/is', $item['media_tag'], $parts);
                     $mediaModel->getVideoThumbnailUrlFromParts($parts, true);
                 }
             }
         }
         /** @var $mediaWriter XenGallery_DataWriter_Media */
         $mediaWriter = XenForo_DataWriter::create('XenGallery_DataWriter_Media');
         $mediaWriter->setImportMode(true);
         $mediaWriter->setExistingData($item['media_id']);
         $mediaWriter->set('last_edit_date', XenForo_Application::$time);
         $mediaWriter->save();
     }
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = new XenForo_Phrase('xengallery_rebuild_thumbnails');
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, XenForo_Locale::numberFormat($data['position']));
     return $data;
 }
Esempio n. 9
0
 public function processAlbumThumbnail($albumId, $fileName, $imageType = false, $width = false, $height = false)
 {
     if (!$imageType || !$width || !$height) {
         $imageInfo = getimagesize($fileName);
         if (!$imageInfo) {
             throw new XenForo_Exception('Non-image passed in to albumThumbnail');
         }
         $imageType = $imageInfo[2];
     }
     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);
     }
     $options = XenForo_Application::getOptions();
     $thumbFile = $this->getAlbumThumbnailFilePath($albumId);
     XenForo_Helper_File::createDirectory(dirname($thumbFile));
     $thumbImage = new XenGallery_Helper_Image($fileName);
     if ($thumbImage) {
         $thumbImage->resize($options->xengalleryThumbnailDimension['width'], $options->xengalleryThumbnailDimension['height'], 'crop');
         $thumbnailed = $thumbImage->saveToPath($thumbFile);
         $originalFile = $this->getAlbumThumbnailFilePath($albumId, true);
         XenForo_Helper_File::createDirectory(dirname($originalFile));
         if ($thumbnailed) {
             $writeSuccess = XenForo_Helper_File::safeRename($fileName, $originalFile);
             if ($writeSuccess && file_exists($fileName)) {
                 @unlink($fileName);
             }
         } else {
             $writeSuccess = false;
         }
         if ($writeSuccess) {
             $albumDw = XenForo_DataWriter::create('XenGallery_DataWriter_Album');
             $albumDw->setExistingData($albumId);
             $albumDw->bulkSet(array('album_thumbnail_date' => XenForo_Application::$time, 'media_cache' => array(), 'manual_media_cache' => 0));
             $albumDw->save();
         }
         return $writeSuccess;
     }
     return false;
 }