1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Views;
13
14 use ICanBoogie\Exception;
15
16 use Brickrouge\Element;
17
18 19 20
21 class ViewEditor implements \Icybee\Modules\Editor\Editor
22 {
23 24 25 26 27
28 public function serialize($content)
29 {
30 return $content;
31 }
32
33 34 35 36 37
38 public function unserialize($serialized_content)
39 {
40 return $serialized_content;
41 }
42
43 44 45 46 47
48 public function from(array $attributes)
49 {
50 return new ViewEditorElement($attributes);
51 }
52
53 public function render($id, $engine=null, $template=null)
54 {
55 global $core;
56
57 $patron = \Patron\Engine::get_singleton();
58 $page = isset($core->request->context->page) ? $core->request->context->page : null;
59
60 if (!$page)
61 {
62 $page = $core->site->resolve_view_target($id);
63
64 if (!$page)
65 {
66 $page = $core->site->home;
67 }
68 }
69
70 $definition = $core->views[$id];
71 $class = $definition['class'] ?: 'Icybee\Modules\Views\View';
72 $view = new $class($id, $definition, $patron, $core->document, $page);
73 $rc = $view();
74
75 if ($template)
76 {
77 return $engine($template, $rc);
78 }
79
80 return $rc;
81 }
82 }