本文整理汇总了PHP中IOHelper::folderExists方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::folderExists方法的具体用法?PHP IOHelper::folderExists怎么用?PHP IOHelper::folderExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOHelper
的用法示例。
在下文中一共展示了IOHelper::folderExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rollBackFileChanges
/**
* @param $manifestData
* @param $handle
*
* @return null
*/
public static function rollBackFileChanges($manifestData, $handle)
{
foreach ($manifestData as $row) {
if (static::isManifestVersionInfoLine($row)) {
continue;
}
if (static::isManifestMigrationLine($row)) {
continue;
}
$rowData = explode(';', $row);
if ($handle == 'craft') {
$directory = craft()->path->getAppPath();
} else {
$directory = craft()->path->getPluginsPath() . $handle . '/';
}
$file = IOHelper::normalizePathSeparators($directory . $rowData[0]);
// It's a folder
if (static::isManifestLineAFolder($file)) {
$folderPath = static::cleanManifestFolderLine($file);
if (IOHelper::folderExists($folderPath . '.bak')) {
IOHelper::rename($folderPath, $folderPath . '-tmp');
IOHelper::rename($folderPath . '.bak', $folderPath);
IOHelper::clearFolder($folderPath . '-tmp');
IOHelper::deleteFolder($folderPath . '-tmp');
}
} else {
if (IOHelper::fileExists($file . '.bak')) {
IOHelper::rename($file . '.bak', $file);
}
}
}
}
示例2: includeCustomCpResources
/**
* Includes resources for the Control Panel from the craft/config/diywidget/ folder.
*/
protected function includeCustomCpResources()
{
$templatePaths = [];
$folderPath = craft()->path->getConfigPath() . 'diywidget/';
if (IOHelper::folderExists($folderPath)) {
$filePaths = glob($folderPath . '*.{twig,html,css,js}', GLOB_BRACE);
foreach ($filePaths as $filePath) {
$pathInFolder = str_replace($folderPath, '', $filePath);
$resourcePath = 'config/diywidget/' . $pathInFolder;
switch (IOHelper::getExtension($filePath)) {
case 'twig':
case 'html':
$templatePaths[] = $pathInFolder;
break;
case 'css':
craft()->templates->includeCssResource($resourcePath);
break;
case 'js':
craft()->templates->includeJsResource($resourcePath);
break;
}
}
}
craft()->diyWidget->templatePaths = $templatePaths;
}
示例3: init
/**
* Initializes the console app by creating the command runner.
*
* @return null
*/
public function init()
{
// Set default timezone to UTC
date_default_timezone_set('UTC');
// Import all the built-in components
foreach ($this->componentAliases as $alias) {
Craft::import($alias);
}
// Attach our Craft app behavior.
$this->attachBehavior('AppBehavior', new AppBehavior());
// Initialize Cache and LogRouter right away (order is important)
$this->getComponent('cache');
$this->getComponent('log');
// So we can try to translate Yii framework strings
$this->coreMessages->attachEventHandler('onMissingTranslation', array('Craft\\LocalizationHelper', 'findMissingTranslation'));
// Set our own custom runtime path.
$this->setRuntimePath(craft()->path->getRuntimePath());
// Attach our own custom Logger
Craft::setLogger(new Logger());
// No need for these.
craft()->log->removeRoute('WebLogRoute');
craft()->log->removeRoute('ProfileLogRoute');
// Load the plugins
craft()->plugins->loadPlugins();
// Validate some basics on the database configuration file.
craft()->validateDbConfigFile();
// Call parent::init before the plugin console command logic so craft()->commandRunner will be available to us.
parent::init();
foreach (craft()->plugins->getPlugins() as $plugin) {
$commandsPath = craft()->path->getPluginsPath() . StringHelper::toLowerCase($plugin->getClassHandle()) . '/consolecommands/';
if (IOHelper::folderExists($commandsPath)) {
craft()->commandRunner->addCommands(rtrim($commandsPath, '/'));
}
}
}
示例4: getInputHtml
public function getInputHtml($name, $value)
{
// Get site templates path
$templatesPath = $siteTemplatesPath = craft()->path->getSiteTemplatesPath();
// Check if the templates path is overriden by configuration
// TODO: Normalize path
$limitToSubfolder = craft()->config->get('templateselectSubfolder');
if ($limitToSubfolder) {
$templatesPath = $templatesPath . rtrim($limitToSubfolder, '/') . '/';
}
// Check if folder exists, or give error
if (!IOHelper::folderExists($templatesPath)) {
throw new \InvalidArgumentException('(Template Select) Folder doesn\'t exist: ' . $templatesPath);
}
// Get folder contents
$templates = IOHelper::getFolderContents($templatesPath, TRUE);
// Add placeholder for when there is no template selected
$filteredTemplates = array('' => Craft::t('No template selected'));
// Turn array into ArrayObject
$templates = new \ArrayObject($templates);
// Iterate over template list
// * Remove full path
// * Remove folders from list
for ($list = $templates->getIterator(); $list->valid(); $list->next()) {
$filename = $list->current();
$filename = str_replace($templatesPath, '', $filename);
$filenameIncludingSubfolder = $limitToSubfolder ? $limitToSubfolder . $filename : $filename;
$isTemplate = preg_match("/(.html|.twig)\$/u", $filename);
if ($isTemplate) {
$filteredTemplates[$filenameIncludingSubfolder] = $filename;
}
}
// Render field
return craft()->templates->render('_includes/forms/select', array('name' => $name, 'value' => $value, 'options' => $filteredTemplates));
}
示例5: addResources
protected function addResources()
{
// Get current language and site translations path
$language = craft()->language;
$path = craft()->path->getSiteTranslationsPath();
// Look for translation file from least to most specific. For example, nl.php gets loaded before nl_nl.php.
$translationFiles = array();
$parts = explode('_', $language);
$totalParts = count($parts);
// If it's Norwegian Bokmål/Nynorsk, add plain ol' Norwegian as a fallback
if ($parts[0] === 'nb' || $parts[0] === 'nn') {
$translationFiles[] = 'no';
}
for ($i = 1; $i <= $totalParts; $i++) {
$translationFiles[] = implode('_', array_slice($parts, 0, $i));
}
// Get translations
$translations = array();
if (IOHelper::folderExists($path)) {
foreach ($translationFiles as $file) {
$path = $path . $file . '.php';
if (IOHelper::fileExists($path)) {
$temp = (include $path);
if (is_array($temp)) {
// If this is framework data and we're not on en_us, then do some special processing.
if (strpos($path, 'framework/i18n/data') !== false && $file !== 'en_us') {
$temp = $this->_processFrameworkData($file);
}
$translations = array_merge($translations, $temp);
}
}
}
}
if (empty($translations)) {
return false;
}
craft()->templates->includeJs('(function(window){
if (window.Craft) {
Craft.translations = $.extend(Craft.translations, ' . json_encode($translations) . ');
var selectors = [
"#page-title h1", // Page titles
"#crumbs a", // Segments in breadcrumbs
".fld-field > span", // Field names inside FLD
".fld-tab .tab > span", // Tab names inside FLD
"#sidebar .heading > span", // CEI heading
"#Assets option", // Options inside Asset field settings
],
$el;
$(selectors.join(",")).each(function () {
$el = $(this);
$el.text(Craft.t($el.text()));
});
}
}(window));');
}
示例6: downloadUpdate
/**
* @param $downloadPath
* @return bool
*/
public function downloadUpdate($downloadPath)
{
$et = new Et(static::DownloadUpdate, 240);
if (IOHelper::folderExists($downloadPath)) {
$downloadPath .= StringHelper::UUID() . '.zip';
}
$et->setDestinationFileName($downloadPath);
if (($fileName = $et->phoneHome()) !== null) {
return $fileName;
}
return false;
}
示例7: getSettingsHtml
/**
* Returns the field's settings HTML.
*
* @return string|null
*/
public function getSettingsHtml()
{
$configOptions = array('' => Craft::t('Default'));
$configPath = craft()->path->getConfigPath() . 'redactor/';
if (IOHelper::folderExists($configPath)) {
$configFiles = IOHelper::getFolderContents($configPath, false, '\\.json$');
if (is_array($configFiles)) {
foreach ($configFiles as $file) {
$configOptions[IOHelper::getFileName($file)] = IOHelper::getFileName($file, false);
}
}
}
return craft()->templates->render('_components/fieldtypes/RichText/settings', array('settings' => $this->getSettings(), 'configOptions' => $configOptions));
}
示例8: downloadUpdate
/**
* @param string $downloadPath
* @param string $md5
*
* @return bool
*/
public function downloadUpdate($downloadPath, $md5)
{
if (IOHelper::folderExists($downloadPath)) {
$downloadPath .= $md5 . '.zip';
}
$updateModel = craft()->updates->getUpdates();
$buildVersion = $updateModel->app->latestVersion . '.' . $updateModel->app->latestBuild;
$path = 'http://download.buildwithcraft.com/craft/' . $updateModel->app->latestVersion . '/' . $buildVersion . '/Patch/' . $updateModel->app->localBuild . '/' . $md5 . '.zip';
$et = new Et($path, 240);
$et->setDestinationFileName($downloadPath);
if (($fileName = $et->phoneHome()) !== null) {
return $fileName;
}
return false;
}
示例9: getSettingsHtml
/**
* @inheritDoc ISavableComponentType::getSettingsHtml()
*
* @return string|null
*/
public function getSettingsHtml()
{
$configOptions = array('' => Craft::t('Default'));
$configPath = craft()->path->getConfigPath() . 'redactor/';
if (IOHelper::folderExists($configPath)) {
$configFiles = IOHelper::getFolderContents($configPath, false, '\\.json$');
if (is_array($configFiles)) {
foreach ($configFiles as $file) {
$configOptions[IOHelper::getFileName($file)] = IOHelper::getFileName($file, false);
}
}
}
$columns = array('text' => Craft::t('Text (stores about 64K)'), 'mediumtext' => Craft::t('MediumText (stores about 4GB)'));
return craft()->templates->render('_components/fieldtypes/RichText/settings', array('settings' => $this->getSettings(), 'configOptions' => $configOptions, 'columns' => $columns, 'existing' => !empty($this->model->id)));
}
示例10: onAfterInstall
/**
* When installed, this plugin converts RichText fields into BetterRedactor
* fields. It also creates a folder, craft/config/redactor_plugins, and
* populates it with some starting plugins.
*/
public function onAfterInstall()
{
craft()->db->createCommand()->update('fields', array('type' => 'BetterRedactor'), array('type' => 'RichText'));
$config_folder = craft()->path->getConfigPath() . '/redactor_plugins';
if (!IOHelper::folderExists($config_folder)) {
$initial_folder = craft()->path->getPluginsPath() . '/betterredactor/redactor_plugins';
$files = array_filter(scandir($initial_folder), function ($file) use($initial_folder) {
return is_file("{$initial_folder}/{$file}");
});
foreach ($files as $file) {
if (preg_match('((.js|.css)$)i', $file)) {
IOHelper::copyFile("{$initial_folder}/{$file}", "{$config_folder}/{$file}");
}
}
}
}
示例11: beforeAction
/**
* @param string $action
* @param array $params
* @return bool
*/
public function beforeAction($action, $params)
{
if ($action == 'create') {
// If the 1nd dimension is the 1nd index, then we know it's a plugin. No need to make them specify the path.
if (isset($params[0][1])) {
$plugin = $params[0][1];
$path = craft()->path->getMigrationsPath($plugin);
if (!IOHelper::folderExists($path)) {
echo 'The migration folder does not exist at ' . $path . ". Creating...\n";
if (!IOHelper::createFolder($path)) {
echo 'Sorry... I tried to create the folder, but could not.';
return 1;
} else {
echo 'Successfully created.';
}
}
}
}
$yiiVersion = Craft::getYiiVersion();
echo "\nCraft Migration Tool (based on Yii v{$yiiVersion})\n\n";
return true;
}
示例12: actionLogs
public function actionLogs()
{
craft()->config->maxPowerCaptain();
if (IOHelper::folderExists(craft()->path->getLogPath())) {
$dateTimePattern = '/^[0-9]{4}\\/[0-9]{2}\\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/';
$logEntries = array();
$currentLogFileName = 'feedme.log';
$currentFullPath = craft()->path->getLogPath() . $currentLogFileName;
if (IOHelper::fileExists($currentFullPath)) {
// Split the log file's contents up into arrays of individual logs, where each item is an array of
// the lines of that log.
$contents = IOHelper::getFileContents(craft()->path->getLogPath() . $currentLogFileName);
$requests = explode('******************************************************************************************************', $contents);
foreach ($requests as $request) {
$logChunks = preg_split('/^(\\d{4}\\/\\d{2}\\/\\d{2} \\d{2}:\\d{2}:\\d{2}) \\[(.*?)\\] \\[(.*?)\\] /m', $request, null, PREG_SPLIT_DELIM_CAPTURE);
// Ignore the first chunk
array_shift($logChunks);
// Loop through them
$totalChunks = count($logChunks);
for ($i = 0; $i < $totalChunks; $i += 4) {
$logEntryModel = new LogEntryModel();
$logEntryModel->dateTime = DateTime::createFromFormat('Y/m/d H:i:s', $logChunks[$i]);
$logEntryModel->level = $logChunks[$i + 1];
$logEntryModel->category = $logChunks[$i + 2];
$message = $logChunks[$i + 3];
$rowContents = explode("\n", $message);
// This is a non-devMode log entry.
$logEntryModel->message = str_replace('[Forced]', '', $rowContents[0]);
// And save the log entry.
$logEntries[] = $logEntryModel;
}
}
}
// Put these logs at the top
$logEntries = array_reverse($logEntries);
$this->renderTemplate('feedme/logs/index', array('logEntries' => $logEntries));
}
}
示例13: getSettingsHtml
/**
* @inheritDoc ISavableComponentType::getSettingsHtml()
*
* @return string|null
*/
public function getSettingsHtml()
{
$configOptions = array('' => Craft::t('Default'));
$configPath = craft()->path->getConfigPath() . 'redactor/';
if (IOHelper::folderExists($configPath)) {
$configFiles = IOHelper::getFolderContents($configPath, false, '\\.json$');
if (is_array($configFiles)) {
foreach ($configFiles as $file) {
$configOptions[IOHelper::getFileName($file)] = IOHelper::getFileName($file, false);
}
}
}
$columns = array('text' => Craft::t('Text (stores about 64K)'), 'mediumtext' => Craft::t('MediumText (stores about 4GB)'));
$sourceOptions = array();
foreach (craft()->assetSources->getPublicSources() as $source) {
$sourceOptions[] = array('label' => $source->name, 'value' => $source->id);
}
$transformOptions = array();
foreach (craft()->assetTransforms->getAllTransforms() as $transform) {
$transformOptions[] = array('label' => $transform->name, 'value' => $transform->id);
}
return craft()->templates->render('redactori/settings', array('settings' => $this->getSettings(), 'configOptions' => $configOptions, 'assetSourceOptions' => $sourceOptions, 'transformOptions' => $transformOptions, 'columns' => $columns, 'existing' => !empty($this->model->id)));
}
示例14: add
/**
* @inheritDoc IZip::add()
*
* @param string $sourceZip
* @param string $pathToAdd
* @param string $basePath
* @param null $pathPrefix
*
* @return bool
*/
public function add($sourceZip, $pathToAdd, $basePath, $pathPrefix = null)
{
$zip = new \ZipArchive();
$zipContents = $zip->open($sourceZip);
if ($zipContents !== true) {
Craft::log('Unable to open zip file: ' . $sourceZip, LogLevel::Error);
return false;
}
if (IOHelper::fileExists($pathToAdd)) {
$folderContents = array($pathToAdd);
} else {
$folderContents = IOHelper::getFolderContents($pathToAdd, true);
}
foreach ($folderContents as $itemToZip) {
if (IOHelper::isReadable($itemToZip)) {
// Figure out the relative path we'll be adding to the zip.
$relFilePath = mb_substr($itemToZip, mb_strlen($basePath));
if ($pathPrefix) {
$pathPrefix = IOHelper::normalizePathSeparators($pathPrefix);
$relFilePath = $pathPrefix . $relFilePath;
}
if (IOHelper::folderExists($itemToZip)) {
if (IOHelper::isFolderEmpty($itemToZip)) {
$zip->addEmptyDir($relFilePath);
}
} elseif (IOHelper::fileExists($itemToZip)) {
// We can't use $zip->addFile() here but it's a terrible, horrible, POS method that's buggy on Windows.
$fileContents = IOHelper::getFileContents($itemToZip);
if (!$zip->addFromString($relFilePath, $fileContents)) {
Craft::log('There was an error adding the file ' . $itemToZip . ' to the zip: ' . $itemToZip, LogLevel::Error);
}
}
}
}
$zip->close();
return true;
}
示例15: add
/**
* Will add either a file or a folder to an existing zip file. If it is a folder, it will add the contents recursively.
*
* @param string $sourceZip The zip file to be added to.
* @param string $pathToAdd A file or a folder to add. If it is a folder, it will recursively add the contents of the folder to the zip.
* @param string $basePath The root path of the file(s) to be added that will be removed before adding.
* @param string $pathPrefix A path to be prepended to each file before it is added to the zip.
* @return bool
*/
public function add($sourceZip, $pathToAdd, $basePath, $pathPrefix = null)
{
$zip = new \PclZip($sourceZip);
if (IOHelper::fileExists($pathToAdd)) {
$folderContents = array($pathToAdd);
} else {
$folderContents = IOHelper::getFolderContents($pathToAdd, true);
}
$filesToAdd = array();
foreach ($folderContents as $itemToZip) {
if (IOHelper::isReadable($itemToZip)) {
if (IOHelper::folderExists($itemToZip) && IOHelper::isFolderEmpty($itemToZip) || IOHelper::fileExists($itemToZip)) {
$filesToAdd[] = $itemToZip;
}
}
}
if (!$pathPrefix) {
$pathPrefix = '';
}
$result = $zip->add($filesToAdd, PCLZIP_OPT_ADD_PATH, $pathPrefix, PCLZIP_OPT_REMOVE_PATH, $basePath);
if ($result == 0) {
Craft::log('Unable to add to zip file: ' . $sourceZip, LogLevel::Error);
return false;
}
return true;
}