diff options
author | Mark Schmitz <kramred@gmail.com> | 2018-06-07 14:23:53 +0100 |
---|---|---|
committer | Mark Schmitz <kramred@gmail.com> | 2018-06-07 14:23:53 +0100 |
commit | 0deaedeeaef088040fb015f5be3e270e3bae508e (patch) | |
tree | bbdab87adf45592a6a881f808e667ba5c21312a9 /application/LinkDB.php | |
parent | f6b3295d28352cbeb46dff04799cf8f4d39087bb (diff) | |
parent | 17e45b2e9c33c736751e059276fadb480f98e621 (diff) | |
download | Shaarli-0deaedeeaef088040fb015f5be3e270e3bae508e.tar.gz Shaarli-0deaedeeaef088040fb015f5be3e270e3bae508e.tar.zst Shaarli-0deaedeeaef088040fb015f5be3e270e3bae508e.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'application/LinkDB.php')
-rw-r--r-- | application/LinkDB.php | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php index c1661d52..cd0f2967 100644 --- a/application/LinkDB.php +++ b/application/LinkDB.php | |||
@@ -436,15 +436,17 @@ You use the community supported version of the original Shaarli project, by Seba | |||
436 | 436 | ||
437 | /** | 437 | /** |
438 | * Returns the list tags appearing in the links with the given tags | 438 | * Returns the list tags appearing in the links with the given tags |
439 | * @param $filteringTags: tags selecting the links to consider | 439 | * |
440 | * @param $visibility: process only all/private/public links | 440 | * @param array $filteringTags tags selecting the links to consider |
441 | * @return: a tag=>linksCount array | 441 | * @param string $visibility process only all/private/public links |
442 | * | ||
443 | * @return array tag => linksCount | ||
442 | */ | 444 | */ |
443 | public function linksCountPerTag($filteringTags = [], $visibility = 'all') | 445 | public function linksCountPerTag($filteringTags = [], $visibility = 'all') |
444 | { | 446 | { |
445 | $links = empty($filteringTags) ? $this->links : $this->filterSearch(['searchtags' => $filteringTags], false, $visibility); | 447 | $links = $this->filterSearch(['searchtags' => $filteringTags], false, $visibility); |
446 | $tags = array(); | 448 | $tags = []; |
447 | $caseMapping = array(); | 449 | $caseMapping = []; |
448 | foreach ($links as $link) { | 450 | foreach ($links as $link) { |
449 | foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) { | 451 | foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) { |
450 | if (empty($tag)) { | 452 | if (empty($tag)) { |
@@ -458,8 +460,19 @@ You use the community supported version of the original Shaarli project, by Seba | |||
458 | $tags[$caseMapping[strtolower($tag)]]++; | 460 | $tags[$caseMapping[strtolower($tag)]]++; |
459 | } | 461 | } |
460 | } | 462 | } |
461 | // Sort tags by usage (most used tag first) | 463 | |
462 | arsort($tags); | 464 | /* |
465 | * Formerly used arsort(), which doesn't define the sort behaviour for equal values. | ||
466 | * Also, this function doesn't produce the same result between PHP 5.6 and 7. | ||
467 | * | ||
468 | * So we now use array_multisort() to sort tags by DESC occurrences, | ||
469 | * then ASC alphabetically for equal values. | ||
470 | * | ||
471 | * @see https://github.com/shaarli/Shaarli/issues/1142 | ||
472 | */ | ||
473 | $keys = array_keys($tags); | ||
474 | $tmpTags = array_combine($keys, $keys); | ||
475 | array_multisort($tags, SORT_DESC, $tmpTags, SORT_ASC, $tags); | ||
463 | return $tags; | 476 | return $tags; |
464 | } | 477 | } |
465 | 478 | ||