protected function addFiles() { $controllers = $this->addChild('Controllers')->ulClass('level1')->liClass('type'); $templates = $this->addChild('Templates')->ulClass('level1')->liClass('type'); $moduleDirs = sfFinder::type('dir')->maxDepth(0)->in(sfConfig::get('sf_app_module_dir')); natcasesort($moduleDirs); foreach ($moduleDirs as $moduleDir) { if (count($found = sfFinder::type('file')->in($moduleDir . '/actions'))) { $moduleControllers = $controllers->addChild(basename($moduleDir))->ulClass('level2'); natcasesort($found); foreach ($found as $path) { $moduleControllers->addChild(basename($path), '#' . dmProject::unRootify($path)); } } if (count($found = sfFinder::type('file')->in($moduleDir . '/templates'))) { $moduleTemplates = $templates->addChild(basename($moduleDir))->ulClass('level2'); natcasesort($found); foreach ($found as $path) { $moduleTemplates->addChild(str_replace($moduleDir . '/templates/', '', $path), '#' . dmProject::unRootify($path)); } } } $stylesheets = $this->addChild('Stylesheets')->ulClass('level1')->liClass('type')->addChild($this->user->getTheme()->getName())->ulClass('level2'); $cssDir = $this->user->getTheme()->getFullPath('css'); $cssFiles = sfFinder::type('file')->name('*.css')->in($cssDir); natcasesort($cssFiles); foreach ($cssFiles as $cssFile) { if (dmProject::isInProject($cssFile)) { $stylesheets->addChild(str_replace($cssDir . '/', '', $cssFile), '#' . dmProject::unRootify($cssFile)); } } return $this; }
/** * Backup a file * return boolean success */ public function save($file) { if (!$this->isEnabled()) { return true; } if (!dmProject::isInProject($file)) { $file = dmOs::join(dmProject::getRootDir(), $file); } if (!is_readable($file)) { throw new dmException('Can no read ' . $file); } $relFile = dmProject::unRootify($file); $backupPath = dmOs::join($this->getDir(), dirname($relFile)); if (!$this->filesystem->mkdir($backupPath)) { throw new dmException('Can not create backup dir ' . $backupPath); } $backupFile = dmOs::join($backupPath, basename($relFile) . '.' . date('Y-m-d_H-i-s')); if (!$this->filesystem->touch($backupFile, 0777)) { throw new dmException('Can not copy ' . $file . ' to ' . $backupFile); } file_put_contents($backupFile, file_get_contents($file)); $this->filesystem->chmod($file, 0777); return true; }
protected function validatePath($path, $restrictedPaths, $verb = 'use') { if (!dmProject::isInProject($path)) { throw new dmCodeEditorException(sprintf('Can not %s %s because it is outside of the project', $verb, $path)); } $path = dmProject::unRootify($path); foreach ($restrictedPaths as $restrictedPath) { if (preg_match('#^' . $restrictedPath . '$#', $path)) { throw new dmCodeEditorException(sprintf('You are not allowed to %s %s', $verb, $path)); } } }
public function deleteDirContent($dir, $throwExceptions = false) { if (!dmProject::isInProject($dir)) { throw new dmException(sprintf('Try to delete %s, which is outside symfony project', $dir)); } $success = true; if (!($dh = @opendir($dir))) { if ($throwExceptions) { throw new dmException("Can not open {$dir} folder"); } else { $success = false; } } while (false !== ($obj = @readdir($dh))) { if ($obj == '.' || $obj == '..') { continue; } if (is_dir($dir . '/' . $obj)) { $success &= $this->deleteDir($dir . '/' . $obj, $throwExceptions); } else { if (!@unlink($dir . '/' . $obj)) { if ($throwExceptions) { throw new dmException("Can not delete file {$dir}/{$obj}"); } else { $success = false; } } } } @closedir($dh); return $success; }
public function deleteDirContent($dir, $throwExceptions = false) { if (!dmProject::isInProject($dir)) { throw new dmException(sprintf('Try to delete %s, which is outside symfony project', $dir)); } $files = sfFinder::type('file')->maxdepth(0)->in($dir); foreach ($files as $file) { $success = @unlink($file); } $dirs = sfFinder::type('dir')->maxdepth(0)->in($dir); foreach ($dirs as $dir) { $this->deleteDir($dir, $throwExceptions); } return true; }