1: <?php
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: function smarty_function_block($params, &$smarty)
31: {
32: if (!isset($params['id'])) {
33: return null;
34: }
35:
36: $display_title = (isset($params['display']) && $params['display'] === 'title');
37: $display_none = (isset($params['display']) && $params['display'] === 'none');
38: $options = isset($params['options']) ? $params['options'] : false;
39: $groups = isset($params['groups']) ? explode('|', $params['groups']) : false;
40: $cache = isset($params['cache']) ? (int)$params['cache'] : false;
41:
42: $block_id = (int)$params['id'];
43:
44: static $block_objs;
45: if (!isset($block_objs[$block_id])) {
46: include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
47:
48: $blockObj = new XoopsBlock($block_id);
49:
50: if (!is_object($blockObj)) {
51: return null;
52: }
53:
54: $block_objs[$block_id] = $blockObj;
55: } else {
56: $blockObj = $block_objs[$block_id];
57: }
58:
59: $user_groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
60:
61: static $allowed_blocks;
62: if (count($allowed_blocks) == 0) {
63: $allowed_blocks = XoopsBlock::getAllBlocksByGroup($user_groups, false);
64: }
65:
66: if ($groups) {
67: if (!array_intersect($user_groups, $groups)) {
68: return null;
69: }
70: } else {
71: if (!in_array($block_id, $allowed_blocks)) {
72: return null;
73: }
74: }
75:
76: if ($options) {
77: $blockObj->setVar('options', $options);
78: }
79:
80: if ($cache) {
81: $blockObj->setVar('bcachetime', $cache);
82: }
83:
84: if ($display_title) {
85: return $blockObj->getVar('title');
86: }
87:
88: $xoopsLogger = XoopsLogger::getInstance();
89: $template =& $GLOBALS['xoopsTpl'];
90:
91: $bcachetime = (int)$blockObj->getVar('bcachetime');
92: if (empty($bcachetime)) {
93: $template->caching = 0;
94: } else {
95: $template->caching = 2;
96: $template->cache_lifetime = $bcachetime;
97: }
98:
99: $template->setCompileId($blockObj->getVar('dirname', 'n'));
100: $tplName = ($tplName = $blockObj->getVar('template')) ? "db:{$tplName}" : 'db:system_block_dummy.tpl';
101: $cacheid = 'blk_' . $block_id;
102:
103: if (!$bcachetime || !$template->is_cached($tplName, $cacheid)) {
104: $xoopsLogger->addBlock($blockObj->getVar('name'));
105: if (!($bresult = $blockObj->buildBlock())) {
106: return null;
107: }
108: if (!$display_none) {
109: $template->assign('block', $bresult);
110: $template->display($tplName, $cacheid);
111: }
112: } else {
113: $xoopsLogger->addBlock($blockObj->getVar('name'), true, $bcachetime);
114: if (!$display_none) {
115: $template->display($tplName, $cacheid);
116: }
117: }
118: $template->setCompileId($blockObj->getVar('dirname', 'n'));
119:
120: return null;
121: }
122: