本文整理汇总了PHP中XenForo_Helper_File::createDirectory方法的典型用法代码示例。如果您正苦于以下问题:PHP XenForo_Helper_File::createDirectory方法的具体用法?PHP XenForo_Helper_File::createDirectory怎么用?PHP XenForo_Helper_File::createDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XenForo_Helper_File
的用法示例。
在下文中一共展示了XenForo_Helper_File::createDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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');
}
示例3: _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;
}
示例4: 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' : '');
}
示例5: _install_1
protected function _install_1()
{
$targetLoc = XenForo_Helper_File::getExternalDataPath() . "/sitemaps";
if (!is_dir($targetLoc)) {
XenForo_Helper_File::createDirectory($targetLoc);
XenForo_Helper_File::makeWritableByFtpUser($targetLoc);
}
}
示例6: regeneratePublicHtml
/**
* @param mixed $overrideMotd set motd pre-cache-update
* @param mixed $unsync if not due to new message set true
*/
public function regeneratePublicHtml($overrideMotd = false, $unsync = false)
{
$viewParams = array();
$options = XenForo_Application::get('options');
$visitor = XenForo_Visitor::getInstance();
if ($options->dark_taigachat_speedmode == 'Disabled') {
return;
}
if ($unsync) {
/** @var XenForo_Model_DataRegistry */
$registryModel = $this->getModelFromCache('XenForo_Model_DataRegistry');
$lastUnsync = $registryModel->get('dark_taigachat_unsync');
if (!empty($lastUnsync) && $lastUnsync > time() - 30) {
return;
}
$registryModel->set('dark_taigachat_unsync', time());
}
// swap timezone to default temporarily
$oldTimeZone = XenForo_Locale::getDefaultTimeZone()->getName();
XenForo_Locale::setDefaultTimeZone($options->guestTimeZone);
$messages = $this->getMessages(array("page" => 1, "perPage" => $options->dark_taigachat_fullperpage, "lastRefresh" => 0));
$messagesMini = $this->getMessages(array("page" => 1, "perPage" => $options->dark_taigachat_sidebarperpage, "lastRefresh" => 0));
$bbCodeParser = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('Base'));
$motd = new XenForo_BbCode_TextWrapper($overrideMotd !== false ? $overrideMotd : $options->dark_taigachat_motd, $bbCodeParser);
$onlineUsersTaiga = $this->getActivityUserList($visitor->toArray());
$viewParams = array('taigachat' => array("messages" => $messages, "sidebar" => false, "editside" => $options->dark_taigachat_editside, "timedisplay" => $options->dark_taigachat_timedisplay, "miniavatar" => $options->dark_taigachat_miniavatar, "lastrefresh" => 0, "numInChat" => $this->getActivityUserCount(), "motd" => $motd, "online" => $onlineUsersTaiga, "route" => $options->dark_taigachat_route, "publichtml" => true, 'canView' => true, 'enabled' => true));
$dep = new Dark_TaigaChat_Dependencies();
$dep->preLoadData();
$viewRenderer = new Dark_TaigaChat_ViewRenderer_JsonInternal($dep, new Zend_Controller_Response_Http(), new Zend_Controller_Request_Http());
if (!file_exists(XenForo_Helper_File::getExternalDataPath() . '/taigachat')) {
XenForo_Helper_File::createDirectory(XenForo_Helper_File::getExternalDataPath() . '/taigachat', true);
}
$innerContent = $viewRenderer->renderView('Dark_TaigaChat_ViewPublic_TaigaChat_List', $viewParams, 'dark_taigachat_list');
$filename = XenForo_Helper_File::getExternalDataPath() . '/taigachat/messages.html';
$yayForNoLocking = mt_rand(0, 10000000);
if (file_put_contents($filename . ".{$yayForNoLocking}.tmp", $innerContent, LOCK_EX) === false) {
throw new XenForo_Exception("Failed writing TaigaChat messages to {$filename}.tmp.{$yayForNoLocking}.tmp");
}
if (!@rename($filename . ".{$yayForNoLocking}.tmp", $filename)) {
@unlink($filename . ".{$yayForNoLocking}.tmp");
}
XenForo_Helper_File::makeWritableByFtpUser($filename);
$viewParams['taigachat']['messages'] = $messagesMini;
$viewParams['taigachat']['sidebar'] = true;
//$viewParams['taigachat']['online'] = null;
$innerContent = $viewRenderer->renderView('Dark_TaigaChat_ViewPublic_TaigaChat_List', $viewParams, 'dark_taigachat_list');
$filename = XenForo_Helper_File::getExternalDataPath() . '/taigachat/messagesmini.html';
if (file_put_contents($filename . ".{$yayForNoLocking}.tmp", $innerContent, LOCK_EX) === false) {
throw new XenForo_Exception("Failed writing TaigaChat messages to {$filename}.{$yayForNoLocking}.tmp");
}
// The only reason this could fail is if the file is being hammered, hence no worries ignoring failure
if (!@rename($filename . ".{$yayForNoLocking}.tmp", $filename)) {
@unlink($filename . ".{$yayForNoLocking}.tmp");
}
XenForo_Helper_File::makeWritableByFtpUser($filename);
// put timezone back to how it was
XenForo_Locale::setDefaultTimeZone($oldTimeZone);
}
示例7: DevHelper_saveTemplate
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;
}
示例8: _createTemplateDirectory
protected function _createTemplateDirectory()
{
if (!is_dir($this->_path)) {
if (XenForo_Helper_File::createDirectory($this->_path)) {
return XenForo_Helper_File::makeWritableByFtpUser($this->_path);
} else {
return false;
}
}
return true;
}
示例9: execute
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;
}
示例10: stream_open
public function stream_open($path, $mode, $options, &$opened_path)
{
$filePath = self::getTempFile($path);
self::$_metadata[$path] = array('length' => 0, 'image' => null, 'start' => microtime(true));
$fileDir = dirname($filePath);
if (!XenForo_Helper_File::createDirectory($fileDir, true)) {
return false;
}
$this->_path = $path;
$this->_resource = fopen($filePath, $mode, false);
return (bool) $this->_resource;
}
示例11: _writeIcon
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;
}
}
示例12: actionXenGallerySave
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)));
}
示例13: createDirectory
public static function createDirectory($path, $createIndexHtml = false)
{
$created = XenForo_Helper_File::createDirectory($path, $createIndexHtml);
// XenForo won't create a directory in the root, manually do it here
if (!$created) {
$path = preg_replace('#/+$#', '', $path);
$path = str_replace('\\', '/', $path);
$parts = explode('/', $path);
$checkOnRoot = implode('/', array_slice($parts, 0, count($parts) - 1));
if (XenForo_Application::getInstance()->getRootDir() == $checkOnRoot) {
if (!file_exists($path)) {
if (mkdir($path)) {
$created = true;
}
}
}
}
return $created;
}
示例14: constructPaths
public function constructPaths($inputsXDS)
{
$libraryPath = XenForo_Application::getInstance()->getRootDir() . '/library';
$addon = $inputsXDS['title'];
if (!empty($inputsXDS['folders_cp_name']) or !empty($inputsXDS['folders_ca_name']) or !empty($inputsXDS['folders_model_name']) or !empty($inputsXDS['folders_dw_name']) or !empty($inputsXDS['folders_install_name']) or !empty($inputsXDS['xds_prefix_public_folder_name']) or !empty($inputsXDS['xds_prefix_public_file_name']) or !empty($inputsXDS['xds_prefix_admin_folder_name']) or !empty($inputsXDS['xds_prefix_admin_file_name']) or !empty($inputsXDS['xds_prefix_admin_file_name'])) {
//main folder
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}");
//ControllerAdmin Folder
if (!empty($inputsXDS['folders_ca_name'])) {
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_ca_name'] . "");
}
//ControllerPublic Folder
if (!empty($inputsXDS['folders_cp_name'])) {
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_cp_name'] . "");
}
//Model Folder
if (!empty($inputsXDS['folders_model_name'])) {
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_model_name'] . "");
}
//DataWriter Folder
if (!empty($inputsXDS['folders_dw_name'])) {
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_dw_name'] . "");
}
//Install Folder
if (!empty($inputsXDS['folders_install_name'])) {
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/" . $inputsXDS['folders_install_name'] . "");
}
//Prefix Folders
if (!empty($inputsXDS['xds_prefix_public_folder_name']) or !empty($inputsXDS['xds_prefix_admin_folder_name'])) {
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/Route");
if (!empty($inputsXDS['xds_prefix_public_folder_name'])) {
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/Route/" . $inputsXDS['xds_prefix_public_folder_name'] . "");
}
if (!empty($inputsXDS['xds_prefix_admin_folder_name'])) {
XenForo_Helper_File::createDirectory("{$libraryPath}/{$addon}/Route/" . $inputsXDS['xds_prefix_admin_folder_name'] . "");
}
}
}
//Data Folder
if (!empty($inputsXDS['xds_input_data_name'])) {
XenForo_Helper_File::createDirectory(XenForo_Application::getInstance()->getRootDir() . '/data/' . $inputsXDS['xds_input_data_name'] . '');
}
}
示例15: _writeAttachmentFile
/**
* Writes out the specified attachment file. The temporary file
* will be moved to the new position!
*
* @param string $tempFile Temporary (source file)
* @param array $data Information about this attachment data (for dest path)
* @param boolean $thumbnail True if writing out thumbnail.
*
* @return boolean
*/
protected function _writeAttachmentFile($tempFile, array $data, $thumbnail = false)
{
if ($this->getExtraData(self::DATA_XMG_DATA)) {
if ($tempFile && is_readable($tempFile)) {
/** @var $mediaModel XenGallery_Model_Media */
$mediaModel = $this->getModelFromCache('XenGallery_Model_Media');
if ($thumbnail) {
$filePath = $mediaModel->getMediaThumbnailFilePath($data);
} else {
$filePath = $this->_getAttachmentModel()->getAttachmentDataFilePath($data);
}
$directory = dirname($filePath);
if (XenForo_Helper_File::createDirectory($directory, true)) {
$success = $this->_copyFile($tempFile, $filePath);
if ($success) {
return parent::_writeAttachmentFile($tempFile, $data, $thumbnail);
}
return false;
}
}
}
return parent::_writeAttachmentFile($tempFile, $data, $thumbnail);
}