Vergleich inc/functions_upload.php - 1.2.0 - 1.2.10

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 3Zeile 3
 * MyBB 1.2
* Copyright � 2006 MyBB Group, All Rights Reserved
*

 * MyBB 1.2
* Copyright � 2006 MyBB Group, All Rights Reserved
*

 * Website: http://www.mybboard.com
* License: http://www.mybboard.com/eula.html

 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/eula.html

 *

 *

 * $Id: functions_upload.php 2163 2006-08-30 05:53:05Z chris $

 * $Id: functions_upload.php 3135 2007-06-14 20:10:46Z dennis $

 */



 */



Zeile 19Zeile 19
 */
function remove_attachment($pid, $posthash, $aid)
{

 */
function remove_attachment($pid, $posthash, $aid)
{

	global $db, $mybb;







	global $db, $mybb, $plugins;

if($pid)
{
$post = get_post($pid);
}


	$aid = intval($aid);
$posthash = $db->escape_string($posthash);
if($posthash != "")
{
$query = $db->simple_select(TABLE_PREFIX."attachments", "*", "aid='$aid' AND posthash='$posthash'");

	$aid = intval($aid);
$posthash = $db->escape_string($posthash);
if($posthash != "")
{
$query = $db->simple_select(TABLE_PREFIX."attachments", "*", "aid='$aid' AND posthash='$posthash'");

		$attachment = $db->fetch_array($query);

		$attachment = $db->fetch_array($query);

	}
else
{
$query = $db->simple_select(TABLE_PREFIX."attachments", "*", "aid='$aid' AND pid='$pid'");
$attachment = $db->fetch_array($query);
}

	}
else
{
$query = $db->simple_select(TABLE_PREFIX."attachments", "*", "aid='$aid' AND pid='$pid'");
$attachment = $db->fetch_array($query);
}

 
	
$plugins->run_hooks("remove_attachment_do_delete", $attachment);


	$db->delete_query(TABLE_PREFIX."attachments", "aid='".$attachment['aid']."'");
@unlink($mybb->settings['uploadspath']."/".$attachment['attachname']);
if($attachment['thumbnail'])
{
@unlink($mybb->settings['uploadspath']."/".$attachment['thumbnail']);

	$db->delete_query(TABLE_PREFIX."attachments", "aid='".$attachment['aid']."'");
@unlink($mybb->settings['uploadspath']."/".$attachment['attachname']);
if($attachment['thumbnail'])
{
@unlink($mybb->settings['uploadspath']."/".$attachment['thumbnail']);

 
	}
if($attachment['visible'] == 1 && $post['pid'])
{
update_thread_counters($post['tid'], array("attachmentcount" => "-1"));

	}
}


	}
}


Zeile 48Zeile 61
 */
