diff --git a/admin/src/Controllers/Pages.php b/admin/src/Controllers/Pages.php index 8c73ddcd..e61a2ca3 100755 --- a/admin/src/Controllers/Pages.php +++ b/admin/src/Controllers/Pages.php @@ -246,7 +246,7 @@ class Pages extends AbstractController if (is_null($id)) { continue; } - $newId = preg_replace('/^(\d+)-/', $i + 1 . '-', $id); + $newId = preg_replace(Page::NUM_REGEX, $i + 1 . '-', $id); if ($newId != $id) { $this->changePageId($page, $newId); } @@ -380,7 +380,7 @@ class Pages extends AbstractController // Check if page number has to change if (!empty($page->date()) && $page->template()->scheme()->get('num') == 'date') { if ($page->num() != $page->date(self::DATE_NUM_FORMAT)) { - $newId = preg_replace('/^(\d+-)/', $page->date(self::DATE_NUM_FORMAT) . '-', $page->id()); + $newId = preg_replace(Page::NUM_REGEX, $page->date(self::DATE_NUM_FORMAT) . '-', $page->id()); try { $this->changePageId($page, $newId); } catch (RuntimeException $e) { diff --git a/formwork/Core/Page.php b/formwork/Core/Page.php index ad8067de..44231420 100755 --- a/formwork/Core/Page.php +++ b/formwork/Core/Page.php @@ -12,6 +12,7 @@ use Spyc; class Page extends AbstractPage { + const NUM_REGEX = '/^(\d+)-/'; const PAGE_STATUS_PUBLISHED = 'published'; const PAGE_STATUS_NOT_PUBLISHED = 'not-published'; const PAGE_STATUS_NOT_ROUTABLE = 'not-routable'; @@ -87,7 +88,7 @@ class Page extends AbstractPage public function num() { - preg_match('/^(\d+)-/', $this->id, $matches); + preg_match(self::NUM_REGEX, $this->id, $matches); return isset($matches[1]) ? $matches[1] : null; } @@ -238,7 +239,7 @@ class Page extends AbstractPage protected function processData() { - $this->data['visible'] = (bool) preg_match('/^\d+-[\w-]+$/', $this->id); + $this->data['visible'] = !is_null($this->num()); if ($this->published() && $this->has('publish-date')) { $this->data['published'] = (strtotime($this->get('publish-date')) < time()); diff --git a/formwork/Core/Site.php b/formwork/Core/Site.php index e5430878..ea5e9b1c 100755 --- a/formwork/Core/Site.php +++ b/formwork/Core/Site.php @@ -114,7 +114,7 @@ class Site extends AbstractPage foreach ($components as $component) { $found = false; foreach (FileSystem::listDirectories($path) as $dir) { - if (preg_replace('/^\d+-/', '', $dir) === $component) { + if (preg_replace(Page::NUM_REGEX, '', $dir) === $component) { $path = $path . $dir . DS; $found = true; break;