VERSION HISTORY for what's new and current bugfixes.
Author: Oliver Seidel
Version: 10.0
Author URI: http://www.deliciousdays.com
*/
/*
Copyright 2006-2008 Oliver Seidel (email : oliver.seidel@deliciousdays.com)
WHAT's NEW in cformsII - v10.0
README:
v9.0 introduces a completely new method of storing its settings,
***** please make a WP database backup first (!) *****
and then migrate your settings (cforms will guide you!)
*) feature: "manual/help page" now also offered in form of a PDF (see help page)
*) feature: enhanced Opera Browser support
*) feature: complete admin UI update: WP2.7'ized it (code and CSS)
*) feature: multi-part/-page form support
*) feature: added dashboard support for WP 2.7
*) feature: general enhancements on tracking page (time stamps on entries etc)
*) bugfix: regexp now allow OR | operator,e .g. ^(a|b)c
*) bugfix: datepicker localization for admin interface
*) bugfix: email verification fields (special regexp) would not work with custom err messages
*) bugfix: fixed install bug that appeared on some WP 2.7 deployments (redeclare err)
*) bugfix: fixed captcha issue for nonAjax forms
*) bugfix: insert_cform() would show the default form versus a specified one
*) bugfix: minor admin email issue re: inclusion of CAPTCHA input
*) other: updated and cleaned up help page
*) other: much improved admin captcha config preview (no saving necessary for preview anymore!)
*) other: made some admin UI changes (font alternatives)
*) other: enhanced handling of duplicate form fields for tracking/admin email (no more __x suffixes)
*) other: revamped admin email assembly process
*/
$localversion = '10.0';
### db settings
global $wpdb, $wp_db_version;
$wpdb->cformssubmissions = $wpdb->prefix . 'cformssubmissions';
$wpdb->cformsdata = $wpdb->prefix . 'cformsdata';
### button stuff
if( !class_exists('buttonsnap') )
require_once (dirname(__FILE__) . '/buttonsnap.php');
require_once(dirname(__FILE__) . '/lib_functions.php');
### new global settings container, will eventually be the only one!
global $cformsSettings;
$cformsSettings = get_option('cforms_settings');
### do a couple of things necessary as part of plugin activation
$dummy = __('Please go to the cforms admin page and run the update process.', 'cforms');
add_action('admin_notices', create_function('', 'global $plugindir, $cformsSettings; if (is_array($cformsSettings) && $cformsSettings[\'global\'][\'update\']) echo \'
\' . sprintf( __(\'Please go to the cforms admin page and run the update process.\', \'cforms\') ,\'admin.php?page=\'.$plugindir.\'/cforms-global-settings.php\') . \'
\';') );
function cforms_activate() {
cforms_init();
require_once(dirname(__FILE__) . '/lib_activate.php');
}
add_action('activate_' . plugin_basename(__FILE__), 'cforms_activate' );
### settings corrputed?
if ( !is_array($cformsSettings) ){
add_action('admin_menu', 'settings_corrupted');
return;
}
### if all data has been erased quit
function settings_corrupted() {
$tmp = basename(dirname(__FILE__));
if (function_exists('add_menu_page')){
add_menu_page(__('cformsII', 'cforms'), __('cformsII', 'cforms'), 'manage_cforms', $tmp.'/cforms-corrupted.php', '', get_cf_plugindir().'/'.$tmp.'/images/cformsicon.gif' );
add_submenu_page($tmp.'/cforms-corrupted.php', __('Corrupted Settings', 'cforms'), __('Corrupted Settings', 'cforms'), 'manage_cforms', $tmp.'/cforms-corrupted.php' );
}
elseif (function_exists('add_management_page'))
add_management_page(__('cformsII', 'cforms'), __('cformsII', 'cforms'), 'manage_cforms', $tmp.'/cforms-corrupted.php');
add_action('wp_print_scripts', 'cforms_scripts_corrupted' );
}
function cforms_scripts_corrupted(){
echo '' . "\n";
}
require_once (dirname(__FILE__) . '/lib_aux.php');
require_once (dirname(__FILE__) . '/editor.php');
### http://trac.wordpress.org/ticket/3002
$plugindir = $cformsSettings['global']['plugindir'];
$cforms_root = $cformsSettings['global']['cforms_root'];
### multi-page forms
add_action('template_redirect', 'start_cforms_session');
function start_cforms_session() {
@session_cache_limiter('private, must-revalidate');
@session_cache_expire(0);
@session_start();
}
###
### main function
###
function cforms($args = '',$no = '') {
global $smtpsettings, $styles, $subID, $cforms_root, $wpdb, $track, $wp_db_version, $cformsSettings;
parse_str($args, $r);
$oldno = $no; ### remeber old val, to reset session when in new MP form
### multi page form: overwrite $no
if( is_array($_SESSION['cforms']) && $_SESSION['cforms']['current']>0 )
$no = $_SESSION['cforms']['current'];
### Safety, in case someone uses '1' for the default form
$no = ($no=='1')?'':$no;
$moveBack=false;
### multi page form: reset button
if( isset($_REQUEST['resetbutton'.$no]) && is_array($_SESSION['cforms']) ){
$no = $_SESSION['cforms']['first'];
unset($_SESSION['cforms']);
$_SESSION['cforms']['current']=0;
$_SESSION['cforms']['first']=$no;
$_SESSION['cforms']['pos']=1;
}
else
### multi page form: back button
if( isset($_REQUEST['backbutton'.$no]) && isset($_SESSION['cforms']) && ($_SESSION['cforms']['pos']-1)>=0){
$no = $_SESSION['cforms']['list'][($_SESSION['cforms']['pos']--)-1];
$_SESSION['cforms']['current']=$no;
$moveBack=true;
}
else ### must be else otherwise back would also trigger reset!
### multi page form: init, no session active
if( $cformsSettings['form'.$no]['mp']['cforms'.$no.'_mp_form'] && $cformsSettings['form'.$no]['mp']['cforms'.$no.'_mp_first'] ){
if ( is_array($_SESSION['cforms']) ){
$no = ($oldno=='1')?'':$oldno; ### restore old val
unset($_SESSION['cforms']);
}
$_SESSION['cforms']['current']=0;
$_SESSION['cforms']['first']=$no;
$_SESSION['cforms']['pos']=1;
}
### custom fields support
if ( !(strpos($no,'+') === false) ) {
$no = substr($no,0,-1);
$customfields = build_fstat($args);
$field_count = count($customfields);
$custom=true;
} else {
$custom=false;
$field_count = $cformsSettings['form'.$no]['cforms'.$no.'_count_fields'];
}
$content = '';
$err=0;
$filefield=0; ### for multiple file upload fields
$validations = array();
$all_valid = 1;
$off=0;
$fieldsetnr=1;
$c_errflag=false;
$custom_error='';
$usermessage_class='';
### ??? check for WP2.0.2
if ( $wp_db_version >= 3440 && function_exists('wp_get_current_user') )
$user = wp_get_current_user();
if( isset($_REQUEST['sendbutton'.$no]) ) { /* alternative sending: both events r ok! */
require_once (dirname(__FILE__) . '/lib_nonajax.php');
$usermessage_class = $all_valid?' success':' failure';
}
if ( substr($cformsSettings['form'.$no]['cforms'.$no.'_tellafriend'],0,1)=='2' && $send2author ) ### called from lib_WPcomments ?
return $all_valid;
###
### paint form
###
$success=false;
if ( isset($_GET['cfemail']) && substr($cformsSettings['form'.$no]['cforms'.$no.'_tellafriend'],0,1)=='2' ){ ### fix for WP Comment (loading after redirect)
$usermessage_class = ' success';
$success=true;
if ( $_GET['cfemail']=='sent' )
$usermessage_text = preg_replace ( '|\r\n|', ' ', stripslashes($cformsSettings['form'.$no]['cforms'.$no.'_success']) );
elseif ( $_GET['cfemail']=='posted' )
$usermessage_text = preg_replace ( '|\r\n|', ' ', stripslashes($cformsSettings['form'.$no]['cforms_commentsuccess']) );
}
$break=' ';
$nl="\n";
$tab="\t";
$tt="\t\t";
$ntt="\n\t\t";
$nttt="\n\t\t\t";
### either show message above or below
$usermessage_text = check_default_vars($usermessage_text,$no);
$usermessage_text = check_cust_vars($usermessage_text,$track,$no);
$umc = ($usermessage_class<>''&&$no>1)?' '.$usermessage_class.$no:'';
if( substr($cformsSettings['form'.$no]['cforms'.$no.'_showpos'],0,1)=='y' ) {
$content .= $ntt . '