From 516c5fcb2b95ef1dc1b0f44624d732555fe09841 Mon Sep 17 00:00:00 2001 From: briandilley Date: Thu, 4 Nov 2004 19:27:04 +0000 Subject: [PATCH] Super duper modifications updated template system updated XML template updated HTML template masturbated --- Changelog | 4 ++ kwotes-lib.pl | 29 ++++++++++++-- kwotes.pl | 39 +++++++++++-------- .../{content-addform.html => add-kwote} | 0 ...t-addform-thanks.html => add-kwote-thanks} | 0 templates/default/after-list | 0 templates/default/before-list | 0 .../{content-default.html => default-content} | 0 .../default/{content-error.html => error} | 0 templates/default/{footer.html => footer} | 0 templates/default/{header.html => header} | 0 templates/default/http-headers | 2 + templates/default/kwote-even | 16 ++++++++ .../{content-show-kwote.html => kwote-odd} | 2 +- templates/default/kwotes.css | 9 ++++- ...{content-list-navigate.html => navigation} | 0 ...vigate-no-back.html => navigation-no-back} | 0 ...-no-forward.html => navigation-no-forward} | 0 .../default/{content-search.html => search} | 0 templates/xml/add-kwote | 5 +++ templates/xml/add-kwote-thanks | 2 + templates/xml/after-list | 2 + templates/xml/before-list | 2 + templates/xml/content-addform-thanks.html | 1 - templates/xml/content-error.html | 3 -- templates/xml/content-show-kwote.html | 3 -- templates/xml/default-content | 4 ++ templates/xml/error | 4 ++ templates/xml/{footer.html => footer} | 2 - templates/xml/{header.html => header} | 5 ++- templates/xml/http-headers | 2 + templates/xml/kwote-even | 2 + templates/xml/kwote-odd | 1 + templates/xml/navigation | 0 templates/xml/navigation-no-back | 0 templates/xml/navigation-no-forward | 0 templates/xml/search | 4 ++ 37 files changed, 110 insertions(+), 33 deletions(-) rename templates/default/{content-addform.html => add-kwote} (100%) rename templates/default/{content-addform-thanks.html => add-kwote-thanks} (100%) create mode 100755 templates/default/after-list create mode 100755 templates/default/before-list rename templates/default/{content-default.html => default-content} (100%) rename templates/default/{content-error.html => error} (100%) rename templates/default/{footer.html => footer} (100%) rename templates/default/{header.html => header} (100%) create mode 100644 templates/default/http-headers create mode 100755 templates/default/kwote-even rename templates/default/{content-show-kwote.html => kwote-odd} (95%) rename templates/default/{content-list-navigate.html => navigation} (100%) rename templates/default/{content-list-navigate-no-back.html => navigation-no-back} (100%) rename templates/default/{content-list-navigate-no-forward.html => navigation-no-forward} (100%) rename templates/default/{content-search.html => search} (100%) create mode 100755 templates/xml/add-kwote create mode 100755 templates/xml/add-kwote-thanks create mode 100755 templates/xml/after-list create mode 100755 templates/xml/before-list delete mode 100755 templates/xml/content-addform-thanks.html delete mode 100755 templates/xml/content-error.html delete mode 100755 templates/xml/content-show-kwote.html create mode 100755 templates/xml/default-content create mode 100755 templates/xml/error rename templates/xml/{footer.html => footer} (88%) rename templates/xml/{header.html => header} (82%) create mode 100755 templates/xml/http-headers create mode 100755 templates/xml/kwote-even create mode 100755 templates/xml/kwote-odd create mode 100755 templates/xml/navigation create mode 100755 templates/xml/navigation-no-back create mode 100755 templates/xml/navigation-no-forward create mode 100755 templates/xml/search diff --git a/Changelog b/Changelog index bc63df0..42628d3 100644 --- a/Changelog +++ b/Changelog @@ -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 diff --git a/kwotes-lib.pl b/kwotes-lib.pl index 62951f4..79b87dd 100755 --- a/kwotes-lib.pl +++ b/kwotes-lib.pl @@ -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("",); + 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"); diff --git a/kwotes.pl b/kwotes.pl index 335100e..6b142ff 100755 --- a/kwotes.pl +++ b/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); diff --git a/templates/default/content-addform.html b/templates/default/add-kwote similarity index 100% rename from templates/default/content-addform.html rename to templates/default/add-kwote diff --git a/templates/default/content-addform-thanks.html b/templates/default/add-kwote-thanks similarity index 100% rename from templates/default/content-addform-thanks.html rename to templates/default/add-kwote-thanks diff --git a/templates/default/after-list b/templates/default/after-list new file mode 100755 index 0000000..e69de29 diff --git a/templates/default/before-list b/templates/default/before-list new file mode 100755 index 0000000..e69de29 diff --git a/templates/default/content-default.html b/templates/default/default-content similarity index 100% rename from templates/default/content-default.html rename to templates/default/default-content diff --git a/templates/default/content-error.html b/templates/default/error similarity index 100% rename from templates/default/content-error.html rename to templates/default/error diff --git a/templates/default/footer.html b/templates/default/footer similarity index 100% rename from templates/default/footer.html rename to templates/default/footer diff --git a/templates/default/header.html b/templates/default/header similarity index 100% rename from templates/default/header.html rename to templates/default/header diff --git a/templates/default/http-headers b/templates/default/http-headers new file mode 100644 index 0000000..844a971 --- /dev/null +++ b/templates/default/http-headers @@ -0,0 +1,2 @@ +Content-Type: text/html + diff --git a/templates/default/kwote-even b/templates/default/kwote-even new file mode 100755 index 0000000..698a387 --- /dev/null +++ b/templates/default/kwote-even @@ -0,0 +1,16 @@ +
+ #${KWOTE_ID} + + - + ${KWOTE_RATING} + + + + +
+ ${KWOTE_TEXT_HTML} +
+
diff --git a/templates/default/content-show-kwote.html b/templates/default/kwote-odd similarity index 95% rename from templates/default/content-show-kwote.html rename to templates/default/kwote-odd index 4fe8a39..ec93f54 100755 --- a/templates/default/content-show-kwote.html +++ b/templates/default/kwote-odd @@ -1,4 +1,4 @@ -
+
#${KWOTE_ID} + There isn't an add kwote page for the xml + template because it is intended to be used + by non human processes + diff --git a/templates/xml/add-kwote-thanks b/templates/xml/add-kwote-thanks new file mode 100755 index 0000000..7fdfffc --- /dev/null +++ b/templates/xml/add-kwote-thanks @@ -0,0 +1,2 @@ + + diff --git a/templates/xml/after-list b/templates/xml/after-list new file mode 100755 index 0000000..055b5a9 --- /dev/null +++ b/templates/xml/after-list @@ -0,0 +1,2 @@ + + diff --git a/templates/xml/before-list b/templates/xml/before-list new file mode 100755 index 0000000..cc16e30 --- /dev/null +++ b/templates/xml/before-list @@ -0,0 +1,2 @@ + + diff --git a/templates/xml/content-addform-thanks.html b/templates/xml/content-addform-thanks.html deleted file mode 100755 index ba95e12..0000000 --- a/templates/xml/content-addform-thanks.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/templates/xml/content-error.html b/templates/xml/content-error.html deleted file mode 100755 index 15cf757..0000000 --- a/templates/xml/content-error.html +++ /dev/null @@ -1,3 +0,0 @@ - -${ERROR_MESSAGE} - diff --git a/templates/xml/content-show-kwote.html b/templates/xml/content-show-kwote.html deleted file mode 100755 index 8a67e5d..0000000 --- a/templates/xml/content-show-kwote.html +++ /dev/null @@ -1,3 +0,0 @@ - - ${KWOTE_TEXT_XML} - diff --git a/templates/xml/default-content b/templates/xml/default-content new file mode 100755 index 0000000..b0fa883 --- /dev/null +++ b/templates/xml/default-content @@ -0,0 +1,4 @@ + + The XML template doesn't have a default content + + diff --git a/templates/xml/error b/templates/xml/error new file mode 100755 index 0000000..199afca --- /dev/null +++ b/templates/xml/error @@ -0,0 +1,4 @@ + + ${ERROR_MESSAGE} + + diff --git a/templates/xml/footer.html b/templates/xml/footer similarity index 88% rename from templates/xml/footer.html rename to templates/xml/footer index c87ed0f..69fe90c 100755 --- a/templates/xml/footer.html +++ b/templates/xml/footer @@ -1,5 +1,3 @@ - - diff --git a/templates/xml/header.html b/templates/xml/header similarity index 82% rename from templates/xml/header.html rename to templates/xml/header index d31993f..aee9f9f 100755 --- a/templates/xml/header.html +++ b/templates/xml/header @@ -2,8 +2,9 @@ ${SITE_NAME} - ${TAG_LINE} + ${TAG_LINE} ${KWOTE_COUNT} ${KWOTE_BACKUP_COUNT} - + + diff --git a/templates/xml/http-headers b/templates/xml/http-headers new file mode 100755 index 0000000..9518470 --- /dev/null +++ b/templates/xml/http-headers @@ -0,0 +1,2 @@ +Content-type: text/xml + diff --git a/templates/xml/kwote-even b/templates/xml/kwote-even new file mode 100755 index 0000000..776242c --- /dev/null +++ b/templates/xml/kwote-even @@ -0,0 +1,2 @@ + + diff --git a/templates/xml/kwote-odd b/templates/xml/kwote-odd new file mode 100755 index 0000000..ac9d915 --- /dev/null +++ b/templates/xml/kwote-odd @@ -0,0 +1 @@ + diff --git a/templates/xml/navigation b/templates/xml/navigation new file mode 100755 index 0000000..e69de29 diff --git a/templates/xml/navigation-no-back b/templates/xml/navigation-no-back new file mode 100755 index 0000000..e69de29 diff --git a/templates/xml/navigation-no-forward b/templates/xml/navigation-no-forward new file mode 100755 index 0000000..e69de29 diff --git a/templates/xml/search b/templates/xml/search new file mode 100755 index 0000000..83ecb7a --- /dev/null +++ b/templates/xml/search @@ -0,0 +1,4 @@ + + There is no search form for the xml template + +