PluginProbe
CSS & JavaScript Toolbox / 11.6
CSS & JavaScript Toolbox v11.6
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / framework / ServicesFW / View.class.php

View.class.php in CSS & JavaScript Toolbox 11.6, at framework/ServicesFW/View.class.php

290 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 /**
7 *
8 */
9 class CJTServicesMVCView {
10
11 /**
12 * put your comment there...
13 *
14 * @var mixed
15 */
16 private $controller;
17
18 /**
19 * put your comment there...
20 *
21 * @var mixed
22 */
23 private $path;
24
25 /**
26 * put your comment there...
27 *
28 * @var mixed
29 */
30 private $scripts = array();
31
32 /**
33 * put your comment there...
34 *
35 * @var mixed
36 */
37 private $styles = array();
38
39 /**
40 * put your comment there...
41 *
42 * @var mixed
43 */
44 private $output;
45
46 /**
47 * put your comment there...
48 *
49 * @var mixed
50 */
51 private $url;
52
53 /**.
54 * put your comment there...
55 *
56 * @param CJTServicesMVCController $controller
57 * @return {CJTServicesView|CJTServicesMVCController}
58 */
59 public function __construct(CJTServicesMVCController & $controller) {
60 # Initialize
61 $this->controller =& $controller;
62 # Enqueue styles and script hooks
63 if( is_admin() ) {
64 add_action( 'admin_print_styles', array( $this, '_enqueueStyles' ) );
65 add_action( 'admin_print_scripts', array( $this, '_enqueueScripts' ) );
66 }
67 # Cache View Path and Urls
68 $config = $this->controller->getConfig();
69 $route = $this->controller->getRoute();
70 $viewConfig = $config[ 'views' ][ $route[ 'view' ] ];
71 $this->path = $config[ 'path' ] . DIRECTORY_SEPARATOR .
72 'Views' . DIRECTORY_SEPARATOR .
73 str_replace( '/', DIRECTORY_SEPARATOR, $viewConfig[ 'path' ] );
74 $this->url = "{$config[ 'url' ]}/Views/{$viewConfig[ 'path' ]}/";
75 }
76
77 /**
78 * put your comment there...
79 *
80 */
81 public function __toString() {
82 # Render
83 return $this->output;
84 }
85
86 /**
87 * put your comment there...
88 *
89 */
90 public function _enqueueScripts()
91 {
92
93 foreach ( $this->scripts as $script )
94 {
95 // Enqueue script
96 wp_enqueue_script( $script[ 'handle' ],
97 $script[ 'src' ],
98 $script[ 'dep' ],
99 $script[ 'version' ],
100 $script[ 'footer' ]
101 );
102
103 // Pluggable script queue
104 foreach ( $script[ 'plugs' ] as $scriptPlug )
105 {
106 call_user_func( $scriptPlug, $script );
107 }
108 }
109
110 }
111
112 /**
113 * put your comment there...
114 *
115 */
116 public function _enqueueStyles() {
117 foreach ( $this->styles as $style ) {
118 wp_enqueue_style( $style[ 'handle' ],
119 $style[ 'src' ],
120 $style[ 'dep' ],
121 $style[ 'version' ],
122 $style[ 'media' ]
123 );
124 }
125 }
126
127 /**
128 * put your comment there...
129 *
130 * @param mixed $script
131 */
132 public function _localizeJS( $script )
133 {
134
135 $l10n =& $script[ 'l10n' ];
136
137 wp_localize_script( $script[ 'handle' ], $l10n[ 'jsName' ], $l10n[ 'strings' ] );
138
139 }
140
141 /***
142 * put your comment there...
143 *
144 * @param mixed $name
145 * @param mixed $url
146 * @param mixed $version
147 * @param mixed $footer
148 */
149 public function enqueueScript( $handle, $src = null, $dep = null, $version = null, $footer = null )
150 {
151
152 $plugs = array();
153
154 $this->scripts[ $handle ] = compact( 'handle', 'src', 'dep', 'version', 'footer', 'plugs' );
155
156 return $this;
157 }
158
159 /***
160 * put your comment there...
161 *
162 * @param mixed $name
163 * @param mixed $url
164 * @param mixed $version
165 * @param mixed $media
166 */
167 public function enqueueStyle($handle, $src = null, $dep = null, $version = null, $media = null) {
168 # Add style
169 $this->styles[] = compact( 'handle', 'src', 'dep', 'version', 'media' );
170 # Chain
171 return $this;
172 }
173
174 /**
175 * put your comment there...
176 *
177 */
178 public function dispatch() {
179 # Get early output so its possible to use Wordpress hooks before they
180 # are elapced
181 $route = $this->controller->getRoute();
182 $this->output = $this->getTemplate( isset( $route[ 'template' ] ) ? $route[ 'template' ] : $route[ 'action' ] );
183 }
184
185 /**
186 * put your comment there...
187 *
188 */
189 public function getPath() {
190 return $this->path;
191 }
192
193 /**
194 *
195 *
196 * @param mixed $name
197 */
198 public function getResName($name)
199 {
200
201 $name = strtolower( $name );
202
203 $name = str_replace( array( '.' ), '-', $name );
204
205 $resName = strtolower( get_class( $this ) ) . "-{$name}";
206
207 return $resName;
208 }
209
210 /**
211 * put your comment there...
212 *
213 * @param mixed $name
214 */
215 public function getResUrl($name) {
216 return "{$this->url}/{$name}";
217 }
218
219 /**
220 * put your comment there...
221 *
222 * @param mixed $name
223 */
224 public function getScriptUrl($name) {
225 return $this->getResUrl( "{$name}.js" );
226 }
227
228 /**
229 * put your comment there...
230 *
231 * @param mixed $name
232 */
233 public function getStyleUrl($name) {
234 return $this->getResUrl( "{$name}.css" );
235 }
236
237 /**
238 * put your comment there...
239 *
240 * @param mixed $name
241 */
242 protected function getTemplate($name) {
243 # Get view path
244 $config = $this->controller->getConfig();
245 $viewPath = $this->getPath();
246 # Template Extension/Format
247 $extension = isset( $viewConfig[ 'format' ] ) ? $viewConfig[ 'format' ] : $config[ 'defaultFormat' ];
248 # Template file
249 $templateFile = $viewPath . DIRECTORY_SEPARATOR . "{$name}.{$extension}.php";
250 # Execute tempate file
251 ob_start();
252 require $templateFile;
253 $result = ob_get_clean();
254 # Returns
255 return $result;
256 }
257
258 /**
259 * put your comment there...
260 *
261 * @param mixed $handle
262 * @param mixed $jsName
263 * @param mixed $strings
264 */
265 public function localizeJS( $handle, $jsName, $strings )
266 {
267
268 $script =& $this->scripts[ $handle ];
269
270 $script[ 'l10n' ] = compact( 'jsName', 'strings' );
271
272 $script[ 'plugs' ][ ] = array( $this, '_localizeJS' );
273
274 return $this;
275 }
276
277 /**
278 * put your comment there...
279 *
280 */
281 protected function messagesList()
282 {
283 ob_start();
284
285 require __DIR__ . DIRECTORY_SEPARATOR . 'ViewTemplates' . DIRECTORY_SEPARATOR . 'MessagesList.html';
286
287 return ob_get_clean();
288 }
289
290 }