Completed
Pull Request — development (#560)
by Thomas
09:56 queued 02:10
created

block.nocache.php ➔ smarty_block_nocache()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 8
nop 4
dl 0
loc 30
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/***************************************************************************
3
  * You can find the license in the docs directory
4
 ***************************************************************************
5
 *
6
 * /* block nocache
7
 *
8
 * usage
9
 *
10
 * {nocache}...{/nocache}
11
 *
12
 * OR
13
 *
14
 * {nocache name="<unique blockname>" <varname1>=$<value1> [...]}...{/nocache}
15
 */
16
function smarty_block_nocache($param, $content, &$smarty, &$repeat)
17
{
18
    static $counter = [];
19
20
    if ($repeat) {
21
        if (!isset($param['name'])) {
22
            return $content;
23
        }
24
25
        $name = $param['name'];
26
        unset($param['name']);
27
28
        if (!isset($counter[$name])) {
29
            $counter[$name] = 0;
30
        }
31
        $counter[$name]++;
32
33
        if ($smarty->_cache_including) {
34
            $param = isset($smarty->_cache_info['cached_vars'][$name][$counter[$name]]) ? $smarty->_cache_info['cached_vars'][$name][$counter[$name]] : [];
35
        } else {
36
            $smarty->_cache_info['cached_vars'][$name][$counter[$name]] = $param;
37
        }
38
39
        foreach ($param as $k => $v) {
40
            $smarty->_tpl_vars[$k] = $v;
41
        }
42
    }
43
44
    return $content;
45
}
46