#!/usr/bin/perl # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # File: simpleforum.cgi # # Name: SimpleForum v3.9 # # Author: Daan Deconinck # # E-mail: daan.deconinck@pandora.be # # Date: 10/12/2002 (DD/MM/YYYY) # # Last Update: 14/07/2003 (DD/MM/YYYY) # # # # This script is made to work on all HTTP # # servers supporting CGI, and requires no # # modules to be installed. # # # # This software cannot be edited or modified # # by anyone without the explicit permission # # from the author. See "Terms of use.txt". # # # # SimpleForum # # ©2003 Daan Deconinck # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # F O R U M # # # # # # # # # # # # # # # # # # # # CONSTANTS / CONFIG # # # # # # # # # # # # # # # # # # # # # # #The dir where SimpleForum will place all its files in, likely you won't want to change this line. #(example: $simpleforum_dir = "simpleforum_files";) $simpleforum_dir = "simpleforum_files"; #The rest of the configurations can be done through the Admin area on the forum. Time to start 'r up :) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # MAIN # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Do not change anything below # See "Terms of use.txt" that came with the download for more info use CGI; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use lib "."; &start; if ($qs) { if ($qs =~ /topic_id=(\d*)(.*?)edit=(\d*)/s and $forum_id) { #edit a post $topic_id = $1; $edit_id = $3; &edit; } elsif ($qs =~ /topic_id=(\d*)(.*?)quickdel=(\d*)/s and $forum_id) { #quickdelete a post $topic_id = $1; $dele_id = $3; &quick_delete; } elsif ($qs =~ /topic_id=(\d*)(.*?)reply=(\d*)/s and $forum_id) { #reply to a specific message $topic_id = $1; $msg_id = $3; &page_start; &post_form("reply_id=$topic_id"); &page_end; } elsif ($qs =~ /topic_id=(\d*)/s and $forum_id) { #print a topic $topic_id = $1; &page_start; &print_topic; &page_end; } elsif ($qs =~ /reply_id=(\d*)/s and $forum_id) { #reply to a topic $topic_id = $1; &verify_content; &write_to_topic; print redirect("simpleforum.cgi?fid=$forum_id"); } elsif ($qs =~ /post/ and $forum_id) { #post a new message if (!param('posted')) { #print the form &page_start; &post_form('post'); &page_end; } else { #"post-new-topic" form is submitted &verify_content; &write_to_topic; print redirect("simpleforum.cgi?fid=$forum_id"); } } elsif ($qs =~ /admin/) { &admin; &page_end; } elsif ($qs =~ /search/) { &page_start; &search; &page_end; } elsif ($qs =~ /help/) { &page_start; &help; &page_end; } elsif ($forum_id) { #print topic index for this forum section &page_start; &print_topic_index; &page_end; } else { #invalid query string print redirect("simpleforum.cgi"); } } else { #index &page_start; &print_forum_index; &page_end; } # # # # # # SUBROUTINES # # # # # # # # # # # # # # # # # # # # # # # # # # sub page_start { #self-explanatory #Don't touch this line! print header; $header_printed = 1; if ($qs =~ /admin/) { if ($forum_id) { $menu = "<$standardfont>$forum_name

$home_name | $lang_forum_index | $forum_name | $lang_new_topic | $lang_search | $lang_help | $lang_admin"; } else { $menu = "<$standardfont>$lang_welcome

$home_name | $lang_forum_index | $lang_search | $lang_help | $lang_admin"; } } else { if ($forum_id) { $menu = "<$standardfont>$forum_name

$home_name | $lang_new_topic | $lang_search | $lang_help | $lang_admin"; } else { $menu = "<$standardfont>$lang_welcome

$home_name | $lang_search | $lang_help | $lang_admin"; } } # # # # HTML # # # # print < $title
$title
<$smallfont>$menu

