Skip to content

Commit

Permalink
Merge pull request #465 from fpellet/fix-accent-url
Browse files Browse the repository at this point in the history
Fix accent url
  • Loading branch information
albogdano authored Jan 11, 2025
2 parents fb5e690 + 354d92f commit 6e18436
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/erudika/scoold/core/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ public String getPostLink(boolean plural, boolean noid) {

public String getPostLink(boolean plural, boolean noid, boolean withContextPathPrefix) {
Post p = this;
String ptitle = Utils.noSpaces(Utils.stripAndTrim(p.getTitle()), "-");
String pid = (noid ? "" : "/" + p.getId() + "/" + ptitle);
String ptitle = StringUtils.stripAccents(Utils.noSpaces(Utils.stripAndTrim(p.getTitle()), "-"));
String pid = (noid ? "" : "/" + Utils.urlEncode(p.getId()) + "/" + Utils.urlEncode(ptitle));
String ctx = withContextPathPrefix ? CONF.serverContextPath() : "";
if (p.isQuestion()) {
return ctx + (plural ? ScooldServer.QUESTIONSLINK : ScooldServer.QUESTIONLINK + pid);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/erudika/scoold/core/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.erudika.para.core.annotations.Stored;
import com.erudika.para.core.utils.Para;
import com.erudika.para.core.utils.Utils;
import com.erudika.scoold.ScooldServer;
import com.erudika.scoold.utils.ScooldUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.time.Instant;
Expand Down Expand Up @@ -752,6 +753,13 @@ public int countNewReports() {
return newreports;
}

public String getProfileLink() {
String name = StringUtils.stripAccents(Utils.noSpaces(Utils.stripAndTrim(this.getName()), "-"));
String seoName = StringUtils.isBlank(name) ? "" : ("/" + name);
String pid = "/" + Utils.urlEncode(this.getCreatorid()) + seoName;
return ScooldServer.PROFILELINK + pid;
}

public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass()) {
return false;
Expand Down
21 changes: 10 additions & 11 deletions src/main/resources/templates/macro.vm
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
<div class="row mbn userbox user-${userboxid}">
<div class="col s4 m5 l3">
#if ($showu)
<a href="$profilelink/$!showu.creatorid/#stripstr($!showu.name)" title="$!showu.name">
<a href="$!showu.getProfileLink()" title="$!showu.name">
<img src="#profilepic($!showu, 'Square50')" width="50" class="profile-pic responsive-img" alt="pic">
</a>
#else
Expand All @@ -368,7 +368,7 @@
</div>
<div class="userbox-body">
#if ($showu)
<a href="$profilelink/$!showu.creatorid/#stripstr($!showu.name)" class="userbox-name">$showu.name</a>
<a href="$!showu.getProfileLink()" class="userbox-name">$showu.name</a>
#else
<span class="grey-text">$!lang.get("profile.deleted")</span>
#end
Expand Down Expand Up @@ -396,7 +396,7 @@
#macro(tinypersonbox $showu)
<div>
#if ($showu)
<a href="$profilelink/$!showu.creatorid/#stripstr($!showu.name)" title="$!showu.name [$!showu.votes]">
<a href="$!showu.getProfileLink()" title="$!showu.name [$!showu.votes]">
<img src="#profilepic($!showu, 'Square32')" width="32" class="profile-pic responsive-img" alt="pic">
</a>
#else
Expand All @@ -408,8 +408,7 @@
#macro(personlink $showu)
<span>
#if ($showu)
#if ($showu.name)#set($seopsuffix = "/#stripstr($!showu.name)" )#else#set($seopsuffix = "" )#end
<a href="$profilelink/$!{showu.id}$!{seosuffix}" title="Go to profile">$!showu.name</a>
<a href="$!showu.getProfileLink()" title="Go to profile">$!showu.name</a>
#else
$!lang.get("profile.deleted")
#end
Expand Down Expand Up @@ -444,7 +443,7 @@
<div class="card personbox ${personboxClass} #if($scooldUtils.isBanned($showFriend) && $isMod)yellow lighten-5 #end">
<div class="row ${cardClass}">
<div class="col ${cardCol1Class}" title="$!showFriend.name">
<a href="$profilelink/$!showFriend.creatorid/#stripstr($!showFriend.name)" title="$!showFriend.name">
<a href="$!showFriend.getProfileLink()" title="$!showFriend.name">
<img src="#profilepic($showFriend, 'Square127')" class="profile-pic responsive-img" alt="pic">
</a>
</div>
Expand All @@ -466,12 +465,12 @@
<label for="$!showFriend.id">
<input type="checkbox" name="selectedUsers" value="$!showFriend.id" class="filled-in" id="$!showFriend.id">
<span>
<a href="$profilelink/${showFriend.creatorid}/#stripstr($!showFriend.name)">$!{showFriend.name}</a>
<a href="$!showFriend.getProfileLink()">$!{showFriend.name}</a>
</span>
</label>
</span>
#else
<a href="$profilelink/${showFriend.creatorid}/#stripstr($!showFriend.name)">$!{showFriend.name}</a>
<a href="$!showFriend.getProfileLink()">$!{showFriend.name}</a>
#end
</div>
#if($isAdmin && $request.getParameter("bulkedit") && !$hideSpacesForMods)
Expand Down Expand Up @@ -550,7 +549,7 @@
#macro(questionspage $posts )
#set($showSpaceLabel = $scooldUtils.isAllSpaces($currentSpace) || $isMod)
#foreach($showpost in $posts)
#set($actionlink = "#getpostlink($showpost false true)")
#set($actionlink = "#getpostlink($showpost false false)")
#set($actionlink2 = "#getpostlink($showpost true true)")
#if($showpost.id == $request.getParameter("deleted"))
#set($deleted = "hide")
Expand Down Expand Up @@ -624,7 +623,7 @@
#if($showpost.type == "unapprovedquestion")
<i class="fa fa-exclamation-circle grey-text tooltipped" data-tooltip="$!lang.get('posts.unapproved')"></i>
#end
<a href="$!actionlink/$!utils.urlEncode($showpost.id)/#stripstr($!showpost.title)" class="mediumText">
<a href="$!actionlink" class="mediumText">
#if($showSpaceLabel)
#set($spaceLabel = "$!scooldUtils.getSpaceName($!showpost.space)")
#if(!$spaceLabel.trim().isEmpty())
Expand Down Expand Up @@ -687,7 +686,7 @@
#if($showpost.type == "unapprovedquestion")
<i class="fa fa-exclamation-circle grey-text tooltipped" data-tooltip="$!lang.get('posts.unapproved')"></i>
#end
<a href="$!actionlink/$!utils.urlEncode($showpost.id)/#stripstr($!showpost.title)" class="mediumText">$!showpost.title</a>
<a href="$!actionlink" class="mediumText">$!showpost.title</a>
</div>
<div class="mbs">
#set($showBody = $utils.stripHtml($utils.markdownToHtml($utils.stripHtml($!showpost.body))) )
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/templates/question.vm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</span>
<div id="post-title" class="largeText">
#if($showPost.isReply())
<a href="$questionlink/$showPost.parentid/#stripstr($!showPost.title)" class="tooltipped" data-tooltip="⮪ $!lang.get('backtopost')">
<a href="$!showPost.getPostLinkForRedirect()" class="tooltipped" data-tooltip="⮪ $!lang.get('backtopost')">
<i class="fa fa-reply smallText grey-text"></i> $!{showPost.title}
</a>
#else
Expand All @@ -50,9 +50,9 @@
#set($sortarr = {'votes': "", 'newest': ""} )
#setsortbyselection($sortarr 'votes')
<span class="right">
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)#sortorderparam('?')" title="Most voted answers"
<a href="$!showPost.getPostLinkForRedirect()#sortorderparam('?')" title="Most voted answers"
class="chip $sortarr.votes">#sortordericon() $!lang.get("votes")</a>
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)?sortby=newest#sortorderparam('&' 'newest')" title="Newest answers"
<a href="$!showPost.getPostLinkForRedirect()?sortby=newest#sortorderparam('&' 'newest')" title="Newest answers"
class="chip $sortarr.newest">#sortordericon("newest") $!lang.get("newest")</a>
</span>
<h3 class="grey-text">$!lang.get("answers.title") #showcount($itemcount.count)</h3>
Expand Down

0 comments on commit 6e18436

Please sign in to comment.