public function prepareFileContent($rawContent, array $meta) { // remove meta header $metaHeaderPattern = "/^(\\/(\\*)|---)[[:blank:]]*(?:\r)?\n" . "(?:(.*?)(?:\r)?\n)?(?(2)\\*\\/|---)[[:blank:]]*(?:(?:\r)?\n|\$)/s"; $content = preg_replace($metaHeaderPattern, '', $rawContent, 1); // replace %site_title% $content = str_replace('%site_title%', $this->getConfig('site_title'), $content); // replace %base_url% if ($this->isUrlRewritingEnabled()) { // always use `%base_url%?sub/page` syntax for internal links // we'll replace the links accordingly, depending on enabled rewriting $content = str_replace('%base_url%?', $this->getBaseUrl(), $content); } else { // actually not necessary, but makes the URL look a little nicer $content = str_replace('%base_url%?', $this->getBaseUrl() . '?', $content); } $content = str_replace('%base_url%', rtrim($this->getBaseUrl(), '/'), $content); // replace %theme_url% $themeUrl = $this->getBaseUrl() . basename($this->getThemesDir()) . '/' . $this->getConfig('theme'); $content = str_replace('%theme_url%', $themeUrl, $content); // replace %meta.*% if (!empty($meta)) { $metaKeys = $metaValues = array(); foreach ($meta as $metaKey => $metaValue) { if (is_scalar($metaValue) || $metaValue === null) { $metaKeys[] = '%meta.' . $metaKey . '%'; $metaValues[] = strval($metaValue); } } $content = str_replace($metaKeys, $metaValues, $content); } return $content; }