練功房推薦書單

  • Google!Android 3手機應用程式設計入門(第四版)
  • 賈伯斯傳(軟皮精裝版)
  • 猛虎出閘制霸版:最新OCP Java SE 6 Programmer專業認證(附原始程式碼及範例檔)
  • SCWCD 5 猛虎出閘:Java Web 應用程式專業認證
jforum论坛二次开发--小修小改汇总贴  XML
Forum Index » JForum中文社群 JForum Chinese Users Community
Author Message
lynx286

九級學員

Joined: 2008-04-24 12:03:16
Messages: 10
Offline

*****************************************
lynx286原创, 首发www.mydwbi.com
http://www.mydwbi.com/posts/list/0/103.page
欢迎转贴, 但转贴请不要删除此段版权说明.
*****************************************

  • 将会员列表改成按id排序(新注册用户排前面)


  • web-inf\config\database\generic\generic_queries.sql

    将58-59行 "order by username" 改成 "order by user_id desc"


  • 添加网站地图

  • -生成sitemap.xml
    jforum 的url后缀是.page不是常规的.htm .html .asp .jsp 所以很多sitemap.xml builder不能识别jforum中的链接,所以自动生成不了sitemap.xml(本人猜想是这个原因),后来找半天找到一个工具叫SOFTplus GSiteCrawler的可以自定义页面后缀,从而自动生成sitemap.xml.

    -添加国际化属性
    zh_CN.properties中最后添加:mydwbi.sitemap=\u7f51\u7ad9\u5730\u56fe

    -添加入口链接
    在forum_list.htm中第181行下添加:
    <td>&nbsp;&nbsp;</td>
    <td align="center" width="20"><img   /></td>
    <td><span class="gensmall"><a href="${contextPath}/sitemap.xml">${I18n.getMessage("mydwbi.sitemap")}</a></span></td>
    





  • 修改版权信息

  • 修改bottom.htm 11行.


  • 将发贴时"poll","attachments","options"改成中文

  • -添加国际化属性
    mydwbi.Options=\u9009\u9879
    mydwbi.Poll=\u6295\u7968
    mydwbi.Attach=\u9644\u4ef6

    -修改模板
    将post_form.htm中第369,372,375行"poll","attachments","options"改成:
    ${I18n.getMessage("mydwbi.Options")}
    ${I18n.getMessage("mydwbi.Poll")}
    ${I18n.getMessage("mydwbi.Attach")}

  • 让发贴的表情符号列表多显示几个表情

  • 修改post_form.htm261行,改成:<#if (count < 32)>


  • 特定用户显示ip

  • post_show_user_inc.htm36,37行改成:
    <#if (post.userIp?exists && isModerator) || (post.userIp?exists && session.username = "lynx286")>
    ${I18n.getMessage("PostShow.userIP")}: <a href="http://whois.domaintools.com/${post.userIp}"  target="_blank">${post.userIp}</a>


    即如果当前登陆用户为该版版主或用户名为lynx286,就显示发贴人ip地址


  • 进入板块后显示主题列表页面发表人栏显示帖子发表时间

  • 进入板块后显示主题列表页面指: /forums/show/xxxx.page 页面
    forum_show.htm页面224行改成:
    <span class="postdetails">${topic.firstPostTime}<br />
    <a href="${JForumContext.encodeURL("/user/profile/${topic.postedBy.id}")}">${topic.postedBy.username}</a></span>

    176行改成:width=140


  • bmp图片也显示缩略图

  • 用户经常用print screen键拷贝屏幕图片,并发到帖子上,是bmp格式,不能显示缩略图,要下载才能看,不太方便。这里改一下可显示缩略图 。
    AttachmentCommon.java 254行添加:"bmp".equals(extension) ||

    This message was edited 3 times. Last update was at 2008-06-15 12:28:46

    andowson

    六段學員
    [Avatar]

    Joined: 2007-01-02 22:20:40
    Messages: 652
    Location: 台北
    Offline

  • 發表文章表單的國際化

  • 針對發表文章時的國際化,我的處理方式是將新產生的語系key歸類為PostForm類別下,由於原本的PostForm.options已經存在,重複使用即可,故我們只需新增兩個新的key: PostForm.poll和PostForm.attachments
    en_US.properties
    PostForm.options= Options
    PostForm.poll = Poll
    PostForm.attachments = Attachments


    zh_CN.properties
    PostForm.options                = \u9009\u9879
    PostForm.poll                   = \u6295\u7968
    PostForm.attachments	        = \u9644\u4ef6


    zh_TW.properties
    PostForm.options                = \u9078\u9805
    PostForm.poll                   = \u7968\u9078\u6D3B\u52D5
    PostForm.attachments            = \u9644\u52A0\u6A94\u6848


    接著將post_form.htm的:
    							    <li target="postOptions" ><a  ><span>Options</span></a></li>
    
    								<#if allowPoll>
    									<li target="postPoll"><a  ><span>Poll</span></a></li>
    								</#if>
    								<#if attachmentsEnabled>
    								    <li target="postAttachments"><a  ><span>Attachments</span></a></li>
    								</#if>
    

    修改為:
    							    <li target="postOptions" ><a  ><span>${I18n.getMessage("PostForm.options")}</span></a></li>
    
    								<#if allowPoll>
    									<li target="postPoll"><a  ><span>${I18n.getMessage("PostForm.poll")}</span></a></li>
    								</#if>
    								<#if attachmentsEnabled>
    								    <li target="postAttachments"><a  ><span>${I18n.getMessage("PostForm.attachments")}</span></a></li>
    								</#if>
    


  • 文章作者資訊顯示IP,並可超連結至whois.domaintools.com,取得詳細資訊

  • 這邊我的處理方式是當使用者為版主或作者時顯示IP
    <#if post.userIp?exists && (isModerator || post.userId == session.userId)>
    	${I18n.getMessage("PostShow.userIP")}: <a href="http://whois.domaintools.com/${post.userIp}"  target="_blank">${post.userIp}</a>
    	<br />
    </#if>

    This message was edited 1 time. Last update was at 2008-06-15 18:47:31


    分享經驗 累積智慧
    [WWW] [MSN]
    lynx286

    九級學員

    Joined: 2008-04-24 12:03:16
    Messages: 10
    Offline

  • 将整个论坛页面宽度由满屏改为固定宽度

  • header.htm 31行: <table width="950" border="0" ALIGN="center">

  • 将论坛跳转下拉框放到上面

  • post_show.htm 等页面 90 行,加上下面代码:
    <td align="left">
    					<span class="gensmall">${I18n.getMessage("ForumIndex.goTo")}:&nbsp;</span>
    					<select onchange="if(this.options[this.selectedIndex].value != -1){ document.location = '${contextPath}/forums/show/'+ this.options[this.selectedIndex].value +'${extension}'; }" name="select">
    						<option value="-1" selected="selected">${I18n.getMessage("ForumIndex.goToSelectAForum")}</option>				
    						
    						<#list allCategories as category>
                                <optgroup label="${category.name}">
    		
    							<#list category.getForums() as forum>
    								<option value="${forum.id}">${forum.name}</option>
    							</#list>
    							</optgroup>
    						</#list>
    					</select>
    					&nbsp;
    					<input class="liteoption" type="button" value="${I18n.getMessage("ForumIndex.goToGo")}" onclick="if(document.f.select.options[document.f.select.selectedIndex].value != -1){ document.location = '${contextPath}/forums/show/'+ document.f.select.options[document.f.select.selectedIndex].value +'${extension}'; }" />
    				  </td>
    

    此段代码可以从 macros\presentaion.ftl 中 <#macro forumsComboTable> 里面拷贝。
    参考:
    http://www.mydwbi.com/posts/list/103.page
    andowson

    六段學員
    [Avatar]

    Joined: 2007-01-02 22:20:40
    Messages: 652
    Location: 台北
    Offline

  • 讓一般使用者可以刪除自己發表的文章

  • 1.打開權限:到系統管理控制台->群組管理->一般使用者->權限->可以刪除文章->是
    2.修改templates/default/post_show_action_buttons_inc.htm裡面的22行:
    <#if canRemove && (((post.userId == session.userId) && (session.userId != 1)) || isModerator || isAdmin)>
    

    3.重新載入JForum即可。

    This message was edited 3 times. Last update was at 2008-08-09 18:40:19


    分享經驗 累積智慧
    [WWW] [MSN]
    lynx286

    九級學員

    Joined: 2008-04-24 12:03:16
    Messages: 10
    Offline

    让附件图片支持gif动画:
    http://www.mydwbi.com/posts/list/470.page

    AttachmentCommon.java:

    private boolean shouldCreateThumb(Attachment a) {
    		if (SystemGlobals
    				.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_CREATE_THUMB)) {
    			String extension = a.getInfo().getExtension().getExtension()
    					.toLowerCase();
    			if (Attachment.isPicture(extension)) {
    				String path = SystemGlobals
    						.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR)
    						+ "/" + a.getInfo().getPhysicalFilename();
    				File fileOriginal = new File(path);
    				Image imageOriginal = null;
    				try {
    					imageOriginal = ImageIO.read(fileOriginal);
    				} catch (IOException e) {
    					e.printStackTrace();
    				}
    				int widthOriginal = imageOriginal.getWidth(null);
    				int heightOriginal = imageOriginal.getHeight(null);
    				if (widthOriginal > 800 || heightOriginal > 600)
    					return true;
    				else
    					return false;
    			} else
    				return false;
    		} else
    			return false;
    	}
    



    Attachment.java:

    public boolean hasThumb() {
    		String pName = this.info.getPhysicalFilename();
    		String extension = pName.substring(pName.lastIndexOf('.') + 1, pName
    				.length() - 1);
    		if (isPicture(extension)
    				&& SystemGlobals
    						.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_CREATE_THUMB))
    			return true;
    		else
    			return false;
    	}
    
    	public String thumbPath() {
    		String fileDir = SystemGlobals
    				.getValue(ConfigKeys.ATTACHMENTS_UPLOAD_DIR)
    				+ '/' + this.info.getPhysicalFilename();
    		String path = SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR)
    				+ "/" + this.info.getPhysicalFilename();
    		if (new File(path + "_thumb").exists()) {
    			return fileDir + "_thumb";
    		} else {
    			return fileDir;
    		}
    	}
    
    	public static boolean isPicture(String extension) {
    		if ("bmp".equals(extension) || "jpg".equals(extension)
    				|| "jpeg".equals(extension) || "gif".equals(extension)
    				|| "png".equals(extension))
    			return true;
    		else
    			return false;
    	}
    



    让头像也支持gif动画:
    http://www.mydwbi.com/posts/list/471.page


    UserCommon.java:

    private static void handleAvatar(User u) {
    		String fileName = MD5.crypt(Integer.toString(u.getId()));
    		FileItem item = (FileItem) JForumExecutionContext.getRequest()
    				.getObjectParameter("avatar");
    		UploadUtils uploadUtils = new UploadUtils(item);
    
    		// Gets file extension
    		String extension = uploadUtils.getExtension().toLowerCase();
    		int type = ImageUtils.IMAGE_UNKNOWN;
    		if (extension.equals("jpg") || extension.equals("jpeg")) {
    			type = ImageUtils.IMAGE_JPEG;
    		} else if (extension.equals("gif")) {
    			type = ImageUtils.IMAGE_GIF;
    		} else if (extension.equals("png")) {
    			type = ImageUtils.IMAGE_PNG;
    		}
    
    		if (type != ImageUtils.IMAGE_UNKNOWN) {
    			String avatarFinalFileName = SystemGlobals.getApplicationPath()
    					+ "/images/avatar/" + fileName + "." + extension;
    			uploadUtils.saveUploadedFile(avatarFinalFileName);
    			File avatar = new File(avatarFinalFileName);
    			Image imageOriginal = null;
    			try {
    				imageOriginal = ImageIO.read(avatar);
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    			int widthOriginal = imageOriginal.getWidth(null);
    			int heightOriginal = imageOriginal.getHeight(null);
    			if (widthOriginal <= 130 && heightOriginal <= 130) {
    				u.setAvatar(fileName + "." + extension);
    			}else{
    				avatar.delete();
    			}
    		}
    	}
    
    andowson

    六段學員
    [Avatar]

    Joined: 2007-01-02 22:20:40
    Messages: 652
    Location: 台北
    Offline

    關於gif部分,我改良了一下lynx286的修改方式:
    AttachmentCommon.java:
    將最大寬度跟高度改為由系統參數檔設定
    	private boolean shouldCreateThumb(Attachment a) {
    		String extension = a.getInfo().getExtension().getExtension().toLowerCase();
    		if (SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_CREATE_THUMB)
                && Attachment.isPicture(extension)) {
                String path = SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR)
    			     + "/" 
    			     + a.getInfo().getPhysicalFilename();
    		    File imageFile = new File(path);
    		    BufferedImage image = null;
    		    try {
    			    image = ImageIO.read(imageFile);
    		    } catch (IOException e) {
    			    e.printStackTrace();
    		    }
    		    int width = image.getWidth(null);
    		    int height = image.getHeight(null);
    		    return (width > SystemGlobals.getIntValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_W) 
    		        || height > SystemGlobals.getIntValue(ConfigKeys.ATTACHMENTS_IMAGES_MAX_THUMB_H));
            }
            return false;
    	}
    

    Attachment.java:
    精簡一下程式碼
    	public boolean hasThumb() 
    	{
    		String filename = this.info.getPhysicalFilename();
    		String extension = filename.substring(filename.lastIndexOf('.') + 1, 
    				filename.length() - 1);
    		return SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_CREATE_THUMB)
    			&& isPicture(extension);
    	}
    	
    	public String thumbPath() {
    		String urlPath = SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_UPLOAD_DIR)
    		    + '/' + this.info.getPhysicalFilename();
    		String realPath = SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR)
    		    + "/" + this.info.getPhysicalFilename();
    		if (new File(realPath + "_thumb").exists()) {
    			return urlPath + "_thumb";
    		} else {
    			return urlPath;
    		}    
    	}
    	
    	public static boolean isPicture(String extension) {
    		return ("jpg".equals(extension) || "jpeg".equals(extension) 
    				|| "gif".equals(extension) || "png".equals(extension)
    				|| "bmp".equals(extension));
    	}
    

    UserCommon.java:
    增加刪除舊的個人頭像,比對用的最大寬度跟高度調整為以系統設定值為準,及將過大的gif轉為png
    	private static void handleAvatar(User u)
    	{
    		// Delete old avatar file
    		if (u.getAvatar() != null) {
    			File avatarFile = new File(u.getAvatar());
    			
    			File fileToDelete = new File(SystemGlobals.getApplicationPath() 
    				+ "/images/avatar/"
    				+ avatarFile.getName());
    			
    			if (fileToDelete.exists()) {
    				fileToDelete.delete();
    			}
    		}
    		
    		String fileName = MD5.crypt(Integer.toString(u.getId()));
    		FileItem item = (FileItem)JForumExecutionContext.getRequest().getObjectParameter("avatar");
    		UploadUtils uploadUtils = new UploadUtils(item);
    		
    		// Gets file extension
    		String extension = uploadUtils.getExtension().toLowerCase();
    		int type = ImageUtils.IMAGE_UNKNOWN;
    		
    		if (extension.equals("jpg") || extension.equals("jpeg")) {
    			type = ImageUtils.IMAGE_JPEG;
    		} else if (extension.equals("gif")) {  
    			type = ImageUtils.IMAGE_GIF;  
    		} else if (extension.equals("png")) {  
    			type = ImageUtils.IMAGE_PNG;  
    		}
    		
    		if (type != ImageUtils.IMAGE_UNKNOWN) {
    			String avatarTmpFileName = SystemGlobals.getApplicationPath() 
    				+ "/images/avatar/" 
    				+ fileName 
    				+ "_tmp." 
    				+ extension;
    	
    			String avatarFinalFileName = SystemGlobals.getApplicationPath() 
    				+ "/images/avatar/" 
    				+ fileName 
    				+ "." 
    				+ extension;
    	
    			uploadUtils.saveUploadedFile(avatarTmpFileName);		
    
    			// OK, time to check and process the avatar size
    			int maxWidth = SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_WIDTH);
    			int maxHeight = SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_HEIGHT);
    
    			File avatar = new File(avatarTmpFileName); 
    			BufferedImage imageOriginal = null;
    			try {
    				imageOriginal = ImageIO.read(avatar);
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    			int width = imageOriginal.getWidth(null);
    			int height = imageOriginal.getHeight(null);
    
    			if (width > maxWidth || height > maxHeight) {				
    				if (type == ImageUtils.IMAGE_GIF) {
    					type = ImageUtils.IMAGE_PNG;
    					extension = "png";
    				}
    				BufferedImage image = ImageUtils.resizeImage(avatarTmpFileName, type, maxWidth, maxHeight);				
    				ImageUtils.saveImage(image, avatarFinalFileName, type);
    				// Delete the temporary file
    				avatar.delete();
    			} else {
    				avatar.renameTo(new File(avatarFinalFileName));
    			}
    			u.setAvatar(fileName + "." + extension);
    		}
    	}
    

    This message was edited 1 time. Last update was at 2008-12-13 13:54:14


    分享經驗 累積智慧
    [WWW] [MSN]
     
    Forum Index » JForum中文社群 JForum Chinese Users Community
    Go to: