| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Elements; |
| 3 |
|
| 4 |
use Depicter\Document\Models; |
| 5 |
use Depicter\Html\Html; |
| 6 |
|
| 7 |
class Svg extends Models\Element |
| 8 |
{ |
| 9 |
|
| 10 |
public function render() { |
| 11 |
$shapeContent = ''; |
| 12 |
|
| 13 |
if( ! empty( $this->options->content ) ){ |
| 14 |
$shapeContent = $this->options->content; |
| 15 |
} elseif ( ! empty( $this->options->source ) && $shapeUrl = wp_get_attachment_url( $this->options->source ) ) { |
| 16 |
$shapeContent = file_get_contents( $shapeUrl ); |
| 17 |
} |
| 18 |
|
| 19 |
$args = $this->getDefaultAttributes(); |
| 20 |
$div = Html::div( $args, "\n\t" . $shapeContent . "\n" ); |
| 21 |
|
| 22 |
if ( false !== $a = $this->getLinkTag() ) { |
| 23 |
return $a->nest( "\n" .$div ) . "\n"; |
| 24 |
} |
| 25 |
|
| 26 |
return $div . "\n"; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Get svg selector |
| 31 |
* |
| 32 |
* @return string |
| 33 |
*/ |
| 34 |
protected function getSvgSelector() { |
| 35 |
return '.' . $this->getSelector() . ' svg, .' . $this->getSelector() . ' path'; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Get styles of svg |
| 40 |
* |
| 41 |
* @return array|array[] |
| 42 |
* @throws \JsonMapper_Exception |
| 43 |
*/ |
| 44 |
protected function getSvgCss() { |
| 45 |
// Get styles list from styles property |
| 46 |
return ! empty( $this->styles ) ? $this->styles->getSvgCss() : []; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Get list of selector and CSS for element |
| 51 |
* |
| 52 |
* @return array |
| 53 |
* @throws \JsonMapper_Exception |
| 54 |
*/ |
| 55 |
public function getSelectorAndCssList(){ |
| 56 |
parent::getSelectorAndCssList(); |
| 57 |
|
| 58 |
// Add SVG selector and css |
| 59 |
$this->selectorCssList[ $this->getSvgSelector() ] = $this->getSvgCss(); |
| 60 |
|
| 61 |
return $this->selectorCssList; |
| 62 |
} |
| 63 |
} |
| 64 |
|