From 7e84ab0222a068e8936323184d10d7dec8112c82 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 19 Aug 2008 21:13:29 +0000 Subject: [PATCH] Add cms table, and move the 'index' pagetext to cms Add .htaccess rules for the cms Add cms page display code and convert index.php to pull from the cms If no page title is passed to send_header(), output the fair name in the tag --- .htaccess | 7 +++++++ common.inc.php | 30 +++++++++++++++++++++++++++++- db/db.code.version.txt | 2 +- db/db.update.111.php | 14 ++++++++++++++ db/db.update.111.sql | 10 ++++++++++ index.php | 7 +------ 6 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 db/db.update.111.php create mode 100644 db/db.update.111.sql diff --git a/.htaccess b/.htaccess index 35fd432..6ab9546 100644 --- a/.htaccess +++ b/.htaccess @@ -1 +1,8 @@ php_flag register_globals off +RewriteEngine On + +RewriteCond %{SCRIPT_FILENAME} !-f +RewriteCond %{SCRIPT_FILENAME} !-l +RewriteCond %{SCRIPT_FILENAME} !-d +RewriteRule ^web/(.*)$ cms.php?f=$1 [L] + diff --git a/common.inc.php b/common.inc.php index 9bd5022..36fb2a9 100644 --- a/common.inc.php +++ b/common.inc.php @@ -373,7 +373,7 @@ function send_header($title="", $nav=null) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > -<head><title><?=i18n($title)?> +<? if($title) echo i18n($title); else echo i18n($config['fairname']); ?> @@ -1008,6 +1008,34 @@ function output_page_text($textname) echo $r->text; } +function output_page_cms($filename) +{ + global $config; + $q=mysql_query("SELECT * FROM cms WHERE filename='".mysql_escape_string($filename)."' AND lang='".$_SESSION['lang']."' ORDER BY dt DESC LIMIT 1"); + if(mysql_num_rows($q)) + { + $r=mysql_fetch_object($q); + send_header($r->title); + + if(file_exists("data/logo-200.gif") && $r->showlogo==1) + echo ""; + + //if it looks like we have HTML content, dont do a nl2br, if there's no html, then do the nl2br + if(strlen($r->text)==strlen(strip_tags($r->text))) + echo nl2br($r->text); + else + echo $r->text; + } + else { + send_header(i18n("Error: File not found")); + echo error(i18n("The file you have requested (%1), does not exist on the server.",array($filename))); + return; + //not defined, lets grab the default text + } + + send_footer(); +} + function generatePassword($pwlen=8) { //these are good characters that are not easily confused with other characters :) diff --git a/db/db.code.version.txt b/db/db.code.version.txt index bc6298e..58c9bdf 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -110 +111 diff --git a/db/db.update.111.php b/db/db.update.111.php new file mode 100644 index 0000000..1f38031 --- /dev/null +++ b/db/db.update.111.php @@ -0,0 +1,14 @@ +lastupdate','$r->lang','".mysql_escape_string($r->text)."','1')"); + } + //and remove it from the pagetext + mysql_query("DELETE FROM pagetext WHERE textname='index' AND year='{$config['FAIRYEAR']}'"); +} +?> diff --git a/db/db.update.111.sql b/db/db.update.111.sql new file mode 100644 index 0000000..74b6554 --- /dev/null +++ b/db/db.update.111.sql @@ -0,0 +1,10 @@ +CREATE TABLE `cms` ( + `id` INT NOT NULL AUTO_INCREMENT , + `filename` VARCHAR( 128 ) NOT NULL , + `dt` DATETIME NOT NULL , + `lang` VARCHAR( 2 ) NOT NULL , + `title` VARCHAR( 128 ) NOT NULL , + `text` TEXT NOT NULL , + `showlogo` BOOL DEFAULT '0' NOT NULL , + PRIMARY KEY ( `id` ) +) TYPE = MYISAM ; diff --git a/index.php b/index.php index 36b54f9..19c4a1c 100644 --- a/index.php +++ b/index.php @@ -23,10 +23,5 @@ ?> "; - - output_page_text("index"); - send_footer(); + output_page_cms("index.html"); ?>