update counter to use name instead of id (id still works though)

This commit is contained in:
mohrt
2002-05-03 18:22:41 +00:00
parent 2cb3d473f6
commit 541e03660e
3 changed files with 56 additions and 46 deletions

View File

@@ -2649,11 +2649,11 @@ The value of $name is Bob.</programlisting>
</thead>
<tbody>
<row>
<entry>id</entry>
<entry>name</entry>
<entry>string</entry>
<entry>No</entry>
<entry><emphasis>default</emphasis></entry>
<entry>The id of the counter</entry>
<entry>The name of the counter</entry>
</row>
<row>
<entry>start</entry>
@@ -2699,8 +2699,8 @@ The value of $name is Bob.</programlisting>
count on each iteration. You can adjust the number, the interval
and the direction of the count, as well as determine whether or not
to print the value. You can run multiple counters concurrently by
supplying a unique id for each one. If you do not supply an id, the
default id will be used. counter was added to Smarty 1.4.0.
supplying a unique id for each one. If you do not supply a name, the
name 'default' will be used. counter was added to Smarty 1.4.0.
</para>
<para>
If you supply the special "assign" attribute, the output of the

View File

@@ -13,47 +13,52 @@ function smarty_function_counter($params, &$smarty)
static $count = array();
static $skipval = array();
static $dir = array();
static $id = "default";
static $name = "default";
static $printval = array();
static $assign = "";
extract($params);
if (!isset($id))
$id = "default";
if (isset($start))
$count[$id] = $start;
else if (!isset($count[$id]))
$count[$id]=1;
if (!isset($print))
$printval[$id]=true;
else
$printval[$id]=$print;
if (!empty($assign)) {
$printval[$id] = false;
$smarty->assign($assign, $count[$id]);
if (!isset($name)) {
if(isset($id)) {
$name = $id;
} else {
$name = "default";
}
}
if ($printval[$id])
echo $count[$id];
if (isset($start))
$count[$name] = $start;
else if (!isset($count[$name]))
$count[$name]=1;
if (!isset($print))
$printval[$name]=true;
else
$printval[$name]=$print;
if (!empty($assign)) {
$printval[$name] = false;
$smarty->assign($assign, $count[$name]);
}
if ($printval[$name])
echo $count[$name];
if (isset($skip))
$skipval[$id] = $skip;
else if (empty($skipval[$id]))
$skipval[$id] = 1;
$skipval[$name] = $skip;
else if (empty($skipval[$name]))
$skipval[$name] = 1;
if (isset($direction))
$dir[$id] = $direction;
else if (!isset($dir[$id]))
$dir[$id] = "up";
$dir[$name] = $direction;
else if (!isset($dir[$name]))
$dir[$name] = "up";
if ($dir[$id] == "down")
$count[$id] -= $skipval[$id];
if ($dir[$name] == "down")
$count[$name] -= $skipval[$name];
else
$count[$id] += $skipval[$id];
$count[$name] += $skipval[$name];
}
/* vim: set expandtab: */

View File

@@ -13,47 +13,52 @@ function smarty_function_counter($params, &$smarty)
static $count = array();
static $skipval = array();
static $dir = array();
static $id = "default";
static $name = "default";
static $printval = array();
static $assign = "";
extract($params);
if (!isset($id))
$id = "default";
if (isset($start))
$count[$id] = $start;
else if (!isset($count[$id]))
$count[$id]=1;
if (!isset($print))
$printval[$id]=true;
else
$printval[$id]=$print;
if (!empty($assign)) {
$printval[$id] = false;
$smarty->assign($assign, $count[$id]);
if (!isset($name)) {
if(isset($id)) {
$name = $id;
} else {
$name = "default";
}
}
if ($printval[$id])
echo $count[$id];
if (isset($start))
$count[$name] = $start;
else if (!isset($count[$name]))
$count[$name]=1;
if (!isset($print))
$printval[$name]=true;
else
$printval[$name]=$print;
if (!empty($assign)) {
$printval[$name] = false;
$smarty->assign($assign, $count[$name]);
}
if ($printval[$name])
echo $count[$name];
if (isset($skip))
$skipval[$id] = $skip;
else if (empty($skipval[$id]))
$skipval[$id] = 1;
$skipval[$name] = $skip;
else if (empty($skipval[$name]))
$skipval[$name] = 1;
if (isset($direction))
$dir[$id] = $direction;
else if (!isset($dir[$id]))
$dir[$id] = "up";
$dir[$name] = $direction;
else if (!isset($dir[$name]))
$dir[$name] = "up";
if ($dir[$id] == "down")
$count[$id] -= $skipval[$id];
if ($dir[$name] == "down")
$count[$name] -= $skipval[$name];
else
$count[$id] += $skipval[$id];
$count[$name] += $skipval[$name];
}
/* vim: set expandtab: */