Refactor VCalendarHelpers methods for improved readability and consistency
This commit is contained in:
parent
7a1c8d5cc1
commit
149ef095f2
@ -8,75 +8,80 @@ use Exception;
|
||||
|
||||
class VCalendarHelpers
|
||||
{
|
||||
|
||||
|
||||
public static function GetValueFromKeyInVCalendarString(string $key, string $vCalendarString): string
|
||||
{
|
||||
$value = "";
|
||||
preg_match("/$key:(.*)\r\n/", $vCalendarString, $matches);
|
||||
if (isset($matches[1])) {
|
||||
$value = trim($matches[1]);
|
||||
}
|
||||
return $value;
|
||||
if (isset($matches[1])) {
|
||||
$value = trim($matches[1]);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function GetDateStartOrDateEndFromVCalendarString(string $key, string $vCalendarString)
|
||||
{
|
||||
preg_match("/$key;TZID=([^:]+):(\d+T\d+)/", $vCalendarString, $matches);
|
||||
if(!$matches){
|
||||
if (!$matches) {
|
||||
return null;
|
||||
}
|
||||
try{
|
||||
try {
|
||||
$dateTz = $matches[1];
|
||||
$datetimeString = $matches[2];
|
||||
$datetimeValue = new DateTime($datetimeString, new DateTimeZone($dateTz));
|
||||
return $datetimeValue;
|
||||
}
|
||||
catch(Exception $e){
|
||||
} catch (Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function GetStartAndEndTimeFromVCalendarString(string $vCalendarString){
|
||||
public static function GetStartAndEndTimeFromVCalendarString(string $vCalendarString)
|
||||
{
|
||||
$startTimeValue = "";
|
||||
$endTimeValue = "";
|
||||
if($vCalendarString != ""){
|
||||
if ($vCalendarString != "") {
|
||||
$dateStart = self::GetDateStartOrDateEndFromVCalendarString("DTSTART", $vCalendarString);
|
||||
if($dateStart != null){
|
||||
if ($dateStart != null) {
|
||||
$startTimeValue = $dateStart->format("H") . "h";
|
||||
}
|
||||
$dateEnd = self::GetDateStartOrDateEndFromVCalendarString("DTEND", $vCalendarString);
|
||||
if($dateEnd != null){
|
||||
if ($dateEnd != null) {
|
||||
$endTimeValue = $dateEnd->format("H") . "h";
|
||||
}
|
||||
}
|
||||
return [
|
||||
"startTime" => $startTimeValue,
|
||||
"endTime" => $endTimeValue
|
||||
"endTime" => $endTimeValue
|
||||
];
|
||||
}
|
||||
|
||||
public static function ReadVCalendarDataBlob($vCalendarData){
|
||||
|
||||
public static function ReadVCalendarDataBlob($vCalendarData)
|
||||
{
|
||||
if (is_resource($vCalendarData)) {
|
||||
return stream_get_contents($vCalendarData);
|
||||
}
|
||||
return $vCalendarData;
|
||||
return stream_get_contents($vCalendarData);
|
||||
}
|
||||
return $vCalendarData;
|
||||
}
|
||||
|
||||
public static function hasAttachment(string $vCalendarString) : bool{
|
||||
public static function hasAttachment(string $vCalendarString): bool
|
||||
{
|
||||
return str_contains($vCalendarString, 'ATTACH;FMTTYPE');
|
||||
}
|
||||
public static function extractAttachments(string $vCalendarString): array {
|
||||
public static function extractAttachments(string $vCalendarString): array
|
||||
{
|
||||
$attachments = [];
|
||||
preg_match_all('/ATTACH;FMTTYPE=([^;]+);FILENAME=([^;]+);X-NC-FILE-ID=([^;]+);/', $vCalendarString, $matches, PREG_SET_ORDER);
|
||||
$vCalendarString = preg_replace("/\r\n|\n|\r/", "\n", $vCalendarString);
|
||||
$vCalendarString = preg_replace("/\n[ \t]/", "", $vCalendarString);
|
||||
preg_match_all('/ATTACH;FMTTYPE=([^;]+);FILENAME=([^;]+);X-NC-FILE-ID=(\d+)/', $vCalendarString, $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $match) {
|
||||
$attachments[] = [
|
||||
'type' =>explode("/" , $match[1])[0], // Extrait 'image' de 'image/png'
|
||||
'mime_type' =>$match[1], // Extrait 'image' de 'image/png'
|
||||
'type' => explode("/", $match[1])[0],
|
||||
'mime_type' => $match[1],
|
||||
'name' => trim($match[2], '/'),
|
||||
'file_id' => (int) $match[3],
|
||||
];
|
||||
}
|
||||
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user