| Server IP : 23.94.149.180 / Your IP : 216.73.216.147 Web Server : nginx/1.20.1 System : Linux deadrock 5.14.0-741.22.1.el9_9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Nov 12 15:18:14 UTC 2026 x86_64 User : apache ( 48) PHP Version : 8.6.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /files/www/lawyerbabe/mblog/php/lib/ |
Upload File : |
<?php
# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
# This program is distributed under the terms of the
# GNU General Public License, version 2.
#
# $Id: function.mtsetvar.php 1174 2008-01-08 21:02:50Z bchoate $
function smarty_function_mtsetvar($args, &$ctx) {
// status: complete
// parameters: name, value
$name = $args['name'];
$name or $name = $args['var'];
if (!$name) return '';
$vars =& $ctx->__stash['vars'];
if (preg_match('/^(\w+)\((.+)\)$/', $name, $matches)) {
$func = $matches[1];
$name = $matches[2];
} else {
if (array_key_exists('function', $args))
$func = $args['function'];
}
# pick off any {...} or [...] from the name.
if (preg_match('/^(.+)([\[\{])(.+)[\]\}]$/', $name, $matches)) {
$name = $matches[1];
$br = $matches[2];
$ref = $matches[3];
if (preg_match('/^\$(.+)/', $ref, $ref_matches)) {
$ref = $vars[$ref_matches[1]];
if (!isset($ref))
$ref = chr(0);
}
$br == '[' ? $index = $ref : $key = $ref;
} else {
if (array_key_exists('index', $args))
$index = $args['index'];
else if (array_key_exists('key', $args))
$key = $args['key'];
}
if (preg_match('/^$/', $name)) {
$name = $vars[$name];
if (!isset($name))
return $ctx->error($ctx->mt->translate(
"You used a [_1] tag without a valid name attribute.", "<MT$tag>" ));
}
$value = $args['value'];
$existing = $vars[$name];
require_once("MTUtil.php");
if (isset($key)) {
if (!isset($existing))
$existing = array($key => $value);
elseif (is_hash($existing))
$existing = $existing[$key];
else
return $ctx->error( $ctx->mt->translate("'[_1]' is not a hash.", $name) );
}
elseif (isset($index)) {
if (!isset($existing))
$existing[$index] = $value;
elseif (is_array($existing)) {
if ( is_numeric($index) )
$existing = $existing[$index];
else
return $ctx->error( $ctx->mt->translate("Invalid index.") );
}
else
return $ctx->error( $ctx->mt->translate("'[_1]' is not an array.", $name) );
}
if (array_key_exists('append', $args) && $args['append']) {
$value = isset($existing) ? $existing . $value : $value;
}
elseif (array_key_exists('prepend', $args) && $args['prepend']) {
$value = isset($existing) ? $value . $existing : $value;
}
elseif ( isset($existing) && array_key_exists('op', $args) ) {
$op = $args['op'];
$value = _math_operation($op, $existing, $value);
if (!isset($value))
return $ctx->error($ctx->mt->translate("[_1] [_2] [_3] is illegal.", $existing, $op, $value));
}
$data = $vars[$name];
if ( isset($key) ) {
if ( ( isset($func) )
&& ( 'delete' == strtolower( $func ) ) ) {
unset($data[$key]);
}
else {
$data[$key] = $value;
}
}
elseif ( isset($index) ) {
$data[$index] = $value;
}
elseif ( isset($func) ) {
if ( 'undef' == strtolower( $func ) ) {
unset($data);
}
else {
if (isset($data) && !is_array($data))
return $ctx->error( $ctx->mt->translate("'[_1]' is not an array.", $name) );
if (!isset($data))
$data = array();
if ( 'push' == strtolower( $func ) ) {
array_push($data, $value);
}
elseif ( 'unshift' == strtolower( $func ) ) {
array_unshift($data, $value);
}
else {
return $ctx->error(
$ctx->mt->translate("'[_1]' is not a valid function.", $func)
);
}
}
}
else {
$data = $value;
}
$hash = $ctx->stash('__inside_set_hashvar');
if (isset($hash)) {
$hash[$name] = $data;
$ctx->stash('__inside_set_hashvar', $hash);
}
else {
if (is_array($vars)) {
$vars[$name] = $data;
} else {
$vars = array($name => $data);
$ctx->__stash['vars'] =& $vars;
}
}
return '';
}
?>