浏览代码

! Some final folding, some fixing

Spuds 12 年之前
父节点
当前提交
129237e9b6
共有 3 个文件被更改,包括 125 次插入1 次删除
  1. 2 1
      Sources/Load.php
  2. 115 0
      Sources/Subs-Graphics.php
  3. 8 0
      Sources/Subs.php

+ 2 - 1
Sources/Load.php

@@ -1329,7 +1329,7 @@ function isBrowser($browser)
 	global $context;
 
 	// @todo REMOVE THIS BEFORE BETA 1 RELEASE.
-	if (in_array($browser, array('ie7', 'ie6', 'ie5.5', 'ie5', 'ie5', 'mac_ie', 'firefox1')))
+	if (in_array($browser, array('ie7', 'ie6', 'ie5.5', 'ie5', 'ie5', 'ie4', 'mac_ie', 'firefox1')))
 	{
 		$line = $file = null;
 		foreach (debug_backtrace() as $step)
@@ -1349,6 +1349,7 @@ function isBrowser($browser)
 		}
 
 		log_error('Old browser support' . $function, 'debug', $file, $line);
+		var_dump($browser);die;
 	}
 
 	// Don't know any browser!

+ 115 - 0
Sources/Subs-Graphics.php

@@ -21,6 +21,121 @@
 if (!defined('SMF'))
 	die('Hacking attempt...');
 
+/**
+ * downloads file from url and stores it locally for avatar use by id_member.
+ * supports GIF, JPG, PNG, BMP and WBMP formats.
+ * detects if GD2 is available.
+ * uses resizeImageFile() to resize to max_width by max_height, and saves the result to a file.
+ * updates the database info for the member's avatar.
+ * returns whether the download and resize was successful.
+ *
+ * @param string $temporary_path, the full path to the temporary file
+ * @param int $memID, member ID
+ * @param int $max_width
+ * @param int $max_height
+ * @return bool, whether the download and resize was successful.
+ *
+ */
+function downloadAvatar($url, $memID, $max_width, $max_height)
+{
+	global $modSettings, $sourcedir, $smcFunc;
+
+	$ext = !empty($modSettings['avatar_download_png']) ? 'png' : 'jpeg';
+	$destName = 'avatar_' . $memID . '_' . time() . '.' . $ext;
+
+	// Just making sure there is a non-zero member.
+	if (empty($memID))
+		return false;
+
+	require_once($sourcedir . '/ManageAttachments.php');
+	removeAttachments(array('id_member' => $memID));
+
+	$id_folder = !empty($modSettings['currentAttachmentUploadDir']) ? $modSettings['currentAttachmentUploadDir'] : 1;
+	$avatar_hash = empty($modSettings['custom_avatar_enabled']) ? getAttachmentFilename($destName, false, null, true) : '';
+	$smcFunc['db_insert']('',
+		'{db_prefix}attachments',
+		array(
+			'id_member' => 'int', 'attachment_type' => 'int', 'filename' => 'string-255', 'file_hash' => 'string-255', 'fileext' => 'string-8', 'size' => 'int',
+			'id_folder' => 'int',
+		),
+		array(
+			$memID, empty($modSettings['custom_avatar_enabled']) ? 0 : 1, $destName, $avatar_hash, $ext, 1,
+			$id_folder,
+		),
+		array('id_attach')
+	);
+	$attachID = $smcFunc['db_insert_id']('{db_prefix}attachments', 'id_attach');
+	// Retain this globally in case the script wants it.
+	$modSettings['new_avatar_data'] = array(
+		'id' => $attachID,
+		'filename' => $destName,
+		'type' => empty($modSettings['custom_avatar_enabled']) ? 0 : 1,
+	);
+
+	$destName = (empty($modSettings['custom_avatar_enabled']) ? (is_array($modSettings['attachmentUploadDir']) ? $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']] : $modSettings['attachmentUploadDir']) : $modSettings['custom_avatar_dir']) . '/' . $destName . '.tmp';
+
+	// Resize it.
+	if (!empty($modSettings['avatar_download_png']))
+		$success = resizeImageFile($url, $destName, $max_width, $max_height, 3);
+	else
+		$success = resizeImageFile($url, $destName, $max_width, $max_height);
+
+	// Remove the .tmp extension.
+	$destName = substr($destName, 0, -4);
+
+	if ($success)
+	{
+		// Walk the right path.
+		if (!empty($modSettings['currentAttachmentUploadDir']))
+		{
+			if (!is_array($modSettings['attachmentUploadDir']))
+				$modSettings['attachmentUploadDir'] = unserialize($modSettings['attachmentUploadDir']);
+			$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
+		}
+		else
+			$path = $modSettings['attachmentUploadDir'];
+
+		// Remove the .tmp extension from the attachment.
+		if (rename($destName . '.tmp', empty($avatar_hash) ? $destName : $path . '/' . $attachID . '_' . $avatar_hash))
+		{
+			$destName = empty($avatar_hash) ? $destName : $path . '/' . $attachID . '_' . $avatar_hash;
+			list ($width, $height) = getimagesize($destName);
+			$mime_type = 'image/' . $ext;
+
+			// Write filesize in the database.
+			$smcFunc['db_query']('', '
+				UPDATE {db_prefix}attachments
+				SET size = {int:filesize}, width = {int:width}, height = {int:height},
+					mime_type = {string:mime_type}
+				WHERE id_attach = {int:current_attachment}',
+				array(
+					'filesize' => filesize($destName),
+					'width' => (int) $width,
+					'height' => (int) $height,
+					'current_attachment' => $attachID,
+					'mime_type' => $mime_type,
+				)
+			);
+			return true;
+		}
+		else
+			return false;
+	}
+	else
+	{
+		$smcFunc['db_query']('', '
+			DELETE FROM {db_prefix}attachments
+			WHERE id_attach = {int:current_attachment}',
+			array(
+				'current_attachment' => $attachID,
+			)
+		);
+
+		@unlink($destName . '.tmp');
+		return false;
+	}
+}
+
 /**
  * Create a thumbnail of the given source.
  *

+ 8 - 0
Sources/Subs.php

@@ -3414,6 +3414,10 @@ function create_button($name, $alt, $label = '', $custom = '', $force_use = fals
 
 /**
  * Empty out the cache folder.
+ * clean the cache directory ($cachedir, if any and in use)
+ * it may only remove the files of a certain type
+ *  (if the $type parameter is given)
+ * @param string $type = ''
  */
 function clean_cache($type = '')
 {
@@ -3436,8 +3440,12 @@ function clean_cache($type = '')
 	// ... as long as Load.php can be modified, anyway.
 	@touch($sourcedir . '/' . 'Load.php');
 	clearstatcache();
+}
+
+/**
  * Load classes that are both (E_STRICT) PHP 4 and PHP 5 compatible.
  * @param string $filename
+ * @todo remove this function since we are no longer supporting PHP < 5
  */
 function loadClassFile($filename)
 {