From fb02817dfc9d37716862a02000490cd3fe1177a4 Mon Sep 17 00:00:00 2001
From: ryan <ryan@1a063a9b-81f0-0310-95a4-ce76da25c4cd>
Date: Wed, 27 Feb 2008 00:25:08 +0000
Subject: [PATCH] Fix users query

git-svn-id: http://svn.automattic.com/wordpress/trunk@7054 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
 wp-admin/includes/file.php | 18 ++++++++++++++++--
 wp-includes/formatting.php |  2 +-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php
index f03ae43691..98482f86ac 100644
--- a/wp-admin/includes/file.php
+++ b/wp-admin/includes/file.php
@@ -42,6 +42,20 @@ function get_real_file_to_edit( $file ) {
 	return $real_file;
 }
 
+function get_temp_dir() {
+	if ( defined('WP_TEMP_DIR') )
+		return trailingslashit(WP_TEMP_DIR);
+
+	$temp = ABSPATH . 'wp-content/';
+	if ( is_dir($temp) && is_writable($temp) )
+		return $temp;
+
+	if  ( function_exists('sys_get_temp_dir') )
+		return trailingslashit(sys_get_temp_dir());
+
+	return '/tmp/';
+}
+
 function validate_file( $file, $allowed_files = '' ) {
 	if ( false !== strpos( $file, '..' ))
 		return 1;
@@ -182,7 +196,7 @@ function download_url( $url ) {
 	if( ! $url )
 		return false;
 
-	$tmpfname = tempnam('/tmp', 'wpupdate');
+	$tmpfname = tempnam(get_temp_dir(), 'wpupdate');
 	if( ! $tmpfname )
 		return false;
 
@@ -288,7 +302,7 @@ function WP_Filesystem( $args = false, $preference = false ) {
 }
 
 function get_filesystem_method() {
-	$tempFile = tempnam('/tmp', 'WPU');
+	$tempFile = tempnam(get_temp_dir(), 'WPU');
 
 	if ( getmyuid() == fileowner($tempFile) ) {
 		unlink($tempFile);
diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php
index 67cff31138..84ef472bc9 100644
--- a/wp-includes/formatting.php
+++ b/wp-includes/formatting.php
@@ -83,7 +83,7 @@ function wpautop($pee, $br = 1) {
 	$pee = preg_replace('!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee);
 	$pee = preg_replace('!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee);
 	if ($br) {
-		$pee = preg_replace('/<(script|style).*?<\/\\1>/se', 'str_replace("\n", "<WPPreserveNewline />", "\\0")', $pee);
+		$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'str_replace("\n", "<WPPreserveNewline />", $matches[1])'), $pee);
 		$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
 		$pee = str_replace('<WPPreserveNewline />', "\n", $pee);
 	}