HTML # # # END HTML # # # } sub print_forum_index { open_dir($simpleforum_dir); print < HTML foreach $file(sort(@files)) { $topic_amount = 0; if ($file =~ /^(forum_(\d*))$/) { $forum_amount++; $forum_dir = $1; $fid = $2; open(INFO, "< $simpleforum_dir/$forum_dir/forum.info") or dienice("Couldn't open $simpleforum_dir/$forum_dir/forum.info: $!"); $forum_info = join '', ; close INFO; if ($forum_info =~ /(.*?)<\/forum_name>/s) { $forum_name = add_html($1); } if ($forum_info =~ /(.*?)<\/forum_more>/s) { $forum_more = add_html($1); } opendir(FDIR, "$simpleforum_dir/$forum_dir") or dienice("Couldn't open FDIR: $!"); @forumdir_files = readdir FDIR; closedir FDIR; foreach $ffile(@forumdir_files) { if ($ffile =~ /^(\d*).topic$/) { $topic_amount++; ($mtime) = (stat("$simpleforum_dir/$forum_dir/$ffile")) [9]; push @topic_files, "$mtime\|$ffile"; } } @topic_files = reverse(sort(@topic_files)); $last_topic = $topic_files[0]; ($mtime,$last_topic) = split(/\|/, $last_topic); if ($last_topic) { open(LTOPIC, "< $simpleforum_dir/$forum_dir/$last_topic") or dienice("Couldn't open LTOPIC ($last_topic): $!"); $ltopic_content = join '', ; close LTOPIC; if ($ltopic_content =~ /(.*)(.*?)<\/name>(.*?) HTML $at_least_one_forum_printed = 1; $last_posted_time = ""; $last_posted_name = ""; $last_topic = ""; $set = ""; @topic_files = (); $new = ""; } } if (!$at_least_one_forum_printed) { print < HTML } print "
<$bigfont>.: $lang_forum_index :. HTML print &select_a_forum; print <
  $lang_forum $lang_topics $lang_last_post
$forum_name
\n$forum_more
$topic_amount $forum_index_date$last_posted_name
$lang_no_forums_yet_long
\n"; if ($forum_amount > 2) { print "
$select_a_forum
\n\n"; } else { print "
\n"; } print "
"; #print statistics &statistics; } sub print_topic_index { #get all the topic files open_dir($topic_dir); @topics = @files; #filter the topic files from the files in topic_dir foreach $tpc(@topics) { if ($tpc =~ /(.*?).topic$/s) { ($mtime) = (stat("$topic_dir/$tpc")) [9]; push @lastmodifiedtopics, "$mtime\|$tpc"; } } @topics = (); foreach $lastmodifiedtopic(reverse(sort(@lastmodifiedtopics))) { $lastmodifiedtopic =~ s/(.*?)\|(.*?).topic/$2.topic/s; push @available_topics, $lastmodifiedtopic; } #we only need a certain amount of topics to print on our index $page = param('page'); if ($page == 0) { $page++; } $startnumber = ($page - 1) * $topics_per_page; $less_than = $startnumber + $topics_per_page; for ($startnumber; $startnumber < $less_than; $startnumber++) { push(@topics,$available_topics[$startnumber]); } # # # # print all the topics in subroutine print_topic_list &print_topic_list; # # # # end of topiclist $lastpage = ($#available_topics + 1) / $topics_per_page; if ($lastpage != int($lastpage)) { $lastpage = int($lastpage) + 1; } #$lastpage = " last »»"; $amount_of_pages = $lastpage; if ($page > 1) { $previouspage = $page - 1;} if ($page < (($#available_topics + 1) / $topics_per_page)) { $nextpage = $page + 1; } if ($nextpage) {$nextpage = "$lang_next »"; } else {$nextpage = "$lang_next »";} if ($previouspage) { $previouspage = "« $lang_previous - "; } else {$previouspage = "« $lang_previous - ";} # # # # HTML # # # # if ($topics_per_page > 5) { print < <$smallfont>$previouspage $nextpage
\n($page $lang_out_of $amount_of_pages) HTML print &select_a_forum.< HTML } # # # END HTML # # # } sub print_topic_list { if ($qs =~ /search/) { $forum_name = "Search"; } # # # # HTML # # # # print < HTML # # # END HTML # # # #open, read and print topic content foreach $topic(@topics) { if ($topic =~ /^(forum_(\d*))\/(\d*\.topic)$/s) { #this only happens when you perform a search $topic_dir = "$simpleforum_dir/$1"; $forum_id = $2; $topic = $3; $highlight = "&highlight=$searchkey"; } if ($topic =~ /(.*?).topic$/sg) { $topic_id = $1; $topic_replies = 0; #open the topic open(TOPIC,"< $topic_dir/$topic") or dienice("Couldn't open $topic_dir/$topic: $!"); $topic_content = join '', ; close TOPIC; open(STATS,"< $simpleforum_dir/viewcount.sf"); $stats_content = join '', ; close STATS; #get necessary content if ($topic_content =~ /(.*?)<\/name>/s) { $topic_name = $1; } if ($topic_content =~ /(.*?)<\/subject>/s) { $topic_subject = $1; } if ($stats_content =~ /<$topic_id>(.*?)\n/s) { $topic_views = $1; } else { $topic_views = 0; } if ($topic_content =~ /(.*)(.*?)<\/name>(.*?) HTML # # # END HTML # # # } } if (!$topic_id) { #no topics posted print < HTML } print "
<$smallfont>» $lang_forum_index » $forum_name HTML print &select_a_forum; print <
  $lang_topic $lang_replies $lang_author $lang_views $lang_last_post
$topic_subject$page_navigation $topic_replies $topic_name $topic_views <$smallfont>$date \@ $hour:$min $ampm
$lang_by $topic_lastpost_name
$lang_no_topics_yet_long
"; } sub print_topic { if (param('action') eq "close" or param('action') eq "open" and $admin_access) { open(TPC, "+>> $simpleforum_dir/forum_$forum_id/$topic_id.topic") or dienice("Couldn't open topic file: $!"); flock TPC, 2; seek TPC, 0, 0; $tpc_content = join '', ; truncate TPC, 0; if (param('action') eq "close") { print TPC "\n\n"; } else { $tpc_content =~ s/\n\n//sg; } print TPC $tpc_content; close TPC; } #open the specific topic open(TOPIC,"< $topic_dir/$topic_id.topic") or dienice("Couldn't open $topic_dir/$topic_id.topic"); $topic_content = join '', ; close TOPIC; #write stats for the topic open (STATS, "+>> $simpleforum_dir/viewcount.sf") or dienice("Couldn't open viewcount file: $!"); flock STATS, 2; seek STATS, 0, 0; $stats_content = join '', ; seek STATS, 0, 0; truncate STATS, 0; if ($stats_content =~ /<$topic_id>(\d*)\n/) { $views = $1 + 1; $stats_content =~ s/<$topic_id>(\d*)\n/<$topic_id>$views\n/sg; } else { print STATS "<$topic_id>1\n"; } print STATS $stats_content; close STATS; #if this is a read-only forum, act as if the topic is a "CLOSED" topic, EXCEPT if you have admin access open (FORUMINFO, "< $simpleforum_dir/forum_$forum_id/forum.info") or dienice("Couldn't open forum.info file for reading: $!"); $forum_info = join '', ; close FORUMINFO; if ($forum_info =~ /(.*?)<\/forum_perm>/s) { $forum_perm = $1; } if ($forum_perm eq "read-only" and !$admin_access) { $topic_closed = 1; } if ($topic_content =~ /(.*?)<\/subject>/s) { $topic_title = $1; } $original_topic_title = $topic_title; $topic_title = add_html($topic_title); # # # # HTML # # # # print <
<$smallfont>» $lang_forum_index » $forum_name » $lang_topic: $topic_title HTML print &select_a_forum; print <
HTML # # # END HTML # # # if ($topic_content =~ //s) { $topic_closed = 1; } if ($qs =~ /page=(\d*)/s) { $page_start = $1; $topic_start = ($page_start * $posts_per_page) - ($posts_per_page - 1); } else { $topic_start = 1; } $topic_end = $posts_per_page + $topic_start; while ($topic_content =~ /(.*?)<\/post>/sg) { $post_number++; #get necessary content and print it if ($post_number >= $topic_start and $post_number < $topic_end) { $post_amount++; $post_content = $1; if ($post_content =~ /(.*?)<\/name>/sg) { $post_name = $1; } if ($post_content =~ /(.*?)<\/email>/sg) { $post_email = $1; } if ($post_content =~ /(.*?)<\/subject>/sg) { $post_subject = $1; } if ($post_content =~ /