setError(Text::get('missingTargetPageError')); } if (!$title) { return $Response->setError(Text::get('missingPageTitleError')); } if (!is_writable(dirname($Parent->getFile()))) { return $Response->setError(Text::get('permissionsDeniedError')); } Debug::log($Parent->url, 'parent page'); $themeTemplate = self::getTemplateNameFromPost(); $isPrivate = (bool) Request::post('private'); return $Response->setRedirect(Page::add($Parent, $title, $themeTemplate, $isPrivate)); } /** * Get a breadcrumb trail for a requested page. * * @return Response the response data */ public static function breadcrumbs(): Response { $Automad = Automad::fromCache(); $Response = new Response(); $url = Request::post('url'); $Page = $Automad->getPage($url); if ($Page) { $Selection = new Selection($Automad->getCollection()); $Selection->filterBreadcrumbs($url); $breadcrumbs = array(); foreach ($Selection->getSelection(false) as $Page) { $breadcrumbs[] = array( 'url' => $Page->origUrl, 'title' => $Page->get(Fields::TITLE) ); } $Response->setData($breadcrumbs); } return $Response; } /** * Send form when there is no posted data in the request or save data if there is. * * @return Response the response object */ public static function data(): Response { $Automad = Automad::fromCache(); $Response = new Response(); $url = Request::post('url'); $Page = $Automad->getPage($url); if (!$Page) { return $Response->setCode(404); } // If the posted form contains any "data", save the form's data to the page file. if ($data = Request::post('data')) { if (filemtime($Page->getFile()) > Request::post('dataFetchTime')) { return $Response->setError(Text::get('preventDataOverwritingError'))->setCode(403); } if (is_array($data)) { // Save page and replace $Response with the returned $Response object (error or redirect). return self::save( $Page, $url, $data, Request::post('slug') ); } } // If only the URL got submitted, just get the form ready. $ThemeCollection = new ThemeCollection(); $Theme = $ThemeCollection->getThemeByKey(strval($Page->get(Fields::THEME))); $keys = Fields::inCurrentTemplate($Page, $Theme); $data = DataFile::read($Page->path) ?? array(); $fields = array_merge( array_fill_keys(Fields::$reserved, ''), array_fill_keys($keys, ''), $data ); ksort($fields); return $Response->setData( array( 'url' => $Page->origUrl, 'slug' => basename($Page->path), 'template' => $Page->getTemplate(), 'fields' => $fields, 'shared' => $Automad->Shared->data, 'readme' => isset($Theme) ? $Theme->readme : '' ) ); } /** * Delete page. * * @return Response the response object */ public static function delete() { $Response = new Response(); $url = Request::post('url'); $Page = Page::fromCache($url); if ($url == '/') { return $Response; } if (!$Page) { return $Response->setError(Text::get('pageNotFoundError'))->setReload(true); } $pageFile = $Page->getFile(); if (!is_writable(dirname($pageFile)) || !is_writable(dirname(dirname($pageFile)))) { return $Response->setError(Text::get('permissionsDeniedError')); } $Page->delete(); $Response->setSuccess(Text::get('deteledSuccess') . ' ' . $Page->origUrl); $Response->setRedirect('page?url=' . urlencode($Page->parentUrl)); Debug::log($Page->url, 'deleted'); Cache::clear(); return $Response; } /** * Duplicate a page. * * @return Response the response object */ public static function duplicate(): Response { $Response = new Response(); $url = Request::post('url'); $Page = Page::fromCache($url); if ($url == '/') { return $Response; } if (!$Page) { return $Response->setError(Text::get('pageNotFoundError'))->setReload(true); } if (!is_writable(dirname(FileSystem::fullPagePath($Page->path)))) { return $Response->setError(Text::get('permissionsDeniedError')); } return $Response->setRedirect($Page->duplicate()); } /** * Move a page. * * @return Response the response object */ public static function move(): Response { $Automad = Automad::fromCache(); $Response = new Response(); $url = Request::post('url'); $dest = Request::post('targetPage'); $layout = Request::post('layout'); $Page = $Automad->getPage($url); $dest = $Automad->getPage($dest); if ($url === '/') { return $Response; } if (!$Page) { return $Response->setError(Text::get('pageNotFoundError'))->setReload(true); } if (!$dest) { return $Response->setError(Text::get('missingTargetPageError')); } if (!is_writable(FileSystem::fullPagePath($dest->path))) { return $Response->setError(Text::get('permissionsDeniedError')); } $pageFile = $Page->getFile(); if (!is_writable(dirname($pageFile)) || !is_writable(dirname(dirname($pageFile)))) { return $Response->setError(Text::get('permissionsDeniedError')); } if ($layout) { $layout = json_decode($layout); } else { $layout = null; } $newPagePath = $Page->moveDirAndUpdateLinks( $dest->path, basename($Page->path), $layout ); $Response->setRedirect(Page::dashboardUrlByPath($newPagePath)); Debug::log($Page->path, 'page'); Debug::log($dest->path, 'destination'); Cache::clear(); $Page = Page::findByPath($newPagePath); if ($Page) { $Response->setData(array('url' => $Page->origUrl)); } return $Response; } /** * Update the index of a page after reordering it in the nav tree. * * @return Response the response object */ public static function updateIndex(): Response { $Response = new Response(); $url = Request::post('url'); $Page = Page::fromCache($url); if (!$Page) { return $Response->setError(Text::get('pageNotFoundError'))->setReload(true); } $parentPath = Request::post('parentPath'); $layout = json_decode(Request::post('layout')); Cache::clear(); return $Response->setData( array( 'index' => PageIndex::write($parentPath, $layout), 'path' => $parentPath ) ); } /** * Get the theme/template file from posted data or return a default template name. * * @return string The template filename */ private static function getTemplateNameFromPost(): string { return $_POST['theme_template'] ?? Page::TEMPLATE_FILE_DEFAULT; } /** * Save a page. * * @param Page $Page * @param string $url * @param array $data * @param string $slug * @return Response the response object */ private static function save(Page $Page, string $url, array $data, string $slug): Response { $Response = new Response(); $pageFile = $Page->getFile(); if (!$data[Fields::TITLE]) { return $Response->setError(Text::get('missingPageTitleError')); } if ($url != '/' && !is_writable(dirname(dirname($pageFile)))) { return $Response->setError(Text::get('permissionsDeniedError')); } if (!is_writable($pageFile) || !is_writable(dirname($pageFile))) { return $Response->setError(Text::get('permissionsDeniedError')); } // The theme and the template get passed as theme/template.php combination separate // form $_POST['data']. That information has to be parsed first and "subdivided". $themeTemplate = self::getTemplateNameFromPost(); if ($result = $Page->save($url, $data, $themeTemplate, $slug)) { if (!empty($result['redirect'])) { return $Response->setRedirect($result['redirect']); } $Response->setData(array('update' => $result)); } return $Response; } } __halt_compiler();----SIGNATURE:----NtUj0msI2YvVeNEBoaMar6cjmXqSanj894R+Ntzgwg0Y6+ZQLKVetZv9ftbppZWWRgO3dXK/ruhFO1SQkIXfVWftkMk8E1eGzkc5ERamN+ZTAivstTWwQqV6F1lnqIBuQQs7zkK54PsgNa1FZMkntCKfItgMaFf/I6WV54hG/Rl0MYWEn238auwcF9pewEWKQlglMDA7AiLyhZQtV0WTVx5KO4odjCdEJRPsxzj/D/diSSevAafvjhXK4ETfMR6+5nYTcCzIDqGAMAV42YkGB/FeyC4YxB+pfsvJAGxi0Dm+P9c8nV17hUlAo8brHB6DQLO799+Rj/N7oNS+fgnUd0JBUSLd/45Vw+bMZsnoSMK7BOu8qT8MAkMCGAxRs5acYkYXuG6lxpGF+4dJYDlf5EpHA1Cpzg+1X3p0ov4AguD9caQSWYvRyZX6fzDFzqrYnJw3PYQgXbTJKv2m0zRq9ClSkCohE6hRW+1NYeK3Ybw70+Qi48Ryw8vtHW7j65NtF23BIf1bBgEPFTDTPtmQy3Kr73qghWHoHdoH5L5vyzciJtx90VDg2m2HKoIfQf6ZuZO/v7kGoAv+BJzkT+e9VbyrwtwP/SCQ5MK+koaAuX6rUEWmw75nellRmIyCXu0g6tlgL+uva9ep6I5ZbwStFtkIbcEwHB0cA5ut1kTrHns=----ATTACHMENT:----NTIxNDA2MDM3MjEwMTA4NCA2NjUwMjkxNjY5OTc1NDM2IDUyNjgxOTU2Nzg3NDc2Nzc=