-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
9 changed files
with
374 additions
and
8 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
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
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,64 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of SilverWare. | ||
* | ||
* PHP version >=5.6.0 | ||
* | ||
* For full copyright and license information, please view the | ||
* LICENSE.md file that was distributed with this source code. | ||
* | ||
* @package SilverWare\Extensions\Assets | ||
* @author Colin Tucker <colin@praxis.net.au> | ||
* @copyright 2017 Praxis Interactive | ||
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @link https://github.com/praxisnetau/silverware | ||
*/ | ||
|
||
namespace SilverWare\Extensions\Assets; | ||
|
||
use SilverStripe\Core\Extension; | ||
use SilverStripe\ORM\FieldType\DBField; | ||
use DOMDocument; | ||
|
||
/** | ||
* An extension which adds inline rendering for vector images to the file class. | ||
* | ||
* @package SilverWare\Extensions\Assets | ||
* @author Colin Tucker <colin@praxis.net.au> | ||
* @copyright 2017 Praxis Interactive | ||
* @license https://opensource.org/licenses/BSD-3-Clause BSD-3-Clause | ||
* @link https://github.com/praxisnetau/silverware | ||
*/ | ||
class RenderInlineExtension extends Extension | ||
{ | ||
/** | ||
* Renders the content of the extended object inline. | ||
* | ||
* @return DBHTMLText | ||
*/ | ||
public function getRenderInline() | ||
{ | ||
// Check File Exists / File Extension: | ||
|
||
if ($this->owner->exists() && $this->owner->getExtension() == 'svg') { | ||
|
||
// Create DOM Document: | ||
|
||
$dom = new DOMDocument(); | ||
|
||
// Load SVG Data into DOM: | ||
|
||
$dom->load(BASE_PATH . $this->owner->URL); | ||
|
||
// Normalise SVG Data: | ||
|
||
$dom->normalizeDocument(); | ||
|
||
// Render SVG as HTML: | ||
|
||
return DBField::create_field('HTMLFragment', $dom->saveHTML($dom->documentElement)); | ||
|
||
} | ||
} | ||
} |
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
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
Oops, something went wrong.