[外掛] 連結頭圖像大小限制 !!! 真正完美版!!!

MODs Released by Other phpbb Sites
非官方認證通過之 MOD ,或許有安全性之疑慮,所有問題由原發表者回覆!

版主: 版主管理群

主題已鎖定
JFA
星球公民
星球公民
文章: 232
註冊時間: 2003-06-23 23:21
來自: 香港
聯繫:

[外掛] 連結頭圖像大小限制 !!! 真正完美版!!!

文章 JFA »

之前大家都在找各式各樣的Remote avatar restrict MOD
經我一晚的研究 , 終於解決了!! :evil:
其實是作者的一個小bugs..........~"~

Hack Title: Rapid offsite avatar check
Hack Version: 1.5.0
Author: Antony Bailey
Description: Checks offsite avatars to make sure they conform to the set params.
Compatibility: 2.0.4

PS:請先移除所有連結頭像限制的MOD!

代碼: 選擇全部

############################################### 
##   Hack Title:   Rapid offsite avatar check
##   Hack Version:   1.5.0 
##   Author:      Antony Bailey
##   Description:   Checks offsite avatars to make sure they conform to the set params. 
##   Compatibility:   2.0.4 
## 
##   Installation Level: Easy
##   Installation Time: 2 minutes 
##   Files To Edit: 1 
##      usercp_avatar.php
## 
## 
##   History: 
##      1.0.0:    Initial test.
##      1.5.0:    Typo fixed. 
## 
##   Author Notes: 
##      Thanks again FB-ke, for saving my typos once again. Just a } that's the bug I had. :roll:
## 
##   Support:      http://www.phpbbhacks.com/forums 
##   Copyright:      ?003 Rapid offsite avatar check 1.0.0 - Antony Bailey
## 
############################################### 
##   You downloaded this hack from phpBBHacks.com, the #1 source for phpBB related downloads. 
##   Please visit http://www.phpbbhacks.com/forums for support. 
############################################### 
## 
############################################### 
##   This hack is released under the GPL License. 
##   This hack can be freely used, but not distributed, without permission. 
##   Intellectual Property is retained by the hack author(s) listed above. 
############################################### 

