Ejemplo n.º 1
0
 public function addAction($request)
 {
     $title = $request->getPost('name');
     $parent = $request->getPost('parent');
     if (empty($title)) {
         $this->sendErrorHeader($this->t('Name cannot be empty.'));
     }
     $filename = FilesystemHelper::sanitizeFilename($title);
     #$parent = FilesystemHelper::sanitizeFilename($parent);
     $parentRoute = $this->getPageTree()->findByRoute($parent);
     if ($parentRoute->isRoot()) {
         $filepath = $this->alias->get("@page/{$filename}.md");
     } else {
         $parentAlias = dirname($parentRoute->getMenuItem()->getPath());
         $filepath = $this->alias->get("{$parentAlias}/{$filename}.md");
     }
     if (is_file($filepath)) {
         $this->sendErrorHeader($this->t('A page with the same name already exists.'));
     }
     $eol = PHP_EOL;
     $pageTitle = $this->t('My new page');
     $data = "---{$eol}title: {$title}{$eol}disabled: 1{$eol}hidden: 1{$eol}---{$eol}{$pageTitle}{$eol}";
     if (!file_put_contents($filepath, $data)) {
         $this->sendErrorHeader($this->t('Page {name} can not be created.', ['{name}' => $title]));
     }
     if (!empty($parent)) {
         $request->setQuery('route', $parent);
     }
     return $this->indexAction($request);
 }
 protected function getCacheDirs()
 {
     $config = $this->config;
     $tempDirs = [['site/data/cache', $this->t('Data cache'), $config->get('cache.data.dir')], ['site/page/cache', $this->t('Page cache'), $config->get('cache.page.dir')], ['site/twig/cache', $this->t('Twig cache'), $config->get('twig.cache')], ['web/assets', $this->t('Web assets'), $this->alias->get('@web/assets')], ['web/cache', $this->t('Web cache'), $this->alias->get('@web/cache')]];
     $dirs = [];
     foreach ($tempDirs as $td) {
         list($key, $label, $path) = $td;
         if (!empty($path) && is_dir($path)) {
             $dirs[$key] = ['label' => $label, 'path' => $path, 'count' => FilesystemHelper::rcount($path)];
         }
     }
     return $dirs;
 }
Ejemplo n.º 3
0
 public function addAction($request)
 {
     $title = $request->getPost('name');
     if (empty($title)) {
         $this->sendErrorHeader($this->t('Name cannot be empty.'));
     }
     $filename = date('Y-m-d-') . FilesystemHelper::sanitizeFilename($title);
     $filepath = $this->alias->get("@post/{$filename}.md");
     if (is_file($filepath)) {
         $this->sendErrorHeader($this->t('A page with the same name already exists.'));
     }
     $eol = PHP_EOL;
     $pageTitle = $this->t('My new blog post');
     $data = "---{$eol}title: {$title}{$eol}disabled: 1{$eol}hidden: 1{$eol}---{$eol}{$pageTitle}{$eol}";
     if (!file_put_contents($filepath, $data)) {
         $this->sendErrorHeader($this->t('Page {name} can not be created.', ['{name}' => $title]));
     }
     return $this->indexAction();
 }