';
// HTML message part?
$html_show_ac = ( substr(get_option('cforms'.$no.'_formdata'),3,1)=='1' )?true:false;
$automessage = '';
$headers2 = "From: ". $frommail . $eol;
$headers2.= "Reply-To: " . $replyto . $eol;
if ( substr(get_option('cforms'.$no.'_tellafriend'),0,1)=='1' ) //TAF: add CC
$headers2.= "CC: " . $replyto . $eol;
$headers2.= "MIME-Version: 1.0" .$eol;
if( $html_show_ac || ($html_show && $ccme) ){
$headers2.= "Content-Type: multipart/alternative; boundary=\"----MIME_BOUNDRY_main_message\"";
$automessage = "This is a multi-part message in MIME format." . $eol;
$automessage .= "------MIME_BOUNDRY_main_message" . $eol;
$automessage .= "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"" . $eol;
$automessage .= "Content-Transfer-Encoding: quoted-printable" . $eol . $eol;
}
else
$headers2.= "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"";
// actual user message
$cmsg = get_option('cforms'.$no.'_cmsg');
$cmsg = check_default_vars($cmsg,$no);
$cmsg = check_cust_vars($cmsg,$track);
// text text
$automessage .= $cmsg . $eol;
// HTML text
if ( $html_show_ac ) {
// actual user message
$cmsghtml = get_option('cforms'.$no.'_cmsg_html');
$cmsghtml = check_default_vars($cmsghtml,$no);
$cmsghtml = str_replace(array("=","\n"),array("=3D","
\n"), check_cust_vars($cmsghtml,$track) );
$automessage .= "------MIME_BOUNDRY_main_message" . $eol;
$automessage .= "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"". $eol;
$automessage .= "Content-Transfer-Encoding: quoted-printable" . $eol . $eol;;
$automessage .= "" . $eol;
$automessage .= "" . $eol;
$automessage .= $cmsghtml;
$automessage .= "" . $eol . $eol;
}
// replace variables
$subject2 = get_option('cforms'.$no.'_csubject');
$subject2 = check_default_vars($subject2,$no);
$subject2 = check_cust_vars($subject2,$track);
// different cc & ac subjects?
$t = explode('$#$',$subject2);
$t[1] = ($t[1]<>'') ? $t[1] : $t[0];
// email tracking via 3rd party?
$field_email = (get_option('cforms'.$no.'_tracking')<>'')?$field_email.get_option('cforms'.$no.'_tracking'):$field_email;
// if in Tell-A-Friend Mode, then overwrite header stuff...
if ( $taf_youremail && $taf_friendsemail && substr(get_option('cforms'.$no.'_tellafriend'),0,1)=='1' )
$field_email = "\"{$taf_friendsname}\" <{$taf_friendsemail}>";
if ( $ccme ) {
if ( $smtpsettings[0]=='1' )
$sent = cforms_phpmailer( $no, $frommail, $replyto, $field_email, stripslashes($t[1]), $message, $formdata, $htmlmessage, $htmlformdata,'ac' );
else
$sent = @mail($field_email, encode_header(stripslashes($t[1])), $fmessage, $headers2); //takes $message!!
}
else {
if ( $smtpsettings[0]=='1' )
$sent = cforms_phpmailer( $no, $frommail, $replyto, $field_email, stripslashes($t[0]) , $cmsg , '', $cmsghtml, '','ac' );
else
$sent = @mail($field_email, encode_header(stripslashes($t[0])), stripslashes($automessage), $headers2);
}
if( $sent<>'1' ) {
$err = __('Error occurred while sending the auto confirmation message: ','cforms') . ($smtpsettings[0]?" ($sent)":'');
$pre = $segments[0].'*$#'.substr(get_option('cforms'.$no.'_popup'),1,1);
return $pre . $err .'|!!!';
}
} // cc
$hide='';
// redirect to a different page on suceess?
if ( get_option('cforms'.$no.'_redirect')==1 ) {
return get_option('cforms'.$no.'_redirect_page');
}
else if ( get_option('cforms'.$no.'_redirect')==2 || get_cforms_submission_left($no)==0 )
$hide = '|~~~';
// return success msg
$pre = $segments[0].'*$#'.substr(get_option('cforms'.$no.'_popup'),0,1);
return $pre . preg_replace ( '|\r\n|', '
', stripslashes(get_option('cforms'.$no.'_success'))) . $hide;
} // no admin mail sent!
else {
// return error msg
$err = __('Error occurred while sending the message: ','cforms') . ($smtpsettings[0]?'
'.$sentadmin:'');
$pre = $segments[0].'*$#'.substr(get_option('cforms'.$no.'_popup'),1,1);
return $pre . $err .'|!!!';
}
} //function
//
// sajax stuff
//
if (!isset($SAJAX_INCLUDED)) {
$GLOBALS['sajax_version'] = '0.12';
$GLOBALS['sajax_debug_mode'] = 0;
$GLOBALS['sajax_export_list'] = array();
$GLOBALS['sajax_request_type'] = 'POST';
$GLOBALS['sajax_remote_uri'] = '';
$GLOBALS['sajax_failure_redirect'] = '';
function sajax_init() {
}
function sajax_get_my_uri() {
return $_SERVER["REQUEST_URI"];
}
$sajax_remote_uri = sajax_get_my_uri();
function sajax_get_js_repr($value) {
$type = gettype($value);
if ($type == "boolean") {
return ($value) ? "Boolean(true)" : "Boolean(false)";
}
elseif ($type == "integer") {
return "parseInt($value)";
}
elseif ($type == "double") {
return "parseFloat($value)";
}
elseif ($type == "array" || $type == "object" ) {
$s = "{ ";
if ($type == "object") {
$value = get_object_vars($value);
}
foreach ($value as $k=>$v) {
$esc_key = sajax_esc($k);
if (is_numeric($k))
$s .= "$k: " . sajax_get_js_repr($v) . ", ";
else
$s .= "\"$esc_key\": " . sajax_get_js_repr($v) . ", ";
}
if (count($value))
$s = substr($s, 0, -2);
return $s . " }";
}
else {
$esc_val = sajax_esc($value);
$s = "'$esc_val'";
return $s;
}
}
function sajax_handle_client_request() {
global $sajax_export_list;
$mode = "";
if (! empty($_GET["rs"]))
$mode = "get";
if (!empty($_POST["rs"]))
$mode = "post";
if (empty($mode))
return;
$target = "";
if ($mode == "get") {
// Bust cache in the head
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
$func_name = $_GET["rs"];
if (! empty($_GET["rsargs"]))
$args = $_GET["rsargs"];
else
$args = array();
}
else {
$func_name = $_POST["rs"];
if (! empty($_POST["rsargs"]))
$args = $_POST["rsargs"];
else
$args = array();
}
if (! in_array($func_name, $sajax_export_list))
echo "-:$func_name not callable";
else {
$result = call_user_func_array($func_name, $args);
echo "+:";
echo "var res = " . trim(sajax_get_js_repr($result)) . "; res;";
}
exit;
}
// javascript escape a value
function sajax_esc($val)
{
$val = str_replace("\\", "\\\\", $val);
$val = str_replace("\r", "\\r", $val);
$val = str_replace("\n", "\\n", $val);
$val = str_replace("'", "\\'", $val);
return str_replace('"', '\\"', $val);
}
function sajax_get_one_stub($func_name) {
ob_start();
$html = ob_get_contents();
ob_end_clean();
return $html;
}
function sajax_show_one_stub($func_name) {
echo sajax_get_one_stub($func_name);
}
function sajax_export() {
global $sajax_export_list;
$n = func_num_args();
for ($i = 0; $i < $n; $i++) {
$sajax_export_list[] = func_get_arg($i);
}
}
$sajax_js_has_been_shown = 0;
function sajax_get_javascript()
{
global $sajax_js_has_been_shown;
global $sajax_export_list;
$html = "";
if (! $sajax_js_has_been_shown) {
$html .= sajax_get_common_js();
$sajax_js_has_been_shown = 1;
}
foreach ($sajax_export_list as $func) {
$html .= sajax_get_one_stub($func);
}
return $html;
}
$SAJAX_INCLUDED = 1;
}
// $sajax_debug_mode = 1;
sajax_init();
sajax_export("cforms_submitcomment");
sajax_export("reset_captcha");
sajax_handle_client_request();
//
// reset captcha image
//
function reset_captcha( $no = '' ){
@session_start();
$_SESSION['turing_string_'.$no] = rc();
//fix for windows!!!
if ( strpos(__FILE__,'\\') ){
$path = preg_replace( '|.*(wp-content.*)cforms.php|','${1}', __FILE__ );
$path = '/'.str_replace('\\','/',$path);
}
else
$path = preg_replace( '|.*(/wp-content/.*)/.*|','${1}', __FILE__ );
$path = get_bloginfo('wpurl') . $path;
$newimage = md5($_SESSION['turing_string_'.$no]).'|'.$no.'|'.$path.'/cforms-captcha.php?ts='.$no.str_replace('&','&',get_captcha_uri());
return $newimage;
}
//
// main function
//
function cforms($args = '',$no = '') {
global $smtpsettings, $styles, $subID, $cforms_root, $wpdb, $track, $wp_db_version;
//Safety, in case someone uses '1' for the default form
$no = ($no=='1')?'':$no;
parse_str($args, $r); // parse all args, and if not specified, initialize to defaults
//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 = get_option('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 ( get_option('cforms'.$no.'_tellafriend')=='2' && $send2author ) //called from lib_WPcomments ?
return $all_valid;
//
// paint form
//
$success=false;
if ( isset($_GET['cfemail']) && get_option('cforms'.$no.'_tellafriend')=='2' ){ // fix for WP Comment (loading after redirect)
$usermessage_class = ' success';
$success=true;
if ( $_GET['cfemail']=='sent' )
$usermessage_text = preg_replace ( '|\r\n|', '
', stripslashes(get_option('cforms'.$no.'_success')) );
elseif ( $_GET['cfemail']=='posted' )
$usermessage_text = preg_replace ( '|\r\n|', '
', stripslashes(get_option('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
if( substr(get_option('cforms'.$no.'_showpos'),0,1)=='y' ) {
$content .= $ntt . '' . $usermessage_text . '
';
$actiontarget = 'a';
} else if ( substr(get_option('cforms'.$no.'_showpos'),1,1)=='y' )
$actiontarget = 'b';
// redirect == 2 : hide form? || or if max entries reached!
if ( (get_option('cforms'.$no.'_redirect')==2 && isset($_REQUEST['sendbutton'.$no]) && $all_valid) )
return $content;
else if ( get_option('cforms'.$no.'_maxentries')<>'' && get_cforms_submission_left($no)==0 ){
if ( $cflimit == "reached" )
return stripslashes(get_option('cforms'.$no.'_limittxt'));
else
return $content.stripslashes(get_option('cforms'.$no.'_limittxt'));
}
//alternative form action
$alt_action=false;
if( get_option('cforms'.$no.'_action')=='1' ) {
$action = get_option('cforms'.$no.'_action_page');
$alt_action=true;
}
else if( get_option('cforms'.$no.'_tellafriend')=='2' )
$action = $cforms_root . '/lib_WPcomment.php'; // re-route and use WP comment processing
else
$action = $_SERVER['REQUEST_URI'] . '#usermessage'. $no . $actiontarget;
$content .= $ntt . '';
if ( get_option('cforms_datepicker')=='1' && !$dpflag ){
$content .= $ntt . '';
$dpflag = true;
}
//link love? you bet ;)
$content .= $ntt . 'cforms contact form by delicious:days
';
//either show message above or below
if( substr(get_option('cforms'.$no.'_showpos'),1,1)=='y' && !($success&&get_option('cforms'.$no.'_redirect')==2))
$content .= $tt . '' . $usermessage_text . '
' . $nl;
return $content;
}
// prep captcha get call
function get_captcha_uri()
{
$captcha = get_option('cforms_captcha_def');
$h = ( $captcha['h']<>'' ) ? stripslashes(htmlspecialchars( $captcha['h'] )) : 25;
$w = ( $captcha['w']<>'' ) ? stripslashes(htmlspecialchars( $captcha['w'] )) : 115;
$c = ( $captcha['c']<>'' ) ? stripslashes(htmlspecialchars( $captcha['c'] )) : '000066';
$l = ( $captcha['l']<>'' ) ? stripslashes(htmlspecialchars( $captcha['l'] )) : '000066';
$f = ( $captcha['f']<>'' ) ? stripslashes(htmlspecialchars( $captcha['f'] )) : 'font4.ttf';
$a1 = ( $captcha['a1']<>'' ) ? stripslashes(htmlspecialchars( $captcha['a1'] )) : -12;
$a2 = ( $captcha['a2']<>'' ) ? stripslashes(htmlspecialchars( $captcha['a2'] )) : 12;
$f1 = ( $captcha['f1']<>'' ) ? stripslashes(htmlspecialchars( $captcha['f1'] )) : 17;
$f2 = ( $captcha['f2']<>'' ) ? stripslashes(htmlspecialchars( $captcha['f2'] )) : 19;
$bg = ( $captcha['bg']<>'' ) ? stripslashes(htmlspecialchars( $captcha['bg'] )) : '1.gif';
return "&w={$w}&h={$h}&c={$c}&l={$l}&f={$f}&a1={$a1}&a2={$a2}&f1={$f1}&f2={$f2}&b={$bg}";
}
// captcha random code
function rc()
{
$captcha = get_option('cforms_captcha_def');
$min = ( $captcha['c1']<>'' ) ? stripslashes(htmlspecialchars( $captcha['c1'] )) : 4;
$max = ( $captcha['c2']<>'' ) ? stripslashes(htmlspecialchars( $captcha['c2'] )) : 5;
$src = ( $captcha['ac']<>'' ) ? stripslashes(htmlspecialchars( $captcha['ac'] )) : 'abcdefghijkmnpqrstuvwxyz23456789';
$srclen = strlen($src)-1;
$length = mt_rand($min,$max);
$Code = '';
for($i=0; $i<$length; $i++)
$Code .= substr($src, mt_rand(0, $srclen), 1);
return $Code;
}
// some css for positioning the form elements
function cforms_style() {
global $wp_query, $cforms_root, $localversion;
// add content actions and filters
$page_obj = $wp_query->get_queried_object();
$onPages = str_replace(' ','',stripslashes(htmlspecialchars( get_option('cforms_include') )));
$onPagesA = explode(',', $onPages);
if( $onPages=='' || in_array($page_obj->ID,$onPagesA) ){
echo "\n\n";
if( get_option('cforms_no_css')<>'1' )
echo ''."\n";
echo ''."\n";
if( get_option('cforms_datepicker')=='1' ){
echo ''."\n";
echo ''."\n";
}
echo ''."\n\n";
}
}
// replace placeholder by generated code
function cforms_insert( $content ) {
global $post;
if ( strpos($content,'#', $content) && check_for_taf('',$post->ID) )
$content = preg_replace('/()?(<\/p>)?/', cforms('').'$1$2', $content);
} else {
if(preg_match('##', $content) && check_for_taf($i,$post->ID) )
$content = preg_replace('/(
)?(<\/p>)?/', cforms('',$i).'$1$2', $content);
}
$content = str_replace('
','',$content);
}
}
return $content;
}
//build field_stat string from array (for custom forms)
function build_fstat($fields) {
$cfarray = array();
for($i=0; $iID == 0)
$pid = false;
else
$pid = $post->ID;
if ( !$pid )
cforms('',$no);
else
echo check_for_taf($no,$pid)?cforms('',$no):'';
}
// inserts a custom cform anywhere you want
function insert_custom_cform($fields='',$no='') {
global $post;
if ( isset($_GET['pid']) )
$pid = $_GET['pid'];
else if ($post->ID == 0)
$pid = false;
else
$pid = $post->ID;
if ( !$pid )
cforms($fields,$no.'+');
else
echo check_for_taf($no,$pid)?cforms($fields,$no.'+'):'';
}
// check if t-f-a is set
function check_for_taf($no,$pid) {
$tmp = get_post_custom($pid);
$taf = $tmp["tell-a-friend"][0];
if ( substr(get_option('cforms'.$no.'_tellafriend'),0,1)<>'1')
return true;
else {
if ( $taf=='1' )
return true;
else
return false;
}
}
// check if post is t-f-a enabled
function is_tellafriend($pid) {
$tmp = get_post_custom($pid);
return ($tmp["tell-a-friend"][0]=='1')?true:false;
}
### Add Tell A Friend checkbox to admin
add_action('dbx_post_sidebar', 'taf_admin');
add_action('dbx_page_sidebar', 'taf_admin');
function taf_admin() {
global $wpdb;
$edit_post = intval($_GET['post']);
for ( $i=1;$i<=get_option('cforms_formcount');$i++ ) {
$tafenabled = ( substr(get_option('cforms'.(($i=='1')?'':$i).'_tellafriend'),0,1)=='1') ? true : false;
if ( $tafenabled ) break;
}
$i = ($i==1)?'':$i;
if ( $tafenabled && function_exists('get_post_custom') ){
$tmp = get_post_custom($edit_post);
$taf = $tmp["tell-a-friend"][0];
$chk = ($taf=='1' || ($edit_post=='' && substr(get_option('cforms'.$i.'_tellafriend'),1,1)=='1') )?'checked="checked"':'';
if ( $wp_db_version >= 6846 ){
?>