1: <?php
2: /**
3: * Provides basic functionality for both managing and displaying blocks.
4: *
5: * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (LGPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9: *
10: * @author Mike Cochrane <mike@graftonhall.co.nz>
11: * @author Jan Schneider <jan@horde.org>
12: * @author Michael Slusarz <slusarz@horde.org>
13: * @category Horde
14: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15: * @package Core
16: */
17: class Horde_Core_Block_Layout
18: {
19: /**
20: * Edit URL.
21: *
22: * @var string
23: */
24: protected $_editUrl;
25:
26: /**
27: * View URL.
28: *
29: * @var string
30: */
31: protected $_viewUrl;
32:
33: /**
34: * Returns whether the specified block may be removed.
35: *
36: * @param integer $row A layout row.
37: * @param integer $col A layout column.
38: *
39: * @return boolean True if this block may be removed.
40: */
41: public function isRemovable($row, $col)
42: {
43: global $conf;
44:
45: $app = $this->_layout[$row][$col]['app'];
46: $type = $this->_layout[$row][$col]['params']['type2'];
47: $block = $app . ':' . $type;
48:
49: /* Check if the block is a fixed block. */
50: if (!in_array($block, $conf['portal']['fixed_blocks'])) {
51: return true;
52: }
53:
54: /* Check if we have still another block of the same type. */
55: $found = false;
56: foreach ($this->_layout as $cur_row) {
57: foreach ($cur_row as $cur_col) {
58: if (isset($cur_col['app']) &&
59: $cur_col['app'] == $app &&
60: $cur_col['params']['type2'] == $type) {
61: if ($found) {
62: return true;
63: }
64: $found = true;
65: }
66: }
67: }
68:
69: return false;
70: }
71:
72: /**
73: * Returns an URL triggering an action to a block.
74: *
75: * @param string $action An action to trigger.
76: * @param integer $row A layout row.
77: * @param integer $col A layout column.
78: *
79: * @return Horde_Url An URL with all necessary parameters.
80: */
81: public function getActionUrl($action, $row, $col)
82: {
83: return Horde::url($this->_editUrl)->unique()->setAnchor('block')->add(array(
84: 'col' => $col,
85: 'row' => $row,
86: 'action' => $action,
87: 'url' => $this->_viewUrl
88: ));
89: }
90:
91: /**
92: * Returns the actions for the block header.
93: *
94: * @param integer $row A layout row.
95: * @param integer $col A layout column.
96: * @param boolean $edit Whether to include the edit icon.
97: * @param $url TODO
98: *
99: * @return string HTML code for the block action icons.
100: */
101: public function getHeaderIcons($row, $col, $edit, $url = null)
102: {
103: $icons = '';
104:
105: if ($edit) {
106: $icons .= Horde::link($this->getActionUrl('edit', $row, $col),
107: Horde_Core_Translation::t("Edit"))
108: . Horde::img('edit.png', Horde_Core_Translation::t("Edit"))
109: . '</a>';
110: }
111:
112: if ($this->isRemovable($row, $col)) {
113: $icons .= Horde::link(
114: $this->getActionUrl('removeBlock', $row, $col), Horde_Core_Translation::t("Remove"),
115: '', '',
116: 'return window.confirm(\''
117: . addslashes(Horde_Core_Translation::t("Really delete this block?")) . '\')')
118: . Horde::img('delete.png', Horde_Core_Translation::t("Remove"))
119: . '</a>';
120: }
121:
122: return $icons;
123: }
124:
125: }
126: