Super duper modifications
updated template system updated XML template updated HTML template masturbated
This commit is contained in:
parent
1410c9d0e8
commit
516c5fcb2b
@ -1,3 +1,7 @@
|
||||
11-04-04
|
||||
* changed the template system
|
||||
* updated the html and xml template
|
||||
|
||||
11-01-04
|
||||
* added support for templates
|
||||
* added xml template
|
||||
|
@ -3,6 +3,22 @@
|
||||
# we use DBI, for it's sexy body
|
||||
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
|
||||
my $GLOBAL_DBH = undef;
|
||||
|
||||
@ -326,13 +342,18 @@ sub xml_escape {
|
||||
}
|
||||
|
||||
##
|
||||
# Sends the HTML header
|
||||
sub send_html_header {
|
||||
print STDOUT "Content-type: text/html\n\n";
|
||||
# Returns the appropriate http headers based
|
||||
# on the template
|
||||
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 {
|
||||
my ($template, $template_file, %vars) = @_;
|
||||
open(IN,"templates/$template/$template_file");
|
||||
|
39
kwotes.pl
39
kwotes.pl
@ -45,13 +45,13 @@ $vars{TAG_LINE} = get_tagline();
|
||||
$vars{TEMPLATE_DIR} = "templates/$template";
|
||||
|
||||
# send header
|
||||
send_html_header();
|
||||
print get_template_headers($template)."\n\n";
|
||||
|
||||
############
|
||||
# action: add (show add form)
|
||||
if ($action eq "add") {
|
||||
$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)
|
||||
@ -60,7 +60,7 @@ if ($action eq "add") {
|
||||
if ($FORM{"content"} eq "") {
|
||||
$vars{TITLE} = "An Error Occured";
|
||||
$vars{ERROR_MESSAGE} = "No text entered";
|
||||
$main_content = wrap_template($template, "content-error.html",%vars);
|
||||
$main_content = wrap_template($template, $CONTENT_ERROR, %vars);
|
||||
|
||||
} else {
|
||||
|
||||
@ -72,13 +72,13 @@ if ($action eq "add") {
|
||||
if (!defined($kid)) {
|
||||
$vars{TITLE} = "An Error Occured";
|
||||
$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
|
||||
} else {
|
||||
$vars{TITLE} = "Kwote Added";
|
||||
$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)) {
|
||||
$vars{TITLE} = "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
|
||||
} else {
|
||||
@ -105,7 +105,7 @@ if ($action eq "add") {
|
||||
$vars{KWOTE_TEXT_XML} = xml_escape($kwote->{'content'});
|
||||
$vars{KWOTE_TEXT_PLAIN} = $kwote->{'content'};
|
||||
$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
|
||||
if ($FORM{"o"} ne "random" && $start_index<=0 && @rows>=$max_returned
|
||||
&& ($start_index+$max_returned)<$max_records) {
|
||||
$navigation_template = "content-list-navigate-no-back.html";
|
||||
$navigation_template = $NAVIGATION_NO_BACK;
|
||||
|
||||
# forward and back
|
||||
} elsif ($FORM{"o"} ne "random" && $start_index>0 && @rows>=$max_returned
|
||||
&& ($start_index+$max_returned)<$max_records ) {
|
||||
$navigation_template = "content-list-navigate.html";
|
||||
$navigation_template = $NAVIGATION;
|
||||
|
||||
# back only
|
||||
} 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
|
||||
$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
|
||||
if (defined(@rows)) {
|
||||
for (my $i=0; $i<@rows && ($i+$start_index)<$max_records; $i++) {
|
||||
my $row = $rows[$i];
|
||||
my $kwote_template = (($i % 2) != 0) ? $KWOTE_ODD : $KWOTE_EVEN;
|
||||
$vars{KWOTE_ID} = $row->{'id'};
|
||||
$vars{KWOTE_TEXT_HTML} = html_escape($row->{'content'});
|
||||
$vars{KWOTE_TEXT_XML} = xml_escape($row->{'content'});
|
||||
$vars{KWOTE_TEXT_PLAIN} = $row->{'content'};
|
||||
$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
|
||||
$main_content .= wrap_template($template, $navigation_template, %vars);
|
||||
|
||||
@ -208,7 +215,7 @@ if ($action eq "add") {
|
||||
# action: search (show the search page)
|
||||
} elsif ($action eq "search") {
|
||||
$vars{TITLE} = "Search";
|
||||
$main_content = wrap_template($template, "content-search.html", %vars);
|
||||
$main_content = wrap_template($template, $CONTENT_SEARCH, %vars);
|
||||
|
||||
##########
|
||||
# action: love
|
||||
@ -228,11 +235,11 @@ if ($action eq "add") {
|
||||
# show the homepage
|
||||
} else {
|
||||
$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
|
||||
render_template($template, "header.html", %vars);
|
||||
render_template($template, $HEADER, %vars);
|
||||
print STDOUT $main_content;
|
||||
render_template($template, "footer.html", %vars);
|
||||
render_template($template, $FOOTER, %vars);
|
||||
|
0
templates/default/after-list
Executable file
0
templates/default/after-list
Executable file
0
templates/default/before-list
Executable file
0
templates/default/before-list
Executable file
2
templates/default/http-headers
Normal file
2
templates/default/http-headers
Normal file
@ -0,0 +1,2 @@
|
||||
Content-Type: text/html
|
||||
|
16
templates/default/kwote-even
Executable file
16
templates/default/kwote-even
Executable file
@ -0,0 +1,16 @@
|
||||
<div class="kwote-even">
|
||||
<span class="kwote-id"><a href="?action=show&id=${KWOTE_ID}">#${KWOTE_ID}</a></span>
|
||||
<span class="vote-controls">
|
||||
<a href="?action=hate&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&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>
|
@ -1,4 +1,4 @@
|
||||
<div class="kwote">
|
||||
<div class="kwote-odd">
|
||||
<span class="kwote-id"><a href="?action=show&id=${KWOTE_ID}">#${KWOTE_ID}</a></span>
|
||||
<span class="vote-controls">
|
||||
<a href="?action=hate&kid=${KWOTE_ID}"
|
@ -62,12 +62,19 @@ a img
|
||||
}
|
||||
|
||||
/* Kwotes */
|
||||
.kwote
|
||||
.kwote-odd
|
||||
{
|
||||
position: relative;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.kwote-even
|
||||
{
|
||||
position: relative;
|
||||
margin-bottom: 10px;
|
||||
background-color: #e9e9e9;
|
||||
}
|
||||
|
||||
.kwote-id
|
||||
{
|
||||
float: left;
|
||||
|
5
templates/xml/add-kwote
Executable file
5
templates/xml/add-kwote
Executable 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
2
templates/xml/add-kwote-thanks
Executable file
@ -0,0 +1,2 @@
|
||||
|
||||
<kwote-added id="${KWOTE_ID}" />
|
2
templates/xml/after-list
Executable file
2
templates/xml/after-list
Executable file
@ -0,0 +1,2 @@
|
||||
|
||||
</kwotes>
|
2
templates/xml/before-list
Executable file
2
templates/xml/before-list
Executable file
@ -0,0 +1,2 @@
|
||||
<kwotes>
|
||||
|
@ -1 +0,0 @@
|
||||
<kwote-added id="${KWOTE_ID" />
|
@ -1,3 +0,0 @@
|
||||
|
||||
<error>${ERROR_MESSAGE}</error>
|
||||
|
@ -1,3 +0,0 @@
|
||||
<kwote id="${KWOTE_ID}" rating="${KWOTE_RATING}">
|
||||
${KWOTE_TEXT_XML}
|
||||
</kwote>
|
4
templates/xml/default-content
Executable file
4
templates/xml/default-content
Executable file
@ -0,0 +1,4 @@
|
||||
<message>
|
||||
The XML template doesn't have a default content
|
||||
</message>
|
||||
|
4
templates/xml/error
Executable file
4
templates/xml/error
Executable file
@ -0,0 +1,4 @@
|
||||
<message>
|
||||
${ERROR_MESSAGE}
|
||||
</message>
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
</kwotes.org>
|
||||
|
||||
|
@ -2,8 +2,9 @@
|
||||
|
||||
<site>
|
||||
<name>${SITE_NAME}</name>
|
||||
<tag-line>${TAG_LINE}</tag-line>
|
||||
<tagline>${TAG_LINE}</tagline>
|
||||
<kwote-count>${KWOTE_COUNT}</kwote-count>
|
||||
<deleted-kwote-count>${KWOTE_BACKUP_COUNT}</deleted-kwote-count>
|
||||
</site>
|
||||
|
||||
|
||||
|
2
templates/xml/http-headers
Executable file
2
templates/xml/http-headers
Executable file
@ -0,0 +1,2 @@
|
||||
Content-type: text/xml
|
||||
|
2
templates/xml/kwote-even
Executable file
2
templates/xml/kwote-even
Executable file
@ -0,0 +1,2 @@
|
||||
|
||||
<kwote id="${KWOTE_ID}"><![CDATA[${KWOTE_TEXT_XML}]]></kwote>
|
1
templates/xml/kwote-odd
Executable file
1
templates/xml/kwote-odd
Executable file
@ -0,0 +1 @@
|
||||
<kwote id="${KWOTE_ID}"><![CDATA[${KWOTE_TEXT_XML}]]></kwote>
|
0
templates/xml/navigation
Executable file
0
templates/xml/navigation
Executable file
0
templates/xml/navigation-no-back
Executable file
0
templates/xml/navigation-no-back
Executable file
0
templates/xml/navigation-no-forward
Executable file
0
templates/xml/navigation-no-forward
Executable file
4
templates/xml/search
Executable file
4
templates/xml/search
Executable file
@ -0,0 +1,4 @@
|
||||
<message>
|
||||
There is no search form for the xml template
|
||||
</message>
|
||||
|
Loading…
Reference in New Issue
Block a user