forked from GEWIS/gewisweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request GEWIS#1943 from tomudding/feature/photo-album-search
feat: photo album search and improved album layout
- Loading branch information
Showing
27 changed files
with
532 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Application\View\Helper; | ||
|
||
use Laminas\View\Helper\AbstractHelper; | ||
|
||
use function mb_stripos; | ||
use function mb_strlen; | ||
use function mb_substr; | ||
use function sprintf; | ||
use function transliterator_transliterate; | ||
|
||
class HighlightSearch extends AbstractHelper | ||
{ | ||
/** | ||
* Insert `<mark>` around a search prompt in the content of a returned result. | ||
*/ | ||
public function __invoke( | ||
string $query, | ||
string $content, | ||
): string { | ||
// Convert the decision to something that is easily searchable (i.e. it MUST contain only Latin-ASCII characters). | ||
$transliteratedDecision = transliterator_transliterate('Any-Latin; Latin-ASCII', $content); | ||
// Do the same for the search prompt, as otherwise searches WITH non-ASCII characters will not work. | ||
$query = transliterator_transliterate('Any-Latin; Latin-ASCII', $query); | ||
|
||
$offset = 0; | ||
$output = ''; | ||
$length = mb_strlen($query); | ||
|
||
// There is a very important assumption here; the transliterated version of the decision MUST be exactly as long as | ||
// the original version. Otherwise, the insertion is done with an incorrect offset. As such, using `iconv` is NOT | ||
// good as it will either extend (e.g. `€` becomes `EUR`) or completely remove characters (`//IGNORE` option). | ||
while (false !== ($position = mb_stripos($transliteratedDecision, $query, $offset, 'UTF-8'))) { | ||
// Progressively insert markers into the original decision. | ||
$output .= sprintf( | ||
'%s%s%s%s', | ||
mb_substr($content, $offset, $position - $offset, 'UTF-8'), | ||
'<mark>', | ||
mb_substr($content, $position, $length, 'UTF-8'), | ||
'</mark>', | ||
); | ||
|
||
$offset = $position + $length; | ||
} | ||
|
||
// Add the final part of the decision back. | ||
$output .= mb_substr($content, $offset, null, 'UTF-8'); | ||
|
||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.