Exemple #1
0
 protected function _writeIcon($nodeId, $number, $tempFile)
 {
     $filePath = $this->getIconFilePath($nodeId, $number);
     $directory = dirname($filePath);
     if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
         if (file_exists($filePath)) {
             @unlink($filePath);
         }
         return XenForo_Helper_File::safeRename($tempFile, $filePath);
     } else {
         return false;
     }
 }
 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)));
 }
Exemple #3
0
 /**
  * Applies the avatar file to the specified user.
  *
  * @param integer $teamId
  * @param string $fileName
  * @param constant|false $imageType Type of image (IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)
  * @param integer|false $width
  * @param integer|false $height
  *
  * @return array
  */
 public function applyAvatar($teamId, $fileName, $imageType = false, $width = false, $height = false)
 {
     if (!$imageType || !$width || !$height) {
         $imageInfo = getimagesize($fileName);
         if (!$imageInfo) {
             throw new Nobita_Teams_Exception_Abstract('Non-image passed in to applyAvatar');
         }
         $width = $imageInfo[0];
         $height = $imageInfo[1];
         $imageType = $imageInfo[2];
     }
     if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         throw new Nobita_Teams_Exception_Abstract('Invalid image type passed in to applyAvatar');
     }
     if (!XenForo_Image_Abstract::canResize($width, $height)) {
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('uploaded_image_is_too_big'), true);
     }
     $maxFileSize = XenForo_Application::getOptions()->Teams_avatarFileSize;
     if ($maxFileSize && filesize($fileName) > $maxFileSize) {
         @unlink($fileName);
         throw new Nobita_Teams_Exception_Abstract(new XenForo_Phrase('your_avatar_file_size_large_smaller_x', array('size' => XenForo_Locale::numberFormat($maxFileSize, 'size'))), true);
     }
     // should be use 280x280px because of grid style
     $maxDimensions = 280;
     $imageQuality = intval(Nobita_Teams_Setup::getInstance()->getOption('logoQuality'));
     $outputType = $imageType;
     $image = XenForo_Image_Abstract::createFromFile($fileName, $imageType);
     if (!$image) {
         return false;
     }
     $image->thumbnailFixedShorterSide($maxDimensions);
     if ($image->getOrientation() != XenForo_Image_Abstract::ORIENTATION_SQUARE) {
         $cropX = floor(($image->getWidth() - $maxDimensions) / 2);
         $cropY = floor(($image->getHeight() - $maxDimensions) / 2);
         $image->crop($cropX, $cropY, $maxDimensions, $maxDimensions);
     }
     $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
     if (!$newTempFile) {
         return false;
     }
     $image->output($outputType, $newTempFile, $imageQuality);
     unset($image);
     $filePath = $this->getAvatarFilePath($teamId);
     $directory = dirname($filePath);
     if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
         if (file_exists($filePath)) {
             @unlink($filePath);
         }
         $writeSuccess = XenForo_Helper_File::safeRename($newTempFile, $filePath);
         if ($writeSuccess && file_exists($newTempFile)) {
             @unlink($newTempFile);
         }
     } else {
         $writeSuccess = false;
     }
     $date = XenForo_Application::$time;
     if ($writeSuccess) {
         $dw = XenForo_DataWriter::create('Nobita_Teams_DataWriter_Team');
         $dw->setExistingData($teamId);
         $dw->set('team_avatar_date', $date);
         $dw->save();
     }
     return $writeSuccess ? $date : 0;
 }
Exemple #4
0
 public function applyCategoryIcon($categoryId, $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 applyCategoryIcon');
         }
         $width = $imageInfo[0];
         $height = $imageInfo[1];
         $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);
     }
     if (!XenForo_Image_Abstract::canResize($width, $height)) {
         throw new XenForo_Exception(new XenForo_Phrase('uploaded_image_is_too_big'), true);
     }
     $maxDimensions = self::$iconSize;
     $imageQuality = self::$iconQuality;
     $outputType = $imageType;
     $image = XenForo_Image_Abstract::createFromFile($fileName, $imageType);
     if (!$image) {
         return false;
     }
     $image->thumbnailFixedShorterSide($maxDimensions);
     if ($image->getOrientation() != XenForo_Image_Abstract::ORIENTATION_SQUARE) {
         $cropX = floor(($image->getWidth() - $maxDimensions) / 2);
         $cropY = floor(($image->getHeight() - $maxDimensions) / 2);
         $image->crop($cropX, $cropY, $maxDimensions, $maxDimensions);
     }
     $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
     if (!$newTempFile) {
         return false;
     }
     $image->output($outputType, $newTempFile, $imageQuality);
     unset($image);
     $filePath = $this->getCategoryIconFilePath($categoryId);
     $directory = dirname($filePath);
     if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
         if (file_exists($filePath)) {
             @unlink($filePath);
         }
         $writeSuccess = XenForo_Helper_File::safeRename($newTempFile, $filePath);
         if ($writeSuccess && file_exists($newTempFile)) {
             @unlink($newTempFile);
         }
     } else {
         $writeSuccess = false;
     }
     if ($writeSuccess) {
         $dw = XenForo_DataWriter::create('Nobita_Teams_DataWriter_Category');
         $dw->setExistingData($categoryId);
         $dw->set('icon_date', XenForo_Application::$time);
         $dw->save();
     }
     return $writeSuccess;
 }
Exemple #5
0
 /**
  * Fetches a remote image, stores it in the file system and records it in the database
  *
  * @param string $url
  * @param array|null $image
  *
  * @return array
  */
 protected function _fetchAndCacheImage($url, array $image = null)
 {
     $urlHash = md5($url);
     $time = XenForo_Application::$time;
     if (!$image || empty($image['image_id'])) {
         $image = array('url' => $url, 'url_hash' => $urlHash, 'fetch_date' => $time, 'file_size' => 0, 'file_name' => '', 'mime_type' => '', 'views' => 0, 'first_request_date' => $time, 'last_request_date' => $time, 'pruned' => 1, 'failed_date' => 0, 'fail_count' => 0);
     }
     $image['is_processing'] = time();
     // intentionally time() as we might have slept
     $db = $this->_getDb();
     if (empty($image['image_id'])) {
         try {
             $db->insert('xf_image_proxy', $image);
             $image['image_id'] = $db->lastInsertId();
         } catch (Exception $e) {
             $image['image_id'] = 0;
             $image['is_processing'] = 0;
             $image['failed_date'] = time();
             $image['fail_count'] = 1;
             return $image;
         }
     } else {
         $db->query("\n\t\t\t\tUPDATE xf_image_proxy\n\t\t\t\tSET is_processing = ?\n\t\t\t\tWHERE image_id = ?\n\t\t\t", array($image['is_processing'], $image['image_id']));
     }
     $results = $this->_fetchImageForProxy($url);
     $requestFailed = $results['failed'];
     $streamFile = $results['tempFile'];
     $fileName = $results['fileName'];
     $mimeType = $results['mimeType'];
     $fileSize = $results['fileSize'];
     if (!$requestFailed) {
         $filePath = $this->getImagePath($image);
         $dirName = dirname($filePath);
         @unlink($filePath);
         if (XenForo_Helper_File::createDirectory($dirName, true) && XenForo_Helper_File::safeRename($streamFile, $filePath)) {
             // ensure the filename fits -- if it's too long, take off from the beginning to keep extension
             if (!preg_match('/./u', $fileName)) {
                 $fileName = preg_replace('/[\\x80-\\xFF]/', '?', $fileName);
             }
             $fileName = XenForo_Input::cleanString($fileName);
             $length = utf8_strlen($fileName);
             if ($length > 250) {
                 $fileName = utf8_substr($fileName, $length - 250);
             }
             $data = array('fetch_date' => time(), 'file_size' => $fileSize, 'file_name' => $fileName, 'mime_type' => $mimeType, 'pruned' => 0, 'is_processing' => 0, 'failed_date' => 0, 'fail_count' => 0);
             $image = array_merge($image, $data);
             $db->update('xf_image_proxy', $data, 'image_id = ' . $db->quote($image['image_id']));
         }
     }
     @unlink($streamFile);
     if ($requestFailed) {
         $data = array('is_processing' => 0, 'failed_date' => time(), 'fail_count' => $image['fail_count'] + 1);
         $image = array_merge($image, $data);
         $db->update('xf_image_proxy', $data, 'image_id = ' . $db->quote($image['image_id']));
     }
     return $image;
 }
 /**
  * Writes out an avatar.
  *
  * @param integer $userId
  * @param string $size Size code
  * @param string $tempFile Temporary avatar file. Will be moved.
  *
  * @return boolean
  */
 protected function _writeAvatar($userId, $size, $tempFile)
 {
     if (!in_array($size, array_keys(self::$_sizes))) {
         throw new XenForo_Exception('Invalid avatar size.');
     }
     $filePath = $this->getAvatarFilePath($userId, $size);
     $directory = dirname($filePath);
     if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
         if (file_exists($filePath)) {
             @unlink($filePath);
         }
         return XenForo_Helper_File::safeRename($tempFile, $filePath);
     } else {
         return false;
     }
 }
 private static function _moveAddOnFiles($packageDir, $xfDir, array $files)
 {
     foreach ($files as $file) {
         $packagePath = sprintf('%s/%s', $packageDir, $file);
         $systemPath = sprintf('%s/%s', $xfDir, $file);
         if (!XenForo_Helper_File::safeRename($packagePath, $systemPath)) {
             throw new XenForo_Exception('File cannot be updated: ' . $file);
         }
     }
 }