# 
#-----[ OPEN ]------------------------------------------ 
# 
includes/usercp_avatar.php 
# 
#-----[ FIND ]------------------------------------------ 
# 
function check_image_type(&$type, &$error, &$error_msg)
{
	global $lang;

	switch( $type )
	{
		case 'jpeg':
		case 'pjpeg':
		case 'jpg':
			return '.jpg';
			break;
		case 'gif':
			return '.gif';
			break;
		case 'png':
			return '.png';
			break;
		default:
			$error = true;
			$error_msg = (!empty($error_msg)) ? $error_msg . '<br />' . $lang['Avatar_filetype'] : $lang['Avatar_filetype'];
			break;
# 
#-----[ BEFORE, ADD, ADD ]------------------------------------------ 
# 
function download_avatar($filename) 
{ 
global $board_config, $userdata; 

$retvar="NULL"; 
clearstatcache(); 
$localfile = './' . $board_config['avatar_path'].'/'.$userdata['session_user_id'].basename($filename); 
$fd = @fopen($filename,"rb"); 
if ($fd) 
{ 

$imgdata = fread($fd,$board_config['avatar_filesize']+1); 
$fl = @fopen($localfile,"wb"); 
if ($fl) 
{ 
$fp=@fwrite($fl,$imgdata); 
@fclose($fl); 
if ($fp != -1) 
{ 
if (filesize($localfile) <= $board_config['avatar_filesize']) 
{ 
$retvar = $localfile;
} 
else 
{ 
@unlink($localfile); 
$retvar = 'SIZE';
} 
} 
else 
{ 
@unlink($localfile); 
message_die(GENERAL_ERROR, 'Could not write avatar file to local storage. Please contact someone who cares with this message', '', __LINE__, __FILE__); 
} 
} 
else 
{ 
@unlink($localfile); 
message_die(GENERAL_ERROR, 'Could not write avatar file to local storage. Please contact the someone who cares with this message', '', __LINE__, __FILE__); 
} 
fclose($fd); 
} 
return $retvar; 
} 
# 
#-----[ FIND ]------------------------------------------ 
# 
function user_avatar_url($mode, &$error, &$error_msg, $avatar_filename) 
{ 
if ( !preg_match('#^(http)|(ftp):\/\/#i', $avatar_filename) ) 
{ 
$avatar_filename = 'http://' . $avatar_filename; 
} 

if ( !preg_match('#^((http)|(ftp):\/\/[\w\-]+?\.([\w\-]+\.)+[\w]+(:[0-9]+)*\/.*?\.(gif|jpg|jpeg|png)$)#is', $avatar_filename) ) 
{ 
$error = true; 
$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Wrong_remote_avatar_format'] : $lang['Wrong_remote_avatar_format']; 
return; 
} 

# 
#-----[ REPLACE WITH ]------------------------------------------ 
# 
function user_avatar_url($mode, &$error, &$error_msg, $avatar_filename) 
{ 
global $board_config, $lang; 

if ( !preg_match('#^(http)|(ftp):\/\/#i', $avatar_filename) ) 
{ 
$avatar_filename = 'http://' . $avatar_filename; 
} 

if ( !preg_match('#^((http)|(ftp):\/\/[\w\-]+?\.([\w\-]+\.)+[\w]+(:[0-9]+)*\/.*?\.(gif|jpg|jpeg|png)$)#is', $avatar_filename) ) 
{ 
$error = true; 
$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Wrong_remote_avatar_format'] : $lang['Wrong_remote_avatar_format']; 
return; 
} 
$tmp_filename=download_avatar($avatar_filename); 

$width=2*$board_config['avatar_max_width']; 
$height=2*$board_config['avatar_max_height']; 
switch ($tmp_filename) 
{ 
case 'NULL': 
$error = true; 
$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['No_connection_URL'] : $lang['No_connection_URL']; 
return; 
break; 
case 'SIZE': 
$l_avatar_size = sprintf($lang['Avatar_filesize'], round($board_config['avatar_filesize'] / 1024)); 
$error = true; 
$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_avatar_size : $l_avatar_size; 
return; 
break; 
default: 
unset ($height); 
unset ($width); 
list($width, $height) = getimagesize($tmp_filename); 
if (!isset($width) or $width<=0) $width=2*$board_config['avatar_max_width']; 
if (!isset($height) or $height<=0) $height=2*$board_config['avatar_max_height']; 
@unlink($tmp_filename); 
if ( $width > $board_config['avatar_max_width'] || $height > $board_config['avatar_max_height'] ) 
{ 
$l_avatar_size = sprintf($lang['Avatar_imagesize'], $board_config['avatar_max_width'], $board_config['avatar_max_height']); 
$error = true; 
$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_avatar_size : $l_avatar_size; 
return; 
} 
} 
}
# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM 
關鍵來了 :mrgreen: 安裝好後 , 請依照以下修改 :
找尋 :

代碼: 選擇全部

return ( $mode == 'editprofile' ) ? ", user_avatar = '" . str_replace("\'", "''", $avatar_filename) . "', user_avatar_type = " . USER_AVATAR_REMOTE : '';
然後把他剪下 , 然後 find:

代碼: 選擇全部

$l_avatar_size = sprintf($lang['Avatar_imagesize'], $board_config['avatar_max_width'], $board_config['avatar_max_height']); 
$error = true; 
$error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_avatar_size : $l_avatar_size; 
return; 
} 
} 
然後after PASTE 就行了!! :mrgreen:

你可以試試 是否真的完美!!

對了 , 最後要把avatars的folder的CHMOD改成777
當然 , 你要到後台把avatars的路徑設定正確^^

來了竹貓這麼久 , 終於有點貢獻了 :oops:

(希望之前沒有人寫過....~"~)
~~~~我的Forum~~~~
圖檔
^^歡迎光臨^^
主題已鎖定

回到「非官方認證外掛」