aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/event/md_exporter.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/event/md_exporter.php')
-rw-r--r--phpBB/phpbb/event/md_exporter.php38
1 files changed, 23 insertions, 15 deletions
diff --git a/phpBB/phpbb/event/md_exporter.php b/phpBB/phpbb/event/md_exporter.php
index e042d0a5d1..1a2d7c989e 100644
--- a/phpBB/phpbb/event/md_exporter.php
+++ b/phpBB/phpbb/event/md_exporter.php
@@ -87,7 +87,7 @@ class md_exporter
$this->validate_events_from_file($file_name, $this->crawl_file_for_events($file_name));
}
- return sizeof($this->events);
+ return count($this->events);
}
/**
@@ -113,7 +113,7 @@ class md_exporter
}
}
- return sizeof($this->events);
+ return count($this->events);
}
/**
@@ -143,6 +143,8 @@ class md_exporter
list($event_name, $details) = explode("\n===\n", $event, 2);
$this->validate_event_name($event_name);
+ $sorted_events = [$this->current_event, $event_name];
+ natsort($sorted_events);
$this->current_event = $event_name;
if (isset($this->events[$this->current_event]))
@@ -150,6 +152,12 @@ class md_exporter
throw new \LogicException("The event '{$this->current_event}' is defined multiple times");
}
+ // Use array_values() to get actual first element and check against natural order
+ if (array_values($sorted_events)[0] === $event_name)
+ {
+ throw new \LogicException("The event '{$sorted_events[1]}' should be defined before '{$sorted_events[0]}'");
+ }
+
if (($this->filter == 'adm' && strpos($this->current_event, 'acp_') !== 0)
|| ($this->filter == 'styles' && strpos($this->current_event, 'acp_') === 0))
{
@@ -219,7 +227,7 @@ class md_exporter
);
}
- return sizeof($this->events);
+ return count($this->events);
}
/**
@@ -381,9 +389,16 @@ class md_exporter
$files = explode("\n + ", $file_details);
foreach ($files as $file)
{
+ if (!preg_match('#^([^ ]+)( \([0-9]+\))?$#', $file))
+ {
+ throw new \LogicException("Invalid event instances for file '{$file}' found for event '{$this->current_event}'", 1);
+ }
+
+ list($file) = explode(" ", $file);
+
if (!file_exists($this->path . $file) || substr($file, -5) !== '.html')
{
- throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 1);
+ throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 2);
}
if (($this->filter !== 'adm') && strpos($file, 'styles/prosilver/template/') === 0)
@@ -396,7 +411,7 @@ class md_exporter
}
else
{
- throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 2);
+ throw new \LogicException("Invalid file '{$file}' not found for event '{$this->current_event}'", 3);
}
$this->events_by_file[$file][] = $this->current_event;
@@ -416,7 +431,7 @@ class md_exporter
}
else
{
- throw new \LogicException("Invalid file list found for event '{$this->current_event}'", 2);
+ throw new \LogicException("Invalid file list found for event '{$this->current_event}'", 1);
}
return $files_list;
@@ -439,16 +454,9 @@ class md_exporter
$event_list = array();
$file_content = file_get_contents($this->path . $file);
- $events = explode('<!-- EVENT ', $file_content);
- // Remove the code before the first event
- array_shift($events);
- foreach ($events as $event)
- {
- $event = explode(' -->', $event, 2);
- $event_list[] = array_shift($event);
- }
+ preg_match_all('/(?:{%|<!--) EVENT (.*) (?:%}|-->)/U', $file_content, $event_list);
- return $event_list;
+ return $event_list[1];
}
/**