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')); } }
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; }
/** * 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; }
protected function _install_1() { $targetLoc = XenForo_Helper_File::getExternalDataPath() . "/sitemaps"; if (!is_dir($targetLoc)) { XenForo_Helper_File::createDirectory($targetLoc); XenForo_Helper_File::makeWritableByFtpUser($targetLoc); } }
/** * @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; }
/** * 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 static function filePutContents($path, $contents) { $dir = dirname($path); XenForo_Helper_File::createDirectory($dir, true); $lines = explode("\n", $contents); $linesTrimmed = array(); foreach ($lines as $line) { if (trim($line) == '') { $linesTrimmed[] = ''; } else { $linesTrimmed[] = $line; } } file_put_contents($path, implode("\n", $linesTrimmed)); XenForo_Helper_File::makeWritableByFtpUser($path); }
/** * @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(1, array("page" => 1, "perPage" => $options->dark_taigachat_fullperpage, "lastRefresh" => 0)); $messagesMini = $this->getMessages(1, array("page" => 1, "perPage" => $options->dark_taigachat_sidebarperpage, "lastRefresh" => 0)); $messageIds = $this->getMessageIds(1, array("page" => 1, "perPage" => $options->dark_taigachat_fullperpage, "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 = null; if ($options->dark_taigachat_sidebar) { $onlineUsersTaiga = $this->getActivityUserList($visitor->toArray()); } $viewParams = array('taigachat' => array("messages" => $messages, "sidebar" => false, "messageIds" => $messageIds, "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(); $dep->preloadTemplate('dark_taigachat_list'); $viewRenderer = new Dark_TaigaChat_ViewRenderer_JsonInternal($dep, new Zend_Controller_Response_Http(), new Zend_Controller_Request_Http()); if (!file_exists($this->getDataPath() . '/taigachat')) { XenForo_Helper_File::createDirectory($this->getDataPath() . '/taigachat', true); } $innerContent = $viewRenderer->renderView('Dark_TaigaChat_ViewPublic_TaigaChat_List', $viewParams, 'dark_taigachat_list'); $filename = $this->getDataPath() . '/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}.{$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; $innerContent = $viewRenderer->renderView('Dark_TaigaChat_ViewPublic_TaigaChat_List', $viewParams, 'dark_taigachat_list'); $filename = $this->getDataPath() . '/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 things back to how they was XenForo_Locale::setDefaultTimeZone($oldTimeZone); }
public static function makeWritableByFtpUser($file) { return XenForo_Helper_File::makeWritableByFtpUser($file); }
/** * 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) { if (is_uploaded_file($source)) { $success = move_uploaded_file($source, $destination); } else { $success = rename($source, $destination); } if ($success) { XenForo_Helper_File::makeWritableByFtpUser($destination); } return $success; }
public function save($filename) { XenForo_Helper_File::makeWritableByFtpUser(dirname($filename)); file_put_contents($filename, $this->_dom->saveXml()); }
/** * Writes out an image. * * @param integer $contentId * @param string $size Size code * @param string $tempFile Temporary image file. Will be moved. * * @return boolean */ protected function _writeImage($contentId, $size, $tempFile) { if (!in_array($size, array_keys(self::$_sizes))) { throw new XenForo_Exception('Invalid image size.'); } $filePath = $this->getImageFilePath($contentId, $size); $directory = dirname($filePath); if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) { if (file_exists($filePath)) { unlink($filePath); } $success = rename($tempFile, $filePath); if ($success) { XenForo_Helper_File::makeWritableByFtpUser($filePath); } return $success; } else { return false; } }
public function writeInstallLock() { $fileName = XenForo_Helper_File::getInternalDataPath() . '/install-lock.php'; $fp = fopen($fileName, 'w'); fwrite($fp, '<?php header(\'Location: ../index.php\'); /* Installed: ' . date(DATE_RFC822) . ' */'); fclose($fp); XenForo_Helper_File::makeWritableByFtpUser($fileName); }
private static function _updateAddOnFiles($addOnId, $tempFile) { $tempDir = $tempFile . '_extracted'; XenForo_Helper_File::createDirectory($tempDir, false); XenForo_Helper_File::makeWritableByFtpUser($tempDir); $decompress = new Zend_Filter_Decompress(array('adapter' => 'Zip', 'options' => array('target' => $tempDir))); if (!$decompress->filter($tempFile)) { throw new XenForo_Exception('Unable to extract add-on package.', true); } $uploadDir = sprintf('%s/upload', $tempDir); if (!is_dir($uploadDir)) { throw new XenForo_Exception('Unsupported add-on package (no "upload" directory found).', true); } $xfDir = dirname(XenForo_Autoloader::getInstance()->getRootDir()); $files = self::_verifyAddOnFiles($uploadDir, $xfDir); $xmlPath = self::_findXmlPath($addOnId, $tempDir, $xfDir, $files); self::_moveAddOnFiles($uploadDir, $xfDir, $files); return $xmlPath; }
/** * Performs a cross-stream/device safe rename by falling back * to a copy+delete if needed. * * @param string $source * @param string $destination * * @return bool */ public static function safeRename($source, $destination) { try { if (is_uploaded_file($source)) { $success = move_uploaded_file($source, $destination); } else { $success = rename($source, $destination); } } catch (Exception $e) { // possibly a perm problem, but may be an issue moving across streams, so copy+delete instead $success = false; } if (!$success) { $success = copy($source, $destination); if ($success) { @unlink($source); } } if ($success) { XenForo_Helper_File::makeWritableByFtpUser($destination); } return $success; }
public static function filePutContents($path, $contents) { $dir = dirname($path); XenForo_Helper_File::createDirectory($dir); if (!is_dir($dir) or !is_writable($dir)) { return false; } if (file_put_contents($path, $contents) > 0) { XenForo_Helper_File::makeWritableByFtpUser($path); return true; } return false; }
public function copyFile($source, $destination) { try { // if (is_uploaded_file($source)) // { // $success = move_uploaded_file($source, $destination); // } // else // { $success = copy($source, $destination); // } } catch (Exception $e) { $success = false; } if ($success) { XenForo_Helper_File::makeWritableByFtpUser($destination); } return $success; }
/** * @param $source * @param $destination * @return bool */ protected function _moveFile($source, $destination) { try { if (is_uploaded_file($source)) { $success = move_uploaded_file($source, $destination); } else { $success = rename($source, $destination); } } catch (Exception $e) { $success = false; } if (!$success) { $success = copy($source, $destination); if ($success) { @unlink($source); } } if ($success) { XenForo_Helper_File::makeWritableByFtpUser($destination); } return $success; }
protected function _createPhotoData($options, &$attachment, $data) { $photoDataModel = $this->_getPhotoDataModel(); $smallThumbFile = $photoDataModel->getContentDataSmallThumbnailFile($data); $mediumThumbFile = $photoDataModel->getContentDataMediumThumbnailFile($data); $largeThumbFile = $photoDataModel->getContentDataLargeThumbnailFile($data); $originalFile = $photoDataModel->getContentDataFile($data); if ($smallThumbFile) { $directory = dirname($smallThumbFile); if (XenForo_Helper_File::createDirectory($directory, true)) { $oldSmallFile = $photoDataModel->getContentDataSmallThumbnailFile($attachment, $options['path']); @copy($oldSmallFile, $smallThumbFile); XenForo_Helper_File::makeWritableByFtpUser($smallThumbFile); } } if ($mediumThumbFile) { $directory = dirname($mediumThumbFile); if (XenForo_Helper_File::createDirectory($directory, true)) { $oldMediumFile = $photoDataModel->getContentDataMediumThumbnailFile($attachment, $options['path']); @copy($oldMediumFile, $mediumThumbFile); XenForo_Helper_File::makeWritableByFtpUser($mediumThumbFile); } } if ($largeThumbFile) { $directory = dirname($largeThumbFile); if (XenForo_Helper_File::createDirectory($directory, true)) { $oldLargeFile = $photoDataModel->getContentDataLargeThumbnailFile($attachment, $options['path']); @copy($oldLargeFile, $largeThumbFile); XenForo_Helper_File::makeWritableByFtpUser($largeThumbFile); } } if ($originalFile) { $directory = dirname($originalFile); if (XenForo_Helper_File::createDirectory($directory, true)) { $oldOriginalFile = $photoDataModel->getContentDataFile($attachment, $options['path']); @copy($oldOriginalFile, $originalFile); XenForo_Helper_File::makeWritableByFtpUser($originalFile); } } return true; }
public function createPhotoThumbnails($filename, $data, $importToStore = false) { $xenOptions = XenForo_Application::getOptions(); $photoDataModel = $this->_getPhotoDataModel(); $extensionType = sonnb_XenGallery_Model_ContentData::$typeMap; $smallThumbFile = $photoDataModel->getContentDataSmallThumbnailFile($data); $mediumThumbFile = $photoDataModel->getContentDataMediumThumbnailFile($data); $largeThumbFile = $photoDataModel->getContentDataLargeThumbnailFile($data); $originalFile = $photoDataModel->getContentDataFile($data); if ($originalFile && !$xenOptions->sonnbXG_disableOriginal) { $directory = dirname($originalFile); if (XenForo_Helper_File::createDirectory($directory, true)) { @copy($filename, $originalFile); XenForo_Helper_File::makeWritableByFtpUser($originalFile); } } $photoDataModel->createContentDataThumbnailFile($filename, $largeThumbFile, $extensionType[$data['extension']], sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_LARGE); $photoDataModel->createContentDataThumbnailFile($largeThumbFile, $mediumThumbFile, $extensionType[$data['extension']], sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_MEDIUM); $photoDataModel->createContentDataThumbnailFile($largeThumbFile, $smallThumbFile, $extensionType[$data['extension']], sonnb_XenGallery_Model_ContentData::CONTENT_FILE_TYPE_SMALL); $db = $this->_getDb(); if ($importToStore !== false) { $useAttachmentStore = $xenOptions->sonnbXG_useBdStore; $engine = ''; if (XenForo_Application::isRegistered('addOns')) { $addOns = XenForo_Application::get('addOns'); } if (!class_exists('bdAttachmentStore_Option') || empty($addOns['bdAttachmentStore'])) { $useAttachmentStore = false; } if ($useAttachmentStore) { $fileModel = $this->_bdAttachmentStore_getFileModel(); $defaultEngine = $fileModel->getDefaultEngine(); if ($defaultEngine === bdAttachmentStore_Option::MODE_ATTACHMENT || $defaultEngine === bdAttachmentStore_Option::MODE_EXTERNAL_DATA) { $defaultEngine = ''; } if (!empty($defaultEngine)) { $engine = $defaultEngine; } } if (!empty($engine)) { $fileModel = $this->_bdAttachmentStore_getFileModel(); $storeOptions = $fileModel->getStorageOptions($engine); if (!isset($storeOptions['keepLocalCopy'])) { $storeOptions['keepLocalCopy'] = bdAttachmentStore_Option::get('keepLocalCopy'); } $smallThumbFileStore = $photoDataModel->getStoreContentDataSmallThumbnailFile($data); $mediumThumbFileStore = $photoDataModel->getStoreContentDataMediumThumbnailFile($data); $largeThumbFileStore = $photoDataModel->getStoreContentDataLargeThumbnailFile($data); $originalFileStore = $photoDataModel->getStoreContentDataFile($data); if (!$xenOptions->sonnbXG_disableOriginal) { $fileModel->saveFile($engine, $storeOptions, $originalFile, $originalFileStore, basename($originalFileStore)); } $fileModel->saveFile($engine, $storeOptions, $largeThumbFile, $largeThumbFileStore, basename($largeThumbFileStore)); $fileModel->saveFile($engine, $storeOptions, $mediumThumbFile, $mediumThumbFileStore, basename($mediumThumbFileStore)); $fileModel->saveFile($engine, $storeOptions, $smallThumbFile, $smallThumbFileStore, basename($smallThumbFileStore)); $db->update('sonnb_xengallery_content_data', array('bdattachmentstore_engine' => $engine, 'bdattachmentstore_options' => serialize($storeOptions)), array('content_data_id = ?' => $data['content_data_id'])); if (empty($storeOptions['keepLocalCopy'])) { @unlink($smallThumbFile); @unlink($mediumThumbFile); @unlink($largeThumbFile); @unlink($originalFile); } } } $db->update('sonnb_xengallery_content_data', array('unassociated' => 0), array('content_data_id = ?' => $data['content_data_id'])); }