PluginProbe
Depicter — Popup & Slider Builder / 1.6.2
Depicter — Popup & Slider Builder v1.6.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Html / Canvas.php

Canvas.php in Depicter — Popup & Slider Builder 1.6.2, at app/src/Html/Canvas.php

156 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Html;
3
4
5 use Averta\WordPress\Handler\Error;
6
7 class Canvas
8 {
9 /**
10 * @var Html
11 */
12 private $html;
13
14 /**
15 * @var Html
16 */
17 private $head;
18
19 /**
20 * @var Html
21 */
22 private $body;
23
24 /**
25 * @var array
26 */
27 private $cssLinks;
28
29 /**
30 * @var array
31 */
32 private $jsLinks;
33
34 /**
35 * @var string
36 */
37 private $content;
38
39 /**
40 * @var string
41 */
42 private $inlineStyle;
43
44
45 public function __construct( $content = '' )
46 {
47 $this->content = $content;
48 }
49
50
51 public function registerStyle( $cssLinks = [] )
52 {
53 $cssLinks = (array) $cssLinks;
54
55 foreach ( $cssLinks as $cssLinkId => $cssLink ){
56 if( is_numeric( $cssLinkId ) ){
57 Error::trigger( 'You must specify a valid ID-name for each css link.' );
58 }
59 $this->cssLinks[ $cssLinkId ] = $cssLink;
60 }
61
62 }
63
64 public function registerScript( $jsLinks = [] )
65 {
66 $jsLinks = (array) $jsLinks;
67
68 foreach ( $jsLinks as $jsLinkId => $jsLink ){
69 if( is_numeric( $jsLinkId ) ){
70 Error::trigger( 'You must specify a valid ID-name for each javascript link.' );
71 }
72 $this->jsLinks[ $jsLinkId ] = $jsLink;
73 }
74
75 }
76
77 public function setContent( $content )
78 {
79 $this->content = $content;
80 }
81
82 public function setInlineStyle( $style )
83 {
84 $this->inlineStyle = $style;
85 }
86
87 public function render()
88 {
89 $this->html = Html::html([]);
90
91 // Make head tag
92 $this->renderHead();
93
94 // Make body tag
95 $this->renderBody();
96
97 $this->html->nest( "\n" .$this->head );
98 $this->html->nest( "\n" .$this->body . "\n" );
99
100 return $this->html;
101 }
102
103 protected function renderHead(){
104 $this->head = Html::head([]);
105
106 $this->head->nest( "\n" . Html::meta([ 'charset' => 'utf-8' ]) );
107 $this->head->nest( "\n" . Html::meta([ 'name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0' ]) );
108 $this->head->nest( "\n" . Html::title([], 'Depicter Preview') );
109
110 $this->renderStyleTags();
111
112 if( $this->inlineStyle ){
113 $this->head->nest( "\n" .Html::style([], $this->inlineStyle ) . "\n" );
114 }
115 }
116
117 protected function renderBody()
118 {
119 $this->body = Html::body([
120 'class' => 'depicter-preview-canvas'
121 ], "\n" . $this->content . "\n" );
122
123 $this->renderScriptTags();
124 }
125
126 protected function renderStyleTags(){
127 if( empty( $this->cssLinks ) ){
128 return;
129 }
130
131 foreach ( $this->cssLinks as $cssId => $cssLink ){
132 $linkTag = Html::link([
133 'rel' => "stylesheet",
134 'id' => $cssId . '-css',
135 'href' => $cssLink,
136 'media' => 'all'
137 ]);
138 $this->head->nest( "\n" .$linkTag );
139 }
140 }
141
142 protected function renderScriptTags(){
143 if( empty( $this->jsLinks ) ){
144 return;
145 }
146
147 foreach ( $this->jsLinks as $jsId => $jsLink ){
148 $scriptTag = Html::script([
149 'id' => $jsId . '-js',
150 'src' => $jsLink
151 ]);
152 $this->body->nest( $scriptTag . "\n" );
153 }
154 }
155 }
156