repository

BlowfishCMS

A small content management system for OpenBSD

version 0.45.6 · ISC · 2026-12-03 · releases

31 lines · 1.3 KB · download this file

package BlowfishCMS::Addon::Hello;
# Sample add-on for the tests: every hook, kept tiny.
use v5.36;

sub migrate ($db) { $db->do('CREATE TABLE IF NOT EXISTS hello_greetings (id INTEGER PRIMARY KEY, text TEXT NOT NULL)') }
sub blocks {
    return {hello_greeting=>{label=>'Greeting',fields=>[[title=>'Panel title','text',120],[name=>'Who to greet','text',60]],
        defaults=>{title=>'hello',name=>'world'},
        render=>sub ($b,%o) {BlowfishCMS::window_html($b->{data}{title},'','<p class="hello">Hello, '.BlowfishCMS::h($b->{data}{name}).'!</p>',%o)}}};
}
sub route ($rest) {
    BlowfishCMS::json_response({pong=>1,greetings=>scalar $BlowfishCMS::db->selectrow_array('SELECT count(*) FROM hello_greetings')}) if $rest eq 'ping';
    return 0;
}
sub admin {
    BlowfishCMS::admin_page('Hello',section=>'x-hello');
    BlowfishCMS::window('hello','<p class="hello-admin">The Hello add-on is on.</p>');
    BlowfishCMS::end_page();
    return 1;
}
sub sitemap { return [['/x/hello/ping','2026-11-01']] }
sub robots { return ['/x/hello/private/'] }
sub hourly { return "said hello" }
# A hand-over from its service (0.45.0): kept as a greeting.
sub from_service ($d) {
    die "No text to keep.\n" unless length($d->{text}//'');
    $BlowfishCMS::db->do('INSERT INTO hello_greetings (text) VALUES (?)',undef,$d->{text});
    return "kept $d->{text}";
}

1;