-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f968f06
commit d46abcf
Showing
7 changed files
with
561 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
Name: fromholdio-svgenius | ||
--- | ||
|
||
SilverStripe\Assets\File: | ||
extensions: | ||
- Fromholdio\SVGenius\Extensions\SVGFileExtension | ||
allowed_extensions: | ||
- svg | ||
app_categories: | ||
image: | ||
- svg | ||
image/supported: | ||
- svg | ||
file_types: | ||
svg: 'Scalable Vector Graphic (SVG)' | ||
class_for_file_extension: | ||
svg: 'Fromholdio\SVGenius\Model\SVGImage' | ||
|
||
SilverStripe\Admin\LeftAndMain: | ||
extra_requirements_css: | ||
- 'fromholdio/silverstripe-svgenius: client/css/svgenius.css' | ||
|
||
--- | ||
Name: fromholdio-svgenius-imageformfactory | ||
After: focuspoint | ||
Only: | ||
moduleexists: jonom/focuspoint | ||
--- | ||
SilverStripe\AssetAdmin\Forms\ImageFormFactory: | ||
extensions: | ||
- Fromholdio\SVGenius\Extensions\SVGImageFormFactoryExtension | ||
|
||
--- | ||
Name: fromholdio-svgenius-model | ||
After: '#assetsfieldtypes' | ||
--- | ||
SilverStripe\Assets\Storage\DBFile: | ||
supported_images: | ||
- 'image/svg+xml' | ||
- 'image/svg' | ||
|
||
--- | ||
Name: fromholdio-svgenius-mimevalidator | ||
After: '#mimevalidator' | ||
Only: | ||
moduleexists: silverstripe/mimevalidator | ||
--- | ||
SilverStripe\MimeValidator\MimeUploadValidator: | ||
MimeTypes: | ||
svg: | ||
- 'image/svg+xml' | ||
- 'image/svg' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.gallery-item__thumbnail[style*=".svg"] { | ||
background-size: contain; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "fromholdio/silverstripe-svgenius", | ||
"type": "silverstripe-vendormodule", | ||
"description": "First-class SVG handling for Silverstripe CMS & front-end", | ||
"license": "BSD-3-Clause", | ||
"keywords": ["silverstripe", "assets", "svg"], | ||
"homepage": "https://github.com/fromholdio/silverstripe-svgenius", | ||
"support": { | ||
"issues": "https://github.com/fromholdio/silverstripe-svgenius/issues" | ||
}, | ||
"authors": [{ | ||
"name": "Luke Fromhold", | ||
"homepage": "https://fromhold.io" | ||
}], | ||
"require": { | ||
"silverstripe/framework": "^5.0.0", | ||
"enshrined/svg-sanitize": "^0.16.0", | ||
"meyfa/php-svg": "^0.14.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Fromholdio\\SVGenius\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"expose": [ | ||
"client" | ||
] | ||
}, | ||
"prefer-stable": true, | ||
"minimum-stability": "dev" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Fromholdio\SVGenius\Extensions; | ||
|
||
use SilverStripe\ORM\DataExtension; | ||
|
||
class SVGFileExtension extends DataExtension | ||
{ | ||
public function IsSVG(): bool | ||
{ | ||
return $this->getOwner()->getIsSVG(); | ||
} | ||
|
||
public function getIsSVG(): bool | ||
{ | ||
return $this->getOwner()->getExtension() === 'svg'; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Fromholdio\SVGenius\Extensions; | ||
|
||
use SilverStripe\Core\Extension; | ||
use SilverStripe\Forms\FieldList; | ||
|
||
class SVGImageFormFactoryExtension extends Extension | ||
{ | ||
public function updateFormFields(FieldList $fields, $controller, $formName, $context) | ||
{ | ||
$image = $context['Record'] ?? null; | ||
if ($image?->getIsSVG()) { | ||
$fields->removeByName([ | ||
'FocusPoint', | ||
'FocusPointTab' | ||
]); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Fromholdio\SVGenius\Model; | ||
|
||
use Fromholdio\SVGenius\SVGeniusTrait; | ||
use SilverStripe\Assets\Image; | ||
use SilverStripe\Assets\Storage\AssetContainer; | ||
use SVG\SVG as SVGParser; | ||
|
||
class SVGImage extends Image | ||
{ | ||
use SVGeniusTrait; | ||
|
||
private static $table_name = 'SVGImage'; | ||
private static $singular_name = 'SVG image'; | ||
private static $plural_name = 'SVG images'; | ||
|
||
public function __construct($record = null, $isSingleton = false, $queryParams = []) | ||
{ | ||
parent::__construct($record, $isSingleton, $queryParams); | ||
if ($this->File->exists()) { | ||
$this->initSVGFromString($this->File->getString(), false); | ||
} | ||
} | ||
|
||
public function onBeforeWrite(): void | ||
{ | ||
$sanitisedString = $this->sanitiseSVGString($this->File->getString()); | ||
$this->File->setFromString( | ||
$sanitisedString, | ||
$this->File->getFilename() | ||
); | ||
$this->svg = SVGParser::fromString($sanitisedString); | ||
parent::onBeforeWrite(); | ||
} | ||
|
||
|
||
public function getImageTag(): string | ||
{ | ||
return parent::getTag(); | ||
} | ||
|
||
public function Thumbnail($width, $height): AssetContainer | ||
{ | ||
return $this->resizeByRatio($width, $height); | ||
} | ||
|
||
public function manipulate($variant, $callback): AssetContainer | ||
{ | ||
return $this; | ||
} | ||
|
||
public function existingOnly(): AssetContainer | ||
{ | ||
return $this->setAllowGeneration(false); | ||
} | ||
|
||
public function Resampled(): AssetContainer | ||
{ | ||
return $this; | ||
} | ||
|
||
public function Quality($quality): AssetContainer | ||
{ | ||
return $this; | ||
} | ||
} |
Oops, something went wrong.