From 4f94560f060a7305ea791def3950adb1bda092ec Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Thu, 14 Jun 2007 07:41:00 -0400 Subject: [PATCH 01/16] fixed session_purge_old() and session_messages.php, redirect() can now take just a path --- http.php | 26 ++++++++++++++++++++++++-- session.php | 6 +++++- session_messages.php | 8 ++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/http.php b/http.php index c7c457a..94dbff1 100644 --- a/http.php +++ b/http.php @@ -19,8 +19,8 @@ # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# return our best guess at the url used to access this page -function this_url() { +# return our best guess at the url used to access this page, without the path or query string +function this_url_sans_path() { list($protocol, $version) = explode('/', $_SERVER['SERVER_PROTOCOL']); $url = strtolower($protocol); @@ -42,15 +42,37 @@ function this_url() { } } + return $url; +} + +# return our best guess at the url used to access this page +function this_url() { + $url = this_url_sans_path(); + $url .= $_SERVER['REQUEST_URI']; return $url; } +# sends an HTTP redirect +# +# $url can be: +# 1) a full URL +# 2) an absolute path +# 3) a filename (you can pass a directory/file.html and such, but "../" prefix is not supported) function redirect($url, $status = '302 Moved Temporarily', $message = '') { + if(!strpos($url, ':')) { + if(substr($url, 0, 1) == '/') { + $url = this_url_sans_path() . $url; + } else { + $url = ereg_replace('/[^/]*([?].*)?$', "/$url", this_url()); + } + } + if(function_exists('session_save_messages')) { session_save_messages(); } + header("HTTP/1.0 $status"); header("Location: $url"); echo($message); diff --git a/session.php b/session.php index c3be9e9..b04ed57 100644 --- a/session.php +++ b/session.php @@ -100,7 +100,7 @@ function _kill_session($id) { # delete expired sessions from database function session_purge_old() { $now = time(); - $exired_sessions = db_get_column('wfpl_sessions', 'id', 'where expires < %i', $now); + $expired_sessions = db_get_column('wfpl_sessions', 'id', 'where expires < %i', $now); if($expired_sessions) foreach($expired_sessions as $expired_session) { _kill_session($expired_session); } @@ -112,6 +112,10 @@ function session_exists() { return false; } + if(isset($GLOBALS['session_id'])) { + return true; + } + $session_key = ereg_replace('[^a-zA-Z0-9]', '', $_REQUEST['session_key']); if(!strlen($session_key) == 16) { diff --git a/session_messages.php b/session_messages.php index 358994c..c3e16f0 100644 --- a/session_messages.php +++ b/session_messages.php @@ -39,18 +39,22 @@ function session_save_messages() { } init_session(); - session_set('wfpl_messages', array_to_string($GLOBALS['wfpl_messages']); + session_set('wfpl_messages', array_to_string($GLOBALS['wfpl_messages'])); } function session_restore_messages() { - if(!session()) { + if(!session_exists()) { return false; } $messages = session_get('wfpl_messages'); if($messages !== false) { $messages = string_to_array($messages); + if(!(isset($GLOBALS['wfpl_messages']) && is_array($GLOBALS['wfpl_messages']))) { + $GLOBALS['wfpl_messages'] = array(); + } # messages from the previous run happened first $GLOBALS['wfpl_messages'] = array_merge($messages, $GLOBALS['wfpl_messages']); + } session_clear('wfpl_messages'); } -- 1.7.10.4 From 4aaf7daac479c97869e5e1ab9b8afc796043fb91 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Fri, 15 Jun 2007 03:53:30 -0400 Subject: [PATCH 02/16] metaform capitalizes default captions, added tem::load_str() metaform preview is passed through template engine properly --- format.php | 5 +++++ metaform.php | 8 ++++++-- template.php | 14 +++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/format.php b/format.php index 055e66d..8979b26 100644 --- a/format.php +++ b/format.php @@ -21,6 +21,11 @@ # This file contains basic encodings +function format_caption($str) { + $str = ucwords($str); + return str_replace('Email', 'E-mail', $str); +} + function format_int($str) { $str = ereg_replace('[^0-9]', '', $str); return ereg_replace('^0*([1-9])', '\1', $str); diff --git a/metaform.php b/metaform.php index 1119d0c..c8bb395 100644 --- a/metaform.php +++ b/metaform.php @@ -187,7 +187,7 @@ function make_html($whole_file = true) { foreach($fields as $field) { list($name, $type, $input, $format, $sql) = $field; $tem->set('name', $name); - $tem->set('caption', $name); # fixme + $tem->set('caption', format_caption($name)); $tem->sub($input); if($input != 'hidden') { $tem->sub('row'); @@ -345,7 +345,11 @@ function preview() { tem_set('form_name', $GLOBALS['form_name']); tem_set('fields', $_REQUEST['fields']); $preview_tem = new tem(); - $preview = $preview_tem->run(make_html(false)); + $preview_tem->load_str(make_html(false)); + if($GLOBALS['opt_db'] == 'Yes') { + $preview_tem->sub('new_msg'); + } + $preview = $preview_tem->run(); unset($preview_tem); tem_set('preview', $preview); set_form_action(); diff --git a/template.php b/template.php index e386fe2..28b4814 100644 --- a/template.php +++ b/template.php @@ -130,16 +130,20 @@ class tem { } #repeat } + # like load() except you pass a string instead of a filename + function load_str($str) { + $this->template = ''; + $parents = array('top_level_subs' => array()); + $parent = 'top_level_subs'; + $this->_load($str, $this->template, $parents, $parent); + } + # This is useful when you have sub-templates that you want to mess with # before the main template is run. But can also be used to simply specify # the filename ahead of time. function load($filename) { $this->filename = $filename; - $tmp = read_whole_file($filename); - $this->template = ''; - $parents = array('top_level_subs' => array()); - $parent = 'top_level_subs'; - $this->_load($tmp, $this->template, $parents, $parent); + $this->load_str(read_whole_file($filename)); } # Run the template. Pass a filename, or a string, unless you've already -- 1.7.10.4 From 7add2ea3f61e40c5f0f5539ac6e02533c9390db4 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Fri, 15 Jun 2007 08:00:34 -0400 Subject: [PATCH 03/16] metaform: added pulldown support, added leftcheck metaform now ships a seperate stylesheet. metaform captions are cleaned up (underscores to spaces and capitalization) metaform's generated php has less duplication added enc_upper() enc_whatever functions can recieve the field name as the second parameter format_options() forces the value to be something in the options list metaform's auto-generated submit button says "Send" if it's e-mail only --- encode.php | 111 +++++++++++++++++++++++++++++++++++++++++--- format.php | 14 ++++++ metaform.php | 39 +++++++++++++--- metaform/htaccess | 3 ++ metaform/preview.html | 4 +- metaform/style.css | 18 +++++++ metaform/template.htaccess | 3 -- metaform/template.html | 9 +--- metaform/template.php | 24 +++++++--- template.php | 2 +- 10 files changed, 193 insertions(+), 34 deletions(-) create mode 100644 metaform/htaccess create mode 100644 metaform/style.css delete mode 100644 metaform/template.htaccess diff --git a/encode.php b/encode.php index a4c4587..38b09bd 100644 --- a/encode.php +++ b/encode.php @@ -89,20 +89,119 @@ function enc_tab($str) { return substr($out, 0, -1); } +function enc_upper($str) { + return strtoupper($str); +} + # display