Exemplo n.º 1
0
Arquivo: main.php Projeto: ryansm/saud
function ncf_send_message()
{
    global $wpdb;
    $options = ncf_get_options();
    $blogname = htmlspecialchars_decode(get_bloginfo('name'));
    // writing log
    $time = date("F jS Y, H:i", time() + 25200);
    $sender = $_POST['ncf_name_field'];
    $msg = $_POST['ncf_message_field'];
    $email = $_POST['ncf_email_field'];
    $subj = isset($_POST['ncf_subject_field']) && !empty($_POST['ncf_subject_field']) ? $_POST['ncf_subject_field'] : FALSE;
    $company = isset($_POST['ncf_company_field']) && !empty($_POST['ncf_company_field']) ? $_POST['ncf_company_field'] : FALSE;
    $phone = isset($_POST['ncf_phone_field']) && !empty($_POST['ncf_phone_field']) ? $_POST['ncf_phone_field'] : FALSE;
    $address = isset($_POST['ncf_address_field']) && !empty($_POST['ncf_address_field']) ? $_POST['ncf_address_field'] : FALSE;
    $ban = "#{$time}\r\n" . ($subj ? 'Subject: ' . $subj . "\r\n" : '') . "Sender: {$sender}\r\n" . ($company ? 'Company: ' . $company . "\r\n" : '') . ($phone ? 'Phone: ' . $phone . "\r\n" : '') . ($address ? 'Address: ' . $address . "\r\n" : '') . "User wants to subscribe: " . (isset($_POST['ncf_subscriber']) && !empty($_POST['ncf_subscriber']) ? 'Yes' . "\r\n" : 'No' . "\r\n") . "Email: {$email}\r\n" . "Message: {$msg}\r\n\r\n";
    $file = plugin_dir_path(__FILE__) . '/message_log.txt';
    $oldContents = file_get_contents($file);
    $oldLevel = error_reporting();
    error_reporting(E_ALL ^ E_WARNING);
    $fr = fopen($file, 'w');
    fwrite($fr, $ban);
    fwrite($fr, $oldContents);
    //	$open = fopen( $file, "c" );
    //	$write = fputs( $open, $ban );
    fclose($fr);
    error_reporting($oldLevel);
    if (isset($_POST['ncf_subscriber']) && !empty($_POST['ncf_subscriber'])) {
        if (!class_exists('LA_Mailchimp')) {
            include_once 'include/mailchimp/src/Mailchimp.php';
        }
        $exploded = explode(' ', $sender);
        $subscriber = ncf_add_subscriber($email, $options['ncf_mc_token'], $options['ncf_mc_list_id'], isset($exploded[0]) ? $exploded[0] : NULL, isset($exploded[1]) ? $exploded[1] : NULL);
    }
    //$lists = ncf_get_MC_lists();
    // get the submitted parameters
    $headers = array();
    $headers[] = 'From: ' . ($options['ncf_use_admin_email'] === 'enable' ? $blogname . ' Admin' : $sender) . ' <' . str_replace(array("\r", "\n", "\n", "\t", ",", ";"), '', $options['ncf_use_admin_email'] === 'enable' ? get_bloginfo('admin_email') : $email) . ">\r\n";
    $headers[] = 'Content-type: text/html';
    $ip = ncf_get_ip_address();
    $server = array_merge(array('HTTP_HOST' => null, 'REQUEST_URI' => null, 'HTTP_REFERER' => null, 'HTTP_USER_AGENT' => null), $_SERVER);
    $subject = $subj ? $subj : $blogname . ' ' . @$options['ncf_email_title_' . $_POST['ncf_form_index']];
    $header = '<html>
				<head>
					<title>' . $subject . '</title>
				</head>
				<body>
				<div id="email_container" style="background: #389569;padding: 40px 20px;">
				<div style="width:550px; padding:8px 20px 8px 20px; background:#fff; margin:0 auto;
				moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; color:#454545;line-height:1.5em; " id="email_content">';
    $footer = '<div style="text-align:center; border-top:1px solid #eee;padding:5px 0 0 0;" id="email_footer">
						<small style="font-size:11px; color:#999; line-height:14px;">
							' . __('This email was sent because someone used Ninja Kick Contact Form on your site', 'ninja-contact-form') . '
						</small>
					</div>
				</div>
			</div>
		</body>
	</html>';
    $result = wp_mail(isset($_POST['send_to']) ? $_POST['send_to'] : $options['ncf_email_' . $_POST['ncf_form_index']], $subj ? $subj : $blogname . ' ' . @$options['ncf_email_title_' . $_POST['ncf_form_index']], $header . '<p><strong>' . __('Name', 'ninja-contact-form') . '</strong>: ' . $sender . "</p>" . ($company ? '<p><strong>' . __('Company', 'ninja-contact-form') . '</strong>: ' . $company . "</p>" : '') . ($phone ? '<p><strong>' . __('Phone', 'ninja-contact-form') . '</strong>: ' . $phone . "</p>" : '') . ($address ? '<p><strong>' . __('Address', 'ninja-contact-form') . '</strong>: ' . $address . "</p>" : '') . '<p><strong>' . __('Email', 'ninja-contact-form') . '</strong>: ' . $email . "</p>" . '<p><strong>' . __('Sent from page', 'ninja-contact-form') . '</strong>: ' . ($server['HTTP_REFERER'] ? $server['HTTP_REFERER'] : 'Page not detected') . "</p>" . '<p><strong>' . __('IP', 'ninja-contact-form') . '</strong>: ' . (isset($ip) ? $ip : 'IP not detected') . "</p>" . '<p><strong>' . __('Browser info', 'ninja-contact-form') . '</strong>: ' . ($server['HTTP_USER_AGENT'] ? $server['HTTP_USER_AGENT'] : 'Browser not detected') . "</p>" . "<p><strong>" . __('Message', 'ninja-contact-form') . "</strong>: </p>" . "<p>" . $msg . "</p>" . $footer, $headers);
    $copy = wp_mail($email, 'Your contact form submission to ' . $blogname, $header . '<p><strong>Name</strong>: ' . $sender . "</p>" . ($company ? '<p><strong>Company</strong>: ' . $company . "</p>" : '') . ($phone ? '<p><strong>Phone</strong>: ' . $phone . "</p>" : '') . ($address ? '<p><strong>Address</strong>: ' . $address . "</p>" : '') . '<p><strong>Email</strong>: ' . $email . "</p>" . "<p><strong>Message</strong>:</p>" . "<p>" . $msg . "</p>" . $footer, $headers);
    if ($result) {
        echo json_encode(array('success' => true, 'result' => $result));
        die;
    }
    echo json_encode(array('success' => false, 'message' => __("Message not sent. An unknown error occurred.", 'ninja-contact-form'), 'result' => $result));
    die;
}
Exemplo n.º 2
0
/**
 * Handler after a file has been uploaded.  If the file is an image, check the size
 * to see if it is too big and, if so, resize and overwrite the original
 * @param Array $params
 */
function ncf_imsanity_handle_upload($params)
{
    $options = ncf_get_options();
    for ($i = 1; $i <= $options['ncf_forms']; $i++) {
        if (isset($_FILES['ncf_pic_' . $i]) && $_FILES['ncf_pic_' . $i]['size'] > 0) {
            /* debug logging... */
            // file_put_contents ( "debug.txt" , print_r($params,1) . "\n" );
            /*	$option_convert_bmp = IMSANITY_DEFAULT_BMP_TO_JPG;
            
            				if ($params['type'] == 'image/bmp' && $option_convert_bmp)
            				{
            					$params = imsanity_bmp_to_jpg($params);
            				}*/
            // make sure this is a type of image that we want to convert and that it exists
            // @TODO when uploads occur via RPC the image may not exist at this location
            $oldPath = $params['file'];
            if (!is_wp_error($params) && file_exists($oldPath) && in_array($params['type'], array('image/png', 'image/gif', 'image/jpeg'))) {
                // figure out where the upload is coming from
                $source = imsanity_get_source();
                list($maxW, $maxH) = imsanity_get_max_width_height($source);
                list($oldW, $oldH) = getimagesize($oldPath);
                /* HACK: if getimagesize returns an incorrect value (sometimes due to bad EXIF data..?)
                			$img = imagecreatefromjpeg ($oldPath);
                			$oldW = imagesx ($img);
                			$oldH = imagesy ($img);
                			imagedestroy ($img);
                			//*/
                /* HACK: an animated gif may have different frame sizes.  to get the "screen" size
                			$data = ''; // TODO: convert file to binary
                			$header = unpack('@6/vwidth/vheight', $data );
                			$oldW = $header['width'];
                			$oldH = $header['width'];
                			//*/
                if ($oldW > $maxW && $maxW > 0 || $oldH > $maxH && $maxH > 0) {
                    $quality = IMSANITY_DEFAULT_QUALITY;
                    list($newW, $newH) = wp_constrain_dimensions($oldW, $oldH, $maxW, $maxH);
                    // this is wordpress prior to 3.5 (image_resize deprecated as of 3.5)
                    //$resizeResult = imsanity_image_resize( $oldPath, $newW, $newH, true, null, null, $quality);
                    $resizeResult = imsanity_image_resize($oldPath, $maxW, $maxH, true, null, null, $quality);
                    /* uncomment to debug error handling code: */
                    // $resizeResult = new WP_Error('invalid_image', __(print_r($_REQUEST)), $oldPath);
                    // regardless of success/fail we're going to remove the original upload
                    unlink($oldPath);
                    if (!is_wp_error($resizeResult)) {
                        $newPath = $resizeResult;
                        // remove original and replace with re-sized image
                        rename($newPath, $oldPath);
                    } else {
                        // resize didn't work, likely because the image processing libraries are missing
                        $params = wp_handle_upload_error($oldPath, sprintf(__("Oh Snap! Imsanity was unable to resize this image " . "for the following reason: '%s'\n\t\t\t\t\t\t.  If you continue to see this error message, you may need to either install missing server" . " components or disable the Imsanity plugin." . "  If you think you have discovered a bug, please report it on the Imsanity support forum.", 'imsanity'), $resizeResult->get_error_message()));
                    }
                }
            }
        }
    }
    return $params;
}