mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 02:46:46 -04:00
Adjust how tags URLs are calculated to support tags with non-ASCII characters like 'children’s'
This commit is contained in:
parent
c5b686636b
commit
6c267497cc
5 changed files with 14 additions and 20 deletions
|
@ -728,7 +728,7 @@ class Ebook{
|
|||
|
||||
public function HasTag(string $tag): bool{
|
||||
foreach($this->Tags as $t){
|
||||
if(strtolower($t->Name) == strtolower($tag)){
|
||||
if(strtolower($t->UrlName) == strtolower($tag)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ class Library{
|
|||
|
||||
$ebooks = [];
|
||||
$collections = [];
|
||||
$tags = [];
|
||||
$ebooksByTag = [];
|
||||
$authors = [];
|
||||
$tagsByName = [];
|
||||
|
||||
|
@ -236,13 +236,12 @@ class Library{
|
|||
|
||||
// Create the tags cache
|
||||
foreach($ebook->Tags as $tag){
|
||||
$tagsByName[] = $tag->Name;
|
||||
$lcTag = strtolower($tag->Name);
|
||||
if(!array_key_exists($lcTag, $tags)){
|
||||
$tags[$lcTag] = [];
|
||||
$tagsByName[$tag->UrlName] = $tag;
|
||||
if(!array_key_exists($tag->UrlName, $ebooksByTag)){
|
||||
$ebooksByTag[$tag->UrlName] = [];
|
||||
}
|
||||
|
||||
$tags[$lcTag][] = $ebook;
|
||||
$ebooksByTag[$tag->UrlName][] = $ebook;
|
||||
}
|
||||
|
||||
// Create the authors cache
|
||||
|
@ -288,13 +287,12 @@ class Library{
|
|||
}
|
||||
|
||||
apcu_delete(new APCUIterator('/^tag-/'));
|
||||
foreach($tags as $tag => $ebooks){
|
||||
apcu_store('tag-' . $tag, $ebooks);
|
||||
foreach($ebooksByTag as $tagName => $ebooks){
|
||||
apcu_store('tag-' . $tagName, $ebooks);
|
||||
}
|
||||
|
||||
ksort($tagsByName);
|
||||
apcu_delete('tags');
|
||||
$tagsByName = array_unique($tagsByName, SORT_STRING);
|
||||
natsort($tagsByName);
|
||||
apcu_store('tags', $tagsByName);
|
||||
|
||||
apcu_delete(new APCUIterator('/^author-/'));
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
class Tag{
|
||||
public $Name;
|
||||
public $Url;
|
||||
public $UrlName;
|
||||
|
||||
public function __construct(string $name){
|
||||
$this->Name = $name;
|
||||
$this->Url = '/tags/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText($this->Name)));
|
||||
$this->UrlName = Formatter::MakeUrlSafe($this->Name);
|
||||
$this->Url = '/tags/' . $this->UrlName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,8 @@ $allSelected = sizeof($tags) == 0 || in_array('all', $tags);
|
|||
<label class="tags">Subjects
|
||||
<select multiple="multiple" name="tags[]" size="1">
|
||||
<option value="all">All</option>
|
||||
<? foreach(Library::GetTags() as $tag){
|
||||
$lcTag = mb_strtolower($tag); ?>
|
||||
<option value="<?= Formatter::ToPlainText($lcTag) ?>"<? if(!$allSelected && in_array($lcTag, $tags)){ ?> selected="selected"<? } ?>><?= Formatter::ToPlainText($tag) ?></option>
|
||||
<? foreach(Library::GetTags() as $tag){ ?>
|
||||
<option value="<?= $tag->UrlName ?>"<? if(!$allSelected && in_array($tag->UrlName, $tags)){ ?> selected="selected"<? } ?>><?= Formatter::ToPlainText($tag->Name) ?></option>
|
||||
<? } ?>
|
||||
</select>
|
||||
</label>
|
||||
|
|
|
@ -49,11 +49,6 @@ try{
|
|||
$tags = [];
|
||||
}
|
||||
|
||||
// Replace dashes passed in from URLs like /tags/science-fiction
|
||||
foreach($tags as $key => $tag){
|
||||
$tags[$key] = str_replace('-', ' ', $tag);
|
||||
}
|
||||
|
||||
// Are we looking at a collection?
|
||||
if($collection !== null){
|
||||
$ebooks = Library::GetEbooksByCollection($collection);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue