当前位置: 首页>>代码示例>>PHP>>正文


PHP XenForo_Helper_File类代码示例

本文整理汇总了PHP中XenForo_Helper_File的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Helper_File类的具体用法?PHP XenForo_Helper_File怎么用?PHP XenForo_Helper_File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了XenForo_Helper_File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateConfig

 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);
 }
开发者ID:maitandat1507,项目名称:DevHelper,代码行数:30,代码来源:XenForoConfig.php

示例2: _createFiles

 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;
 }
开发者ID:Sywooch,项目名称:forums,代码行数:32,代码来源:Abstract.php

示例3: actionIndex

 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);
 }
开发者ID:Sywooch,项目名称:forums,代码行数:35,代码来源:Attachment.php

示例4: renderRaw

 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]);
         }
     }
 }
开发者ID:Sywooch,项目名称:forums,代码行数:31,代码来源:Thumbnail.php

示例5: renderRaw

 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);
 }
开发者ID:Xon,项目名称:XenForo-AttachmentImprovements,代码行数:35,代码来源:View.php

示例6: actionZip

 /**
  * 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);
 }
开发者ID:Sywooch,项目名称:forums,代码行数:40,代码来源:AddOn.php

示例7: actionConfig

 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'));
     }
 }
开发者ID:Sywooch,项目名称:forums,代码行数:26,代码来源:Install.php

示例8: copy

 /**
  * 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);
 }
开发者ID:Sywooch,项目名称:forums,代码行数:34,代码来源:Directory.php

示例9: saveThumbnail

 /**
  * 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');
 }
开发者ID:VoDongMy,项目名称:xenforo-laravel5.1,代码行数:31,代码来源:Abstract.php

示例10: deleteThumb

 public function deleteThumb($mediaID)
 {
     $targetLoc = XenForo_Helper_File::getExternalDataPath() . '/media/' . $mediaID . '.jpg';
     if (file_exists($targetLoc)) {
         unlink($targetLoc);
     }
 }
开发者ID:Sywooch,项目名称:forums,代码行数:7,代码来源:Thumbs.php

示例11: getSitemapFileName

 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' : '');
 }
开发者ID:VoDongMy,项目名称:xenforo-laravel5.1,代码行数:8,代码来源:Sitemap.php

示例12: get_attach_file_name

 public static function get_attach_file_name($attachmentFilename)
 {
     if ($attachmentFilename) {
         $extension = XenForo_Helper_File::getFileExtension($attachmentFilename);
         return str_replace($extension, '', $attachmentFilename);
     }
     return '';
 }
开发者ID:Sywooch,项目名称:forums,代码行数:8,代码来源:Listener.php

示例13: _copyFile

 /**
  * 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;
 }
开发者ID:VoDongMy,项目名称:xenforo-laravel5.1,代码行数:16,代码来源:AttachmentData.php

示例14: _saveTemplate

 /**
  * @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;
 }
开发者ID:namgiangle90,项目名称:tokyobaito,代码行数:12,代码来源:FileHandler.php

示例15: _applyIcon

 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;
 }
开发者ID:darkearl,项目名称:projectT122015,代码行数:57,代码来源:Icon.php


注:本文中的XenForo_Helper_File类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。