Super duper modifications

updated template system
updated XML template
updated HTML template
masturbated
This commit is contained in:
briandilley 2004-11-04 19:27:04 +00:00
parent 1410c9d0e8
commit 516c5fcb2b
37 changed files with 110 additions and 33 deletions

View File

@ -1,3 +1,7 @@
11-04-04
* changed the template system
* updated the html and xml template
11-01-04 11-01-04
* added support for templates * added support for templates
* added xml template * added xml template

View File

@ -3,6 +3,22 @@
# we use DBI, for it's sexy body # we use DBI, for it's sexy body
use DBI; use DBI;
# template variables
$HEADER = "header";
$FOOTER = "footer";
$CONTENT_DEFAULT = "default-content";
$CONTENT_ADD = "add-kwote";
$CONTENT_SEARCH = "search";
$BEFORE_LIST = "before-list";
$AFTER_LIST = "after-list";
$NAVIGATION = "navigation";
$NAVIGATION_NO_BACK = "navigation-no-back";
$NAVIGATION_NO_FORWARD = "navigation-no-forward";
$KWOTE_ODD = "kwote-odd";
$KWOTE_EVEN = "kwote-even";
$CONTENT_ERROR = "error";
$HTTP_HEADERS = "http-headers";
# database connection # database connection
my $GLOBAL_DBH = undef; my $GLOBAL_DBH = undef;
@ -326,13 +342,18 @@ sub xml_escape {
} }
## ##
# Sends the HTML header # Returns the appropriate http headers based
sub send_html_header { # on the template
print STDOUT "Content-type: text/html\n\n"; sub get_template_headers {
my ($template) = @_;
open(IN, "templates/$template/$HTTP_HEADERS");
my $data = join("",<IN>);
close(IN);
return $data;
} }
## ##
# Renders an HTML template # Wraps an HTML template
sub wrap_template { sub wrap_template {
my ($template, $template_file, %vars) = @_; my ($template, $template_file, %vars) = @_;
open(IN,"templates/$template/$template_file"); open(IN,"templates/$template/$template_file");

View File

@ -45,13 +45,13 @@ $vars{TAG_LINE} = get_tagline();
$vars{TEMPLATE_DIR} = "templates/$template"; $vars{TEMPLATE_DIR} = "templates/$template";
# send header # send header
send_html_header(); print get_template_headers($template)."\n\n";
############ ############
# action: add (show add form) # action: add (show add form)
if ($action eq "add") { if ($action eq "add") {
$vars{TITLE} = "Add Kwote"; $vars{TITLE} = "Add Kwote";
$main_content = wrap_template($template, "content-addform.html", %vars); $main_content = wrap_template($template, $CONTENT_ADD, %vars);
############ ############
# action: doadd (add the kwote to the db) # action: doadd (add the kwote to the db)
@ -60,7 +60,7 @@ if ($action eq "add") {
if ($FORM{"content"} eq "") { if ($FORM{"content"} eq "") {
$vars{TITLE} = "An Error Occured"; $vars{TITLE} = "An Error Occured";
$vars{ERROR_MESSAGE} = "No text entered"; $vars{ERROR_MESSAGE} = "No text entered";
$main_content = wrap_template($template, "content-error.html",%vars); $main_content = wrap_template($template, $CONTENT_ERROR, %vars);
} else { } else {
@ -72,13 +72,13 @@ if ($action eq "add") {
if (!defined($kid)) { if (!defined($kid)) {
$vars{TITLE} = "An Error Occured"; $vars{TITLE} = "An Error Occured";
$vars{ERROR_MESSAGE} = "Couldn't add kwote"; $vars{ERROR_MESSAGE} = "Couldn't add kwote";
$main_content = wrap_template($template, "content-error.html",%vars); $main_content = wrap_template($template, $CONTENT_ERROR, %vars);
# all was good # all was good
} else { } else {
$vars{TITLE} = "Kwote Added"; $vars{TITLE} = "Kwote Added";
$vars{KWOTE_ID} = $kid; $vars{KWOTE_ID} = $kid;
$main_content = wrap_template($template, "content-addform-thanks.html", %vars); $main_content = wrap_template($template, $CONTENT_ADD_THANKS, %vars);
} }
} }
@ -95,7 +95,7 @@ if ($action eq "add") {
if (!defined($kwote)) { if (!defined($kwote)) {
$vars{TITLE} = "Kwote Does Not Exist"; $vars{TITLE} = "Kwote Does Not Exist";
$vars{ERROR_MESSAGE} = "That kwote does not exist"; $vars{ERROR_MESSAGE} = "That kwote does not exist";
$main_content = wrap_template($template, "content-error.html",%vars); $main_content = wrap_template($template, $CONTENT_ERROR, %vars);
# all was good # all was good
} else { } else {
@ -105,7 +105,7 @@ if ($action eq "add") {
$vars{KWOTE_TEXT_XML} = xml_escape($kwote->{'content'}); $vars{KWOTE_TEXT_XML} = xml_escape($kwote->{'content'});
$vars{KWOTE_TEXT_PLAIN} = $kwote->{'content'}; $vars{KWOTE_TEXT_PLAIN} = $kwote->{'content'};
$vars{KWOTE_RATING} = $kwote->{'rating'}; $vars{KWOTE_RATING} = $kwote->{'rating'};
$main_content = wrap_template($template, "content-show-kwote.html", %vars); $main_content = wrap_template($template, $KWOTE_EVEN, %vars);
} }
@ -172,35 +172,42 @@ if ($action eq "add") {
# forward, no back # forward, no back
if ($FORM{"o"} ne "random" && $start_index<=0 && @rows>=$max_returned if ($FORM{"o"} ne "random" && $start_index<=0 && @rows>=$max_returned
&& ($start_index+$max_returned)<$max_records) { && ($start_index+$max_returned)<$max_records) {
$navigation_template = "content-list-navigate-no-back.html"; $navigation_template = $NAVIGATION_NO_BACK;
# forward and back # forward and back
} elsif ($FORM{"o"} ne "random" && $start_index>0 && @rows>=$max_returned } elsif ($FORM{"o"} ne "random" && $start_index>0 && @rows>=$max_returned
&& ($start_index+$max_returned)<$max_records ) { && ($start_index+$max_returned)<$max_records ) {
$navigation_template = "content-list-navigate.html"; $navigation_template = $NAVIGATION;
# back only # back only
} elsif ($FORM{"o"} ne "random" && $start_index>0 && @rows<$max_returned) { } elsif ($FORM{"o"} ne "random" && $start_index>0 && @rows<$max_returned) {
$navigation_template = "content-list-navigate-no-forward.html"; $navigation_template = $NAVIGATION_NO_FORWARD;
} }
# wrap the navigation template # wrap the navigation template
$main_content .= wrap_template($template, $navigation_template, %vars); $main_content .= wrap_template($template, $navigation_template, %vars);
# wrap up the "before list" template
$main_content .= wrap_template($template, $BEFORE_LIST, %vars);
# loop through the results # loop through the results
if (defined(@rows)) { if (defined(@rows)) {
for (my $i=0; $i<@rows && ($i+$start_index)<$max_records; $i++) { for (my $i=0; $i<@rows && ($i+$start_index)<$max_records; $i++) {
my $row = $rows[$i]; my $row = $rows[$i];
my $kwote_template = (($i % 2) != 0) ? $KWOTE_ODD : $KWOTE_EVEN;
$vars{KWOTE_ID} = $row->{'id'}; $vars{KWOTE_ID} = $row->{'id'};
$vars{KWOTE_TEXT_HTML} = html_escape($row->{'content'}); $vars{KWOTE_TEXT_HTML} = html_escape($row->{'content'});
$vars{KWOTE_TEXT_XML} = xml_escape($row->{'content'}); $vars{KWOTE_TEXT_XML} = xml_escape($row->{'content'});
$vars{KWOTE_TEXT_PLAIN} = $row->{'content'}; $vars{KWOTE_TEXT_PLAIN} = $row->{'content'};
$vars{KWOTE_RATING} = $row->{'rating'}; $vars{KWOTE_RATING} = $row->{'rating'};
$main_content .= wrap_template($template, "content-show-kwote.html", %vars); $main_content .= wrap_template($template, $kwote_template, %vars);
} }
} }
# wrap up the "after list" template
$main_content .= wrap_template($template, $AFTER_LIST, %vars);
# wrap the navigation template # wrap the navigation template
$main_content .= wrap_template($template, $navigation_template, %vars); $main_content .= wrap_template($template, $navigation_template, %vars);
@ -208,7 +215,7 @@ if ($action eq "add") {
# action: search (show the search page) # action: search (show the search page)
} elsif ($action eq "search") { } elsif ($action eq "search") {
$vars{TITLE} = "Search"; $vars{TITLE} = "Search";
$main_content = wrap_template($template, "content-search.html", %vars); $main_content = wrap_template($template, $CONTENT_SEARCH, %vars);
########## ##########
# action: love # action: love
@ -228,11 +235,11 @@ if ($action eq "add") {
# show the homepage # show the homepage
} else { } else {
$vars{TITLE} = "The Better kwote Database"; $vars{TITLE} = "The Better kwote Database";
$main_content = wrap_template($template, "content-default.html", %vars); $main_content = wrap_template($template, $CONTENT_DEFAULT, %vars);
} }
# finish the HTML # finish the HTML
render_template($template, "header.html", %vars); render_template($template, $HEADER, %vars);
print STDOUT $main_content; print STDOUT $main_content;
render_template($template, "footer.html", %vars); render_template($template, $FOOTER, %vars);

0
templates/default/after-list Executable file
View File

0
templates/default/before-list Executable file
View File

View File

@ -0,0 +1,2 @@
Content-Type: text/html

16
templates/default/kwote-even Executable file
View File

@ -0,0 +1,16 @@
<div class="kwote-even">
<span class="kwote-id"><a href="?action=show&amp;id=${KWOTE_ID}">#${KWOTE_ID}</a></span>
<span class="vote-controls">
<a href="?action=hate&amp;kid=${KWOTE_ID}"
onclick="vote(${KWOTE_ID},'hate'); return false;"
id="hate${KWOTE_ID}">-</a>
<span id="rating${KWOTE_ID}">${KWOTE_RATING}</span>
<a href="?action=love&amp;kid=${KWOTE_ID}"
onclick="vote(${KWOTE_ID},'love'); return false"
id="love${KWOTE_ID}">+</a>
</span>
<div class="kwote-content">
${KWOTE_TEXT_HTML}
</div>
</div>

View File

@ -1,4 +1,4 @@
<div class="kwote"> <div class="kwote-odd">
<span class="kwote-id"><a href="?action=show&amp;id=${KWOTE_ID}">#${KWOTE_ID}</a></span> <span class="kwote-id"><a href="?action=show&amp;id=${KWOTE_ID}">#${KWOTE_ID}</a></span>
<span class="vote-controls"> <span class="vote-controls">
<a href="?action=hate&amp;kid=${KWOTE_ID}" <a href="?action=hate&amp;kid=${KWOTE_ID}"

View File

@ -62,12 +62,19 @@ a img
} }
/* Kwotes */ /* Kwotes */
.kwote .kwote-odd
{ {
position: relative; position: relative;
margin-bottom: 10px; margin-bottom: 10px;
} }
.kwote-even
{
position: relative;
margin-bottom: 10px;
background-color: #e9e9e9;
}
.kwote-id .kwote-id
{ {
float: left; float: left;

5
templates/xml/add-kwote Executable file
View File

@ -0,0 +1,5 @@
<message>
There isn't an add kwote page for the xml
template because it is intended to be used
by non human processes
</message>

2
templates/xml/add-kwote-thanks Executable file
View File

@ -0,0 +1,2 @@
<kwote-added id="${KWOTE_ID}" />

2
templates/xml/after-list Executable file
View File

@ -0,0 +1,2 @@
</kwotes>

2
templates/xml/before-list Executable file
View File

@ -0,0 +1,2 @@
<kwotes>

View File

@ -1 +0,0 @@
<kwote-added id="${KWOTE_ID" />

View File

@ -1,3 +0,0 @@
<error>${ERROR_MESSAGE}</error>

View File

@ -1,3 +0,0 @@
<kwote id="${KWOTE_ID}" rating="${KWOTE_RATING}">
${KWOTE_TEXT_XML}
</kwote>

4
templates/xml/default-content Executable file
View File

@ -0,0 +1,4 @@
<message>
The XML template doesn't have a default content
</message>

4
templates/xml/error Executable file
View File

@ -0,0 +1,4 @@
<message>
${ERROR_MESSAGE}
</message>

View File

@ -1,5 +1,3 @@
</kwotes.org> </kwotes.org>

View File

@ -2,8 +2,9 @@
<site> <site>
<name>${SITE_NAME}</name> <name>${SITE_NAME}</name>
<tag-line>${TAG_LINE}</tag-line> <tagline>${TAG_LINE}</tagline>
<kwote-count>${KWOTE_COUNT}</kwote-count> <kwote-count>${KWOTE_COUNT}</kwote-count>
<deleted-kwote-count>${KWOTE_BACKUP_COUNT}</deleted-kwote-count> <deleted-kwote-count>${KWOTE_BACKUP_COUNT}</deleted-kwote-count>
</site> </site>

2
templates/xml/http-headers Executable file
View File

@ -0,0 +1,2 @@
Content-type: text/xml

2
templates/xml/kwote-even Executable file
View File

@ -0,0 +1,2 @@
<kwote id="${KWOTE_ID}"><![CDATA[${KWOTE_TEXT_XML}]]></kwote>

1
templates/xml/kwote-odd Executable file
View File

@ -0,0 +1 @@
<kwote id="${KWOTE_ID}"><![CDATA[${KWOTE_TEXT_XML}]]></kwote>

0
templates/xml/navigation Executable file
View File

View File

View File

4
templates/xml/search Executable file
View File

@ -0,0 +1,4 @@
<message>
There is no search form for the xml template
</message>