krz/php-blog

Archived

A PHP blogging system with built-in static comments. blog comments php static

Commit 40ff718d02

40ff718d02c38bdbaf9a690faf46e609c4f050df

parent: 703f8be3fd

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-22 20:55 UTC

Add Qlty config; pass Template its fields as an array

Template no longer creates dynamic properties, which PHP 8.2+ printed
as deprecation notices into every page, and two parameters are now
explicitly nullable for PHP 8.4. Page output is otherwise unchanged.
Parsedown.php and prism.js are vendored and excluded from Qlty.

Layout: unified · split

.qlty/.gitignore added +7
@@ -0,0 +1,7 @@
1*
2!configs
3!configs/**
4!hooks
5!hooks/**
6!qlty.toml
7!.gitignore
.qlty/qlty.toml added +47
@@ -0,0 +1,47 @@
1config_version = "0"
2
3exclude_patterns = [
4 "**/vendor/**",
5 "**/node_modules/**",
6 "**/testdata/**",
7 "**/dist/**",
8 "**/.build/**",
9 "**/build/**",
10 "**/*.min.*",
11 "**/generated/**",
12 ".claude/**",
13 "**/Pods/**",
14 # Vendored: erusev/parsedown and a PrismJS 1.23.0 build.
15 "_classes/Parsedown.php",
16 "static/prism.js",
17]
18
19test_patterns = [
20 "**/test/**",
21 "**/tests/**",
22 "**/Tests/**",
23 "**/*_test.*",
24 "**/test_*.*",
25 "**/*.test.*",
26 "**/*Tests.swift",
27 "e2e/**",
28]
29
30[[source]]
31name = "default"
32default = true
33
34[[plugin]]
35name = "osv-scanner"
36
37[[plugin]]
38name = "trufflehog"
39
40# Early returns are guard clauses, which keep the happy path unindented.
41[smells.return_statements]
42enabled = false
43
44# Total file complexity is the sum of its functions, which function_complexity
45# already checks.
46[smells.file_complexity]
47enabled = false
_classes/Template.php +19 −15
@@ -3,15 +3,23 @@
33
44class Template
55{
6 public function __construct(string $canonicalURL, string $pageDescription, string $pageTitle, string $pageExtras, string $contentCol, string $commentSection)
6 // Template placeholders, in the order they are filled in.
7 private const PLACEHOLDERS = [
8 'Page_Title',
9 'Page_Description',
10 'Canonical_URL',
11 'Page_Extras',
12 'Content_Column',
13 'User_Comments',
14 'Current_Year',
15 ];
16
17 private array $fields;
18
19 // $fields maps each {Placeholder} in _templates/template.html to its value.
20 public function __construct(array $fields)
721 {
8 $this->canonicalURL = $canonicalURL;
9 $this->description = $pageDescription;
10 $this->title = $pageTitle;
11 $this->extras = $pageExtras;
12 $this->content = $contentCol;
13 $this->comments = $commentSection;
14 $this->currentYear = date("Y");
22 $this->fields = $fields + ['Current_Year' => date("Y")];
1523 }
1624
1725 public function echoTemplate()
@@ -21,13 +29,9 @@ class Template
2129 $page = file_get_contents($templateFile);
2230
2331 // Replace the template variables
24 $page = str_replace('{Page_Title}', $this->title, $page);
25 $page = str_replace('{Page_Description}', $this->description, $page);
26 $page = str_replace('{Canonical_URL}', $this->canonicalURL, $page);
27 $page = str_replace('{Page_Extras}', $this->extras, $page);
28 $page = str_replace('{Content_Column}', $this->content, $page);
29 $page = str_replace('{User_Comments}', $this->comments, $page);
30 $page = str_replace('{Current_Year}', $this->currentYear, $page);
32 foreach (self::PLACEHOLDERS as $name) {
33 $page = str_replace('{' . $name . '}', $this->fields[$name], $page);
34 }
3135
3236 // Echo the filled-out template
3337 echo $page;
_functions/loadJSON.php +1 −1
@@ -81,7 +81,7 @@ function loadPostJSON(string $fileName, string $query)
8181 }
8282}
8383
84function loadCommentJSON(string $fileName, string $query = null): string
84function loadCommentJSON(string $fileName, ?string $query = null): string
8585{
8686 // Set up an empty comment section
8787 $commentSection = '';
_functions/parseMarkdown.php +1 −1
@@ -1,6 +1,6 @@
11<?php
22
3function parseMarkdown(string $fileName = null, string $fileContents = null)
3function parseMarkdown(?string $fileName = null, ?string $fileContents = null)
44{
55 if ($fileName != null) {
66 // Get file contents
index.php +32 −32
@@ -55,14 +55,14 @@ function showHomepage()
5555
5656 // Create a template
5757 include_once('_classes/Template.php');
58 $template = new Template(
59 $GLOBALS['fullDomain'],
60 'Explore the thoughts of...',
61 'Blog | YourName',
62 '',
63 $contentCol,
64 ''
65 );
58 $template = new Template([
59 'Canonical_URL' => $GLOBALS['fullDomain'],
60 'Page_Description' => 'Explore the thoughts of...',
61 'Page_Title' => 'Blog | YourName',
62 'Page_Extras' => '',
63 'Content_Column' => $contentCol,
64 'User_Comments' => '',
65 ]);
6666
6767 // Echo the HTML to the user
6868 $template->echoTemplate();
@@ -102,14 +102,14 @@ function showPost($params)
102102
103103 // Create a template
104104 include_once('_classes/Template.php');
105 $template = new Template(
106 $GLOBALS['fullDomain'] . '/post/' . $query,
107 $headerData->description . ' Read more at ' . $GLOBALS['fullDomain'] . '!',
108 $headerData->title . ' | Blog',
109 '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script>',
110 $contentCol,
111 $commentSection
112 );
105 $template = new Template([
106 'Canonical_URL' => $GLOBALS['fullDomain'] . '/post/' . $query,
107 'Page_Description' => $headerData->description . ' Read more at ' . $GLOBALS['fullDomain'] . '!',
108 'Page_Title' => $headerData->title . ' | Blog',
109 'Page_Extras' => '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script>',
110 'Content_Column' => $contentCol,
111 'User_Comments' => $commentSection,
112 ]);
113113
114114 // Echo the HTML to the user
115115 $template->echoTemplate();
@@ -132,14 +132,14 @@ function showComments()
132132
133133 // Create a template
134134 include_once('_classes/Template.php');
135 $template = new Template(
136 $GLOBALS['fullDomain'] . '/comments/',
137 'Read through some recent comments for blog posts at ' . $GLOBALS['fullDomain'] . '.',
138 'Recent Comments | Blog',
139 '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script><meta name="robots" content="noindex,nofollow">',
140 '',
141 $commentSection
142 );
135 $template = new Template([
136 'Canonical_URL' => $GLOBALS['fullDomain'] . '/comments/',
137 'Page_Description' => 'Read through some recent comments for blog posts at ' . $GLOBALS['fullDomain'] . '.',
138 'Page_Title' => 'Recent Comments | Blog',
139 'Page_Extras' => '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script><meta name="robots" content="noindex,nofollow">',
140 'Content_Column' => '',
141 'User_Comments' => $commentSection,
142 ]);
143143
144144 // Echo the HTML to the user
145145 $template->echoTemplate();
@@ -156,14 +156,14 @@ function showCategory()
156156
157157 // Create a template
158158 include_once('_classes/Template.php');
159 $template = new Template(
160 $GLOBALS['fullDomain'] . '/categories/',
161 'Browse the categories for blog posts at ' . $GLOBALS['fullDomain'] . '.',
162 'Categories | Blog',
163 '<meta name="robots" content="noindex,nofollow">',
164 $contentCol,
165 ''
166 );
159 $template = new Template([
160 'Canonical_URL' => $GLOBALS['fullDomain'] . '/categories/',
161 'Page_Description' => 'Browse the categories for blog posts at ' . $GLOBALS['fullDomain'] . '.',
162 'Page_Title' => 'Categories | Blog',
163 'Page_Extras' => '<meta name="robots" content="noindex,nofollow">',
164 'Content_Column' => $contentCol,
165 'User_Comments' => '',
166 ]);
167167
168168 // Echo the HTML to the user
169169 $template->echoTemplate();