function remove_attachments($pid, $posthash="")
{

 */
function remove_attachments($pid, $posthash="")
{

	global $db, $mybb;







	global $db, $mybb, $plugins;

if($pid)
{
$post = get_post($pid);
}


	$posthash = $db->escape_string($posthash);
if($posthash != "" && !$pid)
{
$query = $db->simple_select(TABLE_PREFIX."attachments", "*", "posthash='$posthash'");

	$posthash = $db->escape_string($posthash);
if($posthash != "" && !$pid)
{
$query = $db->simple_select(TABLE_PREFIX."attachments", "*", "posthash='$posthash'");

	}

	}

	else
{
$query = $db->simple_select(TABLE_PREFIX."attachments", "*", "pid='$pid'");
}

	else
{
$query = $db->simple_select(TABLE_PREFIX."attachments", "*", "pid='$pid'");
}

 
	$num_attachments = 0;

	while($attachment = $db->fetch_array($query))
{

	while($attachment = $db->fetch_array($query))
{

 
		if($attachment['visible'] == 1) 
{
$num_attachments++;
}

$plugins->run_hooks("remove_attachments_do_delete", $attachment);


		$db->delete_query(TABLE_PREFIX."attachments", "aid='".$attachment['aid']."'");
@unlink($mybb->settings['uploadspath']."/".$attachment['attachname']);
if($attachment['thumbnail'])

		$db->delete_query(TABLE_PREFIX."attachments", "aid='".$attachment['aid']."'");
@unlink($mybb->settings['uploadspath']."/".$attachment['attachname']);
if($attachment['thumbnail'])

		{

		{

			@unlink($mybb->settings['uploadspath']."/".$attachment['thumbnail']);

			@unlink($mybb->settings['uploadspath']."/".$attachment['thumbnail']);

		}
}





		}
}
if($post['pid'])
{
update_thread_counters($post['tid'], array("attachmentcount" => "-{$num_attachments}"));
}

}

/**
* Remove any matching avatars for a specific user ID

}

/**
* Remove any matching avatars for a specific user ID

 *

 *

 * @param int The user ID
* @param string A file name to be excluded from the removal
*/
function remove_avatars($uid, $exclude="")

 * @param int The user ID
* @param string A file name to be excluded from the removal
*/
function remove_avatars($uid, $exclude="")

{
global $mybb;

{
global $mybb, $plugins;

	$dir = opendir($mybb->settings['avataruploadpath']);
if($dir)
{
while($file = @readdir($dir))
{

	$dir = opendir($mybb->settings['avataruploadpath']);
if($dir)
{
while($file = @readdir($dir))
{

 
			$plugins->run_hooks("remove_avatars_do_delete", $file);

			if(preg_match("#avatar_".$uid."\.#", $file) && is_file($mybb->settings['avataruploadpath']."/".$file) && $file != $exclude)
{
@unlink($mybb->settings['avataruploadpath']."/".$file);

			if(preg_match("#avatar_".$uid."\.#", $file) && is_file($mybb->settings['avataruploadpath']."/".$file) && $file != $exclude)
{
@unlink($mybb->settings['avataruploadpath']."/".$file);

Zeile 92Zeile 124
		@closedir($dir);
}
}

		@closedir($dir);
}
}





/**
* Upload a new avatar in to the file system
*

/**
* Upload a new avatar in to the file system
*

Zeile 100Zeile 132
 */
function upload_avatar()
{

 */
function upload_avatar()
{

	global $db, $mybb, $lang, $_FILES;

	global $db, $mybb, $lang, $_FILES, $plugins;

	$avatar = $_FILES['avatarupload'];
if(!is_uploaded_file($avatar['tmp_name']))

	$avatar = $_FILES['avatarupload'];
if(!is_uploaded_file($avatar['tmp_name']))

	{
$ret['error'] = $lang->error_uploadfailed;
return $ret;
}


	{
$ret['error'] = $lang->error_uploadfailed;
return $ret;
}


	// Check we have a valid extension
$ext = get_extension(strtolower($avatar['name']));
if(!preg_match("#(gif|jpg|jpeg|jpe|bmp|png)$#i", $ext)) {
$ret['error'] = $lang->error_avatartype;

	// Check we have a valid extension
$ext = get_extension(strtolower($avatar['name']));
if(!preg_match("#(gif|jpg|jpeg|jpe|bmp|png)$#i", $ext)) {
$ret['error'] = $lang->error_avatartype;

		return $ret;
}

		return $ret;
}


// Next check the file size
if($avatar['size'] > ($mybb->settings['avatarsize']*1024) && $mybb->settings['avatarsize'] > 0)


// Next check the file size
if($avatar['size'] > ($mybb->settings['avatarsize']*1024) && $mybb->settings['avatarsize'] > 0)

Zeile 125Zeile 157
	$filename = "avatar_".$mybb->user['uid'].".".$ext;
$file = upload_file($avatar, $mybb->settings['avataruploadpath'], $filename);
if($file['error'])

	$filename = "avatar_".$mybb->user['uid'].".".$ext;
$file = upload_file($avatar, $mybb->settings['avataruploadpath'], $filename);
if($file['error'])

 
	{
@unlink($mybb->settings['avataruploadpath']."/".$filename);
$ret['error'] = $lang->error_uploadfailed;
return $ret;
}

// Lets just double check that it exists
if(!file_exists($mybb->settings['avataruploadpath']."/".$filename))

	{
$ret['error'] = $lang->error_uploadfailed;
return $ret;

	{
$ret['error'] = $lang->error_uploadfailed;
return $ret;

	}

// Lets just double check that it exists
if(!file_exists($mybb->settings['avataruploadpath']."/".$filename))
{
$ret['error'] = $lang->error_uploadfailed;
return $ret;

 
	}

// Check if this is a valid image or not
$img_dimensions = @getimagesize($mybb->settings['avataruploadpath']."/".$filename);
if(!is_array($img_dimensions))

	}

// Check if this is a valid image or not
$img_dimensions = @getimagesize($mybb->settings['avataruploadpath']."/".$filename);
if(!is_array($img_dimensions))

	{


	{
@unlink($mybb->settings['avataruploadpath']."/".$filename);

		$ret['error'] = $lang->error_uploadfailed;
return $ret;
}

		$ret['error'] = $lang->error_uploadfailed;
return $ret;
}

Zeile 150Zeile 184
	{
case "image/gif":
$img_type = 1;

	{
case "image/gif":
$img_type = 1;

			break;

			break;

		case "image/jpeg":

		case "image/jpeg":

 
		case "image/x-jpg":

		case "image/x-jpeg":
case "image/pjpeg":

		case "image/x-jpeg":
case "image/pjpeg":

 
		case "image/jpg":

			$img_type = 2;
break;
case "image/png":

			$img_type = 2;
break;
case "image/png":

Zeile 167Zeile 203
	// Check if the uploaded file type matches the correct image type (returned by getimagesize)
if($img_dimensions[2] != $img_type || $img_type == 0)
{

	// Check if the uploaded file type matches the correct image type (returned by getimagesize)
if($img_dimensions[2] != $img_type || $img_type == 0)
{

 
		@unlink($mybb->settings['avataruploadpath']."/".$filename);		

		$ret['error'] = $lang->error_uploadfailed;
return $ret;
}

		$ret['error'] = $lang->error_uploadfailed;
return $ret;
}

Zeile 191Zeile 228
		"width" => intval($img_dimensions[0]),
"height" => intval($img_dimensions[1])
);

		"width" => intval($img_dimensions[0]),
"height" => intval($img_dimensions[1])
);

 
	$plugins->run_hooks_by_ref("upload_avatar_end", $ret);

	return $ret;
}


	return $ret;
}


Zeile 202Zeile 240
 */
function upload_attachment($attachment)
{

 */
function upload_attachment($attachment)
{

	global $db, $theme, $templates, $posthash, $pid, $tid, $forum, $mybb, $lang;

	global $db, $theme, $templates, $posthash, $pid, $tid, $forum, $mybb, $lang, $plugins;


$posthash = $db->escape_string($mybb->input['posthash']);



$posthash = $db->escape_string($mybb->input['posthash']);


Zeile 236Zeile 274
		return $ret;
}
if(!is_uploaded_file($attachment['tmp_name']) || empty($attachment['tmp_name']))

		return $ret;
}
if(!is_uploaded_file($attachment['tmp_name']) || empty($attachment['tmp_name']))

	{

	{

		$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_php4;
return $ret;
}
$ext = get_extension($attachment['name']);
// Check if we have a valid extension

		$ret['error'] = $lang->error_uploadfailed.$lang->error_uploadfailed_php4;
return $ret;
}
$ext = get_extension($attachment['name']);
// Check if we have a valid extension

	$query = $db->simple_select(TABLE_PREFIX."attachtypes", "*", "extension='$ext'");

	$query = $db->simple_select(TABLE_PREFIX."attachtypes", "*", "extension='".$db->escape_string($ext)."'");

	$attachtype = $db->fetch_array($query);
if(!$attachtype['atid'])
{

	$attachtype = $db->fetch_array($query);
if(!$attachtype['atid'])
{

Zeile 262Zeile 300
		$query = $db->simple_select(TABLE_PREFIX."attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
$usage = $db->fetch_array($query);
$usage = $usage['ausage']+$attachment['size'];

		$query = $db->simple_select(TABLE_PREFIX."attachments", "SUM(filesize) AS ausage", "uid='".$mybb->user['uid']."'");
$usage = $db->fetch_array($query);
$usage = $usage['ausage']+$attachment['size'];

		if($usage > ($mybb->usergroup['attachquota']*1000))

		if($usage > ($mybb->usergroup['attachquota']*1024))

		{

		{

			$friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1000);

			$friendlyquota = get_friendly_size($mybb->usergroup['attachquota']*1024);

			$ret['error'] = sprintf($lang->error_reachedattachquota, $friendlyquota);
return $ret;
}

			$ret['error'] = sprintf($lang->error_reachedattachquota, $friendlyquota);
return $ret;
}

Zeile 324Zeile 362
		{
case "image/gif":
$img_type = 1;

		{
case "image/gif":
$img_type = 1;

				break;

				break;

			case "image/jpeg":

			case "image/jpeg":

 
			case "image/x-jpg":

			case "image/x-jpeg":
case "image/pjpeg":

			case "image/x-jpeg":
case "image/pjpeg":

 
			case "image/jpg":

				$img_type = 2;
break;
case "image/png":

				$img_type = 2;
break;
case "image/png":

Zeile 340Zeile 380

// Check if the uploaded file type matches the correct image type (returned by getimagesize)
$img_dimensions = @getimagesize($mybb->settings['uploadspath']."/".$filename);


// Check if the uploaded file type matches the correct image type (returned by getimagesize)
$img_dimensions = @getimagesize($mybb->settings['uploadspath']."/".$filename);

		if($img_dimensions[2] != $img_type)
{

		if(!is_array($img_dimensions) || $img_dimensions[2] != $img_type)
{

			@unlink($mybb->settings['uploadspath']."/".$filename);
$ret['error'] = $lang->error_uploadfailed;
return $ret;

			@unlink($mybb->settings['uploadspath']."/".$filename);
$ret['error'] = $lang->error_uploadfailed;
return $ret;

Zeile 352Zeile 392
		if($thumbnail['filename'])
{
$attacharray['thumbnail'] = $thumbnail['filename'];

		if($thumbnail['filename'])
{
$attacharray['thumbnail'] = $thumbnail['filename'];

		}

		}

		elseif($thumbnail['code'] == 4)
{
$attacharray['thumbnail'] = "SMALL";
}

		elseif($thumbnail['code'] == 4)
{
$attacharray['thumbnail'] = "SMALL";
}

	}

	}

	if($forum['modattachments'] == "yes" && is_moderator($forum['fid'], "", $mybb->user['uid']) != "yes")
{
$attacharray['visible'] = 0;

	if($forum['modattachments'] == "yes" && is_moderator($forum['fid'], "", $mybb->user['uid']) != "yes")
{
$attacharray['visible'] = 0;

Zeile 366Zeile 406
	{
$attacharray['visible'] = 1;
}

	{
$attacharray['visible'] = 1;
}

 
	
$plugins->run_hooks_by_ref("upload_attachment_do_insert", $attacharray);


$db->insert_query(TABLE_PREFIX."attachments", $attacharray);


$db->insert_query(TABLE_PREFIX."attachments", $attacharray);

 
	
if($attacharray['pid'] > 0)
{
$post = get_post($attacharray['pid']);
update_thread_counters($post['tid'], array("attachmentcount" => +1));
}


$aid = $db->insert_id();
$ret['aid'] = $aid;


$aid = $db->insert_id();
$ret['aid'] = $aid;

Zeile 383Zeile 431
 */
function upload_file($file, $path, $filename="")
{

 */
function upload_file($file, $path, $filename="")
{

 
	global $plugins;

	if(empty($file['name']) || $file['name'] == "none" || $file['size'] < 1)
{
$upload['error'] = 1;

	if(empty($file['name']) || $file['name'] == "none" || $file['size'] < 1)
{
$upload['error'] = 1;

Zeile 406Zeile 455
	$upload['path'] = $path;
$upload['type'] = $file['type'];
$upload['size'] = $file['size'];

	$upload['path'] = $path;
$upload['type'] = $file['type'];
$upload['size'] = $file['size'];

 
	$plugins->run_hooks_by_ref("upload_file_end", $upload);

	return $upload;
}
?>

	return $upload;
}
?>