Skip to content

Commit 00c64b5

Browse files
committed
Merge branch 'develop' into feature/modularize-editor
Conflicts: WordPress/src/main/java/org/wordpress/android/ui/accounts/ManageBlogsActivity.java
2 parents 3c894b2 + 5771cb1 commit 00c64b5

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package org.wordpress.android.util;
22

3-
import android.text.TextUtils;
4-
53
public class GravatarUtils {
64
/*
75
* see https://en.gravatar.com/site/implement/images/
86
*/
9-
public static String gravatarUrlFromEmail(final String email, int size) {
10-
if (TextUtils.isEmpty(email))
11-
return "";
12-
13-
String url = "http://gravatar.com/avatar/"
14-
+ StringUtils.getMd5Hash(email)
15-
+ "?d=mm";
16-
17-
if (size > 0)
18-
url += "&s=" + Integer.toString(size);
7+
public static String gravatarFromEmail(final String email, int size) {
8+
return "http://gravatar.com/avatar/"
9+
+ StringUtils.getMd5Hash(StringUtils.notNullStr(email))
10+
+ "?d=mm&size=" + Integer.toString(size);
11+
}
1912

20-
return url;
13+
/*
14+
* important: the 404 default means the request will 404 if there is no blavatar
15+
* for the passed site - so the caller needs to trap the 404 to provide a default
16+
*/
17+
public static String blavatarFromUrl(final String url, int size) {
18+
return "http://gravatar.com/blavatar/"
19+
+ StringUtils.getMd5Hash(UrlUtils.getDomainFromUrl(url))
20+
+ "?d=404&size=" + Integer.toString(size);
2121
}
2222
}

WordPressUtils/src/main/java/org/wordpress/android/util/PhotonUtils.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* http://developer.wordpress.com/docs/photon/
88
*/
99
public class PhotonUtils {
10+
1011
private PhotonUtils() {
1112
throw new AssertionError();
1213
}
@@ -73,30 +74,29 @@ public static String getPhotonImageUrl(String imageUrl, int width, int height, Q
7374
return imageUrl + "?w=" + width + "&h=" + height;
7475
}
7576

76-
final String qualityParam;
77+
// strip=all removes EXIF and other non-visual data from JPEGs
78+
String query = "?strip=all";
79+
7780
switch (quality) {
7881
case HIGH:
79-
qualityParam = "quality=100";
82+
query += "&quality=100";
8083
break;
8184
case LOW:
82-
qualityParam = "quality=35";
85+
query += "&quality=35";
8386
break;
8487
default: // medium
85-
qualityParam = "quality=65";
88+
query += "&quality=65";
8689
break;
8790
}
8891

8992
// if both width & height are passed use the "resize" param, use only "w" or "h" if just
9093
// one of them is set
91-
final String query;
9294
if (width > 0 && height > 0) {
93-
query = "?resize=" + width + "," + height + "&" + qualityParam;
95+
query += "&resize=" + width + "," + height;
9496
} else if (width > 0) {
95-
query = "?w=" + width + "&" + qualityParam;
97+
query += "&w=" + width;
9698
} else if (height > 0) {
97-
query = "?h=" + height + "&" + qualityParam;
98-
} else {
99-
query = "?" + qualityParam;
99+
query += "&h=" + height;
100100
}
101101

102102
// return passed url+query if it's already a photon url

WordPressUtils/src/main/java/org/wordpress/android/util/UrlUtils.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import android.webkit.MimeTypeMap;
55
import android.webkit.URLUtil;
66

7+
import org.wordpress.android.util.AppLog.T;
8+
79
import java.io.UnsupportedEncodingException;
810
import java.net.IDN;
911
import java.net.URI;
12+
import java.net.URL;
1013
import java.net.URLDecoder;
1114
import java.net.URLEncoder;
1215
import java.nio.charset.Charset;
@@ -52,11 +55,40 @@ public static String convertUrlToPunycodeIfNeeded(String url) {
5255
return url;
5356
}
5457

58+
/**
59+
* Remove leading double slash, and inherit protocol scheme
60+
*/
61+
public static String removeLeadingDoubleSlash(String url, String scheme) {
62+
if (url != null && url.startsWith("//")) {
63+
url = url.substring(2);
64+
if (scheme != null) {
65+
if (scheme.endsWith("://")){
66+
url = scheme + url;
67+
} else {
68+
AppLog.e(T.UTILS, "Invalid scheme used: " + scheme);
69+
}
70+
}
71+
}
72+
return url;
73+
}
74+
75+
/**
76+
* Add scheme prefix to an URL. This method must be called on all user entered or server fetched URLs to ensure
77+
* http client will work as expected.
78+
*
79+
* @param url url entered by the user or fetched from a server
80+
* @param isHTTPS true will make the url starts with https;//
81+
* @return transformed url prefixed by its http;// or https;// scheme
82+
*/
5583
public static String addUrlSchemeIfNeeded(String url, boolean isHTTPS) {
5684
if (url == null) {
5785
return null;
5886
}
5987

88+
// Remove leading double slash (eg. //example.com), needed for some wporg instances configured to
89+
// switch between http or https
90+
url = removeLeadingDoubleSlash(url, (isHTTPS ? "https" : "http") + "://");
91+
6092
if (!URLUtil.isValidUrl(url)) {
6193
if (!(url.toLowerCase().startsWith("http://")) && !(url.toLowerCase().startsWith("https://"))) {
6294
url = (isHTTPS ? "https" : "http") + "://" + url;
@@ -78,7 +110,8 @@ public static String normalizeUrl(final String urlString) {
78110
// this routine is called from some performance-critical code and creating a URI from a string
79111
// is slow, so skip it when possible - if we know it's not a relative path (and 99.9% of the
80112
// time it won't be for our purposes) then we can normalize it without java.net.URI.normalize()
81-
if (urlString.startsWith("http") && !urlString.contains("build/intermediates/exploded-aar/org.wordpress/graphview/3.1.1")) {
113+
if (urlString.startsWith("http") &&
114+
!urlString.contains("build/intermediates/exploded-aar/org.wordpress/graphview/3.1.1")) {
82115
// return without a trailing slash
83116
if (urlString.endsWith("/")) {
84117
return urlString.substring(0, urlString.length() - 1);

0 commit comments

Comments
 (0)