mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-05-11 02:36:26 +02:00
Add link shortening for http links in sms, using YOURLS
This commit is contained in:
parent
fb3f9425d1
commit
241d079ffb
6 changed files with 140 additions and 1 deletions
controllers/internals
|
@ -450,7 +450,8 @@ use Monolog\Logger;
|
|||
$users_smsstops = [];
|
||||
$users_settings = [];
|
||||
$users_phones = [];
|
||||
$users_phone_groups = [];
|
||||
$users_phone_groups = [];
|
||||
$shortlink_cache = [];
|
||||
|
||||
$now = new \DateTime();
|
||||
$now = $now->format('Y-m-d H:i:s');
|
||||
|
@ -643,6 +644,33 @@ use Monolog\Logger;
|
|||
$text = Tool::convert_to_gsm0338($text);
|
||||
}
|
||||
|
||||
// If the text contain http links we must replace them
|
||||
if (ENABLE_URL_SHORTENER && ((int) ($users_settings[$id_user]['shorten_url'] ?? false)))
|
||||
{
|
||||
$http_links = Tool::search_http_links($text);
|
||||
if ($http_links !== false)
|
||||
{
|
||||
foreach ($http_links as $http_link)
|
||||
{
|
||||
if (!array_key_exists($http_link, $shortlink_cache))
|
||||
{
|
||||
$shortlkink = LinkShortener::shorten($http_link);
|
||||
|
||||
// If link shortening failed, keep original one
|
||||
if ($shortlkink === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$shortlink_cache[$http_link] = $shortlkink;
|
||||
}
|
||||
|
||||
$shortlink = $shortlink_cache[$http_link];
|
||||
$text = str_replace($http_link, $shortlink, $text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Choose phone if no phone defined for message
|
||||
Phones are choosen using type, priority and remaining volume :
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue