mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-17 21:49:04 +01:00
Add Page::NUM_REGEX
and use it whenever possible
This commit is contained in:
parent
8d7287633c
commit
5c334c1cb3
@ -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) {
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user