Jacky sun

Good Good Study, Day Day Up!!!

 

ASP.NET Forums 2.0 本地化修改(一)

该集的内容主要收集于网上,一些原来的出处地址和作者没有找到,只能对原作者说抱歉了,如作者看到需要注明的,请和我联系。

一、使论坛支持中文用户名
       其实这个问题只要了解原理的话,很容易就可以解决,对用户名的限制主要是通过正则表达式来控制。相关文件为各skin目录下的Skin-CreateNewAccount.ascxSkin-CreateNewAccount2.ascx。下面直接贴出修改方法:
查找这一行:

<asp:RegularExpressionValidator EnableClientScript="false" ID="usernameRegExValidator" runat="server" 
ControlToValidate="Username" ValidationExpression="[a-zA-Z]+[^<>]*" Cssclass="validationWarning">*</asp:RegularExpressionValidator>

替换为这一行(已修改,原来的代码由于blog编辑器的问题,自动过滤了一些字符):

<asp:RegularExpressionValidator EnableClientScript="false" ID="usernameRegExValidator" runat="server" ControlToValidate="Username" ValidationExpression="[^0-9|^\<\>\,\.\~\`\!\@\#\$\%\^\&\*\(\)_\+\-\=\\\|\[\]\{\}\:\;\?\']+[^\<\>\,\.\~\`\!\@\#\$\%\^\&\*\(\)_\+\-\=\\\|\[\]\{\}\:\;\?\']*" Cssclass="validationWarning">*</asp:RegularExpressionValidator>

 

二、如果附件为图片,那么直接显示该附件
     影响的文件:Controls项目下的PostDisplay/TextPost.cs文件;
方法一(直接显示):
修改TextPost.cs文件的InitializeSkin(Control skin)方法,代码如下:

body.Text = post.FormattedBody;
   
string Attachment=
post.AttachmentFilename;
   
if (Attachment!="" && Attachment!=null
)
   
{
    
string Extension=Attachment.Substring(Attachment.LastIndexOf("."
));
    Extension
=
Extension.ToLower();
    
if (Extension==".jpg" || Extension==".gif" || Extension==".bmp" || Extension==".pcx"
 || Extension==".png" || Extension==".bmp")
     body.Text 
+= "<img src= '"+Globals.GetSiteUrls().PostAttachment(post.PostID)+"' />"
;
   }


方法二:
把方法一中的body.Text +=改成:

 body.Text += "<a href='"+Globals.GetSiteUrls().PostAttachment(post.PostID)+"' target='_blank'><img src='"+Globals.GetSiteUrls().PostAttachment(post.PostID)+"' border='0' width='560' height='428' onload='javascript:DrawImage(this);'></a>";

并且在ShowPost.aspx文件中增加下列js代码:

var flag=false;
function
 DrawImage(ImgD){
var image=new
 Image();
image.src
=
ImgD.src;
if(image.width>0 && image.height>0
){
flag
=true
;
if(image.width/image.height>= 560/428
){
if(image.width>560
){ 
ImgD.width
=560
;
ImgD.height
=(image.height*560)/
image.width;
}
else
{
ImgD.width
=
image.width; 
ImgD.height
=
image.height;
}
ImgD.alt
=image.width+"×"+
image.height;
}
else
{
if(image.height>428
){ 
ImgD.height
=428
;
ImgD.width
=(image.width*428)/
image.height; 
}
else
{
ImgD.width
=
image.width; 
ImgD.height
=
image.height;
}
ImgD.alt
=image.width+"×"+
image.height;
}
}
}
 

注意:图片高和宽 分别是560*428,你可以改成其他的大小


下集主题预告:
如何将论坛附件直接以文件形式保存,并读取照片文件的Exif信息;

posted on 2004-08-07 00:20  jacky  阅读(2174)  评论(5编辑  收藏  举报

导航