Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 3 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
5 app/controllers/Galleries.java
@@ -14,6 +14,7 @@
import play.data.validation.Required;
import play.mvc.Controller;
import play.mvc.With;
+import utils.LinkifyExtensions;
import controllers.Secure.Security;
/**
@@ -94,7 +95,7 @@ public static void getNewerPhoto(Long id, Long lastId){
pMap.put("poster", photo.poster.username);
pMap.put("image_thumb", photo.thumbImageUrl);
pMap.put("image_full", photo.fullImageUrl);
- pMap.put("tweet_text", photo.message);
+ pMap.put("message", LinkifyExtensions.linkify(photo.message).toString());
pMap.put("id", photo.id);
photoList.add(pMap);
}
@@ -112,7 +113,7 @@ public static void getOlderPhoto(Long id, Long startId){
pMap.put("poster", photo.poster.username);
pMap.put("image_thumb", photo.thumbImageUrl);
pMap.put("image_full", photo.fullImageUrl);
- pMap.put("tweet_text", photo.message);
+ pMap.put("message", LinkifyExtensions.linkify(photo.message).toString());
pMap.put("id", photo.id);
photoList.add(pMap);
}
View
12 app/models/Photo.java
@@ -90,18 +90,6 @@ public boolean hasExpired(long currentTimeMillis) {
return photos;
}
- public static List<Photo> findByGalleryAndRevalidate(Gallery gallery, Long startId, Long endId, int limit) {
- startId = startId > 0 ? startId : 0;
- endId = endId > 0 ? endId : startId + 50;
- List<Photo> photos = Photo.find("gallery = ? AND id > ? AND id < ? ORDER BY id DESC", gallery, startId, endId).fetch(limit);
- for (Photo photo : photos) {
- if (photo.hasExpired(System.currentTimeMillis() + TEN_SECONDS)) {
- revalidate(photo);
- }
- }
- return photos;
- }
-
public static Photo findGallerySnap(Gallery gallery) {
Photo photo = Photo.find("gallery = ?", gallery).first();
if (photo != null && photo.hasExpired(System.currentTimeMillis() + TEN_SECONDS)) {
View
26 app/utils/LinkifyExtensions.java
@@ -0,0 +1,26 @@
+package utils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import play.templates.JavaExtensions;
+import play.templates.BaseTemplate.RawData;
+
+/**
+ * @author uudashr@gmail.com
+ *
+ */
+public class LinkifyExtensions extends JavaExtensions {
+
+ public static RawData linkify(String message) {
+ Pattern pattern = Pattern.compile("(http|https|ftp)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?\\/?([a-zA-Z0-9\\-\\._\\?\\,\\'\\/\\\\\\+&amp;%\\$#\\=~])*");
+ Matcher matcher = pattern.matcher(message);
+ StringBuffer sb = new StringBuffer();
+ while (matcher.find()) {
+ String match = message.substring(matcher.start(), matcher.end());
+ matcher.appendReplacement(sb, "<a href=\"" + match + "\">" + match + "</a>");
+ }
+ matcher.appendTail(sb);
+ return raw(sb.toString());
+ }
+}
View
6 app/views/Galleries/details.html
@@ -52,14 +52,14 @@
function morePhoto(json) {
$.each(json.photos,function(i,photo){
- $("#photos").append('<div class="photo-item" data-id="' + photo.id + '"> <div class="photo"> <a href="' + showPhotoDetailsAction({id:photo.id}) + '"> <img alt="photo"src="'+photo.image_thumb+'"></a></div><a href="http://twitter.com/#!/' + photo.poster + '" class="poster">'+photo.poster+'</a><p>'+photo.tweet_text+'</p></div>')
+ $("#photos").append('<div class="photo-item" data-id="' + photo.id + '"> <div class="photo"> <a href="' + showPhotoDetailsAction({id:photo.id}) + '"> <img alt="photo"src="' + photo.image_thumb + '"></a></div><a href="http://twitter.com/#!/' + photo.poster + '" class="poster">' + photo.poster + '</a><p>' + photo.message + '</p></div>')
});
$('#photos').find(".new-item").slideDown("slow");
}
function newPhoto(json) {
$.each(json.photos,function(i,photo){
- $("#photos").prepend('<div class="photo-item" data-id="' + photo.id + '"> <div class="photo"> <a href="' + showPhotoDetailsAction({id:photo.id}) + '"> <img alt="photo"src="'+photo.image_thumb+'"></a></div><a href="http://twitter.com/#!/' + photo.poster + '" class="poster">'+photo.poster+'</a><p>'+photo.tweet_text+'</p></div>')
+ $("#photos").prepend('<div class="photo-item" data-id="' + photo.id + '"> <div class="photo"> <a href="' + showPhotoDetailsAction({id:photo.id}) + '"> <img alt="photo"src="' + photo.image_thumb + '"></a></div><a href="http://twitter.com/#!/' + photo.poster + '" class="poster">' + photo.poster + '</a><p>' + photo.message + '</p></div>')
});
$('#photos').find(".new-item").slideDown("slow");
}
@@ -90,7 +90,7 @@
</a>
</div>
<a href="http://twitter.com/#!/${photo.poster.username}" class="poster">@${photo.poster.username}</a>
- <p>${photo.message}</p>
+ <p>${photo.message.linkify()}</p>
</div>
#{/list}
</div>
View
2 app/views/Photos/details.html
@@ -60,7 +60,7 @@
<a href="http://twitter.com/#!/${photo.poster.username}" class="poster">${photo.poster.username}</a> <span class="date">${photo.referenceDate.since()}</span>
</div>
<div id="user-content">
- ${photo.message}
+ ${photo.message.linkify()}
</div>
<div id="photo-content">
<img alt="photo" src="${photo.fullImageUrl}"/>

No commit comments for this range

Something went wrong with that request. Please try again.