Exemple #8
0
 protected function _witerCoverPhoto($teamId, $tempFile)
 {
     $filePath = $this->getCoverPhotoFilePath($teamId);
     $directory = dirname($filePath);
     if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
         if (file_exists($filePath)) {
             unlink($filePath);
         }
         return XenForo_Helper_File::safeRename($tempFile, $filePath);
     } else {
         return false;
     }
 }
 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();
         }
     }
 }
Exemple #10
0
 public static function getThumbnailUrl($fullPath, $width, $height = 0, $dir = null)
 {
     $thumbnailPath = self::getThumbnailPath($fullPath, $width, $height, $dir);
     $thumbnailUrl = XenForo_Application::$externalDataUrl . self::_getThumbnailRelativePath($fullPath, $width, $height, $dir);
     if (file_exists($thumbnailPath) && filesize($thumbnailPath) > 0) {
         return $thumbnailUrl;
     }
     $tempPath = self::_getTempPath($fullPath);
     $imageInfo = self::getImageInfo($tempPath);
     $image = null;
     if (!empty($imageInfo['typeInt'])) {
         $image = XenForo_Image_Abstract::createFromFile($tempPath, $imageInfo['typeInt']);
     }
     if (empty($image)) {
         // could not open the image, create a new image
         $longer = max($width, $height);
         $image = XenForo_Image_Abstract::createImage($longer, $longer);
         $imageInfo['typeInt'] = IMAGETYPE_PNG;
     }
     if ($width === '' && $height > 0) {
         // stretch width
         $targetHeight = $height;
         $targetWidth = $targetHeight / $image->getHeight() * $image->getWidth();
         $image->thumbnail($targetWidth, $targetHeight);
     } elseif ($height === '' && $width > 0) {
         // stretch height
         $targetWidth = $width;
         $targetHeight = $targetWidth / $image->getWidth() * $image->getHeight();
         $image->thumbnail($targetWidth, $targetHeight);
     } elseif ($width > 0 && $height > 0) {
         // exact crop
         $origRatio = $image->getWidth() / $image->getHeight();
         $cropRatio = $width / $height;
         if ($origRatio > $cropRatio) {
             $thumbnailHeight = $height;
             $thumbnailWidth = $height * $origRatio;
         } else {
             $thumbnailWidth = $width;
             $thumbnailHeight = $width / $origRatio;
         }
         if ($thumbnailWidth <= $image->getWidth() && $thumbnailHeight <= $image->getHeight()) {
             $image->thumbnail($thumbnailWidth, $thumbnailHeight);
             $image->crop(0, 0, $width, $height);
         } else {
             // thumbnail requested is larger then the image size
             if ($origRatio > $cropRatio) {
                 $image->crop(0, 0, $image->getHeight() * $cropRatio, $image->getHeight());
             } else {
                 $image->crop(0, 0, $image->getWidth(), $image->getWidth() / $cropRatio);
             }
         }
     } elseif ($width > 0) {
         // square crop
         $image->thumbnailFixedShorterSide($width);
         $image->crop(0, 0, $width, $width);
     }
     // TODO: progressive jpeg
     XenForo_Helper_File::createDirectory(dirname($thumbnailPath), true);
     $outputPath = tempnam(XenForo_Helper_File::getTempDir(), __CLASS__);
     /** @noinspection PhpParamsInspection */
     $image->output($imageInfo['typeInt'], $outputPath);
     XenForo_Helper_File::safeRename($outputPath, $thumbnailPath);
     return $thumbnailUrl;
 }
Exemple #11
0
 /**
  * Moves the specified file. If it's an uploaded file, it will be moved with
  * move_uploaded_file().
  *
  * @param string $source
  * @param string $destination
  *
  * @return boolean
  */
 protected function _moveFile($source, $destination)
 {
     return XenForo_Helper_File::safeRename($source, $destination);
 }
 /**
  * Fetches a remote thumbnail, stores it in the file system and records it
  * in the database
  *
  * @param string $url
  * @param array|null $thumbnail
  *
  * @return array
  */
 protected function _fetchAndCacheThumbnail($url, array $thumbnail = null)
 {
     $urlHash = md5($url);
     $time = XenForo_Application::$time;
     if (!$thumbnail || empty($thumbnail['thumbnail_id'])) {
         $thumbnail = array('url' => $url, 'url_hash' => $urlHash, 'fetch_date' => $time, 'file_size' => 0, 'file_name' => '', 'mime_type' => '', 'views' => 0, 'first_request_date' => $time, 'last_request_date' => $time, 'pruned' => 1, 'failed_date' => 0, 'fail_count' => 0);
     }
     $thumbnail['is_processing'] = time();
     // intentionally time() as we might have slept
     $db = $this->_getDb();
     if (empty($thumbnail['thumbnail_id'])) {
         $db->insert('xf_thumbnail_proxy_waindigo', $thumbnail);
         $thumbnail['thumbnail_id'] = $db->lastInsertId();
     } else {
         $db->query("\n\t\t\t\tUPDATE xf_thumbnail_proxy_waindigo\n\t\t\t\tSET is_processing = ?\n\t\t\t\tWHERE thumbnail_id = ?\n\t\t\t", array($thumbnail['is_processing'], $thumbnail['thumbnail_id']));
     }
     $results = $this->_fetchThumbnailForProxy($url);
     $requestFailed = $results['failed'];
     $streamFile = $results['tempFile'];
     $fileName = $results['fileName'];
     $mimeType = $results['mimeType'];
     $fileSize = $results['fileSize'];
     if (!$requestFailed) {
         $filePath = $this->getThumbnailPath($thumbnail);
         $dirName = dirname($filePath);
         @unlink($filePath);
         @unlink($filePath . '.tmp');
         if (XenForo_Helper_File::createDirectory($dirName, true) && XenForo_Helper_File::safeRename($streamFile, $filePath . '.tmp')) {
             if (function_exists('exif_imagetype')) {
                 $imageType = exif_imagetype($filePath . '.tmp');
             } else {
                 $imageSize = getimagesize($filePath . '.tmp');
                 $imageType = $imageSize[2];
             }
             $image = XenForo_Image_Abstract::createFromFile($filePath . '.tmp', $imageType);
             if ($image && $image->thumbnail(XenForo_Application::get('options')->attachmentThumbnailDimensions)) {
                 $image->output($imageType, $filePath);
                 @unlink($filePath . '.tmp');
                 $fileSize = filesize($filePath);
             } else {
                 XenForo_Helper_File::safeRename($filePath . '.tmp', $filePath);
             }
             unset($image);
             // ensure the filename fits -- if it's too long, take off from the beginning to keep extension
             $length = utf8_strlen($fileName);
             if ($length > 250) {
                 $fileName = utf8_substr($fileName, $length - 250);
             }
             $data = array('fetch_date' => time(), 'file_size' => $fileSize, 'file_name' => $fileName, 'mime_type' => $mimeType, 'pruned' => 0, 'is_processing' => 0, 'failed_date' => 0, 'fail_count' => 0);
             $thumbnail = array_merge($thumbnail, $data);
             $db->update('xf_thumbnail_proxy_waindigo', $data, 'thumbnail_id = ' . $db->quote($thumbnail['thumbnail_id']));
         }
     }
     @unlink($streamFile);
     if ($requestFailed) {
         $data = array('is_processing' => 0, 'failed_date' => time(), 'fail_count' => $thumbnail['fail_count'] + 1);
         $thumbnail = array_merge($thumbnail, $data);
         $db->update('xf_thumbnail_proxy_waindigo', $data, 'thumbnail_id = ' . $db->quote($thumbnail['thumbnail_id']));
     }
     return $thumbnail;
 }
