Skip to content

Instantly share code, notes, and snippets.

@matdave
Last active November 16, 2021 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matdave/61286c64e20adb7d01e36c3e891eddaf to your computer and use it in GitHub Desktop.
Save matdave/61286c64e20adb7d01e36c3e891eddaf to your computer and use it in GitHub Desktop.
SVG fix for MODX 3 S3 source
<?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