1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-02-23 10:43:41 +01:00
LinkAce/app/Helper/LinkAce.php
Kovah 0a1f6b3167
Refactor of the HTML meta helper (#122)
Move the HTML meta helper into a new class and refactor the actual parsing of title and description. The helper now uses one single call to get the HTML and then parses the title and description from it.
The helper also now handles invalid URLs correctly. This includes URLs without a proper protocol as they can't be correctly queried for the meta data.
2020-04-29 19:14:42 +02:00

27 lines
704 B
PHP

<?php
namespace App\Helper;
/**
* Class LinkAce
*
* @package App\Helper
*/
class LinkAce
{
/**
* Generate the code for the bookmarklet
*/
public static function generateBookmarkletCode(): string
{
$bmCode = 'javascript:javascript:(function(){var%20url%20=%20location.href;' .
"var%20title%20=%20document.title%20||%20url;window.open('##URL##?u='%20+%20encodeURIComponent(url)" .
"+'&t='%20+%20encodeURIComponent(title),'_blank','menubar=no,height=720,width=600,toolbar=no," .
"scrollbars=yes,status=no,dialog=1');})();";
$bmCode = str_replace('##URL##', route('bookmarklet-add'), $bmCode);
return $bmCode;
}
}