Last active
November 16, 2021 15:52
-
-
Save matdave/61286c64e20adb7d01e36c3e891eddaf to your computer and use it in GitHub Desktop.
SVG fix for MODX 3 S3 source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
switch ($modx->event->name) { | |
case "OnFileManagerUpload": | |
if(!empty($files)){ | |
foreach($files as $file){ | |
$path = $directory . $source->sanitizePath($file['name']); | |
$object = $source->getObjectContents($path); | |
if(empty($object) || empty($object['mime']) || empty($object['content'])) continue; | |
switch($object['mime']) { | |
case 'image/svg': | |
case 'image/svg+xml': | |
if (substr($object['content'],0,5) !== "<?xml") { | |
$content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n".$object['content']; | |
$source->updateObject($path, $content); | |
} | |
break; | |
} | |
} | |
} | |
break; | |
} | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment