public static function updateConfig($key, $value) { /** @var XenForo_Application $app */ $app = XenForo_Application::getInstance(); $path = $app->getRootDir() . '/library/config.php'; $originalContents = file_get_contents($path); $varNamePattern = '#(\\n|^)(?<varName>\\$config'; foreach (explode('.', $key) as $i => $keyPart) { // try to match the quote $varNamePattern .= '\\[([\'"]?)' . preg_quote($keyPart, '#') . '\\' . ($i + 3) . '\\]'; } $varNamePattern .= ').+(\\n|$)#'; $candidates = array(); $offset = 0; while (true) { if (!preg_match($varNamePattern, $originalContents, $matches, PREG_OFFSET_CAPTURE, $offset)) { break; } $offset = $matches[0][1] + strlen($matches[0][0]); $candidates[] = $matches; } if (count($candidates) !== 1) { XenForo_Helper_File::log(__METHOD__, sprintf('count($candidates) = %d', count($candidates))); return; } $matches = reset($candidates); $replacement = $matches[1][0] . $matches['varName'][0] . ' = ' . var_export($value, true) . ';' . $matches[5][0]; $contents = substr_replace($originalContents, $replacement, $matches[0][1], strlen($matches[0][0])); DevHelper_Generator_File::writeFile($path, $contents, true, false); }
protected function _createFiles(sonnb_XenGallery_Model_ContentData $model, $filePath, $contentData, $useTemp = true, $isVideo = false) { $smallThumbFile = $model->getContentDataSmallThumbnailFile($contentData); $mediumThumbFile = $model->getContentDataMediumThumbnailFile($contentData); $largeThumbFile = $model->getContentDataLargeThumbnailFile($contentData); $originalFile = $model->getContentDataFile($contentData); if ($useTemp) { $filename = tempnam(XenForo_Helper_File::getTempDir(), 'xf'); @copy($filePath, $filename); } else { $filename = $filePath; } if ($isVideo === false && $originalFile) { $directory = dirname($originalFile); if (XenForo_Helper_File::createDirectory($directory, true)) { @copy($filename, $originalFile); XenForo_Helper_File::makeWritableByFtpUser($originalFile); } else { return false; } } if ($isVideo === false) { $ext = sonnb_XenGallery_Model_ContentData::$typeMap[$contentData['extension']]; } else { $ext = sonnb_XenGallery_Model_ContentData::$typeMap[sonnb_XenGallery_Model_VideoData::$videoEmbedExtension]; } $model->createContentDataThumbnailFile($filename, $largeThumbFile, $ext, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_LARGE); $model->createContentDataThumbnailFile($largeThumbFile, $mediumThumbFile, $ext, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_MEDIUM); $model->createContentDataThumbnailFile($largeThumbFile, $smallThumbFile, $ext, sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_SMALL); @unlink($filename); return true; }
public function actionIndex() { $attachmentId = $this->_input->filterSingle('attachment_id', XenForo_Input::UINT); $cache = XenForo_Application::getCache(); $imageTypes = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png'); if ($cache) { $attachment = unserialize($cache->load('attachment_cache_' . md5($attachmentId))); if (!$attachment) { $attachment = $this->_getAttachmentOrError($attachmentId); $extension = XenForo_Helper_File::getFileExtension($attachment['filename']); if (isset($imageTypes[$extension])) { $cache->save(serialize($attachment), 'attachment_cache_' . md5($attachmentId), array(), 3600); } } } else { $attachment = $this->_getAttachmentOrError($attachmentId); } $extension = XenForo_Helper_File::getFileExtension($attachment['filename']); if (!in_array($extension, array_keys($imageTypes))) { return parent::actionIndex(); } $attachmentModel = $this->_getAttachmentModel(); $filePath = $attachmentModel->getAttachmentDataFilePath($attachment); if (!file_exists($filePath) || !is_readable($filePath)) { return $this->responseError(new XenForo_Phrase('attachment_cannot_be_shown_at_this_time')); } $this->canonicalizeRequestUrl(XenForo_Link::buildPublicLink('attachments', $attachment)); $eTag = $this->_request->getServer('HTTP_IF_NONE_MATCH'); $this->_routeMatch->setResponseType('raw'); if ($eTag && $eTag == $attachment['attach_date']) { return $this->responseView('XenForo_ViewPublic_Attachment_View304'); } $viewParams = array('attachment' => $attachment, 'attachmentFile' => $filePath); return $this->responseView('XenForo_ViewPublic_Attachment_View', '', $viewParams); }
public function renderRaw() { $url = $this->_params['url']; $width = $this->_params['width']; $height = $this->_params['height']; $crop = $this->_params['crop']; $extension = XenForo_Helper_File::getFileExtension($url); $imageInfo = @getimagesize($url); if (!$imageInfo || !in_array($imageInfo[2], array_values(sonnb_XenGallery_Model_PhotoData::$typeMap)) || !in_array(strtolower($extension), array_keys(sonnb_XenGallery_Model_PhotoData::$imageMimes))) { $url = XenForo_Template_Helper_Core::getAvatarUrl(array(), 'l'); $extension = XenForo_Helper_File::getFileExtension($url); $imageInfo = @getimagesize($url); } $this->_response->setHeader('Content-type', sonnb_XenGallery_Model_PhotoData::$imageMimes[$extension], true); $this->_response->setHeader('ETag', XenForo_Application::$time, true); $this->_response->setHeader('X-Content-Type-Options', 'nosniff'); $this->setDownloadFileName($url, true); $image = XenForo_Image_Abstract::createFromFile($url, sonnb_XenGallery_Model_PhotoData::$typeMap[$extension]); if ($image) { if (XenForo_Image_Abstract::canResize($width, $height)) { if ($crop) { $image->thumbnail($width * 2, $height * 2); $image->crop(0, 0, $width, $height); } else { $image->thumbnail($width, $height); } } else { $image->output(sonnb_XenGallery_Model_PhotoData::$typeMap[$extension]); } } }
public function renderRaw() { $attachment = $this->_params['attachment']; if (!headers_sent() && function_exists('header_remove')) { header_remove('Expires'); header('Cache-control: private'); } $extension = XenForo_Helper_File::getFileExtension($attachment['filename']); $imageTypes = array('svg' => 'image/svg+xml', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png'); if (isset($imageTypes[$extension]) && ($attachment['width'] && $attachment['height'])) { $this->_response->setHeader('Content-type', $imageTypes[$extension], true); $this->setDownloadFileName($attachment['filename'], true); } else { $this->_response->setHeader('Content-type', 'application/octet-stream', true); $this->setDownloadFileName($attachment['filename']); } $this->_response->setHeader('ETag', '"' . $attachment['attach_date'] . '"', true); $this->_response->setHeader('Content-Length', $attachment['file_size'], true); $this->_response->setHeader('X-Content-Type-Options', 'nosniff'); $attachmentFile = $this->_params['attachmentFile']; $options = XenForo_Application::getOptions(); if ($options->SV_AttachImpro_XAR) { if (SV_AttachmentImprovements_AttachmentHelper::ConvertFilename($attachmentFile)) { if (XenForo_Application::debugMode() && $options->SV_AttachImpro_log) { XenForo_Error::debug('X-Accel-Redirect:' . $attachmentFile); } $this->_response->setHeader('X-Accel-Redirect', $attachmentFile); return ''; } if (XenForo_Application::debugMode() && $options->SV_AttachImpro_log) { XenForo_Error::debug('X-Accel-Redirect skipped'); } } return new XenForo_FileOutput($attachmentFile); }
/** * Exports an add-on's XML data. * * @return XenForo_ControllerResponse_Abstract */ public function actionZip() { $addOnId = $this->_input->filterSingle('addon_id', XenForo_Input::STRING); $addOn = $this->_getAddOnOrError($addOnId); $rootDir = XenForo_Application::getInstance()->getRootDir(); $zipPath = XenForo_Helper_File::getTempDir() . '/addon-' . $addOnId . '.zip'; if (file_exists($zipPath)) { unlink($zipPath); } $zip = new ZipArchive(); $res = $zip->open($zipPath, ZipArchive::CREATE); if ($res === TRUE) { $zip->addFromString('addon-' . $addOnId . '.xml', $this->_getAddOnModel()->getAddOnXml($addOn)->saveXml()); if (is_dir($rootDir . '/library/' . $addOnId)) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir . '/library/' . $addOnId)); foreach ($iterator as $key => $value) { $zip->addFile(realpath($key), str_replace($rootDir . '/', '', $key)); } } if (is_dir($rootDir . '/js/' . strtolower($addOnId))) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($rootDir . '/js/' . strtolower($addOnId))); foreach ($iterator as $key => $value) { $zip->addFile(realpath($key), str_replace($rootDir . '/', '', $key)); } } $zip->close(); } if (!file_exists($zipPath) || !is_readable($zipPath)) { return $this->responseError(new XenForo_Phrase('devkit_error_while_creating_zip')); } $this->_routeMatch->setResponseType('raw'); $attachment = array('filename' => 'addon-' . $addOnId . '_' . $addOn['version_string'] . '.zip', 'file_size' => filesize($zipPath), 'attach_date' => XenForo_Application::$time); $viewParams = array('attachment' => $attachment, 'attachmentFile' => $zipPath); return $this->responseView('XenForo_ViewAdmin_Attachment_View', '', $viewParams); }
public function actionConfig() { $config = $this->_input->filterSingle('config', XenForo_Input::JSON_ARRAY); if ($this->_request->isPost()) { $db = $this->_testConfig($config, $error); if ($error) { return $this->responseError($error); } $configFile = XenForo_Application::getInstance()->getConfigDir() . '/config.php'; if (!file_exists($configFile) && is_writable(dirname($configFile))) { try { file_put_contents($configFile, $this->_getInstallModel()->generateConfig($config)); XenForo_Helper_File::makeWritableByFtpUser($configFile); $written = true; } catch (Exception $e) { $written = false; } } else { $written = false; } $viewParams = array('written' => $written, 'configFile' => $configFile, 'config' => $config); return $this->_getInstallWrapper(1, $this->responseView('XenForo_Install_View_Install_ConfigGenerated', 'install_config_generated', $viewParams)); } else { return $this->_getInstallWrapper(1, $this->responseView('XenForo_Install_View_Install_Config', 'install_config')); } }
/** * Is used to copy an entire directory recursively. * * @param $source * @param $target * @param bool $createIndexHtml * @throws GFNCore_Exception */ public static function copy($source, $target, $createIndexHtml = false) { if (!is_dir($source)) { throw new GFNCore_Exception('Source directory does not exist.'); } if (!is_dir($target)) { XenForo_Helper_File::createDirectory($target, $createIndexHtml); } $handle = opendir($source); if (!$handle) { return; } while (($file = readdir($handle)) !== false) { if (in_array($file, array('.', '..'))) { continue; } $from = $source . '/' . $file; $to = $target . '/' . $file; if (is_dir($from)) { self::copy($from, $to); } else { copy($from, $to); } } closedir($handle); }
/** * 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'); }
public function deleteThumb($mediaID) { $targetLoc = XenForo_Helper_File::getExternalDataPath() . '/media/' . $mediaID . '.jpg'; if (file_exists($targetLoc)) { unlink($targetLoc); } }
public function getSitemapFileName($setId, $counter, $compressed = false) { $path = XenForo_Helper_File::getInternalDataPath() . '/sitemaps'; if (!XenForo_Helper_File::createDirectory($path, true)) { throw new XenForo_Exception("Sitemap directory {$path} could not be created"); } return "{$path}/sitemap-{$setId}-{$counter}.xml" . ($compressed ? '.gz' : ''); }
public static function get_attach_file_name($attachmentFilename) { if ($attachmentFilename) { $extension = XenForo_Helper_File::getFileExtension($attachmentFilename); return str_replace($extension, '', $attachmentFilename); } return ''; }
/** * Copies the specified file. * * @param string $source * @param string $destination * * @return boolean */ protected function _copyFile($source, $destination) { $success = copy($source, $destination); if ($success) { XenForo_Helper_File::makeWritableByFtpUser($destination); } return $success; }
/** * @see XenForo_Template_FileHandler::save */ protected function _saveTemplate($title, $styleId, $languageId, $template) { $this->_createTemplateDirectory(); $fileName = $this->_getFileName($title, $styleId, $languageId); file_put_contents($fileName, $template); XenForo_Helper_File::makeWritableByFtpUser($fileName); $this->_postTemplateChange($fileName, 'write'); return $fileName; }
protected static function _applyIcon($node, $upload, $number, $size, $nodeType) { 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); } $outputFiles = array(); $fileName = $upload->getTempFile(); $imageType = $upload->getImageInfoField('type'); $outputType = $imageType; $width = $upload->getImageInfoField('width'); $height = $upload->getImageInfoField('height'); $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xfa'); $image = XenForo_Image_Abstract::createFromFile($fileName, $imageType); if (!$image) { continue; } if ($size > 0) { $image->thumbnailFixedShorterSide($size); if ($image->getOrientation() != XenForo_Image_Abstract::ORIENTATION_SQUARE) { $x = floor(($image->getWidth() - $size) / 2); $y = floor(($image->getHeight() - $size) / 2); $image->crop($x, $y, $size, $size); } } $image->output($outputType, $newTempFile, self::$imageQuality); unset($image); $icons = $newTempFile; switch ($nodeType) { case 'forum': $dw = XenForo_DataWriter::create('XenForo_DataWriter_Forum'); $dwData = array('brcns_pixel_' . $number => $size, 'brcns_icon_date_' . $number => XenForo_Application::$time, 'brcns_select' => 'file'); break; case 'page': $dw = XenForo_DataWriter::create('XenForo_DataWriter_Page'); $dwData = array('brcns_pixel' => $size, 'brcns_icon_date' => XenForo_Application::$time, 'brcns_select' => 'file'); break; case 'link': $dw = XenForo_DataWriter::create('XenForo_DataWriter_LinkForum'); $dwData = array('brcns_pixel' => $size, 'brcns_icon_date' => XenForo_Application::$time, 'brcns_select' => 'file'); break; case 'category': $dw = XenForo_DataWriter::create('XenForo_DataWriter_Category'); $dwData = array('brcns_pixel' => $size, 'brcns_icon_date' => XenForo_Application::$time, 'brcns_select' => 'file'); break; } $dw->setExistingData($node['node_id']); $dw->bulkSet($dwData); $dw->save(); return $icons; }
public function actionIndex() { $file = XenForo_Helper_File::getExternalDataPath() . '/sitemaps/index.xml'; if (!file_exists($file)) { $this->getModelFromCache('EWRutiles_Sitemap_Model_Sitemap')->buildIndex(); } echo file_get_contents($file); exit; }
public function DevHelper_saveTemplate() { if (DevHelper_Helper_Template::autoExportImport() == false) { return false; } $template = $this->getMergedData(); $filePath = DevHelper_Helper_Template::getTemplateFilePath($template); XenForo_Helper_File::createDirectory(dirname($filePath)); return file_put_contents($filePath, $template['template']) > 0; }
protected function _uninstall_0() { $targetLoc = glob(XenForo_Helper_File::getExternalDataPath() . "/sitemaps/*.xml*"); foreach ($targetLoc as $file) { unlink($file); } $targetLoc = XenForo_Helper_File::getExternalDataPath() . "/sitemaps"; if (is_dir($targetLoc)) { rmdir($targetLoc); } }
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; }
protected function _createAddonFile() { $contents = str_replace('/>', '>', file_get_contents($this->_path . '/build-files/addon.xml')); $dir = new DirectoryIterator($this->_path . '/build-files'); foreach ($dir as $file) { if ($file->isDot() or $file->isDir() or XenForo_Helper_File::getFileExtension($file->getFilename()) != 'xml' or $file->getFilename() == 'addon.xml') { continue; } $contents .= str_replace('<?xml version="1.0" encoding="utf-8"?>' . "\n", '', file_get_contents($file->getPathname())); } return $contents . '</addon>'; }
public function renderRaw() { $extension = XenForo_Helper_File::getFileExtension($this->_params['thumbnailPath']); $imageTypes = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png'); $this->_response->setHeader('Content-type', $imageTypes[$extension], true); $this->setDownloadFileName($this->_params['thumbnailPath'], true); $this->_response->setHeader('X-Content-Type-Options', 'nosniff'); if (!is_readable($this->_params['thumbnailPath']) || !file_exists($this->_params['thumbnailPath'])) { $this->_params['thumbnailPath'] = XenGallery_Template_Helper_Core::helperDummyImage('visible', '', '', true); } return new XenForo_FileOutput($this->_params['thumbnailPath']); }
public function renderRaw() { $parent = parent::renderRaw(); $attachment = $this->_params['attachment']; $extension = XenForo_Helper_File::getFileExtension($attachment['filename']); $imageTypes = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png'); if (in_array($extension, array_keys($imageTypes))) { $this->_response->setHeader('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime('+30 days')), true); $this->_response->setHeader('Last-Modified', gmdate('D, d M Y H:i:s \\G\\M\\T', $attachment['attach_date']), true); $this->_response->setHeader('Cache-Control', 'public, max-age=2592000', true); } return $parent; }
public static function deleteAllCached() { foreach (self::$_cached as $url => $tempFile) { if (XenForo_Application::debugMode()) { $fileSize = @filesize($tempFile); } $deleted = @unlink($tempFile); if (XenForo_Application::debugMode()) { XenForo_Helper_File::log(__CLASS__, call_user_func_array('sprintf', array('delete %s -> %s, %s, %d bytes', $url, $tempFile, $deleted ? 'succeeded' : 'failed', !empty($fileSize) ? $fileSize : 0))); } } self::$_cached = array(); }
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))); }
/** * * @see XenResource_Model_Resource::applyResourceIcon() * */ public function applyResourceIcon($resourceId, $fileName, $imageType = false, $width = false, $height = false) { if (!$imageType || !$width || !$height) { $imageInfo = getimagesize($fileName); if (!$imageInfo) { return parent::applyResourceIcon($resourceId, $fileName, $imageType, $width, $height); } $width = $imageInfo[0]; $height = $imageInfo[1]; $imageType = $imageInfo[2]; } if (!in_array($imageType, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) { return parent::applyResourceIcon($resourceId, $fileName, $imageType, $width, $height); } if (!XenForo_Image_Abstract::canResize($width, $height)) { return parent::applyResourceIcon($resourceId, $fileName, $imageType, $width, $height); } $imageQuality = self::$iconQuality; $outputType = $imageType; $image = XenForo_Image_Abstract::createFromFile($fileName, $imageType); if (!$image) { return false; } $maxDimensions = max(array($image->getWidth(), $image->getHeight())); if ($image->getOrientation() != XenForo_Image_Abstract::ORIENTATION_SQUARE) { $x = floor(($maxDimensions - $image->getWidth()) / 2); $y = floor(($maxDimensions - $image->getHeight()) / 2); $image->resizeCanvas($x, $y, $maxDimensions, $maxDimensions); } $newTempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf'); if (!$newTempFile) { return false; } $image->output($outputType, $newTempFile, $imageQuality); unset($image); $returnValue = parent::applyResourceIcon($resourceId, $newTempFile, $imageType, $width, $height); if ($returnValue) { $filePath = $this->getResourceIconFilePath($resourceId); $image = XenForo_Image_Abstract::createFromFile($filePath, $imageType); if (!$image) { return false; } $width = XenForo_Application::get('options')->th_resourceIcons_width; $height = XenForo_Application::get('options')->th_resourceIcons_height; $x = floor(($width - $image->getWidth()) / 2); $y = floor(($height - $image->getHeight()) / 2); $image->resizeCanvas($x, $y, $width, $height); $image->output($outputType, $filePath, $imageQuality); unset($image); } }
public function actionAddOnsServerFile() { $q = $this->_input->filterSingle('q', XenForo_Input::STRING); $paths = array(); /** @var XenForo_Application $app */ $app = XenForo_Application::getInstance(); $libraryPath = sprintf('%s/library', $app->getRootDir()); $library = 'library'; $libraryLength = min(strlen($library), strlen($q)); if (strlen($q) > 0 && strpos($q, '.') === false && substr($q, 0, $libraryLength) === substr($library, 0, $libraryLength)) { if (strlen($q) < 7) { $q = 'library/'; $paths[] = 'library'; } $parts = explode('/', $q); array_shift($parts); $prefix = ''; if (count($parts) > 0) { $prefix = array_pop($parts); } $path = rtrim(sprintf('%s/%s', $libraryPath, implode('/', $parts)), '/'); if (is_dir($path)) { $contents = scandir($path); foreach ($contents as $content) { if (substr($content, 0, 1) === '.') { continue; } if ($prefix !== '' && substr($content, 0, strlen($prefix)) !== $prefix) { continue; } $contentPath = sprintf('%s/%s', $path, $content); if (is_dir($contentPath)) { $paths[] = $contentPath; } else { $ext = XenForo_Helper_File::getFileExtension($contentPath); if ($ext === 'xml') { array_unshift($paths, $contentPath); } } } } } $results = array(); foreach ($paths as $path) { $relativePath = preg_replace('#^' . preg_quote($app->getRootDir()) . '/#', '', $path); $results[$relativePath] = basename($path); } $view = $this->responseView(); $view->jsonParams = array('results' => $results); return $view; }
/** * Recursively creates directories until the full path is created. * * @param string $path Directory path to create * @param boolean $createIndexHtml If true, creates an index.html file in the created directory * * @return boolean True on success */ public static function createDirectory($path, $createIndexHtml = false) { $path = preg_replace('#/+$#', '', $path); if (file_exists($path) && is_dir($path)) { return true; } $path = str_replace('\\', '/', $path); $parts = explode('/', $path); $pathPartCount = count($parts); $partialPath = ''; $rootDir = XenForo_Application::getInstance()->getRootDir(); // find the "lowest" part that exists (and is a dir)... for ($i = $pathPartCount - 1; $i >= 0; $i--) { $partialPath = implode('/', array_slice($parts, 0, $i + 1)); if ($partialPath == $rootDir) { return false; // can't go above the root dir } if (file_exists($partialPath)) { if (!is_dir($partialPath)) { return false; } else { break; } } } if ($i < 0) { return false; } $i++; // skip over the last entry (as it exists) // ... now create directories for anything below it for (; $i < $pathPartCount; $i++) { $partialPath .= '/' . $parts[$i]; if (!mkdir($partialPath)) { return false; } else { if ($createIndexHtml) { XenForo_Helper_File::makeWritableByFtpUser($partialPath); $fp = @fopen($partialPath . '/index.html', 'w'); if ($fp) { fwrite($fp, ' '); fclose($fp); XenForo_Helper_File::makeWritableByFtpUser($partialPath . '/index.html'); } } } } return true; }
public function getAttachmentsForXenGalleryByAttachmentIds($attachmentIds) { $db = $this->_getDb(); $attachments = $this->fetchAllKeyed("\n\t\t\t\tSELECT attachment.*, attachment_data.*, post.username, post.user_id\n\t\t\t\tFROM xf_attachment AS attachment\n\t\t\t\t\tLEFT JOIN xf_attachment_data AS attachment_data\n\t\t\t\t\t\tON (attachment.data_id = attachment_data.data_id)\n\t\t\t\t\tLEFT JOIN xf_post AS post\n\t\t\t\t\t\tON (attachment.content_id = post.post_id)\n\t\t\t\tWHERE attachment.attachment_id IN (" . $db->quote($attachmentIds) . ")\n\t\t\t\t\tAND attachment.content_type = 'post'\n\t\t\t\t\tAND post.message_state = 'visible'\n\t\t\t\tORDER BY attachment.attachment_id ASC", 'attachment_id'); if ($attachments) { foreach ($attachments as $attachId => $attachment) { $extension = XenForo_Helper_File::getFileExtension($attachment['filename']); if (!in_array($extension, array('gif', 'png', 'jpg', 'jpeg', 'jpe'))) { unset($attachments[$attachId]); } } } return $attachments; }
public static function getTemplateIdFromFilePath($filePath) { $basename = basename($filePath); $extension = XenForo_Helper_File::getFileExtension($basename); if (!in_array($extension, array('html', 'css'))) { return 0; } $sanExtension = substr($basename, 0, -1 * (strlen($extension) + 1)); $parts = explode('_', $sanExtension); $lastPart = array_pop($parts); if (!is_numeric($lastPart)) { return 0; } return intval($lastPart); }
public function renderRaw() { $attachment = $this->_params['attachment']; $extension = XenForo_Helper_File::getFileExtension($attachment['filename']); $imageTypes = array('gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png'); if (in_array($extension, array_keys($imageTypes))) { $this->_response->setHeader('Content-type', $imageTypes[$extension], true); $this->setDownloadFileName($attachment['filename'], true); } else { $this->_response->setHeader('Content-type', 'unknown/unknown', true); $this->setDownloadFileName($attachment['filename']); } $this->_response->setHeader('ETag', $attachment['attach_date'], true); $this->_response->setHeader('Content-Length', $attachment['file_size'], true); return new XenForo_FileOutput($this->_params['attachmentFile']); }