XOOPS  2.6.0
function.xoblock.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
40 function smarty_function_xoblock($params, &$smarty)
41 {
42  if (!isset($params['id'])) {
43  return false;
44  }
45 
47 
48  $display_title = (isset($params['display']) && $params['display'] == 'title') ? true : false;
49  $display_none = (isset($params['display']) && $params['display'] == 'none') ? true : false;
50  $options = (isset($params['options'])) ? $params['options'] : false;
51  $groups = (isset($params['groups'])) ? explode('|', $params['groups']) : false;
52  $cache = (isset($params['cache'])) ? intval($params['cache']) : false;
53 
54  $block_id = intval($params['id']);
55 
56  $block_handler = $xoops->getHandlerBlock();
57  static $block_objs;
58  if (!isset($block_objs[$block_id])) {
59  $blockObj = $block_handler->get($block_id);
60  if (!is_object($blockObj)) {
61  return false;
62  }
63  $block_objs[$block_id] = $blockObj;
64  } else {
65  $blockObj = $block_objs[$block_id];
66  }
67  $user_groups = $xoops->getUserGroups();
68 
69  static $allowed_blocks;
70  if (count($allowed_blocks) == 0) {
71  $allowed_blocks = $block_handler->getAllBlocksByGroup($user_groups, false);
72  }
73 
74  if ($groups) {
75  if (!array_intersect($user_groups, $groups)) {
76  return false;
77  }
78  } else {
79  if (!in_array($block_id, $allowed_blocks)) {
80  return false;
81  }
82  }
83 
84  if ($options) {
85  $blockObj->setVar('options', $options);
86  }
87 
88  if ($cache) {
89  $blockObj->setVar('bcachetime', $cache);
90  }
91 
92  if ($display_title) {
93  return $blockObj->getVar('title');
94  }
95 
96  $tpl = new XoopsTpl();
97  $block_renderer = new XoopsThemeBlocksPlugin();
98  $block_renderer->theme = $xoops->theme();
99  $block = $block_renderer->buildBlock($blockObj, $tpl);
100  if (!$display_none) {
101  return $block['content'];
102  }
103  return '';
104 }
$tpl
Definition: backend.php:39
static getInstance()
Definition: Xoops.php:160
$options['editor']
smarty_function_xoblock($params, &$smarty)
$xoops
Definition: admin.php:25
$groups