Browse Source

点赞和头像调整

huangct 8 years ago
parent
commit
4a1d0a0fb6

+ 16 - 0
jpress-model/src/main/java/io/jpress/model/Comment.java

@@ -22,7 +22,10 @@ import io.jpress.model.query.ContentQuery;
 import io.jpress.model.query.UserQuery;
 import io.jpress.model.query.VoteQuery;
 
+import java.io.InputStream;
 import java.math.BigInteger;
+import java.net.URL;
+import java.net.URLConnection;
 
 @Table(tableName = "comment", primaryKey = "id")
 public class Comment extends BaseComment<Comment> {
@@ -153,4 +156,17 @@ public class Comment extends BaseComment<Comment> {
 	public boolean isvoted(BigInteger commentId, BigInteger userId, BigInteger uuUserId) {
 		return VoteQuery.me().findCommentCountVote(commentId, userId, uuUserId);
 	}
+
+	public boolean isImageExist(String urlStr) {
+		try {
+			URL url = new URL(urlStr);
+			// 返回一个 URLConnection 对象,它表示到 URL 所引用的远程对象的连接。
+			URLConnection uc = url.openConnection();
+			// 打开的连接读取的输入流。
+			InputStream in = uc.getInputStream();
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+	}
 }

+ 5 - 1
jpress-web-admin/src/main/webapp/WEB-INF/admin/comment/uuHelperCommentList.html

@@ -108,7 +108,11 @@
                                 <td>
                                     <div class="messageContent">
                                         <div class="leftImg">
-                                            <img src="${(bean.uu_user_avatar)!(bean.user.avatar)!CPATH+'/static/jpress/admin/image/nothumbnail.jpg'}" alt="头像">
+                                            <#if bean?? && bean.uu_user_avatar?? && bean.isImageExist(bean.uu_user_avatar)>
+                                                <img src="${(bean.uu_user_avatar)!}" alt="">
+                                                <#else>
+                                                    <img src="${CPATH}/static/jpress/admin/image/defaultUuUserPhoto.png" alt="">
+                                            </#if>
                                         </div>
                                         <div class="rightContent">
                                             <p>${bean.author!}</p>

BIN
jpress-web-core/src/main/webapp/static/jpress/admin/image/defaultUuUserPhoto.png


+ 10 - 5
jpress-web-front/src/main/java/io/jpress/front/controller/CommentController.java

@@ -202,7 +202,12 @@ public class CommentController extends BaseFrontController {
 			htmlBuilder.append("<div class=\"message\">");
 			htmlBuilder.append("<div class=\"left\">");
 			htmlBuilder.append("<div class=\"img\">");
-			htmlBuilder.append("<img src=\"/jpress/static/jpress/admin/image/dot.png\" alt=\"用户头像\">");
+			String userImage = comment.getUuUserAvatar();
+			if (!comment.isImageExist(userImage)) {
+				userImage = getPara("CPATH") + "/static/jpress/admin/image/defaultUuUserPhoto.png";
+			}
+
+			htmlBuilder.append("<img src=\""+ userImage +"\"" + " alt=\"\">");
 			htmlBuilder.append("</div>");
 			htmlBuilder.append("</div>");
 			htmlBuilder.append("<div class=\"right\">");
@@ -215,10 +220,10 @@ public class CommentController extends BaseFrontController {
 			String imageUrl = null;
 			if (comment.isvoted(comment.getId(), userId, uuUserId)) {
 				htmlBuilder.append(" voted\" ");
-				imageUrl = "/jpress/static/jpress/admin/image/support.png";
+				imageUrl = getPara("CPATH") + "/static/jpress/admin/image/support.png";
 			} else {
 				htmlBuilder.append("\"");
-				imageUrl = "/jpress/static/jpress/admin/image/hands.png";
+				imageUrl = getPara("CPATH") + "/static/jpress/admin/image/hands.png";
 			}
 
 			htmlBuilder.append(" src="+ imageUrl + " alt=\"\" onclick=\"vote("+ comment.getId()+")\"><em class=\"em" + comment.getId() + "\">" + comment.getVoteUp() + "</em></span>");
@@ -234,10 +239,10 @@ public class CommentController extends BaseFrontController {
 				String sonImageUrl = null;
 				if (sonComment.isvoted(sonComment.getId(), userId, uuUserId)) {
 					htmlBuilder.append(" voted\" ");
-					sonImageUrl = "/jpress/static/jpress/admin/image/support.png";
+					sonImageUrl = getPara("CPATH") + "/static/jpress/admin/image/support.png";
 				} else {
 					htmlBuilder.append("\"");
-					sonImageUrl = "/jpress/static/jpress/admin/image/hands.png";
+					sonImageUrl = getPara("CPATH") + "/static/jpress/admin/image/hands.png";
 				}
 
 				htmlBuilder.append(" src="+ sonImageUrl+ " alt=\"\" onclick=\"vote("+ sonComment.getId()+")\"><em class=\"em" + sonComment.getId() + "\">" + sonComment.getVoteUp() + "</em></span>");

+ 21 - 12
jpress-web-template-usoftchina/src/main/webapp/templates/usoftchina/content_uuhelper.html

@@ -130,6 +130,10 @@
             width: 70px;
             height: 70px;
         }
+        .main .container .footer .footer-section .img img{
+           max-width: 70px;
+            max-height: 70px;
+        }
         .main .container .footer .footer-section .img img.imgUas{
             max-width: 70px;
             max-height: 70px;
@@ -256,8 +260,8 @@
             <div class="readCount">
                 <div>
                     <span>阅读 <em>${content.view_count!'0'}</em></span>
-                    <span><img img class="voteContent <#if content.isvoted(content.id, userId!0, userid!0)>voted</#if>" src="/jpress/static/jpress/admin/image/hands.png" alt="" onclick="voteContent(${content.id})"><em class="voteContentCount">${content.vote_up!'0'}</em></span>
-                    <!--<span><img src="/jpress/static/jpress/admin/image/support.png" alt=""/><em>1</em></span>-->
+                    <span><img img class="voteContent <#if content.isvoted(content.id, userId!0, userid!0)>voted</#if>" src="${CPATH}/static/jpress/admin/image/hands.png" alt="" onclick="voteContent(${content.id})"><em class="voteContentCount">${content.vote_up!'0'}</em></span>
+                    <!--<span><img src="${CPATH}/static/jpress/admin/image/support.png" alt=""/><em>1</em></span>-->
                 </div>
                 <p>${(content.getMetadataByKey("copy_right"))!}</p>
             </div>
@@ -272,7 +276,7 @@
                     <input type="hidden" name="uuUserAvatar" value="${iconurl!}" >
 
                     <div class="footer-header">
-                        <div class="infoMessage"><span>写留言</span><img src="/jpress/static/jpress/admin/image/pen.png" alt=""/></div>
+                        <div class="infoMessage"><span>写留言</span><img src="${CPATH}/static/jpress/admin/image/pen.png" alt=""/></div>
                         <div class="writeMessage">
                             <textarea name="text" id="" cols="30" rows="10"></textarea>
                             <div><button class="cancel">取消</button><button type="submit">提交</button></div>
@@ -287,20 +291,25 @@
                         <div class="message">
                             <div class="left">
                                 <div class="img" >
-                                    <img src="${comment.uu_user_avatar!'/jpress/static/jpress/admin/image/dot.png'}" alt="用户头像">
+                                    <#if comment?? && comment.uu_user_avatar?? && comment.isImageExist(comment.uu_user_avatar)>
+                                        <img src="${(comment.uu_user_avatar)!}" alt="">
+                                    <#else>
+                                        <img src="${CPATH}/static/jpress/admin/image/defaultUuUserPhoto.png" alt="">
+                                    </#if>
+
                                 </div>
                             </div>
                             <div class="right">
                                 <div class="detail">
                                     <div class="title">
                                         <span>${comment.author!} <em>${(comment.created?string("yyyy-MM-dd"))!}</em></span>
-                                        <span><img class="votedUas${comment.id} <#if comment.isvoted(comment.id, userId!0, userid!0)>voted</#if>" src="/jpress/static/jpress/admin/image/hands.png" alt="" onclick="vote(${comment.id})"/><em class="em${comment.id}">${(comment.vote_up)!'0'}</em></span>
+                                        <span><img class="votedUas${comment.id} <#if comment.isvoted(comment.id, userId!0, userid!0)>voted</#if>" src="${CPATH}/static/jpress/admin/image/hands.png" alt="" onclick="vote(${comment.id})"/><em class="em${comment.id}">${(comment.vote_up)!'0'}</em></span>
                                     </div>
                                     <p>${comment.text!}</p>
                                     <#if comment.qc_content ??>
                                         <div class="title reply">
                                             <span>作者回复: <em>${(comment.qc_created?string("yyyy-MM-dd"))!}</em></span>
-                                            <span><img class="votedUas${comment.qc_id} <#if comment.isvoted(comment.qc_id, userId!0, userid!0)>voted</#if>" src="/jpress/static/jpress/admin/image/hands.png" alt="" onclick="vote(${comment.qc_id})"/><em class="em${comment.qc_id}">${(comment.qc_vote_up)!'0'}</em></span>
+                                            <span><img class="votedUas${comment.qc_id} <#if comment.isvoted(comment.qc_id, userId!0, userid!0)>voted</#if>" src="${CPATH}/static/jpress/admin/image/hands.png" alt="" onclick="vote(${comment.qc_id})"/><em class="em${comment.qc_id}">${(comment.qc_vote_up)!'0'}</em></span>
                                         </div>
                                         <p>${comment.qc_content!}</p>
                                     </#if>
@@ -312,7 +321,7 @@
                 </#if>
             </@jp.commentPage>
             </div>
-            <div class="loading"><img src="/jpress/static/jpress/admin/image/loading.png" alt="" class="loadingImg"></div>
+            <div class="loading"><img src="${CPATH}/static/jpress/admin/image/loading.png" alt="" class="loadingImg"></div>
             <div class="pull">下拉加载更多</div>
             <!--<div class="pull"><a>没有更多数据了</a></div>-->
         </div>
@@ -380,7 +389,7 @@
     $(document).ready(function() {
         userId = "${userId!0}"
         uuUserId = "${userid!0}";
-        $('.voted').attr("src","/jpress/static/jpress/admin/image/support.png");
+        $('.voted').attr("src","${CPATH}/static/jpress/admin/image/support.png");
     });
     //滚动加载方法
     $(window).scroll(function() {
@@ -401,11 +410,11 @@
         if (imgObj.hasClass("voted")) {
             emObj.text(""+(parseInt(emObj.text())-1));
             imgObj.removeClass("voted");
-            imgObj.attr("src","/jpress/static/jpress/admin/image/hands.png");
+            imgObj.attr("src","${CPATH}/static/jpress/admin/image/hands.png");
         } else {
             emObj.text(""+(parseInt(emObj.text())+1));
             imgObj.addClass("voted");
-            imgObj.attr("src","/jpress/static/jpress/admin/image/support.png")
+            imgObj.attr("src","${CPATH}/static/jpress/admin/image/support.png")
         }
         $.get("${CPATH}/comment/vote?comment_id="+commentid+"&user_id="+userId+"&uu_user_id="+uuUserId, function(result){
             console.log(result.message);
@@ -419,11 +428,11 @@
         if (imgObj.hasClass("voted")) {
             emObj.text(""+(parseInt(emObj.text())-1));
             imgObj.removeClass("voted");
-            imgObj.attr("src","/jpress/static/jpress/admin/image/hands.png");
+            imgObj.attr("src","${CPATH}/static/jpress/admin/image/hands.png");
         } else {
             emObj.text(""+(parseInt(emObj.text())+1));
             imgObj.addClass("voted");
-            imgObj.attr("src","/jpress/static/jpress/admin/image/support.png")
+            imgObj.attr("src","${CPATH}/static/jpress/admin/image/support.png")
         }
         $.get("${CPATH}/c/vote?content_id="+contentId+"&user_id="+userId+"&uu_user_id="+uuUserId, function(result){
             console.log(result.message);