2020-08-11 13:30:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
2020-08-12 13:26:32 +00:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
2020-08-11 13:30:34 +00:00
|
|
|
class Helpers
|
|
|
|
{
|
|
|
|
public static function closetags($html) {
|
|
|
|
preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
|
|
|
|
$openedtags = $result[1];
|
|
|
|
preg_match_all('#</([a-z]+)>#iU', $html, $result);
|
|
|
|
$closedtags = $result[1];
|
|
|
|
$len_opened = count($openedtags);
|
|
|
|
if (count($closedtags) == $len_opened) {
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
$openedtags = array_reverse($openedtags);
|
|
|
|
for ($i=0; $i < $len_opened; $i++) {
|
|
|
|
if (!in_array($openedtags[$i], $closedtags)) {
|
|
|
|
$html .= '</'.$openedtags[$i].'>';
|
|
|
|
} else {
|
|
|
|
unset($closedtags[array_search($openedtags[$i], $closedtags)]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $html;
|
|
|
|
}
|
2020-08-12 13:26:32 +00:00
|
|
|
|
|
|
|
public static function sendNewsNotification(News $news, Collection $users){
|
2020-09-08 06:48:30 +00:00
|
|
|
$headers = 'Content-Transfer-Encoding: 8bit'. "\r\n".
|
|
|
|
'Content-Type: text/html; charset="UTF-8"';
|
|
|
|
|
2020-08-12 13:26:32 +00:00
|
|
|
foreach ($users as $user) {
|
|
|
|
$email = $user->email;
|
|
|
|
|
|
|
|
if($news->name !== "")
|
|
|
|
$subject = $news->name;
|
|
|
|
else
|
|
|
|
$subject = $news->subname;
|
|
|
|
|
|
|
|
$msg = "Hej " . $user->name_first . " ". $user->name_last . ".\n\nDer er kommet en ny nyhed i skolehjems appen! ";
|
|
|
|
|
2020-09-08 06:48:30 +00:00
|
|
|
mail($email, $subject, $msg, $headers);
|
2020-08-12 13:26:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-11 13:30:34 +00:00
|
|
|
}
|