// save template
if ($page->pageType == 'tpl') {
if (!empty($this->parameters['content'])) {
+ $pageEditor = new PageEditor($page);
foreach ($this->parameters['content'] as $languageID => $content) {
- file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']);
+ $pageEditor->updateTemplate($languageID ?: null, $content['content']);
}
}
}
// save template
if ($page->pageType == 'tpl') {
foreach ($this->parameters['content'] as $languageID => $content) {
- file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']);
+ $page->updateTemplate($languageID ?: null, $content['content']);
}
}
*/
protected static $baseClass = Page::class;
+ /**
+ * Creates or updates the page's template file.
+ *
+ * @param integer $languageID language id or `null`
+ * @param string $content template content
+ */
+ public function updateTemplate($languageID, $content) {
+ if ($this->pageType !== 'tpl') {
+ throw new \RuntimeException("Only tpl-type pages support template files.");
+ }
+
+ file_put_contents(WCF_DIR . 'templates/' . $this->getTplName(($languageID ?: null)) . '.tpl', $content);
+ }
+
/**
* @inheritDoc
*/
// generate template if page's type is 'tpl'
$page = new Page($pageID);
if ($page->pageType == 'tpl') {
- file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']);
+ (new PageEditor($page))->updateTemplate($languageID, $content['content']);
}
}
}