mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
update counter to use name instead of id (id still works though)
This commit is contained in:
@@ -2649,11 +2649,11 @@ The value of $name is Bob.</programlisting>
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<row>
|
<row>
|
||||||
<entry>id</entry>
|
<entry>name</entry>
|
||||||
<entry>string</entry>
|
<entry>string</entry>
|
||||||
<entry>No</entry>
|
<entry>No</entry>
|
||||||
<entry><emphasis>default</emphasis></entry>
|
<entry><emphasis>default</emphasis></entry>
|
||||||
<entry>The id of the counter</entry>
|
<entry>The name of the counter</entry>
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry>start</entry>
|
<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
|
count on each iteration. You can adjust the number, the interval
|
||||||
and the direction of the count, as well as determine whether or not
|
and the direction of the count, as well as determine whether or not
|
||||||
to print the value. You can run multiple counters concurrently by
|
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
|
supplying a unique id for each one. If you do not supply a name, the
|
||||||
default id will be used. counter was added to Smarty 1.4.0.
|
name 'default' will be used. counter was added to Smarty 1.4.0.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
If you supply the special "assign" attribute, the output of the
|
If you supply the special "assign" attribute, the output of the
|
||||||
|
@@ -13,47 +13,52 @@ function smarty_function_counter($params, &$smarty)
|
|||||||
static $count = array();
|
static $count = array();
|
||||||
static $skipval = array();
|
static $skipval = array();
|
||||||
static $dir = array();
|
static $dir = array();
|
||||||
static $id = "default";
|
static $name = "default";
|
||||||
static $printval = array();
|
static $printval = array();
|
||||||
static $assign = "";
|
static $assign = "";
|
||||||
|
|
||||||
extract($params);
|
extract($params);
|
||||||
|
|
||||||
if (!isset($id))
|
if (!isset($name)) {
|
||||||
$id = "default";
|
if(isset($id)) {
|
||||||
|
$name = $id;
|
||||||
if (isset($start))
|
} else {
|
||||||
$count[$id] = $start;
|
$name = "default";
|
||||||
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 ($printval[$id])
|
if (isset($start))
|
||||||
echo $count[$id];
|
$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))
|
if (isset($skip))
|
||||||
$skipval[$id] = $skip;
|
$skipval[$name] = $skip;
|
||||||
else if (empty($skipval[$id]))
|
else if (empty($skipval[$name]))
|
||||||
$skipval[$id] = 1;
|
$skipval[$name] = 1;
|
||||||
|
|
||||||
if (isset($direction))
|
if (isset($direction))
|
||||||
$dir[$id] = $direction;
|
$dir[$name] = $direction;
|
||||||
else if (!isset($dir[$id]))
|
else if (!isset($dir[$name]))
|
||||||
$dir[$id] = "up";
|
$dir[$name] = "up";
|
||||||
|
|
||||||
if ($dir[$id] == "down")
|
if ($dir[$name] == "down")
|
||||||
$count[$id] -= $skipval[$id];
|
$count[$name] -= $skipval[$name];
|
||||||
else
|
else
|
||||||
$count[$id] += $skipval[$id];
|
$count[$name] += $skipval[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
/* vim: set expandtab: */
|
||||||
|
@@ -13,47 +13,52 @@ function smarty_function_counter($params, &$smarty)
|
|||||||
static $count = array();
|
static $count = array();
|
||||||
static $skipval = array();
|
static $skipval = array();
|
||||||
static $dir = array();
|
static $dir = array();
|
||||||
static $id = "default";
|
static $name = "default";
|
||||||
static $printval = array();
|
static $printval = array();
|
||||||
static $assign = "";
|
static $assign = "";
|
||||||
|
|
||||||
extract($params);
|
extract($params);
|
||||||
|
|
||||||
if (!isset($id))
|
if (!isset($name)) {
|
||||||
$id = "default";
|
if(isset($id)) {
|
||||||
|
$name = $id;
|
||||||
if (isset($start))
|
} else {
|
||||||
$count[$id] = $start;
|
$name = "default";
|
||||||
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 ($printval[$id])
|
if (isset($start))
|
||||||
echo $count[$id];
|
$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))
|
if (isset($skip))
|
||||||
$skipval[$id] = $skip;
|
$skipval[$name] = $skip;
|
||||||
else if (empty($skipval[$id]))
|
else if (empty($skipval[$name]))
|
||||||
$skipval[$id] = 1;
|
$skipval[$name] = 1;
|
||||||
|
|
||||||
if (isset($direction))
|
if (isset($direction))
|
||||||
$dir[$id] = $direction;
|
$dir[$name] = $direction;
|
||||||
else if (!isset($dir[$id]))
|
else if (!isset($dir[$name]))
|
||||||
$dir[$id] = "up";
|
$dir[$name] = "up";
|
||||||
|
|
||||||
if ($dir[$id] == "down")
|
if ($dir[$name] == "down")
|
||||||
$count[$id] -= $skipval[$id];
|
$count[$name] -= $skipval[$name];
|
||||||
else
|
else
|
||||||
$count[$id] += $skipval[$id];
|
$count[$name] += $skipval[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set expandtab: */
|
/* vim: set expandtab: */
|
||||||
|
Reference in New Issue
Block a user