public function appendPage($page) { $parent = $page->parentFileName; $originalData = $this->getPagesConfig(); $structure = $originalData['static-pages']; if (!strlen($parent)) { $structure[$page->getBaseFileName()] = []; } else { $iterator = function (&$configPages) use(&$iterator, $parent, $page) { foreach ($configPages as $fileName => &$subpages) { if ($fileName == $parent) { $subpages[$page->getBaseFileName()] = []; return true; } if ($iterator($subpages) == true) { return true; } } }; $iterator($structure); } $this->updateStructure($structure); }
/** * Saves the object to the disk. */ public function save() { $isNewFile = !strlen($this->fileName); /* * Generate a file name basing on the URL */ if ($isNewFile) { $dir = rtrim(static::getFilePath($this->theme, ''), '/'); $fileName = trim(str_replace('/', '-', $this->getViewBag()->property('url')), '-'); if (strlen($fileName) > 200) { $fileName = substr($fileName, 0, 200); } if (!strlen($fileName)) { $fileName = 'index'; } $curName = trim($fileName) . '.htm'; $counter = 2; while (File::exists($dir . '/' . $curName)) { $curName = $fileName . '-' . $counter . '.htm'; $counter++; } $this->fileName = $curName; } parent::save(); if ($isNewFile) { $pageList = new PageList($this->theme); $pageList->appendPage($this); } }