Overview

Packages

  • Auth
  • Core
  • Horde
    • Imsp
  • None
  • Notification

Classes

  • Horde
  • Horde_Config
  • Horde_Config_Form
  • Horde_Core_ActiveSync_Connector
  • Horde_Core_ActiveSync_Driver
  • Horde_Core_Ajax_Application
  • Horde_Core_Ajax_Imple
  • Horde_Core_Ajax_Imple_AutoCompleter
  • Horde_Core_Ajax_Imple_Geocoder_Geonames
  • Horde_Core_Ajax_Imple_SpellChecker
  • Horde_Core_Alarm_Handler_Notify
  • Horde_Core_Auth_Application
  • Horde_Core_Auth_Composite
  • Horde_Core_Auth_Ldap
  • Horde_Core_Auth_Msad
  • Horde_Core_Auth_Shibboleth
  • Horde_Core_Auth_Signup_Base
  • Horde_Core_Auth_Signup_Form
  • Horde_Core_Auth_Signup_Null
  • Horde_Core_Auth_Signup_Sql
  • Horde_Core_Auth_Signup_SqlObject
  • Horde_Core_Autoloader_Callback_Mime
  • Horde_Core_Autoloader_Callback_Nls
  • Horde_Core_Block
  • Horde_Core_Block_Collection
  • Horde_Core_Block_Layout
  • Horde_Core_Block_Layout_Manager
  • Horde_Core_Block_Layout_View
  • Horde_Core_Block_Upgrade
  • Horde_Core_Browser
  • Horde_Core_Bundle
  • Horde_Core_Cli
  • Horde_Core_Controller_NotFound
  • Horde_Core_Controller_RequestConfiguration
  • Horde_Core_Controller_RequestMapper
  • Horde_Core_Controller_SettingsFinder
  • Horde_Core_Db_Migration
  • Horde_Core_Factory_ActiveSyncBackend
  • Horde_Core_Factory_ActiveSyncServer
  • Horde_Core_Factory_ActiveSyncState
  • Horde_Core_Factory_Ajax
  • Horde_Core_Factory_Alarm
  • Horde_Core_Factory_Auth
  • Horde_Core_Factory_AuthSignup
  • Horde_Core_Factory_Base
  • Horde_Core_Factory_BlockCollection
  • Horde_Core_Factory_Browser
  • Horde_Core_Factory_Cache
  • Horde_Core_Factory_Crypt
  • Horde_Core_Factory_Data
  • Horde_Core_Factory_Db
  • Horde_Core_Factory_DbBase
  • Horde_Core_Factory_DbPear
  • Horde_Core_Factory_Dns
  • Horde_Core_Factory_Editor
  • Horde_Core_Factory_Facebook
  • Horde_Core_Factory_Group
  • Horde_Core_Factory_History
  • Horde_Core_Factory_HttpClient
  • Horde_Core_Factory_Identity
  • Horde_Core_Factory_Image
  • Horde_Core_Factory_Imple
  • Horde_Core_Factory_Imsp
  • Horde_Core_Factory_ImspAuth
  • Horde_Core_Factory_Injector
  • Horde_Core_Factory_KolabServer
  • Horde_Core_Factory_KolabSession
  • Horde_Core_Factory_KolabStorage
  • Horde_Core_Factory_Ldap
  • Horde_Core_Factory_Lock
  • Horde_Core_Factory_Logger
  • Horde_Core_Factory_LoginTasks
  • Horde_Core_Factory_Mail
  • Horde_Core_Factory_Mapper
  • Horde_Core_Factory_Matcher
  • Horde_Core_Factory_Memcache
  • Horde_Core_Factory_MimeViewer
  • Horde_Core_Factory_Notification
  • Horde_Core_Factory_Perms
  • Horde_Core_Factory_PermsCore
  • Horde_Core_Factory_Prefs
  • Horde_Core_Factory_Request
  • Horde_Core_Factory_Secret
  • Horde_Core_Factory_SessionHandler
  • Horde_Core_Factory_Share
  • Horde_Core_Factory_ShareBase
  • Horde_Core_Factory_Template
  • Horde_Core_Factory_TextFilter
  • Horde_Core_Factory_ThemesCache
  • Horde_Core_Factory_Token
  • Horde_Core_Factory_Tree
  • Horde_Core_Factory_Twitter
  • Horde_Core_Factory_UrlShortener
  • Horde_Core_Factory_Vfs
  • Horde_Core_Factory_View
  • Horde_Core_Factory_Weather
  • Horde_Core_Group_Ldap
  • Horde_Core_Log_Logger
  • Horde_Core_LoginTasks
  • Horde_Core_LoginTasks_Backend_Horde
  • Horde_Core_LoginTasks_SystemTask_Upgrade
  • Horde_Core_Mime_Viewer_Syntaxhighlighter
  • Horde_Core_Mime_Viewer_Vcard
  • Horde_Core_Notification_Event_Status
  • Horde_Core_Notification_Handler_Decorator_Hordelog
  • Horde_Core_Notification_Storage_Session
  • Horde_Core_Perms
  • Horde_Core_Perms_Ui
  • Horde_Core_Prefs_Cache_Session
  • Horde_Core_Prefs_Identity
  • Horde_Core_Prefs_Storage_Configuration
  • Horde_Core_Prefs_Storage_Hooks
  • Horde_Core_Prefs_Storage_Upgrade
  • Horde_Core_Prefs_Ui
  • Horde_Core_Prefs_Ui_Widgets
  • Horde_Core_Share_Driver
  • Horde_Core_Share_FactoryCallback
  • Horde_Core_Sidebar
  • Horde_Core_Text_Filter_Bbcode
  • Horde_Core_Text_Filter_Emails
  • Horde_Core_Text_Filter_Emoticons
  • Horde_Core_Text_Filter_Highlightquotes
  • Horde_Core_Translation
  • Horde_Core_Tree_Html
  • Horde_Core_Tree_Javascript
  • Horde_Core_Tree_Simplehtml
  • Horde_Core_Ui_FlagImage
  • Horde_Core_Ui_JsCalendar
  • Horde_Core_Ui_Language
  • Horde_Core_Ui_Layout
  • Horde_Core_Ui_ModalFormRenderer
  • Horde_Core_Ui_Pager
  • Horde_Core_Ui_Tabs
  • Horde_Core_Ui_TagCloud
  • Horde_Core_Ui_VarRenderer
  • Horde_Core_Ui_VarRenderer_Html
  • Horde_Core_Ui_VarRenderer_TablesetHtml
  • Horde_Core_Ui_Widget
  • Horde_ErrorHandler
  • Horde_Help
  • Horde_Menu
  • Horde_Registry
  • Horde_Registry_Api
  • Horde_Registry_Application
  • Horde_Registry_Caller
  • Horde_Registry_Nlsconfig
  • Horde_Script_Files
  • Horde_Session
  • Horde_Session_Null
  • Horde_Themes
  • Horde_Themes_Cache
  • Horde_Themes_Css
  • Horde_Themes_Element
  • Horde_Themes_Image
  • Horde_Themes_Sound

Exceptions

  • Horde_Exception_HookNotSet
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * This class provides an API to the blocks (applets) framework.
  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_Collection implements Serializable
 18: {
 19:     /**
 20:      * A hash storing the information about all available blocks from
 21:      * all applications.
 22:      *
 23:      * @var array
 24:      */
 25:     protected $_blocks = array();
 26: 
 27:     /**
 28:      * Layout configuration preference name.
 29:      *
 30:      * @var string
 31:      */
 32:     protected $_layout;
 33: 
 34:     /**
 35:      * Constructor.
 36:      *
 37:      * @param array $apps     The applications whose blocks to list.
 38:      * @param string $layout  Layout configuration preference name.
 39:      */
 40:     public function __construct(array $apps, $layout)
 41:     {
 42:         foreach ($apps as $app) {
 43:             $drivers = $GLOBALS['registry']->getAppDrivers($app, 'Block');
 44:             foreach ($drivers as $val) {
 45:                 $tmp = new $val($app);
 46:                 if ($tmp->enabled) {
 47:                     $this->_blocks[$app][$val]['name'] = $tmp->getName();
 48:                 }
 49:             }
 50:         }
 51: 
 52:         $this->_layout = $layout;
 53:     }
 54: 
 55:     /**
 56:      * Return the layout configuration for this collection.
 57:      *
 58:      * @return array  The layout configuration.
 59:      */
 60:     public function getLayout()
 61:     {
 62:         $layout = @unserialize($GLOBALS['prefs']->getValue($this->_layout));
 63: 
 64:         if (empty($layout)) {
 65:             $layout = array();
 66: 
 67:             if (isset($GLOBALS['conf']['portal']['fixed_blocks'])) {
 68:                 foreach ($GLOBALS['conf']['portal']['fixed_blocks'] as $block) {
 69:                     list($app, $type) = explode(':', $block, 2);
 70:                     $layout[] = array(
 71:                         array(
 72:                             'app' => $app,
 73:                             'params' => array(
 74:                                 'type2' => $type,
 75:                                 'params' => false
 76:                             ),
 77:                             'height' => 1,
 78:                             'width' => 1
 79:                         )
 80:                     );
 81:                 }
 82:             }
 83:         }
 84: 
 85:         return $layout;
 86:     }
 87: 
 88:     /**
 89:      * Return the layout manager for this collection.
 90:      *
 91:      * @return Horde_Core_Block_Layout_Manager  Layout manager object.
 92:      */
 93:     public function getLayoutManager()
 94:     {
 95:         return new Horde_Core_Block_Layout_Manager($this);
 96:     }
 97: 
 98:     /**
 99:      * Gets a block object.
100:      *
101:      * @param string $app    Application name.
102:      * @param string $name   The Block's classname.
103:      * @param array $params  Parameters.  If null, the stored parameters will
104:      *                       be used.
105:      *
106:      * @return Horde_Core_Block  Block object.
107:      * @throws Horde_Exception
108:      */
109:     public function getBlock($app, $name, $params = null)
110:     {
111:         global $registry;
112: 
113:         if ($registry->isInactive($app)) {
114:             throw new Horde_Exception(sprintf('%s is not activated.', $GLOBALS['registry']->get('name', $app)));
115:         }
116: 
117:         $pushed = $registry->pushApp($app);
118: 
119:         if (!class_exists($name)) {
120:             if ($pushed) {
121:                 $registry->popApp($app);
122:             }
123:             throw new Horde_Exception(sprintf('%s not found.', $name));
124:         }
125: 
126:         if (is_null($params)) {
127:             foreach ($this->getLayout() as $row) {
128:                 foreach ($row as $col) {
129:                     if (is_array($col) &&
130:                         (strcasecmp($col['params']['type2'], $name) === 0)) {
131:                         $params = $col['params']['params'];
132:                         break 2;
133:                     }
134:                 }
135:             }
136:         }
137: 
138:         $ob = new $name($app, $params);
139: 
140:         if ($pushed) {
141:             $registry->popApp($app);
142:         }
143: 
144:         if (is_null($ob)) {
145:             throw new Horde_Exception(sprintf('%s not found.', $name));
146:         }
147: 
148:         return $ob;
149:     }
150: 
151:     /**
152:      * Returns a pretty printed list of all available blocks.
153:      *
154:      * @return array  A hash with block IDs as keys and application plus block
155:      *                block names as values.
156:      */
157:     public function getBlocksList()
158:     {
159:         $blocks = array();
160: 
161:         /* Get available blocks from all apps. */
162:         foreach ($this->_blocks as $app => $app_blocks) {
163:             $app_name = $GLOBALS['registry']->get('name', $app);
164: 
165:             foreach ($app_blocks as $block_id => $block) {
166:                 $blocks[$app . ':' . $block_id] = $app_name . ': ' . $block['name'];
167:             }
168:         }
169: 
170:         return $blocks;
171:     }
172: 
173:     /**
174:      * Returns a layout with all fixed blocks as per configuration.
175:      *
176:      * @return string  A default serialized block layout.
177:      */
178:     public function getFixedBlocks()
179:     {
180:         $layout = array();
181: 
182: 
183:         return $layout;
184:     }
185: 
186:     /**
187:      * Returns a select widget with all available blocks.
188:      *
189:      * @param string $cur_app    The block from this application gets selected.
190:      * @param string $cur_block  The block with this name gets selected.
191:      * @param boolean $onchange  Include the onchange action
192:      * @param boolean $readonly  Indicates if this block type is changeable.
193:      *
194:      * @return string  The select tag with all available blocks.
195:      */
196:     public function getBlocksWidget($cur_app = null, $cur_block = null,
197:                                     $onchange = false, $readonly = false)
198:     {
199:         $widget = '<select name=' . (!$readonly ? '"app"' : '"roapp"');
200: 
201:         if ($onchange) {
202:             $widget .= ' onchange="document.blockform.action.value=\'save-resume\';document.blockform.submit()"';
203:         }
204: 
205:         if ($readonly) {
206:             $widget .= ' disabled="disabled"';
207:         }
208: 
209:         $widget .= ">\n";
210: 
211:         foreach ($this->getBlocksList() as $id => $name) {
212:             $widget .= sprintf(
213:                 "<option value=\"%s\"%s>%s</option>\n",
214:                 $id,
215:                 ($id == $cur_app . ':' . $cur_block) ? ' selected="selected"' : '',
216:                 $name
217:             );
218:         }
219:         $widget .= "</select>\n";
220:         if ($readonly) {
221:             $widget .= '<input type="hidden" name="app" value="' . $cur_app . ':' . $cur_block . '" />' . "\n";
222:         }
223: 
224:         return $widget;
225:     }
226: 
227:     /**
228:      * Returns the option type.
229:      *
230:      * @param $app TODO
231:      * @param $block TODO
232:      * @param $param_id TODO
233:      *
234:      * @return TODO
235:      */
236:     public function getOptionType($app, $block, $param_id)
237:     {
238:         $this->getParams($app, $block);
239:         return $this->_blocks[$app][$block]['params'][$param_id]['type2'];
240:     }
241: 
242:     /**
243:      * Returns whether the option is required or not. Defaults to true.
244:      *
245:      * @param $app TODO
246:      * @param $block TODO
247:      * @param $param_id TODO
248:      *
249:      * @return TODO
250:      */
251:     public function getOptionRequired($app, $block, $param_id)
252:     {
253:         $this->getParams($app, $block);
254:         return isset($this->_blocks[$app][$block]['params'][$param_id]['required'])
255:             ? $this->_blocks[$app][$block]['params'][$param_id]['required']
256:             : true;
257:     }
258: 
259:     /**
260:      * Returns the values for an option.
261:      *
262:      * @param $app TODO
263:      * @param $block TODO
264:      * @param $param_id TODO
265:      *
266:      * @return TODO
267:      */
268:     public function getOptionValues($app, $block, $param_id)
269:     {
270:         $this->getParams($app, $block);
271:         return $this->_blocks[$app][$block]['params'][$param_id]['values'];
272:     }
273: 
274:     /**
275:      * Returns the widget necessary to configure this block.
276:      *
277:      * @param $app TODO
278:      * @param $block TODO
279:      * @param $param_id TODO
280:      * @param $val TODO
281:      *
282:      * @return TODO
283:      */
284:     public function getOptionsWidget($app, $block, $param_id, $val = null)
285:     {
286:         $widget = '';
287: 
288:         $this->getParams($app, $block);
289:         $param = $this->_blocks[$app][$block]['params'][$param_id];
290:         if (!isset($param['default'])) {
291:             $param['default'] = '';
292:         }
293: 
294:         switch ($param['type']) {
295:         case 'boolean':
296:         case 'checkbox':
297:             $checked = !empty($val[$param_id]) ? ' checked="checked"' : '';
298:             $widget = sprintf('<input type="checkbox" name="params[%s]"%s />', $param_id, $checked);
299:             break;
300: 
301:         case 'enum':
302:             $widget = sprintf('<select name="params[%s]">', $param_id);
303:             foreach ($param['values'] as $key => $name) {
304:                 if (Horde_String::length($name) > 30) {
305:                     $name = substr($name, 0, 27) . '...';
306:                 }
307:                 $widget .= sprintf("<option value=\"%s\"%s>%s</option>\n",
308:                                    htmlspecialchars($key),
309:                                    (isset($val[$param_id]) && $val[$param_id] == $key) ? ' selected="selected"' : '',
310:                                    htmlspecialchars($name));
311:             }
312: 
313:             $widget .= '</select>';
314:             break;
315: 
316:         case 'multienum':
317:             $widget = sprintf('<select multiple="multiple" name="params[%s][]">', $param_id);
318:             foreach ($param['values'] as $key => $name) {
319:                 if (Horde_String::length($name) > 30) {
320:                     $name = substr($name, 0, 27) . '...';
321:                 }
322:                 $widget .= sprintf("<option value=\"%s\"%s>%s</option>\n",
323:                                    htmlspecialchars($key),
324:                                    (isset($val[$param_id]) && in_array($key, $val[$param_id])) ? ' selected="selected"' : '',
325:                                    htmlspecialchars($name));
326:             }
327: 
328:             $widget .= '</select>';
329:             break;
330: 
331:         case 'mlenum':
332:             // Multi-level enum.
333:             if (is_array($val) && isset($val['__' . $param_id])) {
334:                 $firstval = $val['__' . $param_id];
335:             } else {
336:                 $tmp = array_keys($param['values']);
337:                 $firstval = current($tmp);
338:             }
339:             $blockvalues = $param['values'][$firstval];
340:             asort($blockvalues);
341: 
342:             $widget = sprintf('<select name="params[__%s]" onchange="document.blockform.action.value=\'save-resume\';document.blockform.submit()">', $param_id) . "\n";
343:             foreach ($param['values'] as $key => $values) {
344:                 $name = Horde_String::length($key) > 30 ? Horde_String::substr($key, 0, 27) . '...' : $key;
345:                 $widget .= sprintf("<option value=\"%s\"%s>%s</option>\n",
346:                                    htmlspecialchars($key),
347:                                    $key == $firstval ? ' selected="selected"' : '',
348:                                    htmlspecialchars($name));
349:             }
350:             $widget .= "</select><br />\n";
351: 
352:             $widget .= sprintf("<select name=\"params[%s]\">\n", $param_id);
353:             foreach ($blockvalues as $key => $name) {
354:                 $name = (Horde_String::length($name) > 30) ? Horde_String::substr($name, 0, 27) . '...' : $name;
355:                 $widget .= sprintf("<option value=\"%s\"%s>%s</option>\n",
356:                                    htmlspecialchars($key),
357:                                    $val[$param_id] == $key ? ' selected="selected"' : '',
358:                                    htmlspecialchars($name));
359:             }
360:             $widget .= "</select><br />\n";
361:             break;
362: 
363:         case 'int':
364:         case 'text':
365:             $widget = sprintf('<input type="text" name="params[%s]" value="%s" />', $param_id, !isset($val[$param_id]) ? $param['default'] : $val[$param_id]);
366:             break;
367: 
368:         case 'password':
369:             $widget = sprintf('<input type="password" name="params[%s]" value="%s" />', $param_id, !isset($val[$param_id]) ? $param['default'] : $val[$param_id]);
370:             break;
371: 
372:         case 'error':
373:             $widget = '<span class="form-error">' . $param['default'] . '</span>';
374:             break;
375:         }
376: 
377:         return $widget;
378:     }
379: 
380:     /**
381:      * Returns the name of the specified block.
382:      *
383:      * @param string $app    An application name.
384:      * @param string $block  A block name.
385:      *
386:      * @return string  The name of the specified block.
387:      */
388:     public function getName($app, $block)
389:     {
390:         return isset($this->_blocks[$app][$block])
391:             ? $this->_blocks[$app][$block]['name']
392:             : sprintf(Horde_Core_Translation::t("Block \"%s\" of application \"%s\" not found."), $block, $app);
393:     }
394: 
395:     /**
396:      * Returns the parameter list of the specified block.
397:      *
398:      * @param string $app    An application name.
399:      * @param string $block  A block name.
400:      *
401:      * @return array  An array with all parameter names.
402:      */
403:     public function getParams($app, $block)
404:     {
405:         if (!isset($this->_blocks[$app][$block])) {
406:             return array();
407:         }
408: 
409:         if (!isset($this->_blocks[$app][$block]['params'])) {
410:             $blockOb = $this->getBlock($app, $block);
411:             $this->_blocks[$app][$block]['params'] = $blockOb->getParams();
412:         }
413: 
414:         if (isset($this->_blocks[$app][$block]['params']) &&
415:             is_array($this->_blocks[$app][$block]['params'])) {
416:             return array_keys($this->_blocks[$app][$block]['params']);
417:         }
418: 
419:         return array();
420:     }
421: 
422:     /**
423:      * Returns the (clear text) name of the specified parameter.
424:      *
425:      * @param string $app    An application name.
426:      * @param string $block  A block name.
427:      * @param string $param  A parameter name.
428:      *
429:      * @return string  The name of the specified parameter.
430:      */
431:     public function getParamName($app, $block, $param)
432:     {
433:         $this->getParams($app, $block);
434:         return $this->_blocks[$app][$block]['params'][$param]['name'];
435:     }
436: 
437:     /**
438:      * Returns the default value of the specified parameter.
439:      *
440:      * @param string $app    An application name.
441:      * @param string $block  A block name.
442:      * @param string $param  A parameter name.
443:      *
444:      * @return string  The default value of the specified parameter or null.
445:      */
446:     public function getDefaultValue($app, $block, $param)
447:     {
448:         $this->getParams($app, $block);
449:         return isset($this->_blocks[$app][$block]['params'][$param]['default'])
450:             ? $this->_blocks[$app][$block]['params'][$param]['default']
451:             : null;
452:     }
453: 
454:     /**
455:      * Returns if the specified block is customizeable by the user.
456:      *
457:      * @param string $app    An application name.
458:      * @param string $block  A block name.
459:      *
460:      * @return boolean  True is the block is customizeable.
461:      */
462:     public function isEditable($app, $block)
463:     {
464:         $block = $this->getBlock($app, $block);
465:         return $block->updateable || $block->getParams();
466:     }
467: 
468:     /* Serializable methods. */
469: 
470:     public function serialize()
471:     {
472:         return json_encode(array(
473:             $this->_blocks,
474:             $this->_layout
475:         ));
476:     }
477: 
478:     public function unserialize($data)
479:     {
480:         list($this->_blocks, $this->_layout) = json_decode($data, true);
481:     }
482: 
483: }
484: 
API documentation generated by ApiGen