-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zbyt długie linki w postach i mikroblogach nie są skracane #244 #256
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dzięki za pulll request.
@@ -40,7 +42,12 @@ function ($match) { | |||
$url = 'http://' . $url; | |||
} | |||
|
|||
return link_to($url, htmlspecialchars($match[0], ENT_QUOTES, 'UTF-8', false)); | |||
$title = htmlspecialchars($match[0], ENT_QUOTES, 'UTF-8', false); | |||
if (mb_strlen($title) > self::LINK_TITLE_LEN) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warunek sprawdzający długość linku, przeniósłbym do metody truncate()
. Przykładowo, tak wygląda metoda limit()
w laravel (z tym, że ona dodaje ...
na końcu tekstu zamiast [...]
w środek linku):
public static function limit($value, $limit = 100, $end = '...')
{
if (mb_strwidth($value, 'UTF-8') <= $limit) {
return $value;
}
return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
}
Czyli jeżeli długość linka jest ok - metoda zwraca niezmodyfikowany tekst.
Zaktualizuje dzisiaj wieczorem pull requesta. Zastanawiałem się też czy nie warto przenieść tej metody do Coyote\Services\Parser\Helpers\Link bo jest troche na skraju opowiedzialności Coyote\Services\Parser\Parsers\Autolink ? |
Myślałem, że można iść dalej i połączyć te dwie klasy. Wszak obydwie mają za zadanie formatowanie linków na stronie. Ta klasa |
Poprawione zgodnie z obietnicą. |
Zgodnie z treścią zgołoszenia dodano skracanie URLi w przypadku przekroczenia 64 znaków. Zrzut ekranu: https://dl.dropboxusercontent.com/u/435780/Zrzut%20ekranu%20z%202017-01-10%2022-36-12.png