summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--codegen.php23
-rw-r--r--dev-server.php32
-rw-r--r--src/codegen/emoticons.php36
-rw-r--r--src/pages/guestbook.php52
-rw-r--r--src/static/emoticons/angel.gifbin0 -> 175 bytes
-rw-r--r--src/static/emoticons/angry.gifbin0 -> 167 bytes
-rw-r--r--src/static/emoticons/azn.gifbin0 -> 168 bytes
-rw-r--r--src/static/emoticons/bang.gifbin0 -> 351 bytes
-rw-r--r--src/static/emoticons/blank.gifbin0 -> 156 bytes
-rw-r--r--src/static/emoticons/cheesy.gifbin0 -> 172 bytes
-rw-r--r--src/static/emoticons/cool.gifbin0 -> 172 bytes
-rw-r--r--src/static/emoticons/cry.gifbin0 -> 573 bytes
-rw-r--r--src/static/emoticons/embarrassed.gifbin0 -> 650 bytes
-rw-r--r--src/static/emoticons/evil.gifbin0 -> 238 bytes
-rw-r--r--src/static/emoticons/grin.gifbin0 -> 173 bytes
-rw-r--r--src/static/emoticons/huh.gifbin0 -> 167 bytes
-rw-r--r--src/static/emoticons/kiss.gifbin0 -> 171 bytes
-rw-r--r--src/static/emoticons/laugh.gifbin0 -> 336 bytes
-rw-r--r--src/static/emoticons/lipsrsealed.gifbin0 -> 231 bytes
-rw-r--r--src/static/emoticons/police.gifbin0 -> 171 bytes
-rw-r--r--src/static/emoticons/rolleyes.gifbin0 -> 485 bytes
-rw-r--r--src/static/emoticons/sad.gifbin0 -> 167 bytes
-rw-r--r--src/static/emoticons/sad2.gifbin0 -> 436 bytes
-rw-r--r--src/static/emoticons/shocked.gifbin0 -> 178 bytes
-rw-r--r--src/static/emoticons/shrug.gifbin0 -> 998 bytes
-rw-r--r--src/static/emoticons/smiley.gifbin0 -> 174 bytes
-rw-r--r--src/static/emoticons/tongue.gifbin0 -> 233 bytes
-rw-r--r--src/static/emoticons/undecided.gifbin0 -> 171 bytes
-rw-r--r--src/static/emoticons/wink.gifbin0 -> 170 bytes
30 files changed, 143 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 86803b0..edbbc2c 100644
--- a/Makefile
+++ b/Makefile
@@ -3,13 +3,15 @@ HTMLTARGETS:=$(SRCFILES:src/pages/%.php=build/%.html)
DEV_SERVER_BINDING?=127.0.0.1:19310
-.PHONY: build/static publish dev-server
+.PHONY: build/static publish dev-server build/codegen
-all: $(HTMLTARGETS) $(STATICFILES) build/static build/favicon.ico
+all: $(HTMLTARGETS) $(STATICFILES) build/static build/favicon.ico build/codegen
build/favicon.ico: src/favicon.ico
cp src/favicon.ico build/
+build/codegen:
+ php codegen.php
build/static:
rsync -rupE src/static build/
diff --git a/codegen.php b/codegen.php
new file mode 100644
index 0000000..a842b32
--- /dev/null
+++ b/codegen.php
@@ -0,0 +1,23 @@
+<?php
+
+require_once __DIR__ . "/common.php";
+$cg_dir = SRCDIR . "/codegen";
+foreach (scandir($cg_dir) as $cg_ent) {
+ $cg_path = $cg_dir . "/" . $cg_ent;
+ if (
+ $cg_ent[0] === "." ||
+ !is_file($cg_path) ||
+ strtolower(pathinfo($cg_ent, PATHINFO_EXTENSION)) !== "php"
+ ) continue;
+ echo "[codegen] $cg_ent ";
+ $data = include $cg_path;
+ if (!is_array($data) || count($data) !== 2) {
+ trigger_error(
+ "Invalid data returned from codegen script '$cg_ent'",
+ E_USER_WARNING,
+ );
+ continue;
+ }
+ echo "-> $data[0]\n";
+ file_put_contents(__DIR__ . "/build/" . $data[0], $data[1]);
+}
diff --git a/dev-server.php b/dev-server.php
index 2e5aacb..24969f6 100644
--- a/dev-server.php
+++ b/dev-server.php
@@ -8,6 +8,27 @@ const FALLBACK_FILE = TEMPLATE_DIR . "not_found.php";
const DEFAULT_FILE = TEMPLATE_DIR . "index.php";
const DEFAULT_MIME_TYPE = "application/octet-stream";
+$cg_map = [];
+$cg_dir = SRCDIR . "/codegen";
+
+foreach (scandir($cg_dir) as $cg_ent) {
+ $cg_path = $cg_dir . "/" . $cg_ent;
+ if (
+ $cg_ent[0] === "." ||
+ !is_file($cg_path) ||
+ strtolower(pathinfo($cg_ent, PATHINFO_EXTENSION)) !== "php"
+ ) continue;
+ $data = include $cg_path;
+ if (!is_array($data) || count($data) !== 2) {
+ trigger_error(
+ "Invalid data returned from codegen script '$cg_ent'",
+ E_USER_WARNING,
+ );
+ continue;
+ }
+ $cg_map[$data[0]] = $cg_path;
+}
+
function get_mime(string $filename): string {
static $mime_overrides = [
"css" => "text/css",
@@ -39,6 +60,17 @@ elseif (str_ends_with($name, ".html")) {
header("Content-Length: $len");
readfile($path);
exit;
+} elseif (isset($cg_map[$name])) {
+ $data = include $cg_map[$name];
+ if (!is_array($data) || count($data) !== 2) {
+ http_response_code(500);
+ echo "Invalid data returned from codegen script '$cg_ent'\n";
+ exit;
+ }
+ header("Content-Type: " . get_mime($data[0]));
+ header("Content-Length: " . strlen($data[1]));
+ echo $data[1];
+ exit;
}
$include_file = FALLBACK_FILE;
diff --git a/src/codegen/emoticons.php b/src/codegen/emoticons.php
new file mode 100644
index 0000000..51b9ed6
--- /dev/null
+++ b/src/codegen/emoticons.php
@@ -0,0 +1,36 @@
+<?php
+
+$em_dir = SRCDIR . "/static/emoticons";
+$emoticons = array_map(
+ fn($i) => [
+ pathinfo($i, PATHINFO_FILENAME),
+ getimagesize($em_dir . "/" . $i)["3"]
+ ],
+ array_values(
+ array_filter(
+ scandir($em_dir),
+ fn($i) =>
+ $i[0] !== "." &&
+ is_file($em_dir . "/" . $i) &&
+ strtolower(pathinfo($i, PATHINFO_EXTENSION)) === "gif"
+ )
+ )
+);
+
+usort($emoticons, fn($a, $b) => strlen($b[0]) <=> strlen($a[0]));
+
+$emoticons_alpha_lookup = [];
+foreach ($emoticons as $i => $emoticon) {
+ $emoticons_alpha_lookup []= [$i, $emoticon[0]];
+}
+usort($emoticons_alpha_lookup, fn($a, $b) => $a[1] <=> $b[1]);
+$emoticons_alpha_lookup = array_column($emoticons_alpha_lookup, 0);
+
+return [
+ "emoticons.js",
+ "/* auto-generated at " . date("c") . " */\nvar EMOTICONS = " .
+ json_encode([
+ $emoticons,
+ $emoticons_alpha_lookup,
+ ], JSON_PRETTY_PRINT) . ";\n",
+];
diff --git a/src/pages/guestbook.php b/src/pages/guestbook.php
index f84b92d..2d40089 100644
--- a/src/pages/guestbook.php
+++ b/src/pages/guestbook.php
@@ -2,10 +2,11 @@
<param:active-link>guestbook</param:active-link>
<div id="guestbook_frame"></div>
-
+<p><a href="#" id="emoticon-guide">Emoticon guide</a></p>
<div id="guestbook"></div>
<script type="text/javascript" src="/static/jquery-1.12.4.min.js"></script>
+<script type="text/javascript" src="/emoticons.js"></script>
<script>
function htmlentities(str) {
return str.replace(/&/g, "&amp;")
@@ -20,13 +21,56 @@ function nl2br(str, xhtml) {
return str.replace(/\n/g, "<br" + (xhtml ? " /" : "") + ">");
}
+function replace_emoticons(html) {
+ for (var i = 0; i < EMOTICONS[0].length; ++i) {
+ html = html.split(":" + EMOTICONS[0][i][0] + ":")
+ .join(
+ '<img src="/static/emoticons/' + EMOTICONS[0][i][0] + '.gif" ' +
+ EMOTICONS[0][i][1] +
+ ' alt="' + EMOTICONS[0][i][0] + '"' +
+ ' title=":' + EMOTICONS[0][i][0] + ':" />'
+ );
+ }
+ return html;
+}
+
$(function() {
$("#guestbook_frame").append(
$("<iframe></iframe>")
.attr("id", "gbframe")
.attr("frameborder", "0")
- .attr("src", "//guestbook.hozyro.jkohl.link/?__e=1&__p[ok_target]=_top&__p[ok_url]=" + encodeURIComponent(location.href))
+ .attr("src", "//guestbook.web.local/?__e=1&__p[ok_target]=_top&__p[ok_url]=" + encodeURIComponent(location.href))
);
+ $("#emoticon-guide").click(function(e) {
+ e.preventDefault();
+ var win = window.open("about:blank", "emguide", "width=260,height=450,left=0,top=0,popup=yes,toolbar=no,menubar=no,scrollbars=yes");
+ //win.document.title = "Emoticon guide";
+ win.document.open();
+ win.document.write('<html><head>');
+ win.document.write('<title>Emoticon guide</title>');
+ win.document.write('</head><body bgcolor="#05456a">');
+ win.document.write('<center>');
+ win.document.write('<table border=1 bgcolor=white><tbody>');
+ var idx = 0;
+ for (var i = 0; i < EMOTICONS[1].length; ++i) {
+ idx = EMOTICONS[1][i];
+ win.document.write(
+ "<tr><td>" +
+ '<img src="/static/emoticons/' + EMOTICONS[0][idx][0] + '.gif" ' +
+ EMOTICONS[0][idx][1] +
+ ' alt="' + EMOTICONS[0][idx][0] + '"' +
+ ' title=":' + EMOTICONS[0][idx][0] + ':" />' +
+ "</td><td><font face=Verdana size=2>" +
+ ":" + EMOTICONS[0][idx][0] + ":" +
+ "</font></td></tr>\n"
+ );
+ }
+ win.document.write('</tbody></table>');
+ win.document.write('</center>');
+ win.document.write('</body></html>');
+ win.document.close();
+ return;
+ });
})
function _gbcb(data) {
@@ -50,9 +94,9 @@ function _gbcb(data) {
.text(entry.published),
$("<div></div>")
.addClass("guestbook-content")
- .html(nl2br(htmlentities(entry.content)))
+ .html(replace_emoticons(nl2br(htmlentities(entry.content))))
).appendTo("#guestbook")
})
}
</script>
-<script type="text/javascript" src="//guestbook.hozyro.jkohl.link/?__m=ajax&amp;__r=jsonp&amp;__c=_gbcb"></script>
+<script type="text/javascript" src="//guestbook.web.local/?__m=ajax&amp;__r=jsonp&amp;__c=_gbcb"></script>
diff --git a/src/static/emoticons/angel.gif b/src/static/emoticons/angel.gif
new file mode 100644
index 0000000..f52c820
--- /dev/null
+++ b/src/static/emoticons/angel.gif
Binary files differ
diff --git a/src/static/emoticons/angry.gif b/src/static/emoticons/angry.gif
new file mode 100644
index 0000000..205ebfc
--- /dev/null
+++ b/src/static/emoticons/angry.gif
Binary files differ
diff --git a/src/static/emoticons/azn.gif b/src/static/emoticons/azn.gif
new file mode 100644
index 0000000..33149fb
--- /dev/null
+++ b/src/static/emoticons/azn.gif
Binary files differ
diff --git a/src/static/emoticons/bang.gif b/src/static/emoticons/bang.gif
new file mode 100644
index 0000000..cde005e
--- /dev/null
+++ b/src/static/emoticons/bang.gif
Binary files differ
diff --git a/src/static/emoticons/blank.gif b/src/static/emoticons/blank.gif
new file mode 100644
index 0000000..73909d8
--- /dev/null
+++ b/src/static/emoticons/blank.gif
Binary files differ
diff --git a/src/static/emoticons/cheesy.gif b/src/static/emoticons/cheesy.gif
new file mode 100644
index 0000000..d352772
--- /dev/null
+++ b/src/static/emoticons/cheesy.gif
Binary files differ
diff --git a/src/static/emoticons/cool.gif b/src/static/emoticons/cool.gif
new file mode 100644
index 0000000..cead030
--- /dev/null
+++ b/src/static/emoticons/cool.gif
Binary files differ
diff --git a/src/static/emoticons/cry.gif b/src/static/emoticons/cry.gif
new file mode 100644
index 0000000..aaa73a6
--- /dev/null
+++ b/src/static/emoticons/cry.gif
Binary files differ
diff --git a/src/static/emoticons/embarrassed.gif b/src/static/emoticons/embarrassed.gif
new file mode 100644
index 0000000..ad76283
--- /dev/null
+++ b/src/static/emoticons/embarrassed.gif
Binary files differ
diff --git a/src/static/emoticons/evil.gif b/src/static/emoticons/evil.gif
new file mode 100644
index 0000000..502fe24
--- /dev/null
+++ b/src/static/emoticons/evil.gif
Binary files differ
diff --git a/src/static/emoticons/grin.gif b/src/static/emoticons/grin.gif
new file mode 100644
index 0000000..4f86116
--- /dev/null
+++ b/src/static/emoticons/grin.gif
Binary files differ
diff --git a/src/static/emoticons/huh.gif b/src/static/emoticons/huh.gif
new file mode 100644
index 0000000..05721b0
--- /dev/null
+++ b/src/static/emoticons/huh.gif
Binary files differ
diff --git a/src/static/emoticons/kiss.gif b/src/static/emoticons/kiss.gif
new file mode 100644
index 0000000..ad9a55b
--- /dev/null
+++ b/src/static/emoticons/kiss.gif
Binary files differ
diff --git a/src/static/emoticons/laugh.gif b/src/static/emoticons/laugh.gif
new file mode 100644
index 0000000..374ba15
--- /dev/null
+++ b/src/static/emoticons/laugh.gif
Binary files differ
diff --git a/src/static/emoticons/lipsrsealed.gif b/src/static/emoticons/lipsrsealed.gif
new file mode 100644
index 0000000..448399b
--- /dev/null
+++ b/src/static/emoticons/lipsrsealed.gif
Binary files differ
diff --git a/src/static/emoticons/police.gif b/src/static/emoticons/police.gif
new file mode 100644
index 0000000..4f31156
--- /dev/null
+++ b/src/static/emoticons/police.gif
Binary files differ
diff --git a/src/static/emoticons/rolleyes.gif b/src/static/emoticons/rolleyes.gif
new file mode 100644
index 0000000..d7f5f2f
--- /dev/null
+++ b/src/static/emoticons/rolleyes.gif
Binary files differ
diff --git a/src/static/emoticons/sad.gif b/src/static/emoticons/sad.gif
new file mode 100644
index 0000000..bf0348c
--- /dev/null
+++ b/src/static/emoticons/sad.gif
Binary files differ
diff --git a/src/static/emoticons/sad2.gif b/src/static/emoticons/sad2.gif
new file mode 100644
index 0000000..6945d80
--- /dev/null
+++ b/src/static/emoticons/sad2.gif
Binary files differ
diff --git a/src/static/emoticons/shocked.gif b/src/static/emoticons/shocked.gif
new file mode 100644
index 0000000..9f51fe0
--- /dev/null
+++ b/src/static/emoticons/shocked.gif
Binary files differ
diff --git a/src/static/emoticons/shrug.gif b/src/static/emoticons/shrug.gif
new file mode 100644
index 0000000..9e8cda6
--- /dev/null
+++ b/src/static/emoticons/shrug.gif
Binary files differ
diff --git a/src/static/emoticons/smiley.gif b/src/static/emoticons/smiley.gif
new file mode 100644
index 0000000..7b1f6d3
--- /dev/null
+++ b/src/static/emoticons/smiley.gif
Binary files differ
diff --git a/src/static/emoticons/tongue.gif b/src/static/emoticons/tongue.gif
new file mode 100644
index 0000000..1ad749f
--- /dev/null
+++ b/src/static/emoticons/tongue.gif
Binary files differ
diff --git a/src/static/emoticons/undecided.gif b/src/static/emoticons/undecided.gif
new file mode 100644
index 0000000..0c49e06
--- /dev/null
+++ b/src/static/emoticons/undecided.gif
Binary files differ
diff --git a/src/static/emoticons/wink.gif b/src/static/emoticons/wink.gif
new file mode 100644
index 0000000..d148288
--- /dev/null
+++ b/src/static/emoticons/wink.gif
Binary files differ