1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class Horde_Core_Block_Layout_View extends Horde_Core_Block_Layout
17: {
18: 19: 20: 21: 22:
23: protected $_applications = array();
24:
25: 26: 27: 28: 29:
30: protected $_layout = array();
31:
32: 33: 34: 35: 36:
37: protected $_linkTags = array();
38:
39: 40: 41: 42: 43: 44: 45:
46: public function __construct($layout = array(), $editUrl, $viewUrl)
47: {
48: $this->_layout = $layout;
49: $this->_editUrl = $editUrl;
50: $this->_viewUrl = $viewUrl;
51: }
52:
53: 54: 55: 56: 57:
58: public function toHtml()
59: {
60: $tplDir = $GLOBALS['registry']->get('templates', 'horde');
61: $interval = $GLOBALS['prefs']->getValue('summary_refresh_time');
62:
63: $html = '<table id="portal" class="nopadding" cellspacing="8" width="100%">';
64:
65: $bc = $GLOBALS['injector']->getInstance('Horde_Core_Factory_BlockCollection')->create();
66: $covered = array();
67:
68: foreach ($this->_layout as $row_num => $row) {
69: $width = floor(100 / count($row));
70: $html .= '<tr>';
71:
72: foreach ($row as $col_num => $item) {
73: if (isset($covered[$row_num]) &&
74: isset($covered[$row_num][$col_num])) {
75: continue;
76: }
77:
78: if (is_array($item)) {
79: $block_id = 'block_' . $row_num . '_' . $col_num;
80: $this->_applications[$item['app']] = $item['app'];
81: $rowspan = $colspan = 1;
82: try {
83: $block = $bc->getBlock($item['app'], $item['params']['type2'], $item['params']['params']);
84: $rowspan = $item['height'];
85: $colspan = $item['width'];
86: for ($i = 0; $i < $item['height']; $i++) {
87: if (!isset($covered[$row_num + $i])) {
88: $covered[$row_num + $i] = array();
89: }
90: for ($j = 0; $j < $item['width']; $j++) {
91: $covered[$row_num + $i][$col_num + $j] = true;
92: }
93: }
94:
95: if ($block instanceof Horde_Core_Block) {
96: $content = $block->getContent();
97: $header = $block->getTitle();
98:
99: ob_start();
100: include $tplDir . '/portal/block.inc';
101: $html .= ob_get_clean();
102:
103: if ($block->updateable &&
104: $GLOBALS['browser']->hasFeature('xmlhttpreq')) {
105: $refresh_time = isset($item['params']['params']['_refresh_time'])
106: ? $item['params']['params']['_refresh_time']
107: : $interval;
108:
109: if (!empty($refresh_time)) {
110: $updateurl = Horde::getServiceLink('ajax', 'horde')->setRaw(true);
111: $updateurl->pathInfo = 'blockAutoUpdate';
112: $updateurl->add('app', $block->getApp())
113: ->add('blockid', get_class($block));
114:
115: Horde::addInlineScript(
116: 'setTimeout(function() {' .
117: 'new Ajax.PeriodicalUpdater(' .
118: '"' . $block_id . '",' .
119: '"' . strval($updateurl) . '",' .
120: '{ method: "get", evalScripts: true, frequency: ' . intval($refresh_time) . ' }' .
121: ');' .
122: '}, ' . intval($refresh_time * 1000) . ')',
123: 'dom'
124: );
125: }
126: }
127: } else {
128: $html .= '<td width="' . ($width * $colspan) . '%"> </td>';
129: }
130: } catch (Horde_Exception $e) {
131: $header = Horde_Core_Translation::t("Error");
132: $content = $e->getMessage();
133: ob_start();
134: include $tplDir . '/portal/block.inc';
135: $html .= ob_get_clean();
136: }
137: } else {
138: $html .= '<td width="' . ($width) . '%"> </td>';
139: }
140: }
141: $html .= '</tr>';
142: }
143: $html .= '</table>';
144:
145:
146:
147: if (preg_match_all('/<link .*?rel="stylesheet".*?\/>/', $html, $links)) {
148: $html = str_replace($links[0], '', $html);
149: $this->_linkTags = $links[0];
150: }
151:
152: return $html;
153: }
154:
155: 156: 157: 158: 159:
160: public function getLinkTags()
161: {
162: return $this->_linkTags;
163: }
164:
165: 166: 167: 168: 169:
170: public function getApplications()
171: {
172: return array_keys($this->_applications);
173: }
174:
175: }
176: