1<?php
2// $Id$
3
4/**
5 * Smarty plugin
6 * @package Smarty
7 * @subpackage plugins
8 *
9 * File: block.repeat.php
10 * Type: block
11 * Name: repeat
12 * Purpose: repeat a template block a given number of times
13 * Parameters: count [required] - number of times to repeat
14 * assign [optional] - variable to collect output
15 * Author: Scott Matthewman <scott@matthewman.net>
16 */
17
18//this script may only be included - so its better to die if called directly.
19if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
20	header("location: index.php");
21	exit;
22}
23
24
25function smarty_block_repeat($params, $content, $smarty, &$repeat)
26{
27	if ($repeat || ! empty($content)) {
28		$intCount = (int)$params['count'];
29		if ($intCount < 0) {
30			trigger_error("block: negative 'count' parameter");
31			return;
32		}
33
34		$strRepeat = str_repeat($content, $intCount);
35		if (! empty($params['assign'])) {
36			$smarty->assign($params['assign'], $strRepeat);
37		} else {
38			return $strRepeat;
39		}
40	}
41}
42