http://qs321.pair.com?node_id=156579
Category: Web Stuff
Author/Contact Info Adrian P. Dunston (pedro_picasso@x-omega.com)
Description: Do you like Everything2 and Perlmonks but can't seem to get the code to work on your machine because you're running Mandrake and not Debian or RedHat and while EveryDevel is a great company with a great content manager, their documentation leaves a lot to the imagination, and you honestly don't have time to sift through database application code when all you want is to have your own easily maintainable set of interlinked content? Well this is the script for you!

It's a simple CGI hack that imitates PerlMonks/Everything2's noding. You type a "musing" with links to other musings in brackets. It's great for keeping your own interlinked encyclopedia of personal notes.

#!/usr/bin/perl -wT

#########################################################
# Muse 
# A "Web of Content" Manager by Adrian P. Dunston
#
# This is a sort of dumbed down single user of the
# Everything Engine that Perlmonks runs on.
# (www.everydevel.com)
#
# Write different nodes or "musings" and link them
# together by surrounding certain words with [brackets].
# In the case of the last sentence, the word "brackets"
# links to the node of that title.
#########################################################

use strict;
use warnings;

use CGI qw(:standard);    
use CGI::Carp qw(fatalsToBrowser);



start();   


sub start {
    my $cgi = new CGI;
    my $output;
    my $node_text;
    my $node = param("node");
    my $text = param("text");

    print $cgi->header;

    # Untaint
    ($node) = $node =~ /([A-Za-z0-9 -_.,?]{1,30})/g;







    # If text has been passed, put it into its node.
    if ($text) {
        open(NODE, ">data/$node.musing") or die "Couldn't open data/$n
+ode.musing for writing because $!";
        print NODE $text;
        close NODE;
    }

    # If the user wants to see a node, show it to him with a form for 
+editing it.
    if ($node) {

        if (open(NODE, "data/$node.musing")) {
            $node_text .= $_ while <NODE>;
            $output = $node_text;
            $output =~ s|\[(.+?)\]|<a href="muse.cgi?node=$1">$1</a>|g
+;
            $output = "\n\n<table width=\"65\%\" style=\"margin-left: 
+50\"><tr><td>\n" . $output . "</td></tr></table>\n\n";
        } else {
            $output = "There is currently no musing \"$node\".  You ar
+e welcome to create your own.";
        }

        $output = "<html>\n<head><title>$node - Muse</title></head>\n<
+body>\n" .
            "<b style=\"font-size: 18pt\">$node</b><br><br>$output\n<b
+r><br><br>\n";

        $output .= '<form action="muse.cgi" method="post">';
        $output .= "\nEdit the node:<br>\n<textarea name=\"text\" rows
+=\"5\" cols=\"50\">$node_text</textarea><br>\n";
        $output .= "<input type=\"hidden\" name=\"node\" value=\"$node
+\">\n";
        $output .= "<input type=\"submit\" value=\"Edit Musing\">\n</f
+orm>\n";
        $output .= "<hr>\n";
        $output .= '<form action="muse.cgi" method="post"><input type=
+"text" name="node"><input type="submit" value="New Musing"></form>';
        $output .= '[ <a href="muse.cgi">Muse</a> ]  ';
        $output .= "</body>\n</html>";

    # Otherwise, show him the list of nodes in the system.
    } else {
        my @file = <data/*.musing>;

        foreach (@file) {
            s|data/||;        # Get rid of data/
            s/\.musing//;        # Get rid of .musing
            $output .= "<li><a href=\"muse.cgi?node=$_\">$_</a></li>\n
+";
        }

        $output = "<html>\n<head><title>Muse</title></head>\n<body>\n<
+u><b style=\"font-size: 24pt\">MUSE</b></u><br><br>\n" .
            "Musings: \n<ul>\n$output\n</ul>";

        $output .= '<form action="muse.cgi" method="post"><input type=
+"text" name="node"><input type="submit" value="New Musing"></form>';
        $output .= "</body>\n</html>";
    }


    ## OUTPUT
    print $output;


}