';
$templateDom = new DOMDocument();
- @$templateDom->loadHTML($templateHtml, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
+ // Wrap the template HTML in a single root element to ensure proper parsing
+ @$templateDom->loadHTML('
' . $templateHtml . '
', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
+
+ // Remove the back button before publishing
+ $backButton = $templateDom->getElementById('back-to-templates-btn');
+ if ($backButton) {
+ $backButton->parentNode->removeChild($backButton);
+ }
$imgTag = $templateDom->getElementById('previewImage');
if ($imgTag) $imgTag->setAttribute('src', $imageUrl);
@@ -51,16 +60,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
while ($ctaContainer->hasChildNodes()) {
$ctaContainer->removeChild($ctaContainer->firstChild);
}
+
if (!empty(trim($checkoutHtml))) {
$fragment = $templateDom->createDocumentFragment();
+ // Append HTML, suppressing errors for potentially malformed user input
@$fragment->appendXML($checkoutHtml);
$ctaContainer->appendChild($fragment);
+ } elseif ($showCtaButton && $ctaUrl) {
+ $link = $templateDom->createElement('a', $ctaText);
+ $link->setAttribute('href', $ctaUrl);
+ $link->setAttribute('class', 'btn btn-primary btn-lg');
+ $link->setAttribute('role', 'button');
+ $ctaContainer->appendChild($link);
} else {
- $ctaContainer->nodeValue = $ctaText; // Fallback to simple text if no HTML
+ // If no checkout HTML and button is disabled or no URL, remove the container
+ if ($ctaContainer->parentNode) {
+ $ctaContainer->parentNode->removeChild($ctaContainer);
+ }
}
}
- $finalPreviewHtml = $templateDom->saveHTML();
+ // Extract the inner HTML of the temporary div
+ $body = $templateDom->getElementsByTagName('div')->item(0);
+ $finalPreviewHtml = '';
+ foreach ($body->childNodes as $child) {
+ $finalPreviewHtml .= $templateDom->saveHTML($child);
+ }
+
$htmlContent = <<
diff --git a/published/692d23de03ac9.html b/published/692d23de03ac9.html
new file mode 100644
index 0000000..a9f5ff4
--- /dev/null
+++ b/published/692d23de03ac9.html
@@ -0,0 +1,169 @@
+
+
+
+
+
+ Minimalist Modern Title
+
+
+
+
+
+
+
A compelling description for the minimalist modern template.
+
+
+
+
\ No newline at end of file
diff --git a/templates/template-2.html b/templates/template-2.html
index 06155ee..3c7098d 100644
--- a/templates/template-2.html
+++ b/templates/template-2.html
@@ -1,12 +1,13 @@
-
-
-
-
-
-
Bold & Blue Title
-
A vibrant and bold description for the blue-themed template.
A vibrant and bold description for the blue-themed template.
+
+
+
+
\ No newline at end of file
diff --git a/templates/template-3.html b/templates/template-3.html
index 30d48a3..12316a5 100644
--- a/templates/template-3.html
+++ b/templates/template-3.html
@@ -1,10 +1,11 @@
-
-
-
-
Classic Serif Title
-
An elegant and classic description, perfect for a timeless serif-style ebook.