Skip to content

Commit 55037d2

Browse files
committed
Use homeURL instead of hostName to show the blog address. WordPress can be installed in a sub-directory, and so the host name will be the same for two subdir installations on the same host.
1 parent b534e1d commit 55037d2

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ public class BlogUtils {
88
public int compare(Object blog1, Object blog2) {
99
Map<String, Object> blogMap1 = (Map<String, Object>) blog1;
1010
Map<String, Object> blogMap2 = (Map<String, Object>) blog2;
11-
String blogName1 = getBlogNameOrHostNameFromAccountMap(blogMap1);
12-
String blogName2 = getBlogNameOrHostNameFromAccountMap(blogMap2);
11+
String blogName1 = getBlogNameOrHomeURLFromAccountMap(blogMap1);
12+
String blogName2 = getBlogNameOrHomeURLFromAccountMap(blogMap2);
1313
return blogName1.compareToIgnoreCase(blogName2);
1414
}
1515
};
1616

1717
/**
18-
* Return a blog name or blog url (host part only) if trimmed name is an empty string
18+
* Return a blog name or blog home URL if trimmed name is an empty string
1919
*/
20-
public static String getBlogNameOrHostNameFromAccountMap(Map<String, Object> account) {
20+
public static String getBlogNameOrHomeURLFromAccountMap(Map<String, Object> account) {
2121
String blogName = getBlogNameFromAccountMap(account);
2222
if (blogName.trim().length() == 0) {
23-
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
23+
blogName = BlogUtils.getHomeURLOrHostNameFromAccountMap(account);
2424
}
2525
return blogName;
2626
}
@@ -33,9 +33,18 @@ public static String getBlogNameFromAccountMap(Map<String, Object> account) {
3333
}
3434

3535
/**
36-
* Return blog url (host part only) if trimmed name is an empty string
36+
* Return the blog home URL setting or the host name if home URL is an empty string.
3737
*/
38-
public static String getHostNameFromAccountMap(Map<String, Object> account) {
39-
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
38+
public static String getHomeURLOrHostNameFromAccountMap(Map<String, Object> account) {
39+
String homeURL = MapUtils.getMapStr(account, "homeURL").replace("http://", "").replace("https://", "").trim();
40+
if (homeURL.endsWith("/")) {
41+
homeURL = homeURL.substring(0, homeURL.length() -1);
42+
}
43+
44+
if (homeURL.length() == 0) {
45+
return StringUtils.getHost(MapUtils.getMapStr(account, "url"));
46+
}
47+
48+
return homeURL;
4049
}
4150
}

0 commit comments

Comments
 (0)