Exemple #13
0
 public function finalizeTranscode(array $queueRecord, $outputFile)
 {
     $db = XenForo_Application::getDb();
     XenForo_Db::beginTransaction($db);
     $db->delete('xengallery_transcode_queue', 'transcode_queue_id = ' . $db->quote($queueRecord['transcode_queue_id']));
     $queueData = $queueRecord['queue_data'];
     $media = $queueData['media'];
     /** @var XenGallery_Model_Transcode $transcodeModel */
     $transcodeModel = XenForo_Model::create('XenGallery_Model_Transcode');
     if (!file_exists($outputFile)) {
         // transcode failure
         $params = array('username' => $media['username'], 'title' => $media['media_title']);
         $this->_transcodeException($media, 'xengallery_video_by_x_named_y_failed_transcoding', $params);
     }
     $videoInfo = new XenGallery_VideoInfo_Preparer($outputFile);
     $result = $videoInfo->getInfo();
     /** @var XenForo_Model_Attachment $attachmentModel */
     $attachmentModel = XenForo_Model::create('XenForo_Model_Attachment');
     $attachment = $attachmentModel->getAttachmentById($queueData['attachmentId']);
     if (!$result->isValid() || $result->requiresTranscoding()) {
         $params = array('username' => $media['username'], 'title' => $media['media_title']);
         $this->_transcodeException($media, 'xengallery_video_by_x_named_y_failed_transcoding', $params);
     }
     clearstatcache();
     $fields = array('file_hash' => md5_file($outputFile), 'file_size' => filesize($outputFile));
     try {
         $dataDw = XenForo_DataWriter::create('XenForo_DataWriter_AttachmentData');
         $dataDw->setExistingData($attachment['data_id']);
         $dataDw->bulkSet($fields);
         $dataDw->save();
     } catch (XenForo_Exception $e) {
         $params = array('username' => $media['username'], 'title' => $media['media_title']);
         $this->_transcodeException($media, 'xengallery_video_by_x_named_y_failed_transcoding', $params);
     }
     /** @var XenGallery_Model_Media $mediaModel */
     $mediaModel = XenForo_Model::create('XenGallery_Model_Media');
     $data = $dataDw->getMergedData();
     $filePath = $attachmentModel->getAttachmentDataFilePath($data);
     $originalThumbPath = $mediaModel->getMediaThumbnailFilePath($attachment);
     $thumbPath = $mediaModel->getMediaThumbnailFilePath($data);
     XenForo_Helper_File::safeRename($originalThumbPath, $thumbPath);
     XenForo_Helper_File::safeRename($outputFile, $filePath);
     @unlink($queueData['filename']);
     $mediaDw = XenForo_DataWriter::create('XenGallery_DataWriter_Media', XenForo_DataWriter::ERROR_SILENT);
     $tagger = null;
     if (isset($queueData['tags']) && isset($queueData['tagger_permissions'])) {
         $tagModel = XenForo_Model::create('XenForo_Model_Tag');
         $tagger = $tagModel->getTagger('xengallery_media')->setPermissionsFromContext($queueData)->setTags($tagModel->splitTags($queueData['tags']));
     }
     if (!empty($queueData['customFields'])) {
         $mediaDw->setCustomFields($queueData['customFields'], $queueData['customFieldsShown']);
     }
     $mediaDw->bulkSet($media);
     if ($mediaDw->save()) {
         $mediaModel->markMediaViewed($mediaDw->getMergedData(), $media);
         if ($tagger) {
             $tagger->setContent($mediaDw->get('media_id'), true)->save();
         }
         $attachmentData = array('content_type' => 'xengallery_media', 'content_id' => $mediaDw->get('media_id'), 'temp_hash' => '', 'unassociated' => 0);
         $db->update('xf_attachment', $attachmentData, "attachment_id = {$attachment['attachment_id']}");
         $mediaDw->updateUserMediaQuota();
         $transcodeModel->sendTranscodeAlert($mediaDw->getMergedData(), true);
     } else {
         $params = array('username' => $media['username'], 'title' => $media['media_title']);
         $this->_transcodeException($media, 'xengallery_media_uploaded_by_x_named_y_failed_creation', $params);
     }
     XenForo_Db::commit($db);
     $this->_requeueDeferred();
 }
Exemple #14
0
 public function stepGroups($start, array $options)
 {
     $options = array_merge(array('limit' => 100, 'max' => false), $options);
     $model = $this->_importModel;
     $categories = $model->getImportContentMap('nobita_groups_category');
     if ($options['max'] === false) {
         $options['max'] = $this->_sourceDb->fetchOne('SELECT MAX(social_forum_id) FROM xf_social_forum');
     }
     $sDb = $this->_sourceDb;
     $groups = $sDb->fetchAll($sDb->limit('SELECT * FROM xf_social_forum WHERE social_forum_id > ' . $sDb->quote($start), $options['limit']));
     if (!$groups) {
         return true;
     }
     XenForo_Db::beginTransaction();
     $next = 0;
     $total = 0;
     foreach ($groups as $group) {
         $next = $group['social_forum_id'];
         $categoryId = isset($categories[$group['node_id']]) ? $categories[$group['node_id']] : null;
         if (!$categoryId) {
             // invalid category just go on
             continue;
         }
         $groupDw = XenForo_DataWriter::create($this->_teamDwName);
         $groupDw->bulkSet(array('title' => $group['title'], 'team_state' => $group['group_state'], 'tag_line' => $group['title'], 'custom_url' => $group['url_portion'], 'member_count' => $group['member_count'], 'team_date' => $group['created_date'], 'team_category_id' => $categoryId, 'team_avatar_date' => $group['logo_date'], 'user_id' => $group['user_id'], 'always_moderate_join' => $group['social_forum_moderated'] ? 1 : 0, 'privacy_state' => $group['social_forum_open'] ? 'open' : 'closed'));
         $groupDw->save();
         $groupId = $groupDw->get('team_id');
         if ($group['sticky']) {
             XenForo_Model::create('Nobita_Teams_Model_Team')->featureTeam($groupDw->getMergedData());
         }
         if ($group['logo_date']) {
             /* @var $socialModel Waindigo_SocialGroups_Model_SocialForumAvatar */
             $socialModel = XenForo_Model::create('Waindigo_SocialGroups_Model_SocialForumAvatar');
             $filePath = $socialModel->getAvatarFilePath($group['social_forum_id'], 'l', empty($this->_config['dir']['data']) ? null : $this->_config['dir']['data']);
             $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
             if (file_exists($filePath) && $newTempFile) {
                 file_put_contents($newTempFile, file_get_contents($filePath));
                 $groupAvatar = XenForo_Model::create('Nobita_Teams_Model_Avatar')->getAvatarFilePath($groupId);
                 $directory = dirname($groupAvatar);
                 if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
                     XenForo_Helper_File::safeRename($newTempFile, $groupAvatar);
                 }
             }
             @unlink($newTempFile);
         }
         $model->logImportData('nobita_groups_group', $group['social_forum_id'], $groupId);
         $total++;
     }
     XenForo_Db::commit();
     $this->_session->incrementStepImportTotal($total);
     return array($next, $options, $this->_getProgressOutput($next, $options['max']));
 }
Exemple #15
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;
 }