1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
<?php
require_once 'Horde/Browser.php';
require_once 'Horde/Block/Collection.php';
/**
* The Horde_Block_Layout_View class represents the user defined portal layout.
*
* $Horde: framework/Block/Block/Layout/View.php,v 1.4.2.3 2006/06/23 04:35:21 chuck Exp $
*
* Copyright 2003-2006 Mike Cochrane <mike@graftonhall.co.nz>
* Copyright 2003-2006 Jan Schneider <jan@horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Mike Cochrane <mike@graftonhall.co.nz>
* @author Jan Schneider <jan@horde.org>
* @since Horde 3.2
* @package Horde_Block
*/
class Horde_Block_Layout_View {
/**
* The current block layout.
*
* @var array
*/
var $_layout = array();
/**
* All applications used in this layout.
*
* @var array
*/
var $_applications = array();
/**
* CSS link tags pulled out of block content.
*
* @var array
*/
var $_linkTags = array();
/**
* Constructor.
*/
function Horde_Block_Layout_View($layout = '')
{
$this->_layout = @unserialize($layout);
if (!$this->_layout) {
$this->_layout = array();
}
}
/**
* Render the current layout as HTML.
*
* @return string HTML layout.
*/
function toHtml()
{
$browser = &Browser::singleton();
$tplDir = $GLOBALS['registry']->get('templates', 'horde');
$interval = $GLOBALS['prefs']->getValue('summary_refresh_time');
$html = '<table class="nopadding" cellspacing="6" width="100%">';
$covered = array();
foreach ($this->_layout as $row_num => $row) {
$width = floor(100 / count($row));
$html .= '<tr>';
foreach ($row as $col_num => $item) {
if (isset($covered[$row_num]) && isset($covered[$row_num][$col_num])) {
continue;
}
if (is_array($item)) {
$this->_applications[$item['app']] = $item['app'];
$block = &Horde_Block_Collection::getBlock($item['app'], $item['params']['type'], $item['params']['params']);
$rowspan = $item['height'];
$colspan = $item['width'];
$width *= $colspan;
for ($i = 0; $i < $item['height']; $i++) {
if (!isset($covered[$row_num + $i])) {
$covered[$row_num + $i] = array();
}
for ($j = 0; $j < $item['width']; $j++) {
$covered[$row_num + $i][$col_num + $j] = true;
}
}
if (is_a($block, 'PEAR_Error')) {
$header = _("Error");
$content = $block->getMessage();
ob_start();
include $tplDir . '/portal/block.inc';
$html .= ob_get_clean();
} elseif (is_a($block, 'Horde_Block')) {
$header = $block->getTitle();
$content = $block->getContent();
ob_start();
include $tplDir . '/portal/block.inc';
$html .= ob_get_clean();
} else {
$html .= '<td width="' . $width . '%"> </td>';
}
} else {
$html .= '<td width="' . $width . '%"> </td>';
}
}
$html .= '</tr>';
}
$html .= '</table>';
// Strip any CSS <link> tags out of the returned content so
// they can be handled seperately.
if (preg_match_all('/<link .*?rel="stylesheet".*?\/>/', $html, $links)) {
$html = str_replace($links[0], '', $html);
$this->_linkTags = $links[0];
}
return $html;
}
/**
* Get any link tags found in the view.
*/
function getLinkTags()
{
return $this->_linkTags;
}
/**
* Return a list of all the applications used by blocks in this layout.
*
* @return array List of applications.
*/
function getApplications()
{
return array_keys($this->_applications);
}
}
|